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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ac7d117d58046872e9d665c9f99e5bff | Let's call a positive integer n ordinary if in the decimal notation all its digits are the same. For example, 1, 2 and 99 are ordinary numbers, but 719 and 2021 are not ordinary numbers.For a given number n, find the number of ordinary numbers among the numbers from 1 to n. | ['brute force', 'math', 'number theory'] | for t in range(int(input())):
n=input()
print(9*(len(n)-1)+int(n)//int("1"*len(n)))
| Python | [
"math",
"number theory"
] | 328 | 124 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 1,
"number theory": 1,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,172 |
f9375003a3b64bab17176a05764c20e8 | Polycarp likes to play with numbers. He takes some integer number x, writes it down on the board, and then performs with it n - 1 operations of the two kinds: divide the number x by 3 (x must be divisible by 3); multiply the number x by 2. After each operation, Polycarp writes down the result on the board and replaces ... | ['sortings', 'math', 'dfs and similar'] | def f(n, b, c=0):
while n % b == 0:
n //= b
c += 1
return c
n, a = int(input()), [int(i) for i in input().split()]
print(*sorted(a, key = lambda x: (f(x, 2), -f(x, 3))))
| Python | [
"math",
"graphs"
] | 989 | 194 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 1,
"math": 1,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 3,481 |
2bfd566ef883efec5211b01552b45218 | Alice and Bob are playing a fun game of tree tag.The game is played on a tree of n vertices numbered from 1 to n. Recall that a tree on n vertices is an undirected, connected graph with n-1 edges.Initially, Alice is located at vertex a, and Bob at vertex b. They take turns alternately, and Alice makes the first move. I... | ['dp', 'dfs and similar', 'games', 'trees'] | from collections import deque
def dfs(x):
length[x] = 0
queue = deque()
queue.append(x)
while queue:
y = queue.popleft()
for z in t[y]:
if length[z] is None:
length[z] = length[y]+1
queue.append(z)
for _ in range(int(input())):
n,a,b,da,db = list(map(int,input().split()))
t = [[] for i in range(... | Python | [
"graphs",
"games",
"trees"
] | 1,056 | 641 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | {
"games": 1,
"geometry": 0,
"graphs": 1,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 1
} | 4,778 |
2effde97cdb0e9962452a9cab63673c1 | Berlanders like to eat cones after a hard day. Misha Square and Sasha Circle are local authorities of Berland. Each of them controls its points of cone trade. Misha has n points, Sasha — m. Since their subordinates constantly had conflicts with each other, they decided to build a fence in the form of a circle, so that ... | ['geometry', 'math'] |
nm = input()
nOm = nm.split()
n = int(nOm[0])
m = int(nOm[1])
a = b = []
for i in range(0, n):
a.append(input())
for i in range(0, m):
b.append(input())
if(n == 2 and m == 2 and a[0] == '-1 0') or (n == 2 and m == 3 and a[0] == '-1 0') or (n == 3 and m == 3 and a[0] == '-3 -4') or ( n == 1000 and m == 1000 and a[... | Python | [
"math",
"geometry"
] | 577 | 1,938 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 1,
"graphs": 0,
"math": 1,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 308 |
c277a257b3621249098e67c1546a8bc4 | Assume that you have k one-dimensional segments s_1, s_2, \dots s_k (each segment is denoted by two integers — its endpoints). Then you can build the following graph on these segments. The graph consists of k vertexes, and there is an edge between the i-th and the j-th vertexes (i \neq j) if and only if the segments s_... | ['dp', 'dfs and similar', 'trees', 'graphs'] | from __future__ import division,print_function
import sys
le=sys.__stdin__.read().split("\n")[::-1]
aff=[]
#basculer en non enraciné
def f():
n=int(le.pop())
ar=[[] for k in range(n)]
for k in range(n-1):
a,b=map(int,le.pop().split())
a-=1
b-=1
ar[a].append(b)
ar[b].a... | Python | [
"graphs",
"trees"
] | 948 | 2,307 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | {
"games": 0,
"geometry": 0,
"graphs": 1,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 1
} | 3,753 |
13d7f6127a7fe945e19d461b584c6228 | Vasya has n different points A_1, A_2, \ldots A_n on the plane. No three of them lie on the same line He wants to place them in some order A_{p_1}, A_{p_2}, \ldots, A_{p_n}, where p_1, p_2, \ldots, p_n — some permutation of integers from 1 to n.After doing so, he will draw oriented polygonal line on these points, drawi... | ['constructive algorithms', 'geometry', 'greedy', 'math'] | n = int(raw_input())
pts = [map(int, raw_input().split()) for __ in xrange(n)]
s = raw_input().rstrip()
def ccw(a, b, c):
return (pts[c][1] - pts[a][1]) * (pts[b][0] - pts[a][0]) - (pts[b][1] - pts[a][1]) * (pts[c][0] - pts[a][0])
start = min(range(n), key=pts.__getitem__)
unused = set(range(n))
unused.remove(start)... | Python | [
"math",
"geometry"
] | 2,066 | 619 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 1,
"graphs": 0,
"math": 1,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 570 |
33f7c85e47bd6c83ab694a834fa728a2 | You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). | ['dp', 'greedy', 'implementation', 'brute force', 'strings'] | from sys import stdin, stdout
ti = lambda : stdin.readline().strip()
ma = lambda fxn, ti : map(fxn, ti.split())
ol = lambda arr : stdout.write(' '.join(str(i) for i in arr) + '\n')
os = lambda i : stdout.write(str(i) + '\n')
olws = lambda arr : stdout.write(''.join(str(i) for i in arr) + '\n')
s = ti()
n = len(s)
i... | Python | [
"strings"
] | 163 | 803 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 1,
"trees": 0
} | 2,610 |
0c2550b2df0849a62969edf5b73e0ac5 | You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings.An integer greater than 1 is composite, if it is not prime, i.e. if i... | ['dp', 'number theory', 'greedy', 'math'] | dp = [-1, -1, -1, 1, -1, 1, -1, 2, 1, 2, -1, 3, 2, 3, 2, 4, 3, 4, 3, 5, 4, 5, 4, 6, 5, 6, 5, 7, 6, 7, 6, 8, 7, 8, 7, 9, 8, 9, 8, 10, 9, 10, 9, 11, 10, 11, 10, 12, 11, 12, 11, 13, 12, 13, 12, 14, 13, 14, 13, 15, 14, 15, 14, 16, 15, 16, 15, 17, 16, 17, 16, 18, 17, 18, 17, 19, 18, 19, 18, 20, 19, 20, 19, 21, 20, 21, 20, 2... | Python | [
"number theory",
"math"
] | 382 | 675 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 1,
"number theory": 1,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 112 |
19a2d5821ab0abc62bda6628b82d0efb | Easy and hard versions are actually different problems, so we advise you to read both statements carefully.You are given a weighted rooted tree, vertex 1 is the root of this tree. Also, each edge has its own cost.A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. A parent of... | ['greedy', 'two pointers', 'sortings', 'binary search', 'dfs and similar', 'trees'] | import sys, threading
from math import inf
input = sys.stdin.readline
def put():
return map(int, input().split())
def dfs(tree,i, sum, p):
if len(tree[i])==1 and i!=0:
return 1
cnt=0
for j,w,c in tree[i]:
if j!=p:
z=dfs(tree,j, sum+w, i)
cnt+=z
if c==... | Python | [
"graphs",
"trees"
] | 1,587 | 1,825 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | {
"games": 0,
"geometry": 0,
"graphs": 1,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 1
} | 4,401 |
37d906de85f173aca2a9a3559cbcf7a3 | There are n phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct.There is the latest version of Berdroid OS installed on Polycarp's phone. If some number is entered, is shows up all the numbers in the contacts for which... | ['data structures', 'implementation', 'brute force', 'strings'] | def add_subs(num, freq):
used = set()
for l in range(1, len(num) + 1):
for i in range(len(num) - l + 1):
end = i + l
sub = num[i : end]
if sub not in used:
used.add(sub)
if sub not in freq:
freq[sub] = 1
else:
freq[sub] += 1
def count_subs(nums):
... | Python | [
"strings"
] | 871 | 740 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 1,
"trees": 0
} | 3,315 |
cee7f95ec969034af7d53e89539a9726 | Physicist Woll likes to play one relaxing game in between his search of the theory of everything.Game interface consists of a rectangular n × m playing field and a dashboard. Initially some cells of the playing field are filled while others are empty. Dashboard contains images of all various connected (we mean connecti... | ['constructive algorithms', 'graph matchings', 'greedy', 'math'] | import sys
n,m = map(int,raw_input().split())
f = [list(raw_input()+'#') for _ in xrange(n)]+['#'*(m+1)]
for i in xrange(n):
for j in xrange(m):
if f[i][j]!='.': continue
c=(i%3)+(j%3)*3
f[i][j]=c
if f[i][j+1]=='.':
f[i][j+1]=c
elif f[i+1][j]=='.':
f[i... | Python | [
"graphs",
"math"
] | 951 | 629 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 1,
"math": 1,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 200 |
754df388958709e3820219b14beb7517 | You received as a gift a very clever robot walking on a rectangular board. Unfortunately, you understood that it is broken and behaves rather strangely (randomly). The board consists of N rows and M columns of cells. The robot is initially at some cell on the i-th row and the j-th column. Then at every step the robot c... | ['dp', 'probabilities', 'math'] | n,m = (int(s) for s in input().split())
i,j = (int(s) for s in input().split())
def find(n,m,i,j):
if i==n:
return 0
if m==1:
return 2*(n-i)
e,a,b = [0.]*m,[0]*m,[0]*m
for l in range(n-1,0,-1):
a[0],b[0]=.5,.5*(3+e[0])
for k in range(1,m-1):
a[k] = 1/(3-a[k-1]... | Python | [
"math",
"probabilities"
] | 765 | 531 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 1,
"number theory": 0,
"probabilities": 1,
"strings": 0,
"trees": 0
} | 2,551 |
35bf06fffc81e8b9e0ad87c7f47d3a7d | You are given a rectangular parallelepiped with sides of positive integer lengths A, B and C. Find the number of different groups of three integers (a, b, c) such that 1\leq a\leq b\leq c and parallelepiped A\times B\times C can be paved with parallelepipeds a\times b\times c. Note, that all small parallelepipeds have ... | ['number theory', 'math'] | from math import gcd
N = 100001
d = [0 for i in range(N)]
for i in range(1, N):
for j in range(i, N, i):
d[j] += 1
n = int(input())
for _ in range(n):
a, b, c = map(int, input().split())
A, B, C = d[a], d[b], d[c]
AB, BC, CA = d[gcd(a, b)], d[gcd(b, c)], d[gcd(c, a)]
ABC = d[gcd(gcd(a, b),... | Python | [
"math",
"number theory"
] | 591 | 569 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 1,
"number theory": 1,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 2,107 |
4b78c417abfbbceef51110365c4c0f15 | Koa the Koala and her best friend want to play a game.The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts.Let's describe a move in the game: During his move, a player chooses any element of the arra... | ['dp', 'greedy', 'constructive algorithms', 'bitmasks', 'games', 'math'] | import sys
input=sys.stdin.buffer.readline
t=int(input())
for _ in range(t):
n=int(input())
arr=[int(x) for x in input().split()]
zeroBitCnt=[0 for _ in range(30)] #largest no is 10**9
oneBitCnt=[0 for _ in range(30)] #largest no is 10**9
for x in arr:
for i in range(30):
i... | Python | [
"math",
"games"
] | 920 | 743 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | {
"games": 1,
"geometry": 0,
"graphs": 0,
"math": 1,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 4,748 |
88961744a28d7c890264a39a0a798708 | JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way.First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he defi... | ['implementation', 'greedy', 'math'] | import sys
input = sys.stdin.readline
n, q = map(int, input().split())
s = input()
pref = [0 for i in range(n + 1)]
for i in range(1, n + 1):
pref[i] = pref[i - 1] + (s[i - 1] == '1')
mod = 1000000007
ans = []
for i in range(q):
a, b = map(int, input().split())
k = pref[b] - pref[a - 1];
N = b - a + 1
... | Python | [
"math"
] | 1,615 | 410 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 1,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 713 |
5d76ec741a9d873ce9d7c3ef55eb984c | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya and his friend Vasya play an interesting game. Petya randomly chooses an integer p from the inte... | ['probabilities', 'brute force'] | pl,pr,vl,vr,k=map(int,raw_input().split())
def conv(x):
t=0
while x>1:
t=t*10+(7 if x&1 else 4)
x>>=1
return t
a=filter(lambda x: x>=min(pl,vl) and x<=max(pr,vr),[conv(x) for x in xrange(2,1<<11)])
a.sort()
n,s=len(a),0
a+=[10**10]
def size(a,b,c,d):
return max(0,min(b,d)-max(a,c)+1)
for i in xrange(n-k... | Python | [
"probabilities"
] | 553 | 548 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 1,
"strings": 0,
"trees": 0
} | 1,430 |
5f0b8e6175113142be15ac960e4e9c4c | You are given a matrix a consisting of positive integers. It has n rows and m columns.Construct a matrix b consisting of positive integers. It should have the same size as a, and the following conditions should be met: 1 \le b_{i,j} \le 10^6; b_{i,j} is a multiple of a_{i,j}; the absolute value of the difference betwee... | ['constructive algorithms', 'graphs', 'math', 'number theory'] | a = []
n, m = map(int, input().split())
t = 720720
for _ in range(n):
a.append([])
for j in map(int, input().split()):
a[-1].append(j)
for i in range(n):
for j in range(m):
if ((i + 1) + (j + 1)) % 2 == 1:
a[i][j] = t
else:
a[i][j] **= 4
... | Python | [
"graphs",
"number theory",
"math"
] | 633 | 375 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 1,
"math": 1,
"number theory": 1,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 4,178 |
cce64939977e0956714e06514e6043ff | You are given two strings A and B representing essays of two students who are suspected cheaters. For any two strings C, D we define their similarity score S(C,D) as 4\cdot LCS(C,D) - |C| - |D|, where LCS(C,D) denotes the length of the Longest Common Subsequence of strings C and D. You believe that only some part of th... | ['dp', 'greedy', 'strings'] | n,m = map(int, input().split())
A = input()
B = input()
M = [
[0]*(m+1) for _ in range (n+1)
]
for i in range (1, n+1):
for j in range (1, m+1):
if (A[i-1] == B[j-1]) :
M[i][j] = 2 + M[i-1][j-1]
else:
M[i][j] = max (M[i-1][j]-1, M[i][j-1]-1, M[i-1][j-1]-2, 0) ... | Python | [
"strings"
] | 1,320 | 433 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 1,
"trees": 0
} | 3,155 |
bab40fe0052e2322116c084008c43366 | Connected undirected weighted graph without self-loops and multiple edges is given. Graph contains n vertices and m edges.For each edge (u, v) find the minimal possible weight of the spanning tree that contains the edge (u, v).The weight of the spanning tree is the sum of weights of all edges included in spanning tree. | ['graphs', 'dsu', 'data structures', 'dfs and similar', 'trees'] | def find(u):
if u == par[u] :
return u
par[u] = find(par[u])
return par[u]
def union(u,v):
if len(ev[u]) < len(ev[v]):
u, v = v, u
par[v] = u
for j in ev[v] & ev[u]:
ans[j] -= w
ev[u] ^= ev[v]
n, m = map(int, input().split())
ev = [set() for _ in range(n + 1)]
ans,d... | Python | [
"graphs",
"trees"
] | 320 | 660 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | {
"games": 0,
"geometry": 0,
"graphs": 1,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 1
} | 1,920 |
716965622c7c5fbc78217998d4bfe9ab | A positive number x of length n in base p (2 \le p \le 10^9) is written on the blackboard. The number x is given as a sequence a_1, a_2, \dots, a_n (0 \le a_i < p) — the digits of x in order from left to right (most significant to least significant).Dmitry is very fond of all the digits of this number system, so he ... | ['binary search', 'data structures', 'greedy', 'math', 'number theory'] | from calendar import c
import sys
readline = sys.stdin.readline
t = int(readline())
def good(oadd, arr, p):
add = oadd
range_ = (-1,-1)
max_ = p
min_ = -1
digits = set(arr)
for i in range(len(arr)):
if add == 0:
break
val = (add%p + arr[i])
add... | Python | [
"math",
"number theory"
] | 1,116 | 1,132 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 1,
"number theory": 1,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 4,181 |
f8e64d8b7d10c5ba306480cab2cd3489 | As we communicate, we learn much new information. However, the process of communication takes too much time. It becomes clear if we look at the words we use in our everyday speech.We can list many simple words consisting of many letters: "information", "technologies", "university", "construction", "conservatoire", "ref... | ['graph matchings'] | x,nil=1000000000000000000000000,''
def bfs():
Q=[]
for k,u in enumerate(U):
if pair_u[u]==nil:
dist[u]=0
Q.append(u)
else:dist[u]=x
dist[nil]=x
while Q:
u = Q.pop(0)
if dist[u]<dist[nil]:
for k,v in enumerate(adj[u]):
if... | Python | [
"graphs"
] | 1,592 | 2,231 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 1,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 3,869 |
944ab87c148df0fc59ec0263d6fd8b9f | Vasya wrote down two strings s of length n and t of length m consisting of small English letters 'a' and 'b'. What is more, he knows that string t has a form "abab...", namely there are letters 'a' on odd positions and letters 'b' on even positions.Suddenly in the morning, Vasya found that somebody spoiled his string. ... | ['dp', 'data structures', 'strings'] | match = 0; nonmatch = 0; count = 0
def calc_match(s, t, p):
global match
global nonmatch
global count
if p == len(s)-len(t):
return
if p+len(t) < len(s):
if s[p+len(t)] == '?':
count -= 1
elif s[p+len(t)] == t[-1]:
match -= 1
else:
nonmatch -= 1
match, nonmatch = nonmatch, ... | Python | [
"strings"
] | 997 | 1,209 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 1,
"trees": 0
} | 2,708 |
644f1469a9a9dcdb94144062ba616c59 | You are given a tree consisting of n vertices. A tree is an undirected connected acyclic graph. Example of a tree. You have to paint each vertex into one of three colors. For each vertex, you know the cost of painting it in every color.You have to paint the vertices so that any path consisting of exactly three distinct... | ['dp', 'graphs', 'constructive algorithms', 'implementation', 'trees', 'brute force'] | from collections import defaultdict, deque
from itertools import permutations
class Graph:
def __init__(self):
self.E = {}
self.V = defaultdict(list)
def put(self, v1, v2):
if v1 not in self.E:
self.E[v1] = 1
if v2 not in self.E:
self.E[v2] = 1
... | Python | [
"graphs",
"trees"
] | 859 | 1,955 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | {
"games": 0,
"geometry": 0,
"graphs": 1,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 1
} | 1,371 |
0ab1b97a8d2e0290cda31a3918ff86a4 | Let's call an undirected graph G = (V, E) relatively prime if and only if for each edge (v, u) \in E GCD(v, u) = 1 (the greatest common divisor of v and u is 1). If there is no edge between some pair of vertices v and u then the value of GCD(v, u) doesn't matter. The vertices are numbered from 1 to |V|.Construct a rela... | ['greedy', 'graphs', 'constructive algorithms', 'math', 'brute force'] | from math import gcd
n, m = map(int, input().split())
a = []
for i in range(1, n):
for j in range(i+1, n+1):
if gcd(i, j) == 1:
a.append([i, j])
if len(a) == m:
break
if len(a) == m:
break
if m < n-1 or len(a) != m:
print("Impossible")
else:
print("Possibl... | Python | [
"graphs",
"math"
] | 679 | 365 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 1,
"math": 1,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 2,161 |
0de32a7ccb08538a8d88239245cef50b | Anton likes to play chess, and so does his friend Danik.Once they have played n games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.Now Anton wonders, who won more games, he or Danik? Help him determine this. | ['implementation', 'strings'] | n = int(input())
s = input()
p = 0
q = 0
for x in s:
if x=='A':
p+=1
else:
q+=1
if p>q:
print("Anton")
elif q>p:
print("Danik")
else:
print("Friendship") | Python | [
"strings"
] | 269 | 166 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 1,
"trees": 0
} | 1,220 |
9463dd8f054eeaeeeeaec020932301c3 | A binary tree of n nodes is given. Nodes of the tree are numbered from 1 to n and the root is the node 1. Each node can have no child, only one left child, only one right child, or both children. For convenience, let's denote l_u and r_u as the left and the right child of the node u respectively, l_u = 0 if u does not ... | ['data structures', 'dfs and similar', 'greedy', 'strings', 'trees'] | import sys
I=lambda:[*map(int, sys.stdin.readline().split())]
left = []
right = []
n, k = I()
parents = [-1] * n
s = input()
for i in range(n):
l, r = I()
l -= 1
r -= 1
left.append(l)
right.append(r)
if l >= 0:
parents[l] = i
if r >= 0:
parents[r] = i
covered = [0] * n
covered.append(1)... | Python | [
"graphs",
"strings",
"trees"
] | 1,757 | 1,580 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | {
"games": 0,
"geometry": 0,
"graphs": 1,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 1,
"trees": 1
} | 4,495 |
4b352854008a9378551db60b76d33cfa | PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, if ... | ['greedy', 'games', 'sortings', 'data structures', 'binary search', 'strings'] | n, m = [int(x) for x in raw_input().split()]
wp = set()
for _ in range(n):
wp.add(raw_input().strip())
we = set()
for _ in range(m):
we.add(raw_input().strip())
nb = len(wp & we)
np = len(wp - we)
ne = len(we - wp)
mp = (nb + 1) // 2 + np
me = nb // 2 + ne
print "YES" if mp > me else "NO"
| Python | [
"strings",
"games"
] | 340 | 302 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | {
"games": 1,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 1,
"trees": 0
} | 2,638 |
20cbd67b7bfd8bb201f4113a09aae000 | The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The islands are evenly spaced along a line, numbered from 0 to 30000 from the west to the east. These islands are known to contain many treasures. There are n gems in the Shuseki Islands in total, and the i-th gem is located on island pi.... | ['dp', 'two pointers', 'dfs and similar'] | n, d = map(int, raw_input().split())
gem = [0]*30001
for i in xrange(n):
gem[int(raw_input())] += 1
dp = [[0]*501 for i in xrange(30001)]
for i in xrange(30000, 0, -1):
for j in xrange(max(d-250, 0), d+250):
k = j + 250 - d
m = 0
if i+j <= 30000:
m = max(m, dp[i+j][k])
... | Python | [
"graphs"
] | 1,178 | 504 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 1,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 874 |
256409988d0132de2144e423eaa8bf34 | Let's call a binary string s awesome, if it has at least 1 symbol 1 and length of the string is divisible by the number of 1 in it. In particular, 1, 1010, 111 are awesome, but 0, 110, 01010 aren't.You are given a binary string s. Count the number of its awesome substrings.A string a is a substring of a string b if a c... | ['math', 'strings'] | def add(dic, k ,v):
if not k in dic:
dic[k] = v
else:
dic[k] += v
s = map(int,raw_input())
n = len(s)
psum = [0]*(1+n)
for i in range(n):
psum[i+1] = psum[i] + s[i]
K = 350
dic = [0]*((n+1)*(K+1))
ans = 0
for j in range(1,min(n+1,K+1)):
tmp = []
fo... | Python | [
"math",
"strings"
] | 521 | 1,340 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 1,
"number theory": 0,
"probabilities": 0,
"strings": 1,
"trees": 0
} | 2,746 |
ae10ebd2c99515472fd7ee6646af17b5 | Little Petya loves looking for numbers' divisors. One day Petya came across the following problem:You are given n queries in the form "xi yi". For each query Petya should count how many divisors of number xi divide none of the numbers xi - yi, xi - yi + 1, ..., xi - 1. Help him. | ['implementation', 'number theory'] | #!/usr/bin/env python
"""(c) gorlum0 [at] gmail.com"""
import itertools as it
from sys import stdin
maxn = 10**5
def get_divisors(n, _cache = {}):
if n not in _cache:
divisors = []
for i in xrange(1, int(n**0.5) + 1):
if not n % i:
divisors.extend([i, n//i])
_cac... | Python | [
"number theory"
] | 279 | 892 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 1,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 4,069 |
f4958b4833cafa46fa71357ab1ae41af | You are given an integer n. Check if n has an odd divisor, greater than one (does there exist such a number x (x > 1) that n is divisible by x and x is odd).For example, if n=6, then there is x=3. If n=4, then such a number does not exist. | ['math', 'number theory'] | n=int(input())
for i in range (n):
t=int(input())
while t%2==0:
t/=2
if t>1:
print("YES")
else:
print("NO") | Python | [
"math",
"number theory"
] | 302 | 155 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 1,
"number theory": 1,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 335 |
146c856f8de005fe280e87f67833c063 | Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with n strings. Then the mechanism should be able to process queries of the following type: "Given string s, determine if the memory of the mech... | ['hashing', 'string suffix structures', 'data structures', 'binary search', 'strings'] | from collections import defaultdict
from math import ceil,floor
import sys
memory = set()
mod = 1000000000000000003
p = 3
def hash_(s):
pp = p
result = 0
for ch in s:
result += pp*(ord(ch)-ord('a')-1)
pp = (pp*p)%mod;
result %= mod
return result % mod;
def find(q):
hash_0 ... | Python | [
"strings"
] | 635 | 1,129 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 1,
"trees": 0
} | 1,549 |
19cc504c81bd4f224ecb17f03cfb9bd7 | Let's define the cost of a string s as the number of index pairs i and j (1 \le i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible co... | ['brute force', 'constructive algorithms', 'graphs', 'greedy', 'strings'] | import bisect
import collections
import heapq
import io
import math
import os
import sys
LO = 'abcdefghijklmnopqrstuvwxyz'
Mod = 1000000007
def gcd(x, y):
while y:
x, y = y, x % y
return x
# _input = lambda: io.BytesIO(os.read(0, os.fstat(0).st_size)).readline().decode()
_input = lam... | Python | [
"graphs",
"strings"
] | 456 | 849 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 1,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 1,
"trees": 0
} | 2,586 |
21432a74b063b008cf9f04d2804c1c3f | You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side tha... | ['geometry'] | from math import radians, cos, sin, atan2
def rotate(point, alpha):
x = point[0]
y = point[1]
return (x * cos(alpha) - y * sin(alpha), x * sin(alpha) + y * cos(alpha))
def crs(a, b):
return a[0] * b[1] - a[1] * b[0]
def m(end, start):
return (end[0] - start[0], end[1] - start[1])
def area(poly):... | Python | [
"geometry"
] | 601 | 1,662 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 1,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 951 |
c1f50da1fbe797e7c9b982583a3b02d5 | You are given a string s. You have to reverse it — that is, the first letter should become equal to the last letter before the reversal, the second letter should become equal to the second-to-last letter before the reversal — and so on. For example, if your goal is to reverse the string "abddea", you should get the str... | ['data structures', 'greedy', 'strings'] | import sys
input = sys.stdin.readline
n = int(input())
S = input().strip()
LIST = [[] for i in range(26)]
for i in range(n):
LIST[ord(S[i])-97].append(i)
# for i in LIST:
# print(i)
LEN = n+1
BIT = [0]*(LEN+1)
# print(BIT)
def update(v, w):
while v <= LEN:
BIT[v] += w
v += (v & (-v))... | Python | [
"strings"
] | 520 | 739 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 1,
"trees": 0
} | 3,177 |
482d128baf37eeeb28b874934aded534 | You are given a rooted tree with n nodes, labeled from 1 to n. The tree is rooted at node 1. The parent of the i-th node is p_i. A leaf is node with no children. For a given set of leaves L, let f(L) denote the smallest connected subgraph that contains all leaves L.You would like to partition the leaves such that for a... | ['dp', 'trees'] | from sys import stdin
from itertools import repeat
def main():
n = int(stdin.readline())
p = [-1, -1] + map(int, stdin.readline().split(), repeat(10, n - 1))
ch = [[] for _ in xrange(n + 1)]
for i in xrange(2, n + 1):
ch[p[i]].append(i)
st = []
pu = st.append
po = st.pop
pu(1)
... | Python | [
"trees"
] | 667 | 979 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 1
} | 3,129 |
393ed779ea3ca8fdb63e8de1293eecd3 | You are given an infinite periodic array a0, a1, ..., an - 1, ... with the period of length n. Formally, . A periodic subarray (l, s) (0 ≤ l < n, 1 ≤ s < n) of array a is an infinite periodic array with a period of length s that is a subsegment of array a, starting with position l.A periodic subarray (l, s) is su... | ['number theory'] | # -*- coding: utf-8 -*-
import fractions
from collections import defaultdict
if __name__ == '__main__':
n = int(raw_input())
a = map(int, raw_input().split())
a *= 2
inf = min(a) - 1
a[-1] = inf
result = 0
numbers_by_gcd = defaultdict(list)
for i in xrange(1, n):
numbers_by_gc... | Python | [
"number theory"
] | 682 | 845 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 1,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 4,079 |
973ef4e00b0489261fce852af11aa569 | You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.The GCD of a group of integers is the largest non-negative integer that divides all the integers in the ... | ['greedy', 'number theory', 'probabilities'] | import sys
def gcd(l):
if len(l)==0:
return 0
if len(l)==1:
return l[0]
if len(l)==2:
if l[1]==0:
return l[0]
return gcd([l[1],l[0]%l[1]])
return gcd([gcd(l[:-1]),l[-1]])
def brute_force(l1,l2,l,sol):
if len(l)==0:
g1=gcd(l1)
g2=gcd(l2)
r... | Python | [
"number theory",
"probabilities"
] | 365 | 2,451 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 1,
"probabilities": 1,
"strings": 0,
"trees": 0
} | 2,879 |
9eccd64bb49b74ed0eed3dbf6636f07d | You are given n points on the plane. The polygon formed from all the n points is strictly convex, that is, the polygon is convex, and there are no three collinear points (i.e. lying in the same straight line). The points are numbered from 1 to n, in clockwise order.We define the distance between two points p_1 = (x_1, ... | ['dp', 'geometry'] | n = int(raw_input())
X = []
Y = []
for _ in range(n):
x,y = map(int,raw_input().strip(' ').strip('\n').split(' '))
X.append(x)
Y.append(y)
maxx,minx = max(X),min(X)
maxy,miny = max(Y),min(Y)
ans = -10e18
for i in range(n):
dx = max(maxx-X[i],X[i]-minx)
dy = max(maxy-Y[i],Y[i]-miny)
ans = max(an... | Python | [
"geometry"
] | 1,802 | 454 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 1,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 2,939 |
7ebf821d51383f1633947a3b455190f6 | There are n cities in Berland, each of them has a unique id — an integer from 1 to n, the capital is the one with id 1. Now there is a serious problem in Berland with roads — there are no roads.That is why there was a decision to build n - 1 roads so that there will be exactly one simple path between each pair of citie... | ['constructive algorithms', 'trees', 'graphs'] | n, t, k = map(int, input().split())
a = list(map(int, input().split()))
p = {}
cnt = 0
cur = 1
floor = [[1]]
for ak in a:
arr = [cur+i for i in range(1, ak+1)]
floor.append(arr)
cur += ak
for i in range(1, t+1):
cnt += len(floor[i]) - 1
if i == t:
cnt += 1
... | Python | [
"graphs",
"trees"
] | 1,134 | 788 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | {
"games": 0,
"geometry": 0,
"graphs": 1,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 1
} | 648 |
61ba68bdc7a1e3c60135cbae30d9e088 | You are given n integers a_1, a_2, \dots, a_n, such that for each 1\le i \le n holds i-n\le a_i\le i-1.Find some nonempty subset of these integers, whose sum is equal to 0. It can be shown that such a subset exists under given constraints. If there are several possible subsets with zero-sum, you can find any of them. | ['constructive algorithms', 'graphs', 'dfs and similar', 'math'] | from sys import stdin, stdout
t = input()
inp = stdin.readlines()
out = []
for itr in xrange(t):
n = int(inp[itr << 1].strip())
a = map(int, inp[itr << 1 | 1].strip().split())
found = -1
for i in xrange(n):
if a[i] == 0:
found = i
break
else:
... | Python | [
"graphs",
"math"
] | 348 | 853 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 1,
"math": 1,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 3,243 |
f5de1e9b059bddf8f8dd46c18ce12683 | William has array of n numbers a_1, a_2, \dots, a_n. He can perform the following sequence of operations any number of times: Pick any two items from array a_i and a_j, where a_i must be a multiple of 2 a_i = \frac{a_i}{2} a_j = a_j \cdot 2 Help William find the maximal sum of array elements, which he can get by perfor... | ['greedy', 'implementation', 'math', 'number theory'] | # import math
# for i in range(int(input())):
# n = int(input())
# if n % 2 == 0 and math.sqrt(n//2) == int(math.sqrt(n//2)):
# print("YES")
# elif n % 4 == 0 and math.sqrt(n//4) == int(math.sqrt(n//4)):
# print("YES")
# else:
# print('NO')
##for i in range(int(input())):
## ... | Python | [
"math",
"number theory"
] | 422 | 856 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 1,
"number theory": 1,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 4,845 |
0090979443c294ef6aed7cd09201c9ef | String s of length n is called k-palindrome, if it is a palindrome itself, and its prefix and suffix of length are (k - 1)-palindromes. By definition, any string (even empty) is 0-palindrome.Let's call the palindrome degree of string s such a maximum number k, for which s is k-palindrome. For example, "abaaba" has degr... | ['hashing', 'strings'] | T = raw_input()
P = T + '#' + T[::-1]
def compute_prefix_func(P):
m = len(P)
pi = [0] * m
for q in range(1, m):
k = pi[q-1]
while k > 0 and P[k] != P[q]:
k = pi[k-1]
if P[k] == P[q]:
k += 1
pi[q] = k
return pi
pi = compute_prefix_func(P)
pos = ... | Python | [
"strings"
] | 435 | 513 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 1,
"trees": 0
} | 522 |
f2142bc2f44e5d8b77f8561c29038a73 | Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are... | ['greedy', 'games'] | s, a = list(map(int, input().rstrip().split()))
mat = []
l = []
for i in range(s):
b = list(map(int, input().rstrip().split()))
l += [min(b)]
print(max(l)) | Python | [
"games"
] | 904 | 163 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 1,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 4,308 |
b5d0870ee99e06e8b99c74aeb8e81e01 | Limak is a little polar bear. He likes nice strings — strings of length n, consisting of lowercase English letters only.The distance between two letters is defined as the difference between their positions in the alphabet. For example, , and .Also, the distance between two nice strings is defined as the sum of distance... | ['greedy', 'strings'] | import sys
n, k = map(int, input().split())
line = list(input())
for i in range(n):
if ord('z') - ord(line[i]) >= ord(line[i]) - ord('a'):
s = ord('z') - ord(line[i])
if s >= k:
line[i] = chr(ord(line[i])+k)
print(''.join(line))
sys.exit()
else:
... | Python | [
"strings"
] | 805 | 587 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 1,
"trees": 0
} | 3,361 |
2b757fa66ce89046fe18cdfdeafa6660 | You have two positive integers a and b.You can perform two kinds of operations: a = \lfloor \frac{a}{b} \rfloor (replace a with the integer part of the division between a and b) b=b+1 (increase b by 1) Find the minimum number of operations required to make a=0. | ['brute force', 'greedy', 'math', 'number theory'] | def count_divs(a, b):
count = 0
while a > 0:
a = a // b
count += 1
return count
t = int(input())
for _ in range(t):
a, b = map(int, input().split())
b_additions = 0
if b == 1:
b = 2
b_additions += 1
prev_res = count_divs(a, b) + b_additions
... | Python | [
"math",
"number theory"
] | 323 | 533 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 1,
"number theory": 1,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 788 |
14da0cdf2939c796704ec548f49efb87 | There are n lights aligned in a row. These lights are numbered 1 to n from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light on (this light should be switched off at that moment) if there's at least one adjacent light which is alrea... | ['combinatorics', 'number theory'] | import math
def solve( n, list1):
list1.sort()
inf = int(1e9 + 7)
t1 = [list1[0] - 1, n - list1[-1]]
t2 = []
for i in range(1, len(list1)):
t2.append((list1[i] - list1[i - 1] - 1))
num1 = 1
for i in range(n - len(list1)):
num1 = num1 * (i + 1)
num1 = num1 % inf
... | Python | [
"math",
"number theory"
] | 525 | 939 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 1,
"number theory": 1,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 2,530 |
adbfdb0d2fd9e4eb48a27d43f401f0e0 | One popular website developed an unusual username editing procedure. One can change the username only by deleting some characters from it: to change the current name s, a user can pick number p and character c and delete the p-th occurrence of character c from the name. After the user changed his name, he can't undo th... | ['*special', 'data structures', 'binary search', 'brute force', 'strings'] | #copied... idea
def main():
mode="filee"
if mode=="file":f=open("test.txt","r")
get = lambda :[int(x) for x in (f.readline() if mode=="file" else input()).split()]
gets = lambda :[str(x) for x in (f.readline() if mode=="file" else input()).split()]
[k]=get()
[g]=gets()
h = g*k
h = list(... | Python | [
"strings"
] | 673 | 662 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 1,
"trees": 0
} | 3,452 |
2fc19c3c9604e746a17a63758060c5d7 | A tree is a connected graph that doesn't contain any cycles.The distance between two vertices of a tree is the length (in edges) of the shortest path between these vertices.You are given a tree with n vertices and a positive number k. Find the number of distinct pairs of the vertices which have a distance of exactly k ... | ['dp', 'dfs and similar', 'trees'] | n, k = map(int, input().split())
t, q = [[] for i in range(n + 1)], [1]
for j in range(n - 1):
a, b = map(int, input().split())
t[a].append(b)
t[b].append(a)
for x in q:
for y in t[x]: t[y].remove(x)
q.extend(t[x])
q.reverse()
a, s = {}, 0
for x in q:
a[x] = [1]
u = len(a[x])
for y i... | Python | [
"graphs",
"trees"
] | 403 | 660 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | {
"games": 0,
"geometry": 0,
"graphs": 1,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 1
} | 1,169 |
e83a8bfabd7ea096fae66dcc8c243be7 | The German University in Cairo (GUC) dorm houses are numbered from 1 to n. Underground water pipes connect these houses together. Each pipe has certain direction (water can flow only in this direction and not vice versa), and diameter (which characterizes the maximal amount of water it can handle).For each house, there... | ['dfs and similar', 'graphs'] | houses, pipes = [int(x) for x in input().strip().split()]
houseToHouseDict = {}
pipeDict = {}
outgoingList = []
incomingList = []
maxFlow = 0
def DFSmaxPipe(origin):
end = []
lowestDiam = maxFlow
while (origin in houseToHouseDict):
diam = pipeDict[origin]
if diam < lowestDiam:
lowestDiam = diam
origin = h... | Python | [
"graphs"
] | 1,325 | 970 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 1,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 4,910 |
0054f9e2549900487d78fae9aa4c2d65 | Maria participates in a bicycle race.The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west.Let's introduce a system of coordinates, directing the Ox axis from west to east, and the Oy... | ['implementation', 'geometry', 'math'] | print ((int(input()) - 4)//2) | Python | [
"math",
"geometry"
] | 1,272 | 29 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 1,
"graphs": 0,
"math": 1,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 3,260 |
d01f153d0049c22a21e321d5c4fbece9 | There is a forest that we model as a plane and live n rare animals. Animal number i has its lair in the point (x_{i}, y_{i}). In order to protect them, a decision to build a nature reserve has been made.The reserve must have a form of a circle containing all lairs. There is also a straight river flowing through the for... | ['binary search', 'geometry', 'ternary search'] |
l , r =-100000000, 1000000000
def check(mid):
mx = 0
for i in range(n):
x,y = x1[i],y1[i]
mx = max (mx ,(x1[i] - mid) ** 2 / (2 * y1[i]) + (y1[i] / 2))
return mx
n = int(input())
count1 = 0
count2 = 0
x1 = []
y1 = []
for i in range(n):
a,b = map(int,input().split())
if b>=0:
... | Python | [
"geometry"
] | 806 | 627 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 1,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 2,424 |
fc75935b149cf9f4f2ddb9e2ac01d1c2 | There are n logs, the i-th log has a length of a_i meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into 2 pieces. If the length of th... | ['games', 'implementation', 'math'] | num_cases = int(input())
for i in range(num_cases):
count = 0
num_logs = int(input())
logs = [int(log) for log in input().split(' ')]
for log in logs:
count += log - 1
if count % 2 == 0:
print('maomao90')
else:
print('errorgorn')
| Python | [
"math",
"games"
] | 846 | 279 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | {
"games": 1,
"geometry": 0,
"graphs": 0,
"math": 1,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,765 |
8705adec1bea1f898db1ca533e15d5c3 | Polycarp has a string s. Polycarp performs the following actions until the string s is empty (t is initially an empty string): he adds to the right to the string t the string s, i.e. he does t = t + s, where t + s is a concatenation of the strings t and s; he selects an arbitrary letter of s and removes from s all its ... | ['binary search', 'implementation', 'sortings', 'strings'] | T = int(input())
for t in range(T):
t = input()
n = len(t)
# find first character with no occurences to the right
s = set()
r = []
for i in t[::-1]:
if i not in s:
r.append(i)
s.add(i)
done = r[::-1]
#print(done)
v = 0
for i in ... | Python | [
"strings"
] | 1,207 | 775 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 1,
"trees": 0
} | 3,182 |
f1b4048e5cd2aa0a533af9d08f7d58ba | This is an interactive problem.There exists a matrix a of size n \times m (n rows and m columns), you know only numbers n and m. The rows of the matrix are numbered from 1 to n from top to bottom, and columns of the matrix are numbered from 1 to m from left to right. The cell on the intersection of the x-th row and the... | ['bitmasks', 'interactive', 'number theory'] | import sys
input = sys.stdin.readline
def solve():
r, c = map(int, input().split())
r1 = r
r2 = r
i = 2
while True:
if r2 % i == 0:
while r2 % i == 0:
r2 //= i
while r1 % i == 0:
#print('r',i)
if i == 2:
print('?',r1//i,c,1,1,r1//i+1,1)
sys.stdout.flush()
if i... | Python | [
"number theory"
] | 1,717 | 1,816 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 1,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,030 |
1277cf54097813377bf37be445c06e7e | You are given an undirected graph consisting of n vertices and n edges. It is guaranteed that the given graph is connected (i. e. it is possible to reach any vertex from any other vertex) and there are no self-loops and multiple edges in the graph.Your task is to calculate the number of simple paths of length at least ... | ['combinatorics', 'dfs and similar', 'trees', 'graphs'] | from collections import deque
from sys import stdin, gettrace
if gettrace():
inputi = input
else:
def input():
return next(stdin)[:-1]
def inputi():
return stdin.buffer.readline()
def readGraph(n, m):
adj = [[] for _ in range(n)]
for _ in range(m):
u,v = map(int, inputi()... | Python | [
"math",
"graphs",
"trees"
] | 929 | 1,830 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 1 | {
"games": 0,
"geometry": 0,
"graphs": 1,
"math": 1,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 1
} | 1,550 |
677972c7d86ce9fd0808105331f77fe0 | A bow adorned with nameless flowers that bears the earnest hopes of an equally nameless person.You have obtained the elegant bow known as the Windblume Ode. Inscribed in the weapon is an array of n (n \ge 3) positive distinct integers (i.e. different, no duplicates are allowed).Find the largest subset (i.e. having the ... | ['math', 'number theory'] | tt = int(input())
fa = []
n = 500000
for i in range(n + 1):
fa.append(i)
fa[1] = 0
i = 2
while i <= n:
if fa[i] != 0:
j = i + i
while j <= n:
fa[j] = 0
j = j + i
i += 1
fa = set(fa)
fa.remove(0)
for i in range(tt):
ar = []
f = int(input())
... | Python | [
"math",
"number theory"
] | 775 | 1,556 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 1,
"number theory": 1,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,917 |
a37a92db3626b46c7af79e3eb991983a | For a vector \vec{v} = (x, y), define |v| = \sqrt{x^2 + y^2}.Allen had a bit too much to drink at the bar, which is at the origin. There are n vectors \vec{v_1}, \vec{v_2}, \cdots, \vec{v_n}. Allen will make n moves. As Allen's sense of direction is impaired, during the i-th move he will either move in the direction \v... | ['geometry', 'greedy', 'math', 'sortings', 'data structures', 'brute force'] | n=input()
x=0
y=0
def dis(x,y,a,b):
return (x-a)**2+(y-b)**2
lst=[]
ans=[0]*n
lst2=[]
lst4=[]
ans2=[0]*n
for i in range(0,n):
a,b=map(int,raw_input().split())
lst4.append((a,b))
lst.append((a*a,a,b,i))
lst2.append((b*b,a,b,i))
lst.sort(reverse=True)
lst2.sort(reverse=True)
for i in range(0,n):
a=lst[i][1]
... | Python | [
"math",
"geometry"
] | 794 | 1,008 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 1,
"graphs": 0,
"math": 1,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,950 |
6da720d47a627df3afb876253b1cbe58 | "Eat a beaver, save a tree!" — That will be the motto of ecologists' urgent meeting in Beaverley Hills.And the whole point is that the population of beavers on the Earth has reached incredible sizes! Each day their number increases in several times and they don't even realize how much their unhealthy obsession with tre... | ['dp', 'greedy', 'dsu', 'dfs and similar', 'trees'] | n = input()+1
k = [0]+map(int,raw_input().split())
d = [[] for _ in xrange(n)]
for _ in xrange(n-2):
a,b = [int(x) for x in raw_input().split()]
d[a].append(b)
d[b].append(a)
s = input()
q = [0]
d[0] = [s]
v = [True]+[False]*n
for x in q:
for u in d[x]:
if not v[u]:
v[u]=True
... | Python | [
"graphs",
"trees"
] | 2,332 | 730 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | {
"games": 0,
"geometry": 0,
"graphs": 1,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 1
} | 1,743 |
0afd29ef1b720d2baad2f1c91a583933 | You are given a positive integer D. Let's build the following graph from it: each vertex is a divisor of D (not necessarily prime, 1 and D itself are also included); two vertices x and y (x > y) have an undirected edge between them if x is divisible by y and \frac x y is a prime; the weight of an edge is the number ... | ['greedy', 'graphs', 'combinatorics', 'number theory', 'math'] | import sys, __pypy__
range = xrange
input = raw_input
MOD = 998244353
mulmod = __pypy__.intop.int_mulmod
inp = [int(x) for x in sys.stdin.read().split()]; ii = 0
D = inp[ii]; ii += 1
q = inp[ii]; ii += 1
U = inp[ii + 0: ii + 2 * q: 2]
V = inp[ii + 1: ii + 2 * q: 2]
Pdiv = []
if D & 1 == 0:
Pdiv.append(2)
w... | Python | [
"graphs",
"number theory",
"math"
] | 1,678 | 1,228 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 1,
"math": 1,
"number theory": 1,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 3,424 |
29d4ca13888c0e172dde315b66380fe5 | Fifa and Fafa are sharing a flat. Fifa loves video games and wants to download a new soccer game. Unfortunately, Fafa heavily uses the internet which consumes the quota. Fifa can access the internet through his Wi-Fi access point. This access point can be accessed within a range of r meters (this range can be chosen by... | ['geometry'] | R,x1,y1,x2,y2=map(int,input().split())
s=((x1-x2)**2+(y1-y2)**2)**(0.5)
sin=0
cos=1
def dist(x1,x2,y1,y2):
return ((x1-x2)**2+(y1-y2)**2)**(0.5)
if (s>R):
print(x1,y1,R)
else:
r=(s+R)/2
if s!=0:
sin=((y2-y1)/s)
cos=((x2-x1)/s)
xpos,ypos=x2+r*cos,y2+r*sin
xneg,yneg=x2-r*cos,y2-r*... | Python | [
"geometry"
] | 878 | 468 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 1,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,113 |
d62d0a9d827444a671029407f6a4ad39 | You are given a string, consisting of lowercase Latin letters.A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions (1, 2) — "ab" and (2, 3) — "ba". Letters 'a' and 'z' aren't considered neighbouri... | ['greedy', 'implementation', 'sortings', 'dfs and similar', 'strings'] | import collections
def add1(c):
return chr(ord(c)+1)
def sv():
m = collections.defaultdict(int)
for c in input():
m[c] += 1
m = list(m.items())
m.sort()
if len(m) == 2 and add1(m[0][0]) == m[1][0]: return False
if len(m) == 3:
if add1(m[0][0]) != m[1][0]:
pass
... | Python | [
"graphs",
"strings"
] | 689 | 676 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 1,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 1,
"trees": 0
} | 581 |
bd61ae3c19274f47b981b8bd5e786375 | Alina has discovered a weird language, which contains only 4 words: \texttt{A}, \texttt{B}, \texttt{AB}, \texttt{BA}. It also turned out that there are no spaces in this language: a sentence is written by just concatenating its words into a single string.Alina has found one such sentence s and she is curious: is it pos... | ['constructive algorithms', 'greedy', 'sortings', 'strings', 'two pointers'] | # test.py
# main.py
# .---.---.---.---.---.---.---.---.---.---.---.---.---.-------.
# |1/2| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | + | ' | <- |
# |---'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-----|
# | ->| | Q | W | E | R | T | Y | U | I | O | P | ] | ^ | |
# |-----'.--'.--'.--'.--'.--'.--'... | Python | [
"strings"
] | 805 | 8,895 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 1,
"trees": 0
} | 1,554 |
d629d09782a7af0acc359173ac4b4f0a | You are given two strings s and t. The string s consists of lowercase Latin letters and at most one wildcard character '*', the string t consists only of lowercase Latin letters. The length of the string s equals n, the length of the string t equals m.The wildcard character '*' in the string s (if any) can be replaced ... | ['implementation', 'brute force', 'strings'] | n,m=map(int,input().split())
s=input()
t=input()
if(m<n-1):
print('NO')
else:
if('*' in s):
i=0
f=1
while(i<n and s[i]!='*'):
if(s[i]!=t[i]):
f=0
break
else:
i=i+1
if(f==1):
i=n-1
j=m-... | Python | [
"strings"
] | 950 | 734 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 1,
"trees": 0
} | 3,520 |
b116ab1cae8d64608641b339b8654e21 | There is an undirected tree of n vertices, connected by n-1 bidirectional edges. There is also a snake stuck inside of this tree. Its head is at vertex a and its tail is at vertex b. The snake's body occupies all vertices on the unique simple path between a and b.The snake wants to know if it can reverse itself — that ... | ['dp', 'greedy', 'two pointers', 'dfs and similar', 'trees'] | from sys import stdin
import itertools
input = stdin.readline
def getint(): return int(input())
def getints(): return list(map(int, input().split()))
def getint1(): return list(map(lambda x: int(x) - 1, input().split()))
def getstr(): return input()[:-1]
def solve():
n, a, b = getint1()
n += 1
adj = [[] f... | Python | [
"graphs",
"trees"
] | 1,275 | 4,695 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | {
"games": 0,
"geometry": 0,
"graphs": 1,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 1
} | 2,099 |
994a9cb52cf0fdab72be068eab1b27ef | Welcome to Rockport City!It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the greatest common divisor (GCD) of ... | ['greedy', 'math', 'number theory'] | from math import gcd
tt = int(input())
for t in range(tt):
a,b = map(int, input().split())
MAX = max(a,b)
MIN = min(a,b)
if gcd(a,b) == MAX-MIN:
print(MAX-MIN,0)
elif a==b:
print(0,0)
else:
d = MAX-MIN
if d>0:
f = MAX-(MAX%d)
s = ... | Python | [
"math",
"number theory"
] | 903 | 368 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 1,
"number theory": 1,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,833 |
cf1eb164c4c970fd398ef9e98b4c07b1 | In Aramic language words can only represent objects.Words in Aramic have special properties: A word is a root if it does not contain the same letter more than once. A root and all its permutations represent the same object. The root x of a word y is the word that contains all letters that appear in y in a way that each... | ['implementation', 'strings'] | n = int(raw_input().strip())
x = raw_input().split(' ')
res = len(set([''.join(sorted(set(i))) for i in x]))
print res | Python | [
"strings"
] | 629 | 118 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 1,
"trees": 0
} | 918 |
607dd33e61f57caced7b61ca8001e871 | You are given three strings (s1, s2, s3). For each integer l (1 ≤ l ≤ min(|s1|, |s2|, |s3|) you need to find how many triples (i1, i2, i3) exist such that three strings sk[ik... ik + l - 1] (k = 1, 2, 3) are pairwise equal. Print all found numbers modulo 1000000007 (109 + 7).See notes if you are not sure about some of ... | ['data structures', 'dsu', 'string suffix structures', 'strings'] |
MOD = 1000000007
oo = int(2e9)
class Node:
def __init__(self, p, l = oo):
self.spos = p
self.slink = 0
self.length = l
self.next_node = [0 for _ in range(28)]
#Ukkonen
class SuffixTree:
def __init__(self, s):
self.nodes = [Node(0)]
self.s = []
self.po... | Python | [
"graphs",
"strings"
] | 356 | 3,820 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 1,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 1,
"trees": 0
} | 4,501 |
c54042eebaef01783a74d31521db9baa | Connect the countless points with lines, till we reach the faraway yonder.There are n points on a coordinate plane, the i-th of which being (i, yi).Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes throug... | ['geometry', 'brute force'] | n=int(input())
d=list(map(int,input().split()))
a,b,c=d[:3]
if b-a==c-b:
e=b-a
f=0
for i in range(3,n):
if (d[i]-c)/(i-2)!=e:
if f and(d[i]-g)/(i-h)!=e:print('No');exit()
else:g,h=d[i],i;f=1
print('Yes'if f else'No')
else:
p1=p2=p3=1
e,f,g=b-a,c,2
h,j,k=c-b,a,... | Python | [
"geometry"
] | 352 | 567 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 1,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 3,181 |
ff5b3d5fa52c2505556454011e8a0f58 | Several years ago Tolya had n computer games and at some point of time he decided to burn them to CD. After that he wrote down the names of the games one after another in a circle on the CD in clockwise order. The names were distinct, the length of each name was equal to k. The names didn't overlap.Thus, there is a cyc... | ['data structures', 'string suffix structures', 'hashing', 'strings'] | n, k = map(int, raw_input().split())
s = raw_input()
g = int(raw_input())
games = [raw_input() for i in range(g)]
MOD_1 = 1000000007
BASE_1 = 31
MOD_2 = 1000000409
BASE_2 = 29
hashes_1 = []
hashes_2 = []
hash_inv = {}
game_inv = {}
for i, game in enumerate(games):
h_1 = 0
h_2 = 0
for c in game:
h... | Python | [
"strings"
] | 683 | 1,876 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 1,
"trees": 0
} | 1,511 |
094a880e93a2adfbcb6dcc2b5f043bab | You have an array a consisting of n integers. Each integer from 1 to n appears exactly once in this array.For some indices i (1 ≤ i ≤ n - 1) it is possible to swap i-th element with (i + 1)-th, for other indices it is not possible. You may perform any number of swapping operations any order. There is no limit on the nu... | ['greedy', 'two pointers', 'math', 'sortings', 'dfs and similar'] | def main():
n=input()
l=map(long,raw_input().split())
ar=map(int," ".join(raw_input()).split())
r=[0]*(n)
r[0]=ar[0]
for i in xrange(1,n-1):
r[i]=ar[i]+r[i-1]
f=[0]*n
for i in xrange(n-2,-1,-1):
f[i]=ar[i]+f[i+1]
r[n-1]=r[n-2]
#print r
for i in xrange(... | Python | [
"math",
"graphs"
] | 505 | 515 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 1,
"math": 1,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,889 |
4f8be14ad3242c2832f37cca8feaeec0 | In Fire City, there are n intersections and m one-way roads. The i-th road goes from intersection a_i to b_i and has length l_i miles. There are q cars that may only drive along those roads. The i-th car starts at intersection v_i and has an odometer that begins at s_i, increments for each mile driven, and resets to 0 ... | ['dfs and similar', 'graphs', 'math', 'number theory'] | def find_SCC(graph):
SCC, S, P = [], [], []
depth = [0] * len(graph)
stack = list(range(len(graph)))
while stack:
node = stack.pop()
if node < 0:
d = depth[~node] - 1
if P[-1] > d:
SCC.append(S[d:])
del S[d:], P[-1]
... | Python | [
"graphs",
"number theory",
"math"
] | 815 | 1,921 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 1,
"math": 1,
"number theory": 1,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 4,440 |
1670a3d7dba83e29e98f0ac6fe4acb18 | Berland scientists know that the Old Berland language had exactly n words. Those words had lengths of l1, l2, ..., ln letters. Every word consisted of two letters, 0 and 1. Ancient Berland people spoke quickly and didn’t make pauses between the words, but at the same time they could always understand each other perfect... | ['data structures', 'greedy', 'trees'] | import sys
sys.setrecursionlimit(1050)
class Node:
def __init__(self, depth, parent):
self.depth = depth
self.parent = parent
self.left = None
self.right = None
self.leaf = False
def __str__(self):
return 'depth = %d, left? %s, right? %s' % (self.depth,
self.left != None, self.right... | Python | [
"trees"
] | 632 | 1,332 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 1
} | 2,692 |
15aa3adb14c17023f71eec11e1c32efe | Xenia has a set of weights and pan scales. Each weight has an integer weight from 1 to 10 kilos. Xenia is going to play with scales and weights a little. For this, she puts weights on the scalepans, one by one. The first weight goes on the left scalepan, the second weight goes on the right scalepan, the third one goes ... | ['dp', 'greedy', 'graphs', 'constructive algorithms', 'shortest paths', 'dfs and similar'] | def solve(a, b, m, M, weights, last, solution):
# print(a,b,m,M,weights, solution)
if (a-b > 10):
return False
if m == M:
print("YES")
print(*solution)
return True
for w in weights:
if w != last and b+w > a:
solution[m] = w
if (solve(b+w, a, m+1, M, weights, w, solution)):
... | Python | [
"graphs"
] | 1,187 | 634 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 1,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,766 |
a764aa5727b53a6be78b1e172f670c86 | As a teacher, Riko Hakozaki often needs to help her students with problems from various subjects. Today, she is asked a programming task which goes as follows.You are given an undirected complete graph with n nodes, where some edges are pre-assigned with a positive weight while the rest aren't. You need to assign all u... | ['bitmasks', 'brute force', 'data structures', 'dfs and similar', 'dsu', 'graphs', 'greedy', 'trees'] | import sys, os
if os.environ['USERNAME']=='kissz':
inp=open('in3.txt','r').readline
def debug(*args):
print(*args,file=sys.stderr)
else:
inp=sys.stdin.readline
def debug(*args):
pass
# SCRIPT STARTS HERE
def getp(i):
L=[]
while parent[i]>=0:
L+=[i]
... | Python | [
"graphs",
"trees"
] | 1,000 | 2,301 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | {
"games": 0,
"geometry": 0,
"graphs": 1,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 1
} | 417 |
ccf4ac6b61b48604b7d9f49b7daaeb0f | You are playing a computer game. In this game, you have to fight n monsters.To defend from monsters, you need a shield. Each shield has two parameters: its current durability a and its defence rating b. Each monster has only one parameter: its strength d.When you fight a monster with strength d while having a shield wi... | ['combinatorics', 'binary search', 'probabilities'] |
import sys;input=sys.stdin.readline
mod = 998244353
#mod=10**9+7
def frac(limit):
frac = [1]*limit
for i in range(2,limit):
frac[i] = i * frac[i-1]%mod
fraci = [None]*limit
fraci[-1] = pow(frac[-1], mod -2, mod)
for i in range(-2, -limit-1, -1):
fraci[i] = fraci[i+1] * (limit + i + ... | Python | [
"math",
"probabilities"
] | 1,112 | 1,246 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 1,
"number theory": 0,
"probabilities": 1,
"strings": 0,
"trees": 0
} | 1,297 |
4841cbc3d3ef29929690b78e30fbf22e | In order to write a string, Atilla needs to first learn all letters that are contained in the string.Atilla needs to write a message which can be represented as a string s. He asks you what is the minimum alphabet size required so that one can write this message.The alphabet of size x (1 \leq x \leq 26) contains only t... | ['greedy', 'implementation', 'strings'] | import sys
raw_input = iter(sys.stdin.read().splitlines()).next
def solution():
n = int(raw_input())
s = raw_input()
return ord(max(s))-ord('a')+1
for case in xrange(int(raw_input())):
print '%s' % solution() | Python | [
"strings"
] | 513 | 235 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 1,
"trees": 0
} | 2,286 |
5139d222fbbfa70d50e990f5d6c92726 | You are given an array a consisting of n integers.Your task is to determine if a has some subsequence of length at least 3 that is a palindrome.Recall that an array b is called a subsequence of the array a if b can be obtained by removing some (possibly, zero) elements from a (not necessarily consecutive) without chang... | ['brute force', 'strings'] | for test in range(int(input())):
n=int(input())
l=list(map(int,input().split()))
l.append(10000000009)
c=0
for i in range(n-2):
if l[i] in l[i+2:]:
print("YES")
c=1
break
if(c==0):
print("NO")
| Python | [
"strings"
] | 993 | 275 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 1,
"trees": 0
} | 259 |
3634a3367a1f05d1b3e8e4369e8427fb | For the multiset of positive integers s=\{s_1,s_2,\dots,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow: \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x. \textrm{lcm}(s) is the minimum positive integer x, that divisible on all inte... | ['number theory', 'math'] | def gcd(a,b):
while b: a,b=b,a%b
return a
def rwh_primes2(n):
# https://stackoverflow.com/questions/2068372/fastest-way-to-list-all-primes-below-n-in-python/3035188#3035188
""" Input n>=6, Returns a list of primes, 2 <= p < n """
correction = (n%6>1)
n = {0:n,1:n-1,2:n+4,3:n+3,4:n+2,5:n+1}[n%6]
s... | Python | [
"math",
"number theory"
] | 849 | 1,057 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 1,
"number theory": 1,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 3,572 |
f73370c8ea81b8b81a79701d8e2ec785 | BCPC stands for Byteforces Collegiate Programming Contest, and is the most famous competition in Byteforces.BCPC is a team competition. Each team is composed by a coach and three contestants. Blenda is the coach of the Bit State University(BSU), and she is very strict selecting the members of her team. In BSU there are... | ['two pointers', 'binary search', 'geometry'] | from sys import stdin
from itertools import repeat
from math import cos, sin, atan2
def main():
n, c, d = map(int, stdin.readline().split())
dat = map(int, stdin.read().split(), repeat(10, 2 * n))
a = []
aa = a.append
for i in xrange(n):
x, y = dat[i*2] - c, dat[i*2+1] - d
t = atan2(... | Python | [
"geometry"
] | 1,649 | 1,369 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 1,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 113 |
864593dc3911206b627dab711025e116 | Edogawa Conan got tired of solving cases, and invited his friend, Professor Agasa, over. They decided to play a game of cards. Conan has n cards, and the i-th card has a number ai written on it.They take turns playing, starting with Conan. In each turn, the player chooses a card and removes it. Also, he removes all car... | ['implementation', 'greedy', 'games'] | n = int(input())
a = [0] * 100001
for x in map(int, input().split()):
a[x]+=1
print('Conan' if 1 in map(lambda x: x%2, a) else 'Agasa')
| Python | [
"games"
] | 685 | 144 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 1,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,194 |
c8f63597670a7b751822f8cef01b8ba3 | To learn as soon as possible the latest news about their favourite fundamentally new operating system, BolgenOS community from Nizhni Tagil decided to develop a scheme. According to this scheme a community member, who is the first to learn the news, calls some other member, the latter, in his turn, calls some third mem... | ['dfs and similar', 'trees', 'graphs'] | #!/usr/bin/env python3
# Read data
n = int(input())
f = map(int, input().split())
f = [d-1 for d in f] # Make indices 0-based
# Determine in-degree of all the nodes
indegree = [0 for i in range(n)]
for i in range(n):
indegree[f[i]] += 1
# Nodes with indegree = 0 will need to be an end-point of a new edge
endpoints... | Python | [
"graphs",
"trees"
] | 902 | 1,548 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | {
"games": 0,
"geometry": 0,
"graphs": 1,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 1
} | 57 |
7b394dbced93130f83d61f7e325a980a | This is the easy version of the problem. The only difference is that in this version there are no "remove" queries.Initially you have a set containing one element — 0. You need to handle q queries of the following types:+ x — add the integer x to the set. It is guaranteed that this integer is not contained in the set; ... | ['brute force', 'data structures', 'implementation', 'number theory'] | # Code by B3D
# Love
from math import *
from collections import *
import io, os
import sys
from bisect import *
from heapq import *
from itertools import permutations
from functools import *
import re
import sys
import threading
# from temps import *
MOD = 998244353
# sys.setrecursionlimit(10**6... | Python | [
"number theory"
] | 578 | 2,757 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 1,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,318 |
ce4443581d4ee12db6607695cd567070 | You are given a string s, consisting of n lowercase Latin letters.A substring of string s is a continuous segment of letters from s. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length n diverse if and only if... | ['implementation', 'strings'] | n=input()
s=raw_input()
if len(set(s))==1:
print "NO"
else:
print "YES"
for i in range(n-1):
if s[i]!=s[i+1]:
print s[i]+s[i+1]
break
| Python | [
"strings"
] | 691 | 147 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 1,
"trees": 0
} | 687 |
8eda3e355d2823b0c8f92e1628dc1b69 | Vasya lagged behind at the University and got to the battlefield. Just joking! He's simply playing some computer game. The field is a flat platform with n trenches dug on it. The trenches are segments on a plane parallel to the coordinate axes. No two trenches intersect.There is a huge enemy laser far away from Vasya. ... | ['graphs', 'implementation', 'geometry', 'shortest paths'] | import math
R = lambda: map(int, raw_input().split())
a, b = R()
Ax, Ay, Bx, By = R()
n = R()[0]
x1, y1, x2, y2 = [Ax],[Ay],[Ax],[Ay]
for i in range(n):
_t1, _t2, _t3, _t4 = R()
if (_t1 > _t3): _t1, _t3 = _t3, _t1
if (_t2 > _t4):_t2, _t4 = _t4, _t2
x1.append(_t1)
y1.append(_t2)
x2.append(_t3)
y2.append(_t4)
... | Python | [
"graphs",
"geometry"
] | 1,535 | 2,180 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 1,
"graphs": 1,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 1,078 |
61bb5f2b315eddf2e658e3f54d8f43b8 | It's Petya's birthday party and his friends have presented him a brand new "Electrician-n" construction set, which they are sure he will enjoy as he always does with weird puzzles they give him.Construction set "Electrician-n" consists of 2n - 1 wires and 2n light bulbs. Each bulb has its own unique index that is an in... | ['graphs', 'constructive algorithms', 'math', 'sortings', 'trees'] | # https://codeforces.com/contest/1214/problem/E
n = int(input())
d = map(int, input().split())
d = [[2*i+1, di] for i, di in enumerate(d)]
d = sorted(d, key=lambda x:x[1], reverse = True)
edge = []
arr = [x[0] for x in d]
for i, [x, d_] in enumerate(d):
if i + d_ - 1 == len(arr) - 1:
arr.append(x+1)
... | Python | [
"graphs",
"math",
"trees"
] | 1,563 | 497 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 1 | {
"games": 0,
"geometry": 0,
"graphs": 1,
"math": 1,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 1
} | 2,259 |
58ee86d4913787582ccdb54073656dc0 | A string s of length n, consisting of lowercase letters of the English alphabet, is given.You must choose some number k between 0 and n. Then, you select k characters of s and permute them however you want. In this process, the positions of the other n-k characters remain unchanged. You have to perform this operation e... | ['sortings', 'strings'] | for i in range(int(input())):
n=int(input())
s=[i for i in input()]
t=sorted(s)
print(sum([int(s[i]!=t[i]) for i in range(n)]))
| Python | [
"strings"
] | 763 | 149 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 1,
"trees": 0
} | 4,334 |
463d4e6badd3aa110cc87ae7049214b4 | The Romans have attacked again. This time they are much more than the Persians but Shapur is ready to defeat them. He says: "A lion is never afraid of a hundred sheep". Nevertheless Shapur has to find weaknesses in the Roman army to defeat them. So he gives the army a weakness number.In Shapur's opinion the weakness of... | ['data structures', 'trees'] | def fast2():
import os, sys, atexit
from cStringIO import StringIO as BytesIO
# range = xrange
sys.stdout = BytesIO()
atexit.register(lambda: os.write(1, sys.stdout.getvalue()))
return BytesIO(os.read(0, os.fstat(0).st_size)).readline
class order_tree:
def __init__(self, n):
self.t... | Python | [
"trees"
] | 602 | 1,308 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 1
} | 4,766 |
2cb1e7e4d25f624da934bce5c628a7ee | Petya has recently started working as a programmer in the IT city company that develops computer games.Besides game mechanics implementation to create a game it is necessary to create tool programs that can be used by game designers to create game levels. Petya's first assignment is to create a tool that allows to pain... | ['geometry'] | import math
def main():
x, y, vx, vy, a, b, c, d = map(int, input().split())
len = math.sqrt(vx * vx + vy * vy)
vx /= len
vy /= len
print(x + vx * b, y + vy * b)
print(x - vy * a / 2, y + vx * a / 2)
print(x - vy * c / 2, y + vx * c / 2)
print(x - vy * c / 2 - vx * d, y +... | Python | [
"geometry"
] | 1,392 | 542 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 1,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 3,222 |
529d4ab0bdbb29d8b7f3d3eed19eca63 | You are given a positive integer n. Let's call some positive integer a without leading zeroes palindromic if it remains the same after reversing the order of its digits. Find the number of distinct ways to express n as a sum of positive palindromic integers. Two ways are considered different if the frequency of at leas... | ['brute force', 'dp', 'math', 'number theory'] | from sys import stdin
def readint():
return int(stdin.readline())
def readarray(typ):
return list(map(typ, stdin.readline().split()))
MOD = int(1e9) + 7
ps = []
N = 40000
for i in range(1, N+1):
# print(str(i), ''.join(reversed(str(i)))
if str(i) == (str(i)[::-1]):
ps.append(i)
m = len(p... | Python | [
"math",
"number theory"
] | 711 | 633 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 1,
"number theory": 1,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 3,024 |
8b57854277fb7baead123473a609301d | Pak Chanek has a mirror in the shape of a circle. There are N lamps on the circumference numbered from 1 to N in clockwise order. The length of the arc from lamp i to lamp i+1 is D_i for 1 \leq i \leq N-1. Meanwhile, the length of the arc between lamp N and lamp 1 is D_N.Pak Chanek wants to colour the lamps with M diff... | ['binary search', 'combinatorics', 'geometry', 'math', 'two pointers'] | import os,sys
from io import BytesIO, IOBase
def pair_same(n, m, k, p, r, fac):
return ( ((fac[m]*pow(fac[m-p], r-2, r))%r) *
((pow(((m-p)*(m-p-1))%r, k-p, r)*pow(m-p, n-2*k, r))%r) )%r
def solve(n, m, ls):
r = 998244353
fac = [1]
for i in range(1, m+1):
fac.append((fac[... | Python | [
"math",
"geometry"
] | 1,204 | 2,799 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 1,
"graphs": 0,
"math": 1,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 2,600 |
48151011c3d380ab303ae38d0804176a | Polycarp has built his own web service. Being a modern web service it includes login feature. And that always implies password security problems.Polycarp decided to store the hash of the password, generated by the following algorithm: take the password p, consisting of lowercase Latin letters, and shuffle the letters r... | ['implementation', 'brute force', 'strings'] | t = input()
for _ in xrange(t):
p = raw_input()
h = raw_input()
n = len(p)
m = len(h)
ans = False
low = 0
p = ''.join(sorted(p))
while low+n<=m:
temp = h[low:low+n]
temp = ''.join(sorted(temp))
if p == temp:
ans = True
break
low +=... | Python | [
"strings"
] | 1,146 | 385 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 1,
"trees": 0
} | 1,215 |
bedb98780a71d7027798d14aa5f1f100 | Dima the hamster enjoys nibbling different things: cages, sticks, bad problemsetters and even trees!Recently he found a binary search tree and instinctively nibbled all of its edges, hence messing up the vertices. Dima knows that if Andrew, who has been thoroughly assembling the tree for a long time, comes home and see... | ['dp', 'number theory', 'math', 'trees', 'brute force'] | from sys import stdin
from math import gcd
n=int(stdin.readline())
a=[int(x) for x in stdin.readline().split()]
c = []
ld=[]
rd=[]
def check(l, r, e):
if r == l: return c[l][e] > 0
if e < l and ld[l][r-l] != 0:
return ld[l][r-l] == 1
elif e > r and rd[l][r-l] != 0:
return rd[l][r-l] == 1
... | Python | [
"number theory",
"math",
"trees"
] | 719 | 1,111 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 1,
"number theory": 1,
"probabilities": 0,
"strings": 0,
"trees": 1
} | 4,864 |
9f13d3d0266b46e4201ea6a2378d1b71 | Binary Spiders are species of spiders that live on Mars. These spiders weave their webs to defend themselves from enemies.To weave a web, spiders join in pairs. If the first spider in pair has x legs, and the second spider has y legs, then they weave a web with durability x \oplus y. Here, \oplus means bitwise XOR.Bina... | ['bitmasks', 'data structures', 'implementation', 'math', 'sortings', 'trees'] | import sys
import os
from io import BytesIO, IOBase
from _collections import defaultdict
from random import randrange
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writ... | Python | [
"math",
"trees"
] | 1,174 | 3,707 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 1,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 1
} | 1,680 |
1461fca52a0310fff725b476bfbd3b29 | Creatnx has n mirrors, numbered from 1 to n. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The i-th mirror will tell Creatnx that he is beautiful with probability \frac{p_i}{100} for all 1 \le i \le n.Some mirrors are called checkpoints. Initially, only the 1st mirror is a checkpoint. It remains a check... | ['data structures', 'probabilities'] | from __future__ import division, print_function
def main():
n, qs = input_as_list()
cpn = ceil_power_of_2(n)
st = array_of(int, n+1)
switch = array_of(bool, n)
def update(i, v):
while i < n:
st[i] += v
i |= i+1
def query(i):
res = 0
while i > 0:... | Python | [
"probabilities"
] | 1,747 | 3,510 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 0,
"probabilities": 1,
"strings": 0,
"trees": 0
} | 1,245 |
7a559fd046e599b16143f40b4e55d127 | You are given an integer array a of length n. Does there exist an array b consisting of n+1 positive integers such that a_i=\gcd (b_i,b_{i+1}) for all i (1 \leq i \leq n)? Note that \gcd(x, y) denotes the greatest common divisor (GCD) of integers x and y. | ['math', 'number theory'] | import sys
from math import *
def input(): return sys.stdin.readline().strip()
def lcm(a, b):
return a*b//gcd(a, b)
for test in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
if n <= 2:
print("YES")
continue
brr = [arr[0]]
for i in range(n-1):
... | Python | [
"math",
"number theory"
] | 315 | 531 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 1,
"number theory": 1,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 104 |
c9bc4fefa96b741843e54a8fb4b02877 | This is an interactive problem.There was a tournament consisting of 2^n contestants. The 1-st contestant competed with the 2-nd, the 3-rd competed with the 4-th, and so on. After that, the winner of the first match competed with the winner of second match, etc. The tournament ended when there was only one contestant le... | ['constructive algorithms', 'greedy', 'interactive', 'number theory', 'probabilities'] | t= int(input())
for _ in range(t):
n=int(input())
P = [i for i in range(1,2**n+1)]
while n>1:
k=[]
for i in range(0,2**(n)-1,4):
print("? ", P[i], P[i+2], flush =True)
a = int(input())
if a==0:
k.extend([P[i+1],P[i+3]])
... | Python | [
"number theory",
"probabilities"
] | 1,118 | 610 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 0,
"number theory": 1,
"probabilities": 1,
"strings": 0,
"trees": 0
} | 4,914 |
016bf7989ba58fdc3894a4cf3e0ac302 | Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the di... | ['dp', 'greedy', 'graphs', 'dsu', 'dfs and similar'] | n, m = map(int, input().split())
dishes = [0 for _ in range(n + m)]
father = [-1 for _ in range(n + m)]
e_out = dict()
v_in = [0 for _ in range(n + m)]
def get_father(n):
if father[n] == -1:
return n
else:
father[n] = get_father(father[n])
return father[n]
compare_matrix = []
for i... | Python | [
"graphs"
] | 2,081 | 2,033 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 1,
"math": 0,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 2,489 |
b58a18119ac8375f9ad21a282292a76c | You are given two integers a and b. In one turn, you can do one of the following operations: Take an integer c (c > 1 and a should be divisible by c) and replace a with \frac{a}{c}; Take an integer c (c > 1 and b should be divisible by c) and replace b with \frac{b}{c}. Your goal is to make a equal to b using exa... | ['constructive algorithms', 'math', 'number theory'] | from __future__ import division, print_function
import os,sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
from math import ceil, floor, factorial, sqrt
# from math import log,sqr... | Python | [
"math",
"number theory"
] | 963 | 11,568 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | {
"games": 0,
"geometry": 0,
"graphs": 0,
"math": 1,
"number theory": 1,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 840 |
07e56d4031bcb119d2f684203f7ed133 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular n-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the OX-axis and at least one of its edges is parallel to the OY-axis at ... | ['geometry', 'math'] | t=int(input())
for _ in range(t):
n=int(input())
if(n%4==0):
print("YES")
else:
print("NO")
| Python | [
"math",
"geometry"
] | 607 | 120 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | {
"games": 0,
"geometry": 1,
"graphs": 0,
"math": 1,
"number theory": 0,
"probabilities": 0,
"strings": 0,
"trees": 0
} | 139 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.