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 |
|---|---|---|---|---|---|
1186_D. Vus the Cossack and Numbers_15606 | Vus the Cossack has n real numbers a_i. It is known that the sum of all numbers is equal to 0. He wants to choose a sequence b the size of which is n such that the sum of all numbers is 0 and each b_i is either ⌊ a_i ⌋ or ⌈ a_i ⌉. In other words, b_i equals a_i rounded up or down. It is not necessary to round to the ne... | import heapq
import math
n=int(input())
a=[None]*n
h=[]
mh=[]
s=0
d=[0]*n
for i in range(n):
a[i]=float(input())
if a[i]!=int(a[i]):
if a[i]<0:
heapq.heappush(h,[math.floor(a[i])-math.ceil(a[i]),i])
else:
heapq.heappush(mh,[math.ceil(a[i])-math.floor(a[i]),i])
s+=int(... | {
"input": [
"4\n4.58413\n1.22491\n-2.10517\n-3.70387\n",
"5\n-6.32509\n3.30066\n-0.93878\n2.00000\n1.96321\n",
"3\n40.00000\n-21.00003\n-18.99997\n",
"5\n648.85642\n-922.00000\n78.88625\n578.45284\n-384.19551\n",
"1\n0.00000\n",
"5\n-0.50000\n0.50000\n0.50000\n0.50000\n-1.00000\n",
"8\n57... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vus the Cossack has n real numbers a_i. It is known that the sum of all numbers is equal to 0. He wants to choose a sequence b the size of which is n such that the sum of all numbers ... |
1205_C. Palindromic Paths_15610 | This is an interactive problem
You are given a grid n× n, where n is odd. Rows are enumerated from 1 to n from up to down, columns are enumerated from 1 to n from left to right. Cell, standing on the intersection of row x and column y, is denoted by (x, y).
Every cell contains 0 or 1. It is known that the top-left ce... | n = int(input())
a=[]
for i in range(0,n+1):
temp= [0]*(n+1)
a.append(temp)
a[1][1]=1
def ask(x1,y1,x2,y2):
print("?",x1,y1,x2,y2)
a= int(input())
if a:
return True
else:
False
for i in range(3,n+1,1):
a[1][i] = a[1][i-2]^(not(ask(1,i-2,1,i)))
for i in range(2,n+1):
... | {
"input": [
"3\n0\n1\n0\n1\n1\n1\n1",
"11\n11010011011\n00011100100\n11001011101\n10001111011\n01110100000\n01011101111\n01101001100\n10011000110\n00100111011\n01011000110\n01011000110\n",
"9\n100000110\n001101101\n001001011\n011011101\n011100011\n011000101\n011010100\n011001110\n011111110\n",
"5\n10... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This is an interactive problem
You are given a grid n× n, where n is odd. Rows are enumerated from 1 to n from up to down, columns are enumerated from 1 to n from left to right. Cell... |
1248_D1. The World Is Just a Programming Task (Easy Version)_15616 | This is an easier version of the problem. In this version, n ≤ 500.
Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a creative crisis. To improve the situation, Petya gifted him a string consisting of opening and closing brackets only. Petya believe... | import sys
input = sys.stdin.readline
def matcher(correcti):
open_=0
close_=0
count=0
excess=0
for i in range(len(correcti)):
if correcti[i]=='(':
open_+=1
if correcti[i]==')':
close_+=1
if close_>open_ and open_==0:
excess+=1
c... | {
"input": [
"12\n)(()(()())()\n",
"10\n()()())(()\n",
"6\n)))(()\n",
"100\n)()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()(\n",
"498\n)())()(()()))())())()((()())((((()))()((()())()))())())))((()(()())))())())(()()(())())(((()))()))))(((((()())(... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This is an easier version of the problem. In this version, n ≤ 500.
Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya fa... |
1288_C. Two Arrays_15622 | You are given two integers n and m. Calculate the number of pairs of arrays (a, b) such that:
* the length of both arrays is equal to m;
* each element of each array is an integer between 1 and n (inclusive);
* a_i ≤ b_i for any index i from 1 to m;
* array a is sorted in non-descending order;
* array b ... | '''input
10 1
'''
# A coding delight
from sys import stdin, stdout
import gc
gc.disable()
input = stdin.readline
import math
# main starts
n, m = list(map(int, input().split()))
mod = 10 ** 9 + 7
dp1 = [[1 for x in range(m + 1)] for y in range(n + 1)]
dp2 = [[1 for y in range(m + 1)] for y in range(n + 1)]
for j in ... | {
"input": [
"723 9\n",
"2 2\n",
"10 1\n",
"1 2\n",
"678 7\n",
"1 10\n",
"398 8\n",
"526 2\n",
"1 1\n",
"1000 2\n",
"1000 1\n",
"1000 10\n",
"7 7\n",
"648 8\n",
"912 2\n",
"306 9\n",
"2 3\n",
"9 1\n",
"1 7\n",
"912 1\n",
"554 9\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 integers n and m. Calculate the number of pairs of arrays (a, b) such that:
* the length of both arrays is equal to m;
* each element of each array is an integ... |
1331_F. Elementary!_15626 |
Input
The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive.
Output
Output "YES" or "NO".
Examples
Input
GENIUS
Output
YES
Input
DOCTOR
Output
NO
Input
IRENE
Output
YES
Input
MARY
Output
NO
Input
SMARTP... | z="QWERTYUIOPASDFGHJKLZXCVBNM"
t="01101101001001010111101011"
s = input()
cur = '-'
for i in s:
for j in range(26):
if z[j] == i:
if cur == '-':
cur = t[j]
elif t[j] != cur:
print('NO')
exit(0)
print('YES') | {
"input": [
"DOCTOR\n",
"SMARTPHONE\n",
"REVOLVER\n",
"GENIUS\n",
"HOLMES\n",
"IRENE\n",
"MARY\n",
"WATSON\n",
"AID\n",
"TEASE\n",
"SUM\n",
"KHAKI\n",
"WURM\n",
"MUG\n",
"WEEVIL\n",
"WORD\n",
"PRODUCT\n",
"BRIGHT\n",
"SOURPUSS\n",
"AI\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Input
The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive.
Output
Output "YES" or "NO".
Examples
... |
1352_A. Sum of Round Numbers_15630 | A positive (strictly greater than zero) integer is called round if it is of the form d00...0. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all numbers from 1 to 9 (inclusive) are round.
For example, the following numbers are roun... | import sys
num_lines = int(input())
for i in range(num_lines):
cont = 0
resp = ''
whole_number = sys.stdin.readline().strip('\n')
length = len(whole_number) - 1
for idx, k in enumerate(whole_number):
if k != '0':
cont += 1
num = int(k) * 10 **(length - ... | {
"input": [
"5\n5009\n7\n9876\n10000\n10\n",
"2\n954\n18\n",
"5\n5009\n7\n9876\n10000\n10\n",
"2\n9999\n52\n",
"2\n999\n52\n",
"7\n1\n1\n1\n1\n1\n1\n1\n",
"2\n1149\n18\n",
"2\n4119\n52\n",
"2\n999\n27\n",
"5\n5722\n7\n9876\n10000\n10\n",
"2\n1149\n16\n",
"2\n4743\n52\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A positive (strictly greater than zero) integer is called round if it is of the form d00...0. In other words, a positive integer is round if all its digits except the leftmost (most s... |
1371_E2. Asterism (Hard Version)_15634 | This is the hard version of the problem. The difference between versions is the constraints on n and a_i. You can make hacks only if all versions of the problem are solved.
First, Aoi came up with the following idea for the competitive programming problem:
Yuzu is a girl who collecting candies. Originally, she has x ... | import sys
import math
from math import factorial, inf, gcd, sqrt
from heapq import *
from functools import *
from itertools import *
from collections import *
from typing import *
from bisect import *
import random
sys.setrecursionlimit(10**5)
def rarray():
return [int(i) for i in input().split()]
t = 1
# t = ... | {
"input": [
"4 3\n2 3 5 6\n",
"3 2\n1000000000 1 999999999\n",
"3 2\n3 4 5\n",
"4 3\n9 1 1 1\n",
"5 5\n292213182 292213182 292213182 292213183 292213182\n",
"6 5\n459714880 459714883 459714884 459714882 459714878 459714881\n",
"5 5\n324179187 95333719 583067898 217640575 166623692\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This is the hard version of the problem. The difference between versions is the constraints on n and a_i. You can make hacks only if all versions of the problem are solved.
First, Ao... |
1419_A. Digit Game_15640 | Everyone knows that agents in Valorant decide, who will play as attackers, and who will play as defenders. To do that Raze and Breach decided to play t matches of a digit game...
In each of t matches of the digit game, a positive integer is generated. It consists of n digits. The digits of this integer are numerated f... | for _ in range(int(input())):
a = int(input())
number = input()
raze = [0,0] #odd,even
breach = [0,0] #odd,even
count = 0
while count<len(number):
if count%2==0:
if int(number[count])%2==0:
raze[1]+=1
else:
raze[0]+=1
... | {
"input": [
"4\n1\n2\n1\n3\n3\n102\n4\n2069\n",
"1\n33\n200000000000000000000000000000022\n",
"1\n3\n222\n",
"1\n4\n1212\n",
"1\n3\n101\n",
"1\n4\n2323\n",
"1\n2\n39\n",
"1\n2\n13\n",
"1\n4\n2121\n",
"4\n1\n2\n1\n3\n4\n2068\n4\n2069\n",
"1\n2\n21\n",
"2\n3\n212\n2\n11\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Everyone knows that agents in Valorant decide, who will play as attackers, and who will play as defenders. To do that Raze and Breach decided to play t matches of a digit game...
In ... |
1437_A. Marketing Scheme_15644 | You got a job as a marketer in a pet shop, and your current task is to boost sales of cat food. One of the strategies is to sell cans of food in packs with discounts.
Suppose you decided to sell packs with a cans in a pack with a discount and some customer wants to buy x cans of cat food. Then he follows a greedy str... | for _ in range(int(input())):
a,b = map(int,input().split())
aa = a%(b+1);bb = b%(b+1)
if(aa>=(b+1)/2 and bb>=(b+1)/2):
print("YES")
else:
print("NO") | {
"input": [
"3\n3 4\n1 2\n120 150\n",
"10\n335544320 671088640\n335544322 671088639\n335544321 671088639\n335544325 671088637\n335544319 671088640\n335544319 671088641\n335544319 671088639\n335544318 671088639\n335544317 671088637\n335544319 671088643\n",
"3\n335544322 671088639\n335544320 671088640\n209... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You got a job as a marketer in a pet shop, and your current task is to boost sales of cat food. One of the strategies is to sell cans of food in packs with discounts.
Suppose you de... |
1461_E. Water Level_15648 | In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
<image>... | k, l, r, t, x, y = map(int, input().split())
k -= l
r -= l
l = 0
if k < x - y or (k > r - y and k < x):
print("No")
exit()
if x > y:
if k + y > r:
k -= x
t -= 1
print("Yes" if t <= k // (x - y) else "No")
else:
if l + x + y - r <= 1:
print("Yes")
exit()
arr = [-1]... | {
"input": [
"9 1 10 9 2 9\n",
"8 1 10 2 6 5\n",
"8 1 10 2 6 4\n",
"20 15 25 3 5 7\n",
"39438548848582980 11012410395558518 55950951412984721 44 535353 28994364452506991\n",
"512151145295769976 499588189546311526 513794826978301613 1000000000000000000 504656 89379401\n",
"50051392232111956... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself ... |
1538_B. Friends and Candies_15655 | Polycarp has n friends, the i-th of his friends has a_i candies. Polycarp's friends do not like when they have different numbers of candies. In other words they want all a_i to be the same. To solve this, Polycarp performs the following set of actions exactly once:
* Polycarp chooses k (0 ≤ k ≤ n) arbitrary friends... | import sys,os,io
from sys import stdin,stdout
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from bisect import bisect_left , bisect_right
import bisect
import math
input = stdin.readline
alphabets = list('abcdefghijklmnopqrstuvwxyz')
def isPr... | {
"input": [
"5\n4\n4 5 2 5\n2\n0 4\n5\n10 8 5 1 4\n1\n10000\n7\n1 1 1 1 1 1 1\n",
"1\n52\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"1\n2\n1 691\n",
"1\n3\n1 1 67\n",
"1\n52\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarp has n friends, the i-th of his friends has a_i candies. Polycarp's friends do not like when they have different numbers of candies. In other words they want all a_i to be the... |
207_D1. The Beaver's Problem - 3_15664 | The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorting documents by their subjects. Let's describe the problem:
You've got some training set of documents. For each document you know its su... | print('1') | {
"input": [
"36000\nU.K. MONEY MARKET DEFICIT REMOVED\nLONDON, April 9 - The Bank of England said it has satisfied\nits revised estimate of today's shortfall in the money market,\nproviding 261 mln stg assistance in afternoon operations.\nThe Bank bought in band one, 60 mln stg bank bills at 9-7/8\npct and in ba... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorti... |
231_D. Magic Box_15668 | One day Vasya was going home when he saw a box lying on the road. The box can be represented as a rectangular parallelepiped. Vasya needed no time to realize that the box is special, as all its edges are parallel to the coordinate axes, one of its vertices is at point (0, 0, 0), and the opposite one is at point (x1, y1... | x,y,z=map(int,input().split())
a,b,c=map(int,input().split())
a1,a2,a3,a4,a5,a6=map(int,input().split())
sum=0
if x>a:
sum+=a6
if x<0:
sum+=a5
if y>b:
sum+=a2
if y<0:
sum+=a1
if z>c:
sum+=a4
if z<0:
sum+=a3
print(sum) | {
"input": [
"2 2 2\n1 1 1\n1 2 3 4 5 6\n",
"0 0 10\n3 2 3\n1 2 3 4 5 6\n",
"5 5 0\n3 1 3\n832224 636838 995053 211585 505442 341920\n",
"34271 -17508 -6147\n456 567 112\n804178 307516 306399 18981 989216 228388\n",
"967 -1346 2551\n769 331 28\n458319 885170 877010 533360 723416 248230\n",
"-2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
One day Vasya was going home when he saw a box lying on the road. The box can be represented as a rectangular parallelepiped. Vasya needed no time to realize that the box is special, ... |
257_C. View Angle_15672 | Flatland has recently introduced a new type of an eye check for the driver's licence. The check goes like that: there is a plane with mannequins standing on it. You should tell the value of the minimum angle with the vertex at the origin of coordinates and with all mannequins standing inside or on the boarder of this a... | import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
f... | {
"input": [
"2\n2 0\n0 2\n",
"2\n2 1\n1 2\n",
"4\n2 0\n0 2\n-2 0\n0 -2\n",
"3\n2 0\n0 2\n-2 2\n",
"10\n-1 -29\n-1 -26\n1 -26\n-1 -22\n-1 -24\n-1 -21\n1 -24\n-1 -20\n-1 -23\n-1 -25\n",
"20\n-45 147\n-240 784\n-135 441\n-60 196\n-105 343\n-285 931\n-195 637\n-300 980\n-165 539\n-210 686\n-75 24... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Flatland has recently introduced a new type of an eye check for the driver's licence. The check goes like that: there is a plane with mannequins standing on it. You should tell the va... |
280_C. Game on Tree_15676 | Momiji has got a rooted tree, consisting of n nodes. The tree nodes are numbered by integers from 1 to n. The root has number 1. Momiji decided to play a game on this tree.
The game consists of several steps. On each step, Momiji chooses one of the remaining tree nodes (let's denote it by v) and removes all the subtre... | # https://codeforces.com/problemset/problem/280/C
from collections import defaultdict, deque
import sys
nodes = int(sys.stdin.readline())
edges = defaultdict(list)
for line in sys.stdin:
a, b = line.split()
a = int(a)
b = int(b)
edges[a].append(b)
edges[b].append(a)
bfs = deque([(1, 1)])
depths = {... | {
"input": [
"3\n1 2\n1 3\n",
"2\n1 2\n",
"10\n1 2\n2 3\n3 4\n1 5\n2 6\n6 7\n4 8\n6 9\n9 10\n",
"6\n1 3\n2 4\n5 6\n3 6\n5 4\n",
"6\n1 4\n2 4\n5 6\n3 6\n5 4\n",
"6\n1 3\n2 4\n5 6\n3 6\n3 4\n",
"6\n1 3\n2 1\n5 6\n3 6\n3 4\n",
"3\n1 2\n2 3\n",
"6\n1 4\n2 5\n5 6\n3 6\n5 4\n",
"6\n1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Momiji has got a rooted tree, consisting of n nodes. The tree nodes are numbered by integers from 1 to n. The root has number 1. Momiji decided to play a game on this tree.
The game ... |
303_B. Rectangle Puzzle II_15680 | You are given a rectangle grid. That grid's size is n × m. Let's denote the coordinate system on the grid. So, each point on the grid will have coordinates — a pair of integers (x, y) (0 ≤ x ≤ n, 0 ≤ y ≤ m).
Your task is to find a maximum sub-rectangle on the grid (x1, y1, x2, y2) so that it contains the given point (... | from fractions import gcd
n, m, x, y, a, b = map(int, input().split())
r = gcd(a, b)
a, b = a // r, b // r
r = min(n // a, m // b)
a, b = a * r, b * r
cx, cy = (a + 1) // 2, (b + 1) // 2
dx, dy = min(n - a, max(cx, x) - cx), min(m - b, max(cy, y) - cy)
print(dx, dy, a + dx, b + dy)
# Made By Mostafa_Khaled | {
"input": [
"100 100 52 50 46 56\n",
"9 9 5 5 2 1\n",
"71265727 62692710 12444778 3479306 21442685 5463351\n",
"81460 7041354 53032 1297536 41496 5748697\n",
"99373741 10548319 82293354 9865357 58059929 5328757\n",
"1000000000 1000000000 839898171 196274842 131921537 865789406\n",
"656183... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a rectangle grid. That grid's size is n × m. Let's denote the coordinate system on the grid. So, each point on the grid will have coordinates — a pair of integers (x, y)... |
32_C. Flea_15684 | It is known that fleas in Berland can jump only vertically and horizontally, and the length of the jump is always equal to s centimeters. A flea has found herself at the center of some cell of the checked board of the size n × m centimeters (each cell is 1 × 1 centimeters). She can jump as she wishes for an arbitrary n... | n,m,s=map(int,input().split())
r = (-(-n//s)) * (s if n%s==0 else n%s)
c = (-(-m//s)) * (s if m%s==0 else m%s)
print(r*c) | {
"input": [
"3 3 2\n",
"2 3 1000000\n",
"694117 431924 737\n",
"1000000 1000000 12345\n",
"1 2 3\n",
"391814 220151 3756\n",
"40224 890892 54\n",
"242366 216591 4\n",
"9 8 7\n",
"1000000 1000000 2\n",
"38614 941895 999986\n",
"402841 635488 997633\n",
"43496 179847... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
It is known that fleas in Berland can jump only vertically and horizontally, and the length of the jump is always equal to s centimeters. A flea has found herself at the center of som... |
351_A. Jeff and Rounding_15688 | Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:
* choose indexes i and j (i ≠ j) that haven't been chosen yet;
* round elemen... | n, k, s = int(input()), 0, 0
for i in input().split():
j = int(i[-3: ])
if j == 0: k += 1
else: s += j
c = s // 1000 + int(s % 1000 > 500)
a, b = max(0, n - k), min(2 * n - k, n)
if a <= c <= b: s = abs(c * 1000 - s)
else: s = min(abs(a * 1000 - s), abs(b * 1000 - s))
print(str(s // 1000) + '.' + str(s % 10... | {
"input": [
"3\n0.000 0.500 0.750 1.000 2.000 3.000\n",
"3\n4469.000 6526.000 4864.000 9356.383 7490.000 995.896\n",
"9\n5528.947 205.031 5245.169 8832.592 385.656 7126.360 3988.000 9542.000 3044.042 5288.000 9342.837 9979.021 7096.022 5159.200 9400.485 4996.735 1698.000 5403.939\n",
"1\n6418.669 157... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively... |
375_B. Maximum Submatrix 2_15692 | You are given a matrix consisting of digits zero and one, its size is n × m. You are allowed to rearrange its rows. What is the maximum area of the submatrix that only consists of ones and can be obtained in the given problem by the described operations?
Let's assume that the rows of matrix a are numbered from 1 to n ... | '''
from bisect import bisect,bisect_left
from collections import *
from math import gcd,ceil,sqrt,floor,inf
from heapq import *
from itertools import *
from operator import add,mul,sub,xor,truediv,floordiv
from functools import *'''
#------------------------------------------------------------------------
import os
... | {
"input": [
"4 3\n100\n011\n000\n101\n",
"1 1\n1\n",
"2 2\n10\n11\n",
"13 19\n0000111111111111011\n0111000001110001101\n1110100110111011101\n0001101011100001110\n1101100100010000101\n1010100011110011010\n1010011101010000001\n1011101000001111000\n1101110001101011110\n0110101010001111100\n0001011010100... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a matrix consisting of digits zero and one, its size is n × m. You are allowed to rearrange its rows. What is the maximum area of the submatrix that only consists of one... |
397_D. On Sum of Fractions_15696 | Let's assume that
* v(n) is the largest prime number, that does not exceed n;
* u(n) is the smallest prime number strictly greater than n.
Find <image>.
Input
The first line contains integer t (1 ≤ t ≤ 500) — the number of testscases.
Each of the following t lines of the input contains integer n (2 ≤ n ≤ ... | T = int( input() )
#for every prime x
#(b-a)/ab
#1/a-1/b
MAX = 33000
bePrime = [0] * MAX;
primNum = []
for j in range(2, MAX):
if bePrime[j] == 0:
primNum.append( j )
i = j
while i < MAX:
bePrime[i] = 1
i = i + j
def isPrime( a ):
for j in primNum:
i... | {
"input": [
"2\n2\n3\n",
"5\n72\n72\n30\n75\n11\n",
"5\n79\n149\n136\n194\n124\n",
"6\n885\n419\n821\n635\n63\n480\n",
"1\n1000000000\n",
"5\n3\n6\n9\n10\n5\n",
"5\n5\n8\n18\n17\n17\n",
"1\n649580447\n",
"5\n7\n40\n37\n25\n4\n",
"5\n80\n72\n30\n75\n11\n",
"5\n79\n166\n136\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Let's assume that
* v(n) is the largest prime number, that does not exceed n;
* u(n) is the smallest prime number strictly greater than n.
Find <image>.
Input
The first li... |
41_E. 3-cycles_15700 | During a recent research Berland scientists found out that there were n cities in Ancient Berland, joined by two-way paths. Any two cities are joined by no more than one path. No path joins a city with itself. According to a well-known tradition, the road network was built so that it would be impossible to choose three... | p = int(input())
print( ( p // 2 ) ** 2 + ( p // 2) * ( p % 2 ) )
for i in range(p//2):
for j in range(p//2, p):
print(i+1, j+1) | {
"input": [
"4\n",
"3\n",
"29\n",
"18\n",
"3\n",
"31\n",
"1\n",
"18\n",
"15\n",
"15\n",
"9\n",
"6\n",
"16\n",
"23\n",
"33\n",
"23\n",
"10\n",
"31\n",
"33\n",
"19\n",
"5\n",
"12\n",
"7\n",
"2\n",
"13\n",
"8\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
During a recent research Berland scientists found out that there were n cities in Ancient Berland, joined by two-way paths. Any two cities are joined by no more than one path. No path... |
490_D. Chocolate_15708 | Polycarpus likes giving presents to Paraskevi. He has bought two chocolate bars, each of them has the shape of a segmented rectangle. The first bar is a1 × b1 segments large and the second one is a2 × b2 segments large.
Polycarpus wants to give Paraskevi one of the bars at the lunch break and eat the other one himself... | def decomp(a):
cnt2 = 0
while a%2==0:
a = a//2
cnt2 += 1
cnt3 = 0
while a%3==0:
a = a//3
cnt3 += 1
return a,cnt2,cnt3
def cut(a,b,d,p):
while d>0:
if a%p==0:
a = (p-1)*a//p
d = d-1
elif b%p==0:
b = (p-1)*b//p
... | {
"input": [
"36 5\n10 16\n",
"3 5\n2 1\n",
"2 6\n2 3\n",
"261578849 307610920\n636335376 399859678\n",
"199999978 2\n599999934 3\n",
"894 197\n325 232\n",
"60 1080\n60 45\n",
"720005688 725594112\n816293376 960007584\n",
"1 1\n918330048 918330048\n",
"22295873 586964387\n47368... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarpus likes giving presents to Paraskevi. He has bought two chocolate bars, each of them has the shape of a segmented rectangle. The first bar is a1 × b1 segments large and the s... |
514_D. R2D2 and Droid Army_15712 | An army of n droids is lined up in one row. Each droid is described by m integers a1, a2, ..., am, where ai is the number of details of the i-th type in this droid's mechanism. R2-D2 wants to destroy the sequence of consecutive droids of maximum length. He has m weapons, the i-th weapon can affect all the droids in the... | # ---------------------------iye ha aam zindegi---------------------------------------------
import math
import random
import heapq,bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10**8)
mod ... | {
"input": [
"5 2 4\n4 0\n1 2\n2 1\n0 2\n1 3\n",
"3 2 4\n1 2\n1 3\n2 2\n",
"4 5 33\n2 10 2 3 2\n10 6 4 5 0\n3 1 7 3 2\n4 4 2 1 5\n",
"4 5 40\n0 10 9 0 4\n10 5 5 7 4\n9 9 5 5 2\n6 7 9 4 3\n",
"31 2 1913\n845 576\n862 325\n914 283\n431 837\n193 171\n30 248\n290 488\n810 552\n463 74\n765 469\n785 119... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
An army of n droids is lined up in one row. Each droid is described by m integers a1, a2, ..., am, where ai is the number of details of the i-th type in this droid's mechanism. R2-D2 ... |
540_E. Infinite Inversions_15716 | There is an infinite sequence consisting of all positive integers in the increasing order: p = {1, 2, 3, ...}. We performed n swap operations with this sequence. A swap(a, b) is an operation of swapping the elements of the sequence on positions a and b. Your task is to find the number of inversions in the resulting seq... | import sys
from collections import defaultdict
class BIT():
def __init__(self, n):
self.n = n
self.tree = [0] * n
def _get_sum(self, r):
'''
sum on interval [0, r)
'''
result = 0
while r > 0:
result += self.tree[r-1]
r &= (r ... | {
"input": [
"3\n1 6\n3 4\n2 5\n",
"2\n4 2\n1 4\n",
"5\n2 5\n6 3\n4 6\n5 4\n2 5\n",
"30\n1 200000\n2 199999\n3 199998\n4 199997\n5 199996\n200001 399996\n200002 399997\n200003 399998\n200004 399999\n200005 400000\n400001 599998\n400002 599999\n400003 600000\n400004 599996\n400005 599995\n600001 800000... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is an infinite sequence consisting of all positive integers in the increasing order: p = {1, 2, 3, ...}. We performed n swap operations with this sequence. A swap(a, b) is an op... |
569_A. Music_15720 | Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.
Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite ... | T, S, q = map(int, input().split())
count = 0
while True:
count += 1
ds = S * (q - 1)
S += ds
if S >= T:
break
print(count) | {
"input": [
"5 2 2\n",
"6 2 3\n",
"5 4 7\n",
"100000 1 10000\n",
"64 1 8\n",
"100000 1 2\n",
"100000 1 4\n",
"12326 6163 2\n",
"100000 1 5\n",
"12351 1223 6\n",
"2 1 3\n",
"100000 1 3\n",
"6562 1 3\n",
"10033 3 8\n",
"100000 99999 3\n",
"12628 1804 7\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.
U... |
58_D. Calendar_15724 | BerOilGasDiamondBank has branches in n cities, at that n is an even number. The bank management wants to publish a calendar with the names of all those cities written in two columns: the calendar should consist of exactly n / 2 lines of strictly equal length, each of which contains exactly two names and exactly one sep... | # t = int(input())
# while t>0:
n = int(input()) // 2
a = sorted([input() for i in range(n * 2)], reverse=1)
d = input()
L = sum(len(i) for i in a) // n
ans = []
for i in range(n):
x = a.pop()
for y in a[::-1]:
if len(x) + len(y) == L:
ans.append(min(x + d + y, y + d + x))
a.remo... | {
"input": [
"4\nb\naa\nhg\nc\n.\n",
"2\naa\na\n!\n",
"2\naa\na\n|\n",
"4\nqhcivbxotj\nirgxzzxvw\npxdmcyszvk\nyyaevcdal\n~\n",
"34\nobseknnnqk\ncvyvvbcgb\nxvmhfzfl\ngrtp\nhbcbhj\nknnnqk\ncyud\nkuaeui\naeui\nlhpdobsekn\ncxmigej\ncvyvvbcgbs\nuwuu\nnnqk\npzcftfrrqp\nnwsyrgqa\nxvmhfzflku\nndcis\nxhazn... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
BerOilGasDiamondBank has branches in n cities, at that n is an even number. The bank management wants to publish a calendar with the names of all those cities written in two columns: ... |
631_C. Report_15730 | Each month Blake gets the report containing main economic indicators of the company "Blake Technologies". There are n commodities produced by the company. For each of them there is exactly one integer in the final report, that denotes corresponding revenue. Before the report gets to Blake, it passes through the hands o... | def compress(ops):
cops = []
for r, dir in ops:
while cops and cops[-1][0] <= r:
cops.pop()
if not cops or cops[-1][1] != dir:
cops.append((r, dir))
return cops
def transform(lst, ops):
mr, mdir = ops[0]
sections = [range(mr, len(lst))]
ost = 0
oen... | {
"input": [
"3 1\n1 2 3\n2 2\n",
"4 2\n1 2 4 3\n2 3\n1 2\n",
"6 2\n3 1 2 6 4 5\n1 6\n2 3\n",
"100 30\n65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 74 57 115 16 55 88 79 97 21 80 41 56 49 103 61 66... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Each month Blake gets the report containing main economic indicators of the company "Blake Technologies". There are n commodities produced by the company. For each of them there is ex... |
660_A. Co-prime Array_15734 | You are given an array of n elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater than 109 in any place in the array.
An array is co-prime if any two adjacent numbers of it are co-prime.
In the number theory, two integer... |
def gcd(x, y):
if y == 0:
return x
return gcd(y, x % y)
n = int(input())
a = list(map(int, input().split()))
last = 1
ans = []
for i in range(n):
if gcd(a[i], last) != 1:
ans.append(1)
ans.append(a[i])
last = a[i]
print(len(ans) - n)
for i in range(len(ans) - 1):
... | {
"input": [
"3\n2 7 28\n",
"3\n999999937 999999937 2\n",
"2\n3257 3257\n",
"7\n1 982451653 982451653 1 982451653 982451653 982451653\n",
"2\n999999733 999999733\n",
"20\n2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an array of n elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater tha... |
706_D. Vasiliy's Multiset_15738 | Author has gone out of the stories about Vasiliy, so here is just a formal task description.
You are given q queries and a multiset A, initially containing only integer 0. There are three types of queries:
1. "+ x" — add integer x to multiset A.
2. "- x" — erase one occurrence of integer x from multiset A. It's g... | # ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode... | {
"input": [
"10\n+ 8\n+ 9\n+ 11\n+ 6\n+ 1\n? 3\n- 8\n? 3\n? 8\n? 11\n",
"7\n? 1\n+ 941492387\n+ 72235422\n+ 449924898\n+ 783332532\n- 941492387\n- 72235422\n",
"1\n? 4\n",
"10\n? 1\n+ 1\n+ 8\n- 1\n+ 2\n+ 7\n+ 4\n+ 7\n+ 3\n? 7\n",
"3\n? 5\n? 4\n? 3\n",
"12\n+ 4\n+ 4\n+ 5\n? 3\n- 4\n? 3\n- 4\n?... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Author has gone out of the stories about Vasiliy, so here is just a formal task description.
You are given q queries and a multiset A, initially containing only integer 0. There are ... |
74_B. Train_15744 | A stowaway and a controller play the following game.
The train is represented by n wagons which are numbered with positive integers from 1 to n from the head to the tail. The stowaway and the controller are initially in some two different wagons. Every minute the train can be in one of two conditions — moving or idle... | n, rider, cop = map(int, input().split())
rider, cop = rider - 1, cop - 1
if input().strip() == 'to head':
cop_dir = -1
else:
cop_dir = 1
for pos, ch in enumerate(input().strip()):
#print(pos, ch, rider, cop, cop_dir)
if ch == '1':
rider = -1
else:
if cop_dir == -1 and rider < cop:
... | {
"input": [
"5 3 2\nto head\n0001001\n",
"3 2 1\nto tail\n0001\n",
"50 4 12\nto tail\n00000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000001000100000000000000000000000000000000000000010000000010000000000000000000000000000000000000000001\n",
"3 1 3\nto... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A stowaway and a controller play the following game.
The train is represented by n wagons which are numbered with positive integers from 1 to n from the head to the tail. The stowaw... |
773_A. Success Rate_15748 | You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y.
Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the s... | import math as mt
import sys,string,bisect
input=sys.stdin.readline
import random
from collections import deque,defaultdict
L=lambda : list(map(int,input().split()))
Ls=lambda : list(input().split())
M=lambda : map(int,input().split())
I=lambda :int(input())
d=defaultdict(int)
def extended_gcd(a,b):
if(a==0):
... | {
"input": [
"4\n3 10 1 2\n7 14 3 8\n20 70 2 7\n5 6 1 1\n",
"1\n3 999999990 1 1000000000\n",
"1\n2 2 1 1\n",
"5\n1 982449707 1 2\n1 982449707 1 2\n1 982449707 1 2\n1 982449707 1 2\n1 982449707 1 2\n",
"1\n0 1000000000 999999999 1000000000\n",
"5\n1000000000 1000000000 1 2\n1000000000 100000000... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your curren... |
818_B. Permutation Game_15754 | n children are standing in a circle and playing a game. Children's numbers in clockwise order form a permutation a1, a2, ..., an of length n. It is an integer sequence such that each integer from 1 to n appears exactly once in it.
The game consists of m steps. On each step the current leader with index i counts out ai... | n, m = map(int, input().split())
l = list(map(int, input().split()))
a = [-1] * n
s = set(range(1, n + 1))
d = set()
for i in range(m - 1):
for j in range(1, n + 1):
if (l[i] + j - l[i + 1]) % n == 0:
if j in d and a[l[i] - 1] != j:
print(-1)
exit()
a[... | {
"input": [
"3 3\n3 1 2\n",
"4 5\n2 3 1 4 4\n",
"4 5\n1 4 1 3 2\n",
"4 6\n1 1 2 4 4 4\n",
"20 15\n11 19 1 8 17 12 3 1 8 17 12 3 1 8 17\n",
"4 6\n2 3 1 4 4 1\n",
"3 4\n1 3 1 1\n",
"5 7\n4 3 4 3 3 4 5\n",
"2 9\n1 1 1 1 2 1 1 1 1\n",
"4 4\n1 4 1 3\n",
"20 20\n1 20 2 19 3 18 4... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
n children are standing in a circle and playing a game. Children's numbers in clockwise order form a permutation a1, a2, ..., an of length n. It is an integer sequence such that each ... |
864_A. Fair Game_15760 | Petya and Vasya decided to play a game. They have n cards (n is an even number). A single integer is written on each card.
Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with num... | #python3
#utf-8
from collections import Counter
cards_nr = int(input())
number_counter = Counter()
for _ in range(cards_nr):
curr_number = int(input())
number_counter[curr_number] += 1
if len(number_counter) != 2:
print('NO')
else:
num1, num2 = list(number_counter)
if number_counter[num1] != numb... | {
"input": [
"2\n6\n6\n",
"6\n1\n1\n2\n2\n3\n3\n",
"4\n11\n27\n27\n11\n",
"6\n10\n20\n30\n20\n10\n20\n",
"100\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Petya and Vasya decided to play a game. They have n cards (n is an even number). A single integer is written on each card.
Before the game Petya will choose an integer and after that... |
934_C. A Twisty Movement_15769 | A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon.
A performer holding the rod low is represented by a 1, while one holding it high is represented by a 2. Thus, th... | n = int(input())
A = list(map(int, input().split()))
one = [0]
two = [0]
for i in A:
one.append(one[-1])
two.append(two[-1])
if i == 1:
one[-1] += 1
else:
two[-1] += 1
rdp1 = [[1] * n for _ in range(n)]
rdp2 = [[1] * n for _ in range(n)]
for l in range(n):
for r in range(l + 1, n):
... | {
"input": [
"4\n1 2 1 2\n",
"10\n1 1 2 2 2 1 1 2 2 1\n",
"6\n2 2 2 1 1 1\n",
"2\n1 2\n",
"200\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to re... |
988_B. Substrings Sort_15776 | You are given n strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings.
String a is a substring of string b if it is possible to choose several consecutive letters in b in such a way... |
# We are the all singing all dancing crap of the world
n = int(input())
khela = []
for i in range(n):
s = input()
khela.append([len(s),s])
khela = sorted(khela)
if (n==1):
print('YES')
print(khela[0][1])
else:
lent = len(khela)
for i in range(lent-1):
c = 0
... | {
"input": [
"3\nqwerty\nqwerty\nqwerty\n",
"5\na\naba\nabacaba\nba\naba\n",
"5\na\nabacaba\nba\naba\nabab\n",
"3\nab\ncd\nabcd\n",
"2\naabaa\naba\n",
"2\nab\naab\n",
"5\nekgetterherforme\ner\nter\nher\ntter\n",
"4\na\nb\nc\nabc\n",
"4\na\nba\nabacabac\nb\n",
"3\na\nb\nab\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given n strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed befo... |
p02594 AtCoder Beginner Contest 174 - Air Conditioner_15790 | You will turn on the air conditioner if, and only if, the temperature of the room is 30 degrees Celsius or above.
The current temperature of the room is X degrees Celsius. Will you turn on the air conditioner?
Constraints
* -40 \leq X \leq 40
* X is an integer.
Input
Input is given from Standard Input in the follo... | d = int(input())
if d >= 30:
print("Yes")
else:
print("No") | {
"input": [
"25",
"30",
"20",
"44",
"37",
"78",
"47",
"91",
"61",
"26",
"35",
"23",
"48",
"21",
"3",
"1",
"5",
"0",
"6",
"2",
"-1",
"-2",
"-3",
"-4",
"-6",
"-7",
"-11",
"-5",
"-10",
"4",
"-13",... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You will turn on the air conditioner if, and only if, the temperature of the room is 30 degrees Celsius or above.
The current temperature of the room is X degrees Celsius. Will you t... |
p02725 AtCoder Beginner Contest 160 - Traveling Salesman around Lake_15794 | There is a circular pond with a perimeter of K meters, and N houses around them.
The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.
When traveling between these houses, you can only go around the pond.
Find the minimum distance that needs to ... | k,n=map(int,input().split())
l=list(map(int, input().split()))
m=k-(l[n-1]-l[0])
for i in range(1,n):
m=max(m,l[i]-l[i-1])
print(k-m) | {
"input": [
"20 3\n5 10 15",
"20 3\n0 5 15",
"20 3\n5 11 15",
"27 3\n1 5 15",
"20 3\n2 11 15",
"27 3\n1 5 29",
"20 3\n3 11 15",
"20 3\n1 5 17",
"19 3\n0 5 15",
"27 3\n1 6 29",
"20 3\n3 11 29",
"31 3\n3 11 29",
"7 3\n0 5 17",
"7 3\n0 4 17",
"7 3\n0 4 28",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is a circular pond with a perimeter of K meters, and N houses around them.
The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured cl... |
p02856 DISCO Presents Discovery Channel Code Contest 2020 Qual - Digit Sum Replace_15798 | N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals.
The preliminary stage consists of several rounds, which will take place as follows:
* All the N contestants will participate in the first round.
* W... | n=int(input())
DC=[list(map(int,input().split())) for _ in range(n)]
D,S=0,0
for d,c in DC:
D +=c
S +=d*c
print(D-1+(S-1)//9) | {
"input": [
"3\n1 1\n0 8\n7 1",
"2\n2 2\n9 1",
"3\n1 0\n0 8\n7 1",
"3\n1 0\n0 8\n7 2",
"3\n1 0\n0 10\n7 2",
"3\n1 0\n0 17\n7 2",
"3\n1 1\n0 17\n7 2",
"3\n1 1\n0 4\n7 2",
"3\n1 0\n0 4\n7 2",
"3\n1 0\n0 4\n7 1",
"3\n1 0\n0 3\n7 1",
"3\n1 1\n0 8\n7 2",
"3\n1 0\n0 27\n... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals.
The prelimin... |
p02992 AtCoder Beginner Contest 132 - Small Products_15801 | Find the number of sequences of length K consisting of positive integers such that the product of any two adjacent elements is at most N, modulo 10^9+7.
Constraints
* 1\leq N\leq 10^9
* ~~1~~ 2\leq K\leq 100 (fixed at 21:33 JST)
* N and K are integers.
Input
Input is given from Standard Input in the following forma... | import sys
def solve():
N, K = map(int, input().split())
MOD = 10**9 + 7
U = []; V = []
for x in range(1, int(N**.5)+1):
U.append(x)
if x < N//x:
V.append(N//x)
V.reverse(); U.extend(V)
L = len(U)
prv = 0
R = []
for x in U:
R.append(x-prv)
... | {
"input": [
"10 3",
"314159265 35",
"3 2",
"10 4",
"305678790 35",
"5 2",
"10 5",
"306063188 35",
"5 3",
"419072353 35",
"3 3",
"419072353 10",
"3 6",
"419072353 2",
"614246832 2",
"651766788 2",
"314159265 50",
"305678790 60",
"5 4",
"1... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Find the number of sequences of length K consisting of positive integers such that the product of any two adjacent elements is at most N, modulo 10^9+7.
Constraints
* 1\leq N\leq 10... |
p03133 Yahoo Programming Contest 2019 - Odd Subrectangles_15805 | There is a square grid with N rows and M columns. Each square contains an integer: 0 or 1. The square at the i-th row from the top and the j-th column from the left contains a_{ij}.
Among the 2^{N+M} possible pairs of a subset A of the rows and a subset B of the columns, find the number of the pairs that satisfy the f... | def rankmod2(A):
global N, M
ret = 0
i = 0
j = 0
while i < N and j < M:
if A[i][j]:
ret += 1
else:
for ii in range(i+1, N):
if A[ii][j]:
A[i], A[ii] = A[ii], A[i]
ret += 1
break
... | {
"input": [
"2 2\n0 1\n1 0",
"2 3\n0 0 0\n0 1 0",
"2 3\n0 0 0\n-1 1 0",
"2 3\n0 0 -1\n-1 1 0",
"1 3\n0 0 -1\n-1 1 0",
"2 2\n1 1\n1 0",
"1 2\n-1 0 -1\n-1 0 0",
"1 0\n-1 0 -1\n-1 0 0",
"1 1\n-1 1 -4\n0 1 2",
"1 3\n-1 0 -1\n-1 1 0",
"1 3\n-1 0 -1\n-1 1 1",
"1 3\n-1 1 -1\n... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is a square grid with N rows and M columns. Each square contains an integer: 0 or 1. The square at the i-th row from the top and the j-th column from the left contains a_{ij}.
... |
p03278 AtCoder Regular Contest 101 - Ribbons on Tree_15808 | Let N be an even number.
There is a tree with N vertices. The vertices are numbered 1, 2, ..., N. For each i (1 \leq i \leq N - 1), the i-th edge connects Vertex x_i and y_i.
Snuke would like to decorate the tree with ribbons, as follows.
First, he will divide the N vertices into N / 2 pairs. Here, each vertex must ... | mod = 10**9+7 #出力の制限
N = 2*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
import sys
sys.setrecursionlimit(10**4)... | {
"input": [
"4\n1 2\n2 3\n3 4",
"6\n1 2\n1 3\n3 4\n1 5\n5 6",
"10\n8 5\n10 8\n6 5\n1 5\n4 8\n2 10\n3 6\n9 2\n1 7",
"4\n1 2\n1 3\n1 4",
"10\n8 5\n10 8\n6 5\n1 5\n4 8\n2 4\n3 6\n9 2\n1 7",
"10\n8 5\n10 8\n6 5\n1 5\n4 8\n2 4\n3 9\n9 2\n1 7",
"10\n8 5\n10 8\n6 5\n2 5\n4 8\n2 4\n3 9\n9 2\n1 7"... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Let N be an even number.
There is a tree with N vertices. The vertices are numbered 1, 2, ..., N. For each i (1 \leq i \leq N - 1), the i-th edge connects Vertex x_i and y_i.
Snuke ... |
p03433 AtCoder Beginner Contest 088 - Infinite Coins_15812 | E869120 has A 1-yen coins and infinitely many 500-yen coins.
Determine if he can pay exactly N yen using only these coins.
Constraints
* N is an integer between 1 and 10000 (inclusive).
* A is an integer between 0 and 1000 (inclusive).
Input
Input is given from Standard Input in the following format:
N
A
Output... | a = int(input())
b = int(input())
print("Yes" if (a % 500 <= b) else "No")
| {
"input": [
"2763\n0",
"2018\n218",
"37\n514",
"2763\n1",
"2018\n113",
"37\n308",
"2763\n2",
"2018\n111",
"37\n135",
"2763\n-1",
"2018\n101",
"37\n244",
"2763\n-2",
"2018\n001",
"37\n290",
"2763\n-3",
"2018\n011",
"37\n381",
"2763\n-4",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
E869120 has A 1-yen coins and infinitely many 500-yen coins.
Determine if he can pay exactly N yen using only these coins.
Constraints
* N is an integer between 1 and 10000 (inclusi... |
p03592 CODE FESTIVAL 2017 qual A - fLIP_15816 | We have a grid with N rows and M columns of squares. Initially, all the squares are white.
There is a button attached to each row and each column. When a button attached to a row is pressed, the colors of all the squares in that row are inverted; that is, white squares become black and vice versa. When a button attach... | N,M,K = map(int, input().split())
for i in range(N+1):
for j in range(M+1):
if j*(N-i)+i*(M-j) == K:
print('Yes')
exit()
print('No') | {
"input": [
"2 2 2",
"2 2 1",
"7 9 20",
"3 5 8",
"4 2 2",
"4 2 1",
"7 9 8",
"2 5 8",
"6 2 2",
"7 17 8",
"1 5 8",
"2 3 2",
"7 17 5",
"2 1 8",
"2 3 0",
"0 17 5",
"2 2 8",
"2 0 0",
"0 12 5",
"2 0 -1",
"0 12 3",
"0 12 1",
"0 13 1... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We have a grid with N rows and M columns of squares. Initially, all the squares are white.
There is a button attached to each row and each column. When a button attached to a row is ... |
p03749 AtCoder Grand Contest 013 - Placing Squares_15819 | Joisino has a bar of length N, which has M marks on it. The distance from the left end of the bar to the i-th mark is X_i.
She will place several squares on this bar. Here, the following conditions must be met:
* Only squares with integral length sides can be placed.
* Each square must be placed so that its bottom si... | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,M,*X = map(int,read().split())
MOD = 10 ** 9 + 7
def mult(a,b,c,d,e,f):
# (a+bx+cx^2)(d+ex+fx^2) modulo 1-4x+2x^2-x^3
a,b,c,d,e = a*d,a*e+b*d,a*f+b*e+c*d,b*f+c*e,c*f
b += e; c -= 4*e; d +... | {
"input": [
"1000000000 0",
"10 9\n1 2 3 4 5 6 7 8 9",
"5 2\n2 3",
"3 1\n2",
"5 0\n2 3",
"3 1\n1",
"1 0\n2 3",
"3 0\n1",
"1000100000 0",
"2 0\n3 3",
"0000100000 0",
"1000101000 0",
"10 0\n2 11",
"6 0\n9 3",
"4 1\n2",
"10 1\n2 11",
"11 0\n9 3",
"... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Joisino has a bar of length N, which has M marks on it. The distance from the left end of the bar to the i-th mark is X_i.
She will place several squares on this bar. Here, the follo... |
p03913 CODE FESTIVAL 2016 Final - Cookies_15823 | Rng is baking cookies.
Initially, he can bake one cookie per second.
He can also eat the cookies baked by himself. When there are x cookies not yet eaten, he can choose to eat all those cookies. After he finishes eating those cookies, the number of cookies he can bake per second becomes x. Note that a cookie always n... | N,A=map(int,input().split())
ans=N
for i in range(-10,10):
x=int(N**.5)+i
if x>0:
test=x+A+(N-1)//x+1
ans=min(ans,test)
for n in range(2,41):
for i in range(2*n,int(N**(1/n))+1000):
test=i+n*A
q=i//n
r=i%n
prod=pow(q,n-r)*pow(q+1,r)
test+=(N-1)//pro... | {
"input": [
"1000000000000 1000000000000",
"8 1",
"1000000000000 1000000100000",
"9 1",
"7 0",
"1000010000000 1000100100001",
"1000110000000 1000100100001",
"13 1",
"1000100000000 1000100100001",
"13 0",
"1000101000000 1000110100011",
"12 -1",
"0000101000000 100011... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Rng is baking cookies.
Initially, he can bake one cookie per second.
He can also eat the cookies baked by himself. When there are x cookies not yet eaten, he can choose to eat all t... |
p00015 National Budget_15827 | A country has a budget of more than 81 trillion yen. We want to process such data, but conventional integer type which uses signed 32 bit can represent up to 2,147,483,647.
Your task is to write a program which reads two integers (more than or equal to zero), and prints a sum of these integers.
If given integers or t... | p = int(input())
for j in range(p):
a, b = int(input()), int(input())
x = str(a+b)
print("overflow" if len(x)>80 else a+b) | {
"input": [
"6\n1000\n800\n9999999999999999999999999999999999999999\n1\n99999999999999999999999999999999999999999999999999999999999999999999999999999999\n1\n99999999999999999999999999999999999999999999999999999999999999999999999999999999\n0\n10000000000000000000000000000000000000000000000000000000000000000000000... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A country has a budget of more than 81 trillion yen. We want to process such data, but conventional integer type which uses signed 32 bit can represent up to 2,147,483,647.
Your task... |
p00147 Fukushimaken_15831 | "Fukusekiken" is a popular ramen shop where you can line up. But recently, I've heard some customers say, "I can't afford to have vacant seats when I enter the store, even though I have a long waiting time." I'd like to find out why such dissatisfaction occurs, but I'm too busy to check the actual procession while the ... | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0147
"""
import sys
from sys import stdin
from heapq import heappop, heappush
from collections import deque
input = stdin.readline
class Seat():
def __init__(self, n):
self.seat = '_' * n
def get(self, num):
... | {
"input": [
"5\n6\n7\n8",
"5\n12\n7\n8",
"5\n12\n12\n8",
"5\n12\n12\n13",
"5\n24\n12\n13",
"5\n24\n18\n13",
"5\n24\n34\n13",
"5\n25\n34\n13",
"5\n25\n23\n13",
"5\n25\n27\n13",
"5\n24\n27\n13",
"5\n24\n27\n2",
"5\n24\n37\n2",
"5\n16\n37\n2",
"5\n23\n37\n2",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
"Fukusekiken" is a popular ramen shop where you can line up. But recently, I've heard some customers say, "I can't afford to have vacant seats when I enter the store, even though I ha... |
p00298 Mighty Man_15834 | There was a powerful school where powerful people gathered. At the athletic meet of the powerful school, powerful people march in a formation.
While the powerhouses always want to show off their power, most of them don't want to walk on their own. So I thought that some of them would be at the bottom, and a lot of peo... | import sys
f = sys.stdin
n = int(f.readline())
s = [list(map(int, line.split())) for line in f]
p = [[i==j for j in range(n + 1)] for i in range(n + 1)]
c = [0] + [c for c,w in s]
sum_w = [0] + [w for c,w in s]
for i in range(1, len(sum_w)):
sum_w[i] += sum_w[i - 1]
for length in range(n):
for i in range... | {
"input": [
"3\n150 120\n100 50\n80 100",
"3\n156 120\n100 50\n80 100",
"3\n52 5\n100 85\n37 000",
"3\n19 5\n000 49\n43 010",
"3\n156 120\n100 50\n80 000",
"3\n156 159\n100 50\n80 000",
"3\n156 11\n100 50\n80 000",
"3\n156 22\n100 50\n80 000",
"3\n156 22\n100 50\n152 000",
"3\... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There was a powerful school where powerful people gathered. At the athletic meet of the powerful school, powerful people march in a formation.
While the powerhouses always want to sh... |
p00468 Party_15837 | problem
You decide to invite your friends of the school and your friends of a friend to the Christmas party. The number of students in your school is n, and each student is assigned a number from 1 to n. Your number is 1. You have a list of who and who are your friends. Based on this list, create a program that asks f... | while True:
n=int(input())
m=int(input())
if n==0:
break
a=[None for _ in range(m)]
b=[None for _ in range(m)]
friend = set()
friend1=set()
friend2=set()
for i in range(m):
a[i],b[i] = list(map(int, input().split()))
if a[i] ==1:
friend.add(b[i])
... | {
"input": [
"6\n5\n1 2\n1 3\n3 4\n2 3\n4 5\n6\n5\n2 3\n3 4\n4 5\n5 6\n2 5\n0\n0",
"6\n5\n1 2\n1 3\n3 4\n2 3\n4 5\n6\n5\n2 3\n3 4\n4 5\n5 6\n2 6\n0\n0",
"6\n5\n1 2\n1 3\n3 4\n2 3\n4 5\n6\n5\n2 3\n3 4\n1 5\n5 6\n2 6\n0\n0",
"6\n5\n1 2\n1 3\n3 5\n2 3\n4 5\n6\n5\n2 3\n3 4\n1 5\n6 6\n2 6\n0\n0",
"6\n5... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
problem
You decide to invite your friends of the school and your friends of a friend to the Christmas party. The number of students in your school is n, and each student is assigned ... |
p00660 High and Low Cube_15840 | I came to the summer festival with the elementary school students in my neighborhood. To put it bluntly, it plays the role of a guardian, but the smell of yakisoba and takoyaki in the store, and the sound of fireworks that can be heard from time to time, are still exciting even at this age. But today I have to keep an ... | class Surface:
def __init__(self, mp):
self.mp = mp
def mirror(self):
for y in range(5):
self.mp[y] = self.mp[y][::-1]
def mirror_ud(self):
for y in range(2):
self.mp[y], self.mp[4 - y] = self.mp[4 - y], self.mp[y]
def spin90(self):
new_mp = [[N... | {
"input": [
".......#######......................#######..............\n.......#.....#......................#..-..#..............\n.......#.|...#......................#.|.|.#..............\n.......#.....#......................#..-..#..............\n.......#.|...#......................#.|...#..............\n........ | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
I came to the summer festival with the elementary school students in my neighborhood. To put it bluntly, it plays the role of a guardian, but the smell of yakisoba and takoyaki in the... |
p00803 Starship Hakodate-maru_15844 | The surveyor starship Hakodate-maru is famous for her two fuel containers with unbounded capacities. They hold the same type of atomic fuel balls.
There, however, is an inconvenience. The shapes of the fuel containers #1 and #2 are always cubic and regular tetrahedral respectively. Both of the fuel containers should b... | ans = [] # 答え
while True:
N = int(input())
if not N:
break
now_cube = int(N ** (1 / 3 + 0.000001))
now_pyramid = 0
tmp_ans = now_cube ** 3
# 立方体の一辺を小さくしていく、立方体の辺ごとに四角錐の一辺の長さを求め、容量を求める
for i in range(now_cube, -1, -1):
while True:
# もし次の値が最大容量を超えるならば
... | {
"input": [
"100\n64\n50\n20\n151200\n0",
"100\n84\n50\n20\n151200\n0",
"100\n84\n50\n20\n150323\n0",
"100\n160\n50\n20\n150323\n0",
"100\n64\n50\n17\n151200\n0",
"100\n50\n50\n20\n151200\n0",
"100\n63\n50\n20\n150323\n0",
"100\n5\n50\n17\n151200\n0",
"100\n50\n74\n20\n151200\n0",... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The surveyor starship Hakodate-maru is famous for her two fuel containers with unbounded capacities. They hold the same type of atomic fuel balls.
There, however, is an inconvenience... |
p01337 The Number of the Real Roots of a Cubic Equation_15850 | Description
Since the cubic equation: ax ^ 3 + bx ^ 2 + cx + d = 0 is given, please check the number of positive real roots and the number of negative real roots, respectively.
The number of roots shall be counted including the multiple roots.
Input
The input consists of multiple test cases, and the number is rec... | n=int(input())
def f(a,b,c,d):
return lambda x:a*x**3+b*x**2+c*x+d
for i in range(n):
a,b,c,d=map(int,input().split())
fx=f(a,b,c,d)
D=b**2-3*a*c
if D<=0 :
if d==0:
pl=mi=0
elif (a>0 and d<0) or (a<0 and d>0):
pl,mi=1,0
elif (a<0 and d<0) or (a>0 and d... | {
"input": [
"2\n1 3 3 1\n-10 0 0 0",
"2\n1 3 3 1\n-10 0 0 1",
"2\n1 4 3 1\n-14 0 0 1",
"2\n1 3 5 1\n-10 0 0 0",
"2\n1 3 9 1\n-10 0 1 0",
"2\n1 4 3 0\n-1 0 1 1",
"2\n1 1 3 1\n-10 -1 0 0",
"2\n1 4 3 0\n-1 -1 1 1",
"2\n1 4 3 0\n-1 0 0 0",
"2\n1 4 3 0\n-1 0 1 0",
"2\n2 4 3 0\n... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Description
Since the cubic equation: ax ^ 3 + bx ^ 2 + cx + d = 0 is given, please check the number of positive real roots and the number of negative real roots, respectively.
The ... |
p01504 AYBABTU_15853 | There is a tree that has n nodes and n-1 edges. There are military bases on t out of the n nodes. We want to disconnect the bases as much as possible by destroying k edges. The tree will be split into k+1 regions when we destroy k edges. Given the purpose to disconnect the bases, we only consider to split in a way that... | import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve(t):
N, T, K = map(int, readline().split())
if N == T == K == 0:
return False
G = [[] for i in range(N)]
E = []
res = 0
for i in range(N-1):
a, b, c = map(int, readline().split())
res += c
... | {
"input": [
"2 2 1\n1 2 1\n1\n2\n4 3 2\n1 2 1\n1 3 2\n1 4 3\n2\n3\n4\n0 0 0",
"2 2 0\n1 2 1\n1\n2\n4 3 2\n1 2 1\n1 3 2\n1 4 3\n2\n3\n4\n0 0 0",
"2 2 1\n1 2 1\n1\n2\n4 3 2\n1 2 1\n1 3 2\n1 4 2\n2\n3\n4\n0 0 0",
"2 2 1\n1 2 1\n1\n2\n4 3 2\n1 2 1\n1 3 4\n1 4 3\n2\n3\n4\n0 0 0",
"2 2 0\n1 2 1\n1\n2\n... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is a tree that has n nodes and n-1 edges. There are military bases on t out of the n nodes. We want to disconnect the bases as much as possible by destroying k edges. The tree w... |
p01819 Where is the Boundary_15857 | Example
Input
2 1
WE
Output
1 2 | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]
def LI(): return [int(x) for x in sys.stdi... | {
"input": [
"2 1\nWE",
"3 1\nWE",
"3 0\nWE",
"1 1\nWE",
"1 0\nWE",
"2 0\nWE",
"4 0\nWE",
"3 0\nEW",
"1 0\nEW",
"2 1\nEW",
"4 0\nEW",
"5 0\nEW",
"1 0\nEX",
"4 0\nFW",
"3 0\nFW",
"2 0\nFW",
"2 0\nWF",
"1 1\nWD",
"1 0\nVE",
"2 0\nEW",
"... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Example
Input
2 1
WE
Output
1 2
### Input:
2 1
WE
### Output:
1 2
### Input:
3 1
WE
### Output:
1 2
### Code:
import math,string,itertools,fractions,heapq,collections,re,arra... |
p02101 Let's Go To School_15862 | Problem
Gaccho loses motivation as the final exam approaches and often misses school.
There are N days left until the final exam.
Gaccho's motivation on day i is Xi, and the motivation needed to go to school on day i is Yi.
Gaccho goes to school only on days when Xi ≥ Yi.
Haji, who was worried about Gaccho, decided to... | N,P=map(int,input().split())
xs=[]
ys=[]
dp=[[[1e9 for i in range(N+1)] for j in range(N+1)] for k in range(N+1)]
memo=[[0 for i in range(N+1)] for j in range(N+1)]
for i in range(N):
x,y=map(int,input().split())
xs.append(x)
ys.append(y)
for start in range(N):
preuse=0
for now in range(start,N+1):... | {
"input": [
"5 5\n1 1\n1 2\n1 2\n1 3\n1 3",
"3 10\n1 6\n5 10\n0 5",
"6 5\n1 1\n1 2\n1 2\n1 3\n1 3",
"3 10\n1 9\n5 10\n0 5",
"3 7\n1 9\n5 10\n0 5",
"6 5\n0 1\n1 2\n1 2\n2 3\n1 3",
"3 18\n1 6\n5 5\n0 5",
"0 8\n1 2\n5 20\n0 5",
"6 6\n0 0\n1 2\n2 0\n0 3\n2 2",
"6 5\n1 1\n1 2\n1 2\... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Problem
Gaccho loses motivation as the final exam approaches and often misses school.
There are N days left until the final exam.
Gaccho's motivation on day i is Xi, and the motivati... |
p02239 Breadth First Search_15865 | Write a program which reads an directed graph $G = (V, E)$, and finds the shortest distance from vertex $1$ to each vertex (the number of edges in the shortest path). Vertices are identified by IDs $1, 2, ... n$.
Constraints
* $1 \leq n \leq 100$
Input
In the first line, an integer $n$ denoting the number of vertic... | import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque
def resolve():
n = int(input())
ukv = [list(map(int, input().split())) for _ in range(n)]
dist = [-1]*n
que = deque()
que.append(0)
dist[0] = 0
while len(que)>0:
v = que.popleft()
for i... | {
"input": [
"4\n1 2 2 4\n2 1 4\n3 0\n4 1 3",
"4\n1 2 1 4\n2 1 4\n3 0\n4 1 3",
"4\n1 2 1 4\n2 1 4\n3 0\n4 1 4",
"4\n1 2 2 4\n2 1 4\n3 0\n4 1 1",
"4\n1 2 2 4\n2 1 1\n3 0\n4 1 3",
"4\n1 2 1 1\n2 1 4\n3 0\n4 1 4",
"4\n1 2 2 1\n2 1 1\n3 0\n4 1 3",
"4\n1 2 1 4\n3 1 4\n3 0\n4 1 2",
"4\n1... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Write a program which reads an directed graph $G = (V, E)$, and finds the shortest distance from vertex $1$ to each vertex (the number of edges in the shortest path). Vertices are ide... |
p02385 Dice III_15869 | Write a program which reads the two dices constructed in the same way as Dice I, and determines whether these two dices are identical. You can roll a dice in the same way as Dice I, and if all integers observed from the six directions are the same as that of another dice, these dices can be considered as identical.
Co... | roll_dict = dict(E = (3, 1, 0, 5, 4, 2), W = (2, 1, 5, 0, 4, 3), S = (4, 0, 2, 3, 5, 1), N = (1, 5, 2, 3, 0, 4))
dice1 = list(map(int, input().split()))
dice2 = list(map(int, input().split()))
dices = []
dices.append(dice1)
judge = False
for i in "EWSN":
dice = dices[0]
new_dice = []
for j in range(6):
new... | {
"input": [
"1 2 3 4 5 6\n6 5 4 3 2 1",
"1 2 3 4 5 6\n6 2 4 3 5 1",
"1 2 3 2 5 6\n6 5 4 3 2 1",
"1 2 3 2 5 6\n6 1 4 3 2 1",
"1 2 3 2 5 6\n6 0 4 3 2 1",
"1 2 3 2 5 6\n6 0 4 3 4 1",
"1 2 3 2 7 6\n6 0 4 3 4 1",
"1 2 3 2 7 3\n6 0 4 3 4 1",
"1 2 2 2 7 6\n6 0 4 3 4 1",
"1 2 2 2 7 9\... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Write a program which reads the two dices constructed in the same way as Dice I, and determines whether these two dices are identical. You can roll a dice in the same way as Dice I, a... |
1000_B. Light It Up_15879 | Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ... | n,M=map(int,input().split())
s=[int(x) for x in input().split()]
ss=[s[0]]
so=[]
se=[]
for i in range(n-1):
ss.append(s[i+1]-s[i])
ss.append(M-s[n-1])
if (n+1)%2==1:
for i in range(int(n/2)):
so.append(ss[2*i])
se.append(ss[2*i+1])
so.append(ss[n])
sss=sum(so)
a=0
b=sum(se)
... | {
"input": [
"2 7\n3 4\n",
"2 12\n1 10\n",
"3 10\n4 6 7\n",
"1 10\n2\n",
"2 5\n1 3\n",
"1 8\n1\n",
"3 90591\n90579 90580 90581\n",
"1 10000000\n1\n",
"9 20\n5 9 11 12 14 15 16 17 19\n",
"3 4\n1 2 3\n",
"5 16\n1 2 3 4 5\n",
"7 17\n1 5 9 10 11 14 16\n",
"2 4\n1 3\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at m... |
1025_C. Plasticine zebra_15883 | Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras.
Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ... | import sys
s = input()
n = len(s)
if n == 1:
print(1)
sys.exit(0)
for i in range(n-1):
if s[i] == s[i+1] and (s[n-1] != s[0]):
x = s[:i+1]
y = s[i+1:n]
s = x[::-1] + y[::-1]
ans = 1
mx = 1
for i in range(1, n):
if s[i] != s[i-1]:
mx += 1
else:
ans = max(mx, ans)
mx = 1
print(max(mx, ans))
| {
"input": [
"bwwwbwwbw\n",
"bwwbwwb\n",
"bwbw\n",
"www\n",
"wbwbwbwbwb\n",
"bwbwbbbbwb\n",
"bww\n",
"bwb\n",
"bwbwwwwwwwwbwb\n",
"wbwbwb\n",
"wbwb\n",
"bwwwwwbbbbbw\n",
"bwbwbw\n",
"wbbwbw\n",
"bbbbwbwwbbwwwwwbbbwb\n",
"wwwwb\n",
"bw\n",
"bwbwbw... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras.
... |
1068_E. Multihedgehog_15888 | Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to make himself k-multihedgehog.
Let us define k-multihedgehog as fol... | from collections import deque
n, k = list(map(int, input().split()))
G = [set() for _ in range(n + 1)]
q, nq = deque(), deque()
for _ in range(n - 1):
u, v = list(map(int, input().split()))
G[u].add(v)
G[v].add(u)
for u in range(1, n + 1):
if len(G[u]) == 1:
q.append(u)
step = 0
removed = ... | {
"input": [
"3 1\n1 3\n2 3\n",
"14 2\n1 4\n2 4\n3 4\n4 13\n10 5\n11 5\n12 5\n14 5\n5 13\n6 7\n8 6\n13 6\n9 6\n",
"2 1\n1 2\n",
"8 1\n8 2\n2 5\n5 1\n7 2\n2 4\n3 5\n5 6\n",
"5 1\n4 1\n3 1\n5 1\n1 2\n",
"25 2\n1 2\n1 3\n1 4\n2 5\n2 6\n2 7\n3 8\n3 9\n3 10\n4 11\n4 12\n4 13\n4 14\n14 15\n14 16\n14... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices ... |
1090_D. Similar Arrays_15892 | Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great... | # SHRi GANESHA author: Kunal Verma #
import os
import sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from functools import reduce
from io import BytesIO, IOBase
from itertools import combinations
from math import gcd, inf, sqrt, ceil, floor
#sys.setrecursionlimit(2*... | {
"input": [
"4 3\n1 2\n1 3\n2 4\n",
"3 1\n1 2\n",
"1 0\n",
"3 0\n",
"5 10\n4 2\n1 5\n5 2\n1 4\n2 3\n4 3\n1 2\n5 3\n5 4\n3 1\n",
"2 1\n2 1\n",
"10 40\n8 3\n6 8\n7 1\n9 10\n1 3\n2 8\n3 7\n1 8\n8 10\n4 5\n5 1\n10 3\n9 7\n4 6\n5 3\n2 3\n3 9\n9 8\n7 8\n4 1\n1 6\n4 7\n7 6\n6 10\n6 9\n2 6\n5 10\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the e... |
110_A. Nearly Lucky Number_15896 | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d... | # your code goes here
n=int(input())
n=str(n)
k=0
for i in range(len(n)):
if int(n[i]) == 4 or int(n[i]) == 7:
k=k+1
if k==4 or k==7:
print('YES')
else:
print('NO') | {
"input": [
"40047\n",
"7747774\n",
"1000000000000000000\n",
"34777745021000000\n",
"9847745885202111\n",
"123456789123456789\n",
"444444444444444444\n",
"777777777777777\n",
"7777777\n",
"4444000111222333\n",
"1\n",
"7777\n",
"4744000695826\n",
"400000000474\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, ... |
1139_D. Steps to One_15900 | Vivek initially has an empty array a and some integer constant m.
He performs the following algorithm:
1. Select a random integer x uniformly in range from 1 to m and append it to the end of a.
2. Compute the greatest common divisor of integers in a.
3. In case it equals to 1, break
4. Otherwise, return to... | import sys
factors = []
dp = []
mod = (int)(1e9+7)
inv_m = 0
def sub(a, b):
a -= b
a %= mod
if a < 0: a += mod
return a
def add(a, b): return (a + b) % mod
def mul(a, b): return (a * b) % mod
def pow(a, b):
if b == 0:
return 1
if b & 1:
return mul(a, pow(a, b - 1))
else:
aux = pow(a, b >> 1)
return ... | {
"input": [
"4\n",
"2\n",
"1\n",
"677\n",
"9\n",
"30238\n",
"7635\n",
"47539\n",
"14\n",
"2048\n",
"5714\n",
"20\n",
"78088\n",
"93378\n",
"11\n",
"8\n",
"91402\n",
"86632\n",
"64444\n",
"80555\n",
"91568\n",
"75232\n",
"2864... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vivek initially has an empty array a and some integer constant m.
He performs the following algorithm:
1. Select a random integer x uniformly in range from 1 to m and append it to... |
1157_D. N Problems During K Days_15904 | Polycarp has to solve exactly n problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in k days. It means that Polycarp has exactly k days for training!
Polycarp doesn't want to procrastinate, so he wants to sol... |
"""
b[i] = a[i] - i - 1
b[i] <= b[i+1] < 2b[i] + i - 1
sum(b) == r
"""
def solve(n, k):
r = n - k*(k+1)//2
if r < 0:
return None
b0 = r//k
r -= b0*k
seq = [None]*k
seq[0] = b0
b = b0
for i in range(1,k):
bn = b*2 + i - 1
h = r//(k-i)
if h > 0:
... | {
"input": [
"9 4\n",
"8 3\n",
"1 1\n",
"26 6\n",
"3 4\n",
"2 4\n",
"2 3\n",
"800019998 40000\n",
"77792 2\n",
"123456789 13456\n",
"147268968 2\n",
"4 3\n",
"7 2\n",
"2 1\n",
"7 3\n",
"999961559 44720\n",
"3 2\n",
"3 3\n",
"20492 2\n",
"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarp has to solve exactly n problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it ... |
117_A. Elevator_15908 | And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator... | n, m = map(int, input().split())
k = 2 * (m - 1)
for i in range(n):
s, f, t = map(int, input().split())
d = t % k
if s < f: print(k * (s <= d) + f - 1 + t - d)
elif f < s: print(k * (d + s > k + 1) + k + 1 - f + t - d)
else: print(t) | {
"input": [
"5 5\n1 5 4\n1 3 1\n1 3 4\n3 1 5\n4 2 5\n",
"7 4\n2 4 3\n1 2 0\n2 2 0\n1 2 1\n4 3 5\n1 2 2\n4 2 0\n",
"3 4\n2 4 7\n3 3 1\n2 2 9\n",
"8 5\n2 2 91\n5 1 97\n5 1 36\n5 4 19\n2 5 50\n4 2 1\n1 4 9\n3 2 32\n",
"2 100000000\n2 1 3\n99999999 100000000 100000000\n",
"5 5\n1 3 4\n4 4 2\n3 2 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themse... |
1198_B. Welfare State_15912 | There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the governm... | n = int(input())
a = list(map(int,input().split()))
mark=[1 for i in range(n)]
query = []
q = int(input())
m = -1
for i in range(q):
next = list(map(int,input().split()))
if next[0]==2:
m = max(m,next[1])
query.append(next)
mx = 0
for i in range(n):
if a[i]<m:
a[i]=m
for i in range(q-1,-... | {
"input": [
"4\n1 2 3 4\n3\n2 3\n1 2 2\n2 1\n",
"5\n3 50 2 1 10\n3\n1 2 0\n2 8\n1 3 20\n",
"10\n1 2 3 4 5 6 7 8 9 10\n10\n2 1\n2 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n",
"10\n7 9 4 4 7 6 3 7 9 8\n10\n1 3 2\n1 10 5\n1 5 3\n1 5 2\n1 2 9\n1 2 9\n1 2 10\n1 5 7\n1 6 10\n1 10 9\n",
"4\n1 2 3 4\n2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or ear... |
1215_A. Yellow Cards_15916 | The final match of the Berland Football Cup has been held recently. The referee has shown n yellow cards throughout the match. At the beginning of the match there were a_1 players in the first team and a_2 players in the second team.
The rules of sending players off the game are a bit different in Berland football. If... | a1=int(input())
a2=int(input())
k1=int(input())
k2=int(input())
n=int(input())
m1=n - (k1-1)*a1 - (k2-1)*a2
if m1<0:
m1=0
m2=0
if a1*k1 + a2*k2 <=n:
m2=a1+a2
elif k1<=k2:
if n//k1 <= a1:
m2=n//k1
else:
m2=m2+a1
n=n-a1*k1
m2=m2 + min(a2, n//k2)
elif k2 < k1:
if n... | {
"input": [
"3\n1\n6\n7\n25\n",
"2\n3\n5\n1\n8\n",
"6\n4\n9\n10\n89\n",
"8\n4\n1\n2\n9\n",
"398\n235\n999\n663\n552924\n",
"8\n8\n3\n7\n61\n",
"4\n7\n1\n10\n60\n",
"421\n702\n250\n334\n339096\n",
"1000\n1000\n1000\n1000\n1542000\n",
"1000\n1000\n1000\n1000\n2000000\n",
"69... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The final match of the Berland Football Cup has been held recently. The referee has shown n yellow cards throughout the match. At the beginning of the match there were a_1 players in ... |
1238_C. Standard Free2play_15920 | You are playing a game where your character should overcome different obstacles. The current problem is to come down from a cliff. The cliff has height h, and there is a moving platform on each height x from 1 to h.
Each platform is either hidden inside the cliff or moved out. At first, there are n moved out platforms... | n= int(input())
for z in range(n):
h, am = map(int, input().split())
arr = list(map(int, input().split()))
ch = h
i = 1
ac = 0
while i < am:
if ch - arr[i] >= 2:
ch = arr[i] + 1
elif i < am - 1 and arr[i + 1] == ch - 2 or ch == 2:
ch -= 2
i += ... | {
"input": [
"4\n3 2\n3 1\n8 6\n8 7 6 5 3 2\n9 6\n9 8 5 4 3 1\n1 1\n1\n",
"1\n3 2\n3 2\n",
"28\n8 4\n8 7 6 3\n8 5\n8 7 6 3 1\n8 5\n8 7 6 3 2\n8 6\n8 7 6 3 2 1\n8 4\n8 7 6 4\n8 5\n8 7 6 4 1\n8 5\n8 7 6 4 2\n8 6\n8 7 6 4 2 1\n8 5\n8 7 6 4 3\n8 6\n8 7 6 4 3 1\n8 6\n8 7 6 4 3 2\n8 7\n8 7 6 4 3 2 1\n8 4\n8 7 6... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are playing a game where your character should overcome different obstacles. The current problem is to come down from a cliff. The cliff has height h, and there is a moving platfo... |
1256_D. Binary String Minimizing_15924 | You are given a binary string of length n (i. e. a string consisting of n characters '0' and '1').
In one move you can swap two adjacent characters of the string. What is the lexicographically minimum possible string you can obtain from the given one if you can perform no more than k moves? It is possible that you do ... | '''q=int(input())
for i in range(q):
n,k=map(int,input().split())
a=input()
b=[]
indices=[]
for j in range(n):
if(a[j]=='0'):
indices.append(j)
b.append(a[j])
e=0
t=0
while(k>0 and e<=len(indices)):
if(indices[e]<=k):
b[indices[e]],b[t]=b[t],b[indices[e]]
k=k-indices[e]
t=t+1
else:
ar=... | {
"input": [
"3\n8 5\n11011010\n7 9\n1111100\n7 11\n1111100\n",
"2\n8 5\n11011010\n7 9\n1111100\n",
"1\n2 1\n00\n",
"2\n8 5\n11011010\n7 9\n1011100\n",
"3\n8 5\n11011000\n7 9\n1111100\n7 11\n1111100\n",
"2\n8 5\n01011010\n7 9\n1011100\n",
"2\n8 1\n01011010\n7 9\n1011100\n",
"2\n8 5\n11... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a binary string of length n (i. e. a string consisting of n characters '0' and '1').
In one move you can swap two adjacent characters of the string. What is the lexicog... |
127_D. Password_15928 | Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string s, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the t... | from sys import stdin
def findpass(s):
arr = suff_array(s)
n = len(s)
maxidx = arr[n - 1]
valid = False
for i in range(n - 1):
if arr[i] == maxidx:
valid = True
break
if not valid:
maxidx = arr[maxidx - 1]
if maxidx == 0:
return "Just a le... | {
"input": [
"abcdabc\n",
"fixprefixsuffix\n",
"aba\n",
"aaaaabaaaa\n",
"papapapap\n",
"aaa\n",
"abc\n",
"kwuaizneqxfflhmyruotjlkqksinoanvkyvqptkkntnpjdyzicceelgooajdgpkneuhyvhdtmasiglplajxolxovlhkwuaizneqx\n",
"aab\n",
"btbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwyts... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A ... |
12_C. Fruits_15932 | The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times.
When he came to the fruit stall of Ash... | n, m = input().split(" ")
n = int(n)
m = int(m)
priceList = []
res = []
least = 0
most = 0
fruitCount = 0
seq = input().split(" ")
for i in seq:
priceList.append(int(i))
item = []
count = []
for i in range(m):
inp = input()
if inp in item:
count[item.index(inp)] += 1
else:
item.app... | {
"input": [
"5 3\n4 2 1 10 5\napple\norange\nmango\n",
"6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange\n",
"3 1\n14 26 22\naag\n",
"3 3\n4 2 3\nwivujdxzjm\nawagljmtc\nwivujdxzjm\n",
"1 4\n1\nu\nu\nu\nu\n",
"12 18\n42 44 69 16 81 64 12 68 70 75 75 67\nfm\nqamklzfmrjnqgdspwfasjnplg... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If ... |
1323_E. Instant Noodles_15935 | Wu got hungry after an intense training session, and came to a nearby store to buy his favourite instant noodles. After Wu paid for his purchase, the cashier gave him an interesting task.
You are given a bipartite graph with positive integers in all vertices of the right half. For a subset S of vertices of the left ha... | from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
M = mod = 10**9 + 7
def factors(n):return sorted(set(reduce(list.__... | {
"input": [
"3\n2 4\n1 1\n1 1\n1 2\n2 1\n2 2\n\n3 4\n1 1 1\n1 1\n1 2\n2 2\n2 3\n\n4 7\n36 31 96 29\n1 2\n1 3\n1 4\n2 2\n2 4\n3 1\n4 3\n",
"1\n100 27\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Wu got hungry after an intense training session, and came to a nearby store to buy his favourite instant noodles. After Wu paid for his purchase, the cashier gave him an interesting t... |
1342_D. Multiple Testcases_15939 | So you decided to hold a contest on Codeforces. You prepared the problems: statements, solutions, checkers, validators, tests... Suddenly, your coordinator asks you to change all your tests to multiple testcases in the easiest problem!
Initially, each test in that problem is just an array. The maximum size of an array... | import sys
from collections import defaultdict
from bisect import bisect_left
input = sys.stdin.readline
'''
n, m = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
S = input().strip()
for CASES in range(int(input())):
'''
inf = 100000000000000000 # 1e17
mod = 998244353
'''
# example inp... | {
"input": [
"6 10\n5 8 1 10 8 7\n6 6 4 4 3 2 2 2 1 1\n",
"5 1\n1 1 1 1 1\n5\n",
"5 1\n1 1 1 1 1\n1\n",
"4 3\n1 2 2 3\n4 1 1\n",
"1 10\n10\n1 1 1 1 1 1 1 1 1 1\n",
"1 1\n1\n1\n",
"10 2\n1 2 2 2 2 2 2 2 2 2\n10 1\n",
"10 20\n20 1 15 17 11 2 15 3 16 3\n10 9 9 9 8 8 8 7 7 7 7 6 6 4 4 4 3 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
So you decided to hold a contest on Codeforces. You prepared the problems: statements, solutions, checkers, validators, tests... Suddenly, your coordinator asks you to change all your... |
1364_D. Ehab's Last Corollary_15943 | Given a connected undirected graph with n vertices and an integer k, you have to either:
* either find an independent set that has exactly ⌈k/2⌉ vertices.
* or find a simple cycle of length at most k.
An independent set is a set of vertices such that no two of them are connected by an edge. A simple cycle is a... | import io
import os
from collections import Counter, defaultdict, deque
import sys
sys.setrecursionlimit(10 ** 5 + 1)
from types import GeneratorType
# https://github.com/cheran-senthil/PyRival/blob/master/pyrival/misc/bootstrap.py
def bootstrap(f, stack=[]):
def wrappedfunc(*args, **kwargs):
if stack:
... | {
"input": [
"4 5 3\n1 2\n2 3\n3 4\n4 1\n2 4\n",
"5 4 5\n1 2\n1 3\n2 4\n2 5\n",
"4 4 3\n1 2\n2 3\n3 4\n4 1\n",
"4 6 3\n1 2\n2 3\n3 4\n4 1\n1 3\n2 4\n",
"6 8 5\n1 6\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5\n5 6\n",
"3 3 3\n1 2\n2 3\n3 1\n",
"5 6 5\n1 2\n2 3\n3 1\n3 4\n4 5\n5 3\n",
"6 15 3\n4 5\n4 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Given a connected undirected graph with n vertices and an integer k, you have to either:
* either find an independent set that has exactly ⌈k/2⌉ vertices.
* or find a simple cycl... |
1406_B. Maximum Product_15949 | You are given an array of integers a_1,a_2,…,a_n. Find the maximum possible value of a_ia_ja_ka_la_t among all five indices (i, j, k, l, t) (i<j<k<l<t).
Input
The input consists of multiple test cases. The first line contains an integer t (1≤ t≤ 2 ⋅ 10^4) — the number of test cases. The description of the test cases ... | import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): retu... | {
"input": [
"4\n5\n-1 -2 -3 -4 -5\n6\n-1 -2 -3 1 2 -1\n6\n-1 0 0 0 -1 -1\n6\n-9 -7 -5 -3 -2 1\n",
"1\n5\n-3000 -3000 -3000 3000 3000\n",
"4\n5\n-1 -3 -3 -4 -5\n6\n-1 -2 -3 1 2 -1\n6\n-1 0 0 0 -1 -1\n6\n-9 -7 -5 -3 -2 1\n",
"4\n5\n-1 -1 -3 -4 -5\n6\n-1 -2 -3 1 2 -1\n6\n-1 0 0 0 -1 -1\n6\n-9 -7 -5 -3 -... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an array of integers a_1,a_2,…,a_n. Find the maximum possible value of a_ia_ja_ka_la_t among all five indices (i, j, k, l, t) (i<j<k<l<t).
Input
The input consists of ... |
1427_C. The Hard Work of Paparazzi_15953 | You are a paparazzi working in Manhattan.
Manhattan has r south-to-north streets, denoted by numbers 1, 2,…, r in order from west to east, and r west-to-east streets, denoted by numbers 1,2,…,r in order from south to north. Each of the r south-to-north streets intersects each of the r west-to-east streets; the interse... | #Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threadi... | {
"input": [
"500 10\n69 477 122\n73 186 235\n341 101 145\n372 77 497\n390 117 440\n494 471 37\n522 300 498\n682 149 379\n821 486 359\n855 157 386\n",
"10 4\n1 2 1\n5 10 9\n13 8 8\n15 9 9\n",
"6 9\n1 2 6\n7 5 1\n8 5 5\n10 3 1\n12 4 4\n13 6 2\n17 6 6\n20 1 4\n21 5 4\n",
"10 1\n11 6 8\n",
"500 3\n20... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are a paparazzi working in Manhattan.
Manhattan has r south-to-north streets, denoted by numbers 1, 2,…, r in order from west to east, and r west-to-east streets, denoted by numb... |
1450_C1. Errich-Tac-Toe (Easy Version)_15957 | The only difference between the easy and hard versions is that tokens of type O do not appear in the input of the easy version.
Errichto gave Monogon the following challenge in order to intimidate him from taking his top contributor spot on Codeforces.
In a Tic-Tac-Toe grid, there are n rows and n columns. Each cell ... |
def disti(b,ind):
a=[]
for i in b:
h=[]
for j in i: h.append(j)
a.append(h)
ans=0
id=0
for i in range(n):
start = ind[id%3]
id+=1
for j in range(start ,n,3):
left=''
right=''
up=''
down=''
mid1=''
mid2=''
if(j-2 >= 0): left = a[i][j-2] + a[i][j-1] + a[i][j]
if(j+2 <n ): ri... | {
"input": [
"3\n3\n.X.\nXXX\n.X.\n6\nXX.XXX\nXXXXXX\nXXX.XX\nXXXXXX\nXX.X.X\nXXXXXX\n5\nXXX.X\n.X..X\nXXX.X\n..X..\n..X..\n",
"1\n6\nXXXXXX\nXXXXXX\nXX..XX\nXX..XX\nXXXXXX\nXXXXXX\n",
"3\n3\n.X.\nXXX\n.X.\n6\nXX.XXX\nXXXXXX\nXXX.XX\nXXXXXX\nXX.X.X\nXXXXXX\n5\nXXX.X\n.X..X\nXXX.X\n..X..\n..X..\n",
"3\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The only difference between the easy and hard versions is that tokens of type O do not appear in the input of the easy version.
Errichto gave Monogon the following challenge in order... |
1474_A. Puzzle From the Future_15961 | In the 2022 year, Mike found two binary integers a and b of length n (both of them are written only by digits 0 and 1) that can have leading zeroes. In order not to forget them, he wanted to construct integer d in the following way:
* he creates an integer c as a result of bitwise summing of a and b without transfe... | for tc in range(int(input())):
n = int(input())
b = input()
a = ['' for i in range(n)]
d = ['0' for i in range(n)]
if b[0] == '0':d[0] = '1'
else:d[0] = '2'
for i in range(1,n):
if b[i] == '0':
if d[i-1] != '1':
d[i] = '1'
else:d[i] = '0'
... | {
"input": [
"5\n1\n0\n3\n011\n3\n110\n6\n111000\n6\n001011\n",
"5\n1\n0\n3\n011\n3\n110\n6\n111100\n6\n001011\n",
"5\n1\n0\n3\n011\n3\n111\n6\n111100\n6\n001011\n",
"5\n1\n0\n3\n011\n3\n110\n6\n011000\n6\n001011\n",
"5\n1\n0\n3\n011\n3\n110\n6\n011100\n6\n001011\n",
"5\n1\n0\n3\n111\n3\n110\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In the 2022 year, Mike found two binary integers a and b of length n (both of them are written only by digits 0 and 1) that can have leading zeroes. In order not to forget them, he wa... |
149_C. Division into Teams_15965 | Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the ... | import os
import sys
from io import BytesIO, IOBase
def main():
pass
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
s... | {
"input": [
"5\n2 3 3 1 1\n",
"3\n1 2 1\n",
"100\n85 50 17 89 65 89 5 20 86 26 16 21 85 14 44 31 87 31 6 2 48 67 8 80 79 1 48 36 97 1 5 30 79 50 78 12 2 55 76 100 54 40 26 81 97 96 68 56 87 14 51 17 54 37 52 33 69 62 38 63 74 15 62 78 9 19 67 2 60 58 93 60 18 96 55 48 34 7 79 82 32 58 90 67 20 50 27 15 7... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a br... |
1523_C. Compression and Expansion_15969 | <image>
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands.
A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just... | import sys
T = int(sys.stdin.readline().strip())
for t in range (0, T):
n = int(sys.stdin.readline().strip())
x = int(sys.stdin.readline().strip())
ans = [[x]]
for i in range (0, n - 1):
x = int(sys.stdin.readline().strip())
ans.append(ans[-1][:])
if x == 1:
ans[-1].a... | {
"input": [
"2\n4\n1\n1\n2\n3\n9\n1\n1\n1\n2\n2\n1\n2\n1\n2\n",
"2\n4\n1\n1\n2\n3\n9\n1\n1\n1\n2\n2\n1\n2\n1\n2\n",
"7\n1\n1\n2\n1\n1\n2\n1\n2\n3\n1\n1\n1\n3\n1\n1\n2\n3\n1\n2\n1\n3\n1\n2\n3\n",
"10\n4\n1\n1\n1\n1\n4\n1\n1\n1\n2\n4\n1\n1\n2\n1\n4\n1\n1\n2\n2\n4\n1\n1\n2\n3\n4\n1\n2\n1\n1\n4\n1\n2\n1\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
<image>
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands.
A valid nested list is any list which can b... |
155_B. Combination_15973 | Ilya plays a card game by the following rules.
A player has several cards. Each card contains two non-negative integers inscribed, one at the top of the card and one at the bottom. At the beginning of the round the player chooses one of his cards to play it. If the top of the card contains number ai, and the bottom co... | n=int(input())
arr=[]
for i in range(n):
a,b=map(int,input().split())
arr.append((b,a))
arr.sort(reverse=True)
counter=1
ans=0
i=0
while(counter and i<n):
counter-=1
counter+=arr[i][0]
ans+=arr[i][1]
i+=1
print(ans)
| {
"input": [
"2\n1 0\n2 0\n",
"3\n1 0\n2 0\n0 2\n",
"2\n0 10000\n1 0\n",
"1\n2 9999\n",
"1\n10 1\n",
"100\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 0\n0 1\n0 1\n0 1\n0 1\n0 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Ilya plays a card game by the following rules.
A player has several cards. Each card contains two non-negative integers inscribed, one at the top of the card and one at the bottom. A... |
177_C2. Party_15977 | To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friends... | from collections import defaultdict
def Root(child):
while(Parent[child]!=child):
child = Parent[child]
return child
def Union(a,b):
root_a = Root(a)
root_b = Root(b)
if(root_a!=root_b):
if(Size[root_a]<Size[root_b]):
Parent[root_a] = root_b
Size[root_... | {
"input": [
"9\n8\n1 2\n1 3\n2 3\n4 5\n6 7\n7 8\n8 9\n9 6\n2\n1 6\n7 9\n",
"7\n8\n1 2\n1 3\n1 4\n1 5\n2 4\n2 5\n3 4\n5 6\n3\n2 6\n5 7\n6 7\n",
"14\n0\n0\n",
"13\n78\n11 1\n10 6\n6 2\n10 1\n11 6\n11 3\n5 3\n8 1\n12 11\n4 2\n10 3\n13 8\n9 8\n11 7\n7 5\n11 2\n7 1\n4 1\n11 10\n8 3\n13 11\n9 6\n13 9\n12 7... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of t... |
221_D. Little Elephant and Array_15982 | The Little Elephant loves playing with arrays. He has array a, consisting of n positive integers, indexed from 1 to n. Let's denote the number with index i as ai.
Additionally the Little Elephant has m queries to the array, each query is characterised by a pair of integers lj and rj (1 ≤ lj ≤ rj ≤ n). For each query ... | 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... | {
"input": [
"7 2\n3 1 2 2 3 3 7\n1 7\n3 4\n",
"6 6\n1 2 2 3 3 3\n1 2\n2 2\n1 3\n2 4\n4 6\n1 6\n",
"1 2\n1\n1 1\n1 1\n",
"1 1\n1000000000\n1 1\n",
"6 6\n1 2 2 3 3 3\n1 2\n2 2\n1 3\n2 4\n4 6\n1 3\n",
"6 6\n1 2 2 3 2 3\n1 2\n2 2\n1 3\n2 4\n4 6\n1 6\n",
"6 6\n1 2 2 3 3 3\n1 2\n2 2\n2 3\n2 4\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The Little Elephant loves playing with arrays. He has array a, consisting of n positive integers, indexed from 1 to n. Let's denote the number with index i as ai.
Additionally the L... |
245_E. Mishap in Club_15986 | Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, ... | #Problem Set N: Collaborated with no one
n = input()
in_visit = 0
out_visit = 0
for i in range(len(n)):
if n[i] == '+':
in_visit += 1
if out_visit:
out_visit -= 1
elif n[i] == '-':
out_visit += 1
if in_visit:
in_visit -= 1
print(in_vis... | {
"input": [
"+-+-+\n",
"---",
"++\n",
"-+-\n",
"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept... |
270_C. Magical Boxes_15990 | Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.
From the top view each magical box looks like a square with side length equal to 2k (k is an integer, k ≥ 0) units. A magical box v can be put inside a... | from math import*
n = int(input())
v=0
for i in range(n):
a = [int(x)for x in input().split(' ')]
k = ceil(fabs(log(a[1],4)))
if k==0: k=1
if k+a[0]>v:
v = k+a[0]
print(v) | {
"input": [
"2\n0 3\n1 5\n",
"2\n1 10\n2 2\n",
"1\n0 4\n",
"1\n0 17\n",
"5\n1 1000000\n100 100\n101 9\n102 4\n103 8\n",
"16\n1296 2\n1568 1\n7435 2\n3660 1\n6863 2\n886 2\n2596 1\n7239 1\n6146 1\n5634 1\n3119 2\n1166 2\n7610 2\n5992 1\n630 2\n8491 2\n",
"3\n0 20\n1 18\n2 4\n",
"1\n1 1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.
From the top v... |
317_C. Balance_15996 | A system of n vessels with water is given. Several pairs of vessels are connected by tubes with transfusion mechanisms. One may transfer an integer amount of liters of water between two vessels connected by such tube (tube works in both directions). There might be multiple tubes between two vessels. Total number of tub... | read = lambda: map(int, input().split())
n, v, e = read()
adj = [[] for _ in range(n + 1)]
As = [0] + list(read())
Bs = [0] + list(read())
ans = []
for _ in range(e):
a, b = map(int, input().split())
adj[a].append(b)
adj[b].append(a)
def flow(a, b, d):
As[a] -= d
As[b] += d
ans.append((a, b, ... | {
"input": [
"2 10 1\n1 9\n5 5\n1 2\n",
"2 10 0\n5 2\n4 2\n",
"2 10 0\n4 2\n4 2\n",
"2 1000000000 2\n1000000000 999999999\n999999999 1000000000\n1 2\n2 1\n",
"1 1000000000 0\n999999999\n1000000000\n",
"1 1000000000 0\n1000000000\n1000000000\n",
"10 1 3\n0 1 0 1 0 1 0 1 0 1\n1 0 1 0 0 1 0 1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A system of n vessels with water is given. Several pairs of vessels are connected by tubes with transfusion mechanisms. One may transfer an integer amount of liters of water between t... |
341_C. Iahub and Permutations_16000 | Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotage his research work.
The girl finds an important permutation for the resea... | #lahub and Permutations
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
mod = 10**9+7
def pow(n,p,mod=mod): #繰り返し二乗法(nのp乗)
res = 1
while p > 0:
if p % 2 == 0:
n = n ** 2 % mod
p //= 2
else:
res = res * n % mod
... | {
"input": [
"5\n-1 -1 4 3 -1\n",
"6\n-1 -1 -1 -1 -1 -1\n",
"10\n4 10 -1 1 6 8 9 2 -1 -1\n",
"7\n-1 -1 4 -1 7 1 6\n",
"2\n-1 -1\n",
"8\n2 4 5 3 -1 8 -1 6\n",
"20\n-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1\n",
"7\n-1 -1 4 -1 3 1 6\n",
"5\n-1 -1 4 1 -1\n",
"10\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. ... |
388_D. Fox and Perfect Sets_16005 | Fox Ciel studies number theory.
She thinks a non-empty set S contains non-negative integers is perfect if and only if for any <image> (a can be equal to b), <image>. Where operation xor means exclusive or operation (http://en.wikipedia.org/wiki/Exclusive_or).
Please calculate the number of perfect sets consisting of ... | from math import factorial
MOD = 10**9+7
k = int(input())
bink = list(map(int, bin(k)[2:]))
N = len(bink)
# dp[i][j][k] = first i bits, j bases,
# k = 1 if maxor matches k, 0 else
dp = [[[0,0] for j in range(i+2)] for i in range(N+1)]
dp[0][0][1] = 1
for i in range(1, N+1):
for j in range(i+1):
# k = 0 ... | {
"input": [
"2\n",
"4\n",
"1\n",
"3\n",
"102513046\n",
"685146646\n",
"11\n",
"10\n",
"752887969\n",
"341796022\n",
"585325539\n",
"930971393\n",
"802030518\n",
"18\n",
"702209411\n",
"7\n",
"0\n",
"536870912\n",
"335521569\n",
"13\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Fox Ciel studies number theory.
She thinks a non-empty set S contains non-negative integers is perfect if and only if for any <image> (a can be equal to b), <image>. Where operation ... |
409_B. Mysterious Language_16009 | You are given a mysterious language (codenamed "Secret") available in "Custom Invocation" tab. Figure out what this language is and write a program which prints its name. Note that the program must be written in this language.
Input
This program has only one test (your program doesn't have to read anything).
Output
... | """====================================================================================
====================================================================================
___ _______ ___ _______ ___ ___
| /\ | | \ | | / | | | | |\ /|
| ... | {
"input": [
"1\n",
"2\n",
"0\n",
"-1\n",
"-2\n",
"-3\n",
"-6\n",
"-8\n",
"-14\n",
"-17\n",
"-30\n",
"4\n",
"8\n",
"11\n",
"19\n",
"6\n",
"3\n",
"5\n",
"10\n",
"17\n",
"-4\n",
"-5\n",
"-9\n",
"-10\n",
"9\n",
"18\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a mysterious language (codenamed "Secret") available in "Custom Invocation" tab. Figure out what this language is and write a program which prints its name. Note that th... |
436_C. Dungeons and Candies_16013 | During the loading of the game "Dungeons and Candies" you are required to get descriptions of k levels from the server. Each description is a map of an n × m checkered rectangular field. Some cells of the field contain candies (each cell has at most one candy). An empty cell is denoted as "." on the map, but if a cell ... | def put():
return map(int, input().split())
def diff(x,y):
ans = 0
for i in range(n*m):
if s[x][i]!= s[y][i]:
ans+=1
return ans
def find(i):
if i==p[i]:
return i
p[i] = find(p[i])
return p[i]
def union(i,j):
if rank[i]>rank[j]:
i,j = j,i
elif rank[... | {
"input": [
"1 1 4 1\nA\n.\nB\n.\n",
"1 3 5 2\nABA\nBBB\nBBA\nBAB\nABB\n",
"2 3 3 2\nA.A\n...\nA.a\n..C\nX.Y\n...\n",
"2 3 10 2\nABB\nABA\nAAB\nBAB\nAAA\nBBA\nBBB\nBAA\nBBB\nABB\nABA\nBBA\nBBB\nAAB\nABA\nABB\nBBA\nBAB\nBBB\nBBB\n",
"3 2 10 1\nAB\nBA\nAB\nAA\nAA\nBA\nAA\nAA\nAB\nAB\nAB\nBA\nBA\nAB... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
During the loading of the game "Dungeons and Candies" you are required to get descriptions of k levels from the server. Each description is a map of an n × m checkered rectangular fie... |
459_D. Pashmak and Parmida's problem_16017 | Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants her partner to be clever too (although he's not)! Parmida has prepared the following test problem for Pashmak.
There is a sequence a that consists of n integers a1, a2, ..., an. Let's denote f(l, r, x) the number of indic... | # 459D
import sys
from collections import Counter
class BIT():
def __init__(self, n):
self.n = n
self.tree = [0] * n
def _F(self, i):
return i & (i + 1)
def _getSum(self, r):
'''
sum on interval [0, r]
'''
result = 0
while r >= 0:
... | {
"input": [
"3\n1 1 1\n",
"5\n1 2 3 4 5\n",
"7\n1 2 1 1 2 2 1\n",
"2\n1 1\n",
"1\n1\n",
"4\n1 1 2 2\n",
"24\n1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4\n",
"5\n1 1 2 2 2\n",
"2\n1 2\n",
"2\n2 2\n",
"4\n1 1 2 0\n",
"24\n1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants her partner to be clever too (although he's not)! Parmida has prepared the following ... |
480_C. Riding in a Lift_16021 | Imagine that you are in a building that has exactly n floors. You can move between the floors in a lift. Let's number the floors from bottom to top with integers from 1 to n. Now you're on the floor number a. You are very bored, so you want to take the lift. Floor number b has a secret lab, the entry is forbidden. Howe... | def solve(n, st, k):
MOD = int(1e9 + 7)
dp = [0] * (n + 1)
prefix_sum = [0] * (n + 1)
dp[st] = 1
for times in range(k):
prefix_sum[0] = 0
for i in range(1, n + 1):
prefix_sum[i] = prefix_sum[i - 1] + dp[i]
if prefix_sum[i] >= MOD: prefix_sum[i] -= MOD
... | {
"input": [
"5 2 4 1\n",
"5 2 4 2\n",
"5 3 4 1\n",
"5000 2314 1234 5000\n",
"3 2 3 1\n",
"4988 3629 4106 4488\n",
"300 1 300 300\n",
"2 1 2 1\n",
"4999 1 2 4999\n",
"3999 2 10 5000\n",
"10 1 4 4999\n",
"22 9 18 3\n",
"10 1 10 2\n",
"5 3 2 2\n",
"50 5 2 50\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Imagine that you are in a building that has exactly n floors. You can move between the floors in a lift. Let's number the floors from bottom to top with integers from 1 to n. Now you'... |
529_B. Group Photo 2 (online mirror version)_16027 | Many years have passed, and n friends met at a party again. Technologies have leaped forward since the last meeting, cameras with timer appeared and now it is not obligatory for one of the friends to stand with a camera, and, thus, being absent on the photo.
Simply speaking, the process of photographing can be describ... | from operator import neg
n = int(input())
a = [tuple(map(int, input().split())) for i in range(n)]
def check(max_h):
k = n // 2
b = []
for w, h in a:
if h > max_h:
if k <= 0 or w > max_h:
return 1 << 60
b.append((h, w))
k -= 1
else:
... | {
"input": [
"3\n10 1\n20 2\n30 3\n",
"1\n5 10\n",
"3\n3 1\n2 2\n4 3\n",
"4\n573 7\n169 9\n447 7\n947 3\n",
"10\n489 685\n857 870\n736 221\n687 697\n166 360\n265 200\n738 519\n393 760\n66 176\n798 160\n",
"3\n203 145\n780 692\n992 713\n",
"3\n627 286\n37 65\n53 490\n",
"3\n475 487\n41 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Many years have passed, and n friends met at a party again. Technologies have leaped forward since the last meeting, cameras with timer appeared and now it is not obligatory for one o... |
554_D. Kyoya and Permutation_16031 | Let's define the permutation of length n as an array p = [p1, p2, ..., pn] consisting of n distinct integers from range from 1 to n. We say that this permutation maps value 1 into the value p1, value 2 into the value p2 and so on.
Kyota Ootori has just learned about cyclic representation of a permutation. A cycle is a... | def F(n):
a,b = 1,0
for i in range(n):
a,b = b,a+b
return b
def ans(n,k):
if n == 0:
return []
elif n == 1:
return [1]
elif k > F(n):
return [2,1] + [i+2 for i in ans(n-2,k-F(n))]
else:
return [1] + [i+1 for i in ans(n-1,k)]
n,k = map(int,input().spl... | {
"input": [
"10 1\n",
"4 3\n",
"31 1899100\n",
"16 747\n",
"44 863791309\n",
"25 121393\n",
"15 463\n",
"36 7074882\n",
"50 20365011074\n",
"34 2412850\n",
"39 68773650\n",
"24 47430\n",
"18 1809\n",
"19 859\n",
"10 89\n",
"6 10\n",
"32 1314567\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Let's define the permutation of length n as an array p = [p1, p2, ..., pn] consisting of n distinct integers from range from 1 to n. We say that this permutation maps value 1 into the... |
580_C. Kefa and Park_16035 | Kefa decided to celebrate his first big salary by going to the restaurant.
He lives by an unusual park. The park is a rooted tree consisting of n vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the ver... | M=lambda:map(int,input().split())
n,m=M()
*c,=M()
t=[[]for i in range(n)]
v=[0]*n
for i in range(n-1):
x,y=M()
t[x-1].append(y-1)
t[y-1].append(x-1)
a=i=0
q=[(0,0)]
while i<len(q):
x,N=q[i]
v[x]=1
if c[x]+N<=m:
L=1
for y in t[x]:
if not v[y]:
L=0
... | {
"input": [
"7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n",
"4 1\n1 1 0 0\n1 2\n1 3\n1 4\n",
"5 2\n1 1 0 1 1\n1 2\n2 3\n3 4\n4 5\n",
"6 1\n1 0 1 1 0 0\n1 2\n1 3\n1 4\n1 5\n1 6\n",
"2 1\n1 1\n2 1\n",
"3 2\n1 1 1\n1 2\n2 3\n",
"12 3\n1 0 1 0 1 1 1 1 0 0 0 0\n6 7\n12 1\n9 7\n1 4\n10 7\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Kefa decided to celebrate his first big salary by going to the restaurant.
He lives by an unusual park. The park is a rooted tree consisting of n vertices with the root at vertex 1.... |
602_B. Approximating a Constant Range_16039 | When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of consecutive data points that seems as constant as possible and taking their aver... | n = int(input())
arr = list(map(int,input().split()))
d = {}
mx = 0
for c in arr:
nd = {}
nd[c-0.5] = d.get(c-0.5,0)+1
nd[c+0.5] = d.get(c+0.5,0)+1
mx = max(mx,nd[c-0.5],nd[c+0.5])
d = nd
print(mx) | {
"input": [
"5\n1 2 3 3 2\n",
"11\n5 4 5 5 6 7 8 8 8 7 6\n",
"2\n99999 100000\n",
"4\n4 3 2 3\n",
"3\n1 2 3\n",
"4\n10 9 10 9\n",
"3\n1 2 2\n",
"2\n3 2\n",
"3\n99998 99999 100000\n",
"18\n10 9 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 9\n",
"3\n1 2 1\n",
"15\n1000 1000 1000 1000 1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium in... |
673_B. Problems for Round_16045 | There are n problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty, and no two problems have the same difficulty. Moreover, there are m pairs of similar problems. Authors want to split problems between two division according to the following rules:
* Problemset of ... | n, m = map(int, input().split())
s1 = set()
s2 = set()
for _ in range(m):
a, b = map(int, input().split())
a, b = min(a, b), max(a, b)
if a in s2 or b in s1:
print(0)
exit(0)
s1.add(a)
s2.add(b)
if not s2:
s2.add(n)
s1.add(1)
print(max(0, min(s2) - max(s1))) | {
"input": [
"3 2\n3 1\n3 2\n",
"3 3\n1 2\n2 3\n1 3\n",
"5 2\n1 4\n5 2\n",
"3 1\n1 2\n",
"4 2\n3 4\n1 2\n",
"5 1\n1 5\n",
"5 2\n3 5\n1 2\n",
"2 1\n1 2\n",
"3 1\n1 3\n",
"7 2\n1 5\n5 2\n",
"100000 0\n",
"4 2\n1 2\n3 4\n",
"4 2\n1 4\n3 2\n",
"100000 1\n100000 1\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty, and no two problems have the same difficulty. Moreover, there ar... |
719_C. Efim and Strange Grade_16051 | Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after th... | n, t = map(int, input().split())
tmp = input()
s = []
for i in range(n):
s.append(tmp[i])
ind = n
perenos = 0
for i in range(n):
if (s[i] == '.'):
nach = i + 1
for i in range(nach, n):
if (int(s[i]) > 4):
ind = i
break
if (ind == n):
print(*s, sep="")
exit()
while (t > 0 and ... | {
"input": [
"6 2\n10.245\n",
"3 100\n9.2\n",
"6 1\n10.245\n",
"13 1\n761.044449428\n",
"35 8\n984227318.2031144444444444494637612\n",
"31 15\n2707786.24030444444444444724166\n",
"3 1\n0.1\n",
"9 2\n23999.448\n",
"12 5\n872.04488525\n",
"320 142\n2704701300865535.43222331223343... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a... |
740_A. Alyona and copybooks_16055 | Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for a rubles, a pack of two copybooks for b rubles, and a pack of t... |
n, a, b, c = map(int, input().split())
h=n%4
if h==0:
d=0
else:
if h==1:
d=min(a*3,a+b,c)
if h==2:
d=min(a*2,b,c*2)
if h==3:
d=min(a,b+c,c*3)
print(d) | {
"input": [
"1 1 3 4\n",
"999999999 1000000000 1000000000 1000000000\n",
"6 2 1 1\n",
"4 4 4 4\n",
"3 1000000000 1 1000000000\n",
"561775796 937657403 280013594 248004555\n",
"7 12 6 1\n",
"1000000000 1000000000 1000000000 1000000000\n",
"4448 2 3 6\n",
"19 4 3 1\n",
"7 9 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three type... |
787_B. Not Afraid_16061 | Since the giant heads have appeared in the sky all humanity is in danger, so all Ricks and Mortys from all parallel universes are gathering in groups to find a solution to get rid of them.
There are n parallel universes participating in this event (n Ricks and n Mortys). I. e. each of n universes has one Rick and one... | def test(l):
l1=[]
l2=[]
for i in range(len(l)):
if l[i]<0 and l[i] not in l2:
l2.append(l[i])
elif l[i]>0 and l[i] not in l1:
l1.append(l[i])
if len(l1)==0 or len(l2)==0:
return False
for x in l1:
if (x*(-1)) in l2:
return True
... | {
"input": [
"5 2\n5 3 -2 1 -1 5\n3 -5 2 5\n",
"4 2\n1 -3\n4 -2 3 2 -3\n",
"7 2\n3 -1 6 7\n7 -5 4 2 4 7 -3 4\n",
"10 1\n2 4 4\n",
"5 1\n2 -1 -1\n",
"3 1\n3 1 1 2\n",
"10000 1\n1 2550\n",
"1 1\n1 1\n",
"2 1\n2 2 2\n",
"4 1\n3 1 1 -1\n",
"4 2\n2 1 -1\n1 1\n",
"1 2\n2 1 -1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Since the giant heads have appeared in the sky all humanity is in danger, so all Ricks and Mortys from all parallel universes are gathering in groups to find a solution to get rid of ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.