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 |
|---|---|---|---|---|---|
1476_C. Longest Simple Cycle_7561 | You have n chains, the i-th chain consists of c_i vertices. Vertices in each chain are numbered independently from 1 to c_i along the chain. In other words, the i-th chain is the undirected graph with c_i vertices and (c_i - 1) edges connecting the j-th and the (j + 1)-th vertices for each 1 ≤ j < c_i.
Now you decided... | import math,sys,bisect,heapq,os
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
from functools import lru_cache
#sys.setrecursionlimit(200000000)
int1 = lambda x: int(x) - 1
def input(): return sys.stdin.readline().rstrip('\r\n')
#input = iter(sys.stdin.buffer.read().decode().... | {
"input": [
"3\n4\n3 4 3 3\n-1 1 2 2\n-1 2 2 3\n2\n5 6\n-1 5\n-1 1\n3\n3 5 2\n-1 1 1\n-1 3 5\n",
"3\n4\n3 4 3 3\n-1 1 2 2\n-1 2 2 3\n2\n5 6\n-1 5\n0 1\n3\n3 5 2\n-1 1 1\n-1 3 5\n",
"3\n4\n3 4 3 3\n-1 1 2 2\n-1 2 2 3\n2\n5 9\n-1 5\n0 1\n3\n3 5 2\n-1 1 1\n-1 3 5\n",
"3\n4\n3 4 3 4\n-1 1 2 2\n-1 2 2 3\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You have n chains, the i-th chain consists of c_i vertices. Vertices in each chain are numbered independently from 1 to c_i along the chain. In other words, the i-th chain is the undi... |
1501_B. Napoleon Cake_7565 | This week Arkady wanted to cook some pancakes (to follow ancient traditions) and make a problem about that. But then he remembered that one can't make a problem about stacking pancakes without working at a specific IT company, so he decided to bake the Napoleon cake instead.
To bake a Napoleon cake, one has to bake n ... | def get_layers_status(aa):
n = len(aa)
intervals = []
for i in range(n):
if aa[i] > 0:
intervals.append([max(0, i + 1 - aa[i]), i + 1])
endpoints = [(s, 0) for s, e in intervals] + [(e, 1) for s, e in intervals]
endpoints.sort(key = lambda x: x[0] - 0.1 * x[1])
#print(endpo... | {
"input": [
"3\n6\n0 3 0 0 1 3\n10\n0 0 0 1 0 5 0 0 0 2\n3\n0 0 0\n",
"3\n6\n0 3 0 0 1 3\n10\n0 0 0 1 0 5 0 0 0 4\n3\n0 0 0\n",
"3\n6\n0 3 0 0 1 3\n10\n1 0 0 1 0 5 0 0 0 4\n3\n0 0 0\n",
"3\n6\n0 3 0 0 1 3\n10\n0 0 0 1 0 5 0 0 0 3\n3\n0 0 0\n",
"3\n6\n0 3 1 0 1 3\n10\n1 0 0 1 0 5 0 0 0 4\n3\n0 0 0... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This week Arkady wanted to cook some pancakes (to follow ancient traditions) and make a problem about that. But then he remembered that one can't make a problem about stacking pancake... |
1526_D. Kill Anton_7569 | After rejecting 10^{100} data structure problems, Errorgorn is very angry at Anton and decided to kill him.
Anton's DNA can be represented as a string a which only contains the characters "ANTON" (there are only 4 distinct characters).
Errorgorn can change Anton's DNA into string b which must be a permutation of a. ... | from collections import defaultdict
import itertools
import sys
input = sys.stdin.readline
t = int(input())
p = list("ANOT")
q = [0, 1, 2, 3]
d = dict()
for i in range(4):
d[p[i]] = i
for _ in range(t):
a = list(input().rstrip())
n = len(a)
cnt = [0] * 4
x = [[0] * 4 for _ in range(4)]
for i in... | {
"input": [
"4\nANTON\nNAAN\nAAAAAA\nOAANTTON\n",
"1\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n",
"4\nANTON\nNAAN\nAAAAAA\nOAANTTON\n",
"4\nNOTNA\nNAAN\nAAAAAA\nOAANTTON\n",
"4\nNOTNA\nNAAN\nAAAAAA\nOTANTAON\n",
"4\nNOTNA\nAANN\nAAAAAA\nOAANTTON\n",
"4\nNOTNA... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
After rejecting 10^{100} data structure problems, Errorgorn is very angry at Anton and decided to kill him.
Anton's DNA can be represented as a string a which only contains the chara... |
158_B. Taxi_7573 | After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum nu... | n=int(input())
a=list(map(int,input().split()))
s=[0]*5
sum=0
for i in a: s[i]+=1
sum+=s[4]+s[3]
if s[3]<s[1]:
s[1]-=s[3]
s[3]=0
else :
s[3]=0
s[1]=0
sum+=s[2]//2
s[2]%=2
sum+=s[1]//4
s[1]%=4
end=s[2]*2+s[1]
if end>4:sum+=2
elif end>0: sum+=1
print(int(sum))
| {
"input": [
"5\n1 2 4 3 3\n",
"8\n2 3 4 4 2 1 3 1\n",
"5\n4 4 4 4 4\n",
"3\n3 4 3\n",
"2\n2 1\n",
"78\n2 2 2 2 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 3 2 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n",
"7\n2 2 2 1 2 1 2\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), a... |
1_C. Ancient Berland Circus_7579 | Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different.
In Ancient Berland arenas in circuses were shaped as a regular (equiangular) polygon, the size and the number of angles could vary from one circus to another. In each corner of the arena there was a spec... | from math import *
def g(x,y):
if y<1e-3:
return x
else:
return g(y,fmod(x,y))
p=[list(map(float,input().split())) for i in range(3)]
a,b,c=[hypot(x1-x2,y1-y2) for (x1,y1),(x2,y2) in [(p[0],p[1]),(p[0],p[2]),(p[1],p[2])]]
A,B,C=[acos((y*y+z*z-x*x)/2/z/y) for x,y,z in [(a,b,c),(b,c,a),(c,a,b)]]
R... | {
"input": [
"0.000000 0.000000\n1.000000 1.000000\n0.000000 1.000000\n",
"76.820252 66.709341\n61.392328 82.684207\n44.267775 -2.378694\n",
"6.949504 69.606390\n26.139268 72.136945\n24.032442 57.407195\n",
"36.856072 121.845502\n46.453956 109.898647\n-30.047767 77.590282\n",
"-7.347450 36.971423\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different.
In Ancient Berland arenas in circuses were shaped as a regular (eq... |
224_D. Two Strings_7583 | A subsequence of length |x| of string s = s1s2... s|s| (where |s| is the length of string s) is a string x = sk1sk2... sk|x| (1 ≤ k1 < k2 < ... < k|x| ≤ |s|).
You've got two strings — s and t. Let's consider all subsequences of string s, coinciding with string t. Is it true that each character of string s occurs in at... | import bisect
import string
s = input()
t = input()
max_match = [0 for i in range(len(s))]
min_match = [0 for i in range(len(s))]
char_idx = [0 for i in range(30)]
char_occur = [ [] for i in range(30) ]
for (i, ch) in enumerate(t):
idx = ord(ch) - ord('a')
char_occur[idx].append(i)
for ch in string.ascii_lo... | {
"input": [
"abc\nba\n",
"abacaba\naba\n",
"abab\nab\n",
"babaabaabb\nbbccb\n",
"aaaaaa\naaaaaaa\n",
"abcdadbcd\nabcd\n",
"abaaaaba\nabba\n",
"aa\naaa\n",
"iqqiaiiffiqlqfaaflfieflfillkkhqfolhehedqdqqfddlheifeoqeohhoadqkfiqeleeqdekhhahkaqqqiaqliiqlelkhdfodeafqfhogihlgoqafdiffkaekhq... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A subsequence of length |x| of string s = s1s2... s|s| (where |s| is the length of string s) is a string x = sk1sk2... sk|x| (1 ≤ k1 < k2 < ... < k|x| ≤ |s|).
You've got two strings ... |
249_B. Sweets for Everyone!_7587 | For he knew every Who down in Whoville beneath, Was busy now, hanging a mistletoe wreath. "And they're hanging their stockings!" he snarled with a sneer, "Tomorrow is Christmas! It's practically here!"
Dr. Suess, How The Grinch Stole Christmas
Christmas celebrations are coming to Whoville. Cindy Lou Who and her paren... | def check(n, casas):
#print('n:',n)
global T,N,street
current = n
time = T
need = 0
last_house = 0
for ind, i in enumerate(street):
time -= 1
if i == 'S':
current += 1
elif i == 'H':
need += 1
if need == ... | {
"input": [
"23 50\nHHSS.......SSHHHHHHHHHH\n",
"14 100\n...HHHSSS...SH\n",
"6 6\nHSHSHS\n",
"336 400\nHSSHHSSHHS..S..SS..H.S.H..SSH.H.H.H.S.H.S.S.H.S..SS..H.SS.H.SS.SS..SS.H...H.H.H.HSS..H...SS..SS.H..H.S.S....S.H.SS..HS..S.S.S.H.H.S..S.H.SS.SS..SS.SS.HS.SS.HSSSSHSSSSSS.H.SS..HHH.H.H.S..H.SS.S.H..SS... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
For he knew every Who down in Whoville beneath, Was busy now, hanging a mistletoe wreath. "And they're hanging their stockings!" he snarled with a sneer, "Tomorrow is Christmas! It's ... |
296_E. Greg and Friends_7593 | One day Greg and his friends were walking in the forest. Overall there were n people walking, including Greg. Soon he found himself in front of a river. The guys immediately decided to get across the river. Luckily, there was a boat by the river bank, just where the guys were standing. We know that the boat can hold pe... | from collections import deque
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
c50 = sum([1 for i in a if i == 50])
c100 = sum([1 for i in a if i == 100])
c = [[0] * 51 for i in range(51)]
c[0][0] = 1
c[1][0] = 1
c[1][1] = 1
for x in range(2, 51):
for y in range(x + 1):
c[x][y... | {
"input": [
"1 50\n50\n",
"3 100\n50 50 100\n",
"2 50\n50 50\n",
"1 204\n50\n",
"5 123\n50 100 50 50 50\n",
"3 99\n100 50 50\n",
"32 121\n100 100 100 100 100 50 100 100 50 100 50 100 50 100 50 100 50 50 50 100 100 50 100 100 100 100 50 100 50 100 100 50\n",
"23 100\n50 50 50 50 50 50 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
One day Greg and his friends were walking in the forest. Overall there were n people walking, including Greg. Soon he found himself in front of a river. The guys immediately decided t... |
31_C. Schedule_7597 | At the beginning of the new semester there is new schedule in the Berland State University. According to this schedule, n groups have lessons at the room 31. For each group the starting time of the lesson and the finishing time of the lesson are known. It has turned out that it is impossible to hold all lessons, becaus... | from operator import add
import sys
from array import array # noqa: F401
from typing import TypeVar, Generic, Callable, List
T = TypeVar('T')
class SegmentTree(Generic[T]):
__slots__ = ["size", "tree", "identity", "op", "update_op"]
def __init__(self, size: int, identity: T, op: Callable[[T, T], T],
... | {
"input": [
"3\n1 5\n2 6\n3 7\n",
"4\n3 10\n20 30\n1 3\n1 39\n",
"3\n3 10\n20 30\n1 3\n",
"4\n1 5\n5 7\n6 9\n9 10\n",
"16\n203671 381501\n58867 59732\n817520 962123\n125391 163027\n601766 617692\n381501 444610\n761937 817520\n16 10551\n21096 38291\n718073 761937\n583868 601766\n554859 731755\n678... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
At the beginning of the new semester there is new schedule in the Berland State University. According to this schedule, n groups have lessons at the room 31. For each group the starti... |
344_C. Rational Resistance_7601 | Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance R0 = 1. Elements with other resistance can be constructed from these resistors. In this problem, we will co... | import sys
import string
import math
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache
from fractions import Fraction
def mi(s):
return map(int, s.strip().split())
def lmi(s):
return list(mi(s))
def tmi(s):
retur... | {
"input": [
"1 1\n",
"199 200\n",
"3 2\n",
"36 316049483082136289\n",
"1 923438\n",
"999999999999999999 2\n",
"2 999999999999999999\n",
"3 1000000000000000000\n",
"60236007668635342 110624799949034113\n",
"4 5\n",
"288565475053 662099878640\n",
"8944394323791464 552793... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical r... |
390_A. Inna and Alarm Clock_7607 | Inna loves sleeping very much, so she needs n alarm clocks in total to wake up. Let's suppose that Inna's room is a 100 × 100 square with the lower left corner at point (0, 0) and with the upper right corner at point (100, 100). Then the alarm clocks are points with integer coordinates in this square.
The morning has ... | n = int(input())
x_set = set()
y_set = set()
for i in range(n):
x,y = map(int, input().split())
x_set.add(x)
y_set.add(y)
print(min(len(x_set), len(y_set))) | {
"input": [
"4\n0 0\n0 1\n1 0\n1 1\n",
"4\n0 0\n0 1\n0 2\n1 0\n",
"4\n1 1\n1 2\n2 3\n3 3\n",
"42\n28 87\n26 16\n59 90\n47 61\n28 83\n36 30\n67 10\n6 95\n9 49\n86 94\n52 24\n74 9\n86 24\n28 51\n25 99\n40 98\n57 33\n18 96\n43 36\n3 79\n4 86\n38 61\n25 61\n6 100\n58 81\n28 19\n64 4\n3 40\n2 56\n41 49\n9... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Inna loves sleeping very much, so she needs n alarm clocks in total to wake up. Let's suppose that Inna's room is a 100 × 100 square with the lower left corner at point (0, 0) and wit... |
411_C. Kicker_7611 | Kicker (table football) is a board game based on football, in which players control the footballers' figures mounted on rods by using bars to get the ball into the opponent's goal. When playing two on two, one player of each team controls the goalkeeper and the full-backs (plays defence), the other player controls the ... | x = [tuple(int(i) for i in input().split()) for j in range(4)]
if x[0][0] + x[1][1] > x[0][1] + x[1][0]:
t1atk = x[1][1]
t1def = x[0][0]
else:
t1atk = x[0][1]
t1def = x[1][0]
def f():
if t1atk > t2def and t1def > t2atk:
return 0
elif t1atk < t2def and t1def < t2atk:
return 2
... | {
"input": [
"1 1\n2 2\n3 3\n2 2\n",
"3 3\n2 2\n1 1\n2 2\n",
"1 100\n100 1\n99 99\n99 99\n",
"21 22\n21 16\n32 14\n39 35\n",
"12 29\n44 8\n18 27\n43 19\n",
"10 3\n2 5\n1 10\n2 10\n",
"14 47\n47 42\n21 39\n40 7\n",
"6 3\n6 10\n2 5\n4 4\n",
"28 46\n50 27\n23 50\n21 45\n",
"46 33\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Kicker (table football) is a board game based on football, in which players control the footballers' figures mounted on rods by using bars to get the ball into the opponent's goal. Wh... |
439_B. Devu, the Dumb Guy_7615 | Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the ith subject has ci chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously.
Let us say that his initial per chapter learning power of a subject is x hours. In other words he can... | n, x = map(int, input().split())
m = list(map(int, input().split()))
m.sort()
ans = 0
for i in range(n):
ans += m[i] * x
if x > 1:
x -= 1
print(ans)
| {
"input": [
"3 3\n1 1 1\n",
"4 2\n5 1 2 1\n",
"2 3\n4 1\n",
"1 1\n1\n",
"1 1\n9273\n",
"20 10\n6 6 1 2 6 4 5 3 6 5 4 5 6 5 4 6 6 2 3 3\n",
"1 2\n2\n",
"20 4\n1 1 3 5 5 1 3 4 2 5 2 4 3 1 3 3 3 3 4 3\n",
"2 1\n1 2\n",
"1 2\n1\n",
"1 3\n1\n",
"20 10\n6 6 1 2 6 4 5 3 6 5 4... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the ith subject has ci chapters. When you teach him, you are supposed to teach all the c... |
460_D. Little Victor and Set_7619 | Little Victor adores the sets theory. Let us remind you that a set is a group of numbers where all numbers are pairwise distinct. Today Victor wants to find a set of integers S that has the following properties:
* for all x <image> the following inequality holds l ≤ x ≤ r;
* 1 ≤ |S| ≤ k;
* lets denote the i-th... | import random
l, r, k = map(int, input().split(' '))
if k == 1:
print(l)
print(1)
print(l)
quit()
if k == 2:
if r == l+1:
a = l
b = l^r
if a <= b:
print(a)
print(1)
print(l)
quit()
else:
print(b)
... | {
"input": [
"8 30 7\n",
"8 15 3\n",
"999999999996 1000000000000 5\n",
"1023 1536 3\n",
"1 5 5\n",
"1 3 3\n",
"137765364256 267196143745 72414\n",
"93593884958 917491772445 660\n",
"842310243287 842310243288 1\n",
"4294967297 12884901887 3\n",
"100000000000 900000000000 5\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Little Victor adores the sets theory. Let us remind you that a set is a group of numbers where all numbers are pairwise distinct. Today Victor wants to find a set of integers S that h... |
508_C. Anya and Ghosts_7625 | Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one can... | import sys
ghosts, duration, candles = input().split()
arrival = input().split()
burn = []
for j in range(len(arrival)):
time = int(arrival[len(arrival) - 1 - j])
candle = int(candles)
if len(burn) != 0:
for k in range(len(burn)):
if burn[k] <= time:
candle -= 1
for ... | {
"input": [
"1 1 3\n10\n",
"1 8 3\n10\n",
"2 10 1\n5 8\n",
"21 140 28\n40 46 58 67 71 86 104 125 129 141 163 184 193 215 219 222 234 237 241 246 263\n",
"100 257 21\n50 56 57 58 59 60 62 66 71 75 81 84 86 90 91 92 94 95 96 97 100 107 110 111 112 114 115 121 123 125 126 127 129 130 133 134 136 137... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce... |
557_D. Vitaly and Cycle_7629 | After Vitaly was expelled from the university, he became interested in the graph theory.
Vitaly especially liked the cycles of an odd length in which each vertex occurs at most once.
Vitaly was wondering how to solve the following problem. You are given an undirected graph consisting of n vertices and m edges, not ne... | def connected_components(n, graph):
components, visited = [], [False] * n
def dfs(start):
component, stack = [], [start]
while stack:
start = stack[-1]
if visited[start]:
stack.pop()
continue
else:
visited[sta... | {
"input": [
"4 4\n1 2\n1 3\n4 2\n4 3\n",
"3 0\n",
"3 3\n1 2\n2 3\n3 1\n",
"5 4\n1 2\n1 3\n1 4\n1 5\n",
"59139 1\n10301 5892\n",
"76259 0\n",
"9859 1\n1721 9478\n",
"25987 0\n",
"9411 0\n",
"6 4\n1 2\n2 3\n3 1\n4 5\n",
"92387 0\n",
"59139 0\n",
"25539 0\n",
"5 5... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
After Vitaly was expelled from the university, he became interested in the graph theory.
Vitaly especially liked the cycles of an odd length in which each vertex occurs at most once.... |
583_B. Robot's Task_7633 | Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the i-th of them, the robot needs to collect at ... | n = int(input())
a = [int(x) for x in input().split()]
hacked = 0
pos = 0
changes = 0
right = True
while hacked < n:
if right:
r = range(pos, n)
else:
r = range(pos, -1, -1)
for i in r:
if a[i] <= hacked:
a[i] = n + 1
hacked += 1
pos = i
if ... | {
"input": [
"3\n0 2 0\n",
"7\n0 3 1 0 5 2 6\n",
"5\n4 2 3 0 1\n",
"9\n1 3 5 7 8 6 4 2 0\n",
"9\n3 1 5 6 0 3 2 0 0\n",
"10\n0 0 0 0 0 0 0 0 0 0\n",
"9\n6 2 3 7 4 8 5 1 0\n",
"10\n3 4 8 9 5 1 2 0 6 7\n",
"100\n1 3 5 7 58 11 13 15 17 19 45 23 25 27 29 31 33 35 37 39 41 43 21 47 49 51... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n. Each computer contains exactly one piece of information, each of which Doc... |
605_B. Lazy Student_7637 | Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph — something that will definitely never be useful in real life. He asked a girl sitting next to him to lend him some cheat papers for this questions and found there the following defin... | n, m = (int(x) for x in input().split())
edges = []
for i in range(m):
w, in_tree = input().split()
edges.append([int(w), i, int(in_tree)])
sorted_edges = sorted(edges, key = lambda e: (e[0], -e[2]))
print
def free_edge():
for y in range(3, n+1):
for x in range(2, y):
yield [x, y]
f = fr... | {
"input": [
"3 3\n1 0\n2 1\n3 1\n",
"4 5\n2 1\n3 1\n4 0\n1 1\n5 0\n",
"10 15\n752087443 1\n537185872 1\n439895449 1\n494086747 1\n718088132 1\n93444012 0\n670136349 1\n545547453 0\n718088132 0\n853059674 0\n853059674 1\n762928724 1\n762928724 0\n853059674 0\n156495293 1\n",
"3 3\n4 1\n5 1\n7 0\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph — something that will definitely never be usef... |
627_C. Package Delivery_7640 | Johnny drives a truck and must deliver a package from his hometown to the district center. His hometown is located at point 0 on a number line, and the district center is located at the point d.
Johnny's truck has a gas tank that holds exactly n liters, and his tank is initially full. As he drives, the truck consumes ... | destination, max_gas_tank_volume, gas_prices_number = map(int, input().split())
start_point = 0
gas_prices = {start_point:0}
for i in range(gas_prices_number):
coordinate, price = map(int, input().split())
gas_prices[coordinate] = price
points = sorted(gas_prices.keys(), reverse = True)
current_point = start_po... | {
"input": [
"16 5 2\n8 2\n5 1\n",
"10 4 4\n3 5\n5 8\n6 3\n8 4\n",
"400000000 400000000 3\n1 139613\n19426 13509\n246298622 343529\n",
"153 105 1\n96 83995\n",
"229 123 2\n170 270968\n76 734741\n",
"281 12 23\n178 650197\n129 288456\n34 924882\n43 472160\n207 957083\n103 724815\n167 308008\n13... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Johnny drives a truck and must deliver a package from his hometown to the district center. His hometown is located at point 0 on a number line, and the district center is located at t... |
651_C. Watchmen_7644 | Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan consider... | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
def inc_val_of_dict(dictionary, key):
if key not in dictionary:
dictionary[key] = 0
dictionary[key] += 1
def main():
n = int(input())
p_ctr = dict()
x_ctr = dict()
y_ctr = dict()
for _ in range(n):
x, y = map(int, input().spl... | {
"input": [
"3\n1 1\n7 5\n1 5\n",
"6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n",
"2\n2 1\n1 2\n",
"2\n1 4\n2 1\n",
"10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55\n",
"2\n1 1000000000\n2 -1000000000\n",
"1\n-5 -90\n",
"2\n1000000000 0\n-7 1\n",
"2\n1 0\n0 2333... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is loca... |
677_A. Vanya and Fence_7648 | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the... | lin1 = input().split()
h = input().split()
for i in range(len(h)):
h[i] = int(h[i])
n_friends = int(lin1[0])
h_fence = int(lin1[1])
total = 0
for i in h:
if i > h_fence: total += 2
else: total += 1
print(total) | {
"input": [
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n",
"10 561\n657 23 1096 487 785 66 481 554 1000 821\n",
"10 420\n214 614 297 675 82 740 174 23 255 15\n",
"46 71\n30 26 56 138 123 77 60 122 73 45 79 10 130 3 14 1 38 46 128 50 82 16 32 68 28 98 62 106 2 49 131 11 114 39 1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exce... |
6_A. Triangle_7652 | Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo... | # https://codeforces.com/problemset/problem/6/A
import sys
#-----------------------------------------------------------------------------#
# # comment before submission
# sys.stdin = open('inputs.txt', 'r')
# sys.stdout = open('output.txt', 'w')
#------------------------------------------------------------------------... | {
"input": [
"3 5 9 1\n",
"7 2 2 4\n",
"4 2 1 3\n",
"7 7 10 7\n",
"4 4 4 5\n",
"50 1 50 100\n",
"11 30 79 43\n",
"49 51 100 1\n",
"3 1 2 1\n",
"27 53 7 97\n",
"1 5 1 3\n",
"10 20 30 40\n",
"3 5 1 1\n",
"22 80 29 7\n",
"1 5 5 5\n",
"4 4 10 10\n",
"4 8... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve.... |
721_C. Journey_7656 | Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially Irina... | n, m, T = map(int, input().split())
graph_a = [[] for _ in range(n+1)]
graph_b = [[] for _ in range(n+1)]
double_graph_a = [[0 for _ in range(n+1)] for _ in range(n+1)]
double_graph_b = [[0 for _ in range(n+1)] for _ in range(n+1)]
for i in range(m):
u, v, t = map(int, input().split())
graph_a[v].append(u)
... | {
"input": [
"4 3 13\n1 2 5\n2 3 7\n2 4 8\n",
"6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1\n",
"5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2\n",
"4 4 120\n1 2 11\n1 3 20\n2 3 10\n3 4 100\n",
"4 4 1000000000\n1 2 1000000000\n2 3 1000000000\n3 4 1000000000\n1 4 1000000000\n",
"12 12 8\n1 2 2\n2 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected by one... |
743_A. Vladik and flights_7660 | Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows n airports. All the airports are located on a straight line. Each airport has uni... | n, a, b = list(map(int, input().split()))
line = []
aa = input()
for i in range(n):
line += [int(aa[i])]
print(0 + (line[a-1] != line[b-1])) | {
"input": [
"4 1 4\n1010\n",
"5 5 2\n10110\n",
"6 1 6\n111000\n",
"10 5 8\n1000001110\n",
"5 1 5\n11010\n",
"8 4 5\n00001111\n",
"5 1 5\n10000\n",
"8 1 8\n11110000\n",
"10 3 3\n1001011011\n",
"10 1 10\n0000011111\n",
"6 1 6\n011111\n",
"10 3 7\n0000011111\n",
"4 1 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find... |
766_C. Mahmoud and a Message_7664 | Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alpha... | N, s, l = int(input()), [ord(x) - ord('a') for x in input()], [int(x) for x in input().split()]
arr = [[1, l[s[0]]]]
total = 1
ma = 1
t = 1
mi = 1
for c in s[1:]:
tmp = 0
for i in range(len(arr)):
arr[i][1] = min(arr[i][1],l[c])
if i + 1 >= arr[i][1]:
arr = arr[:i]
if(t > i):
t = 0
mi += 1
break
... | {
"input": [
"3\naab\n2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
"10\nabcdeabcde\n5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
"10\naabaabaaba\n3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
"10\naaaaaaaaaa\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\n",
"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some... |
78_B. Easter Eggs_7668 | The Easter Rabbit laid n eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
* Each of the seven colors should be used to paint at least one egg.
* Any four eggs lying ... | n = int(input())
s = 'ROYGBIV'
s1 = 'GBIV'
print(s, (n - 7) // 4 * s1, s1[:(n - 7) % 4], sep='')
| {
"input": [
"8\n",
"13\n",
"21\n",
"24\n",
"61\n",
"10\n",
"9\n",
"17\n",
"16\n",
"97\n",
"11\n",
"29\n",
"14\n",
"22\n",
"23\n",
"34\n",
"25\n",
"100\n",
"8\n",
"7\n",
"81\n",
"15\n",
"20\n",
"95\n",
"92\n",
"19\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The Easter Rabbit laid n eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the fo... |
837_A. Text Volume_7674 | You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
Input
The first line contains one integer number n ... | n = int(input())
text = input()
ll = list(text.split())
num = []
for i in range(len(ll)):
num.append(sum(1 for c in ll[i] if c.isupper()))
print(max(num))
| {
"input": [
"24\nthis is zero answer text\n",
"7\nNonZERO\n",
"24\nHarbour Space University\n",
"15\naAb ABCDFGRHTJS\n",
"24\nHarbour Space UniversitY\n",
"5\naA AA\n",
"10\nas AS ASDA\n",
"200\nhCyIdivIiISmmYIsCLbpKcTyHaOgTUQEwnQACXnrLdHAVFLtvliTEMlzBVzTesQbhXmcqvwPDeojglBMIjOXANfyQx... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text i... |
906_C. Party_7681 | Arseny likes to organize parties and invite people to it. However, not only friends come to his parties, but friends of his friends, friends of friends of his friends and so on. That's why some of Arseny's guests can be unknown to him. He decided to fix this issue using the following procedure.
At each step he selects... | from collections import defaultdict
def count(x):
c=0
while x > 0:
c+=1
x &= (x-1)
return c
n,m=map(int,input().split())
g=defaultdict(list)
for _ in range(m):
u, v = map(int,input().split())
u-=1;v-=1
g[u].append(v)
g[v].append(u)
mask1=0;mask2=0;MAX=(1<<n)-1
a=[0]*(1 << n... | {
"input": [
"4 4\n1 2\n1 3\n1 4\n3 4\n",
"5 6\n1 2\n1 3\n2 3\n2 5\n3 4\n4 5\n",
"22 66\n15 20\n15 4\n2 22\n8 22\n2 4\n8 2\n5 7\n18 8\n10 21\n22 20\n18 7\n2 20\n5 1\n20 19\n21 4\n8 4\n20 5\n7 8\n7 4\n21 15\n21 22\n7 20\n5 22\n21 7\n5 18\n18 21\n19 7\n15 7\n21 8\n18 15\n18 16\n21 19\n19 5\n21 2\n5 15\n8 3\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Arseny likes to organize parties and invite people to it. However, not only friends come to his parties, but friends of his friends, friends of friends of his friends and so on. That'... |
926_E. Merge Equal Elements_7685 | You are given a sequence of positive integers a1, a2, ..., an.
While possible, you perform the following operation: find a pair of equal consecutive elements. If there are more than one such pair, find the leftmost (with the smallest indices of elements). If the two integers are equal to x, delete both and insert a s... | # https://codeforces.com/problemset/problem/926/E
input()
stack1 = [int(i) for i in input().split()]
stack1.reverse()
stack2 = []
while stack1:
transfer = stack1.pop()
while stack2 and stack2[-1] == transfer:
stack2.pop()
transfer += 1
stack2.append(transfer)
print(len(stack2))
print("... | {
"input": [
"7\n4 10 22 11 12 5 6\n",
"6\n5 2 1 1 2 2\n",
"4\n1000000000 1000000000 1000000000 1000000000\n",
"2\n1 1\n",
"3\n2 1 1\n",
"7\n5 5 4 4 5 6 7\n",
"4\n3 2 1 1\n",
"7\n4 10 22 11 16 5 6\n",
"6\n5 3 1 1 2 2\n",
"4\n1000000010 1000000000 1000000000 1000000000\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 sequence of positive integers a1, a2, ..., an.
While possible, you perform the following operation: find a pair of equal consecutive elements. If there are more than... |
955_C. Sad powers_7689 | You're given Q queries of the form (L, R).
For each query you have to find the number of such x that L ≤ x ≤ R and there exist integer numbers a > 0, p > 1 such that x = ap.
Input
The first line contains the number of queries Q (1 ≤ Q ≤ 105).
The next Q lines contains two integers L, R each (1 ≤ L ≤ R ≤ 1018).
Ou... | import math
import bisect
import sys
def flrt(exp,x):
l=max(0,math.floor(x**(1/exp))-3)
r= math.floor(x**(1/exp))+3
while l<r:
mid=(l+r)//2
if mid**exp<=x:
l=mid+1
else:
r=mid
return l-1
def c1(r):
ans=set()
pr = [5,7,11, 13, 17, 19... | {
"input": [
"6\n1 4\n9 9\n5 7\n12 29\n137 591\n1 1000000\n",
"20\n862 928\n758 964\n541 789\n622 943\n328 900\n14 764\n217 972\n461 847\n442 468\n900 986\n518 529\n938 993\n549 851\n690 944\n484 601\n320 910\n98 868\n816 915\n765 880\n551 770\n",
"20\n862 928\n758 964\n541 789\n622 943\n328 900\n14 764\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You're given Q queries of the form (L, R).
For each query you have to find the number of such x that L ≤ x ≤ R and there exist integer numbers a > 0, p > 1 such that x = ap.
Input
... |
p02554 AtCoder Beginner Contest 178 - Ubiquity_7706 | How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an in... | N = int(input())
ans = 10**N - 2*(9**N) + 8**N
print(ans % 1000000007)
| {
"input": [
"869121",
"1",
"2",
"226564",
"0",
"3",
"241465",
"5",
"127499",
"10",
"99752",
"7",
"112403",
"25292",
"5344",
"6841",
"8450",
"15610",
"18734",
"19783",
"21762",
"6053",
"10667",
"15421",
"18759",
"2... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists som... |
p02685 AtCoder Beginner Contest 167 - Colorful Blocks_7710 | There are N blocks arranged in a row. Let us paint these blocks.
We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways.
Find the number of ways to paint the blocks under the following conditions:
* For each block, use one of the M colors... | n,m,k=map(int,input().split())
mod=998244353
ans=0
fact=[1] * (n+1) # 階乗を格納するリスト
factinv=[1] * (n+1) # 階乗を格納するリスト
for i in range(n):
fact[i+1] = fact[i] * (i+1) % mod # 階乗を計算
factinv[i+1] = pow(fact[i+1], mod-2, mod) # modを法とした逆元(フェルマーの小定理)
def nCk(n,k): # 組み合わせ(mod)を返却する
return fact[n] * factinv[n-k... | {
"input": [
"100 100 0",
"3 2 1",
"60522 114575 7559",
"100 110 0",
"6 2 1",
"119754 114575 7559",
"100 010 0",
"12 2 1",
"119754 114575 8988",
"100 010 -1",
"11 2 1",
"145188 114575 8988",
"11 3 1",
"145188 114575 3371",
"5 3 1",
"145188 114575 5625",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are N blocks arranged in a row. Let us paint these blocks.
We will consider two ways to paint the blocks different if and only if there is a block painted in different colors i... |
p02814 AtCoder Beginner Contest 150 - Semi Common Multiple_7714 | Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-co... | import math
from functools import reduce
N,M=map(int,input().split())
A=[int(x)//2 for x in input().split()]
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
def lcm(*numbers):
return reduce(lcm_base, numbers, 1)
LCM=lcm(*A)
for a in A:
if LCM//a%2==0:
print(0)
break
else:
print((M//LCM+1)//... | {
"input": [
"3 100\n14 22 40",
"2 50\n6 10",
"5 1000000000\n6 6 2 6 2",
"3 000\n14 22 40",
"2 46\n6 10",
"2 46\n10 10",
"2 12\n10 10",
"2 85\n6 10",
"3 101\n14 2 2",
"3 000\n14 16 40",
"3 010\n14 16 40",
"3 010\n14 16 4",
"3 110\n14 16 4",
"3 110\n14 22 4",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following conditi... |
p02950 AtCoder Beginner Contest 137 - Polynomial Construction_7718 | Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \le... | p = int(input())
a = list(map(int,input().split()))
ans = [0]*p
for i in range(p):
if a[i] == 0:
continue
ans[0] -= p-1
m = 1
for k in range(p):
ans[p-1-k] -= m
ans[p-1-k] %= p
m *= i
m %= p
print(*ans)
| {
"input": [
"2\n1 0",
"3\n0 0 0",
"5\n0 1 0 1 0",
"3\n0 0 1",
"2\n0 0",
"3\n0 1 0",
"3\n0 1 1",
"3\n1 1 0",
"5\n0 1 0 1 1",
"2\n0 1",
"5\n0 0 0 1 1",
"3\n1 1 1",
"5\n0 0 1 1 1",
"3\n1 0 1",
"5\n1 1 0 1 1",
"5\n1 1 0 1 0",
"2\n1 1",
"3\n1 0 0",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x... |
p03086 AtCoder Beginner Contest 122 - ATCoder_7722 | You are given a string S consisting of uppercase English letters. Find the length of the longest ACGT string that is a substring (see Notes) of S.
Here, a ACGT string is a string that contains no characters other than `A`, `C`, `G` and `T`.
Constraints
* S is a string of length between 1 and 10 (inclusive).
* Each c... | import re
S=input()
ans = sorted((re.findall("[AGCT]*", S)), reverse=True, key=len)
print(len(ans[0])) | {
"input": [
"SHINJUKU",
"ATCODER",
"HATAGAYA",
"SHINJUKV",
"ATCPDER",
"HATAGBYA",
"HASAGBYA",
"VKUJNIHT",
"HATAGCYA",
"VKUJNIHS",
"ATCPCER",
"ATCPBER",
"HASAGCYA",
"VUKJNIHT",
"REBPCTA",
"THINJKUV",
"RDBPCTA",
"AYCGATAH",
"JUKVNIHT",
"RT... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a string S consisting of uppercase English letters. Find the length of the longest ACGT string that is a substring (see Notes) of S.
Here, a ACGT string is a string tha... |
p03231 AtCoder Grand Contest 028 - Two Abbreviations_7726 | You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters.
A string X is called a good string when the following conditions are all met:
* Let L be the length of X. L is divisible by both N and M.
* Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \... | gcd = lambda a,b: a if b==0 else gcd(b,a%b)
n,m = map(int,input().split())
s = input()
t = input()
d = gcd(n,m)
if s[::n//d]==t[::m//d]:
print(n*m//d)
else:
print(-1) | {
"input": [
"3 2\nacp\nae",
"6 3\nabcdef\nabc",
"15 9\ndnsusrayukuaiia\ndujrunuma",
"3 2\nacq\nae",
"3 3\nabcdef\nabc",
"15 9\ndnsusrayukuaiia\nrujdunuma",
"3 4\nasiaukvyartuind\naumnudjus",
"15 9\ndnausrayukusiia\ndujrunuma",
"1 2\nacq\nae",
"4 1\nabq\nae",
"15 16\ndnausr... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters.
A string X is called a good string when the following condi... |
p03381 AtCoder Regular Contest 095 - Many Medians_7730 | When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..... | N=int(input())
X=list(map(int,input().split()))
X_sort=sorted(X)
med_n=X_sort[N//2-1]
med_p=X_sort[N//2]
for i in range(N):
if X[i]<=med_n:
print(med_p)
else:
print(med_n)
| {
"input": [
"6\n5 5 4 4 3 3",
"4\n2 4 4 3",
"2\n1 2",
"6\n1 5 4 4 3 3",
"4\n2 6 4 3",
"2\n1 3",
"6\n1 5 4 4 5 3",
"4\n2 6 4 6",
"2\n1 4",
"6\n1 5 4 6 5 3",
"4\n2 6 5 6",
"2\n2 4",
"4\n2 6 5 0",
"2\n3 4",
"4\n0 6 5 0",
"2\n4 4",
"6\n2 5 4 0 5 3",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, wher... |
p03546 AtCoder Beginner Contest 079 - Wall_7734 | Joisino the magical girl has decided to turn every single digit that exists on this world into 1.
Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points).
She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and... | h,w = map(int,input().split())
c = [list(map(int,input().split())) for i in range(10)]
A = [list(map(int,input().split())) for i in range(h)]
for k in range(10):
for i in range(10):
for j in range(10):
c[i][j] = min(c[i][j],c[i][k]+c[k][j])
ans = 0
for i in range(h):
for j in A[i]:
... | {
"input": [
"2 4\n0 9 9 9 9 9 9 9 9 9\n9 0 9 9 9 9 9 9 9 9\n9 9 0 9 9 9 9 9 9 9\n9 9 9 0 9 9 9 9 9 9\n9 9 9 9 0 9 9 9 9 2\n9 9 9 9 9 0 9 9 9 9\n9 9 9 9 9 9 0 9 9 9\n9 9 9 9 9 9 9 0 9 9\n9 9 9 9 2 9 9 9 0 9\n9 2 9 9 9 9 9 9 9 0\n-1 -1 -1 -1\n8 1 1 8",
"3 5\n0 4 3 6 2 7 2 5 3 3\n4 0 5 3 7 5 3 7 2 7\n5 7 0 7 2 ... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Joisino the magical girl has decided to turn every single digit that exists on this world into 1.
Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points).
She is now st... |
p03700 AtCoder Beginner Contest 063 - Widespread_7738 | You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below.
Fortunately, you are a skilled magician, capable of causing expl... | N, A, B = map(int, input().split())
H = [int(input()) for i in range(N)]
def f(x):
s = sum([- (- max(0, h - x * B) // (A - B)) for h in H])
if s <= x:
return True
else:
return False
l = 0
r = 10 ** 9 + 7
while r - l > 1:
m = (l + r) // 2
if f(m):
r = m
else:
... | {
"input": [
"5 2 1\n900000000\n900000000\n1000000000\n1000000000\n1000000000",
"4 5 3\n8\n7\n4\n2",
"2 10 4\n20\n20",
"5 2 1\n187174154\n900000000\n1000000000\n1000000000\n1000000000",
"4 5 3\n8\n7\n6\n2",
"2 10 4\n20\n37",
"5 2 1\n187174154\n900000000\n1000000000\n1000000000\n1100000000"... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is h_i at the moment of encounter.... |
p03857 AtCoder Regular Contest 065 - Connectivity_7742 | There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the s... | N,K,L = list(map(int,input().split()))
e_list1 = [[] for i in range(N)]
e_list2 = [[] for i in range(N)]
for i in range(K):
p,q = list(map(int,input().split()))
e_list1[p-1].append(q-1)
e_list1[q-1].append(p-1)
for i in range(L):
p,q = list(map(int,input().split()))
e_list2[p-1].append(q-1)
e... | {
"input": [
"7 4 4\n1 2\n2 3\n2 5\n6 7\n3 5\n4 5\n3 4\n6 7",
"4 3 1\n1 2\n2 3\n3 4\n2 3",
"4 2 2\n1 2\n2 3\n1 4\n2 3",
"7 4 4\n1 2\n2 3\n2 7\n6 7\n3 5\n4 5\n3 4\n6 7",
"4 3 0\n1 2\n2 3\n3 4\n2 3",
"4 2 2\n2 2\n2 3\n1 4\n2 3",
"6 3 0\n-1 2\n2 3\n3 4\n2 3",
"14 4 4\n1 2\n2 3\n2 5\n6 7\n... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidi... |
p04022 AtCoder Grand Contest 003 - Anticube_7745 | Snuke got positive integers s_1,...,s_N from his mother, as a birthday present. There may be duplicate elements.
He will circle some of these N integers. Since he dislikes cubic numbers, he wants to ensure that if both s_i and s_j (i ≠ j) are circled, the product s_is_j is not cubic. For example, when s_1=1,s_2=1,s_3=... | def examA():
S = SI()
if "W" in S and not "E" in S:
print("No")
elif "E" in S and not "W" in S:
print("No")
elif "N" in S and not "S" in S:
print("No")
elif "S" in S and not "N" in S:
print("No")
else:
print("Yes")
return
def examB():
N = I()
... | {
"input": [
"10\n1\n10\n100\n1000000007\n10000000000\n1000000009\n999999999\n999\n999\n999",
"6\n2\n4\n8\n16\n32\n64",
"8\n1\n2\n3\n4\n5\n6\n7\n8",
"10\n1\n11\n100\n1000000007\n10000000000\n1000000009\n999999999\n999\n999\n999",
"8\n1\n2\n4\n4\n5\n6\n7\n8",
"8\n1\n2\n6\n4\n5\n7\n7\n3",
"6... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Snuke got positive integers s_1,...,s_N from his mother, as a birthday present. There may be duplicate elements.
He will circle some of these N integers. Since he dislikes cubic numb... |
p00106 Discounts of Buckwheat_7749 | Aizu is famous for its buckwheat. There are many people who make buckwheat noodles by themselves.
One day, you went shopping to buy buckwheat flour. You can visit three shops, A, B and C. The amount in a bag and its unit price for each shop is determined by the follows table. Note that it is discounted when you buy bu... | while 1:
try:
inp=int(input())
if inp==0:break
m_list=[]
for i in range(4):
for j in range(5):
for k in range(6):
for l in range(3):
for m in range(4):
for n in range(5):
... | {
"input": [
"500\n2200\n0",
"500\n1000\n0",
"500\n0000\n0",
"500\n1100\n0",
"500\n0000\n1",
"500\n0000\n2",
"500\n0000\n-1",
"500\n0000\n4",
"500\n0000\n8",
"500\n0000\n-2",
"500\n0000\n3",
"500\n0000\n14",
"500\n0000\n13",
"500\n0000\n19",
"500\n0000\n7",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Aizu is famous for its buckwheat. There are many people who make buckwheat noodles by themselves.
One day, you went shopping to buy buckwheat flour. You can visit three shops, A, B a... |
p00240 Interest Rates_7753 | Interest rates are attached to the money deposited in banks, and the calculation method and interest rates vary from bank to bank. The combination of interest and principal is called principal and interest, but as a method of calculating principal and interest, there are "single interest" that calculates without incorp... | def simple_interest(r, y):
return (100 + r * y) / 100
def compound_interest(r, y):
return ((100 + r) / 100) ** y
import sys
import operator
f = sys.stdin
get_ganri = {1:simple_interest,2:compound_interest}
while True:
n = int(f.readline())
if n == 0:
break
y = int(f.readline())
brt = [l... | {
"input": [
"2\n8\n1 5 2\n2 6 1\n2\n9\n1 5 2\n2 6 1\n0",
"2\n8\n1 5 2\n2 6 1\n2\n9\n1 3 2\n2 6 1\n0",
"2\n8\n1 5 2\n3 6 1\n2\n7\n1 5 2\n2 6 1\n0",
"2\n8\n1 5 2\n2 6 1\n0\n9\n0 3 2\n2 6 1\n0",
"2\n14\n1 5 2\n3 6 1\n2\n7\n1 5 2\n2 6 1\n0",
"2\n8\n1 5 2\n2 6 1\n2\n7\n1 8 2\n2 6 1\n0",
"2\n14... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Interest rates are attached to the money deposited in banks, and the calculation method and interest rates vary from bank to bank. The combination of interest and principal is called ... |
p00412 Gas Station_7756 | Gas stations in the White Tiger service area have $ N $ lanes assigned numbers from $ 1 $ to $ N $. The first car in each lane can refuel.
Cars entering the gas station will choose the lane with the fewest cars in line and line up at the end of the line. If there are multiple such lanes, choose the one with the lowest... |
N,M = [int(i) for i in input().split()]
table = [[] for i in range(N)]
for l in range(M):
command,num = [int(i) for i in input().split()]
if command == 0:
print(table[num-1].pop(0))
else:
minSize = 10000
minId = -1
for i in range(N):
if len(table[i]) < minSize:... | {
"input": [
"2 7\n1 999\n1 1000\n0 2\n1 1001\n1 1002\n0 1\n0 1",
"2 7\n1 999\n1 1000\n0 2\n1 1001\n1 1002\n0 1\n1 1",
"2 7\n1 999\n1 1000\n0 2\n1 1001\n1 1002\n0 2\n1 1",
"2 7\n1 999\n1 1000\n0 2\n1 1001\n1 1002\n1 2\n1 1",
"2 7\n1 999\n1 1000\n0 2\n1 1000\n1 1002\n0 1\n0 1",
"2 7\n1 999\n1 1... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Gas stations in the White Tiger service area have $ N $ lanes assigned numbers from $ 1 $ to $ N $. The first car in each lane can refuel.
Cars entering the gas station will choose t... |
p00616 Cubes Without Holes_7760 | There is a cube which consists of n × n × n small cubes. Small cubes have marks on their surfaces. An example where n = 4 is shown in the following figure.
<image>
Then, as shown in the figure above (right), make a hole that penetrates horizontally or vertically from the marked surface to the opposite surface.
You... | # AOJ 1030 Cubes Without Holes
# Python3 2018.7.6 bal4u
import sys
from sys import stdin
input = stdin.readline
# n <= 500, 2^9 = 512
while True:
n, h = map(int, input().split())
if n == 0: break
ans = []
for i in range(h):
c, a, b = input().split()
a, b = int(a)-1, int(b)-1
if c == "xy":
ans += [a+(b<<... | {
"input": [
"4 3\nxy 4 4\nxz 1 2\nyz 2 3\n4 5\nxy 1 1\nxy 3 3\nxz 3 3\nyz 2 1\nyz 3 3\n0 0",
"4 3\nxy 4 4\nxz 1 2\nyz 2 3\n4 5\nxy 1 1\nxy 3 3\nxz 3 2\nyz 2 1\nyz 3 3\n0 0",
"4 3\nxy 4 4\nxz 1 2\nyz 2 3\n4 5\nxy 1 1\nxy 3 3\nxz 3 1\nyz 2 1\nyz 3 3\n0 0",
"4 3\nxy 4 3\nxz 1 2\nyz 2 3\n4 5\nxy 1 1\nwy ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is a cube which consists of n × n × n small cubes. Small cubes have marks on their surfaces. An example where n = 4 is shown in the following figure.
<image>
Then, as shown ... |
p00760 Millennium_7764 | A wise king declared a new calendar. "Tomorrow shall be the first day of the calendar, that is, the day 1 of the month 1 of the year 1. Each year consists of 10 months, from month 1 through month 10, and starts from a big month. A common year shall start with a big month, followed by small months and big months one aft... | # AOJ 1179: Millennium
# Python3 2018.7.14 bal4u
for cno in range(int(input())):
y, m, d = map(int, input().split())
ans = 195*y
if y > 1: ans += 5*((y-1)//3)
if y % 3: ans += 19*(m-1) + m//2
else: ans += (m-1)*20
print(196666-ans-d)
| {
"input": [
"8\n1 1 1\n344 3 1\n696 5 1\n182 9 5\n998 8 7\n344 2 19\n696 4 19\n999 10 20",
"8\n1 1 1\n344 3 1\n696 5 1\n182 9 5\n998 5 7\n344 2 19\n696 4 19\n999 10 20",
"8\n1 1 1\n344 3 1\n696 5 1\n182 9 5\n998 5 7\n344 2 26\n696 4 19\n999 10 20",
"8\n1 1 1\n344 3 1\n696 4 1\n182 9 5\n998 8 7\n344 2... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A wise king declared a new calendar. "Tomorrow shall be the first day of the calendar, that is, the day 1 of the month 1 of the year 1. Each year consists of 10 months, from month 1 t... |
p00892 Intersection of Two Prisms_7767 | Suppose that P1 is an infinite-height prism whose axis is parallel to the z-axis, and P2 is also an infinite-height prism whose axis is parallel to the y-axis. P1 is defined by the polygon C1 which is the cross section of P1 and the xy-plane, and P2 is also defined by the polygon C2 which is the cross section of P2 and... | import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
M, N = map(int, readline().split())
if M == N == 0:
return False
P = [list(map(int, readline().split())) for i in range(M)]
Q = [list(map(int, readline().split())) for i in range(N)]
xs = set()
xs.update(x for... | {
"input": [
"4 3\n7 2\n3 3\n0 2\n3 1\n4 2\n0 1\n8 1\n4 4\n30 2\n30 12\n2 12\n2 2\n15 2\n30 8\n13 14\n2 8\n8 5\n13 5\n21 7\n21 9\n18 15\n11 15\n6 10\n6 8\n8 5\n10 12\n5 9\n15 6\n20 10\n18 12\n3 3\n5 5\n10 3\n10 10\n20 8\n10 15\n10 8\n4 4\n-98 99\n-99 -99\n99 -98\n99 97\n-99 99\n-98 -98\n99 -99\n96 99\n0 0",
"... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Suppose that P1 is an infinite-height prism whose axis is parallel to the z-axis, and P2 is also an infinite-height prism whose axis is parallel to the y-axis. P1 is defined by the po... |
p01295 Champernowne Constant_7774 | Champernown constant is an irrational number represented in decimal by "0." followed by concatenation of all positive integers in the increasing order. The first few digits of this constant are: 0.123456789101112...
Your task is to write a program that outputs the K digits of Chapnernown constant starting at the N-th ... | #!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.... | {
"input": [
"4 5\n6 7\n0 0",
"3 5\n6 7\n0 0",
"4 5\n1 7\n0 0",
"4 5\n1 13\n0 0",
"2 5\n1 13\n0 0",
"8 5\n6 7\n0 0",
"3 5\n6 5\n0 0",
"2 5\n1 0\n0 0",
"8 5\n6 14\n0 0",
"2 5\n0 0\n0 0",
"8 8\n6 14\n0 0",
"4 5\n0 0\n0 0",
"4 1\n0 0\n0 0",
"4 2\n0 0\n0 -1",
"8... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Champernown constant is an irrational number represented in decimal by "0." followed by concatenation of all positive integers in the increasing order. The first few digits of this co... |
p01624 Ononokomachi's Edit War_7778 | Dr. Akita, who lives in the neighborhood, is a historical researcher in the field and recently discovered a new ancient document about Ono no Komachi.
It is widely known that Ono no Komachi has given General Fukakusa, who wants to be dating, on condition that he keeps going for 100 nights, but he claims that this disc... | INF = 100000000000000
def ev1(s):
ans = 0
try:
ans = eval(s)
if ans == (): raise Exception
if len(s)==0: raise Exception
except:
ans = -INF
return ans
def ev2(s):
ans = 0
try:
ans = eval(s)
if ans == (): raise Exception
if len(s)==0: rais... | {
"input": [
"1 1\n2 2\n3 1+2*3-4\n3 1|2^3&4\n3 (1+2)*3\n3 1-1-1-1\n0 #",
"1 1\n2 2\n6 1+2*3-4\n3 1|2^3&4\n3 (1+2)*3\n3 1-1-1-1\n0 #",
"1 1\n2 2\n6 1+2*3-4\n3 1|2^3&4\n4 (1+2)*3\n3 1-1-1-1\n0 #",
"1 1\n2 2\n1 1+2*3-4\n3 1|2^3&4\n4 (1+2)*3\n3 1-1-1-1\n0 #",
"1 1\n2 2\n1 1+2-3*4\n3 1|2^3&4\n4 (1+2)*... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Dr. Akita, who lives in the neighborhood, is a historical researcher in the field and recently discovered a new ancient document about Ono no Komachi.
It is widely known that Ono no ... |
p02191 Range Count Query_7785 | Range Count Query
Given the sequence a_1, a_2, .., a_N.
In the query, answer the number of terms whose value is l or more and r or less.
input
N Q
a_1 a_2 ... a_N
l_1 r_1
l_2 r_2
::
l_q r_q
output
ans_1
ans_2
::
ans_q
On line i, output the answer to the i-th query, that is, the number of j such as l_i \ leq ... | def num():
return int(input())
def nums():
return list(map(int,input().split()))
"""
N = num()
A = nums()
print(A.index(min(A))+1)
"""
"""
N = num()
A = set(nums())
print(len(A))
"""
def get_near_index(sorted_l,val,last):
left = 0
right = len(sorted_l) - 1
while left <= right:
mid = (right... | {
"input": [
"6 3\n8 6 9 1 2 1\n2 8\n1 7\n3 5",
"6 3\n8 6 15 1 2 1\n2 8\n1 7\n3 5",
"6 3\n8 6 15 1 1 1\n2 8\n1 7\n3 5",
"6 3\n8 6 12 3 1 1\n2 7\n1 7\n3 4",
"6 3\n4 6 12 3 1 1\n2 7\n1 7\n3 4",
"6 3\n4 6 1 3 1 1\n2 7\n1 7\n3 4",
"6 3\n4 6 1 0 1 1\n2 7\n1 7\n3 4",
"6 3\n4 6 1 0 2 1\n2 7\n... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Range Count Query
Given the sequence a_1, a_2, .., a_N.
In the query, answer the number of terms whose value is l or more and r or less.
input
N Q
a_1 a_2 ... a_N
l_1 r_1
l_2 r_2... |
p02345 Range Minimum Query (RMQ)_7789 | Write a program which manipulates a sequence A = {a0, a1, . . . , an-1} with the following operations:
* find(s, t): report the minimum element in as, as+1, . . . ,at.
* update(i, x): change ai to x.
Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
Constraints
* 1 ≤ n ≤ 100000
* 1 ≤ q ≤ 10000... | class SegTree:
def __init__(self,N,f,ini):
"""
f(val,ini)=ini
"""
n=1
while n<N: n<<=1
self.n=n
self.arr=[ini]*(2*n-1)
self.f,self.ini=f,ini
def update(self,i,val):
i += self.n-1
self.arr[i]=val
while i>0:
i... | {
"input": [
"3 5\n0 0 1\n0 1 2\n0 2 3\n1 0 2\n1 1 2",
"1 3\n1 0 0\n0 0 5\n1 0 0",
"1 3\n1 -1 0\n0 0 5\n1 0 0",
"3 5\n0 0 1\n0 1 2\n0 2 3\n1 0 2\n1 1 4",
"1 3\n1 -1 0\n0 0 9\n1 0 0",
"3 5\n0 0 1\n0 2 2\n0 2 3\n1 0 2\n1 1 2",
"1 3\n1 -1 0\n0 0 5\n0 0 0",
"1 3\n1 -1 0\n0 0 15\n1 0 0",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Write a program which manipulates a sequence A = {a0, a1, . . . , an-1} with the following operations:
* find(s, t): report the minimum element in as, as+1, . . . ,at.
* update(i, x)... |
1038_D. Slime_7801 | There are n slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it.
Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists).
When a slime with a value x eats a slime with a value y, the eaten slime disappears, and ... | import sys
import os
def solve(slimes):
if len(slimes) == 1:
return slimes[0]
havePos = False
haveNeg = False
for s in slimes:
if s > 0:
havePos = True
elif s < 0:
haveNeg = True
if havePos and haveNeg:
return sum(map(abs, slimes))
elif... | {
"input": [
"5\n0 -1 -1 -1 -1\n",
"4\n2 1 2 1\n",
"2\n-4 -5\n",
"10\n-20 0 3 -5 -18 15 -3 -9 -7 9\n",
"2\n-2 -2\n",
"8\n-1 5 -19 4 -12 20 1 -12\n",
"1\n-10\n",
"3\n-2 -4 -6\n",
"2\n10 8\n",
"9\n2 4 -4 15 1 11 15 -7 -20\n",
"2\n-2 -3\n",
"2\n-1 -5\n",
"3\n-1 -2 -3\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it.
Any slime can eat its adjacent slime (the closest slime to its left or to... |
1102_A. Integer Sequence Dividing_7809 | You are given an integer sequence 1, 2, ..., n. You have to divide it into two sets A and B in such a way that each element belongs to exactly one set and |sum(A) - sum(B)| is minimum possible.
The value |x| is the absolute value of x and sum(S) is the sum of elements of the set S.
Input
The first line of the input ... | def check(n):
if (n // 2) % 2 == 1:
return 0
return 1
n = int(input())
if n % 2 == 1:
print(check(n))
else:
print(check(n - 1))
| {
"input": [
"6\n",
"5\n",
"3\n",
"46369\n",
"1000003346\n",
"4\n",
"1000070102\n",
"123214213\n",
"999998\n",
"199999998\n",
"65538\n",
"999\n",
"1000271094\n",
"1244164813\n",
"1465465413\n",
"1999999999\n",
"999999998\n",
"1234567889\n",
"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an integer sequence 1, 2, ..., n. You have to divide it into two sets A and B in such a way that each element belongs to exactly one set and |sum(A) - sum(B)| is minimum... |
1130_A. Be Positive_7813 | You are given an array of n integers: a_1, a_2, …, a_n. Your task is to find some non-zero integer d (-10^3 ≤ d ≤ 10^3) such that, after each number in the array is divided by d, the number of positive numbers that are presented in the array is greater than or equal to half of the array size (i.e., at least ⌈n/2⌉). Not... | import itertools
def main():
n = int(input())
data = [int(v) for v in input().split()]
mv = n//2 if n%2==0 else n//2+1
for i in range(-1000, 1001):
if i==0:
continue
if len([v/i for v in data if v/i>0])>=mv:
print(i)
return
print(0)
if __name__ ... | {
"input": [
"7\n0 0 1 -1 0 0 2\n",
"5\n10 0 -7 2 6",
"100\n-261 613 -14 965 -114 -594 516 -631 -477 -352 -481 0 -224 -524 -841 397 -138 -986 -442 -568 -417 -850 -654 -193 -344 -648 -525 -394 -730 -712 -600 0 188 248 -657 -509 -647 -878 175 -894 -557 0 -367 -458 -35 -560 0 -952 -579 -784 -286 -303 -104 -9... | 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 integers: a_1, a_2, …, a_n. Your task is to find some non-zero integer d (-10^3 ≤ d ≤ 10^3) such that, after each number in the array is divided by d, the ... |
1150_B. Tiling Challenge_7817 | One day Alice was cleaning up her basement when she noticed something very curious: an infinite set of wooden pieces! Each piece was made of five square tiles, with four tiles adjacent to the fifth center tile:
<image> By the pieces lay a large square wooden board. The board is divided into n^2 cells arranged into n ... | n = int(input())
A = []
for i in range (n):
s = input()
A.append('#' + s + '#')
A.append('#' * (n + 2))
A.append('#' * (n + 2))
for i in range (n):
for j in range (1, n + 1):
#for k in range (n + 2):
# print(A[k])
#print(i, j)
#print()
#print()
if A[i][j] =... | {
"input": [
"3\n#.#\n...\n#.#\n",
"5\n#.###\n....#\n#....\n....#\n#..##\n",
"4\n##.#\n#...\n####\n##.#\n",
"5\n#.###\n....#\n#....\n###.#\n#####\n",
"20\n#.##.##.##.##.##.###\n...................#\n#..#..#..#..#..#....\n#................#.#\n#..#..#..#..#......#\n....................\n#..#..#..#.... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
One day Alice was cleaning up her basement when she noticed something very curious: an infinite set of wooden pieces! Each piece was made of five square tiles, with four tiles adjacen... |
1172_C1. Nauuo and Pictures (easy version)_7821 | The only difference between easy and hard versions is constraints.
Nauuo is a girl who loves random picture websites.
One day she made a random picture website by herself which includes n pictures.
When Nauuo visits the website, she sees exactly one picture. The website does not display each picture with equal proba... | P = 998244353
N, M = map(int, input().split())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
li = sum([A[i]*B[i] for i in range(N)])
di = sum([(A[i]^1)*B[i] for i in range(N)])
X = [[] for _ in range(M+1)]
X[0] = [1]
def calc(L):
su = sum(L)
pl = 0
pd = 0
RE = []
for i... | {
"input": [
"1 2\n1\n1\n",
"2 1\n0 1\n2 1\n",
"3 3\n0 1 1\n4 3 5\n",
"10 10\n0 1 0 0 1 1 1 1 1 1\n12 18 6 18 7 2 9 18 1 9\n",
"50 50\n0 0 0 1 0 1 0 1 0 1 0 1 0 0 1 0 0 1 0 0 0 1 1 0 0 1 1 0 1 0 1 1 1 0 0 1 1 1 1 0 1 1 1 0 0 0 1 1 0 1\n1 9 24 8 8 11 21 11 8 5 16 32 31 15 29 14 16 20 5 18 5 10 31 2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The only difference between easy and hard versions is constraints.
Nauuo is a girl who loves random picture websites.
One day she made a random picture website by herself which incl... |
118_D. Caesar's Legions_7825 | Gaius Julius Caesar, a famous general, loved to line up his soldiers. Overall the army had n1 footmen and n2 horsemen. Caesar thought that an arrangement is not beautiful if somewhere in the line there are strictly more that k1 footmen standing successively one after another, or there are strictly more than k2 horsemen... | R = lambda: map(int, input().split())
n1, n2, k1, k2 = R()
k1 = min(k1, n1)
k2 = min(k2, n2)
dp = [[[0] * 2 for j in range(n2 + 1)] for i in range(n1 + 1)]
for i in range(k1 + 1):
dp[i][0][0] = 1
for i in range(k2 + 1):
dp[0][i][1] = 1
for i in range(1, n1 + 1):
for j in range(1, n2 + 1):
dp[i][j][0... | {
"input": [
"2 1 1 10\n",
"2 3 1 2\n",
"2 4 1 1\n",
"12 15 7 2\n",
"34 55 2 9\n",
"46 51 4 5\n",
"2 1 1 1\n",
"10 10 5 7\n",
"2 2 1 2\n",
"100 99 10 10\n",
"1 2 1 1\n",
"24 30 5 1\n",
"18 4 3 1\n",
"100 100 10 10\n",
"34 57 1 1\n",
"56 40 3 2\n",
"1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Gaius Julius Caesar, a famous general, loved to line up his soldiers. Overall the army had n1 footmen and n2 horsemen. Caesar thought that an arrangement is not beautiful if somewhere... |
1209_C. Paint the Digits_7829 | You are given a sequence of n digits d_1d_2 ... d_{n}. You need to paint all the digits in two colors so that:
* each digit is painted either in the color 1 or in the color 2;
* if you write in a row from left to right all the digits painted in the color 1, and then after them all the digits painted in the color ... | for _ in range(int(input())):
n = int(input())
d = [*map(int, input())]
s = d[:]
s.sort()
o = []
i = 0
ans = []
for j in range(n):
if d[j] == s[i]:
ans.append('1')
i += 1
else:
ans.append('2')
t = []
for i in range(n):
if ans[i] == '1':
t.append(d[i])
for i in range(n):
if ans[i... | {
"input": [
"5\n12\n040425524644\n1\n0\n9\n123456789\n2\n98\n3\n987\n",
"5\n4\n6148\n1\n7\n5\n49522\n3\n882\n2\n51\n",
"5\n1\n3\n5\n74730\n1\n4\n5\n49554\n2\n59\n",
"5\n1\n3\n5\n74730\n1\n4\n5\n19908\n2\n59\n",
"5\n1\n3\n5\n74730\n1\n4\n5\n19908\n2\n50\n",
"5\n12\n040425524644\n1\n0\n9\n18710... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a sequence of n digits d_1d_2 ... d_{n}. You need to paint all the digits in two colors so that:
* each digit is painted either in the color 1 or in the color 2;
*... |
1228_B. Filling the Grid_7833 | Suppose there is a h × w grid consisting of empty or full cells. Let's make some definitions:
* r_{i} is the number of consecutive full cells connected to the left side in the i-th row (1 ≤ i ≤ h). In particular, r_i=0 if the leftmost cell of the i-th row is empty.
* c_{j} is the number of consecutive full cells ... | n, m = map(int, input().split())
row = list(map(int, input().split()))
col = list(map(int, input().split()))
grid = [['?'] * m for _ in range(n)]
for i in range(n):
lng = row[i]
for j in range(lng):
grid[i][j] = 'b'
if lng < m:
grid[i][lng] = 'w'
for i in range(m):
lng = col[i]
for j... | {
"input": [
"19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4\n",
"3 4\n0 3 1\n0 2 3 0\n",
"1 1\n0\n1\n",
"2 2\n1 1\n1 0\n",
"1 1\n1\n0\n",
"4 4\n2 0 3 1\n1 3 0 3\n",
"3 5\n4 3 2\n3 2 2 1 0\n",
"2 4\n2 2\n0 0 0 2\n",
"4 5\n2 5 2 2\n4 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Suppose there is a h × w grid consisting of empty or full cells. Let's make some definitions:
* r_{i} is the number of consecutive full cells connected to the left side in the i-th... |
1270_B. Interesting Subarray_7837 | For an array a of integers let's denote its maximal element as max(a), and minimal as min(a). We will call an array a of k integers interesting if max(a) - min(a) ≥ k. For example, array [1, 3, 4, 3] isn't interesting as max(a) - min(a) = 4 - 1 = 3 < 4 while array [7, 3, 0, 4, 3] is as max(a) - min(a) = 7 - 0 = 7 ≥ 5.
... | def findsubarray(n,ll):
for i in range(0,n-1):
if abs(ll[i]-ll[i+1])>1:
return 1,i+1,i+2
return 0,None,None
tests = int(input())
for i in range(0,tests):
numberlen = int(input())
numbers = input().split()
numberss = list(map(int,numbers))
result, left,right = findsub... | {
"input": [
"3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020\n",
"1\n16\n1 2 3 4 4 4 2 4 4 4 4 4 5 5 5 5\n",
"1\n8\n1 2 2 2 4 4 4 5\n",
"1\n14\n1 2 3 4 5 4 2 3 4 5 4 3 2 1\n",
"1\n11\n1 2 3 4 5 6 7 6 5 4 6\n",
"1\n9\n2 4 3 2 1 2 3 4 5\n",
"1\n10\n1 2 3 4 4 6 7 7 8 9\n",
"1\n24\n1 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:
For an array a of integers let's denote its maximal element as max(a), and minimal as min(a). We will call an array a of k integers interesting if max(a) - min(a) ≥ k. For example, ar... |
1292_F. Nora's Toy Boxes_7840 | [SIHanatsuka - EMber](https://soundcloud.com/hanatsuka/sihanatsuka-ember)
[SIHanatsuka - ATONEMENT](https://soundcloud.com/hanatsuka/sihanatsuka-atonement)
Back in time, the seven-year-old Nora used to play lots of games with her creation ROBO_Head-02, both to have fun and enhance his abilities.
One day, Nora's adop... | MOD = 1000000007
def isSubset(a, b):
return (a & b) == a
def isIntersect(a, b):
return (a & b) != 0
# Solve for each weakly connected component (WCC)
def cntOrder(s, t):
p = len(s)
m = len(t)
inMask = [0 for i in range(m)]
for x in range(p):
for i in range(m):
if t[i] % s[x] == 0:
inMask[i] |= 1 ... | {
"input": [
"4\n5 7 2 9\n",
"3\n2 6 8\n",
"5\n2 3 4 9 12\n",
"45\n41 50 11 34 39 40 9 22 48 6 31 16 13 8 20 42 27 45 15 43 32 38 28 10 46 17 21 33 4 18 35 14 37 23 29 2 49 19 12 44 36 24 30 26 3\n",
"60\n51 18 41 48 9 10 7 2 34 23 31 55 28 29 47 42 14 30 60 43 16 21 1 33 6 36 58 35 50 19 40 27 26... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
[SIHanatsuka - EMber](https://soundcloud.com/hanatsuka/sihanatsuka-ember)
[SIHanatsuka - ATONEMENT](https://soundcloud.com/hanatsuka/sihanatsuka-atonement)
Back in time, the seven-y... |
1312_G. Autocompletion_7843 | You are given a set of strings S. Each string consists of lowercase Latin letters.
For each string in this set, you want to calculate the minimum number of seconds required to type this string. To type a string, you have to start with an empty string and transform it into the string you want to type using the followin... | import io
import os
DEBUG = False
def dfs(trie, root, preorder=None, postorder=None):
stack = [root]
seen = set()
while stack:
nodeId = stack.pop()
if nodeId not in seen:
if preorder:
preorder(nodeId)
stack.append(nodeId)
seen.add(nodeId... | {
"input": [
"10\n0 i\n1 q\n2 g\n0 k\n1 e\n5 r\n4 m\n5 h\n3 p\n3 e\n5\n8 9 1 10 6\n",
"8\n0 a\n1 b\n2 a\n2 b\n4 a\n4 b\n5 c\n6 d\n5\n2 3 4 7 8\n",
"1\n0 z\n1\n1\n",
"10\n0 i\n1 q\n2 g\n0 k\n1 e\n5 r\n4 m\n5 h\n3 o\n3 e\n5\n8 9 1 10 6\n",
"10\n0 i\n1 q\n2 g\n0 k\n1 e\n5 r\n4 m\n4 g\n3 o\n3 e\n5\n8 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a set of strings S. Each string consists of lowercase Latin letters.
For each string in this set, you want to calculate the minimum number of seconds required to type t... |
1335_D. Anti-Sudoku_7847 | You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it [here](http://tiny.cc/636xmz).
The picture showing the correct sudoku solution:
<image>
Blocks are bordered with bold black color.
Your task is to change at most 9 elements of this field (i.e. choose s... | def f(grid):
for i in range(9):
for j in range(9):
if grid[i][j] == '1':
grid[i][j] = '2'
def main():
t = int(input())
for _ in range(t):
grid = [[x for x in input()] for __ in range(9)]
f(grid)
for row in grid:
print(''.join(row))
main() | {
"input": [
"1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563\n",
"3\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\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 correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it [here](http://tiny.cc/636xmz).
The picture showing the correct sudo... |
1375_E. Inversion SwapSort_7853 | Madeline has an array a of n integers. A pair (u, v) of integers forms an inversion in a if:
* 1 ≤ u < v ≤ n.
* a_u > a_v.
Madeline recently found a magical paper, which allows her to write two indices u and v and swap the values a_u and a_v. Being bored, she decided to write a list of pairs (u_i, v_i) with t... | n=int(input())
arr=list(map(int,input().split()))
ans=[]
for i in range(n):
for j in range(n-1,i,-1):
if arr[i]>arr[j]:
ans.append((arr[i],i+1,j+1))
ans=sorted(ans,key=lambda x:x[0])
ans=sorted(ans,reverse=True,key=lambda x:x[2])
print(len(ans))
for _,u,v in ans:
print(u,v) | {
"input": [
"4\n1 8 1 6\n",
"5\n1 1 1 2 2\n",
"3\n3 1 2\n",
"1\n1\n",
"20\n10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1\n",
"5\n3 4 3 1 2\n",
"100\n32 85 33 27 35 48 64 40 45 120 68 58 108 115 99 71 47 82 42 34 63 49 102 30 88 70 73 52 51 95 104 41 38 59 91 21 43 107 44 113 109 25 55 118 112... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Madeline has an array a of n integers. A pair (u, v) of integers forms an inversion in a if:
* 1 ≤ u < v ≤ n.
* a_u > a_v.
Madeline recently found a magical paper, which all... |
1399_A. Remove Smallest_7857 | You are given the array a consisting of n positive (greater than zero) integers.
In one move, you can choose two indices i and j (i ≠ j) such that the absolute difference between a_i and a_j is no more than one (|a_i - a_j| ≤ 1) and remove the smallest of these two elements. If two elements are equal, you can remove a... | def t(b):
if b:
print("YES")
return
print("NO")
for _ in range(int(input())):
a = int(input())
l = sorted(list(map(int, input().split())))
for i in range(a - 1):
if l[i + 1] - l[i] >= 2:
t(False)
break
else:
t(True)
| {
"input": [
"5\n3\n1 2 2\n4\n5 5 5 5\n3\n1 2 4\n4\n1 3 4 4\n1\n100\n",
"2\n3\n1 2 3\n4\n1 2 3 4\n",
"2\n3\n1 2 2\n4\n5 5 5 5\n",
"5\n2\n2 3\n4\n2 2 8 8\n3\n3 3 3\n4\n5 5 5 5\n4\n1 1 1 1\n",
"1\n1\n114\n",
"2\n3\n1 2 3\n4\n1 3 3 4\n",
"5\n2\n2 3\n4\n1 2 8 8\n3\n3 3 3\n4\n5 5 5 5\n4\n1 1 1 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given the array a consisting of n positive (greater than zero) integers.
In one move, you can choose two indices i and j (i ≠ j) such that the absolute difference between a_i... |
1422_D. Returning Home_7861 | Yura has been walking for some time already and is planning to return home. He needs to get home as fast as possible. To do this, Yura can use the instant-movement locations around the city.
Let's represent the city as an area of n × n square blocks. Yura needs to move from the block with coordinates (s_x,s_y) to the ... | from bisect import *
from collections import *
from math import *
from heapq import *
from typing import List
from itertools import *
from operator import *
from functools import *
import sys
'''
@lru_cache(None)
def fact(x):
if x<2:
return 1
return fact(x-1)*x
@lru_cache(None)
def per(i,j):
return... | {
"input": [
"84 5\n67 59 41 2\n39 56\n7 2\n15 3\n74 18\n22 7\n",
"5 3\n1 1 5 5\n1 2\n4 1\n3 3\n",
"1 0\n1 1 1 1\n",
"1000000000 0\n1 1000000000 1000000000 1\n",
"49397978 9\n35828361 4692148 30832063 21157937\n38015170 25815246\n25302604 1245031\n35710367 30096200\n20411634 24957987\n31626304 147... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Yura has been walking for some time already and is planning to return home. He needs to get home as fast as possible. To do this, Yura can use the instant-movement locations around th... |
1440_C1. Binary Table (Easy Version)_7865 | This is the easy version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved both versions of the problem.
You are given a binary table of size n × m. This table consists of symbols 0 and 1.
You can make such operat... | import sys
from itertools import permutations
from itertools import combinations
from itertools import combinations_with_replacement
#sys.stdin = open('/Users/pranjalkandhari/Desktop/Template/input.txt', 'r')
def makeThree(mat , i , j , liAns):
liToAdd = []
if(mat[i][j] == 1):
liToAdd.append(i)
... | {
"input": [
"5\n2 2\n10\n11\n3 3\n011\n101\n110\n4 4\n1111\n0110\n0110\n1111\n5 5\n01011\n11001\n00010\n11011\n10000\n2 3\n011\n101\n",
"5\n2 2\n10\n11\n3 3\n011\n101\n110\n4 4\n1111\n0110\n0110\n1111\n5 5\n01011\n11001\n00010\n11011\n10000\n2 3\n011\n101\n",
"5\n2 2\n10\n11\n3 3\n011\n101\n110\n4 4\n111... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This is the easy version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved bot... |
1467_D. Sum of Paths_7869 | There are n cells, numbered 1,2,..., n from left to right. You have to place a robot at any cell initially. The robot must make exactly k moves.
In one move, the robot must move one cell to the left or right, provided that it doesn't move out of bounds. In other words, if the robot was in the cell i, it must move to e... | 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.wri... | {
"input": [
"4 40 6\n92 21 82 46\n3 56\n1 72\n4 28\n1 97\n2 49\n2 88\n",
"5 2 5\n3 5 1 4 2\n1 9\n2 4\n3 6\n4 6\n5 2\n",
"5 1 5\n3 5 1 4 2\n1 9\n2 4\n3 6\n4 6\n5 2\n",
"4 40 6\n92 21 82 46\n3 56\n1 72\n4 28\n1 97\n3 49\n2 88\n",
"5 1 5\n3 5 1 4 2\n1 9\n2 4\n3 6\n4 7\n5 2\n",
"4 40 6\n92 21 82 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n cells, numbered 1,2,..., n from left to right. You have to place a robot at any cell initially. The robot must make exactly k moves.
In one move, the robot must move one ... |
1491_G. Switch and Flip_7873 | There are n coins labeled from 1 to n. Initially, coin c_i is on position i and is facing upwards ((c_1, c_2, ..., c_n) is a permutation of numbers from 1 to n). You can do some operations on these coins.
In one operation, you can do the following:
* Choose 2 distinct indices i and j.
* Then, swap the coins on ... | import sys
input = sys.stdin.readline
n = int(input());A = [0] + list(map(int, input().split()));seen = [0] * (n + 1);cycles = [];ans = []
for i in range(1, n + 1):
cur = [];j = i
while not seen[j]:cur.append(j);seen[j] = 1;j = A[j]
if len(cur) > 1: cycles.append(cur)
def swap(x, y):A[x], A[y] = A[y], A[x]... | {
"input": [
"5\n1 2 3 4 5\n",
"3\n2 1 3\n",
"4\n2 1 4 3\n",
"3\n2 3 1\n",
"3\n1 3 2\n",
"3\n3 1 2\n",
"3\n1 2 3\n",
"3\n3 2 1\n",
"4\n2 3 4 1\n"
],
"output": [
"\n0\n",
"\n3\n1 3\n3 2\n3 1\n",
"4\n1 3\n1 4\n3 2\n3 1\n",
"4\n1 2\n2 3\n1 3\n1 2\n",
"3\n2 1\n1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n coins labeled from 1 to n. Initially, coin c_i is on position i and is facing upwards ((c_1, c_2, ..., c_n) is a permutation of numbers from 1 to n). You can do some opera... |
1514_D. Cut and Stick_7877 | Baby Ehab has a piece of Cut and Stick with an array a of length n written on it. He plans to grab a pair of scissors and do the following to it:
* pick a range (l, r) and cut out every element a_l, a_{l + 1}, ..., a_r in this range;
* stick some of the elements together in the same order they were in the array; ... | from bisect import bisect, bisect_left
from random import random
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n, q = map(int, input().split())
a = list(map(int, input().split()))
v = [list() for i in range(n + 1)]
for i in range(n):
v[a[i]].append(i)
for i in range(q):
l, r = map(int, ... | {
"input": [
"6 2\n1 3 2 3 3 2\n1 6\n2 5\n",
"100 1\n1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 1 2 1 1 1 2 2 1 2 2 2 2 1 1 2 1 1 1 2 2 1 1 1 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 1 2 2 2 1 1 2 2 2 1 1 2 2 2 1 2 2 2\n1 100\n",
"1 1\n1\n1 1\n",
"100 1\n1 1 2 2 2 2 2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Baby Ehab has a piece of Cut and Stick with an array a of length n written on it. He plans to grab a pair of scissors and do the following to it:
* pick a range (l, r) and cut out ... |
1541_D. Tree Array_7881 | You are given a tree consisting of n nodes. You generate an array from the tree by marking nodes one by one.
Initially, when no nodes are marked, a node is equiprobably chosen and marked from the entire tree.
After that, until all nodes are marked, a node is equiprobably chosen and marked from the set of unmarked no... | from functools import lru_cache
from collections import deque
M = 10 ** 9 + 7
@lru_cache(None)
def inv(x):
return pow(x, M - 2, M)
@lru_cache(None)
def dp(u, v):
# u before v
if u == 0:
return 0
if v == 0:
return 1
return (dp(u - 1, v) * inv(2) + dp(u, v - 1) * inv(2)) % M
def... | {
"input": [
"5\n1 2\n1 3\n1 4\n2 5\n",
"3\n1 2\n1 3\n",
"6\n2 1\n2 3\n6 1\n1 4\n2 5\n",
"4\n1 2\n2 3\n3 4\n",
"2\n1 2\n",
"5\n1 2\n1 3\n1 4\n1 5\n",
"6\n2 1\n2 3\n6 1\n1 4\n1 5\n",
"6\n2 1\n1 3\n6 1\n1 4\n2 5\n",
"2\n2 1\n",
"5\n1 2\n1 3\n2 4\n2 5\n",
"3\n1 2\n2 3\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a tree consisting of n nodes. You generate an array from the tree by marking nodes one by one.
Initially, when no nodes are marked, a node is equiprobably chosen and ma... |
18_A. Triangle_7887 | At a geometry lesson Bob learnt that a triangle is called right-angled if it is nondegenerate and one of its angles is right. Bob decided to draw such a triangle immediately: on a sheet of paper he drew three points with integer coordinates, and joined them with segments of straight lines, then he showed the triangle t... | import math
"""
#include <cstdio>
#include <iostream>
#include <algorithm>
bool isRight(int *c){
int sides[3] = {0};
sides[0] = (c[4] - c[2]) * (c[4] - c[2]) + (c[5] - c[3])* (c[5] - c[3]);
sides[1] = (c[4] - c[0]) * (c[4] - c[0]) + (c[5] - c[1])* (c[5] - c[1]);
sides[2] = (c[2] - c[0]) * (c[2] - c[0]... | {
"input": [
"-1 0 2 0 0 1\n",
"2 3 4 5 6 6\n",
"0 0 2 0 0 1\n",
"30 8 49 13 25 27\n",
"-67 49 89 -76 -37 87\n",
"34 74 -2 -95 63 -33\n",
"-66 24 8 -29 17 62\n",
"-10 -11 62 6 -12 -3\n",
"49 -7 19 -76 26 3\n",
"0 0 1 0 4 1\n",
"-50 -1 0 50 0 -50\n",
"0 0 1 0 2 1\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
At a geometry lesson Bob learnt that a triangle is called right-angled if it is nondegenerate and one of its angles is right. Bob decided to draw such a triangle immediately: on a she... |
213_A. Game_7891 | Furik and Rubik love playing computer games. Furik has recently found a new game that greatly interested Rubik. The game consists of n parts and to complete each part a player may probably need to complete some other ones. We know that the game can be fully completed, that is, its parts do not form cyclic dependencies.... | n = int(input())
c = list(map(int, input().split()))
d = dict()
d[1] = []
d[2] = []
d[3] = []
for i in range(n):
d[c[i]].append(i)
done = set()
mas = []
k = 0
poss = set()
for i in range(n):
l = list(map(int, input().split()))
l = l[1:]
mas.append(l)
if len(l) == 0:
k = c[i]
poss.add... | {
"input": [
"1\n1\n0\n",
"5\n2 2 1 1 3\n1 5\n2 5 1\n2 5 4\n1 5\n0\n",
"25\n3 3 1 1 1 2 2 2 3 1 2 3 2 1 2 2 2 3 2 1 2 3 2 1 1\n0\n0\n0\n0\n0\n0\n1 12\n0\n1 19\n0\n2 12 21\n2 3 10\n0\n1 21\n0\n1 9\n1 3\n0\n0\n2 3 2\n0\n1 12\n0\n1 3\n2 21 9\n",
"21\n1 2 1 3 3 3 1 1 2 2 3 1 3 1 3 3 1 1 1 2 2\n1 5\n0\n1 1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Furik and Rubik love playing computer games. Furik has recently found a new game that greatly interested Rubik. The game consists of n parts and to complete each part a player may pro... |
237_A. Free Cash_7895 | Valera runs a 24/7 fast food cafe. He magically learned that next day n people will visit his cafe. For each person we know the arrival time: the i-th person comes exactly at hi hours mi minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than ... | t=int(input())
d={}
while (t>0):
t=t-1
s=input()
if s in d:
d[s]+=1
else:
d[s]=1
print(max(d.values())) | {
"input": [
"3\n0 12\n10 11\n22 22\n",
"4\n8 0\n8 10\n8 10\n8 45\n",
"1\n8 0\n",
"10\n0 39\n1 35\n1 49\n1 51\n5 24\n7 40\n7 56\n16 42\n23 33\n23 49\n",
"3\n0 0\n0 0\n0 0\n",
"50\n0 23\n1 21\n2 8\n2 45\n3 1\n4 19\n4 37\n7 7\n7 40\n8 43\n9 51\n10 13\n11 2\n11 19\n11 30\n12 37\n12 37\n12 37\n12 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Valera runs a 24/7 fast food cafe. He magically learned that next day n people will visit his cafe. For each person we know the arrival time: the i-th person comes exactly at hi hours... |
285_D. Permutation Sum_7901 | Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn.
Petya decided to introduce the sum operation on the se... | n = int(input())
ans = [1, 3, 5, 7, 9, 11, 13, 15]
dct = \
{
1 : 1,
3 : 18,
5 : 1800,
7 : 670320,
9 : 734832000,
11 : 890786230,
13 : 695720788,
15 : 150347555
}
if n in ans:
print(dct[n])
else:
print(0) | {
"input": [
"3\n",
"5\n",
"9\n",
"11\n",
"14\n",
"7\n",
"16\n",
"8\n",
"15\n",
"6\n",
"10\n",
"4\n",
"12\n",
"1\n",
"2\n",
"13\n",
"011\n",
"010\n",
"001\n"
],
"output": [
"18\n",
"1800\n",
"734832000\n",
"890786230\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p ... |
333_B. Chips_7907 | Gerald plays the following game. He has a checkered field of size n × n cells, where m various cells are banned. Before the game, he has to put a few chips on some border (but not corner) board cells. Then for n - 1 minutes, Gerald every minute moves each chip into an adjacent cell. He moves each chip from its original... | n, m = tuple(map(int, input().split(' ')))
vb = set()
hb = set()
for k in range(m):
i, j = tuple(map(int, input().split(' ')))
hb.add(i-1)
vb.add(j-1)
c = 0
for i in range(1, n//2):
c += 1 if i not in hb else 0
c += 1 if n-i-1 not in hb else 0
c += 1 if i not in vb else 0
c += 1 if n-i-1 not in vb else 0
c += 1 ... | {
"input": [
"4 3\n3 1\n3 2\n3 3\n",
"3 1\n2 2\n",
"3 0\n",
"5 5\n2 2\n5 3\n2 3\n5 1\n4 4\n",
"5 5\n3 2\n5 4\n3 3\n2 3\n1 2\n",
"6 5\n2 1\n6 4\n2 2\n4 3\n4 1\n",
"2 1\n1 1\n",
"5 5\n3 2\n1 4\n5 1\n4 5\n3 1\n",
"1000 0\n",
"2 3\n1 2\n2 1\n2 2\n",
"5 1\n3 2\n",
"6 5\n2 6\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Gerald plays the following game. He has a checkered field of size n × n cells, where m various cells are banned. Before the game, he has to put a few chips on some border (but not cor... |
37_A. Towers_7914 | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | x=int(input())
l=list(map(int,input().split()))
a=list(set(l))
l.sort()
maxx=l.count(0)
for i in range(len(l)):
if(l.count(l[i])>maxx):
maxx=l.count(l[i])
print(maxx,len(a))
| {
"input": [
"3\n1 2 3\n",
"4\n6 5 6 7\n",
"83\n246 535 994 33 390 927 321 97 223 922 812 705 79 80 977 457 476 636 511 137 6 360 815 319 717 674 368 551 714 628 278 713 761 553 184 414 623 753 428 214 581 115 439 61 677 216 772 592 187 603 658 310 439 559 870 376 109 321 189 337 277 26 70 734 796 907 979... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if thei... |
3_D. Least Cost Bracket Sequence_7918 | This is yet another problem on regular bracket sequences.
A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequences "(())()", "()" and "(()(()))" are regular, while ")(", "(()" and "(()))(" are not. You have a pattern of a bracket sequenc... | from heapq import heappush, heappop
from sys import stdin, exit
template = list(next(stdin).strip())
n, cost, balance = len(template), 0, 0
min_heap = []
for i in range(n):
if template[i] == '(':
balance += 1
elif template[i] == ')':
balance -= 1
else:
cost_left, cost_right = map(int, next(stdin).split())
... | {
"input": [
"(??)\n1 2\n2 8\n",
"???(?)??(??)?)(?(?????????(?()????)(????(?)????)???)??))(?(?????????))???(??)?????))???????(????????\n9 10\n6 3\n8 2\n9 10\n9 3\n6 2\n8 5\n6 7\n2 6\n7 8\n6 10\n1 7\n1 7\n10 7\n10 7\n8 4\n5 9\n9 3\n3 10\n1 10\n8 2\n8 8\n4 8\n6 6\n4 10\n4 5\n5 2\n5 6\n7 7\n7 3\n10 1\n1 4\n5 10\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This is yet another problem on regular bracket sequences.
A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For exam... |
427_A. Police Recruits_7922 | The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police offi... | n=int(input())
a=list(map(int,input().split()))
oc=0
cc=0
ans=0
for i in a:
if i>0:
oc+=i
elif oc==0:
ans+=1
else:
oc-=1
print(ans) | {
"input": [
"11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n",
"3\n-1 -1 1\n",
"8\n1 -1 1 -1 -1 1 1 1\n",
"1\n1\n",
"3\n-1 5 4\n",
"4\n-1 -1 1 1\n",
"98\n-1 -1 1 -1 -1 -1 -1 1 -1 -1 1 -1 -1 1 -1 1 1 1 -1 1 1 1 1 1 -1 1 -1 -1 -1 -1 1 -1 -1 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:
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occu... |
44_I. Toys_7926 | Little Masha loves arranging her toys into piles on the floor. And she also hates it when somebody touches her toys. One day Masha arranged all her n toys into several piles and then her elder brother Sasha came and gathered all the piles into one. Having seen it, Masha got very upset and started crying. Sasha still ca... | def combinacoes(x):
# Se for apenas 1 elemento retorna 1 arranjo
if x == 1:
return [[0]]
else:
# Adiciona os elementos a lista auxiliar
aux = combinacoes(x - 1)
pilha = []
par = 0
# Percorre a lista juntando os elementos nas possibilidades possíveis
for element in aux... | {
"input": [
"3\n",
"8\n",
"7\n",
"6\n",
"2\n",
"1\n",
"8\n",
"6\n",
"5\n",
"4\n",
"7\n",
"5\n",
"001\n"
],
"output": [
"5\n{1,2,3}\n{1,2},{3}\n{1},{2},{3}\n{1},{2,3}\n{1,3},{2}\n",
"4140\n{1,2,3,4,5,6,7,8}\n{1,2,3,4,5,6,7},{8}\n{1,2,3,4,5,6},{7},{8}\n{1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Little Masha loves arranging her toys into piles on the floor. And she also hates it when somebody touches her toys. One day Masha arranged all her n toys into several piles and then ... |
496_A. Minimum Difficulty_7931 | Mike is trying rock climbing but he is awful at it.
There are n holds on the wall, i-th hold is at height ai off the ground. Besides, let the sequence ai increase, that is, ai < ai + 1 for all i from 1 to n - 1; we will call such sequence a track. Mike thinks that the track a1, ..., an has difficulty <image>. In othe... | n=int(input())
lis=list(map(int,input().split()))
dif=abs(lis[1]-lis[0])
pos=[]
for i in range(n-1):
#print(i,end=",")
if(abs(lis[i]-lis[i+1])>dif):
dif=abs(lis[i]-lis[i+1])
for i in range(1,n-1):
t=abs(lis[i-1]-lis[i+1])
if(t>dif):
pos.append(t)
else:
pos.append(dif)
#print(... | {
"input": [
"3\n1 4 6\n",
"5\n1 2 3 4 5\n",
"5\n1 2 3 7 8\n",
"100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Mike is trying rock climbing but he is awful at it.
There are n holds on the wall, i-th hold is at height ai off the ground. Besides, let the sequence ai increase, that is, ai < ai ... |
51_D. Geometrical problem_7935 | Polycarp loves geometric progressions — he collects them. However, as such progressions occur very rarely, he also loves the sequences of numbers where it is enough to delete a single element to get a geometric progression.
In this task we shall define geometric progressions as finite sequences of numbers a1, a2, ...,... | def main():
n = int(input())
l = tuple(map(int, input().split()))
if n == 1:
return 0
if n == 2:
if l[0] == 0 and l[1] != 0: return 1
return 0
def div(a, b):
if b == 0: return 0 if a == 0 else "inf"
return a / b
pref, suff = [["init", 1]], [["init", 1]]
... | {
"input": [
"4\n3 6 12 24\n",
"4\n-8 -16 24 -32\n",
"4\n0 1 2 3\n",
"5\n1 -10 100 -1000 -10000\n",
"2\n0 -17\n",
"2\n7 0\n",
"5\n5 0 5 5 5\n",
"14\n1 1 -2 4 -8 16 -32 64 -128 256 -512 1024 -2048 4096\n",
"8\n729 243 81 27 9 9 3 1\n",
"4\n-1 -1 -1 1\n",
"2\n-17 -527\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarp loves geometric progressions — he collects them. However, as such progressions occur very rarely, he also loves the sequences of numbers where it is enough to delete a single... |
546_E. Soldier and Traveling_7939 | In the country there are n cities and m bidirectional roads between them. Each city has an army. Army of the i-th city consists of ai soldiers. Now soldiers roam. After roaming each soldier has to either stay in his city or to go to the one of neighboring cities by at moving along at most one road.
Check if is it poss... | from sys import stdin
from collections import deque
def bfs(g, el, source, dest, pre):
q = deque()
pre.clear()
pre.extend([None] * len(g))
q.append(source)
while q:
u = q.popleft()
for e in g[u]:
v, c, f = el[e][1], el[e][2], el[e][3]
if pre[v] is None and f < c and v != source:
pre[v] = e
q.app... | {
"input": [
"4 4\n1 2 6 3\n3 5 3 1\n1 2\n2 3\n3 4\n4 2\n",
"2 0\n1 2\n2 1\n",
"10 20\n22 3 4 48 12 12 14 37 15 37\n57 29 35 88 6 54 100 32 91 59\n10 1\n4 3\n4 7\n2 4\n7 6\n1 3\n2 5\n5 10\n1 6\n4 9\n6 10\n8 5\n3 6\n6 5\n8 9\n3 10\n2 6\n9 10\n8 4\n8 10\n",
"1 0\n2\n1\n",
"10 20\n39 65 24 71 86 59 8... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In the country there are n cities and m bidirectional roads between them. Each city has an army. Army of the i-th city consists of ai soldiers. Now soldiers roam. After roaming each s... |
573_B. Bear and Blocks_7943 | Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built n towers in a row. The i-th tower is made of hi identical blocks. For clarification see picture for the first sample.
Limak will repeat the following operation till everything is destroyed.
Block is called internal if i... | # Author : nitish420 --------------------------------------------------------------------
import os
import sys
from io import BytesIO, IOBase
def main():
n=int(input())
arr=list(map(int,input().split()))
if n<3:
print(1)
exit()
dp=[0]*(n)
dp[0]=1
dp[-1]=1
# first find min t... | {
"input": [
"6\n2 1 4 6 2 2\n",
"7\n3 3 3 1 3 3 3\n",
"10\n1 2 2 3 5 5 5 4 2 1\n",
"14\n20 20 20 20 20 20 3 20 20 20 20 20 20 20\n",
"170\n1 2 1 2 1 1 1 1 2 3 2 1 1 2 2 1 2 1 2 1 1 2 3 3 2 1 1 1 1 1 1 1 1 2 1 2 3 3 2 1 2 2 1 2 3 2 1 1 2 3 2 1 2 1 1 1 2 3 3 2 1 2 1 2 1 1 1 2 1 2 1 1 2 2 1 1 2 1 2 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built n towers in a row. The i-th tower is made of hi identical blocks. For clarification ... |
616_C. The Labyrinth_7948 | You are given a rectangular field of n × m cells. Each cell is either empty or impassable (contains an obstacle). Empty cells are marked with '.', impassable cells are marked with '*'. Let's call two empty cells adjacent if they share a side.
Let's call a connected component any non-extendible set of cells such that a... | from collections import deque
dirs = [[1, 0], [-1, 0], [0, 1], [0, -1]]
componentsizes = {}
componentid = 0
n, m = map(int, input().split())
field = [list(input()) for _ in range(n)]
def valid(y, x):
return y >= 0 and x >= 0 and y < n and x < m
def component(y, x):
size = 1
q = deque([(y, x)])
fiel... | {
"input": [
"4 5\n**..*\n..***\n.*.*.\n*.*.*\n",
"3 3\n*.*\n.*.\n*.*\n",
"10 1\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n",
"10 10\n*.*...*.**\n..*...*.**\n.**.***...\n....*.*.**\n***....***\n.*..*...*.\n.***.*..*.\n.*****.*.*\n*.***.*...\n..*..*....\n",
"1 1\n*\n",
"1 1\n.\n",
"10 1\n*\n*\n*\n*\n*\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a rectangular field of n × m cells. Each cell is either empty or impassable (contains an obstacle). Empty cells are marked with '.', impassable cells are marked with '*'... |
635_D. Factory Repairs_7951 | A factory produces thimbles in bulk. Typically, it can produce up to a thimbles a day. However, some of the machinery is defective, so it can currently only produce b thimbles each day. The factory intends to choose a k-day period to do maintenance and construction; it cannot produce any thimbles during this time, but ... | from functools import reduce
class SegmentTree():
def __init__(self, L, function = lambda x,y: x+y, initilizer = None):
self.function = function
self.initilizer = initilizer
N = self.size = len(L)
M = 1 << N.bit_length()
self.margin = 2*M - N
self.L = [None for i in r... | {
"input": [
"5 4 10 1 6\n1 1 5\n1 5 5\n1 3 2\n1 5 2\n2 1\n2 2\n",
"5 2 2 1 8\n1 1 2\n1 5 3\n1 2 1\n2 2\n1 4 2\n1 3 2\n2 1\n2 3\n",
"1 1 2 1 1\n2 1\n",
"1 1 2 0 1\n2 1\n",
"5 4 10 1 6\n1 1 5\n1 5 5\n1 3 2\n1 5 1\n2 1\n2 2\n",
"5 2 2 1 8\n1 1 2\n1 5 3\n1 2 1\n2 2\n1 4 0\n1 3 2\n2 1\n2 3\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A factory produces thimbles in bulk. Typically, it can produce up to a thimbles a day. However, some of the machinery is defective, so it can currently only produce b thimbles each da... |
664_C. International Olympiad_7955 | International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Amo... | from __future__ import print_function
dic = {"9":"1989","0":"1990","1":"1991","2":"1992","3":"1993","4":"1994","5":"1995","6":"1996","7":"1997","8":"1998"}
def get_year(s):
# print("came into get_year")
length=len(s)
if len(s)==1:
return dic[s]
pos=[s]
pre=1
if s[0]=="0" or len(s)<4 or (len(s)==4 and int(s)... | {
"input": [
"5\nIAO'15\nIAO'2015\nIAO'1\nIAO'9\nIAO'0\n",
"4\nIAO'9\nIAO'99\nIAO'999\nIAO'9999\n",
"1\nIAO'113098\n",
"1\nIAO'021113099\n",
"1\nIAO'10005000\n",
"1\nIAO'111111111\n",
"1\nIAO'11378\n",
"1\nIAO'111110\n",
"1\nIAO'001\n",
"1\nIAO'000000000\n",
"1\nIAO'2015\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of conseq... |
689_A. Mike and Cellphone_7959 | While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way:
<image>
Together with his old phone, he lost all his cont... | n = int(input())
s = input()
fill = [[False for i in range(3)] for j in range(4)]
for i in s:
if i == "0":
j = 10
else:
j = ord(i)-ord('1') #0, 1, 2, 3... 8
fill[j//3][j%3] = True
#for i in fill:
# print(i)
top = fill[0][0] or fill[0][1] or fill[0][2]
bottom = fill[2][0] or fill[3][1] or ... | {
"input": [
"9\n123456789\n",
"3\n911\n",
"3\n586\n",
"2\n09\n",
"2\n10\n",
"8\n42937903\n",
"7\n9454566\n",
"2\n05\n",
"4\n4268\n",
"4\n7844\n",
"2\n12\n",
"3\n780\n",
"7\n5740799\n",
"3\n159\n",
"6\n392965\n",
"1\n5\n",
"9\n515821866\n",
"4\n7... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The ... |
710_E. Generate a String_7963 | zscoder wants to generate an input file for some programming competition problem.
His input is a string consisting of n letters 'a'. He is too lazy to write a generator so he will manually generate the input in a text editor.
Initially, the text editor is empty. It takes him x seconds to insert or delete a letter 'a'... | n, x, y = map(int, input().split(" "))
l = [0.]*(n+1)
for i in range(1,n+1):
l[i] = min(l[i-1]+x, l[(i+1)//2]+y+(x*(i&1)))
print(int(l[n])) | {
"input": [
"8 1 10\n",
"8 1 1\n",
"1 1 1\n",
"3768 561740421 232937477\n",
"10000000 1 100\n",
"7789084 807239576 813643932\n",
"10000000 1 10\n",
"58087 1 100000000\n",
"10 62 99\n",
"9999999 987654321 123456789\n",
"35896 278270961 253614967\n",
"1926 84641582 82081... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
zscoder wants to generate an input file for some programming competition problem.
His input is a string consisting of n letters 'a'. He is too lazy to write a generator so he will ma... |
731_E. Funny Game_7967 | Once upon a time Petya and Gena gathered after another programming competition and decided to play some game. As they consider most modern games to be boring, they always try to invent their own games. They have only stickers and markers, but that won't stop them.
The game they came up with has the following rules. In... | n=int(input())
a=[0]+list(map(int, input().split()))
p=[0]
for i in range(1, n+1):
p+=[ p[-1]+a[i] ]
d=[ p[n] ]*(n+1)
for i in range(n-2, 0, -1):
d[i]=max(d[i+1], p[i+1]-d[i+1])
print(d[1])
| {
"input": [
"3\n2 4 8\n",
"4\n1 -7 -2 3\n",
"114\n46 7 39 21 44 31 49 57 26 22 86 45 66 72 96 15 77 38 92 88 50 68 30 55 20 5 15 11 26 66 94 74 43 73 35 7 11 36 26 74 86 52 14 5 91 71 3 75 22 7 10 97 42 41 52 80 97 31 45 59 53 85 87 63 42 51 98 61 26 96 65 22 47 0 36 27 35 69 81 58 9 43 7 98 27 56 101 2 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Once upon a time Petya and Gena gathered after another programming competition and decided to play some game. As they consider most modern games to be boring, they always try to inven... |
777_A. Shell Game_7973 | Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess... | def nap(y):
if y==0:
p=[0,1,2]
return p
if y==1:
p=[1,0,2]
return p
if y==2:
p=[1,2,0]
return p
if y==3:
p=[2,1,0]
return p
if y==4:
p=[2,0,1]
return p
if y==5:
p=[0,2,1]
return p
n=int(input())
x=int... | {
"input": [
"4\n2\n",
"1\n1\n",
"100000\n0\n",
"1999999997\n1\n",
"6\n0\n",
"1999999995\n0\n",
"4\n0\n",
"7\n0\n",
"6\n1\n",
"3\n1\n",
"123456789\n2\n",
"1234567890\n0\n",
"12\n0\n",
"7\n2\n",
"99996\n1\n",
"3\n2\n",
"2000000000\n2\n",
"20000000... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three si... |
801_D. Volatile Kite_7977 | You are given a convex polygon P with n distinct vertices p1, p2, ..., pn. Vertex pi has coordinates (xi, yi) in the 2D plane. These vertices are listed in clockwise order.
You can choose a real number D and move each vertex of the polygon a distance of at most D from their original positions.
Find the maximum value ... | from collections import Counter
n=int(input())
a=[]
for i in range(n):
a.append(list(map(int,input().split())))
#a.append(a[0])
m=10000000000
for i in range(-1,n-1):
b=a[i+1][0]-a[i-1][0]
c=a[i-1][1]-a[i+1][1]
d=-a[i-1][1]*b-a[i-1][0]*c
m=min(m,((a[i-1][0]-a[i][0])**2+(a[i-1][1]-a[i][1])**2)**0.5,\
... | {
"input": [
"6\n5 0\n10 0\n12 -4\n10 -8\n5 -8\n3 -4\n",
"4\n0 0\n0 1\n1 1\n1 0\n",
"4\n-100000 -100000\n-99999 -99999\n100000 99999\n0 -100\n",
"4\n0 0\n1 100\n100 0\n1 -100\n",
"4\n-1000000000 1000000000\n1000000000 500000000\n1000000000 -1000000000\n-500000000 -1000000000\n",
"4\n-10000 -10... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a convex polygon P with n distinct vertices p1, p2, ..., pn. Vertex pi has coordinates (xi, yi) in the 2D plane. These vertices are listed in clockwise order.
You can c... |
822_A. I'm bored with life_7981 | Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopo... |
arr1 = input().split()
a = int(arr1[0])
b = int(arr1[1])
c = int(min(a, b))
res = 1
for i in range(2, c+1):
res *= i
print(res) | {
"input": [
"4 3\n",
"22 12\n",
"8 9\n",
"20 12\n",
"12 12\n",
"3 999279109\n",
"11 999286606\n",
"7 999228288\n",
"12 22\n",
"1000000000 1\n",
"20 6\n",
"8 3\n",
"999639051 3\n",
"14 10\n",
"1 12\n",
"1213 5\n",
"12 23\n",
"1 1\n",
"12 13\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universi... |
847_F. Berland Elections_7985 | The elections to Berland parliament are happening today. Voting is in full swing!
Totally there are n candidates, they are numbered from 1 to n. Based on election results k (1 ≤ k ≤ n) top candidates will take seats in the parliament.
After the end of the voting the number of votes for each candidate is calculated. I... | class State:
__slots__ = ['candidate', 'votes', 'last_vote']
def __init__(self, cand, votes, last):
self.candidate = cand
self.votes = votes
self.last_vote = last
def beats(self, other, extra):
return self.votes + extra > other.votes
def main():
candidates, seats, people, voted = map(int, inp... | {
"input": [
"3 1 5 3\n1 3 1\n",
"3 2 5 3\n1 3 1\n",
"3 1 5 4\n1 2 1 3\n",
"23 13 85 26\n20 21 4 10 7 20 12 23 13 20 11 19 9 13 7 21 19 21 4 10 14 9 10 5 14 7\n",
"2 2 3 1\n1\n",
"71 28 95 28\n17 32 47 35 34 65 44 11 32 9 34 19 34 15 68 7 42 53 67 6 7 70 18 28 45 67 10 20\n",
"3 2 2 1\n3\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The elections to Berland parliament are happening today. Voting is in full swing!
Totally there are n candidates, they are numbered from 1 to n. Based on election results k (1 ≤ k ≤ ... |
869_A. The Artful Expedient_7989 | Rock... Paper!
After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows.
A positive integer n is decided first. Both Koyomi and Karen independently choose n distinct positive integers, denoted ... | # Main maut ko takiya, aur kafan ko chaadar banakar audhta hoon!
print("Karen") | {
"input": [
"3\n1 2 3\n4 5 6\n",
"5\n2 4 6 8 10\n9 7 5 3 1\n",
"1\n1\n2000000\n",
"1\n1048576\n1020000\n",
"3\n9 33 69\n71 74 100\n",
"30\n79656 68607 871714 1858841 237684 1177337 532141 161161 1111201 527235 323345 1979059 665353 507265 1290761 610606 1238375 743262 106355 1167830 180315 12... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Rock... Paper!
After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game wo... |
916_A. Jamie and Alarm Snooze_7995 | Jamie loves sleeping. One day, he decides that he needs to wake up at exactly hh: mm. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every x minutes until hh: mm is reached, and only then he will wake up. He wants to kno... | def lucky(a,b):
return '7' in str(a)+str(b)
x = int(input())
t = 0
h,m = map(int,input().split())
while not lucky(h,m):
t+=1
m -= x
while m<0:
m+=60
h-=1
h%=24
print(t)
| {
"input": [
"3\n11 23\n",
"5\n01 07\n",
"12\n00 06\n",
"60\n00 10\n",
"24\n17 51\n",
"2\n18 19\n",
"48\n07 11\n",
"1\n12 18\n",
"59\n06 18\n",
"60\n03 00\n",
"13\n00 00\n",
"5\n08 05\n",
"60\n01 24\n",
"54\n16 47\n",
"60\n13 29\n",
"10\n03 10\n",
"2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Jamie loves sleeping. One day, he decides that he needs to wake up at exactly hh: mm. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a... |
939_B. Hamster Farm_7999 | Dima has a hamsters farm. Soon N hamsters will grow up on it and Dima will sell them in a city nearby.
Hamsters should be transported in boxes. If some box is not completely full, the hamsters in it are bored, that's why each box should be completely full with hamsters.
Dima can buy boxes at a factory. The factory pr... | # -*- coding: utf-8 -*-
"""
Created on Fri Mar 2 22:09:34 2018
@author: Xiaohua
"""
def Hamster(amounts,boxsize):
a=10000000000000000000
result=[0,0]
for i in range(0,len(boxsize)):
if(amounts[0]%boxsize[i]<a):
a=amounts[0]%boxsize[i]
result[0]=i+1
re... | {
"input": [
"19 3\n5 4 10\n",
"28 3\n5 6 30\n",
"2 1\n2\n",
"1 1\n1\n",
"947264836 50\n977141206 956777871 186433588 538218068 759102378 327484438 88827268 266300062 670616672 756092978 414181331 913675814 898008516 343057716 99416265 236586817 52751842 550467703 684435578 844649988 917709231 550... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Dima has a hamsters farm. Soon N hamsters will grow up on it and Dima will sell them in a city nearby.
Hamsters should be transported in boxes. If some box is not completely full, th... |
991_E. Bus Number_8005 | This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either — although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longer and longer... It's no wonder he didn't get any sleep this night at all.
... | from itertools import chain, combinations
from collections import defaultdict
import math
def powerset(iterable):
xs = iterable
return chain.from_iterable(combinations(xs,n) for n in range(1, len(xs)+1))
def has(s):
h = 1
p = [2,3,5,7,11,13,17,19,23,29]
for i in s:
h *= p[i-1]
return h
h = set()
total ... | {
"input": [
"2028\n",
"97\n",
"10\n",
"868572419889505545\n",
"999999\n",
"74774\n",
"900008\n",
"101010101\n",
"234906817379759421\n",
"890009800\n",
"1\n",
"1000000\n",
"999999999\n",
"987654321\n",
"462534182594129378\n",
"4\n",
"9876543211234567... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either — although he played perfectly, his teammates let him down every time. He had to ... |
p02620 Introduction to Heuristics Contest - Incremental Scoring_8018 | You will be given a contest schedule for D days and M queries of schedule modification. In the i-th query, given integers d_i and q_i, change the type of contest to be held on day d_i to q_i, and then output the final satisfaction at the end of day D on the updated schedule. Note that we do not revert each query. That ... | NTEST = 26
D=int(input())
C=list(map(int,input().split()))
SL=list()
SL.append([0 for i in range(NTEST)])
for d in range(D):
S=list(map(int,input().split()))
SL.append(S)
tests=list()
tests.append(0)
for d in range(D):
tests.append(int(input()))
def calcSat(test_applied):
lastDay = [0 for i in rang... | {
"input": [
"5\n86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82\n19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424\n6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You will be given a contest schedule for D days and M queries of schedule modification. In the i-th query, given integers d_i and q_i, change the type of contest to be held on day d_i... |
p02751 Social Infrastructure Information Systems Division Hitachi Programming Contest 2020 - Odd Sum Rectangles_8021 | We have a grid with (2^N - 1) rows and (2^M-1) columns. You are asked to write 0 or 1 in each of these squares. Let a_{i,j} be the number written in the square at the i-th row from the top and the j-th column from the left.
For a quadruple of integers (i_1, i_2, j_1, j_2) such that 1\leq i_1 \leq i_2\leq 2^N-1, 1\leq ... | #!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdi... | {
"input": [
"1 2",
"1 1",
"2 2",
"2 1",
"3 2",
"4 1",
"3 3",
"5 1",
"1 3",
"3 1",
"2 3",
"1 6",
"5 2",
"4 2",
"3 4",
"2 4",
"1 4",
"1 7",
"8 2",
"3 8",
"2 7",
"1 10",
"2 6",
"2 5",
"2 8",
"3 6",
"10 2",
"6... | 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 (2^N - 1) rows and (2^M-1) columns. You are asked to write 0 or 1 in each of these squares. Let a_{i,j} be the number written in the square at the i-th row from th... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.