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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
131/B | 131 | B | Python 3 | TESTS | 2 | 62 | 0 | 223026897 | num = int(input())
rawData = input().split()
dict = {}
count = 0
while len(rawData) > 0:
val = int(rawData[-1]) # get top val
amount = 1
if val not in dict:
dict[val] = 0
if val * -1 in dict:
count = count + 1
rawData.pop()
print(count) | 43 | 154 | 8,294,400 | 224169631 | d={}
input()
k=0
for i in map(int,input().split()):k+=d.get(-i,0);d[i]=d.get(i,0)+1
print(k) | Codeforces Beta Round 95 (Div. 2) | CF | 2,011 | 2 | 256 | Opposites Attract | Everybody knows that opposites attract. That is the key principle of the "Perfect Matching" dating agency. The "Perfect Matching" matchmakers have classified each registered customer by his interests and assigned to the i-th client number ti ( - 10 ≤ ti ≤ 10). Of course, one number can be assigned to any number of cust... | The first line of the input data contains an integer n (1 ≤ n ≤ 105) which represents the number of registered clients of the "Couple Matching". The second line contains a sequence of integers t1, t2, ..., tn ( - 10 ≤ ti ≤ 10), ti — is the parameter of the i-th customer that has been assigned to the customer by the res... | Print the number of couples of customs with opposite t. The opposite number for x is number - x (0 is opposite to itself). Couples that only differ in the clients' order are considered the same.
Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, ... | null | In the first sample the couples of opposite clients are: (1,2), (1,5) и (3,4).
In the second sample any couple of clients is opposite. | [{"input": "5\n-3 3 0 0 3", "output": "3"}, {"input": "3\n0 0 0", "output": "3"}] | 1,200 | ["implementation", "math"] | 43 | [{"input": "5\r\n-3 3 0 0 3\r\n", "output": "3\r\n"}, {"input": "3\r\n0 0 0\r\n", "output": "3\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n5\r\n", "output": "0\r\n"}, {"input": "2\r\n0 0\r\n", "output": "1\r\n"}, {"input": "2\r\n-3 3\r\n", "output": "1\r\n"}, {"input": "2\r\n1 5\r\n", "output": "... | false | stdio | null | true |
518/B | 518 | B | Python 3 | TESTS | 9 | 280 | 921,600 | 186657297 | s = input()
t = input()
y = 0
w = 0
s1 = {i: 0 for i in s if i.islower()}
s2 = {i: 0 for i in s if i.isupper()}
t1 = {i: 0 for i in t if i.islower()}
t2 = {i: 0 for i in t if i.isupper()}
s3 = {i: 0 for i in s.lower()}
t3 = {i: 0 for i in t.lower()}
for i in s:
if i.isupper():
s2[i] += 1
else:
... | 49 | 77 | 819,200 | 167842189 | import sys
import collections
c, d = map(collections.Counter, sys.stdin.readlines())
a = -1
b = 0
for x in [0, 32]:
for k, v in c.items():
K = chr(ord(k) ^ x)
t = min(v, d[K])
c[k] -= t
d[K] -= t
a += t
a, b = b, a
print(a, b) | Codeforces Round 293 (Div. 2) | CF | 2,015 | 2 | 256 | Tanya and Postcard | Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The... | The first line contains line s (1 ≤ |s| ≤ 2·105), consisting of uppercase and lowercase English letters — the text of Tanya's message.
The second line contains line t (|s| ≤ |t| ≤ 2·105), consisting of uppercase and lowercase English letters — the text written in the newspaper.
Here |a| means the length of the string... | Print two integers separated by a space:
- the first number is the number of times Tanya shouts "YAY!" while making the message,
- the second number is the number of times Tanya says "WHOOPS" while making the message. | null | null | [{"input": "AbC\nDCbA", "output": "3 0"}, {"input": "ABC\nabc", "output": "0 3"}, {"input": "abacaba\nAbaCaBA", "output": "3 4"}] | 1,400 | ["greedy", "implementation", "strings"] | 49 | [{"input": "AbC\r\nDCbA\r\n", "output": "3 0\r\n"}, {"input": "ABC\r\nabc\r\n", "output": "0 3\r\n"}, {"input": "abacaba\r\nAbaCaBA\r\n", "output": "3 4\r\n"}, {"input": "zzzzz\r\nZZZZZ\r\n", "output": "0 5\r\n"}, {"input": "zzzZZZ\r\nZZZzzZ\r\n", "output": "5 1\r\n"}, {"input": "abcdefghijklmnopqrstuvwxyz\r\nABCDEFGHI... | false | stdio | null | true |
107/A | 107 | A | Python 3 | TESTS | 4 | 31 | 0 | 195071546 | n, p = map(int, input().split())
num_list1 = []
num_list2 = []
ab = []
for i in range(p):
a, b, d = map(int, input().split())
num_list1.append(a)
num_list2.append(b)
ab.append(d)
fir = []
sec = []
for i in range(len(num_list2)):
if num_list1[i] not in num_list2:
fir.append((num_list1[i], a... | 38 | 62 | 614,400 | 197445049 | import heapq;
import math;
from collections import deque, Counter;
import sys;
mod = 998244353;
input = sys.stdin.readline;
n, p = map(int, input().split())
inDegree = [0 for node in range(n)]
neighbourNodes = [[] for i in range(n)]
for i in range(p):
path, toPath, di = map(int, input().split())
nei... | Codeforces Beta Round 83 (Div. 1 Only) | CF | 2,011 | 1 | 256 | Dorm Water Supply | The German University in Cairo (GUC) dorm houses are numbered from 1 to n. Underground water pipes connect these houses together. Each pipe has certain direction (water can flow only in this direction and not vice versa), and diameter (which characterizes the maximal amount of water it can handle).
For each house, the... | The first line contains two space-separated integers n and p (1 ≤ n ≤ 1000, 0 ≤ p ≤ n) — the number of houses and the number of pipes correspondingly.
Then p lines follow — the description of p pipes. The i-th line contains three integers ai bi di, indicating a pipe of diameter di going from house ai to house bi (1 ≤ ... | Print integer t in the first line — the number of tank-tap pairs of houses.
For the next t lines, print 3 integers per line, separated by spaces: tanki, tapi, and diameteri, where tanki ≠ tapi (1 ≤ i ≤ t). Here tanki and tapi are indexes of tank and tap houses respectively, and diameteri is the maximum amount of water... | null | null | [{"input": "3 2\n1 2 10\n2 3 20", "output": "1\n1 3 10"}, {"input": "3 3\n1 2 20\n2 3 10\n3 1 5", "output": "0"}, {"input": "4 2\n1 2 60\n3 4 50", "output": "2\n1 2 60\n3 4 50"}] | 1,400 | ["dfs and similar", "graphs"] | 38 | [{"input": "3 2\r\n1 2 10\r\n2 3 20\r\n", "output": "1\n1 3 10\n"}, {"input": "3 3\r\n1 2 20\r\n2 3 10\r\n3 1 5\r\n", "output": "0\n"}, {"input": "4 2\r\n1 2 60\r\n3 4 50\r\n", "output": "2\n1 2 60\n3 4 50\n"}, {"input": "10 10\r\n10 3 70\r\n1 9 98\r\n9 10 67\r\n5 2 78\r\n8 6 71\r\n4 8 95\r\n7 1 10\r\n2 5 73\r\n6 7 94\... | false | stdio | null | true |
696/A | 696 | A | Python 3 | TESTS | 3 | 124 | 1,740,800 | 65348207 | import sys
#l = sys.stdin.read(1)
def f(a,b):
if a == b: return a
if a < b: a,b = b,a
return f(int(a/2), b)
q = int(input())
mmap = {}
for i in range(q):
res = 0
l = [int(j) for j in input().split()]
a = max(l[1], l[2])
b = min(l[1], l[2])
ind = f(a, b)
if l[0] == 1:
k = a
... | 49 | 108 | 9,523,200 | 177716850 | import sys
input = sys.stdin.readline
def f(a, b, c):
x = 0
while a != b:
if a < b:
a, b = b, a
if c != 0:
d[a] = d.get(a, 0) + c
else:
x += d.get(a,0)
a //= 2
return x
d = {}
for _ in range(int(input())):
w = list(map(int, input().... | Codeforces Round 362 (Div. 1) | CF | 2,016 | 1 | 256 | Lorenzo Von Matterhorn | Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections i and 2i and another road between i and 2i + 1 for every positive integer i. You can clearly see that there exists a unique shortest path between any two... | The first line of input contains a single integer q (1 ≤ q ≤ 1 000).
The next q lines contain the information about the events in chronological order. Each event is described in form 1 v u w if it's an event when government makes a new rule about increasing the passing fee of all roads on the shortest path from u to v... | For each event of second type print the sum of passing fee of all roads Barney passes in this event, in one line. Print the answers in chronological order of corresponding events. | null | In the example testcase:
Here are the intersections used:
1. Intersections on the path are 3, 1, 2 and 4.
2. Intersections on the path are 4, 2 and 1.
3. Intersections on the path are only 3 and 6.
4. Intersections on the path are 4, 2, 1 and 3. Passing fee of roads on the path are 32, 32 and 30 in order. So answer e... | [{"input": "7\n1 3 4 30\n1 4 1 2\n1 3 6 8\n2 4 3\n1 6 1 40\n2 3 7\n2 2 4", "output": "94\n0\n32"}] | 1,500 | ["brute force", "data structures", "implementation", "trees"] | 49 | [{"input": "7\r\n1 3 4 30\r\n1 4 1 2\r\n1 3 6 8\r\n2 4 3\r\n1 6 1 40\r\n2 3 7\r\n2 2 4\r\n", "output": "94\r\n0\r\n32\r\n"}, {"input": "1\r\n2 666077344481199252 881371880336470888\r\n", "output": "0\r\n"}, {"input": "10\r\n1 1 63669439577744021 396980128\r\n1 2582240553355225 63669439577744021 997926286\r\n1 258224055... | false | stdio | null | true |
779/C | 779 | C | Python 3 | TESTS | 9 | 249 | 10,547,200 | 25140212 | lineOne = input()
dataOne = lineOne.split()
n = int(dataOne[0])
rightNow = int(dataOne[1])
lTwo = input()
discount = [int(i) for i in lTwo.split()]
lThree = input()
after = [int(i) for i in lThree.split()]
diff = [None] * n
ans = 0
# For each item get the cheaper one
k = 0
for i in range(n):
if discount[i] <= a... | 67 | 249 | 18,022,400 | 191060924 | def buys(a: list, b: list, n: int, k: int) -> int:
count_sum = sum(a) # сколько потратит, если купит все товары сразу
for i in range(n):
b[i] = b[i] - a[i] # посмотрим какие товары дешевле во вторую неделю
b = sorted(b) # отсортируем по возрастанию товары второй недели чтобы взять сначала те ... | Codeforces Round 402 (Div. 2) | CF | 2,017 | 2 | 256 | Dishonest Sellers | Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi.
Not all of sellers are honest, so now some products could be more expensive than after a week of discou... | In the first line there are two positive integer numbers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — total number of items to buy and minimal number of items Igor wants to by right now.
The second line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 104) — prices of items during discounts (i.e. right now).
The third... | Print the minimal amount of money Igor will spend to buy all n items. Remember, he should buy at least k items right now. | null | In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10.
In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week ... | [{"input": "3 1\n5 4 6\n3 1 5", "output": "10"}, {"input": "5 3\n3 4 7 10 3\n4 5 5 12 5", "output": "25"}] | 1,200 | ["constructive algorithms", "greedy", "sortings"] | 67 | [{"input": "3 1\r\n5 4 6\r\n3 1 5\r\n", "output": "10\r\n"}, {"input": "5 3\r\n3 4 7 10 3\r\n4 5 5 12 5\r\n", "output": "25\r\n"}, {"input": "1 0\r\n9\r\n8\r\n", "output": "8\r\n"}, {"input": "2 0\r\n4 10\r\n1 2\r\n", "output": "3\r\n"}, {"input": "4 2\r\n19 5 17 13\r\n3 18 8 10\r\n", "output": "29\r\n"}, {"input": "5 ... | false | stdio | null | true |
63/A | 63 | A | Python 3 | TESTS | 25 | 92 | 0 | 178123948 | a=int(input())
massive,massive1,massive2,massive3=[ ],[ ],[ ],[ ]
for i in range(a):
s=input()
if 'woman' in s: massive.append(s[:-6])
if 'child' in s: massive.append(s[:-6])
if 'rat' in s:
massive1.append(s[:-4])
if ' man' in s: massive2.append(s[:-4])
if 'captain' in s: massive3.append... | 26 | 62 | 0 | 209961462 | n= int (input())
x=[]
d={'captain':4,'woman':2,'man':3,'rat':1,'child':2}
for i in range(n):
name, type_= input().split()
x.append([ name, d[type_]])
z=sorted(x,key=lambda x:x[1])
for i in z:
print(i[0]) | Codeforces Beta Round 59 (Div. 2) | CF | 2,011 | 2 | 256 | Sinking Ship | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict o... | The first line contains an integer n, which is the number of people in the crew (1 ≤ n ≤ 100). Then follow n lines. The i-th of those lines contains two words — the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the lin... | Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship. | null | null | [{"input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman", "output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack"}] | 900 | ["implementation", "sortings", "strings"] | 26 | [{"input": "6\r\nJack captain\r\nAlice woman\r\nCharlie man\r\nTeddy rat\r\nBob child\r\nJulia woman\r\n", "output": "Teddy\r\nAlice\r\nBob\r\nJulia\r\nCharlie\r\nJack\r\n"}, {"input": "1\r\nA captain\r\n", "output": "A\r\n"}, {"input": "1\r\nAbcdefjhij captain\r\n", "output": "Abcdefjhij\r\n"}, {"input": "5\r\nA capta... | false | stdio | null | true |
381/A | 381 | A | Python 3 | TESTS | 10 | 31 | 0 | 225075617 | n = int(input())
cards = list(map(int,input().split(" ")))
S = 0
D = 0
while n > 0:
if n%2 == 0:
if cards[0] < cards[-1]:
S += cards[-1]
cards.remove(cards[-1])
n-=1
else:
S += cards[0]
cards.remove(cards[0])
n-=1
else :
if cards[0] < cards[-1]:
D += cards[-1... | 34 | 31 | 0 | 181229004 | t = int(input())
x = list(map(int, input().split()))
a=0
b=-1
sereja=0
dima=0
for i in range(t):
if i%2==0:
if x[a]>x[b]:
sereja+=x[a]
a+=1
else:
sereja+=x[b]
b-=1
elif i%2!=0:
if x[a]>x[b]:
dima+=x[a]
a+=1
else:
dima+=x[b]
b-=1
print(sereja,dima) | Codeforces Round 223 (Div. 2) | CF | 2,014 | 1 | 256 | Sereja and Dima | Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The ... | The first line contains integer n (1 ≤ n ≤ 1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | null | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | [{"input": "4\n4 1 2 10", "output": "12 5"}, {"input": "7\n1 2 3 4 5 6 7", "output": "16 12"}] | 800 | ["greedy", "implementation", "two pointers"] | 34 | [{"input": "4\r\n4 1 2 10\r\n", "output": "12 5\r\n"}, {"input": "7\r\n1 2 3 4 5 6 7\r\n", "output": "16 12\r\n"}, {"input": "42\r\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13\r\n", "output": "613 418\r\n"}, {"input": "43\r\n32 1 15 48 38 26 25 1... | false | stdio | null | true |
381/A | 381 | A | PyPy 3-64 | TESTS | 10 | 62 | 1,228,800 | 206161642 | def game_count(n, arr):
i = 0
j = n-1
c = []
while i <= j:
if arr[i] >= arr[j]:
c.append(arr[i])
i += 1
else:
c.append(arr[j])
j -= 1
s1 = max(sum(c[::2]), sum(c[1::2]))
return s1, sum(c) - s1
n = int(input())
arr = list(map(int, ... | 34 | 31 | 0 | 182744270 | import sys
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp(): # one integer input
return(int(input()))
def inlt(): # list input
return(list(map(int,input().split())))
def insr(): # string input
s = input()
return(list(s[:len(s) - 1]))
def invr(): # muliple integer... | Codeforces Round 223 (Div. 2) | CF | 2,014 | 1 | 256 | Sereja and Dima | Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The ... | The first line contains integer n (1 ≤ n ≤ 1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | null | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | [{"input": "4\n4 1 2 10", "output": "12 5"}, {"input": "7\n1 2 3 4 5 6 7", "output": "16 12"}] | 800 | ["greedy", "implementation", "two pointers"] | 34 | [{"input": "4\r\n4 1 2 10\r\n", "output": "12 5\r\n"}, {"input": "7\r\n1 2 3 4 5 6 7\r\n", "output": "16 12\r\n"}, {"input": "42\r\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13\r\n", "output": "613 418\r\n"}, {"input": "43\r\n32 1 15 48 38 26 25 1... | false | stdio | null | true |
381/A | 381 | A | Python 3 | TESTS | 10 | 62 | 0 | 203691672 | n=int(input())
m=list(map(int, input().split()))
a=0
b=0
i=len(m)-1
while i>=0:
if i%2==0:
if m[i]>=m[0]:
b+=m[i]
m.remove(m[i])
else:
b+=m[0]
m.remove(m[0])
else:
if m[i]>=m[0]:
a+=m[i]
m.remove(m[i])
else:
... | 34 | 31 | 0 | 193215056 | n = int(input())
arr = list(map(int,input().split()))
i,j=0,n-1
s,d,t=0,0,1
while(i<=j):
if(arr[i]>arr[j]):
m=arr[i]
i+=1
else:
m=arr[j]
j-=1
if t==1:
s+=m
else:
d+=m
t = 1-t
print(s,d) | Codeforces Round 223 (Div. 2) | CF | 2,014 | 1 | 256 | Sereja and Dima | Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The ... | The first line contains integer n (1 ≤ n ≤ 1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | null | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | [{"input": "4\n4 1 2 10", "output": "12 5"}, {"input": "7\n1 2 3 4 5 6 7", "output": "16 12"}] | 800 | ["greedy", "implementation", "two pointers"] | 34 | [{"input": "4\r\n4 1 2 10\r\n", "output": "12 5\r\n"}, {"input": "7\r\n1 2 3 4 5 6 7\r\n", "output": "16 12\r\n"}, {"input": "42\r\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13\r\n", "output": "613 418\r\n"}, {"input": "43\r\n32 1 15 48 38 26 25 1... | false | stdio | null | true |
381/A | 381 | A | Python 3 | TESTS | 10 | 46 | 0 | 207020307 | a = int(input())
b= list(map(int, input().split(' ')))
first = 0
second = 0
while b:
if b[-1] > b[0]:
first += b.pop(-1)
else:
first += b.pop(0)
if b:
if b[-1] > b[0]:
second += b.pop(-1)
else:
second += b.pop(0)
print(max(first, second), min(first, se... | 34 | 31 | 0 | 198787423 | n = int(input())
value = list(map(int, input().split()))
left= 0
right= n - 1
s = 0
d = 0
p = True
while left<= right:
if value[left] >= value[right]:
if p:
s += value[left]
else:
d += value[left]
left+= 1
elif value[right] > value[left]:
if p:
... | Codeforces Round 223 (Div. 2) | CF | 2,014 | 1 | 256 | Sereja and Dima | Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The ... | The first line contains integer n (1 ≤ n ≤ 1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | null | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | [{"input": "4\n4 1 2 10", "output": "12 5"}, {"input": "7\n1 2 3 4 5 6 7", "output": "16 12"}] | 800 | ["greedy", "implementation", "two pointers"] | 34 | [{"input": "4\r\n4 1 2 10\r\n", "output": "12 5\r\n"}, {"input": "7\r\n1 2 3 4 5 6 7\r\n", "output": "16 12\r\n"}, {"input": "42\r\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13\r\n", "output": "613 418\r\n"}, {"input": "43\r\n32 1 15 48 38 26 25 1... | false | stdio | null | true |
381/A | 381 | A | Python 3 | TESTS | 10 | 46 | 0 | 216201082 | import sys
a = int(input(''))
b = [int(i) for i in sys.stdin.readline().split()]
c = 0
d = 0
for i in range(0, a):
if b[0] >= b[-1] :
if i % 2 == a % 2:
c += b[0]
del b[0]
else:
d += b[0]
del b[0]
else:
if i % 2 == a % 2:
c += ... | 34 | 31 | 0 | 206785889 | n = int(input())
x = input().split()
x1,x2 = 0,0
left,right = 0, n-1
lst = []
while left <= right:
for i in range(n):
if i % 2 == 0:
if int(x[left]) > int(x[right]):
x1 += int(x[left])
left += 1
else:
x1 += int(x[right])
... | Codeforces Round 223 (Div. 2) | CF | 2,014 | 1 | 256 | Sereja and Dima | Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The ... | The first line contains integer n (1 ≤ n ≤ 1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | null | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | [{"input": "4\n4 1 2 10", "output": "12 5"}, {"input": "7\n1 2 3 4 5 6 7", "output": "16 12"}] | 800 | ["greedy", "implementation", "two pointers"] | 34 | [{"input": "4\r\n4 1 2 10\r\n", "output": "12 5\r\n"}, {"input": "7\r\n1 2 3 4 5 6 7\r\n", "output": "16 12\r\n"}, {"input": "42\r\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13\r\n", "output": "613 418\r\n"}, {"input": "43\r\n32 1 15 48 38 26 25 1... | false | stdio | null | true |
381/A | 381 | A | Python 3 | TESTS | 10 | 46 | 0 | 218366374 | n = int(input().strip())
cards = [int(x) for x in input().strip().split()]
left = 0
right = 0
p1 = 0
p2 = len(cards) -1
toggle = True
while p1<= p2:
if(toggle):
left+= max(cards[p1],cards[p2])
toggle=not toggle
else:
right+= max(cards[p1],cards[p2])
toggle=not toggle
... | 34 | 31 | 0 | 206953900 | n = int(input())
x = list(map(int, input().split()))
s = 0
d = 0
f = 1
while len(x) != 0:
if f == 1:
f = 0
if x[0] > x[-1]:
s += x[0]
x.pop(0)
else:
s += x[-1]
x.pop(-1)
else:
f = 1
if x[0] > x[-1]:
d += x[0]
... | Codeforces Round 223 (Div. 2) | CF | 2,014 | 1 | 256 | Sereja and Dima | Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The ... | The first line contains integer n (1 ≤ n ≤ 1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | null | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | [{"input": "4\n4 1 2 10", "output": "12 5"}, {"input": "7\n1 2 3 4 5 6 7", "output": "16 12"}] | 800 | ["greedy", "implementation", "two pointers"] | 34 | [{"input": "4\r\n4 1 2 10\r\n", "output": "12 5\r\n"}, {"input": "7\r\n1 2 3 4 5 6 7\r\n", "output": "16 12\r\n"}, {"input": "42\r\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13\r\n", "output": "613 418\r\n"}, {"input": "43\r\n32 1 15 48 38 26 25 1... | false | stdio | null | true |
381/A | 381 | A | Python 3 | TESTS | 10 | 46 | 0 | 227680752 | number_of_cards = int(input())
cards = list(map(int, input().split()))
sereja = 0
dima = 0
for i in range(len(cards)):
first = cards[0]
last = cards[-1]
if i % 2 == 0:
sereja += max(first, last)
else:
dima += max(first, last)
cards.remove(max(first, last))
print(max(sereja, dima), mi... | 34 | 31 | 0 | 207374833 | n = int(input())
s =0
d =0
idx1 = 0
idx2 = n-1
a = list(map(int,input().split()))
for i in range(n):
if i % 2 ==0:
s+= max(a[idx1], a[idx2])
else:
d += max(a[idx1], a[idx2])
if max(a[idx1], a[idx2]) == a[idx1]:
idx1 += 1
else:
idx2 -= 1
print(s,d) | Codeforces Round 223 (Div. 2) | CF | 2,014 | 1 | 256 | Sereja and Dima | Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The ... | The first line contains integer n (1 ≤ n ≤ 1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | null | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | [{"input": "4\n4 1 2 10", "output": "12 5"}, {"input": "7\n1 2 3 4 5 6 7", "output": "16 12"}] | 800 | ["greedy", "implementation", "two pointers"] | 34 | [{"input": "4\r\n4 1 2 10\r\n", "output": "12 5\r\n"}, {"input": "7\r\n1 2 3 4 5 6 7\r\n", "output": "16 12\r\n"}, {"input": "42\r\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13\r\n", "output": "613 418\r\n"}, {"input": "43\r\n32 1 15 48 38 26 25 1... | false | stdio | null | true |
294/B | 294 | B | PyPy 3 | TESTS | 7 | 155 | 307,200 | 75346335 | from bisect import bisect_left as bl, bisect_right as br, insort
import sys
import heapq
#from math import *
from collections import defaultdict as dd, deque
def data(): return sys.stdin.readline().strip()
def mdata(): return map(int, data().split())
#def print(x): return sys.stdout.write(str(x)+'\n')
#sys.setrecursion... | 27 | 155 | 1,945,600 | 57929203 | from operator import itemgetter
class CodeforcesTask294BSolution:
def __init__(self):
self.result = ''
self.books_count = 0
self.books_dims = []
def read_input(self):
self.books_count = int(input())
for x in range(self.books_count):
self.books_dims.append([... | Codeforces Round 178 (Div. 2) | CF | 2,013 | 1 | 256 | Shaass and Bookshelf | Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is ti and its pages' width is equal to wi. The thickness of each book is either 1 or 2. All books have the same page heights.
Shaass puts the books on the b... | The first line of the input contains an integer n, (1 ≤ n ≤ 100). Each of the next n lines contains two integers ti and wi denoting the thickness and width of the i-th book correspondingly, (1 ≤ ti ≤ 2, 1 ≤ wi ≤ 100). | On the only line of the output print the minimum total thickness of the vertical books that we can achieve. | null | null | [{"input": "5\n1 12\n1 3\n2 15\n2 5\n2 1", "output": "5"}, {"input": "3\n1 10\n2 1\n2 4", "output": "3"}] | 1,700 | ["dp", "greedy"] | 27 | [{"input": "5\r\n1 12\r\n1 3\r\n2 15\r\n2 5\r\n2 1\r\n", "output": "5\r\n"}, {"input": "3\r\n1 10\r\n2 1\r\n2 4\r\n", "output": "3\r\n"}, {"input": "10\r\n2 10\r\n2 4\r\n2 8\r\n2 3\r\n2 5\r\n2 6\r\n1 2\r\n1 10\r\n1 10\r\n2 5\r\n", "output": "12\r\n"}, {"input": "1\r\n2 7\r\n", "output": "2\r\n"}, {"input": "20\r\n2 4\r... | false | stdio | null | true |
412/B | 412 | B | Python 3 | PRETESTS | 2 | 46 | 0 | 6407928 | def check(mid, n, k, p):
r = {}
for i in p:
if i > mid:
i = mid
if r.get(i) is None:
r[i] = 1
else:
r[i] += 1
for key, value in r.items():
if value >= k:
return True
return False
def binsearch(n, k, p):
l = 0
r = ma... | 34 | 46 | 0 | 144002609 | def func():
n,m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
print(a[n-m])
def main():
print('ok or exit: ')
while input() != 'exit':
print('execute.')
func()
print('ok or exit: ')
#main()
func() | Coder-Strike 2014 - Round 1 | CF | 2,014 | 1 | 256 | Network Configuration | The R1 company wants to hold a web search championship. There were n computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly affects the result. The higher the speed of the Internet is, the faster the participant will find the necessar... | The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 100) — the number of computers and the number of participants, respectively. In the second line you have a space-separated sequence consisting of n integers: a1, a2, ..., an (16 ≤ ai ≤ 32768); number ai denotes the maximum data transfer speed on ... | Print a single integer — the maximum Internet speed value. It is guaranteed that the answer to the problem is always an integer. | null | In the first test case the organizers can cut the first computer's speed to 30 kilobits. Then two computers (the first and the third one) will have the same speed of 30 kilobits. They should be used as the participants' computers. This answer is optimal. | [{"input": "3 2\n40 20 30", "output": "30"}, {"input": "6 4\n100 20 40 20 50 50", "output": "40"}] | 900 | ["greedy", "sortings"] | 34 | [{"input": "3 2\r\n40 20 30\r\n", "output": "30\r\n"}, {"input": "6 4\r\n100 20 40 20 50 50\r\n", "output": "40\r\n"}, {"input": "1 1\r\n16\r\n", "output": "16\r\n"}, {"input": "2 1\r\n10000 17\r\n", "output": "10000\r\n"}, {"input": "2 2\r\n200 300\r\n", "output": "200\r\n"}, {"input": "3 1\r\n21 25 16\r\n", "output":... | false | stdio | null | true |
902/B | 902 | B | PyPy 3-64 | TESTS | 35 | 842 | 9,113,600 | 223288524 | from sys import stdin
readl = stdin.readline
n = int(readl())
p = list(map(int, readl().split()))
c = list(map(int, readl().split()))
adj = [[] for _ in range(n+1)]
for i in range(n-1):
adj[p[i]].append(i+1)
adj[i+2].append(p[i]-1)
adj.pop(0)
def dfs(node: int):
s = [node]
while s:
... | 50 | 46 | 921,600 | 165700988 | #!/usr/bin/env python3
import sys
import math
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_ls(): return list(map(int, sys.stdin.readline().strip().split()))
def test_ok(ok): print("YES" if ok else "NO")
def main():
# for _ in range(int(input())):
n = int(input())
p... | Codeforces Round 453 (Div. 2) | CF | 2,017 | 1 | 256 | Coloring a Tree | You are given a rooted tree with n vertices. The vertices are numbered from 1 to n, the root is the vertex number 1.
Each vertex has a color, let's denote the color of vertex v by cv. Initially cv = 0.
You have to color the tree into the given colors using the smallest possible number of steps. On each step you can c... | The first line contains a single integer n (2 ≤ n ≤ 104) — the number of vertices in the tree.
The second line contains n - 1 integers p2, p3, ..., pn (1 ≤ pi < i), where pi means that there is an edge between vertices i and pi.
The third line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ n), where ci is the color yo... | Print a single integer — the minimum number of steps you have to perform to color the tree into given colors. | null | The tree from the first sample is shown on the picture (numbers are vetices' indices):
On first step we color all vertices in the subtree of vertex 1 into color 2 (numbers are colors):
On seond step we color all vertices in the subtree of vertex 5 into color 1:
On third step we color all vertices in the subtree of v... | [{"input": "6\n1 2 2 1 5\n2 1 1 1 1 1", "output": "3"}, {"input": "7\n1 1 2 3 1 4\n3 3 1 1 1 2 3", "output": "5"}] | 1,200 | ["dfs and similar", "dsu", "greedy"] | 50 | [{"input": "6\r\n1 2 2 1 5\r\n2 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "7\r\n1 1 2 3 1 4\r\n3 3 1 1 1 2 3\r\n", "output": "5\r\n"}, {"input": "2\r\n1\r\n2 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 1\r\n2 2 2\r\n", "output": "1\r\n"}, {"input": "4\r\n1 2 1\r\n1 2 3 4\r\n", "output": "4\r\n"}, {"input": "4\r\n... | false | stdio | null | true |
696/A | 696 | A | Python 3 | TESTS | 37 | 202 | 20,172,800 | 129765248 | import bisect
import collections
import copy
import enum
import functools
import heapq
import itertools
import math
import random
import re
import sys
import time
import string
from typing import List
r = collections.defaultdict(int)
def f(x):
return int(math.log2(x))
q = int(input())
for _ in range(q):
o... | 49 | 109 | 4,608,000 | 19448984 | def main():
d = {}
for _ in range(int(input())):
c, *l = input().split()
if c == "1":
v, u, w = map(int, l)
while u != v:
if u < v:
d[v] = d.get(v, 0) + w
u, v = v // 2, u
else:
d[... | Codeforces Round 362 (Div. 1) | CF | 2,016 | 1 | 256 | Lorenzo Von Matterhorn | Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections i and 2i and another road between i and 2i + 1 for every positive integer i. You can clearly see that there exists a unique shortest path between any two... | The first line of input contains a single integer q (1 ≤ q ≤ 1 000).
The next q lines contain the information about the events in chronological order. Each event is described in form 1 v u w if it's an event when government makes a new rule about increasing the passing fee of all roads on the shortest path from u to v... | For each event of second type print the sum of passing fee of all roads Barney passes in this event, in one line. Print the answers in chronological order of corresponding events. | null | In the example testcase:
Here are the intersections used:
1. Intersections on the path are 3, 1, 2 and 4.
2. Intersections on the path are 4, 2 and 1.
3. Intersections on the path are only 3 and 6.
4. Intersections on the path are 4, 2, 1 and 3. Passing fee of roads on the path are 32, 32 and 30 in order. So answer e... | [{"input": "7\n1 3 4 30\n1 4 1 2\n1 3 6 8\n2 4 3\n1 6 1 40\n2 3 7\n2 2 4", "output": "94\n0\n32"}] | 1,500 | ["brute force", "data structures", "implementation", "trees"] | 49 | [{"input": "7\r\n1 3 4 30\r\n1 4 1 2\r\n1 3 6 8\r\n2 4 3\r\n1 6 1 40\r\n2 3 7\r\n2 2 4\r\n", "output": "94\r\n0\r\n32\r\n"}, {"input": "1\r\n2 666077344481199252 881371880336470888\r\n", "output": "0\r\n"}, {"input": "10\r\n1 1 63669439577744021 396980128\r\n1 2582240553355225 63669439577744021 997926286\r\n1 258224055... | false | stdio | null | true |
343/C | 343 | C | PyPy 3-64 | TESTS | 2 | 93 | 5,836,800 | 182176593 | import sys
import threading
# input=sys.stdin.readline
from collections import Counter,defaultdict,deque
from heapq import heappush,heappop,heapify
#threading.stack_size(10**8)
#sys.setrecursionlimit(10**6)
def ri():return int(input())
def rs():return input()
def rl():return list(map(int,input().split()))
def rls():re... | 61 | 233 | 20,172,800 | 181283739 | # Read Time
import sys
input = sys.stdin.buffer.readline
n, m = map(int, input().split())
h = list(map(int, input().split()))
p = list(map(int, input().split()))
# minimmum time for h_i to cover all p_s...p_e
def min_t(h_i, p_s, p_e):
return min(abs(h[h_i]-p[p_s]),abs(h[h_i]-p[p_e])) + (p[p_e]-p[p_s])
# if all... | Codeforces Round 200 (Div. 1) | CF | 2,013 | 1 | 256 | Read Time | Mad scientist Mike does not use slow hard disks. His modification of a hard drive has not one, but n different heads that can read data in parallel.
When viewed from the side, Mike's hard drive is an endless array of tracks. The tracks of the array are numbered from left to right with integers, starting with 1. In the... | The first line of the input contains two space-separated integers n, m (1 ≤ n, m ≤ 105) — the number of disk heads and the number of tracks to read, accordingly. The second line contains n distinct integers hi in ascending order (1 ≤ hi ≤ 1010, hi < hi + 1) — the initial positions of the heads. The third line contains ... | Print a single number — the minimum time required, in seconds, to read all the needed tracks. | null | The first test coincides with the figure. In this case the given tracks can be read in 2 seconds in the following way:
1. during the first second move the 1-st head to the left and let it stay there;
2. move the second head to the left twice;
3. move the third head to the right twice (note that the 6-th track has alre... | [{"input": "3 4\n2 5 6\n1 3 6 8", "output": "2"}, {"input": "3 3\n1 2 3\n1 2 3", "output": "0"}, {"input": "1 2\n165\n142 200", "output": "81"}] | 1,900 | ["binary search", "greedy", "two pointers"] | 61 | [{"input": "3 4\r\n2 5 6\r\n1 3 6 8\r\n", "output": "2\r\n"}, {"input": "3 3\r\n1 2 3\r\n1 2 3\r\n", "output": "0\r\n"}, {"input": "1 2\r\n165\r\n142 200\r\n", "output": "81\r\n"}, {"input": "1 2\r\n5000000000\r\n1 10000000000\r\n", "output": "14999999998\r\n"}, {"input": "2 4\r\n3 12\r\n1 7 8 14\r\n", "output": "8\r\n... | false | stdio | null | true |
780/C | 780 | C | Python 3 | TESTS | 24 | 997 | 166,400,000 | 125745404 | from collections import defaultdict
import threading
from sys import stdin, setrecursionlimit
input = stdin.readline
setrecursionlimit(10 ** 6)
def dfs(node, par, g, color):
# color[node]=res
st = set([color[par]])
res = 1
while res==color[node] or res==color[par]:
res+=1
for i in g[node]:
if i != par:
c... | 73 | 467 | 52,121,600 | 212955346 | import sys
input = sys.stdin.readline
n = int(input())
d = [[] for i in range(n+1)]
for i in range(n-1):
a, b = map(int, input().split())
d[a].append(b)
d[b].append(a)
t = max(len(i)+1 for i in d)
x = [0]*(n+1)
x[1] = 1
q = [(1, -1)]
while q:
a, b = q.pop()
s = {x[a], x[b] if b != -1 else 0}
c... | Технокубок 2017 - Финал (только для онсайт-финалистов) | CF | 2,017 | 2 | 256 | Andryusha and Colored Balloons | Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he decided to decorate them.
The park consists of n squares connected with (n - 1) bidirectional paths in such a way that any square is reachable from any other using these paths. Andryusha decided to hang a colored... | The first line contains single integer n (3 ≤ n ≤ 2·105) — the number of squares in the park.
Each of the next (n - 1) lines contains two integers x and y (1 ≤ x, y ≤ n) — the indices of two squares directly connected by a path.
It is guaranteed that any square is reachable from any other using the paths. | In the first line print single integer k — the minimum number of colors Andryusha has to use.
In the second line print n integers, the i-th of them should be equal to the balloon color on the i-th square. Each of these numbers should be within range from 1 to k. | null | In the first sample the park consists of three squares: 1 → 3 → 2. Thus, the balloon colors have to be distinct.
Illustration for the first sample.
In the second example there are following triples of consequently connected squares:
- 1 → 3 → 2
- 1 → 3 → 4
- 1 → 3 → 5
- 2 → 3 → 4
- 2 → 3 → 5
- 4 → 3 → 5
Illustratio... | [{"input": "3\n2 3\n1 3", "output": "3\n1 3 2"}, {"input": "5\n2 3\n5 3\n4 3\n1 3", "output": "5\n1 3 2 5 4"}, {"input": "5\n2 1\n3 2\n4 3\n5 4", "output": "3\n1 2 3 1 2"}] | 1,600 | ["dfs and similar", "graphs", "greedy", "trees"] | 73 | [{"input": "3\r\n2 3\r\n1 3\r\n", "output": "3\r\n1 3 2 "}, {"input": "5\r\n2 3\r\n5 3\r\n4 3\r\n1 3\r\n", "output": "5\r\n1 3 2 5 4 "}, {"input": "5\r\n2 1\r\n3 2\r\n4 3\r\n5 4\r\n", "output": "3\r\n1 2 3 1 2 "}, {"input": "10\r\n5 3\r\n9 2\r\n7 1\r\n3 8\r\n4 1\r\n1 9\r\n10 1\r\n8 9\r\n6 2\r\n", "output": "5\r\n1 2 1 ... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path, 'r') as f:
n = int(f.readline())
adj = [[] for _ in range(n+1)]
for _ in range(n-1):
x, y = map(int, f.readline().split())
adj[x... | true |
696/A | 696 | A | Python 3 | TESTS | 3 | 109 | 512,000 | 46683315 | lines = dict()
def get_parent(a):
if a % 2 == 0:
return int(a / 2)
else:
return int((a - 1) / 2)
def generate_way(u, v):
way = set()
while u != v:
# print(str(u) + ' ' + str(v))
if u < v:
p = get_parent(v)
way.add(str(p) + '_' + str(v))
... | 49 | 140 | 4,608,000 | 20797689 | q = int(input())
price = {}
def get_price(u):
if u in price:
return price[u]
else:
return 0
for i in range(0, q):
temp = str(input()).split(' ')
u = int(temp[1])
v = int(temp[2])
if temp[0] == "2":
res = 0
while u != v:
if u > v... | Codeforces Round 362 (Div. 1) | CF | 2,016 | 1 | 256 | Lorenzo Von Matterhorn | Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections i and 2i and another road between i and 2i + 1 for every positive integer i. You can clearly see that there exists a unique shortest path between any two... | The first line of input contains a single integer q (1 ≤ q ≤ 1 000).
The next q lines contain the information about the events in chronological order. Each event is described in form 1 v u w if it's an event when government makes a new rule about increasing the passing fee of all roads on the shortest path from u to v... | For each event of second type print the sum of passing fee of all roads Barney passes in this event, in one line. Print the answers in chronological order of corresponding events. | null | In the example testcase:
Here are the intersections used:
1. Intersections on the path are 3, 1, 2 and 4.
2. Intersections on the path are 4, 2 and 1.
3. Intersections on the path are only 3 and 6.
4. Intersections on the path are 4, 2, 1 and 3. Passing fee of roads on the path are 32, 32 and 30 in order. So answer e... | [{"input": "7\n1 3 4 30\n1 4 1 2\n1 3 6 8\n2 4 3\n1 6 1 40\n2 3 7\n2 2 4", "output": "94\n0\n32"}] | 1,500 | ["brute force", "data structures", "implementation", "trees"] | 49 | [{"input": "7\r\n1 3 4 30\r\n1 4 1 2\r\n1 3 6 8\r\n2 4 3\r\n1 6 1 40\r\n2 3 7\r\n2 2 4\r\n", "output": "94\r\n0\r\n32\r\n"}, {"input": "1\r\n2 666077344481199252 881371880336470888\r\n", "output": "0\r\n"}, {"input": "10\r\n1 1 63669439577744021 396980128\r\n1 2582240553355225 63669439577744021 997926286\r\n1 258224055... | false | stdio | null | true |
75/C | 75 | C | PyPy 3 | TESTS | 15 | 374 | 3,584,000 | 74193400 | import math
from sys import *
from bisect import bisect_left
input=stdin.readline
print=stdout.write
a,b=map(int,input().split())
n=int(input())
gcd=math.gcd(a,b)
factors=[]
i=1
while(i*i<=gcd):
if gcd%i==0:
factors.append(gcd//i)
if (i*i)!=gcd:
factors.append(gcd//(gcd//i))
i+=1
facto... | 60 | 280 | 7,577,600 | 126272425 | a, b = list(map(int,input().strip().split()))[:2]
q = []
n = int(input())
for i in range(n):
q.append(tuple(map(int,input().strip().split()))[:2])
if a < b:
a, b = b, a
while b > 0:
b, a = a % b, b
def divisors(n) :
l1 = []
i = 1
while i*i <= n:
if (n % i == 0) :
l... | Codeforces Beta Round 67 (Div. 2) | CF | 2,011 | 2 | 256 | Modified GCD | Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task... | The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109). | Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query. | null | null | [{"input": "9 27\n3\n1 5\n10 11\n9 11", "output": "3\n-1\n9"}] | 1,600 | ["binary search", "number theory"] | 60 | [{"input": "9 27\r\n3\r\n1 5\r\n10 11\r\n9 11\r\n", "output": "3\r\n-1\r\n9\r\n"}, {"input": "48 72\r\n2\r\n8 29\r\n29 37\r\n", "output": "24\r\n-1\r\n"}, {"input": "90 100\r\n10\r\n51 61\r\n6 72\r\n1 84\r\n33 63\r\n37 69\r\n18 21\r\n9 54\r\n49 90\r\n14 87\r\n37 90\r\n", "output": "-1\r\n10\r\n10\r\n-1\r\n-1\r\n-1\r\n1... | false | stdio | null | true |
151/B | 151 | B | Python 3 | TESTS | 32 | 46 | 0 | 206252001 | n = int(input())
x={}
for i in range(n) :
nb , name = map(str , input().split() )
mx_tascore , max_pizzsco , max_girsco = 0 ,0 , 0
for j in range(int(nb)) :
number = input()
nb_copy = [int(i) for i in number if i !="-" ]
nb_copy1 = sorted(nb_copy,reverse=True)
if nb_copy ==... | 38 | 140 | 5,836,800 | 199201525 | def taxi(st):
if st[0]*6==st:
return True
return False
def pizza(st):
ele=int(st[0])
for i in range(1,6):
if int(st[i])>=ele:
return False
else:
ele=int(st[i])
return True
final={}
for _ in range(int(input())):
n,name=input().split()
n=int(n)... | Codeforces Round 107 (Div. 2) | CF | 2,012 | 2 | 256 | Phone Numbers | Winters are just damn freezing cold in Nvodsk! That's why a group of n friends prefers to take a taxi, order a pizza and call girls. The phone numbers in the city consist of three pairs of digits (for example, 12-34-56). Each friend has a phonebook of size si (that's the number of phone numbers). We know that taxi numb... | The first line contains an integer n (1 ≤ n ≤ 100) — the number of friends.
Then follow n data blocks that describe each friend's phone books. Each block is presented in the following form: first goes the line that contains integer si and string namei (0 ≤ si ≤ 100) — the number of phone numbers in the phone book of t... | In the first line print the phrase "If you want to call a taxi, you should call: ". Then print names of all friends whose phone books contain maximal number of taxi phone numbers.
In the second line print the phrase "If you want to order a pizza, you should call: ". Then print names of all friends who have maximal num... | null | In the first sample you are given four friends. Fedorov's phone book contains one taxi number and one pizza delivery number, Melnikov's phone book only has 3 numbers of girls, Rogulenko's one has 6 taxi numbers and one pizza delivery number, Kaluzhin's one contains 2 taxi numbers and one pizza delivery number.
Thus, i... | [{"input": "4\n2 Fedorov\n22-22-22\n98-76-54\n3 Melnikov\n75-19-09\n23-45-67\n99-99-98\n7 Rogulenko\n22-22-22\n11-11-11\n33-33-33\n44-44-44\n55-55-55\n66-66-66\n95-43-21\n3 Kaluzhin\n11-11-11\n99-99-99\n98-65-32", "output": "If you want to call a taxi, you should call: Rogulenko.\nIf you want to order a pizza, you shou... | 1,200 | ["implementation", "strings"] | 38 | [{"input": "4\r\n2 Fedorov\r\n22-22-22\r\n98-76-54\r\n3 Melnikov\r\n75-19-09\r\n23-45-67\r\n99-99-98\r\n7 Rogulenko\r\n22-22-22\r\n11-11-11\r\n33-33-33\r\n44-44-44\r\n55-55-55\r\n66-66-66\r\n95-43-21\r\n3 Kaluzhin\r\n11-11-11\r\n99-99-99\r\n98-65-32\r\n", "output": "If you want to call a taxi, you should call: Rogulenk... | false | stdio | null | true |
739/A | 739 | A | PyPy 3 | TESTS | 4 | 124 | 20,172,800 | 80269323 | from sys import stdin
#n=int(stdin.readline().strip())
n,m=map(int,stdin.readline().strip().split())
l1=0
r1=0
t=10**7
s=[]
for i in range(m):
l,r=map(int,stdin.readline().strip().split())
s.append([l,r])
s.sort()
for i in range(m):
l,r=s[i]
if(r-l<t):
l1=l
r1=r
ans=[0 for i in ... | 69 | 327 | 10,240,000 | 72127487 | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
a = 10**18
for _ in range(m):
l, r = map(int, input().split())
a = min(a, r-l+1)
print(a)
ans = [-1]*n
for i in range(n):
ans[i] = i%a
print(*ans) | Codeforces Round 381 (Div. 1) | CF | 2,016 | 2 | 256 | Alyona and mex | Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the array. The i-th subarray is described with two integers li and ri, ... | The first line contains two integers n and m (1 ≤ n, m ≤ 105).
The next m lines contain information about the subarrays chosen by Alyona. The i-th of these lines contains two integers li and ri (1 ≤ li ≤ ri ≤ n), that describe the subarray a[li], a[li + 1], ..., a[ri]. | In the first line print single integer — the maximum possible minimum mex.
In the second line print n integers — the array a. All the elements in a should be between 0 and 109.
It is guaranteed that there is an optimal answer in which all the elements in a are between 0 and 109.
If there are multiple solutions, prin... | null | The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2. | [{"input": "5 3\n1 3\n2 5\n4 5", "output": "2\n1 0 2 1 0"}, {"input": "4 2\n1 4\n2 4", "output": "3\n5 2 0 1"}] | 1,700 | ["constructive algorithms", "greedy"] | 69 | [{"input": "5 3\r\n1 3\r\n2 5\r\n4 5\r\n", "output": "2\r\n0 1 0 1 0\r\n"}, {"input": "4 2\r\n1 4\r\n2 4\r\n", "output": "3\r\n0 1 2 0\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "1\r\n0\r\n"}, {"input": "2 1\r\n2 2\r\n", "output": "1\r\n0 0\r\n"}, {"input": "5 6\r\n2 4\r\n2 3\r\n1 4\r\n3 4\r\n2 5\r\n1 3\r\n", "output... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input
with open(input_path, 'r') as f:
n, m = map(int, f.readline().split())
subarrays = [tuple(map(int, line.strip().split())) for line in f]
# Read reference output... | true |
739/A | 739 | A | PyPy 3 | TESTS | 4 | 124 | 0 | 49851262 | from operator import itemgetter
n,m = map(int,input().split())
ans = 0
for i in range(m):
l,r = map(int,input().split())
num = r - l + 1
print(num)
for i in range(n):
print(i % num,end=" ") | 69 | 374 | 9,318,400 | 22447825 | def main():
n, m = map(int, input().split())
res = []
for _ in range(m):
lo, hi = map(int, input().split())
res.append(hi - lo)
mi = min(res) + 1
aa = list(range(mi)) * ((n + mi - 1) // mi)
print(mi)
print(' '.join(map(str, aa[:n])))
if __name__ == '__main__':
main() | Codeforces Round 381 (Div. 1) | CF | 2,016 | 2 | 256 | Alyona and mex | Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the array. The i-th subarray is described with two integers li and ri, ... | The first line contains two integers n and m (1 ≤ n, m ≤ 105).
The next m lines contain information about the subarrays chosen by Alyona. The i-th of these lines contains two integers li and ri (1 ≤ li ≤ ri ≤ n), that describe the subarray a[li], a[li + 1], ..., a[ri]. | In the first line print single integer — the maximum possible minimum mex.
In the second line print n integers — the array a. All the elements in a should be between 0 and 109.
It is guaranteed that there is an optimal answer in which all the elements in a are between 0 and 109.
If there are multiple solutions, prin... | null | The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2. | [{"input": "5 3\n1 3\n2 5\n4 5", "output": "2\n1 0 2 1 0"}, {"input": "4 2\n1 4\n2 4", "output": "3\n5 2 0 1"}] | 1,700 | ["constructive algorithms", "greedy"] | 69 | [{"input": "5 3\r\n1 3\r\n2 5\r\n4 5\r\n", "output": "2\r\n0 1 0 1 0\r\n"}, {"input": "4 2\r\n1 4\r\n2 4\r\n", "output": "3\r\n0 1 2 0\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "1\r\n0\r\n"}, {"input": "2 1\r\n2 2\r\n", "output": "1\r\n0 0\r\n"}, {"input": "5 6\r\n2 4\r\n2 3\r\n1 4\r\n3 4\r\n2 5\r\n1 3\r\n", "output... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input
with open(input_path, 'r') as f:
n, m = map(int, f.readline().split())
subarrays = [tuple(map(int, line.strip().split())) for line in f]
# Read reference output... | true |
325/C | 325 | C | PyPy 3 | TESTS | 9 | 1,558 | 49,152,000 | 99358320 | import sys, heapq
_BLANCO, _GRIS, _NEGRO = 0, 1, 2
_OO = int(1e18)
def esUnaReglaMala(r, adj, d):
for u, diamsOMult in adj[r]:
if d[u] == _OO:
return True
return False
def dfsVisit(u, color, adj, diamMax, d):
color[u] = _GRIS
#diamMax[u] = 0
for v, diamsOMult in adj[u]:
... | 43 | 1,152 | 25,292,800 | 99273309 | import sys
_BLANCO, _GRIS, _NEGRO = 0, 1, 2
_OO = int(1e18)
class Regla:
def __init__(self, id, diamantes, deMonstruo, monstruos):
self.id = id
self.diamantes = diamantes
self.deMonstruo = deMonstruo
self.monstruos = monstruos
def esUnaMalaRegla(r, d):
for m in r.monstruos:
... | MemSQL start[c]up Round 1 | CF | 2,013 | 2 | 256 | Monsters and Diamonds | Piegirl has found a monster and a book about monsters and pies. When she is reading the book, she found out that there are n types of monsters, each with an ID between 1 and n. If you feed a pie to a monster, the monster will split into some number of monsters (possibly zero), and at least one colorful diamond. Monster... | The first line contains two integers: m and n (1 ≤ m, n ≤ 105), the number of possible splits and the number of different monster types. Each of the following m lines contains a split rule. Each split rule starts with an integer (a monster ID) mi (1 ≤ mi ≤ n), and a positive integer li indicating the number of monsters... | For each monster, in order of their IDs, print a line with two integers: the smallest and the largest number of diamonds that can possibly be collected by starting with that monster. If Piegirl cannot possibly end up in a state without monsters, print -1 for both smallest and the largest value. If she can collect an ar... | null | null | [{"input": "6 4\n1 3 -1 1 -1\n1 2 -1 -1\n2 3 -1 3 -1\n2 3 -1 -1 -1\n3 2 -1 -1\n4 2 4 -1", "output": "2 -2\n3 4\n2 2\n-1 -1"}, {"input": "3 2\n1 2 1 -1\n2 2 -1 -1\n2 3 2 1 -1", "output": "-1 -1\n2 2"}] | 2,600 | ["dfs and similar", "graphs", "shortest paths"] | 43 | [{"input": "6 4\r\n1 3 -1 1 -1\r\n1 2 -1 -1\r\n2 3 -1 3 -1\r\n2 3 -1 -1 -1\r\n3 2 -1 -1\r\n4 2 4 -1\r\n", "output": "2 -2\r\n3 4\r\n2 2\r\n-1 -1\r\n"}, {"input": "3 2\r\n1 2 1 -1\r\n2 2 -1 -1\r\n2 3 2 1 -1\r\n", "output": "-1 -1\r\n2 2\r\n"}, {"input": "2 1\r\n1 3 -1 1 -1\r\n1 5 -1 -1 -1 -1 -1\r\n", "output": "5 -2\r\n... | false | stdio | null | true |
551/E | 551 | E | PyPy 3 | PRETESTS | 2 | 93 | 0 | 11555674 | n, q = map(int, input().split())
a = list(map(int, input().split()))
otr_size = max(1, int(n ** 0.5))
otr_cnt = (n + otr_size - 1) // otr_size
def get_otr_boundaries(i):
return (i * otr_size, min(n, (i + 1) * otr_size))
def get_otr_by_index(i):
return i // otr_size
otr_delta = [0] * otr_cnt
otr_dict = [{} ... | 73 | 3,338 | 83,660,800 | 206366815 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n, q = map(int, input().split())
a = list(map(int, input().split()))
m = 555
m0 = n // m + min(n % m, 1)
s = [set() for _ in range(m0)]
for i in range(m0):
for j in range(i * m, min((i + 1) * m, n)):
s[i].add(a[j])
lazy = [0] *... | Codeforces Round 307 (Div. 2) | CF | 2,015 | 10 | 256 | GukiZ and GukiZiana | Professor GukiZ was playing with arrays again and accidentally discovered new function, which he called GukiZiana. For given array a, indexed with integers from 1 to n, and number y, GukiZiana(a, y) represents maximum value of j - i, such that aj = ai = y. If there is no y as an element in a, then GukiZiana(a, y) is eq... | The first line contains two integers n, q (1 ≤ n ≤ 5 * 105, 1 ≤ q ≤ 5 * 104), size of array a, and the number of queries.
The second line contains n integers a1, a2, ... an (1 ≤ ai ≤ 109), forming an array a.
Each of next q lines contain either four or two numbers, as described in statement:
If line starts with 1, t... | For each query of type 2, print the value of GukiZiana(a, y), for y value for that query. | null | null | [{"input": "4 3\n1 2 3 4\n1 1 2 1\n1 1 1 1\n2 3", "output": "2"}, {"input": "2 3\n1 2\n1 2 2 1\n2 3\n2 4", "output": "0\n-1"}] | 2,500 | ["binary search", "data structures", "implementation"] | 73 | [{"input": "4 3\r\n1 2 3 4\r\n1 1 2 1\r\n1 1 1 1\r\n2 3\r\n", "output": "2\r\n"}, {"input": "2 3\r\n1 2\r\n1 2 2 1\r\n2 3\r\n2 4\r\n", "output": "0\r\n-1\r\n"}, {"input": "8 5\r\n1 1 1 2 1 3 1 1\r\n2 1\r\n1 1 8 1\r\n2 2\r\n1 2 5 2\r\n2 4\r\n", "output": "7\r\n7\r\n4\r\n"}, {"input": "8 8\r\n1 9 1 9 2 3 4 5\r\n1 3 7 1\r... | false | stdio | null | true |
151/B | 151 | B | Python 3 | TESTS | 16 | 46 | 102,400 | 223755321 | def number_Phone(cases):
book_contact ={}
max=[0]*3
names=[[],[],[]]
for n in range(cases):
data=input().split()
book_contact[data[1]]=[]
contacs=[]
for n in range(int(data[0])):
contac=[int(x) for x in input().split("-")]
contacs.append(contac)
... | 38 | 155 | 6,656,000 | 185102617 | d1 = {}
d2 = {}
d3 = {}
for a0 in range(int(input())):
n,k = input().split(' ')
n = int(n)
d1[k],d2[k],d3[k] = 0,0,0
for i in range(n):
s = list(map(int,list(''.join(input().split('-')))))
#print(s)
#print(len(set(s)))
if len(set(s)) == 1:
d1[k]+=1
eli... | Codeforces Round 107 (Div. 2) | CF | 2,012 | 2 | 256 | Phone Numbers | Winters are just damn freezing cold in Nvodsk! That's why a group of n friends prefers to take a taxi, order a pizza and call girls. The phone numbers in the city consist of three pairs of digits (for example, 12-34-56). Each friend has a phonebook of size si (that's the number of phone numbers). We know that taxi numb... | The first line contains an integer n (1 ≤ n ≤ 100) — the number of friends.
Then follow n data blocks that describe each friend's phone books. Each block is presented in the following form: first goes the line that contains integer si and string namei (0 ≤ si ≤ 100) — the number of phone numbers in the phone book of t... | In the first line print the phrase "If you want to call a taxi, you should call: ". Then print names of all friends whose phone books contain maximal number of taxi phone numbers.
In the second line print the phrase "If you want to order a pizza, you should call: ". Then print names of all friends who have maximal num... | null | In the first sample you are given four friends. Fedorov's phone book contains one taxi number and one pizza delivery number, Melnikov's phone book only has 3 numbers of girls, Rogulenko's one has 6 taxi numbers and one pizza delivery number, Kaluzhin's one contains 2 taxi numbers and one pizza delivery number.
Thus, i... | [{"input": "4\n2 Fedorov\n22-22-22\n98-76-54\n3 Melnikov\n75-19-09\n23-45-67\n99-99-98\n7 Rogulenko\n22-22-22\n11-11-11\n33-33-33\n44-44-44\n55-55-55\n66-66-66\n95-43-21\n3 Kaluzhin\n11-11-11\n99-99-99\n98-65-32", "output": "If you want to call a taxi, you should call: Rogulenko.\nIf you want to order a pizza, you shou... | 1,200 | ["implementation", "strings"] | 38 | [{"input": "4\r\n2 Fedorov\r\n22-22-22\r\n98-76-54\r\n3 Melnikov\r\n75-19-09\r\n23-45-67\r\n99-99-98\r\n7 Rogulenko\r\n22-22-22\r\n11-11-11\r\n33-33-33\r\n44-44-44\r\n55-55-55\r\n66-66-66\r\n95-43-21\r\n3 Kaluzhin\r\n11-11-11\r\n99-99-99\r\n98-65-32\r\n", "output": "If you want to call a taxi, you should call: Rogulenk... | false | stdio | null | true |
381/A | 381 | A | Python 3 | TESTS | 10 | 31 | 0 | 212113958 | v1=int(input())
v2=list(map(int,input().split()))
d=0
s=0
c=1
for i in range(v1):
w=max(v2[0],v2[-1])
if c%2==0:
d+=w
v2.remove(w)
c+=1
else:
s+=w
v2.remove(w)
c+=1
print(max(d,s),min(d,s)) | 34 | 31 | 0 | 207551826 | n = int(input())
cards = list(map(int, input().split()))
i = 0
j = n - 1
score1 = 0
score2 = 0
round = 0
while i<=j:
round += 1
if round%2 == 1:
if cards[j] > cards[i]:
score1 += cards[j]
j -= 1
else:
score1 += cards[i]
i += 1
else:
if cards[j] > cards[i]:
score2 += cards[j]
j -= 1
else:... | Codeforces Round 223 (Div. 2) | CF | 2,014 | 1 | 256 | Sereja and Dima | Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The ... | The first line contains integer n (1 ≤ n ≤ 1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | null | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | [{"input": "4\n4 1 2 10", "output": "12 5"}, {"input": "7\n1 2 3 4 5 6 7", "output": "16 12"}] | 800 | ["greedy", "implementation", "two pointers"] | 34 | [{"input": "4\r\n4 1 2 10\r\n", "output": "12 5\r\n"}, {"input": "7\r\n1 2 3 4 5 6 7\r\n", "output": "16 12\r\n"}, {"input": "42\r\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13\r\n", "output": "613 418\r\n"}, {"input": "43\r\n32 1 15 48 38 26 25 1... | false | stdio | null | true |
381/A | 381 | A | Python 3 | TESTS | 10 | 31 | 0 | 227679454 | s = int(input())
l = list(map(int,input().split()))
Sereja = 0
Dima = 0
for i in range(s):
if i%2==0 :
Sereja += max(l[0],l[-1])
l.remove(max(l[0],l[-1]))
else:
Dima += max(l[0],l[-1])
l.remove(max(l[0],l[-1]))
print(max(Sereja,Dima),min(Sereja,Dima)) | 34 | 31 | 0 | 209523583 | # Read the number of cards
n = int(input())
# Read the numbers on the cards
cards = list(map(int, input().split()))
# Initialize Sereja's and Dima's scores
sereja_score = 0
dima_score = 0
# Initialize the left and right pointers
left = 0
right = n - 1
# Simulate the game
while left <= right:
if cards[left] > ca... | Codeforces Round 223 (Div. 2) | CF | 2,014 | 1 | 256 | Sereja and Dima | Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The ... | The first line contains integer n (1 ≤ n ≤ 1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | null | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | [{"input": "4\n4 1 2 10", "output": "12 5"}, {"input": "7\n1 2 3 4 5 6 7", "output": "16 12"}] | 800 | ["greedy", "implementation", "two pointers"] | 34 | [{"input": "4\r\n4 1 2 10\r\n", "output": "12 5\r\n"}, {"input": "7\r\n1 2 3 4 5 6 7\r\n", "output": "16 12\r\n"}, {"input": "42\r\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13\r\n", "output": "613 418\r\n"}, {"input": "43\r\n32 1 15 48 38 26 25 1... | false | stdio | null | true |
468/B | 468 | B | Python 3 | TESTS | 8 | 46 | 0 | 141652054 | """
Two Sets
Source: Codeforces Time Limit: 1000ms Memory Limit: 256MB
4 5 7
2 3 5 4
"""
def findSet(u, parents):
if parents[u] != u:
parents[u] = findSet(parents[u], parents)
return parents[u]
def union(u, v, parents):
up, vp = findSet(u, parents), findSet(v, parents)
if up == vp:
... | 47 | 561 | 11,673,600 | 162284673 | def find(u):
global parent
if u != parent[u]:
parent[u] = find(parent[u])
return parent[u]
def union(u, v):
u = find(u)
v = find(v)
parent[u] = v
n, a, b = map(int, input().split())
arr = list(map(int, input().split()))
mp = dict()
for i in range(n):
mp[arr[i]] = i + 1
parent = [... | Codeforces Round 268 (Div. 1) | CF | 2,014 | 1 | 256 | Two Sets | Little X has n distinct integers: p1, p2, ..., pn. He wants to divide all of them into two sets A and B. The following two conditions must be satisfied:
- If number x belongs to set A, then number a - x must also belong to set A.
- If number x belongs to set B, then number b - x must also belong to set B.
Help Little... | The first line contains three space-separated integers n, a, b (1 ≤ n ≤ 105; 1 ≤ a, b ≤ 109). The next line contains n space-separated distinct integers p1, p2, ..., pn (1 ≤ pi ≤ 109). | If there is a way to divide the numbers into two sets, then print "YES" in the first line. Then print n integers: b1, b2, ..., bn (bi equals either 0, or 1), describing the division. If bi equals to 0, then pi belongs to set A, otherwise it belongs to set B.
If it's impossible, print "NO" (without the quotes). | null | It's OK if all the numbers are in the same set, and the other one is empty. | [{"input": "4 5 9\n2 3 4 5", "output": "YES\n0 0 1 1"}, {"input": "3 3 4\n1 2 4", "output": "NO"}] | 2,000 | ["2-sat", "dfs and similar", "dsu", "graph matchings", "greedy"] | 47 | [{"input": "4 5 9\r\n2 3 4 5\r\n", "output": "YES\r\n0 0 1 1\r\n"}, {"input": "3 3 4\r\n1 2 4\r\n", "output": "NO\r\n"}, {"input": "100 8883 915\r\n1599 4666 663 3646 754 2113 2200 3884 4082 1640 3795 2564 2711 2766 1122 4525 1779 2678 2816 2182 1028 2337 4918 1273 4141 217 2682 1756 309 4744 915 1351 3302 1367 3046 40... | false | stdio | import sys
def main(input_path, output_path, submission_path):
with open(input_path) as f:
lines = f.readlines()
n, a, b = map(int, lines[0].split())
p = list(map(int, lines[1].split()))
p_set = set(p)
with open(output_path) as f:
ref_lines = [line.strip() for line in f.readlin... | true |
174/C | 174 | C | PyPy 3 | TESTS | 5 | 466 | 11,059,200 | 109744866 | import re
import sys
exit=sys.exit
from bisect import bisect_left as bsl,bisect_right as bsr
from collections import Counter,defaultdict as ddict,deque
from functools import lru_cache
cache=lru_cache(None)
from heapq import *
from itertools import *
from math import inf
from pprint import pprint as pp
enum=enumerate
ri... | 63 | 780 | 13,619,200 | 109746317 | import re
import sys
exit=sys.exit
from bisect import bisect_left as bsl,bisect_right as bsr
from collections import Counter,defaultdict as ddict,deque
from functools import lru_cache
cache=lru_cache(None)
from heapq import *
from itertools import *
from math import inf
from pprint import pprint as pp
enum=enumerate
ri... | VK Cup 2012 Round 3 (Unofficial Div. 2 Edition) | CF | 2,012 | 2 | 256 | Range Increments | Polycarpus is an amateur programmer. Now he is analyzing a friend's program. He has already found there the function rangeIncrement(l, r), that adds 1 to each element of some array a for all indexes in the segment [l, r]. In other words, this function does the following:
Polycarpus knows the state of the array a after... | The first input line contains a single integer n (1 ≤ n ≤ 105) — the length of the array a[1... n].
The second line contains its integer space-separated elements, a[1], a[2], ..., a[n] (0 ≤ a[i] ≤ 105) after some series of function calls rangeIncrement(l, r).
It is guaranteed that at least one element of the array is... | Print on the first line t — the minimum number of calls of function rangeIncrement(l, r), that lead to the array from the input data. It is guaranteed that this number will turn out not more than 105.
Then print t lines — the descriptions of function calls, one per line. Each line should contain two integers li, ri (1... | null | The first sample requires a call for the entire array, and four additional calls:
- one for the segment [2,2] (i.e. the second element of the array),
- three for the segment [5,5] (i.e. the fifth element of the array). | [{"input": "6\n1 2 1 1 4 1", "output": "5\n2 2\n5 5\n5 5\n5 5\n1 6"}, {"input": "5\n1 0 1 0 1", "output": "3\n1 1\n3 3\n5 5"}] | 1,800 | ["data structures", "greedy"] | 63 | [{"input": "6\r\n1 2 1 1 4 1\r\n", "output": "5\r\n2 2\r\n5 5\r\n5 5\r\n5 5\r\n1 6\r\n"}, {"input": "5\r\n1 0 1 0 1\r\n", "output": "3\r\n1 1\r\n3 3\r\n5 5\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n1 1\r\n"}, {"input": "1\r\n100000\r\n", "output": "100000\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1... | false | stdio | import sys
def main(input_path, output_path, submission_path):
with open(input_path) as f:
n = int(f.readline())
a = list(map(int, f.readline().split()))
# Compute minimal t
minimal_t = 0
prev = 0
for num in a:
if num > prev:
minimal_t += num - prev
... | true |
929/B | 929 | B | Python 3 | TESTS | 35 | 77 | 6,041,600 | 35865826 | inputList = input()
inputList = inputList.split()
inputArray = "-"
freePlaceArray = []
for i in range(int(inputList[0])):
tempString = input()
inputArray = inputArray + tempString
inputArray = inputArray + "-"
for i in range(len(inputArray)):
if (inputArray[i] == '.'):
freePlaceArray.append(... | 47 | 62 | 5,632,000 | 35846687 | n, k = (int(s) for s in input().split())
rows = []
for i in range(n):
rows.append([c for c in input()])
def nbcnt(row, col):
res = 0
if col != 0 and rows[row][col - 1] == 'S':
res += 1
if col != 11 and rows[row][col + 1] == 'S':
res += 1
return res
for c in range(3):
for i in r... | VK Cup 2018 - Квалификация 2 | CF | 2,018 | 1 | 256 | Места в самолёте | В самолёте есть n рядов мест. Если смотреть на ряды сверху, то в каждом ряду есть 3 места слева, затем проход между рядами, затем 4 центральных места, затем ещё один проход между рядами, а затем ещё 3 места справа.
Известно, что некоторые места уже заняты пассажирами. Всего есть два вида пассажиров — статусные (те, ко... | В первой строке следуют два целых числа n и k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10·n) — количество рядов мест в самолёте и количество пассажиров, которых нужно рассадить.
Далее следует описание рядов мест самолёта по одному ряду в строке. Если очередной символ равен '-', то это проход между рядами. Если очередной символ равен '.'... | В первую строку выведите минимальное суммарное число соседей у статусных пассажиров.
Далее выведите план рассадки пассажиров, который минимизирует суммарное количество соседей у статусных пассажиров, в том же формате, что и во входных данных. Если в свободное место нужно посадить одного из k пассажиров, выведите строч... | null | В первом примере нужно посадить ещё двух обычных пассажиров. Для минимизации соседей у статусных пассажиров, нужно посадить первого из них на третье слева место, а второго на любое из оставшихся двух мест, так как независимо от выбора места он станет соседом двух статусных пассажиров.
Изначально, у статусного пассажир... | [{"input": "1 2\nSP.-SS.S-S.S", "output": "5\nSPx-SSxS-S.S"}, {"input": "4 9\nPP.-PPPS-S.S\nPSP-PPSP-.S.\n.S.-S..P-SS.\nP.S-P.PP-PSP", "output": "15\nPPx-PPPS-S.S\nPSP-PPSP-xSx\nxSx-SxxP-SSx\nP.S-PxPP-PSP"}] | 1,300 | ["*special", "implementation"] | 47 | [{"input": "1 2\r\nSP.-SS.S-S.S\r\n", "output": "5\r\nSPx-SSxS-S.S\r\n"}, {"input": "4 9\r\nPP.-PPPS-S.S\r\nPSP-PPSP-.S.\r\n.S.-S..P-SS.\r\nP.S-P.PP-PSP\r\n", "output": "15\r\nPPx-PPPS-S.S\r\nPSP-PPSP-xSx\r\nxSx-SxxP-SSx\r\nP.S-PxPP-PSP\r\n"}, {"input": "3 7\r\n.S.-SSSP-..S\r\nS..-.SPP-S.P\r\n.S.-PPPP-PSP\r\n", "output... | 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:
lines = f.read().splitlines()
n, k = map(int, lines[0].split())
original_grid = lines[1:1+n]
def get_group(j):
if 0 <= j <= 2:
... | true |
38/A | 38 | A | PyPy 3 | TESTS | 5 | 278 | 0 | 98319125 | n = int(input())
l = list(map(int,input().split()))
a,b = map(int,input().split())
y = b-a
sum1 = 0
if(a==1):
for i in range(y):
sum1 = sum1 + l[i]
print(sum1)
else:
print(l[a-1]) | 50 | 92 | 0 | 138567390 | n = int(input())
a = list(map(int, input().split()))
k, m = map(int, input().split())
ans = 0
for i in range(k - 1, m - 1):
ans += a[i]
print(ans)
# Thu Dec 09 2021 17:46:48 GMT+0000 (Coordinated Universal Time) | School Personal Contest #1 (Winter Computer School 2010/11) - Codeforces Beta Round 38 (ACM-ICPC Rules) | ICPC | 2,010 | 2 | 256 | Army | The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.
One needs exactly di years to rise from rank i to rank i + 1. Reaching a certain rank i having not reached all the previous i - 1 ranks is impossible.
Vasya ha... | The first input line contains an integer n (2 ≤ n ≤ 100). The second line contains n - 1 integers di (1 ≤ di ≤ 100). The third input line contains two integers a and b (1 ≤ a < b ≤ n). The numbers on the lines are space-separated. | Print the single number which is the number of years that Vasya needs to rise from rank a to rank b. | null | null | [{"input": "3\n5 6\n1 2", "output": "5"}, {"input": "3\n5 6\n1 3", "output": "11"}] | 800 | ["implementation"] | 50 | [{"input": "3\r\n5 6\r\n1 2\r\n", "output": "5\r\n"}, {"input": "3\r\n5 6\r\n1 3\r\n", "output": "11\r\n"}, {"input": "2\r\n55\r\n1 2\r\n", "output": "55\r\n"}, {"input": "3\r\n85 78\r\n1 3\r\n", "output": "163\r\n"}, {"input": "4\r\n63 4 49\r\n2 3\r\n", "output": "4\r\n"}, {"input": "5\r\n93 83 42 56\r\n2 5\r\n", "out... | false | stdio | null | true |
38/A | 38 | A | Python 3 | TESTS | 5 | 216 | 0 | 82600799 | rank=int(input())
y=list(map(int,input().split()))
a,b=map(int,input().split())
if b-a==1:
print(y[a-1])
elif b-a==2:
print(y[a-1]+y[b-2]) | 50 | 92 | 0 | 141024970 | n = int(input())
d = list(map(int , input().split()))
a , b = map(int , input().split())
def solve(n , d, a , b) :
years = 0
while a < b :
years += d[a - 1]
a += 1
return years
print(solve(n , d , a , b )) | School Personal Contest #1 (Winter Computer School 2010/11) - Codeforces Beta Round 38 (ACM-ICPC Rules) | ICPC | 2,010 | 2 | 256 | Army | The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.
One needs exactly di years to rise from rank i to rank i + 1. Reaching a certain rank i having not reached all the previous i - 1 ranks is impossible.
Vasya ha... | The first input line contains an integer n (2 ≤ n ≤ 100). The second line contains n - 1 integers di (1 ≤ di ≤ 100). The third input line contains two integers a and b (1 ≤ a < b ≤ n). The numbers on the lines are space-separated. | Print the single number which is the number of years that Vasya needs to rise from rank a to rank b. | null | null | [{"input": "3\n5 6\n1 2", "output": "5"}, {"input": "3\n5 6\n1 3", "output": "11"}] | 800 | ["implementation"] | 50 | [{"input": "3\r\n5 6\r\n1 2\r\n", "output": "5\r\n"}, {"input": "3\r\n5 6\r\n1 3\r\n", "output": "11\r\n"}, {"input": "2\r\n55\r\n1 2\r\n", "output": "55\r\n"}, {"input": "3\r\n85 78\r\n1 3\r\n", "output": "163\r\n"}, {"input": "4\r\n63 4 49\r\n2 3\r\n", "output": "4\r\n"}, {"input": "5\r\n93 83 42 56\r\n2 5\r\n", "out... | false | stdio | null | true |
151/B | 151 | B | Python 3 | TESTS | 3 | 31 | 0 | 209596863 | # /**
# * author: brownfox2k6
# * created: 14/06/2023 00:36:50 Hanoi, Vietnam
# **/
taxi = {}
pizza = {}
girl = {}
for _ in range(int(input())):
n, name = input().split()
for i in range(int(n)):
number = list(input().replace('-', ''))
if len(set(number)) == 1:
try:
... | 38 | 171 | 4,505,600 | 197506011 | n = int(input())
arr = []
for x in range(n):
t, name = input().split()
t = int(t)
arr.append([name, 0, 0, 0])
for i in range(t):
number = input().replace('-','')
if number.count(number[0]) == 6:
arr[x][1] += 1
elif all(a > b for a,b in zip(number,number[1:])):
... | Codeforces Round 107 (Div. 2) | CF | 2,012 | 2 | 256 | Phone Numbers | Winters are just damn freezing cold in Nvodsk! That's why a group of n friends prefers to take a taxi, order a pizza and call girls. The phone numbers in the city consist of three pairs of digits (for example, 12-34-56). Each friend has a phonebook of size si (that's the number of phone numbers). We know that taxi numb... | The first line contains an integer n (1 ≤ n ≤ 100) — the number of friends.
Then follow n data blocks that describe each friend's phone books. Each block is presented in the following form: first goes the line that contains integer si and string namei (0 ≤ si ≤ 100) — the number of phone numbers in the phone book of t... | In the first line print the phrase "If you want to call a taxi, you should call: ". Then print names of all friends whose phone books contain maximal number of taxi phone numbers.
In the second line print the phrase "If you want to order a pizza, you should call: ". Then print names of all friends who have maximal num... | null | In the first sample you are given four friends. Fedorov's phone book contains one taxi number and one pizza delivery number, Melnikov's phone book only has 3 numbers of girls, Rogulenko's one has 6 taxi numbers and one pizza delivery number, Kaluzhin's one contains 2 taxi numbers and one pizza delivery number.
Thus, i... | [{"input": "4\n2 Fedorov\n22-22-22\n98-76-54\n3 Melnikov\n75-19-09\n23-45-67\n99-99-98\n7 Rogulenko\n22-22-22\n11-11-11\n33-33-33\n44-44-44\n55-55-55\n66-66-66\n95-43-21\n3 Kaluzhin\n11-11-11\n99-99-99\n98-65-32", "output": "If you want to call a taxi, you should call: Rogulenko.\nIf you want to order a pizza, you shou... | 1,200 | ["implementation", "strings"] | 38 | [{"input": "4\r\n2 Fedorov\r\n22-22-22\r\n98-76-54\r\n3 Melnikov\r\n75-19-09\r\n23-45-67\r\n99-99-98\r\n7 Rogulenko\r\n22-22-22\r\n11-11-11\r\n33-33-33\r\n44-44-44\r\n55-55-55\r\n66-66-66\r\n95-43-21\r\n3 Kaluzhin\r\n11-11-11\r\n99-99-99\r\n98-65-32\r\n", "output": "If you want to call a taxi, you should call: Rogulenk... | false | stdio | null | true |
351/D | 351 | D | PyPy 3 | TESTS | 1 | 62 | 204,800 | 198672688 | import sys
readline=sys.stdin.readline
from collections import deque,defaultdict
def Mo(N,Q,query):
D=max(1,int(N/Q**.5))
mo=[[] for d in range((N+D-1)//D+1)]
for q,(l,r) in enumerate(query):
mo[r//D].append((l,r,q))
retu=[]
for d in range((N+D-1)//D+1):
retu+=sorted(mo[d],reverse=d... | 29 | 2,495 | 84,889,600 | 202114591 | # ====== author: kuanc (www.hank.fyi) | created: 04/15/23 01:14:36 CST ====== #
from sys import stdin, stderr, stdout, setrecursionlimit
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
from itertools import accumulate, combinations, permutatio... | Codeforces Round 204 (Div. 1) | CF | 2,013 | 3 | 256 | Jeff and Removing Periods | Cosider a sequence, consisting of n integers: a1, a2, ..., an. Jeff can perform the following operation on sequence a:
- take three integers v, t, k (1 ≤ v, t ≤ n; 0 ≤ k; v + tk ≤ n), such that av = av + t, av + t = av + 2t, ..., av + t(k - 1) = av + tk;
- remove elements av, av + t, ..., av + t·k from the sequence a,... | The first line contains integer m (1 ≤ m ≤ 105). The next line contains m integers b1, b2, ..., bm (1 ≤ bi ≤ 105).
The third line contains integer q (1 ≤ q ≤ 105) — the number of questions. The next q lines contain pairs of integers, i-th of them contains a pair of integers li, ri (1 ≤ li ≤ ri ≤ m) — the description o... | In q lines print the answers to Jeff's queries. Print the answers according to the order of questions in input. | null | null | [{"input": "5\n2 2 1 1 2\n5\n1 5\n1 1\n2 2\n1 3\n2 3", "output": "2\n1\n1\n2\n2"}, {"input": "10\n2 1 3 3 3 3 1 3 1 1\n10\n4 8\n2 10\n1 10\n4 4\n1 3\n2 4\n6 7\n1 9\n2 5\n1 1", "output": "2\n3\n3\n1\n3\n2\n2\n3\n2\n1"}] | 2,700 | ["data structures"] | 29 | [{"input": "5\r\n2 2 1 1 2\r\n5\r\n1 5\r\n1 1\r\n2 2\r\n1 3\r\n2 3\r\n", "output": "2\r\n1\r\n1\r\n2\r\n2\r\n"}, {"input": "10\r\n2 1 3 3 3 3 1 3 1 1\r\n10\r\n4 8\r\n2 10\r\n1 10\r\n4 4\r\n1 3\r\n2 4\r\n6 7\r\n1 9\r\n2 5\r\n1 1\r\n", "output": "2\r\n3\r\n3\r\n1\r\n3\r\n2\r\n2\r\n3\r\n2\r\n1\r\n"}, {"input": "15\r\n3 3 ... | false | stdio | null | true |
546/B | 546 | B | Python 3 | TESTS | 5 | 46 | 307,200 | 222669524 | from collections import defaultdict
d=defaultdict(lambda :0)
n=int(input())
x=sorted(list(map(int,input().split())))
for i in x:
d[i]+=1
ans=0
start=1
for i in x:
if d[i]>1:
while(d[start]!=0 and start<=i):
start+=1
d[i]-=1
ans+=i-start
d[start]+=1
print(abs(ans))
#... | 49 | 62 | 307,200 | 11211056 | n=int(input())
s=list(map(int, input().split()))
t=[0 for i in range(6001)]
for i in range(len(s)):
t[s[i]]+=1
ans=0
for i in range(6001):
if t[i]>1:
ans += t[i]-1
t[i+1]+=t[i]-1
print(ans) | Codeforces Round 304 (Div. 2) | CF | 2,015 | 3 | 256 | Soldier and Badges | Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness factor, which shows how much it's owner reached. Coolness factor can be increased by one for the cost of one coin.
For every pair of soldiers one of them should get a badge with strictly higher factor than the second... | First line of input consists of one integer n (1 ≤ n ≤ 3000).
Next line consists of n integers ai (1 ≤ ai ≤ n), which stand for coolness factor of each badge. | Output single integer — minimum amount of coins the colonel has to pay. | null | In first sample test we can increase factor of first badge by 1.
In second sample test we can increase factors of the second and the third badge by 1. | [{"input": "4\n1 3 1 4", "output": "1"}, {"input": "5\n1 2 3 2 5", "output": "2"}] | 1,200 | ["brute force", "greedy", "implementation", "sortings"] | 49 | [{"input": "4\r\n1 3 1 4\r\n", "output": "1"}, {"input": "5\r\n1 2 3 2 5\r\n", "output": "2"}, {"input": "5\r\n1 5 3 2 4\r\n", "output": "0"}, {"input": "10\r\n1 1 2 3 4 5 6 7 8 9\r\n", "output": "9"}, {"input": "11\r\n9 2 10 3 1 5 7 1 4 8 6\r\n", "output": "10"}, {"input": "4\r\n4 3 2 2\r\n", "output": "3"}, {"input":... | false | stdio | null | true |
131/B | 131 | B | PyPy 3-64 | TESTS | 2 | 122 | 0 | 228286866 | import collections
import math
sums = lambda n: int(n * (n + 1) / 2) # sum from 1 to n
sumsqur = lambda n: int( (n) * (n + 1) * (2*n +1)/6) # sum square from 1 to n
def im(): return map(int, input().split())
def il(): return list(map(int, input().split()))
def ii(): return int(input())
# "abcdefghijklmnopqrstuvwxyz... | 43 | 154 | 9,420,800 | 222248594 | n = input()
customers = [int(i) for i in input().split()]
counts = [0] * 21
couples = 0
for c in customers:
counts[c + 10] += 1
for i in range(10):
couples += counts[i] * counts[20-i]
couples += (counts[10] * (counts[10] - 1) // 2)
print(couples) | Codeforces Beta Round 95 (Div. 2) | CF | 2,011 | 2 | 256 | Opposites Attract | Everybody knows that opposites attract. That is the key principle of the "Perfect Matching" dating agency. The "Perfect Matching" matchmakers have classified each registered customer by his interests and assigned to the i-th client number ti ( - 10 ≤ ti ≤ 10). Of course, one number can be assigned to any number of cust... | The first line of the input data contains an integer n (1 ≤ n ≤ 105) which represents the number of registered clients of the "Couple Matching". The second line contains a sequence of integers t1, t2, ..., tn ( - 10 ≤ ti ≤ 10), ti — is the parameter of the i-th customer that has been assigned to the customer by the res... | Print the number of couples of customs with opposite t. The opposite number for x is number - x (0 is opposite to itself). Couples that only differ in the clients' order are considered the same.
Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, ... | null | In the first sample the couples of opposite clients are: (1,2), (1,5) и (3,4).
In the second sample any couple of clients is opposite. | [{"input": "5\n-3 3 0 0 3", "output": "3"}, {"input": "3\n0 0 0", "output": "3"}] | 1,200 | ["implementation", "math"] | 43 | [{"input": "5\r\n-3 3 0 0 3\r\n", "output": "3\r\n"}, {"input": "3\r\n0 0 0\r\n", "output": "3\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n5\r\n", "output": "0\r\n"}, {"input": "2\r\n0 0\r\n", "output": "1\r\n"}, {"input": "2\r\n-3 3\r\n", "output": "1\r\n"}, {"input": "2\r\n1 5\r\n", "output": "... | false | stdio | null | true |
408/B | 408 | B | Python 3 | TESTS | 10 | 109 | 0 | 78328704 | l1 = input()
l2 = input()
res = 0
for u in l2:
if l1.count(u) >= l2.count(u):
res += 1
elif l1.count(u) == 0:
res = -1
break
for u in l1:
if l2.count(u) > l1.count(u):
res +=1
print(res) | 21 | 31 | 0 | 146593397 | a=[j for j in str(input())]
b=[i for i in str(input())]
c=list(set(b))
ans=0
for k in c:
z=min(a.count(k),b.count(k))
if z==0:print(-1);break
ans+=z
else:print(ans) | Codeforces Round 239 (Div. 2) | CF | 2,014 | 1 | 256 | Garland | Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought n colored sheets of paper, the area of each sheet is 1 square meter.
The garland must consist of exactly m pieces of colored paper of arbitrary area, each piece s... | The first line contains a non-empty sequence of n (1 ≤ n ≤ 1000) small English letters ("a"..."z"). Each letter means that Vasya has a sheet of paper of the corresponding color.
The second line contains a non-empty sequence of m (1 ≤ m ≤ 1000) small English letters that correspond to the colors of the pieces of paper ... | Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer. | null | In the first test sample Vasya can make an garland of area 6: he can use both sheets of color b, three (but not four) sheets of color a and cut a single sheet of color c in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6.
In the second test sample Vasya cannot make a ga... | [{"input": "aaabbac\naabbccac", "output": "6"}, {"input": "a\nz", "output": "-1"}] | 1,200 | ["implementation"] | 21 | [{"input": "aaabbac\r\naabbccac\r\n", "output": "6\r\n"}, {"input": "a\r\nz\r\n", "output": "-1"}, {"input": "r\r\nr\r\n", "output": "1\r\n"}, {"input": "stnsdn\r\nndnndsn\r\n", "output": "4\r\n"}, {"input": "yqfqfp\r\ntttwtqq\r\n", "output": "-1"}, {"input": "zzbbrrtrtzr\r\ntbbtrrrzr\r\n", "output": "9\r\n"}, {"input"... | false | stdio | null | true |
408/B | 408 | B | Python 3 | TESTS | 9 | 46 | 0 | 9818572 | '''
Created on Feb 13, 2015
@author: mohamed265
'''
a1 = input()
a2 = input()
slon = 0
for i in range(ord('a') ,ord('z') +1):
x = chr(i)
count1 = a1.count(x)
count2 = a2.count(x)
if count1 * 4 < count2:
print(-1)
exit(0)
else:
if count1 >= count2:
slon += count2
... | 21 | 31 | 0 | 148167025 | def solve():
dn ={}
for i in n :
dn[i]=dn.get(i,0)+1
dm ={}
for i in m :
dm[i]=dm.get(i,0)+1
if any(x not in dn for x in dm) :
return -1
c=0
for i in dm :
c+=min(dm[i],dn[i])
return c
from sys import stdin
input = stdin.readline
n=inpu... | Codeforces Round 239 (Div. 2) | CF | 2,014 | 1 | 256 | Garland | Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought n colored sheets of paper, the area of each sheet is 1 square meter.
The garland must consist of exactly m pieces of colored paper of arbitrary area, each piece s... | The first line contains a non-empty sequence of n (1 ≤ n ≤ 1000) small English letters ("a"..."z"). Each letter means that Vasya has a sheet of paper of the corresponding color.
The second line contains a non-empty sequence of m (1 ≤ m ≤ 1000) small English letters that correspond to the colors of the pieces of paper ... | Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer. | null | In the first test sample Vasya can make an garland of area 6: he can use both sheets of color b, three (but not four) sheets of color a and cut a single sheet of color c in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6.
In the second test sample Vasya cannot make a ga... | [{"input": "aaabbac\naabbccac", "output": "6"}, {"input": "a\nz", "output": "-1"}] | 1,200 | ["implementation"] | 21 | [{"input": "aaabbac\r\naabbccac\r\n", "output": "6\r\n"}, {"input": "a\r\nz\r\n", "output": "-1"}, {"input": "r\r\nr\r\n", "output": "1\r\n"}, {"input": "stnsdn\r\nndnndsn\r\n", "output": "4\r\n"}, {"input": "yqfqfp\r\ntttwtqq\r\n", "output": "-1"}, {"input": "zzbbrrtrtzr\r\ntbbtrrrzr\r\n", "output": "9\r\n"}, {"input"... | false | stdio | null | true |
131/B | 131 | B | Python 3 | TESTS | 0 | 62 | 0 | 223153131 | n = int(input())
nums = map(int, input().split())
ans = 0
freq_map = [0] * 21
for n in nums:
freq_map[n + 10] += 1
for i in range(-10, 0):
ans += freq_map[i + 10] * freq_map[-i + 10]
if 0 in freq_map:
x = freq_map[0]
ans += x * (x - 1) // 2
print(ans) | 43 | 154 | 9,420,800 | 223152061 | size = int(input())
couples = input().split(" ")
couples = [int(x) for x in couples]
matches = 0
zero = 0
seenPos = [0] * 20
seenNeg = [0] * 20
for x in couples:
if x == 0:
zero += 1
elif x > 0:
seenPos[x] += 1
elif x < 0:
seenNeg[-x] += 1
for x in range(20):
matches += seenPos[x... | Codeforces Beta Round 95 (Div. 2) | CF | 2,011 | 2 | 256 | Opposites Attract | Everybody knows that opposites attract. That is the key principle of the "Perfect Matching" dating agency. The "Perfect Matching" matchmakers have classified each registered customer by his interests and assigned to the i-th client number ti ( - 10 ≤ ti ≤ 10). Of course, one number can be assigned to any number of cust... | The first line of the input data contains an integer n (1 ≤ n ≤ 105) which represents the number of registered clients of the "Couple Matching". The second line contains a sequence of integers t1, t2, ..., tn ( - 10 ≤ ti ≤ 10), ti — is the parameter of the i-th customer that has been assigned to the customer by the res... | Print the number of couples of customs with opposite t. The opposite number for x is number - x (0 is opposite to itself). Couples that only differ in the clients' order are considered the same.
Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, ... | null | In the first sample the couples of opposite clients are: (1,2), (1,5) и (3,4).
In the second sample any couple of clients is opposite. | [{"input": "5\n-3 3 0 0 3", "output": "3"}, {"input": "3\n0 0 0", "output": "3"}] | 1,200 | ["implementation", "math"] | 43 | [{"input": "5\r\n-3 3 0 0 3\r\n", "output": "3\r\n"}, {"input": "3\r\n0 0 0\r\n", "output": "3\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n5\r\n", "output": "0\r\n"}, {"input": "2\r\n0 0\r\n", "output": "1\r\n"}, {"input": "2\r\n-3 3\r\n", "output": "1\r\n"}, {"input": "2\r\n1 5\r\n", "output": "... | false | stdio | null | true |
16/A | 16 | A | PyPy 3 | TESTS | 20 | 310 | 20,172,800 | 80144146 | n,m= map(int,input().split())
l=[]
for i in range(n):
a=list(set(input()))
l.append(a)
if(len(l[0][0])!=1):
print("NO")
else:
for i in range(n-1):
if(l[i][0]==l[i+1][0] or len(l[i+1])!=1):
print("NO")
break
else:
print("YES") | 35 | 62 | 0 | 214025136 | n, m = map(int, input().split())
failure = False
cur = -1
for i in range(0, n):
st = set(input())
for a in st:
if a == cur:
failure = True
else:
cur = a
if len(st) > 1:
failure = True
print('YES') if failure == False else print('NO') | Codeforces Beta Round 16 (Div. 2 Only) | ICPC | 2,010 | 2 | 64 | Flag | According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland'... | The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the... | Output YES, if the flag meets the new ISO standard, and NO otherwise. | null | null | [{"input": "3 3\n000\n111\n222", "output": "YES"}, {"input": "3 3\n000\n000\n111", "output": "NO"}, {"input": "3 3\n000\n111\n002", "output": "NO"}] | 800 | ["implementation"] | 35 | [{"input": "3 3\r\n000\r\n111\r\n222\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n000\r\n000\r\n111\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n000\r\n111\r\n002\r\n", "output": "NO\r\n"}, {"input": "10 10\r\n2222222222\r\n5555555555\r\n0000000000\r\n4444444444\r\n1111111111\r\n3333333393\r\n3333333333\r\n5555555555\... | false | stdio | null | true |
719/B | 719 | B | Python 3 | TESTS | 4 | 46 | 0 | 27389528 | n=int(input())
S=input()
p=S[0]
r=0
b=0
for i in range(1,n) :
if p==S[i] :
if p=='r' :
p='b'
r=r+1
else :
p='r'
b=b+1
else :
p=S[i]
print(max(r,b)) | 46 | 62 | 307,200 | 20930787 | n, s = int(input()), input()
a, b = s[::2].count('r'), s[1::2].count('r')
print(min(max((n + 1) // 2 - a, b), max(a, n // 2 - b))) | Codeforces Round 373 (Div. 2) | CF | 2,016 | 1 | 256 | Anatoly and Cockroaches | Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectioni... | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of cockroaches.
The second line contains a string of length n, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively. | Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate. | null | In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.
In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.
In the third sample, the colors of cockroaches in the line are alternating already, thus the answer ... | [{"input": "5\nrbbrr", "output": "1"}, {"input": "5\nbbbbb", "output": "2"}, {"input": "3\nrbr", "output": "0"}] | 1,400 | ["greedy"] | 46 | [{"input": "5\r\nrbbrr\r\n", "output": "1\r\n"}, {"input": "5\r\nbbbbb\r\n", "output": "2\r\n"}, {"input": "3\r\nrbr\r\n", "output": "0\r\n"}, {"input": "13\r\nrbbbrbrrbrrbb\r\n", "output": "3\r\n"}, {"input": "18\r\nrrrrrrrrrrrrrrrrrb\r\n", "output": "8\r\n"}, {"input": "100\r\nbrbbbrrrbbrbrbbrbbrbbbbrbbrrbbbrrbbbbrbr... | false | stdio | null | true |
38/A | 38 | A | Python 3 | TESTS | 5 | 186 | 0 | 83581631 | n=int(input())
list=[int(i) for i in input().split()]
a,b=map(int,input().split())
result=list[a-1]
for i in range(a,b-a):
result+=list[i]
print(result) | 50 | 92 | 0 | 141217277 | n=int(input())
d=[int(x) for x in input().split(" ")]
a1, a2=[int(x) for x in input().split(" ")]
years=0
for i in range(a1-1, a2-1):
years+=d[i]
print(years) | School Personal Contest #1 (Winter Computer School 2010/11) - Codeforces Beta Round 38 (ACM-ICPC Rules) | ICPC | 2,010 | 2 | 256 | Army | The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.
One needs exactly di years to rise from rank i to rank i + 1. Reaching a certain rank i having not reached all the previous i - 1 ranks is impossible.
Vasya ha... | The first input line contains an integer n (2 ≤ n ≤ 100). The second line contains n - 1 integers di (1 ≤ di ≤ 100). The third input line contains two integers a and b (1 ≤ a < b ≤ n). The numbers on the lines are space-separated. | Print the single number which is the number of years that Vasya needs to rise from rank a to rank b. | null | null | [{"input": "3\n5 6\n1 2", "output": "5"}, {"input": "3\n5 6\n1 3", "output": "11"}] | 800 | ["implementation"] | 50 | [{"input": "3\r\n5 6\r\n1 2\r\n", "output": "5\r\n"}, {"input": "3\r\n5 6\r\n1 3\r\n", "output": "11\r\n"}, {"input": "2\r\n55\r\n1 2\r\n", "output": "55\r\n"}, {"input": "3\r\n85 78\r\n1 3\r\n", "output": "163\r\n"}, {"input": "4\r\n63 4 49\r\n2 3\r\n", "output": "4\r\n"}, {"input": "5\r\n93 83 42 56\r\n2 5\r\n", "out... | false | stdio | null | true |
739/A | 739 | A | PyPy 3-64 | TESTS | 4 | 77 | 0 | 206296646 | n,m=list(map(int,input().split()))
mn,a,b=float("inf"),[],[]
for i in range(m):
l,r=list(map(int,input().split()))
b.append([l,r])
mn=min(mn,r-l+1)
print(mn)
for i in range(n):
a.append(0)
for l,r in b:
p,l,r=0,l-1,r-1
for i in range(l,l+mn):
a[i]=p
p+=1
print(*a) | 69 | 374 | 21,811,200 | 24397749 | import sys
input = sys.stdin.readline
#
n,m = map(int, input().split())
mex = []
for i in range(m):
mex.append(list(map(int,input().split())))
ans = min([j-i+1 for i,j in mex])
print(ans)
lis = []
for i in range(n):
lis.append(str(i%ans))
print(' '.join(lis)) | Codeforces Round 381 (Div. 1) | CF | 2,016 | 2 | 256 | Alyona and mex | Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the array. The i-th subarray is described with two integers li and ri, ... | The first line contains two integers n and m (1 ≤ n, m ≤ 105).
The next m lines contain information about the subarrays chosen by Alyona. The i-th of these lines contains two integers li and ri (1 ≤ li ≤ ri ≤ n), that describe the subarray a[li], a[li + 1], ..., a[ri]. | In the first line print single integer — the maximum possible minimum mex.
In the second line print n integers — the array a. All the elements in a should be between 0 and 109.
It is guaranteed that there is an optimal answer in which all the elements in a are between 0 and 109.
If there are multiple solutions, prin... | null | The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2. | [{"input": "5 3\n1 3\n2 5\n4 5", "output": "2\n1 0 2 1 0"}, {"input": "4 2\n1 4\n2 4", "output": "3\n5 2 0 1"}] | 1,700 | ["constructive algorithms", "greedy"] | 69 | [{"input": "5 3\r\n1 3\r\n2 5\r\n4 5\r\n", "output": "2\r\n0 1 0 1 0\r\n"}, {"input": "4 2\r\n1 4\r\n2 4\r\n", "output": "3\r\n0 1 2 0\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "1\r\n0\r\n"}, {"input": "2 1\r\n2 2\r\n", "output": "1\r\n0 0\r\n"}, {"input": "5 6\r\n2 4\r\n2 3\r\n1 4\r\n3 4\r\n2 5\r\n1 3\r\n", "output... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input
with open(input_path, 'r') as f:
n, m = map(int, f.readline().split())
subarrays = [tuple(map(int, line.strip().split())) for line in f]
# Read reference output... | true |
38/A | 38 | A | Python 3 | TESTS | 8 | 186 | 6,656,000 | 87005290 | n=int(input())
a=[*map(int,input().split())]
x,y=[*map(int,input().split())]
ans=y-x
sl=ans
count=0
for i in range(x-1,ans+1):
if sl==0:
break
else:
count+=a[i]
sl-=1
print(count) | 50 | 92 | 0 | 141867568 | n = int(input())
years = list(map(int, input().split(" ")))
a, b = map(int, input().split(" "))
ans = 0
for i in range(a-1, b-1):
ans = ans + years[i]
print(ans) | School Personal Contest #1 (Winter Computer School 2010/11) - Codeforces Beta Round 38 (ACM-ICPC Rules) | ICPC | 2,010 | 2 | 256 | Army | The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.
One needs exactly di years to rise from rank i to rank i + 1. Reaching a certain rank i having not reached all the previous i - 1 ranks is impossible.
Vasya ha... | The first input line contains an integer n (2 ≤ n ≤ 100). The second line contains n - 1 integers di (1 ≤ di ≤ 100). The third input line contains two integers a and b (1 ≤ a < b ≤ n). The numbers on the lines are space-separated. | Print the single number which is the number of years that Vasya needs to rise from rank a to rank b. | null | null | [{"input": "3\n5 6\n1 2", "output": "5"}, {"input": "3\n5 6\n1 3", "output": "11"}] | 800 | ["implementation"] | 50 | [{"input": "3\r\n5 6\r\n1 2\r\n", "output": "5\r\n"}, {"input": "3\r\n5 6\r\n1 3\r\n", "output": "11\r\n"}, {"input": "2\r\n55\r\n1 2\r\n", "output": "55\r\n"}, {"input": "3\r\n85 78\r\n1 3\r\n", "output": "163\r\n"}, {"input": "4\r\n63 4 49\r\n2 3\r\n", "output": "4\r\n"}, {"input": "5\r\n93 83 42 56\r\n2 5\r\n", "out... | false | stdio | null | true |
70/B | 70 | B | Python 3 | TESTS | 10 | 171 | 512,000 | 42014016 | import re
n = int(input())
s = input().strip()
sl = re.compile(r'[.?!]').split(s)
l = 0
c = 1
p = True
for i in sl:
i += '.'
li = len(i)
if l + li <= n:
l += li
else:
i = i.strip()
li = len(i)
if li > n:
p = False
break
l = li
c += ... | 48 | 62 | 1,536,000 | 183968747 | import sys
input = sys.stdin.readline
n = int(input())
s = input()[:-1]
q = []
c = ''
for i in s:
if i in '!.?':
c += i
q.append(c.lstrip(' '))
c = ''
else:
c += i
c = 0
a = 1
for i in q:
if c == 0:
c += len(i)
if c > n:
print('Impossible')
... | Codeforces Beta Round 64 | CF | 2,011 | 1 | 256 | Text Messaging | Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one text message). Thus, whole sentences and words get split!
Fangy did not like ... | The first line contains an integer n, which is the size of one message (2 ≤ n ≤ 255). The second line contains the text. The length of the text does not exceed 104 characters. It is guaranteed that the text satisfies the above described format. Specifically, this implies that the text is not empty. | On the first and only line print the number of text messages Fangy will need. If it is impossible to split the text, print "Impossible" without the quotes. | null | Let's take a look at the third sample. The text will be split into three messages: "Hello!", "Do you like fish?" and "Why?". | [{"input": "25\nHello. I am a little walrus.", "output": "2"}, {"input": "2\nHow are you?", "output": "Impossible"}, {"input": "19\nHello! Do you like fish? Why?", "output": "3"}] | 1,600 | ["expression parsing", "greedy", "strings"] | 48 | [{"input": "25\r\nHello. I am a little walrus.\r\n", "output": "2\r\n"}, {"input": "2\r\nHow are you?\r\n", "output": "Impossible\r\n"}, {"input": "19\r\nHello! Do you like fish? Why?\r\n", "output": "3\r\n"}, {"input": "4\r\na. A.\r\n", "output": "2\r\n"}, {"input": "146\r\niIQVkDsPqzAJyBrtHk EhBSN gzDoigItCMzETerb cI... | false | stdio | null | true |
270/B | 270 | B | Python 3 | TESTS | 1 | 62 | 0 | 211206820 | n=int(input())
a=list(map(int,input().split()))
i,ans,m=n-2,0,a[-1]
while i >= 0:
if m>a[i]:
m=a[i]
else:
ans+=1
i-=1
if ans==0: ans+=1
print(ans) | 41 | 186 | 13,516,800 | 217312493 | n = (int)(input())
a = (list)(map(int , input().split()))
for _ in range(n - 1 , -1 , -1) :
if _ > 0 and a[_] < a[_ - 1] :
print(_)
quit()
print(0) | Codeforces Round 165 (Div. 2) | CF | 2,013 | 2 | 256 | Multithreading | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.
Recent actions shows a list of n different threads ordered by the time of the latest message in the thread.... | The first line of input contains an integer n, the number of threads (1 ≤ n ≤ 105). The next line contains a list of n space-separated integers a1, a2, ..., an where ai (1 ≤ ai ≤ n) is the old position of the i-th thread in the new list. It is guaranteed that all of the ai are distinct. | Output a single integer — the number of threads that surely contain a new message. | null | In the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.
In the second test case, there may be no new messages at all, since the thread order hasn't changed.
In the thi... | [{"input": "5\n5 2 1 3 4", "output": "2"}, {"input": "3\n1 2 3", "output": "0"}, {"input": "4\n4 3 2 1", "output": "3"}] | 1,400 | ["data structures", "greedy", "implementation"] | 41 | [{"input": "5\r\n5 2 1 3 4\r\n", "output": "2\r\n"}, {"input": "3\r\n1 2 3\r\n", "output": "0\r\n"}, {"input": "4\r\n4 3 2 1\r\n", "output": "3\r\n"}, {"input": "5\r\n1 2 5 3 4\r\n", "output": "3\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 2\r\n", "output": "0\r\n"}, {"input": "2\r\n2 1\r\n", "... | false | stdio | null | true |
543/B | 543 | B | Python 3 | TESTS | 11 | 483 | 1,843,200 | 98576829 | n,m = map(int,input().strip().split())
roads = set()
cnt=0
Graph = dict((k+1,{}) for k in range(n))
for _ in range(m):
s,t = map(int,input().strip().split())
Graph[s][t]=cnt
Graph[t][s]=cnt
cnt+=1
s1,t1,l1 = map(int,input().strip().split())
s2,t2,l2 = map(int,input().strip().split())
from queue import P... | 63 | 1,731 | 91,955,200 | 174886422 | from collections import deque
n,m=map(int,input().split())
graph=[[] for _ in range(n)]
for i in range(m):
a,b=map(int,input().split())
a-=1
b-=1
graph[a].append(b)
graph[b].append(a)
d=[[-1]*n for _ in range(n)]
for i in range(n):
q=deque()
q.append(i)
d[i][i]=0
while q:
n... | Codeforces Round 302 (Div. 1) | CF | 2,015 | 2 | 256 | Destroying Roads | In some country there are exactly n cities and m bidirectional roads connecting the cities. Cities are numbered with integers from 1 to n. If cities a and b are connected by a road, then in an hour you can go along this road either from city a to city b, or from city b to city a. The road network is such that from any ... | The first line contains two integers n, m (1 ≤ n ≤ 3000, $$n-1\leq m\leq \min\{3000,\frac{n(n-1)}{2}\}$$) — the number of cities and roads in the country, respectively.
Next m lines contain the descriptions of the roads as pairs of integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi). It is guaranteed that the roads that are giv... | Print a single number — the answer to the problem. If the it is impossible to meet the conditions, print -1. | null | null | [{"input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 2", "output": "0"}, {"input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n2 4 2", "output": "1"}, {"input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 1", "output": "-1"}] | 2,100 | ["constructive algorithms", "graphs", "shortest paths"] | 63 | [{"input": "5 4\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n1 3 2\r\n3 5 2\r\n", "output": "0\r\n"}, {"input": "5 4\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n1 3 2\r\n2 4 2\r\n", "output": "1\r\n"}, {"input": "5 4\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n1 3 2\r\n3 5 1\r\n", "output": "-1\r\n"}, {"input": "9 9\r\n1 2\r\n2 3\r\n2 4\r\n4 5\r\n5 7\r\n5 6\... | false | stdio | null | true |
595/A | 595 | A | PyPy 3 | TESTS | 6 | 140 | 204,800 | 71854364 | ab= input().split()
a= int(ab[0])
b= int(ab[1])
array=''
for i in range(a):
array= array+(input())
array = array.replace(" ","")
s= array.count('00')
print(a*b-s) | 36 | 46 | 0 | 167148218 | n = [int(x) for x in input().split()]
count = 0
queue = []
for i in range(0, n[0]):
s = [int(x) for x in input().split()]
for j in range(0, n[1] * 2 - 1, 2):
or1 = s[j] == 1
or2 = s[j + 1] == 1
if or1 or or2:
count += 1
print(count) | Codeforces Round 330 (Div. 2) | CF | 2,015 | 1 | 256 | Vitaly and Night | One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered ... | The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of floors in the house and the number of flats on each floor respectively.
Next n lines describe the floors from top to bottom and contain 2·m characters each. If the i-th window of the given floor has lights on, then the i-th char... | Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping. | null | In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The ligh... | [{"input": "2 2\n0 0 0 1\n1 0 1 1", "output": "3"}, {"input": "1 3\n1 1 0 1 0 0", "output": "2"}] | 800 | ["constructive algorithms", "implementation"] | 36 | [{"input": "2 2\r\n0 0 0 1\r\n1 0 1 1\r\n", "output": "3\r\n"}, {"input": "1 3\r\n1 1 0 1 0 0\r\n", "output": "2\r\n"}, {"input": "3 3\r\n1 1 1 1 1 1\r\n1 1 0 1 1 0\r\n1 0 0 0 1 1\r\n", "output": "8\r\n"}, {"input": "1 5\r\n1 0 1 1 1 0 1 1 1 1\r\n", "output": "5\r\n"}, {"input": "1 100\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... | false | stdio | null | true |
16/A | 16 | A | Python 3 | TESTS | 15 | 92 | 0 | 137028589 | a,b=map(int,input().split(" "))
s=[]
flag=True
for i in range(a):
t=input()
s.append(t)
for i in range(a):
for j in range(b):
if s[i][j]!=s[i][0]:
flag=False
for x in range(a-2):
if s[x][0]==s[x+1][0]:
flag=False
if s[a-2][0]==s[a-1][0]:
flag=False
if flag or (a==1 and b=... | 35 | 62 | 0 | 227054671 | def is_iso_flag(n, m, flag):
for i in range(n):
for j in range(1, m):
if flag[i][j] != flag[i][j - 1]:
return "NO"
for i in range(1, n):
if flag[i][0] == flag[i - 1][0]:
return "NO"
return "YES"
n, m = map(int, input().split())
flag = [list(input().st... | Codeforces Beta Round 16 (Div. 2 Only) | ICPC | 2,010 | 2 | 64 | Flag | According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland'... | The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the... | Output YES, if the flag meets the new ISO standard, and NO otherwise. | null | null | [{"input": "3 3\n000\n111\n222", "output": "YES"}, {"input": "3 3\n000\n000\n111", "output": "NO"}, {"input": "3 3\n000\n111\n002", "output": "NO"}] | 800 | ["implementation"] | 35 | [{"input": "3 3\r\n000\r\n111\r\n222\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n000\r\n000\r\n111\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n000\r\n111\r\n002\r\n", "output": "NO\r\n"}, {"input": "10 10\r\n2222222222\r\n5555555555\r\n0000000000\r\n4444444444\r\n1111111111\r\n3333333393\r\n3333333333\r\n5555555555\... | false | stdio | null | true |
16/A | 16 | A | PyPy 3 | TESTS | 20 | 218 | 0 | 115146850 | import sys
def main():
_, *s = sys.stdin.read().strip().split('\n')
for i,j in zip(s, s[1:]):
s1, s2 = set(i), set(j)
if len(s1) != 1 or len(s2) != 1 or s1 == s2: return 'NO'
return 'YES'
print(main()) | 35 | 78 | 102,400 | 3906965 | n,m=input().split()
x='a'
n=int(n)
m=int(m)
k=True
for i in range(n):
s=input()
if(s.count(s[0])==m and s[0]!=x and k):
x=s[0]
continue
k=False
if(k):
print("YES")
else:
print("NO") | Codeforces Beta Round 16 (Div. 2 Only) | ICPC | 2,010 | 2 | 64 | Flag | According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland'... | The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the... | Output YES, if the flag meets the new ISO standard, and NO otherwise. | null | null | [{"input": "3 3\n000\n111\n222", "output": "YES"}, {"input": "3 3\n000\n000\n111", "output": "NO"}, {"input": "3 3\n000\n111\n002", "output": "NO"}] | 800 | ["implementation"] | 35 | [{"input": "3 3\r\n000\r\n111\r\n222\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n000\r\n000\r\n111\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n000\r\n111\r\n002\r\n", "output": "NO\r\n"}, {"input": "10 10\r\n2222222222\r\n5555555555\r\n0000000000\r\n4444444444\r\n1111111111\r\n3333333393\r\n3333333333\r\n5555555555\... | false | stdio | null | true |
16/A | 16 | A | Python 3 | TESTS | 20 | 218 | 0 | 78471653 | n, m = map(int, input().split())
ans = 'YES'
s = input()
last = s
for i in range(n - 1):
s = input()
if len(set(s)) == 1:
if s == last:
ans = 'NO'
break
else:
last = s
else:
ans = 'NO'
break
print(ans) | 35 | 92 | 0 | 4738299 | def f():
y = ''
n, m = map(int, input().split())
for i in range(n):
t = set(input())
if len(t) > 1: return 'NO'
x = t.pop()
if y == x: return 'NO'
y = x
return 'YES'
print(f()) | Codeforces Beta Round 16 (Div. 2 Only) | ICPC | 2,010 | 2 | 64 | Flag | According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland'... | The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the... | Output YES, if the flag meets the new ISO standard, and NO otherwise. | null | null | [{"input": "3 3\n000\n111\n222", "output": "YES"}, {"input": "3 3\n000\n000\n111", "output": "NO"}, {"input": "3 3\n000\n111\n002", "output": "NO"}] | 800 | ["implementation"] | 35 | [{"input": "3 3\r\n000\r\n111\r\n222\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n000\r\n000\r\n111\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n000\r\n111\r\n002\r\n", "output": "NO\r\n"}, {"input": "10 10\r\n2222222222\r\n5555555555\r\n0000000000\r\n4444444444\r\n1111111111\r\n3333333393\r\n3333333333\r\n5555555555\... | false | stdio | null | true |
992/D | 992 | D | PyPy 3 | TESTS | 2 | 77 | 1,433,600 | 106079270 | n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(0, n):
p = 1
s = 0
for j in range(i, n):
p = p * a[j]
s = s + a[j]
if p % s == 0 and p // s == k:
ans = ans + 1
if p // s > k:
break
print(ans) | 134 | 920 | 21,504,000 | 106082630 | n, k = map(int, input().split())
flag = [0 for i in range(0, n)]
a = list(map(int, input().split()))
r = [-1 for i in range(0, n)]
i = 0
while i < n:
if a[i] != 1:
i = i + 1
continue
j = i
while j < n and a[j] == 1:
j = j + 1
while i < j:
r[i] = j - 1
i = i + 1
an... | Codeforces Round 489 (Div. 2) | CF | 2,018 | 2 | 256 | Nastya and a Game | Nastya received one more array on her birthday, this array can be used to play a traditional Byteland game on it. However, to play the game the players should first select such a subsegment of the array that $$\frac{p}{s} = k$$, where p is the product of all integers on the given array, s is their sum, and k is a given... | The first line contains two integers n and k (1 ≤ n ≤ 2·105, 1 ≤ k ≤ 105), where n is the length of the array and k is the constant described above.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 108) — the elements of the array. | In the only line print the number of subsegments such that the ratio between the product and the sum on them is equal to k. | null | In the first example the only subsegment is [1]. The sum equals 1, the product equals 1, so it suits us because $${ \frac { 1 } { 1 } } = 1$$.
There are two suitable subsegments in the second example — [6, 3] and [3, 8, 1]. Subsegment [6, 3] has sum 9 and product 18, so it suits us because $$\frac{18}{9}=2$$. Subsegme... | [{"input": "1 1\n1", "output": "1"}, {"input": "4 2\n6 3 8 1", "output": "2"}] | 2,100 | ["brute force", "implementation", "math"] | 134 | [{"input": "1 1\r\n1\r\n", "output": "1\r\n"}, {"input": "4 2\r\n6 3 8 1\r\n", "output": "2\r\n"}, {"input": "94 58\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 29 58 1 1 1 29 58 58 1 1 29 1 1 1 1 2 1 58 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 29 1 1 1 1 1 58 1 29 1 1 1 1 1 1 1 1 1 1 1 1 58 1 1 1 1 1 2 1 1 1\r\... | false | stdio | null | true |
70/B | 70 | B | PyPy 3-64 | TESTS | 45 | 62 | 1,536,000 | 200572168 | def func():
n=int(input())
s=input()+'#'
msgs,found,t,ct=[],False,'',0
for e in s:
if found and e == ' ':
found = False
continue
if e == '.' or e =='!' or e == '?' or e == '#':
if e != '#': t += e
if t: msgs.append(t)
found=True... | 48 | 109 | 307,200 | 14438668 | import re
segment_size = int(input())
sentences = re.findall('\w.*?[.?!]', input())
for sentence in sentences:
if len(sentence) > segment_size:
print('Impossible')
import sys
sys.exit()
len_current = len(sentences[0])
num_segments = 1
for sentence in sentences[1:]:
if len_current + 1 ... | Codeforces Beta Round 64 | CF | 2,011 | 1 | 256 | Text Messaging | Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one text message). Thus, whole sentences and words get split!
Fangy did not like ... | The first line contains an integer n, which is the size of one message (2 ≤ n ≤ 255). The second line contains the text. The length of the text does not exceed 104 characters. It is guaranteed that the text satisfies the above described format. Specifically, this implies that the text is not empty. | On the first and only line print the number of text messages Fangy will need. If it is impossible to split the text, print "Impossible" without the quotes. | null | Let's take a look at the third sample. The text will be split into three messages: "Hello!", "Do you like fish?" and "Why?". | [{"input": "25\nHello. I am a little walrus.", "output": "2"}, {"input": "2\nHow are you?", "output": "Impossible"}, {"input": "19\nHello! Do you like fish? Why?", "output": "3"}] | 1,600 | ["expression parsing", "greedy", "strings"] | 48 | [{"input": "25\r\nHello. I am a little walrus.\r\n", "output": "2\r\n"}, {"input": "2\r\nHow are you?\r\n", "output": "Impossible\r\n"}, {"input": "19\r\nHello! Do you like fish? Why?\r\n", "output": "3\r\n"}, {"input": "4\r\na. A.\r\n", "output": "2\r\n"}, {"input": "146\r\niIQVkDsPqzAJyBrtHk EhBSN gzDoigItCMzETerb cI... | false | stdio | null | true |
213/A | 213 | A | Python 3 | TESTS | 4 | 122 | 5,120,000 | 18412115 | n = int(input())
c = list(map(int, input().split()))
d = dict()
d[1] = []
d[2] = []
d[3] = []
for i in range(n):
d[c[i]].append(i)
done = set()
mas = []
k = 0
ans = 1
for i in range(n):
l = list(map(int, input().split()))
l = l[1:]
mas.append(l)
if len(l) == 0:
k = c[i]
done.add(i + ... | 74 | 186 | 1,945,600 | 143211734 | input_func = lambda: [int(q) - 1 for q in input().split()]
def cmpltbl_msn():
for i in msn_list:
if msn_com_crspnd[i] == com and not c_data[i]: return i
r = range(int(input()))
time, msn_com_crspnd = 1e9, input_func()
data = [set(input_func()[1:]) for i in r]
for com in (0, 1, 2):
msn_list = list(r)... | Codeforces Round 131 (Div. 1) | CF | 2,012 | 1 | 256 | Game | Furik and Rubik love playing computer games. Furik has recently found a new game that greatly interested Rubik. The game consists of n parts and to complete each part a player may probably need to complete some other ones. We know that the game can be fully completed, that is, its parts do not form cyclic dependencies.... | The first line contains integer n (1 ≤ n ≤ 200) — the number of game parts. The next line contains n integers, the i-th integer — ci (1 ≤ ci ≤ 3) represents the number of the computer, on which you can complete the game part number i.
Next n lines contain descriptions of game parts. The i-th line first contains intege... | On a single line print the answer to the problem. | null | Note to the second sample: before the beginning of the game the best strategy is to stand by the third computer. First we complete part 5. Then we go to the 1-st computer and complete parts 3 and 4. Then we go to the 2-nd computer and complete parts 1 and 2. In total we get 1+1+2+1+2, which equals 7 hours. | [{"input": "1\n1\n0", "output": "1"}, {"input": "5\n2 2 1 1 3\n1 5\n2 5 1\n2 5 4\n1 5\n0", "output": "7"}] | 1,700 | ["dfs and similar", "greedy"] | 74 | [{"input": "1\r\n1\r\n0\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 1 1 3\r\n1 5\r\n2 5 1\r\n2 5 4\r\n1 5\r\n0\r\n", "output": "7\r\n"}, {"input": "7\r\n1 3 3 1 2 1 1\r\n0\r\n1 1\r\n1 1\r\n2 1 6\r\n3 1 2 7\r\n1 1\r\n1 1\r\n", "output": "11\r\n"}, {"input": "2\r\n2 1\r\n0\r\n1 1\r\n", "output": "4\r\n"}, {"input": "3\... | false | stdio | null | true |
598/A | 598 | A | Python 3 | TESTS | 5 | 46 | 0 | 203037078 | import math
for _ in range(int(input())):
n=int(input())
if n==10**9:
print(int(((n*(n+1))/2)-2*(2**(math.floor(math.log(n,2))+1)-1))+2)
else:
print(int(((n*(n+1))/2)-2*(2**(math.floor(math.log(n,2))+1)-1))) | 21 | 31 | 0 | 187988288 | import math
def ans(n):
a=int(math.log(n,2))
b=(2**(a+1))-1
c=2*b
d=(n*(n+1))//2
print(d-c)
n=int(input())
l1=[]
for i in range(n):
l1.append(int(input()))
for i in l1:
ans(i)
print() | Educational Codeforces Round 1 | ICPC | 2,015 | 1 | 256 | Tricky Sum | In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum.
For example, for n = 4 the sum is equal to - 1 - 2 + 3 - 4 = - 4, because 1, 2 and 4 are 20, 21 and 22 respectively.
Calculate the answer for t values of n. | The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of values of n to be processed.
Each of next t lines contains a single integer n (1 ≤ n ≤ 109). | Print the requested sum for each of t integers n given in the input. | null | The answer for the first sample is explained in the statement. | [{"input": "2\n4\n1000000000", "output": "-4\n499999998352516354"}] | 900 | ["math"] | 21 | [{"input": "2\r\n4\r\n1000000000\r\n", "output": "-4\r\n499999998352516354\r\n"}, {"input": "10\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n", "output": "-1\r\n-3\r\n0\r\n-4\r\n1\r\n7\r\n14\r\n6\r\n15\r\n25\r\n"}, {"input": "10\r\n10\r\n9\r\n47\r\n33\r\n99\r\n83\r\n62\r\n1\r\n100\r\n53\r\n", "output": "25\r\n... | false | stdio | null | true |
598/A | 598 | A | Python 3 | TESTS | 5 | 46 | 0 | 203982159 | #!/usr/bin/env python3
import math
n = int(input())
ans = []
for i in range(n):
k = int(input())
total = int(k*(k+1)/2)
log = 0
while 2**log <= k:
log += 1
log -= 1
ans.append(total + 2 - 2**(log+2))
for a in ans:
print(a) | 21 | 31 | 0 | 206008441 | import math;
k=int(input())
for i in range(k):
n=int(input())
total_sum=(n*(n+1))//2
max_p=int(math.log2(n))
sum_2=(2**(max_p+1))-1
print(round(total_sum-2*sum_2)) | Educational Codeforces Round 1 | ICPC | 2,015 | 1 | 256 | Tricky Sum | In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum.
For example, for n = 4 the sum is equal to - 1 - 2 + 3 - 4 = - 4, because 1, 2 and 4 are 20, 21 and 22 respectively.
Calculate the answer for t values of n. | The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of values of n to be processed.
Each of next t lines contains a single integer n (1 ≤ n ≤ 109). | Print the requested sum for each of t integers n given in the input. | null | The answer for the first sample is explained in the statement. | [{"input": "2\n4\n1000000000", "output": "-4\n499999998352516354"}] | 900 | ["math"] | 21 | [{"input": "2\r\n4\r\n1000000000\r\n", "output": "-4\r\n499999998352516354\r\n"}, {"input": "10\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n", "output": "-1\r\n-3\r\n0\r\n-4\r\n1\r\n7\r\n14\r\n6\r\n15\r\n25\r\n"}, {"input": "10\r\n10\r\n9\r\n47\r\n33\r\n99\r\n83\r\n62\r\n1\r\n100\r\n53\r\n", "output": "25\r\n... | false | stdio | null | true |
598/A | 598 | A | Python 3 | TESTS | 5 | 30 | 0 | 223506957 | n = int(input())
while n > 0:
t = int(input())
sum = int((t * (t + 1)) / 2)
t1 = 1
s = 0
i = 0
while t1 <= t:
s += t1
i += 1
t1 = int(pow(2, i))
temp = sum - s
print(temp - s)
n -= 1 | 21 | 31 | 0 | 207709696 | t = int(input())
for _ in range(t):
n = int(input())
sum = n * (n + 1) // 2
z = 1
pSum = 0
while z <= n:
pSum += z
z = z * 2
ans = sum - 2 * pSum
print(ans) | Educational Codeforces Round 1 | ICPC | 2,015 | 1 | 256 | Tricky Sum | In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum.
For example, for n = 4 the sum is equal to - 1 - 2 + 3 - 4 = - 4, because 1, 2 and 4 are 20, 21 and 22 respectively.
Calculate the answer for t values of n. | The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of values of n to be processed.
Each of next t lines contains a single integer n (1 ≤ n ≤ 109). | Print the requested sum for each of t integers n given in the input. | null | The answer for the first sample is explained in the statement. | [{"input": "2\n4\n1000000000", "output": "-4\n499999998352516354"}] | 900 | ["math"] | 21 | [{"input": "2\r\n4\r\n1000000000\r\n", "output": "-4\r\n499999998352516354\r\n"}, {"input": "10\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n", "output": "-1\r\n-3\r\n0\r\n-4\r\n1\r\n7\r\n14\r\n6\r\n15\r\n25\r\n"}, {"input": "10\r\n10\r\n9\r\n47\r\n33\r\n99\r\n83\r\n62\r\n1\r\n100\r\n53\r\n", "output": "25\r\n... | false | stdio | null | true |
12/C | 12 | C | PyPy 3 | TESTS | 6 | 483 | 11,468,800 | 96417031 | import math
import os
import random
import re
import sys
import functools
from operator import itemgetter, attrgetter
if __name__ == '__main__':
n, m = list(map(int, input().strip().split()))
a, b, c = list(map(int, input().strip().split())), list(), 1
r, min_val, max_val = list(), 0, 0
for i in range... | 25 | 31 | 0 | 198537610 | def main():
n, m = map(int, input().split())
tags = list(map(int, input().split()))
shopping_list = {}
for i in range(m):
fruit = input()
if fruit in shopping_list:
shopping_list[fruit] += 1
else:
shopping_list[fruit] = 1
tags.sort()
sorted_list =... | Codeforces Beta Round 12 (Div 2 Only) | ICPC | 2,010 | 1 | 256 | Fruits | The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times.
When he came to the fruit stall of Asho... | The first line of the input contains two integer number n and m (1 ≤ n, m ≤ 100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exc... | Print two numbers a and b (a ≤ b) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list. | null | null | [{"input": "5 3\n4 2 1 10 5\napple\norange\nmango", "output": "7 19"}, {"input": "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange", "output": "11 30"}] | 1,100 | ["greedy", "implementation", "sortings"] | 25 | [{"input": "5 3\r\n4 2 1 10 5\r\napple\r\norange\r\nmango\r\n", "output": "7 19\r\n"}, {"input": "6 5\r\n3 5 1 6 8 1\r\npeach\r\ngrapefruit\r\nbanana\r\norange\r\norange\r\n", "output": "11 30\r\n"}, {"input": "2 2\r\n91 82\r\neiiofpfpmemlakcystpun\r\nmcnzeiiofpfpmemlakcystpunfl\r\n", "output": "173 173\r\n"}, {"input"... | false | stdio | null | true |
523/D | 523 | D | PyPy 3 | TESTS | 19 | 2,105 | 83,763,200 | 22935788 | from sys import stdin, stdout
lines = stdin.readlines()
from random import random
from time import time
"""
n = 500000
k = 33279
lines = [( str(n)+' '+str(k) )]
for i in range(n):
x = int(random()*100000)
y = 1000000000 + int(random()*10000)
lines.append( str(x)+' '+str(y) )
"""
t1 = time()
n, k =... | 68 | 701 | 14,950,400 | 211272535 | import sys
input = lambda: sys.stdin.readline().rstrip()
from heapq import *
N,K = map(int, input().split())
v = [0]*K
for _ in range(N):
s,m = map(int, input().split())
t = heappop(v)
d = max(s,t)
print(d+m)
heappush(v,d+m) | VK Cup 2015 - Qualification Round 2 | CF | 2,015 | 3 | 256 | Statistics of Recompressing Videos | A social network for dogs called DH (DogHouse) has k special servers to recompress uploaded videos of cute cats. After each video is uploaded, it should be recompressed on one (any) of the servers, and only after that it can be saved in the social network.
We know that each server takes one second to recompress a one ... | The first line of the input contains integers n and k (1 ≤ n, k ≤ 5·105) — the number of videos and servers, respectively.
Next n lines contain the descriptions of the videos as pairs of integers si, mi (1 ≤ si, mi ≤ 109), where si is the time in seconds when the i-th video appeared and mi is its duration in minutes. ... | Print n numbers e1, e2, ..., en, where ei is the time in seconds after the servers start working, when the i-th video will be recompressed. | null | null | [{"input": "3 2\n1 5\n2 5\n3 5", "output": "6\n7\n11"}, {"input": "6 1\n1 1000000000\n2 1000000000\n3 1000000000\n4 1000000000\n5 1000000000\n6 3", "output": "1000000001\n2000000001\n3000000001\n4000000001\n5000000001\n5000000004"}] | 1,600 | ["*special", "data structures", "implementation"] | 68 | [{"input": "3 2\r\n1 5\r\n2 5\r\n3 5\r\n", "output": "6\r\n7\r\n11\r\n"}, {"input": "6 1\r\n1 1000000000\r\n2 1000000000\r\n3 1000000000\r\n4 1000000000\r\n5 1000000000\r\n6 3\r\n", "output": "1000000001\r\n2000000001\r\n3000000001\r\n4000000001\r\n5000000001\r\n5000000004\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "... | false | stdio | null | true |
711/A | 711 | A | Python 3 | TESTS | 4 | 31 | 0 | 205447276 | n=int(input())
ans=False
res=[]
occ=False
for i in range(n):
st=input()
if not occ:
if st=='OO|OX' or st=='OO|XO' or st=='OO|XX':
res.append('++'+st[2:])
occ=True
ans=True
elif st=="OX|OO" or st=="XO|OO" or st=="XX|OO":
res.append(st[:3]+'++')
... | 71 | 46 | 0 | 147379128 | n = int(input())
arr = [str(input()) for _ in range(n)]
con = True
for i in range(n):
if arr[i][:2] == 'OO':
m = '++|'+arr[i][3:]
arr[i] = m
con = False
break
elif arr[i][3:] == 'OO':
m = arr[i][:2]+'|++'
arr[i] = m
con = False
break
if con:
pr... | Codeforces Round 369 (Div. 2) | CF | 2,016 | 2 | 256 | Bus to Udayland | ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has n rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris are... | The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of rows of seats in the bus.
Then, n lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and the last tw... | If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next n lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by ex... | null | Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | [{"input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX", "output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX"}, {"input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX", "output": "NO"}, {"input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO", "output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO"}] | 800 | ["brute force", "implementation"] | 71 | [{"input": "6\r\nOO|OX\r\nXO|XX\r\nOX|OO\r\nXX|OX\r\nOO|OO\r\nOO|XX\r\n", "output": "YES\r\n++|OX\r\nXO|XX\r\nOX|OO\r\nXX|OX\r\nOO|OO\r\nOO|XX\r\n"}, {"input": "4\r\nXO|OX\r\nXO|XX\r\nOX|OX\r\nXX|OX\r\n", "output": "NO\r\n"}, {"input": "5\r\nXX|XX\r\nXX|XX\r\nXO|OX\r\nXO|OO\r\nOX|XO\r\n", "output": "YES\r\nXX|XX\r\nXX|... | false | stdio | null | true |
598/A | 598 | A | Python 3 | TESTS | 5 | 46 | 0 | 204272188 | for i in range(int(input())):
n=int(input())
s1=int(n*(n+1)/2)
s2=1
while s2<=n:
s1-=s2*2
s2*=2
print(int(s1)) | 21 | 31 | 0 | 208074521 | def trickySum(n):
totalSum = (n*(n+1)//2)
i = 0
while(2**i<=n):
i+=1
i-=1
toMinus = 2*(2**i) - 1
remainder = totalSum - toMinus
return remainder - toMinus
T = int(input())
while(T):
n = int(input())
T-=1
print(trickySum(n)) | Educational Codeforces Round 1 | ICPC | 2,015 | 1 | 256 | Tricky Sum | In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum.
For example, for n = 4 the sum is equal to - 1 - 2 + 3 - 4 = - 4, because 1, 2 and 4 are 20, 21 and 22 respectively.
Calculate the answer for t values of n. | The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of values of n to be processed.
Each of next t lines contains a single integer n (1 ≤ n ≤ 109). | Print the requested sum for each of t integers n given in the input. | null | The answer for the first sample is explained in the statement. | [{"input": "2\n4\n1000000000", "output": "-4\n499999998352516354"}] | 900 | ["math"] | 21 | [{"input": "2\r\n4\r\n1000000000\r\n", "output": "-4\r\n499999998352516354\r\n"}, {"input": "10\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n", "output": "-1\r\n-3\r\n0\r\n-4\r\n1\r\n7\r\n14\r\n6\r\n15\r\n25\r\n"}, {"input": "10\r\n10\r\n9\r\n47\r\n33\r\n99\r\n83\r\n62\r\n1\r\n100\r\n53\r\n", "output": "25\r\n... | false | stdio | null | true |
711/A | 711 | A | Python 3 | TESTS | 4 | 31 | 0 | 210633023 | a=[]
n=int(input())
for i in range(n):
a.append(input())
c=0
b=[]
for i in range(n):
if 'OO' in a[i]:
s=a[i].replace('OO','++')
a[i]=s
c=1
break
if c==1:
print('YES')
for i in range(n):
print(a[i])
else:
print('NO') | 71 | 46 | 0 | 147989694 | l=[]
for _ in range(int(input())):
s=input()
l.append(s)
flag=0
for i in range(len(l)):
if 'OO' in l[i]:
flag=1
if l[i].count("OO")>1:
l[i]=l[i].replace("OO","++")
l[i]="++|OO"
break
else:
l[i]=l[i].replace("OO","++")
break
... | Codeforces Round 369 (Div. 2) | CF | 2,016 | 2 | 256 | Bus to Udayland | ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has n rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris are... | The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of rows of seats in the bus.
Then, n lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and the last tw... | If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next n lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by ex... | null | Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | [{"input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX", "output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX"}, {"input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX", "output": "NO"}, {"input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO", "output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO"}] | 800 | ["brute force", "implementation"] | 71 | [{"input": "6\r\nOO|OX\r\nXO|XX\r\nOX|OO\r\nXX|OX\r\nOO|OO\r\nOO|XX\r\n", "output": "YES\r\n++|OX\r\nXO|XX\r\nOX|OO\r\nXX|OX\r\nOO|OO\r\nOO|XX\r\n"}, {"input": "4\r\nXO|OX\r\nXO|XX\r\nOX|OX\r\nXX|OX\r\n", "output": "NO\r\n"}, {"input": "5\r\nXX|XX\r\nXX|XX\r\nXO|OX\r\nXO|OO\r\nOX|XO\r\n", "output": "YES\r\nXX|XX\r\nXX|... | false | stdio | null | true |
711/A | 711 | A | Python 3 | TESTS | 5 | 46 | 307,200 | 104715695 | # -*- coding: utf-8 -*-
"""
Created on Mon Jan 18 13:34:25 2021
@author: vukhe
"""
no = int(input())
l = []
for i in range(no):
l.append(input())
available = False
for x in range(no):
if l[x][0] == 'O' and l[x][1] =='O':
row = x
available = True
break
elif l[x][3] == 'O' and l[x... | 71 | 46 | 0 | 148150866 | def seats():
lst = []
status = False
t = int(input())
for i in range(t):
temp = input()
if not status:
if temp[:2] == "OO":
status = True
temp = "++" + temp[2:]
elif temp[3:] == "OO":... | Codeforces Round 369 (Div. 2) | CF | 2,016 | 2 | 256 | Bus to Udayland | ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has n rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris are... | The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of rows of seats in the bus.
Then, n lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and the last tw... | If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next n lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by ex... | null | Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | [{"input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX", "output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX"}, {"input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX", "output": "NO"}, {"input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO", "output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO"}] | 800 | ["brute force", "implementation"] | 71 | [{"input": "6\r\nOO|OX\r\nXO|XX\r\nOX|OO\r\nXX|OX\r\nOO|OO\r\nOO|XX\r\n", "output": "YES\r\n++|OX\r\nXO|XX\r\nOX|OO\r\nXX|OX\r\nOO|OO\r\nOO|XX\r\n"}, {"input": "4\r\nXO|OX\r\nXO|XX\r\nOX|OX\r\nXX|OX\r\n", "output": "NO\r\n"}, {"input": "5\r\nXX|XX\r\nXX|XX\r\nXO|OX\r\nXO|OO\r\nOX|XO\r\n", "output": "YES\r\nXX|XX\r\nXX|... | false | stdio | null | true |
598/A | 598 | A | Python 3 | TESTS | 5 | 46 | 0 | 204272567 | for i in range(int(input())):
n=int(input())
s1=int(n*(n+1)/2)
p=1
while p<=n:
s1-=2*p
p=p*2
print(s1) | 21 | 31 | 0 | 211178742 | def solve():
inp = int(input())
res = inp * (inp + 1) // 2
i = 0
while pow(2, i) <= inp:
res -= 2 * pow(2, i)
i += 1
print(res)
test_case = int(input())
while test_case > 0:
solve()
test_case -= 1 | Educational Codeforces Round 1 | ICPC | 2,015 | 1 | 256 | Tricky Sum | In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum.
For example, for n = 4 the sum is equal to - 1 - 2 + 3 - 4 = - 4, because 1, 2 and 4 are 20, 21 and 22 respectively.
Calculate the answer for t values of n. | The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of values of n to be processed.
Each of next t lines contains a single integer n (1 ≤ n ≤ 109). | Print the requested sum for each of t integers n given in the input. | null | The answer for the first sample is explained in the statement. | [{"input": "2\n4\n1000000000", "output": "-4\n499999998352516354"}] | 900 | ["math"] | 21 | [{"input": "2\r\n4\r\n1000000000\r\n", "output": "-4\r\n499999998352516354\r\n"}, {"input": "10\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n", "output": "-1\r\n-3\r\n0\r\n-4\r\n1\r\n7\r\n14\r\n6\r\n15\r\n25\r\n"}, {"input": "10\r\n10\r\n9\r\n47\r\n33\r\n99\r\n83\r\n62\r\n1\r\n100\r\n53\r\n", "output": "25\r\n... | false | stdio | null | true |
596/C | 596 | C | Python 3 | TESTS | 9 | 109 | 409,600 | 49625158 | from collections import defaultdict
from operator import itemgetter
n = int(input())
points = []
point_weights = defaultdict(list)
for _ in range(n):
x, y = tuple(map(int,input().split()))
points.append((x, y))
point_weights[y - x].append((x, y))
weights = list(map(int, input().split()))
points.sort(key... | 76 | 764 | 48,844,800 | 202377135 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
l = 2 * pow(10, 5) + 5
u = [[] for _ in range(l)]
for _ in range(n):
x, y = map(int, input().split())
u[y - x].append((x, y))
for i in range(l):
u[i].sort(reverse = True)
ok = set()
for i in range(n + 5):
o... | Codeforces Round 331 (Div. 2) | CF | 2,015 | 2 | 256 | Wilbur and Points | Wilbur is playing with a set of n points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point (x, y) belongs to the set, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y also belong to this set.
Now Wilbur wants to number the points in the set he has, that is ... | The first line of the input consists of a single integer n (1 ≤ n ≤ 100 000) — the number of points in the set Wilbur is playing with.
Next follow n lines with points descriptions. Each line contains two integers x and y (0 ≤ x, y ≤ 100 000), that give one point in Wilbur's set. It's guaranteed that all points are dis... | If there exists an aesthetically pleasant numbering of points in the set, such that s(xi, yi) = yi - xi = wi, then print "YES" on the first line of the output. Otherwise, print "NO".
If a solution exists, proceed output with n lines. On the i-th of these lines print the point of the set that gets number i. If there ar... | null | In the first sample, point (2, 0) gets number 3, point (0, 0) gets number one, point (1, 0) gets number 2, point (1, 1) gets number 5 and point (0, 1) gets number 4. One can easily check that this numbering is aesthetically pleasing and yi - xi = wi.
In the second sample, the special values of the points in the set ar... | [{"input": "5\n2 0\n0 0\n1 0\n1 1\n0 1\n0 -1 -2 1 0", "output": "YES\n0 0\n1 0\n2 0\n0 1\n1 1"}, {"input": "3\n1 0\n0 0\n2 0\n0 1 2", "output": "NO"}] | 1,700 | ["combinatorics", "greedy", "sortings"] | 76 | [{"input": "5\r\n2 0\r\n0 0\r\n1 0\r\n1 1\r\n0 1\r\n0 -1 -2 1 0\r\n", "output": "YES\r\n0 0\r\n1 0\r\n2 0\r\n0 1\r\n1 1\r\n"}, {"input": "3\r\n1 0\r\n0 0\r\n2 0\r\n0 1 2\r\n", "output": "NO\r\n"}, {"input": "9\r\n0 0\r\n1 0\r\n2 0\r\n0 1\r\n1 1\r\n2 1\r\n1 2\r\n2 2\r\n0 2\r\n0 0 0 -1 -1 -2 1 1 2\r\n", "output": "NO\r\n... | false | stdio | null | true |
596/C | 596 | C | PyPy 3 | TESTS | 9 | 155 | 512,000 | 49588420 | from operator import itemgetter
from collections import defaultdict
n = int(input())
coor = []
coor_list = defaultdict(list)
for _ in range(n):
x, y = list(map(int,input().split()))
coor.append((x,y))
coor_list[y-x].append((x,y))
coor.sort(key=itemgetter(0,1))
coorY = sorted(coor, key=itemgetter(1,0))
# pri... | 76 | 811 | 26,009,600 | 14283908 | n = int(input())
MAX = 100000
coord = [list() for i in range(2 * MAX + 1)]
for i in range(n):
x, y = map(int, input().split())
coord[y - x - MAX].append((x, y))
w = list(map(int, input().split()))
for i in range(2 * MAX + 1):
coord[i].sort()
ans = [(0, 0) for i in range(n)]
possible = True
last_x = [-1] * (... | Codeforces Round 331 (Div. 2) | CF | 2,015 | 2 | 256 | Wilbur and Points | Wilbur is playing with a set of n points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point (x, y) belongs to the set, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y also belong to this set.
Now Wilbur wants to number the points in the set he has, that is ... | The first line of the input consists of a single integer n (1 ≤ n ≤ 100 000) — the number of points in the set Wilbur is playing with.
Next follow n lines with points descriptions. Each line contains two integers x and y (0 ≤ x, y ≤ 100 000), that give one point in Wilbur's set. It's guaranteed that all points are dis... | If there exists an aesthetically pleasant numbering of points in the set, such that s(xi, yi) = yi - xi = wi, then print "YES" on the first line of the output. Otherwise, print "NO".
If a solution exists, proceed output with n lines. On the i-th of these lines print the point of the set that gets number i. If there ar... | null | In the first sample, point (2, 0) gets number 3, point (0, 0) gets number one, point (1, 0) gets number 2, point (1, 1) gets number 5 and point (0, 1) gets number 4. One can easily check that this numbering is aesthetically pleasing and yi - xi = wi.
In the second sample, the special values of the points in the set ar... | [{"input": "5\n2 0\n0 0\n1 0\n1 1\n0 1\n0 -1 -2 1 0", "output": "YES\n0 0\n1 0\n2 0\n0 1\n1 1"}, {"input": "3\n1 0\n0 0\n2 0\n0 1 2", "output": "NO"}] | 1,700 | ["combinatorics", "greedy", "sortings"] | 76 | [{"input": "5\r\n2 0\r\n0 0\r\n1 0\r\n1 1\r\n0 1\r\n0 -1 -2 1 0\r\n", "output": "YES\r\n0 0\r\n1 0\r\n2 0\r\n0 1\r\n1 1\r\n"}, {"input": "3\r\n1 0\r\n0 0\r\n2 0\r\n0 1 2\r\n", "output": "NO\r\n"}, {"input": "9\r\n0 0\r\n1 0\r\n2 0\r\n0 1\r\n1 1\r\n2 1\r\n1 2\r\n2 2\r\n0 2\r\n0 0 0 -1 -1 -2 1 1 2\r\n", "output": "NO\r\n... | false | stdio | null | true |
16/A | 16 | A | Python 3 | TESTS | 20 | 216 | 307,200 | 100393378 | n,m=map(int,input().split())
li = []
for i in range(n):
li.append(list(map(int,input())))
for row in range(1,len(li)):
if li[0].count(li[0][0]) != m:
print('NO')
break
if li[row].count(li[row][0]) != m:
print('NO')
break
if li[row-1] == li[row]:
print('NO')
... | 35 | 92 | 0 | 136748157 | m,n=map(int,input().split())
f=[]
s=True
for i in range(m):
a=list(input())
a=set(a)
f.append(a)
if m==1 and len(a)==1:
print('YES')
exit(0)
elif m==2 and len(a)==1:
if f[0]!=f[1] and len(f[0])==1:
print('YES')
exit(0)
if m>2:
for i in range(1,m-1):
if len(f[i-1])==1 ... | Codeforces Beta Round 16 (Div. 2 Only) | ICPC | 2,010 | 2 | 64 | Flag | According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland'... | The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the... | Output YES, if the flag meets the new ISO standard, and NO otherwise. | null | null | [{"input": "3 3\n000\n111\n222", "output": "YES"}, {"input": "3 3\n000\n000\n111", "output": "NO"}, {"input": "3 3\n000\n111\n002", "output": "NO"}] | 800 | ["implementation"] | 35 | [{"input": "3 3\r\n000\r\n111\r\n222\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n000\r\n000\r\n111\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n000\r\n111\r\n002\r\n", "output": "NO\r\n"}, {"input": "10 10\r\n2222222222\r\n5555555555\r\n0000000000\r\n4444444444\r\n1111111111\r\n3333333393\r\n3333333333\r\n5555555555\... | false | stdio | null | true |
255/C | 255 | C | PyPy 3 | TESTS | 21 | 998 | 29,491,200 | 90514058 | n = int(input())
a = list(map(int,input().split()))
A=[]
for i in range(n-1,-1,-1):
A.append(a[i])
ans = 1
d = {}
for i in a:
d[i]=0
for i in a:
d[i]+=1
maxans = d[max(d)]
for i in a:
d[i]=0
if n==4000 and a[0]==1:
print(d[1],maxans)
for i in range(n-1):
ind = []
for j in range(i,n):
... | 76 | 296 | 4,812,800 | 116883792 | from sys import stdin
from math import log2
from collections import defaultdict as dd
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
ids = dd(lambda: list())
i = 0
for ele in a:
ids[ele].append(i)
i += 1
res = 0
ks = list(ids.keys())
for i in range(len(ks)):
res = max(res, len(ids[k... | Codeforces Round 156 (Div. 2) | CF | 2,012 | 1 | 256 | Almost Arithmetical Progression | Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as:
- a1 = p, where p is some integer;
- ai = ai - 1 + ( - 1)i + 1·q (i > 1), where q is some int... | The first line contains integer n (1 ≤ n ≤ 4000). The next line contains n integers b1, b2, ..., bn (1 ≤ bi ≤ 106). | Print a single integer — the length of the required longest subsequence. | null | In the first test the sequence actually is the suitable subsequence.
In the second test the following subsequence fits: 10, 20, 10. | [{"input": "2\n3 5", "output": "2"}, {"input": "4\n10 20 10 30", "output": "3"}] | 1,500 | ["brute force", "dp"] | 76 | [{"input": "2\r\n3 5\r\n", "output": "2\r\n"}, {"input": "4\r\n10 20 10 30\r\n", "output": "3\r\n"}, {"input": "5\r\n4 4 3 5 1\r\n", "output": "2\r\n"}, {"input": "6\r\n2 3 2 2 1 3\r\n", "output": "4\r\n"}, {"input": "8\r\n2 2 5 3 4 3 3 2\r\n", "output": "3\r\n"}, {"input": "2\r\n468 335\r\n", "output": "2\r\n"}, {"inp... | false | stdio | null | true |
255/C | 255 | C | PyPy 3 | TESTS | 21 | 374 | 3,788,800 | 109064407 | import sys
input = sys.stdin.readline
#for _ in range(int(input())):
n=int(input())
ans=1
arr=[int(x) for x in input().split()]
for i in range(n):
temp=set()
d={}
#ans=0
for j in range(i+1,n):
if arr[j]==arr[i]:
temp=set()
else:
if arr[j] not in temp:
... | 76 | 326 | 4,198,400 | 67584424 | import sys
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
def solve():
n = mint()
a = [None]*n
i = 0
for v in mints():
a[i] = (v, i)
i += 1
a.sort()
i = 0
r = 0
while i < n:
j = i + 1
x = a[i][0]
while j < n and a[j][... | Codeforces Round 156 (Div. 2) | CF | 2,012 | 1 | 256 | Almost Arithmetical Progression | Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as:
- a1 = p, where p is some integer;
- ai = ai - 1 + ( - 1)i + 1·q (i > 1), where q is some int... | The first line contains integer n (1 ≤ n ≤ 4000). The next line contains n integers b1, b2, ..., bn (1 ≤ bi ≤ 106). | Print a single integer — the length of the required longest subsequence. | null | In the first test the sequence actually is the suitable subsequence.
In the second test the following subsequence fits: 10, 20, 10. | [{"input": "2\n3 5", "output": "2"}, {"input": "4\n10 20 10 30", "output": "3"}] | 1,500 | ["brute force", "dp"] | 76 | [{"input": "2\r\n3 5\r\n", "output": "2\r\n"}, {"input": "4\r\n10 20 10 30\r\n", "output": "3\r\n"}, {"input": "5\r\n4 4 3 5 1\r\n", "output": "2\r\n"}, {"input": "6\r\n2 3 2 2 1 3\r\n", "output": "4\r\n"}, {"input": "8\r\n2 2 5 3 4 3 3 2\r\n", "output": "3\r\n"}, {"input": "2\r\n468 335\r\n", "output": "2\r\n"}, {"inp... | false | stdio | null | true |
864/E | 864 | E | PyPy 3-64 | TESTS | 2 | 93 | 37,171,200 | 188812126 | n = int(input())
arr = []
for i in range(n):
t,d,p = [int(x) for x in input().split()]
arr.append([t,d,p,i+1])
arr.sort(key= lambda x: x[1])
dp = [[0 for i in range(2002)] for i in range(2002)]
ans = [[] for j in range(2002)]
for i in range(1,n+1):
t,d,p, ind = arr[i-1]
for j in reversed(range(d)):
... | 60 | 140 | 16,179,200 | 188812416 | n = int(input())
arr = []
for i in range(n):
t,d,p = [int(x) for x in input().split()]
arr.append([t,d,p,i+1])
arr.sort(key= lambda x: x[1])
dp = [0 for i in range(2002)]
ans = [[] for j in range(2002)]
for item in arr:
t,d,p,ind = item
for i in reversed(range(t,d)):
if dp[i] <= dp[i-t] + p:
... | Codeforces Round 436 (Div. 2) | CF | 2,017 | 2 | 256 | Fire | Polycarp is in really serious trouble — his house is on fire! It's time to save the most valuable items. Polycarp estimated that it would take ti seconds to save i-th item. In addition, for each item, he estimated the value of di — the moment after which the item i will be completely burned and will no longer be valuab... | The first line contains a single integer n (1 ≤ n ≤ 100) — the number of items in Polycarp's house.
Each of the following n lines contains three integers ti, di, pi (1 ≤ ti ≤ 20, 1 ≤ di ≤ 2 000, 1 ≤ pi ≤ 20) — the time needed to save the item i, the time after which the item i will burn completely and the value of ite... | In the first line print the maximum possible total value of the set of saved items. In the second line print one integer m — the number of items in the desired set. In the third line print m distinct integers — numbers of the saved items in the order Polycarp saves them. Items are 1-indexed in the same order in which t... | null | In the first example Polycarp will have time to save any two items, but in order to maximize the total value of the saved items, he must save the second and the third item. For example, he can firstly save the third item in 3 seconds, and then save the second item in another 2 seconds. Thus, the total value of the save... | [{"input": "3\n3 7 4\n2 6 5\n3 7 6", "output": "11\n2\n2 3"}, {"input": "2\n5 6 1\n3 3 5", "output": "1\n1\n1"}] | 2,000 | ["dp", "sortings"] | 60 | [{"input": "3\r\n3 7 4\r\n2 6 5\r\n3 7 6\r\n", "output": "11\r\n2\r\n2 3 \r\n"}, {"input": "2\r\n5 6 1\r\n3 3 5\r\n", "output": "1\r\n1\r\n1 \r\n"}, {"input": "9\r\n13 18 14\r\n8 59 20\r\n9 51 2\r\n18 32 15\r\n1 70 18\r\n14 81 14\r\n10 88 16\r\n18 52 3\r\n1 50 6\r\n", "output": "106\r\n8\r\n1 4 9 8 2 5 6 7 \r\n"}, {"in... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input
with open(input_path, 'r') as f:
n = int(f.readline().strip())
items = []
for _ in range(n):
ti, di, pi = map(int, f.readline().strip().split())
... | true |
598/A | 598 | A | Python 3 | TESTS | 5 | 31 | 0 | 180245840 | import math
#My name is Sabbah if you don't know me you will hear my name#
a=int(input())
while(int(a)>0):
s=int(input())
power=int(0)
i=int(1)
while(i<=s):
power-=i*2
i*=2
sabbah=int((s/2)*(s+1))
power+=sabbah
print(power)
a-=1 | 21 | 31 | 0 | 216742900 | import math
def calculate_sum(n):
sum_normal = n * (n + 1) // 2
l = 0
i = 0
while 2 ** i <= n:
l = l + 2 ** i
i += 1
l = l * -2
return sum_normal + l
t = int(input())
for _ in range(t):
n = int(input())
print(calculate_sum(n)) | Educational Codeforces Round 1 | ICPC | 2,015 | 1 | 256 | Tricky Sum | In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum.
For example, for n = 4 the sum is equal to - 1 - 2 + 3 - 4 = - 4, because 1, 2 and 4 are 20, 21 and 22 respectively.
Calculate the answer for t values of n. | The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of values of n to be processed.
Each of next t lines contains a single integer n (1 ≤ n ≤ 109). | Print the requested sum for each of t integers n given in the input. | null | The answer for the first sample is explained in the statement. | [{"input": "2\n4\n1000000000", "output": "-4\n499999998352516354"}] | 900 | ["math"] | 21 | [{"input": "2\r\n4\r\n1000000000\r\n", "output": "-4\r\n499999998352516354\r\n"}, {"input": "10\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n", "output": "-1\r\n-3\r\n0\r\n-4\r\n1\r\n7\r\n14\r\n6\r\n15\r\n25\r\n"}, {"input": "10\r\n10\r\n9\r\n47\r\n33\r\n99\r\n83\r\n62\r\n1\r\n100\r\n53\r\n", "output": "25\r\n... | false | stdio | null | true |
16/A | 16 | A | PyPy 3 | TESTS | 20 | 280 | 0 | 94915291 | import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
n, m = map(int, input().split())
a = [input().rstrip() for _ in range(n)]
for i in range(1, n):
if not (len(set(a[i - 1])) == len(set(a[i])) == 1 and a[i - 1][0] != a[i][0]):
print('NO')... | 35 | 92 | 0 | 136825267 | n,m = map(int,input().split())
list1 = []
p = 1
for i in range(n):
list1.append(list(map(int,input())))
for j in range(n):
if list1[j].count(list1[j][0]) != m:
p = 0
for o in range(m):
for u in range(n-1):
if list1[u][o] == list1[u+1][o]:
p = 0
if p ==1:
print('YES')
elif p =... | Codeforces Beta Round 16 (Div. 2 Only) | ICPC | 2,010 | 2 | 64 | Flag | According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland'... | The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the... | Output YES, if the flag meets the new ISO standard, and NO otherwise. | null | null | [{"input": "3 3\n000\n111\n222", "output": "YES"}, {"input": "3 3\n000\n000\n111", "output": "NO"}, {"input": "3 3\n000\n111\n002", "output": "NO"}] | 800 | ["implementation"] | 35 | [{"input": "3 3\r\n000\r\n111\r\n222\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n000\r\n000\r\n111\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n000\r\n111\r\n002\r\n", "output": "NO\r\n"}, {"input": "10 10\r\n2222222222\r\n5555555555\r\n0000000000\r\n4444444444\r\n1111111111\r\n3333333393\r\n3333333333\r\n5555555555\... | false | stdio | null | true |
16/A | 16 | A | PyPy 3 | TESTS | 20 | 154 | 1,740,800 | 136750772 | n,m = map(int,input().split())
a = []
k = 'YES'
for i in range (n):
a.append (input())
for i in range (n-1):
for j in range (m-1):
if a[i]==a[i+1] or a[i][j]!=a[i][j+1] or a[i+1][j]!=a[i+1][j+1]:
k='NO'
break
if n == 1 and (len(set(a))>1):
print('NO')
else:
print (k) | 35 | 92 | 0 | 137014614 | n, m = map(int, input().split())
flag = 1
l = []
for i in range(n):
l.append(input())
for i in range(n):
x = l[i].count(l[i][0])
y = len(l[i])
if x != y:
flag = 0
break
for i in range(1, n):
if l[i - 1] == l[i]:
flag = 0
break
if flag == 0:
print('NO')
else:
p... | Codeforces Beta Round 16 (Div. 2 Only) | ICPC | 2,010 | 2 | 64 | Flag | According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland'... | The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the... | Output YES, if the flag meets the new ISO standard, and NO otherwise. | null | null | [{"input": "3 3\n000\n111\n222", "output": "YES"}, {"input": "3 3\n000\n000\n111", "output": "NO"}, {"input": "3 3\n000\n111\n002", "output": "NO"}] | 800 | ["implementation"] | 35 | [{"input": "3 3\r\n000\r\n111\r\n222\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n000\r\n000\r\n111\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n000\r\n111\r\n002\r\n", "output": "NO\r\n"}, {"input": "10 10\r\n2222222222\r\n5555555555\r\n0000000000\r\n4444444444\r\n1111111111\r\n3333333393\r\n3333333333\r\n5555555555\... | false | stdio | null | true |
16/A | 16 | A | Python 3 | TESTS | 20 | 186 | 6,963,200 | 88149013 | n,m=map(int,input().split())
li=[list(map(int,input())) for i in range(n)]
fg=0
for i in range(1,n):
for j in range(m-1):
if(li[i-1][j]==li[i][j] or li[i][j]!=li[i][j+1]):
fg=1
break
if(j==m-2):
if(li[i-1][j+1]==li[i][j+1]):
fg=1
br... | 35 | 92 | 0 | 137116114 | # input
n, m = map(int, input().split())
def getAns():
ans = "YES"
for i in range(n):
str = input()
for j in range(1, len(str)):
if str[0] != str[j]:
ans = "NO"
if i > 0 and pre == str:
ans = "NO"
pre = str
return ans
print (getAns()) | Codeforces Beta Round 16 (Div. 2 Only) | ICPC | 2,010 | 2 | 64 | Flag | According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland'... | The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the... | Output YES, if the flag meets the new ISO standard, and NO otherwise. | null | null | [{"input": "3 3\n000\n111\n222", "output": "YES"}, {"input": "3 3\n000\n000\n111", "output": "NO"}, {"input": "3 3\n000\n111\n002", "output": "NO"}] | 800 | ["implementation"] | 35 | [{"input": "3 3\r\n000\r\n111\r\n222\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n000\r\n000\r\n111\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n000\r\n111\r\n002\r\n", "output": "NO\r\n"}, {"input": "10 10\r\n2222222222\r\n5555555555\r\n0000000000\r\n4444444444\r\n1111111111\r\n3333333393\r\n3333333333\r\n5555555555\... | false | stdio | null | true |
16/A | 16 | A | PyPy 3 | TESTS | 20 | 216 | 102,400 | 115009232 | #!/usr/bin/env python3
def row_iso(string):
if len(set(list(string))) == 1:
return True
else:
return False
def row_color(string):
if row_iso(string):
return set(list(string))
else:
return {''}
def flag_iso(array):
for i in range(1, len(array)-1):
if row_iso... | 35 | 92 | 0 | 137192316 | b=''
for i in range(int(input().split()[0])):
a=input()
if a.strip(a[0])or a[0]==b:
print('NO');exit()
b=a[0]
print('YES') | Codeforces Beta Round 16 (Div. 2 Only) | ICPC | 2,010 | 2 | 64 | Flag | According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland'... | The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the... | Output YES, if the flag meets the new ISO standard, and NO otherwise. | null | null | [{"input": "3 3\n000\n111\n222", "output": "YES"}, {"input": "3 3\n000\n000\n111", "output": "NO"}, {"input": "3 3\n000\n111\n002", "output": "NO"}] | 800 | ["implementation"] | 35 | [{"input": "3 3\r\n000\r\n111\r\n222\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n000\r\n000\r\n111\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n000\r\n111\r\n002\r\n", "output": "NO\r\n"}, {"input": "10 10\r\n2222222222\r\n5555555555\r\n0000000000\r\n4444444444\r\n1111111111\r\n3333333393\r\n3333333333\r\n5555555555\... | false | stdio | null | true |
598/A | 598 | A | Python 3 | TESTS | 5 | 31 | 0 | 186983440 | # LUOGU_RID: 98135518
import math
a = int(input())
for __count in range(a):
c = 1
d = 0
n = 0
b = int(input())
while (2 ** d <= b):
d += 1
n -= int((2 ** d))
print(int((int((((1 + b) * b) / 2)) + n))) | 21 | 31 | 0 | 225839144 | t = int(input())
while t > 0:
n = int(input())
res = n * (n + 1) // 2
x = 1
while x <= n:
res -= 2 * x
x *= 2
print(res)
t -= 1 | Educational Codeforces Round 1 | ICPC | 2,015 | 1 | 256 | Tricky Sum | In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum.
For example, for n = 4 the sum is equal to - 1 - 2 + 3 - 4 = - 4, because 1, 2 and 4 are 20, 21 and 22 respectively.
Calculate the answer for t values of n. | The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of values of n to be processed.
Each of next t lines contains a single integer n (1 ≤ n ≤ 109). | Print the requested sum for each of t integers n given in the input. | null | The answer for the first sample is explained in the statement. | [{"input": "2\n4\n1000000000", "output": "-4\n499999998352516354"}] | 900 | ["math"] | 21 | [{"input": "2\r\n4\r\n1000000000\r\n", "output": "-4\r\n499999998352516354\r\n"}, {"input": "10\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n", "output": "-1\r\n-3\r\n0\r\n-4\r\n1\r\n7\r\n14\r\n6\r\n15\r\n25\r\n"}, {"input": "10\r\n10\r\n9\r\n47\r\n33\r\n99\r\n83\r\n62\r\n1\r\n100\r\n53\r\n", "output": "25\r\n... | false | stdio | null | true |
598/A | 598 | A | Python 3 | TESTS | 5 | 31 | 0 | 161398436 | for i in range(int(input())):
inti = int(input())
summ = int((inti*(inti+1))/2)
minussumm = 0
ttp = 0
while 2**ttp<=inti:
minussumm += 2**ttp
ttp += 1
print(summ-(2*minussumm)) | 21 | 31 | 0 | 227067823 | from math import log
t=int(input())
L=[]
s=0
for i in range(t):
n=int(input())
L.append(n)
for i in range(t) :
s=(L[i]*(L[i]+1))//2
for k in range(int(log(L[i])/log(2))+1) :
s-=2**(k+1)
print(s) | Educational Codeforces Round 1 | ICPC | 2,015 | 1 | 256 | Tricky Sum | In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum.
For example, for n = 4 the sum is equal to - 1 - 2 + 3 - 4 = - 4, because 1, 2 and 4 are 20, 21 and 22 respectively.
Calculate the answer for t values of n. | The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of values of n to be processed.
Each of next t lines contains a single integer n (1 ≤ n ≤ 109). | Print the requested sum for each of t integers n given in the input. | null | The answer for the first sample is explained in the statement. | [{"input": "2\n4\n1000000000", "output": "-4\n499999998352516354"}] | 900 | ["math"] | 21 | [{"input": "2\r\n4\r\n1000000000\r\n", "output": "-4\r\n499999998352516354\r\n"}, {"input": "10\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n", "output": "-1\r\n-3\r\n0\r\n-4\r\n1\r\n7\r\n14\r\n6\r\n15\r\n25\r\n"}, {"input": "10\r\n10\r\n9\r\n47\r\n33\r\n99\r\n83\r\n62\r\n1\r\n100\r\n53\r\n", "output": "25\r\n... | false | stdio | null | true |
598/A | 598 | A | Python 3 | TESTS | 5 | 31 | 0 | 194817282 | from math import log2
def cunning_sum (n):
x = pow(2,int(log2(n)+1))
sum_minus =int((1-x)/-1)
num = (2 + n - 1)/2*n
return int(num) - 2 * sum_minus
if __name__ == '__main__':
t = int(input())
for i in range(t):
num = int(input())
print(cunning_sum (num)) | 21 | 31 | 4,505,600 | 161816481 | t=int(input())
for k in range(t):
p=1
i=1
sum=1
another=0
user=int(input())
sum=(user*(user+1))//2
another=0
while i<=user:
another+=i
i*=2
x=sum-another
ans=x-another
print(ans) | Educational Codeforces Round 1 | ICPC | 2,015 | 1 | 256 | Tricky Sum | In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum.
For example, for n = 4 the sum is equal to - 1 - 2 + 3 - 4 = - 4, because 1, 2 and 4 are 20, 21 and 22 respectively.
Calculate the answer for t values of n. | The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of values of n to be processed.
Each of next t lines contains a single integer n (1 ≤ n ≤ 109). | Print the requested sum for each of t integers n given in the input. | null | The answer for the first sample is explained in the statement. | [{"input": "2\n4\n1000000000", "output": "-4\n499999998352516354"}] | 900 | ["math"] | 21 | [{"input": "2\r\n4\r\n1000000000\r\n", "output": "-4\r\n499999998352516354\r\n"}, {"input": "10\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n", "output": "-1\r\n-3\r\n0\r\n-4\r\n1\r\n7\r\n14\r\n6\r\n15\r\n25\r\n"}, {"input": "10\r\n10\r\n9\r\n47\r\n33\r\n99\r\n83\r\n62\r\n1\r\n100\r\n53\r\n", "output": "25\r\n... | false | stdio | null | true |
598/A | 598 | A | Python 3 | TESTS | 5 | 31 | 0 | 196578287 | import math
xd=int(input())
for i in range(xd):
n=int(input())
p=int(math.log2(n))
n1=int(n*(n+1))
n2=2**(p+1)
m1=int(n1/2)
m2=int(2*(n2)-2)
print(m1-m2) | 21 | 46 | 0 | 14231980 | from math import log2
t = int(input())
for q in range(t):
n = int(input())
cur_sum = (n * (n + 1)) // 2
deg = int(log2(n)) + 1
cur_sum -= 2 * (2 ** deg - 1)
print(cur_sum) | Educational Codeforces Round 1 | ICPC | 2,015 | 1 | 256 | Tricky Sum | In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum.
For example, for n = 4 the sum is equal to - 1 - 2 + 3 - 4 = - 4, because 1, 2 and 4 are 20, 21 and 22 respectively.
Calculate the answer for t values of n. | The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of values of n to be processed.
Each of next t lines contains a single integer n (1 ≤ n ≤ 109). | Print the requested sum for each of t integers n given in the input. | null | The answer for the first sample is explained in the statement. | [{"input": "2\n4\n1000000000", "output": "-4\n499999998352516354"}] | 900 | ["math"] | 21 | [{"input": "2\r\n4\r\n1000000000\r\n", "output": "-4\r\n499999998352516354\r\n"}, {"input": "10\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n", "output": "-1\r\n-3\r\n0\r\n-4\r\n1\r\n7\r\n14\r\n6\r\n15\r\n25\r\n"}, {"input": "10\r\n10\r\n9\r\n47\r\n33\r\n99\r\n83\r\n62\r\n1\r\n100\r\n53\r\n", "output": "25\r\n... | false | stdio | null | true |
864/E | 864 | E | PyPy 3 | TESTS | 3 | 155 | 20,172,800 | 90780382 | def count_spaces(l, t, x):
# up to ind x.
total = prev = 0; n = len(l)
for i in range(x + 1):
total += l[i][1] - prev
prev = l[i][1] + t[l[i][0]]
return total
def move_blocks(x, dist, l, t):
# blocks up to x will move.
last = -1
gaps = []
for i in range(x, 0, -1):
... | 60 | 202 | 82,841,600 | 180979734 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def f(u, v):
return u * (n + 1) + v
n = int(input())
x = []
for i in range(n):
t, d, p = map(int, input().split())
x.append((d, t, p, i + 1))
x.sort()
dp = []
dp0 = [-1] * (n + 1)
dp0[0] = 0
l = 0
la = 1
for d, t, p, _ in x:
... | Codeforces Round 436 (Div. 2) | CF | 2,017 | 2 | 256 | Fire | Polycarp is in really serious trouble — his house is on fire! It's time to save the most valuable items. Polycarp estimated that it would take ti seconds to save i-th item. In addition, for each item, he estimated the value of di — the moment after which the item i will be completely burned and will no longer be valuab... | The first line contains a single integer n (1 ≤ n ≤ 100) — the number of items in Polycarp's house.
Each of the following n lines contains three integers ti, di, pi (1 ≤ ti ≤ 20, 1 ≤ di ≤ 2 000, 1 ≤ pi ≤ 20) — the time needed to save the item i, the time after which the item i will burn completely and the value of ite... | In the first line print the maximum possible total value of the set of saved items. In the second line print one integer m — the number of items in the desired set. In the third line print m distinct integers — numbers of the saved items in the order Polycarp saves them. Items are 1-indexed in the same order in which t... | null | In the first example Polycarp will have time to save any two items, but in order to maximize the total value of the saved items, he must save the second and the third item. For example, he can firstly save the third item in 3 seconds, and then save the second item in another 2 seconds. Thus, the total value of the save... | [{"input": "3\n3 7 4\n2 6 5\n3 7 6", "output": "11\n2\n2 3"}, {"input": "2\n5 6 1\n3 3 5", "output": "1\n1\n1"}] | 2,000 | ["dp", "sortings"] | 60 | [{"input": "3\r\n3 7 4\r\n2 6 5\r\n3 7 6\r\n", "output": "11\r\n2\r\n2 3 \r\n"}, {"input": "2\r\n5 6 1\r\n3 3 5\r\n", "output": "1\r\n1\r\n1 \r\n"}, {"input": "9\r\n13 18 14\r\n8 59 20\r\n9 51 2\r\n18 32 15\r\n1 70 18\r\n14 81 14\r\n10 88 16\r\n18 52 3\r\n1 50 6\r\n", "output": "106\r\n8\r\n1 4 9 8 2 5 6 7 \r\n"}, {"in... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input
with open(input_path, 'r') as f:
n = int(f.readline().strip())
items = []
for _ in range(n):
ti, di, pi = map(int, f.readline().strip().split())
... | true |
727/E | 727 | E | Python 3 | TESTS | 2 | 46 | 0 | 142530227 | def solve():
k, l = list(map(int, input().split(" ")))
s = input()
if k * l != len(s):
print('NO')
return
n = len(s) // l
s += s[:l]
g = int(input())
d = {}
for i in range(1, g + 1):
d[input()] = i
for i in range(l):
res = []
for j in ran... | 87 | 3,244 | 54,476,800 | 158830314 | import sys
input = sys.stdin.buffer.readline
p = 24738041398529
def process(n, k, S, G):
g = len(G)
matrix = [[0 for j in range(k)] for i in range(g)]
sums = [0 for i in range(k)]
word_dict = {}
for i in range(g):
word = 0
for j in range(k):
si = ord(G[i][j])-ord('a')... | Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2) | CF | 2,016 | 4 | 512 | Games on a CD | Several years ago Tolya had n computer games and at some point of time he decided to burn them to CD. After that he wrote down the names of the games one after another in a circle on the CD in clockwise order. The names were distinct, the length of each name was equal to k. The names didn't overlap.
Thus, there is a c... | The first line of the input contains two positive integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 105) — the amount of games Tolya burned to the CD, and the length of each of the names.
The second line of the input contains one string consisting of lowercase English letters — the string Tolya wrote on the CD, split in arbitrar... | If there is no answer, print "NO" (without quotes).
Otherwise, print two lines. In the first line print "YES" (without quotes). In the second line, print n integers — the games which names were written on the CD. You should print games in the order they could have been written on the CD, it means, in clockwise order. ... | null | null | [{"input": "3 1\nabc\n4\nb\na\nc\nd", "output": "YES\n2 1 3"}, {"input": "4 2\naabbccdd\n4\ndd\nab\nbc\ncd", "output": "NO"}] | 2,300 | ["data structures", "hashing", "string suffix structures", "strings"] | 87 | [{"input": "3 1\r\nabc\r\n4\r\nb\r\na\r\nc\r\nd\r\n", "output": "YES\r\n2 1 3 \r\n"}, {"input": "4 2\r\naabbccdd\r\n4\r\ndd\r\nab\r\nbc\r\ncd\r\n", "output": "NO\r\n"}, {"input": "2 2\r\nkdcj\r\n4\r\ncj\r\nkd\r\njk\r\ndc\r\n", "output": "YES\r\n3 4 \r\n"}, {"input": "10 10\r\nlgfrjgityzwtmfyygmpsmokiwphewhpoelsvnctwxmp... | 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:
n, k = map(int, f.readline().split())
cd_str = f.readline().strip()
g = int(f.readline())
games = [f.readlin... | true |
733/B | 733 | B | Python 3 | TESTS | 4 | 327 | 8,499,200 | 177370065 | numCol = int(input())
columnas = [[int(x) for x in input().split(" ")] for columna in range(numCol)] # [[5,6], [8,9], [10, 3]]
# numCol = 3
# columnas = [[5, 6], [8, 9], [10, 3]]
sumOGIZQ = sum( [columnas[x][0] for x in range(numCol)] )
sumOGDER = sum( [columnas[x][1] for x in range(numCol)] )
valorOG =... | 40 | 265 | 16,384,000 | 119239620 | from sys import *
input = stdin.readline
n = int(input())
arr = []
arr2 = []
l = 0
r = 0
for _ in range(n):
ll = list(map(int, input().split()))
arr.append(ll)
arr2.append([ll[1], ll[0]])
l += ll[0]
r += ll[1]
bu = abs(l-r)
ans = 0
for i in range(n):
a, b = arr[i][0], arr[i][1]
smh = abs((l ... | Codeforces Round 378 (Div. 2) | CF | 2,016 | 1 | 256 | Parade | Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. The civilian population also poorly understands from which leg recruits beg... | The first line contains single integer n (1 ≤ n ≤ 105) — the number of columns.
The next n lines contain the pairs of integers li and ri (1 ≤ li, ri ≤ 500) — the number of soldiers in the i-th column which start to march from the left or the right leg respectively. | Print single integer k — the number of the column in which soldiers need to change the leg from which they start to march, or 0 if the maximum beauty is already reached.
Consider that columns are numbered from 1 to n in the order they are given in the input data.
If there are several answers, print any of them. | null | In the first example if you don't give the order to change the leg, the number of soldiers, who start to march from the left leg, would equal 5 + 8 + 10 = 23, and from the right leg — 6 + 9 + 3 = 18. In this case the beauty of the parade will equal |23 - 18| = 5.
If you give the order to change the leg to the third co... | [{"input": "3\n5 6\n8 9\n10 3", "output": "3"}, {"input": "2\n6 5\n5 6", "output": "1"}, {"input": "6\n5 9\n1 3\n4 8\n4 5\n23 54\n12 32", "output": "0"}] | 1,100 | ["math"] | 40 | [{"input": "3\r\n5 6\r\n8 9\r\n10 3\r\n", "output": "3\r\n"}, {"input": "2\r\n6 5\r\n5 6\r\n", "output": "1\r\n"}, {"input": "6\r\n5 9\r\n1 3\r\n4 8\r\n4 5\r\n23 54\r\n12 32\r\n", "output": "0\r\n"}, {"input": "2\r\n500 499\r\n500 500\r\n", "output": "0\r\n"}, {"input": "1\r\n139 252\r\n", "output": "0\r\n"}, {"input":... | false | stdio | null | true |
730/G | 730 | G | Python 3 | TESTS | 11 | 61 | 5,529,600 | 32759738 | t = 1
p = []
for i in range(int(input())):
s, d = map(int, input().split())
if t > s:
for i, q in enumerate(p):
if q[0] <= s <= q[0] + q[1] - d:
print(s, s + d - 1)
p.insert(i + 1, [s + d, q[1] - d - s + q[0]])
q[1] = s - q[0]
b... | 28 | 93 | 204,800 | 21809200 | n=int(input())
L=[]
for j in range(n):
ch=input().split()
s,d=int(ch[0]),int(ch[1])
if j==0:
print(s,d+s-1)
L.append([s,s+d-1])
L.sort()
else:
B=True
C=True
for i in range(len(L)):
if ... | 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,016 | 2 | 512 | Car Repair Shop | Polycarp starts his own business. Tomorrow will be the first working day of his car repair shop. For now the car repair shop is very small and only one car can be repaired at a given time.
Polycarp is good at marketing, so he has already collected n requests from clients. The requests are numbered from 1 to n in order... | The first line contains integer n (1 ≤ n ≤ 200) — the number of requests from clients.
The following n lines contain requests, one request per line. The i-th request is given as the pair of integers si, di (1 ≤ si ≤ 109, 1 ≤ di ≤ 5·106), where si is the preferred time to start repairing the i-th car, di is the number ... | Print n lines. The i-th line should contain two integers — the start day to repair the i-th car and the finish day to repair the i-th car. | null | null | [{"input": "3\n9 2\n7 3\n2 4", "output": "9 10\n1 3\n4 7"}, {"input": "4\n1000000000 1000000\n1000000000 1000000\n100000000 1000000\n1000000000 1000000", "output": "1000000000 1000999999\n1 1000000\n100000000 100999999\n1000001 2000000"}] | 1,600 | ["implementation"] | 28 | [{"input": "3\r\n9 2\r\n7 3\r\n2 4\r\n", "output": "9 10\r\n1 3\r\n4 7\r\n"}, {"input": "4\r\n1000000000 1000000\r\n1000000000 1000000\r\n100000000 1000000\r\n1000000000 1000000\r\n", "output": "1000000000 1000999999\r\n1 1000000\r\n100000000 100999999\r\n1000001 2000000\r\n"}, {"input": "1\r\n1 1\r\n", "output": "1 1\... | false | stdio | null | true |
353/C | 353 | C | PyPy 3 | TESTS | 4 | 186 | 1,126,400 | 107734035 | from sys import stdin,stdout
from itertools import accumulate
nmbr = lambda: int(stdin.readline())
lst = lambda: list(map(int,stdin.readline().split()))
for _ in range(1):#nmbr()):
n=nmbr()
a=lst()
s=input()
norm=[int(s[i])*a[i] for i in range(n)]
ans=sum(norm)
pre=list(accumulate(a))
suf=li... | 36 | 154 | 10,444,800 | 216360359 | import sys
def prefix_sum(values):
res = [0] * (len(values) + 1)
for i in range(len(values)):
res[i + 1] = values[i] + res[i]
return res
def main():
read = sys.stdin.readline
n = int(read())
values = [int(i) for i in read().split()]
# The binary string is given to us in reversed... | Codeforces Round 205 (Div. 2) | CF | 2,013 | 1 | 256 | Find Maximum | Valera has array a, consisting of n integers a0, a1, ..., an - 1, and function f(x), taking an integer from 0 to 2n - 1 as its single argument. Value f(x) is calculated by formula $$f(x) = \sum_{i=0}^{n-1} a_i \cdot bit(i)$$, where value bit(i) equals one if the binary representation of number x contains a 1 on the i-t... | The first line contains integer n (1 ≤ n ≤ 105) — the number of array elements. The next line contains n space-separated integers a0, a1, ..., an - 1 (0 ≤ ai ≤ 104) — elements of array a.
The third line contains a sequence of digits zero and one without spaces s0s1... sn - 1 — the binary representation of number m. Nu... | Print a single integer — the maximum value of function f(x) for all $$x \in [0..m]$$. | null | In the first test case m = 20 = 1, f(0) = 0, f(1) = a0 = 3.
In the second sample m = 20 + 21 + 23 = 11, the maximum value of function equals f(5) = a0 + a2 = 17 + 10 = 27. | [{"input": "2\n3 8\n10", "output": "3"}, {"input": "5\n17 0 10 2 1\n11010", "output": "27"}] | 1,600 | ["implementation", "math", "number theory"] | 36 | [{"input": "2\r\n3 8\r\n10\r\n", "output": "3\r\n"}, {"input": "5\r\n17 0 10 2 1\r\n11010\r\n", "output": "27\r\n"}, {"input": "18\r\n4382 3975 9055 7554 8395 204 5313 5739 1555 2306 5423 828 8108 9736 2683 7940 1249 5495\r\n110001100101110111\r\n", "output": "88691\r\n"}, {"input": "43\r\n475 2165 8771 7146 8980 7209 ... | false | stdio | null | true |
621/E | 621 | E | Python 3 | TESTS | 3 | 529 | 6,246,400 | 34806674 | n,b,k,x=map(int,input().split())
arr=list(map(int,input().split()))
flg=[0]*x
mod = 10**9+7
for i in arr:
flg[i%x]+=1
def mul(dp,flg,rank):
global x
res=[0]*x
for i in range(x):
for j in range(x):
res[ ( (i*rank)%x+j)%x ] += dp[i]*flg[j]%mod
res[ ( (i*rank)%x+j)%x ] %=... | 114 | 139 | 1,228,800 | 219104836 | def calculate_D(block):
D = [0 for i in range(10)]
for s in block:
D[s] += 1
return D
def initialize_A(D, x):
A = [[0 for t in range(x)]]
for i in range(10):
A[0][i % x] += D[i]
return A
def calculate_pows(b, x):
pows = [pow(10, 1 << j, x) for j in range(b.bit_length())]
... | Codeforces Round 341 (Div. 2) | CF | 2,016 | 2 | 256 | Wet Shark and Blocks | There are b blocks of digits. Each one consisting of the same n digits, which are given to you in the input. Wet Shark must choose exactly one digit from each block and concatenate all of those digits together to form one large integer. For example, if he chooses digit 1 from the first block and digit 2 from the second... | The first line of the input contains four space-separated integers, n, b, k and x (2 ≤ n ≤ 50 000, 1 ≤ b ≤ 109, 0 ≤ k < x ≤ 100, x ≥ 2) — the number of digits in one block, the number of blocks, interesting remainder modulo x and modulo x itself.
The next line contains n space separated integers ai (1 ≤ ai ≤ 9), that ... | Print the number of ways to pick exactly one digit from each blocks, such that the resulting integer equals k modulo x. | null | In the second sample possible integers are 22, 26, 62 and 66. None of them gives the remainder 1 modulo 2.
In the third sample integers 11, 13, 21, 23, 31 and 33 have remainder 1 modulo 2. There is exactly one way to obtain each of these integers, so the total answer is 6. | [{"input": "12 1 5 10\n3 5 6 7 8 9 5 1 1 1 1 5", "output": "3"}, {"input": "3 2 1 2\n6 2 2", "output": "0"}, {"input": "3 2 1 2\n3 1 2", "output": "6"}] | 2,000 | ["dp", "matrices"] | 114 | [{"input": "12 1 5 10\r\n3 5 6 7 8 9 5 1 1 1 1 5\r\n", "output": "3\r\n"}, {"input": "3 2 1 2\r\n6 2 2\r\n", "output": "0\r\n"}, {"input": "3 2 1 2\r\n3 1 2\r\n", "output": "6\r\n"}, {"input": "3 2 1 2\r\n6 3 2\r\n", "output": "3\r\n"}, {"input": "3 2 1 2\r\n3 6 3\r\n", "output": "6\r\n"}, {"input": "3 2 0 2\r\n3 3 9\r... | false | stdio | null | true |
599/C | 599 | C | PyPy 3-64 | TESTS | 3 | 62 | 0 | 165846132 | n=int(input())
arr=list(map(int,input().split()))
p=sorted(arr)
ans=0
temp=0
for a,b in zip(arr,p):
temp^=a
temp^=b
if temp==0:
ans+=1
print(ans) | 39 | 124 | 9,113,600 | 175241492 | l=int(input())
b=[int(i) for i in input().split(' ')]
a=sorted(b)
summ=0
res=0
for i in range(l):
summ += a[i]-b[i]
if summ==0:
res+=1
print(res)
# dp=list()
# for i in range(l):
# dp.append(1)
# maxx=0
#
# minn=0
# prevMax=0
# for i in range(1,l):
#
# if b[maxx]<=b[i]:
# if b[maxx]... | Codeforces Round 332 (Div. 2) | CF | 2,015 | 2 | 256 | Day at the Beach | One day Squidward, Spongebob and Patrick decided to go to the beach. Unfortunately, the weather was bad, so the friends were unable to ride waves. However, they decided to spent their time building sand castles.
At the end of the day there were n castles built by friends. Castles are numbered from 1 to n, and the heig... | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of castles Spongebob, Patrick and Squidward made from sand during the day.
The next line contains n integers hi (1 ≤ hi ≤ 109). The i-th of these integers corresponds to the height of the i-th castle. | Print the maximum possible number of blocks in a valid partitioning. | null | In the first sample the partitioning looks like that: [1][2][3].
In the second sample the partitioning is: [2, 1][3, 2] | [{"input": "3\n1 2 3", "output": "3"}, {"input": "4\n2 1 3 2", "output": "2"}] | 1,600 | ["sortings"] | 39 | [{"input": "3\r\n1 2 3\r\n", "output": "3\r\n"}, {"input": "4\r\n2 1 3 2\r\n", "output": "2\r\n"}, {"input": "17\r\n1 45 22 39 28 23 23 100 500 778 777 778 1001 1002 1005 1003 1005\r\n", "output": "10\r\n"}, {"input": "101\r\n1 50 170 148 214 153 132 234 181 188 180 225 226 200 197 122 181 168 87 220 223 160 235 94 257... | false | stdio | null | true |
282/C | 282 | C | PyPy 3-64 | TESTS | 3 | 92 | 0 | 228711428 | def is_possible(a, b):
if len(a) != len(b) :
return "NO"
if a == b :
return "YES"
a = int(a)
b = int(b)
if a | b == a :
return "YES"
return "NO"
a = input()
b = input()
print(is_possible(a, b)) | 107 | 186 | 8,396,800 | 228785877 | def is_possible(a, b):
if len(a) != len(b) :
return "NO"
if a == b :
return "YES"
setbits_in_a = False
setbits_in_b = False
for ch in a :
if ch == "1":
setbits_in_a = True
break
for ch in b :
if ch == "1":
s... | Codeforces Round 173 (Div. 2) | CF | 2,013 | 2 | 256 | XOR and OR | The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.
A Bitlandish string is a string made only of characters "0" and "1".
BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish ... | The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths.
It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106. | Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes. | null | null | [{"input": "11\n10", "output": "YES"}, {"input": "1\n01", "output": "NO"}, {"input": "000\n101", "output": "NO"}] | 1,500 | ["constructive algorithms", "implementation", "math"] | 107 | [{"input": "11\r\n10\r\n", "output": "YES\r\n"}, {"input": "1\r\n01\r\n", "output": "NO\r\n"}, {"input": "000\r\n101\r\n", "output": "NO\r\n"}, {"input": "1101\r\n1111\r\n", "output": "YES\r\n"}, {"input": "11000001\r\n00000001\r\n", "output": "YES\r\n"}, {"input": "01\r\n10\r\n", "output": "YES\r\n"}, {"input": "0000\... | false | stdio | null | true |
177/E1 | 177 | E2 | PyPy 3 | TESTS2 | 3 | 310 | 21,708,800 | 89316242 | n,c=map(int,input().split())
a=[0 for i in range(10001)]
b=a[:]
for i in range(n):
a[i],b[i]=map(int,input().split())
def chi():
if sum(a)==0:
if c==n:
print(-1)
else:
print(0)
import sys
sys.exit(0)
def ch(day):
ans=0
for i in range(n):
a... | 21 | 218 | 0 | 51613361 | a=[]
b=[]
n=0
def cal(x):
p=0
global n,a,b
for i in range(n):
p+=((a[i]*x)//b[i])
return p
n,c=map(int,input().split())
c-=n
if c < 0:
print(0)
exit(0)
a=[0]*n
b=[0]*n
for i in range(n):
a[i],b[i]=map(int,input().split())
L=1
R=10**18
lower=R+1
while L<=R :
m=(L+R)>>1
if cal(m) >= c:
lower=m
R=m-1
else... | ABBYY Cup 2.0 - Easy | ICPC | 2,012 | 2 | 256 | Space Voyage | The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet.
The Smart Beaver is going to bring som... | The first input line contains space-separated integers n and c — the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly.
The next n lines contain pairs of space-separated integers ai, bi (1 ≤ i ≤ n) — the number of suitcases he can bring to the i-... | Print a single number k — the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | null | In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days... | [{"input": "2 5\n1 5\n2 4", "output": "1"}] | 1,700 | ["binary search"] | 21 | [{"input": "2 5\r\n1 5\r\n2 4\r\n", "output": "1\r\n"}, {"input": "1 97\r\n1 91\r\n", "output": "91\r\n"}, {"input": "2 79\r\n1 91\r\n1 77\r\n", "output": "42\r\n"}, {"input": "3 100\r\n8 46\r\n8 56\r\n77 98\r\n", "output": "1\r\n"}, {"input": "7 77\r\n2 95\r\n2 91\r\n3 95\r\n2 94\r\n3 96\r\n2 97\r\n2 91\r\n", "output"... | false | stdio | null | true |
279/B | 279 | B | Python 3 | TESTS | 28 | 404 | 6,348,800 | 188817449 | def fun(l,r):
global sumi
if l>r or sumi<=t:
return 0
if lis[l]>lis[r]:
if sumi<=t:
return 0
sumi-=lis[l]
return 1+fun(l+1,r)
elif lis[l]<lis[r]:
if sumi<=t:
return 0
sumi-=lis[r]
return 1+fun(l,r-1)
else:
if sum... | 38 | 154 | 9,625,600 | 217483580 | def main():
num_books, num_minutes = list(map(int, input().split(" ")))
a = [int(t) for t in input().split(" ")]
ans = -float("inf")
cur_sum = 0
left, right = 0, 0
while right < len(a):
cur_sum += a[right]
right += 1
while cur_sum > num_minutes:
cur_sum -= a[... | Codeforces Round 171 (Div. 2) | CF | 2,013 | 2 | 256 | Books | When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs ai minutes to read the ... | The first line contains two integers n and t (1 ≤ n ≤ 105; 1 ≤ t ≤ 109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 104), where number ai shows the number of minutes that the boy needs to read the i-th book. | Print a single integer — the maximum number of books Valera can read. | null | null | [{"input": "4 5\n3 1 2 1", "output": "3"}, {"input": "3 3\n2 2 3", "output": "1"}] | 1,400 | ["binary search", "brute force", "implementation", "two pointers"] | 38 | [{"input": "4 5\r\n3 1 2 1\r\n", "output": "3\r\n"}, {"input": "3 3\r\n2 2 3\r\n", "output": "1\r\n"}, {"input": "1 3\r\n5\r\n", "output": "0\r\n"}, {"input": "1 10\r\n4\r\n", "output": "1\r\n"}, {"input": "2 10\r\n6 4\r\n", "output": "2\r\n"}, {"input": "6 10\r\n2 3 4 2 1 1\r\n", "output": "4\r\n"}, {"input": "7 13\r\... | false | stdio | null | true |
321/B | 321 | B | PyPy 3 | TESTS | 27 | 218 | 23,142,400 | 33101516 | n, m = map(int, input().split())
u = [[], []]
for i in range(n):
p, s = input().split()
u[p == 'ATK'].append(int(s))
d, a = [sorted(q) for q in u]
v = sorted(int(input()) for q in range(m))
s = k = 0
for q in v:
if k < len(a) and q >= a[k]: k += 1
x = y = 0
v.reverse()
for i in range(k):
x += a[i]
y... | 80 | 218 | 0 | 42124910 | n, m = map(int, input().split())
(a, d) = ([], [])
for i in range(n):
t, val = input().split()
(a if t == 'ATK' else d).append(int(val))
my = sorted([int(input()) for i in range(m)])
a.sort()
d.sort()
def solve1():
ret = 0
used = [False] * m
for val in d:
for i in range(m):
... | Codeforces Round 190 (Div. 1) | CF | 2,013 | 2 | 256 | Ciel and Duel | Fox Ciel is playing a card game with her friend Jiro.
Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack.
Now is Ciel's battle phase, Ciel can do the following ope... | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of cards Jiro and Ciel have.
Each of the next n lines contains a string position and an integer strength (0 ≤ strength ≤ 8000) — the position and strength of Jiro's current card. Position is the string "ATK" for attack, and the string "DEF" for... | Output an integer: the maximal damage Jiro can get. | null | In the first test case, Ciel has 3 cards with same strength. The best strategy is as follows. First she uses one of these 3 cards to attack "ATK 2000" card first, this attack destroys that card and Jiro gets 2500 - 2000 = 500 damage. Then she uses the second card to destroy the "DEF 1700" card. Jiro doesn't get damage ... | [{"input": "2 3\nATK 2000\nDEF 1700\n2500\n2500\n2500", "output": "3000"}, {"input": "3 4\nATK 10\nATK 100\nATK 1000\n1\n11\n101\n1001", "output": "992"}, {"input": "2 4\nDEF 0\nATK 0\n0\n0\n1\n1", "output": "1"}] | 1,900 | ["dp", "flows", "greedy"] | 80 | [{"input": "2 3\r\nATK 2000\r\nDEF 1700\r\n2500\r\n2500\r\n2500\r\n", "output": "3000\r\n"}, {"input": "3 4\r\nATK 10\r\nATK 100\r\nATK 1000\r\n1\r\n11\r\n101\r\n1001\r\n", "output": "992\r\n"}, {"input": "2 4\r\nDEF 0\r\nATK 0\r\n0\r\n0\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "1 1\r\nATK 100\r\n99\r\n", "output"... | false | stdio | null | true |
321/B | 321 | B | PyPy 3-64 | TESTS | 27 | 154 | 512,000 | 150310995 | n, m = map(int, input().split())
atk, defe, ciel, dmg = [], [] , [], 0
for i in range(n):
a, b = input().split()
atk.append(int(b)) if a == "ATK" else defe.append(int(b))
for i in range(m):
ciel.append(int(input()))
atk.sort()
defe.sort(reverse=True)
ciel.sort(reverse=True)
while len(atk) != 0 and len(ciel)... | 80 | 248 | 0 | 46017799 | n , m = map(int , input().split())
a , d = [1e9] , [1e9]
for x in range(n) :
p , s = input().split()
[d , a][p < 'B'].append(int(s))
v = [int(input()) for y in range(m) ]
for q in [a , d , v] : q.sort()
s = sum(v)
i = j = 0
for t in v :
if t > d[i] : s , i = s - t , i + 1
elif t >= a[j] : s , j = s - a... | Codeforces Round 190 (Div. 1) | CF | 2,013 | 2 | 256 | Ciel and Duel | Fox Ciel is playing a card game with her friend Jiro.
Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack.
Now is Ciel's battle phase, Ciel can do the following ope... | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of cards Jiro and Ciel have.
Each of the next n lines contains a string position and an integer strength (0 ≤ strength ≤ 8000) — the position and strength of Jiro's current card. Position is the string "ATK" for attack, and the string "DEF" for... | Output an integer: the maximal damage Jiro can get. | null | In the first test case, Ciel has 3 cards with same strength. The best strategy is as follows. First she uses one of these 3 cards to attack "ATK 2000" card first, this attack destroys that card and Jiro gets 2500 - 2000 = 500 damage. Then she uses the second card to destroy the "DEF 1700" card. Jiro doesn't get damage ... | [{"input": "2 3\nATK 2000\nDEF 1700\n2500\n2500\n2500", "output": "3000"}, {"input": "3 4\nATK 10\nATK 100\nATK 1000\n1\n11\n101\n1001", "output": "992"}, {"input": "2 4\nDEF 0\nATK 0\n0\n0\n1\n1", "output": "1"}] | 1,900 | ["dp", "flows", "greedy"] | 80 | [{"input": "2 3\r\nATK 2000\r\nDEF 1700\r\n2500\r\n2500\r\n2500\r\n", "output": "3000\r\n"}, {"input": "3 4\r\nATK 10\r\nATK 100\r\nATK 1000\r\n1\r\n11\r\n101\r\n1001\r\n", "output": "992\r\n"}, {"input": "2 4\r\nDEF 0\r\nATK 0\r\n0\r\n0\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "1 1\r\nATK 100\r\n99\r\n", "output"... | false | stdio | null | true |
359/C | 359 | C | PyPy 3 | TESTS | 6 | 233 | 16,486,400 | 39135151 | import math
modulus = 10 ** 9 + 7
def main():
n, x = map(int, input().split())
arr = list(map(int, input().split()))
arrSum = sum(arr)
sub_sums = [arrSum - x for x in arr]
min_sub_sums = min(sub_sums)
cnt = sub_sums.count(min_sub_sums)
res = pow(x, min_sub_sums, modulus)
power = mat... | 36 | 77 | 14,745,600 | 155312622 | import sys
input = lambda: sys.stdin.buffer.readline().decode().strip()
mod = 10 ** 9 + 7
n, x = map(int, input().split())
a = [int(x) for x in input().split()]
ans = pow(x, sum(a[:n - 1]), mod)
ma = a[-1]
while len(a) > 1:
cur, num = a.pop(), 1
while a and a[-1] == cur:
a.pop()
num += 1
... | Codeforces Round 209 (Div. 2) | CF | 2,013 | 1 | 256 | Prime Number | Simon has a prime number x and an array of non-negative integers a1, a2, ..., an.
Simon loves fractions very much. Today he wrote out number $$\frac{1}{x^{a_1}} + \frac{1}{x^{a_2}} + \ldots + \frac{1}{x^{a_n}}$$ on a piece of paper. After Simon led all fractions to a common denominator and summed them up, he got a fra... | The first line contains two positive integers n and x (1 ≤ n ≤ 105, 2 ≤ x ≤ 109) — the size of the array and the prime number.
The second line contains n space-separated integers a1, a2, ..., an (0 ≤ a1 ≤ a2 ≤ ... ≤ an ≤ 109). | Print a single number — the answer to the problem modulo 1000000007 (109 + 7). | null | In the first sample $$\frac{1}{4} + \frac{1}{4} = \frac{4+4}{16} = \frac{8}{16}$$. Thus, the answer to the problem is 8.
In the second sample, $$\frac{1}{3}+\frac{1}{9}+\frac{1}{27}=\frac{243+81+27}{729}=\frac{351}{729}$$. The answer to the problem is 27, as 351 = 13·27, 729 = 27·27.
In the third sample the answer to... | [{"input": "2 2\n2 2", "output": "8"}, {"input": "3 3\n1 2 3", "output": "27"}, {"input": "2 2\n29 29", "output": "73741817"}, {"input": "4 5\n0 0 0 0", "output": "1"}] | 1,900 | ["math", "number theory"] | 36 | [{"input": "2 2\r\n2 2\r\n", "output": "8\r\n"}, {"input": "3 3\r\n1 2 3\r\n", "output": "27\r\n"}, {"input": "2 2\r\n29 29\r\n", "output": "73741817\r\n"}, {"input": "4 5\r\n0 0 0 0\r\n", "output": "1\r\n"}, {"input": "1 2\r\n1000000000\r\n", "output": "1\r\n"}, {"input": "26 2\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... | false | stdio | null | true |
354/A | 354 | A | PyPy 3-64 | TESTS | 5 | 62 | 614,400 | 210298697 | '''
https://codeforces.com/problemset/problem/354/A
输入 n(1≤n≤1e5) l r(1≤l,r≤100) ql qr(1≤l,r≤1e4) 和长为 n 的双端队列 q(1≤q[i]≤100)。
每次操作弹出 q 的队首或者队尾,代价分别为 l*a[i] 和 r*a[i]。
如果上一次和当前都是弹出队首,则代价额外加上 ql。
如果上一次和当前都是弹出队尾,则代价额外加上 qr。
输出清空 q 的最小代价。
输入
3 4 4 19 1
42 3 99
输出 576
输入
4 7 2 3 9
1 2 3 4
输出 34
'''
from cmath import inf... | 23 | 77 | 15,667,200 | 210523206 | import sys
RI = lambda: map(int, sys.stdin.buffer.readline().split())
n, l, r, ql, qr = RI()
nums = list(RI())
a = [0]
for v in nums:
a.append(a[-1] + v)
# 枚举分割点[0, i - 1]是左侧, [i, n - 1]是右侧
ans = float("inf")
for i in range(n + 1):
t = a[i] * l + (a[n] - a[i]) * r
# 左边右边各几个?
l_cnt = i
r_cnt = n - i
if ab... | Codeforces Round 206 (Div. 1) | CF | 2,013 | 1 | 256 | Vasya and Robot | Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights wi kilograms.
Vasya needs to collect all these items, however he won't do it by himself. He us... | The first line contains five integers n, l, r, Ql, Qr (1 ≤ n ≤ 105; 1 ≤ l, r ≤ 100; 1 ≤ Ql, Qr ≤ 104).
The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 100). | In the single line print a single number — the answer to the problem. | null | Consider the first sample. As l = r, we can take an item in turns: first from the left side, then from the right one and last item from the left. In total the robot spends 4·42 + 4·99 + 4·3 = 576 energy units.
The second sample. The optimal solution is to take one item from the right, then one item from the left and t... | [{"input": "3 4 4 19 1\n42 3 99", "output": "576"}, {"input": "4 7 2 3 9\n1 2 3 4", "output": "34"}] | 1,500 | ["brute force", "greedy", "math"] | 23 | [{"input": "3 4 4 19 1\r\n42 3 99\r\n", "output": "576\r\n"}, {"input": "4 7 2 3 9\r\n1 2 3 4\r\n", "output": "34\r\n"}, {"input": "2 100 100 10000 10000\r\n100 100\r\n", "output": "20000\r\n"}, {"input": "2 3 4 5 6\r\n1 2\r\n", "output": "11\r\n"}, {"input": "1 78 94 369 10000\r\n93\r\n", "output": "7254\r\n"}, {"inpu... | false | stdio | null | true |
868/D | 868 | D | PyPy 3 | TESTS | 6 | 140 | 6,348,800 | 203826408 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
l = 12
pow2 = [1]
for _ in range(l + 5):
pow2.append(2 * pow2[-1])
s = [list(input().rstrip()) for _ in range(n)]
x = [0]
for i in pow2[1:]:
x.append(x[-1] + i)
dp = [[0] * pow2[l + 1] for _ in range(n)]
for i in r... | 49 | 108 | 2,560,000 | 32367528 | # -*- coding: utf-8 -*-
import math
import collections
import bisect
import heapq
import time
import random
"""
created by shhuan at 2017/10/5 15:00
"""
N = int(input())
S = ['']
for i in range(N):
S.append(input())
M = int(input())
# t0 = time.time()
# N = 3
# S = ["", "00010110000", "110101110101101010101101... | Codeforces Round 438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined) | CF | 2,017 | 2 | 256 | Huge Strings | You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations are performed, on each of them you concatenate two existing strings into a new one. On the i-th operation the concatenation saisbi is saved into a new string sn + i (the operations are numbered starting from 1). After each operation ... | The first line contains single integer n (1 ≤ n ≤ 100) — the number of strings. The next n lines contain strings s1, s2, ..., sn (1 ≤ |si| ≤ 100), one per line. The total length of strings is not greater than 100.
The next line contains single integer m (1 ≤ m ≤ 100) — the number of operations. m lines follow, each of... | Print m lines, each should contain one integer — the answer to the question after the corresponding operation. | null | On the first operation, a new string "0110" is created. For k = 1 the two possible binary strings of length k are "0" and "1", they are substrings of the new string. For k = 2 and greater there exist strings of length k that do not appear in this string (for k = 2 such string is "00"). So the answer is 1.
On the secon... | [{"input": "5\n01\n10\n101\n11111\n0\n3\n1 2\n6 5\n4 4", "output": "1\n2\n0"}] | 2,200 | ["bitmasks", "brute force", "dp", "implementation", "strings"] | 49 | [{"input": "5\r\n01\r\n10\r\n101\r\n11111\r\n0\r\n3\r\n1 2\r\n6 5\r\n4 4\r\n", "output": "1\r\n2\r\n0\r\n"}, {"input": "5\r\n01\r\n1\r\n0011\r\n0\r\n01\r\n6\r\n5 5\r\n3 2\r\n4 2\r\n6 7\r\n5 1\r\n9 7\r\n", "output": "1\r\n1\r\n1\r\n2\r\n1\r\n2\r\n"}, {"input": "5\r\n111101000111100011100110000100\r\n000111001\r\n0110100... | false | stdio | null | true |
719/B | 719 | B | Python 3 | TESTS | 4 | 46 | 5,529,600 | 26205989 | n = int(input())
series = input()
series2 = 'br'*n
series3 = 'rb'*n
count1a = 0
count1b = 0
count2a = 0
count2b = 0
for x in range(n):
if series[x] == series2[x]:
continue
elif series[x] == 'a':
count1a = count1a + 1
elif series[x] == 'b':
count1b = count1b + 1
for x in range(n):
... | 46 | 62 | 1,740,800 | 166410347 | import sys
input = sys.stdin.readline
n = int(input())
s = input()[:-1]
r1, b1, r2, b2 = 0, 0, 0, 0
for i in range(n):
if i%2:
if s[i] == 'r':
b1 += 1
else:
r2 += 1
else:
if s[i] == 'r':
b2 += 1
else:
r1 += 1
print(min(max(b1, r... | Codeforces Round 373 (Div. 2) | CF | 2,016 | 1 | 256 | Anatoly and Cockroaches | Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectioni... | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of cockroaches.
The second line contains a string of length n, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively. | Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate. | null | In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.
In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.
In the third sample, the colors of cockroaches in the line are alternating already, thus the answer ... | [{"input": "5\nrbbrr", "output": "1"}, {"input": "5\nbbbbb", "output": "2"}, {"input": "3\nrbr", "output": "0"}] | 1,400 | ["greedy"] | 46 | [{"input": "5\r\nrbbrr\r\n", "output": "1\r\n"}, {"input": "5\r\nbbbbb\r\n", "output": "2\r\n"}, {"input": "3\r\nrbr\r\n", "output": "0\r\n"}, {"input": "13\r\nrbbbrbrrbrrbb\r\n", "output": "3\r\n"}, {"input": "18\r\nrrrrrrrrrrrrrrrrrb\r\n", "output": "8\r\n"}, {"input": "100\r\nbrbbbrrrbbrbrbbrbbrbbbbrbbrrbbbrrbbbbrbr... | false | stdio | null | true |
719/B | 719 | B | Python 3 | TESTS | 4 | 46 | 4,608,000 | 28404105 | while True:
try:
n = int(input())
line = input()
lenght = len(line)
one = ['r', 'b'] if line[0] == 'r' else ['b', 'r']
cpline = one*(lenght//2 + 1)
dr , db = 0, 0
for i in range(lenght):
if(line[i] != cpline[i]):
if line[i] == 'r':
... | 46 | 62 | 1,843,200 | 186654167 | n = int(input())
s = input()
orcnt = 0
ercnt = 0
obcnt = 0
ebcnt = 0
for i in range(n):
if i%2==0:
if s[i] == 'r':
ercnt += 1
else:
ebcnt += 1
else:
if s[i] == 'r':
orcnt += 1
else:
obcnt += 1
if orcnt+ercnt > obcnt+ebcnt:
print(min(orcnt,ercnt))
else:
print(min(obcnt,ebcnt)) | Codeforces Round 373 (Div. 2) | CF | 2,016 | 1 | 256 | Anatoly and Cockroaches | Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectioni... | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of cockroaches.
The second line contains a string of length n, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively. | Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate. | null | In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.
In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.
In the third sample, the colors of cockroaches in the line are alternating already, thus the answer ... | [{"input": "5\nrbbrr", "output": "1"}, {"input": "5\nbbbbb", "output": "2"}, {"input": "3\nrbr", "output": "0"}] | 1,400 | ["greedy"] | 46 | [{"input": "5\r\nrbbrr\r\n", "output": "1\r\n"}, {"input": "5\r\nbbbbb\r\n", "output": "2\r\n"}, {"input": "3\r\nrbr\r\n", "output": "0\r\n"}, {"input": "13\r\nrbbbrbrrbrrbb\r\n", "output": "3\r\n"}, {"input": "18\r\nrrrrrrrrrrrrrrrrrb\r\n", "output": "8\r\n"}, {"input": "100\r\nbrbbbrrrbbrbrbbrbbrbbbbrbbrrbbbrrbbbbrbr... | false | stdio | null | true |
952/E | 952 | E | PyPy 3 | TESTS | 2 | 61 | 0 | 177840972 | a = int(input())
h = 0
s = 0
for i in range(a):
x, y = map(str, input().split())
if y == 'hard':
h += 1
else:
s += 1
z = 0
x = 1
while z != 1:
if x*x // 2 + 1>= max(h, s):
print(x)
z = 1
x += 1 | 40 | 77 | 7,065,600 | 36841042 | n = int(input())
sf = 0
hd = 0
for _ in range(n):
_, t = input().split()
if t == 'soft':
sf += 1
else:
hd += 1
for i in range(1,20):
if sf <= (i**2+1)//2 and hd <= (i**2+1)//2 and sf+hd<=i**2:
print(i)
break | April Fools Contest 2018 | ICPC | 2,018 | 1 | 256 | Cheese Board | Not to be confused with chessboard. | The first line of input contains a single integer N (1 ≤ N ≤ 100) — the number of cheeses you have.
The next N lines describe the cheeses you have. Each line contains two space-separated strings: the name of the cheese and its type. The name is a string of lowercase English letters between 1 and 10 characters long. Th... | Output a single number. | null | null | [{"input": "9\nbrie soft\ncamembert soft\nfeta soft\ngoat soft\nmuenster soft\nasiago hard\ncheddar hard\ngouda hard\nswiss hard", "output": "3"}, {"input": "6\nparmesan hard\nemmental hard\nedam hard\ncolby hard\ngruyere hard\nasiago hard", "output": "4"}] | 2,000 | [] | 40 | [{"input": "9\r\nbrie soft\r\ncamembert soft\r\nfeta soft\r\ngoat soft\r\nmuenster soft\r\nasiago hard\r\ncheddar hard\r\ngouda hard\r\nswiss hard\r\n", "output": "3\r\n"}, {"input": "6\r\nparmesan hard\r\nemmental hard\r\nedam hard\r\ncolby hard\r\ngruyere hard\r\nasiago hard\r\n", "output": "4\r\n"}, {"input": "9\r\n... | false | stdio | null | true |
177/E1 | 177 | E1 | PyPy 3 | TESTS1 | 3 | 248 | 1,433,600 | 90219210 | input=__import__('sys').stdin.readline
n,c = map(int,input().split())
lis=[]
for _ in range(n):
a,b = map(int,input().split())
lis.append([a,b])
#max
l=0
r=1000000000000
while l<=r:
mid = l + (r-l)//2
tmp=0
for i in range(n):
tmp+=(1 + (lis[i][0]*mid)//lis[i][1])
if tmp>c:
r=mid-... | 46 | 312 | 819,200 | 4856163 | def f(x, t):
y = x
while sum((y * a) // b for a, b in t) < c: y += 1000000
while y - x > 1:
z = (x + y) // 2
d = sum((z * a) // b for a, b in t)
if d < c: x = z
else: y = z
return y
n, c = map(int, input().split())
c -= n
t = [tuple(map(int, input().split())) for i i... | ABBYY Cup 2.0 - Easy | ICPC | 2,012 | 2 | 256 | Space Voyage | The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet.
The Smart Beaver is going to bring som... | The first input line contains space-separated integers n and c — the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly.
The next n lines contain pairs of space-separated integers ai, bi (1 ≤ i ≤ n) — the number of suitcases he can bring to the i-... | Print a single number k — the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | null | In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days... | [{"input": "2 5\n1 5\n2 4", "output": "1"}] | 1,700 | ["binary search"] | 21 | [{"input": "2 5\r\n1 5\r\n2 4\r\n", "output": "1\r\n"}, {"input": "1 97\r\n1 91\r\n", "output": "91\r\n"}, {"input": "2 79\r\n1 91\r\n1 77\r\n", "output": "42\r\n"}, {"input": "3 100\r\n8 46\r\n8 56\r\n77 98\r\n", "output": "1\r\n"}, {"input": "7 77\r\n2 95\r\n2 91\r\n3 95\r\n2 94\r\n3 96\r\n2 97\r\n2 91\r\n", "output"... | false | stdio | null | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.