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 |
|---|---|---|---|---|---|
769_A. Year of University Entrance_7071 | There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university.
Each of students joins the group of his course and joins all groups f... | n = int(input())
a = list(map(int, input().split()))
a.sort()
if n % 2:
print(a[n//2]) | {
"input": [
"1\n2050\n",
"3\n2014 2016 2015\n",
"5\n2099 2096 2095 2097 2098\n",
"3\n2011 2010 2012\n",
"5\n2097 2099 2100 2098 2096\n",
"5\n2011 2014 2013 2010 2012\n",
"5\n2021 2023 2024 2020 2022\n",
"5\n2011 2014 2012 2013 2010\n",
"5\n2043 2042 2041 2044 2040\n",
"3\n2012... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of universit... |
793_A. Oleg and shares_7075 | Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg... | n,k=map(int,input().split())
l=list(map(int,input().split()))
K=min(l)
for i in range(n):
if (l[i]-K)%k!=0:
print(-1)
exit()
Sum=sum(l)
K=K*n
Sum=Sum-K
print(Sum//k) | {
"input": [
"2 2\n10 9\n",
"3 3\n12 9 15\n",
"4 1\n1 1000000000 1000000000 1000000000\n",
"3 3\n1 3 5\n",
"10 2\n2 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n",
"2 1\n2 3\n",
"3 5\n2 4 5\n",
"4 4\n1 5 8 14\n",
"2 6\n8 16\n",... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles ... |
813_D. Two Melodies_7078 | Alice is a beginner composer and now she is ready to create another masterpiece. And not even the single one but two at the same time!
Alice has a sheet with n notes written on it. She wants to take two such non-empty non-intersecting subsequences that both of them form a melody and sum of their lengths is maximal.
... | import sys
n = int(input()) + 1
a = [0] + list(map(int, input().split()))
mod7 = [x % 7 for x in a]
dp = [[0]*n for _ in range(n)]
maxnum = [0]*(10**5+10)
ans = 0
for i in range(n):
maxmod = [0]*7
for j in range(n):
maxnum[a[j]] = 0
for j in range(i):
maxnum[a[j]] = max(maxnum[a[j]], dp... | {
"input": [
"6\n62 22 60 61 48 49\n",
"4\n1 2 4 5\n",
"10\n7776 32915 1030 71664 7542 72359 65387 75222 95899 40333\n",
"6\n7 20 21 22 23 28\n",
"2\n1 4\n",
"10\n9 6 8 5 5 2 8 9 2 2\n",
"10\n1 1 1 1 1 1 1 1 1 1\n",
"6\n3 12 4 12 5 6\n",
"2\n5 4\n",
"3\n1 36 6\n",
"4\n15 11... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Alice is a beginner composer and now she is ready to create another masterpiece. And not even the single one but two at the same time!
Alice has a sheet with n notes written on it. ... |
839_C. Journey_7082 | There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them.... | from queue import *
n = int(input())
g = [[] for x in range(n)]
for i in range(n-1):
a, b = map(int, input().split())
a -= 1
b -= 1
g[a].append(b)
g[b].append(a)
used = [0]*n
anw = 0
def solve(v, d, r):
global anw
q = Queue()
q.put((v, d, r))
while not q.empty():
v, d, r = q.get(v)
used[v... | {
"input": [
"5\n1 2\n1 3\n3 4\n2 5\n",
"4\n1 2\n1 3\n2 4\n",
"1\n",
"10\n8 6\n9 10\n8 7\n1 4\n1 8\n9 5\n9 8\n2 5\n3 1\n",
"70\n1 25\n57 1\n18 1\n65 1\n38 1\n1 41\n1 5\n1 69\n1 3\n31 1\n1 8\n1 9\n53 1\n70 1\n45 1\n1 24\n1 42\n1 30\n1 12\n1 37\n64 1\n1 28\n1 58\n1 22\n11 1\n1 4\n1 27\n1 16\n1 21\n5... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse i... |
908_G. New Year and Original Order_7091 | Let S(n) denote the number that represents the digits of n in sorted order. For example, S(1) = 1, S(5) = 5, S(50394) = 3459, S(353535) = 333555.
Given a number X, compute <image> modulo 109 + 7.
Input
The first line of input will contain the integer X (1 ≤ X ≤ 10700).
Output
Print a single integer, the answer to ... | # Problem G
num = input()
num_list = []
for i in range(len(num)):
num_list.append(int(num[i]))
myMod = (10 ** 9) + 7
length = len(num_list)
f = [0] * (length + 1)
t = [1] * (length + 1)
for i in range(length):
f[i+1] = (f[i] * 10 + 1) % myMod
t[i+1] = (t[i] * 10) % myMod
ans = 0
for i in range(1, 10):
dp... | {
"input": [
"345342\n",
"21\n",
"33340691714056185860211260984431382156326935244157\n",
"44649014054971081213608137817466046254652492627741860478258558206397113198232823859870363821007188476405951611069347299689170240023979048198711745011542774268179055311013054073075176122755643483380248999657649211... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Let S(n) denote the number that represents the digits of n in sorted order. For example, S(1) = 1, S(5) = 5, S(50394) = 3459, S(353535) = 333555.
Given a number X, compute <image> mo... |
930_A. Peculiar apple-tree_7095 | In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are n inflorescences, numbered from 1 to n. Inflorescence number 1 is situated near base of tree and any other inflorescence with number i (i > 1) is situated at the top of branch... | from collections import defaultdict,Counter,deque as dq
from sys import stdin
input=stdin.readline
n=int(input())
g=defaultdict(list)
w=list(map(int,input().strip().split()))
for i in range(len(w)):
g[w[i]-1].append(i+1)
g[i+1].append(w[i]-1)
# print(g)
q=dq([0])
d=[-1]*(n)
d[0]=1
cnt=defaultdict(int)
cnt[1]+=1
wh... | {
"input": [
"18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4\n",
"3\n1 1\n",
"5\n1 2 2 2\n",
"3\n1 2\n",
"20\n1 2 2 4 3 5 5 6 6 9 11 9 9 12 13 10 15 13 15\n",
"30\n1 1 1 1 3 3 2 3 7 4 1 2 4 6 2 8 1 2 13 7 5 15 3 3 8 4 4 18 3\n",
"10\n1 2 3 4 5 5 5 7 9\n",
"40\n1 1 1 2 1 2 1 2 4 8 1 7 1 6 2 8... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are n inflorescences, numbered from 1 to n... |
984_A. Game_7101 | Two players play a game.
Initially there are n integers a_1, a_2, …, a_n written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. n - 1 turns are made. The first player makes the first move, then players alternate t... | x = int(input())
l = [int(n) for n in input().split()]
l.sort()
i = 0
while len(l) > 1:
if i % 2 == 0:
l = l[0:len(l) - 1]
else:
l = l[1:len(l)]
i = i + 1
print(l[0])
| {
"input": [
"3\n2 2 2\n",
"3\n2 1 3\n",
"10\n38 82 23 37 96 4 81 60 67 86\n",
"9\n44 53 51 80 5 27 74 79 94\n",
"3\n9 92 12\n",
"3\n1 2 2\n",
"2\n322 322\n",
"10\n58 26 77 15 53 81 68 48 22 65\n",
"1\n124\n",
"3\n1 1 1000\n",
"2\n2 1\n",
"10\n38 82 42 37 96 4 81 60 67 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Two players play a game.
Initially there are n integers a_1, a_2, …, a_n written on the board. Each turn a player selects one number and erases it from the board. This continues unti... |
p02569 AtCoder Library Practice Contest - Lazy Segment Tree_7114 | You are given a binary array A=(A_1,A_2,\cdots,A_N) of length N.
Process Q queries of the following types. The i-th query is represented by three integers T_i,L_i,R_i.
* T_i=1: Replace the value of A_j with 1-A_j for each L_i \leq j \leq R_i.
* T_i=2: Calculate the inversion(*) of the array A_{L_i},A_{L_i+1},\cdots,A... | import sys
input = lambda: sys.stdin.readline().rstrip()
class LazySegmentTree():
def __init__(self, init, unitX, unitA, f, g, h):
self.f = f # (X, X) -> X
self.g = g # (X, A, size) -> X
self.h = h # (A, A) -> A
self.unitX = unitX
self.unitA = unitA
self.f = f
... | {
"input": [
"5 5\n0 1 0 0 1\n2 1 5\n1 3 4\n2 2 5\n1 1 3\n2 1 2",
"5 5\n0 1 0 0 1\n2 1 5\n1 3 4\n2 2 3\n1 1 3\n2 1 2",
"5 5\n0 1 0 0 1\n2 1 5\n1 3 4\n2 2 5\n1 1 1\n2 1 2",
"5 5\n0 1 0 0 1\n2 1 5\n1 3 4\n2 2 5\n2 1 3\n2 1 2",
"5 5\n1 1 0 0 1\n2 1 5\n1 3 4\n2 2 5\n2 1 3\n2 1 2",
"5 5\n0 1 0 0 0\... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a binary array A=(A_1,A_2,\cdots,A_N) of length N.
Process Q queries of the following types. The i-th query is represented by three integers T_i,L_i,R_i.
* T_i=1: Repl... |
p02700 AtCoder Beginner Contest 164 - Battle_7118 | Takahashi and Aoki will have a battle using their monsters.
The health and strength of Takahashi's monster are A and B, respectively, and those of Aoki's monster are C and D, respectively.
The two monsters will take turns attacking, in the order Takahashi's, Aoki's, Takahashi's, Aoki's, ... Here, an attack decreases ... | a,b,c,d = map(int,input().split())
print('Yes' if (c+b-1)//b <= (a+d-1)//d else 'No') | {
"input": [
"46 4 40 5",
"10 9 10 10",
"46 4 4 5",
"10 9 13 10",
"64 4 4 5",
"5 9 13 10",
"64 8 4 5",
"5 9 3 10",
"54 8 4 5",
"5 13 3 10",
"54 8 2 5",
"5 14 3 10",
"54 6 2 5",
"5 14 3 12",
"54 6 0 5",
"7 14 3 12",
"79 6 0 5",
"7 14 1 12",
"7... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Takahashi and Aoki will have a battle using their monsters.
The health and strength of Takahashi's monster are A and B, respectively, and those of Aoki's monster are C and D, respect... |
p02829 AtCoder Beginner Contest 148 - Round One_7122 | Takahashi is solving quizzes. He has easily solved all but the last one.
The last quiz has three choices: 1, 2, and 3.
With his supernatural power, Takahashi has found out that the choices A and B are both wrong.
Print the correct choice for this problem.
Constraints
* Each of the numbers A and B is 1, 2, or 3.
* ... | A = int(input())
B = int(input())
print(1+2+3 -A-B) | {
"input": [
"1\n2",
"3\n1",
"3\n2",
"1\n3",
"3\n001",
"3\n2",
"1\n3",
"3\n001"
],
"output": [
"3",
"2",
"1\n",
"2\n",
"2\n",
"1\n",
"2\n",
"2\n"
]
} | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Takahashi is solving quizzes. He has easily solved all but the last one.
The last quiz has three choices: 1, 2, and 3.
With his supernatural power, Takahashi has found out that the ... |
p02966 AtCoder Grand Contest 036 - Negative Cycle_7125 | We have a weighted directed graph with N vertices numbered 0 to N-1.
The graph initially has N-1 edges. The i-th edge (0 \leq i \leq N-2) is directed from Vertex i to Vertex i+1 and has a weight of 0.
Snuke will now add a new edge (i → j) for every pair i, j (0 \leq i,j \leq N-1,\ i \neq j). The weight of the edge wi... | N = int(input())
A = [[0] * N for _ in range(N)]
Al = [[0] * (N+1) for _ in range(N+1)]
Ar = [[0] * (N+1) for _ in range(N+1)]
for i in range(N) :
a = [int(i) for i in input().split()]
for j in range(N) :
if i < j :
A[i][j] = a[j-1]
elif i > j :
A[i][j] = a[j]
for ... | {
"input": [
"4\n1 1 1\n1 1 1\n1 1 1\n1 1 1",
"3\n2 1\n1 4\n3 3",
"10\n190587 2038070 142162180 88207341 215145790 38 2 5 20\n32047998 21426 4177178 52 734621629 2596 102224223 5 1864\n41 481241221 1518272 51 772 146 8805349 3243297 449\n918151 126080576 5186563 46354 6646 491776 5750138 2897 161\n3656 75... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We have a weighted directed graph with N vertices numbered 0 to N-1.
The graph initially has N-1 edges. The i-th edge (0 \leq i \leq N-2) is directed from Vertex i to Vertex i+1 and ... |
p03101 AtCoder Beginner Contest 121 - White Cells_7129 | There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on what rows and columns are chosen.
Constraints
* All values i... | #!/usr/bin/env python3
h, w, x, y = map(int, open(0).read().split())
print((h-x)*(w-y))
| {
"input": [
"2 4\n2 4",
"5 5\n2 3",
"3 2\n2 1",
"2 4\n2 3",
"5 5\n2 2",
"4 2\n2 1",
"4 5\n2 2",
"4 0\n2 1",
"7 5\n2 2",
"4 0\n0 1",
"7 5\n1 2",
"4 -1\n0 1",
"7 5\n0 2",
"4 0\n-1 1",
"4 1\n2 4",
"7 5\n0 1",
"4 1\n3 4",
"4 0\n-2 2",
"4 -1\n-2 ... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells contained in those rows or columns.
How many whi... |
p03249 AtCoder Regular Contest 103 - Distance Sums_7132 | You are given a sequence D_1, D_2, ..., D_N of length N. The values of D_i are all distinct. Does a tree with N vertices that satisfies the following conditions exist?
* The vertices are numbered 1,2,..., N.
* The edges are numbered 1,2,..., N-1, and Edge i connects Vertex u_i and v_i.
* For each vertex i, the sum of ... | #!/usr/bin/env python3
import sys
sys.setrecursionlimit(101010)
def dfs(v, adj_list, depth, visited):
visited[v] = True
x = depth
for w in adj_list[v]:
if not visited[w]:
x += dfs(w, adj_list, depth + 1, visited)
return x
def solve(n, d):
if n < 7:
print(-1)
... | {
"input": [
"15\n57\n62\n47\n45\n42\n74\n90\n75\n54\n50\n66\n63\n77\n87\n51",
"2\n1\n2",
"7\n10\n15\n13\n18\n11\n14\n19",
"15\n57\n62\n37\n45\n42\n74\n90\n75\n54\n50\n66\n63\n77\n87\n51",
"2\n0\n2",
"7\n10\n15\n13\n18\n11\n24\n19",
"15\n57\n62\n74\n45\n42\n74\n90\n75\n54\n50\n66\n63\n77\n... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a sequence D_1, D_2, ..., D_N of length N. The values of D_i are all distinct. Does a tree with N vertices that satisfies the following conditions exist?
* The vertices... |
p03400 AtCoder Beginner Contest 092 - Chocolate_7136 | Some number of chocolate pieces were prepared for a training camp. The camp had N participants and lasted for D days. The i-th participant (1 \leq i \leq N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result, there were X ... | n=int(input())
d,x=map(int,input().split())
a=[int(input()) for _ in range(n)]
c=0
for ai in a:
c+=1+(d-1)//ai
print(c+x)
| {
"input": [
"5\n30 44\n26\n18\n81\n18\n6",
"3\n7 1\n2\n5\n10",
"2\n8 20\n1\n10",
"5\n30 44\n26\n18\n81\n27\n6",
"3\n7 1\n1\n5\n10",
"2\n8 20\n1\n19",
"3\n7 1\n2\n5\n19",
"2\n8 23\n1\n19",
"5\n1 44\n26\n18\n76\n27\n6",
"3\n1 1\n2\n5\n19",
"3\n1 2\n2\n5\n15",
"5\n1 52\n2... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Some number of chocolate pieces were prepared for a training camp. The camp had N participants and lasted for D days. The i-th participant (1 \leq i \leq N) ate one chocolate piece on... |
p03565 AtCoder Beginner Contest 076 - Dubious Document 2_7140 | E869120 found a chest which is likely to contain treasure.
However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters.
He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with `?`.
One more t... | S = input()
T = input()
ls = len(S)
lt = len(T)
for i in range(ls-lt,-1,-1):
for j in range(lt):
if S[i+j] != T[j] and S[i+j] != '?':
break
else:
print((S[:i] + T + S[i+lt:]).replace('?','a'))
break
else:
print('UNRESTORABLE') | {
"input": [
"?tc????\ncoder",
"??p??d??\nabc",
"?tc??@?\ncoder",
">q???d?>\n_ba",
"d>>>???q\na`a",
"d>>>???q\naaa",
"??p??d??\nabb",
"?tc??@?\ncnder",
"??p??d??\n`bb",
"?tc??@?\nendcr",
"??p??d??\n`ab",
"@tc??@?\nendcr",
"??p??d??\nba`",
"@tc??@?\nendcq",
"... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
E869120 found a chest which is likely to contain treasure.
However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters.
He ... |
p03720 AtCoder Beginner Contest 061 - Counting Roads_7144 | There are N cities and M roads. The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally. There may be more than one road that connects the same pair of two cities. For each city, how many roads are connected to the city?
Constraints
* 2≤N,M≤50
* 1≤a_i,b_i≤N
* a_i ≠ b_i
* All input values a... | n,m = map(int,input().split())
l = [0]*n
for i in range(0,m):
for j in list(map(int,input().split())):
l[j-1]+=1
for i in range(0,n):
print(l[i]) | {
"input": [
"4 3\n1 2\n2 3\n1 4",
"8 8\n1 2\n3 4\n1 5\n2 8\n3 7\n5 2\n4 1\n6 8",
"2 5\n1 2\n2 1\n1 2\n2 1\n1 2",
"3 5\n1 2\n2 1\n1 2\n2 1\n1 2",
"3 5\n1 2\n2 1\n1 2\n1 1\n1 2",
"8 7\n1 2\n3 4\n1 5\n2 8\n3 7\n5 2\n4 1\n6 8",
"8 7\n1 3\n3 4\n1 5\n2 8\n3 7\n5 2\n4 1\n6 8",
"2 5\n1 2\n2 1... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are N cities and M roads. The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally. There may be more than one road that connects the same pair of two... |
p03880 CODE FESTIVAL 2016 Grand Final(Parallel) - Cheating Nim_7148 | A cheetah and a cheater are going to play the game of Nim. In this game they use N piles of stones. Initially the i-th pile contains a_i stones. The players take turns alternately, and the cheetah plays first. In each turn, the player chooses one of the piles, and takes one or more stones from the pile. The player who ... | from functools import reduce
from operator import xor
N = int(input())
As = [int(input()) for _ in range(N)]
dXORs = set([A ^ (A-1) for A in As])
XOR = reduce(xor, As)
ans = 0
for i in reversed(range(30)):
if XOR & (1<<i):
d = ((1<<(i+1)) - 1)
if d in dXORs:
XOR ^= d
ans +... | {
"input": [
"3\n2\n3\n4",
"3\n100\n100\n100",
"3\n3\n3\n4",
"3\n001\n100\n100",
"3\n2\n3\n3",
"3\n2\n1\n3",
"3\n4\n5\n8",
"3\n101\n100\n100",
"3\n3\n5\n4",
"3\n3\n4\n4",
"3\n011\n100\n100",
"3\n100\n110\n100",
"3\n3\n5\n8",
"3\n010\n100\n100",
"3\n3\n1\n4",... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A cheetah and a cheater are going to play the game of Nim. In this game they use N piles of stones. Initially the i-th pile contains a_i stones. The players take turns alternately, an... |
p04041 AtCoder Regular Contest 058 - Iroha and Haiku_7151 | Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order.
Iroha is looking for X,Y,Z-Haiku (defined below) in integer sequences.
Consider all integer sequences of length N whose elements are between 1 and 10, inclusive. Out of those 10^N sequences, how many ... | from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
#import random
def I():
return int(input())
def MI():
return map(int,input().split())
def LI():
... | {
"input": [
"40 5 7 5",
"4 5 7 5",
"3 5 7 5",
"37 4 2 3",
"37 4 3 3",
"5 4 3 3",
"5 4 2 3",
"0 4 2 3",
"8 5 7 5",
"3 3 7 5",
"7 4 2 3",
"37 3 3 3",
"5 8 3 3",
"8 4 2 3",
"8 5 7 3",
"7 4 1 3",
"37 3 2 3",
"7 8 3 3",
"8 5 2 3",
"8 4 7 3",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order.
Iroha is looking for X,Y,Z-Haiku (defined below) in integer sequ... |
p00122 Summer of Pyonkichi_7155 | The University of Aizu has a park covered with grass, and there are no trees or buildings that block the sunlight. On sunny summer days, sprinklers installed in the park operate to sprinkle water on the lawn. The frog Pyonkichi lives in this park. Pyonkichi is not good at hot weather, and on summer days when the sun is... | move = [[-1, 2], [0, 2], [1, 2],
[-1, -2], [0, -2], [1, -2],
[2, 1], [2, 0], [2, -1],
[-2, 1], [-2, 0], [-2, -1]]
spraing_range = [[-1, 1], [0, 1], [1, 1],
[-1, 0], [0, 0], [1, 0],
[-1, -1], [0, -1], [1, -1]]
def main():
while True:
px, py = map(i... | {
"input": [
"6 1\n10\n6 4 3 3 1 2 0 5 4 6 1 8 5 9 7 7 8 6 8 3\n6 1\n10\n6 4 3 3 1 2 0 5 4 6 1 8 5 9 7 7 8 6 9 0\n0 0",
"6 1\n10\n6 4 3 3 1 2 0 5 4 6 1 8 5 9 7 7 8 6 8 3\n6 1\n10\n6 4 3 3 1 2 0 5 4 6 1 8 5 7 7 7 8 6 9 0\n0 0",
"6 1\n10\n6 4 3 3 1 2 0 5 4 6 1 8 5 9 7 7 8 6 3 3\n6 1\n10\n6 4 3 3 1 2 0 5 4 6... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The University of Aizu has a park covered with grass, and there are no trees or buildings that block the sunlight. On sunny summer days, sprinklers installed in the park operate to sp... |
p00255 Salary for a Plumber_7159 | I am a pipe tie craftsman. As long as you get the joints and pipes that connect the pipes, you can connect any pipe. Every day, my master gives me pipes and joints, which I connect and give to my master. But if you have too many pipes, you can't connect them all in one day. Even in such a case, the master smiles and gi... | # -*- coding: utf-8 -*-
"""
Salary for a Plumber
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0260
"""
import sys
def solve(n):
pipes = [int(p) for p in input().split()]
joints = sorted([int(j) for j in input().split()])
total_length = sum(pipes)
record = total_length * n
while joint... | {
"input": [
"3\n1 1 1\n3 3\n4\n3 3 3 3\n1 1 1\n5\n1 2 3 4 5\n4 3 2 1\n0",
"3\n1 1 1\n3 3\n4\n3 1 3 3\n1 1 1\n5\n1 2 3 4 5\n4 3 2 1\n0",
"3\n1 1 1\n3 3\n4\n3 1 3 3\n1 1 1\n5\n1 2 3 4 5\n3 3 2 1\n0",
"3\n0 1 1\n3 3\n4\n3 1 3 3\n1 1 1\n5\n1 2 3 4 5\n3 3 2 1\n0",
"3\n0 1 1\n3 3\n4\n3 1 5 3\n1 1 1\n5\... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
I am a pipe tie craftsman. As long as you get the joints and pipes that connect the pipes, you can connect any pipe. Every day, my master gives me pipes and joints, which I connect an... |
p00441 The Oldest Site_7163 | problem
Once upon a time there were settlements and many people lived there. People built buildings of various shapes and sizes. But those buildings have already been lost, only the literature and the pillars found in the ruins. Was a clue to the location of the building.
There is a description of the temple in the l... | def main():
while True:
n = int(input())
if not n:
break
ps = [list(map(int,input().split())) for i in range(n)]
dic = set()
for t in ps:
dic.add((t[0],t[1]))
ans = 0
for i in range(n):
for j in range(n):
p1 = ps[i]
p2 = ps[j]
p1x = p1[0]
... | {
"input": [
"10\n9 4\n4 3\n1 1\n4 2\n2 4\n5 8\n4 0\n5 3\n0 5\n5 2\n10\n9 4\n4 3\n1 1\n4 2\n2 4\n5 8\n4 0\n5 3\n0 5\n5 2\n0",
"10\n9 4\n4 3\n1 1\n4 2\n2 4\n5 8\n4 0\n5 3\n0 5\n5 2\n10\n2 4\n4 3\n1 1\n4 2\n2 4\n5 8\n4 0\n5 3\n0 5\n5 2\n0",
"10\n9 4\n4 3\n1 1\n4 2\n2 4\n5 8\n4 1\n5 3\n0 5\n5 2\n10\n2 4\n4 3... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
problem
Once upon a time there were settlements and many people lived there. People built buildings of various shapes and sizes. But those buildings have already been lost, only the ... |
p00632 Ghost Buster!_7167 | The city is full of ghosts, something the average person doesn't know about. Most of them are harmless, but the trouble is that there are quite a few evil spirits that curse people.
There was a girl who fought against such evil spirits. She goes to high school with a faceless face during the day, but at night she walk... | from collections import deque
while True:
h, w = map(int, input().split())
if h == 0:
break
mp = [list("X" + input() + "X") for _ in range(h)]
mp.insert(0, ["X"] * (w + 2))
mp.append(["X"] * (w + 2))
for y in range(h + 2):
for x in range(w + 2):
if mp[y][x] == "A":
ax, ay = x, y
... | {
"input": [
"4 7\nA#...#B\n.#.#.#.\n.#.#.#.\n...#...\n5\n4 7\nA#...#B\n.#.#.#.\n.#.#.#.\n...#...\n2\n4 7\nA#...#B\n.#.#.#.\n.#.#.#.\n...#...\n4\n4 7\nA#...#B\n.#.#.#.\n.#.#.#.\n...#...\n442668\n1 10\nA#.......B\n55555554\n1 10\nA#.......B\n55555555\n0 0",
"4 7\nA#...#B\n.#.#.#.\n.#.#.#.\n...#...\n5\n4 7\nA#.... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The city is full of ghosts, something the average person doesn't know about. Most of them are harmless, but the trouble is that there are quite a few evil spirits that curse people.
... |
p00776 Encryption System_7171 | Encryption System
A programmer developed a new encryption system. However, his system has an issue that two or more distinct strings are `encrypted' to the same string.
We have a string encrypted by his system. To decode the original string, we want to enumerate all the candidates of the string before the encryption.... | from itertools import chain
alph = "abcdefghijklmnopqrstuvwxyz"
# s = input()
def solve1(s):
cands = [s]
for c in reversed(alph[:-1]):
cands = chain.from_iterable(
[candidates(s, c) for s in cands]
)
cands = list(cands)
cands.sort()
print(len(cands))
if len(cands) ... | {
"input": [
"enw\nabc\nabcdefghijklmnopqrst\nz\n#",
"enw\nbbc\nabcdefghijklmnopqrst\nz\n#",
"enw\ncbb\nabcdefggijklmnopqrst\nz\n#",
"enw\ncbb\nabcsefggijklmnopqrdt\nz\n#",
"enw\nabb\nabcdefghijklmnopqrst\nz\n#",
"enw\nbcc\nabcdefghijklmnopqrst\nz\n#",
"enw\ncbb\ntsrqponmlkjihgfedcba\nz\n#... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Encryption System
A programmer developed a new encryption system. However, his system has an issue that two or more distinct strings are `encrypted' to the same string.
We have a st... |
p00907 Find the Outlier_7175 | Professor Abacus has just built a new computing engine for making numerical tables. It was designed to calculate the values of a polynomial function in one variable at several points at a time. With the polynomial function f(x) = x2 + 2x + 1, for instance, a possible expected calculation result is 1 (= f(0)), 4 (= f(1)... | from itertools import combinations
def build(X, Y):
A = []
for x in X:
res = 1
for xi in X:
if x == xi:
continue
res *= x - xi
A.append(Y[x] / res)
return A
def calc(X, A, x):
base = 1
for xi in X:
base *= i - xi
return su... | {
"input": [
"2\n1.0\n4.0\n12.0\n16.0\n25.0\n1\n-30.5893962764\n5.76397083962\n39.3853798058\n74.3727663177\n4\n42.4715310246\n79.5420238202\n28.0282396675\n-30.3627807522\n-49.8363481393\n-25.5101480106\n7.58575761381\n5\n-21.9161699038\n-48.469304271\n-24.3188578417\n-2.35085940324\n-9.70239202086\n-47.27095106... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Professor Abacus has just built a new computing engine for making numerical tables. It was designed to calculate the values of a polynomial function in one variable at several points ... |
p01479 Chicken or the Egg_7183 | Time Limit: 8 sec / Memory Limit: 64 MB
Example
Input
eggchickenegg
Output
egg | s=input()
i=c=p=0;b=''
while i<len(s):
if s[i]==b:
if c > p:r=b;p=c
c=0
b=s[i]
i+=[3,7][s[i]=='c']
c+=1
if c>p:r=b
print(['chicken','egg'][r=='e']) | {
"input": [
"eggchickenegg",
"egichgckenegg",
"egechmilfgcgg",
"egichnckegegg",
"egechickgnegg",
"egichgbkenegg",
"egickgbhenegg",
"eghchickenegg",
"egichnckfgegg",
"egickgbhemegg",
"egibkgbhemegg",
"eggchickemegg",
"egechnckigegg",
"egihcgbkenegg",
"egickf... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Time Limit: 8 sec / Memory Limit: 64 MB
Example
Input
eggchickenegg
Output
egg
### Input:
eggchickenegg
### Output:
egg
### Input:
egichgckenegg
### Output:
egg
### Code... |
p02206 Prize_7193 | Prize
Segtree entered a programming contest with a team of $ N $ and won a $ K $ yen prize! I'm trying to distribute this prize now.
Each $ N $ team member, including Segtree, is numbered from $ 1 $ to $ N $ in order of ability. Segtree is $ 1 $.
If the prize amount of $ i $'s teammate $ (i \ geq 2) $ is less than "... | n,k = map(int,input().split())
ok,ng = 0,k+1
while ng-ok>1:
mid = (ng+ok)//2
s = 0
m = mid
for i in range(n):
s += m
m //= 2
if m == 0:
break
if s <= k:
ok = mid
else:
ng = mid
print(ok)
| {
"input": [
"1 1",
"1 2",
"2 1",
"1 3",
"1 4",
"1 6",
"2 12",
"2 8",
"1 9",
"3 12",
"14 32",
"26 36",
"26 30",
"1 11",
"3 24",
"3 17",
"26 42",
"1 18",
"4 24",
"48 62",
"1 38",
"6 31",
"9 22",
"48 40",
"1 74",
"2 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Prize
Segtree entered a programming contest with a team of $ N $ and won a $ K $ yen prize! I'm trying to distribute this prize now.
Each $ N $ team member, including Segtree, is nu... |
p02360 The Maximum Number of Overlaps_7196 | Given a set of $N$ axis-aligned rectangular seals, find the number of overlapped seals on the region which has the maximum number of overlapped seals.
Constraints
* $ 1 \leq N \leq 100000 $
* $ 0 \leq x1_i < x2_i \leq 1000 $
* $ 0 \leq y1_i < y2_i \leq 1000 $
* $ x1_i, y1_i, x2_i, y2_i$ are given in integers
Input
... | #!/usr/bin/env python3
# DSL_5_B: The Maximum Number of Overlaps
from itertools import accumulate
import sys
if __name__ == '__main__':
n = int(input())
ys = [0] * 1001
rects = [None] * 2 * n
i = 0
for line in sys.stdin:
x1, y1, x2, y2 = [int(j) for j in line.split()]
rects[i] = ... | {
"input": [
"2\n0 0 2 2\n2 0 4 2",
"3\n0 0 2 2\n0 0 2 2\n0 0 2 2",
"2\n0 0 3 2\n2 1 4 3",
"2\n0 0 2 2\n2 0 4 4",
"3\n0 0 1 2\n0 0 2 2\n0 0 2 2",
"2\n0 0 3 2\n2 1 4 2",
"2\n0 0 0 1\n2 2 4 2",
"2\n0 0 3 1\n2 1 4 3",
"2\n0 0 3 1\n2 1 4 2",
"2\n0 0 3 1\n2 1 4 4",
"2\n0 0 2 2\n... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Given a set of $N$ axis-aligned rectangular seals, find the number of overlapped seals on the region which has the maximum number of overlapped seals.
Constraints
* $ 1 \leq N \leq ... |
1045_B. Space Isaac_7207 | Everybody seems to think that the Martians are green, but it turns out they are metallic pink and fat. Ajs has two bags of distinct nonnegative integers. The bags are disjoint, and the union of the sets of numbers in the bags is \{0,1,…,M-1\}, for some positive integer M. Ajs draws a number from the first bag and a num... | import sys
input = sys.stdin.readline
def main():
n, m = map(int, input().split())
a = list(map(int, input().split())) + [0]*500000
ans_S = 0
a[n] = a[0] + m
s = [0]*600600
for i in range(n):
s[i] = a[i + 1] - a[i]
s[n] = -1
for i in range(n):
s[2*n - i] = s[i]
for i... | {
"input": [
"4 1000000000\n5 25 125 625\n",
"2 4\n1 3\n",
"2 5\n3 4\n",
"4 20\n5 6 7 16\n",
"9 10\n1 2 3 4 5 6 7 8 9\n",
"3 100000011\n678 500678 1000678\n",
"14 34\n1 2 4 7 10 12 13 18 19 21 24 27 29 30\n",
"36 81\n4 5 7 8 13 14 16 17 22 23 25 26 31 32 34 35 40 41 43 44 49 50 52 53 5... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Everybody seems to think that the Martians are green, but it turns out they are metallic pink and fat. Ajs has two bags of distinct nonnegative integers. The bags are disjoint, and th... |
1068_B. LCM_7211 | Ivan has number b. He is sorting through the numbers a from 1 to 10^{18}, and for every a writes ([a, b])/(a) on blackboard. Here [a, b] stands for least common multiple of a and b. Ivan is very lazy, that's why this task bored him soon. But he is interested in how many different numbers he would write on the boa... | b=int(input())
out=[1]
n=b
i=0
while n%2==0:
i=i+1
out.append(2**i)
n=int(n/2)
out1=[]
for i in range (1,int(n**0.5)+1,2):
if n%i==0:
out1.append(i)
out1.append(int(n/i))
out2=set()
for i in out:
for j in out1:
out2.add(i*j)
#print (out2)
print (len(out2))
| {
"input": [
"1\n",
"2\n",
"244078129\n",
"2793510720\n",
"16\n",
"179\n",
"1048576\n",
"5\n",
"1102701600\n",
"4324320\n",
"2000000014\n",
"8872504640\n",
"963837006\n",
"8\n",
"2327925600\n",
"58697100\n",
"51\n",
"2095133040\n",
"196729490... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Ivan has number b. He is sorting through the numbers a from 1 to 10^{18}, and for every a writes ([a, b])/(a) on blackboard. Here [a, b] stands for least common multiple of a an... |
1139_A. Even Substrings_7219 | You are given a string s=s_1s_2... s_n of length n, which only contains digits 1, 2, ..., 9.
A substring s[l ... r] of s is a string s_l s_{l + 1} s_{l + 2} … s_r. A substring s[l ... r] of s is called even if the number represented by it is even.
Find the number of even substrings of s. Note, that even if some subs... | n = int(input())
s = input()
k = 0
for i in range(1, n + 1):
d = int(s[i - 1])
if d % 2 == 0:
k += i
print(k)
| {
"input": [
"4\n1234\n",
"4\n2244\n",
"3\n112\n",
"3\n121\n",
"3\n122\n",
"39\n263254663359864483324578786753512345165\n",
"3\n211\n",
"3\n111\n",
"2\n81\n",
"3\n222\n",
"3\n212\n",
"2\n13\n",
"10\n9572683145\n",
"1\n3\n",
"3\n221\n",
"2\n18\n",
"2\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a string s=s_1s_2... s_n of length n, which only contains digits 1, 2, ..., 9.
A substring s[l ... r] of s is a string s_l s_{l + 1} s_{l + 2} … s_r. A substring s[l ..... |
1157_B. Long Number_7223 | You are given a long decimal number a consisting of n digits from 1 to 9. You also have a function f that maps every digit from 1 to 9 to some (possibly the same) digit from 1 to 9.
You can perform the following operation no more than once: choose a non-empty contiguous subsegment of digits in a, and replace each digi... | n = int(input())
a = list(input())
a = [int(x) for x in a]
d = {}
replacements = list(map(int, input().split()))
for i in range(9):
d[i+1] = replacements[i]
b = [d[x] for x in a]
ans = ""
flag = False
i = 0
j = 0
k = 0
for i in range(len(a)):
if(a[i] >= b[i]):
ans += str(a[i])
else:
flag = True
break
if(flag):... | {
"input": [
"2\n33\n1 1 1 1 1 1 1 1 1\n",
"4\n1337\n1 2 5 4 6 6 3 1 9\n",
"5\n11111\n9 8 7 6 5 4 3 2 1\n",
"18\n263583239493593927\n7 7 3 7 7 6 9 7 6\n",
"3\n649\n1 5 2 9 7 8 8 3 1\n",
"3\n985\n3 5 3 8 8 6 4 4 3\n",
"19\n2612437771227631192\n6 7 3 6 8 7 9 9 9\n",
"1\n3\n2 8 4 5 4 1 7 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a long decimal number a consisting of n digits from 1 to 9. You also have a function f that maps every digit from 1 to 9 to some (possibly the same) digit from 1 to 9.
... |
1197_E. Culture Code_7229 | There are famous Russian nesting dolls named matryoshkas sold in one of the souvenir stores nearby, and you'd like to buy several of them. The store has n different matryoshkas. Any matryoshka is a figure of volume out_i with an empty space inside of volume in_i (of course, out_i > in_i).
You don't have much free spac... | from sys import stdin, stdout
mod = 10**9+7
n = int(input())
dolls = []
for i in range(n):
o, i = map(int, stdin.readline().split())
dolls.append((o, i))
dolls.sort()
dolls = [(i, o) for (o, i) in dolls]
#print(dolls)
def bin_search(i):
lo = -1
hi = n-1
while lo+1 < hi:
mid = (lo+hi-1)/... | {
"input": [
"7\n4 1\n4 2\n4 2\n2 1\n5 4\n6 4\n3 2\n",
"1\n1000000000 999999999\n",
"4\n3 2\n10 2\n4 3\n5 4\n",
"10\n7 6\n15 14\n6 5\n8 7\n9 8\n17 16\n9 8\n2 1\n3 2\n5 4\n",
"10\n19 17\n14 11\n16 15\n19 18\n12 9\n5 3\n18 16\n13 12\n13 11\n3 2\n",
"10\n12 11\n14 13\n17 16\n3 2\n13 12\n4 3\n16 1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are famous Russian nesting dolls named matryoshkas sold in one of the souvenir stores nearby, and you'd like to buy several of them. The store has n different matryoshkas. Any m... |
1237_H. Balanced Reversals_7234 | You have two strings a and b of equal even length n consisting of characters 0 and 1.
We're in the endgame now. To finally make the universe perfectly balanced, you need to make strings a and b equal.
In one step, you can choose any prefix of a of even length and reverse it. Formally, if a = a_1 a_2 … a_n, you can ch... | import os
import sys
from io import BytesIO, IOBase
# region fastio
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
self.write = self.buffer.write... | {
"input": [
"4\n0100011011\n1101011000\n10101010\n10101010\n0011\n1001\n100011\n110010\n",
"4\n0100011011\n1101011000\n10101010\n10101010\n0011\n1001\n100011\n110010\n",
"4\n0000011011\n1101011000\n10101010\n10101010\n0011\n1001\n100011\n110010\n",
"4\n0100011011\n1101011000\n10101010\n10101010\n0011... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You have two strings a and b of equal even length n consisting of characters 0 and 1.
We're in the endgame now. To finally make the universe perfectly balanced, you need to make stri... |
1256_A. Payment Without Change_7238 | You have a coins of value n and b coins of value 1. You always pay in exact change, so you want to know if there exist such x and y that if you take x (0 ≤ x ≤ a) coins of value n and y (0 ≤ y ≤ b) coins of value 1, then the total value of taken coins will be S.
You have to answer q independent test cases.
Input
The... | from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
def main():
q = int(input())
for i in range(q):
... | {
"input": [
"4\n1 2 3 4\n1 2 3 6\n5 2 6 27\n3 3 5 18\n",
"1\n16 2 3 55\n",
"1\n87 63 54 9\n",
"6\n1 1000000000 1 1000000000\n1 1000000000 1 1000000000\n1 1000000000 1 1000000000\n1 1000000000 1 1000000000\n1 1000000000 1 1000000000\n1 1000000000 1 1000000000\n",
"1\n2104 2104 1 2104\n",
"1\n5... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You have a coins of value n and b coins of value 1. You always pay in exact change, so you want to know if there exist such x and y that if you take x (0 ≤ x ≤ a) coins of value n and... |
127_A. Wasted Time_7242 | Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.
Mr. Scrooge's signature can be represented as a polyline ... |
n,k = list(map(int,input().split()))
ans = 0
for i in range(n):
if i==0:
x,y= list(map(int,input().split()))
else:
X,Y = list(map(int,input().split()))
d = ((X-x)**2+(Y-y)**2)**(1/2)
x,y=X,Y
ans += d
ans=((ans*k)/50)
print('%.9f'%ans) | {
"input": [
"2 1\n0 0\n10 0\n",
"6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0\n",
"5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0\n",
"48 447\n14 9\n9 -17\n-17 11\n-14 14\n19 -8\n-14 -17\n-7 10\n-6 -11\n-9 -19\n19 10\n-4 2\n-5 16\n20 9\n-10 20\n-7 -17\n14 -16\n-2 -10\n-18 -17\n14 12\n-6 -19\n5 -18\n-3 2\n-3 10\n-5 5\n13 -1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eat... |
1323_B. Count Subrectangles_7249 | You are given an array a of length n and array b of length m both consisting of only integers 0 and 1. Consider a matrix c of size n × m formed by following rule: c_{i, j} = a_i ⋅ b_j (i.e. a_i multiplied by b_j). It's easy to see that c consists of only zeroes and ones too.
How many subrectangles of size (area) k con... | n, m, k = map(int, input().split())
def intervals(arr):
res = []
curr = 0
for e in arr:
if e == 1: ... | {
"input": [
"3 5 4\n1 1 1\n1 1 1 1 1\n",
"3 3 2\n1 0 1\n1 1 1\n",
"50 50 6\n1 0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 0 1\n1 1 0 1 0 1 1 0 1 1 1 1 1 1 0 1 1 0 1 0 0 1 1 1 1 0 0 1 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 0\n",
"1 1 1\n1\n1\n",
... | 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 of length n and array b of length m both consisting of only integers 0 and 1. Consider a matrix c of size n × m formed by following rule: c_{i, j} = a_i ⋅ b_j... |
1342_A. Road To Zero_7253 | You are given two integers x and y. You can perform two types of operations:
1. Pay a dollars and increase or decrease any of these integers by 1. For example, if x = 0 and y = 7 there are four possible outcomes after this operation:
* x = 0, y = 6;
* x = 0, y = 8;
* x = -1, y = 7;
* x = 1, y = ... | def to_list(s):
return list(map(lambda x: int(x), s.split(' ')))
def solve(x,y,a,b):
cost = 0
if b <= 2*a:
min_val = min(x,y)
cost += b*min_val
x -= min_val
y -= min_val
max_val = max(x,y)
cost += max_val*a
else:
cost = (x+y)*a
print(cost)
... | {
"input": [
"2\n1 3\n391 555\n0 0\n9 4\n",
"1\n129 8437\n5 3\n",
"3\n1 3\n391 555\n129 8437\n9 4\n321 654\n3 4\n",
"2\n1 3\n391 555\n129 8437\n9 4\n",
"1\n321 654\n3 4\n",
"1\n150 140\n1 1\n",
"1\n129 8437\n5 4\n",
"3\n1 6\n391 555\n129 8437\n9 4\n321 654\n3 4\n",
"2\n1 3\n391 555... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given two integers x and y. You can perform two types of operations:
1. Pay a dollars and increase or decrease any of these integers by 1. For example, if x = 0 and y = 7 ... |
1364_A. XXXXX_7257 | Ehab loves number theory, but for some reason he hates the number x. Given an array a, find the length of its longest subarray such that the sum of its elements isn't divisible by x, or determine that such subarray doesn't exist.
An array a is a subarray of an array b if a can be obtained from b by deletion of several... | t = int(input())
for tc in range(t):
n = int(input())
a = list(map(int, input().split()))
s = set(a)
print(len(s)) | {
"input": [
"3\n3 3\n1 2 3\n3 4\n1 2 3\n2 2\n0 6\n",
"2\n2\n1 1\n1\n1\n",
"2\n4\n1 3 3 3\n3\n1 2 3\n",
"1\n5\n1 3 4 5 2\n",
"2\n5\n1 2 3 4 5\n4\n2 3 4 5\n",
"2\n3\n3 2 1\n6\n3 1 4 1 5 9\n",
"1\n3\n1 1 274005660\n",
"2\n5\n5 5 5 5 5\n3\n1 2 5\n",
"4\n7\n6 6 8 8 6 6 6\n1\n2\n5\n4 5 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Ehab loves number theory, but for some reason he hates the number x. Given an array a, find the length of its longest subarray such that the sum of its elements isn't divisible by x, ... |
1384_B2. Koa and the Beach (Hard Version)_7261 | The only difference between easy and hard versions is on constraints. In this version constraints are higher. You can make hacks only if all versions of the problem are solved.
Koa the Koala is at the beach!
The beach consists (from left to right) of a shore, n+1 meters of sea and an island at n+1 meters from the sho... | import sys
import os,io
input = sys.stdin.readline
# input_all = sys.stdin.read
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
# input_all = io.BytesIO(os.read(0,os.fstat(0).st_size)).read
def read_int():
return map(int, input().split())
def read_list():
return list(map(int, input().split()))
def print... | {
"input": [
"7\n2 1 1\n1 0\n5 2 3\n1 2 3 2 2\n4 3 4\n0 2 4 3\n2 3 5\n3 0\n7 2 3\n3 0 2 1 3 0 1\n7 1 4\n4 4 3 0 2 4 2\n5 2 3\n1 2 3 2 2\n",
"10\n1 1 1\n1\n1 1 1\n0\n1 1 1\n2\n1 1 1\n3\n1 1 1\n4\n2 2 2\n2 3\n2 1 2\n1 1\n2 1 2\n0 0\n14 3 9\n1 3 2 3 3 2 4 2 1 3 6 7 10 1\n7 1 1\n1 1 1 1 1 1 1\n",
"1\n100 5 4\... | 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 on constraints. In this version constraints are higher. You can make hacks only if all versions of the problem are solved.
Koa t... |
1405_D. Tree Tag_7265 | Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of n vertices numbered from 1 to n. Recall that a tree on n vertices is an undirected, connected graph with n-1 edges.
Initially, Alice is located at vertex a, and Bob at vertex b. They take turns alternately, and Alice makes the first mov... | for t in range(int(input())):
n, a, b, da, db = map(int, input().split())
graph = [set() for i in range(n + 1)]
for i in range(n - 1):
u, v = map(int, input().split())
graph[u].add(v)
graph[v].add(u)
visited = {1}
last_visits = set()
visit_now = {1}
while len(visited) < n:
while visit_now:
i = visit... | {
"input": [
"4\n4 3 2 1 2\n1 2\n1 3\n1 4\n6 6 1 2 5\n1 2\n6 5\n2 3\n3 4\n4 5\n9 3 9 2 5\n1 2\n1 6\n1 9\n1 3\n9 5\n7 9\n4 8\n4 3\n11 8 11 3 3\n1 2\n11 9\n4 9\n6 5\n2 10\n3 2\n5 9\n8 3\n7 4\n7 10\n",
"1\n5 5 4 3 4\n1 2\n4 1\n5 1\n5 3\n",
"1\n9 1 5 3 7\n1 2\n2 3\n3 4\n4 5\n3 6\n7 8\n8 9\n6 7\n",
"10\n10... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of n vertices numbered from 1 to n. Recall that a tree on n vertices is an undirected, connected graph ... |
1426_F. Number of Subsequences_7269 | You are given a string s consisting of lowercase Latin letters "a", "b" and "c" and question marks "?".
Let the number of question marks in the string s be k. Let's replace each question mark with one of the letters "a", "b" and "c". Here we can obtain all 3^{k} possible strings consisting only of letters "a", "b" and... | n=int(input())
s=input()
a=[[0,0,0] for i in range(4)]
k=s.count('?')
b=[1]
for i in range(k):
b.append(b[i]*3%1000000007)
for i in range(n):
if s[i]=='a':
a[0][0]+=1
elif s[i]=='b':
a[0][1]+=a[0][0]
a[1][1]+=a[1][0]
elif s[i]=='c':
a[0][2]+=a[0][1]
a[1][2]+=a[1][... | {
"input": [
"9\ncccbbbaaa\n",
"7\n???????\n",
"5\na???c\n",
"6\nac?b?c\n",
"3\nabc\n",
"200\n???c????????ba?????c?b???c???a??a?b??bb?c???cccc?ac?????c??????b??c?aa?cb?ca?a??cc?b???a?c???c??bbb?cacbbac?ccc?a?aca??b??a??c?c?a??????b??a????baa?a?a?????a????bb??b?????ac?b?aacb??c????????a?c??????... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a string s consisting of lowercase Latin letters "a", "b" and "c" and question marks "?".
Let the number of question marks in the string s be k. Let's replace each ques... |
1473_E. Minimum Path_7275 | You are given a weighted undirected connected graph consisting of n vertices and m edges. It is guaranteed that there are no self-loops or multiple edges in the given graph.
Let's define the weight of the path consisting of k edges with indices e_1, e_2, ..., e_k as ∑_{i=1}^{k}{w_{e_i}} - max_{i=1}^{k}{w_{e_i}} + min_... | import io
import os
# import __pypy__
def dijkstra(*args):
# return dijkstraHeap(*args) # 2979 ms
return dijkstraHeapComparatorWrong(*args) # 2823 ms
# return dijkstraHeapComparator(*args) # 2370 ms
# return dijkstraSegTree(*args) # 2417 ms with inf=float('inf), 2995 ms with inf=-1
# return d... | {
"input": [
"7 10\n7 5 5\n2 3 3\n4 7 1\n5 3 6\n2 7 6\n6 2 6\n3 7 6\n4 2 1\n3 1 4\n1 7 4\n",
"5 4\n5 3 4\n2 1 1\n3 2 2\n2 4 2\n",
"6 8\n3 1 1\n3 6 2\n5 4 2\n4 2 2\n6 1 1\n5 2 1\n3 2 3\n1 5 4\n",
"13 37\n3 9 6\n8 7 1\n7 4 10\n10 2 8\n13 1 8\n9 8 1\n8 1 1\n5 1 8\n4 13 5\n5 12 1\n2 9 8\n3 8 5\n1 10 10\n1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a weighted undirected connected graph consisting of n vertices and m edges. It is guaranteed that there are no self-loops or multiple edges in the given graph.
Let's de... |
1521_E. Nastia and a Beautiful Matrix_7280 | You like numbers, don't you? Nastia has a lot of numbers and she wants to share them with you! Isn't it amazing?
Let a_i be how many numbers i (1 ≤ i ≤ k) you have.
An n × n matrix is called beautiful if it contains all the numbers you have, and for each 2 × 2 submatrix of the original matrix is satisfied:
1. The... | def cheak(x):
return x**2-(x//2)**2>=m and x*(x//2+(1 if x%2!=0 else 0))>=mx
for test in range(int(input())):
m,k=(int(i) for i in input().split())
a=[int(i) for i in input().split()]
mx=max(a)
z=0;y=m*4
while z!=y:
x=(z+y)//2
if cheak(x):
y=x
else:
... | {
"input": [
"2\n3 4\n2 0 0 1\n15 4\n2 4 8 1\n",
"1\n9 3\n1 0 8\n",
"1\n12 3\n9 2 1\n",
"2\n3 4\n2 0 0 1\n15 4\n2 4 8 1\n",
"1\n12 3\n9 0 2\n",
"1\n9 3\n2 0 8\n",
"2\n3 4\n2 0 0 1\n15 4\n2 3 8 1\n",
"1\n7 3\n1 0 8\n",
"2\n3 4\n2 0 0 1\n17 4\n2 4 8 1\n",
"1\n9 3\n2 1 8\n",
"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You like numbers, don't you? Nastia has a lot of numbers and she wants to share them with you! Isn't it amazing?
Let a_i be how many numbers i (1 ≤ i ≤ k) you have.
An n × n matrix ... |
1550_E. Stringforces_7283 | You are given a string s of length n. Each character is either one of the first k lowercase Latin letters or a question mark.
You are asked to replace every question mark with one of the first k lowercase Latin letters in such a way that the following value is maximized.
Let f_i be the maximum length substring of str... | import sys
input = sys.stdin.readline
n, k = map(int, input().split())
s = input()[:-1]
left, right = 0, n
while left < right:
mid = right - (right - left) // 2
A = [[0] * (n + 2) for _ in range(k)]
for c in range(k):
A[c][n] = A[c][n + 1] = n + 1
L = 0
for i in range(n - 1, -1, -1... | {
"input": [
"2 3\n??\n",
"10 2\na??ab????b\n",
"9 4\n?????????\n",
"4 4\ncabd\n",
"15 3\n??b?babbc??b?aa\n",
"8 2\naa??ba??\n",
"466 10\nhga??dfdgae??j?f???h?jdd?????dhgc???????bj?j????b?be?b?jedd??g?cg????bj?b?h?heg?cb?e??hgf???fcd?g??hf?a????ie???if?deibf?j?g??cea?????????f?i?geh??h??gb... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a string s of length n. Each character is either one of the first k lowercase Latin letters or a question mark.
You are asked to replace every question mark with one of... |
177_B1. Rectangular Game_7287 | The Smart Beaver from ABBYY decided to have a day off. But doing nothing the whole day turned out to be too boring, and he decided to play a game with pebbles. Initially, the Beaver has n pebbles. He arranges them in a equal rows, each row has b pebbles (a > 1). Note that the Beaver must use all the pebbles he has, i. ... | n=int(input())
r=n+1
i=2
s=n**0.5
while i<=s:
if n%i==0:
r+=n//i
n//=i
s=n**0.5
i=1
i+=1
print(r) | {
"input": [
"10\n",
"8\n",
"999161856\n",
"999999937\n",
"9\n",
"999936000\n",
"18\n",
"33\n",
"999999948\n",
"13\n",
"14\n",
"5\n",
"48\n",
"50\n",
"1000\n",
"999999000\n",
"39\n",
"999989760\n",
"998244352\n",
"1011\n",
"222953472\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The Smart Beaver from ABBYY decided to have a day off. But doing nothing the whole day turned out to be too boring, and he decided to play a game with pebbles. Initially, the Beaver h... |
221_A. Little Elephant and Function_7293 | The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows:
... | n=int(input())
l=list(range(1,n+1))
l=sorted(l)
l.insert(0,l[-1])
l.pop()
print(*l) | {
"input": [
"1\n",
"2\n",
"1000\n",
"683\n",
"998\n",
"195\n",
"811\n",
"419\n",
"6\n",
"67\n",
"875\n",
"25\n",
"999\n",
"101\n",
"7\n",
"971\n",
"683\n",
"875\n",
"4\n",
"5\n",
"971\n",
"291\n",
"101\n",
"24\n",
"99... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th elemen... |
245_B. Internet Address_7297 | Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format:
<protocol>://<domain>.ru[/<context>]
where:
* <protocol> can equal either "http" (without the quotes) or "ftp" (without the q... | s = input()
if s[:3] == "ftp":
pre = "ftp://"
s = s[3:]
elif s[:4] == "http":
pre = "http://"
s = s[4:]
index = s[1:].index("ru")+1
if index == len(s)-2:
s = pre+s[:index]+"."+s[index:]
else:
s = pre+s[:index]+"."+s[index:index+2]+"/"+s[index+2:]
print(s)
| {
"input": [
"httpsunrux\n",
"ftphttprururu\n",
"httpuurrruurruuruuruuurrrurururuurruuuuuuruurr\n",
"httpfttpftpfttftpftpftppfrurururu\n",
"ftptpruuhttpuhttphuhtuhtrurrutphttuhtuht\n",
"ftprftprupruftptprurururftprrftpftprurftprrftprup\n",
"httpftphttptphttphrururuhpftphtpftphtpftphtptpft\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has f... |
26_E. Multithreading_7300 | You are given the following concurrent program. There are N processes and the i-th process has the following pseudocode:
repeat ni times
yi := y
y := yi + 1
end repeat
Here y is a shared variable. Everything else is local for the process. All actions on a given row are a... | import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
n, w = map(int, input().split())
a = [0] + list(map(int, input().split()))
total = sum(a)
def ng():
print('No')
exit()
def ok(a):
print('Yes')
print(*a)
exit()
if w < 1 or t... | {
"input": [
"1 10\n11\n",
"2 3\n4 4\n",
"3 6\n1 2 3\n",
"5 1\n2 3 4 5 6\n",
"95 -200797120\n832 159 171 230 750 361 800 516 567 380 405 527 58 86 68 172 923 920 248 854 804 557 246 61 106 190 67 552 310 645 120 154 244 308 355 832 432 314 824 774 988 513 228 361 390 863 586 732 798 630 798 210 89... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given the following concurrent program. There are N processes and the i-th process has the following pseudocode:
repeat ni times
yi := y
y :... |
340_E. Iahub and Permutations_7308 | Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotage his research work.
The girl finds an important permutation for the resea... | #lahub and Permutations
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
mod = 10**9+7
def pow(n,p,mod=mod): #繰り返し二乗法(nのp乗)
res = 1
while p > 0:
if p % 2 == 0:
n = n ** 2 % mod
p //= 2
else:
res = res * n % mod
... | {
"input": [
"5\n-1 -1 4 3 -1\n",
"6\n-1 -1 -1 -1 -1 -1\n",
"7\n-1 -1 4 -1 7 1 6\n",
"10\n4 10 -1 1 6 8 9 2 -1 -1\n",
"8\n2 4 5 3 -1 8 -1 6\n",
"2\n-1 -1\n",
"20\n-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1\n",
"5\n-1 -1 4 1 -1\n",
"7\n-1 -1 4 -1 7 1 3\n",
"7\n-... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. ... |
388_A. Fox and Box Accumulation_7314 | Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For exampl... | I=lambda:list(map(int,input().split()))
n,=I()
l=I()
l.sort()
ans=0
i=0
k=1
while i<n:
if l[i]<i//k:
k+=1
i+=1
print(k)
| {
"input": [
"9\n0 1 0 2 0 1 1 2 10\n",
"5\n0 1 2 3 4\n",
"3\n0 0 10\n",
"4\n0 0 0 0\n",
"59\n61 33 84 76 56 47 70 94 46 77 95 85 35 90 83 62 48 74 36 74 83 97 62 92 95 75 70 82 94 67 82 42 78 70 50 73 80 76 94 83 96 80 80 88 91 79 83 54 38 90 33 93 53 33 86 95 48 34 46\n",
"18\n0 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:
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the stre... |
408_D. Long Path_7318 | One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one.
The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number i (... | n = int(input())
a = list(map(int,input().split()))
values = [0 for k in range(n)]
for k in range(n) :
back = a[k]
if a[k] == k+1 :
values[k] = 2
else :
values[k] += 2
for t in range(a[k]-1,k) :
values [k] += values[t]
values[k] %= int(1e9 +7)
print(in... | {
"input": [
"2\n1 2\n",
"5\n1 1 1 1 1\n",
"4\n1 1 2 3\n",
"3\n1 1 3\n",
"102\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 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 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\n",
"10\n1 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to ge... |
459_A. Pashmak and Garden_7324 | Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He al... | #!/usr/bin/env python3
import atexit
import io
import sys
import bisect
_I_B = sys.stdin.read().splitlines()
input = iter(_I_B).__next__
_O_B = io.StringIO()
sys.stdout = _O_B
@atexit.register
def write():
sys.__stdout__.write(_O_B.getvalue())
def main():
x1,y1,x2,y2=map(int,input().split())
if x1==x2:
... | {
"input": [
"0 0 1 2\n",
"0 0 0 1\n",
"0 0 1 1\n",
"0 1 3 1\n",
"66 -64 -25 -64\n",
"100 100 100 -100\n",
"-100 -100 100 100\n",
"-1 1 1 -1\n",
"0 1 1 0\n",
"2 8 7 3\n",
"1 3 3 1\n",
"51 -36 18 83\n",
"0 0 1 -1\n",
"1 0 0 1\n",
"6 85 -54 -84\n",
"-42 84... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak ... |
47_E. Cannon_7327 | Bertown is under siege! The attackers have blocked all the ways out and their cannon is bombarding the city. Fortunately, Berland intelligence managed to intercept the enemies' shooting plan. Let's introduce the Cartesian system of coordinates, the origin of which coincides with the cannon's position, the Ox axis is di... | import sys
from array import array # noqa: F401
from math import pi, sin, cos
from bisect import bisect_left
def input():
return sys.stdin.buffer.readline().decode('utf-8')
n, v = map(int, input().split())
v = float(v)
alpha = [float(input()) for _ in range(n)]
m = int(input())
wall = sorted(tuple(map(float, i... | {
"input": [
"2 10\n0.7853\n0.3\n2\n4.0 2.4\n6.0 1.9\n",
"2 10\n0.7853\n0.3\n3\n5.0 5.0\n4.0 2.4\n6.0 1.9\n",
"6 417\n0.0303\n0.7536\n0.7225\n0.2404\n0.2432\n0.4583\n3\n979.9372 477.1436\n469.9804 408.1158\n923.2564 220.5522\n",
"4 851\n0.3178\n0.5635\n0.1335\n0.5107\n4\n685.3785 249.6264\n681.8946 24... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Bertown is under siege! The attackers have blocked all the ways out and their cannon is bombarding the city. Fortunately, Berland intelligence managed to intercept the enemies' shooti... |
554_A. Kyoya and Photobooks_7335 | Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the pho... | s = input()
l = list(s)
a = 'abcdefghijklmnopqrstuvwxyz'
for i in range(len(s)+1):
for j in a:
l.insert(i, j)
print(len(l)-2*len(s)) | {
"input": [
"hi\n",
"a\n",
"lpfpndmjfvqejdgf\n",
"jgv\n",
"fykkiubdkt\n",
"ydzpjhsidipricw\n",
"gggggggggggggggggggg\n",
"kgan\n",
"lllllllllllllll\n",
"e\n",
"ofkvparuvjtggnmab\n",
"zv\n",
"xxncfutrtxcwdzwbgs\n",
"kskkskkkssksssk\n",
"coccoooogogcgocccmcg\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some ord... |
624_B. Making a String_7343 | You are given an alphabet consisting of n letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied:
* the i-th letter occurs in the string no more than ai times;
* the number of occurrences of each letter in the string must be distinct for all the lette... | n = int(input())
m = list(map(int, input().split()))
m.sort(reverse = True)
ans = m[0]
last = m[0]
for i in range(1, len(m)):
last = max(min(last - 1, m[i]), 0)
ans += last
print(ans) | {
"input": [
"3\n2 5 5\n",
"3\n1 1 2\n",
"26\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an alphabet consisting of n letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied:
* the i-th letter o... |
672_D. Robin Hood_7349 | We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor.
There are n citizens in Kekoland, each person has ci coins. Each day, Robin Hood will take exactly 1 coin from the richest person in the city and he will give it to t... | import sys
sys.stderr = sys.stdout
def hood(n, k, C):
C.sort()
m, r = divmod(sum(C), n)
m1 = (m + 1) if r else m
c_lo = C[0]
k_lo = k
for i, c in enumerate(C):
if c_lo == m:
break
c_m = min(c, m)
dc = c_m - c_lo
dk = i * dc
if k_lo >= dk:
... | {
"input": [
"4 1\n1 1 4 2\n",
"3 1\n2 2 2\n",
"10 1000000\n307196 650096 355966 710719 99165 959865 500346 677478 614586 6538\n",
"4 0\n1 4 4 4\n",
"3 4\n1 2 7\n",
"10 20\n6 4 7 10 4 5 5 3 7 10\n",
"2 0\n182 2\n",
"4 100\n1 1 10 10\n",
"4 42\n1 1 1 1000000000\n",
"123 54564\n3... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor.
There are n citizens in Kekol... |
763_B. Timofey and rectangles_7360 | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 different... | n = int(input())
coordinates = []
for i in range(n):
coordinates.append([int(x) % 2 for x in input().split()])
print('YES')
for coordinate in coordinates:
x1, y1, x2, y2 = coordinate
print(2*x2 + y2 + 1)
| {
"input": [
"8\n0 0 5 3\n2 -1 5 0\n-3 -4 2 -1\n-1 -1 2 0\n-3 0 0 5\n5 2 10 3\n7 -3 10 2\n4 -2 7 -1\n",
"25\n0 0 7 7\n0 18 7 29\n7 36 12 41\n7 18 12 29\n15 29 26 36\n7 7 12 18\n12 36 15 41\n15 7 26 18\n12 0 15 7\n12 7 15 18\n7 29 12 36\n12 29 15 36\n15 18 26 29\n26 18 27 29\n12 18 15 29\n26 29 27 36\n0 7 7 18... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rec... |
808_C. Tea Party_7365 | Polycarp invited all his friends to the tea party to celebrate the holiday. He has n cups, one for each of his n friends, with volumes a1, a2, ..., an. His teapot stores w milliliters of tea (w ≤ a1 + a2 + ... + an). Polycarp wants to pour tea in cups in such a way that:
* Every cup will contain tea for at least hal... | import math
import re
n, w = map(int, input().split())
a = list(map(int, input().split()))
a1 = [math.ceil(el/2) for el in a]
s = w - sum(a1)
if s < 0:
print(-1)
elif s == 0:
print(' '.join(map(str, a1)))
else:
for i in range(n):
if a[i] == 1:
a1[i] = 0
a[i] = 0
a2 =... | {
"input": [
"2 10\n8 7\n",
"3 10\n9 8 10\n",
"4 4\n1 1 1 1\n",
"50 1113\n25 21 23 37 28 23 19 25 5 12 3 11 46 50 13 50 7 1 8 40 4 6 34 27 11 39 45 31 10 12 48 2 19 37 47 45 30 24 21 42 36 14 31 30 31 50 6 3 33 49\n",
"11 287\n34 30 69 86 22 53 11 91 62 44 5\n",
"10 21\n3 3 3 3 4 3 3 3 3 3\n",... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarp invited all his friends to the tea party to celebrate the holiday. He has n cups, one for each of his n friends, with volumes a1, a2, ..., an. His teapot stores w milliliters... |
832_D. Misha, Grisha and Underground_7368 | Misha and Grisha are funny boys, so they like to use new underground. The underground has n stations connected with n - 1 routes so that each route connects two stations, and it is possible to reach every station from any other.
The boys decided to have fun and came up with a plan. Namely, in some day in the morning M... | import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
from collections import defaultdict
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" ... | {
"input": [
"3 2\n1 1\n1 2 3\n2 3 3\n",
"4 1\n1 2 3\n1 2 3\n",
"5 20\n5 5 1 4\n1 4 3\n2 4 1\n1 5 5\n5 1 4\n5 1 5\n1 5 5\n5 4 4\n2 3 3\n4 4 1\n1 4 1\n4 5 4\n1 4 5\n4 1 5\n2 4 2\n4 3 3\n2 5 5\n1 5 4\n3 3 4\n5 5 1\n3 4 1\n",
"2 4\n1\n1 1 1\n1 1 2\n1 2 2\n2 2 2\n",
"5 20\n4 1 1 4\n2 2 5\n3 2 5\n2 3 4... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Misha and Grisha are funny boys, so they like to use new underground. The underground has n stations connected with n - 1 routes so that each route connects two stations, and it is po... |
853_B. Jury Meeting_7371 | Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the olympiad should meet together in Metropolis (the capital of the country) for the problem preparation process.
There are n + 1 cities consecutively numbered from 0 to n. City 0 is Metropolis that is the meeting point for... | from bisect import *
from sys import *
n,m,k=[int(i) for i in input().split()]
pln=[]
if m==0:
print(-1)
exit(0)
for i in range(m):
pln.append([int(i) for i in input().split()])
pln.sort()
grp=[[pln[0]]];gt=0;
for i in range(1,m):
if pln[i][0]!=pln[i-1][0]:
gt=gt+1
grp.append([])
gr... | {
"input": [
"2 4 5\n1 2 0 5000\n2 1 0 4500\n2 1 0 3000\n8 0 1 6000\n",
"2 6 5\n1 1 0 5000\n3 2 0 5500\n2 2 0 6000\n15 0 2 9000\n9 0 1 7000\n8 0 2 6500\n",
"7 10 1\n369 6 0 9\n86 7 0 9\n696 0 4 8\n953 6 0 7\n280 4 0 9\n244 0 2 9\n645 6 0 8\n598 7 0 6\n598 0 7 8\n358 0 4 6\n",
"2 5 5\n1 1 0 1\n2 2 0 10... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the olympiad should meet together in Metropolis (the capital of the country) for the pr... |
877_F. Ann and Books_7374 | In Ann's favorite book shop are as many as n books on math and economics. Books are numbered from 1 to n. Each of them contains non-negative number of problems.
Today there is a sale: any subsegment of a segment from l to r can be bought at a fixed price.
Ann decided that she wants to buy such non-empty subsegment t... | # ------------------- 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.... | {
"input": [
"4 1\n1 1 1 2\n1 1 1 1\n4\n1 2\n1 3\n1 4\n3 4\n",
"4 0\n1 2 1 2\n0 0 0 0\n1\n1 4\n",
"2 0\n1 2\n43 43\n3\n1 2\n2 2\n1 1\n",
"10 -10\n1 2 1 2 1 1 2 2 2 1\n7 7 10 3 7 10 6 8 0 1\n10\n2 6\n10 10\n6 9\n5 8\n7 10\n2 7\n2 9\n2 7\n5 6\n2 8\n",
"10 10\n1 1 1 1 1 2 1 2 1 2\n7 10 2 5 0 1 8 10 1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In Ann's favorite book shop are as many as n books on math and economics. Books are numbered from 1 to n. Each of them contains non-negative number of problems.
Today there is a sale... |
901_B. GCD of Polynomials_7378 | Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the remainder o... | """
NTC here
"""
import sys
inp= sys.stdin.readline
input = lambda : inp().strip()
flush= sys.stdout.flush
# import threading
# sys.setrecursionlimit(10**6)
# threading.stack_size(2**25)
def iin(): return int(input())
def lin(): return list(map(int, input().split()))
# range = xrange
# input = raw_input
def main():... | {
"input": [
"1\n",
"2\n",
"70\n",
"64\n",
"102\n",
"141\n",
"43\n",
"36\n",
"91\n",
"50\n",
"77\n",
"135\n",
"44\n",
"59\n",
"20\n",
"14\n",
"57\n",
"34\n",
"13\n",
"118\n",
"101\n",
"96\n",
"6\n",
"72\n",
"84\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https:... |
952_A. Quirky Quantifiers_7384 |
Input
The input contains a single integer a (10 ≤ a ≤ 999).
Output
Output 0 or 1.
Examples
Input
13
Output
1
Input
927
Output
1
Input
48
Output
0 | b=int(input())
if b%2==0:
print(0)
else:
print(1) | {
"input": [
"13\n",
"48\n",
"927\n",
"758\n",
"496\n",
"957\n",
"835\n",
"932\n",
"572\n",
"329\n",
"694\n",
"207\n",
"429\n",
"583\n",
"309\n",
"636\n",
"470\n",
"168\n",
"550\n",
"10\n",
"990\n",
"999\n",
"288\n",
"431\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Input
The input contains a single integer a (10 ≤ a ≤ 999).
Output
Output 0 or 1.
Examples
Input
13
Output
1
Input
927
Output
1
Input
48
Output
0
### Input:
13... |
979_C. Kuro and Walking Route_7388 | Kuro is living in a country called Uberland, consisting of n towns, numbered from 1 to n, and n - 1 bidirectional roads connecting these towns. It is possible to reach each town from any other. Each road connects two towns a and b. Kuro loves walking and he is planning to take a walking marathon, in which he will choos... |
def calculate_max_paths(edges, node, dest, par, cnt):
ans = 1
for child in edges.get(node, []):
if child != par:
ans += calculate_max_paths(edges, child, dest, node, cnt)
if dest == node:
cnt[0] = ans
return ans
def main():
from collections import defaultdict
... | {
"input": [
"3 1 3\n1 2\n2 3\n",
"3 1 3\n1 2\n1 3\n",
"31 29 20\n29 23\n29 18\n22 14\n29 20\n1 21\n29 10\n28 2\n1 17\n17 15\n1 11\n29 31\n28 6\n12 29\n12 26\n1 13\n22 4\n29 25\n28 22\n17 5\n28 30\n20 27\n29 8\n12 28\n1 12\n12 24\n22 7\n12 16\n12 3\n28 9\n1 19\n",
"8 5 1\n5 8\n1 5\n1 3\n1 4\n5 6\n6 7\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Kuro is living in a country called Uberland, consisting of n towns, numbered from 1 to n, and n - 1 bidirectional roads connecting these towns. It is possible to reach each town from ... |
999_D. Equalize the Remainders_7392 | You are given an array consisting of n integers a_1, a_2, ..., a_n, and a positive integer m. It is guaranteed that m is a divisor of n.
In a single move, you can choose any position i between 1 and n and increase a_i by 1.
Let's calculate c_r (0 ≤ r ≤ m-1) — the number of elements having remainder r when divided by ... | from collections import deque
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
a = list(map(int, input().split()))
cnt = [0] * m
x = [[] for _ in range(m)]
for i in range(n):
ai = a[i] % m
cnt[ai] += 1
x[ai].append(i)
l = n // m
q = deque()
for i in range(m):
if cnt[i] < l:
... | {
"input": [
"4 2\n0 1 2 3\n",
"6 3\n3 2 0 6 10 12\n",
"100 25\n6745 2075 7499 7517 1776 5164 2335 2745 4465 1457 7565 2232 2486 9025 8059 9646 8017 7662 9690 3352 2306 366 7422 1073 7169 8966 4506 8225 5614 8628 2908 7452 9625 9332 7097 353 1043 8118 5794 4486 626 971 6731 6618 887 6354 4814 7307 7681 61... | 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 consisting of n integers a_1, a_2, ..., a_n, and a positive integer m. It is guaranteed that m is a divisor of n.
In a single move, you can choose any position... |
p02534 ACL Beginner Contest - Repeat ACL_7405 | You are given an integer K. Print the string obtained by repeating the string `ACL` K times and concatenating them.
For example, if K = 3, print `ACLACLACL`.
Constraints
* 1 \leq K \leq 5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
K
Output
Print the s... | K=int(input())
print("ACL"*K) | {
"input": [
"3",
"4",
"6",
"5",
"10",
"8",
"7",
"9",
"2",
"13",
"1",
"20",
"15",
"16",
"17",
"19",
"24",
"11",
"26",
"27",
"47",
"61",
"115",
"58",
"14",
"22",
"18",
"38",
"46",
"60",
"82",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an integer K. Print the string obtained by repeating the string `ACL` K times and concatenating them.
For example, if K = 3, print `ACLACLACL`.
Constraints
* 1 \leq K... |
p02666 NOMURA Programming Competition 2020 - Urban Planning_7408 | There are N towns numbered 1, 2, \cdots, N.
Some roads are planned to be built so that each of them connects two distinct towns bidirectionally. Currently, there are no roads connecting towns.
In the planning of construction, each town chooses one town different from itself and requests the following: roads are built... | def modfac(n, MOD):
f = 1
factorials = [1]
for m in range(1, n + 1):
f *= m
f %= MOD
factorials.append(f)
inv = pow(f, MOD - 2, MOD)
invs = [1] * (n + 1)
invs[n] = inv
for m in range(n, 1, -1):
inv *= m
inv %= MOD
invs[m - 1] = inv
return... | {
"input": [
"4\n2 1 -1 3",
"2\n2 1",
"10\n2 6 9 -1 6 9 -1 -1 -1 -1",
"4\n2 1 -1 2",
"2\n1 1",
"10\n2 6 9 -1 7 9 -1 -1 -1 -1",
"4\n2 2 -1 3",
"10\n2 9 5 -1 7 9 -1 -1 -1 -1",
"2\n1 2",
"4\n1 1 -1 4",
"4\n2 3 -1 4",
"10\n2 9 5 -1 6 9 -1 -1 -1 -1",
"4\n1 2 -1 4",
"... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are N towns numbered 1, 2, \cdots, N.
Some roads are planned to be built so that each of them connects two distinct towns bidirectionally. Currently, there are no roads connect... |
p02795 Keyence Programming Contest 2020 - Painting_7412 | We have a grid with H rows and W columns, where all the squares are initially white.
You will perform some number of painting operations on the grid. In one operation, you can do one of the following two actions:
* Choose one row, then paint all the squares in that row black.
* Choose one column, then paint all the s... | h = int(input())
w = int(input())
n = int(input())
print(min([(n+h-1)//h, (n+w-1)//w])) | {
"input": [
"3\n7\n10",
"2\n100\n200",
"14\n12\n112",
"3\n7\n15",
"2\n000\n200",
"14\n12\n47",
"2\n000\n217",
"3\n7\n45",
"14\n16\n2",
"3\n7\n76",
"2\n000\n4",
"3\n10\n43",
"14\n12\n183",
"2\n000\n311",
"2\n000\n17",
"3\n7\n54",
"3\n0\n76",
"3\n... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We have a grid with H rows and W columns, where all the squares are initially white.
You will perform some number of painting operations on the grid. In one operation, you can do one... |
p02931 Japanese Student Championship 2019 Qualification - Card Collector_7416 | There are N cards placed on a grid with H rows and W columns of squares.
The i-th card has an integer A_i written on it, and it is placed on the square at the R_i-th row from the top and the C_i-th column from the left.
Multiple cards may be placed on the same square.
You will first pick up at most one card from eac... | import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
N,H,W = map(int,readline().split())
RCA = [tuple(int(x) for x in line.split()) for line in readlines()]
RCA.sort(key = lambda x: -x[2])
RCA
root = list(range(H+W))
size = [0] * (H+W)
no_cycle = [Tru... | {
"input": [
"1 100000 100000\n1 1 1",
"13 5 6\n1 3 35902\n4 6 19698\n4 6 73389\n3 6 3031\n3 1 4771\n1 4 4784\n2 1 36357\n2 1 24830\n5 6 50219\n4 6 22645\n1 2 30739\n1 4 68417\n1 5 78537",
"6 2 2\n2 2 2\n1 1 8\n1 1 5\n1 2 9\n1 2 7\n2 1 4",
"13 5 6\n1 3 35902\n4 6 19698\n4 6 73389\n3 6 3031\n3 1 4771\n... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are N cards placed on a grid with H rows and W columns of squares.
The i-th card has an integer A_i written on it, and it is placed on the square at the R_i-th row from the top... |
p03067 Tenka1 Programmer Beginner Contest 2019 - On the Way_7420 | There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Constraints
* 0\leq A,B,C\leq 100
* A, B and C are distinct integers.
I... | a, b, c = map(int, input().split())
if (c-a)*(c-b) < 0:
print("Yes")
else:
print("No") | {
"input": [
"10 2 4",
"7 3 1",
"31 41 59",
"3 8 5",
"8 2 4",
"3 3 1",
"31 61 59",
"3 8 7",
"1 2 4",
"4 3 1",
"31 49 59",
"6 8 7",
"1 0 4",
"4 2 1",
"39 49 59",
"4 8 7",
"1 -1 4",
"39 49 10",
"4 4 7",
"1 -1 2",
"51 49 10",
"4 4 0"... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1... |
p03210 AtCoder Beginner Contest 114 - 753_7424 | Shichi-Go-San (literally "Seven-Five-Three") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children.
Takahashi is now X years old. Will his growth be celebrated in Shichi-Go-San this time?
Constraints
* 1 ≤ X ≤ 9
* X is an integer.
Input
Input is given from... | a=int(input())
print('YES' if a in [3,5,7] else 'NO') | {
"input": [
"6",
"5",
"11",
"7",
"16",
"3",
"19",
"4",
"12",
"0",
"9",
"1",
"13",
"-1",
"8",
"-2",
"2",
"-3",
"-5",
"-6",
"-9",
"-12",
"-11",
"-4",
"14",
"-7",
"-20",
"22",
"10",
"15",
"-8",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Shichi-Go-San (literally "Seven-Five-Three") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children.
Takahashi is now X year... |
p03359 AtCoder Beginner Contest 096 - Day of Takahashi_7428 | In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year.
For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year.
In this country, a date is called Takahashi when the month and the day are equal as numbers. For exam... | a, b = map(int, input().split())
print(a if (a <= b) else a - 1)
| {
"input": [
"11 30",
"2 1",
"5 5",
"1 30",
"9 5",
"4 0",
"6 5",
"2 50",
"8 5",
"0 50",
"11 5",
"16 3",
"10 -1",
"23 3",
"12 6",
"12 12",
"0 -3",
"-2 1",
"-3 0",
"-5 0",
"5 2",
"-4 1",
"-9 1",
"-16 1",
"-11 0",
"-1... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year.
For example, May 3, 2018 is written as ... |
p03517 CODE FESTIVAL 2017 Elimination Tournament Round 2 (Parallel) - Colorful MST_7431 | Ringo has an undirected graph G with N vertices numbered 1,2,...,N and M edges numbered 1,2,...,M. Edge i connects Vertex a_{i} and b_{i} and has a length of w_i.
Now, he is in the middle of painting these N vertices in K colors numbered 1,2,...,K. Vertex i is already painted in Color c_i, except when c_i = 0, in whic... | class Unionfindtree:
def __init__(self, number):
self.par = [i for i in range(number)]
self.rank = [0] * (number)
def find(self, x): # 親を探す
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def u... | {
"input": [
"4 3 3\n1 0 1 2\n1 2 10\n2 3 20\n2 4 50",
"18 37 12\n5 0 4 10 8 7 2 10 6 0 9 12 12 11 11 11 0 1\n17 1 1\n11 16 7575\n11 15 9\n10 10 289938980\n5 10 17376\n18 4 1866625\n8 11 959154208\n18 13 200\n16 13 2\n2 7 982223\n12 12 9331\n13 12 8861390\n14 13 743\n2 10 162440\n2 4 981849\n7 9 1\n14 17 2800... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Ringo has an undirected graph G with N vertices numbered 1,2,...,N and M edges numbered 1,2,...,M. Edge i connects Vertex a_{i} and b_{i} and has a length of w_i.
Now, he is in the m... |
p03680 AtCoder Beginner Contest 065 - Trained?_7435 | Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It ... | n=int(input())
l=[int(input()) for i in range(n)]
a=1
ans=0
while a!=2:
a=l[a-1]
ans+=1
if ans==n+1:
ans=-1
break
print(ans)
| {
"input": [
"3\n3\n1\n2",
"5\n3\n3\n4\n2\n4",
"4\n3\n4\n1\n2",
"3\n3\n1\n3",
"5\n3\n3\n5\n2\n4",
"4\n4\n3\n1\n2",
"3\n2\n2\n1",
"5\n3\n0\n4\n2\n4",
"4\n3\n3\n1\n2",
"3\n3\n2\n3",
"4\n4\n3\n0\n2",
"4\n4\n4\n0\n2",
"4\n4\n7\n0\n2",
"3\n1\n2\n6",
"5\n1\n3\n5\n... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are... |
p03835 AtCoder Beginner Contest 051 - Sum of Three Integers_7439 | You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
Constraints
* 2≤K≤2500
* 0≤S≤3K
* K and S are integers.
Input
The input is given from Standard Input in the following for... | k,s=map(int,input().split());r=range;print(sum(1for x in r(k+1)for y in r(k+1)if 0<=s-x-y<=k)) | {
"input": [
"2 2",
"5 15",
"3 2",
"5 7",
"3 3",
"4 7",
"3 4",
"1 7",
"2 5",
"4 0",
"6 7",
"17 4",
"5 5",
"5 9",
"2 3",
"6 9",
"12 9",
"7 9",
"11 12",
"82 7",
"10 6",
"21 10",
"24 13",
"12 8",
"12 13",
"7 13",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +... |
p04000 AtCoder Beginner Contest 045 - Snuke's Coloring_7443 | We have a grid with H rows and W columns. At first, all cells were painted white.
Snuke painted N of these cells. The i-th ( 1 \leq i \leq N ) cell he painted is the cell at the a_i-th row and b_i-th column.
Compute the following:
* For each integer j ( 0 \leq j \leq 9 ), how many subrectangles of size 3×3 of the gr... | from collections import defaultdict
H,W,N=map(int,input().split())
ans=[(H-2)*(W-2)]+[0]*9
blacks=defaultdict(int)
for i in range(N):
a, b = map(int,input().split())
for dx in [-1,0,1]:
for dy in [-1,0,1]:
if 2<=a+dx<H and 2<=b+dy<W:
ans[blacks[(a+dx,b+dy)]]-=1
ans[blacks[(a+dx,b+dy)]+1]+... | {
"input": [
"1000000000 1000000000 0",
"4 5 8\n1 1\n1 4\n1 5\n2 3\n3 1\n3 2\n3 4\n4 4",
"10 10 20\n1 1\n1 4\n1 9\n2 5\n3 10\n4 2\n4 7\n5 9\n6 4\n6 6\n6 7\n7 1\n7 3\n7 7\n8 1\n8 5\n8 10\n9 2\n10 4\n10 9",
"1000000000 1000000001 0",
"4 5 8\n1 1\n1 4\n0 5\n2 3\n3 1\n3 2\n3 4\n4 4",
"10 10 20\n1 ... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We have a grid with H rows and W columns. At first, all cells were painted white.
Snuke painted N of these cells. The i-th ( 1 \leq i \leq N ) cell he painted is the cell at the a_i-... |
p00088 The Code A Doctor Loved_7447 | Dr .: Peter, I've finally done it.
Peter: What's wrong, Dr. David? Is it a silly invention again?
Dr .: This table, this table.
| Character | Sign
--- | ---
(Blank) | 101
'| 000000
, | 000011
-| 10010001
. | 010001
? | 000001
A | 100101
B | 10011010
| Character | Sign
--- | ---
C | 0101
D | 0001
E | 110
F | 01001
G |... | # Aizu Problem 0088: The Code A Doctor Loved
#
import sys, math, os
# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
sys.stdin = open("sample-input.txt", "rt")
def bin5(k):
b = bin(k)[2:]
while len(b) < 5:
b = '0' + b
return b
CODE1 = {' ': '101', "'": '000000', ",": '000011'... | {
"input": [
"PETER POTTER",
"PETER POTTRE",
"RETEP POTTRE",
"RETEP PNTTRE",
"REETP PNTTRE",
"REETP PMTTRE",
"RETEP PMTTRE",
"RETEP PRTTME",
"RETEP TRTPME",
"EETRP TRTPME",
"EETRP TRTPNE",
"EETRP ENPTRT",
"PRTEE ENPTRT",
"PRTEE TRTPNE",
"PRTEE TRSPNE",
"... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Dr .: Peter, I've finally done it.
Peter: What's wrong, Dr. David? Is it a silly invention again?
Dr .: This table, this table.
| Character | Sign
--- | ---
(Blank) | 101
'| 000000
... |
p00220 Binary Digit A Doctor Loved_7451 | "What are your shoe sizes?"
Suddenly, the doctor asked me when I met him for the first time.
"It's 23.5"
"Oh, that's a really nice number. It's 2 to the 4th power plus 2 to the 2nd power, 2 to the 1st power, 2 to the 0th power, and 2 to the 1st power."
Then the doctor asked.
"You, how tall are you?"
"Yes, it's 158.... | def ans(N): # N:foat
n=int(N)
d=N-n
ans_l=bin(n)[2:]
ans_r=''
for _ in range(4):
ans_r+=str(int(d*2))
d=d*2-int(d*2)
if n>=256 or d!=0:
return 'NA'
else:
return '0'*(8-len(ans_l))+ans_l+'.'+ans_r
while True:
INP=float(input())
if INP<0: break
prin... | {
"input": [
"23.5\n158.1\n-1.0",
"23.72975180461117\n158.1\n-1.0",
"23.5\n158.1\n-0.5246083014985048",
"23.72975180461117\n158.1\n-0.5449258499657357",
"24.206542817215936\n158.1\n-1.0",
"24.615346202775605\n158.1\n-1.0",
"23.72975180461117\n158.6852941341954\n-0.5449258499657357",
"2... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
"What are your shoe sizes?"
Suddenly, the doctor asked me when I met him for the first time.
"It's 23.5"
"Oh, that's a really nice number. It's 2 to the 4th power plus 2 to the 2nd ... |
p00382 Taxi_7454 | PCK Taxi in Aizu city, owned by PCK company, has adopted a unique billing system: the user can decide the taxi fare. Today as usual, many people are waiting in a queue at the taxi stand in front of the station.
In front of the station, there are $N$ parking spaces in row for PCK taxis, each with an index running from ... | from heapq import heappush, heappop
def main():
n = int(input())
que = []
for i in range(n):
lst = sorted(list(map(int, input().split()))[1:], reverse=True)[:i+1]
heappush(que, lst[-1])
for v in lst[:-1]:
heappush(que, v)
heappop(que)
print(sum(que))
main()
| {
"input": [
"3\n3 8 10 1\n4 7 1 2 15\n3 11 8 19",
"3\n3 8 10 1\n4 7 1 4 15\n3 11 8 19",
"3\n3 8 10 0\n2 7 1 4 15\n3 11 8 19",
"3\n3 8 10 0\n4 7 2 4 4\n3 11 8 19",
"3\n3 2 10 1\n4 7 2 4 15\n3 11 13 19",
"3\n3 8 9 0\n2 7 1 4 15\n2 11 1 19",
"3\n3 8 5 1\n2 6 1 4 15\n3 11 8 15",
"3\n6 8 1... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
PCK Taxi in Aizu city, owned by PCK company, has adopted a unique billing system: the user can decide the taxi fare. Today as usual, many people are waiting in a queue at the taxi sta... |
p00598 Operations with Finite Sets_7457 | Let A, B, C, D, E be sets of integers and let U is a universal set that includes all sets under consideration. All elements in any set are different (no repetitions).
u - union of two sets, AuB = {x ∈ U : x ∈ A or x ∈ B} is the set of all elements which belong to A or B.
i - intersection of two sets, AiB = {x ∈ U : x... | import sys
def rpn(str):
r = []
stack = []
for i in range(0, len(str)):
c = str[i]
if c in "idsu":
while len(stack) > 0:
if stack[-1] in "idsuc":
a = stack.pop()
r.extend(a)
else:
break
... | {
"input": [
"A 3\n1 3 -1\nB 4\n3 1 5 7\nD 1\n5\nR 0\ncAiBdD\nC 3\n1 2 3\nA 4\n2 10 8 3\nB 3\n2 4 8\nR 0\n(As(AiB))uC",
"A 3\n1 3 -1\nB 4\n3 1 5 7\nD 1\n5\nR 0\ncAiBdD\nC 3\n1 2 3\nA 4\n2 9 8 3\nB 3\n2 4 8\nR 0\n(As(AiB))uC",
"A 3\n1 3 -1\nB 4\n3 1 5 7\nD 1\n5\nR 0\ncAiBdD\nC 3\n1 2 3\nA 4\n2 10 8 3\nB 3\... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Let A, B, C, D, E be sets of integers and let U is a universal set that includes all sets under consideration. All elements in any set are different (no repetitions).
u - union of tw... |
p00734 Equal Total Scores_7461 | Taro and Hanako have numbers of cards in their hands. Each of the cards has a score on it. Taro and Hanako wish to make the total scores of their cards equal by exchanging one card in one's hand with one card in the other's hand. Which of the cards should be exchanged with which?
Note that they have to exchange their ... | while True:
n,m = map(int,input().split())
if n == 0:
exit()
t = []
h = []
ans = []
for i in range(n):
t.append(int(input()))
for i in range(m):
h.append(int(input()))
for i in range(n):
for j in range(m):
if (sum(t) - t[i] + h[j]) == (sum(h) -... | {
"input": [
"2 2\n1\n5\n3\n7\n6 5\n3\n9\n5\n2\n3\n3\n12\n2\n7\n3\n5\n4 5\n10\n0\n3\n8\n1\n9\n6\n0\n6\n7 4\n1\n1\n2\n1\n2\n1\n4\n2\n3\n4\n3\n2 3\n1\n1\n2\n2\n2\n0 0",
"2 2\n1\n5\n4\n7\n6 5\n3\n9\n5\n2\n3\n3\n12\n2\n7\n3\n5\n4 5\n10\n0\n3\n8\n1\n9\n6\n0\n6\n7 4\n1\n1\n2\n1\n2\n1\n4\n2\n3\n4\n3\n2 3\n1\n1\n2\n2... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Taro and Hanako have numbers of cards in their hands. Each of the cards has a score on it. Taro and Hanako wish to make the total scores of their cards equal by exchanging one card in... |
p00874 Cubist Artwork_7465 | International Center for Picassonian Cubism is a Spanish national museum of cubist artworks, dedicated to Pablo Picasso. The center held a competition for an artwork that will be displayed in front of the facade of the museum building. The artwork is a collection of cubes that are piled up on the ground and is intended... |
while True:
w,d = map(int,input().split())
if w == 0 and d == 0:
break
h = list(map(int,input().split()))
m = list(map(int,input().split()))
hl = [0] * 30
ml = [0] * 30
for i in h:
hl[i] += 1
for i in m:
ml[i] += 1
ans = 0
for i in range(30):
... | {
"input": [
"5 5\n1 2 3 4 5\n1 2 3 4 5\n5 5\n2 5 4 1 3\n4 1 5 3 2\n5 5\n1 2 3 4 5\n3 3 3 4 5\n3 3\n7 7 7\n7 7 7\n3 3\n4 4 4\n4 3 4\n4 3\n4 2 2 4\n4 2 1\n4 4\n2 8 8 8\n2 3 8 3\n10 10\n9 9 9 9 9 9 9 9 9 9\n9 9 9 9 9 9 9 9 9 9\n10 9\n20 1 20 20 20 20 20 18 20 20\n20 20 20 20 7 20 20 20 20\n0 0",
"5 5\n1 2 3 4 5... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
International Center for Picassonian Cubism is a Spanish national museum of cubist artworks, dedicated to Pablo Picasso. The center held a competition for an artwork that will be disp... |
p01137 Space Coconut Grab_7470 | Space Coconut Crab
Space coconut crab
English text is not available in this practice contest.
Ken Marine Blue is a space hunter who travels through the entire galaxy in search of space coconut crabs. The space coconut crab is the largest crustacean in the universe, and it is said that the body length after growth is... | import math
def solve(e):
k = 2 ** 32
for z in range(100, -1, -1):
z3 = z * z * z
if z3 > e:
continue
e2 = e - z3
ylm = int(math.sqrt(e2))
xzlm = 3 * z * z + 3 * z + 1
for y in range(ylm, -1, -1):
y2 = y * y
if e2 > (y + 1) ... | {
"input": [
"1\n2\n4\n27\n300\n1250\n0",
"1\n2\n4\n6\n300\n1250\n0",
"1\n2\n4\n2\n300\n1250\n0",
"1\n2\n4\n3\n300\n1250\n0",
"1\n2\n4\n3\n76\n1250\n0",
"1\n2\n4\n27\n557\n1250\n0",
"1\n2\n4\n6\n300\n1687\n0",
"1\n1\n4\n2\n300\n1250\n0",
"1\n2\n5\n3\n300\n1250\n0",
"1\n2\n3\n3\... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Space Coconut Crab
Space coconut crab
English text is not available in this practice contest.
Ken Marine Blue is a space hunter who travels through the entire galaxy in search of s... |
p01752 Prowler_7476 | Mr. A and Mr. B live in an N × M rectangular grid area. Each square is either a road, a wall, or a house. Since this area is famous for the frequent occurrence of molestation damage due to the complicated and intricate roads, the boundary between this area and the outside is completely surrounded by walls and isolated.... | 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": [
"4 4\n....\n.#.G\n...#\n^#..",
"3 3\n...\n.G.\n.>.",
"3 3\nG##\n.#.\n.",
"3 3\nG##\n.#.\n.>.",
"3 3\nG##\n.#.\n.<.",
"4 4\n....\n.#.G\n...#\n..#^",
"3 3\nG##\n.#-\n.>.",
"3 3\n##G\n.#-\n.>.",
"4 4\n....\n.#.G\n-..#\n^#..",
"3 3\n##G\n#..\n<..",
"4 4\n./..\n.#.G... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Mr. A and Mr. B live in an N × M rectangular grid area. Each square is either a road, a wall, or a house. Since this area is famous for the frequent occurrence of molestation damage d... |
p01892 SNS_7478 | Problem statement
AOR Ika-chan is in a bad mood lately. Apparently, I don't like the ratio of the number of followers to the number of followers of "Ikatta". Currently, AOR Ika-chan has $ A $ followers, $ B $ followers, and a ratio of $ A: B $.
Therefore, AOR Ika decided to increase or decrease the number of follower... | a, b, n = map(int, input().split())
score = abs(a - b)
for x in range(1, n + 1):
for y in range(1, n + 1):
if b * x % y == 0:
new_a = b * x // y
score = min(score, abs(a - new_a))
print(score)
| {
"input": [
"19 30 3",
"19 28 3",
"19 51 3",
"19 51 1",
"30 51 1",
"30 33 1",
"30 7 1",
"37 7 1",
"19 30 2",
"32 51 1",
"35 7 1",
"32 86 1",
"35 1 1",
"7 26 3",
"35 2 1",
"19 2 2",
"7 42 3",
"35 0 1",
"19 1 2",
"7 64 3",
"7 4 3",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Problem statement
AOR Ika-chan is in a bad mood lately. Apparently, I don't like the ratio of the number of followers to the number of followers of "Ikatta". Currently, AOR Ika-chan ... |
p02312 Intersection of a Circle and a Polygon_7485 | Find the area of intersection between a circle $c$ and a polygon $g$. The center coordinate of the circle is ($0, 0$).
The polygon $g$ is represented by a sequence of points $p_1$, $p_2$,..., $p_n$ where line segments connecting $p_i$ and $p_{i+1}$ ($1 \leq i \leq n−1$) are sides of the polygon. The line segment conne... | import cmath
import itertools
import math
from collections import defaultdict
INF = float("inf")
PI = cmath.pi
TAU = cmath.pi * 2
EPS = 1e-10
class Point:
"""
2次元空間上の点
"""
# 反時計回り側にある
CCW_COUNTER_CLOCKWISE = 1
# 時計回り側にある
CCW_CLOCKWISE = -1
# 線分の後ろにある
CCW_ONLINE_BACK = 2
# 線分の前にある
CCW_ONLINE_FRONT = -2
#... | {
"input": [
"4 5\n0 0\n-3 -6\n1 -3\n5 -4",
"3 5\n1 1\n4 1\n5 5",
"4 5\n0 0\n-3 -5\n1 -3\n5 -4",
"3 5\n1 1\n4 1\n8 5",
"4 8\n0 0\n-3 -5\n1 -3\n5 -4",
"3 8\n1 1\n4 1\n8 5",
"4 8\n-1 0\n-3 -5\n1 -3\n5 -4",
"3 8\n1 1\n4 2\n8 5",
"4 8\n-1 0\n-3 -5\n1 -3\n5 -6",
"3 8\n1 1\n8 2\n8 5"... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Find the area of intersection between a circle $c$ and a polygon $g$. The center coordinate of the circle is ($0, 0$).
The polygon $g$ is represented by a sequence of points $p_1$, $... |
p02460 Map: Delete_7487 | For a dictionary $M$ that stores elements formed by a pair of a string key and an integer value, perform a sequence of the following operations. Note that each key in $M$ must be unique.
* insert($key$, $x$): Insert an element formed by a pair of $key$ and $x$ to $M$.
* get($key$): Print the value with the specified $... | import sys
d = {}
input()
for q in sys.stdin:
q = q.split()
if q[0] == '0':
d[q[1]] = q[2]
elif q[0] == '1':
print(d.get(q[1], 0))
else:
if q[1] in d:
del d[q[1]]
| {
"input": [
"8\n0 blue 4\n0 red 1\n0 white 5\n1 red\n1 blue\n2 red\n1 black\n1 red",
"8\n0 blue 4\n0 red 1\n0 white 5\n1 red\n1 bmue\n2 red\n1 black\n1 red",
"8\n0 blue 4\n0 red 1\n0 white 5\n1 erd\n1 bmue\n2 red\n1 black\n1 red",
"8\n0 blue 4\n0 der 1\n0 white 10\n1 etd\n1 bmue\n2 der\n0 black\n1 de... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
For a dictionary $M$ that stores elements formed by a pair of a string key and an integer value, perform a sequence of the following operations. Note that each key in $M$ must be uniq... |
1004_D. Sonya and Matrix_7497 | Since Sonya has just learned the basics of matrices, she decided to play with them a little bit.
Sonya imagined a new type of matrices that she called rhombic matrices. These matrices have exactly one zero, while all other cells have the Manhattan distance to the cell containing the zero. The cells with equal numbers ... | def get(n,m,a,b,t):
freq=[0]*(t+1)
for i in range(n):
for j in range(m):
val=abs(i-a)+abs(j-b)
freq[val]+=1
return freq
t=int(input())
a=list(map(int,input().split()))
mx=max(a)
f=[0]*(t+1)
for i in a:
f[i]+=1
b=1
for i in range(1,mx+1):
if f[i]!=4*i:
b=i
... | {
"input": [
"20\n1 0 2 3 5 3 2 1 3 2 3 1 4 2 1 4 2 3 2 4\n",
"6\n2 1 0 2 1 2\n",
"18\n2 2 3 2 4 3 3 3 0 2 4 2 1 3 2 1 1 1\n",
"1\n0\n",
"6\n0 0 0 0 0 0\n",
"7\n0 1 2 3 4 2 6\n",
"4\n0 0 0 0\n",
"6\n0 0 0 0 1 0\n",
"20\n1 0 2 3 5 3 2 1 6 2 3 1 4 2 1 4 2 3 2 4\n",
"18\n2 2 3 2 4... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Since Sonya has just learned the basics of matrices, she decided to play with them a little bit.
Sonya imagined a new type of matrices that she called rhombic matrices. These matrice... |
1028_D. Order book_7501 | Let's consider a simplified version of order book of some stock. The order book is a list of orders (offers) from people that want to buy or sell one unit of the stock, each order is described by direction (BUY or SELL) and price.
At every moment of time, every SELL offer has higher price than every BUY offer.
In th... | from sys import stdin
import heapq
MOD = pow(10, 9) + 7
n=int(stdin.readline())
a=[]
for i in range(n):
x=stdin.readline().split()
if x[0]=='ADD':
a.append((0,int(x[1])))
else:
a.append((1,int(x[1])))
next_accept=[-1]*n
accept = -1
for i in range(n-1, -1, -1):
if a[i][0]== 1:
acc... | {
"input": [
"6\nADD 1\nACCEPT 1\nADD 2\nACCEPT 2\nADD 3\nACCEPT 3\n",
"4\nADD 1\nADD 2\nADD 3\nACCEPT 2\n",
"7\nADD 1\nADD 2\nADD 3\nADD 4\nADD 5\nACCEPT 3\nACCEPT 5\n",
"6\nADD 10\nADD 7\nADD 13\nADD 15\nADD 12\nACCEPT 10\n",
"8\nADD 10\nADD 7\nADD 13\nADD 15\nADD 12\nACCEPT 10\nADD 11\nADD 8\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Let's consider a simplified version of order book of some stock. The order book is a list of orders (offers) from people that want to buy or sell one unit of the stock, each order is ... |
1092_D2. Great Vova Wall (Version 2)_7509 | Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.
The current state of the wall can be respresented by a sequence a of n integers, with a_i being the height of the i-th par... | n=int(input())
a=list(map(int,input().split()))
down=[]
good=True
for guy in a:
if len(down)==0:
down.append(guy)
elif down[-1]>guy:
down.append(guy)
elif down[-1]==guy:
down.pop()
else:
good=False
break
if not good:
print("NO")
elif len(down)>1:
print("NO... | {
"input": [
"2\n10 10\n",
"3\n4 5 3\n",
"5\n2 1 1 2 5\n",
"1\n1\n",
"3\n2 2 1\n",
"13\n5 2 2 1 1 2 5 2 1 1 2 2 5\n",
"7\n2 2 2 2 2 2 1\n",
"4\n4 3 2 1\n",
"7\n4 1 1 2 4 3 3\n",
"2\n1 2\n",
"5\n4 3 3 4 1\n",
"20\n10 5 2 3 5 7 7 9 4 9 9 4 9 7 7 5 3 2 5 10\n",
"6\n3 2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finis... |
1111_C. Creative Snap_7513 | Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.
Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of 2. Thanos wants to destroy the... | def solve (l,r,y) :
if (len(y) == 0) :
return a
if (l == r) :
return b*len(y)
c = []
d = []
m = (l+r)//2
for i in y :
if i <= m :
c += [i]
else :
d += [i]
return min(b*(r-l+1)*len(y) , solve(l,m,c) + solve(m+1,r,d))
n,k,a,b = list(... | {
"input": [
"3 2 1 2\n1 7\n",
"2 2 1 2\n1 3\n",
"3 2 5 1\n7 8\n",
"3 3 10000 5\n1 4 5\n",
"5 3 10000 3241\n5 12 2\n",
"5 1 34 241\n22\n",
"3 3 5 10000\n1 4 5\n",
"3 2 7 1\n7 8\n",
"5 3 3521 10000\n5 12 2\n",
"1 1 5 6\n1\n",
"3 2 9 1\n7 8\n",
"5 3 10000 2737\n5 12 2\n",... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.
Let we represent their base with an array, where each position can be occupied ... |
1141_A. Game 23_7517 | Polycarp plays "Game 23". Initially he has a number n and his goal is to transform it to m. In one move, he can multiply n by 2 or multiply n by 3. He can perform any number of moves.
Print the number of moves needed to transform n to m. Print -1 if it is impossible to do so.
It is easy to prove that any way to trans... | def fun(a,b):
if a % b != 0:
return -1
temp = 0
m = a/b
while m % 2 == 0:
m = m / 2
temp += 1
while m % 3 == 0:
m = m/3
temp += 1
if m == 1:
return temp
else :
return -1
a,b = map(int,input().split())
print(fun(b,a)) | {
"input": [
"42 42\n",
"48 72\n",
"120 51840\n",
"1 223092870\n",
"18782 37565\n",
"1001 1001\n",
"5 7\n",
"50 64800\n",
"10 24\n",
"139999978 419999934\n",
"12 26\n",
"10001 10001\n",
"1 7\n",
"1 512\n",
"6 20\n",
"1 2\n",
"300000007 300000007\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarp plays "Game 23". Initially he has a number n and his goal is to transform it to m. In one move, he can multiply n by 2 or multiply n by 3. He can perform any number of moves.... |
1217_C. The Number Of Good Substrings_7526 | You are given a binary string s (recall that a string is binary if each character is either 0 or 1).
Let f(t) be the decimal representation of integer t written in binary form (possibly with leading zeroes). For example f(011) = 3, f(00101) = 5, f(00001) = 1, f(10) = 2, f(000) = 0 and f(000100) = 4.
The substring s_{... | #!/usr/bin/env python3
#Educational Codeforces Round 72 C
import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operat... | {
"input": [
"4\n0110\n0101\n00001000\n0001000\n",
"4\n0110\n1101\n00001000\n0001000\n",
"4\n0110\n1101\n00001000\n0101000\n",
"4\n0110\n1101\n00000000\n0101000\n",
"4\n0110\n1100\n00000000\n0101000\n",
"4\n0110\n1100\n00000000\n0001000\n",
"4\n0110\n1101\n00000000\n0001000\n",
"4\n011... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a binary string s (recall that a string is binary if each character is either 0 or 1).
Let f(t) be the decimal representation of integer t written in binary form (possi... |
1260_A. Heating_7532 | Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.
Your house has n rooms. In the i-th room you can install at most c_i heating radiators. Each radiator can have several sections, but ... | n=int(input())
for i in range(n):
x = list(map(int, input().split(" ")))
print(((x[1]%x[0])*((x[1]//x[0]+1)**2))+(((x[1]//x[0])**2)*(x[0]-(x[1]%x[0])))) | {
"input": [
"4\n1 10000\n10000 1\n2 6\n4 6\n",
"69\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your hous... |
1282_B1. K for the Price of One (Easy Version)_7536 | This is the easy version of this problem. The only difference is the constraint on k — the number of gifts in the offer. In this version: k=2.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "k of goods for the price of one" is held in store... | """
Author : thekushalghosh
Team : CodeDiggers
"""
import sys,math
input = sys.stdin.readline
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(s[:len(s) - 1])
def ... | {
"input": [
"6\n5 6 2\n2 4 3 5 7\n5 11 2\n2 4 3 5 7\n2 10000 2\n10000 10000\n2 9999 2\n10000 10000\n5 13 2\n8 2 8 2 5\n3 18 2\n1 2 3\n",
"8\n5 6 2\n2 4 3 5 7\n5 11 2\n2 4 3 5 7\n3 2 3\n4 2 6\n5 2 3\n10 1 3 9 2\n2 10000 2\n10000 10000\n2 9999 2\n10000 10000\n4 6 4\n3 2 3 2\n5 5 3\n1 2 2 1 2\n",
"2\n2 1 2\... | 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 this problem. The only difference is the constraint on k — the number of gifts in the offer. In this version: k=2.
Vasya came to the store to buy goods fo... |
1326_B. Maximums_7540 | Alicia has an array, a_1, a_2, …, a_n, of non-negative integers. For each 1 ≤ i ≤ n, she has found a non-negative integer x_i = max(0, a_1, …, a_{i-1}). Note that for i=1, x_i = 0.
For example, if Alicia had the array a = \{0, 1, 2, 0, 3\}, then x = \{0, 0, 1, 2, 2\}.
Then, she calculated an array, b_1, b_2, …, b_n: ... | input()
b = list(map(int,input().split()))
a = list()
sumnum = 0
negnum = 0
for i in range(len(b)):
sumnum += b[i]
a.append(sumnum+abs(negnum))
if b[i]<0:
negnum += b[i]
print(*a) | {
"input": [
"3\n1000 999999000 -1000000000\n",
"5\n2 1 2 2 3\n",
"5\n0 1 1 -2 1\n",
"35\n15 13 -19 -7 -28 -16 4 -10 2 -23 -6 -5 -26 -27 -24 -27 -22 1 -32 -19 -16 -15 -29 -26 -25 -17 -11 -20 -2 -11 -20 -30 -1 -7 -27\n",
"3\n0 0 0\n",
"3\n8 -1 0\n",
"10\n10 555 394 -927 -482 18 -196 -464 -1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Alicia has an array, a_1, a_2, …, a_n, of non-negative integers. For each 1 ≤ i ≤ n, she has found a non-negative integer x_i = max(0, a_1, …, a_{i-1}). Note that for i=1, x_i = 0.
F... |
1345_A. Puzzle Pieces_7544 | You are given a special jigsaw puzzle consisting of n⋅ m identical pieces. Every piece has three tabs and one blank, as pictured below.
<image>
The jigsaw puzzle is considered solved if the following conditions hold:
1. The pieces are arranged into a grid with n rows and m columns.
2. For any two pieces that sh... | import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict
from bisect import bisect_left as bl, bisect_right as br
from collections import Counter
from collections import deque
ip = lambda : int(stdin.readline())
inp = lambda: ... | {
"input": [
"3\n1 3\n100000 100000\n2 2\n",
"3\n1 5\n100000 100000\n2 2\n",
"3\n1 3\n100000 100000\n3 2\n",
"3\n2 3\n100000 100000\n3 2\n",
"3\n2 4\n100010 100100\n2 2\n",
"3\n1 6\n100000 100000\n3 2\n",
"3\n1 3\n100000 100100\n2 2\n",
"3\n1 6\n100000 100001\n3 2\n",
"3\n1 3\n1000... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a special jigsaw puzzle consisting of n⋅ m identical pieces. Every piece has three tabs and one blank, as pictured below.
<image>
The jigsaw puzzle is considered solve... |
1408_G. Clusterization Counting_7550 | There are n computers in the company network. They are numbered from 1 to n.
For each pair of two computers 1 ≤ i < j ≤ n you know the value a_{i,j}: the difficulty of sending data between computers i and j. All values a_{i,j} for i<j are different.
You want to separate all computers into k sets A_1, A_2, …, A_k, suc... | # import itertools as it
# import functools as ft
import math
teststring = """4
0 3 4 6
3 0 2 1
4 2 0 5
6 1 5 0
"""
online = __file__ != "/home/jhli/py/Grakn/Problem_G2.py"
true, false = True, False
if True:
def spitout():
for c in teststring.splitlines():
yield c
_ito = spitout()
... | {
"input": [
"7\n0 1 18 15 19 12 21\n1 0 16 13 17 20 14\n18 16 0 2 7 10 9\n15 13 2 0 6 8 11\n19 17 7 6 0 4 5\n12 20 10 8 4 0 3\n21 14 9 11 5 3 0\n",
"4\n0 3 4 6\n3 0 2 1\n4 2 0 5\n6 1 5 0\n",
"1\n0\n",
"4\n0 1 2 3\n1 0 4 5\n2 4 0 6\n3 5 6 0\n",
"7\n0 21 9 3 6 13 16\n21 0 11 2 14 4 18\n9 11 0 19 7 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n computers in the company network. They are numbered from 1 to n.
For each pair of two computers 1 ≤ i < j ≤ n you know the value a_{i,j}: the difficulty of sending data b... |
142_A. Help Farmer_7554 | Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simple... | import math
n = int(input())
mx = 0
mn = 4 * 10**18
for A in range(1, n+1):
if A * A * A > n:
break
if n % A:
continue
nn = n // A
for B in range(1, nn+1):
if B * B > nn:
break
if nn % B:
continue
C = nn // B
mn = min(mn, (A + 1) * (B + 2) * (C + 2) - n)
mx = max(mx, (A + 1) * (B + 2) * (C +... | {
"input": [
"12\n",
"4\n",
"7\n",
"999999993\n",
"257259713\n",
"857656800\n",
"573308928\n",
"286736327\n",
"999893387\n",
"50480\n",
"644972544\n",
"999942949\n",
"679477248\n",
"4472\n",
"99264891\n",
"931170240\n",
"821620800\n",
"509607936\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed... |
1452_E. Two Editorials_7557 | Berland regional ICPC contest has just ended. There were m participants numbered from 1 to m, who competed on a problemset of n problems numbered from 1 to n.
Now the editorial is about to take place. There are two problem authors, each of them is going to tell the tutorial to exactly k consecutive tasks of the proble... | # Enter your code here. Read input from STDIN. Print output to STDOUT# ===============================================================================================
# importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import Byt... | {
"input": [
"10 5 3\n1 3\n2 4\n6 9\n6 9\n1 8\n",
"4 4 1\n3 3\n1 1\n2 2\n4 4\n",
"5 4 5\n1 2\n2 3\n3 4\n4 5\n",
"10 3 3\n2 4\n4 6\n3 5\n",
"3 2 1\n1 1\n2 2\n",
"1 5 1\n1 1\n1 1\n1 1\n1 1\n1 1\n",
"1 6 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n",
"2 9 1\n1 1\n2 2\n1 1\n1 2\n1 1\n2 2\n2 2\n1 2\n2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Berland regional ICPC contest has just ended. There were m participants numbered from 1 to m, who competed on a problemset of n problems numbered from 1 to n.
Now the editorial is ab... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.