id stringlengths 14 117 | description stringlengths 29 13k | code stringlengths 10 49.8k | test_samples dict | source class label 3
classes | prompt stringlengths 391 104k |
|---|---|---|---|---|---|
15_C. Industrial Nim_37313 | There are n stone quarries in Petrograd.
Each quarry owns mi dumpers (1 ≤ i ≤ n). It is known that the first dumper of the i-th quarry has xi stones in it, the second dumper has xi + 1 stones in it, the third has xi + 2, and the mi-th dumper (the last for the i-th quarry) has xi + mi - 1 stones in it.
Two oligarchs p... | __author__ = 'Darren'
def solve():
n = int(input())
xor = 0
for _i in range(n):
x, m = map(int, input().split())
xor ^= xor_range(x - 1) ^ xor_range(x + m - 1)
print(["tolik", "bolik"][xor == 0])
def xor_range(n):
return [n, 1, n+1, 0][n % 4]
if __name__ == '__m... | {
"input": [
"2\n2 1\n3 2\n",
"4\n1 1\n1 1\n1 1\n1 1\n",
"30\n53 12\n13 98\n21 60\n76 58\n39 5\n62 58\n73 80\n13 75\n37 45\n44 86\n1 85\n13 33\n17 50\n12 26\n97 48\n52 40\n2 71\n95 79\n38 76\n24 54\n91 39\n97 92\n94 80\n50 61\n33 56\n22 91\n39 94\n31 56\n28 16\n20 44\n",
"10\n2 3\n1 4\n5 8\n4 10\n10 8... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n stone quarries in Petrograd.
Each quarry owns mi dumpers (1 ≤ i ≤ n). It is known that the first dumper of the i-th quarry has xi stones in it, the second dumper has xi +... |
202_A. LLPS_37319 | This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string s consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.
We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk (1 ≤ ... | # -*- coding: utf-8 -*-
"""
Created on Thu Apr 2 19:56:34 2020
@author: roastedcoder
This is for CodeForces
"""
mod = 1000000007
ssi = lambda : map(int,input().split())
# RoastedCoder
s = input()
l = [0]*26
for i in range(len(s)):
l[ord(s[i])-97] += 1
for i in range(25,-1,-1):
if(l[i] >= 1):
pr... | {
"input": [
"mississipp\n",
"bowwowwow\n",
"codeforces\n",
"radar\n",
"sets\n",
"hellhellhe\n",
"aburvabur\n",
"b\n",
"zzzzzzwait\n",
"zzzzzzzzzz\n",
"a\n",
"testcase\n",
"aa\n",
"aabcdefghh\n",
"zzzzzzzazz\n",
"referee\n",
"seriously\n",
"test\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string s consisting of lowercase English lett... |
250_C. Movie Critics_37325 | A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre — an integer from 1 to k.
On the i-th day the festival will show a movie of genre ai. We know that a movie of each of k genres occurs in the festival progra... | # ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode... | {
"input": [
"7 3\n3 1 3 2 3 1 2\n",
"10 3\n1 1 2 3 2 3 3 1 1 3\n",
"2 2\n1 2\n",
"10 10\n5 7 8 2 4 10 1 3 9 6\n",
"100 12\n9 12 3 3 1 3 12 12 7 9 6 5 8 12 10 7 8 3 4 8 5 9 9 10 9 7 4 5 10 7 4 1 11 6 5 9 1 2 9 9 1 10 6 8 9 10 7 9 10 3 6 4 9 12 11 10 4 4 2 12 11 8 4 9 12 6 4 7 5 1 5 2 7 4 10 2 5 6 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre — an integer from 1 ... |
275_D. Zero Tree_37329 | A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices.
A subtree of a tree T is a tree with both vertices and edges as subsets of vertices and edges of T.
You're given a tr... | import sys
def minp():
return sys.stdin.readline().strip()
n = int(minp())
e = [0]
p = [None]*(n+1)
for i in range(n):
e.append([])
for i in range(n-1):
a, b = map(int,minp().split())
e[a].append(b)
e[b].append(a)
v = list(map(int,minp().split()))
plus = [0]*(n+1)
minus = [0]*(n+1)
was = [False]*(n+1)
was[1] = ... | {
"input": [
"3\n1 2\n1 3\n1 -1 1\n",
"5\n2 3\n4 5\n2 5\n1 3\n0 2 1 4 3\n",
"5\n3 1\n2 4\n3 4\n2 5\n0 -3 -1 2 4\n",
"12\n1 6\n10 1\n4 1\n7 1\n1 2\n5 1\n1 8\n1 11\n3 1\n12 1\n9 1\n580660007 861441526 -264928594 488291045 253254575 -974301934 709266786 926718320 87511873 514836444 -702876508 848928657\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair... |
299_A. Ksusha and Array_37333 | Ksusha is a beginner coder. Today she starts studying arrays. She has array a1, a2, ..., an, consisting of n positive integers.
Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number!
Input
The first line contains integer n (1 ... | input()
line = list(map(int, input().split()))
line.sort()
for i in line:
if i % line[0] != 0:
print(-1)
break
else:
print(line[0])
| {
"input": [
"3\n2 3 5\n",
"5\n2 1 3 1 6\n",
"3\n2 2 4\n",
"2\n6 4\n",
"5\n2 2 2 2 1000000000\n",
"5\n506904227 214303304 136194869 838256937 183952885\n",
"2\n6 10\n",
"5\n10 8 6 4 2\n",
"2\n500000000 1000000000\n",
"1\n1000000000\n",
"2\n4 6\n",
"1\n331358794\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Ksusha is a beginner coder. Today she starts studying arrays. She has array a1, a2, ..., an, consisting of n positive integers.
Her university teacher gave her a task. Find such numb... |
346_B. Lucky Common Subsequence_37339 | In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence BDF is a subsequence of ABCDEF. A substring of a string is a continuous subsequence of the string. For example, BCD is a substri... | #Not actually my code, solved mentally, only submitting to mark as solved so I don't do it again.
def gen(i, j):
if a[i][j] == -1:
a[i][j] = max(gen(i - 1, j - 1) + s2[i - 1] * (s2[i - 1] == s1[j - 1]), gen(i - 1, j), gen(i, j - 1), key = lambda x: [len(x), -x.count(viru)])
return a[i][j]
s1, s2, vir... | {
"input": [
"AA\nA\nA\n",
"AJKEQSLOBSROFGZ\nOVGURWZLWVLUXTH\nOZ\n",
"ABABBB\nABABBB\nABB\n",
"ABABABAC\nABABABAC\nABABAC\n",
"DASSDASDASDDAASDASDADASDASASDAS\nSDADASDASSDAASDASDASDADASSDDA\nSD\n",
"ABBB\nABBB\nABB\n",
"GOZVMIRQIGYGVAGOREQTXFXPEZYOJOXPNDGAESICXHMKQDXQPRLMRVWHXFEJVCWZDLYMQL... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the ... |
414_A. Mashmokh and Numbers_37347 | It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh.
In this game Mashmokh writes sequence of n distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first and the second integer from from the board, on the second move he rem... | from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
def main():
n, k = [ int(x) for x in input().split() ]
x = k - (n // 2 - 1)
if x < 1 or (n < 2 and k > 0):
print(-1)
return
sequence = [0] * n
sequence[0] = x
if n > 1:
... | {
"input": [
"7 2\n",
"5 2\n",
"5 3",
"4 1257\n",
"25095 2372924\n",
"20 15\n",
"7 11\n",
"7 3\n",
"28768 33384329\n",
"2 96996900\n",
"8 10\n",
"205 110\n",
"10 1000004\n",
"7 6\n",
"3455 2792393\n",
"13321 67580511\n",
"5 3\n",
"3 99999997\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh.
In this game Mashmokh writes sequence of n distinct integers on the board. Then Bimokh makes se... |
440_C. One-Based Arithmetic_37351 | Prof. Vasechkin wants to represent positive integer n as a sum of addends, where each addends is an integer number containing only 1s. For example, he can represent 121 as 121=111+11+–1. Help him to find the least number of digits 1 in such sum.
Input
The first line of the input contains integer n (1 ≤ n < 1015).
Ou... | import math
def find(n,i):
ans = 0
k = n // ones[i]
n = n % ones[i]
ans = ans + k * i
if n == 0:
return ans
return ans + min(find(n, i-1), i + find(ones[i] - n, i-1))
n = int(input())
ones = [0]
for i in range(1,17):
one = 10 * ones[i-1] + 1
ones.append(one)
print(find(n,16))
| {
"input": [
"121\n",
"5\n",
"768617061415848\n",
"6816793298\n",
"634\n",
"7\n",
"1\n",
"33388991\n",
"513\n",
"98596326741327\n",
"973546235465729\n",
"1079175250322\n",
"30272863\n",
"21\n",
"2\n",
"11472415\n",
"82415\n",
"185\n",
"203894... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Prof. Vasechkin wants to represent positive integer n as a sum of addends, where each addends is an integer number containing only 1s. For example, he can represent 121 as 121=111+11+... |
486_D. Valid Sets_37357 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.
We call a set S of tree nodes valid if following conditions are satisfied:
1. S is non-empty.
2. S is connected. In ... | import sys
def readInts(): return [int(x) for x in sys.stdin.readline().split()]
def readInt(): return int(sys.stdin.readline())
# def print(x):
# sys.stdout.write(str(x) + '\n')
def solve():
MOD = int(1e9 + 7)
d, n = readInts()
a = readInts()
adj: list = [[] for _ in range(n)]
for _ in ... | {
"input": [
"4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4\n",
"0 3\n1 2 3\n1 2\n2 3\n",
"1 4\n2 1 3 2\n1 2\n1 3\n3 4\n",
"18 29\n18 2 24 10 8 10 19 12 16 2 2 23 15 17 29 13 10 14 21 8 2 13 23 29 20 3 18 16 22\n11 23\n10 19\n14 22\n14 17\n25 26\n7 25\n7 11\n6 13\n1 3\n12 28\n1 2\n8 18\n6 8... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai assoc... |
50_C. Happy Farm 5_37361 | The Happy Farm 5 creators decided to invent the mechanism of cow grazing. The cows in the game are very slow and they move very slowly, it can even be considered that they stand still. However, carnivores should always be chased off them.
For that a young player Vasya decided to make the shepherd run round the cows a... | import math
n = int(input())
l = []
for i in range(n):
l.append(tuple(list(map(int, input().split(" ")))))
l = list(set(l))
n = len(l)
pmin = 0
for i in range(1, n):
if(l[i][1] < l[pmin][1] or (l[i][1] == l[pmin][1] and l[i][0] < l[pmin][0])):
pmin = i
l[pmin], l[0] = l[0], l[pmin]
def orientation(... | {
"input": [
"4\n1 1\n5 1\n5 3\n1 3\n",
"4\n0 2\n2 0\n3 5\n5 3\n",
"10\n1 0\n1 -3\n1 5\n1 -2\n1 5\n1 -2\n1 -2\n1 -2\n1 -2\n1 -2\n",
"60\n-20 179\n-68 0\n-110 68\n-22 177\n47 140\n-49 -4\n-106 38\n-23 22\n20 193\n47 173\n-23 22\n-100 32\n-97 29\n47 124\n-49 -4\n20 193\n-20 179\n-50 149\n-59 -7\n4 193\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The Happy Farm 5 creators decided to invent the mechanism of cow grazing. The cows in the game are very slow and they move very slowly, it can even be considered that they stand still... |
534_E. Berland Local Positioning System_37365 | In Berland a bus travels along the main street of the capital. The street begins from the main square and looks like a very long segment. There are n bus stops located along the street, the i-th of them is located at the distance ai from the central square, all distances are distinct, the stops are numbered in the orde... | r = lambda: list(map(int, input().split()))
ri = lambda: int(input())
n, a, m, b = ri(), r(), ri(), r()
c = [0] * n
for e in b: c[e - 1] += 1
c[0] *= 2; c[-1] *= 2
d = 0
df= 0
r = max(e // 2 for e in c)
c = [e - r * 2 for e in c]
if any(c):
for i in range(n - 1):
de = a[i+1] - a[i]
d += min(c[i], c[... | {
"input": [
"3\n10 200 300\n4\n1 2 2 3\n",
"3\n1 2 3\n4\n1 2 2 3\n",
"6\n2 3 5 7 11 13\n5\n3 4 5 5 6\n",
"6\n2 3 5 7 11 13\n9\n1 2 2 3 3 4 5 5 6\n",
"3\n1 3 11\n6\n1 2 2 2 3 3\n",
"4\n2 3 5 7\n8\n1 2 2 2 3 3 3 4\n",
"3\n1 3 11\n3\n1 2 3\n",
"2\n1 1000000000\n4\n1 1 2 2\n",
"2\n1 1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In Berland a bus travels along the main street of the capital. The street begins from the main square and looks like a very long segment. There are n bus stops located along the stree... |
585_C. Alice, Bob, Oranges and Apples_37371 | Alice and Bob decided to eat some fruit. In the kitchen they found a large bag of oranges and apples. Alice immediately took an orange for herself, Bob took an apple. To make the process of sharing the remaining fruit more fun, the friends decided to play a game. They put multiple cards and on each one they wrote a let... | import fractions
def solve(x, y):
if fractions.gcd(x, y) > 1: return 'Impossible'
turn = x > y
if not turn: x, y = y, x
ans = []
while x != 0 and y != 0:
ans.append((x//y, 'A' if turn else 'B'))
x, y = y, x%y
turn = not turn
ans[-1] = (ans[-1][0]-1, ans[-1][1])
return... | {
"input": [
"2 2\n",
"1 4\n",
"3 2\n",
"964542760623675601 965233603018687501\n",
"529495319593227313 631186172547690847\n",
"1000000000000000000 1000000000000000000\n",
"242 100\n",
"55 89\n",
"976540997167958951 969335176443917693\n",
"567036128564717939 510505130335113937\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Alice and Bob decided to eat some fruit. In the kitchen they found a large bag of oranges and apples. Alice immediately took an orange for herself, Bob took an apple. To make the proc... |
607_C. Marbles_37375 | In the spirit of the holidays, Saitama has given Genos two grid paths of length n (a weird gift even by Saitama's standards). A grid path is an ordered sequence of neighbouring squares in an infinite grid. Two squares are neighbouring if they share a side.
One example of a grid path is (0, 0) → (0, 1) → (0, 2) → (1, 2... | from time import time
opposite = {
'N': 'S',
'S': 'N',
'E': 'W',
'W': 'E'
}
otr = str.maketrans(opposite)
bits = {
'N': 0,
'S': 1,
'E': 2,
'W': 3,
}
Q = 4294967291
def combine(h, v, q):
return (h<<2 | v) % q
def combinel(h, v, q, s):
return (v*s + h) % q
def flip(s):
... | {
"input": [
"7\nNNESWW\nSWSWSW\n",
"3\nNN\nSS\n",
"2\nW\nS\n",
"12\nWNNWSWWSSSE\nNESWNNNWSSS\n",
"11\nWWNNNNWNWN\nENWSWWSSEE\n",
"200\nNESENEESEESWWWNWWSWSWNWNNWNNESWSWNNWNWNENESENNESSWSESWWSSSEEEESSENNNESSWWSSSSESWSWWNNEESSWWNNWSWSSWWNWNNEENNENWWNESSSENWNESWNESWNESEESSWNESSSSSESESSWNNENENESS... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In the spirit of the holidays, Saitama has given Genos two grid paths of length n (a weird gift even by Saitama's standards). A grid path is an ordered sequence of neighbouring square... |
629_B. Far Relative’s Problem_37379 | Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible.
Far cars are as weird as Far Far A... | n = (int)(input())
F1=[0]*n
F2=[0]*n
M1=[0]*n
M2=[0]*n
m=0
f=0
for i in range(n):
c = (input().split())
if(c[0]=='M'):
M1[m]=(int)(c[1])
M2[m]=(int)(c[2])
m=m+1
if(c[0]=='F'):
F1[f]=(int)(c[1])
F2[f]=(int)(c[2])
f=f+1
F=[0]*3232
M=[0]*3266
for i in range(f):
... | {
"input": [
"4\nM 151 307\nF 343 352\nF 117 145\nM 24 128\n",
"6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200\n",
"2\nF 1 1\nM 1 1\n",
"40\nM 55 363\nF 117 252\nM 157 282\nF 322 345\nM 330 363\nF 154 231\nF 216 352\nF 357 365\nM 279 292\nF 353 359\nF 82 183\nM 78 297\nM 231 314\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai ... |
653_C. Bear and Up-Down_37383 | The life goes up and down, just like nice sequences. Sequence t1, t2, ..., tn is called nice if the following two conditions are satisfied:
* ti < ti + 1 for each odd i < n;
* ti > ti + 1 for each even i < n.
For example, sequences (2, 8), (1, 5, 1) and (2, 5, 1, 100, 99, 120) are nice, while (1, 1), (1, 2, ... | def main():
n, l = int(input()), list(map(int, input().split()))
if not (n & 1):
l.append(0)
l.append(150001)
a, b, fails, res = 0, 150001, [], 0
for i, c in enumerate(l, -1):
if i & 1:
if a >= b or b <= c:
if len(fails) > 5:
print(0)
... | {
"input": [
"5\n2 8 4 7 7\n",
"4\n200 150 100 50\n",
"10\n3 2 1 4 1 4 1 4 1 4\n",
"9\n1 2 3 4 5 6 7 8 9\n",
"30\n18647 31594 58075 122543 49766 65303 48728 102863 22542 140297 5300 90685 50141 86948 27074 40214 17945 147095 97758 140835 121469 139920 63817 138623 85609 110002 70046 128002 122139 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The life goes up and down, just like nice sequences. Sequence t1, t2, ..., tn is called nice if the following two conditions are satisfied:
* ti < ti + 1 for each odd i < n;
* ... |
679_A. Bear and Prime 100_37387 | This is an interactive problem. In the output section below you will see the information about flushing the output.
Bear Limak thinks of some hidden number — an integer from interval [2, 100]. Your task is to say if the hidden number is prime or composite.
Integer x > 1 is called prime if it has exactly two distinct ... | #------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
# from fractions import *
# from heapq import*
from bisect import *
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')... | {
"input": [
"yes\nno\nyes\n",
"no\nyes\nno\nno\nno\n",
"9\n",
"2\n",
"82\n",
"59\n",
"58\n",
"18\n",
"100\n",
"25\n",
"85\n",
"16\n",
"3\n",
"38\n",
"62\n",
"97\n",
"51\n",
"94\n",
"36\n",
"87\n",
"64\n",
"69\n",
"74\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This is an interactive problem. In the output section below you will see the information about flushing the output.
Bear Limak thinks of some hidden number — an integer from interval... |
701_B. Cells Not Under Attack_37391 | Vasya has the square chessboard of size n × n and m rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another.
The cell of the field is under rook's attack, if there is at least one rook located in the same row or in the same column with this cell. If there is a roo... | n, m = map(int, input().strip().split())
remains = n*n
deleted_rows = set()
deleted_cols = set()
answer = []
for _ in range(m):
c, r = map(int, input().strip().split())
col_deleted = c in deleted_cols
row_deleted = r in deleted_rows
if not (col_deleted and row_deleted):
if col_deleted:
... | {
"input": [
"5 2\n1 5\n5 1\n",
"100000 1\n300 400\n",
"3 3\n1 1\n3 1\n2 2\n",
"99999 1\n54016 16192\n",
"99991 9\n80814 65974\n12100 98787\n9390 76191\n5628 47659\n80075 25361\n75330 1630\n38758 99962\n33848 40352\n43732 52281\n",
"1 1\n1 1\n",
"330 17\n259 262\n146 20\n235 69\n84 74\n131... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya has the square chessboard of size n × n and m rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another.
The cell of the fi... |
723_C. Polycarp at the Radio_37395 | Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be represented as a sequence a1, a2, ..., an, where ai is a band, which performs the i-th song. Polycarp likes bands with the numbers from 1 to m, but he doesn't really like others.
We define as bj the number of songs the g... | from collections import Counter
n, m = map(int, input().split())
nums = list(map(int, input().split()))
cnts = dict(Counter(nums))
for i in range(1, m+1):
if i not in cnts:
cnts[i] = 0
def minner():
return min(cnts.items(), key=lambda x: x[1])
n //= m
res = 0
for i, num in enumerate(nums):
if ... | {
"input": [
"4 2\n1 2 3 2\n",
"7 3\n1 3 2 2 2 2 1\n",
"4 4\n1000000000 100 7 1000000000\n",
"10 4\n1 1 2 2 3 3 4 4 4 4\n",
"1 1\n381183829\n",
"10 2\n1 1 1 1 1 1 3 4 5 6\n",
"7 3\n2 2 2 1 3 7 6\n",
"7 2\n2 2 2 2 2 2 3\n",
"10 2\n20515728 1 580955166 856585851 1 738372422 1 2 1 900... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be represented as a sequence a1, a2, ..., an, where ai is a band, which performs the i-t... |
745_B. Hongcow Solves A Puzzle_37399 | Hongcow likes solving puzzles.
One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an n by m grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that th... | n, m = map(int, input().split())
o1 = set()
for i in range(n):
s = input()
if s.count('X') != 0:
o1.add((s.count('X'), s.find('X'), s.rfind('X')))
if len(o1) == 1:
print('YES')
else:
print('NO') | {
"input": [
"2 2\n.X\nXX\n",
"5 5\n.....\n..X..\n.....\n.....\n.....\n",
"2 3\nXXX\nXXX\n",
"5 5\nXXX..\n.XXX.\n..XXX\nXXX..\n.XXX.\n",
"4 4\nXX..\n.XX.\n..XX\n....\n",
"3 3\n.XX\nXX.\nXX.\n",
"10 1\n.\n.\n.\n.\nX\n.\n.\n.\n.\n.\n",
"6 8\nXXXXXX..\nXXXXXXXX\n.X.X..X.\n.XXXX..X\nXX.XXX... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Hongcow likes solving puzzles.
One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an n by m gri... |
768_D. Jon and Orbs_37403 | Jon Snow is on the lookout for some orbs required to defeat the white walkers. There are k different types of orbs and he needs at least one of each. One orb spawns daily at the base of a Weirwood tree north of the wall. The probability of this orb being of any kind is equal. As the north of wall is full of dangers, he... | k, q = map(int, input().split())
t = [0] * (k + 1)
t[1] = 1
c = [0]
n = i = 1
while i < 1001:
if (2000 * t[k] > i - (10**-7)):
c.append(n)
i += 1
else:
t = [0] + [(j * t[j] + (k - j + 1) * t[j - 1]) / k for j in range(1, k + 1)]
n += 1
for i in range(q):
print(c[int(input())... | {
"input": [
"1 1\n1\n",
"2 2\n1\n2\n",
"1 1\n1000\n",
"3 5\n1\n4\n20\n50\n300\n",
"5 6\n1\n2\n3\n4\n5\n6\n",
"8 10\n50\n150\n250\n350\n450\n550\n650\n750\n850\n950\n",
"6 6\n10\n20\n30\n40\n50\n60\n",
"990 1\n990\n",
"7 10\n100\n200\n300\n400\n500\n600\n700\n800\n900\n1000\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Jon Snow is on the lookout for some orbs required to defeat the white walkers. There are k different types of orbs and he needs at least one of each. One orb spawns daily at the base ... |
792_C. Divide by Three_37407 | A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible.
The number is called beautiful if it consists of at least one digit, doesn't have leading zer... | a = input()
if len(a) == 1:
if int(a) % 3 == 0:
print(a)
else:
print(-1)
exit(0)
one = []
two = []
sum = 0
zs, zf = 0, 0
for i in range(len(a)):
q = int(a[i])
sum += q
if q == 0:
if zs == 0:
zs = i
else:
if zs != 0 and zf == 0:
zf = i
... | {
"input": [
"10\n",
"11\n",
"1033\n",
"100020001\n",
"100000000000000000222\n",
"8008\n",
"10000555\n",
"20020201\n",
"7\n",
"10001\n",
"2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002\n",
"8059\n",
"100000001\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and yo... |
812_E. Sagheer and Apple Tree_37411 | Sagheer is playing a game with his best friend Soliman. He brought a tree with n nodes numbered from 1 to n and rooted at node 1. The i-th node has ai apples. This tree has a special property: the lengths of all paths from the root to any leaf have the same parity (i.e. all paths have even length or all paths have odd ... | n= int(input())
a = [int(_) for _ in input().split()]
c = [int(_) for _ in input().split()]
depth = [0] * (n)
for i in range(1,n):
depth[i] = depth[c[i-1]-1] + 1
MAX = max(depth)
t = 0
store = {}
todo = []
p = 0
for i in range(n):
if (MAX-depth[i]) % 2 == 0: # odd, useful
t ^= a[i]
todo.append(a[... | {
"input": [
"8\n7 2 2 5 4 3 1 1\n1 1 1 4 4 5 6\n",
"3\n1 2 3\n1 1\n",
"3\n2 2 3\n1 1\n",
"5\n87 100 12 93 86\n1 1 3 4\n",
"8\n5201 769 1896 5497 1825 9718 7784 5952\n1 2 3 4 2 1 7\n",
"5\n753534 24400 461709 881954 452720\n1 2 3 1\n",
"2\n1848 2048\n1\n",
"21\n6194737 6429360 6047962 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Sagheer is playing a game with his best friend Soliman. He brought a tree with n nodes numbered from 1 to n and rooted at node 1. The i-th node has ai apples. This tree has a special ... |
859_B. Lazy Security Guard_37417 | Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly N city blocks, but they let him choose which blocks. That is, your friend must walk the perimeter of a region whose area is exactly N blocks. Your friend is quite lazy... | import math
n=int(input())
print(math.ceil(math.sqrt(n)*2)*2) | {
"input": [
"22\n",
"11\n",
"4\n",
"9\n",
"1024\n",
"718351\n",
"246206\n",
"2\n",
"6\n",
"3751\n",
"3607\n",
"101\n",
"1000000\n",
"59637\n",
"8\n",
"5\n",
"3\n",
"607443\n",
"10\n",
"19\n",
"23\n",
"999999\n",
"31\n",
"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly N city blocks, but they let hi... |
884_A. Book Reading_37421 | Recently Luba bought a very interesting book. She knows that it will take t seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of n next days. The number of seconds that Luba has to spend working during i-th day is ai. If some free time remains, she can spend... | n,t=map(int,input().split())
a=input().split()
i=0
while t > 0:
t-=(86400-int(a[i]))
i += 1
print(i)
| {
"input": [
"2 2\n86400 86398\n",
"2 86400\n0 86400\n",
"6 1200\n86400 86400 86000 86000 86000 86400\n",
"4 172799\n1 1 86400 0\n",
"6 1\n1 1 86400 1 86399 1\n",
"100 1000000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Recently Luba bought a very interesting book. She knows that it will take t seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in ... |
908_C. New Year and Curling_37425 | Carol is currently curling.
She has n disks each with radius r on the 2D plane.
Initially she has all these disks above the line y = 10100.
She then will slide the disks towards the line y = 0 one by one in order from 1 to n.
When she slides the i-th disk, she will place its center at the point (xi, 10100). She w... | n, r = map(int, input().split())
a = input().split()
ans = []
for i in range(n):
res = r
for j in range(i):
if (abs(int(a[j]) - int(a[i])) <= 2 * r):
res = max(res, ans[j] + (4 * r * r - abs(int(a[j]) - int(a[i])) ** 2) ** 0.5)
ans.append(res)
for i in range(n):
print(ans[i], end = '... | {
"input": [
"6 2\n5 5 6 8 3 12\n",
"1 1\n5\n",
"3 10\n1 100 1000\n",
"5 300\n939 465 129 611 532\n",
"5 1\n416 387 336 116 81\n",
"2 1\n2 20\n",
"3 2\n10 10 100\n",
"1 1\n1\n",
"3 10\n1 000 1000\n",
"5 300\n939 465 246 611 532\n",
"5 1\n416 387 230 116 81\n",
"2 1\n0 2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Carol is currently curling.
She has n disks each with radius r on the 2D plane.
Initially she has all these disks above the line y = 10100.
She then will slide the disks towards t... |
92_B. Binary Number_37429 | Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations.
Fangy takes some positive integer x and wants to get a number one from it. While x is not equal to 1, Fangy repeats the following action: if x is odd, then he adds 1 to it, otherwise he divides x by... | from collections import *
def add(n):
for i in range(len(n) - 1, -1, -1):
if n[i] == '1':
n[i] = '0'
else:
n[i] = '1'
return n
n.appendleft('1')
return n
def main():
n, ans = deque(input()), 0
while (len(n) != 1):
if n[-1] == '1':
... | {
"input": [
"1\n",
"101110\n",
"1001001\n",
"11100000110100011110101001101111100000011001111000011110000000111110111\n",
"1000101100110000000001111010110000000010001001111110011011000011101011001001010010111\n",
"10000100000\n",
"1010101001001111000111110011111000010101011111101010\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations.
Fangy takes some positive integer x and wants to get a number... |
983_B. XOR-pyramid_37434 | For an array b of length m we define the function f as
f(b) = \begin{cases} b[1] & if m = 1 \\\ f(b[1] ⊕ b[2],b[2] ⊕ b[3],...,b[m-1] ⊕ b[m]) & otherwise, \end{cases}
where ⊕ is [bitwise exclusive OR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
For example, f(1,2,4,8)=f(1⊕2,2⊕4,4⊕8)=f(3,6,12)=f(3⊕6... | n = int(input())
arr = list(map(int, input().split()))
aux = [[0] * n for i in range(n)]
for i in range(n):
aux[0][i] = arr[i]
for i in range(1, n):
for j in range(n-i):
aux[i][j] = aux[i-1][j] ^ aux[i-1][j+1]
for i in range(1, n):
for j in range(n-i):
aux[i][j] = max(aux[i][j], aux[i-1][j], aux[i-... | {
"input": [
"6\n1 2 4 8 16 32\n4\n1 6\n2 5\n3 4\n1 2\n",
"3\n8 4 1\n2\n2 3\n1 2\n",
"6\n1 2 4 12 16 32\n4\n1 6\n2 5\n3 4\n1 2\n",
"3\n6 4 1\n2\n2 3\n1 2\n",
"6\n0 2 4 12 16 32\n4\n2 6\n2 5\n3 4\n1 2\n",
"6\n0 2 4 12 16 32\n4\n2 3\n2 5\n3 4\n1 2\n",
"3\n8 4 1\n2\n2 3\n2 2\n",
"6\n1 2 4... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
For an array b of length m we define the function f as
f(b) = \begin{cases} b[1] & if m = 1 \\\ f(b[1] ⊕ b[2],b[2] ⊕ b[3],...,b[m-1] ⊕ b[m]) & otherwise, \end{cases}
where ... |
p02565 AtCoder Library Practice Contest - Two SAT_37448 | Consider placing N flags on a line. Flags are numbered through 1 to N.
Flag i can be placed on the coordinate X_i or Y_i. For any two different flags, the distance between them should be at least D.
Decide whether it is possible to place all N flags. If it is possible, print such a configulation.
Constraints
* 1 \l... | class Two_SAT:
"""2-SATを定義する.
"""
#入力定義
def __init__(self,variable=[]):
self.variable=set(variable)
self.clause_number=0
self.variable_number=len(variable)
self.adjacent_out={(v,b):set() for v in variable for b in [True,False]} #出近傍(vが始点)
self.adjacent_in={(v,... | {
"input": [
"3 3\n1 4\n2 5\n0 6",
"3 2\n1 4\n2 5\n0 6",
"3 3\n1 4\n2 5\n0 10",
"3 2\n1 5\n2 5\n0 6",
"3 3\n1 4\n2 2\n0 10",
"3 2\n1 5\n4 5\n0 6",
"3 3\n1 4\n2 4\n0 10",
"3 3\n1 4\n2 5\n0 16",
"3 3\n1 2\n2 4\n-1 9",
"3 3\n2 4\n2 1\n0 10",
"3 3\n0 4\n2 1\n-1 13",
"3 3\n-... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Consider placing N flags on a line. Flags are numbered through 1 to N.
Flag i can be placed on the coordinate X_i or Y_i. For any two different flags, the distance between them shoul... |
p02696 AtCoder Beginner Contest 165 - Floor Function_37452 | Given are integers A, B, and N.
Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N.
Here floor(t) denotes the greatest integer not greater than the real number t.
Constraints
* 1 ≤ A ≤ 10^{6}
* 1 ≤ B ≤ 10^{12}
* 1 ≤ N ≤ 10^{12}
* All values in input are i... | A,B,N = map(int,input().split())
c = min(B - 1,N)
print((A * c)//B) | {
"input": [
"5 7 4",
"11 10 9",
"4 7 4",
"1 7 4",
"5 7 5",
"2 7 4",
"7 7 5",
"20 10 3",
"35 10 3",
"9 6 5",
"56 12 1",
"11 4 4",
"11 11 9",
"-2 2 1",
"14 7 8",
"42 7 3",
"11 10 2",
"2 10 2",
"1 7 1",
"2 10 0",
"1 7 0",
"2 11 0",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Given are integers A, B, and N.
Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N.
Here floor(t) denotes the greatest i... |
p02825 AtCoder Grand Contest 041 - Domino Quality_37456 | Let us consider a grid of squares with N rows and N columns. You want to put some domino pieces on this grid. Each domino piece covers two squares that have a common side. Each square can be covered by at most one piece.
For each row of the grid, let's define its quality as the number of domino pieces that cover at le... | n = int(input())
s3=["abb","a.d","ccd"]
s = [["abcc", "abdd", "ddba", "ccba"],
["dccdd", "daa.c", "c..bc", "c..bd", "ddccd"],
["abbc..", "a.ac..", "bba.cc", "a..aab", "a..b.b", ".aabaa"],
["aba....","aba....","bab....","bab....","a..bbaa","a..aabb",".aabbaa"]]
if n == 2:
print(-1)
elif n == 3:
[print(x) for x ... | {
"input": [
"2",
"6",
"0",
"3",
"5",
"4",
"10",
"13",
"14",
"11",
"15",
"7",
"9",
"8",
"28",
"36",
"12",
"17",
"20",
"26",
"18",
"30",
"16",
"47",
"83",
"111",
"101",
"100",
"34",
"110",
"24",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Let us consider a grid of squares with N rows and N columns. You want to put some domino pieces on this grid. Each domino piece covers two squares that have a common side. Each square... |
p02962 AtCoder Beginner Contest 135 - Strings of Eternity_37459 | Given are two strings s and t consisting of lowercase English letters. Determine if the number of non-negative integers i satisfying the following condition is finite, and find the maximum value of such i if the number is finite.
* There exists a non-negative integer j such that the concatenation of i copies of t is a... | # AOJ ALDS1_14_B "String Search"
# returns i s.t. S[i+j] = T[j] for 0 <= j < len(T)
def RollingHash(S, T, ls):
if len(S) < len(T):
return []
# gcd(h, b) = 1
h = 10**11+7
b = 10**7+7
L = len(T)
bL = 1
for i in range(L):
bL = bL * b % h
hashS = 0
for i in range(L):
... | {
"input": [
"aa\naaaaaaa",
"aba\nbaaab",
"abcabab\nab",
"aa\nabaaaaa",
"abcaabb\nab",
"aba\naaaab",
"aa\naaaaaba",
"aba\naa`ab",
"accaabb\nab",
"ab\naaaaaba",
"`ba\naa`ab",
"acdaabb\nab",
"ab\nabaaaaa",
"`ab\naa`ab",
"acda`bb\nab",
"ab\nabaaaba",
"a... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Given are two strings s and t consisting of lowercase English letters. Determine if the number of non-negative integers i satisfying the following condition is finite, and find the ma... |
p03097 AtCoder Grand Contest 031 - Differ by 1 Bit_37463 | You are given integers N,\ A and B. Determine if there exists a permutation (P_0,\ P_1,\ ...\ P_{2^N-1}) of (0,\ 1,\ ...\ 2^N-1) that satisfies all of the following conditions, and create one such permutation if it exists.
* P_0=A
* P_{2^N-1}=B
* For all 0 \leq i < 2^N-1, the binary representations of P_i and P_{i+1} ... | N, A, B = map(int, input().split())
def f(n, a, b):
if n == 1:
return [a, b]
mask = 1 << (n-1)
if a & mask == b & mask:
v1 = f(n-1, a, b)
v2 = f(n-1, a ^ mask, v1[1] ^ mask)
ret = v1[:1]
ret.extend(v2)
ret.extend(v1[1:])
return ret
else:
... | {
"input": [
"3 2 1",
"2 1 3",
"2 1 0",
"2 0 0",
"1 0 1",
"2 2 0",
"1 2 3",
"1 3 2",
"2 3 2",
"2 0 2",
"2 2 3",
"2 3 1",
"2 0 1",
"1 1 0",
"1 -2 -1",
"1 -1 -2",
"4 0 0",
"7 0 0",
"6 2 1",
"1 0 0",
"5 0 0",
"5 2 1",
"2 2 1",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given integers N,\ A and B. Determine if there exists a permutation (P_0,\ P_1,\ ...\ P_{2^N-1}) of (0,\ 1,\ ...\ 2^N-1) that satisfies all of the following conditions, and cr... |
p03243 AtCoder Beginner Contest 111 - AtCoder Beginner Contest 111_37467 | Kurohashi has never participated in AtCoder Beginner Contest (ABC).
The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same.
What is the earliest ABC where Kurohashi can make his debut?
Constraints
* 100 \leq N... | N=int(input());print(111*(-(-N//111))) | {
"input": [
"750",
"112",
"111",
"426",
"101",
"638",
"268",
"457",
"000",
"985",
"846",
"198",
"706",
"110",
"001",
"409",
"100",
"662",
"011",
"010",
"514",
"583",
"223",
"625",
"266",
"645",
"195",
"398... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Kurohashi has never participated in AtCoder Beginner Contest (ABC).
The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such th... |
p03561 AtCoder Regular Contest 084 - Finite Encyclopedia of Integer Sequences_37473 | In Finite Encyclopedia of Integer Sequences (FEIS), all integer sequences of lengths between 1 and N (inclusive) consisting of integers between 1 and K (inclusive) are listed.
Let the total number of sequences listed in FEIS be X. Among those sequences, find the (X/2)-th (rounded up to the nearest integer) lexicograph... | import sys
input = sys.stdin.readline
K,N = map(int,input().split())
if K % 2 == 0:
L = K // 2
R = L + 1
# 先頭の文字が L のものの最後、R のものの最初、で境界
arr = [L] + [K] * (N-1)
else:
"""
[3,3,3,3,3] だと 手前に3 33 333 3333 が余分。2歩戻る。
"""
arr = [(K+1)//2] * N
x = N//2# x歩 戻る
for i in range(x):
... | {
"input": [
"2 4",
"5 14",
"3 2",
"0 4",
"8 14",
"0 14",
"1 14",
"2 14",
"2 1",
"0 1",
"2 5",
"2 26",
"2 2",
"0 5",
"9 14",
"0 28",
"2 10",
"0 2",
"3 1",
"1 5",
"2 11",
"0 3",
"9 12",
"1 28",
"1 10",
"4 2",
"1... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In Finite Encyclopedia of Integer Sequences (FEIS), all integer sequences of lengths between 1 and N (inclusive) consisting of integers between 1 and K (inclusive) are listed.
Let th... |
p03714 AtCoder Beginner Contest 062 - 3N Numbers_37477 | Let N be a positive integer.
There is a numerical sequence of length 3N, a = (a_1, a_2, ..., a_{3N}). Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements from a without changing the order of the remaining elements. Here, the score of a' is defined as follows: (the sum of the elements ... | def f(x):
y=x[:n];heapify(y);z=sum(y);s=[z]
for i in x[n:n*2]:z+=i-heappushpop(y,i);s+=[z]
return s
from heapq import*;n,*a=map(int,open(0).read().split());print(max(map(sum,zip(f([-i for i in a[n:][::-1]]),f(a)[::-1])))) | {
"input": [
"2\n3 1 4 1 5 9",
"1\n1 2 3",
"3\n8 2 2 7 4 6 5 3 8",
"2\n3 1 4 1 7 9",
"3\n8 2 2 7 4 6 6 3 8",
"2\n3 1 4 1 7 0",
"1\n1 0 5",
"1\n1 -1 5",
"3\n8 1 2 7 4 6 6 0 8",
"1\n0 0 5",
"2\n3 2 4 2 11 0",
"3\n8 2 2 7 4 6 4 0 15",
"3\n8 2 2 7 4 6 4 -1 15",
"3\n... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Let N be a positive integer.
There is a numerical sequence of length 3N, a = (a_1, a_2, ..., a_{3N}). Snuke is constructing a new sequence of length 2N, a', by removing exactly N ele... |
p04037 AtCoder Grand Contest 002 - Candy Piles_37482 | There are N piles of candies on the table. The piles are numbered 1 through N. At first, pile i contains a_i candies.
Snuke and Ciel are playing a game. They take alternating turns. Snuke goes first. In each turn, the current player must perform one of the following two operations:
1. Choose a pile with the largest n... | N=int(input())
A=list(map(int,input().split()))
A.append(0)
A.sort()
winner=""
for i in range(N+1):
if A[N-i]>i:
if (A[N-i]-i)%2==0:
winner="First"
else:
winner="Second"
elif A[N-i]==i:
if (A[N-i+1]-A[N-i])%2==1:
winner="First"
break
... | {
"input": [
"3\n1 2 1",
"2\n1 3",
"3\n1 2 3",
"3\n1 0 1",
"2\n0 3",
"3\n1 1 3",
"3\n2 0 1",
"3\n1 1 4",
"3\n3 0 1",
"3\n1 0 4",
"3\n5 0 1",
"3\n0 0 4",
"3\n1 0 2",
"3\n1 4 1",
"2\n1 4",
"3\n1 2 5",
"2\n1 0",
"3\n1 1 6",
"3\n2 1 1",
"3\n1... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are N piles of candies on the table. The piles are numbered 1 through N. At first, pile i contains a_i candies.
Snuke and Ciel are playing a game. They take alternating turns. ... |
p00118 Property Distribution_37486 | Mr. Tanaka died leaving the orchard of HW Earl. The orchard is divided into H x W plots in the north, south, east, and west directions, and apples, oysters, and oranges are planted in each plot. Mr. Tanaka left such a will.
Divide the orchard into as many relatives as possible on a parcel basis. However, if the same k... | import sys
sys.setrecursionlimit(100000)
def solve(x, y, char):
for deltaX in [1, -1]:
if 0 <= x + deltaX and x + deltaX < w and matrix[y][x + deltaX] == char:
matrix[y][x + deltaX] = "."
solve(x+deltaX, y, char)
for deltaY in [1, -1]:
if 0 <= y + deltaY and y + deltaY ... | {
"input": [
"10 10\n*****@\n@#@@@@#*#*\n@##***@@@*\n****#*@**\n@*#@@*##\n*@@@@*@@@#\n***#@*@##*\n*@@@*@@##@\n*@*#*@##**\n@****#@@#@\n0 0",
"10 10\n####*****@\n@#@@@@#*#*\n@##***@@@*\n#****#*@**\n##@*#@@*##\n*@@@@*@@@#\n***#@*@##*\n*@@@*@@##@\n*@*#*@##**\n@****#@@#@\n0 0",
"10 10\n*****@\n@#@@@@#*#*\n@##*... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Mr. Tanaka died leaving the orchard of HW Earl. The orchard is divided into H x W plots in the north, south, east, and west directions, and apples, oysters, and oranges are planted in... |
p00251 Points for a Perfect Scorer_37490 | Welcome to PC Koshien, players. This year marks the 10th anniversary of Computer Koshien, but the number of questions and the total score will vary from year to year. Scores are set for each question according to the difficulty level. When the number of questions is 10 and the score of each question is given, create a ... | s1=int(input())
s2=int(input())
s3=int(input())
s4=int(input())
s5=int(input())
s6=int(input())
s7=int(input())
s8=int(input())
s9=int(input())
s10=int(input())
total=0
total+=s1
total+=s2
total+=s3
total+=s4
total+=s5
total+=s6
total+=s7
total+=s8
total+=s9
total+=s10
print(total)
| {
"input": [
"1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"1\n2\n4\n4\n5\n6\n7\n8\n9\n10",
"1\n2\n8\n4\n5\n6\n7\n8\n9\n10",
"1\n2\n8\n4\n3\n6\n7\n8\n9\n10",
"1\n2\n8\n3\n3\n6\n7\n8\n9\n10",
"1\n2\n8\n3\n3\n6\n7\n5\n9\n10",
"1\n2\n8\n4\n3\n6\n7\n5\n9\n10",
"1\n2\n2\n4\n3\n6\n7\n5\n9\n10",
"1\n2... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Welcome to PC Koshien, players. This year marks the 10th anniversary of Computer Koshien, but the number of questions and the total score will vary from year to year. Scores are set f... |
p00628 Yes_37496 | Dr .: Peter, do you know "Yes, I have a number"?
Peter: I used to do it on TV the other day. You remember something by the number of characters in each word contained in a sentence. "Yes, I have a number", so it means "the number 3.14" and is a keyword for remembering pi.
Dr .: Peter, that's not the case. This should... | import sys
sys.setrecursionlimit(10**6)
def main():
s = input()
if s == "END OF INPUT":
return False
if s[0] == " ":
s[0] = "."
for _ in range(100):
s = s.replace(" ", " . ")
lst = s.split()
ans = []
for i in lst:
if i == ".":
ans += [0]
e... | {
"input": [
"Yes I have a number\nHow I wish I could calculate an unused color for space\nThank you\nEND OF INPUT",
"Yes I have a number\nHow I wish I could calculate an unused bolor for space\nThank you\nEND OF INPUT",
"Yes I have a rebmun\nHow I wish I could calculate an unused bolor for space\nThank y... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Dr .: Peter, do you know "Yes, I have a number"?
Peter: I used to do it on TV the other day. You remember something by the number of characters in each word contained in a sentence. ... |
p00903 Round Trip_37500 | Jim is planning to visit one of his best friends in a town in the mountain area. First, he leaves his hometown and goes to the destination town. This is called the go phase. Then, he comes back to his hometown. This is called the return phase. You are expected to write a program to find the minimum total cost of this t... | from heapq import heappush, heappop
from collections import defaultdict
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N, M = map(int, readline().split())
if N == M == 0:
return False
D = [0]*N; E = [0]*N
B = [0]*N
H = defaultdict(int)
H[0] = 1
H[1000]... | {
"input": [
"3 6\n3 1\n1 2 1\n2 3 1\n3 2 1\n2 1 1\n1 3 4\n3 1 4\n3 6\n5 1\n1 2 1\n2 3 1\n3 2 1\n2 1 1\n1 3 4\n3 1 4\n4 5\n3 1\n3 1\n1 2 5\n2 3 5\n3 4 5\n4 2 5\n3 1 5\n2 1\n2 1 1\n0 0",
"3 6\n3 1\n1 2 1\n2 3 1\n3 2 1\n2 1 1\n1 3 4\n3 1 4\n3 6\n5 1\n2 2 1\n2 3 1\n3 2 1\n2 1 1\n1 3 4\n3 1 4\n4 5\n3 1\n3 1\n1 2 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Jim is planning to visit one of his best friends in a town in the mountain area. First, he leaves his hometown and goes to the destination town. This is called the go phase. Then, he ... |
p01036 Yu-kun Likes To Play Darts_37502 | Background
The kindergarten attached to the University of Aizu is a kindergarten where children who love programming gather. Yu, one of the kindergarten children, loves darts as much as programming. Yu-kun was addicted to darts recently, but he got tired of ordinary darts, so he decided to make his own darts board.
S... | # 参考 http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=3277276#1
from math import acos, hypot, isclose, sqrt
def intersection(circle, polygon):
# 円と多角形の共通部分の面積
# 多角形の点が反時計回りで与えられれば正の値、時計回りなら負の値を返す
x, y, r = circle
polygon = [(xp-x, yp-y) for xp, yp in polygon]
area = 0.0
for p1, p2 in zip(po... | {
"input": [
"1 2 2 1\n4 1\n0 0\n5 0\n5 5\n0 5",
"1 2 2 1\n4 1\n0 0\n2 0\n2 2\n0 2",
"1 10 10 1\n4 10\n0 0\n1 0\n1 1\n0 1",
"4 3 3 2\n3 1\n1 1\n3 3\n1 5\n4 2\n2 0\n5 0\n4 2\n3 2\n3 3\n4 3\n6 1\n6 5\n4 4\n3 4\n4 4\n5 6\n2 6",
"1 2 2 1\n4 1\n-1 0\n5 0\n5 5\n0 5",
"1 2 2 1\n4 1\n0 0\n1 0\n2 2\n0 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Background
The kindergarten attached to the University of Aizu is a kindergarten where children who love programming gather. Yu, one of the kindergarten children, loves darts as much... |
p01306 Unit Converter_37505 | In the International System of Units (SI), various physical quantities are expressed in the form of "numerical value + prefix + unit" using prefixes such as kilo, mega, and giga. For example, "3.5 kilometers", "5.1 milligrams", and so on.
On the other hand, these physical quantities can be expressed as "3.5 * 10 ^ 3 m... | m = {"yotta":24, "zetta":21, "exa":18, "peta":15, "tera":12, "giga":9, "mega":6, "kilo":3, "hecto":2, "deca":1, "deci":-1, "centi":-2, "milli":-3, "micro":-6, "nano":-9, "pico":-12, "femto":-15, "ato":-18, "zepto":-21, "yocto":-24}
for _ in range(int(input())):
v, *b = input().split()
if len(b) == 2:
k,... | {
"input": [
"7\n12.3 kilo meters\n0.45 mega watts\n0.000000000000000000000001 yotta grams\n1000000000000000000000000 yocto seconds\n42 amperes\n0.42 joules\n1234.56789012345678901234567890 hecto pascals",
"7\n12.3 kilo meters\n0.45 mega watts\n0.000000000000000000000001 yotta grams\n1000000000000000000000000... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In the International System of Units (SI), various physical quantities are expressed in the form of "numerical value + prefix + unit" using prefixes such as kilo, mega, and giga. For ... |
p01787 RLE Replacement_37511 | H - RLE Replacement
Problem Statement
In JAG Kingdom, ICPC (Intentionally Compressible Programming Code) is one of the common programming languages. Programs in this language only contain uppercase English letters and the same letters often appear repeatedly in ICPC programs. Thus, programmers in JAG Kingdom prefer t... | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.... | {
"input": [
"R 100 L 20 E 10 \\$\nR 5 L 10 \\$\nX 20 \\$",
"R 100 L 20 E 10 \\$\nR 5 L 6 \\$\nX 20 \\$",
"R 100 L 20 E 6 \\$\nR 5 L 10 \\$\nX 20 $\\",
"R 100 L 23 E 10 \\$\nR 5 L 6 \\$\nX 20 $\\",
"R 100 K 20 E 10 \\$\nS 1 L 11 \\#\nX 20 \\$",
"R 100 L 20 D 10 \\$\nS 1 L 11 \\%\nW 20 \\$",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
H - RLE Replacement
Problem Statement
In JAG Kingdom, ICPC (Intentionally Compressible Programming Code) is one of the common programming languages. Programs in this language only c... |
p02060 Four Tea_37514 | A: four tea
problem
Tea is indispensable for programming contests. Tea has the effect of relieving constant tension [citation needed]
There are N players participating in the contest, so I would like to prepare tea for this number of people. There are four types of tea packages, A, B, C, and D, all of which are the ... | n,pa,pb,pc,pd,ta,tb,tc,td=map(int,open(0).read().split())
r=range(n+1)
m=1e9
for i in r:
for j in r:
for k in r:
l=0--(n-ta*i-tb*j-tc*k)//td
m=min(m,pa*i+pb*j+pc*k+pd*l*(l>=0))
print(m)
| {
"input": [
"10\n1 2 3 4\n1 2 4 8",
"10\n1 2 3 2\n1 2 4 8",
"10\n1 1 3 2\n0 2 3 8",
"10\n1 1 3 2\n0 2 3 16",
"10\n0 1 3 2\n1 2 3 16",
"10\n1 2 3 4\n1 3 4 8",
"10\n1 1 3 2\n0 2 3 1",
"10\n0 1 6 1\n0 0 1 50",
"10\n0 2 1 4\n0 1 0 8",
"10\n1 2 3 2\n0 0 4 3",
"10\n1 1 6 2\n1 1 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A: four tea
problem
Tea is indispensable for programming contests. Tea has the effect of relieving constant tension [citation needed]
There are N players participating in the conte... |
p02202 Gag_37517 | Gag
Segtree has $ N $ of "gags", each with a value of $ V_i $.
Segtree decided to publish all the gags in any order.
Here, the "joy" you get when you publish the $ i $ th gag to the $ j $ th is expressed as $ V_i --j $.
Find the maximum sum of the "joy" you can get.
input
Input is given from standard input in the... | n = int(input())
v = list(map(int,input().split()))
count = 0
ans = 0
s = -1
while count != n:
ans -= s
s -= 1
count += 1
print(sum(v)-ans)
| {
"input": [
"1\n59549",
"1\n114525",
"1\n105905",
"1\n196252",
"1\n26794",
"1\n22977",
"1\n6310",
"1\n12378",
"1\n20899",
"1\n6312",
"1\n6759",
"1\n1599",
"1\n1545",
"1\n545",
"1\n834",
"1\n736",
"1\n1350",
"1\n1692",
"1\n1144",
"1\n456"... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Gag
Segtree has $ N $ of "gags", each with a value of $ V_i $.
Segtree decided to publish all the gags in any order.
Here, the "joy" you get when you publish the $ i $ th gag to th... |
p02356 The Number of Windows_37520 | For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and $Q$ integers $x_i$ as queries, for each query, print the number of combinations of two integers $(l, r)$ which satisfies the condition: $1 \leq l \leq r \leq N$ and $a_l + a_{l+1} + ... + a_{r-1} + a_r \leq x_i$.
Constraints
* $1 \leq N \leq 10^5$
* $1 ... | from bisect import bisect_right
def main():
N, Q = map(int, input().split())
a = [-1 for i in range(N)]
sum = [0 for i in range(N + 1)]
for i, val in enumerate(input().split()):
a[i] = int(val)
sum[i + 1] = sum[i] + a[i]
X = list(map(int, input().split()))
# print("DEBUG: sum={... | {
"input": [
"6 5\n1 2 3 4 5 6\n6 9 12 21 15",
"6 5\n1 2 3 4 7 6\n6 9 12 21 15",
"6 5\n1 2 3 2 7 6\n6 9 12 21 15",
"6 5\n1 2 3 2 7 6\n6 12 12 21 15",
"6 5\n1 2 3 2 7 6\n0 12 12 21 15",
"6 5\n1 2 3 5 5 6\n6 9 12 21 15",
"6 5\n1 2 3 4 7 6\n6 9 12 21 21",
"6 5\n1 2 3 2 7 6\n6 1 12 21 15",... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and $Q$ integers $x_i$ as queries, for each query, print the number of combinations of two integers $(l, r)$ which satisfi... |
1015_A. Points in Segments_37530 | You are given a set of n segments on the axis Ox, each segment has integer endpoints between 1 and m inclusive. Segments may intersect, overlap or even coincide with each other. Each segment is characterized by two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ m) — coordinates of the left and of the right endpoints.
Consider... | n, m = [int(x) for x in input().split()]
s = set(range(1, m+1))
for _ in range(n):
a, b = [int(x) for x in input().split()]
s -= set(range(a, b+1))
print(len(s))
print(*s)
| {
"input": [
"1 7\n1 7\n",
"3 5\n2 2\n1 2\n5 5\n",
"100 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a set of n segments on the axis Ox, each segment has integer endpoints between 1 and m inclusive. Segments may intersect, overlap or even coincide with each other. Each ... |
1038_E. Maximum Matching_37534 | You are given n blocks, each of them is of the form [color_1|value|color_2], where the block can also be flipped to get [color_2|value|color_1].
A sequence of blocks is called valid if the touching endpoints of neighboring blocks have the same color. For example, the sequence of three blocks A, B and C is valid if th... | def min(a, b):
if a < b:
return a
return b
def max(a,b):
return abs(min(-a,-b))
been = [0 for i in range(4)]
ans = 0
minw = 10**18
degpar = [0 for i in range(4)]
w = [0 for i in range(4)]
gr = [list() for i in range(4)]
rem = [[0 for i in range(4)] for j in range(4)]
def dfs(x, l):
l.append(w[x]... | {
"input": [
"4\n1 1000 1\n2 500 2\n3 250 3\n4 125 4\n",
"7\n1 100000 1\n1 100000 2\n1 100000 2\n4 50000 3\n3 50000 4\n4 50000 4\n3 50000 3\n",
"6\n2 1 4\n1 2 4\n3 4 4\n2 8 3\n3 16 3\n1 32 2\n",
"34\n1 91618 4\n4 15565 2\n1 27127 3\n3 71241 1\n1 72886 4\n3 67359 2\n4 91828 2\n2 79231 4\n1 2518 4\n2 91... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given n blocks, each of them is of the form [color_1|value|color_2], where the block can also be flipped to get [color_2|value|color_1].
A sequence of blocks is called valid... |
1061_A. Coins_37538 | You have unlimited number of coins with values 1, 2, …, n. You want to select some set of coins having the total value of S.
It is allowed to have multiple coins with the same value in the set. What is the minimum number of coins required to get sum S?
Input
The only line of the input contains two integers n and S ... | n, s = map(int, input().split())
print((s + n - 1) // n)
| {
"input": [
"6 16\n",
"5 11\n",
"5 29\n",
"2 999999999\n",
"42482 352232377\n",
"10 46\n",
"22951 747845288\n",
"46602 894472145\n",
"4821 917142246\n",
"2 193379347\n",
"7156 806580442\n",
"90952 904040054\n",
"73439 384841883\n",
"66 982670621\n",
"69018 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You have unlimited number of coins with values 1, 2, …, n. You want to select some set of coins having the total value of S.
It is allowed to have multiple coins with the same value... |
1082_G. Petya and Graph_37541 | Petya has a simple graph (that is, a graph without loops or multiple edges) consisting of n vertices and m edges.
The weight of the i-th vertex is a_i.
The weight of the i-th edge is w_i.
A subgraph of a graph is some set of the graph vertices and some set of the graph edges. The set of edges must meet the condition... | class edge(object):
def __init__(self,ne,to,fl):
self.ne=ne
self.to=to
self.fl=fl
def add(x,y,z):
global tot
tot+=1
e.append(edge(he[x],y,z))
he[x]=tot
def addedge(x,y,z):
add(x,y,z)
add(y,x,0)
def bfs():
global deep
deep=[0 for i in range(T+1)]
q=[]
q.append(S)
deep[S]=1
while (len(q)>0):
x=q[0... | {
"input": [
"3 3\n9 7 8\n1 2 1\n2 3 2\n1 3 3\n",
"4 5\n1 5 2 2\n1 3 4\n1 4 4\n3 4 5\n3 2 2\n4 2 2\n",
"20 10\n487490574 766859182 860731945 956220596 584871933 815478522 698429627 781975977 485357256 396825095 566947997 680691964 834523631 323163346 665972495 5503804 738797202 410201497 91359028 70881164... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Petya has a simple graph (that is, a graph without loops or multiple edges) consisting of n vertices and m edges.
The weight of the i-th vertex is a_i.
The weight of the i-th edge i... |
1102_B. Array K-Coloring_37545 | You are given an array a consisting of n integer numbers.
You have to color this array in k colors in such a way that:
* Each element of the array should be colored in some color;
* For each i from 1 to k there should be at least one element colored in the i-th color in the array;
* For each i from 1 to k al... | from collections import defaultdict
n,k=map(int,input().split())
arr=list(map(int,input().split()))
temp=[0]*5001
for i in arr:
temp[i]+=1
if(max(temp)>k):
print('NO')
elif(k>n):
print('NO')
else:
print('YES')
d=defaultdict(list)
c=0
t=[0]*n
for i in range(n):
t[i]=arr[i]
t.s... | {
"input": [
"5 2\n2 1 1 2 1\n",
"5 2\n3 2 1 2 3\n",
"4 2\n1 2 2 3\n",
"5 5\n1 1 2 2 3\n",
"6 6\n1 2 1 2 4 5\n",
"6 2\n100 100 101 101 102 102\n",
"5 1\n5 2 3 4 5\n",
"5 4\n25 2 3 2 2\n",
"9 9\n1 1 1 1 2 2 2 2 2\n",
"10 10\n1 2 3 1 2 3 1 2 4 5\n",
"10 10\n1 2 3 3 2 1 4 5 7 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an array a consisting of n integer numbers.
You have to color this array in k colors in such a way that:
* Each element of the array should be colored in some color... |
1130_B. Two Cakes_37549 | Sasha and Dima want to buy two n-tier cakes. Each cake should consist of n different tiers: from the size of 1 to the size of n. Tiers should go in order from the smallest to the biggest (from top to bottom).
They live on the same street, there are 2 ⋅ n houses in a row from left to right. Each house has a pastry shop... | l2=[]
n=int(input())
l=list(map(int,input().split()))
for i in range(2*n):
l2.append([l[i],i])
l2.sort()
sd,dd=l2[0][1],l2[1][1]
for i in range(2,2*n):
if i%2:
dd+=abs(l2[i][1]-l2[i-2][1])
else:
sd+=abs(l2[i][1]-l2[i-2][1])
print(sd+dd)
| {
"input": [
"4\n4 1 3 2 2 3 1 4\n",
"3\n1 1 2 2 3 3\n",
"2\n2 1 1 2\n",
"3\n1 3 3 2 1 2\n",
"4\n2 4 3 1 1 3 2 4\n",
"6\n6 4 5 2 6 4 3 3 1 2 1 5\n",
"5\n5 2 1 2 3 5 4 3 1 4\n",
"4\n3 2 1 1 4 2 3 4\n",
"7\n4 2 3 2 7 1 3 1 4 7 5 5 6 6\n",
"8\n4 5 7 8 2 7 6 3 6 1 1 3 5 8 4 2\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Sasha and Dima want to buy two n-tier cakes. Each cake should consist of n different tiers: from the size of 1 to the size of n. Tiers should go in order from the smallest to the bigg... |
1150_C. Prefix Sum Primes_37553 | We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2.
However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in a... | n=int(input())
l=list(map(int,input().split()))
n1,n2=0,0
for i in l:
if i==1:
n1+=1
else:
n2+=1
r=[]
if n1==0 or n2==0:
r=l
else:
r.append(2)
r.append(1)
n1-=1
n2-=1
while n2!=0:
r.append(2)
n2-=1
while n1!=0:
r.append(1)
n1-=1
for ... | {
"input": [
"9\n1 1 2 1 1 1 2 1 1\n",
"5\n1 2 1 2 1\n",
"5\n1 2 2 2 2\n",
"2\n2 2\n",
"3\n1 2 2\n",
"1\n1\n",
"1\n2\n",
"2\n1 1\n",
"10\n1 1 1 2 1 1 1 2 2 2\n",
"41\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2\n",
"10\n1 1 1 1 2 2 2 2 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2.
However, t... |
1172_C2. Nauuo and Pictures (hard version)_37557 | The only difference between easy and hard versions is constraints.
Nauuo is a girl who loves random picture websites.
One day she made a random picture website by herself which includes n pictures.
When Nauuo visits the website, she sees exactly one picture. The website does not display each picture with equal proba... | P = 998244353
N, M = map(int, input().split())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
li = sum([A[i]*B[i] for i in range(N)])
di = sum([(A[i]^1)*B[i] for i in range(N)])
X = [1]
SU = li+di
PO = [0] * (5*M+10)
for i in range(-M-5, 2*M+5):
PO[i] = pow((SU+i)%P, P-2, P)
def calc(L... | {
"input": [
"2 1\n0 1\n2 1\n",
"3 3\n0 1 1\n4 3 5\n",
"1 2\n1\n1\n",
"20 30\n1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 2 1 3 1 4 1 5 1 1 2 3 1 1 3 3 2 2 1 2\n",
"20 30\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n126679203 179924771 16639504 67055540 14134870 36407782 15024189 39367944 121531542 54... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The only difference between easy and hard versions is constraints.
Nauuo is a girl who loves random picture websites.
One day she made a random picture website by herself which incl... |
118_E. Bertown roads_37560 | Bertown has n junctions and m bidirectional roads. We know that one can get from any junction to any other one by the existing roads.
As there were more and more cars in the city, traffic jams started to pose real problems. To deal with them the government decided to make the traffic one-directional on all the roads,... | from sys import stdin,setrecursionlimit
import threading
input = lambda: stdin.readline().rstrip("\r\n")
from collections import deque as que
inin = lambda: int(input())
inar = lambda: list(map(int,input().split()))
from types import GeneratorType
def bootstrap(f, stack=[]):
def wrappedfunc(*args, **kwargs):
... | {
"input": [
"6 7\n1 2\n2 3\n1 3\n4 5\n4 6\n5 6\n2 4\n",
"6 8\n1 2\n2 3\n1 3\n4 5\n4 6\n5 6\n2 4\n3 5\n",
"18 75\n17 1\n13 18\n15 11\n6 3\n18 16\n9 18\n6 15\n6 14\n10 7\n17 16\n12 6\n15 13\n5 1\n4 13\n8 1\n11 5\n16 9\n3 2\n4 16\n4 18\n12 9\n8 11\n5 18\n5 3\n7 11\n2 11\n14 16\n16 15\n13 6\n10 8\n6 7\n7 4\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Bertown has n junctions and m bidirectional roads. We know that one can get from any junction to any other one by the existing roads.
As there were more and more cars in the city, t... |
1209_D. Cow and Snacks_37564 | The legendary Farmer John is throwing a huge party, and animals from all over the world are hanging out at his house. His guests are hungry, so he instructs his cow Bessie to bring out the snacks! Moo!
There are n snacks flavors, numbered with integers 1, 2, …, n. Bessie has n snacks, one snack of each flavor. Every g... | from collections import defaultdict
import sys
import typing
class DSU:
'''
Implement (union by size) + (path halving)
Reference:
Zvi Galil and Giuseppe F. Italiano,
Data structures and algorithms for disjoint set union problems
'''
def __init__(self, n: int = 0) -> None:
self._n... | {
"input": [
"5 4\n1 2\n4 3\n1 4\n3 4\n",
"6 5\n2 3\n2 1\n3 4\n6 5\n4 5\n",
"4 2\n1 3\n2 4\n",
"100000 12\n8 7\n1 9\n5 4\n11 12\n7 8\n3 4\n3 5\n12 15\n15 13\n13 14\n7 8\n11 14\n",
"4 2\n1 2\n2 3\n",
"2 1\n1 2\n",
"10 15\n1 2\n2 3\n3 4\n4 5\n5 1\n1 6\n2 7\n3 8\n4 9\n5 10\n6 8\n7 9\n8 10\n9 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The legendary Farmer John is throwing a huge party, and animals from all over the world are hanging out at his house. His guests are hungry, so he instructs his cow Bessie to bring ou... |
1228_C. Primes and Multiplication_37568 | Let's introduce some definitions that will be needed later.
Let prime(x) be the set of prime divisors of x. For example, prime(140) = \{ 2, 5, 7 \}, prime(169) = \{ 13 \}.
Let g(x, p) be the maximum possible integer p^k where k is an integer such that x is divisible by p^k. For example:
* g(45, 3) = 9 (45 is divis... | """
import math
MOD=1000000007
def powr(n,N):
temp=1
while(N>0):
if(N%2!=0):
temp=(temp*n)%MOD
n=(n*n)%MOD
N=N//2
return (temp%MOD)
x,n=map(int,input().split())
n1=x
L=[]
while(n1%2==0):
L.append(2)
n1=n1//2
for i in range(3,int(math.sqrt(n1))+1,2):
... | {
"input": [
"20190929 1605\n",
"10 2\n",
"947 987654321987654321\n",
"183 183\n",
"848817679 656378982730193530\n",
"9 188\n",
"84649 916822936406978638\n",
"1000000000 1000000000000000000\n",
"2 576460752303423488\n",
"602555209 363072779893033681\n",
"5 29802322387695312... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Let's introduce some definitions that will be needed later.
Let prime(x) be the set of prime divisors of x. For example, prime(140) = \{ 2, 5, 7 \}, prime(169) = \{ 13 \}.
Let g(x, ... |
1270_C. Make Good_37572 | Let's call an array a_1, a_2, ..., a_m of nonnegative integer numbers good if a_1 + a_2 + ... + a_m = 2⋅(a_1 ⊕ a_2 ⊕ ... ⊕ a_m), where ⊕ denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
For example, array [1, 2, 3, 6] is good, as 1 + 2 + 3 + 6 = 12 = 2⋅ 6 = 2⋅ (1⊕ 2 ⊕ 3 ⊕ 6). A... | from functools import reduce
from operator import xor
for _ in range(int(input())):
n = int(input())
a = [*map(int, input().split())]
print(2)
print(sum(a) + reduce(xor, a), reduce(xor, a)) | {
"input": [
"3\n4\n1 2 3 6\n1\n8\n2\n1 1\n",
"3\n4\n1 2 3 6\n1\n8\n2\n1 1\n",
"3\n4\n1 2 3 6\n1\n5\n2\n1 1\n",
"3\n4\n1 2 3 6\n1\n8\n2\n1 0\n",
"3\n4\n1 2 3 6\n1\n5\n2\n1 0\n",
"3\n4\n1 2 3 6\n1\n8\n2\n2 0\n",
"3\n4\n1 4 3 6\n1\n5\n2\n1 0\n",
"3\n4\n1 2 3 9\n1\n8\n2\n2 0\n",
"3\n4... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Let's call an array a_1, a_2, ..., a_m of nonnegative integer numbers good if a_1 + a_2 + ... + a_m = 2⋅(a_1 ⊕ a_2 ⊕ ... ⊕ a_m), where ⊕ denotes the [bitwise XOR operation](https://en... |
1293_A. ConneR and the A.R.C. Markland-N_37576 | [Sakuzyo - Imprinting](https://www.youtube.com/watch?v=55Ca6av1kAY)
A.R.C. Markland-N is a tall building with n floors numbered from 1 to n. Between each two adjacent floors in the building, there is a staircase connecting them.
It's lunchtime for our sensei Colin "ConneR" Neumann Jr, and he's planning for a location... | t = int(input())
for _ in range(t):
variables = [int(_) for _ in input().split()]
n = variables[0]
s = variables[1]
k = variables[2]
closed = set([int(i) for i in input().split()])
minimum = n
tmp = n
for x in range(s, 0, -1):
if x not in closed:
tmp = abs(s-x)
... | {
"input": [
"5\n5 2 3\n1 2 3\n4 3 3\n4 1 2\n10 2 6\n1 2 3 4 5 7\n2 1 1\n2\n100 76 8\n76 75 36 67 41 74 10 77\n",
"1\n10 8 6\n4 8 7 9 6 10\n",
"1\n10 6 9\n8 3 6 10 9 5 2 4 7\n",
"1\n10 8 8\n7 10 8 9 6 3 4 5\n",
"1\n100 1 41\n15 19 26 17 6 16 40 31 39 13 7 33 25 9 21 20 41 23 32 27 3 30 14 4 24 35 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
[Sakuzyo - Imprinting](https://www.youtube.com/watch?v=55Ca6av1kAY)
A.R.C. Markland-N is a tall building with n floors numbered from 1 to n. Between each two adjacent floors in the b... |
1313_A. Fast Food Restaurant_37580 | Tired of boring office work, Denis decided to open a fast food restaurant.
On the first day he made a portions of dumplings, b portions of cranberry juice and c pancakes with condensed milk.
The peculiarity of Denis's restaurant is the procedure of ordering food. For each visitor Denis himself chooses a set of dishes... | import os
import sys
from io import BytesIO, IOBase
def solution(a, b, c):
if a == 0 and b == 0 and c == 0:
print(0)
return
res = 0
comb = ['001', '010', '100', '011', '101', '110', '111']
comb2 = ['01', '10', '11']
a, b, c = sorted([a, b, c])
if a == 0 and b == 0:
pr... | {
"input": [
"7\n1 2 1\n0 0 0\n9 1 7\n2 2 3\n2 3 2\n3 2 2\n4 4 4\n",
"2\n2 2 8\n3 2 2\n",
"2\n2 2 8\n3 3 2\n",
"7\n1 2 1\n0 0 0\n9 1 7\n2 2 3\n2 3 2\n3 2 2\n0 4 4\n",
"7\n1 2 1\n0 0 0\n9 1 1\n2 2 3\n2 3 2\n3 2 2\n0 4 4\n",
"2\n2 2 7\n3 3 0\n",
"7\n1 2 1\n0 0 0\n9 1 1\n2 2 2\n2 3 2\n3 2 2\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Tired of boring office work, Denis decided to open a fast food restaurant.
On the first day he made a portions of dumplings, b portions of cranberry juice and c pancakes with condens... |
1335_E1. Three Blocks Palindrome (easy version)_37584 | The only difference between easy and hard versions is constraints.
You are given a sequence a consisting of n positive integers.
Let's define a three blocks palindrome as the sequence, consisting of at most two distinct elements (let these elements are a and b, a can be equal b) and is as follows: [\underbrace{a, a, ... | T = int(input())
Q = []
# Read all inputs before computing (see last comment, the goal is to print once)
for t in range(T):
N = int(input())
A = [int(_) for _ in input().split()]
Q.append((N, A))
R = []
for N, A in Q:
# Switch the 2 dimensions of the array to maybe prevent cache miss on loops l26 and... | {
"input": [
"6\n8\n1 1 2 2 3 2 1 1\n3\n1 3 3\n4\n1 10 10 1\n1\n26\n2\n2 1\n3\n1 1 1\n",
"6\n8\n1 1 2 2 3 3 1 1\n3\n1 3 3\n4\n1 10 10 1\n1\n26\n2\n2 1\n3\n1 1 1\n",
"6\n8\n1 1 2 2 3 2 1 1\n3\n1 3 3\n4\n1 10 14 1\n1\n26\n2\n2 1\n3\n1 1 1\n",
"6\n8\n1 1 2 4 3 2 1 1\n3\n1 3 3\n4\n1 10 14 1\n1\n26\n2\n2 1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The only difference between easy and hard versions is constraints.
You are given a sequence a consisting of n positive integers.
Let's define a three blocks palindrome as the sequen... |
1358_A. Park Lighting_37588 | Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance.
The park is a rectangular table with n rows and m columns, where the cells of the... | import math
t=int(input())
while(t>0):
t-=1
n,m=map(int,input().split())
print(math.floor((n*m+1)/2)) | {
"input": [
"5\n1 1\n1 3\n2 2\n3 3\n5 3\n",
"2\n1329 2007\n179 57\n",
"2\n1329 2007\n118 57\n",
"5\n2 1\n1 3\n2 2\n3 3\n5 3\n",
"2\n1329 2465\n118 57\n",
"5\n2 1\n1 3\n2 2\n1 3\n5 3\n",
"2\n152 2465\n118 57\n",
"5\n4 1\n1 3\n2 2\n1 3\n5 3\n",
"2\n152 3396\n118 57\n",
"2\n264 3... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see... |
1399_B. Gifts Fixing_37594 | You have n gifts and you want to give all of them to children. Of course, you don't want to offend anyone, so all gifts should be equal between each other. The i-th gift consists of a_i candies and b_i oranges.
During one move, you can choose some gift 1 ≤ i ≤ n and do one of the following operations:
* eat exactly... | # Gifts Fixing
# https://codeforces.com/problemset/problem/1399/B
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
min_a = min(a)
min_b = min(b)
count = 0
for i in range(n):
diff_a = a[i] - min_a
diff_b = b[i] - min_b
... | {
"input": [
"5\n3\n3 5 6\n3 2 3\n5\n1 2 3 4 5\n5 4 3 2 1\n3\n1 1 1\n2 2 2\n6\n1 1000000000 1000000000 1000000000 1000000000 1000000000\n1 1 1 1 1 1\n3\n10 12 8\n7 5 4\n",
"5\n3\n3 5 6\n3 2 3\n5\n1 2 3 4 5\n5 4 3 2 1\n3\n1 1 1\n2 2 2\n6\n1 1000000000 1000000000 1000000000 1000000000 1000000000\n1 1 2 1 1 1\n3... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You have n gifts and you want to give all of them to children. Of course, you don't want to offend anyone, so all gifts should be equal between each other. The i-th gift consists of a... |
1422_E. Minlexes_37598 | Some time ago Lesha found an entertaining string s consisting of lowercase English letters. Lesha immediately developed an unique algorithm for this string and shared it with you. The algorithm is as follows.
Lesha chooses an arbitrary (possibly zero) number of pairs on positions (i, i + 1) in such a way that the foll... | import sys
s = input().strip()
N = len(s)
if len(s) == 1:
print(1, s[0])
sys.exit()
X = [s[-1], s[-2]+s[-1] if s[-2]!=s[-1] else ""]
Y = [1, 2 if s[-2]!=s[-1] else 0]
for i in range(N-3, -1, -1):
c = s[i]
k1 = c+X[-1]
ng = Y[-1]+1
if ng > 10:
k1 = k1[:5] + "..." + k1[-2:]
if c == s[i... | {
"input": [
"abcdd\n",
"abbcdddeaaffdfouurtytwoo\n",
"nnnnnnnnnnnnnnnnaaag\n",
"arexjrujgilmbbao\n",
"gggggggggggggglllll\n",
"bbccccbbbccccbbbccccbbbcccca\n",
"iiiiiitttttyyyyyyyyp\n",
"yaryoznawafbayjwkfl\n",
"hhgxwyrjemygfgs\n",
"rrrccccccyyyyyyyyyyf\n",
"nnnnnnwwwwwwxl... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Some time ago Lesha found an entertaining string s consisting of lowercase English letters. Lesha immediately developed an unique algorithm for this string and shared it with you. The... |
1440_C2. Binary Table (Hard Version)_37602 | This is the hard version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved both versions of the problem.
You are given a binary table of size n × m. This table consists of symbols 0 and 1.
You can make such operat... | import sys
input=sys.stdin.readline
def change(x1,x2,x3,y1,y2,y3,ll):
ll[x1][y1]=1-ll[x1][y1]
ll[x2][y2]=1-ll[x2][y2]
#print(x3,y3,ll)
ll[x3][y3]=1-ll[x3][y3]
t=int(input())
while t:
n,m=map(int,input().split())
ll=[]
for i in range(n):
l=list(map(int,input().strip()))
... | {
"input": [
"5\n2 2\n10\n11\n3 3\n011\n101\n110\n4 4\n1111\n0110\n0110\n1111\n5 5\n01011\n11001\n00010\n11011\n10000\n2 3\n011\n101\n",
"5\n2 2\n10\n11\n3 3\n011\n101\n110\n4 4\n1111\n0110\n0110\n1111\n5 5\n01011\n11001\n00010\n11011\n10000\n2 3\n011\n101\n",
"5\n2 2\n10\n11\n3 3\n011\n101\n110\n4 4\n111... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This is the hard version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved bot... |
1467_E. Distinctive Roots in a Tree_37605 | You are given a tree with n vertices. Each vertex i has a value a_i associated with it.
Let us root the tree at some vertex v. The vertex v is called a distinctive root if the following holds: in all paths that start at v and end at some other node, all the values encountered are distinct. Two different paths may have... | import io, os
from collections import Counter, defaultdict, deque
class LazySegmentTree:
def __init__(self, data, default=0, func=max):
_default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self._lazy = [0] * (2 * ... | {
"input": [
"5\n2 5 1 1 4\n1 2\n1 3\n2 4\n2 5\n",
"5\n2 1 1 1 4\n1 2\n1 3\n2 4\n2 5\n",
"5\n1 2 5 1 4\n1 2\n1 3\n2 4\n2 5\n",
"5\n2 1 1 3 1\n1 2\n1 3\n3 4\n4 5\n",
"5\n2 2 3 5 3\n1 2\n2 3\n3 4\n4 5\n",
"12\n4 1 6 1 7 1 1 3 2 5 3 2\n1 2\n2 10\n1 3\n3 4\n7 9\n3 5\n5 7\n7 8\n1 11\n11 12\n3 6\n",... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a tree with n vertices. Each vertex i has a value a_i associated with it.
Let us root the tree at some vertex v. The vertex v is called a distinctive root if the follow... |
1541_E1. Converging Array (Easy Version)_37611 | This is the easy version of the problem. The only difference is that in this version q = 1. You can make hacks only if both versions of the problem are solved.
There is a process that takes place on arrays a and b of length n and length n-1 respectively.
The process is an infinite sequence of operations. Each operat... | import sys
input = lambda: sys.stdin.readline().rstrip()
N = int(input())
C = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
Q = int(input())
x = int(input())
P = 10 ** 9 + 7
dp = [[0] * 20100 for _ in range(N + 1)]
dp[0][0] = 1
ans = 0
s = x
t = s
for i in range(N):
for j in range(20050, ... | {
"input": [
"3\n2 3 4\n2 1\n1\n-1\n",
"10\n77 16 42 68 100 38 40 99 75 67\n0 1 0 2 1 1 0 0 0\n1\n43\n",
"30\n45 63 41 0 9 11 50 83 33 74 62 85 42 29 17 26 4 0 33 85 16 11 46 98 87 81 70 50 0 22\n1 3 0 1 2 2 0 1 2 1 3 2 0 1 1 2 0 0 2 1 0 2 0 1 3 1 0 3 1\n1\n19\n",
"20\n79 33 19 90 72 83 79 78 81 59 33... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This is the easy version of the problem. The only difference is that in this version q = 1. You can make hacks only if both versions of the problem are solved.
There is a process tha... |
18_B. Platforms_37616 | In one one-dimensional world there are n platforms. Platform with index k (platforms are numbered from 1) is a segment with coordinates [(k - 1)m, (k - 1)m + l], and l < m. Grasshopper Bob starts to jump along the platforms from point 0, with each jump he moves exactly d units right. Find out the coordinate of the poin... | class Platforms:
@classmethod
def read_input(cls):
nums = list(map(int, input('').split()))
return nums[0], nums[1], nums[2], nums[3]
@classmethod
def run(cls):
n, d, m, l = cls.read_input()
end_plat = (n - 1) * m + l
for cur_jump in range(d, (m + 1) * d, d):
... | {
"input": [
"5 4 11 8\n",
"2 2 5 3\n",
"1000000 64 999956 999955\n",
"593287 497915 864740 864733\n",
"1000000 49 999983 999982\n",
"1000000 16 999952 999951\n",
"615188 948759 924417 924407\n",
"228385 744978 699604 157872\n",
"81812 875240 443569 287155\n",
"1000000 3 999997... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In one one-dimensional world there are n platforms. Platform with index k (platforms are numbered from 1) is a segment with coordinates [(k - 1)m, (k - 1)m + l], and l < m. Grasshoppe... |
213_B. Numbers_37620 | Furik loves writing all sorts of problems, especially such that he can't solve himself. You've got one of his problems, the one Furik gave to Rubik. And Rubik asks you to solve it.
There is integer n and array a, consisting of ten integers, indexed by numbers from 0 to 9. Your task is to count the number of positive i... | from math import factorial
dp=[[-1 for i in range (101)] for j in range(101)]
def solve(n,p,a):
if dp[n][p] is not -1:
return dp[n][p]
elif p is 9:
if n>=a[9]:
return 1
else:
return 0
elif p is 0:
ans=0
for i in range(a[0],n):
z=sol... | {
"input": [
"3\n1 1 0 0 0 0 0 0 0 0\n",
"2\n1 1 0 0 0 0 0 0 0 0\n",
"1\n0 0 0 0 0 0 0 0 0 1\n",
"82\n100 100 100 100 100 100 100 100 100 100\n",
"100\n18 2 23 27 9 23 27 13 24 39\n",
"100\n50 0 0 0 0 50 0 0 0 0\n",
"55\n100 100 100 100 100 100 100 100 100 100\n",
"100\n3 24 1 12 29 27... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Furik loves writing all sorts of problems, especially such that he can't solve himself. You've got one of his problems, the one Furik gave to Rubik. And Rubik asks you to solve it.
T... |
237_B. Young Table_37624 | You've got table a, consisting of n rows, numbered from 1 to n. The i-th line of table a contains ci cells, at that for all i (1 < i ≤ n) holds ci ≤ ci - 1.
Let's denote s as the total number of cells of table a, that is, <image>. We know that each cell of the table contains a single integer from 1 to s, at that all ... | n = int(input())
I = lambda : map(int,input().split())
li = list (I())
dd = {}
arr = [ [0 for i in range(51)] for j in range(51) ]
l2 = [ ]
c=0
for i in range (1,n+1) :
l1 = list(I())
l2 = l2 + l1
c = c + len(l1)
for j in range(li[i-1]) :
arr[i][j+1] = l1[j]
dd[l1[j]] = [i , j+1]
#print... | {
"input": [
"1\n4\n4 3 2 1\n",
"3\n3 2 1\n4 3 5\n6 1\n2\n",
"2\n35 7\n6 8 35 9 28 25 10 41 33 39 19 24 5 12 30 40 18 2 4 11 32 13 31 21 14 27 3 34 37 16 17 29 1 42 36\n20 23 38 15 26 7 22\n",
"3\n36 28 14\n46 15 35 60 41 65 73 33 18 20 68 22 28 23 67 44 2 24 21 51 37 3 48 69 12 50 32 72 45 53 17 47 5... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You've got table a, consisting of n rows, numbered from 1 to n. The i-th line of table a contains ci cells, at that for all i (1 < i ≤ n) holds ci ≤ ci - 1.
Let's denote s as the to... |
285_E. Positions in Permutations_37630 | Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn.
We'll call position i (1 ≤ i ≤ n) in permutation p1, p... | mod=10**9+7
n,k=map(int,input().split())
A=[0]*(n+1)
B=[0]*(n+1)
C=[0]*(n+1)
F=[0]*(n+1)
G=[0]*(n+1)
F[0]=G[0]=1
for i in range(1,n+1):
G[i]=F[i]=F[i-1]*i%mod
G[i]=pow(F[i],(mod-2),mod)
for i in range(0,n):
if i*2>n:
break
B[i]=(F[n-i]*G[i]*G[n-i*2])%mod
for i in range(0,n//2+1):
for j in range(0,n//2+1):
A... | {
"input": [
"2 1\n",
"4 1\n",
"7 4\n",
"1 0\n",
"3 2\n",
"10 3\n",
"7 7\n",
"999 300\n",
"1000 999\n",
"10 0\n",
"5 4\n",
"1000 900\n",
"999 600\n",
"1000 998\n",
"999 998\n",
"999 989\n",
"4 2\n",
"8 4\n",
"3 0\n",
"2 2\n",
"999 13\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p ... |
356_C. Compartments_37638 | A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people). We know that if one compartment contain one or two students, then they ge... | n = int(input())
A = [0, 0, 0, 0, 0]
B = map(int, input().split(' '))
for i in B:
A[i] += 1
res = min(A[1], A[2])
A[1] -= res
A[2] -= res
A[3] += res
res += 2 * (A[1] // 3)
A[3] += A[1] // 3
A[1] %= 3
res += 2 * (A[2] // 3)
A[3] += 2 * (A[2] // 3)
A[2] %= 3
assert(A[1] == 0 or A[2] == 0)
if (A[1] == 1):
if (A[3... | {
"input": [
"3\n4 1 1\n",
"4\n0 3 0 4\n",
"5\n1 2 2 4 3\n",
"20\n4 2 3 3 1 3 2 3 1 4 4 4 2 1 4 2 1 3 4 4\n",
"166\n2 3 2 2 2 2 2 2 2 2 0 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 3 2 2 2 2 2 2 2 2 2 4 2 2 2 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 2 2 2 0 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 3 2 2 2 2 2 2 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consistin... |
37_B. Computer Game_37642 | Vasya’s elder brother Petya loves playing computer games. In one of his favourite computer games Petya reached the final level where a fight with the boss take place.
While playing the game Petya found spell scrolls and now he is about to use them. Let’s describe the way fighting goes on this level:
1) The boss has t... | class Scroll:
def __init__(self, id, power, damage):
self.id = id
self.power = power
self.damage = damage
self.active = False
num_scrolls, boss_max, regenerate = map(int, input().split())
scrolls = [Scroll(i+1, *map(int, input().split())) for i in range(num_scrolls)]
scrolls.sort(key = lambda scroll: -scroll.... | {
"input": [
"2 100 10\n100 11\n90 9\n",
"2 10 3\n100 3\n99 1\n",
"5 328 249\n62 265\n32 271\n72 237\n28 99\n22 364\n",
"4 337 873\n62 81\n87 481\n39 1189\n45 450\n",
"2 1000 1\n100 1\n100 1\n",
"5 351 183\n16 337\n19 221\n81 359\n87 253\n5 240\n",
"3 100 5\n100 1\n100 1\n100 1\n",
"10... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya’s elder brother Petya loves playing computer games. In one of his favourite computer games Petya reached the final level where a fight with the boss take place.
While playing t... |
400_A. Inna and Choose Options_37646 | There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below:
There is one person playing the game. Before the beginning of the game he puts 12 cards in a row on the table. Each card contains a character: "X"... | n = int(input())
a = [1, 2, 3, 4, 6, 12]
for i in range(0, n):
s = str(input())
ans = [False for x in range(0, 6)]
nans = 0;
for i in range (0, 6):
for j in range (0, 12 // a[i]):
good = True
for k in range(0, a[i]):
if s[k * 12 // a[i] + j] is 'O':
good = False
break
if good:
nans =... | {
"input": [
"4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO\n",
"13\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\n",
"2\nOOOOOOOOOOOO\nXXXXXXXXXXXX\n",
"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below:
There is ... |
427_B. Prison Transfer_37650 | The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of the prisoners to a prison located in another city.
For this reason, he made the n prisoners to stand in a line, with a number written on their chests. The number is the severity of the crim... | a=list(map(int,input().split()[1:]))
b=list(map(int,input().split()))
m=0
c=0
for i in b:
if i>a[0]:
if not c<a[1]:
m+=c-a[1]+1
c=0
else:c+=1
print(m+c-a[1]+1 if c>=a[1]else m)
| {
"input": [
"1 1 1\n2\n",
"4 3 3\n2 3 1 1\n",
"11 4 2\n2 2 0 7 3 2 2 4 9 1 4\n",
"4 2 2\n1 3 3 2\n",
"3 3 3\n3 2 3\n",
"1 228 1\n1\n",
"2 228885628 1\n90897004 258427916\n",
"57 2 10\n7 5 2 7 4 1 0 5 2 9 2 9 8 6 6 5 9 6 8 1 0 1 0 3 2 6 5 2 8 8 8 8 0 9 4 3 6 6 2 4 5 1 2 0 1 7 1 1 5 4 5... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of the prisoners to a prison located in another city.
F... |
472_A. Design Tutorial: Learn from Math_37656 | One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two ... | def isprime(k):
m=0
for j in range(2,k):
if k%j==0:
m=m+1
if m==0:
return 0
else:
return 1
n=int(input())
for i in range(4,n-3):
if isprime(i)==1 and isprime(n-i)==1:
print(i,n-i)
exit() | {
"input": [
"1000000\n",
"23\n",
"15\n",
"12\n",
"738457\n",
"46220\n",
"59\n",
"58134\n",
"19\n",
"192\n",
"999987\n",
"58113\n",
"14568\n",
"13\n",
"21\n",
"22\n",
"999999\n",
"765\n",
"100007\n",
"57114\n",
"74752\n",
"1289\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, ... |
496_B. Secret Combination_37660 | You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the displ... | n = int(input())
s = input()
i = 0
min_ = int(s)
s1 = s
i = 0
while (i <= n):
s = s[1::] + s[0]
if (int(s[0]) != 0):
g = (9 - int(s[0])) + 1
s2 = ''
for j in range(len(s)):
h = int(s[j]) + g
if (h >= 10):
h = abs(10 - h)
s2 = s2 + str(h... | {
"input": [
"4\n2014\n",
"3\n579\n",
"100\n6669666666666666666866266666666666666666666666666666666666666666626666666666666966666766665667666656\n",
"200\n790255315572987030992457008600274325854479025531557298703099245700860027432585447902553155729870309924570086002743258544790255315572987030992457008... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovere... |
547_A. Mike and Frog_37666 | Mike has a frog and a flower. His frog is named Xaniar and his flower is named Abol. Initially(at time 0), height of Xaniar is h1 and height of Abol is h2. Each second, Mike waters Abol and Xaniar.
<image>
So, if height of Xaniar is h1 and height of Abol is h2, after one second height of Xaniar will become <image> an... | def main():
m, tt = int(input()), [0] * 4
for i in 0, 2:
h, a = map(int, input().split())
x, y = map(int, input().split())
ha = (h, a)
for t in range(1, m * 2):
h = (h * x + y) % m
if h in ha:
if h == ha[0]:
if tt[i]:
... | {
"input": [
"1023\n1 2\n1 0\n1 2\n1 1\n",
"5\n4 2\n1 1\n0 1\n2 3\n",
"999983\n1 37827\n1 1\n2 192083\n3 0\n",
"999983\n420528 808305\n387096 497121\n596163 353326\n47177 758204\n",
"3\n0 2\n1 0\n2 0\n2 1\n",
"999961\n744938 661980\n845908 76370\n237399 381935\n418010 938769\n",
"999983\n8... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Mike has a frog and a flower. His frog is named Xaniar and his flower is named Abol. Initially(at time 0), height of Xaniar is h1 and height of Abol is h2. Each second, Mike waters Ab... |
595_A. Vitaly and Night_37672 | One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered ... | etaj, kvart = map(int, input().split())
Okna = []
notsleep = 0
for i in range(0, etaj):
Okna.append(list(map(int, input().split())))
for i in range(0, etaj):
for j in range(0, (kvart*2)-1, 2):
if Okna[i][j] or Okna[i][j+1] == 1:
notsleep += 1
print(notsleep)
| {
"input": [
"1 3\n1 1 0 1 0 0\n",
"2 2\n0 0 0 1\n1 0 1 1\n",
"1 1\n0 0\n",
"1 1\n0 1\n",
"1 100\n0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he wa... |
616_D. Longest k-Good Segment_37676 | The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | import re
import sys
exit=sys.exit
from bisect import bisect_left as bsl,bisect_right as bsr
from collections import Counter,defaultdict as ddict,deque
from functools import lru_cache
cache=lru_cache(None)
from heapq import *
from itertools import *
from math import inf
from pprint import pprint as pp
enum=enumerate
ri... | {
"input": [
"5 5\n1 2 3 4 5\n",
"9 3\n6 5 1 2 3 2 1 4 5\n",
"3 1\n1 2 3\n",
"3\n1 1 1\n",
"10\n460626451 460626451 460626451 460626451 460626451 460626451 460626451 460626451 460626451 460626451\n",
"9\n1 2 1 2 1 2 1 2 1\n",
"5\n1 2 2 2 1\n",
"7\n13 9 19 13 3 13 12\n",
"10\n933677... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k differ... |
689_B. Mike and Shortcuts_37685 | Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city.
City consists of n intersections numbered from 1 to n. Mike starts walking from his house located at the intersection number 1 and goes along some sequence of intersections. Walking... | def amount_of_total_energy(n, a):
dist = [-1] * n
dist[0] = 0
pos = [0]
for u in pos:
for v in [u - 1, u + 1, a[u] - 1]:
if v >= 0 and v < n and dist[v] == -1:
dist[v] = dist[u] + 1
pos.append(v)
return dist
n = int(input())
a = list(map(int,input().split()))
print(... | {
"input": [
"5\n1 2 3 4 5\n",
"7\n4 4 4 4 7 7 7\n",
"3\n2 2 3\n",
"4\n2 3 3 4\n",
"91\n4 6 23 23 23 23 23 28 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 47 47 47 54 54 54 54 54 54 54 58 58 58 58 58 58 69 69 69 69 69 69 69 69 69 69 69 69 70 70 70 70 70 70 70 70 70 70 71 72 72... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city.
City consists of n intersections numbered fr... |
731_F. Video Cards_37690 | Little Vlad is fond of popular computer game Bota-2. Recently, the developers announced the new add-on named Bota-3. Of course, Vlad immediately bought only to find out his computer is too old for the new game and needs to be updated.
There are n video cards in the shop, the power of the i-th video card is equal to in... | n = int(input())
s = list(map(int, input().split()))
h = max(s)
ss = [0] * (h + 1)
for i in s:
ss[i] += 1
f, x = [0] * h, 0
for j in reversed(ss):
x += j
f.append(x)
f.reverse()
res = []
for i, x in enumerate(ss):
if x:
summ, x = 0, f[i]
for j in range(i, h + 1, i):
o = f[j +... | {
"input": [
"4\n8 2 2 7\n",
"4\n3 2 15 9\n",
"100\n881 479 355 759 257 497 690 598 275 446 439 787 257 326 584 713 322 5 253 781 434 307 164 154 241 381 38 942 680 906 240 11 431 478 628 959 346 74 493 964 455 746 950 41 585 549 892 687 264 41 487 676 63 453 861 980 477 901 80 907 285 506 619 748 773 743... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Little Vlad is fond of popular computer game Bota-2. Recently, the developers announced the new add-on named Bota-3. Of course, Vlad immediately bought only to find out his computer i... |
756_A. Pavel and barbecue_37694 | Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: in the one it was directed originally and in the reversed direction.
Pavel has a plan: a permutation p and a sequence b1, b2, ... | import sys
input = sys.stdin.readline
n = int(input())
permutation = list(map(int, input().split()))
go = set(range(1,n+1))
reached = set()
ans = 0
while go:
x = go.pop()
while x not in reached:
reached.add(x)
x = permutation[x-1]
if x in go:
go.remove(x)
ans += 1
if ans == 1:
ans = 0
permu... | {
"input": [
"3\n2 3 1\n0 0 0\n",
"4\n4 3 2 1\n0 1 1 1\n",
"3\n3 1 2\n0 0 0\n",
"3\n3 1 2\n1 1 1\n",
"20\n10 15 20 17 8 1 14 6 3 13 19 2 16 12 4 5 11 7 9 18\n0 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0\n",
"3\n2 1 3\n0 1 1\n",
"2\n2 1\n1 1\n",
"3\n1 2 3\n1 0 0\n",
"2\n2 1\n0 0\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two di... |
777_B. Game of Credit Cards_37698 | After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.
Rules of this game are simple: each player bring his favourite n-digit credit card. Then both players name the digits written on their... | n = int(input())
s = list(map(int, list(input())))
m = map(int, list(input()))
ma = [0] * 10
for dig in m:
ma[dig] += 1
ma2 = list(ma)
min_f = 0
for nu in s:
for x in range(nu, 10):
if ma[x] > 0:
ma[x] -= 1
break
else:
min_f += 1
for z in range(len(ma)):
... | {
"input": [
"3\n123\n321\n",
"2\n88\n00\n",
"9\n777777777\n777777777\n",
"5\n11222\n22111\n",
"10\n8104381743\n8104381743\n",
"8\n88888888\n98769876\n",
"3\n112\n111\n",
"9\n353589343\n280419388\n",
"1\n4\n5\n",
"100\n63174942208228187194114040303463828697961389327124611870678... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards... |
822_B. Crossword solving_37704 | Erelong Leha was bored by calculating of the greatest common divisor of two factorials. Therefore he decided to solve some crosswords. It's well known that it is a very interesting occupation though it can be very difficult from time to time. In the course of solving one of the crosswords, Leha had to solve a simple ta... | n, m = map(int, input().split())
s = input()
t = input()
res = 1001
res_ind = []
b = 0
e = len(s)
while b <= len(t)-len(s):
sr = t[b:e]
k = 0
ind = []
for i in range(len(s)):
if s[i] != sr[i]:
k += 1
else:
ind.append(i+1)
if k < res:
res = k
... | {
"input": [
"4 10\nabcd\nebceabazcd\n",
"3 5\nabc\nxaybz\n",
"3 5\naaa\naaaaa\n",
"2 3\nab\ndda\n",
"1 1\na\nz\n",
"1 2\nf\nrt\n",
"2 5\naa\navaca\n",
"1 2\nf\ngf\n",
"3 5\naba\nbbbbb\n",
"2 3\nzb\naaz\n",
"3 3\nabc\ncab\n",
"3 4\nabh\nbhaa\n",
"3 5\nvvv\nbqavv\n",... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Erelong Leha was bored by calculating of the greatest common divisor of two factorials. Therefore he decided to solve some crosswords. It's well known that it is a very interesting oc... |
847_G. University Classes_37708 | There are n student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes.
The schedule on Monday is known for each group, i. e. time slots when group will have classes are known.
Your task is to determine the mi... | n = int(input())
schedules = []
for i in range(n):
schedules.append(input())
minimum = 0
for i in range(7):
activeSlots = 0
for j in range(n):
activeSlots += int(schedules[j][i])
if activeSlots > minimum:
minimum = activeSlots
print(minimum) | {
"input": [
"3\n0101011\n0011001\n0110111\n",
"2\n0101010\n1010101\n",
"6\n1101110\n1111011\n1101110\n0100011\n1110110\n1110100\n",
"1\n0111000\n",
"20\n1111111\n1101011\n1111011\n0111111\n1111111\n1110111\n1111111\n1111111\n1111111\n1111111\n1110111\n1111111\n0111111\n1011111\n1111111\n1111111\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes.
T... |
869_B. The Eternal Immortality_37712 | Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.
The phoenix has a rather long lifespan, and reincarnates itself once every a! years. Here a! denotes ... | # Main maut ko takiya, aur kafan ko chaadar banakkar audhta hoon!
a,b=input().split()
if a[:-1]!=b[:-1]:
print("0")
else:
ans=1
for i in range(int(a[-1])+1,int(b[-1])+1):
ans*=i
ans=ans%10
print(ans)
| {
"input": [
"107 109\n",
"0 10\n",
"2 4\n",
"1 3\n",
"998244355 998244359\n",
"1 22\n",
"1230 1232\n",
"0 0\n",
"0 4\n",
"1000000000000000000 1000000000000000000\n",
"0 11\n",
"101 1002\n",
"2 3\n",
"0 100000000000\n",
"6 19\n",
"24 25\n",
"12 23\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to ma... |
895_A. Pizza Separation_37716 | Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to ai. Vasya and Petya want to divide all piece... | n=int(input())
a=list(map(int,input().split()))
print(2*min(abs(180-sum(a[l:r])) for l in range(n) for r in range(l,n)))
| {
"input": [
"4\n170 30 150 10\n",
"3\n100 100 160\n",
"4\n90 90 90 90\n",
"1\n360\n",
"4\n70 80 110 100\n",
"8\n10 10 70 70 90 90 10 10\n",
"5\n211 113 25 9 2\n",
"9\n40 20 20 20 20 20 20 40 160\n",
"130\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The... |
916_B. Jamie and Binary Sequence (changed after round)_37720 | Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem:
Find k integers such that the sum of two to the power of each number equals to the number n and the largest integer in the answer is as small as possible. As t... | n, k = map(int, input().split())
cnt = [0] * 200010
ans = ''
for i in range(64):
if (n >> i)&1:
k -= 1
cnt[i] = 1;
if k < 0:
print("No")
else:
print("Yes")
for i in range(64, -64, -1):
if k >= cnt[i]:
cnt[i - 1] += cnt[i] * 2
k -= cnt[i]
cnt[i] = 0
else: break
for i in range(... | {
"input": [
"23 5\n",
"1 2\n",
"13 2\n",
"513703875844698663 50\n",
"337790572680259391 29\n",
"923065764876596469 30\n",
"281474976710656 5\n",
"288318372649779720 50\n",
"19228 8\n",
"7 4\n",
"374585535361966567 30\n",
"36029346774812736 5\n",
"855969764271400156... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem:
Find k integers such t... |
939_C. Convenient For Everybody_37724 | In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, lo... | # Problem D
n = int(input())
inp = input().split(" ")
people = [ int(x) for x in inp ]
inp = input().split(" ")
s, f = int(inp[0]), int(inp[1])
r = f-s#+1 # tamaño de la ventana
max_s, idx_max = sum( people[i] for i in range(r) ), 0
sum_ac = max_s
res = (n-idx_max+s)%n if (n-idx_max+s)%n else n
for j in range(n):
... | {
"input": [
"5\n1 2 3 4 1\n1 3\n",
"3\n1 2 3\n1 3\n",
"2\n5 1\n1 2\n",
"10\n7171 2280 6982 9126 9490 2598 569 6744 5754 1855\n7 9\n",
"100\n6072 8210 6405 1191 2533 8552 7594 8793 2207 8855 7415 6252 3433 2339 5532 3118 3054 5750 3690 9843 3881 1390 936 8611 7099 988 7730 3835 7065 5030 6932 6936... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers f... |
991_F. Concise and clear_37730 | Vasya is a regular participant at programming contests and is already experienced in finding important sentences in long statements. Of course, numbers constraints are important — factorization of a number less than 1000000 is easier than of a number less than 1000000000. However, sometimes it's hard to understand the ... | import math
import itertools
pow10 = [1]
for i in range(10):
pow10.append(pow10[-1] * 10)
def getlen(x):
"""length of the decimal representation of integer x"""
return int(math.log10(x)) + 1
class ShortestRepresentation:
def __init__(self, n):
self.n = n
self._m = {}
self._... | {
"input": [
"1000000007\n",
"2018\n",
"2000000000\n",
"10000000000\n",
"2148437504\n",
"2190530369\n",
"1024000007\n",
"3758096389\n",
"8589942369\n",
"5159780354\n",
"2684354990\n",
"134217734\n",
"8707129352\n",
"1160290644\n",
"145746783\n",
"8719074... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya is a regular participant at programming contests and is already experienced in finding important sentences in long statements. Of course, numbers constraints are important — fac... |
p02621 AtCoder Beginner Contest 172 - Calc_37744 | Given an integer a as input, print the value a + a^2 + a^3.
Constraints
* 1 \leq a \leq 10
* a is an integer.
Input
Input is given from Standard Input in the following format:
a
Output
Print the value a + a^2 + a^3 as an integer.
Examples
Input
2
Output
14
Input
10
Output
1110 | a= int(input())
eq= a+(a**2)+(a**3)
print(eq) | {
"input": [
"2",
"10",
"1",
"0",
"3",
"4",
"6",
"7",
"-1",
"-2",
"5",
"-3",
"9",
"-4",
"-8",
"-6",
"-14",
"-9",
"-15",
"-11",
"-29",
"-7",
"-10",
"-5",
"-13",
"-12",
"-26",
"8",
"12",
"14",
"20... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Given an integer a as input, print the value a + a^2 + a^3.
Constraints
* 1 \leq a \leq 10
* a is an integer.
Input
Input is given from Standard Input in the following format:
a... |
p02752 Social Infrastructure Information Systems Division Hitachi Programming Contest 2020 - Preserve Diameter_37747 | We have a tree G with N vertices numbered 1 to N. The i-th edge of G connects Vertex a_i and Vertex b_i.
Consider adding zero or more edges in G, and let H be the graph resulted.
Find the number of graphs H that satisfy the following conditions, modulo 998244353.
* H does not contain self-loops or multiple edges.
* ... | import sys
input = sys.stdin.readline
mod=998244353
N=int(input())
E=[[] for i in range(N+1)]
for i in range(N-1):
x,y=map(int,input().split())
E[x].append(y)
E[y].append(x)
Q=[1]
D=[-1]*(N+1)
D[1]=0
while Q:
x=Q.pop()
for to in E[x]:
if D[to]==-1:
D[to]=D[x]+1
Q.a... | {
"input": [
"9\n1 2\n2 3\n4 2\n1 7\n6 1\n2 5\n5 9\n6 8",
"6\n1 6\n2 1\n5 2\n3 4\n2 3",
"19\n2 4\n15 8\n1 16\n1 3\n12 19\n1 18\n7 11\n11 15\n12 9\n1 6\n7 14\n18 2\n13 12\n13 5\n16 13\n7 1\n11 10\n7 17",
"3\n1 2\n2 3",
"6\n1 6\n2 1\n5 1\n3 4\n2 3",
"19\n2 4\n15 8\n1 16\n0 3\n12 19\n1 18\n7 11\n... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We have a tree G with N vertices numbered 1 to N. The i-th edge of G connects Vertex a_i and Vertex b_i.
Consider adding zero or more edges in G, and let H be the graph resulted.
Fi... |
p02887 AtCoder Beginner Contest 143 - Slimes_37750 | There are N slimes lining up from left to right. The colors of these slimes will be given as a string S of length N consisting of lowercase English letters. The i-th slime from the left has the color that corresponds to the i-th character of S.
Adjacent slimes with the same color will fuse into one larger slime withou... | n=int(input())
cnt=0
s=input()
for i in range(1,n):
if s[i]!=s[i-1]:
cnt+=1
print(cnt+1) | {
"input": [
"20\nxxzaffeeeeddfkkkkllq",
"5\naaaaa",
"10\naabbbbaaca",
"20\nxxzaffeeeeedfkkkkllq",
"5\naaaab",
"10\naabbcbaaca",
"20\nxfzaffeeeeedxkkkkllq",
"20\nxfzaffeeeeedxkkkkmlq",
"5\naa`ab",
"10\nacaaacbbaa",
"20\nxfzaffedeeedxkkkkmlq",
"5\naa``b",
"20\nxfzaef... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are N slimes lining up from left to right. The colors of these slimes will be given as a string S of length N consisting of lowercase English letters. The i-th slime from the le... |
p03022 AtCoder Grand Contest 034 - RNG and XOR_37753 | 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... | # Σ(i ^ j = k) ai * bj = ckという形で式が表されるとき
# fwht(a)*fwht(b)=fwht(c)が成り立ち高速化できる
# すごく必死に考えると
# a = [p0 p1 p2 ... p2^N-1]
# b = [x0 x1 x2 ... x2^N-1]
# c = [2^N-1 -1 -1 -1 .... -1]
# とするとうまいことaとcに変数が入らない形になるのでfwht(c)/fwht(a)を計算し
# fwht(b)がわかるのでこれを逆変換すればbが求められる
# なお逆変換は b = fwht(fwht(b)) / 要素数で求められる、なぜかは知らない
# またまたなぜかは知らない... | {
"input": [
"4\n337 780 799 10 796 875 331 223 941 67 148 483 390 565 116 355",
"2\n1 1 1 1",
"2\n1 2 1 2",
"4\n337 780 799 10 796 875 331 223 941 67 268 483 390 565 116 355",
"2\n1 1 1 2",
"2\n1 2 1 3",
"4\n337 780 799 10 796 875 331 223 1804 67 268 483 390 565 116 355",
"2\n1 1 1 3"... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
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... |
p03162 Educational DP Contest - Vacation_37757 | Taro's summer vacation starts tomorrow, and he has decided to make plans for it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i... | n=int(input())
a,b,c=map(int,input().split())
for _ in range(1,n):
aa,bb,cc=map(int,input().split())
a,b,c=aa+max(b,c),bb+max(a,c),cc+max(a,b)
print(max(a,b,c))
| {
"input": [
"3\n10 40 70\n20 50 80\n30 60 90",
"1\n100 10 1",
"7\n6 7 8\n8 8 3\n2 5 2\n7 8 6\n4 6 8\n2 3 4\n7 5 1",
"3\n1 40 70\n20 50 80\n30 60 90",
"1\n100 16 1",
"7\n6 7 8\n8 8 3\n2 5 2\n7 8 6\n4 6 8\n2 3 4\n7 7 1",
"1\n000 16 1",
"7\n6 7 14\n8 8 3\n2 5 2\n7 8 6\n4 6 8\n2 3 4\n7 7 ... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Taro's summer vacation starts tomorrow, and he has decided to make plans for it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the follow... |
p03305 SoundHound Inc. Programming Contest 2018 -Masters Tournament- - Saving Snuuk_37761 | Kenkoooo is planning a trip in Republic of Snuke. In this country, there are n cities and m trains running. The cities are numbered 1 through n, and the i-th train connects City u_i and v_i bidirectionally. Any city can be reached from any city by changing trains.
Two currencies are used in the country: yen and snuuk.... | import math, string, itertools, fractions, collections, re, array, bisect, sys, random, time, copy, functools
from heapq import heappush, heappop, heappushpop, heapify, heapreplace
N, M, S, T = [int(_) for _ in input().split()]
UVAB = [[int(_) for _ in input().split()] for _ in range(M)]
G1 = collections.defaultdict(l... | {
"input": [
"8 12 3 8\n2 8 685087149 857180777\n6 7 298270585 209942236\n2 4 346080035 234079976\n2 5 131857300 22507157\n4 8 30723332 173476334\n2 6 480845267 448565596\n1 4 181424400 548830121\n4 5 57429995 195056405\n7 8 160277628 479932440\n1 6 475692952 203530153\n3 5 336869679 160714712\n2 7 389775999 1991... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Kenkoooo is planning a trip in Republic of Snuke. In this country, there are n cities and m trains running. The cities are numbered 1 through n, and the i-th train connects City u_i a... |
p03465 AtCoder Grand Contest 020 - Median Sum_37764 | You are given N integers A_1, A_2, ..., A_N.
Consider the sums of all non-empty subsequences of A. There are 2^N - 1 such sums, an odd number.
Let the list of these sums in non-decreasing order be S_1, S_2, ..., S_{2^N - 1}.
Find the median of this list, S_{2^{N-1}}.
Constraints
* 1 \leq N \leq 2000
* 1 \leq A_i \... | n = int(input())
a = list(map(int, input().split()))
d = (sum(a)+1)//2
c = 1
for x in a:
c |= c << x
c >>= d
for i in range(d+5):
if c & (1 << i):
print(d+i)
break | {
"input": [
"3\n1 2 1",
"1\n58",
"3\n1 2 0",
"1\n32",
"1\n62",
"1\n26",
"3\n1 2 -1",
"1\n4",
"3\n1 3 -1",
"1\n7",
"1\n0",
"3\n3 5 -1",
"3\n3 9 -1",
"3\n-3 6 1",
"3\n-3 14 3",
"3\n-2 8 0",
"3\n-2 16 0",
"3\n-2 13 0",
"3\n0 11 2",
"3\n0 19... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given N integers A_1, A_2, ..., A_N.
Consider the sums of all non-empty subsequences of A. There are 2^N - 1 such sums, an odd number.
Let the list of these sums in non-decr... |
p03625 AtCoder Beginner Contest 071 - Make a Rectangle_37768 | We have N sticks with negligible thickness. The length of the i-th stick is A_i.
Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.
Constraints
* 4 \leq N \leq 10^5
* 1 \leq A_i \leq ... | N = int(input())
A = sorted([int(_) for _ in input().split()], reverse=True)
e = []
pre = 0
for i in range(N):
if pre == A[i]:
e.append(A[i])
if len(e) >= 2: break
pre = 0
else:
pre = A[i]
if len(e) < 2: print(0)
else: print(e[0] * e[1]) | {
"input": [
"10\n3 3 3 3 4 4 4 5 5 5",
"6\n3 1 2 4 2 1",
"4\n1 2 3 4",
"10\n3 3 3 3 4 4 2 5 5 5",
"6\n3 1 2 4 2 2",
"6\n3 2 2 4 2 2",
"6\n3 2 2 4 3 2",
"10\n3 3 6 3 4 4 1 6 5 5",
"10\n3 3 6 3 4 3 1 6 5 6",
"6\n3 4 2 3 4 3",
"10\n3 3 6 6 4 3 1 6 3 6",
"10\n3 2 8 6 4 0 1... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We have N sticks with negligible thickness. The length of the i-th stick is A_i.
Snuke wants to select four different sticks from these sticks and form a rectangle (including a squar... |
p03785 AtCoder Grand Contest 011 - Airport Bus_37772 | Every day, N passengers arrive at Takahashi Airport. The i-th passenger arrives at time T_i.
Every passenger arrived at Takahashi airport travels to the city by bus. Each bus can accommodate up to C passengers. Naturally, a passenger cannot take a bus that departs earlier than the airplane arrives at the airport. Also... | N,C,K=map(int,input().split())
T=[int(input()) for i in range(N)]
T.sort()
S=[[T[0]]]
t=T[0]
k=0
for i in range(1,N):
if T[i]<=t+K and len(S[k])<C:
S[k].append(T[i])
else:
k+=1
S.append([T[i]])
t=T[i]
print(len(S))
| {
"input": [
"5 3 5\n1\n2\n3\n6\n12",
"6 3 3\n7\n6\n2\n8\n10\n6",
"5 3 5\n1\n4\n3\n6\n12",
"5 5 5\n1\n4\n3\n6\n12",
"6 3 3\n7\n6\n2\n13\n17\n5",
"6 6 0\n7\n9\n8\n9\n19\n5",
"6 6 0\n7\n3\n8\n9\n19\n5",
"5 5 5\n1\n1\n4\n6\n4",
"6 3 3\n7\n6\n2\n13\n10\n6",
"6 3 6\n7\n6\n2\n13\n10\... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Every day, N passengers arrive at Takahashi Airport. The i-th passenger arrives at time T_i.
Every passenger arrived at Takahashi airport travels to the city by bus. Each bus can acc... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.