src_uid stringlengths 32 32 | prob_desc_description stringlengths 63 2.99k | tags stringlengths 6 159 | source_code stringlengths 29 58.4k | lang_cluster stringclasses 1
value | categories sequencelengths 1 5 | desc_length int64 63 3.13k | code_length int64 29 58.4k | games int64 0 1 | geometry int64 0 1 | graphs int64 0 1 | math int64 0 1 | number theory int64 0 1 | probabilities int64 0 1 | strings int64 0 1 | trees int64 0 1 | labels_dict dict | __index_level_0__ int64 0 4.98k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2b37f27a98ec8f80d0bff3f7ae8f2cff | Young boy Artem tries to paint a picture, and he asks his mother Medina to help him. Medina is very busy, that's why she asked for your help.Artem wants to paint an n \times m board. Each cell of the board should be colored in white or black. Lets B be the number of black cells that have at least one white neighbor adj... | ['constructive algorithms'] | for _ in range(int(input())):
N, M = map(int, input().split())
mat = [['B' for col in range(M)] for row in range(N)]
mat[0][0] = 'W'
for row in mat:
print(''.join(row))
| Python | [
"other"
] | 943 | 224 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 4,970 |
94bc4b263821713fb5b1de4de331a515 | You are given a positive integer n. Since n may be very large, you are given its binary representation.You should compute the number of triples (a,b,c) with 0 \leq a,b,c \leq n such that a \oplus b, b \oplus c, and a \oplus c are the sides of a non-degenerate triangle. Here, \oplus denotes the bitwise XOR operation.You... | ['bitmasks', 'dp'] | MOD = 998244353
TRANS = [6, 3, 7, 4, 1, 0]
s = input().strip()
dp = [0] * 7 + [1]
for c in map(int, s):
dp1 = [0] * 8
for i in range(8):
for k in TRANS:
if c:
dp1[k & i] += dp[i]
elif (k & i) == 0:
dp1[i] += dp[i]
dp = [x % MOD f... | Python | [
"other"
] | 582 | 406 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 2,162 |
e588d7600429eb6b70a1a9b5eca194f7 | Recently, on a programming lesson little Petya showed how quickly he can create files and folders on the computer. But he got soon fed up with this activity, and he decided to do a much more useful thing. He decided to calculate what folder contains most subfolders (including nested folders, nested folders of nested fo... | ['data structures', 'implementation'] | import sys
from array import array # noqa: F401
from collections import defaultdict
def input():
return sys.stdin.buffer.readline().decode('utf-8')
cnt1 = defaultdict(set)
cnt2 = defaultdict(int)
for line in sys.stdin:
path = line.rstrip().split('\\')
key = tuple(path[:2])
for i in range(3, len(pa... | Python | [
"other"
] | 1,765 | 496 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,999 |
ac02c52caac155458e998fb448b8cc0d | You play a strategic video game (yeah, we ran out of good problem legends). In this game you control a large army, and your goal is to conquer n castles of your opponent.Let's describe the game process in detail. Initially you control an army of k warriors. Your enemy controls n castles; to conquer the i-th castle, you... | ['dp', 'greedy', 'implementation', 'sortings', 'data structures'] | from heapq import heappush, heappop
n, m, k = map(int, input().split())
a = [0]
b = [0]
c = [0]
for i in range(n):
aa, bb, cc = map(int, input().split())
a.append(aa)
b.append(bb)
c.append(cc)
a += [0]
road = [[] for i in range(n+1)]
last = [i for i in range(0, n+1)]
for i in range(m):
u, v = map(in... | Python | [
"other"
] | 2,395 | 858 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 948 |
c19500d867fd0108fdeed2cbd00bc970 | A sequence of positive integers is called great for a positive integer x, if we can split it into pairs in such a way that in each pair the first number multiplied by x is equal to the second number. More formally, a sequence a of size n is great for a positive integer x, if n is even and there exists a permutation p o... | ['greedy', 'sortings'] | import collections
import os, sys
from io import BytesIO, IOBase
inf = sys.maxsize
def get_ints():
return map(int, input().split())
def get_array():
return list(map(int, input().split()))
mod = 1000000007
MOD = 998244353
def main():
for _ in range(int(input())):
n,x=get... | Python | [
"other"
] | 713 | 2,382 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 2,196 |
9070e0d4f8071d1ee8df5189b7c17bfa | A binary string is a string consisting only of the characters 0 and 1. You are given a binary string s.For some non-empty substring^\dagger t of string s containing x characters 0 and y characters 1, define its cost as: x \cdot y, if x > 0 and y > 0; x^2, if x > 0 and y = 0; y^2, if x = 0 and y > 0. Given a... | ['brute force', 'greedy', 'implementation'] | for i in range(int(input())):
n=int(input())
s=input()
ans=max(s.count('1')*s.count('0'),1)
st=1
s=s.strip()
for j in range(1,n):
if s[j]==s[j-1]:
st+=1
else:
st=1
ans=max(ans,st*st)
print(ans) | Python | [
"other"
] | 757 | 281 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 2,958 |
9fd8e75cb441dc809b1b2c48c4012c76 | You are given n points on the straight line — the positions (x-coordinates) of the cities and m points on the same line — the positions (x-coordinates) of the cellular towers. All towers work in the same way — they provide cellular network for all cities, which are located at the distance which is no more than r from t... | ['two pointers', 'binary search', 'implementation'] | from bisect import bisect_left
n, m = map(int, raw_input().split())
a = map(int, raw_input().split())
b = map(int, raw_input().split())
min_r = 0
for el in a:
i = bisect_left(b, el)
if i == 0:
min_r = max(min_r, abs(el - b[0]))
elif i == m:
min_r = max(min_r, abs(el - b[m-1]))
elif i =... | Python | [
"other"
] | 749 | 512 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,282 |
0fd33e1bdfd6c91feb3bf00a2461603f | The only difference between easy and hard versions is the length of the string.You are given a string s and a string t, both consisting only of lowercase Latin letters. It is guaranteed that t can be obtained from s by removing some (possibly, zero) number of characters (not necessary contiguous) from s without changin... | ['two pointers', 'binary search', 'implementation', 'greedy'] | def checker(mainstr, substr, index):
size = len(mainstr)-1
maxdrop=0
pos=[-1]
for i in substr:
temp = mainstr.find(i,index)
pos.append(temp)
index = temp+1
index=0
newmainstr = mainstr[::-1]
maxsize = len(mainstr)-1
for i in range(len(substr),0,-1):
curr... | Python | [
"other"
] | 1,159 | 749 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 3,891 |
b389750613e9577b3abc9e5e5902b2db | Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the program that plays chess. However, he finds the game on 8 to 8 board to too simple, he uses an infinite one instead.The first task he faced is to check whether the king is in check. Anton doesn't know how to implement this ... | ['implementation'] | n=input()
x,y=map(int,raw_input().split())
v=[(10**11,'?')]*8
for _ in range(n):
c,i,j=raw_input().split()
i,j=int(i),int(j)
if i==x:
d=j-y
if d>0 and d<v[0][0]:
v[0]=(d,c)
elif d<0 and -d<v[1][0]:
v[1]=(-d,c)
if j==y:
d=i-x
if d>0 and d<v[2][0]:
v[2]=(d,c)
elif d<0 and... | Python | [
"other"
] | 1,092 | 754 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 4,073 |
2eb101dcfcc487fe6e44c9b4c0e4024d | The only difference between easy and hard versions is constraints.Ivan plays a computer game that contains some microtransactions to make characters look cooler. Since Ivan wants his character to be really cool, he wants to use some of these microtransactions — and he won't start playing until he gets all of them.Each ... | ['binary search', 'implementation', 'greedy'] | import collections
def main():
from sys import stdin, stdout
def read():
return stdin.readline().rstrip('\n')
def read_array(sep=None, maxsplit=-1):
return read().split(sep, maxsplit)
def read_int():
return int(read())
def read_int_array(sep=None, maxsplit=-1):
... | Python | [
"other"
] | 1,285 | 1,868 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,323 |
5aa653e7af021505e6851c561a762578 | Dr. Evil is interested in math and functions, so he gave Mahmoud and Ehab array a of length n and array b of length m. He introduced a function f(j) which is defined for integers j, which satisfy 0 ≤ j ≤ m - n. Suppose, ci = ai - bi + j. Then f(j) = |c1 - c2 + c3 - c4... cn|. More formally, . Dr. Evil wants Mahmoud and... | ['data structures', 'binary search', 'sortings'] | def read(): return list(map(int, input().split(' ')))
n, m, q = read()
aa = read()
bb = read()
reqs = [read() for _ in range(q)]
asum = 0
bsum = 0
for i, (a, b) in enumerate(zip(aa, bb)):
asum += a if i % 2 == 0 else -a
bsum += b if i % 2 == 0 else -b
bpos = [bsum]
for i in range(len(aa), len(bb)):
b = bb... | Python | [
"other"
] | 730 | 1,032 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 119 |
3c93a76f986b1ef653bf5834716ac72a | You are given a binary string s (recall that a string is binary if each character is either 0 or 1).Let f(t) be the decimal representation of integer t written in binary form (possibly with leading zeroes). For example f(011) = 3, f(00101) = 5, f(00001) = 1, f(10) = 2, f(000) = 0 and f(000100) = 4.The substring s_{l}, ... | ['binary search', 'bitmasks', 'brute force'] | t = int(input())
for _ in range(t):
s = input()
ct = int(0)
ans = int(0)
for i in range(len(s)):
if s[i] == '0':
ct += 1
else:
num = int(0)
for j in range(i,len(s)):
num *= 2
if s[j] == '1':
num += 1
... | Python | [
"other"
] | 752 | 491 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 2,526 |
0a701242ca81029a1791df74dc8ca59b | Consider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4n.Consider that m (m ≤ 4n) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to m (in the order o... | ['implementation'] | n,m=map(int,raw_input().split())
bus=[[0,0,0,0]for i in xrange(n)]
r=0
for i in xrange(1,m+1):
if bus[r][0]==0:
bus[r][0]=i
elif bus[r][3]==0:
bus[r][3]=i
r+=1
r%=n
elif bus[r][1]==0:
bus[r][1]=i
else:
bus[r][2]=i
r+=1
r%=n
for i in xrange(... | Python | [
"other"
] | 1,299 | 386 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,283 |
485d5984e34a479f2c074a305ae999ae | An integer array a_1, a_2, \ldots, a_n is being transformed into an array of lowercase English letters using the following prodecure:While there is at least one number in the array: Choose any number x from the array a, and any letter of the English alphabet y. Replace all occurrences of number x with the letter y. For... | ['greedy', 'implementation'] | from sys import stdin, stdout
I = stdin.readline
O = stdout.write
# n = int(I())
# arr = list(map(int, I().split()))
def solve():
n = int(I())
arr = list(map(int, I().split()))
s = input()
mp = {}
ans = ""
ok = True
for i in range(n):
if arr[i] in mp:
... | Python | [
"other"
] | 1,058 | 586 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 4,107 |
c1158d23d3ad61c346c345f14e63ede4 | 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 height... | ['sortings'] | input()
a=map(int,raw_input().split())
c={}
p,n,s=0,0,0
for x,y in zip(a,sorted(a)):
c[x]=c.get(x,0)+1
if 0==c[x]:
n-=1
elif 1==c[x]:
p+=1
c[y]=c.get(y,0)-1
if 0==c[y]:
p-=1
elif -1==c[y]:
n+=1
if not p and not n:
s+=1
print s | Python | [
"other"
] | 1,474 | 260 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 3,677 |
1f714ac601f6b5bdcb4fa32cdb56629d | You are given a sequence a of length n consisting of 0s and 1s.You can perform the following operation on this sequence: Pick an index i from 1 to n-2 (inclusive). Change all of a_{i}, a_{i+1}, a_{i+2} to a_{i} \oplus a_{i+1} \oplus a_{i+2} simultaneously, where \oplus denotes the bitwise XOR operation Find a sequence ... | ['constructive algorithms'] | try:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
# from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
... | Python | [
"other"
] | 699 | 2,955 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 3,410 |
6c52df7ea24671102e4c0eee19dc6bba | Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo... | ['implementation'] | n = int(input())
i = 0
l = []
c = 1
a = input()
temp = a
while(i<n-1):
a = input()
if(temp!=a):
c =c + 1
temp = a
i = i + 1
print(c) | Python | [
"other"
] | 932 | 156 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 3,333 |
3c066bad8ee6298b318bf0f4521c7c45 | Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at tha... | ['implementation'] | n, x0 = map(int, input().split())
x1, x2 = 0, 1000
for i in range(n):
a, b = map(int, input().split())
x1 = max(x1, min(a, b))
x2 = min(x2, max(a, b))
print(max(0, x1 - x0, x0 - x2) if x2 >= x1 else -1)
| Python | [
"other"
] | 784 | 215 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 2,371 |
c16c49baf7b2d179764871204475036e | Game "Minesweeper 1D" is played on a line of squares, the line's height is 1 square, the line's width is n squares. Some of the squares contain bombs. If a square doesn't contain a bomb, then it contains a number from 0 to 2 — the total number of bombs in adjacent squares.For example, the correct field to play looks li... | ['dp', 'implementation'] | from sys import stdin
def main():
s = stdin.readline().strip()
if s[0] == '2' or s[-1] == '2':
print 0
return
# 0, *1, 1*, *2*, *
if s[0] == '?':
dp = [1, 0, 1, 0, 1]
elif s[0] == '0':
dp = [1, 0, 0, 0, 0]
elif s[0] == '1':
dp = [0, 0, 1, 0, 0]
elif s[... | Python | [
"other"
] | 914 | 949 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,872 |
e48fb08f88f89154c54a3231f0d2f25c | Instructors of Some Informatics School make students go to bed.The house contains n rooms, in each room exactly b students were supposed to sleep. However, at the time of curfew it happened that many students are not located in their assigned rooms. The rooms are arranged in a row and numbered from 1 to n. Initially, i... | ['binary search', 'sortings', 'greedy', 'brute force'] | read = lambda: map(int, input().split())
n, d, b = read()
d += 1
t, a = 0, [0] * (n + 1)
for i, x in enumerate(read()):
t += x
a[i + 1] = t
print(max(i - min(a[min(n, i * d)], (a[n] - a[max(0, n - i * d)])) // b for i in range(n + 3 >> 1)))
| Python | [
"other"
] | 2,926 | 249 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,923 |
5d5dfa4f129bda46055fb636ef33515f | DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert n numbers, in the order they are given, into the hash table. For the i-th number xi, DZY will put it into the bucket numbered h(xi), where h(x) is the hash function. In this problem we will assume, that h(x) = x mod p. Operation a mod b d... | ['implementation'] | p,n=map(int,raw_input().split())
a=[0]*500
for i in range(n):
x=input()
x=x%p
#print i,x
if a[x]==1:
print i+1
exit()
a[x]=1
print -1 | Python | [
"other"
] | 655 | 169 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 3,313 |
8c36ab13ca1a4155cf97d0803aba11a3 | Vasya has two arrays A and B of lengths n and m, respectively.He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the array [1, 10... | ['two pointers', 'greedy'] | n = int(input())
a = list(map(int,input().split()))
m = int(input())
b = list(map(int,input().split()))
i,j,ans =0,0,0
while(i<n and j<m):
if a[i]==b[j]:
ans+=1
i+=1
j+=1
elif a[i]<b[j]:
if i+1<len(a):
a[i+1]+=a[i]
i+=1
elif b[j]<a[i]:
if j+1<len(b... | Python | [
"other"
] | 989 | 403 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 182 |
dd1d166772ee06b383d4ceb94b530fd1 | You have k pieces of laundry, each of which you want to wash, dry and fold. You are at a laundromat that has n1 washing machines, n2 drying machines and n3 folding machines. Each machine can process only one piece of laundry at a time. You can't dry a piece of laundry before it is washed, and you can't fold it before i... | ['implementation', 'greedy'] | k,n1,n2,n3,t1,t2,t3=map(int,raw_input().split())
Z=1024
v=[-10**11]*Z+[0]*10100
v[Z]=0
for i in range(Z,Z+k):
v[i]=max(v[i],v[i-n1]+t1,v[i-n2]+t2,v[i-n3]+t3)
print v[Z+k-1]+t1+t2+t3
| Python | [
"other"
] | 772 | 185 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,350 |
b7ff1ded73a9f130312edfe0dafc626d | After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length n which satisfies the following requirements: There is at least one digit in the string, There is at least one lowercase (small) letter of the Latin alphabet in the string, There is... | ['dp', 'implementation', 'brute force'] | n, m = map(int, input().split())
tmp = [input() for _ in range(n)]
arr = []
for s in tmp:
t = [1e4, 1e4, 1e4]
for j in range(m):
if s[j] >= '0' and s[j] <= '9':
t[0] = min(j, t[0], m-j)
elif s[j] >= 'a' and s[j] <= 'z':
t[1] = min(j, t[1], m-j)
else:
t... | Python | [
"other"
] | 1,302 | 582 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 3,020 |
7f4293c5602429819e05beca45b22c05 | There is a river of width n. The left bank of the river is cell 0 and the right bank is cell n + 1 (more formally, the river can be represented as a sequence of n + 2 cells numbered from 0 to n + 1). There are also m wooden platforms on a river, the i-th platform has length c_i (so the i-th platform takes c_i consecuti... | ['greedy'] | import sys
n, m, d = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a = []
i = 0
j = 0
while i + d < n + 1:
if j >= len(c):
print("NO")
sys.exit()
i += d + c[j] - 1
a += [0] * (d - 1)
a += [j+1] * (c[j])
j += 1
s = 0
if len(a) > n:
s += len(a) - n
elif ... | Python | [
"other"
] | 1,575 | 711 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 4,303 |
b54ced81e152a28c19e0068cf6a754f6 | There are n problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty, and no two problems have the same difficulty. Moreover, there are m pairs of similar problems. Authors want to split problems between two division according to the following rules: Problemset of each d... | ['implementation', 'greedy'] | n,m=map(int,input().split())
a=[0]*(n+1)
c=[0]*4
d=[0]*4
ans=0
for i in range(m):
x,y=sorted(map(int,input().split()))
a[x]|=1
a[y]|=2
for x in a: c[x]+=1
if c[3]==0:
for i in range(1,n):
if a[i]>1: break
d[a[i]]+=1
c[a[i]]-=1
if c[1]>0: continue
ans+=1
print(ans) | Python | [
"other"
] | 1,050 | 293 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,702 |
d6c228bc6e4c17894d9e723ff980844f | Baby Ehab has a piece of Cut and Stick with an array a of length n written on it. He plans to grab a pair of scissors and do the following to it: pick a range (l, r) and cut out every element a_l, a_{l + 1}, ..., a_r in this range; stick some of the elements together in the same order they were in the array; end up wit... | ['binary search', 'data structures', 'greedy', 'implementation', 'sortings'] |
randCnts=25
rand40=[26163, 136194, 134910, 131586, 131511, 151306, 107322, 4960, 27557, 30930, 34180, 123393, 226938, 259573, 203560, 182549, 208694, 270671, 3616, 256123, 215635, 140161, 243942, 251246, 210982, 138905, 226417, 63875, 281860, 24400, 129710, 157586, 257466, 113783, 57707, 20202, 179489, 273724, 71076... | Python | [
"other"
] | 1,188 | 2,695 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,897 |
da5f2ad6c1ef2cccab5c04f44b9e1412 | You are given an integer n and an array a_1,a_2,\ldots,a_n.In one operation, you can choose an index i (1 \le i \lt n) for which a_i \neq a_{i+1} and delete both a_i and a_{i+1} from the array. After deleting a_i and a_{i+1}, the remaining parts of the array are concatenated.For example, if a=[1,4,3,3,6,2], then after ... | ['data structures', 'dp', 'greedy'] | import sys
input = sys.stdin.readline
dp = [[1] * 5050 for _ in range(5050)]
for _ in range(int(input())):
n = int(input())
arr = [*map(int, input().split())]
for i in range(n):
for j in range(n):
dp[i][j] = 1
for j in range(n):
mx = 0
cnt = [0] *... | Python | [
"other"
] | 624 | 969 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 3,674 |
b8016e8d1e7a3bb6d0ffdcc5ef9ced19 | Professor GukiZ has two arrays of integers, a and b. Professor wants to make the sum of the elements in the array a sa as close as possible to the sum of the elements in the array b sb. So he wants to minimize the value v = |sa - sb|.In one operation professor can swap some element from the array a and some element fro... | ['two pointers', 'binary search'] | import sys
range = xrange
input = raw_input
n = int(input())
A = [float(x) for x in input().split()]
m = int(input())
B = [float(x) for x in input().split()]
summa = sum(A) - sum(B)
AA = [-2*a for a in A]
BB = [-2*b for b in B]
besta = besta0 = abs(summa)
besta1i = -1
besta1j = -1
for i in range(n):
for j in ... | Python | [
"other"
] | 807 | 1,509 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 4,711 |
0f637be16ae6087208974eb2c8f3b403 | Mayor of city S just hates trees and lawns. They take so much space and there could be a road on the place they occupy!The Mayor thinks that one of the main city streets could be considerably widened on account of lawn nobody needs anyway. Moreover, that might help reduce the car jams which happen from time to time on ... | ['constructive algorithms', 'implementation', 'greedy'] | import sys
n = int(raw_input())
roads = [tuple(map(int, raw_input().split())) for _ in range(n)]
neck = min(enumerate(roads), key=lambda x: x[1][0] + x[1][1])
snew = [0]*n
snew[neck[0]] = neck[1][0] + neck[1][1]
i = neck[0] - 1
fail = False
while i > -1:
if fail: break
ol = snew[i+1]
mn = roads[i][0]
... | Python | [
"other"
] | 1,294 | 1,556 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 3,913 |
a1951e7d11b504273765fc9fb2f18a5e | You have n students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the i-th student skill is denoted by an integer a_i (different students can have the same skills).So, about the teams. Firstly, these two teams should have the sam... | ['sortings', 'binary search', 'implementation', 'greedy'] | z,zz=input,lambda:list(map(int,z().split()))
zzz=lambda:[int(i) for i in stdin.readline().split()]
szz,graph,mod,szzz=lambda:sorted(zz()),{},10**9+7,lambda:sorted(zzz())
from string import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
... | Python | [
"other"
] | 1,567 | 1,308 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,990 |
4004c77b77076bf450cbe751e025a71f | Baby Ehab is known for his love for a certain operation. He has an array a of length n, and he decided to keep doing the following operation on it: he picks 2 adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR. Note that the length of the array decreases by one. Now he... | ['bitmasks', 'brute force', 'dp', 'greedy'] | t = int(input())
for i in range(t):
n = int(input())
a = ([int(i) for i in input().split()])
xor_arr = 0
for ele in a:
xor_arr = xor_arr ^ ele
if xor_arr == 0 :
print("YES")
else:
count = 0
xor = 0
for ele in a:
... | Python | [
"other"
] | 505 | 534 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 683 |
e95fb7d4309747834b37d4bc3468afb7 | You get to work and turn on the computer. You start coding and give little thought to the RAM role in the whole process. In this problem your task is to solve one of the problems you encounter in your computer routine.We'll consider the RAM as a sequence of cells that can contain data. Some cells already contain some d... | ['binary search', 'bitmasks', 'greedy'] | from sys import stdin, stdout
from collections import Counter, defaultdict
from itertools import permutations, combinations
raw_input = stdin.readline
pr = stdout.write
def in_arr():
return map(int,raw_input().split())
def pr_num(n):
stdout.write(str(n)+'\n')
def pr_arr(arr):
for i in arr:
std... | Python | [
"other"
] | 919 | 717 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 2,916 |
c1e952cb7dd158f12df6affcff07b68a | Прошло много лет, и на вечеринке снова встретились n друзей. С момента последней встречи техника шагнула далеко вперёд, появились фотоаппараты с автоспуском, и теперь не требуется, чтобы один из друзей стоял с фотоаппаратом, и, тем самым, оказывался не запечатлённым на снимке.Упрощенно процесс фотографирования можно оп... | ['dp', 'greedy'] | n = int(input().rstrip())
d = []
for i in range(n):
w, h = map(int, input().rstrip().split())
d.append([w, h])
s = '.'
for i in range(len(d)):
h = d[i][0]
w = d[i][1]
f = 1
for j in range(len(d)):
if j != i:
if d[j][0] <= h and d[j][1] <= h:
w += min(d[j][... | Python | [
"other"
] | 871 | 1,086 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 3,157 |
08f1ba79ced688958695a7cfcfdda035 | Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and the c... | ['dp'] | n = int(input())
a = [int(i) for i in input().split()]
action = 0
rest = 0
for i in range(n):
if a[i] == 0:
rest += 1
action = 0
elif a[i] == 1:
if action != 1:
action = 1
else:
rest += 1
action = 0
elif a[i] == 2:
if action != 2:
... | Python | [
"other"
] | 1,026 | 817 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 897 |
4754dd329ec5a01d4d101951656bf66a | You are given an array a of n integers a_1, a_2, a_3, \ldots, a_n.You have to answer q independent queries, each consisting of two integers l and r. Consider the subarray a[l:r] = [a_l, a_{l+1}, \ldots, a_r]. You can apply the following operation to the subarray any number of times (possibly zero)- Choose two integers ... | ['binary search', 'bitmasks', 'constructive algorithms', 'data structures'] | #from math import ceil, floor #, gcd, log, factorial, comb, perm,
#log10, log2, log, sin, asin, tan, atan, radians
#from heapq import heappop,heappush,heapify #heappop(hq), heapify(list)
from collections import defaultdict as dd
#mydd=dd(list) for .append
#from collections import deque as dq #deque e.g. myqueue=d... | Python | [
"other"
] | 839 | 6,687 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 946 |
a26a97586d4efb5855aa3b930e9effa7 | Gerald plays the following game. He has a checkered field of size n × n cells, where m various cells are banned. Before the game, he has to put a few chips on some border (but not corner) board cells. Then for n - 1 minutes, Gerald every minute moves each chip into an adjacent cell. He moves each chip from its original... | ['two pointers', 'implementation', 'greedy'] | n, m = map(int, input().split())
l = [0 for i in range(0, n)]
c = [0 for i in range(0, n)]
sol = 0
for i in range(0, m):
a, b = map(int, input().split())
l[a-1] = 1
c[b-1] = 1
for i in range(1, n//2):
#ma ocup de liniile i si n-i, coloanele la fel
sol += 4 - (l[i] + c[i] + l[n-i-1] + c[n-i-1])
if... | Python | [
"other"
] | 912 | 399 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,581 |
cf912f6efc3c0e3fabdaa5f878a777c5 | A class of students got bored wearing the same pair of shoes every day, so they decided to shuffle their shoes among themselves. In this problem, a pair of shoes is inseparable and is considered as a single object.There are n students in the class, and you are given an array s in non-decreasing order, where s_i is the ... | ['constructive algorithms', 'greedy', 'implementation', 'two pointers'] | for i in range(int(input())):
n=int(input())
s=input().split()
if n==1:
print(-1)
else:
k=0
b=[]
from collections import Counter
x=Counter(s)
sorted(x.items())
for i in x:
if x[i]==1:
b=[]
print(-1)
break
else:
b.append(len(b)+x[i])
k+=1
for j in rang... | Python | [
"other"
] | 1,098 | 441 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 2,758 |
c914a0f00403ece367f05ba5e8d558ec | Alice and Bob play a game. The game consists of several sets, and each set consists of several rounds. Each round is won either by Alice or by Bob, and the set ends when one of the players has won x rounds in a row. For example, if Bob won five rounds in a row and x = 2, then two sets ends.You know that Alice and Bob h... | ['dp', 'greedy', 'two pointers', 'data structures', 'binary search'] | # Author: yumtam
# Created at: 2020-08-28 05:07
from __future__ import division, print_function
_interactive = False
def stupid(n, ar):
from itertools import product
unknowns = ar.count(-1)
print(n, end=' ')
for consec in range(2, n+1):
ans = 0
for p in product(range(1+1), repeat=... | Python | [
"other"
] | 711 | 3,294 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 2,022 |
c31fed523230af1f904218b2fe0d663d | A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other.The architect bureau, where Pete... | ['implementation', 'sortings'] | n,l = map(int, raw_input().split())
xr = xrange(n)
a = [map(float, raw_input().split()) for _ in xr]
for o in a:
st = o[0] - o[1]/2
ed = o[0] + o[1]/2
o[0] = st
o[1] = ed
b = sorted(a,key=lambda aa:aa[0])
a = None
c = []
r = 2
for i in xr:
if i < n-1:
if b[i+1][0] - b[i][1] == l:
... | Python | [
"other"
] | 819 | 388 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 550 |
56ea328f84b2930656ff5eb9b8fda8e0 | Palo Alto is an unusual city because it is an endless coordinate line. It is also known for the office of Lyft Level 5.Lyft has become so popular so that it is now used by all m taxi drivers in the city, who every day transport the rest of the city residents — n riders.Each resident (including taxi drivers) of Palo-Alt... | ['implementation', 'sortings'] | R=lambda:map(int,input().split())
n,m=R()
a=[[],[]]
for x,y in zip(R(),R()):a[y]+=[x]
r,d=a
s=[0]*m
i=0
for x in r:
while i<m-1and 2*x>d[i]+d[i+1]:i+=1
s[i]+=1
print(*s) | Python | [
"other"
] | 1,127 | 171 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,421 |
90be8c6cf8f2cd626d41d2b0be2dfed3 | Dreamoon likes coloring cells very much.There is a row of n cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 1 to n.You are given an integer m and m integers l_1, l_2, \ldots, l_m (1 \le l_i \le n)Dreamoon will perform m operations.In i-th operation, Dreamoon will choose a number... | ['constructive algorithms', 'greedy'] | n, m = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
if sum(d) < n:
print(-1)
exit()
# d = [(dd[i], i) for i in range(m)]
# d.sort()
pos = [0]*m
ind = n
for i in range(m-1, -1, -1):
ind = min(ind - 1, n - d[i])
pos[i] = ind
if pos[0] < 0:
print(-1)
exit()
lind = -1
for... | Python | [
"other"
] | 841 | 458 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 326 |
c0068963008fdf04ba4261d32f4162a2 | Madoka has become too lazy to write a legend, so let's go straight to the formal description of the problem.An array of integers a_1, a_2, \ldots, a_n is called a hill if it is not empty and there is an index i in it, for which the following is true: a_1 < a_2 < \ldots < a_i > a_{i + 1} > a_{i + 2} > ... | ['dp', 'greedy'] | def solve(a):
n = len(a)
ans, dp1, dp2, dp3, dp4 = 0, [0] * N, [0] * N, [0] * N, [0] * N
val, idx = max(a), -1
for i in range(N):
if a[i] == val:
idx = i
break
dp4[N - 1] = -1e18
for i in range(N - 2, idx - 1, -1):
dp4[i] = 1e18
dp4[i] = min(dp4[i], dp4[i + 1] if a[i] > a[i + 1] else 1e18)
... | Python | [
"other"
] | 1,121 | 1,118 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,187 |
ae531bc4b47e5d31fe71b6de1398b95e | We get more and more news about DDoS-attacks of popular websites.Arseny is an admin and he thinks that a website is under a DDoS-attack if the total number of requests for a some period of time exceeds 100 \cdot t, where t — the number of seconds in this time segment. Arseny knows statistics on the number of requests p... | ['*special', 'brute force'] | def find_d(A):
n = max(A) + 1
A = [None] + A
ind = [[] for _ in range(n)]
for i in range(len(A)):
if not A[i]:
continue
if len(ind[A[i]]) == 2:
ind[A[i]][1] = i
else:
ind[A[i]].append(i)
min_ind = len(A)
d = 0
for l in ind:
... | Python | [
"other"
] | 691 | 1,137 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 4,454 |
c761bb69cf1b5a3dbe38d9f5c46e9007 | As Sherlock Holmes was investigating a crime, he identified n suspects. He knows for sure that exactly one of them committed the crime. To find out which one did it, the detective lines up the suspects and numbered them from 1 to n. After that, he asked each one: "Which one committed the crime?". Suspect number i answe... | ['data structures', 'constructive algorithms', 'implementation'] | from collections import defaultdict
n, m = map(int, input().split())
a = []
for i in range(n):
a.append(int(input()))
d = defaultdict(int)
pos, neg = 0, 0
for x in a:
d[x] += 1
if x > 0:
pos += 1
else:
neg += 1
possible = [False] * n
for i in range(1, n + 1):
t = d[i] + neg - d[-i... | Python | [
"other"
] | 667 | 752 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 2,415 |
3a4b815bcc0983bca9789ec8e76e0ea0 | Your program fails again. This time it gets "Wrong answer on test 233".This is the easier version of the problem. In this version 1 \le n \le 2000. You can hack this problem only if you solve and lock both problems.The problem is about a test containing n one-choice-questions. Each of the questions contains k options, ... | ['dp'] | def main():
M=998244353
n,k,*h=map(int,open(0).read().split())
m=sum(i!=j for i,j in zip(h,h[1:]+h[:1]))
f=[0]*(m+1)
f[0]=b=1
for i in range(1,m+1):f[i]=b=b*i%M
inv=[0]*(m+1)
inv[m]=b=pow(f[m],M-2,M)
for i in range(m,0,-1):inv[i-1]=b=b*i%M
comb=lambda n,k:f[n]*inv[n-k]*inv[k]%M
... | Python | [
"other"
] | 1,877 | 443 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,995 |
3fb43df3a6f763f196aa514f305473e2 | One tradition of ACM-ICPC contests is that a team gets a balloon for every solved problem. We assume that the submission time doesn't matter and teams are sorted only by the number of balloons they have. It means that one's place is equal to the number of teams with more balloons, increased by 1. For example, if there ... | ['data structures', 'greedy'] | import heapq
class Heap(object):
""" A neat min-heap wrapper which allows storing items by priority
and get the lowest item out first (pop()).
Also implements the iterator-methods, so can be used in a for
loop, which will loop through all items in increasing priority order.
Remember ... | Python | [
"other"
] | 1,294 | 3,216 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 4,216 |
f995d575f86eee139c710cb0fe955682 | You are given 2 arrays a and b, both of size n. You can swap two elements in b at most once (or leave it as it is), and you are required to minimize the value \sum_{i}|a_{i}-b_{i}|.Find the minimum possible value of this sum. | ['brute force', 'constructive algorithms', 'data structures', 'sortings'] | import io,os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def main(t):
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
base = sum( [abs(a[i]-b[i]) for i in range(n)] )
ans = base
# print(base,"*")
greater = []
smaller = []
... | Python | [
"other"
] | 261 | 1,356 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 2,613 |
27b73a87fc30c77abb55784e2e1fde38 | A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are r... | ['constructive algorithms'] | n = int(input())
for i in range(n):
e = int(input())
for j in range(e):
print("()" * j + "(" * (e - j) + ")" * (e - j)) | Python | [
"other"
] | 558 | 139 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 436 |
040171969b25ad9be015d95586890cf0 | Archeologists have found a secret pass in the dungeon of one of the pyramids of Cycleland. To enter the treasury they have to open an unusual lock on the door. The lock consists of n words, each consisting of some hieroglyphs. The wall near the lock has a round switch. Each rotation of this switch changes the hieroglyp... | ['data structures', 'sortings', 'greedy', 'brute force'] | #!/usr/bin/env python
# coding: utf-8
if __name__ == '__main__':
import sys
f = sys.stdin
if False:
import StringIO
f = StringIO.StringIO("""4 3
2 3 2
1 1
3 2 3 1
4 2 3 1 2""")
f = StringIO.StringIO("""2 5
2 4 2
2 4 2""")
f = StringIO.StringIO("""4 4
1 2
1 3
1 4
1 2""")
... | Python | [
"other"
] | 1,061 | 2,447 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 2,601 |
78d013b01497053b8e321fe7b6ce3760 | Pupils decided to go to amusement park. Some of them were with parents. In total, n people came to the park and they all want to get to the most extreme attraction and roll on it exactly once.Tickets for group of x people are sold on the attraction, there should be at least one adult in each group (it is possible that ... | ['*special', 'ternary search', 'brute force'] | values = map(int, raw_input().split())
n = values[0]
c1 = values[1]
c2 = values[2]
str = raw_input()
batyas = 0
wegols = 0
for i in str:
if (i == '0'): wegols+=1
else: batyas+=1
ans = 0
for groups in range(1, batyas+1):
cost = groups * c1
d1 = (batyas + wegols) / groups
c = (batyas + wegols) % group... | Python | [
"other"
] | 806 | 479 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 4,895 |
0048623eeb27c6f7c6900d8b6e620f19 | There are n people who want to participate in a boat competition. The weight of the i-th participant is w_i. Only teams consisting of two people can participate in this competition. As an organizer, you think that it's fair to allow only teams with the same total weight.So, if there are k teams (a_1, b_1), (a_2, b_2), ... | ['two pointers', 'greedy', 'brute force'] | t=int(input())
for j in range(t):
n=int(input())
arr=list(map(int,input().split()))
ans=0
for i in range(2,2*n+1):
c=[0]*101
cur=0
for x in arr:
if i>x and c[i-x]!=0:
c[i-x]-=1
cur+=1
else:
c[x]+=1
an... | Python | [
"other"
] | 896 | 349 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 3,470 |
894f407ca706788b13571878da8570f5 | In some country live wizards. They love to ride trolleybuses.A city in this country has a trolleybus depot with n trolleybuses. Every day the trolleybuses leave the depot, one by one and go to the final station. The final station is at a distance of d meters from the depot. We know for the i-th trolleybus that it leave... | ['implementation'] | n,a,d=map(int,input().split())
p=[0]*n
for i in range(n):
t,v=map(int,input().split())
x=v/a
y=(2*d/a) ** 0.5
p[i]=t+y if y<x else t+d/v+x/2
p[i]=max(p[i-1],p[i])
print('\n'.join(map(str,p))) | Python | [
"other"
] | 1,597 | 211 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,121 |
31e58e00ae708df90251d7b751272771 | Vasya plays the Need For Brake. He plays because he was presented with a new computer wheel for birthday! Now he is sure that he will win the first place in the championship in his favourite racing computer game! n racers take part in the championship, which consists of a number of races. After each race racers are arr... | ['binary search', 'sortings', 'greedy'] | class Racer:
def __init__(self, name, points):
self.name = name
self.points = points
def __str__(self):
return '%s %d' % (self.name, self.points)
n = int(input())
best = n * [ None ]
worst = n * [ None ]
for i in range(n):
name, points = input().split()
points = int(points)
... | Python | [
"other"
] | 991 | 2,354 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 2,740 |
44619ba06ec0dc410ef598ea45a76271 | Mike decided to teach programming to children in an elementary school. He knows that it is not an easy task to interest children in that age to code. That is why he decided to give each child two sweets.Mike has n sweets with sizes a_1, a_2, \ldots, a_n. All his sweets have different sizes. That is, there is no such pa... | ['implementation', 'brute force'] | from itertools import combinations
n = int(input())
sizes = list(map(int,input().split(" ")))
targets = list(combinations(sizes,2))
freq = {}
for c in targets:
if sum(c) in freq:
freq[sum(c)].append(c)
else:
freq[sum(c)] = [c]
res = 1
for key,value in freq.items():
res = max(len(value),res... | Python | [
"other"
] | 1,225 | 334 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 790 |
fcd88c7b64da4b839cda4273d928429d | Each day in Berland consists of n hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence a_1, a_2, \dots, a_n (each a_i is either 0 or 1), where a_i=0 if Polycarp works during the i-th hour of the day and a_i=1 if Polycarp rests during the i-th hour of the day.Days go ... | ['implementation'] | # n = input()
# l = ''.join(input().split())
# l += l
# l = l.split('0')
# print(max(len(i) for i in l))
n = int(input())
a = ''.join(input().split())
a += a
a = a.split('0')
print(max(len(i) for i in a))
| Python | [
"other"
] | 593 | 205 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 992 |
63b20ab2993fddf2cc469c4c4e8027df | The new "Die Hard" movie has just been released! There are n people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the... | ['implementation', 'greedy'] | #!/usr/bin/env pypy
from __future__ import division, print_function
from collections import defaultdict, Counter, deque
from future_builtins import ascii, filter, hex, map, oct, zip
from itertools import imap as map, izip as zip, permutations, combinations, combinations_with_replacement
from __builtin__ import xrange a... | Python | [
"other"
] | 377 | 4,535 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 3,872 |
bb521123f9863345d75cfe10677ab344 | We guessed a permutation p consisting of n integers. The permutation of length n is the array of length n where each element from 1 to n appears exactly once. This permutation is a secret for you.For each position r from 2 to n we chose some other index l (l < r) and gave you the segment p_l, p_{l + 1}, \dots, p_r i... | ['greedy', 'constructive algorithms', 'implementation', 'data structures', 'brute force'] | import sys
import collections
import threading
import copy
def check(itr, sets):
d={}
def dmap(x):
return d[x]
for i in range(len(itr)):
d[itr[i]] = i
for perm in sets:
tmp = sorted(list( map(dmap, perm) ))
if len(tmp) != tmp[-1] - tmp[0] + 1:
return Fals... | Python | [
"other"
] | 1,134 | 1,504 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,399 |
02932480c858536191eb24f4ea923029 | This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city ai.Today the bus has completed m trips, each time bringing n participants. The participants were then aligned in on... | ['data structures'] | def main():
_, k, m = [int(x) for x in input().split()]
a = []
last = ("-1", 0)
a.append(last)
for ai in input().split():
if last[0] == ai:
last = (ai, last[1]+1)
a[-1] = last
else:
last = (ai, 1)
a.append(last)
if last[1] == k... | Python | [
"other"
] | 977 | 1,033 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 3,126 |
cfccf06c4d0de89bf0978dc6512265c4 | You are given an array s consisting of n integers.You have to find any array t of length k such that you can cut out maximum number of copies of array t from array s.Cutting out the copy of t means that for each element t_i of array t you have to find t_i in s and remove it from s. If for some t_i you cannot find such ... | ['binary search', 'sortings'] | n,k=map(int,input().split(' '))
a=list(map(int,input().split(' ')))
d={}
for i in a:
if i in d.keys():
d[i]+=1
else:
d[i]=1
s=[]
for i,j in d.items():
s.append([j,i])
s.sort(reverse=True)
b=[]
for i in range(len(s)):
j=1
while s[i][0]//j!=0:
b.append([s[i][0]//j,s[i][1]])
... | Python | [
"other"
] | 1,374 | 397 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 180 |
facd9cd4fc1e53f50a1e6f947d78e942 | n soldiers stand in a circle. For each soldier his height ai is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |ai - aj| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance u... | ['implementation'] | import math
n=int(input())
l=list(map(int,input().split()))
d=0
diff=abs(l[n-1]-l[0])
o1,o2=n,1
for i in range(n-1):
d=abs(l[i+1]-l[i])
#print(d,diff)
if d<diff:
diff=d
o1=i+1
o2=i+2
print(o1,o2) | Python | [
"other"
] | 324 | 231 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 3,584 |
5802f9c010efd1cdcee2fbbb4039a4cb | So you decided to hold a contest on Codeforces. You prepared the problems: statements, solutions, checkers, validators, tests... Suddenly, your coordinator asks you to change all your tests to multiple testcases in the easiest problem!Initially, each test in that problem is just an array. The maximum size of an array i... | ['greedy', 'constructive algorithms', 'two pointers', 'sortings', 'data structures', 'binary search'] | n, k = map(int, input().split())
mmm = list(map(int, input().split()))
ccc = [0] + list(map(int, input().split()))
mmm.sort(reverse=True)
ans = [[]]
for m in mmm:
ai = 0
c = ccc[m]
if c <= len(ans[-1]):
ans.append([m])
continue
l = -1
r = len(ans) - 1
while l + 1 < r:
k... | Python | [
"other"
] | 1,268 | 529 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 3,676 |
4ee194d8dc1d25eb8b186603ee71125e | You are given a line of n colored squares in a row, numbered from 1 to n from left to right. The i-th square initially has the color c_i.Let's say, that two squares i and j belong to the same connected component if c_i = c_j, and c_i = c_k for all k satisfying i < k < j. In other words, all squares on the segment... | ['dp'] | n = int(raw_input())
cs = map(int, raw_input().split(' '))
# remove consecutive dupes
ds = []
for c in cs:
if len(ds)==0:
ds.append(c)
elif ds[-1] != c:
ds.append(c)
cs = ds
n = len(cs)
def memoize(f):
table = {}
def g(*args):
if args in table:
return table[args]
else:
value = table[args] = f(*args)... | Python | [
"other"
] | 942 | 1,601 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 2,973 |
71e6ceb75852f4cd437bbf0478e37dc4 | There is a classroom with two rows of computers. There are n computers in each row and each computer has its own grade. Computers in the first row has grades a_1, a_2, \dots, a_n and in the second row — b_1, b_2, \dots, b_n.Initially, all pairs of neighboring computers in each row are connected by wire (pairs (i, i + 1... | ['brute force', 'data structures', 'implementation'] | def find(A,N,k,c):
num = float('inf')
for i in range(c,N-c):
num = min(num,abs(A[i]-k))
return num
for p in range(int(input())):
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
# if p==393:
# print("|".join([str(x) for x in A])+"|"+"|".join([str(x) for x in B]))
ans = ... | Python | [
"other"
] | 1,075 | 1,008 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 957 |
b1f78130d102aa5f425e95f4b5b3a9fb | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.Vasya is watching a recorded football match now and makes notes of all the fouls that ... | ['implementation'] | h = input()
a = input()
n = int(input())
d = dict()
for i in range(n):
arr = input().split()
mark = (h if arr[1] == 'h' else a) + ' ' + arr[2]
if mark not in d:
d[mark] = 0
if d[mark] < 2:
d[mark] += 1 if arr[3] == 'y' else 2
if d[mark] >= 2:
print(mark, arr[0]) | Python | [
"other"
] | 565 | 314 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 3,134 |
13fbcd245965ff6d1bf08915c4d2a2d3 | There are n segments [l_i, r_i] for 1 \le i \le n. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.To optimize testing ... | ['sortings'] | def get():
return list(map(int, input().split(' ')))
def d():
n = int(input())
t = [];
for i in range(n):
t.append(get() + [i])
t.sort();
i = 0
r = t[0][1]
ans = ["2"]*n
while(i < n and t[i][0] <= r):
ans[t[i][2]] = "1"
r = max(r, t[i][1])
i+=1
if "2" in ans:
print(" ".join(ans)... | Python | [
"other"
] | 374 | 380 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 4,137 |
c8e71b942fac5c99c041ce032fbb9e4c | You are given a permutation, p_1, p_2, \ldots, p_n.Imagine that some positions of the permutation contain bombs, such that there exists at least one position without a bomb.For some fixed configuration of bombs, consider the following process. Initially, there is an empty set, A.For each i from 1 to n: Add p_i to A. If... | ['data structures', 'two pointers'] | import sys
input = sys.stdin.readline
N=int(input())
P=list(map(int,input().split()))
Q=list(map(int,input().split()))
seg_el=1<<(N.bit_length()) # Segment treeの台の要素数
SEG=[0]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化
LAZY=[0]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化
def indexes(L,R... | Python | [
"other"
] | 1,000 | 2,681 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 3,224 |
874e22d4fd8e35f7e0eade2b469ee5dc | You are given a number k and a string s of length n, consisting of the characters '.' and '*'. You want to replace some of the '*' characters with 'x' characters so that the following conditions are met: The first character '*' in the original string should be replaced with 'x'; The last character '*' in the original s... | ['greedy', 'implementation'] | import sys
lines = list(map(str.strip, sys.stdin.readlines()))
def replacefirstlast(s):
result = 0
for i in range(len(s)):
if s[i] == '*':
s[i] = 'x'
result+=1
break
for i in range(len(s)-1,-1,-1):
if s[i] =='*':
s[i] = 'x'
... | Python | [
"other"
] | 1,260 | 861 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 2,283 |
2deed55e860bd69ff0ba3973a1d73cac | You are given n integers a_1, a_2, \ldots, a_n. Find the maximum value of max(a_l, a_{l + 1}, \ldots, a_r) \cdot min(a_l, a_{l + 1}, \ldots, a_r) over all pairs (l, r) of integers for which 1 \le l < r \le n. | ['greedy'] | n=int(input())
for i in range(n):
j=int(input())
res=0
a=list(map(int,input().split()))
for i in range(j-1):
if((a[i]*a[i+1])>res):
res=a[i]*a[i+1]
else:
pass
print(res)
| Python | [
"other"
] | 241 | 233 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,824 |
097e35b5e9c96259c54887158ebff544 | One day Jeff got hold of an integer sequence a1, a2, ..., an of length n. The boy immediately decided to analyze the sequence. For that, he needs to find all values of x, for which these conditions hold: x occurs in sequence a. Consider all positions of numbers x in the sequence a (such i, that ai = x). These numbers, ... | ['implementation', 'sortings'] | import sys
n = int(sys.stdin.readline())
a=list(map(int,sys.stdin.readline().split()))
from collections import defaultdict
d=defaultdict(list)
for i in range(len(a)):
d[a[i]]+=[i]
for v in d.values():
v.sort()
ans=[]
c=0
for k,v in d.items():
if len(v)>1:
c=v[1]-v[0]
flag=0
for j in range(1... | Python | [
"other"
] | 446 | 553 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 2,874 |
3270260030fc56dda3e375af4dad9330 | Lunar New Year is approaching, and you bought a matrix with lots of "crosses".This matrix M of size n \times n contains only 'X' and '.' (without quotes). The element in the i-th row and the j-th column (i, j) is defined as M(i, j), where 1 \leq i, j \leq n. We define a cross appearing in the i-th row and the j-th colu... | ['implementation'] | n = int(input())
matrix_array = []
for i in range(0, n):
next = input()
matrix_array.append(next)
matrix_array1 = [[0]*n for _ in range(n)]
for i in range(0, n):
for j in range(0, n):
matrix_array1[i][j] = matrix_array[i][j]
count = 0
for i in range(1, n-1):
for j in range(1, n-1):
if ... | Python | [
"other"
] | 786 | 534 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,414 |
165467dd842b47bc2d932b04e85ae8d7 | By the age of three Smart Beaver mastered all arithmetic operations and got this summer homework from the amazed teacher:You are given a sequence of integers a1, a2, ..., an. Your task is to perform on it m consecutive operations of the following type: For given numbers xi and vi assign value vi to element axi. For giv... | ['data structures', 'brute force'] |
n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(m):
t, l, r = map(int, input().split())
if t == 1:
a[l-1] = r
else:
s = 0
fiba = fibb = 1
for i in range(l-1, r):
s += fiba * a[i]
fiba, fibb = fibb, fiba + fibb
... | Python | [
"other"
] | 635 | 347 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 4,051 |
b4a4448af5b61fe5a8467a8d0e12fba8 | This is the hard version of the problem. The only difference is that in this version n \leq 200000. You can make hacks only if both versions of the problem are solved.There are n potions in a line, with potion 1 on the far left and potion n on the far right. Each potion will increase your health by a_i when drunk. a_i ... | ['data structures', 'greedy'] | from heapq import *
n = int(input())
a = [int(x) for x in input().split()]
h = 0
hq = []
ans = 0
for x in a:
if x >= 0:
h += x
ans += 1
elif h + x >= 0:
h += x
heappush(hq, x)
ans += 1
elif hq and hq[0] < x:
h += -heapreplace(hq, x) + x
#print(h, ans, hq)
... | Python | [
"other"
] | 687 | 332 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 2,405 |
19d9a438bf6353638b08252b030c407b | Appleman has a very big sheet of paper. This sheet has a form of rectangle with dimensions 1 × n. Your task is help Appleman with folding of such a sheet. Actually, you need to perform q queries. Each query will have one of the following types: Fold the sheet of paper at position pi. After this query the leftmost part ... | ['data structures', 'implementation'] | from itertools import starmap
def main():
n, q = map(int, input().split())
a = list(range(n + 1))
flipped = False
start = 0
end = n
for _ in range(q):
cmd, *args = map(int, input().split())
if cmd == 1:
p = args[0]
if p > end-start-p:
... | Python | [
"other"
] | 861 | 993 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 2,652 |
551e66a4b3da71682652d84313adb8ab | As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they've already made n snowballs with radii equal to r1, r2, ..., rn. To make a snowman, one needs any thr... | ['data structures', 'binary search', 'greedy'] | import sys
d = {}
n= int( sys.stdin.readline().strip('\n\r ') )
nn=0
spare=''
first=True
turnon=False
stoks=['']
while nn<n:
if len(stoks)==1:
stoks = (stoks[0] + sys.stdin.read(2048)).strip('\n\r').split(' ')
s = stoks.pop(0)
if len(s)==0: continue
j = int(s)
if j in d: d[j] += 1
else: d[j] = 1
nn +... | Python | [
"other"
] | 580 | 1,392 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 2,576 |
c37604d5d833a567ff284d7ce5eda059 | Polycarp doesn't like integers that are divisible by 3 or end with the digit 3 in their decimal representation. Integers that meet both conditions are disliked by Polycarp, too.Polycarp starts to write out the positive (greater than 0) integers which he likes: 1, 2, 4, 5, 7, 8, 10, 11, 14, 16, \dots. Output the k-th el... | ['implementation'] | t=int(input())
for i in range(t):
k=int(input())
counter =0
a=0
while(counter <k):
a+=1
if(a%3!=0) and(a%10!=3):
counter+=1
print(a)
| Python | [
"other"
] | 414 | 196 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,177 |
fc29e8c1a9117c1dd307131d852b6088 | It can be shown that any positive integer x can be uniquely represented as x = 1 + 2 + 4 + ... + 2k - 1 + r, where k and r are integers, k ≥ 0, 0 < r ≤ 2k. Let's call that representation prairie partition of x.For example, the prairie partitions of 12, 17, 7 and 1 are: 12 = 1 + 2 + 4 + 5,17 = 1 + 2 + 4 + 8 + 2,7 = 1... | ['binary search', 'greedy'] | from collections import Counter
from math import log2, ceil
MAX = ceil(log2(10 ** 12))
def can():
seqs_cp = Counter(seqs)
for num in set(nums):
cnt = nums[num]
while cnt != 0 and num < 2 ** 63:
dif = min(cnt, seqs_cp[num])
cnt -= dif
seqs_cp[num] -= dif
... | Python | [
"other"
] | 677 | 1,331 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 692 |
c9155ff3aca437eec3c4e9cf95a2d62c | All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring supermarket. The goods in the supermarket have unique integer ids. Also, for every integer there is a product with id equal to this integer. Fedor has n discount coupons, the i-th of them can be used with products with id... | ['data structures', 'binary search', 'sortings', 'greedy'] | from heapq import heappop, heappush
n, k = [int(x) for x in input().split()]
cs = []
for i in range(n):
l, r = [int(x) for x in input().split()]
cs.append((l, r, i+1))
cs.sort()
h = []
for i in range(k-1):
heappush(h, [cs[i][1], cs[i][2]])
lcs = h[:]
l = -1
push_i = k-1
for i in range(k-1, n):
heappus... | Python | [
"other"
] | 700 | 774 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 547 |
39f5e934bf293053246bd3faa8061c3b | Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help. Innokentiy decides that new password should satisfy the following conditions: the length of the password must be equal to n, the password should consist only of... | ['implementation', '*special'] | n,k=map(int,input().split())
a=[]
b='a'
for i in range(k):
a.append(chr(ord(b)+i))
j=0
for i in range(n):
print(a[j],end='')
j=j+1
if j==len(a):
j=0
| Python | [
"other"
] | 581 | 182 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 4,745 |
End of preview. Expand in Data Studio
README.md exists but content is empty.
- Downloads last month
- 8