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 |
|---|---|---|---|---|---|
1037_E. Trips_10 | There are n persons who initially don't know each other. On each morning, two of them, who were not friends before, become friends.
We want to plan a trip for every evening of m days. On each trip, you have to select a group of people that will go on the trip. For every person, one of the following should hold:
* ... | from collections import deque
def solve(adj, m, k, uv):
n = len(adj)
nn = [len(a) for a in adj]
q = deque()
for i in range(n):
if nn[i] < k:
q.append(i)
while q:
v = q.popleft()
for u in adj[v]:
nn[u] -= 1
if nn[u] == k-1:
... | {
"input": [
"4 4 2\n2 3\n1 2\n1 3\n1 4\n",
"5 8 2\n2 1\n4 2\n5 4\n5 2\n4 3\n5 1\n4 1\n3 2\n",
"5 7 2\n1 5\n3 2\n2 5\n3 4\n1 2\n5 3\n1 3\n",
"16 20 2\n10 3\n5 3\n10 5\n12 7\n7 6\n9 12\n9 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n4 13\n13 15\n1 8\n7 15\n1 7\n8 15\n",
"2 1 1\n2 1\n",
"16 20... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n persons who initially don't know each other. On each morning, two of them, who were not friends before, become friends.
We want to plan a trip for every evening of m days... |
1060_A. Phone Numbers_14 | Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.
For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.
You have n cards with digits, and you want to use them to make as many phone n... | n = int(input())
s = input()
k = s.count("8")
l = n - k
if k <= l//10: print(k)
else:
while k > l//10:
k -= 1
l += 1
print(min(k, l//10))
| {
"input": [
"22\n0011223344556677889988\n",
"11\n00000000008\n",
"11\n31415926535\n",
"51\n882889888888689888850888388887688788888888888858888\n",
"55\n7271714707719515303911625619272900050990324951111943573\n",
"72\n888488888888823288848804883838888888887888888888228888218488897809784868\n",... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.
For example, "80123456789" and "80000000000" are pho... |
1101_A. Minimum Integer_19 | You are given q queries in the following form:
Given three integers l_i, r_i and d_i, find minimum positive integer x_i such that it is divisible by d_i and it does not belong to the segment [l_i, r_i].
Can you answer all the queries?
Recall that a number x belongs to segment [l, r] if l ≤ x ≤ r.
Input
The first l... | n = int(input())
A = []
for i in range(n):
A = A+[input().split()]
for a in A:
if int(a[2]) < int(a[0]) or int(a[2]) > int(a[1]):
print(a[2])
else:
print(int(a[2])*(int(a[1])//int(a[2])+1))
| {
"input": [
"5\n2 4 2\n5 10 4\n3 10 1\n1 2 3\n4 6 5\n",
"20\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 100000... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given q queries in the following form:
Given three integers l_i, r_i and d_i, find minimum positive integer x_i such that it is divisible by d_i and it does not belong to the... |
1189_D1. Add on a Tree_27 | Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems.
You are given a tree with n nodes. In the beginning, 0 is written on all edges. In one operation, you can choose any 2 distinct leaves u, v and any real number x and add x to values written on al... | m = int(input())
l = [0 for _ in range(m + 1)]
for _ in range(m - 1):
a,b = map(int, input().split())
l[a] += 1
l[b] += 1
if 2 in l:
print("NO")
else:
print("YES")
| {
"input": [
"2\n1 2\n",
"3\n1 2\n2 3\n",
"5\n1 2\n1 3\n1 4\n2 5\n",
"6\n1 2\n1 3\n1 4\n2 5\n2 6\n",
"50\n16 4\n17 9\n31 19\n22 10\n8 1\n40 30\n3 31\n20 29\n47 27\n22 25\n32 34\n12 15\n40 32\n10 33\n47 12\n6 24\n46 41\n14 23\n12 35\n31 42\n46 28\n31 20\n46 37\n1 39\n29 49\n37 47\n40 6\n42 36\n47 2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems.
You are given a tree with n nodes. In the beginning, 0 is ... |
1208_D. Restore Permutation_31 | An array of integers p_{1},p_{2}, …,p_{n} is called a permutation if it contains each number from 1 to n exactly once. For example, the following arrays are permutations: [3,1,2], [1], [1,2,3,4,5] and [4,3,1,2]. The following arrays are not permutations: [2], [1,1], [2,3,4].
There is a hidden permutation of length n.
... | from sys import stdin,stdout
class Tree(object):
def __init__(self,n):
self.tree=[0]*(4*n+10)
self.b=[0]*(n+10)
self.a=list(map(int,stdin.readline().split()))
self.n=n
def update(self,L,C,l,r,rt):
if l==r:
self.tree[rt]+=C
return
mid=(l+r)... | {
"input": [
"3\n0 0 0\n",
"5\n0 1 1 1 10\n",
"2\n0 1\n",
"100\n0 0 57 121 57 0 19 251 19 301 19 160 57 578 664 57 19 50 0 621 91 5 263 34 5 96 713 649 22 22 22 5 108 198 1412 1147 84 1326 1777 0 1780 132 2000 479 1314 525 68 690 1689 1431 1288 54 1514 1593 1037 1655 807 465 1674 1747 1982 423 837 139... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
An array of integers p_{1},p_{2}, …,p_{n} is called a permutation if it contains each number from 1 to n exactly once. For example, the following arrays are permutations: [3,1,2], [1]... |
1227_D1. Optimal Subsequences (Easy Version)_34 | This is the easier version of the problem. In this version 1 ≤ n, m ≤ 100. You can hack this problem only if you solve and lock both problems.
You are given a sequence of integers a=[a_1,a_2,...,a_n] of length n. Its subsequence is obtained by removing zero or more elements from the sequence a (they do not necessarily... | # class SegmentTree(): # adapted from https://www.geeksforgeeks.org/segment-tree-efficient-implementation/
# def __init__(self,arr,func,initialRes=0):
# self.f=func
# self.N=len(arr)
# self.tree=[0 for _ in range(2*self.N)]
# self.initialRes=initialRes
# for i in range(self.... | {
"input": [
"3\n10 20 10\n6\n1 1\n2 1\n2 2\n3 1\n3 2\n3 3\n",
"7\n1 2 1 3 1 2 1\n9\n2 1\n2 2\n3 1\n3 2\n3 3\n1 1\n7 1\n7 7\n7 4\n",
"2\n1 10\n3\n2 2\n2 1\n1 1\n",
"2\n3922 3922\n3\n2 2\n2 1\n1 1\n",
"1\n1000000000\n1\n1 1\n",
"1\n1\n3\n1 1\n1 1\n1 1\n",
"5\n3 1 4 1 2\n15\n5 5\n5 4\n5 3\n5... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This is the easier version of the problem. In this version 1 ≤ n, m ≤ 100. You can hack this problem only if you solve and lock both problems.
You are given a sequence of integers a=... |
1269_E. K Integers_38 | You are given a permutation p_1, p_2, …, p_n.
In one move you can swap two adjacent values.
You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k.
... | n = int(input())
a = [0] + list(map(int, input().split()))
pos, pb, ps = [[0] * (n + 1) for x in range(3)]
def add(bit, i, val):
while i <= n:
bit[i] += val
i += i & -i
def sum(bit, i):
res = 0
while i > 0:
res += bit[i]
i -= i & -i
return res
def find(bit, sum):
... | {
"input": [
"3\n1 2 3\n",
"5\n5 4 3 2 1\n",
"1\n1\n",
"100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 8... | 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 p_1, p_2, …, p_n.
In one move you can swap two adjacent values.
You want to perform a minimum number of moves, such that in the end there will exist a su... |
1291_E. Prefix Enlightenment_41 | There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1).
You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≤ i_1 < i_2 < i_3 ≤ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = ∅.
In one operation, you ... | from sys import stdin
input = stdin.readline
n , k = [int(i) for i in input().split()]
pairs = [i + k for i in range(k)] + [i for i in range(k)]
initial_condition = list(map(lambda x: x == '1',input().strip()))
data = [i for i in range(2*k)]
constrain = [-1] * (2*k)
h = [0] * (2*k)
L = [1] * k + [0] * k
dp1 = [-1 for... | {
"input": [
"5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n",
"8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n",
"19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n",
"7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n",
"1 1\n1\n1\n1\n",
"5 3\n00011\n3\n1 2 3... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1).
You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection... |
1311_F. Moving Points_45 | There are n points on a coordinate axis OX. The i-th point is located at the integer point x_i and has a speed v_i. It is guaranteed that no two points occupy the same coordinate. All n points move with the constant speed, the coordinate of the i-th point at the moment t (t can be non-integer) is calculated as x_i + t ... | import bisect
def getsum(tree , i):
s = 0
i += 1
while i>0:
s += tree[i]
i -= i & (-i)
return s
def updatebit(tree , n , i , v):
i+= 1
while i <= n:
tree[i] += v
i += i & (-i)
n = int(input())
x = list(map(int , input().split()))
v = list(map(int , input().spli... | {
"input": [
"3\n1 3 2\n-100 2 3\n",
"2\n2 1\n-3 0\n",
"5\n2 1 4 3 5\n2 2 2 3 4\n",
"3\n1 3 2\n-100 2 6\n",
"2\n2 1\n-4 0\n",
"2\n0 1\n-4 0\n",
"2\n0 2\n-4 0\n",
"3\n1 5 2\n-167 2 6\n",
"3\n1 3 2\n-75 1 0\n",
"3\n1 7 2\n-255 0 6\n",
"3\n1 3 8\n-75 1 0\n",
"3\n1 3 8\n-75... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n points on a coordinate axis OX. The i-th point is located at the integer point x_i and has a speed v_i. It is guaranteed that no two points occupy the same coordinate. All... |
1334_D. Minimum Euler Cycle_49 | You are given a complete directed graph K_n with n vertices: each pair of vertices u ≠ v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of... | # -*- coding:utf-8 -*-
"""
created by shuangquan.huang at 2020/7/1
"""
import collections
import time
import os
import sys
import bisect
import heapq
from typing import List
def solve(n, l, r):
# 1, 2, 1, 3, ..., 1, n
# 2, 3, 2, 4, ..., 2, n
# ...
# n-1, n
# 1
lo, hi = 1, n
while... | {
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n",
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a complete directed graph K_n with n vertices: each pair of vertices u ≠ v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find s... |
1354_F. Summoning Minions_52 | Polycarp plays a computer game. In this game, the players summon armies of magical minions, which then fight each other.
Polycarp can summon n different minions. The initial power level of the i-th minion is a_i, and when it is summoned, all previously summoned minions' power levels are increased by b_i. The minions c... | from sys import stdin, gettrace
from heapq import nlargest
if not gettrace():
def input():
return next(stdin)[:-1]
# def input():
# return stdin.buffer.readline()
INF = int(10E10)
def main():
def solve():
n, k = map(int, input().split())
mm = []
for i in range(1,n+1):
... | {
"input": [
"3\n5 2\n5 3\n7 0\n5 0\n4 0\n10 0\n2 1\n10 100\n50 10\n5 5\n1 5\n2 4\n3 3\n4 2\n5 1\n",
"3\n5 2\n5 3\n7 0\n5 0\n4 0\n10 0\n2 1\n10 100\n50 10\n5 5\n1 5\n2 4\n3 3\n4 2\n5 1\n",
"3\n5 2\n5 3\n7 0\n5 0\n4 0\n10 0\n2 1\n10 100\n8 10\n5 5\n1 5\n2 4\n3 3\n4 2\n5 1\n",
"3\n5 2\n5 3\n7 0\n1 0\n4 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarp plays a computer game. In this game, the players summon armies of magical minions, which then fight each other.
Polycarp can summon n different minions. The initial power le... |
1374_E1. Reading Books (easy version)_56 | Easy and hard versions are actually different problems, so read statements of both problems completely and carefully.
Summer vacation has started so Alice and Bob want to play and joy, but... Their mom doesn't think so. She says that they have to read some amount of books before all entertainments. Alice and Bob will ... | import sys
input=sys.stdin.readline
f=lambda :list(map(int, input().strip('\n').split()))
n, k=f()
_11=[]
_01=[]
_10=[]
for _ in range(n):
t, a, b=f()
if a and b:
_11.append(t)
elif a:
_10.append(t)
elif b:
_01.append(t)
_01.sort(); _10.sort(); _11.sort()
for i in range(1, len(_01)):
_01[i]+=_01[i-1]
for i ... | {
"input": [
"8 4\n7 1 1\n2 1 1\n4 0 1\n8 1 1\n1 0 1\n1 1 1\n1 0 1\n3 0 0\n",
"5 2\n6 0 0\n9 0 0\n1 0 1\n2 1 1\n5 1 0\n",
"5 3\n3 0 0\n2 1 0\n3 1 0\n5 0 1\n3 0 1\n",
"2 1\n7 1 1\n2 1 1\n",
"5 1\n2 1 0\n2 0 1\n1 0 1\n1 1 0\n1 0 1\n",
"6 2\n6 0 0\n11 1 0\n9 0 1\n21 1 1\n10 1 0\n8 0 1\n",
"3 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Easy and hard versions are actually different problems, so read statements of both problems completely and carefully.
Summer vacation has started so Alice and Bob want to play and jo... |
1398_A. Bad Triangle_60 | You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≤ a_{i + 1}).
Find three indices i, j, k such that 1 ≤ i < j < k ≤ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to... | t=int(input())
for z in range(t):
n=int(input())
arr=list(map(int,input().split()))
min= arr[0] + arr[1]
pos=True
for i in range(2,n):
if(arr[i]>=min):
pos=False
posf=i
break
if(pos):
print("-1")
else:
print("1 2", posf+1)
| {
"input": [
"3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n",
"3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n",
"1\n6\n1 1 1 2 2 3\n",
"1\n3\n21 78868 80000\n",
"1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n",
"1\n3\n78788 78788 157577\n",
"1\n3\n5623 5624 10000000\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≤ a_{i + 1}).
Find three indices i, j, k such that 1 ≤ i < j < k ≤ n and it is impossible to... |
1421_B. Putting Bricks in the Wall_64 | Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like [walls](https://www.youtube.com/watch?v=YR5ApYxkU-U), he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid.
Roger Waters has a square grid of size n× n and he wants to traverse his grid f... | l=[]
for _ in range(int(input())):
n=int(input())
a=[]
for i in range(n):
a.append(list(input()))
if a[0][1]==a[1][0]:
if a[n-1][n-2]==a[n-2][n-1]:
if a[n-1][n-2]==a[0][1]:
l.append("2")
l.append("1 2")
l.append("2 1")
... | {
"input": [
"3\n4\nS010\n0001\n1000\n111F\n3\nS10\n101\n01F\n5\nS0101\n00000\n01111\n11111\n0001F\n",
"1\n3\nS01\n111\n00F\n",
"1\n5\nS0000\n00000\n00000\n00000\n0000F\n",
"1\n3\nS10\n010\n11F\n",
"1\n3\nS11\n011\n01F\n",
"1\n3\nS10\n010\n01F\n",
"1\n10\nS000000000\n0000000000\n0000000000... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like [walls](https://www.youtube.com/watch?v=YR5ApYxkU-U), he wants to be able to walk freely, so they are blockin... |
143_A. Help Vasilisa the Wise 2_68 | Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with tha... | inn = list(map(int, input().split(" ")))
r1 = inn[0]
r2 = inn[1]
inn = list(map(int, input().split(" ")))
c1 = inn[0]
c2 = inn[1]
inn = list(map(int, input().split(" ")))
d1 = inn[0]
d2 = inn[1]
x = int((d1+c1-r2)/2)
y = int(((2*r1)-d1-c1+r2)/2)
a = int(((2*c1)-d1-c1+r2)/2)
b = int((r2-(2*c1)+d1+c1)/2)
if x == y or x ... | {
"input": [
"1 2\n3 4\n5 6\n",
"11 10\n13 8\n5 16\n",
"3 7\n4 6\n5 5\n",
"10 10\n10 10\n10 10\n",
"3 14\n8 9\n10 7\n",
"12 11\n11 12\n16 7\n",
"12 17\n10 19\n13 16\n",
"9 12\n3 17\n10 10\n",
"10 7\n4 13\n11 6\n",
"7 9\n4 12\n5 11\n",
"2 4\n1 5\n3 3\n",
"13 8\n15 6\n11 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa... |
1466_F. Euclid's nightmare_72 | You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare.
In his bad dream Euclid has a set S of n m-dimensional vectors over the Z_2 field and can perform vector addition on them. In other words h... | import sys
input = sys.stdin.buffer.readline
def _find(s, u):
p = []
while s[u] != u:
p.append(u)
u = s[u]
for v in p: s[v] = u
return u
def _union(s, u, v):
su, sv = _find(s, u), _find(s, v)
if su != sv: s[su] = sv
return su != sv
n, m = map(int, input().split())
s, solo ... | {
"input": [
"3 2\n1 1\n1 2\n2 2 1\n",
"3 5\n2 1 2\n1 3\n1 4\n",
"2 3\n2 1 3\n2 1 2\n",
"50 5000\n2 35 46\n2 43 92\n2 16 88\n2 67 99\n2 36 93\n2 12 20\n2 33 96\n2 55 82\n2 18 32\n2 48 87\n2 29 83\n2 19 37\n2 68 100\n2 13 76\n2 73 90\n2 25 86\n2 17 61\n2 10 27\n2 70 94\n2 28 41\n2 14 53\n2 15 72\n2 8 9... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare.
In... |
1490_G. Old Floppy Drive _76 | Polycarp was dismantling his attic and found an old floppy drive on it. A round disc was inserted into the drive with n integers written on it.
Polycarp wrote the numbers from the disk into the a array. It turned out that the drive works according to the following algorithm:
* the drive takes one positive number x... |
def findIndexGE(prefixSumsMax,startSum,query):
n=len(prefixSumsMax)
b=n
i=-1
while b>0:
while i+b<n and startSum+prefixSumsMax[i+b]<query:
i+=b
b//=2
i+=1
return i
def main():
t=int(input())
allans=[]
for _ in range(t):
n,m=readIntArr()
... | {
"input": [
"3\n3 3\n1 -3 4\n1 5 2\n2 2\n-2 0\n1 2\n2 2\n0 1\n1 2\n",
"3\n3 3\n1 -3 4\n1 5 2\n2 2\n-4 0\n1 2\n2 2\n0 1\n1 2\n",
"3\n3 3\n1 -3 4\n1 5 2\n2 2\n-2 0\n1 2\n2 2\n0 2\n1 2\n",
"3\n3 3\n2 -3 4\n1 5 2\n2 2\n-4 0\n1 2\n2 2\n0 1\n1 2\n",
"3\n3 3\n0 -3 4\n1 5 2\n2 2\n-4 0\n1 1\n2 2\n0 1\n1 2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarp was dismantling his attic and found an old floppy drive on it. A round disc was inserted into the drive with n integers written on it.
Polycarp wrote the numbers from the di... |
1513_C. Add One_80 | You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since... | from os import path
import sys,time
from math import ceil, floor,gcd,log,log2 ,factorial
from collections import defaultdict ,Counter , OrderedDict , deque
from heapq import heapify , heappush , heappop
from bisect import *
# from functools import reduce
from operator import mul
from itertools import permutations
maxx,... | {
"input": [
"5\n1912 1\n5 6\n999 1\n88 2\n12 100\n",
"5\n90 94\n26 25\n64 84\n14 6\n20 96\n",
"5\n90 94\n26 25\n64 84\n18 6\n20 96\n",
"5\n1912 1\n5 6\n999 1\n88 2\n11 100\n",
"5\n90 94\n26 25\n64 84\n22 6\n20 96\n",
"5\n1912 1\n5 6\n999 1\n88 2\n6 100\n",
"5\n90 113\n26 25\n64 84\n22 6\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1... |
1540_C1. Converging Array (Easy Version)_84 | This is the easy version of the problem. The only difference is that in this version q = 1. You can make hacks only if both versions of the problem are solved.
There is a process that takes place on arrays a and b of length n and length n-1 respectively.
The process is an infinite sequence of operations. Each operat... | def putin():
return map(int, input().split())
def sol():
n = int(input())
C = list(putin())
B = list(putin())
q = int(input())
x = int(input())
min_arr = [x]
min_part_sums = [x]
part_sums = [C[0]]
for i in range(1, n):
part_sums.append(part_sums[-1] + C[i])
for elem... | {
"input": [
"3\n2 3 4\n2 1\n1\n-1\n",
"100\n95 54 23 27 51 58 94 34 29 95 53 53 8 5 64 32 17 62 14 37 26 95 27 85 94 37 85 72 88 69 43 9 60 3 48 26 81 48 89 56 34 28 2 63 26 6 13 19 99 41 70 24 92 41 9 73 52 42 34 98 16 82 7 81 28 80 18 33 90 69 19 13 51 96 8 21 86 32 96 7 5 42 52 87 24 82 14 88 4 69 7 69 4 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This is the easy version of the problem. The only difference is that in this version q = 1. You can make hacks only if both versions of the problem are solved.
There is a process tha... |
168_A. Wizards and Demonstration_88 | Some country is populated by wizards. They want to organize a demonstration.
There are n people living in the city, x of them are the wizards who will surely go to the demonstration. Other city people (n - x people) do not support the wizards and aren't going to go to the demonstration. We know that the city administr... | num,wiz,per = map(int,input().split())
k = 0
while (k+wiz)/num*100 < per:
k += 1
print(k) | {
"input": [
"1000 352 146\n",
"10 1 14\n",
"20 10 50\n",
"7879 2590 2818\n",
"78 28 27\n",
"9178 2255 7996\n",
"6571 6449 8965\n",
"6151 6148 3746\n",
"6487 5670 8\n",
"4890 1112 5\n",
"4909 2111 8860\n",
"10000 10000 10000\n",
"78 55 96\n",
"3271 5 50\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Some country is populated by wizards. They want to organize a demonstration.
There are n people living in the city, x of them are the wizards who will surely go to the demonstration.... |
20_B. Equation_92 | You are given an equation:
Ax2 + Bx + C = 0.
Your task is to find the number of distinct roots of the equation and print all of them in ascending order.
Input
The first line contains three integer numbers A, B and C ( - 105 ≤ A, B, C ≤ 105). Any coefficient may be equal to 0.
Output
In case of infinite root cou... | a, b, c = map(float, input().split())
D = b ** 2 - (4 * a * c)
if D < 0:
print(0)
elif a == 0 and b == 0 and c != 0:
print(0)
elif a == 0 and b == 0 and c == 0:
print(-1)
elif a == 0:
x0 = c / -(b)
print(1)
print(x0)
elif b == 0:
print(1)
print(0)
elif D == 0 and (a > 0 or a < 0):
x ... | {
"input": [
"1 -5 6\n",
"0 -2 0\n",
"1223 -23532 1232\n",
"0 1 0\n",
"-1 10 20\n",
"0 3431 43123\n",
"-50000 100000 -50000\n",
"1 1 0\n",
"50000 100000 50000\n",
"0 -2 1\n",
"0 -4 -4\n",
"1 1 1\n",
"1 -100000 0\n",
"-2 -5 0\n",
"0 1 -1\n",
"1 0 0\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 equation:
Ax2 + Bx + C = 0.
Your task is to find the number of distinct roots of the equation and print all of them in ascending order.
Input
The first line con... |
260_B. Ancient Prophesy_98 | A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-".
We'll say that some date is mentioned in the Prophesy if there is a substring in the Prophesy that is the date's record in the format "dd-mm-yyyy". We'll say tha... | s=input()
n=len(s)
l=list("0987654321")
cnt={}
for i in range(n-9):
t=s[i:i+10]
if t[0] in l and t[1] in l and t[2]=="-" and t[3] in l and t[4] in l and t[5]=="-" and t[6] in l and t[7] in l and t[8] in l and t[9] in l:
if 2013<=int(t[6:11])<=2015 and 1<=int(t[3:5])<=12:
if int(t[3:5]) in [1,3,5,7,8,10,1... | {
"input": [
"777-444---21-12-2013-12-2013-12-2013---444-777\n",
"12-12-201312-12-201312-12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-2013\n",
"01--01--2013-12-2013-01--01--2013\n",
"01-04-201425-08-201386-04-201525-10-2014878-04-20102-06-201501-04-2014-08... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-".
We'll say that some date... |
284_B. Cows and Poker Game_102 | There are n cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspense, a player whose current status is not "FOLDED" may show his/her hand to the table. However, so as not to affect any bett... | #!/bin/python
# -*- coding: utf-8 -*-
n = int(input())
s = input()
print(int(s.count('I') == 1) if 'I' in s else s.count('A'))
| {
"input": [
"3\nAFI\n",
"6\nAFFAAA\n",
"2\nFF\n",
"5\nIIIIF\n",
"5\nFAFFF\n",
"2\nFA\n",
"3\nAAA\n",
"5\nFAIAF\n",
"5\nAIFFF\n",
"3\nFFF\n",
"3\nFIF\n",
"3\nIII\n",
"5\nFAAII\n",
"2\nIF\n",
"8\nAFFFFIAF\n",
"5\nIIIII\n",
"3\nIAA\n",
"10\nAAAAAAA... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To incre... |
379_A. New Year Candles_111 | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has a candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make b went out candles into a new candle. As a result, this new candle can be used like... | a, b = map(int, input().split())
c, s = a, 0
while a >= b:
s += a // b
a = (a // b) + (a % b)
print(s + c)
| {
"input": [
"4 2\n",
"6 3\n",
"5 3\n",
"1000 3\n",
"777 17\n",
"4 3\n",
"2 2\n",
"100 4\n",
"10 4\n",
"999 2\n",
"6 4\n",
"1 2\n",
"17 3\n",
"1 4\n",
"26 8\n",
"91 5\n",
"1 3\n",
"1000 2\n",
"20 3\n",
"9 4\n",
"123 5\n",
"1000 10... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has a candles.When Vasily lights up a new candle, it first burns for an hour ... |
39_H. Multiplication Table_115 | Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multiplication. To multiply large numbers one has to learn the multiplication table. Unfortunately, in the second grade students learn... | k=int(input())
for i in range(1,k):
z,a=i,[]
for j in range(k-1):
p,s=z,""
while p:
s=str(p%k)+s
p//=k
z+=i
a.append(s)
print(*a)
| {
"input": [
"10\n",
"3\n",
"9\n",
"8\n",
"6\n",
"4\n",
"7\n",
"5\n",
"2\n",
"010\n"
],
"output": [
"1 2 3 4 5 6 7 8 9 \n2 4 6 8 10 12 14 16 18 \n3 6 9 12 15 18 21 24 27 \n4 8 12 16 20 24 28 32 36 \n5 10 15 20 25 30 35 40 45 \n6 12 18 24 30 36 42 48 54 \n7... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action... |
44_B. Cola_121 | To celebrate the opening of the Winter Computer School the organizers decided to buy in n liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that cola is sold in bottles 0.5, 1 and 2 liters in volume. At that, there are exactly a bottles 0.5 in volume, b one-liter bottles and c of two... | def nik(rudy,x,y,z,cot):
for i in range(z+1):
for j in range(y+1):
t = rudy - i*2 -j
if t>=0 and x*0.5 >= t:
cot+=1
return cot
rudy, x, y, z = list(map(int,input().split()))
cot = 0
print(nik(rudy,x,y,z,cot))
| {
"input": [
"10 5 5 5\n",
"3 0 0 2\n",
"10 20 10 5\n",
"20 1 2 3\n",
"7 2 2 2\n",
"25 10 5 10\n",
"999 999 899 299\n",
"10000 5000 0 5000\n",
"2 2 2 2\n",
"1 0 2 0\n",
"3 3 2 1\n",
"1 1 0 0\n",
"1 0 0 1\n",
"20 10 20 30\n",
"505 142 321 12\n",
"101 10 1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
To celebrate the opening of the Winter Computer School the organizers decided to buy in n liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that co... |
519_B. A and B and Compilation Errors_127 | A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed n compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix s... | n = int(input())
a_sum = sum(map(int, input().split()))
b_sum = sum(map(int, input().split()))
c_sum = sum(map(int, input().split()))
print(a_sum - b_sum)
print(b_sum - c_sum) | {
"input": [
"6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n",
"5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n",
"3\n1 2 3\n3 2\n2\n",
"3\n84 30 9\n9 84\n9\n",
"4\n1 5 7 8\n1 5 7\n1 5\n",
"3\n796067435 964699482 819602309\n964699482 796067435\n964699482\n",
"10\n460626451 802090732 277246428 661369649 388684428... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initial... |
545_C. Woodcutters_131 | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each ... | ll=lambda:map(int,input().split())
t=lambda:int(input())
ss=lambda:input()
#from math import log10 ,log2,ceil,factorial as f,gcd
#from itertools import combinations_with_replacement as cs
#from functools import reduce
#from bisect import bisect_right as br
#from collections import Counter
n=t()
x,h=[],[]
for _ in ran... | {
"input": [
"5\n1 2\n2 1\n5 10\n10 9\n20 1\n",
"5\n1 2\n2 1\n5 10\n10 9\n19 1\n",
"4\n10 4\n15 1\n19 3\n20 1\n",
"2\n1 999999999\n1000000000 1000000000\n",
"67\n1 1\n3 8\n4 10\n7 8\n9 2\n10 1\n11 5\n12 8\n13 4\n16 6\n18 3\n19 3\n22 5\n24 6\n27 5\n28 3\n29 3\n30 5\n32 5\n33 10\n34 7\n35 8\n36 5\n4... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She im... |
593_C. Beautiful Function_138 | Every day Ruslan tried to count sheep to fall asleep, but this didn't help. Now he has found a more interesting thing to do. First, he thinks of some set of circles on a plane, and then tries to choose a beautiful set of points, such that there is at least one point from the set inside or on the border of each of the i... | def f(x):
if x == n:
return "0"
if x == 0:
return "(" + str(X[0]) + "+" + f(1) + ")"
ss = "(abs((t-" + str(x-1) + "))-abs((t-" + str(x) + ")))"
tmp = (X[x] - X[x - 1]) // 2
re = (X[x] - X[x - 1]) - 2 * tmp
X[x] -= re
if t... | {
"input": [
"3\n0 10 4\n10 0 4\n20 10 4\n",
"3\n9 5 8\n8 9 10\n9 5 2\n",
"50\n48 45 42\n32 45 8\n15 41 47\n32 29 38\n7 16 48\n19 9 21\n18 40 5\n39 40 7\n37 0 6\n42 15 37\n9 33 37\n40 41 33\n25 43 2\n23 21 38\n30 20 32\n28 15 5\n47 9 19\n47 22 26\n26 9 18\n24 23 24\n11 29 5\n38 44 9\n49 22 42\n1 15 32\n18... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Every day Ruslan tried to count sheep to fall asleep, but this didn't help. Now he has found a more interesting thing to do. First, he thinks of some set of circles on a plane, and th... |
615_A. Bulbs_142 | Vasya wants to turn on Christmas lights consisting of m bulbs. Initially, all bulbs are turned off. There are n buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
If Va... | import math
nm = input().split()
n = int(nm[0])
m = int(nm[1])
lis = [ 0 for i in range(m+1)]
for _ in range(n) :
inp = list(map(int, input().split()))
inp.pop(0)
for i in inp:
lis[i]=1
prev = i
if sum(lis)==m:
print("YES")
else:
print("NO") | {
"input": [
"3 4\n2 1 4\n3 1 3 1\n1 2\n",
"3 3\n1 1\n1 2\n1 1\n",
"3 4\n1 1\n1 2\n1 3\n",
"1 100\n99 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 70... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya wants to turn on Christmas lights consisting of m bulbs. Initially, all bulbs are turned off. There are n buttons, each of them is connected to some set of bulbs. Vasya can pres... |
634_C. Factory Repairs_145 | A factory produces thimbles in bulk. Typically, it can produce up to a thimbles a day. However, some of the machinery is defective, so it can currently only produce b thimbles each day. The factory intends to choose a k-day period to do maintenance and construction; it cannot produce any thimbles during this time, but ... | from functools import reduce
class SegmentTree():
def __init__(self, L, function = lambda x,y: x+y, initilizer = None):
self.function = function
self.initilizer = initilizer
N = self.size = len(L)
M = 1 << N.bit_length()
self.margin = 2*M - N
self.L = [None for i in r... | {
"input": [
"5 4 10 1 6\n1 1 5\n1 5 5\n1 3 2\n1 5 2\n2 1\n2 2\n",
"5 2 2 1 8\n1 1 2\n1 5 3\n1 2 1\n2 2\n1 4 2\n1 3 2\n2 1\n2 3\n",
"1 1 2 1 1\n2 1\n",
"1 1 2 2 1\n2 1\n",
"5 2 2 1 8\n1 1 2\n1 5 3\n1 2 1\n2 2\n1 4 2\n1 3 0\n2 1\n2 3\n",
"5 2 2 2 8\n1 1 2\n1 5 3\n1 2 1\n2 2\n1 4 2\n1 3 2\n2 1\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A factory produces thimbles in bulk. Typically, it can produce up to a thimbles a day. However, some of the machinery is defective, so it can currently only produce b thimbles each da... |
663_A. Rebus_149 | You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer n. The goal is to replace each question mark with some positive integer from 1 to n, such that equality holds.
Input
The only line of the input contains a re... | s = input().split()
plus = 1
minus = 0
for ch in s:
if (ch == '+') :
plus += 1
if (ch == '-') :
minus += 1
n = int(s[len(s) - 1])
maxx = plus * n - 1 * minus
minn = plus - n * minus
now = n - (plus - minus)
if (n>maxx or n<minn):
print("Impossible")
else:
pre = '+'
print("Possible")
for ch in s:
... | {
"input": [
"? - ? = 1\n",
"? + ? - ? + ? + ? = 42\n",
"? = 1000000\n",
"? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer n. The goal is to repl... |
730_J. Bottles_157 | Nick has n bottles of soda left after his birthday. Each bottle is described by two values: remaining amount of soda ai and bottle volume bi (ai ≤ bi).
Nick has decided to pour all remaining soda into minimal number of bottles, moreover he has to do it as soon as possible. Nick spends x seconds to pour x units of soda... | f = lambda: list(map(int, input().split()))
n = int(input())
a, b = f(), f()
d = [[None] * 10001 for i in range(n)]
def g(i, s):
if s <= 0: return (0, s)
if i == n: return (1e7, 0)
if not d[i][s]:
x, y = g(i + 1, s - b[i])
d[i][s] = min(g(i + 1, s), (x + 1, y + b[i] - a[i]))
return d[... | {
"input": [
"2\n1 1\n100 100\n",
"5\n10 30 5 6 24\n10 41 7 8 24\n",
"4\n3 3 4 3\n4 7 6 5\n",
"30\n10 1 8 10 2 6 45 7 3 7 1 3 1 1 14 2 5 19 4 1 13 3 5 6 1 5 1 1 23 1\n98 4 43 41 56 58 85 51 47 55 20 85 93 12 49 15 95 72 20 4 68 24 16 97 21 52 18 69 89 15\n",
"20\n8 1 44 1 12 1 9 11 1 1 5 2 9 16 16... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Nick has n bottles of soda left after his birthday. Each bottle is described by two values: remaining amount of soda ai and bottle volume bi (ai ≤ bi).
Nick has decided to pour all r... |
776_A. A Serial Killer_163 | Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two potential victims on his first day, selects one of these two, kills selected ... | def main():
l = input().split()
print(*l)
for _ in range(int(input())):
a, b = input().split()
l[a == l[1]] = b
print(*l)
if __name__ == '__main__':
main()
| {
"input": [
"icm codeforces\n1\ncodeforces technex\n",
"ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n",
"wwwww w\n8\nwwwww wwwwwwww\nwwwwwwww wwwwwwwww\nwwwwwwwww wwwwwwwwww\nw www\nwwwwwwwwww wwww\nwwww ww\nwww wwwwww\nwwwwww wwwwwww\n",
"k d\n17\nk l\nd v\nv z\nl r\nz i... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy... |
7_B. Memory Manager_167 | There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet — the memory manager is among them. According to the developers' plan, in the first release the memory manager will be very simple and rectilinear. It will support three operations:
... | t, m = map(int, input().split())
disk = [False] * m
req = 0
for i in range(t):
inp = input().split()
if inp[0][0] == "a":
c = 0
inp[1] = int(inp[1])
for j in range(m):
if disk[j]:
c = 0
else:
c += 1
if c == inp[1]:
... | {
"input": [
"6 10\nalloc 5\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6\n",
"3 1\nerase -1\nerase 0\nerase -2147483648\n",
"26 25\ndefragment\nerase 1\nerase -1560200883\nalloc 44\ndefragment\nalloc 75\nalloc 22\ndefragment\nerase 4\ndefragment\nalloc 57\nalloc 53\nerase 4\nerase -1639632026\nerase -2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet — the memory manager is among them. According t... |
820_D. Mister B and PR Shifts_170 | Some time ago Mister B detected a strange signal from the space, which he started to study.
After some transformation the signal turned out to be a permutation p of length n or its cyclic shift. For the further investigation Mister B need some basis, that's why he decided to choose cyclic shift of this permutation whi... | from sys import stdin
def main():
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
inf = [0] * (n + 1)
curr = 0
d = 0
for i in range(n):
curr += abs(i + 1 - a[i])
if a[i] > i + 1:
d += 1
inf[a[i] - i - 1] += 1
elif a[i] <= i +... | {
"input": [
"3\n3 2 1\n",
"3\n1 2 3\n",
"3\n2 3 1\n",
"4\n1 2 4 3\n",
"4\n2 1 4 3\n",
"10\n1 2 10 9 7 4 8 3 6 5\n",
"10\n1 7 10 6 5 2 3 8 9 4\n",
"4\n4 3 2 1\n",
"4\n2 1 3 4\n",
"10\n1 10 9 5 3 2 4 7 8 6\n",
"4\n2 3 1 4\n",
"4\n2 4 3 1\n",
"10\n1 5 10 8 4 3 9 2 7 6... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Some time ago Mister B detected a strange signal from the space, which he started to study.
After some transformation the signal turned out to be a permutation p of length n or its c... |
846_E. Chemistry in Berland_174 | Igor is a post-graduate student of chemistry faculty in Berland State University (BerSU). He needs to conduct a complicated experiment to write his thesis, but laboratory of BerSU doesn't contain all the materials required for this experiment.
Fortunately, chemical laws allow material transformations (yes, chemistry i... | import sys
# @profile
def main():
f = sys.stdin
# f = open('input.txt', 'r')
# fo = open('log.txt', 'w')
n = int(f.readline())
# b = []
# for i in range(n):
# b.append()
b = list(map(int, f.readline().strip().split(' ')))
a = list(map(int, f.readline().strip().split(' ')))
# ... | {
"input": [
"3\n3 2 1\n1 2 3\n1 1\n1 2\n",
"3\n1 2 3\n3 2 1\n1 1\n1 1\n",
"5\n27468 7465 74275 40573 40155\n112071 76270 244461 264202 132397\n1 777133331\n2 107454154\n3 652330694\n4 792720519\n",
"5\n78188 56310 79021 70050 65217\n115040 5149 128449 98357 36580\n1 451393770\n2 574046602\n3 59013078... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Igor is a post-graduate student of chemistry faculty in Berland State University (BerSU). He needs to conduct a complicated experiment to write his thesis, but laboratory of BerSU doe... |
868_A. Bark to Unlock_178 | As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters.
Mu-mu's enemy Kashtanka wants to unlock Mu-mu's p... | one=input()
num=int(input())
twos=[]
for i in range(num):
twos.append(input())
if (one in twos) or (one[::-1] in twos):
print("YES")
else:
flag1,flag2=False,False
for i in range(num):
if twos[i][0]==one[1]:
flag1=True
if twos[i][1]==one[0]:
flag2=True
if(flag1 and flag2):
print("YES"... | {
"input": [
"ah\n1\nha\n",
"ya\n4\nah\noy\nto\nha\n",
"hp\n2\nht\ntp\n",
"ab\n2\nbb\nbc\n",
"bc\n1\nab\n",
"th\n1\nth\n",
"bn\n100\ndf\nyb\nze\nml\nyr\nof\nnw\nfm\ndw\nlv\nzr\nhu\nzt\nlw\nld\nmo\nxz\ntp\nmr\nou\nme\npx\nvp\nes\nxi\nnr\nbx\nqc\ngm\njs\nkn\ntw\nrq\nkz\nuc\nvc\nqr\nab\nna\nr... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the passwo... |
893_D. Credit Card_182 | Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card.
She starts with 0 money on her account.
In the evening of i-th day a transaction ai occurs. If ai > 0, then ai bourles are deposited to Luba's account. If ai < 0, then ai bourles are withdrawn. And if ai = 0, ... | #Bhargey Mehta (Sophomore)
#DA-IICT, Gandhinagar
import sys, math, queue, bisect
#sys.stdin = open("input.txt", "r")
MOD = 10**9+7
sys.setrecursionlimit(1000000)
n, d = map(int, input().split())
a = list(map(int, input().split()))
p = [0 for i in range(n)]
for i in range(n):
p[i] = p[i-1]+a[i]
mx = [-1 for i in ra... | {
"input": [
"5 10\n-5 0 10 -11 0\n",
"5 10\n-1 5 0 -5 3\n",
"3 4\n-10 0 20\n",
"9 13\n6 14 19 5 -5 6 -10 20 8\n",
"8 9\n6 -1 5 -5 -8 -7 -8 -7\n",
"10 7\n-9 3 -4 -22 4 -17 0 -14 3 -2\n",
"6 2\n-2 3 0 -2 0 0\n",
"5 10\n-8 -24 0 -22 12\n",
"5 13756\n-2 -9 -10 0 10\n",
"7 3\n1 -3 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card.
She starts with 0 money on her account.
In the evening of i-th day a tra... |
915_A. Garden_186 | Luba thinks about watering her garden. The garden can be represented as a segment of length k. Luba has got n buckets, the i-th bucket allows her to water some continuous subsegment of garden of length exactly ai each hour. Luba can't water any parts of the garden that were already watered, also she can't water the gro... | def is_prime(a):
return all(a % i for i in range(2, a))
n, k = map(int, input().split())
l = [int(x) for x in input().split()]
if is_prime(k):
if k in l:
print(1)
else:
print(k)
else:
ll = []
for i in range(len(l)):
if k % l[i] == 0:
ll.append(l[i])
print(k ... | {
"input": [
"3 6\n2 3 5\n",
"6 7\n1 2 3 4 5 6\n",
"3 7\n3 2 1\n",
"4 97\n97 1 50 10\n",
"5 25\n24 5 15 25 23\n",
"3 3\n3 2 1\n",
"4 18\n3 1 1 2\n",
"5 97\n1 10 50 97 2\n",
"1 88\n1\n",
"3 18\n1 9 3\n",
"8 8\n8 7 6 5 4 3 2 1\n",
"2 1\n2 1\n",
"5 16\n8 4 2 1 7\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Luba thinks about watering her garden. The garden can be represented as a segment of length k. Luba has got n buckets, the i-th bucket allows her to water some continuous subsegment o... |
938_B. Run For Your Prize_190 | You and your friend are participating in a TV show "Run For Your Prize".
At the start of the show n prizes are located on a straight line. i-th prize is located at position ai. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these two positi... | input()
a=list(map(int,input().split()))
ans=0
for x in a:
z=min(x-1,1000000-x)
ans=max(z,ans)
print(ans)
| {
"input": [
"2\n2 999995\n",
"3\n2 3 9\n",
"3\n500000 500001 500002\n",
"1\n505050\n",
"2\n999998 999999\n",
"2\n500000 500001\n",
"1\n999995\n",
"1\n753572\n",
"2\n2 999999\n",
"1\n999998\n",
"4\n2 3 4 5\n",
"1\n500002\n",
"2\n100 999900\n",
"1\n500001\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You and your friend are participating in a TV show "Run For Your Prize".
At the start of the show n prizes are located on a straight line. i-th prize is located at position ai. Posit... |
963_B. Destruction of a Tree_193 | You are given a tree (a graph with n vertices and n - 1 edges in which it's possible to reach any vertex from any other vertex using only its edges).
A vertex can be destroyed if this vertex has even degree. If you destroy a vertex, all edges connected to it are also deleted.
Destroy all vertices in the given tree or... | from collections import defaultdict,deque
import sys
import bisect
import math
input=sys.stdin.readline
mod=1000000007
def bfs(root,count):
q=deque([root])
vis.add(root)
while q:
vertex=q.popleft()
for child in graph[vertex]:
if ans[child]==0:
ans[child]=count+1
... | {
"input": [
"5\n0 1 2 1 2\n",
"4\n0 1 2 3\n",
"21\n11 19 4 19 6 0 13 7 6 2 5 3 16 10 1 9 15 21 9 21 2\n",
"100\n57 85 27 81 41 27 73 10 73 95 91 90 89 41 86 44 6 20 9 13 46 73 56 19 37 32 40 42 79 76 96 5 6 8 76 52 14 86 33 69 100 95 58 87 43 47 17 39 48 28 77 65 100 100 41 39 87 5 61 67 94 64 61 88 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a tree (a graph with n vertices and n - 1 edges in which it's possible to reach any vertex from any other vertex using only its edges).
A vertex can be destroyed if thi... |
990_E. Post Lamps_197 | Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has n positions to install lamps, they correspond to the integer numbers from 0 to n - 1 on the OX axis. However, some positions are blocked an... | import sys
from array import array
n, m, k = map(int, input().split())
block = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
if block and block[0] == 0:
print(-1)
exit()
prev = array('i', list(range(n)))
for x in block:
prev[x] = -1
for i in range(1, n):
if prev[i] == -1:... | {
"input": [
"5 1 5\n0\n3 3 3 3 3\n",
"4 3 4\n1 2 3\n1 10 100 1000\n",
"7 4 3\n2 4 5 6\n3 14 15\n",
"6 2 3\n1 3\n1 2 3\n",
"3 1 2\n2\n1 1\n",
"3 1 2\n1\n8 61\n",
"3 0 3\n\n334 500 1001\n",
"20 16 16\n1 2 3 4 5 6 8 9 10 11 13 14 15 16 18 19\n2 1 1 1 1 1 3 3 2 2 1 3 3 3 3 2\n",
"1 1 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has n ... |
p02613 AtCoder Beginner Contest 173 - Judge Status Summary_211 | Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A.
The problem has N test cases.
For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`,... | n=int(input())
S = []
for i in range(n):
S.append(input())
for t in ["AC","WA","TLE","RE"]:
print(f"{t} x {S.count(t)}") | {
"input": [
"6\nAC\nTLE\nAC\nAC\nWA\nTLE",
"10\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC"
],
"output": [
"AC x 3\nWA x 1\nTLE x 2\nRE x 0",
"AC x 10\nWA x 0\nTLE x 0\nRE x 0"
]
} | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A.
The problem has N test cases.
For each test case i (1\leq i \leq ... |
p02744 Panasonic Programming Contest 2020 - String Equivalence_215 | In this problem, we only consider strings consisting of lowercase English letters.
Strings s and t are said to be isomorphic when the following conditions are satisfied:
* |s| = |t| holds.
* For every pair i, j, one of the following holds:
* s_i = s_j and t_i = t_j.
* s_i \neq s_j and t_i \neq t_j.
For example, `a... | a='a'
exec('a=[s+chr(c)for s in a for c in range(97,ord(max(s))+2)];'*~-int(input()))
print(*a) | {
"input": [
"1",
"2",
"4",
"6",
"3",
"7",
"5",
"8",
"4",
"3",
"5",
"6",
"8",
"7"
],
"output": [
"a",
"aa\nab",
"aaaa\naaab\naaba\naabb\naabc\nabaa\nabab\nabac\nabba\nabbb\nabbc\nabca\nabcb\nabcc\nabcd\n",
"aaaaaa\naaaaab\naaaaba\naaaabb\naaa... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In this problem, we only consider strings consisting of lowercase English letters.
Strings s and t are said to be isomorphic when the following conditions are satisfied:
* |s| = |t|... |
p02879 AtCoder Beginner Contest 144 - 9x9_219 | Having learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together. He cannot do any other calculation.
Given are two integers A and B.
If Takahashi can calculate A \times B, print the result; if he cannot, print `-1` instead.
Constraints
* 1 \leq A \leq 20
* 1 \leq B ... | a,b = map(int,input().split())
print(a*b) if(a<=9 and b<=9) else print(-1)
| {
"input": [
"2 5",
"9 9",
"5 10",
"2 8",
"9 5",
"7 10",
"3 8",
"9 8",
"7 7",
"6 8",
"7 9",
"7 8",
"7 3",
"7 2",
"9 2",
"9 4",
"9 6",
"5 6",
"2 6",
"2 2",
"8 5",
"5 1",
"4 8",
"3 9",
"2 3",
"2 4",
"2 1",
"5... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Having learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together. He cannot do any other calculation.
Given are two integers A and B.... |
p03013 AtCoder Beginner Contest 129 - Typical Stairs_223 | There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step. He can climb up one or two steps at a time.
However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are broken, so it is dangerous to set foot on those steps.
How many are there to climb ... | n,m = map(int,input().split())
a_list = [int(input()) for _ in range(m)]
dp = [1]*(n+1)
for a in a_list:
dp[a] = 0
for i in range(2,n+1):
if dp[i] != 0:
dp[i] = dp[i-1] + dp[i-2]
print(dp[n]%(10**9+7)) | {
"input": [
"100 5\n1\n23\n45\n67\n89",
"10 2\n4\n5",
"6 1\n3",
"100 5\n1\n23\n45\n47\n89",
"10 2\n4\n1",
"4 1\n3",
"100 3\n1\n23\n45\n47\n89",
"100 0\n1\n23\n45\n47\n89",
"10 2\n3\n2",
"101 0\n0\n35\n44\n58\n89",
"101 5\n1\n23\n45\n67\n89",
"6 1\n1",
"100 5\n1\n23... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step. He can climb up one or two steps at a time.
However, the treads of ... |
p03153 KEYENCE Programming Contest 2019 - Connecting Cities_227 | There are N cities in Republic of AtCoder. The size of the i-th city is A_{i}. Takahashi would like to build N-1 bidirectional roads connecting two cities so that any city can be reached from any other city by using these roads.
Assume that the cost of building a road connecting the i-th city and the j-th city is |i-j... | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from heapq import heappush, heappop, heapify
from collections import defaultdict
"""
・最小値のある場所を調べる。左右にまたがる辺は結ばない。
・最小値の両隣は必ず最小値と結ぶ。
・結んだあと1点に縮約していく。
"""
N,D,*A = map(int,read().split())
A = [0] + A + ... | {
"input": [
"3 1\n1 100 1",
"12 5\n43 94 27 3 69 99 56 25 8 15 46 8",
"3 1000\n1 100 1",
"6 14\n25 171 7 1 17 162",
"3 1\n2 100 1",
"12 5\n43 94 27 3 69 99 56 25 15 15 46 8",
"3 1000\n1 101 1",
"6 24\n25 171 7 1 17 162",
"3 1\n0 100 1",
"12 5\n43 94 27 3 69 99 56 25 27 15 46 8... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are N cities in Republic of AtCoder. The size of the i-th city is A_{i}. Takahashi would like to build N-1 bidirectional roads connecting two cities so that any city can be reac... |
p03297 AtCoder Grand Contest 026 - rng_10s_231 | Ringo Mart, a convenience store, sells apple juice.
On the opening day of Ringo Mart, there were A cans of juice in stock in the morning. Snuke buys B cans of juice here every day in the daytime. Then, the manager checks the number of cans of juice remaining in stock every night. If there are C or less cans, D new can... | def main():
import math
def gcd(a, b):
while b:
a, b = b, a % b
return a
N = int(input())
ABCD = [list(map(int, input().split())) for i in range(N)]
for A,B,C,D in ABCD:
# 在庫が買う本数以下 or 在庫追加が買う本数以下
if A < B or D < B:
print("No")
con... | {
"input": [
"24\n1 2 3 4\n1 2 4 3\n1 3 2 4\n1 3 4 2\n1 4 2 3\n1 4 3 2\n2 1 3 4\n2 1 4 3\n2 3 1 4\n2 3 4 1\n2 4 1 3\n2 4 3 1\n3 1 2 4\n3 1 4 2\n3 2 1 4\n3 2 4 1\n3 4 1 2\n3 4 2 1\n4 1 2 3\n4 1 3 2\n4 2 1 3\n4 2 3 1\n4 3 1 2\n4 3 2 1",
"14\n9 7 5 9\n9 7 6 9\n14 10 7 12\n14 10 8 12\n14 10 9 12\n14 10 7 11\n14 1... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Ringo Mart, a convenience store, sells apple juice.
On the opening day of Ringo Mart, there were A cans of juice in stock in the morning. Snuke buys B cans of juice here every day in... |
p03455 AtCoder Beginner Contest 086 - Product_235 | AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
Constraints
* 1 ≤ a,b ≤ 10000
* a and b are integers.
Input
Input is given from Standard Input in the following format:
a b
Output
If the product is odd, print `Odd`; if it is even, print `Even`.
E... | print("Odd" if sum([int(i) % 2 for i in input().split()])==2 else "Even") | {
"input": [
"3 4",
"1 21",
"4 4",
"1 15",
"2 4",
"2 15",
"3 0",
"2 26",
"3 -1",
"2 32",
"0 -1",
"1 32",
"0 -2",
"1 17",
"-1 -2",
"0 17",
"-2 -2",
"0 15",
"-2 -1",
"0 0",
"-4 -1",
"0 1",
"-6 -1",
"0 2",
"-6 0",
"1 ... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
Constraints
* 1 ≤ a,b ≤ 10000
* a and b are integers.
Input
Input ... |
p03616 AtCoder Regular Contest 082 - Sandglass_239 | We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contain some amount of sand. When we put the sandglass, either bulb A or B lies on top of the other and becomes the upper bulb. The other bulb becomes the lower bulb.
The sand drops from the upper bulb to the lower bulb at a rate of 1 gram per... | X=int(input())
K=int(input())
r=list(map(int,input().split()))
Q=int(input())
p=[tuple(map(int,input().split())) for i in range(Q)]
N=Q
L=0
R=Q-1
start=0
sign="-"
# N: 処理する区間の長さ
N0 = 2**(N-1).bit_length()
data = [0]*(2*N0)
INF = 0
# 区間[l, r+1)の値をvに書き換える
# vは(t, value)という値にする (新しい値ほどtは大きくなる)
def update(l, r, v):
... | {
"input": [
"100\n5\n48 141 231 314 425\n7\n0 19\n50 98\n143 30\n231 55\n342 0\n365 100\n600 10",
"180\n3\n60 120 180\n3\n30 90\n61 1\n180 180",
"100\n1\n100000\n4\n0 100\n90 100\n100 100\n101 100",
"100\n5\n48 141 231 554 425\n7\n0 19\n50 98\n143 30\n231 55\n342 0\n365 100\n600 10",
"180\n3\n60 ... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contain some amount of sand. When we put the sandglass, either bulb A or B lies on top of the other and bec... |
p03774 AtCoder Beginner Contest 057 - Checkpoints_243 | There are N students and M checkpoints on the xy-plane.
The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j).
When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance.
T... | n,m=map(int,input().split())
p=[list(map(int, input().split())) for _ in range(n)]
c=[list(map(int, input().split())) for _ in range(m)]
for i in p:
d=[abs(i[0]-c[j][0])+abs(i[1]-c[j][1]) for j in range(len(c))]
print(d.index(min(d))+1) | {
"input": [
"3 4\n10 10\n-10 -10\n3 3\n1 2\n2 3\n3 5\n3 5",
"2 2\n2 0\n0 0\n-1 0\n1 0",
"5 5\n-100000000 -100000000\n-100000000 100000000\n100000000 -100000000\n100000000 100000000\n0 0\n0 0\n100000000 100000000\n100000000 -100000000\n-100000000 100000000\n-100000000 -100000000",
"3 4\n10 10\n-10 -10... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are N students and M checkpoints on the xy-plane.
The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j ... |
p03943 AtCoder Beginner Contest 047 - Fighting over Candies_247 | Two students of AtCoder Kindergarten are fighting over candy packs.
There are three candy packs, each of which contains a, b, and c candies, respectively.
Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.
Not... | l=sorted(list(map(int,input().split())))
print("Yes" if l[0]+l[1]==l[2] else "No") | {
"input": [
"56 25 31",
"10 30 20",
"30 30 100",
"106 25 31",
"4 24 20",
"10 29 20",
"30 47 100",
"8 25 31",
"4 29 20",
"30 26 100",
"16 25 31",
"30 16 100",
"16 16 31",
"4 45 20",
"43 16 100",
"16 16 42",
"4 45 8",
"6 16 100",
"16 2 42",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Two students of AtCoder Kindergarten are fighting over candy packs.
There are three candy packs, each of which contains a, b, and c candies, respectively.
Teacher Evi is trying to d... |
p00035 Is it Convex?_251 | 4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YES if there is no dent in the quadrangle $ ABCD $ with the coordinates as the vertices, and NO if there is a dent.
A quadrangle with a de... | def gai(a,b,c,d):
S = a*d - b*c
return(S)
while True:
try:
x1,y1,x2,y2,x3,y3,xp,yp = map(float,input().split(","))
A1,A2,B1,B2,C1,C2,D1,D2 = x1,y1,x2,y2,x3,y3,xp,yp
if gai(x1 - x2,y1 - y2,x1 - xp,y1 - yp) < 0 and gai(x2 - x3,y2 - y3,x2 - xp,y2 - yp) < 0 and gai(x3 - x1,y3 -... | {
"input": [
"0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0\n0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0",
"0.0,0.0,1.0,0.0,1.0,1.0,0.0,0.1\n0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0",
"1.0,0.0,0.1,0.1,0.0,0.1,0.0,0.0\n0.3,0.1,0.1,1.1,0.0,0.3,0.0,0.0",
"1.0,0.0,0.2,0.1,0.0,0.1,0.0,1.0\n0.3,0.0,0.1,0.1,0.0,0.3,0.0,0.0",
"1.0,0.0,0.1,... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YE... |
p00167 Bubble Sort_255 | Sorting algorithms for sorting data are basic algorithms indispensable in computer science. For example, as shown in the figure below, the operation of "sorting the elements of an array of integer values in ascending order" is alignment.
<image>
Many alignment algorithms have been devised, but one of the basic alg... | def bubble_sort(n):
arr = [int(input()) for _ in range(n)]
cnt = 0
for i in range(n):
for j in range(n-1, i, -1):
if arr[j] < arr[j-1]:
arr[j], arr[j-1] = arr[j-1], arr[j]
cnt += 1
return cnt
while True:
n = int(input())
if n == 0: break
p... | {
"input": [
"5\n5\n3\n2\n1\n4\n6\n1\n2\n3\n4\n5\n6\n3\n3\n2\n1\n0",
"5\n5\n3\n2\n1\n7\n6\n1\n2\n3\n4\n5\n6\n3\n3\n2\n1\n0",
"5\n5\n3\n2\n1\n7\n6\n1\n2\n3\n4\n0\n6\n3\n3\n2\n1\n0",
"5\n5\n3\n2\n1\n4\n6\n1\n2\n2\n4\n5\n6\n3\n3\n2\n1\n0",
"5\n5\n3\n2\n1\n7\n6\n1\n2\n3\n4\n5\n6\n3\n3\n3\n1\n0",
"... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Sorting algorithms for sorting data are basic algorithms indispensable in computer science. For example, as shown in the figure below, the operation of "sorting the elements of an arr... |
p00323 Metal Recycling_258 | PCK, which recycles Aizu's precious metal, Aizunium, has a network all over the country and collects Aizunium with many collection vehicles. This company standardizes the unit of weight and number of lumps for efficient processing.
A unit called "bokko" is used for the weight of the lump. x Bocco's Aidunium weighs 2 x... | n = int(input())
size = 200100
total = [0 for _ in range(size)]
for _ in range(n):
s = sum(map(int, input().split()))
total[s] += 1
for i in range(size - 1):
if total[i] % 2:
print(i, 0)
total[i + 1] += total[i] // 2
| {
"input": [
"1\n100000 2",
"3\n2 1\n1 3\n2 2",
"1\n100010 2",
"3\n2 1\n1 3\n2 0",
"1\n100010 3",
"3\n2 1\n1 3\n2 1",
"1\n100011 3",
"3\n2 1\n1 5\n2 2",
"1\n000011 3",
"3\n2 1\n1 5\n3 2",
"1\n000011 1",
"3\n3 1\n1 5\n3 2",
"3\n3 1\n1 5\n2 2",
"1\n100111 1",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
PCK, which recycles Aizu's precious metal, Aizunium, has a network all over the country and collects Aizunium with many collection vehicles. This company standardizes the unit of weig... |
p00822 Weather Forecast_263 | You are the God of Wind.
By moving a big cloud around, you can decide the weather: it invariably rains under the cloud, and the sun shines everywhere else.
But you are a benign God: your goal is to give enough rain to every field in the countryside, and sun to markets and festivals. Small humans, in their poor vocabu... | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.... | {
"input": [
"1\n0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0\n7\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n1 0 0 0 0 0 1 0 0 0 0 1 1 0 0 1\n0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 1\n0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0\n0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0\n1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1\n0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0\n7\n0 0 0 0 0 0 0 0 1 0 0 0 0 0... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are the God of Wind.
By moving a big cloud around, you can decide the weather: it invariably rains under the cloud, and the sun shines everywhere else.
But you are a benign God:... |
p01086 Short Phrase_268 | Short Phrase
A Short Phrase (aka. Tanku) is a fixed verse, inspired by Japanese poetry Tanka and Haiku. It is a sequence of words, each consisting of lowercase letters 'a' to 'z', and must satisfy the following condition:
> (The Condition for a Short Phrase)
> The sequence of words can be divided into five sections ... | tanku = [5, 7, 5, 7, 7]
while True:
n = int(input())
if n==0:
break
w = [len(input()) for i in range(n)]
ans = 0
for i in range(n):
sum = 0
k = 0
for j in range(i, n):
sum += w[j]
if sum == tanku[k]:
sum = 0
k += 1
if k==5:
ans = i+1
brea... | {
"input": [
"9\ndo\nthe\nbest\nand\nenjoy\ntoday\nat\nacm\nicpc\n14\noh\nyes\nby\nfar\nit\nis\nwow\nso\nbad\nto\nme\nyou\nknow\nhey\n15\nabcde\nfghijkl\nmnopq\nrstuvwx\nyzz\nabcde\nfghijkl\nmnopq\nrstuvwx\nyz\nabcde\nfghijkl\nmnopq\nrstuvwx\nyz\n0",
"9\ndo\nhte\nbest\nand\nenjoy\ntoday\nat\nacm\nicpc\n14\noh... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Short Phrase
A Short Phrase (aka. Tanku) is a fixed verse, inspired by Japanese poetry Tanka and Haiku. It is a sequence of words, each consisting of lowercase letters 'a' to 'z', an... |
p01356 Nearest Station_272 | I have n tickets for a train with a rabbit. Each ticket is numbered from 0 to n − 1, and you can use the k ticket to go to p⋅ak + q⋅bk station.
Rabbit wants to go to the all-you-can-eat carrot shop at the station m station ahead of the current station, but wants to walk as short as possible. The stations are lined up ... | def solve():
n,m,a,b,p,q = map(int,input().split())
if a==1 and b==1:
if (p+q)*n <= m:
return m - (p+q)*n
else:
k = m//(p+q)
return min(m-k*(p+q),(k+1)*(p+q)-m)
else:
ans = m
for i in range(min(n-1,40),-1,-1):
f = p*(a**i) + q*(... | {
"input": [
"6 1 2 3 4 5",
"6 200 2 3 4 5",
"6 1 2 3 4 7",
"6 106 2 3 4 5",
"6 2 2 3 4 7",
"6 159 2 3 4 5",
"6 200 2 3 8 8",
"6 159 2 3 3 5",
"6 3 1 3 4 8",
"22 144 2 3 3 5",
"17 144 2 3 6 5",
"9 5 1 3 15 9",
"17 22 2 3 6 7",
"6 373 2 3 4 5",
"6 200 2 4 8 5... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
I have n tickets for a train with a rabbit. Each ticket is numbered from 0 to n − 1, and you can use the k ticket to go to p⋅ak + q⋅bk station.
Rabbit wants to go to the all-you-can-... |
p01538 Kakezan_276 | Taro is an elementary school student who has just learned multiplication. Somehow, he likes multiplication, so when he sees numbers, he wants to multiply. He seems to like to do the following for integers greater than or equal to 0. (Processing flow)
* Procedure 1. If a certain integer n greater than or equal to 0 is ... | "かけざん"
"最大のものを取得して、一桁になるまでに操作を行う回数を答える"
def kakezan(n):
ret = 0
str_n = str(n)
digit_amount = len(str_n)
for i in range(digit_amount-1):
# print(str_n[:i+1])
# print(str_n[i+1:])
# print("")
ret = max(ret, int(str_n[:i+1])*int(str_n[i+1:]))
return ret
Q = int(inp... | {
"input": [
"2\n999999\n1000000",
"3\n9\n99\n123",
"2\n999999\n1000100",
"3\n9\n99\n238",
"2\n999999\n1010100",
"3\n9\n99\n39",
"2\n999999\n1010110",
"3\n16\n120\n59",
"3\n16\n127\n59",
"3\n16\n127\n21",
"3\n16\n127\n5",
"3\n3\n127\n5",
"3\n0\n42\n4",
"3\n0\n37... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Taro is an elementary school student who has just learned multiplication. Somehow, he likes multiplication, so when he sees numbers, he wants to multiply. He seems to like to do the f... |
p01694 Step Aerobics_280 | Step up and down
Kazuki, commonly known as Kerr, who attends JAG University, was invited by your friend this summer to participate in the ICPC (International Collegiate Potchari Contest). ICPC is a sports contest and requires a high degree of athletic ability. However, Mr. Kerr was always in front of the computer, and... | while True:
N = int(input())
if N == 0:
break
a = input()
b = a.split()
x = 0
for i in range(N//2):
if b[2 * i] == 'lu' and b[(2 * i)+1] == 'ru':
x += 1
if b[2 * i] == 'ru' and b[(2 * i)+1] == 'lu':
x += 1
if b[2 * i] == 'ld' and b[(2 * ... | {
"input": [
"4\nlu ru ld rd\n4\nlu ld lu ru\n1\nlu\n10\nru lu ld rd ru rd ru lu rd ld\n0",
"4\nlu ru ld rd\n4\nlu ld lu ru\n0\nlu\n10\nru lu ld rd ru rd ru lu rd ld\n0",
"4\nlu ru ld rd\n0\nlu ld lu ru\n0\nul\n10\nvr lu ld rd rv rd ru lu rc kd\n0",
"4\nlu ru ld rd\n4\nlu ld lu ru\n0\nul\n10\nru lu ld... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Step up and down
Kazuki, commonly known as Kerr, who attends JAG University, was invited by your friend this summer to participate in the ICPC (International Collegiate Potchari Cont... |
p01974 Pigeonhole principle_284 | problem
Given $ N $ different natural numbers $ a_i $. I decided to make a pair by choosing a different natural number from the given natural numbers. Output one pair that can be created with a value difference that is a multiple of $ N -1 $.
It should be noted that such a pair always exists.
Example
Input
5
1... | N = int(input())
a = [int(x) for x in input().split()]
x, y = -1, -1
for i in range(N) :
for j in range(N) :
if i != j and abs(a[i] - a[j]) % (N - 1) == 0 :
x, y = i, j
print(a[x], a[y])
| {
"input": [
"5\n1 2 4 7 10",
"5\n2 2 4 7 10",
"5\n1 2 22 7 0",
"5\n1 2 4 3 10",
"5\n0 2 3 7 1",
"5\n0 2 1 7 1",
"5\n1 2 4 3 15",
"5\n3 2 6 5 24",
"5\n0 2 0 7 1",
"5\n0 2 7 13 24",
"5\n-1 2 3 7 13",
"5\n4 4 22 7 24",
"5\n2 3 30 7 0",
"5\n1 2 4 11 20",
"5\n4 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
problem
Given $ N $ different natural numbers $ a_i $. I decided to make a pair by choosing a different natural number from the given natural numbers. Output one pair that can be cre... |
p02260 Selection Sort_289 | Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:
SelectionSort(A)
1 for i = 0 to A.length-1
2 mini = i
3 for j = i to A.length-1
4 if A[j] < A[mini]
5 mini = j
6 swap A[i] and A[mini]... | n = int(input())
s = list(map(int, input().split()))
indexMin = 0
count = 0
for start in range(n):
indexMin = s[start:].index(min(s[start:])) + start
s[start], s[indexMin] = s[indexMin], s[start]
if start != indexMin:
count+=1
print(*s)
print(count)
| {
"input": [
"6\n5 2 4 6 1 3",
"6\n5 6 4 2 1 3",
"6\n5 2 4 6 1 0",
"6\n5 6 4 4 1 3",
"6\n6 2 4 6 1 0",
"6\n5 6 4 4 1 2",
"6\n6 2 4 6 0 0",
"6\n5 6 4 3 1 2",
"6\n6 2 8 6 0 0",
"6\n5 6 4 2 1 2",
"6\n6 4 8 6 0 0",
"6\n9 6 4 2 1 3",
"6\n6 4 8 6 0 -1",
"6\n9 6 2 2 1 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:
SelectionSort(A)
1 for i = 0 ... |
p02408 Finding Missing Cards_293 | Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers).
The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
Note
解説
Input
In the first line, the number of cards n (n ≤ 52) is given.
In the following n line... | n=int(input())
cs = [ (s,k) for s in ['S','H','C','D'] for k in range(1,14) ]
for _ in range(n):
s,k=input().split()
cs.remove((s,int(k)))
for (s, k) in cs:
print(s, k) | {
"input": [
"47\nS 10\nS 11\nS 12\nS 13\nH 1\nH 2\nS 6\nS 7\nS 8\nS 9\nH 6\nH 8\nH 9\nH 10\nH 11\nH 4\nH 5\nS 2\nS 3\nS 4\nS 5\nH 12\nH 13\nC 1\nC 2\nD 1\nD 2\nD 3\nD 4\nD 5\nD 6\nD 7\nC 3\nC 4\nC 5\nC 6\nC 7\nC 8\nC 9\nC 10\nC 11\nC 13\nD 9\nD 10\nD 11\nD 12\nD 13",
"47\nS 10\nS 11\nS 12\nS 13\nH 1\nH 2\nS ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers).
The 52 cards include 13 ranks of each of the four suits:... |
101_C. Vectors_303 | At a geometry lesson Gerald was given a task: to get vector B out of vector A. Besides, the teacher permitted him to perform the following operations with vector А:
* Turn the vector by 90 degrees clockwise.
* Add to the vector a certain vector C.
Operations could be performed in any order any number of times.
... | import math
def ok(xa, ya):
x, y = xb - xa, yb - ya
d = math.gcd(abs(xc), abs(yc))
if xc == 0 and yc == 0:
return x == 0 and y == 0
if xc == 0:
return x % yc == 0 and y % yc == 0
if yc == 0:
return x % xc == 0 and y % xc == 0
if (x % d != 0) or (y % d != 0):
retu... | {
"input": [
"0 0\n1 1\n1 1\n",
"0 0\n1 1\n0 1\n",
"0 0\n1 1\n2 2\n",
"3 1\n-2 3\n-2 -2\n",
"-8916 9282\n2666 2344\n9109 -2730\n",
"0 45\n42 -47\n-51 -82\n",
"45 6\n65 5\n0 5\n",
"3 4\n-4 3\n1 7\n",
"-75629161 -68114618\n23285096 90997125\n84795646 72358903\n",
"2 3\n2 3\n0 0\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
At a geometry lesson Gerald was given a task: to get vector B out of vector A. Besides, the teacher permitted him to perform the following operations with vector А:
* Turn the vect... |
1043_A. Elections_307 | Awruk is taking part in elections in his school. It is the final round. He has only one opponent — Elodreip. The are n students in the school. Each student has exactly k votes and is obligated to use all of them. So Awruk knows that if a person gives a_i votes for Elodreip, than he will get exactly k - a_i votes from t... | import math
n = int(input())
l= list(map(int,input().split()))
s = 2*sum(l)
z= s/n
p = max(l)
an = int(z+1)
print(max(p,an)) | {
"input": [
"5\n2 2 3 2 2\n",
"5\n1 1 1 5 1\n",
"3\n1 2 6\n",
"10\n7 7 7 7 7 7 7 7 7 7\n",
"76\n13 13 5 6 20 20 6 1 18 18 13 15 20 3 9 11 3 11 3 8 12 15 2 4 16 17 8 11 15 6 6 5 3 12 19 15 17 8 5 20 12 6 9 7 20 15 8 7 5 17 9 12 12 17 12 16 2 6 16 16 17 18 6 7 19 13 6 3 8 16 13 7 1 14 11 9\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Awruk is taking part in elections in his school. It is the final round. He has only one opponent — Elodreip. The are n students in the school. Each student has exactly k votes and is ... |
1107_D. Compression_315 | You are given a binary matrix A of size n × n. Let's denote an x-compression of the given matrix as a matrix B of size n/x × n/x such that for every i ∈ [1, n], j ∈ [1, n] the condition A[i][j] = B[⌈ i/x ⌉][⌈ j/x ⌉] is met.
Obviously, x-compression is possible only if x divides n, but this condition is not enough. For... | # ---------------------------iye ha aam zindegi---------------------------------------------
import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
mod = 10 ** 9 + 7
mod1 = 998244353
# ------------------------------warmup----------------------------
impor... | {
"input": [
"8\nE7\nE7\nE7\n00\n00\nE7\nE7\nE7\n",
"4\n7\nF\nF\nF\n",
"8\nFF\nFF\n00\n00\nFF\nFF\n00\n00\n",
"4\n0\n0\n0\n1\n",
"8\n33\n33\n33\n33\n33\n33\n11\n11\n",
"16\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\n",
"12\nE38\nE38\nE38... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a binary matrix A of size n × n. Let's denote an x-compression of the given matrix as a matrix B of size n/x × n/x such that for every i ∈ [1, n], j ∈ [1, n] the conditi... |
1136_D. Nastya Is Buying Lunch_319 | At the big break Nastya came to the school dining room. There are n pupils in the school, numbered from 1 to n. Unfortunately, Nastya came pretty late, so that all pupils had already stood in the queue, i.e. Nastya took the last place in the queue. Of course, it's a little bit sad for Nastya, but she is not going to de... | import sys
import math
import bisect
from math import sqrt
def input(): return sys.stdin.readline().strip()
def iinput(): return int(input())
def rinput(): return map(int, sys.stdin.readline().strip().split())
def get_list(): return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1e9)+7
n, m = ... | {
"input": [
"5 2\n3 1 5 4 2\n5 2\n5 4\n",
"3 3\n3 1 2\n1 2\n3 1\n3 2\n",
"2 1\n1 2\n1 2\n",
"10 23\n6 9 8 10 4 3 7 1 5 2\n7 2\n3 2\n2 4\n2 3\n7 5\n6 4\n10 7\n7 1\n6 8\n6 2\n8 10\n3 5\n3 1\n6 1\n10 2\n8 2\n10 1\n7 4\n10 5\n6 9\n6 5\n9 1\n10 4\n",
"2 0\n1 2\n",
"3 2\n1 2 3\n1 2\n2 1\n",
"10... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
At the big break Nastya came to the school dining room. There are n pupils in the school, numbered from 1 to n. Unfortunately, Nastya came pretty late, so that all pupils had already ... |
1155_A. Reverse a Substring_323 | You are given a string s consisting of n lowercase Latin letters.
Let's define a substring as a contiguous subsegment of a string. For example, "acab" is a substring of "abacaba" (it starts in position 3 and ends in position 6), but "aa" or "d" aren't substrings of this string. So the substring of the string s from po... | '''
Online Python Compiler.
Code, Compile, Run and Debug python program online.
Write your code in this editor and press "Run" button to execute it.
'''
def main():
n = input()
s = input()
for i in range(len(s)-1):
if s[i]>s[i+1]:
print('YES'... | {
"input": [
"7\nabacaba\n",
"6\naabcfg\n",
"6\nbabcdc\n",
"5\nbadec\n",
"3\naba\n",
"7\nbaaaccb\n",
"3\naaa\n",
"4\npara\n",
"3\nbac\n",
"7\nbdadccd\n",
"2\nba\n",
"7\nstoopid\n",
"7\nyxyzyyx\n",
"3\nacb\n",
"7\nbcbcbdc\n",
"7\nabacaba\n",
"2\naa\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a string s consisting of n lowercase Latin letters.
Let's define a substring as a contiguous subsegment of a string. For example, "acab" is a substring of "abacaba" (it... |
1176_F. Destroy it!_327 | You are playing a computer card game called Splay the Sire. Currently you are struggling to defeat the final boss of the game.
The boss battle consists of n turns. During each turn, you will get several cards. Each card has two parameters: its cost c_i and damage d_i. You may play some of your cards during each turn i... | import sys
import math
import cProfile
DEBUG = False
def log(s):
if DEBUG and False:
print(s)
def calc_dmg(num, arr):
maximum = 0
if num - len(arr) < 0:
maximum = max(arr)
return sum(arr) + maximum
if DEBUG:
sys.stdin = open('input.txt')
pr = cProfile.Profile()
pr.... | {
"input": [
"5\n3\n1 6\n1 7\n1 5\n2\n1 4\n1 3\n3\n1 10\n3 5\n2 3\n3\n1 15\n2 4\n1 10\n1\n1 100\n",
"5\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 100\n1 1\n1 1\n",
"1\n4\n1 1\n1 1\n2 2\n3 4\n",
"5\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 2\n1 1\n1 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are playing a computer card game called Splay the Sire. Currently you are struggling to defeat the final boss of the game.
The boss battle consists of n turns. During each turn, ... |
1195_D2. Submarine in the Rybinsk Sea (hard edition)_331 | This problem differs from the previous one only in the absence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n.
A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the st... | from collections import Counter
n = int(input())
a = list(map(int, input().split()))
l = [len(str(i)) for i in a]
c = Counter(l)
cl = [c[i] for i in range(1,11)]
M = 998244353
pad = lambda a, d: a%d + (a - a%d) * 10
#print(a, l, c, cl)
ans = 0
for i in a:
il = len(str(i)) # let's calculate it again to avoid zi... | {
"input": [
"3\n12 3 45\n",
"2\n123 456\n",
"20\n76 86 70 7 16 24 10 62 26 29 40 65 55 49 34 55 92 47 43 100\n",
"100\n6591 1074 3466 3728 549 5440 533 3543 1536 2967 1587 304 6326 6410 8670 6736 4482 8431 1697 9264 8338 2995 3725 1805 488 4563 4261 6025 2602 1892 9297 4359 1139 7117 1423 4834 5663 7... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This problem differs from the previous one only in the absence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n.
A team of SIS students is going to make a trip... |
1236_A. Stones_335 | Alice is playing with some stones.
Now there are three numbered heaps of stones. The first of them contains a stones, the second of them contains b stones and the third of them contains c stones.
Each time she can do one of two operations:
1. take one stone from the first heap and two stones from the second heap (... | t = int(input())
while t>0:
x, y, z = [int(i) for i in input().split()]
s = 0
f = -1
z = z//2
if y >= z:
y = y - z
s = z*2 + z
else:
s = y*2 + y
f = 1
if f == -1:
y = y//2
if x >= y:
s = s + 2*y + y
else:
... | {
"input": [
"3\n3 4 5\n1 0 5\n5 3 2\n",
"20\n9 4 8\n10 6 7\n4 6 0\n7 7 6\n3 3 10\n4 2 1\n4 4 0\n2 0 0\n8 8 7\n3 1 7\n3 10 7\n1 7 3\n7 9 1\n1 6 9\n0 9 5\n4 0 0\n2 10 0\n4 8 5\n10 0 1\n8 1 1\n",
"64\n0 0 0\n0 0 1\n0 0 2\n0 0 3\n0 1 0\n0 1 1\n0 1 2\n0 1 3\n0 2 0\n0 2 1\n0 2 2\n0 2 3\n0 3 0\n0 3 1\n0 3 2\n0 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Alice is playing with some stones.
Now there are three numbered heaps of stones. The first of them contains a stones, the second of them contains b stones and the third of them conta... |
1277_E. Two Fairs_341 | There are n cities in Berland and some pairs of them are connected by two-way roads. It is guaranteed that you can pass from any city to any other, moving along the roads. Cities are numerated from 1 to n.
Two fairs are currently taking place in Berland — they are held in two different cities a and b (1 ≤ a, b ≤ n; a ... | import sys
import threading
from collections import deque
def func():
lines = sys.stdin.readlines()
nxt = 0
t = int(lines[nxt])
nxt += 1
ans = []
for _ in range(t):
n,m,a,b = map(int, lines[nxt].split())
nxt += 1
g = [[] for _ in range(n)]
for _ in range(m):
... | {
"input": [
"3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 3\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n",
"3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 4\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n",
"3\n7 7 3 5\n1 2\n2 3\n3 4\n2 5\n5 6\n6 7\n7 5\n4 5 2 4\n1 2\n2 3\n3 4\n4 1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n cities in Berland and some pairs of them are connected by two-way roads. It is guaranteed that you can pass from any city to any other, moving along the roads. Cities are ... |
1382_A. Common Subsequence_351 | You are given two arrays of integers a_1,…,a_n and b_1,…,b_m.
Your task is to find a non-empty array c_1,…,c_k that is a subsequence of a_1,…,a_n, and also a subsequence of b_1,…,b_m. If there are multiple answers, find one of the smallest possible length. If there are still multiple of the smallest possible length, f... | #!/usr/bin/env python3
import io
import os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def get_str():
return input().decode().strip()
def rint():
return map(int, input().split())
def oint():
return int(input())
t = oint()
for _ in range(t):
n, m = rint()
a = set(rint())
b =... | {
"input": [
"5\n4 5\n10 8 6 4\n1 2 3 4 5\n1 1\n3\n3\n1 1\n3\n2\n5 3\n1000 2 2 2 3\n3 1 5\n5 5\n1 2 3 4 5\n1 2 3 4 5\n",
"1\n2 2\n1 1\n1 2\n",
"1\n1 3\n3\n1 2 3\n",
"1\n1 1\n1000\n1000\n",
"1\n2 2\n2 2\n2 2\n",
"5\n4 5\n10 8 6 4\n1 2 3 4 5\n1 1\n3\n3\n1 1\n3\n2\n5 3\n1000 2 2 2 3\n3 1 5\n5 5\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given two arrays of integers a_1,…,a_n and b_1,…,b_m.
Your task is to find a non-empty array c_1,…,c_k that is a subsequence of a_1,…,a_n, and also a subsequence of b_1,…,b_m... |
1497_D. Genius_359 | Please note the non-standard memory limit.
There are n problems numbered with integers from 1 to n. i-th problem has the complexity c_i = 2^i, tag tag_i and score s_i.
After solving the problem i it's allowed to solve problem j if and only if IQ < |c_i - c_j| and tag_i ≠ tag_j. After solving it your IQ changes and be... | def nr():return int(input())
def nrs():return [int(i) for i in input().split()]
def f(n,t,s):
d=[0]*n
for i in range(1,n):
for j in range(i-1,-1,-1):
if t[i]==t[j]:continue
sc=abs(s[i]-s[j])
d[i],d[j]=max(d[i],d[j]+sc),max(d[j],d[i]+sc)
return max(d)
for _ in range(nr()):
n=nr()
t=nrs()
s=nrs()
print(... | {
"input": [
"5\n4\n1 2 3 4\n5 10 15 20\n4\n1 2 1 2\n5 10 15 20\n4\n2 2 4 1\n2 8 19 1\n2\n1 1\n6 9\n1\n1\n666\n",
"5\n4\n1 2 3 4\n5 10 15 20\n4\n1 2 1 2\n5 10 15 20\n4\n2 2 4 1\n2 8 19 2\n2\n1 1\n6 9\n1\n1\n666\n",
"5\n4\n1 2 3 4\n5 10 15 20\n4\n1 2 2 2\n5 10 15 20\n4\n2 2 4 1\n2 8 19 2\n2\n1 1\n6 9\n1\n1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Please note the non-standard memory limit.
There are n problems numbered with integers from 1 to n. i-th problem has the complexity c_i = 2^i, tag tag_i and score s_i.
After solving... |
151_C. Win or Freeze_363 | You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer q. During a move a player should write any integer number that is a non-trivial divisor of the last written number. Then he should run this number of circl... | import sys
line = sys.stdin.readline()
N = int(line)
tmp = N
factor = []
i = 2
while i**2 <= tmp:
if tmp % i == 0:
tmp //= i
factor.append(i)
else: i += 1
if tmp != 1: factor.append(i)
if len(factor) == 2: print(2)
else:
print(1)
if len(factor) <= 1: print(0)
else: print(factor[0] * ... | {
"input": [
"1\n",
"6\n",
"30\n",
"8587340257\n",
"9\n",
"81\n",
"27\n",
"1408514752349\n",
"25\n",
"49380563\n",
"266418\n",
"319757451841\n",
"6599669076000\n",
"8\n",
"1000000000000\n",
"30971726\n",
"274875809788\n",
"64\n",
"34280152201... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer q. During a move a... |
1547_C. Pair Programming_367 | Monocarp and Polycarp are learning new programming techniques. Now they decided to try pair programming.
It's known that they have worked together on the same file for n + m minutes. Every minute exactly one of them made one change to the file. Before they started, there were already k lines written in the file.
Ever... | # -*- coding: utf-8 -*-
"""
Created on Sat Jul 10 23:15:34 2021
@author: Kevin Chang
Project: Codeforces Problem 1547C
"""
t = int(input())
for i in range(t):
shit = input()
k, n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = [... | {
"input": [
"5\n\n3 2 2\n2 0\n0 5\n\n4 3 2\n2 0 5\n0 6\n\n0 2 2\n1 0\n2 3\n\n5 4 4\n6 0 8 0\n0 7 0 9\n\n5 4 1\n8 7 8 0\n0\n",
"5\n\n3 2 2\n2 0\n0 5\n\n4 3 2\n2 0 5\n0 6\n\n0 2 2\n1 0\n2 3\n\n5 4 4\n6 0 8 0\n0 7 0 9\n\n5 4 1\n8 7 8 0\n0\n",
"5\n\n3 2 2\n2 0\n0 5\n\n4 3 2\n2 1 5\n0 6\n\n0 2 2\n1 0\n2 3\n\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Monocarp and Polycarp are learning new programming techniques. Now they decided to try pair programming.
It's known that they have worked together on the same file for n + m minutes.... |
195_A. Let's Watch Football_372 | Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will "hang up" as the size of data to watch per second will be more than the si... | from math import ceil
a,b,c = map(int,input().split())
t = (a*c - c*b)/b
print(ceil(t)) | {
"input": [
"10 3 2\n",
"13 12 1\n",
"4 1 1\n",
"993 992 991\n",
"100 1 10\n",
"960 935 994\n",
"99 8 99\n",
"60 16 1\n",
"759 10 258\n",
"24 19 9\n",
"196 169 144\n",
"1000 999 1\n",
"945 812 917\n",
"1000 100 10\n",
"500 300 300\n",
"888 777 1000\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection ... |
219_A. k-String_376 | A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string s, ... | from collections import Counter
import string
import math
import sys
def array_int():
return [int(i) for i in sys.stdin.readline().split()]
def vary(number_of_variables):
if number_of_variables==1:
return int(sys.stdin.readline())
if number_of_variables>=2:
return map(int,sys.stdin.readline(... | {
"input": [
"2\naazz\n",
"3\nabcabcabz\n",
"2\naaab\n",
"2\nbabac\n",
"2\naaaaaabbbb\n",
"1\naabaab\n",
"2\naabbbbccccccdddddddd\n",
"2\nabba\n",
"2\naaaazzzz\n",
"250\ncececececececececececececececececececececececececececececececececececececececececececececececececececececece... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a... |
242_C. King's Path_380 | The black king is standing on a chess field consisting of 109 rows and 109 columns. We will consider the rows of the field numbered with integers from 1 to 109 from top to bottom. The columns are similarly numbered with integers from 1 to 109 from left to right. We will denote a cell of the field that is located in the... | from collections import deque
x0,y0,x1,y1=list(map(int, input().split()))
n=int(input())
allowed={}
for i in range(n):
r,a,b=list(map(int,input().split()))
for j in range(a,b+1):
allowed[(r,j)]=True
visited={}
q=deque()
q.append((x0,y0))
visited[(x0,y0)]=0
dire=[(-1,0),(1,0),(0,-1),(0,1),(-1,-1),(-1,1)... | {
"input": [
"3 4 3 10\n3\n3 1 4\n4 5 9\n3 10 10\n",
"1 1 2 10\n2\n1 1 3\n2 6 10\n",
"5 7 6 11\n3\n5 3 8\n6 7 11\n5 2 5\n",
"1 1 1 2\n5\n1000000000 1 10000\n19920401 1188 5566\n1000000000 1 10000\n1 1 10000\n5 100 200\n",
"6 15 7 15\n9\n6 15 15\n7 14 14\n6 15 15\n9 14 14\n7 14 16\n6 15 15\n6 15 15... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The black king is standing on a chess field consisting of 109 rows and 109 columns. We will consider the rows of the field numbered with integers from 1 to 109 from top to bottom. The... |
268_A. Games_384 | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ... | n=int(input())
mat=[]
for i in range(n):
mat.append(list(map(int, input().rstrip().split())))
b=0
for i in range (n):
for j in range (n):
if mat[i][0]==mat[j][1]:
b=b+1
print(b) | {
"input": [
"2\n1 2\n1 2\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"3\n1 2\n2 4\n3 4\n",
"24\n9 83\n90 31\n83 3\n83 3\n21 31\n83 3\n32 31\n12 21\n31 21\n90 32\n32 21\n12 9\n12 31\n9 83\n83 12\n32 3\n32 83\n90 31\n9 32\n31 21\n83 90\n32 21\n21 3\n32 9\n",
"25\n91 57\n2 73\n54 57\n2 57\n23 57\n2 6\n5... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets ... |
290_D. Orange_388 | <image>
Input
The first line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be a letter of English alphabet, lowercase or uppercase.
The second line of the input is an integer between 0 and 26, inclusive.
Output
Output the required string.
Examples
Input
AprilFool
14... | text = input().lower()
caps = int(input())+97
for letter in text:
print(letter.upper(), end='')if letter < chr(caps) else print(letter, end='')
print() | {
"input": [
"AprilFool\n14\n",
"qH\n2\n",
"nifzlTLaeWxTD\n0\n",
"WlwbRjvrOZakKXqecEdlrCnmvXQtLKBsy\n5\n",
"LiqWMLEULRhW\n1\n",
"kGqopTbelcDUcoZgnnRYXgPCRQwSLoqeIByFWDI\n26\n",
"DuFhhnq\n4\n",
"aaaaAaaaaaaAAaaAaaAaAaaaAaaaaaAAaaAAAAAaaAaAAAAaAA\n4\n",
"VtQISIHREYaEGPustEkzJRN\n20\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
<image>
Input
The first line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be a letter of English alphabet, lowercase or uppercase.
Th... |
316_B2. EKG_392 | In the rush of modern life, people often forget how beautiful the world is. The time to enjoy those around them is so little that some even stand in queues to several rooms at the same time in the clinic, running from one queue to another.
(Cultural note: standing in huge and disorganized queues for hours is a native ... | def f(x, p):
q = []
while x:
q.append(x)
x = p[x]
return q
from collections import defaultdict
n, k = map(int, input().split())
t = list(map(int, input().split()))
p = [0] * (n + 1)
for i, j in enumerate(t, 1):
p[j] = i
p = [f(i, p) for i, j in enumerate(t, 1) if j == 0]
s = defaultdict(... | {
"input": [
"6 2\n2 3 0 5 6 0\n",
"6 2\n0 0 1 0 4 5\n",
"6 1\n2 0 4 0 6 0\n",
"4 1\n0 0 0 0\n",
"20 20\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"10 4\n0 1 4 2 7 0 10 0 5 8\n",
"10 7\n10 8 6 5 0 0 0 4 3 9\n",
"10 1\n8 7 0 2 0 10 0 0 3 5\n",
"10 7\n7 9 2 10 0 0 0 3 5 1\n",
"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In the rush of modern life, people often forget how beautiful the world is. The time to enjoy those around them is so little that some even stand in queues to several rooms at the sam... |
339_A. Helpful Maths_396 | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe... | x=input()
x=x.replace("+","")
x=sorted(x)
for i in range(1,2*len(x)-1,2):
x.insert(i,"+")
x=''.join(x)
print(x)
| {
"input": [
"2\n",
"3+2+1\n",
"1+1+3+1+3\n",
"2+2+1+1+3\n",
"3+1\n",
"1+3\n",
"2+2+1+1+1+3+1+1+3+3+2+3+1+3+1+1+3+1+1+2+2+2+2+1+2+1+2+1+1+1+3+1+3+2+3+2+3+3+1+1+1+2+3+2+1+3+1+3+2+2\n",
"2+2\n",
"1+1\n",
"2+3+3+1+2+2+2+1+1+2+1+3+2+2+3+3+2+2+3+3+3+1+1+1+3+3+3+2+1+3+2+3+2+1+1+3+3+3... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. P... |
361_C. Levko and Array Recovery_399 | Levko loves array a1, a2, ... , an, consisting of integers, very much. That is why Levko is playing with array a, performing all sorts of operations with it. Each operation Levko performs is of one of two types:
1. Increase all elements from li to ri by di. In other words, perform assignments aj = aj + di for all j ... | import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writa... | {
"input": [
"4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 8\n",
"4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 13\n",
"4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 8\n",
"1 4\n1 1 1 2\n2 1 1 6\n1 1 1 1\n2 1 1 7\n",
"2 2\n2 1 2 8\n2 1 2 7\n",
"97 29\n2 78 82 356152\n2 14 29 430177\n1 59 8... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Levko loves array a1, a2, ... , an, consisting of integers, very much. That is why Levko is playing with array a, performing all sorts of operations with it. Each operation Levko perf... |
385_A. Bear and Raspberry_403 | The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following n days. According to the bear's data, on the i-th (1 ≤ i ≤ n) day, the price for one barrel of honey is going to is xi kilos of raspberry.
Unfortunately, the b... |
n, c = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
d = l[i] - l[i + 1] - c
ans = max(ans, d)
print(ans) | {
"input": [
"6 2\n100 1 10 40 10 40\n",
"5 1\n5 10 7 3 20\n",
"3 0\n1 2 3\n",
"89 1\n50 53 97 41 68 27 53 66 93 19 11 78 46 49 38 69 96 9 43 16 1 63 95 64 96 6 34 34 45 40 19 4 53 8 11 18 95 25 50 16 64 33 97 49 23 81 63 10 30 73 76 55 7 70 9 98 6 36 75 78 3 92 85 75 40 75 55 71 9 91 15 17 47 55 44 3... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following n days. According to th... |
405_E. Graph Cutting_406 | Little Chris is participating in a graph cutting contest. He's a pro. The time has come to test his skills to the fullest.
Chris is given a simple undirected connected graph with n vertices (numbered from 1 to n) and m edges. The problem is to cut it into edge-distinct paths of length 2. Formally, Chris has to partiti... | import sys
input = sys.stdin.readline
print = sys.stdout.write
def get_input():
n, m = [int(x) for x in input().split(' ')]
graph = [[] for _ in range(n + 1)]
for _ in range(m):
c1, c2 = [int(x) for x in input().split(' ')]
graph[c1].append(c2)
graph[c2].append(c1)
if m % 2 ... | {
"input": [
"3 2\n1 2\n2 3\n",
"3 3\n1 2\n2 3\n3 1\n",
"8 12\n1 2\n2 3\n3 4\n4 1\n1 3\n2 4\n3 5\n3 6\n5 6\n6 7\n6 8\n7 8\n",
"9 12\n1 2\n2 3\n4 5\n5 6\n6 7\n7 8\n1 4\n4 7\n2 5\n5 8\n3 6\n6 9\n",
"5 4\n2 1\n3 2\n4 3\n5 4\n",
"4 4\n1 2\n2 3\n3 1\n1 4\n",
"9 8\n1 9\n2 9\n3 9\n4 9\n5 9\n6 9\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Little Chris is participating in a graph cutting contest. He's a pro. The time has come to test his skills to the fullest.
Chris is given a simple undirected connected graph with n v... |
433_A. Kitahara Haruki's Gift_410 | Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal ... | n = int(input())
a = list(input().split(' '))
a = list(int(x) for x in a)
one, two = 0, 0
for i in range(n):
if a[i] == 100:
one += 1
else:
two += 1
flag = False
if one%2 == 0 and two%2 == 0 or one > two and two % 2 == 1 and one % 2 == 0 and one >= 2 \
or one < two and two%2 == 1 and one%2 ==... | {
"input": [
"4\n100 100 100 200\n",
"3\n100 200 100\n",
"9\n100 100 100 200 100 100 200 100 200\n",
"3\n100 100 100\n",
"7\n200 200 200 100 200 200 200\n",
"100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of cours... |
478_A. Initial Bet_416 | There are five people playing a game called "Generosity". Each person gives some non-zero number of coins b as an initial bet. After all players make their bets of b coins, the following operation is repeated for several times: a coin is passed from one player to some other player.
Your task is to write a program that... | l=list(map(int,input().split()))
x=sum(l)
if(x%5==0 and x!=0):
print(int(x/5))
else:
print(-1)
| {
"input": [
"2 5 4 0 4\n",
"4 5 9 2 1\n",
"99 100 100 100 100\n",
"57 83 11 4 93\n",
"99 99 99 99 99\n",
"100 0 0 0 0\n",
"0 1 2 3 4\n",
"93 100 99 90 98\n",
"87 38 19 33 100\n",
"1 1 1 1 1\n",
"0 0 0 0 1\n",
"2 3 4 5 6\n",
"1 2 1 2 3\n",
"0 0 0 0 0\n",
"10... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are five people playing a game called "Generosity". Each person gives some non-zero number of coins b as an initial bet. After all players make their bets of b coins, the follow... |
500_C. New Year Book Reading_420 | New Year is coming, and Jaehyun decided to read many books during 2015, unlike this year. He has n books numbered by integers from 1 to n. The weight of the i-th (1 ≤ i ≤ n) book is wi.
As Jaehyun's house is not large enough to have a bookshelf, he keeps the n books by stacking them vertically. When he wants to read a... | n,m=map(int,input().split())
weight=[int(i) for i in input().split()]
order=[int(i) for i in input().split()]
stack=[]
for i in order:
if i-1 not in stack:
stack.append(i-1)
#print(stack)
ans=0
for i in order:
#i=i-1
currlift=sum(weight[i] for i in stack[0:stack.index(i-1)])
ans+=currlift
t... | {
"input": [
"3 5\n1 2 3\n1 3 2 3 1\n",
"50 50\n75 71 23 37 28 23 69 75 5 62 3 11 96 100 13 50 57 51 8 90 4 6 84 27 11 89 95 81 10 62 48 52 69 87 97 95 30 74 21 42 36 64 31 80 81 50 56 53 33 99\n26 30 5 33 35 29 6 15 36 17 32 16 14 1 29 34 22 40 12 42 38 48 39 50 13 47 18 43 10 8 49 45 11 31 21 37 46 28 20 41... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
New Year is coming, and Jaehyun decided to read many books during 2015, unlike this year. He has n books numbered by integers from 1 to n. The weight of the i-th (1 ≤ i ≤ n) book is w... |
526_A. King of Thieves_424 | In this problem you will meet the simplified model of game King of Thieves.
In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your character, avoiding traps and obstacles on your way.
<image>
An interesting feature of the game is that you can design your own levels... | #!/usr/bin/env python
# jump.py - Codeforces <!!! NNNA !!!> quiz
#
# Copyright (C) 2015 Sergey
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0... | {
"input": [
"16\n.**.*..*.***.**.\n",
"11\n.*.*...*.*.\n",
"20\n.*..*...*....*.....*\n",
"97\n****.***.***.*..**.**.*.*.***.*............*..*......*.***.**.*.***.*.***.*..*.**.*.***.**.*****.\n",
"5\n*.***\n",
"4\n****\n",
"11\n.*.*.*.*...\n",
"72\n.***.**.*.*...*****.*.*.*.*.**....**... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In this problem you will meet the simplified model of game King of Thieves.
In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your... |
551_B. ZgukistringZ_428 | Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one.
GukiZ has strings a, b, and c. He wants to obtain string k by swapping some letters in a, so that k should contain as many non-overlapping substrings equal either to b or c as possible. Substring of string x... | from collections import defaultdict
def find_max_possible_substring(a, a_char_counts, char_counts):
max_count_of_sub = len(a)
for char, count in char_counts.items():
max_count_of_sub = min(max_count_of_sub, a_char_counts[char] // char_counts[char])
return max_count_of_sub
def get_optimal_count(... | {
"input": [
"pozdravstaklenidodiri\nniste\ndobri\n",
"aaa\na\nb\n",
"abbbaaccca\nab\naca\n",
"brtakoktrosttttttttttosafasfkalsfkodfdasiofhadfhasdsajfdsafoasodsafahaihfdisoadspapsapiosapdsajdipsahdhasuirhaeuifhhfkjgosooooooooodafdfioottttafdsafaddfuiasdjfjasdo\nokat\ntako\n",
"aleksandrehteosidate... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one.
GukiZ has strings a, b, and c. He wants to obtain string k by swapping... |
578_C. Weakness and Poorness_432 | You are given a sequence of n integers a1, a2, ..., an.
Determine a real number x such that the weakness of the sequence a1 - x, a2 - x, ..., an - x is as small as possible.
The weakness of a sequence is defined as the maximum value of the poorness over all segments (contiguous subsequences) of a sequence.
The poor... | """ Python 3 compatibility tools. """
from __future__ import division, print_function
import itertools
import sys
import os
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
input = raw_input
range = xrange
filter = itertools.ifilter
map = itertools.imap
zip = itertools.izip
def is_it_local():
... | {
"input": [
"10\n1 10 2 9 3 8 4 7 5 6\n",
"4\n1 2 3 4\n",
"3\n1 2 3\n",
"10\n-405 -230 252 -393 -390 -259 97 163 81 -129\n",
"3\n10000 -10000 10000\n",
"1\n-10000\n",
"20\n-16 -23 29 44 -40 -50 -41 34 -38 30 -12 28 -44 -49 15 50 -28 38 -2 0\n",
"10\n-405 -230 252 -393 -271 -259 97 163... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a sequence of n integers a1, a2, ..., an.
Determine a real number x such that the weakness of the sequence a1 - x, a2 - x, ..., an - x is as small as possible.
The we... |
5_A. Chat Server's Outgoing Traffic_436 | Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands:
* Include a perso... | import sys
n=0
ans=0
while True:
i=sys.stdin.readline().strip()
if len(i)<=1:
break
if i[0]=="+":
n+=1
elif i[0]=="-":
n-=1
else:
ans+=(len(i.split(':')[1]))*n
print(ans) | {
"input": [
"+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate\n",
"+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate\n",
"+adabacaba\n-adabacaba\n+aca\naca:caba\n-aca\n+bacaba\n-bacaba\n+aba\n-aba\n+bad\n",
"+cab\n+abac\n-abac\n+baca\n",
"+8UjgAJ\n8UjgAJ:02hR7UBc1tqqfL\n-8Uj... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp ha... |
621_D. Rat Kwesh and Cheese_440 | Wet Shark asked Rat Kwesh to generate three positive real numbers x, y and z, from 0.1 to 200.0, inclusive. Wet Krash wants to impress Wet Shark, so all generated numbers will have exactly one digit after the decimal point.
Wet Shark knows Rat Kwesh will want a lot of cheese. So he will give the Rat an opportunity to ... | from decimal import *
getcontext().prec = 700
x, y, z = map(Decimal, input().split())
a = []
a.append((y**z * x.ln(), -1, 'x^y^z'))
a.append((z**y * x.ln(), -2, 'x^z^y'))
a.append((y *z * x.ln(), -3, '(x^y)^z'))
a.append((x**z * y.ln(), -5, 'y^x^z'))
a.append((z**x * y.ln(), -6, 'y^z^x'))
a.append((x *z * y.ln(), -7... | {
"input": [
"1.1 3.4 2.5\n",
"1.9 1.8 1.7\n",
"2.0 2.0 2.0\n",
"1.0 200.0 200.0\n",
"0.2 0.1 0.6\n",
"1.9 3.0 4.1\n",
"51.8 51.8 7.1\n",
"113.9 125.2 88.8\n",
"1.9 4.8 3.9\n",
"2.2 148.1 138.0\n",
"1.0 200.0 1.0\n",
"1.7 4.5 4.2\n",
"0.2 0.6 0.3\n",
"200.0 200.... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Wet Shark asked Rat Kwesh to generate three positive real numbers x, y and z, from 0.1 to 200.0, inclusive. Wet Krash wants to impress Wet Shark, so all generated numbers will have ex... |
643_B. Bear and Two Paths_444 | Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities.
Bear Limak was once in a city a and he wanted to go to a city b. There was no direct connection so he decided to take a long walk, visiting ea... | import io,os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
n, k = map(int, input().split())
a, b, c, d = map(int, input().split())
if k < n + 1 or n == 4:
print("-1")
exit(0)
l = [_ for _ in range(1, n + 1)]
l.remove(a)
l.remove(b)
l.remove(c)
l.remove(d)
print(a, end = ' ')
print(c, end = ' ')
fo... | {
"input": [
"1000 999\n10 20 30 40\n",
"7 11\n2 4 7 3\n",
"1000 1001\n217 636 713 516\n",
"1000 1998\n833 681 19 233\n",
"4 5\n1 3 4 2\n",
"6 7\n3 1 2 4\n",
"5 7\n4 3 2 1\n",
"55 56\n53 54 52 55\n",
"1000 1000\n89 983 751 38\n",
"1000 1002\n641 480 458 289\n",
"6 5\n3 2 5 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities.
Bear ... |
670_B. Game of Robots_448 | In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. Aft... | n, k = input().split(' ')
n = int(n)
k = int(k)
d = input().split(' ')
i = 0
while True:
i += 1
p = int((i) * (i+1) / 2)
if k <= p :
print(d[k-(p-i)-1])
break | {
"input": [
"4 5\n10 4 18 3\n",
"2 2\n1 2\n",
"4 9\n5 1000000000 999999999 12\n",
"4 6\n5 1000000000 999999999 12\n",
"1 1\n4\n",
"3 5\n4 5 6\n",
"3 4\n4 5 6\n",
"3 6\n4 5 6\n",
"4 2\n5 1000000000 999999999 12\n",
"2 3\n6 7\n",
"2 1\n5 1\n",
"4 1\n5 1000000000 99999999... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.
At some moment, robots decided to play the... |
691_D. Swaps in Permutation_452 | You are given a permutation of the numbers 1, 2, ..., n and m pairs of positions (aj, bj).
At each step you can choose a pair from the given positions and swap the numbers in that positions. What is the lexicographically maximal permutation one can get?
Let p and q be two permutations of the numbers 1, 2, ..., n. p i... | # by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO, IOBase
def solve(n,p,path):
se, x, fin = [1] * (n + 1), 1, [0] * n
while x != len(se):
se[x], jj, curr, inde, vals = 0, 0, [x], [x - 1], [p[x - 1]]
while jj != len(curr):
zz = curr[... | {
"input": [
"9 6\n1 2 3 4 5 6 7 8 9\n1 4\n4 7\n2 5\n5 8\n3 6\n6 9\n",
"3 10\n2 3 1\n1 1\n3 3\n3 3\n3 2\n1 1\n2 2\n3 1\n1 3\n2 1\n3 3\n",
"7 20\n6 2 5 7 3 1 4\n7 7\n1 1\n2 2\n6 1\n4 4\n2 2\n2 2\n6 6\n3 5\n7 4\n1 6\n4 4\n6 1\n1 1\n3 3\n5 3\n3 5\n5 3\n2 2\n4 4\n",
"4 20\n4 2 3 1\n2 2\n1 4\n2 2\n1 1\n3 3... | 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 the numbers 1, 2, ..., n and m pairs of positions (aj, bj).
At each step you can choose a pair from the given positions and swap the numbers in that po... |
716_D. Complete The Graph_455 | ZS the Coder has drawn an undirected graph of n vertices numbered from 0 to n - 1 and m edges between them. Each edge of the graph is weighted, each weight is a positive integer.
The next day, ZS the Coder realized that some of the weights were erased! So he wants to reassign positive integer weight to each of the edg... | import heapq
from collections import defaultdict
class Graph:
def __init__(self, n):
self.nodes = set(range(n))
self.edges = defaultdict(list)
self.distances = {}
def add_edge(self, from_node, to_node, distance):
self.edges[from_node].append(to_node)
self.edges[to_node... | {
"input": [
"5 5 13 0 4\n0 1 5\n2 1 2\n3 2 3\n1 4 0\n4 3 4\n",
"2 1 123456789 0 1\n0 1 0\n",
"2 1 999999999 1 0\n0 1 1000000000\n",
"7 9 999999999 0 3\n0 1 0\n1 2 0\n2 3 0\n0 4 1\n4 1 1\n1 5 499999999\n5 2 499999999\n2 6 1\n6 3 1\n",
"7 9 320 0 3\n0 1 0\n1 2 0\n2 3 0\n0 4 1\n4 1 1\n1 5 100\n5 2 1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
ZS the Coder has drawn an undirected graph of n vertices numbered from 0 to n - 1 and m edges between them. Each edge of the graph is weighted, each weight is a positive integer.
The... |
737_A. Road to Cinema_459 | Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the service to the cinema. Let's introduce a coordinate system so that the car rental service is at the point 0, and the cinema is at the point s.
... | # Question B. Road to Cinema
import sys
def roadToCinema(V, S, T, stations): # O(M)
"""
V : volume of fuel tank
S : total distance
T : time limit
stations: fuel stations' locations
rtype : boolean, whether this aircraft can travel within the time limit
"""
m = len(s... | {
"input": [
"3 1 8 10\n10 8\n5 7\n11 9\n3\n",
"2 2 10 18\n10 4\n20 6\n5 3\n",
"1 1 2 2\n1000000000 1000000000\n1\n",
"1 1 1000000000 1000000000\n100 1000000000\n1\n",
"1 1 10 18\n5 6\n5\n",
"2 1 1000000000 2000000000\n111 999999999\n101 999999998\n1\n",
"4 13 400 600\n13 30\n1 19\n1 160\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the servic... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.