Dataset Viewer
Auto-converted to Parquet Duplicate
problem_id
int64
0
2.83k
question
stringlengths
143
9.11k
difficulty
stringclasses
6 values
source
stringclasses
7 values
tags
listlengths
0
0
lang
stringclasses
1 value
lang_conf
float64
0.71
1
code
stringlengths
23
11.9k
tests_passed
int64
1
20
tests_total
int64
1
20
compare_modes
listlengths
1
3
time_limit_s
float64
0.1
15
memory_limit_mb
int64
28
50k
quality_score
float64
0.55
1
url
stringlengths
36
105
0
There are $n$ candy boxes in front of Tania. The boxes are arranged in a row from left to right, numbered from $1$ to $n$. The $i$-th box contains $r_i$ candies, candies have the color $c_i$ (the color can take one of three values ​​— red, green, or blue). All candies inside a single box have the same color (and it is ...
HARD
codeforces
[]
python
1
INF = 10000000000.0 max_n = 50 max_k = 2000 def main(): (n, s, k) = map(int, input().split()) s -= 1 buf = [''] * (max_n + 1) dp = [[0 for i in range(max_n + 1)] for j in range(max_k + 1)] r = list(map(int, input().split())) c = input() answer = INF for i in range(len(c)): buf[i] = c[i] for i in range(k, -1...
20
20
[ "exact" ]
5
256
0.999
https://codeforces.com/problemset/problem/1057/C
0
There are $n$ candy boxes in front of Tania. The boxes are arranged in a row from left to right, numbered from $1$ to $n$. The $i$-th box contains $r_i$ candies, candies have the color $c_i$ (the color can take one of three values ​​— red, green, or blue). All candies inside a single box have the same color (and it is ...
HARD
codeforces
[]
python
1
(n, s, k) = map(int, input().split()) s -= 1 r = list(map(int, input().split())) INF = float('inf') c = input() dp = [[] for i in range(n)] def calc(u): if dp[u]: return dp[u] = [0] * (r[u] + 1) + [INF] * (k - r[u]) for i in range(n): if c[u] != c[i] and r[i] > r[u]: calc(i) d = abs(u - i) for j in ran...
20
20
[ "exact" ]
5
256
0.999
https://codeforces.com/problemset/problem/1057/C
0
There are $n$ candy boxes in front of Tania. The boxes are arranged in a row from left to right, numbered from $1$ to $n$. The $i$-th box contains $r_i$ candies, candies have the color $c_i$ (the color can take one of three values ​​— red, green, or blue). All candies inside a single box have the same color (and it is ...
HARD
codeforces
[]
python
1
import math def solve(): (n, s, k) = map(int, input().split()) s -= 1 r = list(map(int, input().split())) c = input() inf = int(1000000000.0) dp = [[inf for j in range(n)] for i in range(k + 1)] for i in range(0, k + 1): for j in range(0, n): if i == 0 or i <= r[j]: dp[i][j] = 0 continue for K i...
20
20
[ "exact" ]
5
256
0.999
https://codeforces.com/problemset/problem/1057/C
1
If you visit Aizu Akabeko shrine, you will find a unique paper fortune on which a number with more than one digit is written. Each digit ranges from 1 to 9 (zero is avoided because it is considered a bad omen in this shrine). Using this string of numeric values, you can predict how many years it will take before your ...
UNKNOWN_DIFFICULTY
aizu
[]
python
1
def sub(maxs, mins): for i in range(len(maxs)): if maxs[i] != mins[i]: if i == len(maxs) - 1: return int(maxs[i]) - int(mins[i]) if i == len(maxs) - 2: return int(maxs[i:i + 2]) - int(mins[i:i + 2]) return 10 return 0 def checkEqual(S): ans = 8 for k in range(1, len(S)): if len(S) % k != 0: ...
20
20
[ "exact" ]
1
268
0.935
null
1
If you visit Aizu Akabeko shrine, you will find a unique paper fortune on which a number with more than one digit is written. Each digit ranges from 1 to 9 (zero is avoided because it is considered a bad omen in this shrine). Using this string of numeric values, you can predict how many years it will take before your ...
UNKNOWN_DIFFICULTY
aizu
[]
python
1
n = input() length = len(n) ans = 10 lst = [] ind = 0 while ind < length: if n[ind] == '1' and ind + 1 <= length - 1: lst.append(int(n[ind:ind + 2])) ind += 2 else: lst.append(int(n[ind])) ind += 1 if len(lst) >= 2: ans = min(ans, max(lst) - min(lst)) divisors = [] for i in range(1, length // 2 + 1): if len...
20
20
[ "exact" ]
1
268
0.935
null
2
You have a deck of $n$ cards, and you'd like to reorder it to a new one. Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card. In each step you pick some integer $k > 0$...
EASY
codeforces
[]
python
1
import heapq from math import sqrt import operator import sys inf_var = 0 if inf_var == 1: inf = open('input.txt', 'r') else: inf = sys.stdin input = inf.readline def read_one_int(): return int(input().rstrip('\n')) def read_list_of_ints(): res = [int(val) for val in input().rstrip('\n').split(' ')] return res ...
4
4
[ "exact", "token" ]
1
512
0.849
https://codeforces.com/problemset/problem/1492/B
2
You have a deck of $n$ cards, and you'd like to reorder it to a new one. Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card. In each step you pick some integer $k > 0$...
EASY
codeforces
[]
python
1
t = int(input()) for _ in range(t): n = int(input()) p = list(map(int, input().split())) ans = [] p1 = [-1] * (n + 1) for i in range(n): p1[p[i]] = i i = n while i: while i > 0 and p1[i] == -1: i -= 1 else: if i: k = 0 for j in range(p1[i], n): ans.append(p[j]) p1[p[j]] = -1 k ...
4
4
[ "exact", "token" ]
1
512
0.849
https://codeforces.com/problemset/problem/1492/B
2
You have a deck of $n$ cards, and you'd like to reorder it to a new one. Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card. In each step you pick some integer $k > 0$...
EASY
codeforces
[]
python
1
import sys def get_ints(): return map(int, sys.stdin.readline().strip().split()) def get_list(): return list(map(int, sys.stdin.readline().strip().split())) def get_list_string(): return list(map(str, sys.stdin.readline().strip().split())) def get_string(): return sys.stdin.readline().strip() def get_int(): r...
4
4
[ "exact", "token" ]
1
512
0.849
https://codeforces.com/problemset/problem/1492/B
3
The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example * 1 * 1 x 2 x 2 = 4 * 1 x 2 x 2 x 3 x 5 x 5 = 300 Etc. are humming numbers, but 11, 13, 14 etc. are not humming numbers. All humming numbers are divisible by a power of 60 (for example, 54 is ...
UNKNOWN_DIFFICULTY
aizu
[]
python
1
import sys from sys import stdin from bisect import bisect_right, bisect_left from math import ceil, log input = stdin.readline def main(args): hammings = [] temp = set() for i in range(ceil(log(1000000.0, 2)) + 1): for j in range(ceil(log(1000000.0, 3)) + 1): for k in range(ceil(log(1000000.0, 5)) + 1): a...
20
20
[ "exact" ]
1
134
0.896
null
3
The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example * 1 * 1 x 2 x 2 = 4 * 1 x 2 x 2 x 3 x 5 x 5 = 300 Etc. are humming numbers, but 11, 13, 14 etc. are not humming numbers. All humming numbers are divisible by a power of 60 (for example, 54 is ...
UNKNOWN_DIFFICULTY
aizu
[]
python
1
MAX = 1000000 t = [0] * (MAX + 5) a5 = 1 for i in range(9): a3 = 1 for j in range(13): a35 = a5 * a3 if a35 > MAX: break a2 = 1 for k in range(20): if a35 * a2 > MAX: break t[a35 * a2] = 1 a2 <<= 1 a3 *= 3 a5 *= 5 while 1: a = input() if a == '0': break (m, n) = map(int, a.split()) pr...
20
20
[ "exact" ]
1
134
0.896
null
3
The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example * 1 * 1 x 2 x 2 = 4 * 1 x 2 x 2 x 3 x 5 x 5 = 300 Etc. are humming numbers, but 11, 13, 14 etc. are not humming numbers. All humming numbers are divisible by a power of 60 (for example, 54 is ...
UNKNOWN_DIFFICULTY
aizu
[]
python
1
while 1: datas = list(map(int, input().split())) if datas[0] == 0: break (n, m) = (datas[0], datas[1]) cnt = 0 for i in range(n, m + 1): b = i while b % 5 == 0: b //= 5 while b % 3 == 0: b //= 3 while b % 2 == 0: b //= 2 if b == 1: cnt += 1 print(cnt)
20
20
[ "exact" ]
1
134
0.896
null
6
Tom has finally taken over the business empire and now looking for a new Name of the business to make a new start. Joe (Tom's dear friend) suggested a string $S$ consisting of Uppercase and lowercase letters Tom wants to make some changes as per the following criteria: 1) String should $not$ have any vowels ...
UNKNOWN_DIFFICULTY
codechef
[]
python
1
s = input().lower() vow = ['a', 'e', 'i', 'o', 'u', 'y'] ans = '' for ch in s: if ch in vow: continue if ch.isalpha(): ans += '.' + ch print(ans)
1
1
[ "whitespace" ]
5
256
0.619
https://www.codechef.com/SPRT2020/problems/EMPRNM
7
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them ...
EASY
codechef
[]
python
1
for i in range(0, int(input())): n = int(input()) l = list(input()) t = 0 a = 0 b = 0 for j in range(0, n): t = t + 1 if l[j] == '0': a = a + 1 else: b = b + 1 if b >= t / 2: print('YES') break elif j == n - 1 and b < t / 2: print('NO') else: continue
1
1
[ "whitespace" ]
0.5
50,000
0.774
https://www.codechef.com/problems/CCHEAVEN
7
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them ...
EASY
codechef
[]
python
1
for _ in range(int(input())): n = int(input()) s = input() (c, c1) = (0, 0) ans = 'NO' for i in s: if i == '1': c1 += 1 c += 1 if c1 * 2 >= c: ans = 'YES' break print(ans)
1
1
[ "whitespace" ]
0.5
50,000
0.774
https://www.codechef.com/problems/CCHEAVEN
7
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them ...
EASY
codechef
[]
python
1
t = int(input()) for ni in range(t): l = int(input()) s = input() (s0, s1) = (0, 0) pos = 'NO' for i in range(len(s)): if s[i] == '0': s0 = s0 + 1 else: s1 = s1 + 1 if s1 >= s0: pos = 'YES' break print(pos)
1
1
[ "whitespace" ]
0.5
50,000
0.774
https://www.codechef.com/problems/CCHEAVEN
9
You are given an array A of N integers A_{1}, A_{2}, \ldots, A_{N}. Determine if there are two [permutations] B and C of this array, for which the following condition is satisfied: * There doesn't exist a pair of integers (i, j) such that 1 ≤ i ≤ j ≤ N and (i, j) \neq (1, N), for which the subarray B[i:j] is a permuta...
HARD
codechef
[]
python
1
from math import ceil, log, floor, sqrt, gcd for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) f = {} for i in l: try: f[i] += 1 except: f[i] = 1 if max(f.values()) > n // 2 or len(set(l)) <= 2: print('NO') else: print('YES') l.sort() print(*l) print(*l[n // 2:...
1
1
[ "whitespace" ]
1
50,000
0.772
https://www.codechef.com/problems/DIFSUBARRAYS
9
You are given an array A of N integers A_{1}, A_{2}, \ldots, A_{N}. Determine if there are two [permutations] B and C of this array, for which the following condition is satisfied: * There doesn't exist a pair of integers (i, j) such that 1 ≤ i ≤ j ≤ N and (i, j) \neq (1, N), for which the subarray B[i:j] is a permuta...
HARD
codechef
[]
python
1
import math import bisect import heapq from math import gcd, floor, sqrt, log from collections import defaultdict as ddc from collections import Counter def intin(): return int(input()) def mapin(): return map(int, input().split()) def strin(): return input().split() INF = 10 ** 20 mod = 1000000007 def exponenti...
1
1
[ "whitespace" ]
1
50,000
0.772
https://www.codechef.com/problems/DIFSUBARRAYS
10
You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $a_i + 1$. After each such operation, the length of the array wil...
HARD
codeforces
[]
python
1
n = int(input()) arr = list(map(int, input().split())) tracker = [[-1] * (n + 1) for _ in range(2024)] d = [[] for _ in range(n)] for (j, v) in enumerate(arr): tracker[v][j] = j d[j].append(j) for v in range(1, 2024): for i in range(n): j = tracker[v][i] h = tracker[v][j + 1] if j != -1 else -1 if j != -1 and ...
20
20
[ "exact" ]
2
256
0.995
https://codeforces.com/problemset/problem/1312/E
10
You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $a_i + 1$. After each such operation, the length of the array wil...
HARD
codeforces
[]
python
1
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) INF = 10 ** 9 dp = [[INF] * (n + 1) for i in range(n + 1)] val = [[-1] * (n + 1) for i in range(n + 1)] for i in range(n): dp[i][i + 1] = 1 val[i][i + 1] = a[i] for l in range(2, n + 1): for i in range(n - l + 1): j = i + l ...
20
20
[ "exact" ]
2
256
0.995
https://codeforces.com/problemset/problem/1312/E
10
You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $a_i + 1$. After each such operation, the length of the array wil...
HARD
codeforces
[]
python
1
import sys readline = sys.stdin.buffer.readline N = int(readline()) A = list(map(int, readline().split())) dp = [[0] * N for _ in range(N)] for j in range(N): dp[j][0] = A[j] for l in range(1, N): for j in range(l, N): for k in range(j - l, j): if dp[k][k - j + l] == dp[j][j - k - 1] > 0: dp[j][l] = 1 + dp[j...
20
20
[ "exact" ]
2
256
0.995
https://codeforces.com/problemset/problem/1312/E
11
There are players standing in a row each player has a digit written on their T-Shirt (multiple players can have the same number written on their T-Shirt). You have to select a group of players, note that players in this group should be standing in $\textbf{consecutive fashion}$. For example second player of chosen g...
UNKNOWN_DIFFICULTY
codechef
[]
python
1
import sys def GRIG(L): LENT = len(L) MINT = 1 GOT = 0 DY = [[{x: 0 for x in range(0, 10)}, 0, 0]] for i in L: DY.append([{x: 0 for x in range(0, 10)}, 0, 0]) GOT += 1 for j in range(0, GOT): if DY[j][0][i] == 1: DY[j][0][i] = 0 DY[j][1] -= 1 else: DY[j][0][i] = 1 DY[j][1] += 1 DY[j...
1
1
[ "whitespace" ]
5
256
0.72
https://www.codechef.com/COVO2020/problems/GRIG
11
There are players standing in a row each player has a digit written on their T-Shirt (multiple players can have the same number written on their T-Shirt). You have to select a group of players, note that players in this group should be standing in $\textbf{consecutive fashion}$. For example second player of chosen g...
UNKNOWN_DIFFICULTY
codechef
[]
python
1
import sys import math from collections import defaultdict, Counter def possible(n1, n): odd = set() for j in range(n): if s[j] in odd: odd.remove(s[j]) else: odd.add(s[j]) if j < n1 - 1: continue if len(odd) <= 1: return True if s[j - n1 + 1] in odd: odd.remove(s[j - n1 + 1]) else: odd...
1
1
[ "whitespace" ]
5
256
0.72
https://www.codechef.com/COVO2020/problems/GRIG
11
There are players standing in a row each player has a digit written on their T-Shirt (multiple players can have the same number written on their T-Shirt). You have to select a group of players, note that players in this group should be standing in $\textbf{consecutive fashion}$. For example second player of chosen g...
UNKNOWN_DIFFICULTY
codechef
[]
python
1
from collections import defaultdict t = int(input()) for _ in range(t): s = input() s = list(s) l = s[:] n = len(s) ans = 0 if n <= 1000: if n <= 100: l = [] for i in range(n): for j in range(i + 1, n): l.append(s[i:j]) ans = 0 for i in l: dic = defaultdict(lambda : 0) for j in i: ...
1
1
[ "whitespace" ]
5
256
0.72
https://www.codechef.com/COVO2020/problems/GRIG
14
There are X+Y+Z people, conveniently numbered 1 through X+Y+Z. Person i has A_i gold coins, B_i silver coins and C_i bronze coins. Snuke is thinking of getting gold coins from X of those people, silver coins from Y of the people and bronze coins from Z of the people. It is not possible to get two or more different col...
UNKNOWN_DIFFICULTY
atcoder
[]
python
1
from heapq import heappushpop import sys (X, Y, Z) = map(int, sys.stdin.readline().split()) N = X + Y + Z ABC = [list(map(int, sys.stdin.readline().split())) for _ in range(N)] ABC.sort(key=lambda x: x[0] - x[1], reverse=True) GB = [None] * N Q = [a - c for (a, _, c) in ABC[:X]] Q.sort() gs = sum((a for (a, _, _) in AB...
20
20
[ "exact" ]
2
256
0.927
null
14
There are X+Y+Z people, conveniently numbered 1 through X+Y+Z. Person i has A_i gold coins, B_i silver coins and C_i bronze coins. Snuke is thinking of getting gold coins from X of those people, silver coins from Y of the people and bronze coins from Z of the people. It is not possible to get two or more different col...
UNKNOWN_DIFFICULTY
atcoder
[]
python
1
from heapq import * (X, Y, Z) = map(int, input().split()) N = X + Y + Z A = [] q1 = [] q2 = [] L = [0] R = [0] for _ in [0] * N: A.append([int(e) for e in input().split()]) A.sort(key=lambda a: a[0] - a[1]) for i in range(N): L += [L[i] + A[i][1]] heappush(q1, A[i][1] - A[i][2]) R += [R[i] + A[-1 - i][0]] heappush...
20
20
[ "exact" ]
2
256
0.927
null
14
There are X+Y+Z people, conveniently numbered 1 through X+Y+Z. Person i has A_i gold coins, B_i silver coins and C_i bronze coins. Snuke is thinking of getting gold coins from X of those people, silver coins from Y of the people and bronze coins from Z of the people. It is not possible to get two or more different col...
UNKNOWN_DIFFICULTY
atcoder
[]
python
1
import sys from heapq import heappush, heappushpop (X, Y, Z) = map(int, input().split()) xyz = sorted([list(map(int, l.split())) for l in sys.stdin], key=lambda x: x[0] - x[1]) uq = [] cy = 0 for (x, y, z) in xyz[:Y]: heappush(uq, y - z) cy += y Ly = [cy] for (x, y, z) in xyz[Y:Y + Z]: cy += y - heappushpop(uq, y - ...
20
20
[ "exact" ]
2
256
0.927
null
15
You are the principal of the Cake school in chefland and today is your birthday. You want to treat each of the children with a small cupcake which is made by you. But there is a problem, You don't know how many students are present today. The students have gathered of the morning assembly in $R$ rows and $C$ columns. N...
UNKNOWN_DIFFICULTY
codechef
[]
python
1
for _ in range(int(input())): n = list(map(int, input().split())) print(n[0] * n[1])
1
1
[ "whitespace" ]
5
256
0.61
https://www.codechef.com/ENDE2020/problems/ENCDEC2
15
You are the principal of the Cake school in chefland and today is your birthday. You want to treat each of the children with a small cupcake which is made by you. But there is a problem, You don't know how many students are present today. The students have gathered of the morning assembly in $R$ rows and $C$ columns. N...
UNKNOWN_DIFFICULTY
codechef
[]
python
1
t = int(input()) for t1 in range(t): (r, c) = map(int, input().split()) print(r * c)
1
1
[ "whitespace" ]
5
256
0.61
https://www.codechef.com/ENDE2020/problems/ENCDEC2
15
You are the principal of the Cake school in chefland and today is your birthday. You want to treat each of the children with a small cupcake which is made by you. But there is a problem, You don't know how many students are present today. The students have gathered of the morning assembly in $R$ rows and $C$ columns. N...
UNKNOWN_DIFFICULTY
codechef
[]
python
1
t = int(input()) for _ in range(t): (R, C) = map(int, input().split()) ans = R * C print(ans)
1
1
[ "whitespace" ]
5
256
0.61
https://www.codechef.com/ENDE2020/problems/ENCDEC2
16
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = E, and west if S_i = W. You will appoint one of the N people as the leader, then command the rest of them to ...
EASY
atcoder
[]
python
1
n = int(input()) s = input() cnt = s[1:].count('E') ans = cnt for i in range(1, n): if s[i - 1] == 'W': cnt += 1 if s[i] == 'E': cnt -= 1 ans = min(ans, cnt) print(ans)
3
3
[ "exact" ]
5
256
0.8
https://atcoder.jp/contests/abc098/tasks/arc098_a
16
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = E, and west if S_i = W. You will appoint one of the N people as the leader, then command the rest of them to ...
EASY
atcoder
[]
python
1
N = int(input()) S = list(input()) e_count = 0 for s in S: if s == 'E': e_count += 1 min_inv = float('infinity') for s in S: if s == 'E': e_count -= 1 min_inv = min(e_count, min_inv) if s == 'W': e_count += 1 print(min_inv)
3
3
[ "exact" ]
5
256
0.8
https://atcoder.jp/contests/abc098/tasks/arc098_a
16
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = E, and west if S_i = W. You will appoint one of the N people as the leader, then command the rest of them to ...
EASY
atcoder
[]
python
1
n = int(input()) s = input() W_cnt = [0] E_cnt = [0] for ss in s: w = W_cnt[-1] if ss == 'W': w += 1 W_cnt.append(w) for ss in reversed(s): e = E_cnt[-1] if ss == 'E': e += 1 E_cnt.append(e) E_cnt = E_cnt[::-1] minc = float('inf') for i in range(n): c = W_cnt[i] + E_cnt[i + 1] minc = min(minc, c) print(minc...
3
3
[ "exact" ]
5
256
0.8
https://atcoder.jp/contests/abc098/tasks/arc098_a
20
Salmon loves to be a tidy person. One day, when he looked at the mess that he made after playing with his rubber ducks, he felt awful. Now he wants to clean up his mess, by placing his ducks into boxes. Each rubber duck has a color. There are a total of $N+1$ colors, numbered from $0$ to $N$. Salmon wants to place his ...
UNKNOWN_DIFFICULTY
codechef
[]
python
1
t = int(input()) for i in range(0, t): (n, k) = list(map(int, input().split())) c = list(map(int, input().split())) l = c[:] while sum(l) != 0: a = max(l) b = min(l) m1 = c.index(a) m2 = c.index(b) n1 = l.index(a) n2 = l.index(b) print(str(m2) + ' ' + str(c[m2]) + ' ' + str(m1) + ' ' + str(k - c[m2]))...
1
1
[ "whitespace" ]
5
256
0.725
https://www.codechef.com/UWCOI21/problems/UWCOI21C
21
Consider sequences \{A_1,...,A_N\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ......
MEDIUM
atcoder
[]
python
1
(N, K) = map(int, input().split()) D = [0] * (K + 1) D[K] = 1 mod = 10 ** 9 + 7 for i in range(K, 0, -1): D[i] = pow(K // i, N, mod) for j in range(2 * i, K + 1, i): D[i] = (D[i] - D[j]) % mod c = 0 for i in range(len(D)): c += D[i] * i print(c % mod)
20
20
[ "exact" ]
2
1,024
0.883
https://atcoder.jp/contests/abc162/tasks/abc162_e
21
Consider sequences \{A_1,...,A_N\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ......
MEDIUM
atcoder
[]
python
1
(n, k) = map(int, input().split()) mod = 10 ** 9 + 7 lst = [0] * (k + 1) ans = 0 for i in range(k, 0, -1): lst[i] += pow(k // i, n, mod) if k // i == 1: continue else: for j in range(2, k // i + 1): lst[i] -= lst[i * j] for i in range(1, k + 1): ans += i * lst[i] % mod ans %= mod print(ans)
20
20
[ "exact" ]
2
1,024
0.883
https://atcoder.jp/contests/abc162/tasks/abc162_e
21
Consider sequences \{A_1,...,A_N\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ......
MEDIUM
atcoder
[]
python
1
mod = 10 ** 9 + 7 (n, k) = list(map(int, input().split())) c = {i: pow(k // i, n, mod) for i in range(1, k + 1)} for i in range(k, 0, -1): for j in range(2 * i, k + 1, i): c[i] -= c[j] _sum = 0 for x in range(1, k + 1): _sum += c[x] * x % mod print(_sum % mod)
20
20
[ "exact" ]
2
1,024
0.883
https://atcoder.jp/contests/abc162/tasks/abc162_e
22
There are two $n$-element arrays of integers, $A$ and $B$. Permute them into some $A^{\prime}$ and $B^{\prime}$ such that the relation $A^{\prime}[i]+B^{\prime}[i]\ge k$ holds for all $i$ where $0\leq i<n$. There will be $q$ queries consisting of $A$, $B$, and $k$. For each query, return YES if some permutation $A^{\...
EASY
hackerrank
[]
python
1
def isGood(listA, listB, k): n = len(listA) listA.sort() listB.sort(reverse=True) for i in range(n): if listA[i] + listB[i] < k: return False return True T = int(input().strip()) for i in range(T): [n, k] = [int(x) for x in input().strip().split()] listA = [int(x) for x in input().strip().split()] listB = ...
1
1
[ "exact" ]
5
256
0.775
https://www.hackerrank.com/challenges/two-arrays/problem
22
There are two $n$-element arrays of integers, $A$ and $B$. Permute them into some $A^{\prime}$ and $B^{\prime}$ such that the relation $A^{\prime}[i]+B^{\prime}[i]\ge k$ holds for all $i$ where $0\leq i<n$. There will be $q$ queries consisting of $A$, $B$, and $k$. For each query, return YES if some permutation $A^{\...
EASY
hackerrank
[]
python
1
import sys f = sys.stdin T = int(f.readline()) while T: (N, K) = map(int, f.readline().split()) A = list(map(int, f.readline().split())) B = list(map(int, f.readline().split())) A.sort() B.sort() B.reverse() flag = 0 for i in range(len(A)): if A[i] + B[i] >= K: flag += 1 if flag == i + 1: print('YES') ...
1
1
[ "exact" ]
5
256
0.775
https://www.hackerrank.com/challenges/two-arrays/problem
22
There are two $n$-element arrays of integers, $A$ and $B$. Permute them into some $A^{\prime}$ and $B^{\prime}$ such that the relation $A^{\prime}[i]+B^{\prime}[i]\ge k$ holds for all $i$ where $0\leq i<n$. There will be $q$ queries consisting of $A$, $B$, and $k$. For each query, return YES if some permutation $A^{\...
EASY
hackerrank
[]
python
1
import sys def main(): line = sys.stdin.readline() t = int(line) for testcase in range(t): line = sys.stdin.readline() vals = [int(i) for i in line.split()] k = vals[1] line = sys.stdin.readline() alist = map(int, line.split()) line = sys.stdin.readline() blist = map(int, line.split()) alist = sorte...
1
1
[ "exact" ]
5
256
0.775
https://www.hackerrank.com/challenges/two-arrays/problem
23
We have a tree with N vertices numbered 1 to N. The i-th edge in this tree connects Vertex a_i and b_i. For each k=1, ..., N, solve the problem below: - Consider writing a number on each vertex in the tree in the following manner: - First, write 1 on Vertex k. - Then, for each of the numbers 2, ..., N in this order,...
MEDIUM_HARD
atcoder
[]
python
1
import sys from functools import reduce def rerooting(N, adj, merge, finalize, identity): order = [None] * N parent = [None] * N parent[0] = -1 stack = [0] for i in range(N): v = stack.pop() order[i] = v for u in adj[v]: if parent[u] is None: parent[u] = v stack.append(u) dp_down = [None] * N f...
20
20
[ "exact" ]
3
1,024
0.964
https://atcoder.jp/contests/abc160/tasks/abc160_f
23
We have a tree with N vertices numbered 1 to N. The i-th edge in this tree connects Vertex a_i and b_i. For each k=1, ..., N, solve the problem below: - Consider writing a number on each vertex in the tree in the following manner: - First, write 1 on Vertex k. - Then, for each of the numbers 2, ..., N in this order,...
MEDIUM_HARD
atcoder
[]
python
1
import sys sys.setrecursionlimit(10 ** 7) M = 10 ** 9 + 7 N = 10 ** 6 fac = [0] * (N + 1) fac[0] = b = 1 for i in range(1, N + 1): fac[i] = b = b * i % M inv = [0] * (N + 1) inv[N] = b = pow(fac[N], M - 2, M) for i in range(N, 0, -1): inv[i - 1] = b = b * i % M def dfs1(v, p): s = 1 l = [] (c1, c2) = ([1], [1]) ...
20
20
[ "exact" ]
3
1,024
0.964
https://atcoder.jp/contests/abc160/tasks/abc160_f
23
We have a tree with N vertices numbered 1 to N. The i-th edge in this tree connects Vertex a_i and b_i. For each k=1, ..., N, solve the problem below: - Consider writing a number on each vertex in the tree in the following manner: - First, write 1 on Vertex k. - Then, for each of the numbers 2, ..., N in this order,...
MEDIUM_HARD
atcoder
[]
python
1
import sys input = sys.stdin.readline from collections import deque nn = 200200 mod = 10 ** 9 + 7 fa = [1] * (nn + 1) fainv = [1] * (nn + 1) inv = [1] * (nn + 1) for i in range(nn): fa[i + 1] = fa[i] * (i + 1) % mod fainv[-1] = pow(fa[-1], mod - 2, mod) for i in range(nn)[::-1]: fainv[i] = fainv[i + 1] * (i + 1) % mo...
20
20
[ "exact" ]
3
1,024
0.964
https://atcoder.jp/contests/abc160/tasks/abc160_f
24
Today, Chef has a fencing job at hand and has to fence up a surface covering N$N$ points. To minimize his work, he started looking for an algorithm that had him fence the least amount of length. He came up with the Convex Hull algorithm, but soon realized it gave him some random shape to fence. However, Chef likes re...
VERY_HARD
codechef
[]
python
1
import math (n, m) = map(int, input().split()) hyp = math.sqrt(1 + m * m) cosx = 1 / hyp sinx = m / hyp ptsx = [] ptsy = [] for i in range(n): (px, py) = list(map(int, input().strip().split())) ptsx.append(cosx * px + sinx * py) ptsy.append(cosx * py - sinx * px) w = max(ptsx) - min(ptsx) l = max(ptsy) - min(ptsy) p...
1
1
[ "float" ]
1
50,000
0.733
https://www.codechef.com/problems/PCJ18F
24
Today, Chef has a fencing job at hand and has to fence up a surface covering N$N$ points. To minimize his work, he started looking for an algorithm that had him fence the least amount of length. He came up with the Convex Hull algorithm, but soon realized it gave him some random shape to fence. However, Chef likes re...
VERY_HARD
codechef
[]
python
1
import math (n, m) = map(int, input().split()) hyp = math.sqrt(1 + m * m) cosx = 1 / hyp sinx = m / hyp pts = [[], []] for i in range(n): p = input().split() px = int(p[0]) py = int(p[1]) pts[0].append(cosx * px + sinx * py) pts[1].append(cosx * py - sinx * px) w = max(pts[0]) - min(pts[0]) l = max(pts[1]) - min(p...
1
1
[ "float" ]
1
50,000
0.733
https://www.codechef.com/problems/PCJ18F
24
Today, Chef has a fencing job at hand and has to fence up a surface covering N$N$ points. To minimize his work, he started looking for an algorithm that had him fence the least amount of length. He came up with the Convex Hull algorithm, but soon realized it gave him some random shape to fence. However, Chef likes re...
VERY_HARD
codechef
[]
python
1
import math import sys (n, m) = map(int, input().split()) pts = [list(map(int, line.strip().split())) for line in sys.stdin] hyp = math.sqrt(1 + m * m) cosx = 1 / hyp sinx = m / hyp for apt in pts: (apt[0], apt[1]) = (cosx * apt[0] + sinx * apt[1], -sinx * apt[0] + cosx * apt[1]) l = max((a[0] for a in pts)) - min((a[...
1
1
[ "float" ]
1
50,000
0.733
https://www.codechef.com/problems/PCJ18F
26
Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down. Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units...
EASY
codeforces
[]
python
1
n = int(input()) s = list(map(int, input().split()))[:n] k = -1 if s[n - 1] == 0: print('UP') elif s[n - 1] == 15 or s[n - 2] > s[n - 1]: print('DOWN') elif n == 1: print(k) else: print('UP')
20
20
[ "exact" ]
5
256
0.997
https://codeforces.com/problemset/problem/719/A
26
Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down. Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units...
EASY
codeforces
[]
python
1
n = int(input()) list = [int(i) for i in input().split()] if n == 1 and list[0] == 0: print('UP') exit() elif n == 1 and list[0] == 15: print('DOWN') exit() elif n == 1: print('-1') exit() (a, b) = (list[n - 2], list[n - 1]) if b == a + 1 and a >= 0 and (a <= 13) or (a == 1 and b == 0): print('UP') elif a >= 2 a...
20
20
[ "exact" ]
5
256
0.997
https://codeforces.com/problemset/problem/719/A
26
Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down. Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units...
EASY
codeforces
[]
python
1
n = int(input()) a = [int(x) for x in input().split()] up = True if a[-1] == 15: print('DOWN') elif a[-1] == 0: print('UP') elif len(a) == 1: print(-1) elif a[-1] - 1 == a[-2]: print('UP') else: print('DOWN')
20
20
[ "exact" ]
5
256
0.997
https://codeforces.com/problemset/problem/719/A
27
You are given an array $a$ of length $n$ consisting of zeros. You perform $n$ actions with this array: during the $i$-th action, the following sequence of operations appears: Choose the maximum by length subarray (continuous subsegment) consisting only of zeros, among all such segments choose the leftmost one; Let th...
MEDIUM_HARD
codeforces
[]
python
1
def generate(l, n): if n <= 0: return if n == 1: d.append((l, 1, l)) return elif n % 2 == 1: d.append((l, n, l + (n - 1) // 2)) generate(l, (n - 1) // 2) generate(l + (n - 1) // 2 + 1, (n - 1) // 2) else: d.append((l, n, l + (n - 1) // 2)) generate(l, (n - 1) // 2) generate(l + n // 2, (n - 1) // ...
20
20
[ "exact", "whitespace" ]
1
256
0.999
https://codeforces.com/problemset/problem/1353/D
27
You are given an array $a$ of length $n$ consisting of zeros. You perform $n$ actions with this array: during the $i$-th action, the following sequence of operations appears: Choose the maximum by length subarray (continuous subsegment) consisting only of zeros, among all such segments choose the leftmost one; Let th...
MEDIUM_HARD
codeforces
[]
python
1
from collections import Counter from collections import defaultdict from collections import deque import math import heapq import sys input = sys.stdin.readline import bisect rs = lambda : input().strip() ri = lambda : int(input()) rl = lambda : list(map(int, input().split())) rls = lambda : list(map(str, input().split...
20
20
[ "exact", "whitespace" ]
1
256
0.999
https://codeforces.com/problemset/problem/1353/D
27
You are given an array $a$ of length $n$ consisting of zeros. You perform $n$ actions with this array: during the $i$-th action, the following sequence of operations appears: Choose the maximum by length subarray (continuous subsegment) consisting only of zeros, among all such segments choose the leftmost one; Let th...
MEDIUM_HARD
codeforces
[]
python
1
import heapq t = int(input()) for loop in range(t): n = int(input()) q = [] q.append([-1 * n, 0, n - 1]) ans = [0] * n cnt = 1 while len(q) > 0: tmppop = heapq.heappop(q) (length, l, r) = tmppop mid = (l + r) // 2 ans[mid] = cnt cnt += 1 if mid - 1 >= l: heapq.heappush(q, [-1 * (mid - 1 - l + 1), l...
20
20
[ "exact", "whitespace" ]
1
256
0.999
https://codeforces.com/problemset/problem/1353/D
29
The Cybermen and the Daleks have long been the Doctor's main enemies. Everyone knows that both these species enjoy destroying everything they encounter. However, a little-known fact about them is that they both also love taking Turing tests! Heidi designed a series of increasingly difficult tasks for them to spend the...
MEDIUM_HARD
codeforces
[]
python
1
import sys import os from io import IOBase, BytesIO def main(): n = int(input()) points = [0] * (4 * n + 1) for i in range(4 * n + 1): (a, b) = get_ints() points[i] = (a, b) l = 4 * n + 1 for i in range(l): (mnx, mxx, mny, mxy) = (51, -1, 51, -1) for j in range(l): if i == j: continue x = points...
20
20
[ "exact" ]
5
256
0.973
https://codeforces.com/problemset/problem/1184/C1
29
The Cybermen and the Daleks have long been the Doctor's main enemies. Everyone knows that both these species enjoy destroying everything they encounter. However, a little-known fact about them is that they both also love taking Turing tests! Heidi designed a series of increasingly difficult tasks for them to spend the...
MEDIUM_HARD
codeforces
[]
python
1
from sys import stdin, stdout def rsingle_int(): return int(stdin.readline().rstrip()) def rmult_int(): return [int(x) for x in stdin.readline().rstrip().split()] def r_str(): return stdin.readline().rstrip() def rsingle_char(): return stdin.read(1) def main(): n = rsingle_int() num_p = 4 * n + 1 points = [...
20
20
[ "exact" ]
5
256
0.973
https://codeforces.com/problemset/problem/1184/C1
29
The Cybermen and the Daleks have long been the Doctor's main enemies. Everyone knows that both these species enjoy destroying everything they encounter. However, a little-known fact about them is that they both also love taking Turing tests! Heidi designed a series of increasingly difficult tasks for them to spend the...
MEDIUM_HARD
codeforces
[]
python
1
n = int(input()) p = [] dx = {} dy = {} min_x = None max_x = None min_y = None max_y = None for _ in range(4 * n + 1): (x, y) = map(int, input().split()) p.append([x, y]) if x not in dx: dx[x] = 0 dx[x] += 1 if y not in dy: dy[y] = 0 dy[y] += 1 for x in sorted(dx.keys()): if dx[x] >= n: min_x = x break f...
20
20
[ "exact" ]
5
256
0.973
https://codeforces.com/problemset/problem/1184/C1
30
Jerry is a little mouse. He is trying to survive from the cat Tom. Jerry is carrying a parallelepiped-like piece of cheese of size A × B × C. It is necessary to trail this cheese to the Jerry's house. There are several entrances in the Jerry's house. Each entrance is a rounded hole having its own radius R. Could you he...
UNKNOWN_DIFFICULTY
aizu
[]
python
1
while True: (d, w, h) = sorted(map(int, input().split())) if d == w == h == 0: break dw = d ** 2 + w ** 2 n = int(input()) for i in range(n): y = int(input()) if (2 * y) ** 2 > dw: print('OK') else: print('NA')
20
20
[ "exact" ]
1
134
0.888
null
30
Jerry is a little mouse. He is trying to survive from the cat Tom. Jerry is carrying a parallelepiped-like piece of cheese of size A × B × C. It is necessary to trail this cheese to the Jerry's house. There are several entrances in the Jerry's house. Each entrance is a rounded hole having its own radius R. Could you he...
UNKNOWN_DIFFICULTY
aizu
[]
python
1
def get_input(): while True: try: yield ''.join(input()) except EOFError: break while True: d = [int(i) for i in input().split()] if d[0] == 0 and d[1] == 0 and (d[2] == 0): break d.sort() cheese = d[0] * d[0] + d[1] * d[1] N = int(input()) for l in range(N): R = int(input()) * 2 if cheese < R * ...
20
20
[ "exact" ]
1
134
0.888
null
30
Jerry is a little mouse. He is trying to survive from the cat Tom. Jerry is carrying a parallelepiped-like piece of cheese of size A × B × C. It is necessary to trail this cheese to the Jerry's house. There are several entrances in the Jerry's house. Each entrance is a rounded hole having its own radius R. Could you he...
UNKNOWN_DIFFICULTY
aizu
[]
python
1
while True: (d, w, h) = list(map(int, input().split())) if d == 0 and w == 0 and (h == 0): break vmin = min(d * d + w * w, d * d + h * h, w * w + h * h) for _ in range(int(input())): r = int(input()) print('OK' if (2 * r) ** 2 > vmin else 'NA')
20
20
[ "exact" ]
1
134
0.888
null
31
John is new to Mathematics and does not know how to calculate GCD of numbers. So he wants you to help him in a few GCD calculations. John has a list A of numbers, indexed 1 to N. He wants to create another list B having N+1 numbers, indexed from 1 to N+1, and having the following property: GCD(B[i], B[i+1]) = A[i], ∀...
EASY
hackerrank
[]
python
1
def gcd(a, b): return a if b == 0 else gcd(b, a % b) def lcm(a, b): return a * b // gcd(a, b) for _ in range(int(input())): n = int(input()) (a, ret) = ([1] + list(map(int, input().split())) + [1], '') for i in range(1, n + 2): ret += str(lcm(a[i], a[i - 1])) + ' ' print(ret)
1
1
[ "whitespace" ]
5
256
0.751
https://www.hackerrank.com/challenges/john-and-gcd-list/problem
31
John is new to Mathematics and does not know how to calculate GCD of numbers. So he wants you to help him in a few GCD calculations. John has a list A of numbers, indexed 1 to N. He wants to create another list B having N+1 numbers, indexed from 1 to N+1, and having the following property: GCD(B[i], B[i+1]) = A[i], ∀...
EASY
hackerrank
[]
python
1
def lcm(a, b): return a * b // gcd(a, b) def gcd(a, b): if a == 0: return b return gcd(b % a, a) T = int(input()) for t in range(T): N = int(input()) A = list(map(int, input().split())) B = [A[0]] for i in range(N - 1): B.append(lcm(A[i], A[i + 1])) B.append(A[N - 1]) print(' '.join(map(str, B)))
1
1
[ "exact" ]
5
256
0.751
https://www.hackerrank.com/challenges/john-and-gcd-list/problem
33
A gene is represented as a string of length $n$ (where $n$ is divisible by $4$), composed of the letters $\mbox{A}$, $\mbox{C}$, $\textbf{T}$, and $\mbox{G}$. It is considered to be steady if each of the four letters occurs exactly $\frac{n}{4}$ times. For example, $\textbf{GACT}$ and $\textbf{AAGTGCCT}$ are both stea...
MEDIUM
hackerrank
[]
python
1
def solve(S, n): count = {} for c in S: count[c] = count.get(c, 0) + 1 for c in count: if count[c] > n // 4: count[c] = count[c] - n // 4 else: count[c] = 0 if sum((count[c] for c in count)) == 0: return 0 count2 = {} (i, j, best) = (0, 0, n) while j < n: while j < n and any((count2.get(c, 0) < c...
1
1
[ "exact" ]
5
256
0.775
https://www.hackerrank.com/challenges/bear-and-steady-gene/problem
33
A gene is represented as a string of length $n$ (where $n$ is divisible by $4$), composed of the letters $\mbox{A}$, $\mbox{C}$, $\textbf{T}$, and $\mbox{G}$. It is considered to be steady if each of the four letters occurs exactly $\frac{n}{4}$ times. For example, $\textbf{GACT}$ and $\textbf{AAGTGCCT}$ are both stea...
MEDIUM
hackerrank
[]
python
1
from collections import defaultdict length = int(input()) S = input() prefix = {} suffix = {} prefix[-1] = defaultdict(int) suffix[len(S)] = defaultdict(int) def deep_copy(o): copy = defaultdict(int) for (k, v) in o.items(): copy[k] = v return copy for (i, c) in enumerate(S): prefix[i] = deep_copy(prefix[i - 1])...
1
1
[ "exact" ]
5
256
0.775
https://www.hackerrank.com/challenges/bear-and-steady-gene/problem
33
A gene is represented as a string of length $n$ (where $n$ is divisible by $4$), composed of the letters $\mbox{A}$, $\mbox{C}$, $\textbf{T}$, and $\mbox{G}$. It is considered to be steady if each of the four letters occurs exactly $\frac{n}{4}$ times. For example, $\textbf{GACT}$ and $\textbf{AAGTGCCT}$ are both stea...
MEDIUM
hackerrank
[]
python
1
n = int(input()) S = input() my_dict = {} my_dict['A'] = -n // 4 my_dict['G'] = -n // 4 my_dict['C'] = -n // 4 my_dict['T'] = -n // 4 for letter in S: my_dict[letter] += 1 current = {'A': 0, 'C': 0, 'G': 0, 'T': 0} current[S[0]] += 1 best_length = len(S) right = 0 left = 0 while right < len(S) and (my_dict['A'] != 0 o...
1
1
[ "exact" ]
5
256
0.775
https://www.hackerrank.com/challenges/bear-and-steady-gene/problem
34
Casimir has a string $s$ which consists of capital Latin letters 'A', 'B', and 'C' only. Each turn he can choose to do one of the two following actions: he can either erase exactly one letter 'A' and exactly one letter 'B' from arbitrary places of the string (these letters don't have to be adjacent); or he can erase ...
EASY
codeforces
[]
python
1
def solve(s): return s.count('B') == s.count('A') + s.count('C') n = int(input()) for i in range(n): s = input() if solve(s): print('YES') else: print('NO')
20
20
[ "exact" ]
2
256
1
https://codeforces.com/problemset/problem/1579/A
34
Casimir has a string $s$ which consists of capital Latin letters 'A', 'B', and 'C' only. Each turn he can choose to do one of the two following actions: he can either erase exactly one letter 'A' and exactly one letter 'B' from arbitrary places of the string (these letters don't have to be adjacent); or he can erase ...
EASY
codeforces
[]
python
1
for i in range(int(input())): s = input() a = s.count('A') b = s.count('B') c = s.count('C') lst = [a + b + c] if len(set(s)) == 1: print('NO') continue if b == 0: print('NO') continue if b - a == c or b - c == a: print('YES') else: print('NO')
20
20
[ "exact" ]
2
256
1
https://codeforces.com/problemset/problem/1579/A
34
Casimir has a string $s$ which consists of capital Latin letters 'A', 'B', and 'C' only. Each turn he can choose to do one of the two following actions: he can either erase exactly one letter 'A' and exactly one letter 'B' from arbitrary places of the string (these letters don't have to be adjacent); or he can erase ...
EASY
codeforces
[]
python
1
t = int(input()) L = [] for i in range(t): ch = input() nb1 = nb2 = 0 for j in ch: if j == 'B': nb1 += 1 else: nb2 += 1 if nb1 == nb2: L.append('YES') else: L.append('NO') for i in range(t): print(L[i])
20
20
[ "exact" ]
2
256
1
https://codeforces.com/problemset/problem/1579/A
35
Snuke found a random number generator. It generates an integer between 0 and 2^N-1 (inclusive). An integer sequence A_0, A_1, \cdots, A_{2^N-1} represents the probability that each of these integers is generated. The integer i (0 \leq i \leq 2^N-1) is generated with probability A_i / S, where S = \sum_{i=0}^{2^N-1} A_i...
UNKNOWN_DIFFICULTY
atcoder
[]
python
1
N = int(input()) A = [int(i) for i in input().split()] MOD = 998244353 NN = 1 << N def fwht(a): i = 1 while i < NN: j = 0 while j < NN: for k in range(i): (x, y) = (a[j + k], a[i + j + k]) (a[j + k], a[i + j + k]) = ((x + y) % MOD, (x - y) % MOD) j += i << 1 i <<= 1 def inv(x): return pow(x, MO...
20
20
[ "exact" ]
3
1,024
0.85
null
36
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given an odd integer $N$ and two integer sequences $A_{1}, A_{2}, \ldots, A_{N}$ and $B_{1}, B_{2}, \ldots, B_{N}$. Your task is to reorder the elements of $B$, forming a new sequence $C_{1}, C_{2}, \ldots...
HARD
codechef
[]
python
1
import itertools t = int(input()) for _ in range(t): N = int(input()) A = list(map(int, input().split(' '))) B = list(map(int, input().split(' '))) ultimate_sum = 0 for i in range(20): mask = 1 << i count_a = 0 count_b = 0 for (a, b) in zip(A, B): if a & mask > 0: count_a += 1 if b & mask > 0: ...
1
1
[ "whitespace" ]
2
50,000
0.772
https://www.codechef.com/problems/XORGM
36
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given an odd integer $N$ and two integer sequences $A_{1}, A_{2}, \ldots, A_{N}$ and $B_{1}, B_{2}, \ldots, B_{N}$. Your task is to reorder the elements of $B$, forming a new sequence $C_{1}, C_{2}, \ldots...
HARD
codechef
[]
python
1
import itertools T = int(input()) def helper(A_rem, B_rem, ultimate_sum): a = A_rem[0] candidates = [] index_B = [] if len(A_rem) == 1: if a ^ B_rem[0] == ultimate_sum: return B_rem else: return -1 for (i, b) in enumerate(B_rem): if a ^ b == ultimate_sum: candidates.append(b) index_B.append(i) ...
1
1
[ "whitespace" ]
2
50,000
0.772
https://www.codechef.com/problems/XORGM
36
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given an odd integer $N$ and two integer sequences $A_{1}, A_{2}, \ldots, A_{N}$ and $B_{1}, B_{2}, \ldots, B_{N}$. Your task is to reorder the elements of $B$, forming a new sequence $C_{1}, C_{2}, \ldots...
HARD
codechef
[]
python
1
def solve(a, b, n): ans = 0 for i in range(n): ans ^= a[i] ^ b[i] for i in range(n): a[i] ^= ans if sorted(a) == sorted(b): return a return -1 for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = solve(a, b, n) if ans == -1: print...
1
1
[ "whitespace" ]
2
50,000
0.772
https://www.codechef.com/problems/XORGM
37
Mole is hungry again. He found one ant colony, consisting of n ants, ordered in a row. Each ant i (1 ≤ i ≤ n) has a strength si. In order to make his dinner more interesting, Mole organizes a version of «Hunger Games» for the ants. He chooses two numbers l and r (1 ≤ l ≤ r ≤ n) and each pair of ants with indices betwe...
HARD
codeforces
[]
python
1
from math import gcd class SegTree: def __init__(self, arr=None, length=None): if arr is not None: self.n = len(arr) self.t = [1 for _ in range(2 * self.n)] self.ct = [0] * self.n + [1] * self.n self.construct(arr) else: assert False self.n = length self.t = [1 for _ in range(2 * self.n)] ...
20
20
[ "exact" ]
1
256
0.995
https://codeforces.com/problemset/problem/474/F
38
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
MEDIUM
codechef
[]
python
1
n = int(input()) a = list(map(int, input().split())) cnt = {} for i in range(n): mn = a[i] for j in range(i, n): mn = min(mn, a[j]) if mn in cnt: cnt[mn] += 1 else: cnt[mn] = 1 q = int(input()) for i in range(q): k = int(input()) if k in cnt: print(cnt[k]) else: print(0)
20
20
[ "exact", "whitespace" ]
1
50,000
0.993
https://www.codechef.com/problems/SUBMIN
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
68