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 |
|---|---|---|---|---|---|
645_D. Robot Rapping Results Report_21731 | While Farmer John rebuilds his farm in an unfamiliar portion of Bovinia, Bessie is out trying some alternative jobs. In her new gig as a reporter, Bessie needs to know about programming competition results as quickly as possible. When she covers the 2016 Robot Rap Battle Tournament, she notices that all of the robots o... | from collections import defaultdict
class RobotRapping():
def __init__(self, n, m, battles):
self.n, self.m = n, m
self.battles = battles
def generate_graph(self, k):
edge_map = defaultdict(list)
rev_map = defaultdict(list)
for i in range(k):
edge_map[self.... | {
"input": [
"3 2\n1 2\n3 2\n",
"4 5\n2 1\n1 3\n2 3\n4 2\n4 3\n",
"5 10\n4 3\n4 1\n2 1\n1 3\n5 1\n5 3\n5 4\n2 5\n2 3\n2 4\n",
"2 1\n2 1\n",
"4 6\n1 4\n4 2\n2 3\n1 2\n1 3\n4 3\n",
"5 10\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5\n",
"5 10\n2 1\n5 2\n3 2\n3 1\n5 4\n3 4\n4 2\n5 1\n4 1\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
While Farmer John rebuilds his farm in an unfamiliar portion of Bovinia, Bessie is out trying some alternative jobs. In her new gig as a reporter, Bessie needs to know about programmi... |
672_B. Different is Good_21735 | A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string s consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string s to be distinct. Substring is a string formed by some num... | n = int(input())
s = input()
s = set(s)
if n<27:
print(n - len(s))
else:
print('-1') | {
"input": [
"2\naa\n",
"4\nkoko\n",
"5\nmurat\n",
"1\na\n",
"26\nahnxdnbfbcrirerssyzydihuee\n",
"1\nq\n",
"26\nbbbbbabbaababaaabaaababbaa\n",
"25\npeoaicnbisdocqofsqdpgobpn\n",
"26\nabcdefghijklmnopqrstuvwxya\n",
"27\naaaaaaaaaaaaaaaaabaaaaaaaaa\n",
"27\nqwertyuiopasdfghjk... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string s consisting of lowercase English letters. Since K... |
697_D. Puzzles_21739 | Barney lives in country USC (United States of Charzeh). USC has n cities numbered from 1 through n and n - 1 roads between them. Cities and roads of USC form a rooted tree (Barney's not sure why it is rooted). Root of the tree is the city number 1. Thus if one will start his journey from city 1, he can visit any city h... | import sys
input = sys.stdin.readline
n = int(input())
par = [-1] + [int(i) - 1 for i in input().split()]
child = [[] for i in range(n)]
for i in range(1, n):
child[par[i]].append(i)
size = [1] * n
def dfs():
stack = [0]
visit = [False] * n
while stack:
u = stack[-1]
if not visit[u]:
... | {
"input": [
"12\n1 1 2 2 4 4 3 3 1 10 8\n",
"7\n1 2 1 1 4 4\n",
"3\n1 2\n",
"10\n1 2 2 2 5 4 6 5 6\n",
"85\n1 1 2 2 4 6 1 3 6 3 3 11 9 14 12 5 8 11 16 19 12 17 2 19 1 24 6 2 6 6 24 3 20 1 1 1 17 8 4 25 31 32 39 12 35 23 31 26 46 9 37 7 5 23 41 41 39 9 11 54 36 54 28 15 25 58 56 18 23 70 68 18 3 4... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Barney lives in country USC (United States of Charzeh). USC has n cities numbered from 1 through n and n - 1 roads between them. Cities and roads of USC form a rooted tree (Barney's n... |
73_B. Need For Brake_21745 | Vasya plays the Need For Brake. He plays because he was presented with a new computer wheel for birthday! Now he is sure that he will win the first place in the championship in his favourite racing computer game!
n racers take part in the championship, which consists of a number of races. After each race racers are a... | class Racer:
def __init__(self, name, points):
self.name = name
self.points = points
def __str__(self):
return '%s %d' % (self.name, self.points)
n = int(input())
best = n * [ None ]
worst = n * [ None ]
for i in range(n):
name, points = input().split()
points = int(points)
... | {
"input": [
"3\nteama 10\nteamb 20\nteamc 40\n2\n10 20\nteama\n",
"2\nteama 10\nteamb 10\n2\n10 10\nteamb\n",
"10\njcfdh 1000000\nchk 1000000\nkga 1000000\nbeh 1000000\ngeg 1000000\nhaj 1000000\nagah 1000000\ndhk 1000000\nhj 1000000\ndb 1000000\n5\n1000000 1000000 1000000 1000000 1000000\ndb\n",
"5\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya plays the Need For Brake. He plays because he was presented with a new computer wheel for birthday! Now he is sure that he will win the first place in the championship in his fa... |
808_A. Lucky Year_21753 | Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not.
You are given current year in Berland. Your task is to find how long... | import math
a = int(input())
#print(math.log(a))
b = int(10 ** ((math.log(a+1) // math.log(10))))
#print(b)
total = b
while total <= a:
total += b
print(str(total-a)) | {
"input": [
"4000\n",
"4\n",
"201\n",
"80100\n",
"98\n",
"9020\n",
"79\n",
"1000000000\n",
"62\n",
"80900\n",
"67\n",
"52\n",
"2001\n",
"42\n",
"9002\n",
"20000\n",
"120\n",
"93\n",
"95\n",
"90000\n",
"90\n",
"9001\n",
"220\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its numbe... |
832_B. Petya and Exam_21757 | It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one..
There is a glob pattern in the statements (a string consisting of lowercase English letters, characters "?" and "*"). It is kno... | a=input()
s=input()
k=int(input())
def qw(c):
t=True
w=-1
if len(s)>len(c)+1: t=False
try:
for j in range(len(s)):
w+=1
if s[j]=='?':
if c[w] not in a: t=False
elif s[j]=='*':
b=len(c)-len(s)+1
for e in c[j:j+b]:
if e in a:
t=False
w+=b-1
else:
if s[j]!=c[w]: t=False
... | {
"input": [
"ab\na?a\n2\naaa\naab\n",
"abc\na?a?a*\n4\nabacaba\nabaca\napapa\naaaaax\n",
"c\n*\n83\nbbc\ncacb\nbcbc\naca\nba\nc\nccac\nab\nab\nbacba\nbb\nc\nbcc\nc\ncbc\ncbbb\nac\nb\nacbcb\nbccc\ncccb\nb\na\nca\nc\nccaa\naa\ncacb\nccc\na\nccc\nababb\nbab\ncaa\nbaa\na\ncc\ncbbbc\naaaa\nabbab\naabac\nbcbab... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help wi... |
877_D. Olya and Energy Drinks_21763 | Olya loves energy drinks. She loves them so much that her room is full of empty cans from energy drinks.
Formally, her room can be represented as a field of n × m cells, each cell of which is empty or littered with cans.
Olya drank a lot of energy drink, so now she can run k meters per second. Each second she chooses... | from collections import deque
n, m, k = map(int, input().split())
INF = float("inf")
d = [[INF] * m for _ in range(n)]
t = [[] for i in range(n)]
for i in range(n):
a = list(input())
t[i] = a
sx, sy, gx, gy = map(int, input().split())
sx, sy, gx, gy = sx - 1, sy - 1, gx - 1, gy - 1
def bfs():
que = deque... | {
"input": [
"3 4 4\n....\n###.\n....\n1 1 3 1\n",
"2 2 1\n.#\n#.\n1 1 2 2\n",
"3 4 1\n....\n###.\n....\n1 1 3 1\n",
"4 4 4\n...#\n.#.#\n....\n##..\n1 1 3 4\n",
"10 10 1\n##########\n#.........\n#.#######.\n#.#.....#.\n#.#.###.#.\n#.#.#.#.#.\n#.#.#.#.#.\n#.#.#...#.\n#.#.#####.\n#.#.......\n6 6 10 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Olya loves energy drinks. She loves them so much that her room is full of empty cans from energy drinks.
Formally, her room can be represented as a field of n × m cells, each cell of... |
900_E. Maximum Questions_21766 | Vasya wrote down two strings s of length n and t of length m consisting of small English letters 'a' and 'b'. What is more, he knows that string t has a form "abab...", namely there are letters 'a' on odd positions and letters 'b' on even positions.
Suddenly in the morning, Vasya found that somebody spoiled his string... | n = int(input()); s = input(); m = int(input())
a = [0]*(n+2); b = [0]*(n+2); q = [0]*(n+1);
dp = [(0, 0)]*(n+2)
for i in range(0, n):
b[i] = b[i-2]+(s[i] == 'b')
a[i] = a[i-2]+(s[i] == 'a')
q[i] = q[i-1]+(s[i] == '?')
for i in range(n-m, -1, -1):
dp[i] = dp[i+1]
i_b = 1 if m%2 == 1 else 2
i_a = 1 if m%... | {
"input": [
"9\nab??ab???\n3\n",
"5\nbb?a?\n1\n",
"14\na?a?b????b?ba?\n3\n",
"6\nab??ab\n4\n",
"43\n????aabaababa?aaaa?abbbabbb?ab??baabbbbbabb\n5\n",
"9\n?????aba?\n2\n",
"1\nb\n1\n",
"29\n?bba?ab?b?bbbbaa?a?bba?aab?a?\n4\n",
"112\n??????ab????aaab?a?aa?babb??b?b?b?baaab?bbba?ab?... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya wrote down two strings s of length n and t of length m consisting of small English letters 'a' and 'b'. What is more, he knows that string t has a form "abab...", namely there a... |
923_C. Perfect Security_21769 | Alice has a very important message M consisting of some non-negative integers that she wants to keep secret from Eve. Alice knows that the only theoretically secure cipher is one-time pad. Alice generates a random key K of the length equal to the message's length. Alice computes the bitwise xor of each element of the m... | def add(x):
global tree
now = 0
tree[now][2] += 1
for i in range(29, -1, -1):
bit = (x>>i)&1
if tree[now][bit]==0:
tree[now][bit]=len(tree)
tree.append([0, 0, 0])
now = tree[now][bit]
tree[now][2] += 1
def find_min(x):
global tree
now = an... | {
"input": [
"10\n331415699 278745619 998190004 423175621 42983144 166555524 843586353 802130100 337889448 685310951\n226011312 266003835 342809544 504667531 529814910 684873393 817026985 844010788 993949858 1031395667\n",
"5\n12 7 87 22 11\n18 39 9 12 16\n",
"3\n8 4 13\n17 2 7\n",
"5\n134 246 57 176 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Alice has a very important message M consisting of some non-negative integers that she wants to keep secret from Eve. Alice knows that the only theoretically secure cipher is one-time... |
979_A. Pizza, Pizza, Pizza!!!_21775 | Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to cele... |
n = int(input()) + 1
if n == 1:
print(0)
exit()
if n % 2 == 0:
print(n //2)
else:
print(n) | {
"input": [
"4\n",
"3\n",
"63\n",
"779547116602436424\n",
"99999999999999999\n",
"335408917861648766\n",
"1234567891\n",
"578223540024979436\n",
"24\n",
"148049062628894320\n",
"520974001910286909\n",
"10000000000\n",
"891351282707723851\n",
"234122432773361866... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard probl... |
999_B. Reversing Encryption_21779 | A string s of length n can be encrypted by the following algorithm:
* iterate over all divisors of n in decreasing order (i.e. from n to 1),
* for each divisor d, reverse the substring s[1 ... d] (i.e. the substring which starts at position 1 and ends at position d).
For example, the above algorithm applied t... | l = int(input())
s = list(input())
for i in range(2, l + 1):
if l % i > 0: continue
s[:i] = s[i - 1::-1]
print(''.join(s))
| {
"input": [
"10\nrocesfedoc\n",
"1\nz\n",
"16\nplmaetwoxesisiht\n",
"2\nir\n",
"60\nwwwwwxwwwwwwfhwwhwwwwwwawwwwwwwwwwwwwnwwwwwwwwwwwwwwwwwwwwww\n",
"90\nmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm\n",
"3\nilj\n",
"97\nqnqrmdhmbubaijtwsec... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A string s of length n can be encrypted by the following algorithm:
* iterate over all divisors of n in decreasing order (i.e. from n to 1),
* for each divisor d, reverse the su... |
p02664 NOMURA Programming Competition 2020 - Postdocs_21793 | For a string S consisting of the uppercase English letters `P` and `D`, let the doctoral and postdoctoral quotient of S be the total number of occurrences of `D` and `PD` in S as contiguous substrings. For example, if S = `PPDDP`, it contains two occurrences of `D` and one occurrence of `PD` as contiguous substrings, s... | # B - Postdocs
t = input()
print(t.replace('?', 'D')) | {
"input": [
"PD?D??P",
"P?P?",
"PDPD???",
"?P?P",
"DDPP???",
"??PP",
"DDPO???",
"??OP",
"DDPO?>?",
"??OO",
"?>?OPDD",
"@?OP",
"?>?PPDD",
"@?PO",
"DDPP?>?",
"@?PN",
"DDPP?>@",
"NP?@",
"DDPP??@",
"@P?N",
"@DPP??D",
"@P@N",
"D??... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
For a string S consisting of the uppercase English letters `P` and `D`, let the doctoral and postdoctoral quotient of S be the total number of occurrences of `D` and `PD` in S as cont... |
p02793 AtCoder Beginner Contest 152 - Flatten_21797 | Given are N positive integers A_1,...,A_N.
Consider positive integers B_1, ..., B_N that satisfy the following condition.
Condition: For any i, j such that 1 \leq i < j \leq N, A_i B_i = A_j B_j holds.
Find the minimum possible value of B_1 + ... + B_N for such B_1,...,B_N.
Since the answer can be enormous, print t... | N = int(input())
A = [int(a) for a in input().split()]
import fractions
mod = 10**9+7
t = 1
for a in A:
t = a*t//fractions.gcd(a, t)
ans = 0
for a in A:
ans += t//a
print(ans%mod) | {
"input": [
"3\n2 3 4",
"3\n1000000 999999 999998",
"5\n12 12 12 12 12",
"3\n2 3 2",
"3\n1000000 999999 1014329",
"5\n11 12 12 12 12",
"3\n2 6 2",
"3\n1000000 999999 1246389",
"5\n11 17 12 12 12",
"3\n1 6 2",
"3\n1000000 1225154 1246389",
"5\n11 17 14 12 12",
"3\n1... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Given are N positive integers A_1,...,A_N.
Consider positive integers B_1, ..., B_N that satisfy the following condition.
Condition: For any i, j such that 1 \leq i < j \leq N, A_i ... |
p02929 Japanese Student Championship 2019 Qualification - Cell Inversion_21801 | There are 2N squares arranged from left to right. You are given a string of length 2N representing the color of each of the squares.
The color of the i-th square from the left is black if the i-th character of S is `B`, and white if that character is `W`.
You will perform the following operation exactly N times: choo... | from math import factorial
mod = 10 ** 9 + 7
n = int(input())
inp = list(input())
if inp[0] == 'W' or inp[-1] == 'W':
print(0)
exit(0)
arr = ['L']
swap_dict = {'L': 'R', 'R': 'L'}
for i in range(1, 2 * n):
arr.append(arr[i - 1] if inp[i] != inp[i - 1] else swap_dict[arr[i - 1]])
if arr.count('L') != arr.cou... | {
"input": [
"2\nBWWB",
"5\nWWWWWWWWWW",
"4\nBWBBWWWB",
"5\nWWVWWWWWWW",
"4\nBWWWBBWB",
"5\nWWVWWWWWWX",
"5\nWWVWWWXWWX",
"5\nWWVVWWXWWX",
"5\nWXWWWWWWWW",
"5\nWWVWWXWWWW",
"4\nBWBBWBWW",
"5\nWWVWWWWVWX",
"5\nWWVVWWXXWX",
"5\nWWWWWWWWXW",
"5\nWWWWXWWVWW",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are 2N squares arranged from left to right. You are given a string of length 2N representing the color of each of the squares.
The color of the i-th square from the left is bla... |
p03065 Tenka1 Programmer Contest 2019 - Polynomial Divisors_21804 | You are given a polynomial of degree N with integer coefficients: f(x)=a_Nx^N+a_{N-1}x^{N-1}+...+a_0. Find all prime numbers p that divide f(x) for every integer x.
Constraints
* 0 \leq N \leq 10^4
* |a_i| \leq 10^9(0\leq i\leq N)
* a_N \neq 0
* All values in input are integers.
Input
Input is given from Standard I... | def factors(z):
ret = []
for i in range(2, int(z**(1/2))+1):
if z%i == 0:
ret.append(i)
while z%i == 0:
z //= i
if z != 1:
ret.append(z)
return ret
def eratosthenes(N):
if N == 0:
return []
from collections import deque
work = ... | {
"input": [
"2\n7\n-7\n14",
"0\n998244353",
"0\n1365261696",
"0\n754892205",
"0\n663325004",
"0\n130630416",
"0\n46502294",
"0\n41442548",
"0\n15639162",
"0\n1226279",
"0\n124557",
"0\n99361",
"0\n1336",
"0\n565",
"0\n553",
"0\n587",
"0\n1081",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a polynomial of degree N with integer coefficients: f(x)=a_Nx^N+a_{N-1}x^{N-1}+...+a_0. Find all prime numbers p that divide f(x) for every integer x.
Constraints
* 0 ... |
p03208 AtCoder Beginner Contest 115 - Christmas Eve_21808 | In some other world, today is Christmas Eve.
There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.
He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees shoul... | N, K = map(int, input().split())
H = [int(input()) for n in range(N)]
H.sort()
R = [H[i+K-1] - H[i] for i in range(N+1-K)]
print(min(R))
| {
"input": [
"5 3\n10\n15\n11\n14\n12",
"5 3\n5\n7\n5\n7\n7",
"5 3\n5\n7\n10\n7\n7",
"5 3\n5\n7\n10\n0\n7",
"5 3\n8\n7\n10\n0\n7",
"3 3\n5\n7\n10\n7\n7",
"5 3\n0\n15\n11\n15\n12",
"5 3\n10\n21\n10\n0\n6",
"3 3\n10\n7\n1\n1\n5",
"5 3\n10\n21\n19\n0\n6",
"4 3\n10\n21\n19\n0\n... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In some other world, today is Christmas Eve.
There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.
He decides to choose K tr... |
p03357 AtCoder Regular Contest 097 - Sorted and Sorted_21811 | There are 2N balls, N white and N black, arranged in a row. The integers from 1 through N are written on the white balls, one on each ball, and they are also written on the black balls, one on each ball. The integer written on the i-th ball from the left (1 ≤ i ≤ 2N) is a_i, and the color of this ball is represented by... | import sys
input = sys.stdin.readline
n = int(input())
INF = 10 ** 9
info = [list(input().split()) for i in range(2 * n)]
ind = {}
for i in range(2 * n):
if info[i][0] == "B":
info[i] = (0, int(info[i][1]))
else:
info[i] = (1, int(info[i][1]))
ind[info[i][0] * 10 ** 5 + info[i][1]] = i
r... | {
"input": [
"9\nW 3\nB 1\nB 4\nW 1\nB 5\nW 9\nW 2\nB 6\nW 5\nB 3\nW 8\nB 9\nW 7\nB 2\nB 8\nW 4\nW 6\nB 7",
"3\nB 1\nW 2\nB 3\nW 1\nW 3\nB 2",
"4\nB 4\nW 4\nB 3\nW 3\nB 2\nW 2\nB 1\nW 1",
"3\nB 1\nW 1\nB 3\nW 2\nW 3\nB 2",
"4\nB 4\nW 4\nB 2\nW 3\nB 3\nW 2\nB 1\nW 1",
"4\nB 2\nW 4\nB 3\nW 3\nB ... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are 2N balls, N white and N black, arranged in a row. The integers from 1 through N are written on the white balls, one on each ball, and they are also written on the black ball... |
p03515 CODE FESTIVAL 2017 Elimination Tournament Round 3 (Parallel) - Black Cats Deployment_21814 | Snuke Festival 2017 will be held in a tree with N vertices numbered 1,2, ...,N. The i-th edge connects Vertex a_i and b_i, and has joyfulness c_i.
The staff is Snuke and N-1 black cats. Snuke will set up the headquarters in some vertex, and from there he will deploy a cat to each of the other N-1 vertices.
For each v... | import sys
from operator import itemgetter
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
class UnionFind:
def __init__(self, N):
self.root = list(range(N + 1))
def __getitem__(self, x):
root = self.root
while root[x] != x:
... | {
"input": [
"15\n6 3 2\n13 3 1\n1 13 2\n7 1 2\n8 1 1\n2 8 2\n2 12 2\n5 2 2\n2 11 2\n10 2 2\n10 9 1\n9 14 2\n4 14 1\n11 15 2",
"19\n19 14 48\n11 19 23\n17 14 30\n7 11 15\n2 19 15\n2 18 21\n19 10 43\n12 11 25\n3 11 4\n5 19 50\n4 11 19\n9 12 29\n14 13 3\n14 6 12\n14 15 14\n5 1 6\n8 18 13\n7 16 14",
"3\n1 2 ... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Snuke Festival 2017 will be held in a tree with N vertices numbered 1,2, ...,N. The i-th edge connects Vertex a_i and b_i, and has joyfulness c_i.
The staff is Snuke and N-1 black ca... |
p03833 AtCoder Regular Contest 067 - Yakiniku Restaurants_21819 | There are N barbecue restaurants along a street. The restaurants are numbered 1 through N from west to east, and the distance between restaurant i and restaurant i+1 is A_i.
Joisino has M tickets, numbered 1 through M. Every barbecue restaurant offers barbecue meals in exchange for these tickets. Restaurant i offers a... | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import itertools
INF=10**10
N,M = map(int,readline().split())
A = [0,0]+list(map(int,readline().split()))
B = [[INF]*M]+[list(map(int,line.split())) for line in readlines()]
for i in range(1,N+1):
... | {
"input": [
"3 4\n1 4\n2 2 5 1\n1 3 3 2\n2 2 5 1",
"5 3\n1 2 3 4\n10 1 1\n1 1 1\n1 10 1\n1 1 1\n1 1 10",
"3 4\n1 4\n2 2 5 1\n1 3 6 2\n2 2 5 1",
"5 3\n1 2 3 4\n10 1 1\n1 1 1\n1 10 1\n1 1 1\n0 1 10",
"1 4\n1 4\n2 2 5 1\n1 3 6 2\n2 2 5 1",
"5 3\n1 2 4 4\n10 1 1\n1 1 1\n1 10 1\n1 1 1\n0 1 10",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are N barbecue restaurants along a street. The restaurants are numbered 1 through N from west to east, and the distance between restaurant i and restaurant i+1 is A_i.
Joisino ... |
p03998 AtCoder Beginner Contest 045 - Card Game for Three (ABC Edit)_21823 | Alice, Bob and Charlie are playing Card Game for Three, as below:
* At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged.
* The players take turns. Alice goes first.
* If the cu... | hands = {char:list(input()) for char in 'abc'}
next_hand = 'a'
while hands[next_hand]:
next_hand = hands[next_hand].pop(0)
print(next_hand.upper()) | {
"input": [
"abcb\naacb\nbccc",
"aca\naccc\nca",
"abcb\naabb\nbccc",
"caa\naccc\nca",
"aaca\naabb\ncccc",
"abcb\nbbaa\nbccc",
"aacb\nbbaa\nbccc",
"aacb\nbbaa\ncccb",
"aaca\nbbaa\ncccb",
"aaca\naabb\ncccb",
"acaa\naabb\ncccc",
"acaa\nabab\ncccc",
"acaa\nabab\nbccc",... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Alice, Bob and Charlie are playing Card Game for Three, as below:
* At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b`... |
p00086 Patrol_21827 | In 1862, the lord of Aizu was ordered to serve as a guardian of Kyoto. The Kyoto Shugoshoku is an important role to protect Kyoto at the end of the Edo period when security has deteriorated. You have to patrol the city by sharing it with the shogunate and other clan. However, when it came time to decide the sharing rou... | import sys
def is_half_euler_graph(node_list):
for node in node_list:
isBool = True
for dic_key, dic_value in node.items():
if dic_key != 1 and dic_key != 2:
if dic_value % 2 != 0:
isBool = False
break
else :
... | {
"input": [
"1 3\n3 4\n3 5\n3 6\n4 6\n4 7\n4 7\n5 6\n6 7\n5 8\n5 8\n6 8\n6 9\n7 9\n8 9\n9 2\n0 0\n1 3\n3 4\n3 4\n4 2\n0 0",
"1 3\n3 4\n3 5\n3 6\n4 6\n4 7\n4 7\n5 6\n6 7\n5 8\n5 8\n3 8\n6 9\n7 9\n8 9\n9 2\n0 0\n1 3\n3 4\n3 4\n4 2\n0 0",
"1 3\n3 4\n3 5\n3 6\n4 6\n4 7\n4 7\n5 6\n6 7\n5 8\n1 8\n3 8\n6 9\n7 9... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In 1862, the lord of Aizu was ordered to serve as a guardian of Kyoto. The Kyoto Shugoshoku is an important role to protect Kyoto at the end of the Edo period when security has deteri... |
p00218 Dividing Students_21831 | At Aizu Shingakujuku, students are divided into classes by conducting a proficiency test when they enter the cram school. The test consists of three subjects: Mathematics, English, and Japanese, and students are divided into A, B, and C classes. The level of class A is the highest and then decreases in order.
The clas... | while True:
#繰り返し回数を入力し0であった場合はbreakする
num = int(input())
if num == 0:
break
else:
for _ in range(num):
a,b,c = map(int,input().split())
#100 点の科目があるまたは数学と英語の平均点が 90 点以上または3 科目の平均点が 80 点以上の場合"A"を出力する
if a == 100 or b == 100 or c == 100 or ... | {
"input": [
"4\n100 70 20\n98 86 55\n80 34 36\n65 79 65\n2\n99 81 20\n66 72 90\n0",
"4\n100 70 20\n98 86 55\n80 34 39\n65 79 65\n2\n99 81 20\n66 72 90\n0",
"4\n100 70 20\n98 86 55\n80 34 36\n65 140 65\n2\n99 81 20\n66 72 90\n0",
"4\n100 70 20\n98 86 19\n80 34 39\n65 79 65\n2\n99 75 20\n66 72 90\n0",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
At Aizu Shingakujuku, students are divided into classes by conducting a proficiency test when they enter the cram school. The test consists of three subjects: Mathematics, English, an... |
p00378 Heat Strokes_21834 | We have had record hot temperatures this summer. To avoid heat stroke, you decided to buy a quantity of drinking water at the nearby supermarket. Two types of bottled water, 1 and 0.5 liter, are on sale at respective prices there. You have a definite quantity in your mind, but are willing to buy a quantity larger than ... | a, b, x = map(int, input().split())
if b * 2 <= a:
ans = b * (x // 500 + bool(x % 500))
else:
ans = a * (x // 1000) + min(b * ((x % 1000) // 500 + bool((x % 1000) % 500)), a * bool(x % 1000))
print(ans)
| {
"input": [
"180 100 2400",
"200 90 2018",
"180 100 3257",
"12 90 2018",
"324 100 3257",
"22 90 2018",
"324 101 3257",
"21 90 2018",
"324 111 3257",
"324 111 5696",
"467 101 5696",
"467 101 10577",
"467 001 10577",
"467 011 10577",
"21 671 759",
"467 00... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We have had record hot temperatures this summer. To avoid heat stroke, you decided to buy a quantity of drinking water at the nearby supermarket. Two types of bottled water, 1 and 0.5... |
p00596 Dominoes Arrangement_21838 | [0, 0]
[0, 1] [1, 1]
[0, 2] [1, 2] [2, 2]
[0, 3] [1, 3] [2, 3] [3, 3]
[0, 4] [1, 4] [2, 4] [3, 4] [4, 4]
[0, 5] [1, 5] [2, 5] [3, 5] [4, 5] [5, 5]
[0, 6] [1, 6] [2, 6] [3, 6] [4, 6] [5, 6] [6, 6]
Consider the standard set of 28 western dominoes as shown in the above figure. Given a subset of the ... | import sys
def subset(line):
l = line.strip().split(" ")
a = list(map(int, l))
xy = list(map(lambda x: [x // 10, x % 10], a))
dominos = [[2 if [x, y] in xy and x == y else \
1 if [x, y] in xy else \
1 if [y, x] in xy else 0 \
for x in range(0, 7)] for y i... | {
"input": [
"6\n13 23 14 24 15 25\n10\n00 01 11 02 12 22 03 13 23 33",
"6\n13 23 20 24 15 25\n10\n00 01 11 02 12 22 03 13 23 33",
"6\n13 23 20 24 11 25\n10\n00 01 11 02 12 22 03 13 23 33",
"6\n13 23 20 24 11 25\n10\n00 01 11 02 12 22 03 13 16 33",
"6\n16 23 16 16 15 25\n10\n00 01 11 02 12 22 03 1... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
[0, 0]
[0, 1] [1, 1]
[0, 2] [1, 2] [2, 2]
[0, 3] [1, 3] [2, 3] [3, 3]
[0, 4] [1, 4] [2, 4] [3, 4] [4, 4]
[0, 5] [1, 5] [2, 5] [3, 5] [4, 5] [5, 5]
[0, 6] [1, 6] [2, 6... |
p01135 Poor Mail Forwarding_21846 | The postal system in the area where Masa lives has changed a bit. In this area, each post office is numbered consecutively from 1 to a different number, and mail delivered to a post office is intended from that post office via several post offices. Delivered to the post office. Mail "forwarding" is only done between sp... | def solve():
from sys import stdin
f_i = stdin
ans = ''
while True:
n, m = map(int, f_i.readline().split())
if n == 0:
break
# prep for warshall-floyd algorithm
inf = 10000 * 31 + 1
dist = [[inf] * n for i in range(n)]
for i ... | {
"input": [
"4 5\n1 2 10\n1 3 15\n2 3 5\n2 4 3\n3 4 10\n2\n1 4 10 LoveLetter\n2 3 20 Greetings\n3 3\n1 2 1\n2 3 1\n3 1 1\n3\n1 2 1 BusinessMailC\n2 3 1 BusinessMailB\n3 1 1 BusinessMailA\n0 0",
"4 5\n1 2 10\n1 3 15\n2 3 5\n2 4 3\n3 4 10\n2\n1 4 10 LoveLetter\n2 3 13 Greetings\n3 3\n1 2 1\n2 3 1\n3 1 1\n3\n1 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The postal system in the area where Masa lives has changed a bit. In this area, each post office is numbered consecutively from 1 to a different number, and mail delivered to a post o... |
p01593 Earn Big_21853 | Problem C: Earn Big
A group of N people is trying to challenge the following game to earn big money.
First, N participants are isolated from each other. From this point, they are not allowed to contact each other, or to leave any information for other participants. The game organizer leads each participant, one by on... | dp=[1]+[0]*1000
n,m=map(int,input().split())
for i in range(n):
j=1
while i+j<=n and j<=m:dp[i+j]+=dp[i]/(n-i);j+=1
print('%.10f'%dp[n]) | {
"input": [
"2 1",
"100 50",
"4 1",
"110 50",
"4 0",
"010 50",
"110 89",
"110 12",
"010 4",
"010 1",
"3 2",
"3 1",
"010 6",
"010 2",
"010 3",
"011 1",
"011 2",
"15 1",
"14 1",
"7 1",
"22 2",
"22 4",
"011 6",
"100 10",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Problem C: Earn Big
A group of N people is trying to challenge the following game to earn big money.
First, N participants are isolated from each other. From this point, they are no... |
p01750 Hyperrectangle_21856 | Sunuke received a d-dimensional hypercube with a side length of l1 × ... × ld as a birthday present. Sunuke placed this rectangular parallelepiped so that the range of the i-th coordinate was 0 or more and li or less, and ate the part that satisfied x1 + ... + xd ≤ s. However, xi represents the i-th coordinate. If the ... | import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
MOD = 10**9 + 7
D = int(readline())
L = [int(readline()) for i in range(D)]
S = int(readline())
dp = [0]*(S+1)
dp[S] = 1
for i in range(D):
l = L[i]
for i in range(l, S+1):
dp[i-l] -= d... | {
"input": [
"5\n12\n34\n56\n78\n90\n123",
"2\n6\n3\n4",
"5\n12\n34\n56\n17\n90\n123",
"2\n6\n3\n3",
"5\n12\n34\n56\n1\n90\n123",
"5\n12\n25\n56\n1\n90\n123",
"5\n12\n25\n56\n2\n90\n123",
"5\n12\n34\n15\n17\n90\n123",
"5\n12\n43\n56\n1\n90\n123",
"5\n12\n25\n56\n1\n24\n123",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Sunuke received a d-dimensional hypercube with a side length of l1 × ... × ld as a birthday present. Sunuke placed this rectangular parallelepiped so that the range of the i-th coordi... |
p02169 Count Words_21862 | Problem
There are $ M $ type characters. Use them to create a string of length $ N $. How many strings are used that have $ K $ or more? Find too much divided by $ 998244353 $.
Here, the difference between two strings of length $ N $ is defined as follows.
* If the two strings are $ S = S_1S_2 \ ldots S_N $, $ T = T... | #!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]... | {
"input": [
"7 8 3",
"1000000000000000000 1000000000000000000 1000",
"5 10 3",
"1 1 2",
"2 10 1",
"10 8 3",
"1000000000000000000 1000000000000000000 1001",
"5 2 3",
"10 8 6",
"2 2 2",
"1 10 1",
"10 6 6",
"2 3 2",
"2 10 2",
"2 11 2",
"3 5 3",
"6 5 3"... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Problem
There are $ M $ type characters. Use them to create a string of length $ N $. How many strings are used that have $ K $ or more? Find too much divided by $ 998244353 $.
Here... |
p02310 Tangent to a Circle_21865 | Find the tangent lines between a point $p$ and a circle $c$.
Constraints
* $-1,000 \leq px, py, cx, cy \leq 1,000$
* $1 \leq r \leq 1,000$
* Distance between $p$ and the center of $c$ is greater than the radius of $c$.
Input
The input is given in the following format.
$px \; py$
$cx \; cy \; r$
$px$ and $py$ repr... | import cmath
import itertools
import math
import os
import sys
from collections import defaultdict
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353
PI = cmath.pi
TAU = cmath.pi * 2
EPS = 1e-10
class Poi... | {
"input": [
"-3 0\n2 2 2",
"0 0\n2 2 2",
"-3 0\n3 2 2",
"-1 0\n2 2 2",
"-4 0\n3 2 2",
"1 0\n2 2 2",
"-4 -1\n3 2 2",
"1 0\n4 2 2",
"-4 -1\n2 2 2",
"-4 -1\n4 2 2",
"-4 -1\n4 2 3",
"-4 -1\n4 2 6",
"-4 -1\n8 2 6",
"-8 -1\n8 2 6",
"-8 -2\n8 2 6",
"-8 -2\n8 2... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Find the tangent lines between a point $p$ and a circle $c$.
Constraints
* $-1,000 \leq px, py, cx, cy \leq 1,000$
* $1 \leq r \leq 1,000$
* Distance between $p$ and the center of $... |
p02458 Multi-Set_21867 | For a set $S$ of integers, perform a sequence of the following operations. Note that multiple elements can have equivalent values in $S$.
* insert($x$): Insert $x$ to $S$ and report the number of elements in $S$ after the operation.
* find($x$): Report the number of $x$ in $S$.
* delete($x$): Delete all $x$ from $S$.
... | import bisect
import collections
def main6():
values = collections.defaultdict(int)
element_count = 0
q = int(input())
for _ in range(q):
com, *para = map(int, input().split())
if com == 0:
values[para[0]] += 1
element_count += 1
print(element_c... | {
"input": [
"10\n0 1\n0 1\n0 2\n0 3\n2 2\n1 1\n1 2\n1 3\n0 4\n3 1 4",
"10\n0 1\n0 1\n0 2\n0 3\n2 2\n1 1\n1 1\n1 3\n0 4\n3 1 4",
"10\n0 1\n0 1\n0 2\n0 0\n2 2\n1 1\n1 2\n1 3\n0 4\n3 1 4",
"10\n0 1\n0 1\n0 2\n0 3\n2 2\n1 1\n1 1\n1 3\n1 4\n3 1 4",
"10\n0 1\n0 1\n0 2\n0 5\n2 2\n1 1\n1 1\n1 3\n1 4\n3 1... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
For a set $S$ of integers, perform a sequence of the following operations. Note that multiple elements can have equivalent values in $S$.
* insert($x$): Insert $x$ to $S$ and report ... |
1017_D. The Wu_21876 | Childan is making up a legendary story and trying to sell his forgery — a necklace with a strong sense of "Wu" to the Kasouras. But Mr. Kasoura is challenging the truth of Childan's story. So he is going to ask a few questions about Childan's so-called "personal treasure" necklace.
This "personal treasure" is a multis... | from sys import stdin
def main():
n, m, q = map(int, input().split())
c = sz = 1 << n
costs, cnt = [0] * sz, [0] * sz
for w in map(int, input().split()):
c //= 2
for i in range(c, sz, c * 2):
for j in range(i, i + c):
costs[j] += w
for i, c in enumerate(... | {
"input": [
"2 4 5\n40 20\n01\n01\n10\n11\n00 20\n00 40\n11 20\n11 40\n11 60\n",
"1 2 4\n100\n0\n1\n0 0\n0 100\n1 0\n1 100\n",
"12 1 1\n0 1 2 3 4 5 6 7 8 9 10 11\n001010001000\n001010001000 100\n",
"1 1 1\n67\n0\n1 47\n",
"12 1 1\n0 1 2 3 4 5 6 7 0 9 10 11\n001010001000\n001010001000 100\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Childan is making up a legendary story and trying to sell his forgery — a necklace with a strong sense of "Wu" to the Kasouras. But Mr. Kasoura is challenging the truth of Childan's s... |
1041_A. Heist_21880 | There was an electronic store heist last night.
All keyboards which were in the store yesterday were numbered in ascending order from some integer number x. For example, if x = 4 and there were 3 keyboards in the store, then the devices had indices 4, 5 and 6, and if x = 10 and there were 7 of them then the keyboards ... | def heist(n,a):
return max(a)-min(a)-n+1
n=int(input())
a=list(map(int,input().split()))
print(heist(n,a)) | {
"input": [
"4\n10 13 12 8\n",
"5\n7 5 6 4 8\n",
"3\n1000000000 500000000 2\n",
"2\n500000000 500000001\n",
"2\n10 1\n",
"2\n999999998 1000000000\n",
"2\n10000000 100000000\n",
"10\n2830 6117 3663 4414 7223 6665 1779 5891 7065 6591\n",
"40\n194 121 110 134 172 142 195 135 186 187 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There was an electronic store heist last night.
All keyboards which were in the store yesterday were numbered in ascending order from some integer number x. For example, if x = 4 and... |
1105_C. Ayoub and Lost Array_21888 | Ayoub had an array a of integers of size n and this array had two interesting properties:
* All the integers in the array were between l and r (inclusive).
* The sum of all the elements was divisible by 3.
Unfortunately, Ayoub has lost his array, but he remembers the size of the array n and the numbers l and... | MOD = 10**9 + 7
n,l,r = map(int,input().split())
dp = [[ 0,0,0]for i in range(n+1)]
# In condition l <= x <= r , mod 0,1,2 number count(define a,b,c)
a = r//3 - (l - 1)//3
b = (r+1)//3 - (l - 1 + 1)//3
c = (r+2)//3 - (l - 1 + 2)//3
#example
#l = 2 , r = 10
#a = 10//3 - 1//3 = 3 - 0 = 3 (3,6,9)
#b = 11//3 - 2//3 =... | {
"input": [
"9 9 99\n",
"2 1 3\n",
"3 2 2\n",
"1561 27096 939571\n",
"1050 1 982008957\n",
"200000 1 1000000000\n",
"3 1000000000 1000000000\n",
"142972 686320621 866589707\n",
"100 1 2\n",
"64 759746120 905671814\n",
"120881 536336525 585696606\n",
"557 686714962 9408... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Ayoub had an array a of integers of size n and this array had two interesting properties:
* All the integers in the array were between l and r (inclusive).
* The sum of all the... |
1153_B. Serval and Toy Bricks_21894 | Luckily, Serval got onto the right bus, and he came to the kindergarten on time. After coming to kindergarten, he found the toy bricks very funny.
He has a special interest to create difficult problems for others to solve. This time, with many 1 × 1 × 1 toy bricks, he builds up a 3-dimensional object. We can describe ... | import sys, os, re, datetime
from collections import *
from bisect import *
def mat(v, *dims):
def submat(i):
if i == len(dims)-1: return [v for _ in range(dims[-1])]
return [submat(i+1) for _ in range(dims[i])]
return submat(0)
__cin__ = None
def cin():
global __cin__
if __cin__ is None... | {
"input": [
"4 5 5\n3 5 2 0 4\n4 2 5 4\n0 0 0 0 1\n1 0 1 0 0\n0 1 0 0 0\n1 1 1 0 0\n",
"3 7 3\n2 3 0 0 2 0 1\n2 1 3\n1 0 0 0 1 0 0\n0 0 0 0 0 0 1\n1 1 0 0 0 0 0\n",
"2 58 77\n0 0 0 0 6 0 0 0 40 0 0 0 0 22 0 0 41 74 0 0 0 0 0 0 0 15 0 0 60 5 69 0 0 30 0 0 23 60 0 35 0 0 0 0 0 0 69 0 0 0 0 0 0 0 0 0 0 0\n0... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Luckily, Serval got onto the right bus, and he came to the kindergarten on time. After coming to kindergarten, he found the toy bricks very funny.
He has a special interest to create... |
1175_A. From Hero to Zero_21898 | You are given an integer n and an integer k.
In one step you can do one of the following moves:
* decrease n by 1;
* divide n by k if n is divisible by k.
For example, if n = 27 and k = 3 you can do the following steps: 27 → 26 → 25 → 24 → 8 → 7 → 6 → 2 → 1 → 0.
You are asked to calculate the minimum numbe... | import math
t=int(input())
for _ in range(t):
n,k=map(int,input().split())
count=0
a,b=int(n//k),int(n%k)
while n>0:
if k>n:
a,b=0,int(n%k)
else:
a,b=math.floor(n//k),int(n%k)
n=a
if a==0:
count+=b
else:
count+=(b+1)
print(count) | {
"input": [
"2\n59 3\n1000000000000000000 10\n",
"1\n2 99\n",
"3\n99 97\n30 30\n20 25\n",
"93\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an integer n and an integer k.
In one step you can do one of the following moves:
* decrease n by 1;
* divide n by k if n is divisible by k.
For example, if ... |
1231_C. Increasing Matrix_21905 | In this problem, a n × m rectangular matrix a is called increasing if, for each row of i, when go from left to right, the values strictly increase (that is, a_{i,1}<a_{i,2}<...<a_{i,m}) and for each column j, when go from top to bottom, the values strictly increase (that is, a_{1,j}<a_{2,j}<...<a_{n,j}).
In a given ma... | def main():
n, m = map(int, input().split())
l = list(list(map(int, input().split()))[::-1] for _ in range(n))[::-1]
for r0, r1 in zip(l, l[1:-1]):
for i, a in enumerate(r1[1:-1], 1):
if not a:
r1[i] = min(r1[i - 1], r0[i]) - 1
print(sum(map(sum, l)) if all(r1[i - 1] ... | {
"input": [
"3 3\n1 2 3\n2 0 4\n4 5 6\n",
"3 3\n1 2 3\n2 3 4\n3 4 2\n",
"4 5\n1 3 5 6 7\n3 0 7 0 9\n5 0 0 0 10\n8 9 10 11 12\n",
"3 3\n1 2 3\n3 0 4\n4 5 6\n",
"3 3\n1 2 3\n2 3 4\n3 5 5\n",
"3 3\n2999 3000 4000\n3000 0 7000\n4000 6000 8000\n",
"8 5\n2 3 6 7 9\n4 0 0 0 12\n5 7 0 9 15\n6 0 0... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In this problem, a n × m rectangular matrix a is called increasing if, for each row of i, when go from left to right, the values strictly increase (that is, a_{i,1}<a_{i,2}<...<a_{i,m... |
1272_E. Nearest Opposite Parity_21909 | You are given an array a consisting of n integers. In one move, you can jump from the position i to the position i - a_i (if 1 ≤ i - a_i) or to the position i + a_i (if i + a_i ≤ n).
For each position i from 1 to n you want to know the minimum the number of moves required to reach any position j such that a_j has the ... |
input()
n=map(int,input().split())
n=list(n)
ans=len(n)*[-1]
a=[]
go=[[] for _ in range(len(n))]
for i,x in enumerate(n):
for y in (x,-x):
y+=i
if y>=0 and y<len(n):
if x%2!=n[y]%2:
ans[i]=1
a.append(i)
else:
go[y].append(i)
w... | {
"input": [
"10\n4 5 7 6 7 5 4 4 6 4\n",
"150\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an array a consisting of n integers. In one move, you can jump from the position i to the position i - a_i (if 1 ≤ i - a_i) or to the position i + a_i (if i + a_i ≤ n).
... |
1295_F. Good Contest_21912 | An online contest will soon be held on ForceCoders, a large competitive programming platform. The authors have prepared n problems; and since the platform is very popular, 998244351 coder from all over the world is going to solve them.
For each problem, the authors estimated the number of people who would solve it: fo... | import sys
from itertools import chain
readline = sys.stdin.readline
MOD = 998244353
def compress(L):
L2 = list(set(L))
L2.sort()
C = {v : k for k, v in enumerate(L2)}
return L2, C
N = int(readline())
LR = [tuple(map(int, readline().split())) for _ in range(N)]
LR = [(a-1, b) for a, b in LR]
LR2 = LR... | {
"input": [
"2\n1 1\n0 0\n",
"2\n1 1\n1 1\n",
"2\n42 1337\n13 420\n",
"3\n1 2\n1 2\n1 2\n",
"10\n2139 77689\n7692 31588\n39321 54942\n48988 55097\n46970 54864\n61632 70126\n4240 37374\n69600 79133\n69308 91118\n12408 56672\n",
"50\n16 47\n24 34\n12 78\n72 91\n68 98\n22 76\n44 66\n12 65\n65 81... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
An online contest will soon be held on ForceCoders, a large competitive programming platform. The authors have prepared n problems; and since the platform is very popular, 998244351 c... |
1338_B. Edge Weight Assignment_21918 | You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold:
* For every two different leaves v_{1} and v_{2} of this tree, [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of weights of all edges on the simple path between v_... | import sys
# try:
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
# except:
# pass
input = sys.stdin.readline
def DFS(i):
visited = {i:True}
stack = [(i,0)]
while len(stack)!=0:
tail,depth = stack.pop(-1)
flag = True
for each in neigh[tail]:
if each not in visited:
visit... | {
"input": [
"6\n1 3\n2 3\n3 4\n4 5\n4 6\n",
"6\n1 3\n2 3\n3 4\n4 5\n5 6\n",
"7\n1 2\n2 7\n3 4\n4 7\n5 6\n6 7\n",
"5\n1 2\n2 3\n1 4\n4 5\n",
"4\n1 2\n2 3\n3 4\n",
"3\n1 2\n2 3\n",
"5\n1 5\n2 5\n3 5\n4 5\n",
"5\n1 2\n2 3\n1 4\n3 5\n",
"5\n1 2\n2 3\n2 4\n4 5\n",
"6\n1 3\n2 3\n3 6... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold:
* For every two different leaves v_{1} and v_{... |
1360_A. Minimal Square_21922 | Find the minimum area of a square land on which you can place two identical rectangular a × b houses. The sides of the houses should be parallel to the sides of the desired square land.
Formally,
* You are given two identical rectangles with side lengths a and b (1 ≤ a, b ≤ 100) — positive integers (you are given ... | num=int(input(""))
i=0
while i<num:
a,b=(input("")).split()
minimum=min(int(a),int(b))
maximum=max(int(a),int(b))
if minimum*2<maximum:
print(maximum**2)
else:
print((minimum*2)**2)
i+=1
| {
"input": [
"8\n3 2\n4 2\n1 1\n3 1\n4 7\n1 3\n7 4\n100 100\n",
"8\n3 2\n4 2\n1 1\n3 1\n4 7\n1 3\n7 4\n100 101\n",
"8\n3 2\n4 2\n1 1\n3 1\n4 7\n1 2\n7 4\n100 101\n",
"8\n3 2\n4 2\n1 1\n3 1\n1 7\n1 2\n7 4\n100 101\n",
"8\n3 2\n2 2\n1 1\n3 1\n1 11\n1 2\n7 4\n100 101\n",
"8\n3 2\n2 2\n1 1\n4 1\n2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Find the minimum area of a square land on which you can place two identical rectangular a × b houses. The sides of the houses should be parallel to the sides of the desired square lan... |
1380_B. Universal Solution_21926 | Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string s = s_1 s_2 ... s_{n} of length n where each letter is either R, S or P.
While initializing, the bot is choosing a starting index pos (1 ≤ pos ≤ n), and then it can play any numbe... | dic={
'R':'P',
'P':'S',
'S':'R'
}
t=int(input())
for _ in range(t):
S=input()
n=len(S)
r,p,s=[0,0,0]
for i in range(len(S)):
if S[i]=='R':
r=r+1
elif S[i]=='P':
p=p+1
else:
s=s+1
m=max(r,p,s)
if r==m:
print(n*dic['R'... | {
"input": [
"3\nRRRR\nRSP\nS\n",
"3\nRRRR\nRSP\nS\n",
"3\nRRRR\nSSP\nS\n",
"3\nQRRR\nRSP\nS\n",
"3\nRRRR\nSSP\nR\n",
"3\nQRRR\nRSP\nR\n",
"3\nRRSR\nSSP\nS\n",
"3\nRRTR\nSSP\nS\n",
"3\nSRRR\nSSP\nR\n",
"3\nRRTR\nSSP\nR\n",
"3\nRRQR\nRSP\nR\n",
"3\nSQRR\nSSP\nR\n",
"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string s = s_1 s_2 ... s_{n} of length n where eac... |
1400_B. RPG Protagonist_21930 | You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course.
You decided to rob a town's blacksmith and you take a follower with you. You can carry at most p units and your follower — at most f units.
... | # cook your dish here
# cook your dish here
from sys import stdin,stdout
from collections import Counter
from itertools import permutations
import bisect
import math
I=lambda: map(int,stdin.readline().split())
I1=lambda: stdin.readline()
for _ in range(int(I1())):
p,f=I()
cs,cw=I()
s,w=I()
if s>w:
... | {
"input": [
"3\n33 27\n6 10\n5 6\n100 200\n10 10\n5 5\n1 19\n1 3\n19 5\n",
"9\n475033014 267058742\n26843 148652\n850113755 279316120\n871120869 885251487\n51363 15651\n220811492 256297120\n473761699 194406678\n38725 23371\n167395720 333327477\n107541472 19164492\n74340 1113\n654389849 224345301\n663158140 4... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course.
You... |
1424_B. Valuable Paper_21933 | The pandemic is upon us, and the world is in shortage of the most important resource: toilet paper. As one of the best prepared nations for this crisis, BubbleLand promised to help all other world nations with this valuable resource. To do that, the country will send airplanes to other countries carrying toilet paper.
... | import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
import os
self.os = os
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or ... | {
"input": [
"3 5\n1 2 1\n2 3 2\n3 3 3\n2 1 4\n2 2 5\n",
"5 12\n1 3 1\n2 3 1\n3 1 1\n3 2 1\n1 4 1\n2 4 1\n4 1 1\n4 2 1\n1 5 1\n2 5 1\n5 1 1\n5 2 1\n",
"5 9\n3 3 8\n2 4 7\n2 3 6\n2 1 9\n5 1 3\n1 1 6\n4 3 6\n4 1 2\n4 2 3\n",
"5 7\n1 1 1\n1 2 1\n2 3 1\n2 4 1\n3 5 1\n4 5 1\n5 5 1\n",
"5 8\n1 1 1\n1 2 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The pandemic is upon us, and the world is in shortage of the most important resource: toilet paper. As one of the best prepared nations for this crisis, BubbleLand promised to help al... |
1469_D. Ceil Divisions_21940 | You have an array a_1, a_2, ..., a_n where a_i = i.
In one step, you can choose two indices x and y (x ≠ y) and set a_x = \left⌈ (a_x)/(a_y) \right⌉ (ceiling function).
Your goal is to make array a consist of n - 1 ones and 1 two in no more than n + 5 steps. Note that you don't have to minimize the number of steps.
... |
import math
def solution() :
for tc in range(int(input())) :
n = int(input())
ls = [i for i in range(1, n+1)]
ans = []
for i in range(n-2, 0, -1) :
while math.ceil(ls[n-1] / ls[i]) >= ls[i] :
ans.append([n, i+1])
ls[n-1] = math.ceil(ls[n... | {
"input": [
"2\n3\n4\n",
"1\n6401\n",
"1\n2653\n",
"1\n1443\n",
"1\n915\n",
"1\n1749\n",
"1\n2493\n",
"1\n1644\n",
"1\n2077\n",
"1\n218\n",
"1\n212\n",
"1\n43\n",
"1\n41\n",
"1\n2\n",
"1\n4\n",
"1\n3\n",
"1\n6\n",
"1\n12\n",
"1\n2406\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You have an array a_1, a_2, ..., a_n where a_i = i.
In one step, you can choose two indices x and y (x ≠ y) and set a_x = \left⌈ (a_x)/(a_y) \right⌉ (ceiling function).
Your goal is... |
1517_E. Group Photo_21945 | In the 2050 Conference, some people from the competitive programming community meet together and are going to take a photo. The n people form a line. They are numbered from 1 to n from left to right. Each of them either holds a cardboard with the letter 'C' or a cardboard with the letter 'P'.
Let C=\\{c_1,c_2,...,c_m\... | import sys,io,os
try:Z=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
except:Z=lambda:sys.stdin.readline().encode()
Y=lambda:map(int,Z().split())
from bisect import bisect
M=998244353
def add(a,b):
v=a+b
if v>=M:v-=M
if v<0:v+=M
return v
def sol(n,a,disp=0):
if n<2:return 1
if n<3:return 2-... | {
"input": [
"3\n5\n2 1 2 1 1\n4\n9 2 2 2\n1\n998244353\n",
"3\n5\n2 1 2 1 1\n4\n11 2 2 2\n1\n998244353\n",
"3\n5\n1 1 2 1 1\n4\n11 2 2 2\n1\n998244353\n",
"3\n5\n2 2 2 1 1\n4\n11 2 2 2\n1\n998244353\n",
"3\n5\n1 1 1 1 1\n4\n11 2 3 2\n1\n998244353\n",
"3\n5\n1 1 0 1 1\n4\n11 2 2 3\n1\n99824435... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In the 2050 Conference, some people from the competitive programming community meet together and are going to take a photo. The n people form a line. They are numbered from 1 to n fro... |
172_C. Bus_21950 | There is a bus stop near the university. The lessons are over, and n students come to the stop. The i-th student will appear at the bus stop at time ti (all ti's are distinct).
We shall assume that the stop is located on the coordinate axis Ox, at point x = 0, and the bus goes along the ray Ox, that is, towards the po... | from collections import defaultdict
n, m = map(int, input().split())
r, p = [0] * n, defaultdict(list)
i = d = 0
while i < n - m:
for j in range(i, i + m):
t, x = map(int, input().split())
p[x].append(j)
d = max(t, d)
y = sorted(p.keys())
for x in y:
for j in p[x]: r[j] = d + x
... | {
"input": [
"20 4\n28 13\n31 13\n35 6\n36 4\n52 6\n53 4\n83 2\n84 4\n87 1\n93 6\n108 4\n113 6\n116 1\n125 2\n130 2\n136 13\n162 2\n166 4\n184 1\n192 2\n",
"2 1\n3 5\n4 5\n",
"5 4\n3 5\n4 5\n5 5\n6 5\n7 1\n",
"1 10\n3 5\n",
"16 1\n29 10\n48 13\n53 10\n54 5\n59 6\n67 9\n68 10\n95 13\n132 5\n148 6\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is a bus stop near the university. The lessons are over, and n students come to the stop. The i-th student will appear at the bus stop at time ti (all ti's are distinct).
We sh... |
192_D. Demonstration_21954 | In the capital city of Berland, Bertown, demonstrations are against the recent election of the King of Berland. Berland opposition, led by Mr. Ovalny, believes that the elections were not fair enough and wants to organize a demonstration at one of the squares.
Bertown has n squares, numbered from 1 to n, they are numb... | from sys import stdin, stdout
n, k = map(int, stdin.readline().split())
value = int(stdin.readline())
prices = list(map(int, stdin.readline().split()))
used = {}
challengers = prices[:-1]
for i in range(n - 1):
challengers[i] = (challengers[i], i)
challengers.sort(reverse = True)
ind = challengers[k - 1][1]
cn... | {
"input": [
"5 2\n8\n2 4 5 3 1\n",
"5 4\n1000000000000000\n5 4 3 2 1\n",
"5 2\n8\n3 2 4 1 5\n",
"10 9\n624\n47 56 60 51 88 82 77 83 89 100\n",
"10 2\n1523\n661 230 363 300 28 72 676 741 837 984\n",
"100 10\n9199\n89 409 428 408 309 400 259 393 212 273 472 654 533 774 663 484 695 801 587 518 5... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In the capital city of Berland, Bertown, demonstrations are against the recent election of the King of Berland. Berland opposition, led by Mr. Ovalny, believes that the elections were... |
216_D. Spider's Web_21958 | Paw the Spider is making a web. Web-making is a real art, Paw has been learning to do it his whole life. Let's consider the structure of the web.
<image>
There are n main threads going from the center of the web. All main threads are located in one plane and divide it into n equal infinite sectors. The sectors are in... | #------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
# from fractions import *
# from heapq import*
from bisect import *
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')... | {
"input": [
"7\n3 1 6 7\n4 3 5 2 9\n2 8 1\n4 3 7 6 4\n3 2 5 9\n3 6 3 8\n3 4 2 9\n",
"4\n5 2 6 10 8 3\n1 7\n2 10 4\n2 9 5\n",
"5\n3 12 10 19\n5 1 4 18 11 13\n4 17 15 2 6\n4 3 12 18 10\n4 2 8 5 9\n",
"10\n1 77966\n1 79480\n1 94920\n1 53920\n1 15585\n1 57339\n1 1585\n1 91802\n1 27934\n1 20354\n",
"5... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Paw the Spider is making a web. Web-making is a real art, Paw has been learning to do it his whole life. Let's consider the structure of the web.
<image>
There are n main threads go... |
265_B. Roadside Trees (Simplified Edition)_21964 | Squirrel Liss loves nuts. There are n trees (numbered 1 to n from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree i is hi. Liss wants to eat all nuts.
Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the following act... | n = int(input())
l = []
for _ in range(n):
l.append(int(input()))
t = len(l)
current = 0
t+=l[0]-current
current = l[0]
for i in range(1,n):
if current<=l[i]:
t+=1+l[i]-current
current = l[i]
else:
t += 1+current-l[i]
current = l[i]
print(t)
| {
"input": [
"5\n2\n1\n2\n1\n1\n",
"2\n1\n2\n",
"1\n1\n",
"2\n1\n0\n",
"2\n2\n0\n",
"2\n2\n1\n",
"1\n2\n",
"5\n2\n1\n2\n2\n1\n",
"2\n3\n0\n",
"2\n4\n1\n",
"1\n3\n",
"5\n3\n1\n2\n2\n1\n",
"5\n3\n1\n2\n3\n1\n",
"2\n4\n0\n",
"2\n5\n1\n",
"2\n5\n0\n",
"5... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Squirrel Liss loves nuts. There are n trees (numbered 1 to n from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree i is hi. Li... |
289_B. Polo the Penguin and Matrix_21968 | Little penguin Polo has an n × m matrix, consisting of integers. Let's index the matrix rows from 1 to n from top to bottom and let's index the columns from 1 to m from left to right. Let's represent the matrix element on the intersection of row i and column j as aij.
In one move the penguin can add or subtract number... | n,m,d=map(int,input().split())
x=[]
y=[]
for i in range(n):
a=list(map(int,input().split()))
y+=a
x.append(a)
y.sort()
e=y[(0+n*m-1)//2]
a=x[0][0]%d
count=0
ans=0
for i in x:
for j in range(len(i)):
if(i[j]%d!=a):
pass
else:
count+=1
ans+=(max(i[j],e)-... | {
"input": [
"1 2 7\n6 7\n",
"2 2 2\n2 4\n6 8\n",
"7 4 5\n7 7 7 12\n7 12 12 7\n7 7 7 7\n7 7 12 7\n7 7 12 12\n12 12 7 12\n7 7 7 7\n",
"3 3 3\n5 8 5\n11 11 17\n14 5 2\n",
"7 7 47\n47 47 47 47 47 47 47\n47 47 47 47 77 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 47 47\n47 47 47 4... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Little penguin Polo has an n × m matrix, consisting of integers. Let's index the matrix rows from 1 to n from top to bottom and let's index the columns from 1 to m from left to right.... |
314_B. Sereja and Periods_21972 | Let's introduce the designation <image>, where x is a string, n is a positive integer and operation " + " is the string concatenation operation. For example, [abc, 2] = abcabc.
We'll say that string s can be obtained from string t, if we can remove some characters from string t and obtain string s. For example, string... | b, p = map(int, input().split())
s1 = input()
s2 = input()
cnt = [0] * len(s2)
nxt = [0] * len(s2)
for i in range(len(s2)):
pos = i
for j in range(len(s1)):
if s1[j] == s2[pos]:
pos += 1
if pos == len(s2):
cnt[i] += 1
pos = 0
nxt[i]... | {
"input": [
"10 3\nabab\nbab\n",
"541 9\nbxhwcmunbdxcatppdsw\nshbppncwbnsxxnxunwsbncpdchcbcspdcppdchmbbcuapphpdxbpcswcxpxpdscxpddbcppdxhpxbuxxdbpdpuudb\n",
"8058035 2\nrioqrqetkzfbldjiemsfzbhzfnwywmxxgdpyl\ngfmhefhyyndzmsbfnefmwmpxfxfhflzplgoxfrrdxilibzlephlezisfztsfitnrzrilzmtipzofkrwlmhnifdzwexzzxjpy\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Let's introduce the designation <image>, where x is a string, n is a positive integer and operation " + " is the string concatenation operation. For example, [abc, 2] = abcabc.
We'll... |
430_D. Working out_21986 | Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and m columns. Let number a[i][j] represents the calories burned by performing workout at the cell of gym in the i-th line and the j-th column.
Iahub starts with ... | n,m=map(int,input().split())
a=[]
for i in range(n):a.append(list(map(int,input().split())))
dpa=[[[0,0] for i in range(m+2)] for i in range(n+2)]
dpb=[[[0,0] for i in range(m+2)] for i in range(n+2)]
ans=0
for i in range(1,n+1):
for j in range(1,m+1):
dpa[i][j][0]=max(dpa[i-1][j][0],dpa[i][j-1][0])+a[i-1][j-1]
dp... | {
"input": [
"3 3\n100 100 100\n100 1 100\n100 100 100\n",
"3 3\n0 0 0\n0 10000 0\n0 0 0\n",
"3 3\n1 10 1\n1 10 1\n1 10 1\n",
"3 3\n0 0 0\n0 100 0\n0 0 0\n",
"4 5\n87882 40786 3691 85313 46694\n28884 16067 3242 97367 78518\n4250 35501 9780 14435 19004\n64673 65438 56977 64495 27280\n",
"3 3\n1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and m columns. Let number ... |
453_A. Little Pony and Expected Maximum_21990 | Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game.
The dice has m faces: the first face of the dice contains a dot, the second one contains two dots, ... | def main():
m, n = map(int, input().split())
print(sum((i + 1) * (((i + 1) / m) ** n - (i / m) ** n) for i in range(m)))
if __name__ == '__main__':
main() | {
"input": [
"2 2\n",
"6 1\n",
"6 3\n",
"94444 9\n",
"50000 50000\n",
"1 8\n",
"100000 5001\n",
"50323 7\n",
"24236 90163\n",
"51520 73331\n",
"54230 31747\n",
"3 6\n",
"99999 1111\n",
"26946 99523\n",
"3 10\n",
"99999 99999\n",
"53513 34040\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in ... |
523_B. Mean Requests_21998 | In this problem you will have to deal with a real algorithm that is used in the VK social network.
As in any other company that creates high-loaded websites, the VK developers have to deal with request statistics regularly. An important indicator reflecting the load of the site is the mean number of requests for a cer... | __author__ = 'ruckus'
n, T, c = input().split()
n = int(n)
T = int(T)
c = float(c)
a = list(map(int, input().split()))
m = int(input())
q = list(map(int, input().split()))
res_a = 0
real = 0
maxi_q = max(q)
q_n = 0
for i in range(q[-1]):
res_a = (res_a + a[i] / T) / c
real += a[i]
if i >= T:
real -=... | {
"input": [
"13 4 1.250000\n3 3 3 3 3 20 3 3 3 3 3 3 3\n10\n4 5 6 7 8 9 10 11 12 13\n",
"11 4 1.250000\n9 11 7 5 15 6 6 6 6 6 6\n8\n4 5 6 7 8 9 10 11\n",
"1 1 2.000000\n1\n1\n1\n",
"1 1 2.000000\n758432\n1\n1\n",
"64 3 1.333333\n1337 1913 135 885 1567 1049 1116 368 350 725 517 1874 588 918 1923 9... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In this problem you will have to deal with a real algorithm that is used in the VK social network.
As in any other company that creates high-loaded websites, the VK developers have t... |
549_H. Degenerate Matrix_22002 | The determinant of a matrix 2 × 2 is defined as follows:
<image>
A matrix is called degenerate if its determinant is equal to zero.
The norm ||A|| of a matrix A is defined as a maximum of absolute values of its elements.
You are given a matrix <image>. Consider any degenerate matrix B such that norm ||A - B|| is m... | A,B,C,D=map(int,(input()+' '+input()).split());k=max(map(abs,[A+B+C+D,A+B-C-D,A-B+C-D,A-B-C+D]))+1e-9;print(abs(A*D-B*C)/k) | {
"input": [
"1 0\n0 1\n",
"1 2\n3 4\n",
"12 180\n79 47\n",
"116954418 255136645\n-851641472 174491320\n",
"95145788 53456393\n42406028 83987544\n",
"-2665612 -7693032\n-2861368 -6201836\n",
"-67 -77\n-56 -75\n",
"-2 1\n1 -2\n",
"-718 -387\n972 972\n",
"-1 -1\n1 0\n",
"8205... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The determinant of a matrix 2 × 2 is defined as follows:
<image>
A matrix is called degenerate if its determinant is equal to zero.
The norm ||A|| of a matrix A is defined as a ma... |
576_A. Vasya and Petya's Game_22006 | Vasya and Petya are playing a simple game. Vasya thought of number x between 1 and n, and Petya tries to guess the number.
Petya can ask questions like: "Is the unknown number divisible by number y?".
The game is played by the following rules: first Petya asks all the questions that interest him (also, he can ask no ... | def input_ints():
return list(map(int, input().split()))
def main():
n = int(input())
ans = []
for x in range(2, n + 1):
s = set()
xx = x
for y in range(2, n + 1):
while xx % y == 0:
xx /= y
s.add(y)
if len(s) == 1:
... | {
"input": [
"4\n",
"6\n",
"1000\n",
"907\n",
"20\n",
"44\n",
"289\n",
"211\n",
"953\n",
"729\n",
"37\n",
"998\n",
"625\n",
"784\n",
"31\n",
"15\n",
"322\n",
"19\n",
"557\n",
"1\n",
"30\n",
"900\n",
"400\n",
"894\n",
"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya and Petya are playing a simple game. Vasya thought of number x between 1 and n, and Petya tries to guess the number.
Petya can ask questions like: "Is the unknown number divisi... |
598_E. Chocolate Bar_22009 | You have a rectangular chocolate bar consisting of n × m single squares. You want to eat exactly k squares, so you may need to break the chocolate bar.
In one move you can break any single rectangular piece of chocolate in two rectangular pieces. You can break only by lines between squares: horizontally or vertically... | d = [0] * 49011
def g(n, m, k):
t = 1e9
for i in range(1, m // 2 + 1):
for j in range(k + 1):
t = min(t, f(n, m - i, k - j) + f(n, i, j))
return n * n + t
def f(n, m, k):
if n > m: n, m = m, n
k = min(k, n * m - k)
if k == 0: return 0
if k < 0: return 1e9
q = n + 31... | {
"input": [
"4\n2 2 1\n2 2 3\n2 2 2\n2 2 4\n",
"4\n2 2 1\n2 2 1\n2 2 2\n2 2 4\n",
"4\n2 2 2\n2 2 1\n2 2 2\n2 2 4\n",
"4\n2 2 4\n2 2 1\n2 2 2\n2 2 4\n",
"4\n2 1 1\n2 2 3\n2 2 2\n2 2 4\n",
"4\n2 1 1\n2 2 3\n2 2 2\n4 2 4\n",
"4\n2 2 2\n2 2 1\n4 2 2\n2 2 2\n",
"4\n2 1 1\n2 3 3\n2 2 2\n4 2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You have a rectangular chocolate bar consisting of n × m single squares. You want to eat exactly k squares, so you may need to break the chocolate bar.
In one move you can break any... |
61_C. Capture Valerian_22013 | It's now 260 AD. Shapur, being extremely smart, became the King of Persia. He is now called Shapur, His majesty King of kings of Iran and Aniran.
Recently the Romans declared war on Persia. They dreamed to occupy Armenia. In the recent war, the Romans were badly defeated. Now their senior army general, Philip is captu... | n, m = input().split()
b = input()
if b.isdigit() and int(b) == 0:
print(int(b))
elif n == m:
print(b)
else:
n= int(n)
st1 = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]
st2 =['0', '1','2','3','4','5','6','7','8','9','A','B','C','D', 'E', 'F','G','H','I','J','K','L','M','N','O','P','Q']
... | {
"input": [
"2 2\n1111001\n",
"12 13\nA\n",
"5 R\n4\n",
"10 2\n1\n",
"16 R\n5\n",
"21 21\n2G3DK3F23905\n",
"3 R\n2\n",
"20 5\n1FAD98HHG13G\n",
"10 10\n100000000000\n",
"2 R\n1\n",
"10 R\n1137\n",
"10 R\n999\n",
"15 11\n760595A635B24\n",
"19 12\nEHIAG4GG072\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
It's now 260 AD. Shapur, being extremely smart, became the King of Persia. He is now called Shapur, His majesty King of kings of Iran and Aniran.
Recently the Romans declared war on ... |
63_B. Settlers' Training_22017 | In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly n soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either inc... | """
Oh, Grantors of Dark Disgrace,
Do Not Wake Me Again.
"""
from collections import Counter
n, k = map(int, input().split())
cc = Counter(map(int, input().split()))
coins = 0
while cc[k] != n:
t = 0
for i in range(1, k):
if t+1 <= cc[i]:
cc[i] -= 1
cc[i+1] += 1
t... | {
"input": [
"4 4\n1 2 2 3\n",
"4 3\n1 1 1 1\n",
"10 100\n98 99 99 99 99 99 99 100 100 100\n",
"1 5\n1\n",
"17 9\n2 3 4 5 5 5 5 5 6 6 7 7 8 8 8 8 8\n",
"10 10\n1 1 1 3 3 4 7 8 8 8\n",
"81 90\n1 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense struct... |
667_E. Chain Reaction_22020 | Group of Berland scientists, with whom you have a close business relationship, makes a research in the area of peaceful nuclear energy. In particular, they found that a group of four nanobots, placed on a surface of a plate, can run a powerful chain reaction under certain conditions.
To be precise, researchers introd... | import sys
sys.stderr = sys.stdout
from collections import namedtuple
Bot = namedtuple('Bot', ('x', 'y', 'i'))
def yxi(bot):
return bot.y, bot.x, bot.i
def reaction1(B, V):
Bv = sorted(B[i] for i in range(4) if V[i])
Bh = sorted((B[i] for i in range(4) if not V[i]), key=yxi)
S = [None] * 4
if... | {
"input": [
"2\n1 1\n1 -1\n-1 1\n-1 -1\n1 1\n2 2\n4 4\n6 6\n",
"1\n7434523 11523154\n7611807 5876512\n3910524 11523154\n3373024 5876512\n",
"1\n-100000000 -100000000\n100000000 -100000000\n-100000000 100000000\n100000000 99999999\n",
"1\n3 0\n5 0\n4 9\n5 9\n",
"1\n35 23\n49 28\n28 28\n23 23\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Group of Berland scientists, with whom you have a close business relationship, makes a research in the area of peaceful nuclear energy. In particular, they found that a group of four ... |
714_B. Filya and Homework_22026 | Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers a1, a2, ..., an. First, he pick an integer x and then he adds x to some elements of the array (no more than once), subtract x ... | n=int(input())
s=set()
L=[ int(x) for x in input().split() ]
for i in L :
s.add(i)
if ( len(s) > 3 ) :
print("NO")
elif (len(s) == 1 or len(s) == 2 ) :
print("YES")
else :
L=[]
for i in s :
L.append(i)
L.sort()
a,b,c = L[0], L[1], L[2]
if ( b-a == c-b ):
print("YES")
... | {
"input": [
"5\n1 3 3 2 1\n",
"5\n1 2 3 4 5\n",
"3\n0 3 5\n",
"3\n1 2 3\n",
"4\n0 2 3 4\n",
"3\n0 1 5\n",
"5\n1 4 4 4 6\n",
"3\n2 3 8\n",
"3\n1 1 2\n",
"3\n1 3 4\n",
"5\n3 6 7 8 9\n",
"3\n2 1 3\n",
"2\n100000001 100000003\n",
"3\n1 6 10\n",
"7\n1 1 1 1 1 2 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negativ... |
734_E. Anton and Tree_22030 | Anton is growing a tree in his garden. In case you forgot, the tree is a connected acyclic undirected graph.
There are n vertices in the tree, each of them is painted black or white. Anton doesn't like multicolored trees, so he wants to change the tree such that all vertices have the same color (black or white).
To c... | def main():
n = int(input())
colors = input()[::2]
dsu = list(range(n))
edges = [[] for _ in range(n)]
for _ in range(n - 1):
u, v = map(int, input().split())
u -= 1
v -= 1
if colors[u] == colors[v]:
a, b = dsu[u], dsu[v]
while a != dsu[a]:
... | {
"input": [
"11\n0 0 0 1 1 0 1 0 0 1 1\n1 2\n1 3\n2 4\n2 5\n5 6\n5 7\n3 8\n3 9\n3 10\n9 11\n",
"4\n0 0 0 0\n1 2\n2 3\n3 4\n",
"2\n1 0\n2 1\n",
"1\n0\n",
"15\n0 1 0 0 1 1 0 1 1 1 1 1 0 1 0\n10 7\n10 3\n10 8\n5 7\n13 14\n8 13\n15 4\n15 13\n5 2\n9 3\n11 15\n13 6\n1 12\n9 1\n",
"42\n1 0 0 1 0 1 1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Anton is growing a tree in his garden. In case you forgot, the tree is a connected acyclic undirected graph.
There are n vertices in the tree, each of them is painted black or white.... |
803_B. Distances to Zero_22038 | You are given the array of integer numbers a0, a1, ..., an - 1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array.
Input
The first line contains integer n (1 ≤ n ≤ 2·105) — length of the array a. The second line contains... | import sys
n = int(sys.stdin.readline())
a = sys.stdin.readline().strip().split()
def findDistancesToZero(n,a):
pos_zero_left = a.index('0')
pos_zero_right = a.index('0')
pos = 0
positions = ''
while pos<n:
worked = False
while pos<=pos_zero_right:
print(st... | {
"input": [
"7\n5 6 0 1 -2 3 4\n",
"5\n0 1 2 3 4\n",
"9\n2 1 0 3 0 0 3 2 4\n",
"5\n0 0 0 0 -1000000000\n",
"8\n0 -1000000000 1000000000 1000000000 1000000000 -1000000000 1000000000 1000000000\n",
"5\n1000000000 0 -1000000000 0 -1000000000\n",
"5\n-1000000000 -1000000000 0 1000000000 10000... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given the array of integer numbers a0, a1, ..., an - 1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zer... |
84_A. Toy Army_22044 | The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows.
There are two armies on the playing field each of which consists of n men (n is always even). The current player sp... | n=int(input())
print((n*3)//2)
| {
"input": [
"2\n",
"4\n",
"8457980\n",
"100000000\n",
"6\n",
"8\n",
"5687986\n",
"59790\n",
"10984932\n",
"99999994\n",
"10\n",
"2000\n",
"10000\n",
"54646\n",
"1000\n",
"25460\n",
"99999998\n",
"578456\n",
"99999996\n",
"500\n",
"50... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The game... |
898_C. Phone Numbers_22050 | Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers.
Vasya decided to organize information about the phone numbers of friends. You will be given n strings — all entries from Vasya's phone books. Each entry starts with a fri... | n=int(input())
dic={}
for i in range(n):
l=list(map(str,input().split()))
s1=l[0]
if s1 in dic.keys():
dic[l[0]]+=list(set(l[2:]))
else:
dic[l[0]]=list(set(l[2:]))
print(len(dic.keys()))
for ix in dic.keys():
l=dic[ix][:]
ll=len(l)
lln=[1 for i in range(ll)]
for i in rang... | {
"input": [
"4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndasha 2 23 789\n",
"3\nkarl 2 612 12\npetr 1 12\nkatya 1 612\n",
"2\nivan 1 00123\nmasha 1 00123\n",
"1\negew 5 3 123 23 1234 134\n",
"20\nl 6 02 02 2 02 02 2\nl 8 8 8 8 2 62 13 31 3\ne 9 0 91 0 0 60 91 60 2 44\ne 9 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers.
Vasya decided to organize informa... |
919_D. Substring_22054 | You are given a graph with n nodes and m directed edges. One lowercase letter is assigned to each node. We define a path's value as the number of the most frequently occurring letter. For example, if letters on a path are "abaca", then the value of that path is 3. Your task is find a path whose value is the largest.
I... | from collections import defaultdict
import sys
from sys import stdin
def check(a):
for i in a:
if i:
return True
return False
def change(x):
return ord(x)-ord('a')
def solve():
n, m = map(int, stdin.readline().split())
s = input()
d = {}
for i in range(n):
d[i+1... | {
"input": [
"10 14\nxzyzyzyzqx\n1 2\n2 4\n3 5\n4 5\n2 6\n6 8\n6 5\n2 10\n3 9\n10 9\n4 6\n1 10\n2 8\n3 7\n",
"5 4\nabaca\n1 2\n1 3\n3 4\n4 5\n",
"6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4\n",
"1 1\nf\n1 1\n",
"5 8\ntetqw\n2 1\n4 4\n5 5\n5 2\n4 5\n1 5\n1 5\n1 1\n",
"5 8\nreeet\n4 3\n2 5\n4 2\n2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a graph with n nodes and m directed edges. One lowercase letter is assigned to each node. We define a path's value as the number of the most frequently occurring letter.... |
946_C. String Transformation_22058 | You are given a string s consisting of |s| small english letters.
In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace letter z with any other letter.
Your target is to make some number of ... | i = 97
j = 0
s = [x for x in input()]
for item in s:
if item <= chr(i):
s[j] = chr(i)
i += 1
if i>122:
print("".join(s))
break
j += 1
else:
print(-1)
| {
"input": [
"aacceeggiikkmmooqqssuuwwyy\n",
"thereisnoanswer\n",
"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\n",
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n",
"aaadefghijklmnopqrstuvwxyz\n",
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... | 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 |s| small english letters.
In one move you can replace any character of this string to the next character in alphabetical order (a will be repl... |
975_A. Aramic script_22062 | In Aramic language words can only represent objects.
Words in Aramic have special properties:
* A word is a root if it does not contain the same letter more than once.
* A root and all its permutations represent the same object.
* The root x of a word y is the word that contains all letters that appear in y ... | n=int(input())
s=input()
a=s.split(" ")
visited=[]
for i in range(len(a)):
visited.append(0)
arr=[]
for g in range(len(a)):
aux=[]
for h in range(26):
aux.append(0)
arr.append(aux)
for x in range(len(a)):
for y in range(len(a[x])):
if(arr[x][ord(a[x][y])-97]==0):
arr[x][ord(a[x][y])-97]+=1
count_arr=... | {
"input": [
"5\na aa aaa ab abb\n",
"3\namer arem mrea\n",
"10\nbda bbb cda dca dda dcb bcd dcb ada ddd\n",
"2\nfhjlqs aceginpr\n",
"2\nbcdfghimn efghijlmo\n",
"10\ncda bbb cda dca dda dcb bcd dcb ada ddd\n",
"2\nfhjlqs acegjnpr\n",
"3\namer mera mrea\n",
"10\nbda bbb cda dca dda ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In Aramic language words can only represent objects.
Words in Aramic have special properties:
* A word is a root if it does not contain the same letter more than once.
* A roo... |
994_F. Compute Power_22065 | You need to execute several tasks, each associated with number of processors it needs, and the compute power it will consume.
You have sufficient number of analog computers, each with enough processors for any task. Each computer can execute up to one task at a time, and no more than two tasks total. The first task ca... | # Codeforces Round #488 by NEAR (Div. 2)
import collections
from functools import cmp_to_key
#key=cmp_to_key(lambda x,y: 1 if x not in y else -1 )
import math
import sys
def getIntList():
return list(map(int, input().split()))
import bisect
def makePair(z):
return [(z[i], z[i+1]) for i in range(0,le... | {
"input": [
"6\n8 10 9 9 8 10\n1 10 5 5 1 10\n",
"6\n8 10 9 9 8 10\n1 1 1 1 1 1\n",
"10\n99999954 99999947 99999912 99999920 99999980 99999928 99999908 99999999 99999927 99999957\n15 97 18 8 82 21 73 15 28 75\n",
"50\n1 2 7 8 4 9 1 8 3 6 7 2 10 10 4 2 1 7 9 10 10 1 4 7 5 6 1 6 6 2 5 4 5 10 9 9 7 5 5 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You need to execute several tasks, each associated with number of processors it needs, and the compute power it will consume.
You have sufficient number of analog computers, each wit... |
p02769 AtCoder Beginner Contest 156 - Roaming_22080 | There is a building with n rooms, numbered 1 to n.
We can move from any room to any other room in the building.
Let us call the following event a move: a person in some room i goes to another room j~ (i \neq j).
Initially, there was one person in each room in the building.
After that, we know that there were exactl... | n,k=map(int,input().split())
mod=10**9+7
lim=n
fcl=[1]*(lim+1)
for i in range(1,lim+1):
fcl[i]=(fcl[i-1]*i)%mod
def comb(x,y,p):
return ((fcl[x]*pow(fcl[y],p-2,p))%p*pow(fcl[x-y],p-2,p))%p
ans=0
for i in range(min(n,k+1)):
ans+=comb(n-1,n-i-1,mod)*comb(n,i,mod)
ans%=mod
print(ans) | {
"input": [
"3 2",
"200000 1000000000",
"15 6",
"1 2",
"15 8",
"30 6",
"4 2",
"200000 0000001000",
"4 4",
"200000 0000001001",
"5 4",
"200000 0001001001",
"90099 0001001001",
"140753 0011001000",
"135689 0011001000",
"125848 0011001000",
"111965 001... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is a building with n rooms, numbered 1 to n.
We can move from any room to any other room in the building.
Let us call the following event a move: a person in some room i goes ... |
p02904 AtCoder Grand Contest 038 - Sorting a Segment_22083 | Snuke has a permutation (P_0,P_1,\cdots,P_{N-1}) of (0,1,\cdots,N-1).
Now, he will perform the following operation exactly once:
* Choose K consecutive elements in P and sort them in ascending order.
Find the number of permutations that can be produced as P after the operation.
Constraints
* 2 \leq N \leq 200000... | n, k = map(int,input().split())
P = list(map(int,input().split()))
# for i in range(n-k+1):
# pp = P[i:i+k]
# pp.sort()
# print(P[:i] + pp + P[i+k:])
A = []
B = []
VA = [0] * n
VB = [0] * n
import heapq
for i in range(k):
heapq.heappush(A, P[i]) # 最小値用
heapq.heappush(B, -P[i]) # 最大値用
ans = 1
fo... | {
"input": [
"10 4\n2 0 1 3 7 5 4 6 8 9",
"5 3\n0 2 1 4 3",
"4 4\n0 1 2 3",
"10 4\n2 0 1 2 7 5 4 6 8 9",
"5 3\n1 2 1 4 3",
"4 4\n0 1 2 4",
"5 3\n2 2 1 4 3",
"7 4\n1 0 1 2 7 5 4 6 8 9",
"8 4\n1 1 0 4",
"10 4\n2 -1 1 2 7 5 4 6 4 9",
"12 4\n-1 0 2 2 14 9 8 6 3 2",
"13 4\n1... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Snuke has a permutation (P_0,P_1,\cdots,P_{N-1}) of (0,1,\cdots,N-1).
Now, he will perform the following operation exactly once:
* Choose K consecutive elements in P and sort them i... |
p03039 AtCoder Beginner Contest 127 - Cell Distance_22087 | We have a grid of squares with N rows and M columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left. We will choose K of the squares and put a piece on each of them.
If we place the K pieces on squares (x_1, y_1), (x_2, y_2), ..., and (x_K, y_K), the cost of this arrangement is... | n,m,k=map(int,input().split())
mod=10**9+7
f=[1]
for i in range(2*10**5+7):f+=[f[-1]*(i+1)%mod]
def comb(a,b):return f[a]*pow(f[b],mod-2,mod)*pow(f[a-b],mod-2,mod)%mod
ans=0
for i in range(1,n):
ans+=(i*(n-i)*m**2)*(comb(n*m-2,k-2))
ans%=mod
for i in range(1,m):
ans+=(i*(m-i)*n**2)*(comb(n*m-2,k-2))
ans%=mod
pr... | {
"input": [
"2 2 2",
"100 100 5000",
"4 5 4",
"100 100 4270",
"100 100 619",
"100 101 619",
"110 101 619",
"110 101 767",
"110 111 767",
"110 111 32",
"110 111 3",
"100 111 3",
"110 101 3",
"100 101 3",
"4 2 2",
"100 110 5000",
"4 5 7",
"100 100... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We have a grid of squares with N rows and M columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left. We will choose K of the squares and put a... |
p03180 Educational DP Contest - Grouping_22091 | There are N rabbits, numbered 1, 2, \ldots, N.
For each i, j (1 \leq i, j \leq N), the compatibility of Rabbit i and j is described by an integer a_{i, j}. Here, a_{i, i} = 0 for each i (1 \leq i \leq N), and a_{i, j} = a_{j, i} for each i and j (1 \leq i, j \leq N).
Taro is dividing the N rabbits into some number of... | N = int(input())
a = [list(map(int, input().split())) for _ in range(N)]
score = [0]*(1<<N)
for S in range(1<<N):
for i in range(N):
if (S>>i)&1:
for j in range(i+1, N):
if (S>>j)&1:
score[S] += a[i][j]
dp = [-10**18]*(1<<N)
dp[0] = 0
for S in range(1<<... | {
"input": [
"3\n0 10 20\n10 0 -100\n20 -100 0",
"4\n0 1000000000 1000000000 1000000000\n1000000000 0 1000000000 1000000000\n1000000000 1000000000 0 -1\n1000000000 1000000000 -1 0",
"16\n0 5 -4 -5 -8 -4 7 2 -4 0 7 0 2 -3 7 7\n5 0 8 -9 3 5 2 -7 2 -7 0 -1 -4 1 -1 9\n-4 8 0 -9 8 9 3 1 4 9 6 6 -6 1 8 9\n-5 -9... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are N rabbits, numbered 1, 2, \ldots, N.
For each i, j (1 \leq i, j \leq N), the compatibility of Rabbit i and j is described by an integer a_{i, j}. Here, a_{i, i} = 0 for eac... |
p03328 AtCoder Beginner Contest 099 - Stone Monument_22095 | In some village, there are 999 towers that are 1,(1+2),(1+2+3),...,(1+2+3+...+999) meters high from west to east, at intervals of 1 meter.
It had been snowing for a while before it finally stopped. For some two adjacent towers located 1 meter apart, we measured the lengths of the parts of those towers that are not cov... | a, b = map(int, input().split())
print(((b-a)*((b-a)+1))//2 - b) | {
"input": [
"54 65",
"8 13",
"105 65",
"8 16",
"105 88",
"105 147",
"0 1",
"196 147",
"0 2",
"96 147",
"1 2",
"96 262",
"96 336",
"96 412",
"96 590",
"96 816",
"5 1",
"64 816",
"5 0",
"64 1208",
"7 0",
"64 2323",
"7 1",
"... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In some village, there are 999 towers that are 1,(1+2),(1+2+3),...,(1+2+3+...+999) meters high from west to east, at intervals of 1 meter.
It had been snowing for a while before it f... |
p03484 AtCoder Regular Contest 088 - Christmas Tree_22098 | Takahashi has decided to make a Christmas Tree for the Christmas party in AtCoder, Inc.
A Christmas Tree is a tree with N vertices numbered 1 through N and N-1 edges, whose i-th edge (1\leq i\leq N-1) connects Vertex a_i and b_i.
He would like to make one as follows:
* Specify two non-negative integers A and B.
* Pr... | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from bisect import bisect_left, bisect_right
N = int(readline())
m = map(int,read().split())
AB = zip(m,m)
graph = [[] for _ in range(N+1)]
for a,b in AB:
graph[a].append(b)
graph[b].append(a)
... | {
"input": [
"7\n1 2\n2 3\n2 4\n4 5\n4 6\n6 7",
"10\n1 2\n2 3\n3 4\n2 5\n6 5\n6 7\n7 8\n5 9\n10 5",
"8\n1 2\n2 3\n3 4\n4 5\n5 6\n5 7\n5 8",
"7\n1 2\n2 3\n2 4\n2 5\n4 6\n6 7",
"7\n1 4\n2 3\n2 4\n4 5\n4 6\n6 7",
"7\n1 4\n2 3\n2 4\n4 5\n7 6\n6 7",
"7\n1 4\n2 3\n2 4\n1 5\n7 6\n6 7",
"7\n1 ... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Takahashi has decided to make a Christmas Tree for the Christmas party in AtCoder, Inc.
A Christmas Tree is a tree with N vertices numbered 1 through N and N-1 edges, whose i-th edge... |
p03649 AtCoder Regular Contest 079 - Decrease (Judge ver.)_22102 | We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. (The operation is the same as the one in Problem D.)
* Determine the largest element in the sequence (if there is more than... | import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
count = 0
B = [A[0]]
for i in range(N-1):
a = A[i+1]+count
C = []
for b in B:
x = (b-a)//(N+1)
C.append(x)
s = sum(C)
count += s
new_B = []
for i, b in enumerate(... | {
"input": [
"2\n2 2",
"4\n3 3 3 3",
"7\n27 0 0 0 0 0 0",
"3\n1 0 3",
"10\n1000 193 256 777 0 1 1192 1234567891011 48 425",
"2\n2 4",
"4\n3 3 3 2",
"10\n1000 193 256 777 0 2 1192 1234567891011 48 425",
"2\n2 7",
"10\n1000 193 256 777 0 2 1192 2138223215855 48 425",
"2\n0 7"... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1... |
p03805 AtCoder Beginner Contest 054 - One-stroke Path_22106 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges.
Here, a self-loop is an edge where a_i = b_i (1≤i≤M), and double edges are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M).
How many different paths start from vertex 1 and vi... | import itertools
n,m = map(int,input().split())
ab = []
count = 0
for i in range(m):
ab.append(set(map(int,input().split())))
ns = [i for i in range(1,n+1)]
ptn = [i for i in list(itertools.permutations(ns)) if i[0]==1]
for i in ptn:
first = i[0]
for s in range(1,n):
if {first,i[s]} not in ab:
break
... | {
"input": [
"7 7\n1 3\n2 7\n3 4\n4 5\n4 6\n5 6\n6 7",
"3 3\n1 2\n1 3\n2 3",
"7 4\n1 3\n2 7\n3 4\n4 5\n4 6\n5 6\n6 7",
"7 7\n1 3\n2 7\n3 4\n4 5\n4 1\n5 6\n6 7",
"7 7\n1 3\n2 7\n3 4\n4 5\n4 6\n4 6\n6 7",
"7 4\n1 4\n2 7\n3 4\n4 5\n4 6\n5 6\n6 7",
"7 7\n1 5\n2 7\n3 4\n4 5\n4 6\n4 6\n6 7",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges.
Here, a self-loop is an edge where a_i = b_i (1≤i≤M), and d... |
p03973 CODE FESTIVAL 2016 qual B - Greedy customers_22110 | N people are waiting in a single line in front of the Takahashi Store. The cash on hand of the i-th person from the front of the line is a positive integer A_i.
Mr. Takahashi, the shop owner, has decided on the following scheme: He picks a product, sets a positive integer P indicating its price, and shows this product... | n = int(input())
a = []
for i in range(n):
a0 = int(input())
a.append(a0)
ans = 0
key = "b"
count = 1
m = 0
for i in range(n):
if key == "a":
if a[i] == count:
count += 1
elif a[i] > count:
if a[i]%count == 0:
ans += a[i]//count - 1
else:
... | {
"input": [
"15\n3\n1\n4\n1\n5\n9\n2\n6\n5\n3\n5\n8\n9\n7\n9",
"3\n3\n2\n5",
"15\n3\n1\n4\n1\n5\n9\n2\n6\n5\n3\n5\n8\n9\n6\n9",
"3\n3\n2\n10",
"3\n6\n2\n10",
"3\n6\n3\n10",
"3\n7\n3\n10",
"3\n7\n5\n10",
"3\n7\n9\n10",
"3\n7\n13\n10",
"15\n3\n1\n4\n1\n5\n9\n2\n11\n5\n3\n5\n... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
N people are waiting in a single line in front of the Takahashi Store. The cash on hand of the i-th person from the front of the line is a positive integer A_i.
Mr. Takahashi, the sh... |
p00062 What is the Bottommost?_22114 | Consider creating the following number pattern.
4 8 2 3 1 0 8 3 7 6
2 0 5 4 1 8 1 0 3
2 5 9 5 9 9 1 3
7 4 4 4 8 0 4
1 8 8 2 8 4
9 6 0 0 2
5 6 0 2
1 6 2
7 8
Five
This pattern follows the rules below.
A B
C
In the sequence of numbers, C is the ones digit of A + B. For example
9 5
Four
Now, the ones digit of 9... | while True:
try:
L = [int(x) for x in list(input())]
except:
break
T =[]
while len(L) > 1:
for i in range(len(L)-1):
T.append( (L[i] + L[i+1])%10 )
L = T[:]
T = []
print(L[0])
| {
"input": [
"4823108376\n1234567890\n0123456789",
"4823108376\n2273064329\n0123456789",
"4823108376\n2314825047\n0123456789",
"4823108376\n1842094049\n0123456789",
"4823108376\n2704372300\n0123456789",
"4823108376\n2811474872\n0123456789",
"4823108376\n1472363412\n0123456789",
"482310... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Consider creating the following number pattern.
4 8 2 3 1 0 8 3 7 6
2 0 5 4 1 8 1 0 3
2 5 9 5 9 9 1 3
7 4 4 4 8 0 4
1 8 8 2 8 4
9 6 0 0 2
5 6 0 2
1 6 2
7 8
Five
This pattern follo... |
p00193 Convenience Store_22118 | Convenience store Deven Eleven is planning to open its first store in Aizuwakamatsu City to expand its business. There are already many other convenience stores in Aizuwakamatsu, so the place to open a new store is likely to be the key to success. Under the premise that "customers use the convenience store closest to t... | import sys
def generate_next_hexes(x, y):
hexes = [(x, y - 1), (x, y + 1), (x - 1, y), (x + 1, y)]
if y % 2:
hexes += [(x - 1, y - 1), (x - 1, y + 1)]
else:
hexes += [(x + 1, y - 1), (x + 1, y + 1)]
return hexes
def update_map(hex_map, hexes):
num_updated_hexes = 0
distance = 0... | {
"input": [
"6 6\n6\n1 1\n6 1\n3 2\n3 5\n1 6\n5 6\n2\n1 3\n5 3\n6 6\n6\n3 2\n3 5\n6 1\n1 1\n1 6\n5 6\n2\n2 3\n5 3\n0 0",
"6 6\n6\n1 1\n6 1\n3 2\n3 5\n1 6\n5 6\n2\n1 3\n5 3\n6 6\n6\n3 2\n3 5\n6 1\n1 1\n1 6\n5 6\n2\n2 3\n6 3\n0 0",
"6 6\n6\n1 1\n6 1\n3 2\n3 5\n0 6\n5 6\n2\n1 3\n2 3\n6 6\n6\n3 2\n3 5\n6 1\n... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Convenience store Deven Eleven is planning to open its first store in Aizuwakamatsu City to expand its business. There are already many other convenience stores in Aizuwakamatsu, so t... |
p00544 Russian Flag_22122 | problem
President K decided to make a flag for IOI 2016 in Russia. Chairman K first took out the old flag from the warehouse. This flag is divided into squares of N rows and M columns, and each square is painted in one of white, blue, and red.
Chairman K is trying to repaint some of the squares on this flag to make i... | #C
inf = float("inf")
N,M = map(int,input().split())
flag = [list(str(input())) for i in range(N)]
WBR = []
for i in range(N):
w = flag[i].count("W")
b = flag[i].count("B")
r = flag[i].count("R")
WBR.append([w,b,r])
ans = inf
for w in range(N-2):
for b in range(N-1):
if w >= b:
... | {
"input": [
"4 5\nWRWRW\nBWRWB\nWRWRW\nRWBWR",
"4 5\nWRWRW\nBRWWB\nWRWRW\nRWBWR",
"4 5\nWRWRW\nBWRWB\nWRWRW\nRWBWQ",
"4 5\nWQWRW\nBWRXB\nRVWRW\nWQBWQ",
"4 3\nWQWRW\nBWRXB\nRVWRW\nRWBWQ",
"4 5\nWQWRW\nBWRXC\nRVWRW\nWQBWQ",
"4 10\nWRWQW\nBWRXB\nRVWRW\nRWBWQ",
"4 0\nWQXRW\nBWRXB\nVRWRW\n... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
problem
President K decided to make a flag for IOI 2016 in Russia. Chairman K first took out the old flag from the warehouse. This flag is divided into squares of N rows and M column... |
p00708 Building a Space Station_22126 | You are a member of the space station engineering team, and are assigned a task in the construction process of the station. You are expected to write a computer program to complete the task.
The space station is made up with a number of units, called cells. All cells are sphere-shaped, but their sizes are not necessar... | # http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1127
# クラスカル or プリム法
import math
class UnionFind:
def __init__(self, n):
self.n = n
# 各要素の親要素の番号を格納するリスト
# 根がルートの時は、グループの要素数を格納 最初は全て根で要素数1
self.parents = [-1] * n
# 再帰 groupの根を返す
# 経路圧縮あり
def find(self, x):
... | {
"input": [
"3\n10.000 10.000 50.000 10.000\n40.000 10.000 50.000 10.000\n40.000 40.000 50.000 10.000\n2\n30.000 30.000 30.000 20.000\n40.000 40.000 40.000 20.000\n5\n5.729 15.143 3.996 25.837\n6.013 14.372 4.818 10.671\n80.115 63.292 84.477 15.120\n64.095 80.924 70.029 14.881\n39.472 85.116 71.369 5.553\n0",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are a member of the space station engineering team, and are assigned a task in the construction process of the station. You are expected to write a computer program to complete th... |
p00979 Fast Forwarding_22132 | Fast Forwarding
Mr. Anderson frequently rents video tapes of his favorite classic films. Watching the films so many times, he has learned the precise start times of his favorite scenes in all such films. He now wants to find how to wind the tape to watch his favorite scene as quickly as possible on his video player.
... | #!/usr/bin/python3
import os
import sys
def main():
T = read_int()
print(solve(T))
def solve(T):
if T <= 3:
return T
sec = 1
T -= 1
f = 3
while T >= 2 * f:
T -= 2 * f
f *= 3
sec += 2
if T >= f:
T -= f
sec += 1
else:
f //=... | {
"input": [
"19",
"0",
"26",
"25",
"23",
"5",
"4",
"1",
"8",
"38",
"47",
"48",
"75",
"138",
"149",
"132",
"374",
"315",
"933",
"945",
"456",
"942",
"2139",
"1374",
"3723",
"18",
"14",
"7",
"2",
"3"... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Fast Forwarding
Mr. Anderson frequently rents video tapes of his favorite classic films. Watching the films so many times, he has learned the precise start times of his favorite scen... |
p01111 Skyscraper MinatoHarukas_22136 | Skyscraper "MinatoHarukas"
Mr. Port plans to start a new business renting one or more floors of the new skyscraper with one giga floors, MinatoHarukas. He wants to rent as many vertically adjacent floors as possible, because he wants to show advertisement on as many vertically adjacent windows as possible. The rent fo... | 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": [
"15\n16\n2\n3\n9699690\n223092870\n847288609\n900660121\n987698769\n999999999\n0",
"15\n16\n2\n3\n9699690\n116276261\n847288609\n900660121\n987698769\n999999999\n0",
"15\n16\n2\n3\n9699690\n223092870\n869854515\n900660121\n987698769\n999999999\n0",
"15\n26\n2\n3\n9699690\n223092870\n86985... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Skyscraper "MinatoHarukas"
Mr. Port plans to start a new business renting one or more floors of the new skyscraper with one giga floors, MinatoHarukas. He wants to rent as many verti... |
p01410 Dangerous Tower_22140 | Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well.
Today's training is to gain dexterity that never mistypes by carefully stacking blocks. Since there are many building blocks, let's build a tall tower.
There are N blocks, and the i-th (... | import sys
readline = sys.stdin.readline
write = sys.stdout.write
from heapq import heappush, heappop
class MinCostFlow:
INF = 10**18
def __init__(self, N):
self.N = N
self.G = [[] for i in range(N)]
def add_edge(self, fr, to, cap, cost):
forward = [to, cap, cost, None]
ba... | {
"input": [
"3\n10 40\n10 40\n20 30",
"4\n1 2\n2 3\n3 4\n4 1",
"3\n10 40\n15 40\n20 30",
"4\n1 2\n3 3\n3 4\n4 1",
"3\n10 40\n15 40\n40 30",
"4\n1 2\n3 3\n3 7\n4 1",
"4\n2 2\n3 3\n3 7\n4 1",
"3\n10 40\n15 40\n20 32",
"4\n2 4\n3 3\n3 7\n4 1",
"3\n10 36\n15 40\n20 32",
"3\n10... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well.
Today's training is to gain dexterity that never m... |
p01726 Almost Same Substring_22145 | The unlucky Ikta-kun has rewritten the important character string T that he had to a different character string T'by the virus. It is known that the virus has rewritten one letter of T to a different letter. That is, T and T'are different by exactly one character. In order to restore T, Ikta prepared a document S in wh... | import string
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
s0 = "^" + string.ascii_uppercase + string.ascii_lowercase
*S, = map(s0.index, readline().strip()); N = len(S)
*T, = map(s0.index, readline().strip()); M = len(T)
base = 59; mod = 10**9 + 9
pw = [1]*(N+1)
... | {
"input": [
"aaaaaa\naaaaaa",
"abcbcdbc\nabc",
"baaaaaaaa\nb",
"aaaaaa\naaaaab",
"bbcbcdbc\nabc",
"aaaaaa\nbbaaaa",
"bbcbcdbc\nbca",
"aaaaaa\nbaaaaa",
"bbcbcdbc\nacb",
"aaaaaa\nbbaa`a",
"cbdcbcbb\nbca",
"aaaaaa\nbaba`a",
"cbdcbcbb\nbda",
"aaaaab\nbaba`a",
"... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The unlucky Ikta-kun has rewritten the important character string T that he had to a different character string T'by the virus. It is known that the virus has rewritten one letter of ... |
p02000 Bumpy Array_22149 | problem
Given the sequence $ A $ of length $ N $. The $ i $ item in $ A $ is $ A_i $. You can do the following for this sequence:
* $ 1 \ leq i \ leq N --Choose the integer i that is 1 $. Swap the value of $ A_i $ with the value of $ A_ {i + 1} $.
Find the minimum number of operations required to make $ A $ a sequ... | n = int(input())
a = list(map(int, input().split()))
ans = n
s = 0
b = [0 for i in range(n)]
for i in range(n):
b[i] = a[i]
for i in range(1,n):
if i%2 == 1:
if b[i] > b[i-1]:
flag = True
if i < n-1:
if b[i-1] > b[i+1] and b[i+1] < b[i]:
v = b[... | {
"input": [
"5\n1 2 3 4 5",
"5\n0 2 3 4 5",
"5\n1 2 1 4 5",
"5\n0 4 3 13 4",
"5\n0 2 3 4 8",
"5\n0 2 3 4 14",
"5\n0 1 3 4 5",
"5\n0 2 3 4 2",
"5\n0 2 3 8 2",
"5\n0 2 3 13 2",
"5\n0 2 3 13 4",
"5\n0 4 3 9 4",
"5\n0 4 3 12 4",
"5\n1 4 3 12 4",
"5\n2 4 3 12 4"... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
problem
Given the sequence $ A $ of length $ N $. The $ i $ item in $ A $ is $ A_i $. You can do the following for this sequence:
* $ 1 \ leq i \ leq N --Choose the integer i that i... |
p02145 Shiritori_22151 | Problem
Here is a list of strings. Let's take a break and play with shiritori. Shiritori is performed according to the following rules.
1. First of all, select one of your favorite strings from the list and exclude that string from the list.
2. Next, select one character string from the list in which the last charact... | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string... | {
"input": [
"5\nyou\nate\nmy\nhum\ntoast",
"7\nshe\nsells\nsea\nshells\nby\nthe\nseashore",
"7\nshf\nsells\nsea\nshells\nby\nthe\nseashore",
"7\nshf\nsells\nsea\nshells\nby\nteh\nseashore",
"7\nshf\nsells\nsea\nshells\nby\nthd\nseashore",
"7\nshf\nsells\nsea\nshells\nbx\nthd\nseashore",
"... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Problem
Here is a list of strings. Let's take a break and play with shiritori. Shiritori is performed according to the following rules.
1. First of all, select one of your favorite ... |
p02286 Treap_22153 | A binary search tree can be unbalanced depending on features of data. For example, if we insert $n$ elements into a binary search tree in ascending order, the tree become a list, leading to long search times. One of strategies is to randomly shuffle the elements to be inserted. However, we should consider to maintain t... | from random import random
from collections import deque
from copy import deepcopy
import sys
input = sys.stdin.readline
class Treap:
def __init__(self, iterable=None):
# vertex = [left, right, key, priority, #descendants, sum of descendants]
self.root = None
if iterable: self._construct(ite... | {
"input": [
"16\ninsert 35 99\ninsert 3 80\ninsert 1 53\ninsert 14 25\ninsert 80 76\ninsert 42 3\ninsert 86 47\ninsert 21 12\ninsert 7 10\ninsert 6 90\nprint\nfind 21\nfind 22\ndelete 35\ndelete 99\nprint",
"16\ninsert 35 99\ninsert 3 80\ninsert 1 53\ninsert 14 25\ninsert 80 76\ninsert 42 3\ninsert 102 47\ni... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A binary search tree can be unbalanced depending on features of data. For example, if we insert $n$ elements into a binary search tree in ascending order, the tree become a list, lead... |
p02433 List_22156 | For a dynamic list $L$ of integers, perform a sequence of the following operations. $L$ has a special element called END at the end of the list and an element of $L$ is indicated by a cursor.
* insert($x$): Insert $x$ before the element indicated by the cursor. After this operation, the cursor points the inserted elem... | q = int(input())
A = [0 for i in range(1500000)]
A[0] = 'end'
cursor = 0
head = [0 for i in range(1500000)]
head_len = 0
def insert(x):
global cursor
cursor += 1
A[cursor] = x
def move(d):
global cursor, head, head_len
if d >= 0:
head[head_len-1+d+(1): head_len-1+(1):-1] = A[cursor-d+1:cursor+1]
else:
A[curs... | {
"input": [
"5\n0 1\n0 2\n0 3\n1 1\n2",
"5\n0 1\n0 2\n0 2\n1 1\n2",
"5\n0 1\n0 2\n0 2\n0 1\n2",
"5\n0 1\n0 2\n0 3\n0 1\n2",
"5\n0 1\n0 2\n0 4\n1 1\n2",
"5\n0 1\n0 2\n0 4\n0 0\n2",
"5\n0 1\n0 0\n0 2\n0 0\n2",
"5\n0 1\n0 0\n0 1\n0 0\n2",
"5\n0 1\n0 0\n0 1\n1 0\n2",
"5\n0 1\n0 -1... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
For a dynamic list $L$ of integers, perform a sequence of the following operations. $L$ has a special element called END at the end of the list and an element of $L$ is indicated by a... |
1006_C. Three Parts of the Array_22166 | You are given an array d_1, d_2, ..., d_n consisting of n integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possibly, em... | x = int(input())
v = list(map(int,input().strip().split()))[:x]
i = 0
j = x-1
s1 = 0
s2 = 0
ans = 0
while(i<=j):
if(s2<s1):
s2+=v[j]
j=j-1
else:
s1+=v[i]
i=i+1
if(s1==s2):
ans=s1
print(ans) | {
"input": [
"3\n4 1 2\n",
"5\n1 3 1 1 4\n",
"5\n1 3 2 1 4\n",
"5\n1 3 5 4 5\n",
"1\n1000000000\n",
"2\n1 1\n",
"5\n2 3 5 4 5\n",
"1\n1000000100\n",
"3\n3 1 2\n",
"5\n1 3 3 1 4\n",
"5\n2 3 5 4 10\n",
"5\n1 8 3 2 4\n",
"5\n1 15 4 2 1\n",
"5\n0 2 4 2 4\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 an array d_1, d_2, ..., d_n consisting of n integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each elem... |
102_B. Sum of Digits_22170 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-di... | num = input()
c = 0
while(len(num) != 1):
num = str(sum(int(i) for i in num))
c += 1
print(c) | {
"input": [
"0\n",
"10\n",
"991\n",
"644818852\n",
"8\n",
"29\n",
"165767221702271872\n",
"211288847\n",
"677257481\n",
"353869285\n",
"477533739511673792\n",
"288403032\n",
"858893424\n",
"32\n",
"1\n",
"28\n",
"100\n",
"339900034079539584\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. ... |
1051_B. Relatively Prime Pairs_22174 | You are given a set of all integers from l to r inclusive, l < r, (r - l + 1) ≤ 3 ⋅ 10^5 and (r - l) is always odd.
You want to split these numbers into exactly (r - l + 1)/(2) pairs in such a way that for each pair (i, j) the greatest common divisor of i and j is equal to 1. Each number should appear in exactly one o... | l,r=map(int,input().split())
print('YES')
for i in range((r-l+1)//2):
print(l+i*2,l+i*2+1)
| {
"input": [
"1 8\n",
"3 12\n",
"2 7\n",
"1 2\n",
"4 9\n",
"1 8\n",
"2 3\n",
"3 6\n",
"804212830686677670 804212830686679109\n",
"4 5\n",
"2 5\n",
"3 8\n",
"3 14\n",
"1 14\n",
"3 22\n",
"0 7\n",
"2 9\n",
"4 13\n",
"1 6\n",
"0 1\n",
"5... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a set of all integers from l to r inclusive, l < r, (r - l + 1) ≤ 3 ⋅ 10^5 and (r - l) is always odd.
You want to split these numbers into exactly (r - l + 1)/(2) pairs... |
1073_C. Vasya and Robot_22178 | Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell (0, 0). Robot can perform the following four kinds of operations:
* U — move from (x, y) to (x, y + 1);
* D — move from (x, y) to (x, y - 1);
* L — move from (x, y) to (x - 1, y);
* R — move from (x, y) to (x + 1,... | # -*- coding: utf-8 -*-
"""
created by shhuan at 2018/11/3 11:30
search for minimum steps, consider binary search
"""
N = int(input())
ops = [x for x in input()]
X, Y = map(int, input().split())
dd = abs(X) + abs(Y)
lops = len(ops)
if dd > lops or (lops - dd) % 2 != 0:
print(-1)
exit(0)
[ll, lr, lu, ld... | {
"input": [
"5\nRURUU\n-2 3\n",
"4\nRULR\n1 1\n",
"3\nUUU\n100 100\n",
"13\nUUULRUDDRLUUD\n13 -10\n",
"77\nLRRUDLDUDRDRURURURLDLLURLULDDURUDUUDDUDLLDULRLRLRRRRULLRRRDURRDLUDULRUURRLDLU\n-6 -7\n",
"27\nRLUUDUDDRRULRDDULDULRLDLDRL\n0 -3\n",
"3\nLLD\n-2 -1\n",
"60\nLLDDDULDLDRUULRLLLLLDU... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell (0, 0). Robot can perform the following four kinds of operations:
* U — move from (x,... |
1095_C. Powers Of Two_22182 | A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contain... | import math
n,k=[int(x) for x in input().split()]
s=k
arr= [1 for i in range(k)]
i = k - 1
while(i >= 0):
while (s+ arr[i] <= n):
s += arr[i]
arr[i] *= 2
i -= 1
if (s != n):
print("NO")
else:
print("YES")
for i in range(0, k, 1):
print(arr[i], end = ' ')
'''n=int(input()... | {
"input": [
"8 1\n",
"5 1\n",
"9 4\n",
"3 7\n",
"9 2\n",
"688 500\n",
"536870911 28\n",
"999999999 9586\n",
"655 647\n",
"88562726 66\n",
"8 7\n",
"1 1\n",
"698 698\n",
"697 301\n",
"10 3\n",
"5 4\n",
"6 4\n",
"536870912 1\n",
"536870911 27\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two... |
1114_D. Flood Fill_22186 | You are given a line of n colored squares in a row, numbered from 1 to n from left to right. The i-th square initially has the color c_i.
Let's say, that two squares i and j belong to the same connected component if c_i = c_j, and c_i = c_k for all k satisfying i < k < j. In other words, all squares on the segment fro... | def run_length_compress(string):
string = string + ["."]
n = len(string)
begin = 0
end = 1
cnt = 1
ans = []
while True:
if end >= n:
break
if string[begin] == string[end]:
end += 1
cnt += 1
else:
ans.append(string[beg... | {
"input": [
"1\n4\n",
"4\n5 2 2 1\n",
"8\n4 5 2 2 1 3 5 5\n",
"172\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a line of n colored squares in a row, numbered from 1 to n from left to right. The i-th square initially has the color c_i.
Let's say, that two squares i and j belong t... |
1163_A. Eating Soup_22192 | The three friends, Kuro, Shiro, and Katie, met up again! It's time for a party...
What the cats do when they unite? Right, they have a party. Since they wanted to have as much fun as possible, they invited all their friends. Now n cats are at the party, sitting in a circle and eating soup. The rules are simple: anyone... | n , m = map(int,input().split())
import math
if n==m:
print(0)
elif m==0:
print(1)
elif m==1:
print(1)
else:
if n%2==0:
if n//2==m:
print(n//2)
elif m>n//2:
print(n-m)
else:
print(m)
else:
if math.ceil(n//2)==m or math.floor(n//2)==... | {
"input": [
"2 2\n",
"3 0\n",
"6 2\n",
"7 4\n",
"4 0\n",
"571 402\n",
"543 110\n",
"1000 972\n",
"5 2\n",
"132 128\n",
"1000 1000\n",
"3 3\n",
"973 799\n",
"980 632\n",
"1000 843\n",
"924 576\n",
"721 343\n",
"361 300\n",
"311 3\n",
"950... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The three friends, Kuro, Shiro, and Katie, met up again! It's time for a party...
What the cats do when they unite? Right, they have a party. Since they wanted to have as much fun as... |
1183_F. Topforces Strikes Back_22196 | One important contest will take place on the most famous programming platform (Topforces) very soon!
The authors have a pool of n problems and should choose at most three of them into this contest. The prettiness of the i-th problem is a_i. The authors have to compose the most pretty contest (in other words, the cumul... | from sys import stdin
from itertools import tee
def input():
return stdin.readline()
def remove_divisors(x, xs):
return [y for y in xs if y%xs != 0]
q = int(input())
for _ in range(q):
n = int(input())
aas = list(set(map(int,input().split())))
aas.sort(reverse=True)
# if len(aas) > 2 and aas... | {
"input": [
"3\n4\n5 6 15 30\n4\n10 6 30 15\n3\n3 4 6\n",
"1\n9\n7 4 2 2 2 2 2 2 2\n",
"1\n53\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 3 4 5\n",
"1\n37\n166320 83160 41580 33264 27720 23760 2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
One important contest will take place on the most famous programming platform (Topforces) very soon!
The authors have a pool of n problems and should choose at most three of them int... |
1201_A. Important Exam_22200 | A class of students wrote a multiple-choice test.
There are n students in the class. The test had m questions, each of them had 5 possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question i worth a_i points. Incorrect answers are graded with zero points.... | def get_ints():
return list(map(int, input().split()))
N, M = get_ints()
a = [input() for i in range(N)]
s = get_ints()
ans=0
for i in range(M):
d = {}
for row in a:
c = ord(row[i])-65
if c in d:
d[c]+=1
else:
d[c]=1
ans += max(d.values())*s[i]
print(ans... | {
"input": [
"3 3\nABC\nBCD\nCDE\n5 4 12\n",
"2 4\nABCD\nABCE\n1 2 3 4\n",
"10 10\nCBBBBBBBBB\nABBBBEBBBB\nBDBBBBBBBB\nBBBBBBBBBB\nBABBBBBEBB\nEBBBBBBBBB\nBBBCBDCBBB\nBEBBEBBBBB\nBBBBBBBBBB\nBBBDBBBABB\n840 678 490 900 683 84 256 233 468 856\n",
"2 1\nB\nA\n317\n",
"2 5\nABCDE\nABCDE\n2 3 5 7 11\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A class of students wrote a multiple-choice test.
There are n students in the class. The test had m questions, each of them had 5 possible answers (A, B, C, D or E). There is exactly... |
1243_A. Maximum Square_22207 | Ujan decided to make a new wooden roof for the house. He has n rectangular planks numbered from 1 to n. The i-th plank has size a_i × 1 (that is, the width is 1 and the height is a_i).
Now, Ujan wants to make a square roof. He will first choose some of the planks and place them side by side in some order. Then he will... | n=int(input())
for _ in range(n):
i=int(input())
ar=sorted(list(map(int,input().split())))[::-1]
mx=0
for e in range(i):
mx=max(mx,min(e+1,ar[e]))
print(mx)
| {
"input": [
"4\n5\n4 3 1 4 5\n4\n4 4 4 4\n3\n1 1 1\n5\n5 5 1 1 5\n",
"10\n1\n1\n2\n2 1\n3\n3 1 2\n3\n2 2 2\n4\n4 1 4 1\n5\n5 4 3 2 1\n5\n1 2 3 4 5\n6\n3 2 1 6 2 2\n10\n4 5 2 9 6 10 3 7 1 8\n10\n1 3 2 2 2 9 10 10 9 7\n",
"4\n5\n2 3 1 4 5\n4\n4 4 4 4\n3\n1 1 1\n5\n5 5 1 1 5\n",
"10\n1\n1\n2\n2 1\n3\n3 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Ujan decided to make a new wooden roof for the house. He has n rectangular planks numbered from 1 to n. The i-th plank has size a_i × 1 (that is, the width is 1 and the height is a_i)... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.