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 listlengths 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
55f0ecc597e6e40256a14debcad1b878 | The only difference between the two versions is that this version asks the maximal possible answer.Homer likes arrays a lot. Today he is painting an array a_1, a_2, \dots, a_n with two kinds of colors, white and black. A painting assignment for a_1, a_2, \dots, a_n is described by an array b_1, b_2, \dots, b_n that b_i... | ['constructive algorithms', 'data structures', 'dp', 'greedy', 'implementation'] | import sys
input = lambda: sys.stdin.readline().rstrip("\n\r")
def solve():
n = int(input())
a = [0] + list(map(int, input().split()))
pos = [n + 1] * (n + 1)
nxt = [None] * (n + 1)
for i in range(n, -1, -1):
nxt[i] = pos[a[i]]
pos[a[i]] = i
ans = 0
black... | Python | [
"other"
] | 1,490 | 918 | 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,779 |
f92757d0369327f63185aca802616ad7 | You have an n × m rectangle table, its cells are not initially painted. Your task is to paint all cells of the table. The resulting picture should be a tiling of the table with squares. More formally: each cell must be painted some color (the colors are marked by uppercase Latin letters); we will assume that two cells ... | ['constructive algorithms', 'greedy'] | n, m = map(int, raw_input().split())
a = [['' for j in xrange(m)] for i in xrange(n)]
b = [[0 for j in xrange(m+1)] for i in xrange(n+1)]
alpha = 'ABCDEFGH'
for i in xrange(n):
for j in xrange(m):
if a[i][j]:
continue
c, d = 0, 1
while 1:
if b[i][j] & d:
... | Python | [
"other"
] | 556 | 1,039 | 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
} | 176 |
5c63f91eb955cb6c3172cb7c8f78976c | Sereja loves integer sequences very much. He especially likes stairs.Sequence a1, a2, ..., a|a| (|a| is the length of the sequence) is stairs if there is such index i (1 ≤ i ≤ |a|), that the following condition is met: a1 < a2 < ... < ai - 1 < ai > ai + 1 > ... > a|a| - 1 > a|a|.For example, seq... | ['implementation', 'sortings', 'greedy'] | n =input()
arr = map(int,raw_input().split())
b=[0]*10000
for i in arr:
b[i]+=1
m = max(arr)
ans=[]
for i in range(10000):
if i<m and b[i]!=0:
ans.append(i)
b[i]-=1
ans.append(m)
for i in range(10000,-1,-1):
if i<m and b[i]!=0:
ans.append(i)
b[i]-=1
print len(ans)
for i in an... | Python | [
"other"
] | 551 | 336 | 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,240 |
3fe51d644621962fe41c32a2d90c7f94 | You are given an array a consisting of n positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by 2) or determine that there is no such subset.Both the given array and required subset may contain equal values. | ['dp', 'implementation', 'greedy', 'brute force'] | #!/bin/python3
t = int(input())
while t > 0:
n = int(input())
array = list(map(int, input().split()))
if n == 1:
# 1 is 00000001 in binary , and 2 is 00000010
# for future reference 1 bitwise AND 2 is false
# that's a fancy way to say array[0] == 1
if array[0] & 1:
... | Python | [
"other"
] | 276 | 746 | 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,290 |
d3c8c1e32dcf4286bef19e9f2b79c8bd | Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter — its complexity. The complexity of the i-th chore equals hi.As Petya is older, he wants to take the chores with complexity larger t... | ['sortings'] | n, a, b = [int(s) for s in input().split(' ')]
h = [int(x) for x in input().split(' ')]
h.sort()
print(h[b] - h[b - 1]) | Python | [
"other"
] | 657 | 119 | 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,108 |
a30b5ff6855dcbad142f6bcc282601a0 | Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some value of d meters, and a throw is worth 3 points if the distance is larger tha... | ['two pointers', 'implementation', 'sortings', 'data structures', 'binary search', 'brute force'] | R=lambda:(input(),sorted(map(int,raw_input().split())))
n,a=R()
m,b=R()
x,y=n*3,m*3
t=(x-y,x,y)
i,j=0,0
for v in sorted(a+b)+[1<<50]:
while i<n and v>a[i]:i+=1;x-=1
while j<m and v>b[j]:j+=1;y-=1
t=max(t,(x-y,x,y))
print '%d:%d'%t[1:]
| Python | [
"other"
] | 589 | 248 | 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,878 |
b87a90f2b4822e59d66b06886a5facad | This is the easy version of the problem. The difference is that in this version the array can not contain zeros. You can make hacks only if both versions of the problem are solved.You are given an array [a_1, a_2, \ldots a_n] consisting of integers -1 and 1. You have to build a partition of this array into the set of s... | ['constructive algorithms', 'dp', 'greedy'] | def alternating_sum(n, a):
alter_sum = 0
for i in range(n):
if i % 2 != 0:
alter_sum -= a[i]
else:
alter_sum += a[i]
return alter_sum
def zero_partition(n, a):
if n % 2 != 0:
return -1
if alternating_sum(n, a) == 0:
return [... | Python | [
"other"
] | 1,480 | 924 | 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,663 |
bee33afb70e4c3e062ec7980b44cc0dd | Let n be a positive integer. Let a, b, c be nonnegative integers such that a + b + c = n.Alice and Bob are gonna play rock-paper-scissors n times. Alice knows the sequences of hands that Bob will play. However, Alice has to play rock a times, paper b times, and scissors c times.Alice wins if she beats Bob in at least \... | ['dp', 'constructive algorithms', 'greedy'] | def ans(n):
if(n%2==0):
return int(n/2)
else:
if(int(n//2)%2==0):
return int(n//2)+1
else:
return int(n//2)+1
t=int(input())
for i in range(t):
n=int(input())
abc=list(map(int,input().split()))
op=input()
r=0
p=0
s=0
for j in range(n):... | Python | [
"other"
] | 827 | 1,453 | 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
} | 908 |
082eec813f870357dbe3c5abec6a2b52 | This is the harder version of the problem. In this version, 1 \le n, m \le 2\cdot10^5. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems.You are given a sequence of integers a=[a_1,a_2,\dots,a_n] of length n. Its subsequence is obtained by removing zero o... | ['greedy', 'constructive algorithms', 'sortings', 'data structures', 'binary search'] | # Binary Indexed Tree (Fenwick Tree)
class BIT():
"""一点加算、区間取得クエリをそれぞれO(logN)で答える
add: i番目にvalを加える
get_sum: 区間[l, r)の和を求める
i, l, rは0-indexed
"""
def __init__(self, n):
self.n = n
self.bit = [0] * (n + 1)
def _sum(self, i):
s = 0
while i > 0:
s += ... | Python | [
"other"
] | 2,426 | 1,511 | 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,737 |
88d54818fd8bab2f5d0bd8d95ec860db | You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined . You have to perform exactly k1 operations on array A and exactly k2 operations on array B. In one operation, you have to choose one element of the array and increase or decrease it by 1.Output the minimum possible valu... | ['data structures', 'sortings', 'greedy'] | n, k1, k2 = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
k = k1+k2
C = [abs(x - y) for x, y in zip(A, B)]
E = sum([x**2 for x in C])
if k == 0:
print(E)
else:
while E > 0 and k>0:
C.sort(reverse=True)
C[0] -= 1
k -= 1
E = sum([x**2 for x in C])
if k%2 ... | Python | [
"other"
] | 411 | 363 | 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,977 |
d174982b64cc9e8d8a0f4b8646f1157c | You are given a binary matrix A of size n \times n. Rows are numbered from top to bottom from 1 to n, columns are numbered from left to right from 1 to n. The element located at the intersection of row i and column j is called A_{ij}. Consider a set of 4 operations: Cyclically shift all rows up. The row with index i wi... | ['brute force', 'constructive algorithms', 'greedy', 'implementation'] | #from sys import stdin
#input = stdin.readline
#// - remember to add .strip() when input is a string
t = int(input())
for _ in range(t):
input()
n = int(input())
one_count = 0
grid = []
dp = []
for i in range(n):
row = list(input().strip())
row = list(map(int,row))
... | Python | [
"other"
] | 2,168 | 875 | 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,612 |
19564d66e0de78780f4a61c69f2c8e27 | Consider the decimal presentation of an integer. Let's call a number d-magic if digit d appears in decimal presentation of the number on even positions and nowhere else.For example, the numbers 1727374, 17, 1 are 7-magic but 77, 7, 123, 34, 71 are not 7-magic. On the other hand the number 7 is 0-magic, 123 is 2-magic, ... | ['dp'] | #!/usr/bin/env python3
from __future__ import division, print_function
def counter(a, m, d):
modulo = 1000000007
res = [0, ] * (2*m)
res[0] = 1
shift = 1
for pos in range(len(a), 0, -1):
ptype = pos % 2
cur = int(a[pos-1])
tres = [0, ] * (2*m)
for i in range(10):
... | Python | [
"other"
] | 576 | 2,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
} | 1,334 |
8a4a46710104de78bdf3b9d5462f12bf | One not particularly beautiful evening Valera got very bored. To amuse himself a little bit, he found the following game.He took a checkered white square piece of paper, consisting of n × n cells. After that, he started to paint the white cells black one after the other. In total he painted m different cells on the pie... | ['implementation', 'brute force'] | read = lambda: map(int, input().split())
xy = [[0]*1002 for i in range(1002)]
n, m = read()
for i in range(m):
x, y = read()
for j in range(x-1, x+2):
for k in range(y-1, y+2):
xy[j][k] += 1
if xy[j][k] is 9:
print(i+1)
exit()
print(-1) | Python | [
"other"
] | 792 | 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,272 |
63c2142461c93ae4c962eac1ecb5b192 | Given three distinct integers a, b, and c, find the medium number between all of them.The medium number is the number that is neither the minimum nor the maximum of the given three numbers. For example, the median of 5,2,6 is 5, since the minimum is 2 and the maximum is 6. | ['implementation', 'sortings'] | a=int(input())
for i in range(a):
b=list(map(int,input().split()))
c=sorted(b)
print(c[1]) | Python | [
"other"
] | 315 | 106 | 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,438 |
b0561fee6236f0720f737ca41e20e382 | Nick had received an awesome array of integers a=[a_1, a_2, \dots, a_n] as a gift for his 5 birthday from his mother. He was already going to explore its various properties but after unpacking he was disappointed a lot because the product a_1 \cdot a_2 \cdot \dots a_n of its elements seemed to him not large enough.He w... | ['implementation', 'greedy'] | n = int(input())
if(n>0):
arr = [int(i) for i in input().strip().split(" ")]
maxMin = 0
for i in range(n):
if(arr[i] != -1):
maxMin = i
break
for i in range(n):
if(arr[i]>=0):
arr[i] = (-arr[i]-1)
if(arr[i]<arr[maxMin] and arr[i] != -1):
maxMin = i
if(len(arr)%2 != 0):
if(arr[maxMin] != -1... | Python | [
"other"
] | 1,334 | 433 | 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,654 |
6422a70e686c34b4b9b6b5797712998e | The research center Q has developed a new multi-core processor. The processor consists of n cores and has k cells of cache memory. Consider the work of this processor.At each cycle each core of the processor gets one instruction: either do nothing, or the number of the memory cell (the core will write an information to... | ['implementation'] | n, m, k = map(int, input().split())
cores = [1 for i in range(n)]
cells = [1 for i in range(k)]
info = []
blockings = [0 for i in range(n)]
for i in range(n):
k = list(map(int, input().split()))
for j in range(len(k)):
k[j] -= 1
info.append(k)
for i in range(m):
for j in range(n):
if cor... | Python | [
"other"
] | 1,401 | 860 | 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,626 |
e4381bd9f22c0e49525cc05cc5cd2399 | Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin.The world can be represented by the first quadrant of a plane and the wall is built along the identity line (i.... | ['implementation'] | def coincount(n, S):
f = 0
x = y = 0
i = 0
cross = [0,0,0]
count = 0
while i < n:
cross[0] = cross[1]
cross[1] = cross[2]
cur_m = S[i]
if cur_m == "U":
y += 1
elif cur_m == "R":
x += 1
if x > y: f = -1
elif ... | Python | [
"other"
] | 1,303 | 574 | 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,761 |
ddaf86169a79942cefce8e5b5f3d6118 | You have a garland consisting of n lamps. Each lamp is colored red, green or blue. The color of the i-th lamp is s_i ('R', 'G' and 'B' — colors of lamps in the garland).You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland ... | ['dp', 'constructive algorithms', 'greedy'] | n=int(input())
s0=input()
s=[]
res=0
for i in range(len(s0)):
s.append(s0[i])
s.append('B')
for i in range(len(s)-2):
if(s[i]==s[i+1]):
if(s[i]=='R'):
if (s[i+2] == 'R'):
s[i+1]='G'
if (s[i+2] == 'G'):
s[i+1]='B'
if (s[i+2] == 'B'):
... | Python | [
"other"
] | 858 | 842 | 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
} | 530 |
57df7947bb90328f543b984833a78e64 | Phoenix has n blocks of height h_1, h_2, \dots, h_n, and all h_i don't exceed some value x. He plans to stack all n blocks into m separate towers. The height of a tower is simply the sum of the heights of its blocks. For the towers to look beautiful, no two towers may have a height difference of strictly more than x. P... | ['constructive algorithms', 'data structures', 'greedy'] | from bisect import insort
for _ in range(int(input())):
N,M,X = map(int,input().split())
blocks_heights = map(int,input().split())
if N<M:print("NO");continue
print("YES")
towers = {}
heights = []
smallest_height = 0
smallest_towers = list(range(1,M+1))
s = ""
for block_heigh... | Python | [
"other"
] | 491 | 881 | 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,765 |
5ce39a83d27253f039f0e26045249d99 | You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp.Initially all m lamps are tur... | ['implementation'] | def Fuk(f,n,m):
a = []
d = 0
for j in range(0,m):
s = 0
for i in range(0,n):
s = s + int(f[i][j])
a.append(s)
for i in range(0,n):
c = 0
for j in range(0,m):
if int(a[j])-int(f[i][j]) == 0:
break
else:
... | Python | [
"other"
] | 944 | 538 | 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,720 |
8b007a212a940f09a9306b0c0091e2ad | There are n houses numbered from 1 to n on a circle. For each 1 \leq i \leq n - 1, house i and house i + 1 are neighbours; additionally, house n and house 1 are also neighbours.Initially, m of these n houses are infected by a deadly virus. Each morning, Cirno can choose a house which is uninfected and protect the house... | ['greedy', 'implementation', 'sortings'] | n=int(input())
for i in range(n):
n_,m=list(map(int,input().split()))
arr=sorted(list(map(int,input().split())))
# print(arr)
arr_=[]
arr_.append(n_-arr[-1]+arr[0]-1)
for j in range(m-1):
arr_.append(arr[j+1]-arr[j]-1)
arr_.sort(reverse=True)
# arr_.reve... | Python | [
"other"
] | 920 | 703 | 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
} | 162 |
55962ef2cf88c87873b996dc54cc1bf1 | Petya organized a strange birthday party. He invited n friends and assigned an integer k_i to the i-th of them. Now Petya would like to give a present to each of them. In the nearby shop there are m unique presents available, the j-th present costs c_j dollars (1 \le c_1 \le c_2 \le \ldots \le c_m). It's not allowed to... | ['binary search', 'dp', 'greedy', 'sortings', 'two pointers'] | for _ in range(int(input())):
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
a.sort()
x=0
for i in range(n-1,-1,-1):
if x>=m:
x=m-1
ans+=min(b[a[i]-1],b[x])
x+=1
print(ans) | Python | [
"other"
] | 623 | 306 | 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
} | 876 |
a4647cced2dc6adcb0b8abc24f2d7dce | Dasha has 10^{100} coins. Recently, she found a binary string s of length n and some operations that allows to change this string (she can do each operation any number of times): Replace substring 00 of s by 0 and receive a coins. Replace substring 11 of s by 1 and receive b coins. Remove 0 from any position in s and p... | ['data structures', 'greedy', 'implementation'] | import sys
input = sys.stdin.readline
out = []
ssl = []
t = int(input())
for _ in range(t):
n,a,b,c = map(int,input().split())
s = input().strip()
ssl.append(s)
#if ssl[0] == '1111' and _ == 5099:
# print(n,a,b,c,s)
z = [0]
zc = 0
oc = 0
for ch in s:
... | Python | [
"other"
] | 731 | 3,253 | 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
} | 721 |
ffc96dc83a6fde2e83e07671a8d8ed41 | You are given an array a_1, a_2, \dots, a_n, which is sorted in non-descending order. You decided to perform the following steps to create array b_1, b_2, \dots, b_n: Create an array d consisting of n arbitrary non-negative integers. Set b_i = a_i + d_i for each b_i. Sort the array b in non-descending order. You are gi... | ['binary search', 'greedy', 'two pointers'] | import bisect
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
maxis=[]
minis=[]
for i in a:
v=bisect.bisect_left(b,i)
minis.append(max(0,b[v]-i))
mx=[i for i in b]
for i in range(n-2,-1,-1):
v=bisect.bisect_left(b,a[i+1])
if ... | Python | [
"other"
] | 689 | 450 | 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,289 |
93f6404a23bd2ff867d63db9ddf868ff | Ilya is a very good-natured lion. He likes maths. Of all mathematical objects, his favourite one is matrices. Now he's faced a complicated matrix problem he needs to solve.He's got a square 2n × 2n-sized matrix and 4n integers. You need to arrange all these numbers in the matrix (put each number in a single individual ... | ['constructive algorithms', 'implementation', 'sortings', 'greedy'] | n = input()
ans = 0
l = sorted(map(int, raw_input().split()))[::-1]
pref = [0]*(n+1)
for i in range(n):
pref[i+1] = pref[i] + l[i]
ind = 1
while ind <= n:
ans += pref[ind]
ind <<= 2
print ans | Python | [
"other"
] | 924 | 203 | 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,088 |
c3a7d82f6c3cf8678a1c7c521e0a5f51 | Theater stage is a rectangular field of size n × m. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.You are to place a spotlight on the stage in some good position. The spotlight will project light in one of the four ... | ['dp', 'implementation', 'brute force'] | n, m = map(int, input().split())
plan = [list(map(int, input().split())) for _ in range(n)]
def lc(plan):
cnt = 0
for row in plan:
os = row.count(1)
l = len(row)
if os == 1:
cnt += l - 1
elif os > 1:
ll = row.index(1)
rr = row[::-1].index(1)
... | Python | [
"other"
] | 825 | 421 | 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,636 |
0b9be2f076cfa13cdc76c489bf1ea416 | Let's call a string good if its length is at least 2 and all of its characters are \texttt{A} except for the last character which is \texttt{B}. The good strings are \texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots. Note that \texttt{B} is not a good string.You are given an initially empty string s_1.You can perform the f... | ['constructive algorithms', 'implementation'] | nt = int(input())
for _ in range(nt):
counter = 0
flagb = 0
flaga = 0
s2 = input()
l = len(s2)
for i in range(l-1,-1,-1):
ch = s2[i]
if ch == "B":
flagb = 1
counter += 1
else:
flaga = 1
if i == l-1:
break
if(counter != 0):
counter -= 1
if (flaga == 0 or flagb == 0 or counter != 0... | Python | [
"other"
] | 572 | 358 | 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,305 |
c4d32fcacffaa5d3a4db6dfa376d0324 | You are given a sequence b_1, b_2, \ldots, b_n. Find the lexicographically minimal permutation a_1, a_2, \ldots, a_{2n} such that b_i = \min(a_{2i-1}, a_{2i}), or determine that it is impossible. | ['greedy'] | import heapq
def restorePermutation(n, A):
ans = []
unUsed = set(list(range(1, 2*n + 1)))
for val in A:
if not 1 <= val <= 2*n: return -1
ans.append(val)
ans.append(-1)
unUsed.remove(val)
minHeapq = [val for val in unUsed]
heapq.heapify(minHeapq)
#idea us... | Python | [
"other"
] | 213 | 1,034 | 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
} | 314 |
3800f4d44031aad264e43dc6b490592c | Levian works as an accountant in a large company. Levian knows how much the company has earned in each of the n consecutive months — in the i-th month the company had income equal to a_i (positive income means profit, negative income means loss, zero income means no change). Because of the general self-isolation, the f... | ['data structures', 'constructive algorithms', 'implementation', 'greedy'] | from sys import stdin,stderr
def rl():
return [int(w) for w in stdin.readline().split()]
n, = rl()
a = rl()
x, = rl()
if x >= 0:
if sum(a) + (n // 2) * x > 0:
print(n)
else:
print(-1)
else:
margin = sum(a)
if margin + (1 - n % 2) * x <= 0:
print(-1)
else:
k = n
... | Python | [
"other"
] | 1,202 | 684 | 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,903 |
c1eb165162df7d602c376d8555d8aef8 | Rebel spy Heidi has just obtained the plans for the Death Star from the Empire and, now on her way to safety, she is trying to break the encryption of the plans (of course they are encrypted – the Empire may be evil, but it is not stupid!). The encryption has several levels of security, and here is how the first one lo... | ['brute force'] | line = input().split()
n = int(line[0])
p = int(line[1])
a = input().split()
suma = 0
for i in range(n):
a[i] = int(a[i])
suma += a[i]
Max = 0
sum = 0
for i in range(n-1):
sum += a[i]
total = (sum % p) + ((suma-sum) % p)
if (total>Max):
Max = total
print(Max) | Python | [
"other"
] | 974 | 289 | 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,596 |
926ec28d1c80e7cbe0bb6d209e664f48 | The little girl loves the problems on array queries very much.One day she came across a rather well-known problem: you've got an array of n elements (the elements of the array are indexed starting from 1); also, there are q queries, each one is defined by a pair of integers l_i, r_i (1 \le l_i \le r_i \le n). You need ... | ['data structures', 'implementation', 'sortings', 'greedy'] | #!/usr/bin/python
from collections import deque
def ir():
return int(raw_input())
def ia():
line = raw_input()
line = line.split()
return map(int, line)
n, q = ia()
a = ia(); a.sort(reverse=True)
d = [0 for i in range(n+1)]
for i in range(q):
l, r = ia(); l-=1; r-=1
d[l] += 1; d[r+1] -=1
... | Python | [
"other"
] | 694 | 484 | 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,276 |
0c9f2301629726870a0ab57299773fd6 | Polycarp bought a new expensive painting and decided to show it to his n friends. He hung it in his room. n of his friends entered and exited there one by one. At one moment there was no more than one person in the room. In other words, the first friend entered and left first, then the second, and so on.It is known tha... | ['implementation'] | for _ in range(int(input())):
s = input()
ans = 0
ll, rr = 0, len(s)
k = 0
if '0' in s:
rr = s.index('0') + 1
k += 1
if '1' in s:
ll = len(s) - s[::-1].index('1') - 1
k += 2
if k == 3:
print(rr - ll)
elif k == 1:
print(rr)
... | Python | [
"other"
] | 1,058 | 394 | 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
} | 535 |
02b7ff5e0b7f8cd074d9e76251c2725e | Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are n mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For that ... | ['constructive algorithms'] | a=int(input())
l=1
r=a
ans=[1]
while(len(ans)!=a):
i=len(ans)
if(i%2==1):
ans.append(r)
r-=1
else:
ans.append(l+1)
l+=1
print(*ans)
| Python | [
"other"
] | 618 | 176 | 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,830 |
5b9aed235094de7de36247a3b2a34e0f | 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 fr... | ['constructive algorithms', 'implementation'] | n, m = [int(s) for s in input().split()]
c = 0
for i in range (n):
a = [int(s) for s in input().split()]
for j in range(m):
if (a[2*j]+a[2*j+1]) != 0:
c +=1
print(c) | Python | [
"other"
] | 893 | 197 | 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,555 |
39fd7843558ed2aa6b8c997c2b8a1fad | Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online. The store contains k items. n customers have already used the above service. Each user paid for m items. Let aij denote the j-th item in the i-th person's order.Due to the spa... | ['brute force'] | from sys import stdin
l2i = lambda l: [int(x) for x in l.strip().split()]
n, m, k = l2i(stdin.readline())
shop = l2i(stdin.readline())
time = 0
while n != 0:
n -= 1
for commodity in l2i(stdin.readline()):
sw = commodity
pos = 0
while shop[0] != sw or pos == 0:
sw, shop[pos... | Python | [
"other"
] | 940 | 405 | 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,592 |
daf675dadc8edcd6734edbf3548eb6bf | You are given n elements numbered from 1 to n, the element i has value a_i and color c_i, initially, c_i = 0 for all i.The following operation can be applied: Select three elements i, j and k (1 \leq i < j < k \leq n), such that c_i, c_j and c_k are all equal to 0 and a_i = a_k, then set c_j = 1. Find the maximum... | ['greedy', 'greedy', 'sortings', 'two pointers'] | n=int(input())
a=list(map(int, input().split()))
b=[[] for i in range(n+1)]
for i in range(n):
b[a[i]].append(i)
c=[]
for i in range(1, n+1):
if len(b[i])>1:
c.append([b[i][0], b[i][-1]])
c=sorted(c, key=lambda x:x[0])
d=[]
ldx=0
rdx=0
f=0
cnt=0
for i in range(len(c)):
if rdx<c[i][1]... | Python | [
"other"
] | 546 | 694 | 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,241 |
1b9a204dd08d61766391a3b4d2429df2 | She is skilled in all kinds of magics, and is keen on inventing new one.—Perfect Memento in Strict SensePatchouli is making a magical talisman. She initially has n magical tokens. Their magical power can be represented with positive integers a_1, a_2, \ldots, a_n. Patchouli may perform the following two operations on t... | ['bitmasks', 'constructive algorithms', 'greedy', 'sortings'] | for s in[*open(0)][2::2]:b=min(a:=[x&-x for x in
map(int,s.split())]);print(len(a)+min(k:=bin(b)[::-1].find('1')-1,k*a.count(b))) | Python | [
"other"
] | 836 | 129 | 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,204 |
a26b23f2b667b7cb3d10f2389fa2cb53 | You are given a set of points on a straight line. Each point has a color assigned to it. For point a, its neighbors are the points which don't have any other points between them and a. Each point has at most two neighbors - one from the left and one from the right.You perform a sequence of operations on this set of poi... | ['data structures', 'implementation', 'greedy'] | s = input()
n = 1
for i in range(1, len(s)):
if s[i] != s[i-1]:
n += 1
mas = [0] * n
col = [0] * n
count = 1
idx = 0
c = s[0]
for i in range(1, len(s)):
if s[i] == s[i-1]:
count += 1
else:
mas[idx] = count
col[idx] = c
idx += 1
count = 1
c = s[i]
mas[idx] = count
col[idx] =... | Python | [
"other"
] | 770 | 810 | 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
} | 381 |
6ed24fef3b7f0f0dc040fc5bed535209 | Uh oh! Ray lost his array yet again! However, Omkar might be able to help because he thinks he has found the OmkArray of Ray's array. The OmkArray of an array a with elements a_1, a_2, \ldots, a_{2k-1}, is the array b with elements b_1, b_2, \ldots, b_{k} such that b_i is equal to the median of a_1, a_2, \ldots, a_{2i-... | ['data structures', 'greedy', 'implementation'] | def solve(n, a):
prev = a[0]
r = [10 ** 9]
l = [-r[0]]
for i in range(1, n):
if a[i] < prev:
if a[i] < l[-1]:
return False
elif a[i] == l[-1]:
l.pop()
r.append(prev)
elif a[i] > prev:
if a[i] > r[... | Python | [
"other"
] | 842 | 660 | 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,982 |
3372948de45ea0867e8cc44dff3d635f | Petya sometimes has to water his field. To water the field, Petya needs a tank with exactly V ml of water.Petya has got N tanks, i-th of them initially containing ai ml of water. The tanks are really large, any of them can contain any amount of water (no matter how large this amount is).Also Petya has got a scoop that ... | ['dp', 'implementation', 'greedy'] | import sys
input = raw_input
range = xrange
n,K,V = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
Acop = A[:]
if (V%K)==0:
asum = sum(A)
if asum>=V:
print 'YES'
for i in range(1,n):
A[0] += A[i]
count = (A[i]+K-1)//K
if coun... | Python | [
"other"
] | 976 | 2,495 | 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,299 |
a2d4f0182456cedbe85dff97ec0f477e | To satisfy his love of matching socks, Phoenix has brought his n socks (n is even) to the sock store. Each of his socks has a color c_i and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either: recolor a sock to any color c' (1 \le c' \le n) turn a left sock into a right sock turn... | ['greedy', 'sortings', 'two pointers'] | t=int(input())
# if (t==1):
# try :
# for i in range(t):
# n,l,r=map(int,input().split())
# xx=list(map(int,input().split()))
# score=0
# if(i==529):
# print(i)
# print(l)
# print(r)
# ... | Python | [
"other"
] | 753 | 4,873 | 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,972 |
b784cebc7e50cc831fde480171b9eb84 | When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of consecutive data points that seems as constant as possible and taking their aver... | ['dp', 'two pointers', 'implementation'] | from collections import Counter
cnt = Counter()
n = int(raw_input())
a = map(int,raw_input().split())
def isOK(x):
if cnt[x-2]>0 or cnt[x+2]>0:
return False
else:
cnt[x]+=1
return True
ret = cur = 0
for i in xrange(n):
while cur < n and isOK(a[cur]):
cur+=1
ret = max(r... | Python | [
"other"
] | 970 | 357 | 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,321 |
4720ca1d2f4b7a0e553a3ea07a76943c | Gerald has a friend, Pollard. Pollard is interested in lucky tickets (ticket is a sequence of digits). At first he thought that a ticket is lucky if between some its digits we can add arithmetic signs and brackets so that the result obtained by the arithmetic expression was number 100. But he quickly analyzed all such ... | ['constructive algorithms', 'brute force'] | N,M = map(int,raw_input().split())
P = {}
Q = {}
for i in range(10001):
for j in range(1,5):
P[(i,j)] = set()
Q[(i,j)] = set()
for i in range(10):
P[(i,1)].add(i)
Q[(i,1)].add(i)
for i in range(100):
P[(i,2)].add(i)
Q[(i,2)].add(i)
a,b = i/10,i%10
next = [a+b,abs(a-b),a*b]
... | Python | [
"other"
] | 1,343 | 1,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
} | 4,966 |
c8cdb9f6a44e1ce9ef81a981c9b334c2 | Zookeeper is buying a carton of fruit to feed his pet wabbit. The fruits are a sequence of apples and oranges, which is represented by a binary string s_1s_2\ldots s_n of length n. 1 represents an apple and 0 represents an orange.Since wabbit is allergic to eating oranges, Zookeeper would like to find the longest conti... | ['dp', 'two pointers', 'divide and conquer', 'data structures', 'binary search'] | import sys
readline = sys.stdin.readline
N = int(readline())
A = list(map(int, readline().strip()))
def calc(l, r):
m = (l+r)//2
if l+1 == r:
return A[l]
if l+2 == r:
return 2*(A[l]+A[l+1])
X = A[l:m][::-1]
Y = A[m:r]
LX = len(X)
LY = len(Y)
a1 = [0]*LX
a2 = [0]*LY
... | Python | [
"other"
] | 589 | 1,843 | 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,418 |
cb47d710361979de0f975cc34fc22c7a | Little boy Gerald studies at school which is quite far from his house. That's why he has to go there by bus every day. The way from home to school is represented by a segment of a straight line; the segment contains exactly n + 1 bus stops. All of them are numbered with integers from 0 to n in the order in which they f... | ['dp', 'binary search', 'data structures'] | from sys import stdin
from collections import *
def fast2():
import os, sys, atexit
range = xrange
from cStringIO import StringIO as BytesIO
sys.stdout = BytesIO()
atexit.register(lambda: os.write(1, sys.stdout.getvalue()))
return BytesIO(os.read(0, os.fstat(0).st_size)).readline
class segme... | Python | [
"other"
] | 1,375 | 1,577 | 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,383 |
e95e2d21777c1d686bede1b0a5dacbf5 | You are given a string s. You have to determine whether it is possible to build the string s out of strings aa, aaa, bb and/or bbb by concatenating them. You can use the strings aa, aaa, bb and/or bbb any number of times and in any order.For example: aaaabbb can be built as aa + aa + bbb; bbaaaaabbb can be built as bb ... | ['implementation'] | t = int(input(""))
for i in range(t):
x = input("")
count = 1
base = x[0]
answer = "YES"
for i in range(1, len(x)):
if x[i] == base:
count = count + 1
else:
if count == 1:
answer = "NO"
break
else:
ba... | Python | [
"other"
] | 483 | 426 | 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,884 |
31057c0e76e6985a68b2a298236a8ee5 | The Beroil corporation structure is hierarchical, that is it can be represented as a tree. Let's examine the presentation of this structure as follows: employee ::= name. | name:employee1,employee2, ... ,employeek. name ::= name of an employee That is, the description of each employee consists of his name, a colon (:),... | ['data structures', 'implementation', 'expression parsing'] | #!/usr/bin/env python3
tree = input().strip()
def get_answer(tree, start_index = 0, prev = []):
colon_index = tree.find(':', start_index)
period_index = tree.find('.', start_index)
name_end_index = colon_index if ((colon_index != -1) and (colon_index < period_index)) else period_index
name = tree[start_index... | Python | [
"other"
] | 1,336 | 742 | 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,575 |
dd62b6860b6a4cf33aef89c2f674331f | The Government of Mars is not only interested in optimizing space flights, but also wants to improve the road system of the planet.One of the most important highways of Mars connects Olymp City and Kstolop, the capital of Cydonia. In this problem, we only consider the way from Kstolop to Olymp City, but not the reverse... | ['dp'] | # What to check if it made a difference
# Putting in result before going straight to memo
# limits[i] > s ? How is this so effective?
n, l, k = map(int, input().split())
coor = list(map(int, input().split()))+[l]
limits = list(map(int, input().split()))+[0]
memo = {}
def dfs(i, k, s): # coordinate, takes left, speed
... | Python | [
"other"
] | 2,054 | 1,721 | 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,408 |
a8334846b495efbded9bb0641d6a1964 | The only difference between this problem and the hard version is the maximum number of questions.This is an interactive problem.There is a hidden integer 1 \le x \le n which you have to find. In order to find it you can ask at most \mathbf{53} questions.In each question you can choose a non-empty integer set S and ask ... | ['dp', 'interactive'] | import sys, random
input = sys.stdin.readline
n = int(input())
good = list(range(1, n + 1))
mid = []
def query(l):
print('?',len(l),' '.join(map(str, l)))
sys.stdout.flush()
#return random.randint(0, 1)
s = input().strip()
return s == 'YES'
from functools import cache
@cach... | Python | [
"other"
] | 1,267 | 2,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
} | 869 |
d44542a39df3b06fa32c69d99887a2e2 | Innocentius has a problem — his computer monitor has broken. Now some of the pixels are "dead", that is, they are always black. As consequence, Innocentius can't play the usual computer games. He is recently playing the following game with his younger brother Polycarpus.Innocentius is touch-typing a program that paints... | ['constructive algorithms', 'implementation', 'greedy', 'brute force'] | from itertools import chain
# To draw square: if point isn't 'w', draw '+'
def draw_square(scr, square_a, ymin, xmin):
for i in range(square_a + 1):
if scr[ymin][xmin + i] != 'w':
scr[ymin] = scr[ymin][:xmin + i] + '+' + scr[ymin][xmin + i + 1:]
if scr[ymin + square_a][xmin + i] != 'w':
... | Python | [
"other"
] | 1,448 | 7,311 | 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,285 |
aeea2ca73f1b5c5b86fb508afcbec68a | You are given an integer n.Let's define s(n) as the string "BAN" concatenated n times. For example, s(1) = "BAN", s(3) = "BANBANBAN". Note that the length of the string s(n) is equal to 3n.Consider s(n). You can perform the following operation on s(n) any number of times (possibly zero): Select any two distinct indices... | ['constructive algorithms'] | #Khushal Sindhav
#Indian Institute Of Technology, Jodhpur
# 4 Nov 2022
def exe():
global n
if n==1:
print(1)
print(1,2)
return
if n==2:
print(1)
print(2,6)
return
l=[]
i,j=1,3*n
s=["B","A","N"]*n
while i<j:
l.append([... | Python | [
"other"
] | 824 | 523 | 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
} | 296 |
85453ab4eb82b894ef8941c70c6d713c | Soon there will be held the world's largest programming contest, but the testing system still has m bugs. The contest organizer, a well-known university, has no choice but to attract university students to fix all the bugs. The university has n students able to perform such work. The students realize that they are the ... | ['data structures', 'binary search', 'sortings', 'greedy'] | import sys
import heapq
range = xrange
input = raw_input
n,m,s = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
Bind = sorted(range(n),key=lambda i:B[i])
Aind = sorted(range(m),key=lambda i:A[i])
big = 10**9+10
def... | Python | [
"other"
] | 1,254 | 1,230 | 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,461 |
12c223c903544899638e47bcab88999a | Constanze is the smartest girl in her village but she has bad eyesight.One day, she was able to invent an incredible machine! When you pronounce letters, the machine will inscribe them onto a piece of paper. For example, if you pronounce 'c', 'o', 'd', and 'e' in that order, then the machine will inscribe "code" onto t... | ['dp'] | s = raw_input()
flag = True
maxn = int(1e5+5)
fib = [0]*maxn
fib[0] = 1
fib[1] = 1
fib[2] = 2
fib[3] = 3
mod = int(1e9+7)
for i in range(4,maxn):
fib[i] = (fib[i-1]+fib[i-2])%mod
for i in range(len(s)):
if s[i] == "m" or s[i] == "w":
flag = False
if not flag:
print 0
else:
i = 0
cnt = 0
ans = 1
while i<len... | Python | [
"other"
] | 1,595 | 528 | 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,823 |
224a0b09547ec1441474efbd8e06353b | You are given an array a consisting of n (n \ge 3) positive integers. It is known that in this array, all the numbers except one are the same (for example, in the array [4, 11, 4, 4] all numbers except one are equal to 4).Print the index of the element that does not equal others. The numbers in the array are numbered f... | ['brute force', 'implementation'] | import sys
import math
masterlist = []
numofcases = int(input())
for i in range(1, (numofcases * 2) + 1):
next = input()
if i % 2 == 0:
masterlist.append([int(x) for x in next.split(" ")])
for i in masterlist:
twonums = list(set(i))
if i.count(twonums[0]) == 1:
print(i.index(twon... | Python | [
"other"
] | 358 | 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
} | 1,725 |
bd40f54a1e764ba226d5387fcd6b353f | Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion of the championship the driver with most points is the cha... | ['implementation'] | champion_data,points = {},[25, 18, 15, 12, 10, 8, 6, 4, 2, 1]+[0]*50
for tour in range(int(input())):
for j in range(int(input())):
player =str(input())
if player not in champion_data:
champion_data[player] = [0]*51+[player]
champion_data[player][0] += points[j]
champion_data[player][j+1] += 1
win = champio... | Python | [
"other"
] | 1,041 | 418 | 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
} | 841 |
10f4fc5cc2fcec02ebfb7f34d83debac | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with numbers ... | ['binary search', 'implementation'] | import sys
def search(Max,new,num):
if new[0]>num:
return 1
Min =0
Mid = int((Max+Min)/2)
while Min<=Max:
if new[Mid]==num:
return Mid+1
break
elif new[Min]==num:
return Min+1
break
elif new[Mid]<num and new[Mid+1]>num:
return Mid+2
break
elif new[Mid]<num:
Min=Mid+1
else:
Max=M... | Python | [
"other"
] | 726 | 614 | 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,928 |
267c04c77f97bbdf7697dc88c7bfa4af | In this task you need to process a set of stock exchange orders and use them to create order book.An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number i has price pi, direction di — buy or sell, and integer qi. This means that the participant is ready to buy or sell q... | ['data structures', 'implementation', 'sortings', 'greedy'] | __author__ = 'trunghieu11'
def main():
n, s = map(int, raw_input().split())
buy = dict()
sell = dict()
for i in range(n):
line = raw_input().split()
d = str(line[0])
p = int(line[1])
q = int(line[2])
if d == "B":
if (d, p) in buy.keys():
... | Python | [
"other"
] | 1,172 | 1,049 | 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,981 |
c3ee6419adfc85c80f35ecfdea6b0d43 | You are given an array a of n elements. Your can perform the following operation no more than n times: Select three indices x,y,z (1 \leq x < y < z \leq n) and replace a_x with a_y - a_z. After the operation, |a_x| need to be less than 10^{18}.Your goal is to make the resulting array non-decreasing. If there are ... | ['constructive algorithms', 'greedy'] | import array
import bisect
import heapq
import math
import collections
import sys
import copy
from functools import reduce
import decimal
from io import BytesIO, IOBase
import os
import itertools
import functools
from types import GeneratorType
import fractions
# sys.setrecursionlimit(10 ** 9)
decimal... | Python | [
"other"
] | 475 | 9,131 | 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,634 |
c9744e25f92bae784c3a4833c15d03f4 | Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers.Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly: i... | ['implementation', 'sortings'] | n = input()
s = map(int,raw_input().split())
l = []
r = []
for i in range(1,n-1) :
if s[i]> s[i-1] and s[i]>s[i+1] :
l.append(i+1)
if s[i]< s[i-1] and s[i]<s[i+1] :
r.append(i+1)
if ( len(l) == 1 ) and ( len(r) == 1) and (l[0] <= r[0]) and ( s[l[0]-2] < s[r[0]-1] ) and ( s[r[0]] > s[l[0]-1] ):
print 'ye... | Python | [
"other"
] | 469 | 721 | 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
} | 223 |
3cb4c89b174bf5ea51e797b78103e089 | Polycarpus has a hobby — he develops an unusual social network. His work is almost completed, and there is only one more module to implement — the module which determines friends. Oh yes, in this social network one won't have to add friends manually! Pairs of friends are deduced in the following way. Let's assume that ... | ['implementation', '*special', 'greedy'] | n, d = map(int, input().split())
f = list()
m = dict()
for i in range(n):
add = False
a, b, t2 = input().split()
t2 = int(t2)
c = m.get(b + ' ' + a, 0)
if c != -1:
if c != 0:
for t1 in c:
if 0 < t2 - t1 <= d:
f.append(a + ' ' + b)
... | Python | [
"other"
] | 737 | 675 | 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
} | 276 |
c4c8cb860ea9a5b56bb35532989a9192 | A number is ternary if it contains only digits 0, 1 and 2. For example, the following numbers are ternary: 1022, 11, 21, 2002.You are given a long ternary number x. The first (leftmost) digit of x is guaranteed to be 2, the other digits of x can be 0, 1 or 2.Let's define the ternary XOR operation \odot of two ternary n... | ['implementation', 'greedy'] |
t = int(input())
for i in range(t):
n = int(input())
x = input()
a = ''
b = ''
firstOne = False
for i in range(n):
if not firstOne:
if x[i] == '2':
a += '1'
b += '1'
elif x[i] == '0':
a += '0'
b += '... | Python | [
"other"
] | 972 | 689 | 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,832 |
9877f4773f34041ea60f9052a36af5a8 | This is an interactive problem!Nastia has a hidden permutation p of length n consisting of integers from 1 to n. You, for some reason, want to figure out the permutation. To do that, you can give her an integer t (1 \le t \le 2), two different indices i and j (1 \le i, j \le n, i \neq j), and an integer x (1 \le x \le ... | ['constructive algorithms', 'interactive'] | import sys
def ask(q):
print(q, flush=True)
ret = int(input())
assert ret != -1
return ret
input = lambda: sys.stdin.buffer.readline().decode().strip()
for _ in range(int(input())):
n = int(input())
ans, ix = [0] * n, n
for i in range(2, n + 1, 2):
pos = ask(f'? ... | Python | [
"other"
] | 767 | 713 | 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
} | 117 |
9ad07b42358e7f7cfa15ea382495a8a1 | In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After... | ['implementation'] | n, k = [int(x) for x in raw_input().split()]
a = [int(x) for x in raw_input(). split()]
cur = 0
i = 1
while cur + i < k:
cur += i
i += 1
rem = k - cur
if rem == 0:
print a[i - 1]
else:
print a[rem - 1]
| Python | [
"other"
] | 697 | 219 | 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,786 |
bcee233ddb1509a14f2bd9fd5ec58798 | One day shooshuns found a sequence of n integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps: Find the number that goes k-th in the current sequence and add the same number to the end of the sequence; Delete the first number of the current sequence. The... | ['implementation', 'brute force'] | import sys
n, k = [int(x) for x in raw_input().split()]
elems = [int(x) for x in raw_input().split()]
k -= 1
for i in xrange(k, n):
if elems[i] != elems[k]:
print -1
sys.exit(0)
# We are good. get the last element until k which is not equal.
steps = -1
for i in xrange(k):
if elems[i] != ele... | Python | [
"other"
] | 454 | 363 | 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,807 |
aab8d5a2d42b4199310f3f535a6b3bd7 | Tanya wants to go on a journey across the cities of Berland. There are n cities situated along the main railroad line of Berland, and these cities are numbered from 1 to n. Tanya plans her journey as follows. First of all, she will choose some city c_1 to start her journey. She will visit it, and after that go to some ... | ['data structures', 'sortings'] | x=int(input());a=list(map(int,input().split()));b={}
for i in range(x):
tem=a[i]
if tem-i in b.keys():
b[tem-i]+=tem
else:
b[tem-i]=tem
print(max(b.values())) | Python | [
"other"
] | 1,591 | 165 | 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
} | 744 |
02d62bb1eb4cc0e373b862a980d6b29c | Berland shop sells n kinds of juices. Each juice has its price c_i. Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin "A", vitamin "B" and vitamin "C". Each juice can contain one, two or all three types of vitamins in it.Petya knows that he needs all three types of vitamins to s... | ['dp', 'implementation', 'bitmasks', 'brute force'] | n=int(input())
p={
"A":10**9,
"B":10**9,
"C":10**9,
"AB":10**9,
"BC":10**9,
"AC":10**9,
"ABC":10**9
}
for i in range(n):
x,y=input().split()
x=int(x)
y=''.join(sorted(y))
p[y]=min(p[y],x)
x=min(
p["A"]+p["B"]+p["C"],
p["AB"]+p["C"],
p["AC"]+p["B"],
... | Python | [
"other"
] | 524 | 642 | 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
} | 851 |
7bbb4b9f5eccfe13741445c815a4b1ca | The USA Construction Operation (USACO) recently ordered Farmer John to arrange a row of n haybale piles on the farm. The i-th pile contains a_i haybales. However, Farmer John has just left for vacation, leaving Bessie all on her own. Every day, Bessie the naughty cow can choose to move one haybale in any pile to an adj... | ['implementation', 'greedy'] | a=int(input())
for i in range(a):
n,d=map(int,input().split())
z=list(map(int,input().split()))
if(n==1):
print(z[0])
else:
if(z[1]>=d):
print(z[0]+d)
else:
for i in range(1,len(z)):
if(d<=0):
break;
... | Python | [
"other"
] | 870 | 791 | 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,153 |
f3d34922baf84c534e78e283dcadc742 | You are playing a very popular computer game. The next level consists of n consecutive locations, numbered from 1 to n, each of them containing either land or water. It is known that the first and last locations contain land, and for completing the level you have to move from the first location to the last. Also, if yo... | ['implementation'] | t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int,input().split()))
x = False
start = 0
end = 0
flag = False
for i in range(n):
if a[i] == 0 and not x:
start = i-1
while i<n and a[i]!=1:
i+=1
end = i... | Python | [
"other"
] | 843 | 477 | 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,472 |
12abfbe7118868a0b1237489b5c92760 | There are n pillars aligned in a row and numbered from 1 to n.Initially each pillar contains exactly one disk. The i-th pillar contains a disk having radius a_i.You can move these disks from one pillar to another. You can take a disk from pillar i and place it on top of pillar j if all these conditions are met: there i... | ['implementation', 'greedy'] | n = int(input())
l = list(map(int,input().split()))
max1 = l.index(n)
for i in range(1,n):
if i <= max1:
if l[i-1] < l[i]:
continue
else:
print("NO")
exit()
else:
if l[i] < l[i-1]:
continue
else:
print("NO")
exit()
print("YES")
| Python | [
"other"
] | 1,130 | 256 | 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,348 |
c315870f5798dfd75ddfc76c7e3f6fa5 | Andrew and Eugene are playing a game. Initially, Andrew has string s, consisting of digits. Eugene sends Andrew multiple queries of type "di → ti", that means "replace all digits di in string s with substrings equal to ti". For example, if s = 123123, then query "2 → 00" transforms s to 10031003, and query "3 → " ("rep... | ['dp'] | MOD = 1000000007
st,n,t,mp=input(),int(input()),[],{}
t.append(['',st])
for i in range(10):
mp[str(i)]=(10,i)
for i in range(n):
t.append(input().split("->"))
for i in range(n,-1,-1):
a,b=1,0
for j in t[i][1]:
a,b=a*mp[j][0]%MOD,(b*mp[j][0]+mp[j][1])%MOD
mp[t[i][0]]= a,b
print(mp[''][1])
| Python | [
"other"
] | 795 | 302 | 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
} | 339 |
857de33d75daee460206079fa2c15814 | Given a permutation p of length n, find its subsequence s_1, s_2, \ldots, s_k of length at least 2 such that: |s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k| is as big as possible over all subsequences of p with length at least 2. Among all such subsequences, choose the one whose length, k, is as small as possible. If multipl... | ['two pointers', 'greedy'] | def ints():
return map(int,raw_input().split())
for _ in range(input()):
n = input()
a = ints()
l = [a[0],a[1]]
low = 0
i = 2
if n==2:
print 2
for x in l:
print x,
print
continue
while i!= n:
l.append(a[i])
if a[i-2]<a[i-1]<a[i]... | Python | [
"other"
] | 740 | 527 | 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,874 |
e3a03f3f01a77a1983121bab4218c39c | The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building.The slogan of the company consists of n characters, so the decorators hung a large... | ['implementation', 'greedy'] | N,K = map(int, input().split())
S = input()
a = K-1
b = N-K
if a ==0:
a = 1000
if b == 0:
b =1000
pos = K-1
printed = 1
print('PRINT '+str(S[pos]))
if a<=b:
while pos!=0:
print('LEFT')
pos-=1
print('PRINT '+str(S[pos]))
printed+=1
if printed !=N:
while pos!=K-1:
... | Python | [
"other"
] | 1,480 | 833 | 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,427 |
6d146936ab34deaee24721e53474aef0 | Iahub wants to enhance his multitasking abilities. In order to do this, he wants to sort n arrays simultaneously, each array consisting of m integers.Iahub can choose a pair of distinct indices i and j (1 ≤ i, j ≤ m, i ≠ j). Then in each array the values at positions i and j are swapped only if the value at position i ... | ['two pointers', 'implementation', 'sortings', 'greedy'] | n,m,k=map(int,raw_input().split())
for _ in range(n):
raw_input()
print (m)*(m-1)/2
for i in range(1,m):
for j in range(i+1,m+1):
if k==0:
print i,j
else:
print j,i
| Python | [
"other"
] | 642 | 213 | 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,556 |
dddeb7663c948515def967374f2b8812 | You are a given an array a of length n. Find a subarray a[l..r] with length at least k with the largest median.A median in an array of length n is an element which occupies position number \lfloor \frac{n + 1}{2} \rfloor after we sort the elements in non-decreasing order. For example: median([1, 2, 3, 4]) = 2, median([... | ['binary search', 'data structures', 'dp'] |
a = []
n, k = 0, 0
def check(median):
mini = 2*10**5+1
part_sums = [0]
for val in a[:k]:
part_sums.append(part_sums[-1] + (val >= median) - (val < median))
for key, val in enumerate(a[k:]):
mini = min(mini, part_sums[key])
if part_sums[-1] - mini > 0:
... | Python | [
"other"
] | 594 | 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
} | 1,357 |
2d988fe01f91847dcad52111c468c0ba | Slime has a sequence of positive integers a_1, a_2, \ldots, a_n.In one operation Orac can choose an arbitrary subsegment [l \ldots r] of this sequence and replace all values a_l, a_{l + 1}, \ldots, a_r to the value of median of \{a_l, a_{l + 1}, \ldots, a_r\}.In this problem, for the integer multiset s, the median of s... | ['constructive algorithms', 'greedy'] | import sys
from collections import deque
readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')
def solve():
... | Python | [
"other"
] | 824 | 627 | 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,876 |
c943a6413441651ec9f420ef44ea48d0 | You have an array a[1], a[2], ..., a[n], containing distinct integers from 1 to n. Your task is to sort this array in increasing order with the following operation (you may need to apply it multiple times): choose two indexes, i and j (1 ≤ i < j ≤ n; (j - i + 1) is a prime number); swap the elements on positions i a... | ['sortings', 'greedy'] | # from random import shuffle
# f = open("out.txt", "w")
# n = 1000
# test = list(range(1, n + 1))
# shuffle(test)
# print(n, file=f)
# print(' '.join(map(str, test)), file=f)
from bisect import *
from sys import stdin
f = stdin # open("out.txt", "r")
n = int(f.readline())
primes = [1] * (n + 1)
primes[0] = 0
prime... | Python | [
"other"
] | 602 | 945 | 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,027 |
18f44ab990ef841c947e2da831321845 | A widely known among some people Belarusian sport programmer Lesha decided to make some money to buy a one square meter larger flat. To do this, he wants to make and carry out a Super Rated Match (SRM) on the site Torcoder.com. But there's a problem — a severe torcoder coordinator Ivan does not accept any Lesha's probl... | ['brute force'] | import itertools
def check(curr_words, line):
if curr_words == []:
return True
for i in range(len(line)):
if line[i] == curr_words[0]:
return check(curr_words[1:], line[i+1:])
return False
n = int(input())
words = input().split()
m = int(input())
res, idx = 0, 0
for i in range... | Python | [
"other"
] | 1,817 | 772 | 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,131 |
ce8350be138ce2061349d7f9224a5aaf | Young Teodor enjoys drawing. His favourite hobby is drawing segments with integer borders inside his huge [1;m] segment. One day Teodor noticed that picture he just drawn has one interesting feature: there doesn't exist an integer point, that belongs each of segments in the picture. Having discovered this fact, Teodor ... | ['data structures', 'dp'] | from sys import stdin
from itertools import repeat
from bisect import bisect
def main():
n, m = map(int, stdin.readline().split())
dat = map(int, stdin.read().split(), repeat(10, 2 * n))
s = [0] * (m + 1)
for i, x in enumerate(dat):
if i & 1:
s[x] -= 1
else:
s[x-1... | Python | [
"other"
] | 1,272 | 855 | 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
} | 888 |
59d4c66892fa3157d1163225a550a368 | A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length 0 are not allowed).Let's consider e... | ['dp', 'greedy', 'brute force'] | n , m = [int(x) for x in input().split()]
grid = [[x for x in input()] for _ in range(n)]
star_mem = {}
astr_num = set()
def l_0 (x) :
return x < 1
def astr_size(x, y, size ):
for i in range(y,y+size+1,1):
astr_num.add((x,i))
for i in range(y,y-size-1,-1):
astr_num.add((x,i))
for i i... | Python | [
"other"
] | 1,198 | 1,892 | 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,062 |
3d6411d67c85f6293f1999ccff2cd8ba | In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly n soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either inc... | ['implementation'] | # -*- coding: utf-8 -*-
N , K = [int(n) for n in raw_input().split(" ")]
r = []
num = raw_input().split(" ")
#N , K = 100 , 100
#num = [1 for i in xrange(100)]
for i in xrange(K):
r.append(0)
for n in num:
t = int(n)
r[t - 1] += 1
cnt = 0
while True:
i = 0
while i < K - 1 and r[i] == 0:
i ... | Python | [
"other"
] | 1,282 | 518 | 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,967 |
468020848783d8e017f2d7de5b4fe940 | A set of points on a plane is called good, if for any two points at least one of the three conditions is true: those two points lie on same horizontal line; those two points lie on same vertical line; the rectangle, with corners in these two points, contains inside or on its borders at least one point of the set, other... | ['constructive algorithms', 'divide and conquer'] | s = set()
def build(l, r):
if (l >= r):
return
mid = (l+r) >> 1
for i in range(l, r):
s.add((a[mid][0], a[i][1]))
build(l, mid)
build(mid+1, r)
n = input()
a = []
for i in range(0, n):
x, y = map(int, raw_input().split())
a.append((x, y))
a.sort()
build(0, n)
print len(s)
for... | Python | [
"other"
] | 587 | 350 | 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
} | 665 |
6477fdad8455f57555f93c021995bb4d | Arkady invited Anna for a dinner to a sushi restaurant. The restaurant is a bit unusual: it offers n pieces of sushi aligned in a row, and a customer has to choose a continuous subsegment of these sushi to buy.The pieces of sushi are of two types: either with tuna or with eel. Let's denote the type of the i-th from the... | ['binary search', 'implementation', 'greedy'] | n=int(input())
a=[int(x) for x in input().split()]
c1=0
c2=0
ans=[]
f=[a[0],1]
ans.append(f)
j=0
i=1
answer=0
while(i<n):
if(a[i]==a[i-1]):
ans[j][1]+=1
else:
j+=1
ans.append([a[i],1])
i+=1
for i in range(1,len(ans)):
res=2*min(ans[i-1][1],ans[i][1])
if(res>answer):
a... | Python | [
"other"
] | 891 | 344 | 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,815 |
05177408414e4056cd6b1ea46d1ac499 | This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on n are less than in the hard version of the problem.You are given an array a of n integers (there are no equals elements in the array). You can perform the following operations on array elements: c... | ['dp', 'two pointers', 'greedy'] | # f = open('test.py')
# def input():
# return f.readline().replace('\n','')
def read_list():
return list(map(int,input().strip().split(' ')))
def print_list(l):
print(' '.join(map(str,l)))
N = int(input())
for _ in range(N):
n = int(input())
nums = read_list()
dic = {}
for i in range(n):
dic[nums[i]] = i
... | Python | [
"other"
] | 1,289 | 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,330 |
cc9abcff3224118b533881335e4c582b | You have two binary strings a and b of length n. You would like to make all the elements of both strings equal to 0. Unfortunately, you can modify the contents of these strings using only the following operation: You choose two indices l and r (1 \le l \le r \le n); For every i that respects l \le i \le r, change a_i t... | ['constructive algorithms', 'implementation'] | f=open(0)
I=lambda:next(f,'0 ')[:-1]
I()
while n:=int(I()):i=int(a:=I(),2)^int(I(),2);c=[f'{i} {i}'for i,x in
enumerate(a,1)if'0'<x];c+=(len(c)+i)%2*['1 1',f'1 {n}',f'2 {n}'];print(*(['YES',len(c)]+c,['NO'])[1<i+1<1<<n]) | Python | [
"other"
] | 852 | 220 | 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,595 |
2733797c5dd5b9d9e0bf9fe786c3120a | Let's consider the famous game called Boom (aka Hat) with simplified rules.There are n teams playing the game. Each team has two players. The purpose of the game is to explain the words to the teammate without using any words that contain the same root or that sound similarly. Player j from team i (1 ≤ i ≤ n, 1 ≤ j ≤ 2... | ['implementation'] | from collections import deque
stdin = open('input.txt', 'r')
stdout = open('output.txt', 'w')
n,t = [int(x) for x in stdin.readline().split()]
teams = []
for x in range(n):
a1,b1,a2,b2 = [int(x) for x in stdin.readline().split()]
teams.append([(a1,b1), (a2,b2)])
m = int(stdin.readline())
deck = deque()
c... | Python | [
"other"
] | 2,388 | 1,158 | 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,196 |
45cf60f551bd5cbb1f3df6ac3004b53c | Given the integer n — the number of available blocks. You must use all blocks to build a pedestal. The pedestal consists of 3 platforms for 2-nd, 1-st and 3-rd places respectively. The platform for the 1-st place must be strictly higher than for the 2-nd place, and the platform for the 2-nd place must be strictly highe... | ['constructive algorithms', 'greedy'] | # -*- coding: utf-8 -*-
"""
Created on Sat Jun 11 14:58:24 2022
@author: Ajay Varma
"""
# 5 9 3
# aaacc
# bbdddeeee
# aaabbcc
for i in range(int(input())):
n = int(input())
if n==7:
print(2 ,4, 1)
continue
if n%3:
a = (n//3)+1
b = (n//3)+2
c =... | Python | [
"other"
] | 871 | 598 | 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,366 |
5097e92916e49cdc6fb4953b864186db | The marmots have prepared a very easy problem for this year's HC2 – this one. It involves numbers n, k and a sequence of n positive integers a1, a2, ..., an. They also came up with a beautiful and riveting story for the problem statement. It explains what the input means, what the program should output, and it also rea... | ['sortings', 'greedy'] | f = lambda: map(int, input().split())
n, k = f()
print(sum(sorted(f())[:k])) | Python | [
"other"
] | 534 | 76 | 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,926 |
235131226fee9d04efef4673185c1c9b | There are n students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team.The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive.Firstly, the first coach will choose the ... | ['data structures', 'implementation', 'sortings'] | n, k = tuple([int(i) for i in input().split()])
#places = [None] * (n)
data = [int(i) for i in input().split()]
nextup = {}
nextdown = {}
nextup[data[n-1]] = -1
nextdown[data[0]] = -1
for i in range(n-1):
#places[data[i] - 1] = i
nextup[data[i]] = data[i+1]
nextdown[data[i+1]] = data[i]
#results = [None] * ... | Python | [
"other"
] | 1,099 | 2,606 | 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
} | 997 |
1f4dfaff6d9d0e95573f272f71b0fd45 | In the game Lizard Era: Beginning the protagonist will travel with three companions: Lynn, Meliana and Worrigan. Overall the game has n mandatory quests. To perform each of them, you need to take exactly two companions.The attitude of each of the companions to the hero is an integer. Initially, the attitude of each of ... | ['meet-in-the-middle'] | import copy
def fill(k):
global di
for i in range(3):
x = [tasks[k][0], tasks[k][1], tasks[k][2]]
x[i] = 0
mi = min(x)
x[0],x[1],x[2] = x[0]-mi, x[1]-mi, x[2]-mi
for p in di[k+1]:
u,v,w = x[0]+p[0],x[1]+p[1],x[2]+p[2]
mi = min(u,v,w)
u,v,w = u-mi, v-mi, w-mi
di[k][(u,v,w)] = 1
def recurse(k):
... | Python | [
"other"
] | 749 | 2,202 | 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
} | 555 |
667e8938b964d7a24500003f6b89717b | Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. 2 \cdot n students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly n people in each row). Students are numbered from 1 to n in each row in order f... | ['dp'] | n = int(input())
masiv = []
for i in range(2):
lst = [0] + list(map(int, input().split()))
masiv.append(lst)
lst_1 = [0] * (n + 1)
lst_2 = [0] * (n + 1)
lst_1[1] = masiv[0][1]
lst_2[1] = masiv[1][1]
for j in range(2, n + 1):
lst_1[j] = max(lst_2[j - 1], lst_2[j - 2]) + masiv[0][j]
lst_2[j] = max(lst_1[... | Python | [
"other"
] | 1,144 | 450 | 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
} | 219 |
51113dfdbf9f59152712b60e7a14368a | You are given a sequence a_1, a_2, \dots, a_n consisting of n integers.You may perform the following operation on this sequence: choose any element and either increase or decrease it by one.Calculate the minimum possible difference between the maximum element and the minimum element in the sequence, if you can perform ... | ['greedy', 'constructive algorithms', 'two pointers', 'sortings', 'binary search', 'ternary search'] | n, k = [int(x) for x in input().split()]
d = {}
b = []
for i in map(int, input().split()):
if i not in d:
b.append(i)
d[i] = 1
else:
d[i] += 1
b.sort()
mi, ma = 0, len(b) - 1
left, right = b[mi], b[ma]
am_left, am_right = d[b[mi]], d[b[ma]]
mi, ma = 1, len(b) - 2
while right - left > 0... | Python | [
"other"
] | 388 | 859 | 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
} | 617 |
61fb771f915b551a9bcce90c74e0ef64 | Eugene likes working with arrays. And today he needs your help in solving one challenging task.An array c is a subarray of an array b if c can be obtained from b by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.Let's call a nonempty arr... | ['data structures', 'two pointers', 'implementation', 'binary search'] | n = int(input())
seen = dict()
seen[0] = 0
out = 0
l = list(map(int,input().split()))
curr = 0
bestCurr = 0
for i in range(n):
curr += l[i]
if curr in seen:
bestCurr = min(bestCurr + 1, i - seen[curr])
else:
bestCurr += 1
out += bestCurr
seen[curr] = i + 1
print(out) | Python | [
"other"
] | 829 | 303 | 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
} | 947 |
c8747882ea0a79c0f821a6b9badd2625 | This is the hard version of the problem. The only difference is that in this version q = n.You are given an array of integers a_1, a_2, \ldots, a_n.The cost of a subsegment of the array [l, r], 1 \leq l \leq r \leq n, is the value f(l, r) = \operatorname{sum}(l, r) - \operatorname{xor}(l, r), where \operatorname{sum}(l... | ['binary search', 'bitmasks', 'brute force', 'greedy', 'implementation', 'two pointers'] | from bisect import bisect_left, bisect_right
import sys
import io
import os
# region IO
BUFSIZE = 8192
class FastIO(io.IOBase):
newlines = 0
def __init__(self, file):
self._file = file
self._fd = file.fileno()
self.buffer = io.BytesIO()
self.writable = "x" i... | Python | [
"other"
] | 907 | 3,857 | 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,480 |
d1f4872924f521b6cc206ee1e8f2dd3a | You work as a system administrator in a dormitory, which has n rooms one after another along a straight hallway. Rooms are numbered from 1 to n.You have to connect all n rooms to the Internet.You can connect each room to the Internet directly, the cost of such connection for the i-th room is i coins. Some rooms also ha... | ['dp', 'greedy', 'data structures'] |
def solve(N, K, S):
nxt = [0] * (N+1)
cur = 1 << 30
for i in xrange(N, 0, -1):
if S[i-1] == '1':
cur = i
nxt[i] = cur
dp = [0]
for i in xrange(1, N+1):
dp.append(dp[-1] + i)
c = nxt[max(i-K, 1)]
if c <= i+K:
dp[i] = min(dp[i], dp[... | Python | [
"other"
] | 977 | 433 | 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,337 |
87045c4df69110642122f2c114476947 | There are n piles of stones of sizes a1, a2, ..., an lying on the table in front of you.During one move you can take one pile and add it to the other. As you add pile i to pile j, the size of pile j increases by the current size of pile i, and pile i stops existing. The cost of the adding operation equals the size of t... | ['greedy'] | R=lambda:map(int,raw_input().split())
n=input()
a=sorted(R(),reverse=True)
for i in xrange(1,n):a[i]+=a[i-1]
t=[a[n-1]-a[0]]*100100
for k in xrange(1,n+1):
s,u,p,d=0,0,1,0
while u<n:
p*=k
d+=1
s+=(a[min(u+p,n-1)]-a[u])*d
u+=p
t[k]=s
q=input()
print ' '.join(map(lambda x:str(t[x]),R()))
| Python | [
"other"
] | 795 | 310 | 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
} | 157 |
5278cb48aca6fc84e2df393cd8723ecb | A binary string is a string consisting only of the characters 0 and 1. You are given a binary string s_1 s_2 \ldots s_n. It is necessary to make this string non-decreasing in the least number of operations. In other words, each character should be not less than the previous. In one operation, you can do the following: ... | ['brute force', 'dp', 'greedy', 'implementation'] | from sys import stdin, stdout
t = int(stdin.readline())
for p in range(t):
n = int(stdin.readline())
listA = [int(x) for x in str(stdin.readline().strip())]
count = 0
i = 0
while i < n-1:
#print(i, count)
if listA[i] == 1 and listA[i+1] == 0:
if i+2 ... | Python | [
"other"
] | 623 | 730 | 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,076 |
4931c42108f487b81b702db3617f0af6 | Jack has become a soldier now. Unfortunately, he has trouble with the drill. Instead of marching beginning with the left foot and then changing legs with each step, as ordered, he keeps repeating a sequence of steps, in which he sometimes makes the wrong steps or — horror of horrors! — stops for a while. For example, i... | ['dp', 'binary search', 'greedy'] | __author__ = 'Darren'
def solve():
original = input()
temp = [original[0]]
for i in range(1, len(original)):
if original[i] == original[i-1] != 'X':
temp.append('X')
temp.append(original[i])
augmented = ''.join(temp)
answer = 0
if augmented[0] == augmented[-1] != 'X... | Python | [
"other"
] | 1,652 | 1,299 | 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,406 |
e12d86f0c8645424b942d3dd9038e04d | Vasya is choosing a laptop. The shop has n laptops to all tastes.Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties.If all three properties of a laptop are strictly less than those properties of s... | ['implementation', 'brute force'] | n = int(input())
laptops = []
for i in range(n):
speed, ram, hdd, cost = map(int, input().split())
laptops.append([False, speed, ram, hdd, cost])
for i in range(n):
for j in range(n):
if laptops[i][1] < laptops[j][1] and laptops[i][2] < laptops[j][2] and laptops[i][3] < laptops[j][3]:
l... | Python | [
"other"
] | 657 | 519 | 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,155 |
4abdd16670a796be3a0bff63b9798fed | Ilya plays a card game by the following rules.A player has several cards. Each card contains two non-negative integers inscribed, one at the top of the card and one at the bottom. At the beginning of the round the player chooses one of his cards to play it. If the top of the card contains number ai, and the bottom cont... | ['sortings', 'greedy'] | n=int(input())
c=[]
value=0
count=1
for i in range(n):
a,b=map(int,input().split())
if b!=0:
value+=a
count+=b-1
else:
c.append(a)
c.sort()
if len(c)>0:
index=len(c)-1
for i in range(count):
value+=c[index]
index-=1
if index==-1:
break
... | Python | [
"other"
] | 1,168 | 402 | 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,807 |
ae7c80e068e267673a5f910bb0b121ec | Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every... | ['data structures', 'implementation', 'brute force'] | n=int(input().split()[0])
s={input()for _ in[0]*n}
a=[['SET'.find(x)for x in y]for y in s]
print(sum(''.join('SET '[(3-x-y,x)[x==y]]for x,y in
zip(a[i],a[j]))in s for i in range(n)for j in range(i))//3) | Python | [
"other"
] | 1,114 | 203 | 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
} | 35 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.