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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
416/A | 416 | A | Python 3 | TESTS | 64 | 124 | 614,400 | 51845347 | def trocaSinal(s):
if s == ">=":
return "<"
if s == "<=":
return ">"
if s == ">":
return "<="
if s == "<":
return ">="
n = int(input())
s = [0]*n
for i in range(n):
s[i] = input()
u = 2*10**9
l = -2*10**9
for i in range(n):
t = s[i].split(" ")
sinal = t[0]
... | 66 | 62 | 0 | 160917352 | n=int(input())
l=-2*10**9
r=2*10**9
for i in range(n):
s,v,f=input().split()
v=int(v)
if f=='N':
s={'<':'>','>':'<'}[s[0]]+s[1:]
if len(s)==1:
s+='='
else:
s=s[0]
if s[0]=='<':
... | Codeforces Round 241 (Div. 2) | CF | 2,014 | 1 | 256 | Guess a number! | A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.
The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions:
- Is it true that y is strictl... | The first line of the input contains a single integer n (1 ≤ n ≤ 10000) — the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is:
- ">" (for the first type queries),
- "<" (for the second type queries)... | Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation - 2·109 ≤ y ≤ 2·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes). | null | null | [{"input": "4\n>= 1 Y\n< 3 N\n<= -3 N\n> 55 N", "output": "17"}, {"input": "2\n> 100 Y\n< -100 Y", "output": "Impossible"}] | 1,400 | ["greedy", "implementation", "two pointers"] | 66 | [{"input": "4\r\n>= 1 Y\r\n< 3 N\r\n<= -3 N\r\n> 55 N\r\n", "output": "17\r\n"}, {"input": "2\r\n> 100 Y\r\n< -100 Y\r\n", "output": "Impossible\r\n"}, {"input": "4\r\n< 1 N\r\n> 1 N\r\n> 1 N\r\n> 1 N\r\n", "output": "1\r\n"}, {"input": "4\r\n<= 1 Y\r\n>= 1 Y\r\n>= 1 Y\r\n<= 1 Y\r\n", "output": "1\r\n"}, {"input": "4\r... | false | stdio | import sys
def main(input_path, output_path, submission_path):
with open(input_path) as f:
lines = f.readlines()
n = int(lines[0].strip())
queries = [line.strip().split() for line in lines[1:n+1]]
low = -2 * 10**9
high = 2 * 10**9
for sign, x_str, ans in queries:
x = i... | true |
356/C | 356 | C | PyPy 3 | TESTS | 3 | 139 | 0 | 42822914 | def bal(s,n,sums):
rems = sums%3
fss = sums//3 - rems
t = [0]*n
i = 0
while rems > 0:
rems -= 1
t[i] = 4
i += 1
while fss > 0:
fss -= 1
t[i] = 3
i += 1
return t
def cdif(s,b,n):
ss = sorted(s,reverse=True)
dif = 0
for i ... | 141 | 607 | 14,745,600 | 42135284 | #! /usr/bin/env python
n = int(input())
counts = [0] * 5
nums = [int(x) for x in input().split()]
for x in nums:
counts[x] += 1
s = sum(nums)
if s > 2 and s != 5:
ans = 0
if counts[1] >= counts[2]:
ans += counts[2]
counts[3] += counts[2]
counts[1] -= counts[2]
ans += 2 * (c... | Codeforces Round 207 (Div. 1) | CF | 2,013 | 1 | 256 | Compartments | A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people). We know that if one compartment contain one or two students, then they ge... | The first line contains integer n (1 ≤ n ≤ 106) — the number of compartments in the carriage. The second line contains n integers a1, a2, ..., an showing how many students ride in each compartment (0 ≤ ai ≤ 4). It is guaranteed that at least one student is riding in the train. | If no sequence of swapping seats with other people leads to the desired result, print number "-1" (without the quotes). In another case, print the smallest number of people you need to persuade to swap places. | null | null | [{"input": "5\n1 2 2 4 3", "output": "2"}, {"input": "3\n4 1 1", "output": "2"}, {"input": "4\n0 3 0 4", "output": "0"}] | 2,100 | ["combinatorics", "constructive algorithms", "greedy", "implementation"] | 141 | [{"input": "5\r\n1 2 2 4 3\r\n", "output": "2\r\n"}, {"input": "3\r\n4 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n0 3 0 4\r\n", "output": "0\r\n"}, {"input": "5\r\n4 4 3 3 1\r\n", "output": "1\r\n"}, {"input": "5\r\n4 3 4 2 4\r\n", "output": "1\r\n"}, {"input": "10\r\n2 1 2 3 4 1 3 4 4 4\r\n", "output": "2\r\n"}, {"... | false | stdio | null | true |
748/B | 748 | B | Python 3 | TESTS | 64 | 436 | 6,963,200 | 85478124 | s=input()
t=input()
num=len(s)
pair1=[0]*num
for i in range (num):
pair1[i]=[0]*2
def check(s,t,num):
arr=[0]*256
count=0
countie=0
same=[0]*num
for i in range (num):
if s[i]==t[i]:
same[i]=s[i]
if s[i] !=t[i]:
if same.count(s[i])>0 or same.count(t[i])>0:
... | 86 | 62 | 4,608,000 | 23302486 | s1, s2 = input(), input()
n = len(s1)
d = dict()
for i in range(n):
a = s1[i]
b = s2[i]
if b < a:
a, b = b, a
if a not in d and b not in d:
d[a] = b
d[b] = a
elif ((a in d and b not in d) or (a not in d and b in d)):
print(-1)
break
elif d[a] != b or d[b] ... | Technocup 2017 - Elimination Round 3 | CF | 2,016 | 2 | 256 | Santa Claus and Keyboard Check | Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be.
I... | The input consists of only two strings s and t denoting the favorite Santa's patter and the resulting string. s and t are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters. | If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes).
Otherwise, the first line of output should contain the only integer k (k ≥ 0) — the number of pairs of keys that should be swapped. The following k lines ... | null | null | [{"input": "helloworld\nehoolwlroz", "output": "3\nh e\nl o\nd z"}, {"input": "hastalavistababy\nhastalavistababy", "output": "0"}, {"input": "merrychristmas\nchristmasmerry", "output": "-1"}] | 1,500 | ["implementation", "strings"] | 86 | [{"input": "helloworld\r\nehoolwlroz\r\n", "output": "3\r\nh e\r\nl o\r\nd z\r\n"}, {"input": "hastalavistababy\r\nhastalavistababy\r\n", "output": "0\r\n"}, {"input": "merrychristmas\r\nchristmasmerry\r\n", "output": "-1\r\n"}, {"input": "kusyvdgccw\r\nkusyvdgccw\r\n", "output": "0\r\n"}, {"input": "bbbbbabbab\r\naaaa... | 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:
s, t = f.read().split()
s = s.strip()
t = t.strip()
with open(submission_path, 'r') as f:
lines = [line.strip() for line in f.readlines(... | true |
748/B | 748 | B | PyPy 3-64 | TESTS | 64 | 93 | 2,150,400 | 166298674 | from collections import Counter, deque, defaultdict
import math, sys
from itertools import permutations, accumulate
from sys import *
from heapq import *
from bisect import bisect_left, bisect_right
from functools import cmp_to_key
from random import shuffle, randint
xor = randint(10 ** 7, 10**8)
# https://github.com/c... | 86 | 62 | 4,608,000 | 23302742 | s1, s2 = input(), input()
alph1, alph2 = [], set()
ans = 0
for i in range(len(s1)):
fff = [max(s1[i], s2[i]), min(s1[i], s2[i])]
ff = fff not in alph1
if ff and (s1[i] in alph2 or s2[i] in alph2):
ans = -1
break
elif ff:
alph1.append(fff)
if s1[i] != s2[i]:
an... | Technocup 2017 - Elimination Round 3 | CF | 2,016 | 2 | 256 | Santa Claus and Keyboard Check | Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be.
I... | The input consists of only two strings s and t denoting the favorite Santa's patter and the resulting string. s and t are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters. | If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes).
Otherwise, the first line of output should contain the only integer k (k ≥ 0) — the number of pairs of keys that should be swapped. The following k lines ... | null | null | [{"input": "helloworld\nehoolwlroz", "output": "3\nh e\nl o\nd z"}, {"input": "hastalavistababy\nhastalavistababy", "output": "0"}, {"input": "merrychristmas\nchristmasmerry", "output": "-1"}] | 1,500 | ["implementation", "strings"] | 86 | [{"input": "helloworld\r\nehoolwlroz\r\n", "output": "3\r\nh e\r\nl o\r\nd z\r\n"}, {"input": "hastalavistababy\r\nhastalavistababy\r\n", "output": "0\r\n"}, {"input": "merrychristmas\r\nchristmasmerry\r\n", "output": "-1\r\n"}, {"input": "kusyvdgccw\r\nkusyvdgccw\r\n", "output": "0\r\n"}, {"input": "bbbbbabbab\r\naaaa... | 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:
s, t = f.read().split()
s = s.strip()
t = t.strip()
with open(submission_path, 'r') as f:
lines = [line.strip() for line in f.readlines(... | true |
962/A | 962 | A | Python 3 | TESTS | 11 | 109 | 20,582,400 | 126806876 | from math import ceil
i = int(input())
l = list(map(int,input().split()))
t=ceil(sum(l)/2)
for x in range(i):
t-=l[x]
if not t:break
print(x+1) | 106 | 93 | 17,510,400 | 178943617 | kac_gun = int(input())
dizi = input().split()
toplam, toplam2 = 0, 0
for i in range(kac_gun):
toplam += int(dizi[i])
for a in range(kac_gun + 1):
if toplam / 2 <= toplam2:
print(a)
break
toplam2 += int(dizi[a]) | Educational Codeforces Round 42 (Rated for Div. 2) | ICPC | 2,018 | 2 | 256 | Equator | Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.
On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He ... | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests.
The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$... | Print the index of the day when Polycarp will celebrate the equator. | null | In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.
In the second example Polycarp will celebrate the equator on the evening of the third day, because up to th... | [{"input": "4\n1 3 2 1", "output": "2"}, {"input": "6\n2 2 2 2 2 2", "output": "3"}] | 1,300 | ["implementation"] | 106 | [{"input": "4\r\n1 3 2 1\r\n", "output": "2\r\n"}, {"input": "6\r\n2 2 2 2 2 2\r\n", "output": "3\r\n"}, {"input": "1\r\n10000\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 3\r\n", "output": "2\r\n"}, {"input": "4\r\n2 1 1 3\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 3\r... | false | stdio | null | true |
757/A | 757 | A | Python 3 | TESTS | 27 | 62 | 204,800 | 112166820 | n=str(input())
d={'B':0,'u':0,'l':0,'b':0,'s':0,'r':0}
c=0
for i in n:
if i in d:
d[i]+=1
else:
d[i]=1
a=d['B']
for i in d:
if i=='a' or i=='u':
a= min(a,d[i]//2)
else:
a=min(a,d[i])
print(a) | 107 | 62 | 204,800 | 27699983 | S = input()
comp = "Bulbasaur"
nB = S.count("B")
nu = S.count("u")
nl = S.count("l")
nb = S.count("b")
na = S.count("a")
ns = S.count("s")
nr = S.count("r")
ans = min(nB, nu // 2, nl, nb, na // 2, ns, nr)
print(ans) | Codecraft-17 and Codeforces Round 391 (Div. 1 + Div. 2, combined) | CF | 2,017 | 1 | 256 | Gotta Catch Em' All! | Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbas... | Input contains a single line containing a string s (1 ≤ |s| ≤ 105) — the text on the front page of the newspaper without spaces and punctuation marks. |s| is the length of the string s.
The string s contains lowercase and uppercase English letters, i.e. $$s_i \in \{a,b,\ldots,z,A,B,\ldots,Z\}$$. | Output a single integer, the answer to the problem. | null | In the first case, you could pick: Bulbbasaur.
In the second case, there is no way to pick even a single Bulbasaur.
In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur". | [{"input": "Bulbbasaur", "output": "1"}, {"input": "F", "output": "0"}, {"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb", "output": "2"}] | 1,000 | ["implementation"] | 107 | [{"input": "Bulbbasaur\r\n", "output": "1\r\n"}, {"input": "F\r\n", "output": "0\r\n"}, {"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb\r\n", "output": "2\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr\r\n", "output": "5\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuu... | false | stdio | null | true |
446/A | 446 | A | Python 3 | TESTS | 38 | 139 | 9,318,400 | 7261916 | n = int(input())
t = list(map(int, input().split()))
t.append(0)
a = b = s = 0
for i in range(1, n):
if t[i] > t[i - 1]: b += 1
else:
s = max(s, a + b + 2)
a, b = b if t[i + 1] > t[i - 1] + 1 else 0, 0
print(min(n, max(s, a + b + 2))) | 92 | 140 | 13,516,800 | 152943843 | from operator import le
n=int(input())
a=[int(x) for x in ("0 "+input()+" 0").split(" ")]
a[0]=int(1e10)
a[n+1]=int(-1e10)
left=[1]*(n+5)
right=[1]*(n+5)
ans=0
for i in range(1, n+1):
if a[i]>a[i-1]: left[i]=left[i-1]+1
for i in range(n, 0, -1):
if a[i]<a[i+1]: right[i]=right[i+1]+1
ans=max(left)
ans=max(ri... | Codeforces Round #FF (Div. 1) | CF | 2,014 | 1 | 256 | DZY Loves Sequences | DZY has a sequence a, consisting of n integers.
We'll call a sequence ai, ai + 1, ..., aj (1 ≤ i ≤ j ≤ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment.
Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one numb... | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109). | In a single line print the answer to the problem — the maximum length of the required subsegment. | null | You can choose subsegment a2, a3, a4, a5, a6 and change its 3rd element (that is a4) to 4. | [{"input": "6\n7 2 3 1 5 6", "output": "5"}] | 1,600 | ["dp", "implementation", "two pointers"] | 92 | [{"input": "6\r\n7 2 3 1 5 6\r\n", "output": "5\r\n"}, {"input": "10\r\n424238336 649760493 681692778 714636916 719885387 804289384 846930887 957747794 596516650 189641422\r\n", "output": "9\r\n"}, {"input": "50\r\n804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 189641422 25202... | false | stdio | null | true |
446/A | 446 | A | PyPy 3-64 | TESTS | 38 | 217 | 18,329,600 | 137932932 | n = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)
B = [0 for i in range(n + 1)]
for i in range(1, n + 1):
if A[i] <= A[i - 1]:
B[i] = 1
B[i] += B[i - 1]
l, r = 1, n
while l < r:
# print(l, r)
mid = (l + r + 1) // 2
ok = False
for j in range(mid, n + 1):
i = j - ... | 92 | 171 | 13,312,000 | 35974116 | length = int(input())
nums = [int(num) for num in input().split()] + [float('inf'), float('-inf')]
ans = 0
small = 0
big = 0
for i in range(length):
if nums[i] > nums[i - 1]:
small += 1
big += 1
else:
ans = max(ans, small + 1, big)
big = small + 1 if nums[i + 1] > nums[i - 1] +... | Codeforces Round #FF (Div. 1) | CF | 2,014 | 1 | 256 | DZY Loves Sequences | DZY has a sequence a, consisting of n integers.
We'll call a sequence ai, ai + 1, ..., aj (1 ≤ i ≤ j ≤ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment.
Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one numb... | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109). | In a single line print the answer to the problem — the maximum length of the required subsegment. | null | You can choose subsegment a2, a3, a4, a5, a6 and change its 3rd element (that is a4) to 4. | [{"input": "6\n7 2 3 1 5 6", "output": "5"}] | 1,600 | ["dp", "implementation", "two pointers"] | 92 | [{"input": "6\r\n7 2 3 1 5 6\r\n", "output": "5\r\n"}, {"input": "10\r\n424238336 649760493 681692778 714636916 719885387 804289384 846930887 957747794 596516650 189641422\r\n", "output": "9\r\n"}, {"input": "50\r\n804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 189641422 25202... | false | stdio | null | true |
446/A | 446 | A | PyPy 3 | TESTS | 38 | 280 | 11,673,600 | 56875534 | n = int(input())
a = [0] + list(map(int, input().split()))
best = 1
curl = 0
prevl = 0
for i in range(1, n + 1):
if a[i] > a[i - 1]:
curl += 1
best = max(best, curl + prevl, curl + 1 if curl != n else 0)
else:
if i == n:
best = max(best, prevl + curl, curl + 1 if curl != n else 0)
else:
best = max(best,... | 92 | 171 | 19,251,200 | 161612007 | n=int(input())
a=list(map(int,input().split()))
dpl=[1]*n
dpr=[1]*n
for i in range(1,n):
if a[i]>a[i-1]:dpl[i]=dpl[i-1]+1
for i in range(n-2,-1,-1):
if a[i]<a[i+1]:dpr[i]=dpr[i+1]+1
res=max(dpl)
if res<n:res=res+1
for i in range(1,n-1):
if a[i+1]-a[i-1]>1:res=max(res,dpl[i-1]+dpr[i+1]+1)
print(res) | Codeforces Round #FF (Div. 1) | CF | 2,014 | 1 | 256 | DZY Loves Sequences | DZY has a sequence a, consisting of n integers.
We'll call a sequence ai, ai + 1, ..., aj (1 ≤ i ≤ j ≤ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment.
Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one numb... | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109). | In a single line print the answer to the problem — the maximum length of the required subsegment. | null | You can choose subsegment a2, a3, a4, a5, a6 and change its 3rd element (that is a4) to 4. | [{"input": "6\n7 2 3 1 5 6", "output": "5"}] | 1,600 | ["dp", "implementation", "two pointers"] | 92 | [{"input": "6\r\n7 2 3 1 5 6\r\n", "output": "5\r\n"}, {"input": "10\r\n424238336 649760493 681692778 714636916 719885387 804289384 846930887 957747794 596516650 189641422\r\n", "output": "9\r\n"}, {"input": "50\r\n804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 189641422 25202... | false | stdio | null | true |
446/A | 446 | A | Python 3 | TESTS | 38 | 343 | 15,155,200 | 38097317 | n=int(input())
a=list(map(int,input().split()))
ch=[1]*n
for i in range(1,n):
if a[i-1]<a[i]: ch[i]+=ch[i-1]
cc=ch[:]
for i in range(n-1,0,-1):
if ch[i]>ch[i-1]: cc[i-1]=cc[i]
ch=cc[:]
mx=1
for i in range(n):
mx=max(mx,ch[i]+1)
try:
if a[i+2]>a[i]+1 and ch[i]!=ch[i+1]:
mx=max(mx,ch[i... | 92 | 186 | 11,161,600 | 162708204 | n = int(input())
a = list(map(int, input().split()))
a.append(a[n - 1])
a.append(a[n - 1])
m = len(a)
L = [0] * m
R = [0] * m
L[0] = 1
for i in range(1, n):
if a[i] > a[i - 1]:
L[i] = L[i - 1] + 1
else:
L[i] = 1
R[n - 1] = 1
for i in range(n - 2, -1, -1):
if a[i] < a[i + 1]:
R[i] = R... | Codeforces Round #FF (Div. 1) | CF | 2,014 | 1 | 256 | DZY Loves Sequences | DZY has a sequence a, consisting of n integers.
We'll call a sequence ai, ai + 1, ..., aj (1 ≤ i ≤ j ≤ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment.
Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one numb... | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109). | In a single line print the answer to the problem — the maximum length of the required subsegment. | null | You can choose subsegment a2, a3, a4, a5, a6 and change its 3rd element (that is a4) to 4. | [{"input": "6\n7 2 3 1 5 6", "output": "5"}] | 1,600 | ["dp", "implementation", "two pointers"] | 92 | [{"input": "6\r\n7 2 3 1 5 6\r\n", "output": "5\r\n"}, {"input": "10\r\n424238336 649760493 681692778 714636916 719885387 804289384 846930887 957747794 596516650 189641422\r\n", "output": "9\r\n"}, {"input": "50\r\n804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 189641422 25202... | false | stdio | null | true |
818/E | 818 | E | Python 3 | TESTS | 7 | 77 | 7,065,600 | 36888581 | n,k=[int(x) for x in input().strip().split(' ')]
arr=[int(x) for x in input().strip().split(' ')]
n=len(arr)
if(k==1):
print((n*(n+1))//2)
else:
c=0
prod=1
for i in arr:
prod*=i
if(prod%k==0):
c+=1
head=1
tail=1
for i in range(1,n):
p=prod//(arr[i-1]*head)
... | 135 | 373 | 31,744,000 | 127711452 | import bisect
import sys
input = sys.stdin.readline
def prime_factorize(n):
ans = []
for i in range(2, int(n ** (1 / 2)) + 1):
while True:
if n % i:
break
ans.append(i)
n //= i
if n == 1:
break
if not n == 1:
ans.append... | Educational Codeforces Round 24 | ICPC | 2,017 | 2 | 256 | Card Game Again | Vova again tries to play some computer card game.
The rules of deck creation in this game are simple. Vova is given an existing deck of n cards and a magic number k. The order of the cards in the deck is fixed. Each card has a number written on it; number ai is written on the i-th card in the deck.
After receiving th... | The first line contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109).
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers written on the cards. | Print the number of ways to choose x and y so the resulting deck is valid. | null | In the first example the possible values of x and y are:
1. x = 0, y = 0;
2. x = 1, y = 0;
3. x = 2, y = 0;
4. x = 0, y = 1. | [{"input": "3 4\n6 2 8", "output": "4"}, {"input": "3 6\n9 1 14", "output": "1"}] | 1,900 | ["binary search", "data structures", "number theory", "two pointers"] | 135 | [{"input": "3 4\r\n6 2 8\r\n", "output": "4\r\n"}, {"input": "3 6\r\n9 1 14\r\n", "output": "1\r\n"}, {"input": "5 1\r\n1 3 1 3 1\r\n", "output": "15\r\n"}, {"input": "5 1\r\n5 5 5 5 5\r\n", "output": "15\r\n"}, {"input": "5 1\r\n5 4 4 4 4\r\n", "output": "15\r\n"}, {"input": "100 1\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1... | false | stdio | null | true |
748/B | 748 | B | Python 3 | TESTS | 23 | 124 | 307,200 | 41148279 | a = input()
b = input()
d = {}
for i in range(len(a)):
if d.get(a[i]) and d[a[i]] != b[i] or d.get(b[i]) and d[b[i]] != a[i]:
print('-1')
break
elif not d.get(a[i]) and not d.get(b[i]):
d[a[i]] = b[i]
else:
ans = {}
for x in d:
if x != d[x]:
ans[x] = d[x]
... | 86 | 62 | 4,608,000 | 23302904 | s1 = input()
s2 = input()
n = len(s1)
d = dict()
for i in range(n):
a = s1[i]
b = s2[i]
if b < a:
a, b = b, a
if a not in d and b not in d:
d[a] = b
d[b] = a
elif (a in d and b not in d) or (a not in d and b in d):
print(-1)
break
elif d[a] != b or d[b] !=... | Technocup 2017 - Elimination Round 3 | CF | 2,016 | 2 | 256 | Santa Claus and Keyboard Check | Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be.
I... | The input consists of only two strings s and t denoting the favorite Santa's patter and the resulting string. s and t are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters. | If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes).
Otherwise, the first line of output should contain the only integer k (k ≥ 0) — the number of pairs of keys that should be swapped. The following k lines ... | null | null | [{"input": "helloworld\nehoolwlroz", "output": "3\nh e\nl o\nd z"}, {"input": "hastalavistababy\nhastalavistababy", "output": "0"}, {"input": "merrychristmas\nchristmasmerry", "output": "-1"}] | 1,500 | ["implementation", "strings"] | 86 | [{"input": "helloworld\r\nehoolwlroz\r\n", "output": "3\r\nh e\r\nl o\r\nd z\r\n"}, {"input": "hastalavistababy\r\nhastalavistababy\r\n", "output": "0\r\n"}, {"input": "merrychristmas\r\nchristmasmerry\r\n", "output": "-1\r\n"}, {"input": "kusyvdgccw\r\nkusyvdgccw\r\n", "output": "0\r\n"}, {"input": "bbbbbabbab\r\naaaa... | 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:
s, t = f.read().split()
s = s.strip()
t = t.strip()
with open(submission_path, 'r') as f:
lines = [line.strip() for line in f.readlines(... | true |
416/A | 416 | A | Python 3 | TESTS | 62 | 77 | 307,200 | 109443805 | n = int(input())
flag = True
l = -2e9
r = 2e9
for i in range(n):
q = input()
ans = q[-1]
if(ans == 'Y'):
ans = True
else:
ans = False
if(q[1]=='='):
num = int(q[3:-2])
else:
num = int(q[2:-2])
# print(num)
if(flag==True):
if(q[0] == '>'):
... | 66 | 77 | 0 | 15838635 | def main():
lo, hi = -2000000000, 2000000001
for _ in range(int(input())):
s, x, yn = input().split()
if yn == "N":
s = {"<": ">=", ">": "<=", "<=": ">", ">=": "<"}[s]
x = int(x) + 1 if s in ("<=", ">") else int(x)
if s[0] == "<":
if hi > x:
... | Codeforces Round 241 (Div. 2) | CF | 2,014 | 1 | 256 | Guess a number! | A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.
The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions:
- Is it true that y is strictl... | The first line of the input contains a single integer n (1 ≤ n ≤ 10000) — the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is:
- ">" (for the first type queries),
- "<" (for the second type queries)... | Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation - 2·109 ≤ y ≤ 2·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes). | null | null | [{"input": "4\n>= 1 Y\n< 3 N\n<= -3 N\n> 55 N", "output": "17"}, {"input": "2\n> 100 Y\n< -100 Y", "output": "Impossible"}] | 1,400 | ["greedy", "implementation", "two pointers"] | 66 | [{"input": "4\r\n>= 1 Y\r\n< 3 N\r\n<= -3 N\r\n> 55 N\r\n", "output": "17\r\n"}, {"input": "2\r\n> 100 Y\r\n< -100 Y\r\n", "output": "Impossible\r\n"}, {"input": "4\r\n< 1 N\r\n> 1 N\r\n> 1 N\r\n> 1 N\r\n", "output": "1\r\n"}, {"input": "4\r\n<= 1 Y\r\n>= 1 Y\r\n>= 1 Y\r\n<= 1 Y\r\n", "output": "1\r\n"}, {"input": "4\r... | false | stdio | import sys
def main(input_path, output_path, submission_path):
with open(input_path) as f:
lines = f.readlines()
n = int(lines[0].strip())
queries = [line.strip().split() for line in lines[1:n+1]]
low = -2 * 10**9
high = 2 * 10**9
for sign, x_str, ans in queries:
x = i... | true |
356/C | 356 | C | Python 3 | TESTS | 12 | 560 | 14,540,800 | 44927335 | a = [0] * 5
tot, ans = 0, 0
input()
for x in list(map(int, input().split())):
a[x] += 1
tot += x
mn = min(a[1], a[2])
a[1] -= mn
a[2] -= mn
a[3] += mn
ans += mn
if a[1]:
add = a[1] // 3
a[1] %= 3
a[3] += add
ans += 2 * add
ans += 1 if a[1] == 1 and a[3] else 2 if a[1] and not a[3] else 0
if a[2]:
ad... | 141 | 607 | 14,745,600 | 42135284 | #! /usr/bin/env python
n = int(input())
counts = [0] * 5
nums = [int(x) for x in input().split()]
for x in nums:
counts[x] += 1
s = sum(nums)
if s > 2 and s != 5:
ans = 0
if counts[1] >= counts[2]:
ans += counts[2]
counts[3] += counts[2]
counts[1] -= counts[2]
ans += 2 * (c... | Codeforces Round 207 (Div. 1) | CF | 2,013 | 1 | 256 | Compartments | A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people). We know that if one compartment contain one or two students, then they ge... | The first line contains integer n (1 ≤ n ≤ 106) — the number of compartments in the carriage. The second line contains n integers a1, a2, ..., an showing how many students ride in each compartment (0 ≤ ai ≤ 4). It is guaranteed that at least one student is riding in the train. | If no sequence of swapping seats with other people leads to the desired result, print number "-1" (without the quotes). In another case, print the smallest number of people you need to persuade to swap places. | null | null | [{"input": "5\n1 2 2 4 3", "output": "2"}, {"input": "3\n4 1 1", "output": "2"}, {"input": "4\n0 3 0 4", "output": "0"}] | 2,100 | ["combinatorics", "constructive algorithms", "greedy", "implementation"] | 141 | [{"input": "5\r\n1 2 2 4 3\r\n", "output": "2\r\n"}, {"input": "3\r\n4 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n0 3 0 4\r\n", "output": "0\r\n"}, {"input": "5\r\n4 4 3 3 1\r\n", "output": "1\r\n"}, {"input": "5\r\n4 3 4 2 4\r\n", "output": "1\r\n"}, {"input": "10\r\n2 1 2 3 4 1 3 4 4 4\r\n", "output": "2\r\n"}, {"... | false | stdio | null | true |
416/A | 416 | A | Python 3 | TESTS | 61 | 124 | 0 | 51959460 | #import sys
#sys.stdin = open("123.data")
t = int(input())
l = -2000000000
r = 2000000000
while t > 0:
zn, n, fl = map(str, input().split())
n = int(n)
if fl == 'Y':
if zn == '>':
l = max(l, n - 1)
elif zn == '<':
r = min(r, n - 1)
elif zn == '>=':
l = max(l, n)
elif zn == '<=':
r = min(r, n)
e... | 66 | 77 | 307,200 | 104168641 | n=int(input())
l=-(10**9) - 1
r=10**9 + 1
for _ in range(n):
x,y,z=input().split()
x=str(x)
y=int(y)
z=str(z)
if z=="Y":
if x==">=":
if y>l:
l=y
elif x==">":
if y>=l:
l=y+1
elif x=="<=":
if y<r:
... | Codeforces Round 241 (Div. 2) | CF | 2,014 | 1 | 256 | Guess a number! | A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.
The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions:
- Is it true that y is strictl... | The first line of the input contains a single integer n (1 ≤ n ≤ 10000) — the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is:
- ">" (for the first type queries),
- "<" (for the second type queries)... | Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation - 2·109 ≤ y ≤ 2·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes). | null | null | [{"input": "4\n>= 1 Y\n< 3 N\n<= -3 N\n> 55 N", "output": "17"}, {"input": "2\n> 100 Y\n< -100 Y", "output": "Impossible"}] | 1,400 | ["greedy", "implementation", "two pointers"] | 66 | [{"input": "4\r\n>= 1 Y\r\n< 3 N\r\n<= -3 N\r\n> 55 N\r\n", "output": "17\r\n"}, {"input": "2\r\n> 100 Y\r\n< -100 Y\r\n", "output": "Impossible\r\n"}, {"input": "4\r\n< 1 N\r\n> 1 N\r\n> 1 N\r\n> 1 N\r\n", "output": "1\r\n"}, {"input": "4\r\n<= 1 Y\r\n>= 1 Y\r\n>= 1 Y\r\n<= 1 Y\r\n", "output": "1\r\n"}, {"input": "4\r... | false | stdio | import sys
def main(input_path, output_path, submission_path):
with open(input_path) as f:
lines = f.readlines()
n = int(lines[0].strip())
queries = [line.strip().split() for line in lines[1:n+1]]
low = -2 * 10**9
high = 2 * 10**9
for sign, x_str, ans in queries:
x = i... | true |
416/A | 416 | A | PyPy 3 | TESTS | 61 | 264 | 6,144,000 | 60035100 | n = int(input())
y = [-2*10**9,2*10**9]
k=[]
f=0
for i in range(n):
k.append(list(map(str,input().split())))
for i in range(n):
x = int(k[i][1])
if k[i][2]=='N':
if k[i][0]=='>':
k[i][0]='<='
elif k[i][0]=='>=':
k[i][0]='<'
elif k[i][0]=='<':
k[i][0]='>='
else:
k[i][0]='>'
if k[i][0]=='>':
y[... | 66 | 77 | 307,200 | 108603211 | left=-2000000000
right=2000000000
for _ in range(int(input())):
temp=input().split()
sign=temp[0]
n=int(temp[1])
tf=temp[2]
if tf=='Y':
if sign=='>' and left<=n:
left=n+1
elif sign=='>=' and left<n:
left=n
elif sign=='<' and right>=n:
righ... | Codeforces Round 241 (Div. 2) | CF | 2,014 | 1 | 256 | Guess a number! | A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.
The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions:
- Is it true that y is strictl... | The first line of the input contains a single integer n (1 ≤ n ≤ 10000) — the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is:
- ">" (for the first type queries),
- "<" (for the second type queries)... | Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation - 2·109 ≤ y ≤ 2·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes). | null | null | [{"input": "4\n>= 1 Y\n< 3 N\n<= -3 N\n> 55 N", "output": "17"}, {"input": "2\n> 100 Y\n< -100 Y", "output": "Impossible"}] | 1,400 | ["greedy", "implementation", "two pointers"] | 66 | [{"input": "4\r\n>= 1 Y\r\n< 3 N\r\n<= -3 N\r\n> 55 N\r\n", "output": "17\r\n"}, {"input": "2\r\n> 100 Y\r\n< -100 Y\r\n", "output": "Impossible\r\n"}, {"input": "4\r\n< 1 N\r\n> 1 N\r\n> 1 N\r\n> 1 N\r\n", "output": "1\r\n"}, {"input": "4\r\n<= 1 Y\r\n>= 1 Y\r\n>= 1 Y\r\n<= 1 Y\r\n", "output": "1\r\n"}, {"input": "4\r... | false | stdio | import sys
def main(input_path, output_path, submission_path):
with open(input_path) as f:
lines = f.readlines()
n = int(lines[0].strip())
queries = [line.strip().split() for line in lines[1:n+1]]
low = -2 * 10**9
high = 2 * 10**9
for sign, x_str, ans in queries:
x = i... | true |
416/A | 416 | A | Python 3 | TESTS | 62 | 78 | 6,963,200 | 125107477 | n = int(input())
check = pow(10, 10)
arr = [-check, check, -check, check]
for i in range(n):
s = input().split()
if(s[0] == '>'):
if(s[2] == 'Y'):
arr[0] = max(arr[0], int(s[1]))
else:
arr[3] = min(arr[3], int(s[1]))
elif(s[0] == '<'):
if(s[2] == 'Y'... | 66 | 77 | 6,963,200 | 130594525 | n = int(input())
max = 2 * (10**9)
min = -2 * (10**9)
for q in range(n):
sxans = input().split()
s = sxans[0]
val = int(sxans[1])
ans = sxans[2]
if '>=' in s :
if ans == 'Y':
if int(val) > min:
min = val
else:
if int(val) < max :
... | Codeforces Round 241 (Div. 2) | CF | 2,014 | 1 | 256 | Guess a number! | A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.
The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions:
- Is it true that y is strictl... | The first line of the input contains a single integer n (1 ≤ n ≤ 10000) — the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is:
- ">" (for the first type queries),
- "<" (for the second type queries)... | Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation - 2·109 ≤ y ≤ 2·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes). | null | null | [{"input": "4\n>= 1 Y\n< 3 N\n<= -3 N\n> 55 N", "output": "17"}, {"input": "2\n> 100 Y\n< -100 Y", "output": "Impossible"}] | 1,400 | ["greedy", "implementation", "two pointers"] | 66 | [{"input": "4\r\n>= 1 Y\r\n< 3 N\r\n<= -3 N\r\n> 55 N\r\n", "output": "17\r\n"}, {"input": "2\r\n> 100 Y\r\n< -100 Y\r\n", "output": "Impossible\r\n"}, {"input": "4\r\n< 1 N\r\n> 1 N\r\n> 1 N\r\n> 1 N\r\n", "output": "1\r\n"}, {"input": "4\r\n<= 1 Y\r\n>= 1 Y\r\n>= 1 Y\r\n<= 1 Y\r\n", "output": "1\r\n"}, {"input": "4\r... | false | stdio | import sys
def main(input_path, output_path, submission_path):
with open(input_path) as f:
lines = f.readlines()
n = int(lines[0].strip())
queries = [line.strip().split() for line in lines[1:n+1]]
low = -2 * 10**9
high = 2 * 10**9
for sign, x_str, ans in queries:
x = i... | true |
540/B | 540 | B | Python 3 | TESTS | 2 | 93 | 1,536,000 | 114497440 | def marks(n, k, p, x, y, A):
j = n - k
a = sum(1 for m in A if m < y)
b = sum(1 for m in A if m > y)
m = n // 2
if a > m or b > m:
return None
B = [y] * (n - k - (m - a)) + [1] * (m - a)
s = sum(A) + sum(B)
return B if s <= x else None
def main():
n, k, p, x, y = readinti()... | 78 | 62 | 2,252,800 | 137113754 | n,k,p,x,y=map(int,input().split())
l=list(map(int,input().split()))
k1=0
for x1 in l :
if x1>=y :
k1+=1
t=(n)//2+1
if k1>t :
t=0
else :
t=abs(t-k1)
if sum(l)+t*y+abs(n-k-t)>x or p<y or (n-k)<t :
print(-1)
quit()
ans=[y]*t+[1]*(n-k-t)
print(*ans) | Codeforces Round 301 (Div. 2) | CF | 2,015 | 2 | 256 | School Marks | Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all tests... | The first line contains 5 space-separated integers: n, k, p, x and y (1 ≤ n ≤ 999, n is odd, 0 ≤ k < n, 1 ≤ p ≤ 1000, n ≤ x ≤ n·p, 1 ≤ y ≤ p). Here n is the number of tests that Vova is planned to write, k is the number of tests he has already written, p is the maximum possible mark for a test, x is the maximum total n... | If Vova cannot achieve the desired result, print "-1".
Otherwise, print n - k space-separated integers — the marks that Vova should get for the remaining tests. If there are multiple possible solutions, print any of them. | null | The median of sequence a1, ..., an where n is odd (in this problem n is always odd) is the element staying on (n + 1) / 2 position in the sorted list of ai.
In the first sample the sum of marks equals 3 + 5 + 4 + 4 + 1 = 17, what doesn't exceed 18, that means that Vova won't be disturbed by his classmates. And the med... | [{"input": "5 3 5 18 4\n3 5 4", "output": "4 1"}, {"input": "5 3 5 16 4\n5 5 5", "output": "-1"}] | 1,700 | ["greedy", "implementation"] | 78 | [{"input": "5 3 5 18 4\r\n3 5 4\r\n", "output": "4 1\r\n"}, {"input": "5 3 5 16 4\r\n5 5 5\r\n", "output": "-1\r\n"}, {"input": "5 3 5 17 4\r\n5 5 5\r\n", "output": "1 1\r\n"}, {"input": "5 3 5 12 1\r\n5 5 1\r\n", "output": "-1\r\n"}, {"input": "5 3 5 13 1\r\n5 5 1\r\n", "output": "1 1\r\n"}, {"input": "7 4 5 26 5\r\n5... | false | stdio | import sys
def main(input_path, output_path, submission_path):
with open(input_path, 'r') as f_in:
n, k, p, x, y = map(int, f_in.readline().split())
existing = list(map(int, f_in.readline().split()))
with open(submission_path, 'r') as f_sub:
submission_line = f_sub.read().strip()
... | true |
217/A | 217 | A | PyPy 3 | TESTS | 49 | 280 | 1,740,800 | 77327694 | n=int(input())
d=dict()
d1=dict()
l=[]
d1=dict()
for i in range(n):
a,b=map(int,input().split())
if b not in d:
d.update({b:{a}})
l.append(b)
d1.update({b:1})
else:
d[b].add(a)
ans=0
e=dict()
for i in d:
t=len(e)
e.update({i:{i}})
for j in d:
if len(d[j].i... | 76 | 92 | 0 | 137516786 | n=int(input())
ans=1
x1=[]
y1=[]
for i in range(n):
x,y=list(map(int,input().split()))
x1.append({x})
y1.append({y})
for i in range(n-1):
for j in range(i+1,n):
if x1[i]&x1[j] or y1[i]&y1[j]:
x1[j]|=x1[i]
y1[j]|=y1[i]
ans+=1
break
print(n-ans) | Codeforces Round 134 (Div. 1) | CF | 2,012 | 2 | 256 | Ice Skating | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves... | The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсid... | Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. | null | null | [{"input": "2\n2 1\n1 2", "output": "1"}, {"input": "2\n2 1\n4 1", "output": "0"}] | 1,200 | ["brute force", "dfs and similar", "dsu", "graphs"] | 76 | [{"input": "2\r\n2 1\r\n1 2\r\n", "output": "1\r\n"}, {"input": "2\r\n2 1\r\n4 1\r\n", "output": "0\r\n"}, {"input": "24\r\n171 35\r\n261 20\r\n4 206\r\n501 446\r\n961 912\r\n581 748\r\n946 978\r\n463 514\r\n841 889\r\n341 466\r\n842 967\r\n54 102\r\n235 261\r\n925 889\r\n682 672\r\n623 636\r\n268 94\r\n635 710\r\n474 ... | false | stdio | null | true |
217/A | 217 | A | Python 3 | TESTS | 47 | 92 | 0 | 206617316 | MAX_N = 105
root = [[] for _ in range(MAX_N)]
n = int(input().strip())
for i in range(1, n + 1):
x, y = map(int, input().strip().split())
root[i] = [x, y, i]
def find_root(u):
if root[u[2]][2] == u[2]:
return u[2]
else:
root[u[2]][2] = find_root(root[u[2]])
return root[u[2]][2]
... | 76 | 92 | 0 | 144843945 | n=int(input())
q={}
l=[]
r=[]
def f(a):
while q[a]!=a:
a=q[a]
return a
for i in range(n):
a,b=map(str,input().split())
o,p="x"+a,"y"+b
l+=[[o,p]]
r+=[o,p]
q[o]=o
q[p]=p
for i in range(n):
l[i][0]=f(l[i][0])
l[i][1]=f(l[i][1])
q[l[i][1]]=q[l[i][0]]
for i in r:
q[i]... | Codeforces Round 134 (Div. 1) | CF | 2,012 | 2 | 256 | Ice Skating | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves... | The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсid... | Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. | null | null | [{"input": "2\n2 1\n1 2", "output": "1"}, {"input": "2\n2 1\n4 1", "output": "0"}] | 1,200 | ["brute force", "dfs and similar", "dsu", "graphs"] | 76 | [{"input": "2\r\n2 1\r\n1 2\r\n", "output": "1\r\n"}, {"input": "2\r\n2 1\r\n4 1\r\n", "output": "0\r\n"}, {"input": "24\r\n171 35\r\n261 20\r\n4 206\r\n501 446\r\n961 912\r\n581 748\r\n946 978\r\n463 514\r\n841 889\r\n341 466\r\n842 967\r\n54 102\r\n235 261\r\n925 889\r\n682 672\r\n623 636\r\n268 94\r\n635 710\r\n474 ... | false | stdio | null | true |
217/A | 217 | A | PyPy 3 | TESTS | 49 | 280 | 1,228,800 | 97127514 | linhas = int(input())
drifts = []
for _ in range(linhas):
x, y = list(map(int, input().split()))
drifts.append((x,y))
componentes = []
def get_all_conections(x, y, i):
j = 0
while j < len(drifts):
if drifts[j][0] == x or drifts[j][1] == y:
componentes[i].append(drifts[j])
... | 76 | 92 | 0 | 146270957 | n = int(input())
coords = []
for _ in range(n):
nx, ny = map(int, input().split())
coords.append((nx, ny))
def search(x, y, v):
v.append((x, y))
for nx, ny in coords:
if (nx == x and ny != y) or (nx != x and ny == y):
if (nx, ny) not in v:
search(nx, ny, v)
ret... | Codeforces Round 134 (Div. 1) | CF | 2,012 | 2 | 256 | Ice Skating | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves... | The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсid... | Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. | null | null | [{"input": "2\n2 1\n1 2", "output": "1"}, {"input": "2\n2 1\n4 1", "output": "0"}] | 1,200 | ["brute force", "dfs and similar", "dsu", "graphs"] | 76 | [{"input": "2\r\n2 1\r\n1 2\r\n", "output": "1\r\n"}, {"input": "2\r\n2 1\r\n4 1\r\n", "output": "0\r\n"}, {"input": "24\r\n171 35\r\n261 20\r\n4 206\r\n501 446\r\n961 912\r\n581 748\r\n946 978\r\n463 514\r\n841 889\r\n341 466\r\n842 967\r\n54 102\r\n235 261\r\n925 889\r\n682 672\r\n623 636\r\n268 94\r\n635 710\r\n474 ... | false | stdio | null | true |
217/A | 217 | A | PyPy 3 | TESTS | 49 | 186 | 0 | 112725054 | # juntar em grupos onde é possível chegar de algum deles
# um grupo são elementos que um pode chegar em outro sem gastar snow drifts extras, ou seja, possui x ou y igual
# o valor final vai ser qtdGrupos - 1
teste = [[1,2],[4,2],[3,8],[7,6],[6,6],[8,2],[8,8],[6,10],[2,1],[2,8]]
def canReach(g1, g2):
intersectX = bo... | 76 | 92 | 0 | 147147951 | def DFS(x, mark, a, v):
mark[x] = True
for i in v[a[x][0]]:
if mark[i]:
continue
DFS(i, mark, a, v)
for i in v[a[x][1]+1000]:
if mark[i]:
continue
DFS(i, mark, a, v)
n = int(input())
a = []
v = []
for i in range(2001):
v.append(list([]))
for i in r... | Codeforces Round 134 (Div. 1) | CF | 2,012 | 2 | 256 | Ice Skating | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves... | The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсid... | Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. | null | null | [{"input": "2\n2 1\n1 2", "output": "1"}, {"input": "2\n2 1\n4 1", "output": "0"}] | 1,200 | ["brute force", "dfs and similar", "dsu", "graphs"] | 76 | [{"input": "2\r\n2 1\r\n1 2\r\n", "output": "1\r\n"}, {"input": "2\r\n2 1\r\n4 1\r\n", "output": "0\r\n"}, {"input": "24\r\n171 35\r\n261 20\r\n4 206\r\n501 446\r\n961 912\r\n581 748\r\n946 978\r\n463 514\r\n841 889\r\n341 466\r\n842 967\r\n54 102\r\n235 261\r\n925 889\r\n682 672\r\n623 636\r\n268 94\r\n635 710\r\n474 ... | false | stdio | null | true |
217/A | 217 | A | Python 3 | TESTS | 49 | 154 | 0 | 6547691 | import sys
def main():
n = int(input())
drifts = dict()
for _ in range(n):
i, j = map(int, input().split())
drifts[i] = drifts.get(i, set()) | set([j])
ans = 0
if n > 1:
group = set()
for d in drifts:
if not len(group):
group |= drifts[d]... | 76 | 92 | 0 | 148064758 | def dfs(index):
visited[index] = 0
for i in range(n):
if((graph[i][0] == graph[index][0] or graph[i][1] == graph[index][1] ) and visited[i] == -1 ):
dfs(i)
n = int(input())
if(n >= 1 and n <= 100):
visited = []
graph = {}
count = -1
for i in range(n):
x, y = input().... | Codeforces Round 134 (Div. 1) | CF | 2,012 | 2 | 256 | Ice Skating | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves... | The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсid... | Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. | null | null | [{"input": "2\n2 1\n1 2", "output": "1"}, {"input": "2\n2 1\n4 1", "output": "0"}] | 1,200 | ["brute force", "dfs and similar", "dsu", "graphs"] | 76 | [{"input": "2\r\n2 1\r\n1 2\r\n", "output": "1\r\n"}, {"input": "2\r\n2 1\r\n4 1\r\n", "output": "0\r\n"}, {"input": "24\r\n171 35\r\n261 20\r\n4 206\r\n501 446\r\n961 912\r\n581 748\r\n946 978\r\n463 514\r\n841 889\r\n341 466\r\n842 967\r\n54 102\r\n235 261\r\n925 889\r\n682 672\r\n623 636\r\n268 94\r\n635 710\r\n474 ... | false | stdio | null | true |
798/B | 798 | B | Python 3 | TESTS | 89 | 46 | 0 | 141164301 | n = int(input())
l = []
for i in range(n):
l.append(input())
ex_list = []
ex_list.append(l[0])
for i in range(len(l[0]) - 1):
s = ex_list[i]
ex_list.append( s[1:] + s[:1] )
r = []
for i in l:
for j in range(len(ex_list)):
if i == ex_list[j]:
r.append( (len(ex_list[0])-j) % len(ex_lis... | 99 | 46 | 0 | 190118801 | s = []
for _ in range(int(input())) :
s.append(str(input()))
ans = 10**9
avail = True
for i in s :
c = 0
for j in s :
pat = j + j
x = pat.find(i)
if x < 0 :
avail = False
else :
c += x
ans = min(c, ans)
if avail :
print(ans)
else :
print(-... | Codeforces Round 410 (Div. 2) | CF | 2,017 | 2 | 256 | Mike and strings | Mike has n strings s1, s2, ..., sn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec".
Now Mike asks himself: what... | The first line contains integer n (1 ≤ n ≤ 50) — the number of strings.
This is followed by n lines which contain a string each. The i-th line corresponding to string si. Lengths of strings are equal. Lengths of each string is positive and don't exceed 50. | Print the minimal number of moves Mike needs in order to make all the strings equal or print - 1 if there is no solution. | null | In the first sample testcase the optimal scenario is to perform operations in such a way as to transform all strings into "zwoxz". | [{"input": "4\nxzzwo\nzwoxz\nzzwox\nxzzwo", "output": "5"}, {"input": "2\nmolzv\nlzvmo", "output": "2"}, {"input": "3\nkc\nkc\nkc", "output": "0"}, {"input": "3\naa\naa\nab", "output": "-1"}] | 1,300 | ["brute force", "dp", "strings"] | 99 | [{"input": "4\r\nxzzwo\r\nzwoxz\r\nzzwox\r\nxzzwo\r\n", "output": "5\r\n"}, {"input": "2\r\nmolzv\r\nlzvmo\r\n", "output": "2\r\n"}, {"input": "3\r\nkc\r\nkc\r\nkc\r\n", "output": "0\r\n"}, {"input": "3\r\naa\r\naa\r\nab\r\n", "output": "-1\r\n"}, {"input": "3\r\nkwkb\r\nkbkw\r\nbkwk\r\n", "output": "3\r\n"}, {"input":... | false | stdio | null | true |
638/B | 638 | B | PyPy 3 | TESTS | 11 | 155 | 1,433,600 | 83740168 | #from bisect import bisect_left as bl #c++ lowerbound bl(array,element)
#from bisect import bisect_right as br #c++ upperbound br(array,element)
#from __future__ import print_function, division #while using python2
def modinv(n,p):
return pow(n,p-2,p)
def merge(a, b):
if a in ... | 67 | 61 | 5,120,000 | 16853128 | n = int(input())
genom = dict()
heads = set()
for i in range(n):
part = input()
heads.add(part[0])
for i in range(len(part)):
prev = None
next = None
if i - 1 >= 0:
prev = part[i - 1]
if i + 1 < len(part):
next = part[i + 1]
if part[i] in g... | VK Cup 2016 - Qualification Round 2 | CF | 2,016 | 1 | 256 | Making Genome in Berland | Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct En... | The first line of the input contains a positive integer n (1 ≤ n ≤ 100) — the number of genome fragments.
Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are d... | In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them. | null | null | [{"input": "3\nbcd\nab\ncdef", "output": "abcdef"}, {"input": "4\nx\ny\nz\nw", "output": "xyzw"}] | 1,500 | ["*special", "dfs and similar", "strings"] | 67 | [{"input": "3\r\nbcd\r\nab\r\ncdef\r\n", "output": "abcdef\r\n"}, {"input": "4\r\nx\r\ny\r\nz\r\nw\r\n", "output": "xyzw\r\n"}, {"input": "25\r\nef\r\nfg\r\ngh\r\nhi\r\nij\r\njk\r\nkl\r\nlm\r\nmn\r\nno\r\nab\r\nbc\r\ncd\r\nde\r\nop\r\npq\r\nqr\r\nrs\r\nst\r\ntu\r\nuv\r\nvw\r\nwx\r\nxy\r\nyz\r\n", "output": "abcdefghijk... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path) as f:
n = int(f.readline().strip())
fragments = [line.strip() for line in f]
with open(output_path) as f:
correct_output = f.read().strip()
... | true |
793/A | 793 | A | Python 3 | TESTS | 22 | 124 | 8,806,400 | 159705366 | n,k = map(int,input().split(' '))
a = list(map(int,input().split(' ')))
x = min(a)
summ = 0
flag = 1
for i in range(0,len(a)):
if((a[i]-x)%k==1):
flag = 0
break
summ += (a[i]-x)//k
if(flag):
print(summ)
else:
print("-1") | 88 | 77 | 13,721,600 | 212480658 | n, k = map(int, input().split())
a = list(map(int, input().split()))
flag = False
if n == 1:
print(0)
else:
ans = 0
b = min(a)
for i in range(n):
if (a[i] - b) % k == 0:
ans += (a[i] - b) // k
else:
flag = True
break
if flag:
print(-1)
... | Tinkoff Challenge - Elimination Round | CF | 2,017 | 1 | 256 | Oleg and shares | Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg... | The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) — the number of share prices, and the amount of rubles some price decreases each second.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the initial prices. | Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible. | null | Consider the first example.
Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds.
There... | [{"input": "3 3\n12 9 15", "output": "3"}, {"input": "2 2\n10 9", "output": "-1"}, {"input": "4 1\n1 1000000000 1000000000 1000000000", "output": "2999999997"}] | 900 | ["implementation", "math"] | 88 | [{"input": "3 3\r\n12 9 15\r\n", "output": "3"}, {"input": "2 2\r\n10 9\r\n", "output": "-1"}, {"input": "4 1\r\n1 1000000000 1000000000 1000000000\r\n", "output": "2999999997"}, {"input": "1 11\r\n123\r\n", "output": "0"}, {"input": "20 6\r\n38 86 86 50 98 62 32 2 14 62 98 50 2 50 32 38 62 62 8 14\r\n", "output": "151... | false | stdio | null | true |
757/A | 757 | A | PyPy 3 | TESTS | 22 | 77 | 1,536,000 | 147966697 | dict = {"B":0,"u":0,"l":0,"b":0,"a":0,"s":0,"r":0}
str = input()
for i in str:
if i in dict:
dict[i]+=1
dict["u"]=dict["u"]//2
print(min(dict.values())) | 107 | 62 | 204,800 | 147207091 | y = input(); dct = {}
for i in ['B', 'u', 'l', 'b', 'a', 's', 'r']:
dct[i] = y.count(i)
x = min(dct['B'], dct['l'], dct['b'], dct['s'], dct['r'])
z = min(dct['u'] // 2, dct['a'] // 2)
print(min(x,z)) | Codecraft-17 and Codeforces Round 391 (Div. 1 + Div. 2, combined) | CF | 2,017 | 1 | 256 | Gotta Catch Em' All! | Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbas... | Input contains a single line containing a string s (1 ≤ |s| ≤ 105) — the text on the front page of the newspaper without spaces and punctuation marks. |s| is the length of the string s.
The string s contains lowercase and uppercase English letters, i.e. $$s_i \in \{a,b,\ldots,z,A,B,\ldots,Z\}$$. | Output a single integer, the answer to the problem. | null | In the first case, you could pick: Bulbbasaur.
In the second case, there is no way to pick even a single Bulbasaur.
In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur". | [{"input": "Bulbbasaur", "output": "1"}, {"input": "F", "output": "0"}, {"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb", "output": "2"}] | 1,000 | ["implementation"] | 107 | [{"input": "Bulbbasaur\r\n", "output": "1\r\n"}, {"input": "F\r\n", "output": "0\r\n"}, {"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb\r\n", "output": "2\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr\r\n", "output": "5\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuu... | false | stdio | null | true |
638/B | 638 | B | Python 3 | PRETESTS | 9 | 77 | 5,836,800 | 16842419 | import string
def strIntersection(s1, s2):
out = ""
for c in s1:
if c in s2 and not c in out:
out += c
return out
def srtUnion(s1, s2, u_str):
if u_str in s1[:len(u_str)]:
return s2 + s1[len(u_str):]
else:
return s1 + s2[len(u_str):]
n = int(input())
data = l... | 67 | 62 | 0 | 19563283 | n=int(input())
d={}
p={}
ans=''
for x in [input() for i in range(n)]:
for i in range(len(x)-1): d[x[i]]=x[i+1]
for i in range(1,len(x)): p[x[i]]=1
d.setdefault(x[-1],'')
for x in range(9,123):
x=chr(x)
if p.get(x,0)>0 or d.get(x,'Q')=='Q': continue
while x!='':
ans+=x
t=d[x]
... | VK Cup 2016 - Qualification Round 2 | CF | 2,016 | 1 | 256 | Making Genome in Berland | Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct En... | The first line of the input contains a positive integer n (1 ≤ n ≤ 100) — the number of genome fragments.
Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are d... | In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them. | null | null | [{"input": "3\nbcd\nab\ncdef", "output": "abcdef"}, {"input": "4\nx\ny\nz\nw", "output": "xyzw"}] | 1,500 | ["*special", "dfs and similar", "strings"] | 67 | [{"input": "3\r\nbcd\r\nab\r\ncdef\r\n", "output": "abcdef\r\n"}, {"input": "4\r\nx\r\ny\r\nz\r\nw\r\n", "output": "xyzw\r\n"}, {"input": "25\r\nef\r\nfg\r\ngh\r\nhi\r\nij\r\njk\r\nkl\r\nlm\r\nmn\r\nno\r\nab\r\nbc\r\ncd\r\nde\r\nop\r\npq\r\nqr\r\nrs\r\nst\r\ntu\r\nuv\r\nvw\r\nwx\r\nxy\r\nyz\r\n", "output": "abcdefghijk... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path) as f:
n = int(f.readline().strip())
fragments = [line.strip() for line in f]
with open(output_path) as f:
correct_output = f.read().strip()
... | true |
979/B | 979 | B | Python 3 | TESTS | 85 | 561 | 9,216,000 | 38250868 | a= input()
n=int(a)
list1 = {}
list3 = ['Kuro', 'Shiro' , 'Katie']
for i in range(3):
list1[i] = input()
l = len(list1[0])
#print(l)
for i in range(3):
list1[i]=sorted(list1[i])
mx = 0
p=0
list2 = {}
for i in range(3):
for j in range(len(list1[i])):
if list1[i][j] != list1[i][j-1]:
... | 184 | 124 | 716,800 | 40246832 | x = int(input())
u = input()
v = input()
w = input()
def wtf(s):
ans = 0
for i in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ':
ans = max(ans, s.count(i))
need = len(s)-ans
if need == 0 and x == 1:
return len(s)-1
if need > x:
return ans + x
else:
return len(s)
return ans
a = [wtf(u), wtf(v)... | Codeforces Round 482 (Div. 2) | CF | 2,018 | 1 | 256 | Treasure Hunt | After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.
The three friends are very smart so they passed all the challenges very quickly and finally reached the destination... | The first line contains an integer $$$n$$$ ($$$0 \leq n \leq 10^{9}$$$) — the number of turns.
Next 3 lines contain 3 ribbons of Kuro, Shiro and Katie one per line, respectively. Each ribbon is a string which contains no more than $$$10^{5}$$$ uppercase and lowercase Latin letters and is not empty. It is guaranteed th... | Print the name of the winner ("Kuro", "Shiro" or "Katie"). If there are at least two cats that share the maximum beauty, print "Draw". | null | In the first example, after $$$3$$$ turns, Kuro can change his ribbon into ooooo, which has the beauty of $$$5$$$, while reaching such beauty for Shiro and Katie is impossible (both Shiro and Katie can reach the beauty of at most $$$4$$$, for example by changing Shiro's ribbon into SSiSS and changing Katie's ribbon int... | [{"input": "3\nKuroo\nShiro\nKatie", "output": "Kuro"}, {"input": "7\ntreasurehunt\nthreefriends\nhiCodeforces", "output": "Shiro"}, {"input": "1\nabcabc\ncbabac\nababca", "output": "Katie"}, {"input": "15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE", "output": "Draw"}] | 1,800 | ["greedy"] | 184 | [{"input": "3\r\nKuroo\r\nShiro\r\nKatie\r\n", "output": "Kuro\r\n"}, {"input": "7\r\ntreasurehunt\r\nthreefriends\r\nhiCodeforces\r\n", "output": "Shiro\r\n"}, {"input": "1\r\nabcabc\r\ncbabac\r\nababca\r\n", "output": "Katie\r\n"}, {"input": "15\r\nfoPaErcvJ\r\nmZaxowpbt\r\nmkuOlaHRE\r\n", "output": "Draw\r\n"}, {"in... | false | stdio | null | true |
1010/C | 1010 | C | Python 3 | TESTS | 27 | 248 | 8,704,000 | 68300655 | import math
def binpow(a, n):
if n == 0:
return 1
if n % 2 == 1:
return binpow(a, n - 1) * a
else:
b = binpow(a, n //2)
return b * b
n, k = map(int, input().split())
a = list(map(int, input().split()))
gcd = a[0]
for i in range(1, n):
gcd = math.gcd(gcd, a[i])
s = set()
d = gcd % k
isk = gcd
while d not in ... | 107 | 202 | 34,201,600 | 128931406 | def gcd(a, b):
if a > b:
a, b = b, a
if b % a==0:
return a
return gcd(b % a, a)
def process(A, k):
g = k
for x in A:
g = gcd(x, g)
return [i*g for i in range(k//g)]
n, k = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
answer = process(A, k)
pri... | Codeforces Round 499 (Div. 1) | CF | 2,018 | 1 | 256 | Border | Astronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every tourist who visited the planet. Natasha is the inhabitant of Earth, therefore she had to pay the tax to enter the territory of Mars.
There are... | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100\,000$$$, $$$2 \le k \le 100\,000$$$) — the number of denominations of banknotes and the base of the number system on Mars.
The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — denominations of ban... | On the first line output the number of values $$$d$$$ for which Natasha can make the Martians happy.
In the second line, output all these values in increasing order.
Print all numbers in decimal notation. | null | Consider the first test case. It uses the octal number system.
If you take one banknote with the value of $$$12$$$, you will get $$$14_8$$$ in octal system. The last digit is $$$4_8$$$.
If you take one banknote with the value of $$$12$$$ and one banknote with the value of $$$20$$$, the total value will be $$$32$$$. I... | [{"input": "2 8\n12 20", "output": "2\n0 4"}, {"input": "3 10\n10 20 30", "output": "1\n0"}] | 1,800 | ["number theory"] | 107 | [{"input": "2 8\r\n12 20\r\n", "output": "2\r\n0 4 "}, {"input": "3 10\r\n10 20 30\r\n", "output": "1\r\n0 "}, {"input": "5 10\r\n20 16 4 16 2\r\n", "output": "5\r\n0 2 4 6 8 "}, {"input": "10 5\r\n4 6 8 6 4 10 2 10 8 6\r\n", "output": "5\r\n0 1 2 3 4 "}, {"input": "20 25\r\n15 10 5 20 10 5 15 5 15 10 15 5 5 5 5 10 15 ... | false | stdio | null | true |
1010/C | 1010 | C | Python 3 | TESTS | 27 | 218 | 8,806,400 | 68300754 | import math
def binpow(a, n):
if n == 0:
return 1
if n % 2 == 1:
return binpow(a, n - 1) * a
else:
b = binpow(a, n //2)
return b * b
n, k = map(int, input().split())
a = list(map(int, input().split()))
gcd = a[0]
for i in range(1, n):
gcd = math.gcd(gcd, a[i])
s = set()
d = gcd % k
isk = gcd
while d not in ... | 107 | 218 | 8,089,600 | 40793343 | def gcd(a,b):
if b == 0:
return a
if b > a:
return gcd(b,a)
return gcd(b,a%b)
n,k = list(map(int,input().split()))
l = list(map(int,input().split()))
out = k
for i in l:
out = gcd(i,out)
print(k//out)
print(' '.join(list(map(str,range(0,k,out))))) | Codeforces Round 499 (Div. 1) | CF | 2,018 | 1 | 256 | Border | Astronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every tourist who visited the planet. Natasha is the inhabitant of Earth, therefore she had to pay the tax to enter the territory of Mars.
There are... | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100\,000$$$, $$$2 \le k \le 100\,000$$$) — the number of denominations of banknotes and the base of the number system on Mars.
The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — denominations of ban... | On the first line output the number of values $$$d$$$ for which Natasha can make the Martians happy.
In the second line, output all these values in increasing order.
Print all numbers in decimal notation. | null | Consider the first test case. It uses the octal number system.
If you take one banknote with the value of $$$12$$$, you will get $$$14_8$$$ in octal system. The last digit is $$$4_8$$$.
If you take one banknote with the value of $$$12$$$ and one banknote with the value of $$$20$$$, the total value will be $$$32$$$. I... | [{"input": "2 8\n12 20", "output": "2\n0 4"}, {"input": "3 10\n10 20 30", "output": "1\n0"}] | 1,800 | ["number theory"] | 107 | [{"input": "2 8\r\n12 20\r\n", "output": "2\r\n0 4 "}, {"input": "3 10\r\n10 20 30\r\n", "output": "1\r\n0 "}, {"input": "5 10\r\n20 16 4 16 2\r\n", "output": "5\r\n0 2 4 6 8 "}, {"input": "10 5\r\n4 6 8 6 4 10 2 10 8 6\r\n", "output": "5\r\n0 1 2 3 4 "}, {"input": "20 25\r\n15 10 5 20 10 5 15 5 15 10 15 5 5 5 5 10 15 ... | false | stdio | null | true |
419/A | 420 | A | Python 3 | TESTS | 35 | 171 | 614,400 | 76442034 | word = input()
res = 'YES'
mwords = 'AHIMOTUVWXY'
def isSymmetric(s):
if(s == 'A' or s == 'H' or s == 'I' or s == 'M' or s == 'O' or s == 'T' or s == 'U' or s == 'V' or s == 'W' or s == 'W' or s == 'X' or s == 'Y'):
return True
return False
if(len(word) > 1):
for n in range(len(word)):
if... | 80 | 46 | 0 | 180009839 | name = input()
mirror_letters = "AHIMOTUVWXY"
if all(char in mirror_letters for char in name) and name == name[::-1]:
print("YES")
else:
print("NO") | Coder-Strike 2014 - Finals | CF | 2,014 | 1 | 256 | Start Up | Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out... | The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font: | Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes). | null | null | [{"input": "AHA", "output": "YES"}, {"input": "Z", "output": "NO"}, {"input": "XO", "output": "NO"}] | 1,000 | [] | 80 | [{"input": "AHA\r\n", "output": "YES\r\n"}, {"input": "Z\r\n", "output": "NO\r\n"}, {"input": "XO\r\n", "output": "NO\r\n"}, {"input": "AAA\r\n", "output": "YES\r\n"}, {"input": "AHHA\r\n", "output": "YES\r\n"}, {"input": "BAB\r\n", "output": "NO\r\n"}, {"input": "OMMMAAMMMO\r\n", "output": "YES\r\n"}, {"input": "YYHUI... | false | stdio | null | true |
745/B | 745 | B | Python 3 | TESTS | 8 | 732 | 6,758,400 | 23064268 | def formsL(i,j,p):
r1 = p[i][j] == p[i][j + 1] == p[i + 1][j + 1] == "X" and p[i + 1][j] == "."
r2 = p[i][j] == p[i][j + 1] == p[i - 1][j + 1] == "X" and p[i - 1][j] == "."
#print(p[i][j], p[i][j + 1], p[i - 1][j + 1], p[i - 1][j])
r3 = p[i][j] == p[i][j + 1] == p[i + 1][j] == "X" and p[i + 1][j + 1] ==... | 77 | 62 | 409,600 | 27388033 | '''input
5 5
.....
..X..
.....
.....
.....
'''
s1, e1, s2, e2 = 500, -1, 500, -1
n, m = map(int, input().split())
s = set(input() for _ in range(n))
s.discard("." * m)
print("YES" if len(s) == 1 else "NO") | Codeforces Round 385 (Div. 2) | CF | 2,016 | 2 | 256 | Hongcow Solves A Puzzle | Hongcow likes solving puzzles.
One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an n by m grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that th... | The first line of input will contain two integers n and m (1 ≤ n, m ≤ 500), the dimensions of the puzzle piece.
The next n lines will describe the jigsaw piece. Each line will have length m and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space.
It is gua... | Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise. | null | For the first sample, one example of a rectangle we can form is as follows
For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.
In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle: | [{"input": "2 3\nXXX\nXXX", "output": "YES"}, {"input": "2 2\n.X\nXX", "output": "NO"}, {"input": "5 5\n.....\n..X..\n.....\n.....\n.....", "output": "YES"}] | 1,400 | ["implementation"] | 77 | [{"input": "2 3\r\nXXX\r\nXXX\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n.X\r\nXX\r\n", "output": "NO\r\n"}, {"input": "5 5\r\n.....\r\n..X..\r\n.....\r\n.....\r\n.....\r\n", "output": "YES\r\n"}, {"input": "1 500\r\n.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX... | false | stdio | null | true |
540/B | 540 | B | PyPy 3 | TESTS | 13 | 202 | 2,764,800 | 93565673 | n,k,p,x,y=map(int,input().split())
s=0
cnt=0
ans=[]
for arr in map(int,input().split()):
s+=arr
if arr>=y:
cnt+=1
while cnt<(n+1)/2:
ans.append(y)
cnt+=1
while len(ans)+k<n:
ans.append(1)
if s+sum(ans)<=x:
for i in range(len(ans)):
print(ans[i],"",end='')
print("")
else:
... | 78 | 62 | 4,710,400 | 10943462 | def read_data():
n, k, p, x, y = map(int, input().split())
As = list(map(int, input().split()))
return n, k, p, x, y, As
def solve(n, k, p, x, y, As):
'''median (As + Bs) >= y
sum(As + Bs) <= x
1 <= Bi <= p
'''
middle = n // 2
As.sort(reverse=True)
sumA = sum(As)
minSum = su... | Codeforces Round 301 (Div. 2) | CF | 2,015 | 2 | 256 | School Marks | Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all tests... | The first line contains 5 space-separated integers: n, k, p, x and y (1 ≤ n ≤ 999, n is odd, 0 ≤ k < n, 1 ≤ p ≤ 1000, n ≤ x ≤ n·p, 1 ≤ y ≤ p). Here n is the number of tests that Vova is planned to write, k is the number of tests he has already written, p is the maximum possible mark for a test, x is the maximum total n... | If Vova cannot achieve the desired result, print "-1".
Otherwise, print n - k space-separated integers — the marks that Vova should get for the remaining tests. If there are multiple possible solutions, print any of them. | null | The median of sequence a1, ..., an where n is odd (in this problem n is always odd) is the element staying on (n + 1) / 2 position in the sorted list of ai.
In the first sample the sum of marks equals 3 + 5 + 4 + 4 + 1 = 17, what doesn't exceed 18, that means that Vova won't be disturbed by his classmates. And the med... | [{"input": "5 3 5 18 4\n3 5 4", "output": "4 1"}, {"input": "5 3 5 16 4\n5 5 5", "output": "-1"}] | 1,700 | ["greedy", "implementation"] | 78 | [{"input": "5 3 5 18 4\r\n3 5 4\r\n", "output": "4 1\r\n"}, {"input": "5 3 5 16 4\r\n5 5 5\r\n", "output": "-1\r\n"}, {"input": "5 3 5 17 4\r\n5 5 5\r\n", "output": "1 1\r\n"}, {"input": "5 3 5 12 1\r\n5 5 1\r\n", "output": "-1\r\n"}, {"input": "5 3 5 13 1\r\n5 5 1\r\n", "output": "1 1\r\n"}, {"input": "7 4 5 26 5\r\n5... | false | stdio | import sys
def main(input_path, output_path, submission_path):
with open(input_path, 'r') as f_in:
n, k, p, x, y = map(int, f_in.readline().split())
existing = list(map(int, f_in.readline().split()))
with open(submission_path, 'r') as f_sub:
submission_line = f_sub.read().strip()
... | true |
45/I | 45 | I | PyPy 3-64 | TESTS | 12 | 122 | 0 | 181802551 | n=int(input())
A=list(map(int,input().split()))
P=[]
M=[]
Z=0
for a in A:
if a==0:
Z+=1
elif a>0:
P.append(a)
else:
M.append(-a)
if n==1:
print(A[0])
exit()
if len(M)==1 and len(P)==0 and Z>0:
print(0)
exit()
M.sort(reverse=True)
if len(M)%2==1:
M.pop()
ANS=... | 65 | 92 | 0 | 144584616 | for _ in range(1):
n = int(input())
a = list(map(int, input().split()))
pos = []
neg = []
zero = 0
for i in range(n):
if a[i] > 0:
pos.append(a[i])
elif a[i] == 0:
zero += 1
else:
neg.append(a[i])
if len(neg) % 2:
neg.remo... | School Team Contest 3 (Winter Computer School 2010/11) | ICPC | 2,010 | 2 | 256 | TCMCF+++ | Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest n problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of poin... | The first line contains an integer n (1 ≤ n ≤ 100) — the number of the suggested problems. The next line contains n space-separated integers ci ( - 100 ≤ ci ≤ 100) — the cost of the i-th task. The tasks' costs may coinсide. | Print space-separated the costs of the problems that needed to be solved to get the maximal possible number of points. Do not forget, please, that it was necessary to solve at least one problem. If there are several solutions to that problem, print any of them. | null | null | [{"input": "5\n1 2 -3 3 3", "output": "3 1 2 3"}, {"input": "13\n100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "100 100 100 100 100 100 100 100 100 100 100 100 100"}, {"input": "4\n-2 -2 -2 -2", "output": "-2 -2 -2 -2"}] | 1,400 | ["greedy"] | 65 | [{"input": "5\r\n1 2 -3 3 3\r\n", "output": "3 1 2 3 \r\n"}, {"input": "13\r\n100 100 100 100 100 100 100 100 100 100 100 100 100\r\n", "output": "100 100 100 100 100 100 100 100 100 100 100 100 100 \r\n"}, {"input": "4\r\n-2 -2 -2 -2\r\n", "output": "-2 -2 -2 -2 \r\n"}, {"input": "1\r\n1\r\n", "output": "1 \r\n"}, {"i... | false | stdio | import sys
from collections import Counter
def compute_max_product(ci):
if all(x == 0 for x in ci):
return 0
positives = [x for x in ci if x > 0]
negatives = [x for x in ci if x < 0]
zeros = [x for x in ci if x == 0]
non_zero = positives + negatives
if not non_zero:
return 0
... | true |
45/I | 45 | I | PyPy 3-64 | TESTS | 12 | 154 | 0 | 181150149 | n=int(input())
arr=list(map(int,input().split()))
if n==1:print(arr[0]); quit()
neg,pos,z=list(),list(),0
for i in arr:
if i<0:neg.append(i)
elif i>0:pos.append(i)
neg=sorted(neg)
if len(pos)==0 and len(neg)==1:print(0); quit()
if len(neg)%2==0:
if len(neg):print(*neg,end=' ')
else:
neg.pop()
if len... | 65 | 92 | 4,505,600 | 133614763 | n = int(input())
L = [int(l) for l in input().split()]
if (n == 1):
print(*L)
else:
L.sort()
L.reverse()
res = []
for i in L:
if i > 0:
res.append(i)
else:
break
L.reverse()
dp = []
for i in L:
if i < 0:
dp.append(i)
... | School Team Contest 3 (Winter Computer School 2010/11) | ICPC | 2,010 | 2 | 256 | TCMCF+++ | Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest n problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of poin... | The first line contains an integer n (1 ≤ n ≤ 100) — the number of the suggested problems. The next line contains n space-separated integers ci ( - 100 ≤ ci ≤ 100) — the cost of the i-th task. The tasks' costs may coinсide. | Print space-separated the costs of the problems that needed to be solved to get the maximal possible number of points. Do not forget, please, that it was necessary to solve at least one problem. If there are several solutions to that problem, print any of them. | null | null | [{"input": "5\n1 2 -3 3 3", "output": "3 1 2 3"}, {"input": "13\n100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "100 100 100 100 100 100 100 100 100 100 100 100 100"}, {"input": "4\n-2 -2 -2 -2", "output": "-2 -2 -2 -2"}] | 1,400 | ["greedy"] | 65 | [{"input": "5\r\n1 2 -3 3 3\r\n", "output": "3 1 2 3 \r\n"}, {"input": "13\r\n100 100 100 100 100 100 100 100 100 100 100 100 100\r\n", "output": "100 100 100 100 100 100 100 100 100 100 100 100 100 \r\n"}, {"input": "4\r\n-2 -2 -2 -2\r\n", "output": "-2 -2 -2 -2 \r\n"}, {"input": "1\r\n1\r\n", "output": "1 \r\n"}, {"i... | false | stdio | import sys
from collections import Counter
def compute_max_product(ci):
if all(x == 0 for x in ci):
return 0
positives = [x for x in ci if x > 0]
negatives = [x for x in ci if x < 0]
zeros = [x for x in ci if x == 0]
non_zero = positives + negatives
if not non_zero:
return 0
... | true |
45/I | 45 | I | PyPy 3-64 | TESTS | 12 | 92 | 0 | 208560419 | n = int(input())
l = list(map(int, input().split()))
if n == 1:
print(l[0])
exit()
z = []
neg = []
ans = []
for i in l:
if i > 0:
ans.append(i)
elif i == 0:
z.append(i)
else:
neg.append(i)
neg.sort()
# print(len(neg))
# print(ans)
if len(neg) == 1 and len(z) > 0 and len(ans) ... | 65 | 124 | 0 | 15502293 | n, a = int(input()), list(map(int, input().split()))
an, ap = sorted(x for x in a if x < 0), [x for x in a if x > 0]
if n > 1 and len(an) % 2:
an.pop()
print(' '.join(map(str, ap + an)) if ap or an else 0) | School Team Contest 3 (Winter Computer School 2010/11) | ICPC | 2,010 | 2 | 256 | TCMCF+++ | Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest n problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of poin... | The first line contains an integer n (1 ≤ n ≤ 100) — the number of the suggested problems. The next line contains n space-separated integers ci ( - 100 ≤ ci ≤ 100) — the cost of the i-th task. The tasks' costs may coinсide. | Print space-separated the costs of the problems that needed to be solved to get the maximal possible number of points. Do not forget, please, that it was necessary to solve at least one problem. If there are several solutions to that problem, print any of them. | null | null | [{"input": "5\n1 2 -3 3 3", "output": "3 1 2 3"}, {"input": "13\n100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "100 100 100 100 100 100 100 100 100 100 100 100 100"}, {"input": "4\n-2 -2 -2 -2", "output": "-2 -2 -2 -2"}] | 1,400 | ["greedy"] | 65 | [{"input": "5\r\n1 2 -3 3 3\r\n", "output": "3 1 2 3 \r\n"}, {"input": "13\r\n100 100 100 100 100 100 100 100 100 100 100 100 100\r\n", "output": "100 100 100 100 100 100 100 100 100 100 100 100 100 \r\n"}, {"input": "4\r\n-2 -2 -2 -2\r\n", "output": "-2 -2 -2 -2 \r\n"}, {"input": "1\r\n1\r\n", "output": "1 \r\n"}, {"i... | false | stdio | import sys
from collections import Counter
def compute_max_product(ci):
if all(x == 0 for x in ci):
return 0
positives = [x for x in ci if x > 0]
negatives = [x for x in ci if x < 0]
zeros = [x for x in ci if x == 0]
non_zero = positives + negatives
if not non_zero:
return 0
... | true |
756/A | 756 | A | PyPy 3-64 | TESTS | 9 | 62 | 0 | 197324142 | import sys
def dfs(pos):
"""找排列中形成的环,每形成一个环就需要两次改变与其它环构成同一个环"""
global ans
if pos in vis:
return
st = [pos]
while st:
t = st.pop()
if t in vis:
ans += 2
continue
st.append(p[t - 1])
vis.add(t)
if __name__ == '__main__':
n = eval... | 87 | 264 | 46,080,000 | 161339328 | from bisect import *
from collections import *
import sys
import io, os
import math
import random
from heapq import *
gcd = math.gcd
sqrt = math.sqrt
maxint=10**21
def ceil(a, b):
a = -a
k = a // b
k = -k
return k
# arr=list(map(int, input().split()))
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).... | 8VC Venture Cup 2017 - Final Round | CF | 2,017 | 2 | 256 | Pavel and barbecue | Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: in the one it was directed originally and in the reversed direction.
Pavel has a plan: a permutation p and a sequence b1, b2, ... | The first line contain the integer n (1 ≤ n ≤ 2·105) — the number of skewers.
The second line contains a sequence of integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the permutation, according to which Pavel wants to move the skewers.
The third line contains a sequence b1, b2, ..., bn consisting of zeros and ones, according t... | Print single integer — the minimum total number of elements in the given permutation p and the given sequence b he needs to change so that every skewer will visit each of 2n placements. | null | In the first example Pavel can change the permutation to 4, 3, 1, 2.
In the second example Pavel can change any element of b to 1. | [{"input": "4\n4 3 2 1\n0 1 1 1", "output": "2"}, {"input": "3\n2 3 1\n0 0 0", "output": "1"}] | 1,700 | ["constructive algorithms", "dfs and similar"] | 87 | [{"input": "4\r\n4 3 2 1\r\n0 1 1 1\r\n", "output": "2\r\n"}, {"input": "3\r\n2 3 1\r\n0 0 0\r\n", "output": "1\r\n"}, {"input": "1\r\n1\r\n0\r\n", "output": "1\r\n"}, {"input": "2\r\n1 2\r\n0 0\r\n", "output": "3\r\n"}, {"input": "2\r\n2 1\r\n0 0\r\n", "output": "1\r\n"}, {"input": "2\r\n1 2\r\n0 1\r\n", "output": "2\... | false | stdio | null | true |
745/B | 745 | B | Python 3 | TESTS | 8 | 46 | 1,024,000 | 27387532 | '''input
5 5
.....
..X..
.....
.....
.....
'''
s1, e1, s2, e2 = 500, -1, 500, -1
n, m = map(int, input().split())
l = []
for a in range(n):
i = input()
if "X" in i:
s1 = min(s1, i.index("X"))
e1 = max(e1, m - 1 - i[::-1].index("X"))
s2 = min(s2, a)
e2 = max(e2, a)
l.append(i)
if "".join(l).count("X") == 1:
... | 77 | 62 | 4,608,000 | 23056483 | n, m = map(int, input().split())
empthy = '.' * m
last = ''
mistake = False
for i in range(n):
s = input()
if s != empthy:
if last == '':
last = s
else:
if last != s:
mistake = True
break
if mistake:
print('NO')
else:
print('YES') | Codeforces Round 385 (Div. 2) | CF | 2,016 | 2 | 256 | Hongcow Solves A Puzzle | Hongcow likes solving puzzles.
One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an n by m grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that th... | The first line of input will contain two integers n and m (1 ≤ n, m ≤ 500), the dimensions of the puzzle piece.
The next n lines will describe the jigsaw piece. Each line will have length m and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space.
It is gua... | Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise. | null | For the first sample, one example of a rectangle we can form is as follows
For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.
In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle: | [{"input": "2 3\nXXX\nXXX", "output": "YES"}, {"input": "2 2\n.X\nXX", "output": "NO"}, {"input": "5 5\n.....\n..X..\n.....\n.....\n.....", "output": "YES"}] | 1,400 | ["implementation"] | 77 | [{"input": "2 3\r\nXXX\r\nXXX\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n.X\r\nXX\r\n", "output": "NO\r\n"}, {"input": "5 5\r\n.....\r\n..X..\r\n.....\r\n.....\r\n.....\r\n", "output": "YES\r\n"}, {"input": "1 500\r\n.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX... | false | stdio | null | true |
756/A | 756 | A | PyPy 3-64 | TESTS | 9 | 46 | 0 | 180021669 | import sys
input = sys.stdin.buffer.readline
def find_root(root_dict, x):
L = []
while x != root_dict[x]:
L.append(x)
x = root_dict[x]
for y in L:
root_dict[y] = x
return x
def process(A, B):
n = len(A)
answer = 0
root_dict = [i for i in range(n+1)]
if sum(B) %... | 87 | 296 | 18,534,400 | 24043689 | if __name__ == '__main__':
n, = map(int, input().split())
p = list(map(lambda x: int(x)-1, input().split()))
swaps = sum(map(int, input().split()))
res = 1 - (swaps % 2)
visited = [False for _ in range(n)]
cycles = 0
for i in range(n):
if visited[i]:
continue
visited[i] = True
j = p[i]
while j != i:
... | 8VC Venture Cup 2017 - Final Round | CF | 2,017 | 2 | 256 | Pavel and barbecue | Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: in the one it was directed originally and in the reversed direction.
Pavel has a plan: a permutation p and a sequence b1, b2, ... | The first line contain the integer n (1 ≤ n ≤ 2·105) — the number of skewers.
The second line contains a sequence of integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the permutation, according to which Pavel wants to move the skewers.
The third line contains a sequence b1, b2, ..., bn consisting of zeros and ones, according t... | Print single integer — the minimum total number of elements in the given permutation p and the given sequence b he needs to change so that every skewer will visit each of 2n placements. | null | In the first example Pavel can change the permutation to 4, 3, 1, 2.
In the second example Pavel can change any element of b to 1. | [{"input": "4\n4 3 2 1\n0 1 1 1", "output": "2"}, {"input": "3\n2 3 1\n0 0 0", "output": "1"}] | 1,700 | ["constructive algorithms", "dfs and similar"] | 87 | [{"input": "4\r\n4 3 2 1\r\n0 1 1 1\r\n", "output": "2\r\n"}, {"input": "3\r\n2 3 1\r\n0 0 0\r\n", "output": "1\r\n"}, {"input": "1\r\n1\r\n0\r\n", "output": "1\r\n"}, {"input": "2\r\n1 2\r\n0 0\r\n", "output": "3\r\n"}, {"input": "2\r\n2 1\r\n0 0\r\n", "output": "1\r\n"}, {"input": "2\r\n1 2\r\n0 1\r\n", "output": "2\... | false | stdio | null | true |
638/B | 638 | B | Python 3 | PRETESTS | 9 | 62 | 4,812,800 | 16843756 | def intersect(str1, str2):
length = 0
min_len = min(len(str1), len(str2))
#print('inter ', str1[len(str1) - length:], str2[:length])
for i in range(min_len):
if (str1[len(str1) - i:] == str2[:i]):
#print('int', i, str1[len(str1) - i:], str2[:i])
length = i
return length
def dfs(v):
global g
global used... | 67 | 62 | 0 | 212957585 | def solve():
n = int(input())
gens = []
for i in range(n):
s = input()
gens.append(s)
nxt = [None] * 26
inp = [0] * 26
found = [False] * 26
for s in gens:
for ch in s:
found[ord(ch) - ord('a')] = True
for ch1, ch2 in zip(s, s[1:]):
u = ord(ch1) - ord('a')
v = ord(ch2) - o... | VK Cup 2016 - Qualification Round 2 | CF | 2,016 | 1 | 256 | Making Genome in Berland | Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct En... | The first line of the input contains a positive integer n (1 ≤ n ≤ 100) — the number of genome fragments.
Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are d... | In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them. | null | null | [{"input": "3\nbcd\nab\ncdef", "output": "abcdef"}, {"input": "4\nx\ny\nz\nw", "output": "xyzw"}] | 1,500 | ["*special", "dfs and similar", "strings"] | 67 | [{"input": "3\r\nbcd\r\nab\r\ncdef\r\n", "output": "abcdef\r\n"}, {"input": "4\r\nx\r\ny\r\nz\r\nw\r\n", "output": "xyzw\r\n"}, {"input": "25\r\nef\r\nfg\r\ngh\r\nhi\r\nij\r\njk\r\nkl\r\nlm\r\nmn\r\nno\r\nab\r\nbc\r\ncd\r\nde\r\nop\r\npq\r\nqr\r\nrs\r\nst\r\ntu\r\nuv\r\nvw\r\nwx\r\nxy\r\nyz\r\n", "output": "abcdefghijk... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path) as f:
n = int(f.readline().strip())
fragments = [line.strip() for line in f]
with open(output_path) as f:
correct_output = f.read().strip()
... | true |
1010/C | 1010 | C | PyPy 3-64 | TESTS | 3 | 46 | 0 | 176886549 | import math
n, k = map(int, input().split())
g = 0
a = list(map(int, input().split()))
for i in range(n):
g = math.gcd(a[i], g)
ans = set()
s = 0
for i in range(k):
ans.add(s%k)
s+=g
print(len(ans));
print(*ans) | 107 | 233 | 8,704,000 | 41306093 | import math
from functools import reduce
a,b = map(int,input().split())
c = list(map(int,input().split()))
d = c[0]
for j in range(a):
d = math.gcd(d,c[j])
if d == 1:
break
e = math.gcd(d,b)
print(b//e)
#f = [i for i in range(b) if i%e == 0]
#g = " ".join(str(k) for k in range(b) if k%e == 0)
print(" ".... | Codeforces Round 499 (Div. 1) | CF | 2,018 | 1 | 256 | Border | Astronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every tourist who visited the planet. Natasha is the inhabitant of Earth, therefore she had to pay the tax to enter the territory of Mars.
There are... | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100\,000$$$, $$$2 \le k \le 100\,000$$$) — the number of denominations of banknotes and the base of the number system on Mars.
The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — denominations of ban... | On the first line output the number of values $$$d$$$ for which Natasha can make the Martians happy.
In the second line, output all these values in increasing order.
Print all numbers in decimal notation. | null | Consider the first test case. It uses the octal number system.
If you take one banknote with the value of $$$12$$$, you will get $$$14_8$$$ in octal system. The last digit is $$$4_8$$$.
If you take one banknote with the value of $$$12$$$ and one banknote with the value of $$$20$$$, the total value will be $$$32$$$. I... | [{"input": "2 8\n12 20", "output": "2\n0 4"}, {"input": "3 10\n10 20 30", "output": "1\n0"}] | 1,800 | ["number theory"] | 107 | [{"input": "2 8\r\n12 20\r\n", "output": "2\r\n0 4 "}, {"input": "3 10\r\n10 20 30\r\n", "output": "1\r\n0 "}, {"input": "5 10\r\n20 16 4 16 2\r\n", "output": "5\r\n0 2 4 6 8 "}, {"input": "10 5\r\n4 6 8 6 4 10 2 10 8 6\r\n", "output": "5\r\n0 1 2 3 4 "}, {"input": "20 25\r\n15 10 5 20 10 5 15 5 15 10 15 5 5 5 5 10 15 ... | false | stdio | null | true |
419/A | 420 | A | Python 3 | TESTS | 35 | 77 | 921,600 | 111317481 | def tetap_identik(nama):
char_list = ["A","H","I","M","O","T","U","V","W","X","Y"]
matched_list = [characters in char_list for characters in nama]
if len(nama) > 1:
if all(matched_list):
if nama == nama[::-1]:
return "YES"
else:
return "NO"
... | 80 | 46 | 0 | 180019560 | """
https://codeforces.com/problemset/problem/420/A
"""
chaine = input()
def is_palindrome(c):
return c == c[::-1]
def bonnes_lettres(c):
lettres = "AHIMOTUVWXY"
for l in c:
if l not in lettres:
return False
return True
if bonnes_lettres(chaine) and is_palindrome(chaine):
p... | Coder-Strike 2014 - Finals | CF | 2,014 | 1 | 256 | Start Up | Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out... | The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font: | Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes). | null | null | [{"input": "AHA", "output": "YES"}, {"input": "Z", "output": "NO"}, {"input": "XO", "output": "NO"}] | 1,000 | [] | 80 | [{"input": "AHA\r\n", "output": "YES\r\n"}, {"input": "Z\r\n", "output": "NO\r\n"}, {"input": "XO\r\n", "output": "NO\r\n"}, {"input": "AAA\r\n", "output": "YES\r\n"}, {"input": "AHHA\r\n", "output": "YES\r\n"}, {"input": "BAB\r\n", "output": "NO\r\n"}, {"input": "OMMMAAMMMO\r\n", "output": "YES\r\n"}, {"input": "YYHUI... | false | stdio | null | true |
217/A | 217 | A | PyPy 3 | TESTS | 49 | 312 | 2,048,000 | 96401157 | import sys
def get_ints(): return list(map(int, sys.stdin.readline().strip().split()))
testcases = int(input())
group = []
for testcase in range(testcases):
x, y = get_ints()
if len(group) == 0 :
group.append([(x,y)])
continue
flag = 0
#print(group)
for subgroup in group:
... | 76 | 92 | 0 | 149040685 | n=int(input())
snowdrifts=[]
for s in range(n):
snowdrifts.append(list(map(int,input().split()))+[None])
def dfs(current):
current[2]=True
for snowdrift in snowdrifts:
if not snowdrift[2] and (current[0]==snowdrift[0] or current[1]==snowdrift[1]):
dfs(snowdrift)
a=0
for s in snowdri... | Codeforces Round 134 (Div. 1) | CF | 2,012 | 2 | 256 | Ice Skating | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves... | The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсid... | Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. | null | null | [{"input": "2\n2 1\n1 2", "output": "1"}, {"input": "2\n2 1\n4 1", "output": "0"}] | 1,200 | ["brute force", "dfs and similar", "dsu", "graphs"] | 76 | [{"input": "2\r\n2 1\r\n1 2\r\n", "output": "1\r\n"}, {"input": "2\r\n2 1\r\n4 1\r\n", "output": "0\r\n"}, {"input": "24\r\n171 35\r\n261 20\r\n4 206\r\n501 446\r\n961 912\r\n581 748\r\n946 978\r\n463 514\r\n841 889\r\n341 466\r\n842 967\r\n54 102\r\n235 261\r\n925 889\r\n682 672\r\n623 636\r\n268 94\r\n635 710\r\n474 ... | false | stdio | null | true |
217/A | 217 | A | Python 3 | TESTS | 49 | 218 | 307,200 | 68071595 | def is_connected(first, second):
for heap in first:
for el in second:
if heap[0] == el[0] or heap[1] == el[1]:
return True
return False
groups = []
n = int(input())
for _ in range(n):
inp_snow = tuple(map(int, input().split(' ')))
fitted = False
for group in gro... | 76 | 92 | 0 | 151627290 | def findSet(ump,u):
r=u
while(ump[r]>=0):
r=ump[r]
while(u != r):
par=ump[u]
ump[u]=r
u=par
return r
def setUnion(ump,u,v):
u=findSet(ump,u)
v=findSet(ump,v)
if(u==v): return False
totalChilds=ump[u]+ump[v]
if(ump[u]<=ump[v]):
ump[v]=u
ump[u]=totalChilds
else :
ump[u]=v
ump[v]=totalChilds
ret... | Codeforces Round 134 (Div. 1) | CF | 2,012 | 2 | 256 | Ice Skating | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves... | The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсid... | Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. | null | null | [{"input": "2\n2 1\n1 2", "output": "1"}, {"input": "2\n2 1\n4 1", "output": "0"}] | 1,200 | ["brute force", "dfs and similar", "dsu", "graphs"] | 76 | [{"input": "2\r\n2 1\r\n1 2\r\n", "output": "1\r\n"}, {"input": "2\r\n2 1\r\n4 1\r\n", "output": "0\r\n"}, {"input": "24\r\n171 35\r\n261 20\r\n4 206\r\n501 446\r\n961 912\r\n581 748\r\n946 978\r\n463 514\r\n841 889\r\n341 466\r\n842 967\r\n54 102\r\n235 261\r\n925 889\r\n682 672\r\n623 636\r\n268 94\r\n635 710\r\n474 ... | false | stdio | null | true |
45/I | 45 | I | PyPy 3 | TESTS | 50 | 248 | 20,172,800 | 128202392 | n = int(input())
inputs = sorted(list(map(int, input().split())), reverse=True)
neg = 0
ans = []
for points in inputs:
if points < 0:
neg += 1
elif points == 0:
continue
else:
ans.append(points)
if neg % 2 != 0:
k = len(inputs) - 1
else:
k = len(inputs)
for i in range(len(... | 65 | 124 | 0 | 151024985 | n = int(input())
arr = list(map(int,input().split()))
count_neg = 0
neg_max = -100
for e in arr:
if e<0:
count_neg+=1
neg_max = max(neg_max,e)
ans = []
if count_neg&1:
arr.remove(neg_max)
for e in arr:
if e!=0:
ans.append(e)
if ans:
print(*ans)
else:
if arr:
... | School Team Contest 3 (Winter Computer School 2010/11) | ICPC | 2,010 | 2 | 256 | TCMCF+++ | Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest n problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of poin... | The first line contains an integer n (1 ≤ n ≤ 100) — the number of the suggested problems. The next line contains n space-separated integers ci ( - 100 ≤ ci ≤ 100) — the cost of the i-th task. The tasks' costs may coinсide. | Print space-separated the costs of the problems that needed to be solved to get the maximal possible number of points. Do not forget, please, that it was necessary to solve at least one problem. If there are several solutions to that problem, print any of them. | null | null | [{"input": "5\n1 2 -3 3 3", "output": "3 1 2 3"}, {"input": "13\n100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "100 100 100 100 100 100 100 100 100 100 100 100 100"}, {"input": "4\n-2 -2 -2 -2", "output": "-2 -2 -2 -2"}] | 1,400 | ["greedy"] | 65 | [{"input": "5\r\n1 2 -3 3 3\r\n", "output": "3 1 2 3 \r\n"}, {"input": "13\r\n100 100 100 100 100 100 100 100 100 100 100 100 100\r\n", "output": "100 100 100 100 100 100 100 100 100 100 100 100 100 \r\n"}, {"input": "4\r\n-2 -2 -2 -2\r\n", "output": "-2 -2 -2 -2 \r\n"}, {"input": "1\r\n1\r\n", "output": "1 \r\n"}, {"i... | false | stdio | import sys
from collections import Counter
def compute_max_product(ci):
if all(x == 0 for x in ci):
return 0
positives = [x for x in ci if x > 0]
negatives = [x for x in ci if x < 0]
zeros = [x for x in ci if x == 0]
non_zero = positives + negatives
if not non_zero:
return 0
... | true |
540/B | 540 | B | PyPy 3-64 | TESTS | 13 | 62 | 1,433,600 | 205012049 | import sys
input = sys.stdin.readline
n, k, p, x, y = map(int, input().split())
w = sorted(map(int, input().split()))
c = sum(1 for i in w if i >= y)
a = max(0, (n+1)//2 - c)
b = sum(w) + a*y + n-a-k
if b <= x:
print(' '.join(map(str, [y]*a + [1]*(n-a-k))))
else:
print(-1) | 78 | 62 | 4,710,400 | 10945091 | n,k,p,x,y = map(int, input().split())
written = sorted([int(x) for x in input().split()])
# very smart
if sum(written) + (n - k) > x:
print(-1)
exit()
answer = []
for i in range(n-k):
median_index = (len(written))//2
if len(written)%2 == 0:
try:
test = written[median_index-1]
... | Codeforces Round 301 (Div. 2) | CF | 2,015 | 2 | 256 | School Marks | Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all tests... | The first line contains 5 space-separated integers: n, k, p, x and y (1 ≤ n ≤ 999, n is odd, 0 ≤ k < n, 1 ≤ p ≤ 1000, n ≤ x ≤ n·p, 1 ≤ y ≤ p). Here n is the number of tests that Vova is planned to write, k is the number of tests he has already written, p is the maximum possible mark for a test, x is the maximum total n... | If Vova cannot achieve the desired result, print "-1".
Otherwise, print n - k space-separated integers — the marks that Vova should get for the remaining tests. If there are multiple possible solutions, print any of them. | null | The median of sequence a1, ..., an where n is odd (in this problem n is always odd) is the element staying on (n + 1) / 2 position in the sorted list of ai.
In the first sample the sum of marks equals 3 + 5 + 4 + 4 + 1 = 17, what doesn't exceed 18, that means that Vova won't be disturbed by his classmates. And the med... | [{"input": "5 3 5 18 4\n3 5 4", "output": "4 1"}, {"input": "5 3 5 16 4\n5 5 5", "output": "-1"}] | 1,700 | ["greedy", "implementation"] | 78 | [{"input": "5 3 5 18 4\r\n3 5 4\r\n", "output": "4 1\r\n"}, {"input": "5 3 5 16 4\r\n5 5 5\r\n", "output": "-1\r\n"}, {"input": "5 3 5 17 4\r\n5 5 5\r\n", "output": "1 1\r\n"}, {"input": "5 3 5 12 1\r\n5 5 1\r\n", "output": "-1\r\n"}, {"input": "5 3 5 13 1\r\n5 5 1\r\n", "output": "1 1\r\n"}, {"input": "7 4 5 26 5\r\n5... | false | stdio | import sys
def main(input_path, output_path, submission_path):
with open(input_path, 'r') as f_in:
n, k, p, x, y = map(int, f_in.readline().split())
existing = list(map(int, f_in.readline().split()))
with open(submission_path, 'r') as f_sub:
submission_line = f_sub.read().strip()
... | true |
745/B | 745 | B | Python 3 | TESTS | 15 | 62 | 0 | 23076944 | n,m = [int(ele) for ele in input().split(' ')]
started = 0
left_o,right_o = 0,0
bad = False
for i in range(n):
line = input()
l_line = line.lstrip('.')
r_line = line.rstrip('.')
s_line = line.strip('.')
if ('.' in s_line) or ((started is 2) and (s_line is not '')):
bad = True
#break
elif s_line is not '' and ... | 77 | 62 | 4,608,000 | 23056529 | n,m=map(int, input().split())
flag=False
s1=''
for i in range(n):
s=input()
if s.find('X')>-1:
if s1=='':
s1=s
flag=True
elif s1==s:
flag=True
else:
flag=False
break
if flag:
print('YES')
else:
print('NO') | Codeforces Round 385 (Div. 2) | CF | 2,016 | 2 | 256 | Hongcow Solves A Puzzle | Hongcow likes solving puzzles.
One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an n by m grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that th... | The first line of input will contain two integers n and m (1 ≤ n, m ≤ 500), the dimensions of the puzzle piece.
The next n lines will describe the jigsaw piece. Each line will have length m and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space.
It is gua... | Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise. | null | For the first sample, one example of a rectangle we can form is as follows
For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.
In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle: | [{"input": "2 3\nXXX\nXXX", "output": "YES"}, {"input": "2 2\n.X\nXX", "output": "NO"}, {"input": "5 5\n.....\n..X..\n.....\n.....\n.....", "output": "YES"}] | 1,400 | ["implementation"] | 77 | [{"input": "2 3\r\nXXX\r\nXXX\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n.X\r\nXX\r\n", "output": "NO\r\n"}, {"input": "5 5\r\n.....\r\n..X..\r\n.....\r\n.....\r\n.....\r\n", "output": "YES\r\n"}, {"input": "1 500\r\n.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX... | false | stdio | null | true |
745/B | 745 | B | Python 3 | TESTS | 8 | 62 | 4,915,200 | 24284189 | n, m = [int(i) for i in input().split()]
early_exit = False
first_flag = True
last_flag = False
for i in range(n):
s=input()
position = [j for j in range(m) if s[j]=='X']
if position:
if first_flag:
first_block = (position[0], position[-1] - position[0]+1)
first_flag = False
... | 77 | 62 | 4,608,000 | 23057898 | #!/usr/bin/env python3
def main():
n, m = map(int, input().split())
left = None
right = None
for _ in range(n):
line = input().strip()
cur_l = line.find("X")
if cur_l != -1:
if left is None:
left = cur_l
else:
if left !=... | Codeforces Round 385 (Div. 2) | CF | 2,016 | 2 | 256 | Hongcow Solves A Puzzle | Hongcow likes solving puzzles.
One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an n by m grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that th... | The first line of input will contain two integers n and m (1 ≤ n, m ≤ 500), the dimensions of the puzzle piece.
The next n lines will describe the jigsaw piece. Each line will have length m and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space.
It is gua... | Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise. | null | For the first sample, one example of a rectangle we can form is as follows
For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.
In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle: | [{"input": "2 3\nXXX\nXXX", "output": "YES"}, {"input": "2 2\n.X\nXX", "output": "NO"}, {"input": "5 5\n.....\n..X..\n.....\n.....\n.....", "output": "YES"}] | 1,400 | ["implementation"] | 77 | [{"input": "2 3\r\nXXX\r\nXXX\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n.X\r\nXX\r\n", "output": "NO\r\n"}, {"input": "5 5\r\n.....\r\n..X..\r\n.....\r\n.....\r\n.....\r\n", "output": "YES\r\n"}, {"input": "1 500\r\n.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX... | false | stdio | null | true |
745/B | 745 | B | Python 3 | TESTS | 8 | 187 | 4,608,000 | 29110060 | import sys
n,m = map(int,input().split())
start = 500
pstart = pend = pcnt = no = totalcnt = 0
for i in range(n):
s = input()
start = end = cnt = 0
for j in range(m):
if s[j] == 'X':
totalcnt += 1
cnt += 1
if j < start:
start = j
if j... | 77 | 62 | 4,608,000 | 23059981 | n, m = map(int, input().split())
ss = ""
for i in range(n):
s = str(input())
if 'X' in s:
if ss == "":
ss = s
else:
if s == ss:
pass
else:
print("NO")
exit()
print("YES") | Codeforces Round 385 (Div. 2) | CF | 2,016 | 2 | 256 | Hongcow Solves A Puzzle | Hongcow likes solving puzzles.
One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an n by m grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that th... | The first line of input will contain two integers n and m (1 ≤ n, m ≤ 500), the dimensions of the puzzle piece.
The next n lines will describe the jigsaw piece. Each line will have length m and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space.
It is gua... | Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise. | null | For the first sample, one example of a rectangle we can form is as follows
For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.
In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle: | [{"input": "2 3\nXXX\nXXX", "output": "YES"}, {"input": "2 2\n.X\nXX", "output": "NO"}, {"input": "5 5\n.....\n..X..\n.....\n.....\n.....", "output": "YES"}] | 1,400 | ["implementation"] | 77 | [{"input": "2 3\r\nXXX\r\nXXX\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n.X\r\nXX\r\n", "output": "NO\r\n"}, {"input": "5 5\r\n.....\r\n..X..\r\n.....\r\n.....\r\n.....\r\n", "output": "YES\r\n"}, {"input": "1 500\r\n.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX... | false | stdio | null | true |
798/B | 798 | B | Python 3 | TESTS | 22 | 46 | 0 | 216130547 | # /**
# * author: brownfox2k6
# * created: 29/07/2023 00:55:01 Hanoi, Vietnam
# **/
n = int(input())
if n == 1:
exit(print(0))
s = input()
sz = len(s)
need = [0] * n
for i in range(1, n):
t = input()
if t == s:
continue
for j in range(1, sz):
if t[j:] + t[:j] == s:
... | 99 | 62 | 0 | 163983586 | import sys
input = sys.stdin.readline
n = int(input())
g = [input()[:-1] for _ in range(n)]
x = g[0]
m = len(x)
d = 2500
ans = 0
for i in range(m):
x = x[1:] + x[0]
c = (i + 1)%m
for j in range(1, n):
t = m
s = g[j]
while t > 0 and s != x:
s = s[1:] + s[0]
t ... | Codeforces Round 410 (Div. 2) | CF | 2,017 | 2 | 256 | Mike and strings | Mike has n strings s1, s2, ..., sn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec".
Now Mike asks himself: what... | The first line contains integer n (1 ≤ n ≤ 50) — the number of strings.
This is followed by n lines which contain a string each. The i-th line corresponding to string si. Lengths of strings are equal. Lengths of each string is positive and don't exceed 50. | Print the minimal number of moves Mike needs in order to make all the strings equal or print - 1 if there is no solution. | null | In the first sample testcase the optimal scenario is to perform operations in such a way as to transform all strings into "zwoxz". | [{"input": "4\nxzzwo\nzwoxz\nzzwox\nxzzwo", "output": "5"}, {"input": "2\nmolzv\nlzvmo", "output": "2"}, {"input": "3\nkc\nkc\nkc", "output": "0"}, {"input": "3\naa\naa\nab", "output": "-1"}] | 1,300 | ["brute force", "dp", "strings"] | 99 | [{"input": "4\r\nxzzwo\r\nzwoxz\r\nzzwox\r\nxzzwo\r\n", "output": "5\r\n"}, {"input": "2\r\nmolzv\r\nlzvmo\r\n", "output": "2\r\n"}, {"input": "3\r\nkc\r\nkc\r\nkc\r\n", "output": "0\r\n"}, {"input": "3\r\naa\r\naa\r\nab\r\n", "output": "-1\r\n"}, {"input": "3\r\nkwkb\r\nkbkw\r\nbkwk\r\n", "output": "3\r\n"}, {"input":... | false | stdio | null | true |
745/B | 745 | B | PyPy 3 | TESTS | 10 | 139 | 23,961,600 | 23549268 | n,m=[int(i) for i in input().split()]
flg=0
ans=1
chk=''
for i in range(n):
tmp=input()
if flg==0 and 'X' in tmp:
tmp=tmp.rstrip('.').lstrip('.')
if '.' in tmp:
ans=0
break
else:
chk=tmp
flg=1
elif flg==1 and 'X' in tmp:
if chk!... | 77 | 62 | 4,608,000 | 23066321 | n,m=map(int,input().split())
osn=' '
iter=-1
p=-1
for i in range(n):
y=input()
if 'X' in y and osn==' ':
k=y.count('X')
f=y.index('X')
for j in range(f,f+k):
if y[j]!='X':
p=0
osn=y
iter=i
elif osn==y and osn!=' ':
if i==iter+1:
... | Codeforces Round 385 (Div. 2) | CF | 2,016 | 2 | 256 | Hongcow Solves A Puzzle | Hongcow likes solving puzzles.
One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an n by m grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that th... | The first line of input will contain two integers n and m (1 ≤ n, m ≤ 500), the dimensions of the puzzle piece.
The next n lines will describe the jigsaw piece. Each line will have length m and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space.
It is gua... | Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise. | null | For the first sample, one example of a rectangle we can form is as follows
For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.
In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle: | [{"input": "2 3\nXXX\nXXX", "output": "YES"}, {"input": "2 2\n.X\nXX", "output": "NO"}, {"input": "5 5\n.....\n..X..\n.....\n.....\n.....", "output": "YES"}] | 1,400 | ["implementation"] | 77 | [{"input": "2 3\r\nXXX\r\nXXX\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n.X\r\nXX\r\n", "output": "NO\r\n"}, {"input": "5 5\r\n.....\r\n..X..\r\n.....\r\n.....\r\n.....\r\n", "output": "YES\r\n"}, {"input": "1 500\r\n.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX... | false | stdio | null | true |
416/A | 416 | A | Python 3 | TESTS | 38 | 109 | 307,200 | 82629014 | n = int(input())
# l = []
lt = lte = (10**9+1)
gt = gte = -(10**9+1)
for _ in range(n):
t1, t2, t3 = input().split()
t2 = int(t2)
if t3 == "Y":
if t1==">=":
gte = max(gte, t2)
elif t1==">":
gt = max(gt, t2)
elif t1=="<=":
lte = min(lte, t2)
else:
lt = min(lt, t2)
else:
if t1==">=":
lt =... | 66 | 78 | 0 | 9388541 | nop = {'<': '>=', '>': '<=', '<=': '>', '>=': '<'}
vmin, vmax = -(10 ** 9 + 1), 10 ** 9 + 1
for i in range(int(input())):
q = input().split()
op, x = q[0] if q[2] == 'Y' else nop[q[0]], int(q[1])
if op[0] == '<':
if op[-1] != '=':
x -= 1
vmax = min(vmax, x)
elif op[0] == '>':... | Codeforces Round 241 (Div. 2) | CF | 2,014 | 1 | 256 | Guess a number! | A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.
The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions:
- Is it true that y is strictl... | The first line of the input contains a single integer n (1 ≤ n ≤ 10000) — the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is:
- ">" (for the first type queries),
- "<" (for the second type queries)... | Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation - 2·109 ≤ y ≤ 2·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes). | null | null | [{"input": "4\n>= 1 Y\n< 3 N\n<= -3 N\n> 55 N", "output": "17"}, {"input": "2\n> 100 Y\n< -100 Y", "output": "Impossible"}] | 1,400 | ["greedy", "implementation", "two pointers"] | 66 | [{"input": "4\r\n>= 1 Y\r\n< 3 N\r\n<= -3 N\r\n> 55 N\r\n", "output": "17\r\n"}, {"input": "2\r\n> 100 Y\r\n< -100 Y\r\n", "output": "Impossible\r\n"}, {"input": "4\r\n< 1 N\r\n> 1 N\r\n> 1 N\r\n> 1 N\r\n", "output": "1\r\n"}, {"input": "4\r\n<= 1 Y\r\n>= 1 Y\r\n>= 1 Y\r\n<= 1 Y\r\n", "output": "1\r\n"}, {"input": "4\r... | false | stdio | import sys
def main(input_path, output_path, submission_path):
with open(input_path) as f:
lines = f.readlines()
n = int(lines[0].strip())
queries = [line.strip().split() for line in lines[1:n+1]]
low = -2 * 10**9
high = 2 * 10**9
for sign, x_str, ans in queries:
x = i... | true |
711/B | 711 | B | Python 3 | TESTS | 6 | 46 | 0 | 187221458 | n=int(input())
lst=[]
for i in range(n):
a=[int(x) for x in input().split()]
lst.append(a)
for i in range(n):
for j in range(n):
if lst[i][j]==0:
ini=i
inj=j
if n==1:
print(1)
exit()
SUM=0
SUMI=0
if ini>0:
for i in range(n):
SUM+=lst[0][i]
else:
for i in range(n):
SUM+=lst[1][i]
for i in ... | 147 | 218 | 6,451,200 | 20354592 | #!/usr/bin/env python3
def main():
n = int(input())
mx = [[int(x) for x in input().split()] for _ in range(n)]
i, j = -1, -1
if n == 1:
print(1)
return
for ii in range(n):
if 0 in mx[ii]:
i = ii
j = mx[i].index(0)
break
sr = [sum(x... | Codeforces Round 369 (Div. 2) | CF | 2,016 | 2 | 256 | Chris and Magic Square | ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid on the entrance which is filled with integers. Chris noticed that exactly one of the cells in the grid is empty, and to enter Udayland, they need to fill a positive integer into the empty cell.
Chris tried filling in ran... | The first line of the input contains a single integer n (1 ≤ n ≤ 500) — the number of rows and columns of the magic grid.
n lines follow, each of them contains n integers. The j-th number in the i-th of them denotes ai, j (1 ≤ ai, j ≤ 109 or ai, j = 0), the number in the i-th row and j-th column of the magic grid. If ... | Output a single integer, the positive integer x (1 ≤ x ≤ 1018) that should be filled in the empty cell so that the whole grid becomes a magic square. If such positive integer x does not exist, output - 1 instead.
If there are multiple solutions, you may print any of them. | null | In the first sample case, we can fill in 9 into the empty cell to make the resulting grid a magic square. Indeed,
The sum of numbers in each row is:
4 + 9 + 2 = 3 + 5 + 7 = 8 + 1 + 6 = 15.
The sum of numbers in each column is:
4 + 3 + 8 = 9 + 5 + 1 = 2 + 7 + 6 = 15.
The sum of numbers in the two diagonals is:
4 +... | [{"input": "3\n4 0 2\n3 5 7\n8 1 6", "output": "9"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 1 1\n1 1 1 1", "output": "1"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 2 1\n1 1 1 1", "output": "-1"}] | 1,400 | ["constructive algorithms", "implementation"] | 147 | [{"input": "3\r\n4 0 2\r\n3 5 7\r\n8 1 6\r\n", "output": "9\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 1 1\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 2 1\r\n1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 ... | false | stdio | null | true |
745/B | 745 | B | Python 3 | TESTS | 26 | 499 | 5,222,400 | 23055724 | from sys import exit
n, m = map(int, input().split())
a = []
for i in range(n):
a.append(input())
left, right, top, bot = m, 0, m, 0
for i in range(n):
for j in range(m):
if a[i][j] == "X":
left = min(left, j)
right = max(right, j)
top = min(top, i)
bot =... | 77 | 62 | 5,120,000 | 23072374 | class MatrixCalculator:
def calculate(self, x, y, rows):
first_occurrence = True
empty_after_x_row = False
leftest_x = 0
rightest_x = 0
x_count = 0
for row in rows:
if 'X' in row:
if empty_after_x_row:
return "NO" # row ... | Codeforces Round 385 (Div. 2) | CF | 2,016 | 2 | 256 | Hongcow Solves A Puzzle | Hongcow likes solving puzzles.
One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an n by m grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that th... | The first line of input will contain two integers n and m (1 ≤ n, m ≤ 500), the dimensions of the puzzle piece.
The next n lines will describe the jigsaw piece. Each line will have length m and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space.
It is gua... | Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise. | null | For the first sample, one example of a rectangle we can form is as follows
For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.
In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle: | [{"input": "2 3\nXXX\nXXX", "output": "YES"}, {"input": "2 2\n.X\nXX", "output": "NO"}, {"input": "5 5\n.....\n..X..\n.....\n.....\n.....", "output": "YES"}] | 1,400 | ["implementation"] | 77 | [{"input": "2 3\r\nXXX\r\nXXX\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n.X\r\nXX\r\n", "output": "NO\r\n"}, {"input": "5 5\r\n.....\r\n..X..\r\n.....\r\n.....\r\n.....\r\n", "output": "YES\r\n"}, {"input": "1 500\r\n.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX... | false | stdio | null | true |
217/A | 217 | A | PyPy 3 | TESTS | 48 | 186 | 2,048,000 | 108647181 | n = int(input())
connect = []
for i in range(n):
index_list = []
x, y = [int(i) for i in input().split()]
if len(connect) == 0:
connect.append([[x, y]])
else:
check = False
for cnt in connect:
for point in cnt:
p_x = point[0]
p_y = point[1]
if p_x == x or p_y == y:
check = True
cnt.ap... | 76 | 92 | 0 | 156954513 | n=int(input())
a=[]
for i in range(n):
x,y=map(int,input().split())
a.append([x,y,False])
def dfs(x):
x[2]=True
for s in a:
if not s[2] and (x[0]==s[0] or x[1]==s[1]):
dfs(s)
rj=0
for i in a:
if not i[2]:
rj+=1
dfs(i)
print(rj-1) | Codeforces Round 134 (Div. 1) | CF | 2,012 | 2 | 256 | Ice Skating | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves... | The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсid... | Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. | null | null | [{"input": "2\n2 1\n1 2", "output": "1"}, {"input": "2\n2 1\n4 1", "output": "0"}] | 1,200 | ["brute force", "dfs and similar", "dsu", "graphs"] | 76 | [{"input": "2\r\n2 1\r\n1 2\r\n", "output": "1\r\n"}, {"input": "2\r\n2 1\r\n4 1\r\n", "output": "0\r\n"}, {"input": "24\r\n171 35\r\n261 20\r\n4 206\r\n501 446\r\n961 912\r\n581 748\r\n946 978\r\n463 514\r\n841 889\r\n341 466\r\n842 967\r\n54 102\r\n235 261\r\n925 889\r\n682 672\r\n623 636\r\n268 94\r\n635 710\r\n474 ... | false | stdio | null | true |
217/A | 217 | A | Python 3 | TESTS | 45 | 248 | 0 | 53302544 | n = int(input())
xl = set()
yl = set()
x = set()
y = set()
k = n - 1
p = set()
for i in range(n):
a, b = map(int, input().split())
p.add((a, b))
if a in x:
k -= 1
if a in xl:
xl.remove(a)
else:
xl.add(a)
x.add(a)
if b in y:
k -= 1
if b... | 76 | 92 | 0 | 164162883 | a = int(input())
mas = [[] for i in range(a)]
arr = [input().split() for i in range(a)]
for i in range(a):
for j in range(i+1 ,a):
if arr[i][0]==arr[j][0] or arr[i][1]==arr[j][1]:
mas[i].append(j)
mas[j].append(i)
used = [False for i in range(a)]
count = 0
def dfs(v):
if used[v]:... | Codeforces Round 134 (Div. 1) | CF | 2,012 | 2 | 256 | Ice Skating | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves... | The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсid... | Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. | null | null | [{"input": "2\n2 1\n1 2", "output": "1"}, {"input": "2\n2 1\n4 1", "output": "0"}] | 1,200 | ["brute force", "dfs and similar", "dsu", "graphs"] | 76 | [{"input": "2\r\n2 1\r\n1 2\r\n", "output": "1\r\n"}, {"input": "2\r\n2 1\r\n4 1\r\n", "output": "0\r\n"}, {"input": "24\r\n171 35\r\n261 20\r\n4 206\r\n501 446\r\n961 912\r\n581 748\r\n946 978\r\n463 514\r\n841 889\r\n341 466\r\n842 967\r\n54 102\r\n235 261\r\n925 889\r\n682 672\r\n623 636\r\n268 94\r\n635 710\r\n474 ... | false | stdio | null | true |
45/I | 45 | I | Python 3 | TESTS | 5 | 62 | 0 | 216408075 | # LUOGU_RID: 118111189
input();a=input();b=0;c=a.count('-')
if' 0'in a:b=1;a=a.replace(' 0','')
if'0'==a[0]:b=1;a=a[2:]
if c==1:
if len(a.split())==1:
if b:print(0)
else:print(a)
else:a=list(map(int,a.split()));a.sort();print(str(a[1:])[1:-1].replace(',',''))
elif c%2:a=list(map(int,a.split()));... | 65 | 124 | 0 | 230015858 | n = int(input())
a = list(map(int, input().split()))
a.sort()
if n == 1:
print(a[0])
exit(0)
if n == 2 and a[1] == 0:
print(0)
exit(0)
output = []
i = 0
while i < n:
if a[i] > 0:
output.append(a[i])
elif a[i] < 0 and a[i+1] < 0:
output.extend([a[i], a[i+1]])
i += 1
i ... | School Team Contest 3 (Winter Computer School 2010/11) | ICPC | 2,010 | 2 | 256 | TCMCF+++ | Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest n problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of poin... | The first line contains an integer n (1 ≤ n ≤ 100) — the number of the suggested problems. The next line contains n space-separated integers ci ( - 100 ≤ ci ≤ 100) — the cost of the i-th task. The tasks' costs may coinсide. | Print space-separated the costs of the problems that needed to be solved to get the maximal possible number of points. Do not forget, please, that it was necessary to solve at least one problem. If there are several solutions to that problem, print any of them. | null | null | [{"input": "5\n1 2 -3 3 3", "output": "3 1 2 3"}, {"input": "13\n100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "100 100 100 100 100 100 100 100 100 100 100 100 100"}, {"input": "4\n-2 -2 -2 -2", "output": "-2 -2 -2 -2"}] | 1,400 | ["greedy"] | 65 | [{"input": "5\r\n1 2 -3 3 3\r\n", "output": "3 1 2 3 \r\n"}, {"input": "13\r\n100 100 100 100 100 100 100 100 100 100 100 100 100\r\n", "output": "100 100 100 100 100 100 100 100 100 100 100 100 100 \r\n"}, {"input": "4\r\n-2 -2 -2 -2\r\n", "output": "-2 -2 -2 -2 \r\n"}, {"input": "1\r\n1\r\n", "output": "1 \r\n"}, {"i... | false | stdio | import sys
from collections import Counter
def compute_max_product(ci):
if all(x == 0 for x in ci):
return 0
positives = [x for x in ci if x > 0]
negatives = [x for x in ci if x < 0]
zeros = [x for x in ci if x == 0]
non_zero = positives + negatives
if not non_zero:
return 0
... | true |
515/B | 515 | B | PyPy 3-64 | TESTS | 42 | 109 | 0 | 140659374 | n, m = map(int, input().split())
x = list(map(int, input().split()))[1:]
y = list(map(int, input().split()))[1:]
happy_x, happy_y = [False] * n, [False] * m
for i in x:
happy_x[i - 1] = True
for i in y:
happy_y[i - 1] = True
curr = 0
for step in range(1000):
if happy_x[curr % n] or happy_y[curr % m]:
... | 56 | 46 | 0 | 141461559 | if __name__ == '__main__':
n, m = map(int, input().split())
b_index = list(map(int, input().split()))[1:]
g_index = list(map(int, input().split()))[1:]
b = [0]*n
g = [0]*m
for i in b_index:
b[i] = 1
for i in g_index:
g[i] = 1
# print(b)
# print(g)
for t in rang... | Codeforces Round 292 (Div. 2) | CF | 2,015 | 2 | 256 | Drazil and His Happy Friends | Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites $$(i \bmod n)$$-th... | The first line contains two integer n and m (1 ≤ n, m ≤ 100).
The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi < n), denoting the list of indices of happy boys.
The third line conatins integer g (0 ≤ ... | If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No". | null | By $$i \bmod k$$ we define the remainder of integer division of i by k.
In first sample case:
- On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day.
- On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so no... | [{"input": "2 3\n0\n1 0", "output": "Yes"}, {"input": "2 4\n1 0\n1 2", "output": "No"}, {"input": "2 3\n1 0\n1 1", "output": "Yes"}] | 1,300 | ["brute force", "dsu", "meet-in-the-middle", "number theory"] | 56 | [{"input": "2 3\r\n0\r\n1 0\r\n", "output": "Yes\r\n"}, {"input": "2 4\r\n1 0\r\n1 2\r\n", "output": "No\r\n"}, {"input": "2 3\r\n1 0\r\n1 1\r\n", "output": "Yes\r\n"}, {"input": "16 88\r\n6 5 14 2 0 12 7\r\n30 21 64 35 79 74 39 63 44 81 73 0 27 33 69 12 86 46 20 25 55 52 7 58 23 5 60 32 41 50 82\r\n", "output": "Yes\r... | false | stdio | null | true |
540/B | 540 | B | PyPy 3-64 | TESTS | 8 | 46 | 0 | 223774695 | n, k, p, x, y = map(int, input().split())
a = list(map(int, input().split()))
start_sum = sum(a)
minor = 0 # кол-во оценок за кр, которые он уже написал, ниже медианы
for i in range(k):
if a[i] < y:
minor += 1
sum_marks = x - start_sum # сколько баллов еще нужно набрать до получения статуса "ботан"
if su... | 78 | 62 | 4,710,400 | 10946124 | n, k, p, x, y=map(int, input().split())
s=list(map(int, input().split()))
s=sorted(s)
if p<y:
print(-1)
else:
kol=0
summ=0
for i in s: #������� ����� � ���������� ������� ��� y
summ+=i
if i>=y:
kol+=1
if k-kol>=n//2+1 or summ > x: #���� ������� �������� ������ y
... | Codeforces Round 301 (Div. 2) | CF | 2,015 | 2 | 256 | School Marks | Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all tests... | The first line contains 5 space-separated integers: n, k, p, x and y (1 ≤ n ≤ 999, n is odd, 0 ≤ k < n, 1 ≤ p ≤ 1000, n ≤ x ≤ n·p, 1 ≤ y ≤ p). Here n is the number of tests that Vova is planned to write, k is the number of tests he has already written, p is the maximum possible mark for a test, x is the maximum total n... | If Vova cannot achieve the desired result, print "-1".
Otherwise, print n - k space-separated integers — the marks that Vova should get for the remaining tests. If there are multiple possible solutions, print any of them. | null | The median of sequence a1, ..., an where n is odd (in this problem n is always odd) is the element staying on (n + 1) / 2 position in the sorted list of ai.
In the first sample the sum of marks equals 3 + 5 + 4 + 4 + 1 = 17, what doesn't exceed 18, that means that Vova won't be disturbed by his classmates. And the med... | [{"input": "5 3 5 18 4\n3 5 4", "output": "4 1"}, {"input": "5 3 5 16 4\n5 5 5", "output": "-1"}] | 1,700 | ["greedy", "implementation"] | 78 | [{"input": "5 3 5 18 4\r\n3 5 4\r\n", "output": "4 1\r\n"}, {"input": "5 3 5 16 4\r\n5 5 5\r\n", "output": "-1\r\n"}, {"input": "5 3 5 17 4\r\n5 5 5\r\n", "output": "1 1\r\n"}, {"input": "5 3 5 12 1\r\n5 5 1\r\n", "output": "-1\r\n"}, {"input": "5 3 5 13 1\r\n5 5 1\r\n", "output": "1 1\r\n"}, {"input": "7 4 5 26 5\r\n5... | false | stdio | import sys
def main(input_path, output_path, submission_path):
with open(input_path, 'r') as f_in:
n, k, p, x, y = map(int, f_in.readline().split())
existing = list(map(int, f_in.readline().split()))
with open(submission_path, 'r') as f_sub:
submission_line = f_sub.read().strip()
... | true |
45/I | 45 | I | PyPy 3-64 | TESTS | 40 | 124 | 0 | 208410450 | n = int(input())
ls = list(map(int,input().split()))
if n == 1 :
print(ls[0])
exit()
ct0, neg = 0, []
for i in ls :
if i > 0 :
print(i,end=" ")
elif i < 0 :
neg.append(i)
else :
ct0 += 1
neg.sort()
if ct0 == n or (len(neg) == 1 and ct0 == 1) :
print(0)
for i in range(len(... | 65 | 154 | 0 | 120290431 | try:
n = int(input())
arr = list(map(int, input().split()))
positive = [item for item in arr if item > 0]
negative = [item for item in arr if item < 0]
zero = [item for item in arr if item == 0]
negative.sort(reverse=True)
length = len(negative)
z_length = len(zero)
if length > 1:
... | School Team Contest 3 (Winter Computer School 2010/11) | ICPC | 2,010 | 2 | 256 | TCMCF+++ | Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest n problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of poin... | The first line contains an integer n (1 ≤ n ≤ 100) — the number of the suggested problems. The next line contains n space-separated integers ci ( - 100 ≤ ci ≤ 100) — the cost of the i-th task. The tasks' costs may coinсide. | Print space-separated the costs of the problems that needed to be solved to get the maximal possible number of points. Do not forget, please, that it was necessary to solve at least one problem. If there are several solutions to that problem, print any of them. | null | null | [{"input": "5\n1 2 -3 3 3", "output": "3 1 2 3"}, {"input": "13\n100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "100 100 100 100 100 100 100 100 100 100 100 100 100"}, {"input": "4\n-2 -2 -2 -2", "output": "-2 -2 -2 -2"}] | 1,400 | ["greedy"] | 65 | [{"input": "5\r\n1 2 -3 3 3\r\n", "output": "3 1 2 3 \r\n"}, {"input": "13\r\n100 100 100 100 100 100 100 100 100 100 100 100 100\r\n", "output": "100 100 100 100 100 100 100 100 100 100 100 100 100 \r\n"}, {"input": "4\r\n-2 -2 -2 -2\r\n", "output": "-2 -2 -2 -2 \r\n"}, {"input": "1\r\n1\r\n", "output": "1 \r\n"}, {"i... | false | stdio | import sys
from collections import Counter
def compute_max_product(ci):
if all(x == 0 for x in ci):
return 0
positives = [x for x in ci if x > 0]
negatives = [x for x in ci if x < 0]
zeros = [x for x in ci if x == 0]
non_zero = positives + negatives
if not non_zero:
return 0
... | true |
217/A | 217 | A | PyPy 3 | TESTS | 48 | 280 | 21,401,600 | 86807984 | def need(xyl):
dsul = [] #use list to repsent dsu
for x,y in xyl: #100
ux,uy = None,None #x and y's union
for i in range(len(dsul)):
ds = dsul[i]
if x in ds[0]: #found x in ith dsu
ds[1].add(y)
ux = i
con... | 76 | 92 | 0 | 166874127 | n = int(input())
x = [0]
y = [0]
danh_so = [0]*(n+10)
for _ in range(n):
s = input()
t = s.split()
x += [int(t[0])]
y += [int(t[1])]
del (s);del(t)
def dfs(u, s):
global danh_so
danh_so[u] = s
for i in range(1, n+1):
if danh_so[i] == 0 and (x[i] == x[u] or y[i] == y[u]):
... | Codeforces Round 134 (Div. 1) | CF | 2,012 | 2 | 256 | Ice Skating | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves... | The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсid... | Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. | null | null | [{"input": "2\n2 1\n1 2", "output": "1"}, {"input": "2\n2 1\n4 1", "output": "0"}] | 1,200 | ["brute force", "dfs and similar", "dsu", "graphs"] | 76 | [{"input": "2\r\n2 1\r\n1 2\r\n", "output": "1\r\n"}, {"input": "2\r\n2 1\r\n4 1\r\n", "output": "0\r\n"}, {"input": "24\r\n171 35\r\n261 20\r\n4 206\r\n501 446\r\n961 912\r\n581 748\r\n946 978\r\n463 514\r\n841 889\r\n341 466\r\n842 967\r\n54 102\r\n235 261\r\n925 889\r\n682 672\r\n623 636\r\n268 94\r\n635 710\r\n474 ... | false | stdio | null | true |
749/C | 749 | C | PyPy 3-64 | TESTS | 20 | 124 | 22,323,200 | 202415267 | import sys
input = lambda: sys.stdin.readline().rstrip()
N = int(input())
S = [c for c in input()]
D,R = [],[]
for i in range(N):
if S[i]=='D':
D.append(i)
else:
R.append(i)
D = D[::-1]
R = R[::-1]
while True:
for i in range(N):
if S[i]=='D':
if not R:
... | 144 | 124 | 7,782,400 | 197508005 | n = int(input())
s = list(input())
r, d =0, 0
while(True):
t=0
for i in range(n):
if s[i]=='D':
if d>0:
s[i]='0'
d-=1
t+=1
else:
r+=1
if s[i]=='R':
if r>0:
s[i]='0'
r-=1
t+=1
else:
d+=1
if t==0:
for i in range(n):
if s[i]!='0':
print(s[i])
exit() | Codeforces Round 388 (Div. 2) | CF | 2,016 | 1 | 256 | Voting | There are n employees in Alternative Cake Manufacturing (ACM). They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote.
Each of the employees belongs to one of two fractions: depublicans or remocrats, and these two fractions have opposite opinions o... | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of employees.
The next line contains n characters. The i-th character is 'D' if the i-th employee is from depublicans fraction or 'R' if he is from remocrats. | Print 'D' if the outcome of the vote will be suitable for depublicans and 'R' if remocrats will win. | null | Consider one of the voting scenarios for the first sample:
1. Employee 1 denies employee 5 to vote.
2. Employee 2 denies employee 3 to vote.
3. Employee 3 has no right to vote and skips his turn (he was denied by employee 2).
4. Employee 4 denies employee 2 to vote.
5. Employee 5 has no right to vote and skips his tur... | [{"input": "5\nDDRRR", "output": "D"}, {"input": "6\nDDRRRR", "output": "R"}] | 1,500 | ["greedy", "implementation", "two pointers"] | 144 | [{"input": "5\r\nDDRRR\r\n", "output": "D\r\n"}, {"input": "6\r\nDDRRRR\r\n", "output": "R\r\n"}, {"input": "1\r\nD\r\n", "output": "D\r\n"}, {"input": "1\r\nR\r\n", "output": "R\r\n"}, {"input": "2\r\nDR\r\n", "output": "D\r\n"}, {"input": "3\r\nRDD\r\n", "output": "D\r\n"}, {"input": "3\r\nDRD\r\n", "output": "D\r\n"... | false | stdio | null | true |
40/D | 40 | D | Python 3 | TESTS | 16 | 404 | 1,126,400 | 41635611 | from fractions import Fraction
import sys
sys.setrecursionlimit(1000*100)
A=int(input())
p=[]
c=1
for _ in range(300):
p.append(c)
c*=12
r=[]
for i in range(300):
for j in range(i+1):
if p[j]+p[i-j]==A:
r.append(i+1)
break
s=set()
for i in r:
for j in range(i):
... | 74 | 154 | 204,800 | 199720448 | import heapq
import sys
lim = 1000
a = int(input())
def gen_pow():
ans = {}
pw_x = 1
x = 0
while pw_x <= a:
ans[pw_x] = x
pw_x *= 12
x += 1
return ans
pow_map = gen_pow()
year_list = set()
for pw_x, x in pow_map.items():
pw_y = a - pw_x
if pw_y not in pow_ma... | Codeforces Beta Round 39 | CF | 2,010 | 3 | 256 | Interesting Sequence | Berland scientists noticed long ago that the world around them depends on Berland population. Due to persistent research in this area the scientists managed to find out that the Berland chronology starts from the moment when the first two people came to that land (it is considered to have happened in the first year). A... | The first line contains integer A (1 ≤ A < 10300). It is guaranteed that the number doesn't contain leading zeros. | On the first output line print YES, if there could be a year in which the total population of the country equaled A, otherwise print NO.
If the answer is YES, then you also have to print number k — the number of years in which the population could equal A. On the next line you have to output precisely k space-separate... | null | null | [{"input": "2", "output": "YES\n1\n1\n0"}, {"input": "3", "output": "NO"}, {"input": "13", "output": "YES\n1\n2\n0"}, {"input": "1729", "output": "YES\n1\n4\n1\n156"}] | 2,600 | ["math"] | 74 | [{"input": "2\r\n", "output": "YES\r\n1\r\n1\r\n0\r\n"}, {"input": "3\r\n", "output": "NO\r\n"}, {"input": "13\r\n", "output": "YES\r\n1\r\n2\r\n0\r\n"}, {"input": "1729\r\n", "output": "YES\r\n1\r\n4\r\n1\r\n156\r\n"}, {"input": "1\r\n", "output": "NO\r\n"}, {"input": "156\r\n", "output": "YES\r\n1\r\n4\r\n1\r\n1729\r... | false | stdio | null | true |
618/C | 618 | C | PyPy 3-64 | TESTS | 14 | 686 | 16,896,000 | 190096831 | import math
from math import sqrt, inf, gcd, ceil, tan, pi, sin, cos
import queue
# -------- info --------
# https://codeforces.com/profile/Wolxy
# -------- sys --------
def next_int() -> int:
return int(input())
def next_ints() -> map:
return map(int, input().split(' '))
def next_list() -> list:
r... | 98 | 311 | 30,208,000 | 157410048 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
xy = [tuple(map(int, input().split())) for _ in range(n)]
x1, y1 = xy[0]
ans = [1, 0, 0]
inf = 8 * pow(10, 18) + 1
d = inf
for i in range(1, n):
x0, y0 = xy[i]
d0 = pow(x1 - x0, 2) + pow(y1 - y0, 2)
if d > d0:
... | Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) | CF | 2,016 | 2 | 256 | Constellation | Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, the i-th star is located at coordinates (xi, yi). No two stars are located at the same position.
In the evening Noku is going to take a look at the night sky. He would like to find three d... | The first line of the input contains a single integer n (3 ≤ n ≤ 100 000).
Each of the next n lines contains two integers xi and yi ( - 109 ≤ xi, yi ≤ 109).
It is guaranteed that no two stars lie at the same point, and there does not exist a line such that all stars lie on that line. | Print three distinct integers on a single line — the indices of the three points that form a triangle that satisfies the conditions stated in the problem.
If there are multiple possible answers, you may print any of them. | null | In the first sample, we can print the three indices in any order.
In the second sample, we have the following picture.
Note that the triangle formed by starts 1, 4 and 3 doesn't satisfy the conditions stated in the problem, as point 5 is not strictly outside of this triangle (it lies on it's border). | [{"input": "3\n0 1\n1 0\n1 1", "output": "1 2 3"}, {"input": "5\n0 0\n0 2\n2 0\n2 2\n1 1", "output": "1 3 5"}] | 1,600 | ["geometry", "implementation"] | 98 | [{"input": "3\r\n0 1\r\n1 0\r\n1 1\r\n", "output": "1 2 3\r\n"}, {"input": "5\r\n0 0\r\n0 2\r\n2 0\r\n2 2\r\n1 1\r\n", "output": "1 3 5\r\n"}, {"input": "3\r\n819934317 939682125\r\n487662889 8614219\r\n-557136619 382982369\r\n", "output": "1 3 2\r\n"}, {"input": "10\r\n25280705 121178189\r\n219147240 -570920213\r\n-82... | false | stdio | import sys
def main(input_path, output_path, submission_path):
# Read input points
with open(input_path, 'r') as f:
n = int(f.readline().strip())
points = []
for _ in range(n):
x, y = map(int, f.readline().strip().split())
points.append((x, y))
# Read su... | true |
749/C | 749 | C | Python 3 | TESTS | 20 | 280 | 10,342,400 | 169632842 | from collections import deque
d = deque([])
r = deque([])
n = int(input())
s = input()
q = [1] * n
for i in range(n):
if s[i] == "D":
d.append(i)
else:
r.append(i)
e = deque([*range(n)])
w = deque([])
x = {"R","D"}
while len(x)==2:
x=set()
for i in range(len(e)):
i = e.popleft()
... | 144 | 124 | 12,595,200 | 181066500 | from collections import deque
n=int(input())
a=input()
q1=deque()
q2=deque()
for i in range(n):
if a[i]=='D':
q1.append(i)
else:
q2.append(i)
while q1 and q2:
# print(q1[0],q2[0])
if q1[0]<q2[0]:
q2.popleft()
q1.append(n+q1.popleft())
else:
q1.popleft()
... | Codeforces Round 388 (Div. 2) | CF | 2,016 | 1 | 256 | Voting | There are n employees in Alternative Cake Manufacturing (ACM). They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote.
Each of the employees belongs to one of two fractions: depublicans or remocrats, and these two fractions have opposite opinions o... | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of employees.
The next line contains n characters. The i-th character is 'D' if the i-th employee is from depublicans fraction or 'R' if he is from remocrats. | Print 'D' if the outcome of the vote will be suitable for depublicans and 'R' if remocrats will win. | null | Consider one of the voting scenarios for the first sample:
1. Employee 1 denies employee 5 to vote.
2. Employee 2 denies employee 3 to vote.
3. Employee 3 has no right to vote and skips his turn (he was denied by employee 2).
4. Employee 4 denies employee 2 to vote.
5. Employee 5 has no right to vote and skips his tur... | [{"input": "5\nDDRRR", "output": "D"}, {"input": "6\nDDRRRR", "output": "R"}] | 1,500 | ["greedy", "implementation", "two pointers"] | 144 | [{"input": "5\r\nDDRRR\r\n", "output": "D\r\n"}, {"input": "6\r\nDDRRRR\r\n", "output": "R\r\n"}, {"input": "1\r\nD\r\n", "output": "D\r\n"}, {"input": "1\r\nR\r\n", "output": "R\r\n"}, {"input": "2\r\nDR\r\n", "output": "D\r\n"}, {"input": "3\r\nRDD\r\n", "output": "D\r\n"}, {"input": "3\r\nDRD\r\n", "output": "D\r\n"... | false | stdio | null | true |
796/C | 796 | C | PyPy 3-64 | TESTS | 102 | 686 | 111,206,400 | 219616832 | import sys
input = sys.stdin.buffer.readline
def process(n, A, G):
g = [[] for i in range(n+1)]
for u, v in G:
g[u].append(v)
g[v].append(u)
#answer is I think max(A), max(A)+1, max(A)+2
#everything increases at most twice
#once distance 2 from the hack
#once distance 1 ... | 129 | 561 | 74,444,800 | 215837257 | # 答案好像就只有3种情况
import sys
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
g = [[] for _ in range(n)]
for _ in range(n - 1):
u, v = map(int, sys.stdin.readline().split())
g[u - 1].append(v - 1)
g[v - 1].append(u - 1)
def check(x):
root = None
for i,v in enumerate(a):
... | Codeforces Round 408 (Div. 2) | CF | 2,017 | 2 | 256 | Bank Hacking | Although Inzane successfully found his beloved bone, Zane, his owner, has yet to return. To search for Zane, he would need a lot of money, of which he sadly has none. To deal with the problem, he has decided to hack the banks.
There are n banks, numbered from 1 to n. There are also n - 1 wires connecting the banks. Al... | The first line contains one integer n (1 ≤ n ≤ 3·105) — the total number of banks.
The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the strengths of the banks.
Each of the next n - 1 lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — meaning that there is a wire directly connec... | Print one integer — the minimum strength of the computer Inzane needs to accomplish the goal. | null | In the first sample, Inzane can hack all banks using a computer with strength 5. Here is how:
- Initially, strengths of the banks are [1, 2, 3, 4, 5].
- He hacks bank 5, then strengths of the banks become [1, 2, 4, 5, - ].
- He hacks bank 4, then strengths of the banks become [1, 3, 5, - , - ].
- He hacks bank 3, t... | [{"input": "5\n1 2 3 4 5\n1 2\n2 3\n3 4\n4 5", "output": "5"}, {"input": "7\n38 -29 87 93 39 28 -55\n1 2\n2 5\n3 2\n2 4\n1 7\n7 6", "output": "93"}, {"input": "5\n1 2 7 6 7\n1 5\n5 3\n3 4\n2 4", "output": "8"}] | 1,900 | ["constructive algorithms", "data structures", "dp", "trees"] | 129 | [{"input": "5\r\n1 2 3 4 5\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n", "output": "5"}, {"input": "7\r\n38 -29 87 93 39 28 -55\r\n1 2\r\n2 5\r\n3 2\r\n2 4\r\n1 7\r\n7 6\r\n", "output": "93"}, {"input": "5\r\n1 2 7 6 7\r\n1 5\r\n5 3\r\n3 4\r\n2 4\r\n", "output": "8"}, {"input": "3\r\n2 2 2\r\n3 2\r\n1 2\r\n", "output": "3"}, {"inp... | false | stdio | null | true |
749/C | 749 | C | PyPy 3 | TESTS | 20 | 140 | 28,569,600 | 127875772 | R = lambda: map(int, input().split())
n = int(input())
s = input()
ds, rs = [], []
vst = [0] * (n + 1)
for i in range(n):
if s[i] == 'D':
ds.append(i)
else:
rs.append(i)
di, ri = -1, -1
while di < len(ds) - 1 and ri < len(rs) - 1:
for i in range(n):
if not vst[i]:
if ri +... | 144 | 140 | 9,728,000 | 143159142 | import sys
input = sys.stdin.buffer.readline
def process(S):
count = [0, 0]
while True:
n = len(S)
L2 = []
count2 = [0, 0]
for i in range(n):
if S[i]=='D':
if count[1] > 0:
count[1]-=1
else:
L2... | Codeforces Round 388 (Div. 2) | CF | 2,016 | 1 | 256 | Voting | There are n employees in Alternative Cake Manufacturing (ACM). They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote.
Each of the employees belongs to one of two fractions: depublicans or remocrats, and these two fractions have opposite opinions o... | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of employees.
The next line contains n characters. The i-th character is 'D' if the i-th employee is from depublicans fraction or 'R' if he is from remocrats. | Print 'D' if the outcome of the vote will be suitable for depublicans and 'R' if remocrats will win. | null | Consider one of the voting scenarios for the first sample:
1. Employee 1 denies employee 5 to vote.
2. Employee 2 denies employee 3 to vote.
3. Employee 3 has no right to vote and skips his turn (he was denied by employee 2).
4. Employee 4 denies employee 2 to vote.
5. Employee 5 has no right to vote and skips his tur... | [{"input": "5\nDDRRR", "output": "D"}, {"input": "6\nDDRRRR", "output": "R"}] | 1,500 | ["greedy", "implementation", "two pointers"] | 144 | [{"input": "5\r\nDDRRR\r\n", "output": "D\r\n"}, {"input": "6\r\nDDRRRR\r\n", "output": "R\r\n"}, {"input": "1\r\nD\r\n", "output": "D\r\n"}, {"input": "1\r\nR\r\n", "output": "R\r\n"}, {"input": "2\r\nDR\r\n", "output": "D\r\n"}, {"input": "3\r\nRDD\r\n", "output": "D\r\n"}, {"input": "3\r\nDRD\r\n", "output": "D\r\n"... | false | stdio | null | true |
798/B | 798 | B | PyPy 3-64 | TESTS | 89 | 62 | 2,150,400 | 147661820 | n=int(input())
ar=[]
for _ in range(n):
s=input()
ar.append(s)
ans=float("inf")
f=True
for i in range(n):
temp=0
p=ar[i]+ar[i]
for j in range(n):
if i!=j:
if ar[j] not in p:
f=False
break
else :
ind=p.find(ar[j])
... | 99 | 62 | 0 | 207808307 | n = int(input())
words = [input() for _ in range(n)]
def solve(x ,y, dep):
if x == y:
return 0
if dep > 50:
return -float('inf')
return 1+solve(x, y[1:]+y[0], dep+1)
best = float('inf')
for x in words:
total = 0
for y in words:
res = solve(x, y, 0)
if res < 0:
... | Codeforces Round 410 (Div. 2) | CF | 2,017 | 2 | 256 | Mike and strings | Mike has n strings s1, s2, ..., sn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec".
Now Mike asks himself: what... | The first line contains integer n (1 ≤ n ≤ 50) — the number of strings.
This is followed by n lines which contain a string each. The i-th line corresponding to string si. Lengths of strings are equal. Lengths of each string is positive and don't exceed 50. | Print the minimal number of moves Mike needs in order to make all the strings equal or print - 1 if there is no solution. | null | In the first sample testcase the optimal scenario is to perform operations in such a way as to transform all strings into "zwoxz". | [{"input": "4\nxzzwo\nzwoxz\nzzwox\nxzzwo", "output": "5"}, {"input": "2\nmolzv\nlzvmo", "output": "2"}, {"input": "3\nkc\nkc\nkc", "output": "0"}, {"input": "3\naa\naa\nab", "output": "-1"}] | 1,300 | ["brute force", "dp", "strings"] | 99 | [{"input": "4\r\nxzzwo\r\nzwoxz\r\nzzwox\r\nxzzwo\r\n", "output": "5\r\n"}, {"input": "2\r\nmolzv\r\nlzvmo\r\n", "output": "2\r\n"}, {"input": "3\r\nkc\r\nkc\r\nkc\r\n", "output": "0\r\n"}, {"input": "3\r\naa\r\naa\r\nab\r\n", "output": "-1\r\n"}, {"input": "3\r\nkwkb\r\nkbkw\r\nbkwk\r\n", "output": "3\r\n"}, {"input":... | false | stdio | null | true |
768/A | 768 | A | Python 3 | TESTS | 25 | 61 | 9,113,600 | 161715081 | n = int(input())
a = list(map(int,input().split(" ")))
if n <= 2:
print(0)
else:
minimum_count = a.count(min(a))
maximum_count = a.count(max(a))
print(n-minimum_count-maximum_count) | 88 | 62 | 8,806,400 | 161203085 | n = int(input());a = [*map(int, input().split())];print(max(0, n-(a.count(min(a)) + a.count(max(a))))) | Divide by Zero 2017 and Codeforces Round 399 (Div. 1 + Div. 2, combined) | CF | 2,017 | 2 | 256 | Oath of the Night's Watch | "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I ple... | First line consists of a single integer n (1 ≤ n ≤ 105) — the number of stewards with Jon Snow.
Second line consists of n space separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) representing the values assigned to the stewards. | Output a single integer representing the number of stewards which Jon will feed. | null | In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are steward... | [{"input": "2\n1 5", "output": "0"}, {"input": "3\n1 2 5", "output": "1"}] | 900 | ["constructive algorithms", "sortings"] | 88 | [{"input": "2\r\n1 5\r\n", "output": "0"}, {"input": "3\r\n1 2 5\r\n", "output": "1"}, {"input": "4\r\n1 2 3 4\r\n", "output": "2"}, {"input": "8\r\n7 8 9 4 5 6 1 2\r\n", "output": "6"}, {"input": "1\r\n1\r\n", "output": "0"}, {"input": "1\r\n100\r\n", "output": "0"}, {"input": "205\r\n5 5 3 3 6 2 9 3 8 9 6 6 10 8 1 5 ... | false | stdio | null | true |
768/A | 768 | A | PyPy 3-64 | TESTS | 25 | 93 | 13,414,400 | 165611236 | n=int(input());arr=list(map(int,input().rstrip().split()));arr.sort()
a,b=0,0
for e in range(n-1):
if arr[e]!=arr[e+1]:a=(e+1);break
for e in range(n-1,0,-1):
if arr[e]!=arr[e-1]:b=(e+1);break
if a>b or n==1 or n==2:print(0)
else:print((b-a)-1) | 88 | 62 | 13,209,600 | 220741625 | n= int(input())
the_list=list(map(int,input().split()))
if the_list.count(max(the_list))+the_list.count (min(the_list))>=len(the_list):print(0)
else : print(len(the_list)-(the_list.count(max(the_list))+the_list.count(min(the_list)))) | Divide by Zero 2017 and Codeforces Round 399 (Div. 1 + Div. 2, combined) | CF | 2,017 | 2 | 256 | Oath of the Night's Watch | "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I ple... | First line consists of a single integer n (1 ≤ n ≤ 105) — the number of stewards with Jon Snow.
Second line consists of n space separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) representing the values assigned to the stewards. | Output a single integer representing the number of stewards which Jon will feed. | null | In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are steward... | [{"input": "2\n1 5", "output": "0"}, {"input": "3\n1 2 5", "output": "1"}] | 900 | ["constructive algorithms", "sortings"] | 88 | [{"input": "2\r\n1 5\r\n", "output": "0"}, {"input": "3\r\n1 2 5\r\n", "output": "1"}, {"input": "4\r\n1 2 3 4\r\n", "output": "2"}, {"input": "8\r\n7 8 9 4 5 6 1 2\r\n", "output": "6"}, {"input": "1\r\n1\r\n", "output": "0"}, {"input": "1\r\n100\r\n", "output": "0"}, {"input": "205\r\n5 5 3 3 6 2 9 3 8 9 6 6 10 8 1 5 ... | false | stdio | null | true |
768/A | 768 | A | Python 3 | TESTS | 25 | 109 | 8,806,400 | 160143136 | x = int(input())
y = sorted([int(i) for i in input().split()])
if len(y) < 3:
print(0)
if len(y) >= 3:
one = y.count(min(y))
two = y.count(max(y))
print(len(y) - (one + two)) | 88 | 77 | 8,806,400 | 161715956 | n = int(input())
a = list(map(int,input().split(" ")))
minimum = a.count(min(a))
maximum = a.count(max(a))
ans = n - minimum - maximum
print("0" if ans <= 0 else ans) | Divide by Zero 2017 and Codeforces Round 399 (Div. 1 + Div. 2, combined) | CF | 2,017 | 2 | 256 | Oath of the Night's Watch | "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I ple... | First line consists of a single integer n (1 ≤ n ≤ 105) — the number of stewards with Jon Snow.
Second line consists of n space separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) representing the values assigned to the stewards. | Output a single integer representing the number of stewards which Jon will feed. | null | In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are steward... | [{"input": "2\n1 5", "output": "0"}, {"input": "3\n1 2 5", "output": "1"}] | 900 | ["constructive algorithms", "sortings"] | 88 | [{"input": "2\r\n1 5\r\n", "output": "0"}, {"input": "3\r\n1 2 5\r\n", "output": "1"}, {"input": "4\r\n1 2 3 4\r\n", "output": "2"}, {"input": "8\r\n7 8 9 4 5 6 1 2\r\n", "output": "6"}, {"input": "1\r\n1\r\n", "output": "0"}, {"input": "1\r\n100\r\n", "output": "0"}, {"input": "205\r\n5 5 3 3 6 2 9 3 8 9 6 6 10 8 1 5 ... | false | stdio | null | true |
762/C | 762 | C | Python 3 | TESTS | 17 | 265 | 12,697,600 | 199408513 | a = input()
b = input()
arr = [[0]*26 for i in range(len(a))]
arr[0][ord(a[0])-97] = 1
for i in range(1,len(a)):
arr[i][ord(a[i])-97] = arr[i-1][ord(a[i])-97] + 1
p = [0]
s = [0]
inf_p = False
inf_s = False
pref = 0
suf = len(a) - 1
for i in range(len(b)):
while True:
if pref > len(a) - 1:
i... | 99 | 343 | 5,939,200 | 42141097 | # cook your dish here
a = list(input())
b = list(input())
m = len(a)
n = len(b)
s = [-1]
i = 0
j = 0
while i<m and j<n:
if(a[i]==b[j]):
s.append(i)
j+=1
i+=1
e = [1000000]
i = m-1
j= n-1
while i>=0 and j>=0:
if(a[i]==b[j]):
e.append(i)
j-=1
... | Educational Codeforces Round 17 | ICPC | 2,017 | 2 | 256 | Two strings | You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of th... | The first line contains string a, and the second line — string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 105 characters. | On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters.
If the answer consists of zero characters, output «-» (a minus sign). | null | In the first example strings a and b don't share any symbols, so the longest string that you can get is empty.
In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b. | [{"input": "hi\nbob", "output": "-"}, {"input": "abca\naccepted", "output": "ac"}, {"input": "abacaba\nabcdcba", "output": "abcba"}] | 2,100 | ["binary search", "hashing", "strings", "two pointers"] | 99 | [{"input": "hi\r\nbob\r\n", "output": "-\r\n"}, {"input": "abca\r\naccepted\r\n", "output": "ac\r\n"}, {"input": "abacaba\r\nabcdcba\r\n", "output": "abcba\r\n"}, {"input": "lo\r\neuhaqdhhzlnkmqnakgwzuhurqlpmdm\r\n", "output": "-\r\n"}, {"input": "aaeojkdyuilpdvyewjfrftkpcobhcumwlaoiocbfdtvjkhgda\r\nmlmarpivirqbxcyhyer... | false | stdio | null | true |
446/A | 446 | A | Python 3 | TESTS | 24 | 280 | 13,004,800 | 31613177 | def find_longest_streak(n, nums):
if n < 2:
return n
rights = [0] * n
lefts = [0] * n
rights[0] = 1
lefts[n-1] = 1
for i in range(1, n):
if nums[i] > nums[i-1]:
rights[i] = rights[i-1] + 1
else:
rights[i] = 1
for i in range(n-2, -1, -1):
... | 92 | 186 | 11,571,200 | 132086655 | n=int(input())
l=[0]+list(map(int,input().split()))+[0]
front=[0]*(n+2)
last=[0]*(n+2)
front[1]=1
last[n]=1
for i in range(2,n+1):
if l[i-1]<l[i]:
front[i]=front[i-1]+1
else:
front[i]=1
for i in range(n-1,0,-1):
if l[i]<l[i+1]:
last[i]=last[i+1]+1
else:
last[i]=1
ans=1
fo... | Codeforces Round #FF (Div. 1) | CF | 2,014 | 1 | 256 | DZY Loves Sequences | DZY has a sequence a, consisting of n integers.
We'll call a sequence ai, ai + 1, ..., aj (1 ≤ i ≤ j ≤ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment.
Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one numb... | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109). | In a single line print the answer to the problem — the maximum length of the required subsegment. | null | You can choose subsegment a2, a3, a4, a5, a6 and change its 3rd element (that is a4) to 4. | [{"input": "6\n7 2 3 1 5 6", "output": "5"}] | 1,600 | ["dp", "implementation", "two pointers"] | 92 | [{"input": "6\r\n7 2 3 1 5 6\r\n", "output": "5\r\n"}, {"input": "10\r\n424238336 649760493 681692778 714636916 719885387 804289384 846930887 957747794 596516650 189641422\r\n", "output": "9\r\n"}, {"input": "50\r\n804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 189641422 25202... | false | stdio | null | true |
762/C | 762 | C | PyPy 3-64 | TESTS | 17 | 77 | 5,017,600 | 180735267 | from sys import stdin
input=lambda :stdin.readline()[:-1]
s=input()
t=input()
n=len(s)
m=len(t)
left=[0]*m
R=0
for i in range(m):
while R!=n and t[i]!=s[R]:
R+=1
left[i]=R
R=min(R+1,n)
right=[0]*m
L=n-1
for i in range(m-1,-1,-1):
while L!=-1 and t[i]!=s[L]:
L-=1
right[i]=L
L=max(L-1,-1)
#print(ri... | 99 | 93 | 8,089,600 | 230897513 | a, b = input(), input()
n = len(b)
def f(a, b):
i, t = 0, [0]
for q in a:
if i < n and q == b[i]: i += 1
t.append(i)
return t
u, v = f(a, b), f(a[::-1], b[::-1])[::-1]
t = [x + y for x, y in zip(u, v)]
i = t.index(max(t))
x, y = u[i], v[i]
s = b[:x] + b[max(x, n - y):]
print(s if s else '-') | Educational Codeforces Round 17 | ICPC | 2,017 | 2 | 256 | Two strings | You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of th... | The first line contains string a, and the second line — string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 105 characters. | On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters.
If the answer consists of zero characters, output «-» (a minus sign). | null | In the first example strings a and b don't share any symbols, so the longest string that you can get is empty.
In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b. | [{"input": "hi\nbob", "output": "-"}, {"input": "abca\naccepted", "output": "ac"}, {"input": "abacaba\nabcdcba", "output": "abcba"}] | 2,100 | ["binary search", "hashing", "strings", "two pointers"] | 99 | [{"input": "hi\r\nbob\r\n", "output": "-\r\n"}, {"input": "abca\r\naccepted\r\n", "output": "ac\r\n"}, {"input": "abacaba\r\nabcdcba\r\n", "output": "abcba\r\n"}, {"input": "lo\r\neuhaqdhhzlnkmqnakgwzuhurqlpmdm\r\n", "output": "-\r\n"}, {"input": "aaeojkdyuilpdvyewjfrftkpcobhcumwlaoiocbfdtvjkhgda\r\nmlmarpivirqbxcyhyer... | false | stdio | null | true |
768/A | 768 | A | PyPy 3-64 | TESTS | 25 | 93 | 11,264,000 | 229746657 | a = int(input())
b = [int(i) for i in input().split(' ')]
if(a==1):
print(0)
else:
b.sort()
i = 0
mini = b[i]
j = a-1
maxi = b[j]
while(i<a and b[i]==mini):
i += 1
while(j>=0 and b[j]==maxi):
j -= 1
print(j-i+1) | 88 | 77 | 8,806,400 | 164092593 | input();r=[*map(int,input().split())]
print(max(0,len(r)-r.count(min(r))-r.count(max(r)))) | Divide by Zero 2017 and Codeforces Round 399 (Div. 1 + Div. 2, combined) | CF | 2,017 | 2 | 256 | Oath of the Night's Watch | "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I ple... | First line consists of a single integer n (1 ≤ n ≤ 105) — the number of stewards with Jon Snow.
Second line consists of n space separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) representing the values assigned to the stewards. | Output a single integer representing the number of stewards which Jon will feed. | null | In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are steward... | [{"input": "2\n1 5", "output": "0"}, {"input": "3\n1 2 5", "output": "1"}] | 900 | ["constructive algorithms", "sortings"] | 88 | [{"input": "2\r\n1 5\r\n", "output": "0"}, {"input": "3\r\n1 2 5\r\n", "output": "1"}, {"input": "4\r\n1 2 3 4\r\n", "output": "2"}, {"input": "8\r\n7 8 9 4 5 6 1 2\r\n", "output": "6"}, {"input": "1\r\n1\r\n", "output": "0"}, {"input": "1\r\n100\r\n", "output": "0"}, {"input": "205\r\n5 5 3 3 6 2 9 3 8 9 6 6 10 8 1 5 ... | false | stdio | null | true |
768/A | 768 | A | Python 3 | TESTS | 25 | 93 | 13,209,600 | 217118900 | n = int(input())
a = list(map(int, input().split()))
a.sort()
# print(a)
supported = len(a[1:-1])
# print(supported)
for i in range(1, n):
if a[0] == a[i]:
# print(a[i], 'i')
supported -= 1
else:
break
for j in range(n - 2, -1, -1):
if a[-1] == a[j]:
# print(a[j], 'j')
... | 88 | 77 | 11,264,000 | 228455237 | number = int(input())
elements = [int(el) for el in input().split(" ")]
elements.sort()
max_el = elements[len(elements) - 1]
min_el = elements[0]
count = 0
for i in range(len(elements)):
if elements[i] > min_el and elements[i] < max_el:
count += 1
print(count) | Divide by Zero 2017 and Codeforces Round 399 (Div. 1 + Div. 2, combined) | CF | 2,017 | 2 | 256 | Oath of the Night's Watch | "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I ple... | First line consists of a single integer n (1 ≤ n ≤ 105) — the number of stewards with Jon Snow.
Second line consists of n space separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) representing the values assigned to the stewards. | Output a single integer representing the number of stewards which Jon will feed. | null | In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are steward... | [{"input": "2\n1 5", "output": "0"}, {"input": "3\n1 2 5", "output": "1"}] | 900 | ["constructive algorithms", "sortings"] | 88 | [{"input": "2\r\n1 5\r\n", "output": "0"}, {"input": "3\r\n1 2 5\r\n", "output": "1"}, {"input": "4\r\n1 2 3 4\r\n", "output": "2"}, {"input": "8\r\n7 8 9 4 5 6 1 2\r\n", "output": "6"}, {"input": "1\r\n1\r\n", "output": "0"}, {"input": "1\r\n100\r\n", "output": "0"}, {"input": "205\r\n5 5 3 3 6 2 9 3 8 9 6 6 10 8 1 5 ... | false | stdio | null | true |
768/A | 768 | A | Python 3 | TESTS | 25 | 108 | 8,806,400 | 181351042 | n=int(input())
num=sorted([int(x) for x in input().split()])
if n==1: print(0)
else: print(len(num)-num.count(num[0])-num.count(num[-1])) | 88 | 77 | 11,776,000 | 171538532 | if __name__ == '__main__':
n = int(input())
strenghts = [int(s) for s in input().split()]
minimum = min(strenghts)
maximum = max(strenghts)
count = 0
for i in range(n):
if minimum < strenghts[i] < maximum:
count += 1
print(count) | Divide by Zero 2017 and Codeforces Round 399 (Div. 1 + Div. 2, combined) | CF | 2,017 | 2 | 256 | Oath of the Night's Watch | "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I ple... | First line consists of a single integer n (1 ≤ n ≤ 105) — the number of stewards with Jon Snow.
Second line consists of n space separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) representing the values assigned to the stewards. | Output a single integer representing the number of stewards which Jon will feed. | null | In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are steward... | [{"input": "2\n1 5", "output": "0"}, {"input": "3\n1 2 5", "output": "1"}] | 900 | ["constructive algorithms", "sortings"] | 88 | [{"input": "2\r\n1 5\r\n", "output": "0"}, {"input": "3\r\n1 2 5\r\n", "output": "1"}, {"input": "4\r\n1 2 3 4\r\n", "output": "2"}, {"input": "8\r\n7 8 9 4 5 6 1 2\r\n", "output": "6"}, {"input": "1\r\n1\r\n", "output": "0"}, {"input": "1\r\n100\r\n", "output": "0"}, {"input": "205\r\n5 5 3 3 6 2 9 3 8 9 6 6 10 8 1 5 ... | false | stdio | null | true |
745/B | 745 | B | PyPy 3 | TESTS | 13 | 124 | 23,756,800 | 23057030 | import sys
def solve():
n, m = map(int, input().split())
A = {line.rstrip() for line in sys.stdin}
return len(A) == 1 or len(A) == 2 and '.'*n in A
print('YES' if solve() else 'NO') | 77 | 62 | 5,222,400 | 23055375 | n, m = map(int, input().split())
pu = [input() for i in range(n)]
cors = []
res = True
for string in pu:
if "X" in string:
if not len(cors):
cors = string.find("X"), string.rfind("X")
res = res and string.count("X") == (cors[1] - cors[0] + 1) and string[cors[0]:cors[1] + 1] == "X" * (cor... | Codeforces Round 385 (Div. 2) | CF | 2,016 | 2 | 256 | Hongcow Solves A Puzzle | Hongcow likes solving puzzles.
One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an n by m grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that th... | The first line of input will contain two integers n and m (1 ≤ n, m ≤ 500), the dimensions of the puzzle piece.
The next n lines will describe the jigsaw piece. Each line will have length m and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space.
It is gua... | Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise. | null | For the first sample, one example of a rectangle we can form is as follows
For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.
In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle: | [{"input": "2 3\nXXX\nXXX", "output": "YES"}, {"input": "2 2\n.X\nXX", "output": "NO"}, {"input": "5 5\n.....\n..X..\n.....\n.....\n.....", "output": "YES"}] | 1,400 | ["implementation"] | 77 | [{"input": "2 3\r\nXXX\r\nXXX\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n.X\r\nXX\r\n", "output": "NO\r\n"}, {"input": "5 5\r\n.....\r\n..X..\r\n.....\r\n.....\r\n.....\r\n", "output": "YES\r\n"}, {"input": "1 500\r\n.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX... | false | stdio | null | true |
623/C | 623 | C | PyPy 3-64 | TESTS | 16 | 530 | 20,684,800 | 164050222 | from sys import stdin, stdout, maxsize
from typing import List
def sdiameter_axes(axis_one, axes_two):
return int(pow(axis_one-axes_two, 2))
def sdiameter_xy(x, y):
return int(pow(x, 2))+int(pow(y, 2))
prefix_max_y = None
sufix_max_y = None
prefix_min_y =None
sufix_min_y = None
def check(D, n, points):
... | 176 | 1,450 | 23,449,600 | 164355894 | from sys import stdin, stdout, maxsize
from typing import List
def sdiameter_axes(axis_one, axes_two):
"""calcula el diametro**2 entre elementos de un mismo eje"""
return int(pow(axis_one-axes_two, 2))
def sdiameter_xy(x, y):
"""calcula el diametro**2 entre elementos de ambos ejes"""
return int(pow(x,... | AIM Tech Round (Div. 1) | CF | 2,016 | 2 | 256 | Electric Charges | Programmer Sasha is a student at MIPT (Moscow Institute of Physics and Technology) and he needs to make a laboratory work to pass his finals.
A laboratory unit is a plane with standard coordinate axes marked on it. Physicists from Moscow Institute of Physics and Technology charged the axes by large electric charges: a... | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of points marked on the plane.
Each of the next n lines contains two integers xi and yi ( - 108 ≤ xi, yi ≤ 108) — the coordinates of the i-th point. It is guaranteed that no two points coincide. | Print a single integer — the square of the minimum possible diameter of the set. | null | In the first sample Sasha puts electrons at all points, all particles eventually fall at a single point (1, 0).
In the second sample Sasha puts an electron at point (1, 10), and a proton at point (10, 1). The result is a set of two points (1, 0) and (0, 1), which has a diameter of $$\sqrt{2}$$. | [{"input": "3\n1 10\n1 20\n1 30", "output": "0"}, {"input": "2\n1 10\n10 1", "output": "2"}] | 2,900 | ["binary search", "dp"] | 176 | [{"input": "3\r\n1 10\r\n1 20\r\n1 30\r\n", "output": "0\r\n"}, {"input": "2\r\n1 10\r\n10 1\r\n", "output": "2\r\n"}, {"input": "10\r\n1 6\r\n2 2\r\n-1 9\r\n-8 8\r\n-4 10\r\n-10 -6\r\n5 -1\r\n-3 -7\r\n-4 3\r\n9 4\r\n", "output": "100\r\n"}, {"input": "18\r\n-14 -745\r\n87 -4611\r\n89 -3748\r\n-77 273\r\n-21 -4654\r\n-... | false | stdio | null | true |
623/A | 623 | A | Python 3 | TESTS | 25 | 561 | 13,516,800 | 52357662 | from collections import defaultdict
import queue
class GraphString():
def __init__(self, n, m, edges):
self.edge_list = defaultdict(list)
self.nonedge_list = defaultdict(list)
for x,y in edges:
self.edge_list[x-1].append(y-1)
self.edge_list[y-1].append(x-1)
... | 106 | 468 | 4,198,400 | 15809389 | def dfs(v):
visit[v] = cnt
for u in vertex[v]:
if not visit[u] and u in challengers:
dfs(u)
n, m = map(int, input().split())
vertex = [[] for i in range(n + 1)]
challengers = set()
ans = [''] * (n + 1)
middle = set()
for i in range(m):
a, b = map(int, input().split())
ve... | AIM Tech Round (Div. 1) | CF | 2,016 | 2 | 256 | Graph and String | One day student Vasya was sitting on a lecture and mentioned a string s1s2... sn, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph G with the following properties:
- G has exactly n vertices, numbered from 1 to n.... | The first line of the input contains two integers n and m $$( 1 \leq n \leq 500, 0 \leq m \leq \frac { n ( n - 1 ) } { 2 } )$$ — the number of vertices and edges in the graph found by Petya, respectively.
Each of the next m lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the edges of the graph G. It ... | In the first line print "Yes" (without the quotes), if the string s Petya is interested in really exists and "No" (without the quotes) otherwise.
If the string s exists, then print it on the second line of the output. The length of s must be exactly n, it must consist of only letters "a", "b" and "c" only, and the gra... | null | In the first sample you are given a graph made of two vertices with an edge between them. So, these vertices can correspond to both the same and adjacent letters. Any of the following strings "aa", "ab", "ba", "bb", "bc", "cb", "cc" meets the graph's conditions.
In the second sample the first vertex is connected to al... | [{"input": "2 1\n1 2", "output": "Yes\naa"}, {"input": "4 3\n1 2\n1 3\n1 4", "output": "No"}] | 1,800 | ["constructive algorithms", "graphs"] | 106 | [{"input": "2 1\r\n1 2\r\n", "output": "Yes\r\naa\r\n"}, {"input": "4 3\r\n1 2\r\n1 3\r\n1 4\r\n", "output": "No\r\n"}, {"input": "4 4\r\n1 2\r\n1 3\r\n1 4\r\n3 4\r\n", "output": "Yes\r\nbacc\r\n"}, {"input": "1 0\r\n", "output": "Yes\r\na\r\n"}, {"input": "8 28\r\n3 2\r\n4 2\r\n7 4\r\n6 3\r\n3 7\r\n8 1\r\n3 4\r\n5 1\r... | false | stdio | import sys
def main():
input_path = sys.argv[1]
ref_output_path = sys.argv[2]
sub_output_path = sys.argv[3]
# Read input
with open(input_path) as f:
n, m = map(int, f.readline().split())
edges = []
for _ in range(m):
u, v = map(int, f.readline().split())
... | true |
768/A | 768 | A | PyPy 3-64 | TESTS | 25 | 92 | 13,619,200 | 205762943 | n = int(input())
if n==1:
print(0)
else:
lst = list(map(int, input().split()))
a = min(lst)
b = max(lst)
a1 = lst.count(a)
b1 = lst.count(b)
print(len(lst) - a1 - b1) | 88 | 77 | 11,878,400 | 174716328 | n = input()
strength = [int(x) for x in input().split()]
min = min(strength)
max = max(strength)
counter = 0
for i in strength:
if i > min and i < max:
counter += 1
print(counter) | Divide by Zero 2017 and Codeforces Round 399 (Div. 1 + Div. 2, combined) | CF | 2,017 | 2 | 256 | Oath of the Night's Watch | "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I ple... | First line consists of a single integer n (1 ≤ n ≤ 105) — the number of stewards with Jon Snow.
Second line consists of n space separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) representing the values assigned to the stewards. | Output a single integer representing the number of stewards which Jon will feed. | null | In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are steward... | [{"input": "2\n1 5", "output": "0"}, {"input": "3\n1 2 5", "output": "1"}] | 900 | ["constructive algorithms", "sortings"] | 88 | [{"input": "2\r\n1 5\r\n", "output": "0"}, {"input": "3\r\n1 2 5\r\n", "output": "1"}, {"input": "4\r\n1 2 3 4\r\n", "output": "2"}, {"input": "8\r\n7 8 9 4 5 6 1 2\r\n", "output": "6"}, {"input": "1\r\n1\r\n", "output": "0"}, {"input": "1\r\n100\r\n", "output": "0"}, {"input": "205\r\n5 5 3 3 6 2 9 3 8 9 6 6 10 8 1 5 ... | false | stdio | null | true |
768/A | 768 | A | Python 3 | TESTS | 25 | 62 | 8,806,400 | 175689689 | n=int(input())
l=list(map(int,input().split()))
maxi=l.count(max(l))
mini=l.count(min(l))
if n==1:
print(0)
else:
print(n - maxi - mini) | 88 | 77 | 13,107,200 | 192579328 | n = int(input())
if n < 3:
print(0)
else:
count = 0
l = sorted([int(i) for i in input().split()])
for i in range(1,n-1):
count += 1 if l[0] < l[i] < l[-1] else 0
print(count) | Divide by Zero 2017 and Codeforces Round 399 (Div. 1 + Div. 2, combined) | CF | 2,017 | 2 | 256 | Oath of the Night's Watch | "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I ple... | First line consists of a single integer n (1 ≤ n ≤ 105) — the number of stewards with Jon Snow.
Second line consists of n space separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) representing the values assigned to the stewards. | Output a single integer representing the number of stewards which Jon will feed. | null | In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are steward... | [{"input": "2\n1 5", "output": "0"}, {"input": "3\n1 2 5", "output": "1"}] | 900 | ["constructive algorithms", "sortings"] | 88 | [{"input": "2\r\n1 5\r\n", "output": "0"}, {"input": "3\r\n1 2 5\r\n", "output": "1"}, {"input": "4\r\n1 2 3 4\r\n", "output": "2"}, {"input": "8\r\n7 8 9 4 5 6 1 2\r\n", "output": "6"}, {"input": "1\r\n1\r\n", "output": "0"}, {"input": "1\r\n100\r\n", "output": "0"}, {"input": "205\r\n5 5 3 3 6 2 9 3 8 9 6 6 10 8 1 5 ... | false | stdio | null | true |
745/B | 745 | B | Python 3 | TESTS | 32 | 764 | 32,870,400 | 23062053 | import sys
fin = sys.stdin
fout = sys.stdout
n, m = map(int, fin.readline().split())
fS = set()
temp = []
for i in range(n):
cur = fin.readline().strip()
for j in range(m):
if cur[j] == 'X':
fS.add((i, j))
temp.append((i, j))
minX = 10 ** 9
minY = 10 ** 9
maxX = -1
maxY = -1
fo... | 77 | 62 | 5,529,600 | 25954044 | #!/usr/bin/env python3
from sys import stdin,stdout
def ri():
return map(int, input().split())
n, m = ri()
found = 0
for i in range(n):
r = input()
if found == 0 and 'X' in r:
r0 = r
found = 1
continue
if found and 'X' in r:
if r != r0:
print("NO")
... | Codeforces Round 385 (Div. 2) | CF | 2,016 | 2 | 256 | Hongcow Solves A Puzzle | Hongcow likes solving puzzles.
One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an n by m grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that th... | The first line of input will contain two integers n and m (1 ≤ n, m ≤ 500), the dimensions of the puzzle piece.
The next n lines will describe the jigsaw piece. Each line will have length m and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space.
It is gua... | Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise. | null | For the first sample, one example of a rectangle we can form is as follows
For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.
In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle: | [{"input": "2 3\nXXX\nXXX", "output": "YES"}, {"input": "2 2\n.X\nXX", "output": "NO"}, {"input": "5 5\n.....\n..X..\n.....\n.....\n.....", "output": "YES"}] | 1,400 | ["implementation"] | 77 | [{"input": "2 3\r\nXXX\r\nXXX\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n.X\r\nXX\r\n", "output": "NO\r\n"}, {"input": "5 5\r\n.....\r\n..X..\r\n.....\r\n.....\r\n.....\r\n", "output": "YES\r\n"}, {"input": "1 500\r\n.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX... | false | stdio | null | true |
711/B | 711 | B | Python 3 | TESTS | 6 | 31 | 0 | 195994193 | a = int(input())
if a==1:
print(1)
else:
list = []
sum1,sum2,sum3,sum4,sum5,sum6,sum7 = 0,0,0,0,0,0,0
for i in range(a):
a1 = str(input()).split()
if '0' in a1:
number1 = i
list.append(a1)
number2 = list[number1].index('0')
for i in range(a):
sum1 += i... | 147 | 233 | 6,246,400 | 20235445 | N = int(input())
if N == 1:
print(1)
exit()
mat = []
for i in range(N):
mat.append(list(map(int, input().split())))
if 0 in mat[i]:
zero_pos = (i, mat[i].index(0))
# 和を求めておく
if zero_pos[0] == 0:
v_sum = sum(mat[1])
else:
v_sum = sum(mat[0])
# 和から0を埋める
zero_row_sum = sum(mat[zero_pos[0]... | Codeforces Round 369 (Div. 2) | CF | 2,016 | 2 | 256 | Chris and Magic Square | ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid on the entrance which is filled with integers. Chris noticed that exactly one of the cells in the grid is empty, and to enter Udayland, they need to fill a positive integer into the empty cell.
Chris tried filling in ran... | The first line of the input contains a single integer n (1 ≤ n ≤ 500) — the number of rows and columns of the magic grid.
n lines follow, each of them contains n integers. The j-th number in the i-th of them denotes ai, j (1 ≤ ai, j ≤ 109 or ai, j = 0), the number in the i-th row and j-th column of the magic grid. If ... | Output a single integer, the positive integer x (1 ≤ x ≤ 1018) that should be filled in the empty cell so that the whole grid becomes a magic square. If such positive integer x does not exist, output - 1 instead.
If there are multiple solutions, you may print any of them. | null | In the first sample case, we can fill in 9 into the empty cell to make the resulting grid a magic square. Indeed,
The sum of numbers in each row is:
4 + 9 + 2 = 3 + 5 + 7 = 8 + 1 + 6 = 15.
The sum of numbers in each column is:
4 + 3 + 8 = 9 + 5 + 1 = 2 + 7 + 6 = 15.
The sum of numbers in the two diagonals is:
4 +... | [{"input": "3\n4 0 2\n3 5 7\n8 1 6", "output": "9"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 1 1\n1 1 1 1", "output": "1"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 2 1\n1 1 1 1", "output": "-1"}] | 1,400 | ["constructive algorithms", "implementation"] | 147 | [{"input": "3\r\n4 0 2\r\n3 5 7\r\n8 1 6\r\n", "output": "9\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 1 1\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 2 1\r\n1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 ... | false | stdio | null | true |
377/A | 377 | A | Python 3 | TESTS | 11 | 1,840 | 39,321,600 | 137868455 | def neighbors(x, y, stack, visited, g):
if x > 0 and g[x - 1][y] == '.' and (x + 1, y) not in visited:
stack.append((x - 1, y))
if x < r - 1 and g[x + 1][y] == '.' and (x + 1, y) not in visited:
stack.append((x + 1, y))
if y > 0 and g[x][y - 1] == '.' and (x, y - 1) not in visited:
s... | 89 | 155 | 26,624,000 | 208087161 | n,m,k=map(int,input().split())
MAP=[list(input().strip()) for i in range(n)]
USED=[[0]*m for i in range(n)]
empty=0
for i in range(n):
for j in range(m):
if MAP[i][j]==".":
empty+=1
x,y=i,j
rest=empty-k
USED[x][y]=1
count=1
Q=[(x,y)]
while Q:
x,y=Q.pop()
if count==rest... | Codeforces Round 222 (Div. 1) | CF | 2,013 | 2 | 256 | Maze | Pavel loves grid mazes. A grid maze is an n × m rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.
Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any oth... | The first line contains three integers n, m, k (1 ≤ n, m ≤ 500, 0 ≤ k < s), where n and m are the maze's height and width, correspondingly, k is the number of walls Pavel wants to add and letter s represents the number of empty cells in the original maze.
Each of the next n lines contains m characters. They describe t... | Print n lines containing m characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#").
It is guaranteed that a solution exists. If there are multiple solutions you can output any of them. | null | null | [{"input": "3 4 2\n#..#\n..#.\n#...", "output": "#.X#\nX.#.\n#..."}, {"input": "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#", "output": "#XXX\n#X#.\nX#..\n...#\n.#.#"}] | 1,600 | ["dfs and similar"] | 89 | [{"input": "3 4 2\r\n#..#\r\n..#.\r\n#...\r\n", "output": "#.X#\r\nX.#.\r\n#...\r\n"}, {"input": "5 4 5\r\n#...\r\n#.#.\r\n.#..\r\n...#\r\n.#.#\r\n", "output": "#XXX\r\n#X#.\r\nX#..\r\n...#\r\n.#.#\r\n"}, {"input": "3 3 2\r\n...\r\n.#.\r\n...\r\n", "output": "X..\r\nX#.\r\n...\r\n"}, {"input": "3 3 2\r\n#.#\r\n...\r\n#... | false | stdio | import sys
from collections import deque
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path) as f:
lines = f.readlines()
first_line = lines[0].strip().split()
n, m, k = map(int, first_line[:3])
original = [line.strip() ... | true |
671/A | 671 | A | PyPy 3-64 | TESTS | 40 | 826 | 13,004,800 | 151388139 | import math
class PoV:
def __init__(self,x,y):
self.x = x
self.y = y
def __sub__(self,o): return PoV(self.x-o.x,self.y-o.y)
def __abs__(self): return math.sqrt(self.x*self.x+self.y*self.y)
def mindet(a,b):
n = len(a)-1
pre = [0]*(n+1)
suf = [0]*(n+2)
pre[0] = float('inf... | 148 | 873 | 5,222,400 | 17867408 | from math import *
ax, ay, bx, by, cx, cy = [int(t) for t in input().split()]
n = int(input())
dist = 0
maxv = [[-inf, -inf], [-inf, -inf]]
index = [[0,0], [0,0]]
def update(d, idx, p):
global maxv, index
if d > maxv[p][0]:
maxv[p][1] = maxv[p][0]
index[p][1] = index[p][0]
maxv[p][0] =... | Codeforces Round 352 (Div. 1) | CF | 2,016 | 2 | 256 | Recycling Bottles | It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin.
We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). Both Adil and Bera can c... | First line of the input contains six integers ax, ay, bx, by, tx and ty (0 ≤ ax, ay, bx, by, tx, ty ≤ 109) — initial positions of Adil, Bera and recycling bin respectively.
The second line contains a single integer n (1 ≤ n ≤ 100 000) — the number of bottles on the ground.
Then follow n lines, each of them contains t... | Print one real number — the minimum possible total distance Adil and Bera need to walk in order to put all bottles into recycling bin. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checke... | null | Consider the first sample.
Adil will use the following path: $$(3,1)\rightarrow(2,1)\rightarrow(0,0)\rightarrow(1,1)\rightarrow(0,0)$$.
Bera will use the following path: $$(1,2)\rightarrow(2,3)\rightarrow(0,0)$$.
Adil's path will be $$1 + \sqrt{5} + \sqrt{2} + \sqrt{2}$$ units long, while Bera's path will be $$\sqrt... | [{"input": "3 1 1 2 0 0\n3\n1 1\n2 1\n2 3", "output": "11.084259940083"}, {"input": "5 0 4 2 2 0\n5\n5 2\n3 0\n5 5\n3 5\n3 3", "output": "33.121375178000"}] | 1,800 | ["dp", "geometry", "greedy", "implementation"] | 148 | [{"input": "3 1 1 2 0 0\r\n3\r\n1 1\r\n2 1\r\n2 3\r\n", "output": "11.084259940083\r\n"}, {"input": "5 0 4 2 2 0\r\n5\r\n5 2\r\n3 0\r\n5 5\r\n3 5\r\n3 3\r\n", "output": "33.121375178000\r\n"}, {"input": "107 50 116 37 104 118\r\n12\r\n16 78\r\n95 113\r\n112 84\r\n5 88\r\n54 85\r\n112 80\r\n19 98\r\n25 14\r\n48 76\r\n95... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path) as f:
correct = f.read().strip()
with open(submission_path) as f:
submission = f.read().strip()
try:
correct_val = float(correct)
subm... | true |
671/A | 671 | A | PyPy 3-64 | TESTS | 40 | 1,294 | 24,780,800 | 151384091 | import math
class PoV:
def __init__(self,x,y):
self.x = x
self.y = y
def __sub__(self,o): return PoV(self.x-o.x,self.y-o.y)
def __abs__(self): return math.sqrt(self.x*self.x+self.y*self.y)
def solv(tot,asave,bsave):
n = len(asave)
if n==1: return tot-max(0,max(asave[0][0],bsave[0][... | 148 | 904 | 22,528,000 | 17855831 | import math
def dst(p1, p2):
x1, y1 = p1
x2, y2 = p2
result = math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
return result
def min_dst(a, b, t, bs):
bottles = [(dst(t, x), dst(a, x), dst(b, x)) for x in bs]
full_dst = sum(2 * bot[0] for bot in bottles)
min_a = full_dst - bottles[0][0] + bo... | Codeforces Round 352 (Div. 1) | CF | 2,016 | 2 | 256 | Recycling Bottles | It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin.
We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). Both Adil and Bera can c... | First line of the input contains six integers ax, ay, bx, by, tx and ty (0 ≤ ax, ay, bx, by, tx, ty ≤ 109) — initial positions of Adil, Bera and recycling bin respectively.
The second line contains a single integer n (1 ≤ n ≤ 100 000) — the number of bottles on the ground.
Then follow n lines, each of them contains t... | Print one real number — the minimum possible total distance Adil and Bera need to walk in order to put all bottles into recycling bin. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checke... | null | Consider the first sample.
Adil will use the following path: $$(3,1)\rightarrow(2,1)\rightarrow(0,0)\rightarrow(1,1)\rightarrow(0,0)$$.
Bera will use the following path: $$(1,2)\rightarrow(2,3)\rightarrow(0,0)$$.
Adil's path will be $$1 + \sqrt{5} + \sqrt{2} + \sqrt{2}$$ units long, while Bera's path will be $$\sqrt... | [{"input": "3 1 1 2 0 0\n3\n1 1\n2 1\n2 3", "output": "11.084259940083"}, {"input": "5 0 4 2 2 0\n5\n5 2\n3 0\n5 5\n3 5\n3 3", "output": "33.121375178000"}] | 1,800 | ["dp", "geometry", "greedy", "implementation"] | 148 | [{"input": "3 1 1 2 0 0\r\n3\r\n1 1\r\n2 1\r\n2 3\r\n", "output": "11.084259940083\r\n"}, {"input": "5 0 4 2 2 0\r\n5\r\n5 2\r\n3 0\r\n5 5\r\n3 5\r\n3 3\r\n", "output": "33.121375178000\r\n"}, {"input": "107 50 116 37 104 118\r\n12\r\n16 78\r\n95 113\r\n112 84\r\n5 88\r\n54 85\r\n112 80\r\n19 98\r\n25 14\r\n48 76\r\n95... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path) as f:
correct = f.read().strip()
with open(submission_path) as f:
submission = f.read().strip()
try:
correct_val = float(correct)
subm... | true |
623/A | 623 | A | Python 3 | TESTS | 25 | 452 | 1,331,200 | 15981447 | #filename 623A Codeforce AIM Tech Round (Div. 1)
n, m = input().split()
n = int(n)
m = int(m)
a = n * [False]
for i in range(0,n):
a[i] = n * [False]
s = n * ['0']
adj = n * [0]
for i in range(0,m):
u, v = input().split()
u = int(u)-1
v = int(v)-1
a[u][v] = True
a[v][u] = True
adj[u] += 1
... | 106 | 498 | 12,390,400 | 15799752 | import sys
n, m = map(int, input().split())
graph = [set([i]) for i in range(n)]
for i in range(m):
i, j = map(int, input().split())
graph[i - 1].add(j - 1)
graph[j - 1].add(i - 1)
thebs = set()
for i in range(n):
if len(graph[i]) == n:
thebs.add(i)
aset = False
cset = False
theas = set()
thecs... | AIM Tech Round (Div. 1) | CF | 2,016 | 2 | 256 | Graph and String | One day student Vasya was sitting on a lecture and mentioned a string s1s2... sn, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph G with the following properties:
- G has exactly n vertices, numbered from 1 to n.... | The first line of the input contains two integers n and m $$( 1 \leq n \leq 500, 0 \leq m \leq \frac { n ( n - 1 ) } { 2 } )$$ — the number of vertices and edges in the graph found by Petya, respectively.
Each of the next m lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the edges of the graph G. It ... | In the first line print "Yes" (without the quotes), if the string s Petya is interested in really exists and "No" (without the quotes) otherwise.
If the string s exists, then print it on the second line of the output. The length of s must be exactly n, it must consist of only letters "a", "b" and "c" only, and the gra... | null | In the first sample you are given a graph made of two vertices with an edge between them. So, these vertices can correspond to both the same and adjacent letters. Any of the following strings "aa", "ab", "ba", "bb", "bc", "cb", "cc" meets the graph's conditions.
In the second sample the first vertex is connected to al... | [{"input": "2 1\n1 2", "output": "Yes\naa"}, {"input": "4 3\n1 2\n1 3\n1 4", "output": "No"}] | 1,800 | ["constructive algorithms", "graphs"] | 106 | [{"input": "2 1\r\n1 2\r\n", "output": "Yes\r\naa\r\n"}, {"input": "4 3\r\n1 2\r\n1 3\r\n1 4\r\n", "output": "No\r\n"}, {"input": "4 4\r\n1 2\r\n1 3\r\n1 4\r\n3 4\r\n", "output": "Yes\r\nbacc\r\n"}, {"input": "1 0\r\n", "output": "Yes\r\na\r\n"}, {"input": "8 28\r\n3 2\r\n4 2\r\n7 4\r\n6 3\r\n3 7\r\n8 1\r\n3 4\r\n5 1\r... | false | stdio | import sys
def main():
input_path = sys.argv[1]
ref_output_path = sys.argv[2]
sub_output_path = sys.argv[3]
# Read input
with open(input_path) as f:
n, m = map(int, f.readline().split())
edges = []
for _ in range(m):
u, v = map(int, f.readline().split())
... | true |
798/B | 798 | B | PyPy 3 | TESTS | 6 | 78 | 1,536,000 | 146234712 | import collections
n = int(input())
l = []
for i in range(n):
l.append(list(input()))
ans = 10 ** 8
f=0
for i in range(n):
y = 0
for j in range(n):
x = collections.deque(l[j])
while list(x) != l[i]:
a = x.popleft()
x.append(a)
y += 1
if y>=100:... | 99 | 62 | 102,400 | 194119639 | import sys,random,bisect
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush
from math import gcd
mod = int(1e9 + 7)
inf = int(1e20)
input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())
ii = lambda :int(input())
py = lambda ... | Codeforces Round 410 (Div. 2) | CF | 2,017 | 2 | 256 | Mike and strings | Mike has n strings s1, s2, ..., sn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec".
Now Mike asks himself: what... | The first line contains integer n (1 ≤ n ≤ 50) — the number of strings.
This is followed by n lines which contain a string each. The i-th line corresponding to string si. Lengths of strings are equal. Lengths of each string is positive and don't exceed 50. | Print the minimal number of moves Mike needs in order to make all the strings equal or print - 1 if there is no solution. | null | In the first sample testcase the optimal scenario is to perform operations in such a way as to transform all strings into "zwoxz". | [{"input": "4\nxzzwo\nzwoxz\nzzwox\nxzzwo", "output": "5"}, {"input": "2\nmolzv\nlzvmo", "output": "2"}, {"input": "3\nkc\nkc\nkc", "output": "0"}, {"input": "3\naa\naa\nab", "output": "-1"}] | 1,300 | ["brute force", "dp", "strings"] | 99 | [{"input": "4\r\nxzzwo\r\nzwoxz\r\nzzwox\r\nxzzwo\r\n", "output": "5\r\n"}, {"input": "2\r\nmolzv\r\nlzvmo\r\n", "output": "2\r\n"}, {"input": "3\r\nkc\r\nkc\r\nkc\r\n", "output": "0\r\n"}, {"input": "3\r\naa\r\naa\r\nab\r\n", "output": "-1\r\n"}, {"input": "3\r\nkwkb\r\nkbkw\r\nbkwk\r\n", "output": "3\r\n"}, {"input":... | false | stdio | null | true |
671/A | 671 | A | PyPy 3 | TESTS | 40 | 1,435 | 10,035,200 | 51802797 | R = lambda: map(int, input().split())
ax, ay, bx, by, tx, ty = R()
n = int(input())
dp = [[0] * (n + 1) for i in range(4)]
for i in range(n):
x, y = R()
da, db, dt = ((x - ax) ** 2 + (y - ay) ** 2) ** 0.5, ((x - bx) ** 2 + (y - by) ** 2) ** 0.5, ((x - tx) ** 2 + (y - ty) ** 2) ** 0.5
dp[0][i] = dp[0][i - 1]... | 148 | 935 | 18,636,800 | 47841542 | import math
ax, ay, bx, by, tx, ty = [int(coord) for coord in input().split()]
n = int(input())
x ,y = [], []
minDis = 0
diff1 = []
diff2 = []
for i in range(n):
xi, yi = [int(coord) for coord in input().split()]
x.append(xi)
y.append(yi)
disBin = math.sqrt((xi-tx)**2 + (yi-ty)**2)
... | Codeforces Round 352 (Div. 1) | CF | 2,016 | 2 | 256 | Recycling Bottles | It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin.
We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). Both Adil and Bera can c... | First line of the input contains six integers ax, ay, bx, by, tx and ty (0 ≤ ax, ay, bx, by, tx, ty ≤ 109) — initial positions of Adil, Bera and recycling bin respectively.
The second line contains a single integer n (1 ≤ n ≤ 100 000) — the number of bottles on the ground.
Then follow n lines, each of them contains t... | Print one real number — the minimum possible total distance Adil and Bera need to walk in order to put all bottles into recycling bin. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checke... | null | Consider the first sample.
Adil will use the following path: $$(3,1)\rightarrow(2,1)\rightarrow(0,0)\rightarrow(1,1)\rightarrow(0,0)$$.
Bera will use the following path: $$(1,2)\rightarrow(2,3)\rightarrow(0,0)$$.
Adil's path will be $$1 + \sqrt{5} + \sqrt{2} + \sqrt{2}$$ units long, while Bera's path will be $$\sqrt... | [{"input": "3 1 1 2 0 0\n3\n1 1\n2 1\n2 3", "output": "11.084259940083"}, {"input": "5 0 4 2 2 0\n5\n5 2\n3 0\n5 5\n3 5\n3 3", "output": "33.121375178000"}] | 1,800 | ["dp", "geometry", "greedy", "implementation"] | 148 | [{"input": "3 1 1 2 0 0\r\n3\r\n1 1\r\n2 1\r\n2 3\r\n", "output": "11.084259940083\r\n"}, {"input": "5 0 4 2 2 0\r\n5\r\n5 2\r\n3 0\r\n5 5\r\n3 5\r\n3 3\r\n", "output": "33.121375178000\r\n"}, {"input": "107 50 116 37 104 118\r\n12\r\n16 78\r\n95 113\r\n112 84\r\n5 88\r\n54 85\r\n112 80\r\n19 98\r\n25 14\r\n48 76\r\n95... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path) as f:
correct = f.read().strip()
with open(submission_path) as f:
submission = f.read().strip()
try:
correct_val = float(correct)
subm... | true |
671/A | 671 | A | PyPy 3-64 | TESTS | 40 | 1,278 | 23,654,400 | 151385031 | import math
class PoV:
def __init__(self,x,y):
self.x = x
self.y = y
def __sub__(self,o): return PoV(self.x-o.x,self.y-o.y)
def __abs__(self): return math.sqrt(self.x*self.x+self.y*self.y)
def maxsave(a,b):
if len(a)==1: return max(a[0][0],b[0][0])
if a[0][1]!=b[0][1]: ... | 148 | 967 | 4,300,800 | 20664257 | import sys
import math
def top2(sx, sy, tx, ty, n, px, py):
t1 = -1e18
p1 = -1
t2 = -1e18
p2 = -1
for i in range(n):
v = math.sqrt((px[i] - tx) ** 2 + (py[i] - ty) ** 2) - math.sqrt((px[i] - sx) ** 2 + (py[i] - sy) ** 2)
if v > t1:
t2 = t1
p2 = p1... | Codeforces Round 352 (Div. 1) | CF | 2,016 | 2 | 256 | Recycling Bottles | It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin.
We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). Both Adil and Bera can c... | First line of the input contains six integers ax, ay, bx, by, tx and ty (0 ≤ ax, ay, bx, by, tx, ty ≤ 109) — initial positions of Adil, Bera and recycling bin respectively.
The second line contains a single integer n (1 ≤ n ≤ 100 000) — the number of bottles on the ground.
Then follow n lines, each of them contains t... | Print one real number — the minimum possible total distance Adil and Bera need to walk in order to put all bottles into recycling bin. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checke... | null | Consider the first sample.
Adil will use the following path: $$(3,1)\rightarrow(2,1)\rightarrow(0,0)\rightarrow(1,1)\rightarrow(0,0)$$.
Bera will use the following path: $$(1,2)\rightarrow(2,3)\rightarrow(0,0)$$.
Adil's path will be $$1 + \sqrt{5} + \sqrt{2} + \sqrt{2}$$ units long, while Bera's path will be $$\sqrt... | [{"input": "3 1 1 2 0 0\n3\n1 1\n2 1\n2 3", "output": "11.084259940083"}, {"input": "5 0 4 2 2 0\n5\n5 2\n3 0\n5 5\n3 5\n3 3", "output": "33.121375178000"}] | 1,800 | ["dp", "geometry", "greedy", "implementation"] | 148 | [{"input": "3 1 1 2 0 0\r\n3\r\n1 1\r\n2 1\r\n2 3\r\n", "output": "11.084259940083\r\n"}, {"input": "5 0 4 2 2 0\r\n5\r\n5 2\r\n3 0\r\n5 5\r\n3 5\r\n3 3\r\n", "output": "33.121375178000\r\n"}, {"input": "107 50 116 37 104 118\r\n12\r\n16 78\r\n95 113\r\n112 84\r\n5 88\r\n54 85\r\n112 80\r\n19 98\r\n25 14\r\n48 76\r\n95... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path) as f:
correct = f.read().strip()
with open(submission_path) as f:
submission = f.read().strip()
try:
correct_val = float(correct)
subm... | true |
982/A | 982 | A | PyPy 3 | TESTS | 17 | 92 | 0 | 120791260 | n=int(input())
ar=input()
flag=True
if(n==1):
if(ar[0]=='0'):
flag=False
else:
for i in range(n):
if(i==0):
if(ar[i]==ar[i+1]):
flag=False
elif(i==(n-1)):
if(ar[i]==ar[i-1]):
flag=False
else:
if(ar[i]==ar[i+1] a... | 55 | 46 | 0 | 144351284 | n = int(input())
a = '0'+ input() +'0'
if '000'in a or '11' in a:
print("NO")
else:
print("Yes") | Codeforces Round 484 (Div. 2) | CF | 2,018 | 1 | 256 | Row | You're given a row with $$$n$$$ chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated.
2. It's impossible to seat one more person without violating the first rule.
The seating is given as a string consisting of zeros and ones ($$$0$$$ m... | The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of chairs.
The next line contains a string of $$$n$$$ characters, each of them is either zero or one, describing the seating. | Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No".
You are allowed to print letters in whatever case you'd like (uppercase or lowercase). | null | In sample case one the given seating is maximal.
In sample case two the person at chair three has a neighbour to the right.
In sample case three it is possible to seat yet another person into chair three. | [{"input": "3\n101", "output": "Yes"}, {"input": "4\n1011", "output": "No"}, {"input": "5\n10001", "output": "No"}] | 1,200 | ["brute force", "constructive algorithms"] | 55 | [{"input": "3\r\n101\r\n", "output": "Yes\r\n"}, {"input": "4\r\n1011\r\n", "output": "No\r\n"}, {"input": "5\r\n10001\r\n", "output": "No\r\n"}, {"input": "1\r\n0\r\n", "output": "No\r\n"}, {"input": "1\r\n1\r\n", "output": "Yes\r\n"}, {"input": "100\r\n01010010101010010100100101010010101001010010010010100101010100101... | false | stdio | null | true |
982/A | 982 | A | PyPy 3 | TESTS | 29 | 155 | 0 | 97257961 | import math
n = int(input())
s = input()
if len(s) <= 2:
if '1' not in s:
ans = 'No'
else:
ans = 'Yes'
else:
if '000' not in s and '11' not in s and s[:2] != '00' and s[-2:] != '00':
ans = 'Yes'
else:
ans = 'No'
print(ans) | 55 | 46 | 0 | 150225461 | x=int(input())
s='0'+input()+'0'
if '000' in s:
print('No')
elif '11' in s:
print('No')
else:
print('Yes') | Codeforces Round 484 (Div. 2) | CF | 2,018 | 1 | 256 | Row | You're given a row with $$$n$$$ chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated.
2. It's impossible to seat one more person without violating the first rule.
The seating is given as a string consisting of zeros and ones ($$$0$$$ m... | The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of chairs.
The next line contains a string of $$$n$$$ characters, each of them is either zero or one, describing the seating. | Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No".
You are allowed to print letters in whatever case you'd like (uppercase or lowercase). | null | In sample case one the given seating is maximal.
In sample case two the person at chair three has a neighbour to the right.
In sample case three it is possible to seat yet another person into chair three. | [{"input": "3\n101", "output": "Yes"}, {"input": "4\n1011", "output": "No"}, {"input": "5\n10001", "output": "No"}] | 1,200 | ["brute force", "constructive algorithms"] | 55 | [{"input": "3\r\n101\r\n", "output": "Yes\r\n"}, {"input": "4\r\n1011\r\n", "output": "No\r\n"}, {"input": "5\r\n10001\r\n", "output": "No\r\n"}, {"input": "1\r\n0\r\n", "output": "No\r\n"}, {"input": "1\r\n1\r\n", "output": "Yes\r\n"}, {"input": "100\r\n01010010101010010100100101010010101001010010010010100101010100101... | false | stdio | null | true |
525/C | 525 | C | PyPy 3 | TESTS | 84 | 311 | 33,075,200 | 24521521 | n=int(input())
a=[int(x) for x in input().split()]
a.sort()
l=0
r=0
ans=0
i=n-1
while i>=0:
if a[i]==a[i-1] or a[i]==a[i-1]+1:
if(l==0):
l=a[i-1]
else :
ans+=l*a[i-1]
l=0
i-=2
else:
... | 96 | 109 | 13,516,800 | 210301970 | n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
p,i,ans=[],1,0
while i<n:
if a[i-1]-a[i]==1:
p.append(a[i])
i+=1
elif a[i-1]==a[i]:
p.append(a[i])
i+=1
i+=1
for i in range(1,len(p),2):
ans+=p[i]*p[i-1]
print(ans) | Codeforces Round 297 (Div. 2) | CF | 2,015 | 2 | 256 | Ilya and Sticks | In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length li.
Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that maxi... | The first line of the input contains a positive integer n (1 ≤ n ≤ 105) — the number of the available sticks.
The second line of the input contains n positive integers li (2 ≤ li ≤ 106) — the lengths of the sticks. | The first line of the output must contain a single non-negative integer — the maximum total area of the rectangles that Ilya can make from the available sticks. | null | null | [{"input": "4\n2 4 4 2", "output": "8"}, {"input": "4\n2 2 3 5", "output": "0"}, {"input": "4\n100003 100004 100005 100006", "output": "10000800015"}] | 1,600 | ["greedy", "math", "sortings"] | 96 | [{"input": "4\r\n2 4 4 2\r\n", "output": "8\r\n"}, {"input": "4\r\n2 2 3 5\r\n", "output": "0\r\n"}, {"input": "4\r\n100003 100004 100005 100006\r\n", "output": "10000800015\r\n"}, {"input": "8\r\n5 3 3 3 3 4 4 4\r\n", "output": "25\r\n"}, {"input": "10\r\n123 124 123 124 2 2 2 2 9 9\r\n", "output": "15270\r\n"}, {"inp... | false | stdio | null | true |
730/I | 730 | I | Python 3 | TESTS | 3 | 62 | 614,400 | 22320896 | import timeit
def cin():
return list(map(int, input().split()))
def a():
return timeit.default_timer()
n,p,s = cin()
A=cin()
B=cin()
C=list(enumerate(A))
D=list(enumerate(B))
C.sort(key=lambda C:C[-1])
D.sort(key=lambda D:D[-1])
E=[A[i]+B[i] for i in range(n)]
F,G=[],[]
i,j=len(A)-1,len(B)-1
while len(F)<p or ... | 152 | 77 | 6,246,400 | 25329824 | #!/usr/bin/env python3
from itertools import accumulate
from heapq import heappop, heappush
def top(ppl_indices, vals, start):
Q = []
res = [0 for i in range(len(ppl_indices))]
for k, idx in enumerate(ppl_indices):
heappush(Q, -vals[idx])
if k >= start:
res[k] = res[k-1] - heap... | 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,016 | 2 | 512 | Olympiad in Programming and Sports | There are n students at Berland State University. Every student has two skills, each measured as a number: ai — the programming skill and bi — the sports skill.
It is announced that an Olympiad in programming and sports will be held soon. That's why Berland State University should choose two teams: one to take part in... | The first line contains three positive integer numbers n, p and s (2 ≤ n ≤ 3000, p + s ≤ n) — the number of students, the size of the programming team and the size of the sports team.
The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 3000), where ai is the programming skill of the i-th student.
T... | In the first line, print the the maximum strength of the university on the Olympiad. In the second line, print p numbers — the members of the programming team. In the third line, print s numbers — the members of the sports team.
The students are numbered from 1 to n as they are given in the input. All numbers printed ... | null | null | [{"input": "5 2 2\n1 3 4 5 2\n5 3 2 1 4", "output": "18\n3 4\n1 5"}, {"input": "4 2 2\n10 8 8 3\n10 7 9 4", "output": "31\n1 2\n3 4"}, {"input": "5 3 1\n5 2 5 1 7\n6 3 1 6 3", "output": "23\n1 3 5\n4"}] | 2,000 | ["dp", "flows", "graphs", "greedy"] | 152 | [{"input": "5 2 2\r\n1 3 4 5 2\r\n5 3 2 1 4\r\n", "output": "18\r\n3 4 \r\n1 5 \r\n"}, {"input": "4 2 2\r\n10 8 8 3\r\n10 7 9 4\r\n", "output": "31\r\n1 2 \r\n3 4 \r\n"}, {"input": "5 3 1\r\n5 2 5 1 7\r\n6 3 1 6 3\r\n", "output": "23\r\n1 3 5 \r\n4 \r\n"}, {"input": "2 1 1\r\n100 101\r\n1 100\r\n", "output": "200\r\n1 ... | false | stdio | import sys
def main():
input_path = sys.argv[1]
correct_output_path = sys.argv[2]
submission_output_path = sys.argv[3]
# Read input
with open(input_path) as f:
input_data = f.read().splitlines()
n, p, s = map(int, input_data[0].split())
a = list(map(int, input_data[1].split()))
... | true |
985/B | 985 | B | Python 3 | TESTS | 26 | 1,200 | 82,124,800 | 79340272 | while True:
try:
def solution(n, m):
light= set()
has = "NO"
lght = []
for i in range(n):
a = input()
tlt = []
for j in range(m):
if a[j] == '1':
tlt.append(j)
lght.append([[len(tlt)], tlt])
lght.sort()
prv = 0
#print(lght)
for i in range(n-1,-1,-1):
tlt =lght[i... | 67 | 78 | 819,200 | 175077513 | n,m=map(int,input().split())
a=[int(input(),2)for _ in range(n)]
s=t=0
for x in a:
t|=s&x;s|=x
print(('YES','NO')[all(x&s&~t for x in a)]) | Educational Codeforces Round 44 (Rated for Div. 2) | ICPC | 2,018 | 3 | 256 | Switches and Lamps | You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp.
Initially all m lamps are t... | The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2000) — the number of the switches and the number of the lamps.
The following n lines contain m characters each. The character ai, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise.
It is guaranteed that if you press all... | Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch. | null | null | [{"input": "4 5\n10101\n01000\n00111\n10000", "output": "YES"}, {"input": "4 5\n10100\n01000\n00110\n00101", "output": "NO"}] | 1,200 | ["implementation"] | 67 | [{"input": "4 5\r\n10101\r\n01000\r\n00111\r\n10000\r\n", "output": "YES\r\n"}, {"input": "4 5\r\n10100\r\n01000\r\n00110\r\n00101\r\n", "output": "NO\r\n"}, {"input": "1 5\r\n11111\r\n", "output": "NO\r\n"}, {"input": "10 1\r\n1\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n1\r\n", "output": "YES\r\n"}, {"input": "1 1\r\... | false | stdio | null | true |
515/B | 515 | B | Python 3 | TESTS | 27 | 92 | 819,200 | 107377350 | def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def MAP2():return map(float,input().split())
def LIST(): return list(map(int, input().split()))
def STRING(): return input()
import string
import sys
from heapq import heappop , heappush
from bisect import *
from ... | 56 | 46 | 0 | 150316382 | import math
n, m = map(int, input().split())
happy = None
b = list(map(int, input().split()))
if b[0]:
happy = b[1]
b = set(b[1:])
g = list(map(int, input().split()))
if g[0]:
happy = g[1] + n
b.update((x + n for x in g[1:]))
d = math.gcd(n, m)
happy = set()
parent = list(range(n + m))
def find(x):
while ... | Codeforces Round 292 (Div. 2) | CF | 2,015 | 2 | 256 | Drazil and His Happy Friends | Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites $$(i \bmod n)$$-th... | The first line contains two integer n and m (1 ≤ n, m ≤ 100).
The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi < n), denoting the list of indices of happy boys.
The third line conatins integer g (0 ≤ ... | If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No". | null | By $$i \bmod k$$ we define the remainder of integer division of i by k.
In first sample case:
- On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day.
- On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so no... | [{"input": "2 3\n0\n1 0", "output": "Yes"}, {"input": "2 4\n1 0\n1 2", "output": "No"}, {"input": "2 3\n1 0\n1 1", "output": "Yes"}] | 1,300 | ["brute force", "dsu", "meet-in-the-middle", "number theory"] | 56 | [{"input": "2 3\r\n0\r\n1 0\r\n", "output": "Yes\r\n"}, {"input": "2 4\r\n1 0\r\n1 2\r\n", "output": "No\r\n"}, {"input": "2 3\r\n1 0\r\n1 1\r\n", "output": "Yes\r\n"}, {"input": "16 88\r\n6 5 14 2 0 12 7\r\n30 21 64 35 79 74 39 63 44 81 73 0 27 33 69 12 86 46 20 25 55 52 7 58 23 5 60 32 41 50 82\r\n", "output": "Yes\r... | false | stdio | null | true |
515/B | 515 | B | PyPy 3 | TESTS | 27 | 140 | 20,172,800 | 86857156 | n,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
happyboy = {}
happygirl = {}
for i in range(1,len(a)):
happyboy[a[i]] = 1
for i in range(1,len(b)):
happygirl[b[i]] = 1
for i in range(n+m):
boy = i%n
girl = i%m
if (boy in happyboy) or (girl in... | 56 | 46 | 0 | 169689236 | def GCD(a, b):
remain = 0
while b != 0:
remain = a % b
a = b
b = remain
return a
if __name__ == "__main__":
nBoys, nGirls = map(int, input().split())
lstB = list(map(int, input().split()))
lstG = list(map(int, input().split()))
numUnhappy = nBoys + nGirls - lstB[0] -... | Codeforces Round 292 (Div. 2) | CF | 2,015 | 2 | 256 | Drazil and His Happy Friends | Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites $$(i \bmod n)$$-th... | The first line contains two integer n and m (1 ≤ n, m ≤ 100).
The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi < n), denoting the list of indices of happy boys.
The third line conatins integer g (0 ≤ ... | If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No". | null | By $$i \bmod k$$ we define the remainder of integer division of i by k.
In first sample case:
- On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day.
- On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so no... | [{"input": "2 3\n0\n1 0", "output": "Yes"}, {"input": "2 4\n1 0\n1 2", "output": "No"}, {"input": "2 3\n1 0\n1 1", "output": "Yes"}] | 1,300 | ["brute force", "dsu", "meet-in-the-middle", "number theory"] | 56 | [{"input": "2 3\r\n0\r\n1 0\r\n", "output": "Yes\r\n"}, {"input": "2 4\r\n1 0\r\n1 2\r\n", "output": "No\r\n"}, {"input": "2 3\r\n1 0\r\n1 1\r\n", "output": "Yes\r\n"}, {"input": "16 88\r\n6 5 14 2 0 12 7\r\n30 21 64 35 79 74 39 63 44 81 73 0 27 33 69 12 86 46 20 25 55 52 7 58 23 5 60 32 41 50 82\r\n", "output": "Yes\r... | false | stdio | null | true |
982/A | 982 | A | Python 3 | TESTS | 26 | 93 | 0 | 39684634 | n=int(input())
s=input()
c=0
if n==1 and s=='1':
print("Yes")
c=1
if c==0 and n==1 and s=='0':
print("No")
c=1
if c==0 and('11' in s or '000' in s):
print("No")
c=1
if c==0 and ('001' in s or '100' in s):
if '001' in s and s.index('001')==0:
print("No")
c=1
if c==... | 55 | 46 | 0 | 153864912 | n=int(input())
stringul=input()
if n==1:
if stringul=='1':
print("Yes")
else:
print("No")
else:
if '11' in stringul or '000' in stringul or stringul[0:2]=='00' or stringul[n-2:n]=='00':
print("No")
else:
print("Yes") | Codeforces Round 484 (Div. 2) | CF | 2,018 | 1 | 256 | Row | You're given a row with $$$n$$$ chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated.
2. It's impossible to seat one more person without violating the first rule.
The seating is given as a string consisting of zeros and ones ($$$0$$$ m... | The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of chairs.
The next line contains a string of $$$n$$$ characters, each of them is either zero or one, describing the seating. | Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No".
You are allowed to print letters in whatever case you'd like (uppercase or lowercase). | null | In sample case one the given seating is maximal.
In sample case two the person at chair three has a neighbour to the right.
In sample case three it is possible to seat yet another person into chair three. | [{"input": "3\n101", "output": "Yes"}, {"input": "4\n1011", "output": "No"}, {"input": "5\n10001", "output": "No"}] | 1,200 | ["brute force", "constructive algorithms"] | 55 | [{"input": "3\r\n101\r\n", "output": "Yes\r\n"}, {"input": "4\r\n1011\r\n", "output": "No\r\n"}, {"input": "5\r\n10001\r\n", "output": "No\r\n"}, {"input": "1\r\n0\r\n", "output": "No\r\n"}, {"input": "1\r\n1\r\n", "output": "Yes\r\n"}, {"input": "100\r\n01010010101010010100100101010010101001010010010010100101010100101... | false | stdio | null | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.