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 |
|---|---|---|---|---|---|
p02707 AtCoder Beginner Contest 163 - management_19399 | A company has N members, who are assigned ID numbers 1, ..., N.
Every member, except the member numbered 1, has exactly one immediate boss with a smaller ID number.
When a person X is the immediate boss of a person Y, the person Y is said to be an immediate subordinate of the person X.
You are given the information ... | N=int(input())
A=list(map(int,input().split()))
b=[0]*N
for c in A:
b[c-1]+=1
for i in b:
print(i) | {
"input": [
"7\n1 2 3 4 5 6",
"5\n1 1 2 2",
"10\n1 1 1 1 1 1 1 1 1",
"5\n1 1 2 3",
"7\n1 2 1 4 5 6",
"10\n1 1 1 1 1 2 1 1 1",
"5\n1 2 2 3",
"7\n1 2 3 4 5 4",
"5\n1 2 2 2",
"7\n1 2 2 4 5 6",
"10\n1 1 1 2 1 2 1 1 1",
"7\n1 2 3 4 5 2",
"7\n1 2 2 4 1 6",
"7\n1 2 3 ... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A company has N members, who are assigned ID numbers 1, ..., N.
Every member, except the member numbered 1, has exactly one immediate boss with a smaller ID number.
When a person X ... |
p02836 AtCoder Beginner Contest 147 - Palindrome-philia_19403 | Takahashi loves palindromes. Non-palindromic strings are unacceptable to him. Each time he hugs a string, he can change one of its characters to any character of his choice.
Given is a string S. Find the minimum number of hugs needed to make S palindromic.
Constraints
* S is a string consisting of lowercase English ... | s = input()
t = 0
for i in range(len(s)//2):
if s[i] != s[-(i+1)]:
t += 1
print(t) | {
"input": [
"abcdabc",
"redcoder",
"vvvvvv",
"aacdabc",
"redocder",
"vwwvvv",
"rdebrdeo",
"uuxxuu",
"wvvvvv",
"aacbadc",
"reeocddr",
"vvvvvw",
"cdabcaa",
"rddcoeer",
"vwvvvv",
"ccabcaa",
"rddboeer",
"aacbacc",
"rdeboder",
"vvvwwv",
"... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Takahashi loves palindromes. Non-palindromic strings are unacceptable to him. Each time he hugs a string, he can change one of its characters to any character of his choice.
Given is... |
p02973 AtCoder Beginner Contest 134 - Sequence Decomposing_19407 | You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:
* If A_i and A_j (i < j) are painted with the same color, A_i < A_j.
Find the minimum number of col... | import bisect
from collections import deque
N = int(input())
ans = deque([-1])
for _ in range(N):
a = int(input())
i = bisect.bisect_left(ans, a)
if i == 0:
ans.appendleft(a)
else:
ans[i-1] = a
print(len(ans))
| {
"input": [
"4\n0\n0\n0\n0",
"5\n2\n1\n4\n5\n3",
"4\n0\n-1\n0\n0",
"4\n1\n0\n0\n0",
"5\n10\n-1\n1\n13\n3",
"5\n0\n0\n0\n0\n0",
"5\n1\n4\n5\n7\n14",
"5\n4\n1\n4\n5\n3",
"4\n1\n-1\n0\n0",
"5\n4\n1\n4\n9\n3",
"5\n7\n1\n4\n9\n3",
"4\n-1\n0\n0\n0",
"5\n12\n1\n4\n9\n3",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the follo... |
p03109 AtCoder Beginner Contest 119 - Still TBD_19411 | You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.)
Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise.
Constraints
* S is... | s = input()
month = int(s[5:7])
print("Heisei" if month < 5 else "TBD") | {
"input": [
"2019/04/30",
"2019/11/01",
"2019/03/30",
"2019/11/00",
"2019/04/20",
"2019/12/01",
"2019/14/20",
"2119/12/01",
"2019/24/10",
"1019/04/30",
"2119/10/01",
"2029/11/00",
"2029/24/10",
"2119/10/11",
"2029/10/00",
"2119/20/11",
"2029/10/01",... | 5ATCODER | 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 as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.)
Write a pro... |
p03256 AtCoder Grand Contest 027 - ABland Yard_19415 | You are given an undirected graph consisting of N vertices and M edges. The vertices are numbered 1 to N, and the edges are numbered 1 to M. In addition, each vertex has a label, `A` or `B`. The label of Vertex i is s_i. Edge i bidirectionally connects vertex a_i and b_i.
The phantom thief Nusook likes to choose some ... | import sys,time
sys.setrecursionlimit(10**7)
start_time = time.time()
N,M = map(int,input().split())
S = input()
src = [tuple(map(lambda x:int(x)-1,sys.stdin.readline().split())) for i in range(M)]
outdeg = [set() for i in range(2*N)]
for x,y in src:
if S[x] == S[y]:
#A0->A1, B0->B1
outdeg[x].add(... | {
"input": [
"13 17\nBBABBBAABABBA\n7 1\n7 9\n11 12\n3 9\n11 9\n2 1\n11 5\n12 11\n10 8\n1 11\n1 8\n7 7\n9 10\n8 8\n8 12\n6 2\n13 11",
"2 3\nAB\n1 1\n1 2\n2 2",
"4 3\nABAB\n1 2\n2 3\n3 1",
"13 23\nABAAAABBBBAAB\n7 1\n10 6\n1 11\n2 10\n2 8\n2 11\n11 12\n8 3\n7 12\n11 2\n13 13\n11 9\n4 1\n9 7\n9 6\n8 13\... | 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 graph consisting of N vertices and M edges. The vertices are numbered 1 to N, and the edges are numbered 1 to M. In addition, each vertex has a label, `A` ... |
p03409 AtCoder Beginner Contest 091 - 2D Plane 2N Points_19419 | On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).
A red point and a blue point can form a friendly pair when, the x-coordinate of the red point is smaller than that of the blue point, an... | N = int(input())
AB = sorted([[int(_) for _ in input().split()] for _ in range(N)],
key=lambda x: x[1],
reverse=True)
CD = sorted([[int(_) for _ in input().split()] for _ in range(N)])
for i in range(N):
for j in range(len(AB)):
if AB[j][0] < CD[i][0] and AB[j][1] < CD[i][1]:
... | {
"input": [
"2\n2 2\n3 3\n0 0\n1 1",
"5\n0 0\n7 3\n2 2\n4 8\n1 6\n8 5\n6 9\n5 4\n9 1\n3 7",
"5\n0 0\n1 1\n5 5\n6 6\n7 7\n2 2\n3 3\n4 4\n8 8\n9 9",
"3\n0 0\n1 1\n5 2\n2 3\n3 4\n4 5",
"3\n2 0\n3 1\n1 3\n4 2\n0 4\n5 5",
"2\n2 2\n3 5\n0 0\n1 1",
"5\n0 0\n7 3\n2 2\n4 8\n1 6\n8 5\n6 9\n5 4\n9 1... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).
... |
p03727 AtCoder Grand Contest 014 - Blue and Red Tree_19424 | There is a tree with N vertices numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i.
Initially, each edge is painted blue. Takahashi will convert this blue tree into a red tree, by performing the following operation N-1 times:
* Select a simple path that consists of only blue edges, and remo... | import queue
n,q=int(input()),queue.Queue()
s=[set() for i in range(n+1)]
for i in range(2*n-2):
u,v=map(int,input().split())
if v in s[u]:
q.put((u,v))
else:
s[u].add(v)
s[v].add(u)
f=[i for i in range(n+1)]
def find(x):
if f[x]==x:
return x
else:
f[x]=find(f[x])
return f[x]
while not q.empty():
u,v=... | {
"input": [
"5\n1 2\n2 3\n3 4\n4 5\n3 4\n2 4\n1 4\n1 5",
"6\n1 2\n3 5\n4 6\n1 6\n5 1\n5 3\n1 4\n2 6\n4 3\n5 6",
"3\n1 2\n2 3\n1 3\n3 2",
"5\n1 2\n2 3\n3 2\n4 5\n3 4\n2 4\n1 4\n1 5",
"6\n1 2\n3 5\n4 6\n1 6\n5 2\n5 3\n1 4\n2 6\n4 3\n5 6",
"3\n1 0\n2 3\n1 3\n3 2",
"5\n1 2\n2 3\n3 2\n4 5\n3 4... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is a tree with N vertices numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i.
Initially, each edge is painted blue. Takahashi will convert this blue ... |
p03891 CODE FESTIVAL 2016 Relay (Parallel) - Magic Square 2_19428 | A 3×3 grid with a integer written in each square, is called a magic square if and only if the integers in each row, the integers in each column, and the integers in each diagonal (from the top left corner to the bottom right corner, and from the top right corner to the bottom left corner), all add up to the same sum.
... | a=int(input())
b=int(input())
c=int(input())
x=[[0,0,0] for _ in range(3)]
for i in range(-300,301):
x[0][0]=a
x[0][1]=b
x[1][1]=c
x[0][2]=i-a-b
x[2][2]=i-a-c
x[2][1]=i-b-c
x[1][2]=i-x[0][2]-x[2][2]
x[1][0]=i-c-x[1][2]
x[2][0]=i-x[2][1]-x[2][2]
ok = True
for j in range(3):
... | {
"input": [
"8\n3\n5",
"1\n1\n1",
"8\n0\n5",
"1\n0\n1",
"8\n-1\n5",
"1\n0\n2",
"1\n-1\n1",
"1\n-1\n2",
"1\n-1\n4",
"1\n0\n4",
"1\n1\n2",
"1\n-2\n2",
"1\n-2\n3",
"1\n-3\n3",
"1\n0\n3",
"8\n-1\n4",
"8\n0\n6",
"8\n-2\n5",
"1\n-2\n4",
"1\n-1... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A 3×3 grid with a integer written in each square, is called a magic square if and only if the integers in each row, the integers in each column, and the integers in each diagonal (fro... |
p04050 AtCoder Grand Contest 001 - Arrays and Palindrome_19432 | Snuke got a present from his mother on his birthday. The present was a pair of two sequences a and b, consisting of positive integers. They satisfied all of the following properties:
* The sum of all elements of a is N.
* The sum of all elements of b is N.
* Any string of length N that satisfies the following two cond... | n,m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
breakFlag = False
for i in range(1,m-1):
if a[i]%2==1:
if a[0]%2==1:
if a[len(a)-1]%2==1:
print("Impossible")
breakFlag = True
break
else:
a[... | {
"input": [
"3 2\n2 1",
"55 10\n1 2 3 4 5 6 7 8 9 10",
"6 1\n6",
"3 2\n2 0",
"55 10\n2 2 3 4 5 6 7 8 9 10",
"6 1\n3",
"1 1\n6",
"-1 1\n2 0",
"1 1\n12",
"6 2\n2 1",
"6 1\n5",
"0 2\n1 0",
"-1 2\n3 0",
"1 1\n7",
"1 1\n15",
"1 1\n1",
"3 2\n2 2",
"-1... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Snuke got a present from his mother on his birthday. The present was a pair of two sequences a and b, consisting of positive integers. They satisfied all of the following properties:
... |
p00129 Hide-and-Seek Supporting System_19436 | Taro is not good at hide-and-seek. As soon as you hide, you will find it, and it will be difficult to find the hidden child. My father, who couldn't see it, made an ultra-high performance location search system. You can use it to know exactly where your friends are, including your own. Once you become a demon, you can ... | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0129
"""
import sys
from sys import stdin
from math import sqrt, atan2, acos, sin, cos, hypot
input = stdin.readline
class Point(object):
epsilon = 1e-10
def __init__(self, x=0.0, y=0.0):
if isinstance(x, tuple):
... | {
"input": [
"3\n6 6 3\n19 7 4\n21 8 1\n6\n5 4 2 11\n12 4 2 11\n11 9 2 11\n14 3 20 5\n17 9 20 5\n20 10 20 5\n0",
"3\n6 6 3\n19 7 4\n21 8 1\n6\n5 4 2 11\n12 4 2 11\n11 9 2 11\n14 3 22 5\n17 9 20 5\n20 10 20 5\n0",
"3\n6 6 3\n19 7 6\n42 8 1\n6\n5 4 2 11\n12 4 2 11\n11 9 1 11\n14 3 22 5\n17 9 20 5\n20 10 20 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Taro is not good at hide-and-seek. As soon as you hide, you will find it, and it will be difficult to find the hidden child. My father, who couldn't see it, made an ultra-high perform... |
p00262 Triangle of Blocks_19440 | The following sorting operation is repeated for the stacked blocks as shown in Fig. A.
1. Stack all the bottom blocks (white blocks in Figure a) on the right edge (the remaining blocks will automatically drop one step down, as shown in Figure b).
2. If there is a gap between the blocks, pack it to the left to eliminat... | tri_nums = [i * (i + 1) // 2 for i in range(1500)]
while True:
n = int(input())
if n == 0:
break
blst = list(map(int, input().split()))
if sum(blst) not in tri_nums:
print(-1)
continue
end = [i + 1 for i in range(tri_nums.index(sum(blst)))]
lenb = n
cnt = 0
while blst != end:
if cnt > 10... | {
"input": [
"6\n1 4 1 3 2 4\n5\n1 2 3 4 5\n10\n1 1 1 1 1 1 1 1 1 1\n9\n1 1 1 1 1 1 1 1 1\n12\n1 4 1 3 2 4 3 3 2 1 2 2\n1\n5050\n3\n10000 10000 100\n0",
"6\n1 4 1 3 2 4\n5\n1 2 5 4 5\n10\n1 1 1 1 1 1 1 1 1 1\n9\n1 1 1 1 1 1 1 1 1\n12\n1 4 1 3 2 4 3 3 2 1 2 2\n1\n5050\n3\n10000 10000 100\n0",
"6\n1 4 1 3 2... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The following sorting operation is repeated for the stacked blocks as shown in Fig. A.
1. Stack all the bottom blocks (white blocks in Figure a) on the right edge (the remaining bloc... |
p00449 Boat Travel_19443 | problem
There are n islands in JOI, and each island is numbered from 1 to n. Currently, the JOI country is developing a route network connecting each island.
You work at a ticket center that handles ship tickets. There are many people in JOI who want to travel between islands by boat, as cheaply as possible, and they... | # AOJ 0526: Boat Travel
# Python3 2018.7.1 bal4u
INF = 0x7fffffff
while True:
n, k = map(int, input().split())
if n == 0: break
fee = [[INF for j in range(101)] for i in range(101)]
for i in range(n+1): fee[i][i] = 0
for i in range(k):
v = list(map(int, input().split()))
a, b = v[1], v[2]
if v[0] == 1:
e... | {
"input": [
"3 8\n1 3 1 10\n0 2 3\n1 2 3 20\n1 1 2 5\n0 3 2\n1 1 3 7\n1 2 1 9\n0 2 3\n5 16\n1 1 2 343750\n1 1 3 3343\n1 1 4 347392\n1 1 5 5497\n1 2 3 123394\n1 2 4 545492\n1 2 5 458\n1 3 4 343983\n1 3 5 843468\n1 4 5 15934\n0 2 1\n0 4 1\n0 3 2\n0 4 2\n0 4 3\n0 5 3\n0 0",
"3 8\n1 3 1 10\n0 2 3\n1 2 2 20\n1 1 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
problem
There are n islands in JOI, and each island is numbered from 1 to n. Currently, the JOI country is developing a route network connecting each island.
You work at a ticket ce... |
p00640 Distorted Love_19446 | Saying that it is not surprising that people want to know about their love, she has checked up his address, name, age, phone number, hometown, medical history, political party and even his sleeping position, every piece of his personal information. The word "privacy" is not in her dictionary. A person like her is calle... | # AOJ 1054: Distorted Love
# Python3 2018.7.7 bal4u
while True:
n = int(input())
if n == 0: break
input() # w, h
pag, dic = [], {}
for i in range(n):
nm, k = input().split()
dic[nm] = i
btn = []
for j in range(int(k)):
x1, y1, x2, y2, bnm = input().split()
btn.append((int(x1), int(y1), int(x2), in... | {
"input": [
"3\n800 600\nindex 1\n500 100 700 200 profile\nprofile 2\n100 100 400 200 index\n100 400 400 500 link\nlink 1\n100 100 300 200 index\n9\nclick 600 150\nshow\nclick 200 450\nshow\nback\nback\nshow\nforward\nshow\n0",
"3\n800 600\nindex 1\n842 100 700 200 profile\nprofile 2\n100 100 400 200 index\n... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Saying that it is not surprising that people want to know about their love, she has checked up his address, name, age, phone number, hometown, medical history, political party and eve... |
p00916 Count the Regions_19452 | There are a number of rectangles on the x-y plane. The four sides of the rectangles are parallel to either the x-axis or the y-axis, and all of the rectangles reside within a range specified later. There are no other constraints on the coordinates of the rectangles.
The plane is partitioned into regions surrounded by ... | 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**13
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": [
"3\n4 28 27 11\n15 20 42 5\n11 24 33 14\n5\n4 28 27 11\n12 11 34 2\n7 26 14 16\n14 16 19 12\n17 28 27 21\n2\n300000 1000000 600000 0\n0 600000 1000000 300000\n0",
"3\n4 28 27 11\n15 20 42 5\n11 24 33 14\n5\n4 28 27 11\n12 11 34 2\n7 26 14 16\n14 16 19 12\n17 28 27 21\n2\n322297 1000000 600000 0\n... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are a number of rectangles on the x-y plane. The four sides of the rectangles are parallel to either the x-axis or the y-axis, and all of the rectangles reside within a range sp... |
p01049 Array Update_19455 | Problem
There is an arithmetic progression A with the number of terms N, the first term a, and the tolerance d. Since M statements that update the sequence are given in the following format, find the value of the K item when the sequence A is updated M times in the given order.
* The i-th statement is represented by ... | n = int(input())
a, d = map(int, input().split())
mem = {}
def get_mem(num):
if num in mem:return mem[num]
else:return num
m = int(input())
for _ in range(m):
x, y, z = map(int, input().split())
if x == 0:
ny, nz = get_mem(y), get_mem(z)
mem[y] = nz
mem[z] = ny
if x == 1:
nz = get_mem(... | {
"input": [
"6\n5 5\n4\n0 1 2\n1 1 2\n0 4 1\n1 1 6\n3",
"5\n2 3\n3\n0 2 5\n0 3 5\n1 2 4\n2",
"6\n5 5\n4\n-1 1 2\n1 1 2\n0 4 1\n1 1 6\n3",
"6\n5 4\n4\n-1 1 2\n0 1 2\n0 4 1\n1 1 6\n3",
"5\n2 2\n3\n0 2 5\n0 3 5\n1 2 4\n2",
"6\n10 5\n4\n-1 1 2\n0 1 2\n0 4 1\n1 1 6\n3",
"6\n7 5\n4\n0 1 2\n1 1 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Problem
There is an arithmetic progression A with the number of terms N, the first term a, and the tolerance d. Since M statements that update the sequence are given in the following... |
p01318 Immortal Jewels_19460 | English text is not available in this practice contest.
At one point, a nobleman fell in love with a brave princess in a poor country and applied for marriage. The princess has given certain conditions to the aristocrats. The condition was to bring in a large number of jewels called "immortal jewels". Immortal gems ar... | import sys
readline = sys.stdin.readline
write = sys.stdout.write
def common_tangent_lines(x1, y1, r1, x2, y2, r2):
result = []
xd = x2 - x1; yd = y2 - y1
rr0 = xd**2 + yd**2
if (r1 - r2)**2 <= rr0:
cv = r1 - r2
if rr0 == (r1 - r2)**2:
bx = r1*cv*xd/rr0
by = r1*... | {
"input": [
"6\n-2 -2 1 1\n2 2 2 0\n5 7 1 1\n8 0 3 1\n13 4 1 1\n16 1 1 2\n3\n0 0 2 1\n10 0 2 1\n0 10 2 1\n3\n0 0 2 1\n10 0 2 1\n0 6 2 1\n3\n0 0 2 1\n10 0 2 1\n0 4 2 1\n1\n0 0 1 1\n0",
"6\n-2 -2 1 1\n2 2 2 0\n5 7 1 1\n8 0 3 1\n13 4 1 1\n16 1 1 2\n3\n-1 0 2 1\n10 0 2 1\n0 10 4 1\n3\n0 0 2 1\n10 0 2 1\n0 6 2 1\... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
English text is not available in this practice contest.
At one point, a nobleman fell in love with a brave princess in a poor country and applied for marriage. The princess has given... |
p01486 CatChecker_19464 | Example
Input
mmemewwemeww
Output
Cat | import re
b=s=input()
while 1:
s=re.sub(r'(m|e)mew(e|w)','\\1\\2',s)
if b==s:break
b=s
print(['Rabbit','Cat'][s=='mew']) | {
"input": [
"mmemewwemeww",
"mmemwweemeww",
"wwemeewwmemm",
"mmemwweeneww",
"mnemwweeneww",
"wweneewwmenm",
"wwmneewwmene",
"xwmneewwmene",
"xweneewwmmne",
"xweneewvmmne",
"xmeneewvmwne",
"enwmvweenemx",
"enwmvwfenemx",
"enwmwwfenemx",
"enwmwweenemx",
"... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Example
Input
mmemewwemeww
Output
Cat
### Input:
mmemewwemeww
### Output:
Cat
### Input:
mmemwweemeww
### Output:
Rabbit
### Code:
import re
b=s=input()
while 1:
s=re.sub... |
p01648 Median Tree_19468 | Problem Statement
You are given a connected undirected graph which has even numbers of nodes. A connected graph is a graph in which all nodes are connected directly or indirectly by edges.
Your task is to find a spanning tree whose median value of edges' costs is minimum. A spanning tree of a graph means that a tree ... | 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**13
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": [
"2 1\n1 2 5\n4 6\n1 2 1\n1 3 2\n1 4 3\n2 3 4\n2 4 5\n3 4 6\n8 17\n1 4 767\n3 1 609\n8 3 426\n6 5 972\n8 1 607\n6 4 51\n5 1 683\n3 6 451\n3 4 630\n8 7 912\n3 7 43\n4 7 421\n3 5 582\n8 4 538\n5 7 832\n1 6 345\n8 2 608\n0 0",
"2 1\n1 2 5\n4 6\n2 2 1\n1 3 2\n1 4 3\n2 3 4\n2 4 5\n3 4 6\n8 17\n1 4 767\... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Problem Statement
You are given a connected undirected graph which has even numbers of nodes. A connected graph is a graph in which all nodes are connected directly or indirectly by ... |
p01933 Displayed tweets_19472 | problem
In Ikatta, the SNS used by AOR Ika-chan, posts are called tweets.
And in squid, there is a concern that visibility will deteriorate if there are many replies to tweets, so when a tweet meets any of the following rules, the tweet will be displayed on the screen. ing.
* Rule 1. No reply to any tweet
* Rule 2. ... | # AOJ 2833: Displayed tweets
# Python3 2018.7.12 bal4u
INF = 0x7ffffff
N, K = map(int, input().split())
k, f = [INF]*(N+1), [0]*(N+1)
a = [0]+[int(input()) for i in range(N)]
ans = 0
for i in range(N, 0, -1):
re = a[i]
if re:
if f[i] == 0: v = 0; ans += 1
else:
v = k[i]
if v < K: ans += 1
v += 1
if v ... | {
"input": [
"6 3\n0\n0\n2\n3\n4\n5",
"6 6\n0\n0\n2\n3\n4\n5",
"2 9\n0\n0\n2\n3\n4\n5",
"4 3\n0\n0\n2\n3\n4\n5",
"4 1\n0\n0\n2\n3\n4\n5",
"5 25\n0\n1\n0\n3\n1\n17",
"0 22\n0\n1\n1\n1\n1\n6",
"1 16\n0\n0\n2\n5\n4\n2",
"12 3\n0\n0\n0\n3\n4\n5",
"7 10\n0\n0\n2\n3\n1\n0",
"11 4... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
problem
In Ikatta, the SNS used by AOR Ika-chan, posts are called tweets.
And in squid, there is a concern that visibility will deteriorate if there are many replies to tweets, so w... |
p02213 Don't Rotate the Dice!_19476 | Problem statement
I have a grid of $ H $ rows and $ W $ columns. Hereafter, the cells in the $ i $ row and $ j $ column on the grid are written as $ (i, j) $ cells.
Each cell in the grid has a number between $ 1 $ and $ 6 $, or the letter `#` in $ 1 $ each. However, `#` is always written in the cell of $ (i, j) $ whe... | import sys
sys.setrecursionlimit(pow(10, 8))
S = [6, 3, 1, 4, 2, 5]
H, W = map(int, input().split())
X = []
for i in range(H):
X.append(input().strip())
def migi(S):
return [S[1], S[2], S[3], S[0], S[4], S[5]]
def hidari(S):
return [S[3], S[0], S[1], S[2], S[4], S[5]]
def sita(S):
return [S[4], S[1], ... | {
"input": [
"3 3\n631\n4#2\n516",
"3 3\n631\n4#2\n486",
"3 2\n631\n4#2\n246",
"3 3\n631\n4#2\n246",
"3 2\n631\n4$2\n246",
"3 3\n421\n4#2\n516",
"3 3\n631\n4#2\n646",
"3 3\n631\n4#2\n266",
"1 2\n631\n4#2\n246",
"3 2\n631\n4$2\n153",
"3 3\n631\n4#3\n646",
"3 3\n734\n4#2\... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Problem statement
I have a grid of $ H $ rows and $ W $ columns. Hereafter, the cells in the $ i $ row and $ j $ column on the grid are written as $ (i, j) $ cells.
Each cell in the... |
p02367 Bridges_19479 | Find bridges of an undirected graph G(V, E).
A bridge (also known as a cut-edge) is an edge whose deletion increase the number of connected components.
Constraints
* 1 ≤ |V| ≤ 100,000
* 0 ≤ |E| ≤ 100,000
* The graph is connected
* There are no parallel edges
* There are no self-loops
Input
|V| |E|
s0 t0
s1 t1
:
s... | import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): retu... | {
"input": [
"5 4\n0 1\n1 2\n2 3\n3 4",
"4 4\n0 1\n0 2\n1 2\n2 3",
"5 4\n0 1\n1 2\n1 3\n3 4",
"4 4\n0 1\n0 2\n1 2\n2 4",
"4 4\n0 1\n1 2\n1 2\n2 4",
"4 3\n0 1\n1 2\n1 2\n2 4",
"4 3\n0 1\n1 4\n1 2\n2 4",
"5 4\n0 1\n1 3\n2 3\n3 4",
"4 2\n0 1\n0 2\n1 2\n2 3",
"2 4\n0 1\n0 2\n1 2\n2... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Find bridges of an undirected graph G(V, E).
A bridge (also known as a cut-edge) is an edge whose deletion increase the number of connected components.
Constraints
* 1 ≤ |V| ≤ 100,... |
1033_D. Divisors_19489 | You are given n integers a_1, a_2, …, a_n. Each of a_i has between 3 and 5 divisors. Consider a = ∏ a_i — the product of all input integers. Find the number of divisors of a. As this number may be very large, print it modulo prime number 998244353.
Input
The first line contains a single integer n (1 ≤ n ≤ 500) — the ... | from math import gcd
def divisors(n, a):
d = {}
bad = []
for i in range(n):
c = a[i]
if (int(c ** 0.25 + 0.0001)) ** 4 == c:
p = int(c ** 0.25 + 0.0001)
if p not in d:
d[p] = 4
else:
d[p] += 4
elif (int(c ** (1 / ... | {
"input": [
"3\n4\n8\n16\n",
"8 \n4606061759128693\n4606066102679989\n4606069767552943\n4606063116488033\n4606063930903637\n4606064745319241\n4606063930904021\n4606065559735517",
"3\n9\n15\n143",
"1\n7400840699802997\n",
"4\n2 2 3\n2 2 3\n2 2 5\n2 3 7\n",
"4\n2 7 7\n3 7 7 7\n2 7 7\n4 7 7 7 7\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given n integers a_1, a_2, …, a_n. Each of a_i has between 3 and 5 divisors. Consider a = ∏ a_i — the product of all input integers. Find the number of divisors of a. As this ... |
1056_B. Divide Candies_19493 | Arkady and his friends love playing checkers on an n × n field. The rows and the columns of the field are enumerated from 1 to n.
The friends have recently won a championship, so Arkady wants to please them with some candies. Remembering an old parable (but not its moral), Arkady wants to give to his friends one set o... | n,m=map(int,input().split())
s=list()
for i in range(1,m+1):
for j in range(1,m+1):
if (i**2+j**2)%m==0:
s.append([i,j])
ans=0
for k in s:
#print(k)
ky=(n-k[0])//(m)+1
my=(n-k[1])//(m)+1
ans+=ky*my
print(ans) | {
"input": [
"3 3\n",
"6 5\n",
"1000000000 1\n",
"999999999 228\n",
"1 10\n",
"15 1000\n",
"10000 3\n",
"1000000000 1000\n",
"1 1\n",
"10000 2\n",
"100 100\n",
"1000 999\n",
"1000000000 81\n",
"10000 1\n",
"10000 5\n",
"10 200\n",
"12345 1\n",
"3... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Arkady and his friends love playing checkers on an n × n field. The rows and the columns of the field are enumerated from 1 to n.
The friends have recently won a championship, so Ark... |
1099_C. Postcard_19499 | Andrey received a postcard from Irina. It contained only the words "Hello, Andrey!", and a strange string consisting of lowercase Latin letters, snowflakes and candy canes. Andrey thought that this string is an encrypted message, and decided to decrypt it.
Andrey noticed that snowflakes and candy canes always stand af... | s=input()
k=int(input())
temp=""
cnt=0
for i in range(len(s)):
if(s[i]=="?" or s[i]=="*"):
cnt+=1
continue
else:
temp+=s[i]
#print(temp,len(temp))
if(len(temp)-cnt>k):
print("Impossible")
elif(len(temp)==k):
print(temp)
elif(len(temp)<k):
req=k-len(temp)
temp2=""
flag=0
for i in range(len(s)):
if(s[i]==... | {
"input": [
"ab?a\n3\n",
"ababb\n5\n",
"hw?ap*yn?eww*ye*ar\n12\n",
"ab?a\n2\n",
"ab?a\n1\n",
"m?tsw\n98\n",
"cqbpdkhounszhavfvgjqogwnwblypesjyvjiqxartehljficmjcfvgiwcknmilplixlbcuzifkgxvawlhmzufjgxhkfodihhsguc\n100\n",
"hw?ap*yn?eww*ye*ar\n12\n",
"np*lr*lg*br*t*x\n26\n",
"flvl... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Andrey received a postcard from Irina. It contained only the words "Hello, Andrey!", and a strange string consisting of lowercase Latin letters, snowflakes and candy canes. Andrey tho... |
111_B. Petya and Divisors_19503 | Little Petya loves looking for numbers' divisors. One day Petya came across the following problem:
You are given n queries in the form "xi yi". For each query Petya should count how many divisors of number xi divide none of the numbers xi - yi, xi - yi + 1, ..., xi - 1. Help him.
Input
The first line contains an int... | maxn=100000
div=[0]*(maxn+1)
last=[-maxn]*(maxn+1)
for i in range(maxn+1):
div[i]=list()
for i in range(2,maxn+1):
for j in range(i,maxn+1,i):
div[j].append(i)
t=int(input())
for k in range(0,t):
x_i,y_i = input().split(" ")
x_i=int(x_i)
y_i=int(y_i)
if y_i==0:
print(len(div[... | {
"input": [
"6\n4 0\n3 1\n5 2\n6 2\n18 4\n10000 3\n",
"15\n94836 0\n22780 1\n48294 0\n24834 3\n37083 2\n57862 0\n37231 1\n81795 7\n32835 2\n4696 8\n95612 0\n7536 6\n70084 5\n72956 10\n41647 7\n",
"20\n68260 0\n819 1\n54174 1\n20460 1\n25696 2\n81647 4\n17736 4\n91307 5\n5210 4\n87730 2\n4653 8\n11044 6\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Little Petya loves looking for numbers' divisors. One day Petya came across the following problem:
You are given n queries in the form "xi yi". For each query Petya should count how ... |
1186_C. Vus the Cossack and Strings_19511 | Vus the Cossack has two binary strings, that is, strings that consist only of "0" and "1". We call these strings a and b. It is known that |b| ≤ |a|, that is, the length of b is at most the length of a.
The Cossack considers every substring of length |b| in string a. Let's call this substring c. He matches the corresp... | a=input()
b=input()
A=[]
al=len(a)
bl=len(b)
A.append(0)
count=0
for x in a:
if x=='1':
count+=1
A.append(count)
evencount=0
bcount=0
for x in b:
if x=='1':
bcount+=1
for i in range((al+1)-bl):
acount=A[i+bl]-A[i]
if (acount%2)==(bcount%2):
evencount+=1
print(evencount)
| {
"input": [
"01100010\n00110\n",
"1010111110\n0110\n",
"0\n1\n",
"1011101100\n1100001\n",
"10010110100000101100\n11101\n",
"1011101100\n1000001\n",
"10010110100000101100\n11001\n",
"1010111110\n0111\n",
"10010110100000101100\n10001\n",
"1010111110\n0011\n",
"01100010\n1011... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vus the Cossack has two binary strings, that is, strings that consist only of "0" and "1". We call these strings a and b. It is known that |b| ≤ |a|, that is, the length of b is at mo... |
1205_B. Shortest Cycle_19515 | You are given n integer numbers a_1, a_2, ..., a_n. Consider graph on n nodes, in which nodes i, j (i≠ j) are connected if and only if, a_i AND a_j≠ 0, where AND denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND).
Find the length of the shortest cycle in this graph or determine th... | from collections import *
import sys
# "". join(strings)
def ri():
return int(input())
def rl():
return list(map(int, input().split()))
n = ri()
aa = rl()
zero_cnt = 0
aa = [value for value in aa if value != 0]
n = len(aa)
edges = set()
graph = defaultdict(list)
bit_shared = default... | {
"input": [
"4\n1 2 4 8\n",
"5\n5 12 9 16 48\n",
"4\n3 6 28 9\n",
"150\n0 0 0 0 0 0 0 2537672836907008 0 0 0 0 0 0 16384 0 0 0 0 34360787232 0 0 70871155232 0 0 0 0 0 0 0 0 0 0 0 2256197860262016 0 0 0 0 0 0 0 0 0 0 536872961 0 0 0 0 0 0 0 0 0 0 33619968 0 0 0 0 0 0 0 0 0 0 0 0 37189881297899520 0 18... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given n integer numbers a_1, a_2, ..., a_n. Consider graph on n nodes, in which nodes i, j (i≠ j) are connected if and only if, a_i AND a_j≠ 0, where AND denotes the [bitwise ... |
1248_C. Ivan the Fool and the Probability Theory_19521 | Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n r... | N = int(1e5+3)
MOD = int(1e9+7)
memo = [0] * N
def dp():
memo[0] = 2
memo[1] = 2
for i in range(2, N):
memo[i] = (memo[i-1] + memo[i-2]) % MOD
n, m = map(int, input().split())
dp()
print((memo[n] + - 1 + memo[m] - 1) % MOD)
| {
"input": [
"2 3\n",
"91697 91697\n",
"2 1\n",
"1 99998\n",
"13771 94814\n",
"100000 99999\n",
"2 5\n",
"100000 1\n",
"3 6\n",
"99999 99999\n",
"99998 1\n",
"1 2\n",
"24538 86821\n",
"1 99999\n",
"68869 1\n",
"1 3\n",
"52702 64157\n",
"99999 1\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got... |
1266_G. Permutation Concatenation_19525 | Let n be an integer. Consider all permutations on integers 1 to n in lexicographic order, and concatenate them into one big sequence P. For example, if n = 3, then P = [1, 2, 3, 1, 3, 2, 2, 1, 3, 2, 3, 1, 3, 1, 2, 3, 2, 1]. The length of this sequence is n ⋅ n!.
Let 1 ≤ i ≤ j ≤ n ⋅ n! be a pair of indices. We call the... | n = int(input())
f_n = n
cnt = 0
for k in range(n-1, 0, -1):
cnt += f_n
f_n *= k
if f_n >= 998244353:
f_n %= 998244353
print((n*f_n-cnt)%998244353) | {
"input": [
"2\n",
"10\n",
"20\n",
"623847\n",
"9\n",
"19\n",
"5\n",
"17\n",
"78266\n",
"1872\n",
"3\n",
"98232\n",
"7\n",
"16\n",
"15\n",
"18\n",
"898934\n",
"1000000\n",
"11\n",
"6\n",
"8\n",
"152\n",
"4\n",
"13\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Let n be an integer. Consider all permutations on integers 1 to n in lexicographic order, and concatenate them into one big sequence P. For example, if n = 3, then P = [1, 2, 3, 1, 3,... |
1288_B. Yet Another Meme Problem_19529 | Try guessing the statement from this picture <http://tiny.cc/ogyoiz>.
You are given two integers A and B, calculate the number of pairs (a, b) such that 1 ≤ a ≤ A, 1 ≤ b ≤ B, and the equation a ⋅ b + a + b = conc(a, b) is true; conc(a, b) is the concatenation of a and b (for example, conc(12, 23) = 1223, conc(100, 11)... | for _ in range(int(input())):
A, B = list(map(int, input().split()))
res = 0
seed = 9
while seed <= B:
res += A
seed = seed*10 + 9
print(res)
| {
"input": [
"3\n1 11\n4 2\n191 31415926\n",
"1\n9 9009\n",
"1\n8585 99\n",
"1\n8585 8976\n",
"1\n12112004 98798745\n",
"1\n1 99999\n",
"1\n10 9009\n",
"1\n8585 83\n",
"1\n15751 8976\n",
"1\n12112004 33023389\n",
"1\n2 99999\n",
"3\n1 7\n4 2\n191 31415926\n",
"1\n85... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Try guessing the statement from this picture <http://tiny.cc/ogyoiz>.
You are given two integers A and B, calculate the number of pairs (a, b) such that 1 ≤ a ≤ A, 1 ≤ b ≤ B, and the... |
1331_E. Jordan Smiley_19533 | <image>
Input
The input contains two integers row, col (0 ≤ row, col ≤ 63), separated by a single space.
Output
Output "IN" or "OUT".
Examples
Input
0 0
Output
OUT
Input
27 0
Output
IN
Input
0 27
Output
OUT
Input
27 27
Output
IN | s = [
"0000000000000000000000000010101111110100000000000000000000000000",
"0000000000000000000000101110101010010111110000000000000000000000",
"0000000000000000000011101000100011010000100100000000000000000000",
"0000000000000000011110101011111000011110101110100000000000000000",
"00000000000000001100000010100000111100001... | {
"input": [
"0 0\n",
"0 27\n",
"27 27\n",
"27 0\n",
"0 45\n",
"53 27\n",
"27 1\n",
"0 18\n",
"51 1\n",
"0 13\n",
"51 0\n",
"1 13\n",
"0 6\n",
"0 10\n",
"0 8\n",
"0 3\n",
"1 0\n",
"1 1\n",
"27 36\n",
"9 0\n",
"32 1\n",
"0 22\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
<image>
Input
The input contains two integers row, col (0 ≤ row, col ≤ 63), separated by a single space.
Output
Output "IN" or "OUT".
Examples
Input
0 0
Output
OUT
Input... |
1351_C. Skier_19537 | Skier rides on a snowy field. Its movements can be described by a string of characters 'S', 'N', 'W', 'E' (which correspond to 1 meter movement in the south, north, west or east direction respectively).
It is known that if he moves along a previously unvisited segment of a path (i.e. this segment of the path is visite... | num_lines = int(input())
for _ in range(num_lines):
d = input()
c = 0
points = set()
start_point = (0, 0)
for s in d:
if s == 'N':
end_point = (start_point[0] + 1, start_point[1])
if s == 'S':
end_point = (start_point[0] - 1, start_point[1])
if s == ... | {
"input": [
"5\nNNN\nNS\nWWEN\nWWEE\nNWNWS\n",
"1\nENNNNNNNNNNNSSSSSSSSSSSEEEEEEEEEEN\n",
"1\nNEEEEEEEEEEEWWWWWWWWWWWNNNNNNNNNNE\n",
"1\nENNNNNNNNNNNSSSSSSSNSSSEEEEEEEEEES\n",
"5\nNNN\nNS\nWWEN\nEEWW\nNWNWS\n",
"1\nNNNNNNNNNNNESSSSSSSNSSSEEEEEEEEEES\n",
"1\nNNNNSNNNNNNESSSSSSSNSNSEEEEEEEE... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Skier rides on a snowy field. Its movements can be described by a string of characters 'S', 'N', 'W', 'E' (which correspond to 1 meter movement in the south, north, west or east direc... |
1371_E1. Asterism (Easy Version)_19541 | This is the easy version of the problem. The difference between versions is the constraints on n and a_i. You can make hacks only if all versions of the problem are solved.
First, Aoi came up with the following idea for the competitive programming problem:
Yuzu is a girl who collecting candies. Originally, she has x ... | import sys
input = sys.stdin.readline
n,p=map(int,input().split())
A=sorted(map(int,input().split()))
MAX=A[-1]
start=max(A[0],MAX-(n-1))
S=[]
ind=0
for c in range(start,MAX+1):
while ind<n and A[ind]<=c:
ind+=1
S.append(ind)
#print(S)
SS=[S[i]-i for i in range(len(S))]
MAX=10**9
MIN=0
for i in ran... | {
"input": [
"4 3\n2 3 5 6\n",
"3 2\n3 4 5\n",
"4 3\n9 1 1 1\n",
"6 5\n589325244 589325243 589325246 589325243 589325246 589325243\n",
"4 2\n1070 1070 1069 1069\n",
"3 2\n568378695 568378695 568378694\n",
"6 5\n880 883 884 882 878 881\n",
"3 2\n795 611 751\n",
"3 2\n472048795 90777... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This is the easy version of the problem. The difference between versions is the constraints on n and a_i. You can make hacks only if all versions of the problem are solved.
First, Ao... |
1394_B. Boboniu Walks on Graph_19544 | Boboniu has a directed graph with n vertices and m edges.
The out-degree of each vertex is at most k.
Each edge has an integer weight between 1 and m. No two edges have equal weights.
Boboniu likes to walk on the graph with some specific rules, which is represented by a tuple (c_1,c_2,…,c_k). If he now stands on a v... | from random import randrange
import sys
input = sys.stdin.buffer.readline
def solve(digit, res):
ans = 0
if digit == k:
return int(res == zob_all)
for i in range(digit + 1):
ans += solve(digit + 1, res^zob[digit][i])
return ans
n, m, k = map(int, input().split())
edges = [list(map(in... | {
"input": [
"5 5 1\n1 4 1\n5 1 2\n2 5 3\n4 3 4\n3 2 5\n",
"4 6 3\n4 2 1\n1 2 2\n2 4 3\n4 1 4\n4 3 5\n3 1 6\n",
"6 13 4\n3 5 1\n2 5 2\n6 3 3\n1 4 4\n2 6 5\n5 3 6\n4 1 7\n4 3 8\n5 2 9\n4 2 10\n2 1 11\n6 1 12\n4 6 13\n",
"9 60 9\n8 4 1\n2 6 2\n4 3 3\n2 9 4\n6 7 5\n7 6 6\n7 8 7\n9 5 8\n2 8 9\n1 8 10\n2 7... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Boboniu has a directed graph with n vertices and m edges.
The out-degree of each vertex is at most k.
Each edge has an integer weight between 1 and m. No two edges have equal weight... |
1418_G. Three Occurrences_19547 | You are given an array a consisting of n integers. We denote the subarray a[l..r] as the array [a_l, a_{l + 1}, ..., a_r] (1 ≤ l ≤ r ≤ n).
A subarray is considered good if every integer that occurs in this subarray occurs there exactly thrice. For example, the array [1, 2, 2, 2, 1, 1, 2, 2, 2] has three good subarrays... | import random
n = int(input())
a = list(map(int, input().split()))
a.insert(0, 0)
cnt = [0] * (n + 1)
cnt2 = [0] * (n + 1)
hashs = [0] * (n + 1)
r1 = [None] * (n + 1)
r2 = [None] * (n + 1)
for i in range(1, n + 1):
r1[i] = random.randint(1, 1000000000000)
r2[i] = random.randint(1, 1000000000000)
mpp = {
... | {
"input": [
"10\n1 2 3 4 1 2 3 1 2 3\n",
"12\n1 2 3 4 3 4 2 1 3 4 2 1\n",
"9\n1 2 2 2 1 1 2 2 2\n",
"100\n79 79 79 97 97 97 64 64 64 2 2 2 38 38 38 65 65 65 10 10 10 25 25 25 53 53 53 73 73 73 11 11 11 29 29 29 93 93 93 73 73 73 89 89 89 72 72 72 49 49 49 78 78 78 92 92 92 90 90 90 95 95 95 92 92 92 ... | 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. We denote the subarray a[l..r] as the array [a_l, a_{l + 1}, ..., a_r] (1 ≤ l ≤ r ≤ n).
A subarray is considered good if every inte... |
1436_F. Sum Over Subsets_19550 | You are given a multiset S. Over all pairs of subsets A and B, such that:
* B ⊂ A;
* |B| = |A| - 1;
* greatest common divisor of all elements in A is equal to one;
find the sum of ∑_{x ∈ A}{x} ⋅ ∑_{x ∈ B}{x}, modulo 998 244 353.
Input
The first line contains one integer m (1 ≤ m ≤ 10^5): the number of di... | import sys
input=sys.stdin.readline
max_n=10**5+1
mod=998244353
spf=[i for i in range(max_n)]
prime=[True for i in range(max_n)]
mobius=[0 for i in range(max_n)]
prime[0]=prime[1]=False
mobius[1]=1
primes=[]
for i in range(2,max_n):
if(prime[i]):
spf[i]=i
mobius[i]=-1
primes.append(i)
f... | {
"input": [
"1\n1 5\n",
"4\n1 1\n2 1\n3 1\n6 1\n",
"2\n1 1\n2 1\n",
"1\n21662 10\n",
"10\n82453 8\n43312 10\n57885 9\n16967 11\n83794 13\n20422 15\n85527 7\n13341 9\n15764 10\n99662 8\n",
"20\n77048 1\n35951 1\n84200 1\n85813 1\n48514 1\n41042 1\n98965 1\n59553 1\n51695 1\n22919 1\n4858 1\n88... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a multiset S. Over all pairs of subsets A and B, such that:
* B ⊂ A;
* |B| = |A| - 1;
* greatest common divisor of all elements in A is equal to one;
find t... |
1461_D. Divide and Summarize_19554 | Mike received an array a of length n as a birthday present and decided to test how pretty it is.
An array would pass the i-th prettiness test if there is a way to get an array with a sum of elements totaling s_i, using some number (possibly zero) of slicing operations.
<image>
An array slicing operation is conducted... | from sys import stdin, stdout
input = stdin.readline
print = stdout.write
s = set()
def rec(a):
s.add(sum(a))
c = (min(a) + max(a)) / 2
sl = sr = 0
left = []
right = []
for i in a:
if i <= c:
left += i,
sl += i
else:
right += i,
... | {
"input": [
"2\n5 5\n1 2 3 4 5\n1\n8\n9\n12\n6\n5 5\n3 1 3 1 3\n1\n2\n3\n9\n11\n",
"2\n5 5\n1 2 3 4 5\n1\n8\n9\n12\n6\n5 5\n0 1 3 1 3\n1\n2\n3\n9\n11\n",
"2\n5 5\n1 2 3 4 5\n1\n8\n9\n12\n6\n5 5\n0 1 3 1 3\n1\n2\n3\n2\n11\n",
"2\n5 5\n1 2 3 4 5\n1\n5\n9\n12\n6\n5 5\n3 1 3 1 3\n1\n2\n3\n9\n11\n",
"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Mike received an array a of length n as a birthday present and decided to test how pretty it is.
An array would pass the i-th prettiness test if there is a way to get an array with a... |
1486_E. Paired Payment_19558 | There are n cities and m bidirectional roads in the country. The roads in the country form an undirected weighted graph. The graph is not guaranteed to be connected. Each road has it's own parameter w. You can travel through the roads, but the government made a new law: you can only go through two roads at a time (go f... | import sys, io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
read = lambda: map(int, input().split())
from heapq import heappush, heappop
inf = 1e10
n, m = read()
e = {}
for _ in range(m):
v, u, w = read()
v -= 1
u -= 1
if v not in e:
e[v] = []
if u not in e:
e[u]... | {
"input": [
"3 2\n1 2 1\n2 3 2\n",
"5 6\n1 2 3\n2 3 4\n3 4 5\n4 5 6\n1 5 1\n2 4 2\n",
"10 20\n10 1 15\n7 1 32\n5 3 36\n3 9 14\n3 4 19\n6 8 4\n9 6 18\n7 3 38\n10 7 12\n7 5 29\n7 6 14\n6 2 40\n8 9 19\n7 8 11\n7 4 19\n2 1 38\n10 9 3\n6 5 50\n10 3 41\n1 8 3\n",
"2 1\n2 1 48\n",
"10 20\n10 1 15\n7 1 3... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n cities and m bidirectional roads in the country. The roads in the country form an undirected weighted graph. The graph is not guaranteed to be connected. Each road has it'... |
1538_A. Stone Game_19563 | Polycarp is playing a new computer game. This game has n stones in a row. The stone on the position i has integer power a_i. The powers of all stones are distinct.
Each turn Polycarp can destroy either stone on the first position or stone on the last position (in other words, either the leftmost or the rightmost stone... | t=int(input())
while t!=0:
t-=1
n=int(input())-1
a=list(map(int,input().split()))
le=min(a.index(max(a)),a.index(min(a)))
ri=max(a.index(max(a)),a.index(min(a)))
mid=ri-le-1
ri=n-ri
print(sum([le,ri,mid])-max(le,ri,mid)+2) | {
"input": [
"5\n5\n1 5 4 3 2\n8\n2 1 3 4 5 6 8 7\n8\n4 2 3 1 8 6 7 5\n4\n3 4 2 1\n4\n2 3 1 4\n",
"1\n10\n3 2 1 5 4 7 6 9 8 10\n",
"1\n52\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52\n",
"1\n52\n52 5... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarp is playing a new computer game. This game has n stones in a row. The stone on the position i has integer power a_i. The powers of all stones are distinct.
Each turn Polycarp... |
185_B. Mushroom Scientists_19569 | As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (x, y, z). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formula: <ima... | a=int(input())
b=list(map(int,input().split()))
if sum(b)==0:print(' '.join([str(a/3)]*3))
else:print(' '.join(map(str,map(lambda x:a*x/sum(b),b))))
| {
"input": [
"3\n1 1 1\n",
"3\n2 0 0\n",
"10\n0 0 0\n",
"557\n84 654 154\n",
"1000\n197 198 199\n",
"5\n0 0 0\n",
"9\n8 2 0\n",
"1\n1000 1000 1000\n",
"1000\n117 403 270\n",
"1\n0 0 0\n",
"706\n197 265 571\n",
"1000\n0 1 1\n",
"938\n414 308 795\n",
"188\n748 859... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (x, y, ... |
231_C. To Add or Not to Add_19574 | A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array.
However, before looking for such number, you are allowed to perform not more than k following operations — choose an arbitrary element from the array and add 1 to it. I... | import sys
import math as mt
input=sys.stdin.buffer.readline
#t=int(input())
t=1
for __ in range(t):
#n=int(input())
n,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
maxn,maxl=l[0],1
suma=[0]*(n+2)
suma[0]=0
for i in range(n):
suma[i+1]=suma[i]+l[i]
... | {
"input": [
"3 4\n5 5 5\n",
"5 3\n6 3 4 0 2\n",
"5 3\n3 1 2 2 1\n",
"7 999999990\n999999999 999999999 999999999 3 4 2 1\n",
"4 100\n1 1 1 1000000000\n",
"20 10\n-12 28 0 -27 16 25 -17 -25 9 -15 -38 19 33 20 -18 22 14 36 33 29\n",
"5 1000\n1 1 1 1000000000 998756787\n",
"4 1000000000\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array.
However, before looking for suc... |
257_B. Playing Cubes_19578 | Petya and Vasya decided to play a little. They found n red cubes and m blue cubes. The game goes like that: the players take turns to choose a cube of some color (red or blue) and put it in a line from left to right (overall the line will have n + m cubes). Petya moves first. Petya's task is to get as many pairs of nei... | #------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
BUF... | {
"input": [
"2 4\n",
"3 1\n",
"98813 893\n",
"947 883\n",
"304 122\n",
"9999 99999\n",
"900 1000\n",
"99801 38179\n",
"159 259\n",
"4 4\n",
"50 30\n",
"1 2\n",
"831 69318\n",
"80 120\n",
"99999 99997\n",
"9999 31411\n",
"12930 98391\n",
"7131 31... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Petya and Vasya decided to play a little. They found n red cubes and m blue cubes. The game goes like that: the players take turns to choose a cube of some color (red or blue) and put... |
280_B. Maximum Xor Secondary_19582 | Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x1, x2, ..., xk (k > 1) is such maximum element xj, that the following inequality holds: <image>.
The lucky number of the sequence of distinct positive integers x1, x2, ..., xk (k > 1) is t... | #http://codeforces.com/problemset/problem/281/D
#SC = TC = o(n)
n = int(input())
a = list(map(int, input().strip().split()))
stack = [] #decreasing stack
max_xor = 0
for k in range(n):
#if stack empty
if not stack:
stack.append(a[k])
#if less than top of stack
elif a[k]<stack[-1]:
max_xor = max(max_xor, a[... | {
"input": [
"5\n9 8 3 5 7\n",
"5\n5 2 1 4 3\n",
"10\n29272229 8752316 10025994 52398694 57994948 49609605 28150935 66061676 44865054 87041483\n",
"10\n3106954 3413954 3854371 85952704 17834583 20954227 58810981 7460648 97908613 97965110\n",
"10\n4547989 39261040 94929326 38131456 26174500 7152864... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x1, x2, ..., xk (k > 1) is such maximum element xj, t... |
303_A. Lucky Permutation Triple_19586 | Bike is interested in permutations. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] is not.
A permutation triple of permutations of length n (a, b, c) is called a... | n = int(input())
if n % 2 == 0:
print(-1)
else:
print(*range(n))
print(*range(n))
print(*map(lambda x: x * 2 % n, range(n))) | {
"input": [
"5\n",
"2\n",
"9\n",
"39\n",
"31598\n",
"16586\n",
"100000\n",
"31980\n",
"16968\n",
"73268\n",
"77\n",
"73650\n",
"41904\n",
"5014\n",
"87\n",
"99182\n",
"39\n",
"99998\n",
"20\n",
"72598\n",
"10465\n",
"1\n",
"3... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Bike is interested in permutations. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, [0, 2, 1] is a p... |
32_B. Borze_19590 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
Input
The first line contains a nu... | x=input()
code=x.split()
q=[]
for i in x:
q.append(i)
code=q
i=0
total=""
while i < len(code):
if(code[i] == '.'):
total = total + '0'
elif(code[i] == '-'):
if(code[i + 1] == '.'):
total =total + '1'
elif (code[i+1] == '-'):
total = total + '2'
i+=1
... | {
"input": [
"--.\n",
".-.--\n",
"-..-.--\n",
"-.....----.\n",
"-.-..-.--.---..---.-..---.-...-.-.----..-.---.-.---..-.--.---.-.-------.---.--....----.-.---.---.---.----.-----..---.-.-.-.-----.--.-------.-..\n",
"-..--.-.\n",
"--.--.--.---.--.-.---.-.-..-..--.-..---.-.....-..---.-----.--..... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to de... |
350_E. Wrong Floyd_19594 | Valera conducts experiments with algorithms that search for shortest paths. He has recently studied the Floyd's algorithm, so it's time to work with it.
Valera's already written the code that counts the shortest distance between any pair of vertexes in a non-directed connected graph from n vertexes and m edges, contai... | # written with help of editorial
n, m, k = map(int, input().split())
ban = list(map(int, input().split()))
if k == n or m > n * (n - 1) // 2 - k + 1:
print('-1')
else:
edges = [(i, j) for i in range(1, n + 1) for j in range(i + 1, n + 1)]
for i in range(1, k):
a = min(ban[i], ban[0])
b = m... | {
"input": [
"3 2 2\n1 2\n",
"3 3 2\n1 2\n",
"250 300 2\n157 204\n",
"99 4754 98\n42 72 26 62 58 59 33 83 63 74 15 44 66 16 90 49 31 71 1 77 18 99 78 48 53 80 36 87 68 9 20 51 5 81 60 7 3 37 17 28 27 73 40 98 88 14 24 55 32 70 96 92 67 50 46 25 84 94 29 12 52 89 11 2 13 91 61 45 23 65 43 35 97 34 6 54... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Valera conducts experiments with algorithms that search for shortest paths. He has recently studied the Floyd's algorithm, so it's time to work with it.
Valera's already written the ... |
375_A. Divisible by Seven_19598 | You have number a, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7.
Number a doesn't contain any leading zeroes and contains digits 1, 6, 8, 9 (it also can contain another digits). The resultin... | # Made By Mostafa_Khaled
bot = True
a=input()
cnt=[0]*10
for i in (1,6,8,9):
cnt[i]=-1
for i in a:
cnt[int(i)]+=1
mod = [1869, 1968, 9816, 6198, 1698, 1986, 1896, 1869]
modCnt=0
for i in range(1,10):
for j in range(cnt[i]):
modCnt= (modCnt*3 + i)%7
print(str(i)*cnt[i], end='')
modCnt=(10000*modCnt)%... | {
"input": [
"1689\n",
"18906\n",
"9825995656040286793128006047268547610068699214477842995873286607346639816314908021369221299622234988\n",
"16891\n",
"16899\n",
"16898\n",
"91111168\n",
"2419323689\n",
"9883291673084\n",
"1689999999999\n",
"16890000000000000000000000000000... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You have number a, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divis... |
397_C. On Number of Decompositions into Multipliers_19602 | You are given an integer m as a product of integers a1, a2, ... an <image>. Your task is to find the number of distinct decompositions of number m into the product of n ordered positive integers.
Decomposition into n products, given in the input, must also be considered in the answer. As the answer can be very large, ... | # by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO, IOBase
from collections import Counter
def factor(x,cou):
while not x%2:
x /= 2
cou[2] += 1
for i in range(3,int(x**0.5)+1,2):
while not x%i:
x //= i
cou[i] += 1
... | {
"input": [
"2\n5 7\n",
"3\n1 1 2\n",
"1\n15\n",
"1\n111546435\n",
"10\n6295 3400 4042 2769 3673 264 5932 4977 1776 5637\n",
"5\n387420489 244140625 387420489 387420489 1\n",
"2\n5 10\n",
"20\n16777216 1048576 524288 8192 8192 524288 2097152 8388608 1048576 67108864 16777216 1048576 4... | 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 m as a product of integers a1, a2, ... an <image>. Your task is to find the number of distinct decompositions of number m into the product of n ordered positi... |
41_D. Pawn_19606 | On some square in the lowest row of a chessboard a stands a pawn. It has only two variants of moving: upwards and leftwards or upwards and rightwards. The pawn can choose from which square of the lowest row it can start its journey. On each square lay from 0 to 9 peas. The pawn wants to reach the uppermost row having c... | import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
n, m, k = map(int, input().split())
k += 1
a = [tuple(map(int, input().rstrip())) for _ in range(n)]
empty = -1
dp = [[[empty] * k for _ in range(m)] for _ in range(n)]
prev = [[[(-1, -1, '*')] * k f... | {
"input": [
"2 2 10\n98\n75\n",
"3 3 1\n123\n456\n789\n",
"3 3 0\n123\n456\n789\n",
"100 2 8\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
On some square in the lowest row of a chessboard a stands a pawn. It has only two variants of moving: upwards and leftwards or upwards and rightwards. The pawn can choose from which s... |
446_B. DZY Loves Modification_19610 | As we know, DZY loves playing games. One day DZY decided to play with a n × m matrix. To be more precise, he decided to modify the matrix with exactly k operations.
Each modification is one of the following:
1. Pick some row of the matrix and decrease each element of the row by p. This operation brings to DZY the v... | """
#If FastIO not needed, used this and don't forget to strip
#import sys, math
#input = sys.stdin.readline
"""
import os
import sys
from io import BytesIO, IOBase
import heapq as h
import bisect
from types import GeneratorType
BUFSIZE = 8192
class SortedList:
def __init__(self, iterable=[], _load=200):
... | {
"input": [
"2 2 2 2\n1 3\n2 4\n",
"2 2 5 2\n1 3\n2 4\n",
"5 5 20 100\n464 757 53 708 262\n753 769 189 38 796\n394 60 381 384 935\n882 877 501 615 464\n433 798 504 301 301\n",
"10 10 50 80\n529 349 889 455 946 983 482 179 590 907\n436 940 407 631 26 963 181 789 461 437\n367 505 888 521 449 741 900 99... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
As we know, DZY loves playing games. One day DZY decided to play with a n × m matrix. To be more precise, he decided to modify the matrix with exactly k operations.
Each modification... |
468_C. Hack it!_19614 | Little X has met the following problem recently.
Let's define f(x) as the sum of digits in decimal representation of number x (for example, f(1234) = 1 + 2 + 3 + 4). You are to calculate <image>
Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the foll... | A = int(input())
F1019 = (45 * 19 * 10**18 + 1) % A
r = (-F1019) % A
print(r + 1, 10**19 + r)
| {
"input": [
"46\n",
"126444381000032\n",
"4\n",
"10000\n",
"7\n",
"36\n",
"10\n",
"999999999999999999\n",
"789136710974630947\n",
"999999999999999989\n",
"1000000000000000000\n",
"776930\n",
"219760524792138559\n",
"58929554039\n",
"10\n",
"43\n",
"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Little X has met the following problem recently.
Let's define f(x) as the sum of digits in decimal representation of number x (for example, f(1234) = 1 + 2 + 3 + 4). You are to calc... |
490_C. Hacking Cypher_19618 | Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long inte... | from sys import stdin
c = list(stdin.readline()[:-1:])
a,b = map(int,input().split())
pref = []
pref1 = []
summ = 0
summ1 = 0
boo = 0
x = 1
for i in range(len(c)):
summ = summ * 10 + int(c[i])
summ %= a
pref.append(summ)
for i in range(len(c)-1,-1,-1):
summ1 += x * int(c[i])
x *= 10
x %= b
s... | {
"input": [
"284254589153928171911281811000\n1009 1000\n",
"120\n12 1\n",
"116401024\n97 1024\n",
"8784054131798916\n9 61794291\n",
"4261508098904115227\n52546339 6430\n",
"4530228043401488\n71454701 8\n",
"425392502895812\n4363 2452\n",
"8552104774\n973 76\n",
"142222201649130\n4... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusio... |
514_C. Watto and Mechanism_19622 | Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with n strings. Then the mechanism should be able to process queries of the following type: "Given string s, determine if the memory of the mech... | from sys import stdin
from functools import reduce
from collections import defaultdict
_data = iter(stdin.read().split('\n'))
def input():
while True:
return next(_data)
n, m = [int(x) for x in input().split()]
B = 10007
MOD = 1000000000000000003
h = lambda s: reduce(lambda s, c: (B * s + ord(c)) % MOD, s... | {
"input": [
"2 3\naaaaa\nacacaca\naabaa\nccacacc\ncaaac\n",
"5 4\nab\ncacab\ncbabc\nacc\ncacab\nabc\naa\nacbca\ncb\n",
"1 5\nacbacbacb\ncbacbacb\nacbacbac\naacbacbacb\nacbacbacbb\nacbaabacb\n",
"1 1\nbbbbbbbaaaabbbbbaabbbba\naaabbbabbbbbbbaabbabbbb\n",
"9 9\ncaccbcacabccba\naacbcbcaabacbcbcba\nba... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with n ... |
540_D. Bad Luck Island_19626 | The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper... | A, B, C = map(lambda x: int(x)+1, input().split())
M = max(max(A, B), C)
p = [[[0] * (M) for i in range(M)] for j in range(M)]
for a in range(M):
for b in range(M):
for c in range(M):
val=0
if a == 0 or b == 0:
val=0
elif c == 0:
val=1... | {
"input": [
"2 1 2\n",
"2 2 2\n",
"1 1 3\n",
"98 100 99\n",
"100 99 100\n",
"100 1 100\n",
"39 96 87\n",
"78 80 80\n",
"50 93 89\n",
"99 1 100\n",
"5 5 5\n",
"4 4 4\n",
"100 99 98\n",
"100 50 40\n",
"100 2 100\n",
"100 99 99\n",
"100 98 99\n",
"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet eq... |
58_C. Trees_19632 | On Bertown's main street n trees are growing, the tree number i has the height of ai meters (1 ≤ i ≤ n). By the arrival of the President of Berland these trees were decided to be changed so that their heights formed a beautiful sequence. This means that the heights of trees on ends (the 1st one and the n-th one) should... | from collections import defaultdict as dd
n = int(input())
a = list(map(int, input().split()))
count = dd(lambda: 0)
for i in range(n//2):
count[a[i]-i] += 1
count[a[n-i-1] - i] += 1
#print(i, a[i]-i, a[n-i-1]-i)
#print([count[k] for k in count.keys()])
if n%2: count[a[n//2]-n//2] += 1
print(n - max([count... | {
"input": [
"4\n1 2 2 1\n",
"3\n2 2 2\n",
"1\n100000\n",
"5\n4 5 6 5 1\n",
"10\n73905 73906 73907 85732 73909 73909 73908 73907 73906 73905\n",
"7\n1 2 3 7 6 5 4\n",
"9\n100 12 13 14 15 14 13 12 11\n",
"5\n3 3 4 3 2\n",
"5\n1 1 1 1 1\n",
"1\n2727\n",
"5\n92605 92606 41969 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
On Bertown's main street n trees are growing, the tree number i has the height of ai meters (1 ≤ i ≤ n). By the arrival of the President of Berland these trees were decided to be chan... |
611_E. New Year and Three Musketeers_19636 | Do you know the story about the three musketeers? Anyway, you must help them now.
Richelimakieu is a cardinal in the city of Bearis. He found three brave warriors and called them the three musketeers. Athos has strength a, Borthos strength b, and Caramis has strength c.
The year 2015 is almost over and there are stil... | import sys,io,os
try:Z=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
except:Z=lambda:sys.stdin.readline().encode()
X=lambda x:print(x)or quit()
n=int(Z());a,b,c=sorted(map(int,Z().split()));t=map(int,Z().split());d=[0]*7
B=[a,b]+sorted([a+b,c])+[a+c,b+c,a+b+c]
for i in t:
for v in range(7):
if i<=B[v... | {
"input": [
"5\n10 20 30\n1 1 1 1 51\n",
"7\n30 20 10\n34 19 50 33 88 15 20\n",
"5\n10 20 30\n1 1 1 1 50\n",
"6\n10 5 10\n10 9 5 25 20 5\n",
"3\n2 2 2\n1 1 1\n",
"1\n100000000 100000000 100000000\n100000000\n",
"1\n100000000 100000000 100000000\n1\n",
"4\n6 7 8\n8 8 8 12\n",
"1\n1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Do you know the story about the three musketeers? Anyway, you must help them now.
Richelimakieu is a cardinal in the city of Bearis. He found three brave warriors and called them the... |
631_B. Print Check_19640 | Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the pr... | def main():
n, m, k = map(int, input().split())
lst = [[0] * m for _ in range(n)]
rows = {}
cols = {}
for i in range(k):
q, idx, a = map(int, input().split())
if q == 1:
rows[idx - 1] = (a, i)
else:
cols[idx - 1] = (a, i)
for r in range(n):
... | {
"input": [
"5 3 5\n1 1 1\n1 3 1\n1 5 1\n2 1 1\n2 3 1\n",
"3 3 3\n1 1 3\n2 2 1\n1 2 2\n",
"1 10 1\n1 1 1000000000\n",
"2 2 3\n1 1 1\n1 2 1\n2 1 2\n",
"1 1 1\n1 1 1000000000\n",
"1 2 1\n2 2 1000000000\n",
"2 1 5\n1 1 7\n1 2 77\n2 1 777\n1 1 77\n1 2 7\n",
"1 2 4\n1 1 1\n2 1 2\n2 2 3\n1 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical st... |
706_C. Hard problem_19647 | Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help.
Vasiliy is given n strings consisting of lowercase English letters. He wants them to be sorted in lexicographical order (as in the dictionary), but he is not allowed to swap any of them. The only ope... | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random
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 list(map(int, sys.stdin.r... | {
"input": [
"3\n1 3 1\naa\nba\nac\n",
"2\n5 5\nbbb\naaa\n",
"2\n3 3\naaa\naa\n",
"2\n1 2\nba\nac\n",
"4\n1000000000 1000000000 1000000000 1000000000\nza\nbt\ncm\ndn\n",
"5\n1000000000 1000000000 1000000000 1000000000 1000000000\nea\ndb\ncc\nbd\nae\n",
"10\n1000000000 1000000000 1000000000... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help.
Vasiliy is given n strings consisting of lowercase English let... |
729_E. Subordinates_19651 | There are n workers in a company, each of them has a unique id from 1 to n. Exaclty one of them is a chief, his id is s. Each worker except the chief has exactly one immediate superior.
There was a request to each of the workers to tell how how many superiors (not only immediate). Worker's superiors are his immediate ... | n,s = map(int,input().split())
A = list(map(int,input().split()))
if A[s-1] != 0:
per = 1
A[s-1] = 0
else:
per = 0
A.sort()
maxs = max(A)
ans = [0] * (maxs + 1)
answer = maxs + 1
o = -1
for j in range(n):
if A[j] == 0:
o += 1
if ans[A[j]] == 0:
ans[A[j]] = 1
answer -= 1
... | {
"input": [
"5 3\n1 0 0 4 1\n",
"3 2\n2 0 2\n",
"3 3\n1 1 0\n",
"3 1\n2 1 1\n",
"10 6\n3 0 0 0 0 0 0 1 0 0\n",
"3 3\n2 1 0\n",
"9 1\n0 1 1 1 1 1 6 7 8\n",
"3 3\n2 1 2\n",
"3 2\n2 2 2\n",
"9 1\n0 0 0 2 5 5 5 5 5\n",
"5 5\n0 1 1 0 0\n",
"2 2\n0 1\n",
"6 1\n5 2 1 3 3 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n workers in a company, each of them has a unique id from 1 to n. Exaclty one of them is a chief, his id is s. Each worker except the chief has exactly one immediate superio... |
74_A. Room Leader_19655 | Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.
In the beginning of the round the contestants are divided into rooms. Each room contains exactly n participants. During the contest the participants are suggested to solve five proble... | arr = []
for _ in range(0,int(input())):
arr.append(list(input().split()))
ans = []
for i in range(0,len(arr)):
sum = int(arr[i][1])*100 - int(arr[i][2])*50
for j in range(3,8):
sum += int(arr[i][j])
ans.append(sum)
a = max(ans)
for i in range(0,len(ans)):
if ans[i] == a:
print(arr[i][0])
break... | {
"input": [
"5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0\n",
"10\nW22kb1L1 0 39 0 465 0 1961 865\n1MCXiVYmu5ys0afl 0 38 0 0 0 1982 1241\nCxg706kUJtQ 0 23 211 0 0 1785 1056\nmzEY 0 16 0 0 0 1988... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.
In the beginning of the round the contestants ... |
797_E. Array Queries_19661 | a is an array of n positive integers, all of which are not greater than n.
You have to process q queries to this array. Each query is represented by two numbers p and k. Several operations are performed in each query; each operation changes p to p + ap + k. There operations are applied until p becomes greater than n. ... | from sys import stdin, stdout, setrecursionlimit
input = stdin.readline
# import string
# characters = string.ascii_lowercase
# digits = string.digits
# setrecursionlimit(int(1e5))
# dir = [-1,0,1,0,-1]
# moves = 'NESW'
inf = float('inf')
from functools import cmp_to_key
from collections import defaultdict as dd
from c... | {
"input": [
"3\n1 1 1\n3\n1 1\n2 1\n3 1\n",
"50\n49 21 50 31 3 19 10 40 20 5 47 12 12 30 5 4 5 2 11 23 5 39 3 30 19 3 23 40 4 14 39 50 45 14 33 37 1 15 43 30 45 23 32 3 9 17 9 5 14 12\n50\n36 29\n44 24\n38 22\n30 43\n15 19\n39 2\n13 8\n29 50\n37 18\n32 19\n42 39\n20 41\n14 11\n4 25\n14 35\n17 23\n1 29\n3 19\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
a is an array of n positive integers, all of which are not greater than n.
You have to process q queries to this array. Each query is represented by two numbers p and k. Several oper... |
818_A. Diplomas and Certificates_19665 | There are n students who have taken part in an olympiad. Now it's time to award the students.
Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and ce... | n,k = map(int,input().split())
p = (n // 2) //(k+1)
o = p * k
l = n - p - o
print(str(p)+' '+str(o)+' '+str(l)) | {
"input": [
"1000000000000 5\n",
"1000000000000 499999999999\n",
"18 2\n",
"9 10\n",
"1000000000000 1\n",
"1000000000000 32416187567\n",
"1000000000000 5915587276\n",
"216929598879 768233755932\n",
"999999999999 10000000000\n",
"1 1\n",
"999999999999 1000000000000\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n students who have taken part in an olympiad. Now it's time to award the students.
Some of them will receive diplomas, some wiil get certificates, and others won't receive... |
843_B. Interactive LowerBound_19669 | This is an interactive problem.
You are given a sorted in increasing order singly linked list. You should find the minimum integer in the list which is greater than or equal to x.
More formally, there is a singly liked list built on an array of n elements. Element with index i contains two integers: valuei is the int... | from random import sample
def R():
return map(int, input().split())
def ask(i):
print('?', i, flush=True)
v, nxt = R()
if v < 0:
exit()
return v, nxt
def ans(v):
print('!', v)
exit()
n, s, x = R()
mv = -1
i = s
S = 800
q = range(1, n + 1)
if n > S:
q = sample(q, S)
if s n... | {
"input": [
"5 3 80\n97 -1\n58 5\n16 2\n81 1\n79 4\n",
"1 1 0\n0 -1\n",
"5 3 974128233\n547205043 5\n318213550 1\n122625404 4\n184874700 2\n669820978 -1\n",
"5 3 80\n97 -1\n58 5\n16 2\n81 1\n79 4\n",
"10 3 2\n3 9\n9 -1\n0 7\n6 8\n5 4\n8 2\n1 10\n7 6\n4 5\n2 1\n",
"5 3 145337745\n619347297 5\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This is an interactive problem.
You are given a sorted in increasing order singly linked list. You should find the minimum integer in the list which is greater than or equal to x.
M... |
889_D. Symmetric Projections_19673 | You are given a set of n points on the plane. A line containing the origin is called good, if projection of the given set to this line forms a symmetric multiset of points. Find the total number of good lines.
Multiset is a set where equal elements are allowed.
Multiset is called symmetric, if there is a point P on t... | from fractions import Fraction
import time
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def to_tuple(self):
return (self.x, self.y)
def __repr__(self):
return "Point({}, {})".format(self.x, self.y)
def __eq__(self, other):
return self.to_tuple... | {
"input": [
"2\n4 3\n1 2\n",
"3\n1 2\n2 1\n3 3\n",
"10\n0 5\n1 0\n2 3\n3 2\n4 6\n5 9\n6 1\n7 8\n8 4\n9 7\n",
"10\n-7 6\n-16 11\n-9 -5\n3 4\n-8 12\n-17 6\n2 -1\n-5 15\n-7 4\n-6 -2\n",
"8\n11 -3\n12 -5\n10 -6\n9 -4\n8 -8\n6 -7\n7 -10\n5 -9\n",
"8\n-10000 4285\n-7143 -10000\n-4286 -1429\n-1429 -... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a set of n points on the plane. A line containing the origin is called good, if projection of the given set to this line forms a symmetric multiset of points. Find the t... |
912_B. New Year's Eve_19677 | Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains n sweet candies from the good ol' bakery, each labeled from 1 to n corresponding to its tastiness. No two candies have the same tastiness.
The choice of candies has a direc... | def parr(arr):
print(*arr, sep=' ')
def gcd(a, b):
while b:
if b % a == 0:
break
tmp = a
a = b % a
b = tmp
return a
# for _ in range(int(input())):
n, k = map(int, input().split())
ans = 0
if k == 1:
ans = n
else:
ans = int('1' * (len(bin(n)[2:])), 2)... | {
"input": [
"6 6\n",
"4 3\n",
"1000000000000000000 2\n",
"3 3\n",
"329594893019364551 25055600080496801\n",
"36028797018963967 345\n",
"1000000000000000000 1000000000000000000\n",
"815936580997298686 684083143940282566\n",
"4 1\n",
"2147483647 31\n",
"848698811 317703059\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains n sweet candies from the good ol' ba... |
934_B. A Prosperous Lot_19681 | Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside.
Big Banban is hesitating over the amount ... | k = int(input())
if(k>36):
print(-1) #at max 888888888888888888....10 power 18 , not more than that...
#in one 8, two loops ,so 36 loop
else:
print("8"*(k//2) + "6"*(k%2))
| {
"input": [
"2\n",
"6\n",
"1000000\n",
"25\n",
"16\n",
"37\n",
"20\n",
"23\n",
"38\n",
"33\n",
"87\n",
"40\n",
"6\n",
"462\n",
"5\n",
"1\n",
"34\n",
"7\n",
"14\n",
"3\n",
"32\n",
"15\n",
"88\n",
"11\n",
"12\n",
"2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the ... |
988_A. Diverse Team_19688 | There are n students in a school class, the rating of the i-th student on Codehorses is a_i. You have to form a team consisting of k students (1 ≤ k ≤ n) such that the ratings of all team members are distinct.
If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then pri... | n, k = map(int, input().split())
a = list(map(int, input().split()))
d = {}
for i in range(n):
d[a[i]] = i + 1
if len(d) < k:
print('NO')
else:
print('YES')
values = list(d.values())
for i in range(k):
print(values[i], end=' ') | {
"input": [
"5 3\n15 13 15 15 12\n",
"5 4\n15 13 15 15 12\n",
"4 4\n20 10 40 30\n",
"100 100\n63 100 75 32 53 24 73 98 76 15 70 48 8 81 88 58 95 78 27 92 14 16 72 43 46 39 66 38 64 42 59 9 22 51 4 6 10 94 28 99 68 80 35 50 45 20 47 7 30 26 49 91 77 19 96 57 65 1 11 13 31 12 82 87 93 34 62 3 21 79 56 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n students in a school class, the rating of the i-th student on Codehorses is a_i. You have to form a team consisting of k students (1 ≤ k ≤ n) such that the ratings of all ... |
p02724 AtCoder Beginner Contest 160 - Golden Coins_19703 | Takahashi loves gold coins. He gains 1000 happiness points for each 500-yen coin he has and gains 5 happiness points for each 5-yen coin he has. (Yen is the currency of Japan.)
Takahashi has X yen. If he exchanges his money so that he will gain the most happiness points, how many happiness points will he earn?
(We as... | x=int(input())
ans=0
print(500*(x//500)+5*(x//5)) | {
"input": [
"0",
"1000000000",
"1024",
"1",
"1000000001",
"656",
"-1",
"506",
"685",
"925",
"-8",
"989",
"-11",
"1802",
"2972",
"2636",
"1385",
"1233",
"865",
"-20",
"1608",
"2611",
"743",
"1352",
"1311",
"42",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Takahashi loves gold coins. He gains 1000 happiness points for each 500-yen coin he has and gains 5 happiness points for each 5-yen coin he has. (Yen is the currency of Japan.)
Takah... |
p02855 DISCO Presents Discovery Channel Code Contest 2020 Qual - Strawberry Cakes_19707 | Chokudai made a rectangular cake for contestants in DDCC 2020 Finals.
The cake has H - 1 horizontal notches and W - 1 vertical notches, which divide the cake into H \times W equal sections. K of these sections has a strawberry on top of each of them.
The positions of the strawberries are given to you as H \times W ch... | import bisect
H,W,K=map(int,input().split())
s=[""]*H
ans=[[0]*W for _ in range(H)]
St=[0]*H#i行目にイチゴがあるか?
St2=[]
for i in range(H):
s[i]=input()
if "#" in s[i]:
St[i]=1
St2.append(i)
a=1
#i行目,aからスタートして埋める
for i in range(H):
if St[i]==1:
flag=0
for j in r... | {
"input": [
"3 3 5\n#.#\n.#.\n#.#",
"13 21 106\n.....................\n.####.####.####.####.\n..#.#..#.#.#....#....\n..#.#..#.#.#....#....\n..#.#..#.#.#....#....\n.####.####.####.####.\n.....................\n.####.####.####.####.\n....#.#..#....#.#..#.\n.####.#..#.####.#..#.\n.#....#..#.#....#..#.\n.####.##... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Chokudai made a rectangular cake for contestants in DDCC 2020 Finals.
The cake has H - 1 horizontal notches and W - 1 vertical notches, which divide the cake into H \times W equal se... |
p02991 AtCoder Beginner Contest 132 - Hopscotch Addict_19711 | Ken loves ken-ken-pa (Japanese version of hopscotch). Today, he will play it on a directed graph G. G consists of N vertices numbered 1 to N, and M edges. The i-th edge points from Vertex u_i to Vertex v_i.
First, Ken stands on Vertex S. He wants to reach Vertex T by repeating ken-ken-pa. In one ken-ken-pa, he does th... | import sys
input = sys.stdin.readline
N, M = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(M):
a, b = map(int, input().split())
graph[a-1].append(b-1)
#graph[b-1].append(a-1)
S, T = map(int, input().split())
S -= 1; T -= 1
D = [[-1]*3 for _ in range(N)]
D[S][0] = 0
q = [(S, 0)]
w... | {
"input": [
"4 4\n1 2\n2 3\n3 4\n4 1\n1 3",
"6 8\n1 2\n2 3\n3 4\n4 5\n5 1\n1 4\n1 5\n4 6\n1 6",
"3 3\n1 2\n2 3\n3 1\n1 2",
"2 0\n1 2",
"4 4\n1 3\n2 3\n3 4\n4 1\n1 3",
"6 8\n1 4\n2 3\n3 4\n4 5\n5 1\n1 4\n1 5\n4 6\n1 6",
"3 3\n1 2\n2 3\n2 1\n1 2",
"3 1\n1 1\n3 3\n3 1\n1 2",
"4 1\n1 ... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Ken loves ken-ken-pa (Japanese version of hopscotch). Today, he will play it on a directed graph G. G consists of N vertices numbered 1 to N, and M edges. The i-th edge points from Ve... |
p03132 Yahoo Programming Contest 2019 - Ears_19715 | Snuke stands on a number line. He has L ears, and he will walk along the line continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a point with coordinate greater than L.
* He starts walking at a point with integer coordinate, and also finishes walking at a point with ... | n=int(input())
zot=lambda x:0 if x==0 else (x+1)%2+1
A=[int(input()) for i in range(n)]
D=[0,0,0,0,0]
for a in A:
d0 = D[0] + a
d1 = min(D[:2])+ [2,1,0][zot(a)]
d2 = min(D[:3])+ [1,0,1][zot(a)]
d3 = min(D[:4])+ [2,1,0][zot(a)]
d4 = min(D) + a
D=[d0,d1,d2,d3,d4]
print(min(D)) | {
"input": [
"4\n1\n0\n2\n3",
"8\n2\n0\n0\n2\n1\n3\n4\n1",
"7\n314159265\n358979323\n846264338\n327950288\n419716939\n937510582\n0",
"4\n1\n0\n4\n3",
"8\n2\n0\n0\n2\n0\n3\n4\n1",
"4\n0\n0\n4\n3",
"8\n2\n0\n1\n2\n0\n1\n0\n1",
"8\n2\n0\n1\n2\n0\n1\n0\n0",
"8\n4\n0\n0\n2\n0\n1\n2\n1",... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Snuke stands on a number line. He has L ears, and he will walk along the line continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a... |
p03275 AtCoder Beginner Contest 107 - Median of Medians_19718 | We will define the median of a sequence b of length M, as follows:
* Let b' be the sequence obtained by sorting b in non-decreasing order. Then, the value of the (M / 2 + 1)-th element of b' is the median of b. Here, / is integer division, rounding down.
For example, the median of (10, 30, 20) is 20; the median of ... | N=int(input())
A=list(map(int,input().split()))
A_sort=sorted(A)
ANSMIN=0
ANSMAX=N-1
cums=[None]*(N+1)
def midup(x):
cums[0]=0
for i in range(N):
if A[i]>=x:
cums[i+1]=cums[i]+1
else:
cums[i+1]=cums[i]-1
MINS=min(cums)
MAXS=max(cums)
#print(MINS,MAXS,cums)... | {
"input": [
"3\n10 30 20",
"10\n5 9 5 9 8 9 3 5 4 3",
"1\n10",
"3\n10 9 20",
"10\n5 9 5 9 8 4 3 5 4 3",
"1\n4",
"10\n5 9 5 9 16 8 3 5 4 3",
"1\n2",
"1\n16",
"1\n7",
"1\n3",
"1\n6",
"1\n1",
"3\n-1 9 3",
"3\n10 31 20",
"1\n19",
"1\n21",
"3\n12 8 3... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We will define the median of a sequence b of length M, as follows:
* Let b' be the sequence obtained by sorting b in non-decreasing order. Then, the value of the (M / 2 + 1)-th eleme... |
p03591 CODE FESTIVAL 2017 qual A - Snuke's favorite YAKINIKU_19724 | Ringo is giving a present to Snuke.
Ringo has found out that Snuke loves yakiniku (a Japanese term meaning grilled meat. yaki: grilled, niku: meat). He supposes that Snuke likes grilled things starting with `YAKI` in Japanese, and does not like other things.
You are given a string S representing the Japanese name of ... | import re
s = input()
if re.match('YAKI', s):
print('Yes')
else:
print('No')
| {
"input": [
"YAKINIKU",
"TAKOYAKI",
"YAK",
"UKINIKAY",
"UAKOYAKI",
"KAY",
"NKIUIKAY",
"IKAYOKAU",
"JAY",
"NKIUAKIY",
"AAKOYUKI",
"JAZ",
"OKIUAKIY",
"AAKPYUKI",
"ZAJ",
"OKIVAKIY",
"IKUYPKAA",
"[AJ",
"OKIVALIY",
"IKVYPKAA",
"[AK",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Ringo is giving a present to Snuke.
Ringo has found out that Snuke loves yakiniku (a Japanese term meaning grilled meat. yaki: grilled, niku: meat). He supposes that Snuke likes gril... |
p03910 CODE FESTIVAL 2016 Final - Exactly N points_19730 | The problem set at CODE FESTIVAL 20XX Finals consists of N problems.
The score allocated to the i-th (1≦i≦N) problem is i points.
Takahashi, a contestant, is trying to score exactly N points. For that, he is deciding which problems to solve.
As problems with higher scores are harder, he wants to minimize the highest... | N = int(input())
for n in range(1, N+1):
if n*(n+1)//2 >= N:
break
d = n*(n+1)//2-N
s = set(range(1, n+1))
s.discard(d)
for i in s:
print(i)
#print(sum(s))
| {
"input": [
"4",
"7",
"1",
"14",
"2",
"3",
"8",
"12",
"21",
"5",
"9",
"17",
"31",
"32",
"10",
"41",
"13",
"80",
"101",
"111",
"6",
"11",
"25",
"16",
"30",
"40",
"22",
"57",
"44",
"19",
"33",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The problem set at CODE FESTIVAL 20XX Finals consists of N problems.
The score allocated to the i-th (1≦i≦N) problem is i points.
Takahashi, a contestant, is trying to score exactly... |
p00014 Integral_19734 | Write a program which computes the area of a shape represented by the following three lines:
$y = x^2$
$y = 0$
$x = 600$
It is clear that the area is $72000000$, if you use an integral you learn in high school. On the other hand, we can obtain an approximative area of the shape by adding up areas of many rectangles... | while 1:
try:
d=int(input())
ans=0
for i in range(600//d):
ans+=d*d*d*i*i
print(ans)
except:break
| {
"input": [
"20\n10",
"20\n15",
"20\n4",
"20\n8",
"20\n2",
"20\n6",
"20\n1",
"20\n-1",
"20\n3",
"20\n5",
"20\n24",
"20\n12",
"20\n20",
"20\n25",
"20\n30",
"20\n50",
"20\n60",
"20\n75",
"20\n40",
"20\n100",
"20\n120",
"20\n150",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Write a program which computes the area of a shape represented by the following three lines:
$y = x^2$
$y = 0$
$x = 600$
It is clear that the area is $72000000$, if you use an int... |
p00146 Lupin The 4th_19738 | The phantom thief "Lupin IV" is told by the beautiful "Fujiko Mine", a descendant of the Aizu clan, that the military funds left by the Aizu clan are sleeping in Aizuwakamatsu city. According to a report by Lupine's longtime companion, "Ishikawa Koshiemon," military funds are stored in several warehouses in a Senryobak... | n = int(input())
ids = []
dists = []
weights = []
for _ in range(n):
s, d, v = map(int, input().split())
ids.append(s)
dists.append(d)
weights.append(v * 20)
dic = {}
INF = 10 ** 20
def score(rest, pos, total_weight, order):
if rest == 0:
return 0, []
if (rest, pos) in dic:
return dic[(rest, pos)]
... | {
"input": [
"5\n13 199 1\n51 1000 1\n37 350 10\n27 300 2\n99 200 1000",
"3\n11 100 1\n13 200 20\n12 300 3",
"2\n1 100 1\n2 200 2",
"5\n13 199 1\n93 1000 1\n37 350 10\n27 300 2\n99 200 1000",
"3\n9 100 1\n13 200 20\n12 300 3",
"2\n2 100 1\n2 200 2",
"5\n13 199 1\n93 1000 1\n37 350 10\n27 3... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The phantom thief "Lupin IV" is told by the beautiful "Fujiko Mine", a descendant of the Aizu clan, that the military funds left by the Aizu clan are sleeping in Aizuwakamatsu city. A... |
p00279 Happy End Problem_19741 | Let's write a program related to an unsolved math problem called "Happy End Problem". Create a program to find the smallest convex polygon formed by connecting exactly k points from the N points given on the plane. However, after being given the coordinates of N points, the question is given the number k of the angles ... | def cross(z1, z2):
return z1.real * z2.imag - z1.imag * z2.real
def ccw(p1, p2, p3):
return cross(p2 - p1, p3 - p1) > 0
def triangle_area(p1, p2, p3):
# returns signed trangle area
return cross(p2 - p1, p3 - p1) / 2
from sys import stdin
file_input = stdin
N = int(file_input.readline())
P = []
M = {... | {
"input": [
"5\n0 0\n3 0\n5 2\n1 4\n0 3\n3\n3\n4\n5",
"5\n0 0\n3 -1\n5 2\n1 4\n0 3\n3\n3\n4\n5",
"5\n1 0\n3 -1\n5 2\n1 1\n0 3\n3\n3\n4\n5",
"5\n0 0\n2 0\n5 2\n1 4\n0 3\n3\n3\n4\n5",
"5\n1 0\n3 -1\n5 2\n1 1\n0 3\n3\n3\n4\n4",
"5\n0 0\n2 0\n5 1\n1 4\n0 3\n3\n3\n4\n5",
"5\n1 0\n3 0\n5 2\n1 1... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Let's write a program related to an unsolved math problem called "Happy End Problem". Create a program to find the smallest convex polygon formed by connecting exactly k points from t... |
p00467 Sugoroku_19744 | Sugoroku
problem
JOI is playing sugoroku alone. There are N squares in a straight line in this sugoroku, and each has a movement instruction written on it. The starting point is the 1st square and the goal is the Nth square. JOI repeats the following until he reaches the goal.
Roll the dice and proceed from the curr... | for e in iter(input,'0 0'):
N,M=map(int,e.split())
S=[int(input())for _ in[0]*N]
p=b=1
for i in range(M):
d=int(input())
p+=d
if N<=p:
if b:print(-~i);b=0
continue
p+=S[~-p]
if(N<=p)*b:print(-~i);b=0
| {
"input": [
"10 5\n0\n0\n5\n6\n-3\n8\n1\n8\n-4\n0\n1\n3\n5\n1\n5\n10 10\n0\n-1\n-1\n4\n4\n-5\n0\n1\n-6\n0\n1\n5\n2\n4\n6\n5\n5\n4\n1\n6\n0 0",
"10 5\n0\n0\n5\n6\n-3\n8\n1\n8\n-4\n0\n1\n3\n5\n1\n5\n10 10\n0\n-1\n-1\n4\n4\n-5\n0\n1\n-6\n0\n1\n5\n2\n5\n6\n5\n5\n4\n1\n6\n0 0",
"10 5\n0\n0\n5\n6\n-2\n8\n1\n8\... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Sugoroku
problem
JOI is playing sugoroku alone. There are N squares in a straight line in this sugoroku, and each has a movement instruction written on it. The starting point is the... |
p00659 Popularity Estimation_19748 | You are the planning manager of an animation production company. What animation production companies produce these days is not limited to animation itself. Related products, such as figures of characters and character song CDs, are also important sources of revenue. How much this profit can be increased depends solely ... | # AOJ 1074: Popularity Estimation
# Python3 2018.7.10 bal4u
while True:
n = int(input())
if n == 0: break
f, tbl = [0]*31, []
for i in range(n):
a = input().split()
nm = a.pop(0)
m = int(a.pop(0))
d = list(map(int, a))
tbl.append([0, nm, d])
for i in d: f[i] += 1
for i in range(n):
for j in tbl[i][2... | {
"input": [
"4\nakzakr 2 1 8\nfnmyi 5 2 3 4 6 9\ntsnukk 5 2 3 4 7 9\nyskwcnt 6 3 4 7 8 9 10\n4\nakzakr 1 2\nfnmyi 3 10 11 12\ntsnukk 2 1 8\nyskwcnt 2 1 8\n5\nknmmdk 2 13 19\nakmhmr 4 13 15 19 22\nmksyk 6 3 7 12 13 15 19\nskrkyk 3 1 4 8\ntmemm 3 1 17 24\n5\nknmmdk 5 5 6 16 18 26\nakmhmr 9 3 4 7 11 14 15 17 18 20\... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are the planning manager of an animation production company. What animation production companies produce these days is not limited to animation itself. Related products, such as f... |
p01336 THE BYDOLM@STER_19758 | Description
THE BY DOLM @ STER is a training simulation game scheduled to be released on EXIDNA by 1rem on April 1, 2010. For the time being, it probably has nothing to do with an arcade game where the network connection service stopped earlier this month.
This game is a game in which members of the unit (formation) t... | while True:
try:
n, m = map(int, input().split())
except EOFError:
break
costs = []
vocals = []
dances = []
looks = []
for _ in range(n):
input()
c, v, d, l = map(int, input().split())
costs.append(c)
vocals.append(v)
dances.append(d)
looks.append(l)
def max_param(para... | {
"input": [
"3 10\nDobkeradops\n7 5 23 10\nPataPata\n1 1 2 1\ndop\n5 3 11 14\n2 300\nBydo System Alpha\n7 11 4 7\nGreen Inferno\n300 300 300 300",
"3 10\nDobkeradops\n7 5 23 10\nPataPata\n1 1 2 1\ndop\n5 3 11 14\n2 300\nBydp System Alpha\n7 11 4 7\nGreen Inferno\n300 300 300 300",
"3 10\nDobkeradops\n7 5... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Description
THE BY DOLM @ STER is a training simulation game scheduled to be released on EXIDNA by 1rem on April 1, 2010. For the time being, it probably has nothing to do with an ar... |
p01816 Bit Operation Game_19763 | H --Bit Operation Game
Given a rooted tree with N vertices. The vertices are numbered from 0 to N − 1, and the 0th vertex represents the root. `T = 0` for the root, but for the other vertices
* `T = T & X;`
* `T = T & Y;`
* `T = T | X`
* `T = T | Y`
* `T = T ^ X`
* `T = T ^ Y`
One of the operations is written. Her... | from collections import deque
from itertools import permutations
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N, M = map(int, readline().split())
OP = [0]*N
ops = ["T=T&X\n", "T=T&Y\n", "T=T|X\n", "T=T|Y\n", "T=T^X\n", "T=T^Y\n"]
for i in range(N-1):
s = readlin... | {
"input": [
"6 3\nT=T|X\nT=T|Y\nT=T|Y\nT=T^Y\nT=T&X\n0 1\n0 2\n1 3\n1 4\n2 5\n5 6\n3 5\n0 0",
"6 6\nT=T|X\nT=T|Y\nT=T|Y\nT=T^Y\nT=T&X\n0 1\n0 2\n1 3\n1 4\n2 5\n5 6\n3 5\n0 0",
"6 6\nT=T|X\nT=T|Y\nT=T|Y\nT=T^Y\nT=T&X\n0 1\n0 2\n1 3\n1 4\n2 5\n9 6\n3 5\n0 0",
"6 6\nT=T|X\nT=T|Y\nT=T|Y\nT=T^Y\nT=T&X\n0 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
H --Bit Operation Game
Given a rooted tree with N vertices. The vertices are numbered from 0 to N − 1, and the 0th vertex represents the root. `T = 0` for the root, but for the other... |
p02100 Factorization_19766 | Problem
Mr. ukuku1333 is a little sloppy, so when I expanded the product of the linear expressions of x, I couldn't figure out the original linear expression.
Given the nth degree polynomial of x, factor it into the product of the original linear expressions of x.
The nth degree polynomial of x is given by the follow... | def parse(S):
poly = []
t = []
for x in S.split('+'):
if '-' in x:
t = t + ['-' + a if i != 0 else a for i, a in enumerate(x.split('-'))]
else:
t.append(x)
for x in t:
if '^' in x:
t = x.split('x^')
if len(t[0]) == 0:
... | {
"input": [
"x^5+15x^4+85x^3+225x^2+274x+120",
"x^2+3x+2",
"x^3-81x^2-1882x-1800",
"x^2-1",
"x^1-2",
"x^1-1",
"x^1-3",
"x^1-4",
"x^2-4",
"x^1-5",
"x^1-6",
"x^1+6",
"x^1+5",
"x^1+7",
"x^2+4x+3",
"x^1+8",
"x^1+9",
"x^1+2",
"x^1+4",
"x^1-7"... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Problem
Mr. ukuku1333 is a little sloppy, so when I expanded the product of the linear expressions of x, I couldn't figure out the original linear expression.
Given the nth degree po... |
p02238 Depth First Search_19770 | Depth-first search (DFS) follows the strategy to search ”deeper” in the graph whenever possible. In DFS, edges are recursively explored out of the most recently discovered vertex $v$ that still has unexplored edges leaving it. When all of $v$'s edges have been explored, the search ”backtracks” to explore edges leaving ... | from sys import stdin
n = int(stdin.readline())
M = [0] + [list(map(int, stdin.readline().split()[2:])) for i in range(n)]
sndf = [0] + [[False, i] for i in range(1, n + 1)]
tt = 0
def dfs(u):
global tt
sndf[u][0] = True
tt += 1
sndf[u].append(tt)
for v in M[u]:
if not sndf[v][0]:
... | {
"input": [
"4\n1 1 2\n2 1 4\n3 0\n4 1 3",
"6\n1 2 2 3\n2 2 3 4\n3 1 5\n4 1 6\n5 1 6\n6 0",
"6\n1 2 2 3\n2 2 3 4\n3 1 6\n4 1 6\n5 1 6\n6 0",
"4\n1 1 1\n2 1 4\n3 0\n4 1 3",
"4\n1 1 1\n2 1 4\n3 0\n4 1 2",
"6\n1 2 2 3\n2 2 3 4\n3 1 5\n4 1 6\n5 1 6\n6 -1",
"4\n1 1 3\n2 1 4\n3 0\n4 1 3",
"... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Depth-first search (DFS) follows the strategy to search ”deeper” in the graph whenever possible. In DFS, edges are recursively explored out of the most recently discovered vertex $v$ ... |
p02384 Dice II_19774 | Construct a dice from a given sequence of integers in the same way as Dice I.
You are given integers on the top face and the front face after the dice was rolled in the same way as Dice I. Write a program to print an integer on the right side face.
<image>
Constraints
* $0 \leq $ the integer assigned to a face $ ... | def lotate(dic, dire):
if dire == 'N':
x,y,z,w = dic['up'], dic['back'], dic['bottom'], dic['front']
dic['back'], dic['bottom'], dic['front'], dic['up'] = x,y,z,w
elif dire == 'S':
x, y, z, w = dic['up'], dic['back'], dic['bottom'], dic['front']
dic['front'], dic['up'], dic['back... | {
"input": [
"1 2 3 4 5 6\n3\n6 5\n1 3\n3 2",
"1 2 3 4 5 6\n3\n4 5\n1 3\n3 2",
"1 2 3 4 5 6\n3\n4 5\n1 3\n6 2",
"1 2 3 4 5 6\n3\n4 5\n2 3\n6 2",
"1 2 3 4 5 6\n3\n6 5\n2 3\n6 2",
"1 2 3 4 5 6\n3\n6 3\n1 3\n3 2",
"1 2 3 4 5 6\n3\n4 2\n1 3\n3 2",
"1 2 3 4 5 6\n3\n4 5\n2 3\n4 2",
"1 2 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Construct a dice from a given sequence of integers in the same way as Dice I.
You are given integers on the top face and the front face after the dice was rolled in the same way as D... |
1060_B. Maximum Sum of Digits_19789 | You are given a positive integer n.
Let S(x) be sum of digits in base 10 representation of x, for example, S(123) = 1 + 2 + 3 = 6, S(0) = 0.
Your task is to find two integers a, b, such that 0 ≤ a, b ≤ n, a + b = n and S(a) + S(b) is the largest possible among all such pairs.
Input
The only line of input contains a... | def digitSum(x):
s = 0
while x != 0:
s += x % 10
x = (x//10)
return s
n = int(input())
x = n
b = 1
s = 0
while x != 0:
num1 = (x - 1)*b + (b-1)
num2 = n - num1
ans = digitSum(num1) + digitSum(num2)
if ans > s:
s = ans
x = (x//10)
b = b * 10
print(s) | {
"input": [
"35\n",
"10000000000\n",
"999999999992\n",
"30892252868\n",
"9999999\n",
"2303910749\n",
"290687942106\n",
"11\n",
"4394826\n",
"99999999997\n",
"7019\n",
"2452148459\n",
"15\n",
"17219\n",
"13350712\n",
"9999991\n",
"142098087\n",
"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a positive integer n.
Let S(x) be sum of digits in base 10 representation of x, for example, S(123) = 1 + 2 + 3 = 6, S(0) = 0.
Your task is to find two integers a, b, ... |
1101_B. Accordion_19795 | An accordion is a string (yes, in the real world accordions are musical instruments, but let's forget about it for a while) which can be represented as a concatenation of: an opening bracket (ASCII code 091), a colon (ASCII code 058), some (possibly zero) vertical line characters (ASCII code 124), another colon, and a ... | #!/usr/bin/env python
# -*- coding: utf-8 -*-
s = input()
ans = -1
left = 0
right = len(s) - 1
lok = 1
while left < len(s):
if s[left] == '[':
lok = 2
left += 1
elif s[left] == ':' and lok == 2:
break
else:
left += 1
rok = 1
while right >= 0:
if s[right] == ']':
... | {
"input": [
"|[a:b:|]\n",
"|]:[|:]\n",
"[:]:[:]\n",
"]zp\n",
":[]f:\n",
":p|:rpv::r:h|]:\n",
"g|t:]l]w]]]x|q]jf[[[div::it:t\n",
"vu:]|ar|q|mwyl|]tr:qm:k:[|::jc]zzf\n",
"[a|u\n",
"[:\n",
":::]\n",
":::]|||[:::\n",
"xx:|o[vu]yp[]ew[l|::::x[t::\n",
"topkek[::]\n",... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
An accordion is a string (yes, in the real world accordions are musical instruments, but let's forget about it for a while) which can be represented as a concatenation of: an opening ... |
114_A. Cifera_19801 | When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million... | n = int(input())
m = int(input())
l = 0
x = n
while x<m:
l += 1
x *= n
if x == m:
print("YES")
print(l)
else:
print("NO")
| {
"input": [
"3\n8\n",
"5\n25\n",
"256\n16777217\n",
"2147483646\n2147483647\n",
"99\n970300\n",
"54958832\n956670209\n",
"2147483647\n2147483647\n",
"8\n4096\n",
"26859739\n595086170\n",
"52010\n557556453\n",
"24\n191102976\n",
"137\n2571353\n",
"925093\n1098566745... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too mu... |
1208_E. Let Them Slide_19806 | You are given n arrays that can have different sizes. You also have a table with w columns and n rows. The i-th array is placed horizontally in the i-th row. You can slide each array within its row as long as it occupies several consecutive cells and lies completely inside the table.
You need to find the maximum sum o... | import sys
input = sys.stdin.readline
from collections import deque
def slidemax(X, k):
q = deque([])
ret = []
for i in range(len(X)):
while q and q[-1][1] <= X[i]:
q.pop()
deque.append(q, (i+k, X[i]))
if q[0][0] == i:
deque.popleft(q)
if i >= k-1:
... | {
"input": [
"3 3\n3 2 4 8\n2 2 5\n2 6 3\n",
"2 2\n2 7 8\n1 -8\n",
"3 3\n3 2 4 8\n2 2 5\n2 10 3\n",
"3 3\n3 2 4 8\n2 2 5\n2 10 2\n",
"2 2\n2 7 2\n1 -8\n",
"3 5\n3 2 4 8\n2 2 5\n2 10 3\n",
"3 4\n3 2 4 8\n2 2 5\n2 6 3\n",
"3 3\n3 2 4 8\n2 2 5\n2 20 3\n",
"3 3\n3 4 4 8\n2 2 5\n2 10 2\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given n arrays that can have different sizes. You also have a table with w columns and n rows. The i-th array is placed horizontally in the i-th row. You can slide each array ... |
1227_D2. Optimal Subsequences (Hard Version)_19809 | This is the harder version of the problem. In this version, 1 ≤ n, m ≤ 2⋅10^5. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems.
You are given a sequence of integers a=[a_1,a_2,...,a_n] of length n. Its subsequence is obtained by removing zero or more e... | """
Author - Satwik Tiwari .
18th Feb , 2021 - Thursday
"""
#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import Byt... | {
"input": [
"3\n10 20 10\n6\n1 1\n2 1\n2 2\n3 1\n3 2\n3 3\n",
"7\n1 2 1 3 1 2 1\n9\n2 1\n2 2\n3 1\n3 2\n3 3\n1 1\n7 1\n7 7\n7 4\n",
"2\n392222 322\n3\n2 2\n2 1\n1 1\n",
"2\n1 10\n3\n2 2\n2 1\n1 1\n",
"1\n1\n3\n1 1\n1 1\n1 1\n",
"5\n3 1 4 1 2\n15\n5 5\n5 4\n5 3\n5 2\n5 1\n4 4\n4 3\n4 2\n4 1\n3... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This is the harder version of the problem. In this version, 1 ≤ n, m ≤ 2⋅10^5. You can hack this problem if you locked it. But you can hack the previous problem only if you locked bot... |
126_A. Hot Bath_19813 | Bob is about to take a hot bath.
There are two taps to fill the bath: a hot water tap and a cold water tap. The cold water's temperature is t1, and the hot water's temperature is t2. The cold water tap can transmit any integer number of water units per second from 0 to x1, inclusive. Similarly, the hot water tap can ... | import math
def gcd(a,b):
if(b==0):
return a
return gcd(b,a%b)
l=input().split()
t1=int(l[0])
t2=int(l[1])
x1=int(l[2])
x2=int(l[3])
t0=int(l[4])
num1=t2-t0
num2=t0-t1
if(t1==t2):
print(x1,x2)
quit()
if(num1==0):
print(0,x2)
quit()
if(num2==0):
print(x1,0)
quit()
z=num2/num1
maxa... | {
"input": [
"10 70 100 100 25\n",
"300 500 1000 1000 300\n",
"143 456 110 117 273\n",
"129630 805489 631548 761110 577559\n",
"7 9 481 961 9\n",
"581106 975502 703094 487920 637713\n",
"100 100 100 100 100\n",
"5 10 6361 6643 9\n",
"5 5 5 5 5\n",
"1 100000 1000 1 2\n",
"1 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Bob is about to take a hot bath.
There are two taps to fill the bath: a hot water tap and a cold water tap. The cold water's temperature is t1, and the hot water's temperature is t2... |
1312_A. Two Regular Polygons_19819 | You are given two integers n and m (m < n). Consider a convex regular polygon of n vertices. Recall that a regular polygon is a polygon that is equiangular (all angles are equal in measure) and equilateral (all sides have the same length).
<image> Examples of convex regular polygons
Your task is to say if it is poss... | for i in range(int(input())):
a,b=input().split()
if int(b)<=2:
print("NO")
elif int(a)%int(b)==0:
print("YES")
else:
print("NO") | {
"input": [
"2\n6 3\n7 3\n",
"2\n69 68\n11 9\n",
"1\n69 68\n",
"2\n69 120\n11 9\n",
"1\n69 37\n",
"2\n6 3\n7 5\n",
"2\n6 3\n7 1\n",
"1\n3 1\n",
"1\n70 37\n",
"2\n2 3\n7 5\n",
"1\n13 37\n",
"1\n13 44\n",
"1\n13 10\n",
"1\n13 17\n",
"1\n5 17\n",
"1\n9 17\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given two integers n and m (m < n). Consider a convex regular polygon of n vertices. Recall that a regular polygon is a polygon that is equiangular (all angles are equal in me... |
1334_E. Divisor Paths_19822 | You are given a positive integer D. Let's build the following graph from it:
* each vertex is a divisor of D (not necessarily prime, 1 and D itself are also included);
* two vertices x and y (x > y) have an undirected edge between them if x is divisible by y and \frac x y is a prime;
* the weight of an edge i... | import sys
input = sys.stdin.buffer.readline
mod=998244353
d=int(input())
div=[]
x=2
di=0
t=0
while d>1 and x*x<=d:
if d%x==0:
div.append(x)
d//=x
di+=1
t+=1
while d%x==0:
d//=x
t+=1
x+=1
if d>1:
div.append(d)
di+=1
t+=1
fac=[1]
for i in range(1,t+... | {
"input": [
"12\n3\n4 4\n12 1\n3 4\n",
"288807105787200\n4\n46 482955026400\n12556830686400 897\n414 12556830686400\n4443186242880 325\n",
"1\n1\n1 1\n",
"17592186044416\n1\n17592186044416 1\n",
"18\n36\n1 1\n1 2\n1 3\n1 6\n1 9\n1 18\n2 1\n2 2\n2 3\n2 6\n2 9\n2 18\n3 1\n3 2\n3 3\n3 6\n3 9\n3 18\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a positive integer D. Let's build the following graph from it:
* each vertex is a divisor of D (not necessarily prime, 1 and D itself are also included);
* two ve... |
1354_G. Find a Gift_19825 | This is an interactive problem. Don't forget to flush output after printing queries using cout.flush() or fflush(stdout) in C++ or similar functions in other programming languages.
There are n gift boxes in a row, numbered from 1 to n from left to right. It's known that exactly k of them contain valuable gifts — other... | from random import randint
def ask(l1, r1, l2, r2):
print('?', r1 - l1 + 1, r2 - l2 + 1)
for i in range(l1, r1 + 1):
print(i + 1, end=' ')
print()
for i in range(l2, r2 + 1):
print(i + 1, end=' ')
print(flush=True)
s = input()
if s[0] == 'F':
return 0
if s[0] == 'S':
return 1
if s[0] == 'E':
return 2... | {
"input": [
"2\n2 1\n-\n-\n-\nFIRST\n-\n5 2\n-\n-\n-\nFIRST\n-\n-\n-\nSECOND\n-\n-\n-\nEQUAL\n-",
"2\n2 1\n100 1\n5 2\n99 98 100 100 100\n",
"2\n2 1\n100 1\n5 2\n99 98 100 100 000\n",
"2\n2 1\n-\n-\n-\nFIRST\n-\n5 2\n-\n-\n-\nFIRST\n-\n-\n-\nSECOND\n-\n-\n-\nEQUAL\n.",
"2\n2 1\n100 1\n5 2\n99 98 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This is an interactive problem. Don't forget to flush output after printing queries using cout.flush() or fflush(stdout) in C++ or similar functions in other programming languages.
T... |
1374_E2. Reading Books (hard version)_19829 | Easy and hard versions are actually different problems, so read statements of both problems completely and carefully.
Summer vacation has started so Alice and Bob want to play and joy, but... Their mom doesn't think so. She says that they have to read exactly m books before all entertainments. Alice and Bob will read ... | import sys
input = sys.stdin.readline
INF = 10 ** 18
n, m, k = map(int, input().split())
B = sorted((tuple(map(int, input().split())) + (i,) for i in range(n)), key=lambda v: v[0])
GB, AB, BB, RB = ([] for _ in range(4))
for t, a, b, i in B:
if a and b: GB.append((t, i))
elif a: AB.append((t, i))
elif b: BB.appen... | {
"input": [
"6 3 2\n6 0 0\n11 1 0\n9 0 1\n21 1 1\n10 1 0\n8 0 1\n",
"6 3 1\n6 0 0\n11 1 0\n9 0 1\n21 1 1\n10 1 0\n8 0 1\n",
"3 3 1\n27 0 0\n28 0 0\n11 0 0\n",
"1 1 1\n3 0 1\n",
"8 5 1\n43 0 1\n5 0 1\n23 1 1\n55 0 1\n19 1 1\n73 1 1\n16 1 1\n42 1 1\n",
"27 5 1\n232 0 1\n72 0 1\n235 0 1\n2 0 1\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Easy and hard versions are actually different problems, so read statements of both problems completely and carefully.
Summer vacation has started so Alice and Bob want to play and jo... |
1398_B. Substring Removal Game_19833 | Alice and Bob play a game. They have a binary string s (a string such that each character in it is either 0 or 1). Alice moves first, then Bob, then Alice again, and so on.
During their move, the player can choose any number (not less than one) of consecutive equal characters in s and delete them.
For example, if the... | for i in range(int(input())):
s = list(filter(lambda x:x !='',input().split('0')))
s.sort(reverse=True)
pr = ''
for i in range(0,len(s),2):
pr +=s[i]
print(len(pr))
| {
"input": [
"5\n01111001\n0000\n111111\n101010101\n011011110111\n",
"5\n01111101\n0000\n111111\n101010101\n011011110111\n",
"5\n01111101\n0000\n111111\n101010101\n011001110111\n",
"5\n01111101\n0000\n111111\n101010101\n011001111111\n",
"5\n11111101\n0000\n111111\n101010101\n011001111111\n",
"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Alice and Bob play a game. They have a binary string s (a string such that each character in it is either 0 or 1). Alice moves first, then Bob, then Alice again, and so on.
During th... |
1421_C. Palindromifier_19837 | Ringo found a string s of length n in his [yellow submarine](https://www.youtube.com/watch?v=m2uTFF_3MaA). The string contains only lowercase letters from the English alphabet. As Ringo and his friends love palindromes, he would like to turn the string s into a palindrome by applying two types of operations to the stri... | s=input()
n= len(s)
print(4)
print("L",2)
print("R",n)
print("R",2)
print("R",2*n+1)
| {
"input": [
"acccc\n",
"abac\n",
"hannah\n",
"vux\n",
"eaebyud\n",
"nxccb\n",
"abac\n",
"mcrpwaao\n",
"vdgcwgxbh\n",
"dasca\n",
"vyppyq\n",
"acccc\n",
"evmo\n",
"tifui\n",
"hannah\n",
"ittmcsvmoa\n",
"vxu\n",
"eabeyud\n",
"xnccb\n",
"aab... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Ringo found a string s of length n in his [yellow submarine](https://www.youtube.com/watch?v=m2uTFF_3MaA). The string contains only lowercase letters from the English alphabet. As Rin... |
143_B. Help Kingdom of Far Far Away 2_19841 | For some time the program of rounding numbers that had been developed by the Codeforces participants during one of the previous rounds, helped the citizens of Far Far Away to convert numbers into a more easily readable format. However, as time went by, the economy of the Far Far Away developed and the scale of operatio... | import math
import sys
import collections
# imgur.com/Pkt7iIf.png
def getdict(n):
d = {}
if type(n) is list:
for i in n:
if i in d:
d[i] += 1
else:
d[i] = 1
else:
for i in range(n):
t = ii()
if t in d:
... | {
"input": [
"2012\n",
"0.000\n",
"-12345678.9\n",
"-0.00987654321\n",
"-3136\n",
"-815237564329654906966710129877160169011275185850610159260306644937525319275278007248384181194947.28\n",
"-31237099946005389291000524337411657445033712616943108265479899943319776753\n",
"2567340036354357... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
For some time the program of rounding numbers that had been developed by the Codeforces participants during one of the previous rounds, helped the citizens of Far Far Away to convert ... |
1491_A. K-th Largest Value_19847 | You are given an array a consisting of n integers. Initially all elements of a are either 0 or 1. You need to process q queries of two kinds:
* 1 x : Assign to a_x the value 1 - a_x.
* 2 k : Print the k-th largest value of the array.
As a reminder, k-th largest value of the array b is defined as following:
... | n, q = map(int,input().split())
a = list(map(int,input().split()))
zero = a.count(0)
one = n - zero
for _ in range(q):
t, x = map(int,input().split())
if t == 1:
if a[x-1] == 1:
zero += 1
one -= 1
a[x-1] = 0
else:
zero -= 1
one += 1
... | {
"input": [
"5 5\n1 1 0 1 0\n2 3\n1 2\n2 3\n2 1\n2 5\n",
"1 1\n0\n2 1\n",
"5 5\n0 1 0 1 0\n2 3\n1 2\n2 3\n2 1\n2 5\n",
"5 5\n1 1 1 1 0\n2 3\n1 2\n2 3\n2 1\n2 5\n",
"5 5\n1 1 1 1 0\n2 3\n1 2\n2 3\n2 1\n2 2\n",
"5 5\n0 1 0 0 0\n2 3\n1 2\n2 3\n2 1\n2 3\n",
"5 5\n1 1 1 1 0\n2 5\n1 2\n2 3\n2 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. Initially all elements of a are either 0 or 1. You need to process q queries of two kinds:
* 1 x : Assign to a_x the value 1 - a_... |
1513_D. GCD and MST_19851 | You are given an array a of n (n ≥ 2) positive integers and an integer p. Consider an undirected weighted graph of n vertices numbered from 1 to n for which the edges between the vertices i and j (i<j) are added in the following manner:
* If gcd(a_i, a_{i+1}, a_{i+2}, ..., a_{j}) = min(a_i, a_{i+1}, a_{i+2}, ..., a_... |
class UnionFind:
def __init__(self, n):
self.Id = list(range(n+1))
self.sz = [1]*(n+1)
def find(self, node):
root = node
while root != self.Id[root]:
root = self.Id[root]
while node != root:
nxt = self.Id[node]
self.Id[node] = root
... | {
"input": [
"4\n2 5\n10 10\n2 5\n3 3\n4 5\n5 2 4 9\n8 8\n5 3 3 6 10 100 9 15\n",
"1\n10 243864180\n886547706 549473499 522487623 522487623 522487623 694839856 347419928 5067 79578125 636625000\n",
"1\n2 1000000000\n1000000000 1000000000\n",
"3\n2 1000000000\n5 5\n2 1000000000\n4 7\n2 99999999\n100000... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an array a of n (n ≥ 2) positive integers and an integer p. Consider an undirected weighted graph of n vertices numbered from 1 to n for which the edges between the vert... |
1540_C2. Converging Array (Hard Version)_19854 | This is the hard version of the problem. The only difference is that in this version 1 ≤ q ≤ 10^5. You can make hacks only if both versions of the problem are solved.
There is a process that takes place on arrays a and b of length n and length n-1 respectively.
The process is an infinite sequence of operations. Each... | def solve():
MOD = 10**9+7
n = int(input())
c = list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
q = int(input())
queries = list(map(int, input().split()))
maxans = 1
for c1 in c:
maxans = maxans * (c1+1) % MOD
ans = {}
for i in range(1, n):
... | {
"input": [
"3\n2 3 4\n2 1\n5\n-1 0 1 -100000 100000\n",
"3\n2 3 4\n2 1\n5\n-1 1 1 -100000 100000\n",
"3\n2 3 4\n2 1\n5\n-1 2 1 -100000 100100\n",
"3\n2 3 4\n2 1\n5\n-2 2 1 -100000 100100\n",
"3\n1 3 4\n2 1\n5\n-2 2 1 -100000 100100\n",
"3\n1 3 4\n2 0\n5\n-2 2 1 -100000 100100\n",
"3\n2 3... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This is the hard version of the problem. The only difference is that in this version 1 ≤ q ≤ 10^5. You can make hacks only if both versions of the problem are solved.
There is a proc... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.