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 |
|---|---|---|---|---|---|
1419_B. Stairs_5188 | Jett is tired after destroying the town and she wants to have a rest. She likes high places, that's why for having a rest she wants to get high and she decided to craft staircases.
A staircase is a squared figure that consists of square cells. Each staircase consists of an arbitrary number of stairs. If a staircase ha... | ty=[1]
p=2
while(True):
p=p*2
ty.append(p-1)
if(p>10**18):
break
t=int(input())
for j in range(0,t):
x=int(input())
s=0
c=0
for o in ty:
s=s+((o)*(o+1))//2
if(s<=x):
c=c+1
else:
break
print(c)
| {
"input": [
"4\n1\n8\n6\n1000000000000000000\n",
"4\n1\n8\n1\n1000000000000000000\n",
"4\n1\n3\n1\n1000000100000000000\n",
"4\n1\n8\n10\n1100000000000000100\n",
"4\n1\n4\n10\n1110000000000000100\n",
"4\n1\n4\n10\n0111000000000000100\n",
"4\n1\n8\n10\n0111100000000000100\n",
"4\n1\n39\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Jett is tired after destroying the town and she wants to have a rest. She likes high places, that's why for having a rest she wants to get high and she decided to craft staircases.
A... |
1437_B. Reverse Binary Strings_5192 | You are given a string s of even length n. String s is binary, in other words, consists only of 0's and 1's.
String s has exactly n/2 zeroes and n/2 ones (n is even).
In one operation you can reverse any substring of s. A substring of a string is a contiguous subsequence of that string.
What is the minimum number of... | #!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
#New Imports
def solution():
n = int(input())
s = input()
val = s.count('10')
a1 = n//2 - val
val = s.count('01')
a2 = n//2 - val
print(min(a1,a2))
return
def main():
testcases = 1
testcases = int(inp... | {
"input": [
"3\n2\n10\n4\n0110\n8\n11101000\n",
"3\n2\n10\n4\n0110\n8\n11100001\n",
"3\n2\n10\n4\n1010\n8\n11101000\n",
"3\n2\n10\n4\n0011\n8\n11101000\n",
"3\n2\n10\n4\n0101\n8\n11100001\n",
"3\n2\n10\n4\n0101\n8\n11101000\n",
"3\n2\n10\n4\n0011\n8\n11100001\n",
"3\n2\n10\n4\n1001\n8... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a string s of even length n. String s is binary, in other words, consists only of 0's and 1's.
String s has exactly n/2 zeroes and n/2 ones (n is even).
In one operati... |
1461_F. Mathematical Expression_5195 | Barbara was late for her math class so as a punishment the teacher made her solve the task on a sheet of paper. Barbara looked at the sheet of paper and only saw n numbers a_1, a_2, …, a_n without any mathematical symbols. The teacher explained to Barbara that she has to place the available symbols between the numbers ... | import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
ops = input().strip()
if len(ops) == 1:
print(ops.join(map(str, a)))
elif '+' in ops and '*' in ops:
seqs = [[a[0]]]
output = []
# split into seqs of all 0's or non 0's
# every seq in seqs is a list of all ... | {
"input": [
"4\n2 1 1 2\n+*\n",
"3\n2 2 0\n+-*\n",
"4\n2 1 1 5\n+*-\n",
"10\n1 1 0 1 1 1 1 0 0 0\n*-+\n",
"10\n0 2 2 2 0 0 0 2 0 0\n-*+\n",
"100\n1 2 2 2 1 1 2 2 0 2 2 0 1 0 0 0 0 1 0 0 0 1 1 2 1 1 2 2 0 2 0 2 1 1 0 2 1 0 1 2 1 2 2 1 1 1 2 1 1 1 0 1 1 0 0 2 2 1 2 2 1 0 1 0 0 2 1 2 1 1 0 2 1 0... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Barbara was late for her math class so as a punishment the teacher made her solve the task on a sheet of paper. Barbara looked at the sheet of paper and only saw n numbers a_1, a_2, …... |
1487_A. Arena_5199 | n heroes fight against each other in the Arena. Initially, the i-th hero has level a_i.
Each minute, a fight between two different heroes occurs. These heroes can be chosen arbitrarily (it's even possible that it is the same two heroes that were fighting during the last minute).
When two heroes of equal levels fight,... | tests = int(input())
for t in range(tests):
n = int(input())
heroes = list(map(int, input().split(' ')))
m = min(heroes)
print(sum([1 for x in heroes if x > m])) | {
"input": [
"3\n3\n3 2 2\n2\n5 5\n4\n1 3 3 7\n",
"2\n4\n2 2 2 3\n2\n2 2\n",
"2\n4\n1 1 1 1\n3\n1 1 1\n",
"2\n5\n1 2 3 5 5\n3\n5 5 5\n",
"2\n4\n5 5 5 5\n2\n5 5\n",
"2\n5\n1 1 1 1 1\n3\n1 1 1\n",
"2\n3\n4 4 4\n2\n4 4\n",
"2\n5\n9 3 3 4 100\n4\n100 100 100 100\n",
"2\n5\n1 1 1 1 1\n4... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
n heroes fight against each other in the Arena. Initially, the i-th hero has level a_i.
Each minute, a fight between two different heroes occurs. These heroes can be chosen arbitrari... |
1538_C. Number of Pairs_5204 | You are given an array a of n integers. Find the number of pairs (i, j) (1 ≤ i < j ≤ n) where the sum of a_i + a_j is greater than or equal to l and less than or equal to r (that is, l ≤ a_i + a_j ≤ r).
For example, if n = 3, a = [5, 1, 2], l = 4 and r = 7, then two pairs are suitable:
* i=1 and j=2 (4 ≤ 5 + 1 ≤ 7... | # Author: Javier Bórquez
import os
import sys
import bisect
def main():
fastReadInt = sys.stdin.buffer.readline
def fastReadStr(): return sys.stdin.buffer.readline().decode('utf-8').strip()
def fastWrite(ans): return sys.stdout.buffer.write(str(str(ans) + "\n").encode('utf-8'))
def fastWriteList(ans): return ... | {
"input": [
"4\n3 4 7\n5 1 2\n5 5 8\n5 1 2 4 3\n4 100 1000\n1 1 1 1\n5 9 13\n2 5 5 1 1\n",
"1\n100 120 130\n1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 7... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an array a of n integers. Find the number of pairs (i, j) (1 ≤ i < j ≤ n) where the sum of a_i + a_j is greater than or equal to l and less than or equal to r (that is, ... |
231_E. Cactus_5213 | A connected undirected graph is called a vertex cactus, if each vertex of this graph belongs to at most one simple cycle.
A simple cycle in a undirected graph is a sequence of distinct vertices v1, v2, ..., vt (t > 2), such that for any i (1 ≤ i < t) exists an edge between vertices vi and vi + 1, and also exists an ed... | from collections import defaultdict
import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
from collections import defaultdict
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self... | {
"input": [
"10 11\n1 2\n2 3\n3 4\n1 4\n3 5\n5 6\n8 6\n8 7\n7 6\n7 9\n9 10\n6\n1 2\n3 5\n6 9\n9 2\n9 3\n9 10\n",
"2 1\n1 2\n3\n1 2\n1 2\n2 1\n",
"5 4\n1 3\n2 3\n4 3\n1 5\n3\n1 3\n2 4\n5 2\n",
"6 6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 1\n4\n1 2\n1 6\n6 5\n4 3\n",
"40 43\n1 2\n1 3\n1 4\n4 5\n5 6\n1 7\n5 8\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A connected undirected graph is called a vertex cactus, if each vertex of this graph belongs to at most one simple cycle.
A simple cycle in a undirected graph is a sequence of distin... |
257_D. Sum_5217 | Vasya has found a piece of paper with an array written on it. The array consists of n integers a1, a2, ..., an. Vasya noticed that the following condition holds for the array ai ≤ ai + 1 ≤ 2·ai for any positive integer i (i < n).
Vasya wants to add either a "+" or a "-" before each number of array. Thus, Vasya will ge... | #!/usr/bin/python3
n = int(input())
a = list(map(int, input().split()))
s = a[-1]
ans = ['+']
for v in reversed(a[:-1]):
if s > 0:
s -= v
ans.append('-')
else:
s += v
ans.append('+')
if 0 <= s <= a[-1]:
print(''.join(reversed(ans)))
else:
s = -a[-1]
ans = ['-']
f... | {
"input": [
"3\n3 3 5\n",
"4\n1 2 3 5\n",
"42\n2 2 2 3 6 8 14 22 37 70 128 232 330 472 473 784 1481 2008 3076 4031 7504 8070 8167 11954 17832 24889 27113 41190 48727 92327 148544 186992 247329 370301 547840 621571 868209 1158781 1725242 3027208 4788036 5166155\n",
"44\n4 6 8 14 28 36 43 76 78 151 184... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya has found a piece of paper with an array written on it. The array consists of n integers a1, a2, ..., an. Vasya noticed that the following condition holds for the array ai ≤ ai ... |
32_D. Constellation_5225 | A star map in Berland is a checked field n × m squares. In each square there is or there is not a star. The favourite constellation of all Berland's astronomers is the constellation of the Cross. This constellation can be formed by any 5 stars so, that for some integer x (radius of the constellation) the following is t... | 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())
a = [tuple(map(lambda c: c == '*', input().rstrip())) for _ in range(n)]
cnt = [0] * 400
for i in range(1, n - 1):
for j in range(1, m - 1):
if not a[... | {
"input": [
"5 6 1\n....*.\n...***\n....*.\n..*...\n.***..\n",
"7 7 2\n...*...\n.......\n...*...\n*.***.*\n...*...\n.......\n...*...\n",
"5 6 2\n....*.\n...***\n....*.\n..*...\n.***..\n",
"5 5 3\n*.***\n.****\n..***\n*.***\n.**.*\n",
"5 5 1\n.....\n.....\n.*..*\n*.*..\n....*\n",
"10 10 40\n**... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A star map in Berland is a checked field n × m squares. In each square there is or there is not a star. The favourite constellation of all Berland's astronomers is the constellation o... |
351_B. Jeff and Furik_5229 | Jeff has become friends with Furik. Now these two are going to play one quite amusing game.
At the beginning of the game Jeff takes a piece of paper and writes down a permutation consisting of n numbers: p1, p2, ..., pn. Then the guys take turns to make moves, Jeff moves first. During his move, Jeff chooses two adjace... | from sys import *
n=int(stdin.readline().strip())
s1=stdin.readline().strip()
a=list(map(int,s1.split()))
if n==1:
print('0')
else:
x=0
n0=1
while n0<n:
n0=n0*2
b=[0]*(2*n0+10)
'''for i in range (n-1):
for j in range (i+1,n):
if a[i]>a[j]:
x+=1'''
... | {
"input": [
"5\n3 5 2 4 1\n",
"2\n1 2\n",
"2\n2 1\n",
"95\n68 56 24 89 79 20 74 69 49 59 85 67 95 66 15 34 2 13 92 25 84 77 70 71 17 93 62 81 1 87 76 38 75 31 63 51 35 33 37 11 36 52 23 10 27 90 12 6 45 32 86 26 60 47 91 65 58 80 78 88 50 9 44 4 28 29 22 8 48 7 19 57 14 54 55 83 5 30 72 18 82 94 43 4... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Jeff has become friends with Furik. Now these two are going to play one quite amusing game.
At the beginning of the game Jeff takes a piece of paper and writes down a permutation con... |
420_A. Start Up_5238 | Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out... | '''input
XO
'''
s = input()
if all(s[x] == s[~x] for x in range(len(s)//2)):
if any(y not in "AHIMOTUVWXY" for y in s[:len(s)//2+1]):
print("NO")
else:
print("YES")
else:
print("NO") | {
"input": [
"AHA\n",
"Z\n",
"XO\n",
"HNCMEEMCNH\n",
"AABAA\n",
"NNN\n",
"WWS\n",
"X\n",
"D\n",
"AAAKTAAA\n",
"QOQ\n",
"G\n",
"AHHA\n",
"WYYW\n",
"SSS\n",
"JL\n",
"H\n",
"ZZ\n",
"VO\n",
"VIYMAXXAVM\n",
"C\n",
"AZA\n",
"L\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts c... |
490_E. Restoring Increasing Sequence_5245 | Peter wrote on the board a strictly increasing sequence of positive integers a1, a2, ..., an. Then Vasil replaced some digits in the numbers of this sequence by question marks. Thus, each question mark corresponds to exactly one lost digit.
Restore the the original sequence knowing digits remaining on the board.
Inpu... | def solve(s, t, i, l):
if i == l:
return False
if s[i] == "?":
if solve(s, t, i + 1, l):
s[i] = t[i]
return True
elif t[i] == "9":
return False
s[i] = nxt[t[i]]
for j in range(i, l):
if s[j] == "?":
s[j] = "0... | {
"input": [
"3\n?\n18\n1?\n",
"2\n??\n?\n",
"5\n12224\n12??5\n12226\n?0000\n?00000\n",
"98\n?\n?0\n2?\n6?\n6?\n69\n??\n??\n96\n1?2\n??3\n104\n??4\n1?9\n??2\n18?\n?01\n205\n?19\n244\n??8\n?5?\n?5?\n276\n??3\n???\n???\n?28\n?3?\n3??\n??8\n355\n4?0\n4??\n?10\n??1\n417\n4?9\n?3?\n4?4\n?61\n?8?\n???\n507\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Peter wrote on the board a strictly increasing sequence of positive integers a1, a2, ..., an. Then Vasil replaced some digits in the numbers of this sequence by question marks. Thus, ... |
514_E. Darth Vader and Tree_5249 | When Darth Vader gets bored, he sits down on the sofa, closes his eyes and thinks of an infinite rooted tree where each node has exactly n sons, at that for each node, the distance between it an its i-th left child equals to di. The Sith Lord loves counting the number of nodes in the tree that are at a distance at most... | # fast io
from sys import stdin
_data = iter(stdin.read().split('\n'))
input = lambda: next(_data)
N = 101
MOD = 1000000007
def mul_vec_mat(v, a):
c = [0] * N
for i in range(N):
c[i] = sum(a[j][i] * v[j] % MOD for j in range(N)) % MOD
return c
def mul_vec_sparse_mat(v, a):
c = [0] * N
for... | {
"input": [
"3 3\n1 2 3\n",
"2 1\n2 2\n",
"39 93585\n2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 3 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n",
"97 78153\n2 2 1 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
When Darth Vader gets bored, he sits down on the sofa, closes his eyes and thinks of an infinite rooted tree where each node has exactly n sons, at that for each node, the distance be... |
569_B. Inventory_5255 | Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the track of everything.
During an audit, you were surprised to find out that the... | n = int(input())
fix = list()
factors = set(range(1, n + 1))
for i in map(int, input().split()):
if i in factors:
factors.remove(i)
fix.append(i)
else:
fix.append(None)
print(' '.join(str(factors.pop()) if i is None else str(i) for i in fix)) | {
"input": [
"3\n1 3 2\n",
"4\n2 2 3 3\n",
"1\n2\n",
"2\n1 4\n",
"5\n1 1 1 1 1\n",
"7\n45301 14370 61599 42695 46301 24556 26812\n",
"5\n19 11 8 8 10\n",
"3\n3 3 1\n",
"5\n5 3 4 4 2\n",
"15\n2 2 1 2 1 2 3 3 1 3 2 1 2 3 2\n",
"18\n3 11 5 9 5 4 6 4 5 7 5 1 8 11 11 2 1 9\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easie... |
631_D. Messenger_5264 | Each employee of the "Blake Techologies" company uses a special messaging app "Blake Messenger". All the stuff likes this app and uses it constantly. However, some important futures are missing. For example, many users want to be able to search through the message history. It was already announced that the new feature ... | def ziped(a):
p = []
for i in a:
x = int(i.split('-')[0])
y = i.split('-')[1]
if len(p) > 0 and p[-1][1] == y:
p[-1][0] += x
else:
p.append([x, y])
return p
def solve(a, b , c):
ans = 0
if len(b) == 1:
for token in a:
... | {
"input": [
"6 1\n3-a 6-b 7-a 4-c 8-e 2-a\n3-a\n",
"5 5\n1-h 1-e 1-l 1-l 1-o\n1-w 1-o 1-r 1-l 1-d\n",
"5 3\n3-a 2-b 4-c 3-a 2-c\n2-a 2-b 1-c\n",
"9 3\n1-h 1-e 2-l 1-o 1-w 1-o 1-r 1-l 1-d\n2-l 1-o 1-w\n",
"9 2\n1-a 2-b 1-o 1-k 1-l 1-m 1-a 3-b 3-z\n1-a 2-b\n",
"2 2\n1-a 1-b\n2-a 1-b\n",
"10... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Each employee of the "Blake Techologies" company uses a special messaging app "Blake Messenger". All the stuff likes this app and uses it constantly. However, some important futures a... |
660_B. Seating On Bus_5268 | Consider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4n.
Consider that m (m ≤ 4n) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to m (in the order... |
n,m = map(int,input().split())
for k in range(1,2*n +1):
num = 2 *n +k
if num <= m:
print(num, end=" ")
num = k
if num <= m:
print(num, end=" ")
| {
"input": [
"2 7\n",
"9 36\n",
"100 199\n",
"10 10\n",
"10 39\n",
"1 1\n",
"100 1\n",
"100 200\n",
"77 13\n",
"100 103\n",
"10 40\n",
"3 9\n",
"100 399\n",
"1 4\n",
"77 280\n",
"77 1\n",
"100 13\n",
"10 1\n",
"100 201\n",
"100 400\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Consider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is... |
74_C. Chessboard Billiard_5274 | Let's imagine: there is a chess piece billiard ball. Its movements resemble the ones of a bishop chess piece. The only difference is that when a billiard ball hits the board's border, it can reflect from it and continue moving.
More formally, first one of four diagonal directions is chosen and the billiard ball moves ... | import math
n,m=map(int,input().split())
print(math.gcd(n-1,m-1)+1)
| {
"input": [
"3 4\n",
"3 3\n",
"8 50\n",
"302237 618749\n",
"999999 1000000\n",
"893011 315181\n",
"4449 1336\n",
"871866 348747\n",
"999 999\n",
"2311 7771\n",
"429181 515017\n",
"21 15\n",
"201439 635463\n",
"977965 896468\n",
"1000000 1000000\n",
"384... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Let's imagine: there is a chess piece billiard ball. Its movements resemble the ones of a bishop chess piece. The only difference is that when a billiard ball hits the board's border,... |
773_B. Dynamic Problem Scoring_5278 | Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends... | import sys
inf = 10**9 + 7
def solve():
n = int(sys.stdin.readline())
v = [int(vi) for vi in sys.stdin.readline().split()] # Vesya
p = [int(pi) for pi in sys.stdin.readline().split()] # Petya
cnt = [0]*5
for i in range(5):
if v[i] != -1:
cnt[i] += 1
if p[i] != -1:
... | {
"input": [
"4\n-1 20 40 77 119\n30 10 73 50 107\n21 29 -1 64 98\n117 65 -1 -1 -1\n",
"5\n119 119 119 119 119\n0 0 0 0 -1\n20 65 12 73 77\n78 112 22 23 11\n1 78 60 111 62\n",
"2\n5 15 40 70 115\n50 45 40 30 15\n",
"3\n55 80 10 -1 -1\n15 -1 79 60 -1\n42 -1 13 -1 -1\n",
"2\n33 15 51 7 101\n41 80 40... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not t... |
798_A. Mike and palindrome_5282 | Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforc... | import sys
import math
import itertools
import collections
def getdict(n):
d = {}
if type(n) is list or type(n) is str:
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": [
"abbcca\n",
"abcda\n",
"abccaa\n",
"abcdmnp\n",
"ucnolsloncw\n",
"acbb\n",
"typayzzyapyt\n",
"abcde\n",
"eusneioiensue\n",
"ecabd\n",
"afghqwe\n",
"abcdabcde\n",
"guayhmg\n",
"ww\n",
"abcb\n",
"lkvhhvkl\n",
"abbcs\n",
"cbacb\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is... |
818_C. Sofa Thief_5286 | Yet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss?
Fortunately, the thief had left a note for Grandpa Maks. This note got Maks to the sofa storehouse. Still he had no idea which sofa belongs ... | import sys
from collections import defaultdict as dd
from collections import deque
pl=1
from math import *
import copy
#sys.setrecursionlimit(10**6)
if pl:
input=sys.stdin.readline
def li():
return [int(xxx) for xxx in input().split()]
def fi():
return int(input())
def si():
return list(input().rstrip())
def mi(... | {
"input": [
"2\n3 2\n3 1 3 2\n1 2 2 2\n1 0 0 1\n",
"2\n2 2\n2 1 1 1\n1 2 2 2\n1 0 0 0\n",
"3\n10 10\n1 2 1 1\n5 5 6 5\n6 4 5 4\n2 1 2 0\n",
"2\n5 7\n2 7 1 7\n2 4 3 4\n0 0 0 1\n",
"3\n7 3\n2 3 3 3\n5 1 6 1\n7 2 7 1\n0 2 2 0\n",
"2\n6 4\n6 4 5 4\n4 3 4 2\n1 0 1 0\n",
"1\n3 3\n2 3 3 3\n0 0 0... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Yet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss?
For... |
864_B. Polycarp and Letters_5292 | Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.
Let A be a set of positions in the string. Let's call it pretty if following conditions are met:
* letters on positions from A in the string are all distinct and lowercase; ... | import re
input()
print(max(map(lambda s: len(set(s)), re.split('[A-Z]', input())))) | {
"input": [
"11\naaaaBaabAbA\n",
"3\nABC\n",
"12\nzACaAbbaazzC\n",
"100\nchMRWwymTDuZDZuSTvUmmuxvSscnTasyjlwwodhzcoifeahnbmcifyeobbydwparebduoLDCgHlOsPtVRbYGGQXfnkdvrWKIwCRl\n",
"200\neLCCuYMPPwQoNlCpPOtKWJaQJmWfHeZCKiMSpILHSKjFOYGpRMzMCfMXdDuQdBGNsCNrHIVJzEFfBZcNMwNcFjOFVJvEtUQmLbFNKVHgNDyFkFVQh... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.
Let A be a set of positions in the stri... |
88_A. Chord_5296 | Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note aft... | # Problem: 88A
# Time Created: August 10(Monday) 2020 || 11:37:58
#>-------------------------<#
import sys
input = sys.stdin.readline
#>-------------------------<#
from itertools import permutations
# Helper Functions. -> Don't cluster your code.
def check_chord(tup):
notes = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F... | {
"input": [
"A B H\n",
"C E G\n",
"C# B F\n",
"E G# C\n",
"D# C G\n",
"F# H C\n",
"C C# D\n",
"D B E\n",
"F# H D\n",
"C F A\n",
"D B B\n",
"A F F#\n",
"A F D\n",
"G# G# A\n",
"A H B\n",
"E A C#\n",
"A B C\n",
"F E A\n",
"A D F\n",
"C G D... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes ar... |
912_D. Fishes_5300 | While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size n × m, divided into cells of size 1 × 1, inhabited by tiny evil fishes (no more than one fish per cell, otherwise they'll strife!).
The gift bundle also includes a square scoop of size r × r, designed for fishing.... | n, m, r, k = map(int, input().split())
def count(y, x):
minx = max(0, x-(r-1))
maxx = min(m-1-(r-1), x)
miny = max(0, y-(r-1))
maxy = min(n-1-(r-1), y)
res = (maxy-miny+1)*(maxx-minx+1)
return res
#X = [[0]*m for i in range(n)]
#for i in range(n):
#for j in range(m):
#X[i][j] = cou... | {
"input": [
"12 17 9 40\n",
"3 3 2 3\n",
"20 78 8 997\n",
"88888 99999 77777 1\n",
"9199 8137 4561 82660\n",
"100000 100000 1000 100000\n",
"20 59 2 88\n",
"2 20 1 14\n",
"1 1 1 1\n",
"90706 97197 90706 96593\n",
"51133 7737 2779 83291\n",
"90755 85790 85790 98432\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size n × m, divided into cells of size 1 × 1, inhabited by tiny evil fishes (no mo... |
934_D. A Determined Cleanup_5304 | In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must.
Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this...
Given two integers p and k, find a polynomial f(x) with non-negative integer coefficients stric... | p, k = input().split()
p, k = int(p), int(k)
s = k - 1
ls = [0]
while s < p:
ls.append(0)
ls.append(0)
s = s * k * k + k - 1
n = len(ls)
for i in range(n):
if (i & 1) == 0:
ls[i] = k - 1
res = s - p
for i in range(n):
t = res % k
if i & 1:
ls[i] += t
else:
ls[i] -= t
... | {
"input": [
"46 2\n",
"2018 214\n",
"9 3\n",
"3 2\n",
"1000000000000000000 2000\n",
"10 3\n",
"20180214 5\n",
"998244353998244353 2000\n",
"8 3\n",
"1562 862\n",
"7 2\n",
"5 3\n",
"6 3\n",
"1000000000000000000 2\n",
"250 1958\n",
"7 3\n",
"1314 520\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must.
Little Tommy finds an old polynomial and cleaned it up by taking it modulo a... |
988_C. Equal Sums_5310 | You are given k sequences of integers. The length of the i-th sequence equals to n_i.
You have to choose exactly two sequences i and j (i ≠ j) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence i (its length will be equal to n_i - 1) equals to the sum of the... | k = int(input())
arr = []
for _ in range(k):
n = int(input())
arr.append(list(map(int,input().split())))
d = {}
for i in range(k):
s = sum(arr[i])
used = set()
for j,c in enumerate(arr[i]):
if c in used:
continue
used.add(c)
if s-c in d:
print("YES")
... | {
"input": [
"2\n5\n2 3 1 3 2\n6\n1 1 2 2 2 1\n",
"4\n6\n2 2 2 2 2 2\n5\n2 2 2 2 2\n3\n2 2 2\n5\n2 2 2 2 2\n",
"3\n1\n5\n5\n1 1 1 1 1\n2\n2 3\n",
"2\n2\n0 -10000\n2\n10000 0\n",
"4\n6\n2 2 2 2 2 2\n5\n2 2 2 2 2\n3\n2 2 2\n5\n2 2 2 2 2\n",
"2\n5\n2 3 1 3 2\n6\n1 1 2 2 2 1\n",
"2\n2\n-1 -100... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given k sequences of integers. The length of the i-th sequence equals to n_i.
You have to choose exactly two sequences i and j (i ≠ j) such that you can remove exactly one el... |
p02595 AtCoder Beginner Contest 174 - Distance_5324 | We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).
Among them, we are looking for the points such that the distance from the origin is at most D. How many such points are there?
We remind you that the distance between the origin and the point (p, q) can be represented as \... | N, D = map(int, input().split())
P = [tuple(map(int, input().split())) for i in range(N)]
print(sum([p * p + q * q <= D * D for p, q in P]))
| {
"input": [
"12 3\n1 1\n1 1\n1 1\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3",
"4 5\n0 5\n-2 4\n3 4\n4 -4",
"20 100000\n14309 -32939\n-56855 100340\n151364 25430\n103789 -113141\n147404 -136977\n-37006 -30929\n188810 -49557\n13419 70401\n-88280 165170\n-196399 137941\n-176527 -61904\n46659 115261\n-1535... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).
Among them, we are looking for the points such that the distance from the origin is at... |
p02726 AtCoder Beginner Contest 160 - Line++_5328 | We have an undirected graph G with N vertices numbered 1 to N and N edges as follows:
* For each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1.
* There is an edge between Vertex X and Vertex Y.
For each k=1,2,...,N-1, solve the problem below:
* Find the number of pairs of integers (i,j) (1 \leq i... | n,x,y = map(int, input().split())
x = x-1
y = y-1
k=[0]*n
for i in range(n-1):
for j in range(i+1,n):
m = min(j-i,abs(x-i)+1+abs(y-j))
k[m] += 1
for i in range(1,n):
print(k[i]) | {
"input": [
"7 3 7",
"10 4 8",
"3 1 3",
"5 2 4",
"4 1 3",
"7 3 4",
"10 4 6",
"9 2 4",
"14 3 4",
"10 4 9",
"10 4 5",
"3 2 3",
"5 1 4",
"4 1 2",
"8 4 5",
"12 8 9",
"10 5 8",
"6 1 3",
"10 1 6",
"17 4 5",
"19 5 8",
"8 1 3",
"10 1... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We have an undirected graph G with N vertices numbered 1 to N and N edges as follows:
* For each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1.
* There is an edge b... |
p02993 AtCoder Beginner Contest 131 - Security_5334 | The door of Snuke's laboratory is locked with a security code.
The security code is a 4-digit number. We say the security code is hard to enter when it contains two consecutive digits that are the same.
You are given the current security code S. If S is hard to enter, print `Bad`; otherwise, print `Good`.
Constraint... | S=input()
for i in range(3):
if S[i]==S[i+1]:
print('Bad')
exit(0)
print('Good') | {
"input": [
"1333",
"8080",
"3776",
"0024",
"333",
"5823",
"7702",
"446",
"12101",
"4736",
"6783",
"12904",
"24106",
"8244",
"9217",
"5243",
"199",
"4960",
"2178",
"6416",
"9215",
"7196",
"16798",
"29052",
"11746",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The door of Snuke's laboratory is locked with a security code.
The security code is a 4-digit number. We say the security code is hard to enter when it contains two consecutive digit... |
p03134 Yahoo Programming Contest 2019 - Pass_5338 | There are N Snukes lining up in a row. You are given a string S of length N. The i-th Snuke from the front has two red balls if the i-th character in S is `0`; one red ball and one blue ball if the i-th character in S is `1`; two blue balls if the i-th character in S is `2`.
Takahashi has a sequence that is initially ... | s = input()
n = len(s)
red = [0]
blue = [0]
mod = 998244353
red = [-1]*(2*n)
blue = [-1]*(2*n)
cntr = 0
cntb = 0
for i in range(n):
cntr = max(cntr,i)
cntb = max(cntb,i)
if s[i] == "0":
red[cntr] = 1
red[cntr+1] = 1
cntr += 2
if s[i] == "1":
red[cntr] = 1
cntr += 1
blue[cntb] = 1
cnt... | {
"input": [
"1210",
"02",
"12001021211100201020",
"1",
"0",
"10",
"11",
"21",
"101",
"111",
"011",
"010",
"110",
"102",
"2100",
"2",
"12",
"22",
"20",
"001",
"000",
"100",
"202",
"201",
"121",
"220",
"120",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are N Snukes lining up in a row. You are given a string S of length N. The i-th Snuke from the front has two red balls if the i-th character in S is `0`; one red ball and one bl... |
p03279 AtCoder Regular Contest 101 - Robots and Exits_5341 | There are N robots and M exits on a number line. The N + M coordinates of these are all integers and all distinct. For each i (1 \leq i \leq N), the coordinate of the i-th robot from the left is x_i. Also, for each j (1 \leq j \leq M), the coordinate of the j-th exit from the left is y_j.
Snuke can repeatedly perform ... | from bisect import bisect
from collections import defaultdict
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
self.depth = n.bit_length()
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return... | {
"input": [
"4 1\n1 2 4 5\n3",
"4 5\n2 5 7 11\n1 3 6 9 13",
"10 10\n4 13 15 18 19 20 21 22 25 27\n1 5 11 12 14 16 23 26 29 30",
"3 4\n2 5 10\n1 3 7 13",
"2 2\n2 3\n1 4",
"4 5\n0 5 7 11\n1 3 6 9 13",
"0 2\n2 3\n1 4",
"4 5\n0 5 7 19\n1 3 6 9 13",
"1 2\n1 0\n7 4",
"0 2\n2 3\n2 4"... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are N robots and M exits on a number line. The N + M coordinates of these are all integers and all distinct. For each i (1 \leq i \leq N), the coordinate of the i-th robot from ... |
p03434 AtCoder Beginner Contest 088 - Card Game for Two_5345 | We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards... | input()
card=sorted(map(int,input().split()))[::-1]
print(sum(card[::2])-sum(card[1::2])) | {
"input": [
"4\n20 18 2 18",
"2\n3 1",
"3\n2 7 4",
"4\n20 18 2 12",
"2\n2 1",
"3\n3 7 4",
"4\n20 1 2 12",
"2\n2 0",
"3\n3 9 4",
"4\n20 1 4 12",
"2\n2 -1",
"2\n4 -1",
"4\n20 2 0 12",
"2\n5 -2",
"4\n23 4 0 12",
"4\n23 4 1 12",
"2\n4 0",
"4\n18 4 1... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
T... |
p03593 CODE FESTIVAL 2017 qual A - Palindromic Matrix_5349 | We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the top and j-th column from the left. In this matrix, each a_{ij} is a lowercase English letter.
Snuke is creating another H-by-W matrix, A', by freely rearranging the elements in A. Here, he wants to satisfy the following condition:
* Every ro... | from collections import Counter
H, W = map(int, input().split())
cntA = Counter()
for _ in range(H):
cntA += Counter(list(input()))
four = (H // 2) * (W // 2)
for a, c in cntA.items():
if four <= 0:
break
while c >= 4 and four > 0:
c -= 4
four -= 1
cntA[a] = c
if four > 0:
... | {
"input": [
"2 5\nabxba\nabyba",
"5 1\nt\nw\ne\ne\nt",
"2 2\naa\nbb",
"1 1\nz",
"3 4\naabb\naabb\naacc",
"2 5\nabxab\nabyba",
"1 1\ny",
"5 1\nu\nw\ne\ne\nt",
"2 2\nba\nbb",
"2 5\nbaxba\nabyba",
"5 1\nu\nw\ne\ne\ns",
"2 5\nbaxba\nacyba",
"2 2\nab\nbb",
"0 5\nbax... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the top and j-th column from the left. In this matrix, each a_{ij} is a lowercase English letter.
Snuke is cr... |
p03914 CODE FESTIVAL 2016 Final - Road of the King_5354 | There are N towns in Takahashi Kingdom. They are conveniently numbered 1 through N.
Takahashi the king is planning to go on a tour of inspection for M days. He will determine a sequence of towns c, and visit town c_i on the i-th day. That is, on the i-th day, he will travel from his current location to town c_i. If he... | mod=10**9+7
N,M=map(int,input().split())
dp=[[0 for i in range(N+1)] for j in range(N+1)]
dp[N][N]=1
for i in range(M-1,-1,-1):
for k in range(1,N+1):
for j in range(k,N+1):
if j==k:
if j<N:
dp[j][k]=(j*dp[j][k]+(N-j)*dp[j+1][k])%mod
else:
... | {
"input": [
"3 3",
"150 300",
"300 150",
"3 5",
"21 300",
"300 280",
"5 5",
"13 300",
"5 6",
"13 146",
"2 146",
"1 8",
"62 300",
"13 178",
"3 6",
"4 146",
"3 146",
"4 6",
"2 8",
"2 13",
"2 5",
"62 108",
"13 214",
"2 3",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are N towns in Takahashi Kingdom. They are conveniently numbered 1 through N.
Takahashi the king is planning to go on a tour of inspection for M days. He will determine a seque... |
p00016 Treasure Hunt_5358 | When a boy was cleaning up after his grand father passing, he found an old paper:
<image>
In addition, other side of the paper says that "go ahead a number of steps equivalent to the first integer, and turn clockwise by degrees equivalent to the second integer".
His grand mother says that Sanbonmatsu was standing ... | import math
def calc(x, y, r, d, nd):
x = x + r * math.cos(math.radians(d))
y = y + r * math.sin(math.radians(d))
d -= nd
return x, y, d
x = y = 0
d = 90
while True:
r, nd = map(int, input().split(","))
if r == nd == 0: break
x, y, d = calc(x, y, r, d, nd)
print(int(x))
print(int(y)) | {
"input": [
"56,65\n97,54\n64,-4\n55,76\n42,-27\n43,80\n87,-86\n55,-6\n89,34\n95,5\n0,0",
"56,65\n97,54\n64,-4\n55,76\n42,-27\n43,80\n87,-86\n55,-6\n89,34\n5,59\n0,0",
"56,65\n97,54\n64,-4\n55,76\n42,-27\n43,80\n77,-86\n55,-6\n89,34\n95,5\n0,0",
"56,65\n97,54\n64,-4\n65,76\n42,-27\n43,80\n77,-86\n55,... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
When a boy was cleaning up after his grand father passing, he found an old paper:
<image>
In addition, other side of the paper says that "go ahead a number of steps equivalent to ... |
p00148 Candy and Class Flag_5362 | In Group C of the 3rd year, we decided to use the "class flag" used at the sports festival on November 10, 2007 at future class reunions. So, in order to decide which students to keep the "class flag", I decided to play the following game using a large amount of candy that the teacher gave me the other day.
* Each stu... | while True:
try:
n = int(input())
except:
break
ans = n % 39
if ans == 0:
ans = "39"
else:
ans = "{0:02d}".format(ans)
print("3C"+ans)
| {
"input": [
"50\n5576\n5577\n5578",
"50\n5576\n6063\n5578",
"50\n5576\n6063\n515",
"50\n5576\n6063\n39",
"50\n9200\n6063\n39",
"50\n2171\n6063\n39",
"50\n1864\n6063\n39",
"50\n1864\n7383\n39",
"50\n1864\n7046\n39",
"50\n1864\n13193\n39",
"50\n1864\n896\n39",
"50\n1864\... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In Group C of the 3rd year, we decided to use the "class flag" used at the sports festival on November 10, 2007 at future class reunions. So, in order to decide which students to keep... |
p00469 Lining up the cards_5367 | problem
Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers can Hanako make in total?
For example, consider that you are given five c... | import itertools
while(True):
n = int(input())
k = int(input())
if (n,k) == (0,0):
break
num_lis = []
for _ in range(n):
num_lis.append(input())
word_list = []
for item in list(itertools.permutations(num_lis,k)):
word_list.append("".join(item))
print(len(set(word_list)))
| {
"input": [
"4\n2\n1\n2\n12\n1\n6\n3\n72\n2\n12\n7\n2\n1\n0\n0",
"4\n2\n1\n3\n12\n1\n6\n3\n72\n2\n12\n7\n2\n1\n0\n0",
"4\n2\n1\n3\n12\n1\n6\n3\n11\n2\n12\n7\n2\n1\n0\n0",
"4\n2\n0\n5\n12\n1\n6\n3\n72\n2\n12\n7\n2\n1\n0\n0",
"4\n2\n1\n3\n12\n1\n6\n3\n9\n2\n12\n7\n2\n1\n0\n0",
"4\n1\n1\n3\n12\n... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
problem
Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a... |
p00661 Time Manipulation_5371 | She is an apprentice wizard. She first learned the magic of manipulating time. And she decided to open a liquor store to earn a living. It has to do with the fact that all the inhabitants of the country where she lives love alcohol. Residents especially like sake that has been aged for many years, and its value increas... | # AOJ 1076 Time Manipulation
# Python3 2018.7.10 bal4u
while True:
n, m = map(int, input().split())
if n == 0: break
p = list(map(int, input().split()))
if 1 in p: n = 0
print(n/2)
| {
"input": [
"12 3\n2 3 6\n12 4\n1 2 3 6\n0 0",
"12 3\n2 3 6\n13 4\n1 2 3 6\n0 0",
"12 3\n2 3 6\n12 4\n2 2 3 6\n0 0",
"12 3\n1 4 11\n13 4\n1 2 3 6\n0 0",
"7 3\n4 1 29\n13 4\n2 2 6 6\n0 0",
"17 3\n2 4 11\n13 4\n1 2 3 6\n0 0",
"15 3\n2 6 11\n13 4\n1 2 3 6\n0 0",
"21 3\n2 3 19\n13 4\n1 2 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
She is an apprentice wizard. She first learned the magic of manipulating time. And she decided to open a liquor store to earn a living. It has to do with the fact that all the inhabit... |
p00935 Decimal Sequences_5376 | Example
Input
3
3 0 1
Output
2 | j=''.join
u=input
n=int(u())
d=j(j(u().split())for i in[0]*(n//19+(n%19>0)))
i=0
while 1:
if d.find(str(i))<0:
print(i)
exit()
i+=1 | {
"input": [
"3\n3 0 1",
"3\n0 0 1",
"3\n0 0 2",
"3\n-1 -1 1",
"3\n0 1 2",
"3\n0 0 0",
"3\n3 0 2",
"3\n1 0 1",
"3\n0 1 0",
"3\n6 0 2",
"3\n1 0 0",
"3\n1 1 0",
"3\n8 0 2",
"3\n-1 0 1",
"3\n8 0 3",
"3\n8 1 3",
"3\n0 -1 1",
"3\n8 0 1",
"3\n8 -1 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Example
Input
3
3 0 1
Output
2
### Input:
3
3 0 1
### Output:
2
### Input:
3
0 0 1
### Output:
2
### Code:
j=''.join
u=input
n=int(u())
d=j(j(u().split())for i in[0]*(n//19+(... |
p01676 Tree Reconstruction_5386 | J - Tree Reconstruction
Problem Statement
You have a directed graph. Some non-negative value is assigned on each edge of the graph. You know that the value of the graph satisfies the flow conservation law That is, for every node v, the sum of values on edges incoming to v equals to the sum of values of edges outgoing... | from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N, M = map(int, readline().split())
G = [[] for i in range(N)]
for i in range(M):
s, t = map(int, readline().split())
G[s-1].append(t-1)
used = [0]*N
cnt = 0
ans = 0
... | {
"input": [
"9 13\n1 2\n1 3\n2 9\n3 4\n3 5\n3 6\n4 9\n5 7\n6 7\n6 8\n7 9\n8 9\n9 1",
"9 13\n1 2\n1 3\n2 9\n3 4\n3 5\n3 6\n4 9\n5 8\n6 7\n6 8\n7 9\n8 9\n9 1",
"9 13\n1 2\n1 3\n1 9\n1 4\n3 5\n5 6\n4 9\n5 7\n6 7\n8 8\n7 9\n5 9\n9 1",
"9 1\n1 1\n1 3\n1 9\n1 4\n3 5\n5 6\n4 9\n5 7\n6 7\n6 8\n7 9\n5 9\n9 1"... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
J - Tree Reconstruction
Problem Statement
You have a directed graph. Some non-negative value is assigned on each edge of the graph. You know that the value of the graph satisfies th... |
p02240 Connected Components_5393 | Write a program which reads relations in a SNS (Social Network Service), and judges that given pairs of users are reachable each other through the network.
Constraints
* $2 \leq n \leq 100,000$
* $0 \leq m \leq 100,000$
* $1 \leq q \leq 10,000$
Input
In the first line, two integer $n$ and $m$ are given. $n$ is the ... | # -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**6)
class LinkedList:
def __init__(self, n):
self.n = n
self.ll = [[] for _ in range(self.n)]
def link(self, u, v, direction=False):
self.ll[u].append(v)
if not direction:
self.ll[v].append(u)
def dfs... | {
"input": [
"10 9\n0 1\n0 2\n3 4\n5 7\n5 6\n6 7\n6 8\n7 8\n8 9\n3\n0 1\n5 9\n1 3",
"10 9\n0 1\n0 2\n3 4\n5 7\n5 6\n3 7\n6 8\n7 8\n8 9\n3\n0 1\n5 9\n1 3",
"16 9\n0 2\n0 2\n3 4\n5 7\n5 6\n3 7\n6 13\n7 8\n8 9\n3\n0 1\n5 9\n1 3",
"16 9\n0 2\n0 2\n3 4\n2 7\n5 6\n3 7\n6 13\n7 8\n8 9\n3\n0 1\n5 9\n1 3",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Write a program which reads relations in a SNS (Social Network Service), and judges that given pairs of users are reachable each other through the network.
Constraints
* $2 \leq n \... |
p02386 Dice IV_5397 | Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
Constraints
* $2 \leq n \leq 100$
* $0 \leq $ the integer assigned to a face $ \leq 100$
Input
In the first line, the number of dices $n$ i... | ptn=[
[1,2,3,4,5,6],
[2,6,3,4,1,5],
[3,6,5,2,1,4],
[4,6,2,5,1,3],
[5,6,4,3,1,2],
[6,2,4,3,5,1]
]
def diffDice(orgDice, newDice):
flg = False # diff
tmpDice = [0,0,0,0,0,0]
for i in range(6):
#newDiceをptn1で並べ替え
for idx, j in enumerate(ptn[i]):
tmpDice[idx] = newDice[j-1]
if orgDic... | {
"input": [
"3\n1 2 3 4 5 6\n6 5 4 3 2 1\n5 4 3 2 1 6",
"3\n1 2 3 4 5 6\n6 2 4 3 5 1\n6 5 4 3 2 1",
"3\n1 2 3 4 5 6\n6 5 4 3 2 1\n5 4 0 2 1 6",
"3\n1 2 3 4 5 6\n6 2 5 3 5 1\n6 5 4 3 2 1",
"3\n1 2 3 4 5 6\n5 5 4 3 2 1\n5 4 0 2 1 6",
"3\n1 2 3 4 5 6\n6 2 5 3 0 1\n6 5 4 3 2 1",
"3\n1 2 3 3 5... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
Const... |
1077_E. Thematic Contests_5412 | Polycarp has prepared n competitive programming problems. The topic of the i-th problem is a_i, and some problems' topics may coincide.
Polycarp has to host several thematic contests. All problems in each contest should have the same topic, and all contests should have pairwise distinct topics. He may not use all the ... | # from collections import Counter as C
# n, k_ = map(int, input().split())
# l = [*map(int, input().split())]
# c = C(l)
# d = {}
# for k, v in c.items():
# d[v] = d.get(v, []) + [str(k)]
# ld = sorted([(k, v) for k, v in d.items()], reverse = True)
# res = []
# # print(ld)
# for e in ld:
# res += [e[1]]
# ... | {
"input": [
"10\n6 6 6 3 6 1000000000 3 3 6 6\n",
"3\n1337 1337 1337\n",
"18\n2 1 2 10 2 10 10 2 2 1 10 10 10 10 1 1 10 10\n",
"55\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3\n",
"3\n1 2 3\n",
"2\n1 1\n",
"1\n1000000000\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarp has prepared n competitive programming problems. The topic of the i-th problem is a_i, and some problems' topics may coincide.
Polycarp has to host several thematic contests... |
1119_E. Pavel and Triangles_5418 | Pavel has several sticks with lengths equal to powers of two.
He has a_0 sticks of length 2^0 = 1, a_1 sticks of length 2^1 = 2, ..., a_{n-1} sticks of length 2^{n-1}.
Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be ... | n = int(input())
a = list(map(int, input().split()))
ans = 0
last = 0
for q in range(len(a)):
while last > 0 and a[q] >= 2:
ans += 1
a[q] -= 2
last -= 1
ans += a[q]//3
last += a[q] % 3
print(ans)
| {
"input": [
"5\n1 2 2 2 2\n",
"3\n1 1 1\n",
"3\n3 3 3\n",
"1\n963837006\n",
"57\n28 57 82 64 59 54 23 13 19 67 77 46 100 73 59 21 72 81 53 73 92 86 14 100 9 17 77 96 46 41 24 29 60 100 89 47 8 25 24 64 3 32 14 53 80 70 87 1 99 77 41 60 8 95 2 1 78\n",
"5\n1 3 3 5 3\n",
"3\n1 2 2\n",
"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Pavel has several sticks with lengths equal to powers of two.
He has a_0 sticks of length 2^0 = 1, a_1 sticks of length 2^1 = 2, ..., a_{n-1} sticks of length 2^{n-1}.
Pavel wants ... |
1146_B. Hate "A"_5422 | Bob has a string s consisting of lowercase English letters. He defines s' to be the string after removing all "a" characters from s (keeping all other characters in the same order). He then generates a new string t by concatenating s and s'. In other words, t=s+s' (look at notes for an example).
You are given a string... | s = input()
s1 = ""
a = 0
for i in s:
if i == 'a':
a -= -1
else:
s1 += i
if len(s1) % 2:
print(":(")
exit()
t = len(s1) // 2
ch = 1
x = len(s) - 1
for i in range(t - 1, -1, -1):
if s1[i] != s[x]:
ch = 0
break
x += -1
if ch:
for i in range(len(s) - t): print(... | {
"input": [
"ababacacbbcc\n",
"aacaababc\n",
"baba\n",
"aaaaa\n",
"abbbb\n",
"aeaaaaravazyzaadwaarzajaaawvcakaanbparauaoaaamsmjaaaayaylhaaaxegasgaaaipaakalaspkbaaaaazfacaaafzypraervzyzdwrzjwvcknbpruomsmjyylhxegsgipklspkbzfcfzypr\n",
"aaautkayaeaaatyogasaavnkkoaaaaoaaoipvaaaafamaajaaajmada... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Bob has a string s consisting of lowercase English letters. He defines s' to be the string after removing all "a" characters from s (keeping all other characters in the same order). H... |
1167_B. Lost Numbers_5425 | This is an interactive problem. Remember to flush your output while communicating with the testing program. You may use fflush(stdout) in C++, system.out.flush() in Java, stdout.flush() in Python or flush(output) in Pascal to flush the output. If you use some other programming language, consult its documentation. You m... | # -*- coding: utf-8 -*-
"""
Created on Mon Apr 15 18:26:08 2019
@author: Hamadeh
"""
class LLNode:
def __init__(self, data):
self.data = data
self.next = None
self.prev = None
# Class to create a Doubly Linked List
class LL:
# Constructor for empty Doubly Linked List
de... | {
"input": [
"16\n64\n345\n672",
"16 8 4 15 23 42\n",
"15 42 16 4 8 23\n",
"15 23 42 16 8 4\n",
"ADAPTIVE 16379\n",
"23 16 42 8 4 15\n",
"ADAPTIVE 16381\n",
"ADAPTIVE 2\n",
"42 23 8 15 16 4\n",
"15 23 8 4 16 42\n",
"15 23 42 16 4 8\n",
"23 42 4 16 8 15\n",
"ADAPTIVE... | 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. Remember to flush your output while communicating with the testing program. You may use fflush(stdout) in C++, system.out.flush() in Java, stdout.flush... |
1185_E. Polycarp and Snakes_5429 | After a hard-working week Polycarp prefers to have fun. Polycarp's favorite entertainment is drawing snakes. He takes a rectangular checkered sheet of paper of size n × m (where n is the number of rows, m is the number of columns) and starts to draw snakes in cells.
Polycarp draws snakes with lowercase Latin letters. ... |
def naiveSolve():
return
from collections import defaultdict
def charToInt(c): #'a'->0
if c=='.':
return -1
return ord(c)-ord('a')
def main():
t=int(input())
allans=[]
for _ in range(t):
n,m=readIntArr()
grid=[] # convert all chars to int
fo... | {
"input": [
"3\n3 3\n...\n...\n...\n4 4\n..c.\nadda\nbbcb\n....\n3 5\n..b..\naaaaa\n..b..\n",
"2\n3 3\n...\n.a.\n...\n2 2\nbb\ncc\n",
"1\n5 6\n...a..\n..bbb.\n...a..\n.cccc.\n...a..\n",
"2\n1 1\na\n1 1\nz\n",
"3\n3 3\n...\n...\n...\n4 4\n..c.\nadea\nbbcb\n....\n3 5\n..b..\naaaaa\n..b..\n",
"2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
After a hard-working week Polycarp prefers to have fun. Polycarp's favorite entertainment is drawing snakes. He takes a rectangular checkered sheet of paper of size n × m (where n is ... |
1204_C. Anna, Svyatoslav and Maps_5433 | The main characters have been omitted to be short.
You are given a directed unweighted graph without loops with n vertexes and a path in it (that path is not necessary simple) given by a sequence p_1, p_2, …, p_m of m vertexes; for each 1 ≤ i < m there is an arc from p_i to p_{i+1}.
Define the sequence v_1, v_2, …, v... | from collections import deque
n = int(input())
graph = [list(map(lambda bit: bit == '1', list(input()))) for _ in range(n)]
m = int(input())
way = list(map(lambda i: int(i) - 1, input().split()))
#print(graph)
def dfs(start):
queue = deque([start])
d = [-1] * n
d[start] = 0
while len(queue) != 0:
... | {
"input": [
"3\n011\n101\n110\n7\n1 2 3 1 3 2 1\n",
"4\n0110\n0001\n0001\n1000\n3\n1 2 4\n",
"4\n0110\n0010\n1001\n1000\n20\n1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4\n",
"4\n0110\n0010\n0001\n1000\n4\n1 2 3 4\n",
"16\n0100001011000101\n0001010100010111\n1100010111110111\n0000010011111101\n10010101... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The main characters have been omitted to be short.
You are given a directed unweighted graph without loops with n vertexes and a path in it (that path is not necessary simple) given ... |
1221_A. 2048 Game_5437 | You are playing a variation of game 2048. Initially you have a multiset s of n integers. Every integer in this multiset is a power of two.
You may perform any number (possibly, zero) operations with this multiset.
During each operation you choose two equal integers from s, remove them from s and insert the number eq... | q=int(input())
for i in range(q):
n=int(input())
lst2=[]
lst1=list(map(int,input().split()))
for i in range(len(lst1)):
if lst1[i]<=2048:
lst2.append(lst1[i])
sum1=sum(lst2)
if sum1>=2048:
print("YES")
else:
print("NO") | {
"input": [
"6\n4\n1024 512 64 512\n1\n2048\n3\n64 512 2\n2\n4096 4\n7\n2048 2 2048 2048 2048 2048 2048\n2\n2048 4096\n",
"6\n4\n1024 512 64 512\n1\n2048\n3\n64 512 2\n2\n4096 4\n1\n2048 2 2048 2048 2048 2048 2048\n2\n2048 4096\n",
"6\n4\n1024 512 64 512\n1\n4096\n3\n64 512 2\n2\n4096 4\n7\n2048 2 2048 2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are playing a variation of game 2048. Initially you have a multiset s of n integers. Every integer in this multiset is a power of two.
You may perform any number (possibly, zero... |
1266_B. Dice Tower_5443 | Bob is playing with 6-sided dice. A net of such standard cube is shown below.
<image>
He has an unlimited supply of these dice and wants to build a tower by stacking multiple dice on top of each other, while choosing the orientation of each dice. Then he counts the number of visible pips on the faces of the dice.
Fo... | # -*- coding: utf-8 -*-
"""
Created on Wed Mar 18 14:08:47 2020
@author: Varun
"""
from sys import stdin, stdout
stdin.readline()
numbers = map(int, stdin.readline().split())
def check(n):
if n < 15:
return False
m = n%14
return 1 <= m <= 6
for el in numbers:
if check(el):
... | {
"input": [
"4\n29 34 19 38\n",
"4\n29 34 18 38\n",
"4\n29 13 19 38\n",
"4\n29 13 19 57\n",
"4\n49 13 19 57\n",
"4\n29 34 19 30\n",
"4\n26 34 19 30\n",
"4\n29 34 0 38\n",
"4\n49 13 19 66\n",
"4\n29 68 25 38\n",
"4\n29 68 25 32\n",
"4\n0 34 18 38\n",
"4\n29 65 19 38... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Bob is playing with 6-sided dice. A net of such standard cube is shown below.
<image>
He has an unlimited supply of these dice and wants to build a tower by stacking multiple dice o... |
1287_D. Numbers on Tree_5447 | Evlampiy was gifted a rooted tree. The vertices of the tree are numbered from 1 to n. Each of its vertices also has an integer a_i written on it. For each vertex i, Evlampiy calculated c_i — the number of vertices j in the subtree of vertex i, such that a_j < a_i.
<image>Illustration for the second example, the first... | import sys
# inf = open('input.txt', 'r')
# reader = (line.rstrip() for line in inf)
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
n = int(input())
cs = [0] * (n + 1)
ps = [0] * (n + 1)
children = [[] for _ in range(n+1)]
for i in range(1, n+1):
p, c = map(int, input().split())
ps[i] ... | {
"input": [
"3\n2 0\n0 2\n2 0\n",
"5\n0 1\n1 3\n2 1\n3 0\n2 0\n",
"3\n2 0\n0 2\n2 0\n",
"3\n2 1\n0 0\n1 1\n",
"2\n0 1\n1 0\n",
"3\n3 1\n1 0\n0 1\n",
"2\n2 1\n0 1\n",
"1\n0 0\n",
"3\n0 0\n1 0\n1 0\n",
"3\n0 1\n3 0\n1 0\n",
"5\n0 1\n1 3\n2 1\n3 0\n2 0\n",
"2\n2 0\n0 0\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Evlampiy was gifted a rooted tree. The vertices of the tree are numbered from 1 to n. Each of its vertices also has an integer a_i written on it. For each vertex i, Evlampiy calculate... |
1307_D. Cow and Fields_5451 | Bessie is out grazing on the farm, which consists of n fields connected by m bidirectional roads. She is currently at field 1, and will return to her home at field n at the end of the day.
The Cowfederation of Barns has ordered Farmer John to install one extra bidirectional road. The farm has k special fields and he h... | import sys
from collections import deque
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
# v(G), e(G), special v
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
# adjacency lists
g = [[] for _ in range(n + 1)]
for _ in range(m):
v, to = map(int, input().split(... | {
"input": [
"5 4 2\n2 4\n1 2\n2 3\n3 4\n4 5\n",
"5 5 3\n1 3 5\n1 2\n2 3\n3 4\n3 5\n2 4\n",
"5 4 2\n3 4\n2 1\n2 3\n1 4\n4 5\n",
"4 3 2\n3 4\n1 2\n2 3\n1 4\n",
"16 15 3\n12 14 16\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n1 13\n13 14\n14 15\n15 16\n",
"10 10 2\n3 6\n1 2\n2 3\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Bessie is out grazing on the farm, which consists of n fields connected by m bidirectional roads. She is currently at field 1, and will return to her home at field n at the end of the... |
1330_D. Dreamoon Likes Sequences_5455 | Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS:
You are given two integers d, m, find the number of arrays a, satisfying the following constraints:
* The length of a is n, n ≥ 1
* 1 ≤ a_1 < a_2 < ... < a_n ≤ d
* Define an array b of length n as foll... | t = int(input())
for _ in range(t):
d, m = map(int, input().split())
a = []
i = 0
while d > (1<<(i+1))-1:
a.append(1<<i)
i += 1
a.append((1<<i) - (1<<(i+1)) + d + 1)
#print(a)
ans = 1
for x in a:
ans *= x+1
ans %= m
print((ans-1)%m) | {
"input": [
"10\n1 1000000000\n2 999999999\n3 99999998\n4 9999997\n5 999996\n6 99995\n7 9994\n8 993\n9 92\n10 1\n",
"10\n1 1000000000\n2 999999999\n3 99999998\n4 9999997\n5 999996\n10 99995\n7 9994\n8 993\n9 92\n10 1\n",
"10\n1 1000000000\n2 999999999\n3 99999998\n4 9999997\n5 999996\n10 99995\n7 9994\n8... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS:
You are given two integers d, m, find the number of arrays a, satisfying ... |
1350_D. Orac and Medians_5459 | Slime has a sequence of positive integers a_1, a_2, …, a_n.
In one operation Orac can choose an arbitrary subsegment [l … r] of this sequence and replace all values a_l, a_{l + 1}, …, a_r to the value of median of \\{a_l, a_{l + 1}, …, a_r\}.
In this problem, for the integer multiset s, the median of s is equal to th... | # Template 1.0
import sys, re, math
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): retur... | {
"input": [
"5\n5 3\n1 5 2 6 1\n1 6\n6\n3 2\n1 2 3\n4 3\n3 1 2 3\n10 3\n1 2 3 4 5 6 7 8 9 10\n",
"1\n7 2\n5 5 1 1 2 1 1\n",
"1\n26 2\n2 1 1 1 3 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 1 9 1 1 10 1\n",
"1\n17 15\n3 5 4 6 10 2 16 10 18 8 5 1 2 7 15 14 8\n",
"1\n10 10\n10 1 1 1 1 1 1 11 1 11\n",
"1\n7 3\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Slime has a sequence of positive integers a_1, a_2, …, a_n.
In one operation Orac can choose an arbitrary subsegment [l … r] of this sequence and replace all values a_l, a_{l + 1}, …... |
1393_C. Pinkie Pie Eats Patty-cakes_5465 | Pinkie Pie has bought a bag of patty-cakes with different fillings! But it appeared that not all patty-cakes differ from one another with filling. In other words, the bag contains some patty-cakes with the same filling.
Pinkie Pie eats the patty-cakes one-by-one. She likes having fun so she decided not to simply eat t... | def solve(n,ar):
freq = [0] * 200000
for i in range(n):
freq[ar[i]] += 1
maxi = 0
max_freq = 0
for i in range(len(freq)):
if maxi < freq[i]:
maxi = max(maxi,freq[i])
max_freq = 1
elif freq[i] == maxi:
max_freq += 1
print((n-max_fr... | {
"input": [
"4\n7\n1 7 1 6 4 4 6\n8\n1 1 4 6 4 6 4 7\n3\n3 3 3\n6\n2 5 2 3 1 4\n",
"1\n15\n1 2 3 4 5 1 2 3 4 5 1 2 3 4 5\n",
"1\n15\n1 2 3 4 5 1 2 3 4 5 2 2 3 4 5\n",
"4\n7\n1 7 1 6 4 7 6\n8\n1 1 4 6 4 6 4 7\n3\n3 3 3\n6\n2 5 2 3 1 4\n",
"1\n15\n1 2 3 4 5 1 2 3 4 5 2 1 3 4 5\n",
"4\n7\n1 7 1 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Pinkie Pie has bought a bag of patty-cakes with different fillings! But it appeared that not all patty-cakes differ from one another with filling. In other words, the bag contains som... |
1418_B. Negative Prefixes_5469 | You are given an array a, consisting of n integers.
Each position i (1 ≤ i ≤ n) of the array is either locked or unlocked. You can take the values on the unlocked positions, rearrange them in any order and place them back into the unlocked positions. You are not allowed to remove any values, add the new ones or rearra... | import sys
from sys import stdin
import math
import fractions
#Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))
def iinput():
return int(input())
def minput():
return map(int,input().split())
def linput():
return list(map(int,input().split()))
def fiinput():
return int(stdin.readline())
def fminput(... | {
"input": [
"5\n3\n1 3 2\n0 0 0\n4\n2 -3 4 -1\n1 1 1 1\n7\n-8 4 -2 -6 4 7 1\n1 0 0 0 1 1 0\n5\n0 1 -4 6 3\n0 0 0 1 1\n6\n-1 7 10 4 -8 -1\n1 0 0 0 0 1\n",
"5\n3\n1 3 2\n0 0 0\n4\n2 -3 4 -1\n1 1 1 1\n7\n-8 4 -2 -6 4 7 1\n1 0 0 0 1 1 0\n5\n0 1 -4 6 3\n0 0 0 1 1\n6\n-1 7 10 4 -8 -1\n1 0 0 0 0 1\n",
"5\n3\n1 ... | 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.
Each position i (1 ≤ i ≤ n) of the array is either locked or unlocked. You can take the values on the unlocked positions, rearrang... |
1436_A. Reorder_5473 | For a given array a consisting of n integers and a given integer m find if it is possible to reorder elements of the array a in such a way that ∑_{i=1}^{n}{∑_{j=i}^{n}{(a_j)/(j)}} equals m? It is forbidden to delete elements as well as insert new elements. Please note that no rounding occurs during division, for exampl... | #import numpy as np
#import collections
#import sys
# =============================================================================
#def get_primeFactor(n):
# res=[1]
# x=2
# while x*x<=n:
# while n%x==0:
# res.append(x)
# n//=x
# x+=1
# if n>1:res.append(n)
# return r... | {
"input": [
"2\n3 8\n2 5 1\n4 4\n0 1 2 3\n",
"1\n3 6\n4 4 4\n",
"1\n3 2\n1 2 3\n",
"1\n3 16\n2 5 1\n",
"1\n1 2\n4\n",
"1\n4 8\n4 4 4 4\n",
"1\n3 2\n2 2 2\n",
"1\n2 8\n8 8\n",
"1\n1 0\n5\n",
"1\n1 0\n1\n",
"2\n3 18\n3 3 3\n4 26\n10 10 2 4\n",
"1\n3 8\n2 4 10\n",
"2\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
For a given array a consisting of n integers and a given integer m find if it is possible to reorder elements of the array a in such a way that ∑_{i=1}^{n}{∑_{j=i}^{n}{(a_j)/(j)}} equ... |
1485_F. Copy or Prefix Sum_5479 | You are given an array of integers b_1, b_2, …, b_n.
An array a_1, a_2, …, a_n of integers is hybrid if for each i (1 ≤ i ≤ n) at least one of these conditions is true:
* b_i = a_i, or
* b_i = ∑_{j=1}^{i} a_j.
Find the number of hybrid arrays a_1, a_2, …, a_n. As the result can be very large, you should pri... | for s in[*open(0)][2::2]:
C=[0];N=0;D={0:1};S=1
for n in map(int,s.split()):C+=C[-1]+n,;N+=1
for i in range(1,N):D[C[i]],S=S,(2*S-D.get(C[i],0))%(10**9+7)
print(S) | {
"input": [
"4\n3\n1 -1 1\n4\n1 2 3 4\n10\n2 -1 1 -2 2 3 -5 0 2 -1\n4\n0 0 0 1\n",
"4\n3\n1 -1 1\n4\n1 2 3 4\n10\n2 -1 1 -2 2 6 -5 0 2 -1\n4\n0 0 0 1\n",
"4\n3\n1 -1 1\n4\n1 2 3 4\n10\n2 -1 1 -2 1 6 -5 0 2 -1\n4\n0 0 0 1\n",
"4\n3\n1 -1 1\n4\n1 2 2 4\n10\n2 -1 1 -2 1 1 -5 0 2 -1\n4\n0 -1 0 1\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an array of integers b_1, b_2, …, b_n.
An array a_1, a_2, …, a_n of integers is hybrid if for each i (1 ≤ i ≤ n) at least one of these conditions is true:
* b_i = a... |
1536_B. Prinzessin der Verurteilung_5485 | I, Fischl, Prinzessin der Verurteilung, descend upon this land by the call of fate an — Oh, you are also a traveler from another world? Very well, I grant you permission to travel with me.
It is no surprise Fischl speaks with a strange choice of words. However, this time, not even Oz, her raven friend, can interpret h... | # abc = 'abcdefghijklmnopqrstuvwxy'
# test1_previous = [x + y for x in abc for y in abc if x!='m']
def nextchr(c):
return chr(ord(c)+1)
def next(s):
if s == '':
ans = '.'
elif s[-1] == 'z':
ans = next(s[:-1]) + 'a'
else:
ans = s[:-1] + nextchr(s[-1])
return ans
t = int(in... | {
"input": [
"3\n28\nqaabzwsxedcrfvtgbyhnujmiklop\n13\ncleanairactbd\n10\naannttoonn\n",
"1\n41\nsugimotomikasaackermannelectromasterjsoap\n",
"1\n25\nabcdefghijklmnopqrstuvwxy\n",
"4\n5\noisha\n10\niloveoisha\n16\nshahromloveoisha\n16\noishaloveshahrom\n",
"1\n41\nsugimotomikasaacjermannelectroma... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
I, Fischl, Prinzessin der Verurteilung, descend upon this land by the call of fate an — Oh, you are also a traveler from another world? Very well, I grant you permission to travel wit... |
163_A. Substring and Subsequence_5489 | One day Polycarpus got hold of two non-empty strings s and t, consisting of lowercase Latin letters. Polycarpus is quite good with strings, so he immediately wondered, how many different pairs of "x y" are there, such that x is a substring of string s, y is a subsequence of string t, and the content of x and y is the s... | from sys import stdin
s=[ord(i)-97 for i in stdin.readline().strip()]
s1=[ord(i)-97 for i in stdin.readline().strip()]
n=len(s)
m=len(s1)
mod=1000000007
dp=[[0 for i in range(n)] for j in range(26)]
for i in range(m):
arr=[0 for j in range(n)]
for j in range(n):
if s1[i]==s[j] :
arr[j]=1
... | {
"input": [
"codeforces\nforceofcode\n",
"aa\naa\n",
"bbabb\nbababbbbab\n",
"ab\nbbbba\n",
"xzzxxxzxzzzxzzzxxzzxzzxzxzxxzxxzxxzxzzxxzxxzxxxzxzxzxxzzxxxxzxzzzxxxzxzxxxzzxxzxxzxxzzxxzxxzxzxzzzxzzzzxzxxzzxzxxzxxzzxzxzx\nzzx\n",
"a\nb\n",
"zxzxzxzxzxzxzx\nd\n",
"pfdempfohomnpgbeegikfmflna... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
One day Polycarpus got hold of two non-empty strings s and t, consisting of lowercase Latin letters. Polycarpus is quite good with strings, so he immediately wondered, how many differ... |
183_B. Zoo_5493 | The Zoo in the Grid Kingdom is represented by an infinite grid. The Zoo has n observation binoculars located at the OX axis. For each i between 1 and n, inclusive, there exists a single binocular located at the point with coordinates (i, 0). There are m flamingos in the Zoo, located at points with positive coordinates.... | def gcd(a,b):
if b == 0:
return a
return gcd(b, a % b)
def normalize_rational(num,den):
#associate the -ve with the num or cancel -ve sign when both are -ve
if num ^ den < 0 and num > 0 or num ^ den > 0 and num < 0:
num = -num; den = -den
#put it in its simplest form
g = gcd... | {
"input": [
"5 5\n2 1\n4 1\n3 2\n4 3\n4 4\n",
"1000000 2\n194305 1024\n4388610 1023\n",
"3 3\n227495634 254204506\n454991267 508409012\n217792637 799841973\n",
"1000000 2\n136395332 110293751\n568110113 459392523\n",
"3 3\n1 1\n2 10\n3 100\n",
"1000000 2\n881456674 979172365\n878302062 975668... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The Zoo in the Grid Kingdom is represented by an infinite grid. The Zoo has n observation binoculars located at the OX axis. For each i between 1 and n, inclusive, there exists a sing... |
230_C. Shifts_5499 | You are given a table consisting of n rows and m columns. Each cell of the table contains a number, 0 or 1. In one move we can choose some row of the table and cyclically shift its values either one cell to the left, or one cell to the right.
To cyclically shift a table row one cell to the right means to move the valu... | def solve(rows):
all_dists = [0 for _ in range(len(rows[0]))]
for r in rows:
dists = [len(r) for _ in r]
if '1' not in r:
return -1
start = r.index('1')
for i in range(len(r)):
right = (i+start)%len(r) # going right
left = (start+2*len(r)-i)%le... | {
"input": [
"3 6\n101010\n000100\n100000\n",
"2 3\n111\n000\n",
"6 6\n111000\n011100\n001110\n000111\n100011\n110001\n",
"3 3\n001\n010\n100\n",
"2 9\n101010101\n010101010\n",
"10 10\n0001001101\n0010001010\n1100000000\n0110110110\n1011011010\n1001001001\n0100010001\n0110000100\n0000100000\n1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a table consisting of n rows and m columns. Each cell of the table contains a number, 0 or 1. In one move we can choose some row of the table and cyclically shift its va... |
256_B. Mr. Bender and Square_5503 | Mr. Bender has a digital table of size n × n, each cell can be switched on or off. He wants the field to have at least c switched on squares. When this condition is fulfilled, Mr Bender will be happy.
We'll consider the table rows numbered from top to bottom from 1 to n, and the columns — numbered from left to right f... | x, y, n, c = 0, 0, 0, 0
def suma_impares(m):
return m * m
def suma_n(m):
return m * (m - 1) // 2
def cnt(t):
u, d, l, r = x + t, x - t, y - t, y + t
suma = t ** 2 + (t + 1) ** 2
if u > n: suma -= suma_impares(u - n)
if d < 1: suma -= suma_impares(1 - d)
if l < 1: suma -= suma_impares(1 - l)
if r > n: suma -= su... | {
"input": [
"9 3 8 10\n",
"6 4 3 1\n",
"1000000000 44 30 891773002\n",
"1000000000 999999938 999999936 384381709\n",
"1000000000 999999946 60 715189365\n",
"1000000000 999999946 999999941 715189365\n",
"1000000 951981 612086 60277\n",
"1000000000 6 999999904 272656295\n",
"1000000... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Mr. Bender has a digital table of size n × n, each cell can be switched on or off. He wants the field to have at least c switched on squares. When this condition is fulfilled, Mr Bend... |
27_B. Tournament_5507 | The tournament «Sleepyhead-2010» in the rapid falling asleep has just finished in Berland. n best participants from the country have participated in it. The tournament consists of games, each of them is a match between two participants. n·(n - 1) / 2 games were played during the tournament, and each participant had a m... | a = int(input())
d = {}
f = {}
for i in range(a*(a-1)//2-1):
v, c = map(int, input().split())
if v not in f:
f[v] = []
f[v].append(c)
if v in d:
d[v] += 1
else:
d[v] = 1
if c in d:
d[c] += 1
else:
d[c] = 1
s = []
m = 0
for i in range(1, a + 1):
if ... | {
"input": [
"4\n4 2\n4 1\n2 3\n2 1\n3 1\n",
"4\n3 1\n4 1\n4 2\n3 2\n3 4\n",
"5\n3 5\n2 5\n1 5\n1 4\n4 3\n1 3\n2 3\n4 5\n4 2\n",
"6\n3 1\n5 4\n2 1\n6 2\n5 2\n3 6\n6 4\n3 2\n3 4\n6 1\n6 5\n5 1\n2 4\n3 5\n",
"5\n4 5\n1 5\n4 3\n2 5\n2 1\n2 4\n3 5\n2 3\n1 3\n",
"5\n2 1\n4 1\n5 1\n4 5\n3 5\n2 3\n3 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The tournament «Sleepyhead-2010» in the rapid falling asleep has just finished in Berland. n best participants from the country have participated in it. The tournament consists of gam... |
302_A. Eugeny and Array_5511 | Eugeny has array a = a1, a2, ..., an, consisting of n integers. Each integer ai equals to -1, or to 1. Also, he has m queries:
* Query number i is given as a pair of integers li, ri (1 ≤ li ≤ ri ≤ n).
* The response to the query will be integer 1, if the elements of array a can be rearranged so as the sum ali + a... | from collections import Counter
num, cases = map(int, input().split())
arr = list(map(int, input().split()))
count = Counter(arr)
minus = count[-1]
plus = count[1]
mn = min(plus, minus)
ans = []
while cases:
cases -= 1
a, b = map(int, input().split())
if (b - a + 1) % 2 != 0:
ans.append(0)
eli... | {
"input": [
"5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n",
"2 3\n1 -1\n1 1\n1 2\n2 2\n",
"5 5\n-1 -1 -1 -1 -1\n1 1\n1 1\n3 4\n1 1\n1 4\n",
"7 7\n-1 -1 -1 1 -1 -1 -1\n1 1\n2 7\n1 3\n1 5\n4 7\n1 7\n6 7\n",
"9 9\n-1 1 1 1 1 1 1 1 1\n1 7\n5 6\n1 4\n1 1\n1 1\n6 8\n1 1\n6 7\n3 5\n",
"3 3\n1 1 1\n2 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Eugeny has array a = a1, a2, ..., an, consisting of n integers. Each integer ai equals to -1, or to 1. Also, he has m queries:
* Query number i is given as a pair of integers li, r... |
34_E. Collisions_5518 | On a number line there are n balls. At time moment 0 for each ball the following data is known: its coordinate xi, speed vi (possibly, negative) and weight mi. The radius of the balls can be ignored.
The balls collide elastically, i.e. if two balls weighing m1 and m2 and with speeds v1 and v2 collide, their new speeds... | class Ball:
def __init__(self, x, v, m):
self.v = v
self.x = x
self.m = m
def move(self, time):
self.x += self.v * time
def collisionTime(self, other):
if self.v == other.v:
return float("inf")
t = - (self.x - other.x) / (self.v - other.v)
... | {
"input": [
"2 9\n3 4 5\n0 7 8\n",
"3 10\n1 2 3\n4 -5 6\n7 -8 9\n",
"10 100\n0 100 1\n1 -100 1\n2 100 1\n3 -100 1\n4 100 1\n5 -100 1\n6 100 1\n7 -100 1\n8 100 1\n9 -100 1\n",
"10 48\n99 87 97\n95 94 100\n92 100 93\n98 98 92\n100 99 96\n69 76 97\n96 97 100\n94 100 96\n89 99 95\n97 87 100\n",
"2 1\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
On a number line there are n balls. At time moment 0 for each ball the following data is known: its coordinate xi, speed vi (possibly, negative) and weight mi. The radius of the balls... |
374_A. Inna and Pink Pony_5522 | Dima and Inna are doing so great! At the moment, Inna is sitting on the magic lawn playing with a pink pony. Dima wanted to play too. He brought an n × m chessboard, a very tasty candy and two numbers a and b.
Dima put the chessboard in front of Inna and placed the candy in position (i, j) on the board. The boy said h... | n, m, i, j, a, b = map(int, input().split())
corners = [(1, 1), (1, m), (n, 1), (n, m)]
result = False
ans = -1
for cnt in corners:
if (abs(cnt[0] - i) % a == 0) and (abs(cnt[1] - j) % b == 0):
result = True
t1, t2 = abs(cnt[0] - i) // a, abs(cnt[1] - j) // b
if (t1 + t2) % 2 == 0:
... | {
"input": [
"5 5 2 3 1 1\n",
"5 7 1 3 2 2\n",
"2 6 1 2 2 2\n",
"100 100 50 50 500 500\n",
"1000000 2 2 2 2 1\n",
"33999 99333 33000 99000 3 9\n",
"5 1 3 1 1 1\n",
"6 1 5 1 2 2\n",
"100 100 70 5 1 1\n",
"1 100 1 50 1 50\n",
"11 11 3 3 4 4\n",
"5 8 4 2 1 2\n",
"10000... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Dima and Inna are doing so great! At the moment, Inna is sitting on the magic lawn playing with a pink pony. Dima wanted to play too. He brought an n × m chessboard, a very tasty cand... |
445_B. DZY Loves Chemistry_5530 | DZY loves chemistry, and he enjoys mixing chemicals.
DZY has n chemicals, and m pairs of them will react. He wants to pour these chemicals into a test tube, and he needs to pour them in one by one, in any order.
Let's consider the danger of a test tube. Danger of an empty test tube is 1. And every time when DZY pour... | def iterative_dfs(graph, start, path=[]):
visited = {}
for i in graph:
visited[i] = []
q=[start]
while q:
v=q.pop(0)
if not visited[v]:
visited[v] = True
path=path+[v]
q=graph[v]+q
return path
nodes, edges = map(int, input().split(' ')... | {
"input": [
"3 2\n1 2\n2 3\n",
"2 1\n1 2\n",
"1 0\n",
"26 17\n1 2\n2 3\n1 6\n6 7\n7 8\n2 9\n4 10\n3 11\n11 12\n9 13\n6 14\n2 16\n5 18\n6 19\n11 22\n15 24\n6 26\n",
"8 5\n1 2\n1 3\n1 4\n5 6\n7 8\n",
"10 10\n1 8\n4 10\n4 6\n5 10\n2 3\n1 7\n3 4\n3 6\n6 9\n3 7\n",
"40 28\n1 2\n2 4\n3 5\n1 7\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
DZY loves chemistry, and he enjoys mixing chemicals.
DZY has n chemicals, and m pairs of them will react. He wants to pour these chemicals into a test tube, and he needs to pour them... |
467_C. George and Job_5534 | The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.
Given a sequence of n integers p1, p2, ..., pn. You are to choose k pairs of integers:
[l1, r1], [l2... | n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
p_a = [0 for _ in range(n)]
p_a[0] = a[0]
for i in range(1, n):
p_a[i] = p_a[i - 1] + a[i]
INF = -1e10
# print(p_a)
dp = {}
from types import GeneratorType
def bootstrap(f, stack=[]):
def wrappedfunc(*args, **kwargs):
if st... | {
"input": [
"5 2 1\n1 2 3 4 5\n",
"7 1 3\n2 10 7 18 5 33 0\n",
"10 1 10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n",
"23 2 4\n965481468 524609549 327408602 598336282 745920261 141281382 661619186 475657944 798069657 19918618 428716... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced ... |
513_G1. Inversions problem_5540 | You are given a permutation of n numbers p1, p2, ..., pn. We perform k operations of the following type: choose uniformly at random two indices l and r (l ≤ r) and reverse the order of the elements pl, pl + 1, ..., pr. Your task is to find the expected value of the number of inversions in the resulting permutation.
In... | n, k = map(int, input().split())
p = list(map(int, input().split()))
def count_invs(a):
ans = 0
for i in range(n-1):
for j in range(i + 1, n):
if a[i] > a[j]:
ans += 1
return ans
def inv_in_perms(a, count):
if count > 0:
ans = 0
for l in range(... | {
"input": [
"3 1\n1 2 3\n",
"3 4\n1 3 2\n",
"29 121\n1 25 15 18 29 26 3 9 16 8 7 5 12 11 24 28 10 13 27 14 21 17 22 20 6 23 19 4 2\n",
"1 1\n1\n",
"29 124\n25 17 19 13 18 10 4 15 27 26 23 12 3 7 29 9 22 6 5 20 24 28 11 14 8 16 2 1 21\n",
"30 187\n4 18 2 8 5 9 15 14 25 16 30 12 7 24 13 27 29 2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a permutation of n numbers p1, p2, ..., pn. We perform k operations of the following type: choose uniformly at random two indices l and r (l ≤ r) and reverse the order o... |
53_D. Physical Education_5544 | Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: a1, a2, ..., an, where ai is the height of the i-th student in the line and n is the number of students in the line... | import sys
n = int(sys.stdin.readline ())
a= [int (x) for x in sys.stdin.readline ().split ()]
assert len(a) == n
b = [int (x) for x in sys.stdin.readline ().split ()]
assert len(b) == n
ans = []
for i in range (n):
j = i;
while b[j] != a[i] :
j += 1
while j > i:
ans += [(j, j + 1)]
... | {
"input": [
"2\n1 100500\n1 100500\n",
"4\n1 2 3 2\n3 2 1 2\n",
"1\n800950546\n800950546\n",
"1\n873725529\n873725529\n",
"2\n344379439 344379439\n344379439 344379439\n",
"5\n470138369 747764103 729004864 491957578 874531368\n874531368 729004864 491957578 747764103 470138369\n",
"4\n68110... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in... |
567_F. Mausoleum_5547 | King of Berland Berl IV has recently died. Hail Berl V! As a sign of the highest achievements of the deceased king the new king decided to build a mausoleum with Berl IV's body on the main square of the capital.
The mausoleum will be constructed from 2n blocks, each of them has the shape of a cuboid. Each block has th... | n,k = map(int,input().split())
n*=2
n+=2
l,le,e = [[] for i in range(n)],[[] for i in range(n)],[0]*n
ok = 1
for i in range(k):
a,c,b = input().split()
a,b = int(a), int(b)
if c=="=":
if a==b:
continue
if (e[a] and e[a]!=b) or (e[b] and e[b]!=a):
ok = 0
e[a],... | {
"input": [
"3 0\n",
"4 1\n3 = 6\n",
"3 1\n2 > 3\n",
"1 1\n1 <= 2\n",
"8 5\n2 <= 4\n5 > 10\n3 < 9\n4 = 8\n12 >= 16\n",
"10 5\n17 <= 10\n16 >= 18\n9 > 18\n8 = 8\n6 >= 13\n",
"1 1\n1 > 2\n",
"5 8\n8 = 9\n7 >= 7\n3 <= 9\n4 > 10\n5 >= 1\n7 = 7\n2 < 6\n4 <= 7\n",
"5 5\n10 <= 8\n5 >=... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
King of Berland Berl IV has recently died. Hail Berl V! As a sign of the highest achievements of the deceased king the new king decided to build a mausoleum with Berl IV's body on the... |
630_O. Arrow_5554 | Petya has recently started working as a programmer in the IT city company that develops computer games.
Besides game mechanics implementation to create a game it is necessary to create tool programs that can be used by game designers to create game levels. Petya's first assignment is to create a tool that allows to pa... | from math import atan2, pi
EPS = 0.00000001
def eq(a, b):
return abs(a - b) < EPS
class Vector:
def __init__(self, x2, y2, x1=0, y1=0):
self.x = (x2 - x1)
self.y = y2 - y1
self.s = (self.x ** 2 + self.y ** 2) ** 0.5
def __add__(self, other):
return Vector(self.x + other... | {
"input": [
"8 8 0 2 8 3 4 5\n",
"10 10 -7 0 5 8 2 11\n",
"870 396 187 223 444 202 222 732\n",
"10 10 -7 -7 5 8 2 11\n",
"254 578 251 809 412 966 92 984\n",
"767 238 263 303 155 351 21 686\n",
"10 10 7 7 5 8 2 11\n",
"10 10 7 -7 5 8 2 11\n",
"403 24 708 984 850 765 344 865\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Petya has recently started working as a programmer in the IT city company that develops computer games.
Besides game mechanics implementation to create a game it is necessary to crea... |
659_G. Fence Divercity_5558 | Long ago, Vasily built a good fence at his country house. Vasily calls a fence good, if it is a series of n consecutively fastened vertical boards of centimeter width, the height of each in centimeters is a positive integer. The house owner remembers that the height of the i-th board to the left is hi.
Today Vasily de... | mod = 10 ** 9 + 7
n = int(input())
h = list(map(lambda x: int(x) - 1, input().split()))
ans = x = 0
for i in range(n):
ans += h[i] + min(h[i], h[i - 1]) * x
if i < n - 1:
x *= min(h[i - 1], h[i], h[i + 1])
x += min(h[i], h[i + 1])
ans %= mod
x %= mod
print(ans)
| {
"input": [
"3\n3 4 2\n",
"2\n1 1\n",
"10\n529280935 122195401 684409084 743180136 724768643 211207376 167236398 696535490 425348743 1\n",
"5\n483078839 692549116 1 458438081 1\n",
"15\n2 72 77 69 62 73 58 9 4 95 97 14 41 79 34\n",
"50\n1 3083990 976356336 922018335 1 170272482 1 547248035 1 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Long ago, Vasily built a good fence at his country house. Vasily calls a fence good, if it is a series of n consecutively fastened vertical boards of centimeter width, the height of e... |
682_D. Alyona and Strings_5562 | After returned from forest, Alyona started reading a book. She noticed strings s and t, lengths of which are n and m respectively. As usual, reading bored Alyona and she decided to pay her attention to strings s and t, which she considered very similar.
Alyona has her favourite positive integer k and because she is to... | n, m, k = map(int, input().split())
s, t = input(), input()
n += 1
m += 1
p = [i for i in range(n * m - n) if (i + 1) % n]
r = p[::-1]
d = [0] * n * m
for i in p:
if s[i % n] == t[i // n]: d[i] = d[i - n - 1] + 1
f = d[:]
for y in range(k - 1):
for i in p: f[i] = max(f[i], f[i - 1], f[i - n])
for i in... | {
"input": [
"9 12 4\nbbaaababb\nabbbabbaaaba\n",
"3 2 2\nabc\nab\n",
"120 362 6\ncaaccbbbabbbcbaacbaccacaaccacaaababccaccaabaccacccbbaaaaababbccbbacccaacabacbaaacabbacbabcccbccbcbbcaabaaabaabcccaabacbb\nabcbbaaccbbcabbcbbcacbabaacbaaacabcbabcabbabccbcaaacaccaaabbcbaacccccbcabacaacabbbcabaabcbbccabacbaaaa... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
After returned from forest, Alyona started reading a book. She noticed strings s and t, lengths of which are n and m respectively. As usual, reading bored Alyona and she decided to pa... |
705_C. Thor_5566 | Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't).
q events are abou... | import collections
import copy
n, q = map(int, input().split())
Q = collections.deque()
A = n * [0]
B = copy.copy(A)
L = []
s = n = 0
for _ in range(q):
y, x = map(int, input().split())
if 2 > y:
x -= 1
Q.append(x)
B[x] += 1
A[x] += 1
s += 1
elif 3 > y:
x -= ... | {
"input": [
"4 6\n1 2\n1 4\n1 2\n3 3\n1 3\n1 3\n",
"3 4\n1 3\n1 1\n1 2\n2 3\n",
"300000 1\n1 300000\n",
"10 85\n2 2\n1 10\n1 1\n2 6\n1 2\n1 4\n1 7\n2 1\n1 1\n3 3\n1 9\n1 6\n1 8\n1 10\n3 8\n2 8\n1 6\n1 3\n1 9\n1 6\n1 3\n1 8\n1 1\n1 6\n1 10\n2 1\n2 10\n1 10\n1 1\n1 10\n1 6\n1 2\n1 8\n1 3\n1 4\n1 9\n1 5... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can'... |
749_A. Bachgold Problem_5572 | Bachgold problem is very easy to formulate. Given a positive integer n represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer k is called prime if it is greater than 1 and has exactly two positive integer divi... | n=int(input())
c=0
if(n%2==1):
n-=3
l=[2]*(n//2)
l.append(3)
print(len(l))
print(*l)
else:
l=[2]*(n//2)
print(len(l))
print(*l) | {
"input": [
"6\n",
"5\n",
"15326\n",
"23\n",
"11110\n",
"99544\n",
"99993\n",
"99996\n",
"9\n",
"90672\n",
"100000\n",
"99995\n",
"90472\n",
"10\n",
"8\n",
"774\n",
"14\n",
"99999\n",
"14878\n",
"99998\n",
"93\n",
"2422\n",
"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Bachgold problem is very easy to formulate. Given a positive integer n represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists... |
817_B. Makes And The Product_5579 | After returning from the army Makes received a gift — an array a consisting of n positive integer numbers. He hadn't been solving problems for a long time, so he became interested to answer a particular question: how many triples of indices (i, j, k) (i < j < k), such that ai·aj·ak is minimum possible, are there in the... | n=int(input())
a=list(map(int,(input().split(' '))))
a=sorted(a)
a.append(0)
ans=1
t=0
while a[3+t]==a[2]:t=t+1
if a[3]==a[0]:ans=(t+3)*(t+2)*(t+1)/6
elif a[3]==a[1]:ans=(t+2)*(t+1)/2
elif a[3]==a[2]:ans=t+1
print(int(ans))
| {
"input": [
"5\n1 3 2 3 4\n",
"6\n1 3 3 1 3 2\n",
"4\n1 1 1 1\n",
"4\n1 1 3 3\n",
"3\n5 9 5\n",
"9\n10 10 4 10 7 9 6 7 3\n",
"6\n2 2 2 1 2 2\n",
"9\n2 2 3 3 3 3 3 3 3\n",
"5\n9 10 10 3 8\n",
"10\n1 2 1 2 3 2 3 2 2 2\n",
"8\n3 2 2 5 2 2 1 2\n",
"3\n1 3 1\n",
"3\n3 1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
After returning from the army Makes received a gift — an array a consisting of n positive integer numbers. He hadn't been solving problems for a long time, so he became interested to ... |
842_B. Gleb And Pizza_5583 | Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius r and center at the origin. Pizza consists of the main part — circle of radius r - d with center at the origin, an... | '''input
8 4
7
7 8 1
-7 3 2
0 2 1
0 -2 2
-3 -3 1
0 6 2
5 3 1
'''
r, d = map(int, input().split())
n = int(input())
c = 0
for _ in range(n):
x, y, r1 = map(int, input().split())
s = (x**2 + y**2)**0.5
if r-d <= s-r1 and s+r1 <= r:
c += 1
print(c)
| {
"input": [
"10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2\n",
"8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1\n",
"1 0\n1\n1 1 0\n",
"3 0\n5\n3 0 0\n0 3 0\n-3 0 0\n0 -3 0\n3 0 1\n",
"5 3\n1\n500 500 10\n",
"9 0\n5\n8 1 0\n8 2 0\n8 3 0\n-8 3 0\n-8 2 0\n",
"10 2\n11\n1 1 0\n2 2 3\n3 3 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza... |
863_B. Kayaking_5587 | Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·n people in the group (including Vadim), and they have exactly... | n = int(input())
n = 2*n
w = [int(i) for i in input().split()]
w.sort()
import math
res = math.inf
for x in range(n):
for y in range(x+1, n):
wc = w[:]
wc.pop(y); wc.pop(x)
# print(wc)
s = 0
for i in range(0, n-3, 2):
s += wc[i+1]-wc[i]
res = min(s, res)
print(res) | {
"input": [
"4\n1 3 4 6 3 4 100 200\n",
"2\n1 2 3 4\n",
"45\n476 103 187 696 463 457 588 632 763 77 391 721 95 124 378 812 980 193 694 898 859 572 721 274 605 264 929 615 257 918 42 493 1 3 697 349 990 800 82 535 382 816 943 735 11 272 562 323 653 370 766 332 666 130 704 604 645 717 267 255 37 470 925 94... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready... |
888_F. Connecting Vertices_5590 | There are n points marked on the plane. The points are situated in such a way that they form a regular polygon (marked points are its vertices, and they are numbered in counter-clockwise order). You can draw n - 1 segments, each connecting any two marked points, in such a way that all points have to be connected with e... | import sys
from array import array
n = int(input())
edge = [list(map(int, input().split())) for _ in range(n)]
mod = 10**9 + 7
dp_f = [array('i', [-1])*n for _ in range(n)]
dp_g = [array('i', [-1])*n for _ in range(n)]
for i in range(n):
dp_f[i][i] = dp_g[i][i] = 1
for i in range(n-1):
dp_f[i][i+1] = dp_g[i... | {
"input": [
"3\n0 0 1\n0 0 1\n1 1 0\n",
"4\n0 1 1 1\n1 0 1 1\n1 1 0 1\n1 1 1 0\n",
"3\n0 0 0\n0 0 1\n0 1 0\n",
"4\n0 0 1 0\n0 0 0 1\n1 0 0 0\n0 1 0 0\n",
"4\n0 0 0 1\n0 0 0 0\n0 0 0 1\n1 0 1 0\n",
"10\n0 0 0 0 0 0 1 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 1 0 0 0 0 0 0\n0 0 1 0 0 0 0 0 0 0\n0 0 0 0... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n points marked on the plane. The points are situated in such a way that they form a regular polygon (marked points are its vertices, and they are numbered in counter-clockw... |
911_D. Inversion Counting_5594 | A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and ai < aj. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3).
You are given a per... | def solve():
n=int(input())
a=list(map(int,input().split()))
cl=['odd','even']
m=int(input())
ans=True
b=[]
ap=b.append
for i in range(n):
for j in range(i):
if a[j]>a[i]:
ans=not ans
for i in range(m):
left,right=map(int,input().split())
... | {
"input": [
"4\n1 2 4 3\n4\n1 1\n1 4\n1 4\n2 3\n",
"3\n1 2 3\n2\n1 2\n2 3\n",
"1\n1\n10\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n",
"3\n2 1 3\n3\n2 3\n1 1\n1 3\n",
"7\n2 6 1 7 4 5 3\n5\n4 5\n7 7\n5 6\n4 5\n4 5\n",
"3\n2 1 3\n3\n2 1\n1 1\n1 3\n",
"3\n2 1 3\n3\n2 3\n1 1\n2 3\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such th... |
933_B. A Determined Cleanup_5598 | In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must.
Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this...
Given two integers p and k, find a polynomial f(x) with non-negative integer coefficients stric... | s = input()
# s = '46 2'
p, k = list(map(int, s.split()))
res = []
f = True
while p != 0:
if f:
n = p % k
m = (p - n) // k
f = False
else:
n = (-p) % k
m = (p + n) // k
f = True
res.append(n)
p = m
print(len(res))
print(' '.join(list(map(str, res)))) | {
"input": [
"46 2\n",
"2018 214\n",
"2 3\n",
"393939393939393939 393\n",
"1000000000000000000 3\n",
"1000000000000000000 2\n",
"7 2\n",
"4 3\n",
"1562 862\n",
"5 3\n",
"10 3\n",
"2 2\n",
"7 3\n",
"1314 520\n",
"20180214 5\n",
"6666666666666666 3\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must.
Little Tommy finds an old polynomial and cleaned it up by taking it modulo a... |
987_B. High School: Become Human_5604 | Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before.
It turns out that high school struggles are not gone. If someone is not like others, he is bullied. Vasya-8800 is an economy-cl... | import math
x,y=map(lambda x:math.log(int(x))/int(x),input().split())
print('<=>'[(x>=y)+(x>y)]) | {
"input": [
"5 8\n",
"6 6\n",
"10 3\n",
"15657413 15657414\n",
"4 1000000000\n",
"4 4\n",
"27 3\n",
"620537015 620537016\n",
"1 100\n",
"3 2\n",
"3 5\n",
"1000000000 1000000000\n",
"5 3\n",
"10 3\n",
"56498103 56498102\n",
"2 6\n",
"17 18\n",
"1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans... |
p02588 AtCoder Grand Contest 047 - Integer Product_5618 | You are given N real values A_1, A_2, \ldots, A_N. Compute the number of pairs of indices (i, j) such that i < j and the product A_i \cdot A_j is integer.
Constraints
* 2 \leq N \leq 200\,000
* 0 < A_i < 10^4
* A_i is given with at most 9 digits after the decimal.
Input
Input is given from Standard Input in the fol... | import collections
N=int(input())
A=[]
PRECISION_DIGITS=9
cnt=collections.defaultdict(int)
for n in range(N):
tmpA = float(input())
tmpA = round(tmpA*10**PRECISION_DIGITS)
#print(tmpA)
five = 0
two = 0
while (tmpA % 2) == 0:
two += 1
tmpA //= 2
while (tmpA % 5) == 0:
five += 1
tmpA //= 5
# (10**9) ... | {
"input": [
"5\n7.5\n2.4\n17.000000001\n17\n16.000000000",
"11\n0.9\n1\n1\n1.25\n2.30000\n5\n70\n0.000000001\n9999.999999999\n0.999999999\n1.000000001",
"5\n7.5\n2.4\n17.000000001\n17\n16.487690532545415",
"5\n7.950925288494011\n2.4\n17.000000001\n17\n16.487690532545415",
"5\n7.5\n2.4\n17.0000000... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given N real values A_1, A_2, \ldots, A_N. Compute the number of pairs of indices (i, j) such that i < j and the product A_i \cdot A_j is integer.
Constraints
* 2 \leq N \le... |
p02719 AtCoder Beginner Contest 161 - Replacing Integer_5622 | Given any integer x, Aoki can do the operation below.
Operation: Replace x with the absolute difference of x and K.
You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.
Constraints
* 0 ≤ N ≤ 10^{18}
* 1 ≤ K ≤ 10^{18}
* All valu... | n,k= map(int,input().split())
a=n%k
b=abs(k-a)
print(min(a,b)) | {
"input": [
"1000000000000000000 1",
"7 4",
"2 6",
"1000000000000010000 1",
"7 6",
"7 9",
"17 12",
"7 13",
"8 16",
"5 9",
"30 23",
"10 22",
"37 10",
"12 23",
"14 23",
"13 30",
"19 31",
"-1 -2",
"44 30",
"70 44",
"33 84",
"1 -3",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Given any integer x, Aoki can do the operation below.
Operation: Replace x with the absolute difference of x and K.
You are given the initial value of an integer N. Find the minimum... |
p02848 AtCoder Beginner Contest 146 - ROT N_5626 | We have a string S consisting of uppercase English letters. Additionally, an integer N will be given.
Shift each character of S by N in alphabetical order (see below), and print the resulting string.
We assume that `A` follows `Z`. For example, shifting `A` by 2 results in `C` (`A` \to `B` \to `C`), and shifting `Y` ... | N = int(input())
S = input()
print(''.join(chr((ord(c) - ord('A') + N) % 26 + ord('A')) for c in S))
| {
"input": [
"13\nABCDEFGHIJKLMNOPQRSTUVWXYZ",
"0\nABCXYZ",
"2\nABCXYZ",
"13\nABCDEFGGIJKLMNOPQRSTUVWXYZ",
"0\nYBCXAZ",
"2\nABDXYZ",
"13\nABCDEFGGIJKLMNOOQRSTUVWXYZ",
"0\nYBBXAZ",
"2\nZYXDBA",
"13\nABCDEFGOIJKLMNGOQRSTUVWXYZ",
"0\nYABXAZ",
"2\nZXXDBA",
"13\nZYXWVUTS... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We have a string S consisting of uppercase English letters. Additionally, an integer N will be given.
Shift each character of S by N in alphabetical order (see below), and print the ... |
p02986 AtCoder Beginner Contest 133 - Colorful Tree_5629 | There is a tree with N vertices numbered 1 to N. The i-th edge in this tree connects Vertex a_i and Vertex b_i, and the color and length of that edge are c_i and d_i, respectively. Here the color of each edge is represented by an integer between 1 and N-1 (inclusive). The same integer corresponds to the same color, and... | import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
class LCA:
def __init__(self,V,edges,depth,parent,root=0):
self.edges=edges
self.maxLog=18
self.parent=[[-1]*V for _ in range(self.maxLog+1)]
self.parent[0]=parent
self.depth=depth
for i in range(self.ma... | {
"input": [
"5 3\n1 2 1 10\n1 3 2 20\n2 4 4 30\n5 2 1 40\n1 100 1 4\n1 100 1 5\n3 1000 3 4",
"5 3\n1 2 1 10\n1 3 1 20\n2 4 4 30\n5 2 1 40\n1 100 1 4\n1 100 1 5\n3 1000 3 4",
"5 3\n1 2 1 10\n1 3 1 20\n2 4 4 30\n5 2 1 40\n1 100 1 4\n1 100 1 5\n3 1000 1 4",
"5 3\n1 2 1 10\n1 3 1 20\n2 4 4 30\n5 2 1 40\n... | 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 to N. The i-th edge in this tree connects Vertex a_i and Vertex b_i, and the color and length of that edge are c_i and d_i, respectively. He... |
p03127 AtCoder Beginner Contest 118 - Monsters Battle Royale_5633 | There are N monsters, numbered 1, 2, ..., N.
Initially, the health of Monster i is A_i.
Below, a monster with at least 1 health is called alive.
Until there is only one alive monster, the following is repeated:
* A random alive monster attacks another random alive monster.
* As a result, the health of the monster a... | from fractions import gcd
from functools import reduce
n, *A = map(int, open(0).read().split())
print(reduce(gcd, A)) | {
"input": [
"3\n1000000000 1000000000 1000000000",
"4\n5 13 8 1000000000",
"4\n2 10 8 40",
"3\n1000000100 1000000000 1000000000",
"4\n5 13 8 1000010000",
"4\n0 10 8 40",
"3\n1100000100 0100100010 1000000000",
"3\n0111100010 0101001110 1010110101",
"4\n0 0 0 0111111011",
"3\n11... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are N monsters, numbered 1, 2, ..., N.
Initially, the health of Monster i is A_i.
Below, a monster with at least 1 health is called alive.
Until there is only one alive monst... |
p03270 AtCoder Regular Contest 102 - Stop. Otherwise..._5636 | Takahashi throws N dice, each having K sides with all integers from 1 to K. The dice are NOT pairwise distinguishable. For each i=2,3,...,2K, find the following value modulo 998244353:
* The number of combinations of N sides shown by the dice such that the sum of no two different sides is i.
Note that the dice are ... | from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect
def read():
return int(input())
def reads():
return [int(x) for x in input().split()]
K, N = reads()
MOD = 998244353
MAXN = 4020
fact = [1] * MAXN
f... | {
"input": [
"6 1000",
"3 3",
"4 5",
"8 1000",
"3 6",
"1 5",
"13 1000",
"18 1000",
"18 1100",
"2 3",
"18 0100",
"5 3",
"21 1100",
"5 5",
"35 1100",
"47 1100",
"47 1000",
"93 1000",
"110 1000",
"110 1010",
"110 0010",
"110 0110",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Takahashi throws N dice, each having K sides with all integers from 1 to K. The dice are NOT pairwise distinguishable. For each i=2,3,...,2K, find the following value modulo 998244353... |
p03427 AtCoder Grand Contest 021 - Digit Sum 2_5640 | Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
Constraints
* 1\leq N \leq 10^{16}
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the maximum possible sum of the digits (in base 10) of a positive integer not... | N=input()
NL=len(N)
if N[1:]=='9'*(NL-1):
ans=int(N[0])+9*(NL-1)
else:
ans=int(N[0])+9*(NL-1)-1
print(ans) | {
"input": [
"3141592653589793",
"100",
"9995",
"1265641936938969",
"101",
"613",
"1180",
"2005985506723837",
"78",
"813322357948504",
"127248513971408",
"46390584841058",
"51",
"67784328360011",
"89",
"34",
"307201070613497",
"2",
"190903186... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
Constraints
* 1\leq N \leq 10^{16}
* N is an integer.
Input
Input is given from ... |
p03585 Tenka1 Programmer Contest - CARtesian Coodinate_5643 | There are N lines in the xy-plane. The i-th line is represented by A_ix+B_iy=C_i. Any two lines among the N+2 lines, the above N lines plus the x-axis and y-axis, cross each other at exactly one point.
For each pair 1 \leq i < j \leq N, there is a car at the cross point of the i-th and j-th lines. Even where three or ... | def addbit(i):
i += 1
while i <= N:
BIT[i] += 1
i += i & (-i)
def getsum(i):
ret = 0
i += 1
while i != 0:
ret += BIT[i]
i -= i&(-i)
return ret
def bit(L):
global BIT
BIT=[0] * (N+1)
re = 0
for l in L:
re += getsum(l)
addbit(l)
r... | {
"input": [
"4\n1 1 2\n1 -1 0\n3 -1 -2\n1 -3 4",
"3\n1 1 1\n2 -1 2\n-1 2 2",
"7\n1 7 8\n-2 4 9\n3 -8 -5\n9 2 -14\n6 7 5\n-8 -9 3\n3 8 10",
"4\n1 1 2\n1 -1 0\n3 -1 -2\n1 -3 5",
"3\n1 1 1\n2 -1 2\n-1 2 4",
"3\n1 1 1\n2 -1 2\n-1 2 1",
"7\n1 7 8\n-2 4 9\n3 -8 -5\n9 2 -14\n4 7 5\n-8 -9 3\n3 8 ... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are N lines in the xy-plane. The i-th line is represented by A_ix+B_iy=C_i. Any two lines among the N+2 lines, the above N lines plus the x-axis and y-axis, cross each other at ... |
p03743 AtCoder Regular Contest 072 - Alice in linear land_5647 | Alice lives on a line. Today, she will travel to some place in a mysterious vehicle. Initially, the distance between Alice and her destination is D. When she input a number x to the vehicle, it will travel in the direction of the destination by a distance of x if this move would shorten the distance between the vehicle... | N, D = map(int, input().split())
d = list(map(int, input().split()))
Q = int(input())
q = list(map(lambda x : int(x)-1 , input().split()))
dis = [0 for i in range(N+1)]
dis[0] = D
for i in range(N):
dis[i+1] = min(dis[i], abs(dis[i] - d[i]))
dp = [0 for i in range(N+1)]
dp[N] = 1
for i in range(N-1, -1, -1):
... | {
"input": [
"5 9\n4 4 2 3 2\n5\n1 4 2 3 5",
"6 15\n4 3 5 4 2 1\n6\n1 2 3 4 5 6",
"4 10\n3 4 3 3\n2\n4 3",
"5 9\n4 4 2 3 4\n5\n1 4 2 3 5",
"6 15\n4 3 5 4 2 1\n6\n1 2 3 0 5 6",
"6 15\n4 3 5 4 2 1\n6\n1 2 4 0 5 6",
"6 15\n4 3 5 4 0 1\n6\n1 2 3 4 5 6",
"4 10\n3 2 3 3\n2\n4 3",
"6 15\n... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Alice lives on a line. Today, she will travel to some place in a mysterious vehicle. Initially, the distance between Alice and her destination is D. When she input a number x to the v... |
p03903 CODE FESTIVAL 2016 Elimination Tournament Round 1 (Parallel) - Graph_5650 | Takahashi found an undirected connected graph with N vertices and M edges. The vertices are numbered 1 through N. The i-th edge connects vertices a_i and b_i, and has a weight of c_i.
He will play Q rounds of a game using this graph. In the i-th round, two vertices S_i and T_i are specified, and he will choose a subse... | from collections import deque
import sys
sys.setrecursionlimit(10**5)
N, M = map(int, input().split())
E = []
for i in range(M):
a, b, c = map(int, input().split())
E.append((c, a-1, b-1))
E.sort()
*p, = range(N)
def root(x):
if x == p[x]:
return x
p[x] = y = root(p[x])
return y
L = 2*N-1... | {
"input": [
"4 6\n1 3 5\n4 1 10\n2 4 6\n3 2 2\n3 4 5\n2 1 3\n1\n2 3",
"4 3\n1 2 3\n2 3 4\n3 4 5\n2\n2 3\n1 4",
"4 6\n1 3 5\n4 1 10\n2 4 6\n3 2 2\n3 4 5\n2 1 4\n1\n2 3",
"4 6\n1 3 5\n4 1 11\n2 4 6\n3 2 2\n3 4 5\n2 1 4\n1\n2 1",
"4 6\n1 3 5\n4 2 10\n2 4 6\n3 2 2\n3 4 5\n2 1 3\n1\n2 3",
"4 6\n1 ... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Takahashi found an undirected connected graph with N vertices and M edges. The vertices are numbered 1 through N. The i-th edge connects vertices a_i and b_i, and has a weight of c_i.... |
p00009 Prime Number_5654 | Write a program which reads an integer n and prints the number of prime numbers which are less than or equal to n. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
Input
Input consists of several da... | import sys
import math
LIMIT = 1000000
p = 2
pList = [True] * (LIMIT + 1)
while p ** 2 <= LIMIT:
if(pList[p]):
for i in range(p * 2, LIMIT + 1 , p):
pList[i] = False
p += 1
# print(pList)
lines = str(sys.stdin.read()).strip().split("\n")
for line in lines:
line = int(line)
co... | {
"input": [
"10\n3\n11",
"10\n3\n5",
"10\n3\n9",
"10\n3\n2",
"10\n6\n2",
"10\n6\n11",
"10\n1\n5",
"10\n1\n2",
"10\n2\n2",
"10\n3\n4",
"10\n6\n3",
"10\n2\n5",
"10\n1\n4",
"10\n2\n4",
"10\n5\n1",
"10\n4\n1",
"10\n1\n1",
"10\n2\n1",
"10\n8\n1",... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Write a program which reads an integer n and prints the number of prime numbers which are less than or equal to n. A prime number is a natural number which has exactly two distinct na... |
p00141 Spiral Pattern_5658 | I decided to create a program that displays a "round and round pattern". The "round and round pattern" is as follows.
* If the length of one side is n, it is displayed as a character string with n rows and n columns.
* A spiral pattern that rotates clockwise with the lower left corner as the base point.
* The part wit... | vector = ((0, -1), (1, 0), (0, 1), (-1, 0))
def make_guruguru(d):
lst = [["#"] * (d + 4)]
for _ in range(d + 2):
lst.append(["#"] + [" "] * (d + 2) + ["#"])
lst.append(["#"] * (d + 4))
x, y = 2, d + 1
lst[y][x] = "#"
direct = 0
vx, vy = vector[0]
cnt = 1
while True:
while lst[y + vy * 2][x + ... | {
"input": [
"2\n5\n6",
"2\n5\n5",
"2\n8\n5",
"2\n12\n5",
"2\n12\n3",
"2\n5\n9",
"2\n5\n7",
"2\n8\n9",
"2\n16\n3",
"2\n9\n9",
"2\n10\n7",
"2\n8\n4",
"2\n20\n3",
"2\n9\n8",
"2\n9\n7",
"2\n2\n4",
"2\n20\n4",
"2\n9\n13",
"2\n1\n13",
"2\n2\n2... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
I decided to create a program that displays a "round and round pattern". The "round and round pattern" is as follows.
* If the length of one side is n, it is displayed as a character... |
p00274 A Pair of Prizes_5662 | Jou and Yae are a good couple. Jou is collecting prizes for capsule toy vending machines (Gachapon), and even when they go out together, when they find Gachapon, they seem to get so hot that they try it several times. Yae was just looking at Jou, who looked happy, but decided to give him a Gachapon prize for his upcomi... | # AOJ 0279: A Pair of Prizes
# Python3 2018.6.25 bal4u
while True:
n = int(input())
if n == 0: break
k = list(map(int, input().split()))
one, many = 0, 0
for i in k:
if i == 1: one += 1
elif i > 1: many += 1
print(one+many+1 if many > 0 else "NA")
| {
"input": [
"2\n3 2\n3\n0 1 1\n1\n1000\n0",
"2\n3 0\n3\n0 1 1\n1\n1000\n0",
"2\n3 2\n3\n0 1 1\n1\n0000\n0",
"2\n1 0\n3\n0 1 1\n1\n1000\n0",
"2\n2 0\n3\n0 1 1\n0\n1100\n0",
"2\n1 0\n3\n0 1 1\n0\n1100\n0",
"2\n3 2\n3\n0 0 1\n1\n1000\n0",
"2\n6 4\n3\n0 1 2\n1\n0000\n0",
"2\n0 4\n3\n0... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Jou and Yae are a good couple. Jou is collecting prizes for capsule toy vending machines (Gachapon), and even when they go out together, when they find Gachapon, they seem to get so h... |
p00462 Pizza_5666 | problem
JOI Pizza sells pizza home delivery along the d-meter-long ring road that runs through the city center.
JOI Pizza has n stores S1, ..., Sn on the loop line. The head office is S1. The distance from S1 to Si when moving the loop line clockwise is set to di meters. D2 , ..., dn is an integer greater than or equ... | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0539
AC
"""
import sys
from sys import stdin
from bisect import bisect_right
input = stdin.readline
def main(args):
while True:
d = int(input()) # ??°??¶????????????
if d == 0:
break
n ... | {
"input": [
"8\n3\n2\n3\n1\n4\n6\n20\n4\n4\n12\n8\n16\n7\n7\n11\n8\n0",
"8\n3\n2\n3\n1\n4\n6\n20\n4\n4\n10\n8\n16\n7\n7\n11\n8\n0",
"8\n3\n2\n3\n1\n4\n6\n20\n4\n4\n12\n8\n16\n7\n7\n4\n8\n0",
"8\n3\n2\n3\n1\n4\n6\n20\n4\n4\n14\n8\n16\n7\n7\n11\n8\n0",
"8\n3\n2\n3\n1\n7\n7\n12\n4\n4\n12\n8\n16\n7\n... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
problem
JOI Pizza sells pizza home delivery along the d-meter-long ring road that runs through the city center.
JOI Pizza has n stores S1, ..., Sn on the loop line. The head office ... |
p00652 Cutting a Chocolate_5669 | Turtle Shi-ta and turtle Be-ko decided to divide a chocolate. The shape of the chocolate is rectangle. The corners of the chocolate are put on (0,0), (w,0), (w,h) and (0,h). The chocolate has lines for cutting. They cut the chocolate only along some of these lines.
The lines are expressed as follows. There are m poi... | # AOJ 1067 Cutting a Chocolate
# Python3 2018.7.10 bal4u
from bisect import bisect_left
while True:
n, m, w, h, S = map(int, input().split())
if n == 0: break
m, wh2 = m+1, 2*(w*h)
S = wh2-2*S
tbl, s = [[0,0,0,0]], [0]
for i in range(1, m):
l, r = map(int, input().split())
tbl.append([l, r, 0, r-l])
s.app... | {
"input": [
"2 3 10 10 50\n3 3\n6 6\n10 10\n4.0000000000 4.0000000000\n7.0000000000 7.0000000000\n2 3 10 10 70\n3 3\n6 6\n10 10\n4.0000000000 4.0000000000\n7.0000000000 7.0000000000\n2 3 10 10 30\n3 3\n6 6\n10 10\n4.0000000000 4.0000000000\n7.0000000000 7.0000000000\n2 3 10 10 40\n3 3\n6 6\n10 10\n4.0000000000 4... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Turtle Shi-ta and turtle Be-ko decided to divide a chocolate. The shape of the chocolate is rectangle. The corners of the chocolate are put on (0,0), (w,0), (w,h) and (0,h). The choco... |
p00928 Automotive Navigation_5675 | Example
Input
4 2 1 1
1 1 1 2
2 2 2 1
2 2 1 2
1 1 2 1
9 N
Output
1 1
2 2 | # coding: utf-8
import sys
sys.setrecursionlimit(50000000)
max_c=101
vec=[(0,2),(2,0),(0,-2),(-2,0)]
try:
while True:
log=[-1 for i in range(10001)]
n,x0,y0,t=map(int,input().split())
field=[[0 for i in range(max_c)]for i in range(max_c)]
for i in range(n):
a,b,c,d=map(la... | {
"input": [
"4 2 1 1\n1 1 1 2\n2 2 2 1\n2 2 1 2\n1 1 2 1\n9 N",
"4 2 1 1\n1 1 1 2\n2 2 2 1\n2 2 1 2\n1 1 2 1\n17 N",
"4 2 1 1\n1 1 1 2\n2 2 2 1\n2 2 1 2\n1 1 2 1\n4 N",
"4 2 1 1\n1 0 1 2\n2 2 2 1\n2 2 1 2\n1 1 2 1\n2 N",
"4 1 1 1\n1 1 1 2\n2 2 2 1\n2 2 1 2\n1 1 2 1\n4 N",
"4 2 1 1\n1 0 1 2\n2... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Example
Input
4 2 1 1
1 1 1 2
2 2 2 1
2 2 1 2
1 1 2 1
9 N
Output
1 1
2 2
### Input:
4 2 1 1
1 1 1 2
2 2 2 1
2 2 1 2
1 1 2 1
9 N
### Output:
1 1
2 2
### Input:
4 2 1 1
1 1 1 2
2... |
p01061 Community Integration_5677 | Problem
There are N villages. Each village is numbered from 1 to N. Due to the recent merger boom, several villages have been merged. Two or more merged villages will become one new city, and villages that are not merged with any village will remain villages.
You will be given multiple pieces of information that two ... | n, m = map(int, input().split())
q = []
for _ in range(m):
a, b = map(int, input().split())
i, j = -1, -1
for k in range(len(q)):
if i == -1:
if a in q[k]:
i = k
if j == -1:
if b in q[k]:
j = k
if i >= 0 and j >= 0:
... | {
"input": [
"4 2\n1 4\n2 3",
"5 0",
"10 5\n3 4\n1 2\n9 6\n2 6\n2 9",
"3 1\n1 2",
"3 3\n1 2\n2 3\n3 1",
"3 2\n1 2\n2 3",
"5 4\n1 2\n2 3\n3 4\n4 5",
"4 0",
"10 5\n3 4\n1 2\n9 6\n3 6\n2 9",
"3 1\n1 3",
"5 3\n1 2\n2 3\n3 1",
"8 4\n1 2\n2 3\n3 4\n4 5",
"7 0",
"13 0"... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Problem
There are N villages. Each village is numbered from 1 to N. Due to the recent merger boom, several villages have been merged. Two or more merged villages will become one new ... |
p01498 King Slime_5684 | There is a grid of size W × H surrounded by walls. Some cells in the grid are occupied by slimes. The slimes want to unite with each other and become a "King Slime".
In each move, a slime can move to east, west, south and north direction until it enters a cell occupied by another slime or hit the surrounding wall. If ... | import sys
class UnionFind:
def __init__(self,sz):
self.__ranks = [1] * sz
self.__parents = [ i for i in range(sz) ]
def find_parent(self, x):
if x == self.__parents[x]:
return x
else:
self.__parents[x] = self.find_parent(self.__parents[x])
re... | {
"input": [
"2 3 3\n2 2\n3 3",
"4 3 3\n1 1\n1 3\n3 1\n3 3",
"2 4 4\n2 2\n3 3",
"2 4 4\n2 2\n2 3",
"2 3 3\n2 4\n3 3",
"4 3 3\n1 1\n0 3\n3 1\n3 3",
"2 4 6\n2 2\n2 3",
"1 4 4\n2 2\n3 3",
"4 3 3\n1 1\n1 3\n6 1\n3 2",
"2 4 6\n2 2\n0 3",
"4 3 3\n1 1\n1 3\n3 1\n3 6",
"4 6 3\n... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is a grid of size W × H surrounded by walls. Some cells in the grid are occupied by slimes. The slimes want to unite with each other and become a "King Slime".
In each move, a ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.