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 |
|---|---|---|---|---|---|
158_D. Ice Sculptures_23158 | The Berland University is preparing to celebrate the 256-th anniversary of its founding! A specially appointed Vice Rector for the celebration prepares to decorate the campus. In the center of the campus n ice sculptures were erected. The sculptures are arranged in a circle at equal distances from each other, so they f... | n=int(input())
s=list(map(int,input().split()))
max=0
for i in range(n):
max+=s[i]
for i in range(2,n):
if n%i==0 and n//i>=3:
for j in range(i):
sum=0
x=j
while(x<n):
sum+=s[x]
x+=i
if sum>max:max=sum
print(max) | {
"input": [
"6\n1 2 3 4 5 6\n",
"6\n1 -2 3 -4 5 -6\n",
"8\n1 2 -3 4 -5 5 2 3\n",
"12\n1 1 1 1 1 1 1 -1000 1 1 1 1\n",
"13\n6 7 8 2 5 1 -9 -6 9 10 8 9 -8\n",
"6\n1 0 1 0 1 0\n",
"4\n1 -10 1 -10\n",
"3\n-1 -1 -1\n",
"5\n0 -1 1 1 0\n",
"6\n-8 -8 6 5 -5 1\n",
"7\n0 55 -5 50 53... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The Berland University is preparing to celebrate the 256-th anniversary of its founding! A specially appointed Vice Rector for the celebration prepares to decorate the campus. In the ... |
200_B. Drinks_23164 | Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are n drinks in his fridge, the volume fraction of orange juice in the i-th drink equals pi percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportions of ea... | napitki = int(input())
apelsina_v_soke = [int(x) for x in input().split()]
kokteil = sum(apelsina_v_soke) / napitki
kokteil = format(kokteil, '.12f')
print(kokteil) | {
"input": [
"3\n50 50 100\n",
"4\n0 25 50 75\n",
"1\n0\n",
"13\n2 22 7 0 1 17 3 17 11 2 21 26 22\n",
"99\n60 65 40 63 57 44 30 84 3 10 39 53 40 45 72 20 76 11 61 32 4 26 97 55 14 57 86 96 34 69 52 22 26 79 31 4 21 35 82 47 81 28 72 70 93 84 40 4 69 39 83 58 30 7 32 73 74 12 92 23 61 88 9 58 70 32... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are n drinks in his fridge, the volume fraction of ora... |
225_A. Dice Tower_23168 | A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given constraints (both of them are shown on the picture on the left).
<imag... | q=int(input())
w=int(input())
k=0
for i in range(q):
e=list(map(int,input().split()))
if (w in e) or ((7-w) in e):
print('NO')
k=1
break
if k==0:
print('YES') | {
"input": [
"3\n3\n2 6\n4 1\n5 3\n",
"3\n6\n3 2\n5 4\n2 4\n",
"2\n4\n2 6\n5 4\n",
"96\n4\n1 5\n5 1\n6 5\n2 1\n2 1\n2 6\n6 5\n6 5\n6 2\n2 6\n1 5\n6 5\n1 5\n2 6\n6 5\n5 6\n2 1\n2 6\n1 2\n1 5\n2 6\n2 6\n2 1\n1 5\n5 1\n1 2\n2 6\n2 6\n6 5\n1 5\n2 1\n2 6\n1 2\n5 6\n1 5\n2 6\n6 2\n2 6\n6 5\n1 5\n6 5\n6 5\n1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two d... |
249_D. Donkey and Stars_23172 | In the evenings Donkey would join Shrek to look at the stars. They would sit on a log, sipping tea and they would watch the starry sky. The sky hung above the roof, right behind the chimney. Shrek's stars were to the right of the chimney and the Donkey's stars were to the left. Most days the Donkey would just count the... | import bisect
def INPUT():
global n, a, b, c, d
n = int(input())
a, b, c, d = [int(j) for i in input().split() for j in i.split("/")]
global y_alpha
y_alpha = []
for _ in range(n):
x, y = [int(x) for x in input().split()]
y_alpha.append((b * y - a * x, c * x - d * y))
if __name__ == '__main__':
INPUT()
y... | {
"input": [
"15\n1/3 2/1\n3 1\n6 2\n4 2\n2 5\n4 5\n6 6\n3 4\n1 6\n2 1\n7 4\n9 3\n5 3\n1 3\n15 5\n12 4\n",
"5\n0/17 74/0\n68877 18122\n96115 84747\n71027 43746\n31622 3444\n93281 34803\n",
"5\n3/18 18/17\n49797 95131\n5075 96918\n91898 7865\n91852 41070\n12076 45049\n",
"15\n1/4 2/1\n3 1\n6 2\n9 3\n12... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In the evenings Donkey would join Shrek to look at the stars. They would sit on a log, sipping tea and they would watch the starry sky. The sky hung above the roof, right behind the c... |
297_B. Fish Weight_23179 | It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be wi, then 0 < w1 ≤ w2 ≤ ... ≤ wk holds.
Polar bears Alice and Bob each have caught some fish, and they are g... | n,m,k=list(map(int,input().split()))
a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
for i in range(n):
if a[-i-1]>int(b[-i-1] if i<m else 0):
print('YES')
break
else:
print('NO') | {
"input": [
"4 7 9\n5 2 7 3\n3 5 2 7 3 8 7\n",
"3 3 3\n2 2 2\n1 1 3\n",
"25 25 10\n10 6 2 1 9 7 2 5 6 9 2 3 2 8 5 8 2 9 10 8 9 7 7 4 8\n6 2 10 4 7 9 3 2 4 5 1 8 6 9 8 6 9 8 4 8 7 9 10 2 8\n",
"7 7 10\n8 2 8 10 6 9 10\n2 4 9 5 6 2 5\n",
"1 1 1000000000\n502700350\n502700349\n",
"1 1 1\n1\n1\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight... |
31_E. TV Game_23183 | There is a new TV game on BerTV. In this game two players get a number A consisting of 2n digits. Before each turn players determine who will make the next move. Each player should make exactly n moves. On it's turn i-th player takes the leftmost digit of A and appends it to his or her number Si. After that this leftmo... | n = int(input())
s = input()
mat = [[[int(0),int(0),""] for _i in range(n+1)] for _j in range(n+1)]
for i in range(2*n):
digit = int(s[i])
toIter = min(i,n)
minh = max(i-n,0)
maxh = min(n,i)
for m in range(minh,maxh+1):
h = i - m
v = mat[h][m]
if h < n:
#add current symbol to homer
vnext = mat... | {
"input": [
"2\n1234\n",
"2\n9911\n",
"12\n254163163934611135461589\n",
"1\n21\n",
"4\n00013213\n",
"1\n01\n",
"5\n9823921785\n",
"18\n112233445566778899112233445566778899\n",
"18\n101011411002041200101000000000001000\n",
"15\n051911296923361789993851872792\n",
"18\n789998... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is a new TV game on BerTV. In this game two players get a number A consisting of 2n digits. Before each turn players determine who will make the next move. Each player should ma... |
368_B. Sereja and Suffixes_23189 | Sereja has an array a, consisting of n integers a1, a2, ..., an. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out m integers l1, l2, ..., lm (1 ≤ li ≤ n). For each number li he wants to know how many distinct numbers are staying on the positions li, li + 1, ...... | n, m = map(int, input().split())
l = list(map(int, input().split()))
els = []
for i in range(m):
els.append(int(input()))
b = set()
aux = [0]*n
cont = 0
for i in range(n-1, -1, -1):
if l[i] not in b:
b.add(l[i])
cont += 1
aux[i] = cont
for i in els:
print(aux[i-1]) | {
"input": [
"10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n",
"1 5\n5\n1\n1\n1\n1\n1\n",
"8 3\n8 6 4 3 4 2 4 8\n6\n4\n2\n",
"4 7\n3 1 4 2\n4\n1\n2\n3\n2\n4\n4\n",
"1 1\n1\n1\n",
"7 1\n68346 10956 76708 23018 84063 34833 80407\n1\n",
"10 2\n2 6 5 7 2 2 3 2 4 8\n1\n2\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Sereja has an array a, consisting of n integers a1, a2, ..., an. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out m integers... |
412_B. Network Configuration_23196 | The R1 company wants to hold a web search championship. There were n computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly affects the result. The higher the speed of the Internet is, the faster the participant will find the necessar... | n,k=[int(i)for i in input().split()]
l1=list(map(int,input().strip().split()))
l1.sort()
print(l1[n-k]) | {
"input": [
"6 4\n100 20 40 20 50 50\n",
"3 2\n40 20 30\n",
"2 2\n200 300\n",
"100 1\n199 348 489 76 638 579 982 125 28 401 228 117 195 337 80 914 752 98 679 417 47 225 357 413 849 622 477 620 487 223 321 240 439 393 733 660 652 500 877 40 788 246 376 723 952 601 912 316 598 809 476 932 384 147 982 2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The R1 company wants to hold a web search championship. There were n computers given for the competition, each of them is connected to the Internet. The organizers believe that the da... |
439_D. Devu and his Brother_23200 | Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given two arrays a and b by their father. The array a is given to Devu and b to his brother.
As Devu is really a naughty kid, he wants the minimum value of his array a should be at least as much as the ma... | def costo(a, b, t):
resultado = 0
for elem in a:
resultado += max(t - elem, 0)
for elem in b:
resultado += max(elem - t, 0)
return resultado
m, n = tuple(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
inf, sup = min(a), max(b)
while ... | {
"input": [
"2 2\n2 3\n3 5\n",
"3 2\n1 2 3\n3 4\n",
"3 2\n4 5 6\n1 2\n",
"1 1\n2\n1\n",
"2 1\n2 2\n3\n",
"1 1\n100\n183299\n",
"1 1\n1\n1\n",
"1 2\n1\n2 2\n",
"10 10\n23 100 38 38 73 54 59 69 44 86\n100 100 100 100 100 100 100 100 100 100\n",
"1 1\n100\n4\n",
"1 1\n9999999... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given two arrays a and b by their father. The array a is given to Dev... |
461_A. Appleman and Toastman_23204 | Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks:
* Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman.
* Each time Applema... | n=int(input())
a=sorted([int(i) for i in input().split()])
l=len(a)
out=0
for i in range(l):
out+=(i+2)*a[i]
out-=a[l-1]
print(out)
| {
"input": [
"3\n3 1 5\n",
"1\n10\n",
"10\n2 2 2 5 5 6 10 10 10 10\n",
"10\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n",
"10\n8 10 2 5 6 2 4 7 2 1\n",
"10\n431255 724672 228496 397870 397870 397870 397870 724672 888642 431255\n",
"1\n1000000\n",
"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks:
* Each time Toastman gets a gro... |
508_E. Arthur and Brackets_23210 | Notice that the memory limit is non-standard.
Recently Arthur and Sasha have studied correct bracket sequences. Arthur understood this topic perfectly and become so amazed about correct bracket sequences, so he even got himself a favorite correct bracket sequence of length 2n. Unlike Arthur, Sasha understood the topic... | n = int(input())
L = [tuple(map(int, input().split(' '))) for i in range(n)]
ans = []
try :
for l,r in reversed(L) :
d,a=1,"("
while d < l :
d += len(ans[-1])
a += ans.pop()
if d > r : raise IndexError
a += ")"
ans.append(a)
except IndexError :
pri... | {
"input": [
"3\n2 3\n1 4\n1 4\n",
"3\n5 5\n3 3\n1 1\n",
"4\n1 1\n1 1\n1 1\n1 1\n",
"3\n5 5\n3 3\n2 2\n",
"4\n4 4\n1 1\n2 2\n2 2\n",
"50\n97 97\n61 61\n59 59\n29 29\n13 13\n7 7\n5 5\n3 3\n1 1\n3 3\n1 1\n13 13\n11 11\n9 9\n3 3\n1 1\n1 1\n1 1\n27 27\n25 25\n1 1\n21 21\n19 19\n17 17\n15 15\n5 5\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Notice that the memory limit is non-standard.
Recently Arthur and Sasha have studied correct bracket sequences. Arthur understood this topic perfectly and become so amazed about corr... |
533_B. Work Group_23214 | One Big Software Company has n employees numbered from 1 to n. The director is assigned number 1. Every employee of the company except the director has exactly one immediate superior. The director, of course, doesn't have a superior.
We will call person a a subordinates of another person b, if either b is an immediate... | n = int(input())
t = [list(map(int, input().split())) for q in range(n)]
t[0][0] = 0
n += 1
u = [-1e7] * n
v = [0] * n
for i, (j, a) in list(enumerate(t, 1))[::-1]:
u[i] = max(u[i], v[i] + a)
v[j], u[j] = max(v[j] + v[i], u[j] + u[i]), max(v[j] + u[i], u[j] + v[i])
print(u[1]) | {
"input": [
"7\n-1 3\n1 2\n1 1\n1 4\n4 5\n4 3\n5 2\n",
"20\n-1 100\n1 35\n1 22\n1 28\n1 2\n1 8\n1 17\n1 50\n5 37\n1 25\n1 29\n5 21\n4 16\n2 39\n1 41\n3 28\n3 30\n2 36\n2 26\n14 17\n",
"2\n-1 1\n1 2\n",
"3\n-1 1\n1 2\n1 3\n",
"4\n-1 1\n1 100\n1 100\n1 100\n",
"3\n-1 1\n1 2\n2 3\n",
"2\n-1 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
One Big Software Company has n employees numbered from 1 to n. The director is assigned number 1. Every employee of the company except the director has exactly one immediate superior.... |
558_A. Lala Land and Apple Trees_23218 | Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly n apple trees. Tree number i is located in a position xi and has ai apples growing on it. Amr wants to collect apples from the apple tre... | a = [list(map(int, input().split(" "))) for x in range(int(input()))]
pl = []; ol = []
for i in range(len(a)):
if a[i][0] < 0:
ol.append(a[i])
else:
pl.append(a[i])
pl.sort(); ol.sort(); ol.reverse()
del a; dl = abs(len(ol)-len(pl)); sum = int(0); j = 0
m = min(len(ol), len(pl))
if (len(pl) == 0... | {
"input": [
"2\n-1 5\n1 5\n",
"3\n1 9\n3 5\n7 10\n",
"3\n-2 2\n1 4\n-1 3\n",
"3\n-94146 4473\n28707 99079\n-4153 8857\n",
"2\n-100000 100000\n100000 99999\n",
"1\n1 1\n",
"18\n-18697 44186\n56333 51938\n-75688 49735\n77762 14039\n-43996 81060\n69700 49107\n74532 45568\n-94476 203\n-92347 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly... |
583_D. Once Again..._23222 | You are given an array of positive integers a1, a2, ..., an × T of length n × T. We know that for any i > n it is true that ai = ai - n. Find the length of the longest non-decreasing sequence of the given array.
Input
The first line contains two space-separated integers: n, T (1 ≤ n ≤ 100, 1 ≤ T ≤ 107). The second li... | 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.writabl... | {
"input": [
"4 3\n3 1 4 2\n",
"81 10683\n3 52 265 294 213 242 185 151 27 165 128 237 124 14 43 147 104 162 124 103 233 156 288 57 289 195 129 77 97 138 153 289 203 126 34 5 97 35 224 120 200 203 222 94 171 294 293 108 145 193 227 206 34 295 1 233 258 7 246 34 60 232 58 169 77 150 272 279 171 228 168 84 114 2... | 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 positive integers a1, a2, ..., an × T of length n × T. We know that for any i > n it is true that ai = ai - n. Find the length of the longest non-decreasing ... |
677_C. Vanya and Label_23232 | While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bit... | #------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
BUF... | {
"input": [
"V_V\n",
"Codeforces\n",
"z\n",
"UhXl\n",
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_\n",
"zHsIINYjVtU71kmM9E\n",
"6\n",
"Lb1T3sA4BcTx4KAgLIsl-dNOGDvimpxZOxJfMz6VC3nQkB3Y780qqX_1dnjjb59H9X\n",
"Bq\n",
"fRRNAdMvLFTX21T0FG5gyn7NG0SaIvzGG_g_SO\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got ne... |
6_C. Alice, Bob and Chocolate_23236 | Alice and Bob like games. And now they are ready to start a new game. They have placed n chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with... | n=int(input())
*l,=map(int,input().split())
a=b=i=0
j=n-1
while i<=j:
if a<=b:a+=l[i];i+=1
else:b+=l[j];j-=1
print(i,n-i)
#hello | {
"input": [
"5\n2 9 8 2 7\n",
"2\n1 1\n",
"4\n1 1 1 1\n",
"3\n1 1 1\n",
"4\n4 3 2 8\n",
"1\n6\n",
"6\n1 4 7 3 2 1\n",
"3\n6 8 4\n",
"2\n8 2\n",
"12\n4 2 7 1 9 5 6 2 7 8 5 7\n",
"1\n1\n",
"11\n7 9 1 8 7 1 7 1 4 8 1\n",
"13\n9 9 9 9 9 9 9 9 9 9 9 9 9\n",
"5\n1 9 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Alice and Bob like games. And now they are ready to start a new game. They have placed n chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, an... |
743_C. Vladik and fractions_23242 | Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer n he can represent fraction <image> as a sum of three distinct positive fractions in form <image>.
Help Vladik with that, i.e for a given n find three distinct positive integers x, y and z such that <image... | n = int(input())
if n == 1:
print(-1)
else:
print(n, n + 1, n + n ** 2)
| {
"input": [
"7\n",
"3\n",
"82\n",
"720\n",
"1239\n",
"9999\n",
"4938\n",
"9562\n",
"6143\n",
"7274\n",
"30\n",
"3112\n",
"28\n",
"8865\n",
"5\n",
"2023\n",
"1936\n",
"9998\n",
"9798\n",
"4999\n",
"1\n",
"513\n",
"9146\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer n he can represent fraction <image> as a sum of three distinct positi... |
78_D. Archer's Shot_23249 | A breakthrough among computer games, "Civilization XIII", is striking in its scale and elaborate details. Let's take a closer look at one of them.
The playing area in the game is split into congruent cells that are regular hexagons. The side of each cell is equal to 1. Each unit occupies exactly one cell of the playin... | import math
k = int(input())
n = int(k/3)*2 + 1
# print('n', n)
ans = 0
last = 0
while True:
point_to_check = (n+2)//2
# print('p', point_to_check)
x = 0.0
y = n# *math.sqrt(3)
# print('r', math.sqrt((x**2+y**2)))
# p1
x -= 0.5
y += 0.5 #* math.sqrt(3)
# print('r', math.sqrt... | {
"input": [
"4\n",
"5\n",
"3\n",
"10264\n",
"217\n",
"7\n",
"777777\n",
"47248\n",
"13\n",
"301\n",
"1034\n",
"6\n",
"6486\n",
"225481\n",
"1\n",
"403\n",
"6726\n",
"43\n",
"9\n",
"21352\n",
"999811\n",
"10000\n",
"999998\n",... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A breakthrough among computer games, "Civilization XIII", is striking in its scale and elaborate details. Let's take a closer look at one of them.
The playing area in the game is spl... |
811_A. Vladik and Courtesy_23253 | At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn.
More formally, the guys take turns giving each ot... | # coding: utf-8
import math
vs = ["Vladik", "Valera"]
a, b = map(int, input().split(" "))
an = math.floor(math.sqrt(a))
bn = 0
while True:
bn += 1
if b < bn * (bn + 1):
bn -= 1
break
print(vs[an > bn])
| {
"input": [
"1 1\n",
"7 6\n",
"2 2\n",
"1000000000 999982505\n",
"100 9\n",
"2 1\n",
"4 4\n",
"3 2\n",
"999963734 999994456\n",
"5 4\n",
"5 5\n",
"7 8\n",
"957985574 24997558\n",
"965161805 908862070\n",
"10 11\n",
"1 2\n",
"1000 996\n",
"103309... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought th... |
837_C. Two Seals_23257 | One very important person has a piece of paper in the form of a rectangle a × b.
Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).
A very importa... | n,A,B=map(int,input().split())
arr=[]
for x in range(n):
i,j=map(int,input().split())
arr.append([i,j])
ans=int(0)
i=int(0)
j=int(0)
for i in range(n):
for j in range(i+1,n):
a=arr[i][0]
b=arr[i][1]
c=arr[j][0]
d=arr[j][1]
temp=a*b+c*d
if(temp<=ans):
... | {
"input": [
"4 10 9\n2 3\n1 1\n5 10\n9 11\n",
"2 2 2\n1 2\n2 1\n",
"3 10 10\n6 6\n7 7\n20 5\n",
"2 2 4\n3 1\n2 2\n",
"2 4 6\n4 4\n4 2\n",
"1 100 50\n4 20\n",
"5 9 7\n2 8\n3 8\n2 8\n4 4\n2 2\n",
"6 7 5\n6 6\n4 7\n6 1\n4 1\n4 6\n1 5\n",
"2 2 3\n1 2\n2 2\n",
"6 8 5\n4 1\n3 3\n5 3... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
One very important person has a piece of paper in the form of a rectangle a × b.
Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the s... |
883_E. Field of Wonders_23263 | Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter ... | n = int(input())
S = input()
HaveLetters = set(list(S))
m = int(input())
words = []
CanLetters = set([chr(i) for i in range(ord("a"), ord("z") + 1)]) - HaveLetters
for _ in range(m):
Word = input()
for i in range(n):
if S[i] == "*":
if Word[i] in HaveLetters:
break
el... | {
"input": [
"3\na*a\n2\naaa\naba\n",
"4\na**d\n2\nabcd\nacbd\n",
"5\nlo*er\n2\nlover\nloser\n",
"2\n**\n1\naa\n",
"1\n*\n1\na\n",
"42\n*****o*******t********************oo******\n10\nvcrccobltkeidtxhsxhccaslkjhfyeqsetoowaemso\nuimjsoxifamvctkgqmrwhyjrgmlydczzqjoobnnwch\nuvmjsoqizfavctkxemrpay... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden... |
926_G. Large Bouquets_23268 | A flower shop has got n bouquets, and the i-th bouquet consists of ai flowers. Vasya, the manager of the shop, decided to make large bouquets from these bouquets.
Vasya thinks that a bouquet is large if it is made of two or more initial bouquets, and there is a constraint: the total number of flowers in a large bouqu... | n = int(input())
flowers = input().split()
odd = 0
ott = 0
for val in flowers:
if int(val) % 2 == 0:
odd += 1
else:
ott += 1
while ott > odd + 2:
ott -= 2
odd += 1
print(min(odd, ott))
| {
"input": [
"5\n2 3 4 2 7\n",
"6\n2 2 6 8 6 12\n",
"3\n11 4 10\n",
"4\n943543 151729 379602 589828\n",
"2\n468463 62253\n",
"1\n999999\n",
"20\n274039 899325 798709 157662 963297 276599 529230 80095 252956 980560 358150 82383 29856 901568 123794 275349 512273 508369 120076 170206\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A flower shop has got n bouquets, and the i-th bouquet consists of ai flowers. Vasya, the manager of the shop, decided to make large bouquets from these bouquets.
Vasya thinks that ... |
p02556 AtCoder Beginner Contest 178 - Dist Max_23285 | There are N points on the 2D plane, i-th of which is located on (x_i, y_i). There can be multiple points that share the same coordinate. What is the maximum possible Manhattan distance between two distinct points?
Here, the Manhattan distance between two points (x_i, y_i) and (x_j, y_j) is defined by |x_i-x_j| + |y_i-... | N=int(input())
x=[]
y=[]
for i in range(N):
b,c=map(int,input().split(" "))
x.append(b+c)
y.append(b-c)
print(max([max(x)-min(x),max(y)-min(y)])) | {
"input": [
"3\n1 1\n2 4\n3 2",
"2\n1 1\n1 1",
"3\n1 2\n2 4\n3 2",
"2\n0 1\n1 1",
"2\n0 0\n1 1",
"3\n1 2\n1 4\n3 1",
"2\n0 -1\n1 2",
"3\n0 0\n1 4\n6 1",
"3\n0 0\n2 4\n6 1",
"3\n0 0\n2 4\n9 1",
"3\n0 0\n2 5\n9 1",
"3\n-1 0\n2 5\n9 0",
"3\n-2 -1\n0 6\n9 0",
"3\n-... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are N points on the 2D plane, i-th of which is located on (x_i, y_i). There can be multiple points that share the same coordinate. What is the maximum possible Manhattan distanc... |
p02687 AtCoder Beginner Contest 166 - A?C_23289 | AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is held at a time.
The company holds these two types of contests alternately: an ARC follows an ABC and vice versa.
Given a string S representing the type of the contest held last week, print the str... | s = str(input())
print("ARC" if s == "ABC" else "ABC") | {
"input": [
"ABC"
],
"output": [
"ARC"
]
} | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is held at a time.
The company holds these two types of contest... |
p02816 AtCoder Beginner Contest 150 - Xor Shift_23292 | Given are two sequences a=\\{a_0,\ldots,a_{N-1}\\} and b=\\{b_0,\ldots,b_{N-1}\\} of N non-negative integers each.
Snuke will choose an integer k such that 0 \leq k < N and an integer x not less than 0, to make a new sequence of length N, a'=\\{a_0',\ldots,a_{N-1}'\\}, as follows:
* a_i'= a_{i+k \mod N}\ XOR \ x
F... | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = a + a[:-1]
da = [a[i] ^ a[i+1] for i in range(len(a) - 1)]
db = [b[i] ^ b[i+1] for i in range(len(b) - 1)]
fail = [0 for i in range(len(da))]
fail[0] = -1
p = 0
for q in range(2, len(da)):
while p >= 0 and da[q-1] != da[... | {
"input": [
"6\n0 1 3 7 6 4\n1 5 4 6 2 3",
"3\n0 2 1\n1 2 3",
"5\n0 0 0 0 0\n2 2 2 2 2",
"3\n0 2 1\n2 0 3",
"3\n0 2 1\n2 1 0",
"3\n0 2 0\n1 3 3",
"3\n1 0 1\n2 2 3",
"3\n0 2 1\n0 1 3",
"3\n0 0 1\n2 3 2",
"3\n1 0 1\n2 3 2",
"3\n0 1 1\n3 2 3",
"3\n1 2 1\n3 0 0",
"3\n0... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Given are two sequences a=\\{a_0,\ldots,a_{N-1}\\} and b=\\{b_0,\ldots,b_{N-1}\\} of N non-negative integers each.
Snuke will choose an integer k such that 0 \leq k < N and an intege... |
p02952 AtCoder Beginner Contest 136 - Uneven Numbers_23296 | Given is an integer N. Find the number of positive integers less than or equal to N that have an odd number of digits (in base ten without leading zeros).
Constraints
* 1 \leq N \leq 10^5
Input
Input is given from Standard Input in the following format:
N
Output
Print the number of positive integers less than ... | a = int(input())
b = [i for i in range(a) if len(str(i+1))%2!=0]
print(len(b)) | {
"input": [
"11",
"100000",
"136",
"2",
"100010",
"36",
"3",
"4",
"1",
"0",
"7",
"6",
"5",
"8",
"179",
"339",
"161",
"312",
"126",
"359",
"164",
"109",
"105",
"107",
"122",
"151",
"154",
"137",
"172",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Given is an integer N. Find the number of positive integers less than or equal to N that have an odd number of digits (in base ten without leading zeros).
Constraints
* 1 \leq N \le... |
p03088 AtCoder Beginner Contest 122 - We Like AGC_23300 | You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7:
* The string does not contain characters other than `A`, `C`, `G` and `T`.
* The string does not contain `AGC` as a substring.
* The condition above cannot be violated by swapping two adjacent chara... | N = int(input())
memo = [{} for i in range(N + 1)]
MOD = 10 ** 9 + 7
def ok(last4):
for i in range(4):
t = list(last4)
if i >= 1:
t[i], t[i - 1] = t[i - 1], t[i]
if "".join(t).count("AGC") >= 1:
return False
return True
def dfs(cur, l... | {
"input": [
"4",
"3",
"100",
"5",
"6",
"8",
"15",
"12",
"9",
"14",
"7",
"13",
"20",
"10",
"11",
"24",
"26",
"23",
"16",
"25",
"28",
"41",
"36",
"19",
"27",
"18",
"32",
"34",
"22",
"43",
"44",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7:
* The string does not contain characters other than `A`, `C`,... |
p03233 AtCoder Grand Contest 028 - Min Cost Cycle_23304 | We have a directed weighted graph with N vertices. Each vertex has two integers written on it, and the integers written on Vertex i are A_i and B_i.
In this graph, there is an edge from Vertex x to Vertex y for all pairs 1 \leq x,y \leq N, and its weight is {\rm min}(A_x,B_y).
We will consider a directed cycle in thi... | import sys
import socket
if socket.gethostname() in ['N551J', 'F551C']:
test_case = 'c1.in'
sys.stdin = open(test_case)
def read_int_list():
return list(map(int, input().split()))
def read_int():
return int(input())
def read_str_list():
return input().split()
def read_str():
return inpu... | {
"input": [
"3\n1 5\n4 2\n6 3",
"6\n19 92\n64 64\n78 48\n57 33\n73 6\n95 73",
"4\n1 5\n2 6\n3 7\n4 8",
"3\n2 5\n4 2\n6 3",
"6\n19 92\n64 64\n78 48\n57 33\n142 6\n95 73",
"4\n1 5\n2 6\n0 7\n4 8",
"3\n1 5\n4 4\n6 3",
"6\n19 92\n64 64\n29 48\n57 33\n142 6\n95 73",
"4\n1 5\n0 6\n0 7\n... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We have a directed weighted graph with N vertices. Each vertex has two integers written on it, and the integers written on Vertex i are A_i and B_i.
In this graph, there is an edge f... |
p03384 AtCoder Regular Contest 095 - Permutation Tree_23307 | Takahashi has an ability to generate a tree using a permutation (p_1,p_2,...,p_n) of (1,2,...,n), in the following process:
First, prepare Vertex 1, Vertex 2, ..., Vertex N. For each i=1,2,...,n, perform the following operation:
* If p_i = 1, do nothing.
* If p_i \neq 1, let j' be the largest j such that p_j < p_i. S... | import sys
from collections import deque
def diameter(n, links):
q = deque([(0, -1)])
v = 0
while q:
v, p = q.popleft()
q.extend((u, v) for u in links[v] if u != p)
q = deque([(v, -1)])
w = 0
parents = [-1] * n
while q:
w, p = q.popleft()
parents[w] = p
... | {
"input": [
"15\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n4 8\n4 9\n5 10\n5 11\n6 12\n6 13\n7 14\n7 15",
"6\n1 2\n1 3\n1 4\n1 5\n5 6",
"6\n1 2\n2 3\n3 4\n1 5\n5 6",
"6\n1 2\n2 3\n5 4\n1 5\n5 6",
"15\n1 2\n1 3\n2 4\n2 5\n3 6\n4 7\n4 8\n4 9\n5 10\n5 11\n6 12\n6 13\n7 14\n7 15",
"6\n1 2\n1 3\n1 4\n1 5\n4 6... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Takahashi has an ability to generate a tree using a permutation (p_1,p_2,...,p_n) of (1,2,...,n), in the following process:
First, prepare Vertex 1, Vertex 2, ..., Vertex N. For each... |
p03548 AtCoder Beginner Contest 078 - ISU_23311 | We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters.
We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two... | x,y,z=map(int,input().split())
x-=z
print(x//(z+y)) | {
"input": [
"100000 1 1",
"13 3 1",
"64145 123 456",
"12 3 1",
"64146 123 456",
"100010 1 1",
"8 3 1",
"64145 33 456",
"12 3 2",
"64146 123 44",
"100010 1 0",
"64145 33 653",
"64146 205 44",
"110010 1 0",
"8 3 3",
"64145 20 653",
"108320 205 44",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters.
We would... |
p03704 AtCoder Regular Contest 075 - Mirrored_23315 | For a positive integer n, we denote the integer obtained by reversing the decimal notation of n (without leading zeroes) by rev(n). For example, rev(123) = 321 and rev(4000) = 4.
You are given a positive integer D. How many positive integers N satisfy rev(N) = N + D?
Constraints
* D is an integer.
* 1 ≤ D < 10^9
In... | def solve(d, K):
r = 1
for k in range(K,1,-2):
if d >= 10**k:
return 0
t = (-d)%10
d = abs((d-t*(10**(k-1)-1))//10)
r *= 10-t-(K==k)
return r*(10**(K%2)) if d == 0 else 0
D = int(input())
result = 0
l = len(str(D))
for k in range(l,2*l+1):
result += solve(D, k)
print(result) | {
"input": [
"63",
"864197532",
"75",
"70",
"27",
"9",
"28269",
"729",
"-18",
"-45",
"-63",
"-54",
"-36",
"-495",
"72",
"-90",
"99",
"-396",
"180",
"198",
"6200730",
"-450",
"-279",
"-270",
"-297",
"-369",
"540... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
For a positive integer n, we denote the integer obtained by reversing the decimal notation of n (without leading zeroes) by rev(n). For example, rev(123) = 321 and rev(4000) = 4.
You... |
p03859 AtCoder Regular Contest 065 - Shuffling_23318 | There is a string S of length N consisting of characters `0` and `1`. You will perform the following operation for each i = 1, 2, ..., m:
* Arbitrarily permute the characters within the substring of S starting at the l_i-th character from the left and extending through the r_i-th character.
Here, the sequence l_i i... | # coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline
n,m = map(int,readline().split())
s = input()
mp = map(int,read().split())
r = list(range(n))
for i,j in zip(mp,mp):
if r[i-1] < j-1:
r[i-1] = j-1
for i in range(1,n):
if r[i] < r[i-1]: r[i] = r[i-1]
zer... | {
"input": [
"11 6\n00101000110\n2 4\n2 3\n4 7\n5 6\n6 10\n10 11",
"5 2\n01001\n2 4\n3 5",
"9 3\n110111110\n1 4\n4 6\n6 9",
"5 2\n01001\n1 4\n3 5",
"5 2\n01001\n1 5\n3 5",
"11 6\n00101000110\n2 4\n2 3\n4 4\n5 6\n6 10\n10 11",
"5 2\n01001\n2 4\n5 5",
"9 3\n110111110\n1 4\n4 6\n6 5",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is a string S of length N consisting of characters `0` and `1`. You will perform the following operation for each i = 1, 2, ..., m:
* Arbitrarily permute the characters within ... |
p00108 Operation of Frequency of Appearance_23324 | There is a frequency operation in the conversion operation of a finite number sequence. The conversion result of the sequence $ S = \\ {s_1, s_2, ... s_n \\} $ is a sequence of the same length. If the result is $ C = \\ {c_1, c_2, ..., c_n \\} $, then $ c_i $ represents the number of $ s_i $ in the sequence $ S $.
For... | from collections import Counter
def pr(s):
c=0
while 1:
b=s
t=Counter(s)
s=[t[i] for i in s]
c+=1
if b==s:break
return s,c-1
while 1:
le=int(input())
if not le:break
s=list(map(int,input().split()))
s,c=pr(s)
print(c)
print(" ".join(map(s... | {
"input": [
"10\n4 5 1 1 4 5 12 3 5 4\n0",
"10\n4 5 1 1 4 5 12 3 6 4\n0",
"10\n4 5 1 1 4 5 12 3 0 5\n0",
"10\n4 5 1 1 3 5 14 3 0 5\n0",
"10\n4 5 1 1 3 10 14 3 0 5\n0",
"10\n4 5 1 0 3 10 14 3 0 5\n0",
"10\n1 5 1 0 3 10 14 3 0 5\n0",
"10\n1 5 1 0 3 4 27 0 0 5\n0",
"10\n2 5 1 0 3 4 2... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is a frequency operation in the conversion operation of a finite number sequence. The conversion result of the sequence $ S = \\ {s_1, s_2, ... s_n \\} $ is a sequence of the sa... |
p00242 Input Candidates_23328 | Mobile phones are equipped with a function that displays input candidates in order to efficiently input texts such as emails. This records frequently used words and presents words that have the entered letters as initial letters as input candidates. For example, if you usually enter the word "computer" a lot, just ente... | from collections import defaultdict
while True:
n = int(input())
if n==0:
break
initial = defaultdict(set)
cnt = defaultdict(int)
for _ in range(n):
l = list(input().split())
for li in l:
initial[li[0]].add(li)
cnt[li] += 1
... | {
"input": [
"1\nben likes bananas the best among many fruits because bananas are sweet and cheap\nb\n1\nwinners get to visit aizu and the university of aizu and make many friends as well\na\n3\nask alex about\nthe answer for the\nassignment on android apps\na\n2\nprogramming is both\na sport and an intellectual ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Mobile phones are equipped with a function that displays input candidates in order to efficiently input texts such as emails. This records frequently used words and presents words tha... |
p00423 Card Game_23332 | Two players, A and B, play the game using cards with numbers from 0 to 9. First, the two arrange the given n cards face down in a horizontal row. After that, the two players turn their cards face up one by one from the left, and the owner of the card with the larger number takes the two cards. At this time, the sum of ... | while True:
n = int(input())
if n == 0:
break
pointA, pointB = 0, 0
for i in range(n):
cardA, cardB = map(int, input().split())
if cardA == cardB:
pointA += cardA
pointB += cardB
elif cardA > cardB:
pointA += cardA + cardB
else:... | {
"input": [
"3\n9 1\n5 4\n0 8\n3\n9 1\n5 4\n1 0\n3\n9 1\n5 5\n1 8\n0",
"3\n9 1\n5 4\n0 4\n3\n9 1\n5 4\n1 0\n3\n9 1\n5 5\n1 8\n0",
"3\n9 1\n5 4\n0 8\n3\n9 1\n5 4\n1 0\n3\n9 1\n5 0\n1 8\n0",
"3\n9 1\n5 4\n1 4\n3\n9 1\n5 4\n1 0\n3\n9 1\n5 5\n1 8\n0",
"3\n9 1\n5 4\n0 8\n3\n9 1\n5 4\n1 0\n3\n9 1\n5 0\... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Two players, A and B, play the game using cards with numbers from 0 to 9. First, the two arrange the given n cards face down in a horizontal row. After that, the two players turn thei... |
p00762 Biased Dice_23337 | Professor Random, known for his research on randomized algorithms, is now conducting an experiment on biased dice. His experiment consists of dropping a number of dice onto a plane, one after another from a fixed position above the plane. The dice fall onto the plane or dice already there, without rotating, and may rol... | def get_num(top): # 転がす番号の候補を決める
if top == 1:
return [5, 4]
elif top == 2:
return [6, 4]
elif top == 3:
return [6, 5]
elif top == 4:
return [6, 5]
elif top == 5:
return [6, 4]
elif top == 6:
return [5, 4]
def get_dir(num, front, top): # 転がる向きを決... | {
"input": [
"4\n6 4\n6 4\n6 4\n6 4\n2\n5 3\n5 3\n8\n4 2\n4 2\n4 2\n4 2\n4 2\n4 2\n4 2\n4 2\n6\n4 6\n1 5\n2 3\n5 3\n2 4\n4 2\n0",
"4\n6 4\n6 4\n6 4\n6 4\n2\n5 3\n5 3\n8\n4 2\n4 2\n4 2\n4 2\n4 2\n4 2\n4 2\n4 2\n6\n3 6\n1 5\n2 3\n5 3\n2 4\n4 2\n0",
"4\n6 4\n6 4\n6 4\n6 4\n2\n5 3\n5 3\n8\n4 2\n4 2\n4 2\n4 2\... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Professor Random, known for his research on randomized algorithms, is now conducting an experiment on biased dice. His experiment consists of dropping a number of dice onto a plane, o... |
p00894 Gift from the Goddess of Programming_23341 | The goddess of programming is reviewing a thick logbook, which is a yearly record of visitors to her holy altar of programming. The logbook also records her visits at the altar.
The altar attracts programmers from all over the world because one visitor is chosen every year and endowed with a gift of miracle programmin... | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]
def LI(): return [int(x) for x in sys.stdin.... | {
"input": [
"14\n04/21 09:00 I 000\n04/21 09:00 I 001\n04/21 09:15 I 002\n04/21 09:30 O 001\n04/21 09:45 O 000\n04/21 10:00 O 002\n04/28 09:00 I 003\n04/28 09:15 I 000\n04/28 09:30 I 004\n04/28 09:45 O 004\n04/28 10:00 O 000\n04/28 10:15 O 003\n04/29 20:00 I 002\n04/29 21:30 O 002\n20\n06/01 09:00 I 001\n06/01 0... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The goddess of programming is reviewing a thick logbook, which is a yearly record of visitors to her holy altar of programming. The logbook also records her visits at the altar.
The ... |
p01297 Safe Area_23348 | Nathan O. Davis is challenging a kind of shooter game. In this game, enemies emit laser beams from outside of the screen. A laser beam is a straight line with a certain thickness. Nathan moves a circular-shaped machine within the screen, in such a way it does not overlap a laser beam. As in many shooters, the machine i... | import sys
readline = sys.stdin.readline
write = sys.stdout.write
def cross_point(p0, q0, p1, q1):
x0, y0 = p0; x1, y1 = q0
x2, y2 = p1; x3, y3 = q1
dx0 = x1 - x0
dy0 = y1 - y0
dx1 = x3 - x2
dy1 = y3 - y2
s = (y0-y2)*dx1 - (x0-x2)*dy1
sm = dx0*dy1 - dy0*dx1
if sm == 0:
retu... | {
"input": [
"100 100 1 1\n50 0 50 100 50\n640 480 1 1\n0 0 640 480 100\n0 0 0 0",
"100 100 1 1\n50 0 50 100 50\n640 480 1 2\n0 0 640 480 100\n0 0 0 0",
"100 100 1 1\n62 0 50 100 50\n640 480 1 1\n0 0 640 480 100\n0 0 0 0",
"100 100 1 1\n50 0 50 100 50\n640 480 1 2\n0 0 640 480 110\n0 0 0 0",
"100 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Nathan O. Davis is challenging a kind of shooter game. In this game, enemies emit laser beams from outside of the screen. A laser beam is a straight line with a certain thickness. Nat... |
p02347 Range Search (kD Tree)_23358 | The range search problem consists of a set of attributed records S to determine which records from S intersect with a given range.
For n points on a plane, report a set of points which are within in a given range. Note that you do not need to consider insert and delete operations for the set.
Constraints
* 0 ≤ n ≤ 5... | import math
import sys
from bisect import bisect_left, bisect_right
from typing import List, Optional, Tuple
class KDTree(object):
def __init__(self, n: int) -> None:
self.n = n
self.root = int(math.sqrt(n))
self.coordinates = [(0, 0, 0)] * n
self.low: List[int] = []
self.h... | {
"input": [
"6\n2 1\n2 2\n4 2\n6 2\n3 3\n5 4\n2\n2 4 0 4\n4 10 2 5",
"6\n2 1\n2 2\n4 2\n6 2\n3 6\n5 4\n2\n2 4 0 4\n4 10 2 5",
"6\n2 1\n2 2\n4 2\n6 4\n3 6\n5 4\n2\n2 4 0 4\n4 10 4 5",
"6\n2 1\n2 2\n5 1\n6 4\n3 6\n5 4\n2\n2 4 0 4\n4 10 4 5",
"6\n0 1\n2 2\n5 1\n6 4\n3 6\n5 4\n2\n2 4 0 4\n4 10 4 5",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The range search problem consists of a set of attributed records S to determine which records from S intersect with a given range.
For n points on a plane, report a set of points whi... |
101_A. Homework_23368 | Once when Gerald studied in the first year at school, his teacher gave the class the following homework. She offered the students a string consisting of n small Latin letters; the task was to learn the way the letters that the string contains are written. However, as Gerald is too lazy, he has no desire whatsoever to l... | from collections import Counter
import operator
import random
a=list(input())
k=int(input())
omap=(Counter(a))
x=sorted(omap.items(), key = operator.itemgetter(1))
i=0
while(k>0 and i<len(x)):
if(x[i][1]<=k):
k=k-x[i][1]
del omap[x[i][0]]
else:
omap[x[i][0]]=omap[x[i][0]]-k
k=0
i+=1
print(len(omap))
ans=""... | {
"input": [
"abacaba\n4\n",
"aaaaa\n4\n",
"abcdefgh\n10\n",
"zimxucbrzojfqvizcopkplrpnvihveqpgvzszkubftoozrydxijokjxfhdfjracjonqupmnhadtsotxrxmwgno\n51\n",
"geovcaxzjyhxbpnbkbsxfpkyofopxquzzxeigdflfumisevzsjdywehxconimkkbvjyxbqlnmaphvnngcjqoefqkfzmiruubbcmv\n24\n",
"jeliuewohkqtghdneuuhcputwi... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Once when Gerald studied in the first year at school, his teacher gave the class the following homework. She offered the students a string consisting of n small Latin letters; the tas... |
1042_E. Vasya and Magic Matrix_23372 | Vasya has got a magic matrix a of size n × m. The rows of the matrix are numbered from 1 to n from top to bottom, the columns are numbered from 1 to m from left to right. Let a_{ij} be the element in the intersection of the i-th row and the j-th column.
Vasya has also got a chip. Initially, the chip is in the intersec... | import io, os
ns = iter(os.read(0, os.fstat(0).st_size).split()).__next__
MX = 10 ** 6
MOD = 998244353
n, m = int(ns()), int(ns())
a = [int(ns()) for i in range(n * m)]
s = (int(ns()) - 1) * m + int(ns()) - 1
inv = [1] * MX
for i in range(2, MX):
inv[i] = -(MOD // i) * inv[MOD % i] % MOD
ind = sorted(list(range... | {
"input": [
"2 3\n1 5 7\n2 3 1\n1 2\n",
"1 4\n1 1 2 1\n1 3\n",
"3 3\n2 0 1\n1 0 0\n0 0 0\n1 1\n",
"13 8\n5 7 7 7 9 1 10 7\n2 10 5 4 5 4 9 1\n8 6 10 8 10 9 9 5\n7 10 9 8 6 7 5 8\n1 6 4 2 4 9 3 10\n10 4 4 6 5 6 6 4\n7 5 3 9 8 5 1 3\n9 6 1 9 10 5 3 7\n6 3 7 6 9 9 1 6\n8 6 5 9 1 9 2 1\n1 8 2 8 9 7 3 3\n7... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya has got a magic matrix a of size n × m. The rows of the matrix are numbered from 1 to n from top to bottom, the columns are numbered from 1 to m from left to right. Let a_{ij} b... |
1065_D. Three Pieces_23376 | You stumbled upon a new kind of chess puzzles. The chessboard you are given is not necesserily 8 × 8, but it still is N × N. Each square has some number written on it, all the numbers are from 1 to N^2 and all the numbers are pairwise distinct. The j-th square in the i-th row has a number A_{ij} written on it.
In your... | import sys
from math import *
def minp():
return sys.stdin.readline().strip()
n = int(minp())
m = [None]*n
k = [None]*3
dp = [None]*3
dp[0] = [None]*(n*n)
dp[1] = [None]*(n*n)
dp[2] = [None]*(n*n)
path = [None]*(n*n)
for i in range(n):
m[i] = list(map(int, minp().split()))
for j in range(n):
path[m[i][j]-1] = (i... | {
"input": [
"3\n1 9 3\n8 6 7\n4 2 5\n",
"6\n32 17 18 23 26 33\n7 36 22 3 1 5\n30 9 8 34 27 21\n16 6 35 28 4 25\n29 19 24 13 11 12\n2 20 15 14 31 10\n",
"10\n38 18 27 74 94 4 45 82 83 88\n73 95 50 40 28 59 47 19 58 60\n23 75 14 22 97 81 3 85 87 6\n56 80 30 62 57 90 5 41 69 44\n72 46 70 32 11 76 91 1 77 17... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You stumbled upon a new kind of chess puzzles. The chessboard you are given is not necesserily 8 × 8, but it still is N × N. Each square has some number written on it, all the numbers... |
1088_B. Ehab and subtraction_23380 | You're given an array a. You should repeat the following operation k times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0.
Input
The first line contains integers n and k (1 ≤ n,k ≤ 10^5), the length ... | # coding: utf-8
# Your code here!
import sys
n,k = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
cnt = 0
prev = 0
for i in range(len(A)):
ans = A[i] - prev
if ans != 0:
print(ans)
prev = A[i]
cnt += 1
if cnt == k:
break
for _ in range(k-cn... | {
"input": [
"3 5\n1 2 3\n",
"4 2\n10 3 5 3\n",
"1 2\n1000000000\n",
"3 1\n3 5 10\n",
"7 5\n5 8 10 3 6 10 8\n",
"10 20\n9 10 9 10 10 9 3 10 9 3\n",
"50 30\n26 87 83 27 2 51 94 38 21 9 6 7 85 20 68 56 30 55 62 51 16 82 100 28 93 70 33 52 50 87 55 36 93 84 63 94 96 2 42 84 37 54 34 76 38 86 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You're given an array a. You should repeat the following operation k times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elemen... |
1107_B. Digital root_23384 | Today at the lesson of mathematics, Petya learns about the digital root.
The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-d... | n = int(input())
for _ in range(n):
k,x = map(int,input().split(" "))
print((k-1)*9+x) | {
"input": [
"3\n1 5\n5 2\n3 1\n",
"1\n123421 1\n",
"1\n123421 2\n",
"3\n1 5\n5 2\n5 1\n",
"1\n170261 2\n",
"3\n1 1\n5 2\n5 1\n",
"1\n11400 2\n",
"3\n1 2\n5 2\n5 1\n",
"1\n796 2\n",
"3\n1 2\n5 1\n5 1\n",
"1\n461 2\n",
"3\n1 4\n5 1\n5 1\n",
"1\n461 4\n",
"3\n1 2\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Today at the lesson of mathematics, Petya learns about the digital root.
The digital root of a non-negative integer is the single digit value obtained by an iterative process of summ... |
1136_B. Nastya Is Playing Computer Games_23388 | Finished her homework, Nastya decided to play computer games. Passing levels one by one, Nastya eventually faced a problem. Her mission is to leave a room, where a lot of monsters live, as quickly as possible.
There are n manholes in the room which are situated on one line, but, unfortunately, all the manholes are clo... | n,k=map(int,input().split())
print(n+min(k-1,n-k)+2*n) | {
"input": [
"5 1\n",
"2 2\n",
"4 2\n",
"44 1\n",
"4291 2145\n",
"2266 1133\n",
"1023 999\n",
"5000 888\n",
"5000 3378\n",
"2029 360\n",
"9 1\n",
"2563 1281\n",
"40 24\n",
"8 2\n",
"5000 539\n",
"2944 2468\n",
"8 4\n",
"10 9\n",
"530 530\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Finished her homework, Nastya decided to play computer games. Passing levels one by one, Nastya eventually faced a problem. Her mission is to leave a room, where a lot of monsters liv... |
1154_F. Shovels Shop_23392 | There are n shovels in the nearby shop. The i-th shovel costs a_i bourles.
Misha has to buy exactly k shovels. Each shovel can be bought no more than once.
Misha can buy shovels by several purchases. During one purchase he can choose any subset of remaining (non-bought) shovels and buy this subset.
There are also m ... | from sys import stdin, stdout
n, m, k = tuple(map(lambda x: int(x), stdin.readline().split()))
a = stdin.readline().split()
for i in range(len(a)):
a[i] = int(a[i])
prefix_sum = []
a = sorted(a, key=lambda x: x)
for x in a:
if prefix_sum:
prefix_sum.append(prefix_sum[-1] + x)
else:
prefix_s... | {
"input": [
"5 1 4\n2 5 7 4 6\n5 4\n",
"9 4 8\n6 8 5 1 8 1 1 2 1\n9 2\n8 4\n5 3\n9 7\n",
"7 4 5\n2 5 4 2 6 3 1\n2 1\n6 5\n2 1\n3 1\n",
"9 4 8\n6 8 5 1 8 1 1 2 1\n9 4\n8 4\n5 3\n9 7\n",
"7 4 5\n2 5 4 2 6 3 1\n2 1\n6 8\n2 1\n3 1\n",
"7 4 5\n2 5 4 2 6 3 2\n2 1\n6 8\n2 1\n3 1\n",
"9 4 8\n6 4 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n shovels in the nearby shop. The i-th shovel costs a_i bourles.
Misha has to buy exactly k shovels. Each shovel can be bought no more than once.
Misha can buy shovels by ... |
1176_D. Recover it!_23396 | Authors guessed an array a consisting of n integers; each integer is not less than 2 and not greater than 2 ⋅ 10^5. You don't know the array a, but you know the array b which is formed from it with the following sequence of operations:
1. Firstly, let the array b be equal to the array a;
2. Secondly, for each i f... | from sys import stdin, stdout
import collections
import math
import heapq
def primes(n):
""" Returns a list of primes < n """
sieve = [True] * n
for i in range(3,int(n**0.5)+1,2):
if sieve[i]:
sieve[i*i::2*i]=[False]*((n-i*i-1)//(2*i)+1)
return [2] + [i for i in range(3,n,2) if sie... | {
"input": [
"3\n3 5 2 3 2 4\n",
"1\n3 6\n",
"1\n2750131 199999\n",
"1\n3 2\n",
"1\n68914 137828\n",
"2\n1327 1847 2654 283\n",
"100\n3 3 2 2 3 2 3 2 2 2 2 3 3 2 2 2 2 2 3 3 3 2 3 3 3 2 2 2 3 3 2 3 2 2 3 2 3 2 2 2 3 2 3 3 3 2 3 3 3 2 2 3 3 3 3 3 2 3 2 2 2 3 3 3 2 3 3 3 3 2 2 3 2 3 2 3 2 3 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Authors guessed an array a consisting of n integers; each integer is not less than 2 and not greater than 2 ⋅ 10^5. You don't know the array a, but you know the array b which is forme... |
1195_C. Basketball Exercise_23400 | Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. 2 ⋅ n students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly n people in each row). Students are numbered from 1 to n in each row in order from ... | n=int(input())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
dp=[[-1,-1] for i in range(n-1)]
dp.append([a[n-1],b[n-1]])
dp.append([0,0])
for i in range(n-1):
dp[n-2-i][0]=a[n-2-i]+max(dp[n-1-i][1],dp[n-i][1])
dp[n-2-i][1]=b[n-2-i]+max(dp[n-1-i][0],dp[n-i][0])
print(max(dp[0][0],dp[0][... | {
"input": [
"5\n9 3 5 7 3\n5 8 1 4 5\n",
"1\n7\n4\n",
"3\n1 2 9\n10 1 1\n",
"1\n5\n8\n",
"100\n1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4\n4... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. 2 ⋅ n students have come to Demid's exercise session, and he lined up t... |
1234_E. Special Permutations_23404 | Let's define p_i(n) as the following permutation: [i, 1, 2, ..., i - 1, i + 1, ..., n]. This means that the i-th permutation is almost identity (i.e. which maps every element to itself) permutation but the element i is on the first position. Examples:
* p_1(4) = [1, 2, 3, 4];
* p_2(4) = [2, 1, 3, 4];
* p_3(4) ... | """
> File Name: e.py
> Author: Code_Bear
> Mail: secret
> Created Time: Tue Oct 15 17:00:25 2019
"""
#import sys
#input = sys.stdin.readline
def solver():
n, m = map(int, input().split())
s = list(map(int, input().split()))
xin, xout = [0] * (n + 10), [0] * (n + 10)
xsum = [0] * (n + ... | {
"input": [
"5 5\n2 1 5 3 5\n",
"4 4\n1 2 3 4\n",
"2 10\n1 2 1 1 2 2 2 2 2 2\n",
"2 10\n1 2 1 1 1 2 2 2 2 2\n",
"5 5\n3 1 5 3 5\n",
"3 10\n1 2 1 1 2 2 2 2 2 2\n",
"8 5\n3 1 5 3 5\n",
"8 5\n3 2 5 3 5\n",
"8 5\n3 2 8 3 5\n",
"8 5\n4 2 8 3 5\n",
"8 5\n4 2 8 3 6\n",
"10 5\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Let's define p_i(n) as the following permutation: [i, 1, 2, ..., i - 1, i + 1, ..., n]. This means that the i-th permutation is almost identity (i.e. which maps every element to itsel... |
1253_D. Harmonious Graph_23408 | You're given an undirected graph with n nodes and m edges. Nodes are numbered from 1 to n.
The graph is considered harmonious if and only if the following property holds:
* For every triple of integers (l, m, r) such that 1 ≤ l < m < r ≤ n, if there exists a path going from node l to node r, then there exists a pat... | import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(300000)
n, m = map(int, input().split())
sn, smx = list(range(n+1)), list(range(n+1))
def s_find(u):
p = []
while sn[u] != u:
p.append(u)
u = sn[u]
for v in p: sn[v] = u
return u
def s_union(u, v):
su, sv = s_find(... | {
"input": [
"200000 3\n7 9\n9 8\n4 5\n",
"14 8\n1 2\n2 7\n3 4\n6 3\n5 7\n3 8\n6 8\n11 12\n",
"500 5\n100 300\n200 400\n420 440\n430 450\n435 460\n",
"200000 1\n1 200000\n",
"3 1\n1 3\n",
"974 5\n100 300\n200 400\n420 440\n430 450\n435 460\n",
"5 1\n1 3\n",
"974 5\n100 300\n200 400\n42... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You're given an undirected graph with n nodes and m edges. Nodes are numbered from 1 to n.
The graph is considered harmonious if and only if the following property holds:
* For ev... |
1277_C. As Simple as One and Two_23412 | You are given a non-empty string s=s_1s_2... s_n, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string s if there is an integer j ... | t = int(input())
for _ in range(t):
s = input()
i = 0
R = []
while i < len(s):
# print(s[i:i+5])
if i+4<len(s) and s[i:i+5] == "twone":
# print('paso')
R.append(i+2+1)
i+=5
elif i+2<len(s) and (s[i:i+3] == "one" or s[i:i+3] == "two"):
... | {
"input": [
"10\nonetwonetwooneooonetwooo\ntwo\none\ntwooooo\nttttwo\nttwwoo\nooone\nonnne\noneeeee\noneeeeeeetwooooo\n",
"4\nonetwone\ntestme\noneoneone\ntwotwo\n",
"1\nzzzone\n",
"10\nonetwonetwooneooonetwooo\ntwo\none\ntwooooo\nttttwo\nttwwoo\nooone\nonnne\noneeeee\noneeeeeeetwooooo\n",
"4\non... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a non-empty string s=s_1s_2... s_n, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least ... |
1320_D. Reachable Strings_23415 | In this problem, we will deal with binary strings. Each character of a binary string is either a 0 or a 1. We will also deal with substrings; recall that a substring is a contiguous subsequence of a string. We denote the substring of string s starting from the l-th character and ending with the r-th character as s[l ..... | import sys
input = sys.stdin.readline
n=int(input())
t=input().strip()
q=int(input())
ZEROS=[0]*n
ZERO_ONE=[]
ONECOUNT=[0]*n
ind=0
count=0
for i in range(n):
ZEROS[i]=ind
if t[i]=="0":
ind+=1
ONECOUNT[i]=count%2
ZERO_ONE.append(count%2)
count=0
else:
count+=1
... | {
"input": [
"5\n11011\n3\n1 3 3\n1 4 2\n1 2 3\n",
"3\n010\n3\n1 3 1\n1 3 1\n3 2 1\n",
"10\n1100111011\n10\n10 10 1\n5 4 5\n6 10 1\n10 10 1\n10 10 1\n5 5 4\n6 10 1\n4 6 4\n10 10 1\n6 10 1\n",
"50\n01110100101100100100011001100001110010010000000101\n50\n27 18 7\n22 35 2\n50 35 1\n41 16 1\n27 5 5\n11 6 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In this problem, we will deal with binary strings. Each character of a binary string is either a 0 or a 1. We will also deal with substrings; recall that a substring is a contiguous s... |
133_B. Unary_23419 | Unary is a minimalistic Brainfuck dialect in which programs are written using only one token.
Brainfuck programs use 8 commands: "+", "-", "[", "]", "<", ">", "." and "," (their meaning is not important for the purposes of this problem). Unary programs are created from Brainfuck programs using the following algorithm... | # n=bin()
s=input()
ans=""
for i in s:
if i==">":
ans+="1000"
elif i=="<":
ans+="1001"
elif i =="+":
ans+="1010"
elif i=="-":
ans+="1011"
elif i==".":
ans+="1100"
elif i==",":
ans+="1101"
elif i=="[":
ans+="1110"
elif i=="]":
... | {
"input": [
"++++[>,.<-]\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:
Unary is a minimalistic Brainfuck dialect in which programs are written using only one token.
Brainfuck programs use 8 commands: "+", "-", "[", "]", "<", ">", "." and "," (their mea... |
1381_D. The Majestic Brown Tree Snake_23425 | There is an undirected tree of n vertices, connected by n-1 bidirectional edges. There is also a snake stuck inside of this tree. Its head is at vertex a and its tail is at vertex b. The snake's body occupies all vertices on the unique simple path between a and b.
The snake wants to know if it can reverse itself — tha... | import sys
T=int(sys.stdin.readline().strip())
#T=1
def dfs(x, h, fa):
stack_queue=[]
stack_queue.append((x,h,fa,0, 0))
while (len(stack_queue)>0) :
now=stack_queue.pop()
x,h,fa,r, idone=now
#print (x,r,idone,fa,stack_queue)
if r==0:
for i1 in range(idone,len(e[x])):
i=e[x][i1]
if fa==i:
... | {
"input": [
"4\n8 4 7\n1 2\n2 3\n1 4\n4 5\n4 6\n1 7\n7 8\n4 3 2\n4 3\n1 2\n2 3\n9 3 5\n1 2\n2 3\n3 4\n1 5\n5 6\n6 7\n1 8\n8 9\n16 15 12\n1 2\n2 3\n1 4\n4 5\n5 6\n6 7\n4 8\n8 9\n8 10\n10 11\n11 12\n11 13\n13 14\n10 15\n15 16\n",
"4\n8 4 7\n1 2\n2 3\n1 4\n4 5\n4 6\n1 7\n7 8\n4 3 2\n4 3\n1 2\n2 3\n9 3 5\n1 2\n2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is an undirected tree of n vertices, connected by n-1 bidirectional edges. There is also a snake stuck inside of this tree. Its head is at vertex a and its tail is at vertex b. ... |
1401_E. Divide Square_23429 | There is a square of size 10^6 × 10^6 on the coordinate plane with four points (0, 0), (0, 10^6), (10^6, 0), and (10^6, 10^6) as its vertices.
You are going to draw segments on the plane. All segments are either horizontal or vertical and intersect with at least one side of the square.
Now you are wondering how many ... | import sys, math
import io, os
data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
#from bisect import bisect_left as bl, bisect_right as br, insort
#from heapq import heapify, heappush, heappop
#from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
#def data(... | {
"input": [
"3 3\n2 3 1000000\n4 0 4\n3 0 1000000\n4 0 1\n2 0 5\n3 1 1000000\n",
"3 0\n3 1 1000000\n1 1 1000000\n2 1 1000000\n",
"1 1\n500000 1 1000000\n500000 0 999999\n",
"0 0\n",
"1 1\n83893 0 1000000\n507509 0 668083\n",
"0 1\n242110 453990 1000000\n",
"1 1\n231451 171893 1000000\n355... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is a square of size 10^6 × 10^6 on the coordinate plane with four points (0, 0), (0, 10^6), (10^6, 0), and (10^6, 10^6) as its vertices.
You are going to draw segments on the p... |
1446_C. Xor Tree_23434 | For a given sequence of distinct non-negative integers (b_1, b_2, ..., b_k) we determine if it is good in the following way:
* Consider a graph on k nodes, with numbers from b_1 to b_k written on them.
* For every i from 1 to k: find such j (1 ≤ j ≤ k, j≠ i), for which (b_i ⊕ b_j) is the smallest among all such j,... | from bisect import bisect_left
import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=0
tmp=0
t=bisect_left(a,0)
s=bisect_left(a,1<<31)
stack=[(0,1<<31,t,s,0)]
while stack:
l,r,l1,r1,score=stack.pop()
ans=max(score,ans)
if l+1==r:
an... | {
"input": [
"5\n0 1 5 2 6\n",
"7\n6 9 8 7 3 5 2\n",
"14\n39 16 34 2 15 19 30 43 37 36 51 33 13 55\n",
"109\n74 18 237 179 195 112 156 11 72 68 173 202 78 250 224 251 107 55 186 144 57 62 28 210 132 64 93 6 211 0 174 163 248 226 167 246 46 102 253 180 121 56 151 35 150 254 168 201 242 118 190 158 196 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
For a given sequence of distinct non-negative integers (b_1, b_2, ..., b_k) we determine if it is good in the following way:
* Consider a graph on k nodes, with numbers from b_1 to... |
1497_B. M-arrays_23440 | You are given an array a_1, a_2, …, a_n consisting of n positive integers and a positive integer m.
You should divide elements of this array into some arrays. You can order the elements in the new arrays as you want.
Let's call an array m-divisible if for each two adjacent numbers in the array (two numbers on the pos... | import math
for _ in range(int(input())):
n,m=map(int,input().split())
a=list(map(int,input().split()))
rems=[0]*m
for e in a:
rems[e%m]+=1
ans=1 if rems[0]>0 else 0
for i in range(1,m//2+1):
if rems[i]==0 and rems[m-i]==0:
continue
matched, unm... | {
"input": [
"4\n6 4\n2 2 8 6 9 4\n10 8\n1 1 1 5 2 4 4 8 6 7\n1 1\n666\n2 2\n2 4\n",
"4\n6 4\n1 2 8 6 9 4\n10 8\n1 1 1 5 2 4 4 8 6 7\n1 1\n666\n2 2\n2 4\n",
"4\n6 4\n1 2 8 3 9 4\n10 8\n1 1 1 5 2 4 4 8 6 7\n1 1\n666\n2 2\n2 4\n",
"4\n6 4\n1 2 8 3 11 4\n10 8\n1 1 1 5 2 4 4 8 6 13\n1 1\n666\n2 2\n2 4\n",... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an array a_1, a_2, …, a_n consisting of n positive integers and a positive integer m.
You should divide elements of this array into some arrays. You can order the eleme... |
151_A. Soft Drinking_23444 | This winter is so cold in Nvodsk! A group of n friends decided to buy k bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has l milliliters of the drink. Also they bought c limes and cut each of them into d slices. After that they found p grams of salt.
To make a toast, each friend needs nl ... | party = list(map(int, input().split()))
friends, bottles, ml, limes, lime_slices, salt, friend_ml, friend_salt = party
total_gas = bottles * ml
total_limes = limes * lime_slices
rotation_ml = friend_ml * friends
q_tosts = -1
while all(x >= 0 for x in (salt, total_gas, total_limes)):
total_gas -= rotation_ml
... | {
"input": [
"3 4 5 10 8 100 3 1\n",
"5 100 10 1 19 90 4 3\n",
"10 1000 1000 25 23 1 50 1\n",
"17 1000 1000 1000 1000 1000 3 7\n",
"3 5 3 7 6 10 3 1\n",
"3 4 3 5 3 6 2 1\n",
"1 6 5 5 5 8 3 1\n",
"115 1000 1000 1000 1000 1000 17 15\n",
"2 4 7 3 4 10 2 1\n",
"1 1000 1000 1000 100... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This winter is so cold in Nvodsk! A group of n friends decided to buy k bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has l milliliters of the drink. Al... |
1547_A. Shortest Path with Obstacle_23448 | There are three cells on an infinite 2-dimensional grid, labeled A, B, and F. Find the length of the shortest path from A to B if:
* in one move you can go to any of the four adjacent cells sharing a side;
* visiting the cell F is forbidden (it is an obstacle).
Input
The first line contains an integer t (1 ≤ ... | import sys
import bisect
#import math
#import itertools
def get_line(): return list(map(int, sys.stdin.readline().strip().split()))
def in1(): return int(input())
def decimalToBinary(n): return bin(n).replace("0b", "")
for _ in range(in1()):
t=get_line()
a1,a2=get_line()
b1,b2=get_line()
f1,f2=get_lin... | {
"input": [
"7\n\n1 1\n3 3\n2 2\n\n2 5\n2 1\n2 3\n\n1000 42\n1000 1\n1000 1000\n\n1 10\n3 10\n2 10\n\n3 8\n7 8\n3 7\n\n2 1\n4 1\n1 1\n\n1 344\n1 10\n1 1\n",
"7\n\n1 1\n3 3\n2 2\n\n2 5\n2 1\n2 3\n\n1000 42\n1000 1\n1000 1000\n\n1 10\n3 10\n2 10\n\n3 8\n7 8\n3 7\n\n2 1\n4 1\n1 1\n\n1 413\n1 10\n1 1\n",
"7\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are three cells on an infinite 2-dimensional grid, labeled A, B, and F. Find the length of the shortest path from A to B if:
* in one move you can go to any of the four adja... |
174_C. Range Increments_23452 | Polycarpus is an amateur programmer. Now he is analyzing a friend's program. He has already found there the function rangeIncrement(l, r), that adds 1 to each element of some array a for all indexes in the segment [l, r]. In other words, this function does the following:
function rangeIncrement(l,... | n = int(input())
big = 10 ** 5
last = (big + 1) * [ -1 ]
data = list(map(int, input().split()))
data.insert(0, 0)
data.append(0)
result = []
previous = 0
for pos, current in enumerate(data):
if current > previous:
for x in range(previous + 1, current + 1):
last[x] = pos
elif current < previ... | {
"input": [
"6\n1 2 1 1 4 1\n",
"5\n1 0 1 0 1\n",
"2\n2 1\n",
"3\n2 4 2\n",
"2\n1 1\n",
"3\n1 1 1\n",
"20\n1 6 8 9 10 10 11 11 10 10 9 6 6 6 6 4 3 2 1 0\n",
"3\n0 2 1\n",
"3\n2 2 1\n",
"2\n2 4\n",
"2\n1 3\n",
"1\n1\n",
"5\n1 0 2 1 0\n",
"20\n2 2 4 5 5 6 7 6 5 5... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarpus is an amateur programmer. Now he is analyzing a friend's program. He has already found there the function rangeIncrement(l, r), that adds 1 to each element of some array a ... |
242_A. Heads or Tails_23460 | Petya and Vasya are tossing a coin. Their friend Valera is appointed as a judge. The game is very simple. First Vasya tosses a coin x times, then Petya tosses a coin y times. If the tossing player gets head, he scores one point. If he gets tail, nobody gets any points. The winner is the player with most points by the e... | x, y, a, b = map(int, input().split())
ans = []
for x1 in range(a,x+1):
if x1<=b: continue
for y1 in range(b,y+1):
if x1>y1 and x1>=a and y1>=b: ans.append((x1,y1))
print(len(ans))
for x in ans: print(*x) | {
"input": [
"3 2 1 1\n",
"2 4 2 2\n",
"4 5 2 3\n",
"9 7 4 7\n",
"99 100 20 7\n",
"20 10 1 8\n",
"80 100 1 50\n",
"10 20 4 6\n",
"100 100 100 5\n",
"70 80 30 80\n",
"99 100 20 7\n",
"100 99 10 13\n",
"60 50 30 40\n",
"50 50 1 30\n",
"100 99 10 13\n",
"10... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Petya and Vasya are tossing a coin. Their friend Valera is appointed as a judge. The game is very simple. First Vasya tosses a coin x times, then Petya tosses a coin y times. If the t... |
267_B. Dominoes_23464 | You have a set of dominoes. Each domino is a rectangular tile with a line dividing its face into two square ends. Can you put all dominoes in a line one by one from left to right so that any two dominoes touched with the sides that had the same number of points? You can rotate the dominoes, changing the left and the ri... |
def euler(start):
s = [(start,0)]
ans = []
while s:
i,e = s[-1]
if i in mark:
mark.remove(i)
if degree[i]==0:
ans.append(e)
s.pop()
else:
for j,e in graph[i]:
if vis[abs(e)]==0:
degree[i]-=... | {
"input": [
"5\n1 2\n2 4\n2 4\n6 4\n2 1\n",
"100\n5 0\n6 4\n1 6\n2 2\n4 0\n0 4\n4 4\n4 0\n6 6\n0 2\n3 2\n0 4\n0 4\n2 0\n4 4\n0 4\n2 6\n4 2\n1 4\n2 5\n2 0\n3 2\n1 4\n5 4\n4 2\n2 4\n4 0\n0 1\n6 4\n2 1\n5 4\n4 0\n5 6\n4 1\n2 4\n6 1\n6 4\n2 5\n2 4\n3 3\n5 4\n6 4\n2 2\n2 5\n4 4\n5 2\n3 4\n1 0\n2 2\n5 6\n3 5\n6 0\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You have a set of dominoes. Each domino is a rectangular tile with a line dividing its face into two square ends. Can you put all dominoes in a line one by one from left to right so t... |
290_B. QR code_23468 | <image>
Input
The input contains two integers a1, a2 (0 ≤ ai ≤ 32), separated by a single space.
Output
Output a single integer.
Examples
Input
1 1
Output
0
Input
3 7
Output
0
Input
13 10
Output
1 | num = input().split()
print(int(num[0]) + int(num[1][::-1]))
| {
"input": [
"13 10\n",
"3 7\n",
"1 1\n",
"9 190952\n",
"4 236\n",
"6 12\n",
"6 2531\n",
"7 8518\n",
"8 2132\n",
"304089172 303455736\n",
"5 0\n",
"27 12\n",
"4 41\n",
"937477084 827336327\n",
"27 13\n",
"0 0\n",
"4 255\n",
"9 262143\n",
"32 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
<image>
Input
The input contains two integers a1, a2 (0 ≤ ai ≤ 32), separated by a single space.
Output
Output a single integer.
Examples
Input
1 1
Output
0
Input
3 7
O... |
316_A2. Special Task_23472 | Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get th... | import math
'''
r,c,n,k = map(int,input().split())
matrix = [['*' for row in range(c)] for column in range(r)]
for i in range(n):
x,y = map(int,input().split())
matrix[x-1][y-1] = '#'
ans = 0
for row1 in range(r):
for row2 in range(r):
if matrix[row1:row2+1].count('#') >= k:
ans+=1
for c... | {
"input": [
"1?AA\n",
"AJ\n",
"???\n",
"??JG?\n",
"9???\n",
"B?\n",
"A\n",
"IG5IJ\n",
"5??\n",
"????\n",
"?\n",
"???2\n",
"3??\n",
"?BB\n",
"7\n",
"H1I??\n",
"HH???\n",
"BC??\n",
"CB\n",
"?3?2\n",
"?J?5?\n",
"BBB?\n",
"102345... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the be... |
338_D. GCD Table_23476 | Consider a table G of size n × m such that G(i, j) = GCD(i, j) for all 1 ≤ i ≤ n, 1 ≤ j ≤ m. GCD(a, b) is the greatest common divisor of numbers a and b.
You have a sequence of positive integer numbers a1, a2, ..., ak. We say that this sequence occurs in table G if it coincides with consecutive elements in some row, s... |
from math import gcd
def LCM(a, b):
if min(a, b) == 0: return max(a, b)
return a // gcd(a, b) * b
class Eqn():
def __init__(self, r, mod):
self.r = r
self.mod = mod
def bye():
print("NO")
exit(0)
def exgcd(a, b):
if b == 0:
return (1, 0)
xp, yp = exgcd(b, a ... | {
"input": [
"100 8 5\n5 2 1 2 1\n",
"100 100 7\n1 2 3 4 5 6 7\n",
"100 100 5\n5 2 1 2 1\n",
"1000000000000 1000000000000 10\n99991 99992 99993 99994 99995 99996 99997 99998 99999 31000000000\n",
"991234567890 927215128595 5\n6 11 8 3 2000000014\n",
"54275126675 128566125 50\n1 1 3 1 1 3 7 1 9... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Consider a table G of size n × m such that G(i, j) = GCD(i, j) for all 1 ≤ i ≤ n, 1 ≤ j ≤ m. GCD(a, b) is the greatest common divisor of numbers a and b.
You have a sequence of posit... |
361_A. Levko and Table_23480 | Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.
Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them.
Input
The ... | n, p = map(int, input().split())
for i in range(n):
arr = []
for j in range(n):
arr.append("0")
arr[i] = str(p)
answer = " ".join(arr)
print(answer) | {
"input": [
"4 7\n",
"2 4\n",
"3 2\n",
"54 341\n",
"81 111\n",
"100 997\n",
"99 998\n",
"9 3\n",
"100 1000\n",
"92 460\n",
"31 581\n",
"99 2\n",
"1 407\n",
"4 7\n",
"100 100\n",
"100 999\n",
"99 1\n",
"2 7\n",
"1 8\n",
"11 547\n",
"3... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of... |
405_C. Unusual Product_23487 | Little Chris is a huge fan of linear algebra. This time he has been given a homework about the unusual square of a square matrix.
The dot product of two integer number vectors x and y of size n is the sum of the products of the corresponding components of the vectors. The unusual square of an n × n square matrix A is ... | # from operator import and_, xor
# from functools import reduce
# from itertools import chain
from sys import stdin
input = stdin.readline
n = int(input())
l = list(list(map(int, input().split())) for _ in range(n))
q = int(input())
output = []
ans = 0
# We don't care about anything except for the trace of the matrix... | {
"input": [
"3\n1 1 1\n0 1 1\n1 0 0\n12\n3\n2 3\n3\n2 2\n2 2\n1 3\n3\n3\n1 2\n2 1\n1 1\n3\n",
"1\n0\n5\n1 1\n3\n1 1\n1 1\n3\n",
"2\n1 0\n1 1\n6\n1 2\n3\n2 1\n3\n1 1\n3\n",
"3\n0 0 0\n0 0 1\n0 1 1\n3\n1 2\n1 3\n1 1\n",
"2\n1 1\n1 0\n5\n3\n1 1\n3\n2 1\n3\n",
"3\n1 0 1\n0 1 1\n1 0 1\n4\n3\n3\n3\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Little Chris is a huge fan of linear algebra. This time he has been given a homework about the unusual square of a square matrix.
The dot product of two integer number vectors x and ... |
432_D. Prefixes and Suffixes_23491 | You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character.
Let's introduce several definitions:
* A substring s[i..j] (1 ≤ i ≤ j ≤ |s|) of string s is string sisi + 1...sj.
* The prefix of string s of length l (1 ≤ l ≤ |s|) is string s[1..l].
* The suffix of string s o... | def zeta(s):
n = len(s)
z = [0]*n
l,r = 0,0
for i in range(1,n):
if(i<=r): z[i] = min(r-i+1,z[i-l])
while(i+z[i]<n and s[z[i]]==s[i+z[i]]):
z[i]+=1
if(i+z[i]-1>r):
l=i
r = i+z[i]-1
return z
s = input()
n = len(s)
z = zeta(s)
l = [0]*n
for i in z:
l[i]+=1
cum = [l[-1]]
for i in range(n-2,-1,-1):
cu... | {
"input": [
"AAA\n",
"ABACABA\n",
"ZZ\n",
"A\n",
"AXAXA\n",
"AB\n",
"AAAAAAAAAAAAAAAAXAAAAAAAAAAAAAAAAAAAAAAA\n",
"GERALDPAVELGERALDPAVEL\n",
"CODEFORCES\n",
"AXXAA\n",
"BA\n",
"GERALDPAVDLGERALDPAVEL\n",
"CODEFORCET\n",
"ABADABA\n",
"AA\n",
"AAADABA\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character.
Let's introduce several definitions:
* A substring s[i..j] (1 ≤ i ≤ j ≤ |s|) of... |
455_A. Boredom_23495 | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and... | n = int(input())
l = input().split()
g = [0]*100000
for i in l:
g[int(i)-1] += 1
'''
p = []
a = []
for i in range(100000):
b = g[i]
if b!=0:
a.append((i+1)*b)
else:
if a != []:
p.append(a)
a = []
def f(v):
if v==[]:
return 0
elif len(v)==1:
... | {
"input": [
"3\n1 2 3\n",
"9\n1 2 1 3 2 2 2 2 3\n",
"2\n1 2\n",
"100\n2 10 9 1 2 6 7 2 2 8 9 9 9 5 6 2 5 1 1 10 7 4 5 5 8 1 9 4 10 1 9 3 1 8 4 10 8 8 2 4 6 5 1 4 2 2 1 2 8 5 3 9 4 10 10 7 8 6 1 8 2 6 7 1 6 7 3 10 10 3 7 7 6 9 6 8 8 10 4 6 4 3 3 3 2 3 10 6 8 5 5 10 3 7 3 1 1 1 5 5\n",
"100\n7 6 3 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence a consis... |
500_A. New Year Transportation_23501 | New Year is coming in Line World! In this world, there are n cells numbered by integers from 1 to n, as a 1 × n board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0121 has ... | a, b = map(int, input().split())
c = list(map(int, input().split()))
d = 0
while d < b - 1:
d += c[d]
if d == b - 1:
print("YES")
else:
print("NO") | {
"input": [
"8 4\n1 2 1 2 1 2 1\n",
"8 5\n1 2 1 2 1 1 1\n",
"4 4\n1 1 1\n",
"8 8\n1 1 1 1 1 1 1\n",
"120 104\n41 15 95 85 34 11 25 42 65 39 77 80 74 17 66 73 21 14 36 63 63 79 45 24 65 7 63 80 51 21 2 19 78 28 71 2 15 23 17 68 62 18 54 39 43 70 3 46 34 23 41 65 32 10 13 18 10 3 16 48 54 18 57 28 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
New Year is coming in Line World! In this world, there are n cells numbered by integers from 1 to n, as a 1 × n board. People live in cells. However, it was hard to move between disti... |
550_E. Brackets in Implications_23507 | Implication is a function of two logical arguments, its value is false if and only if the value of the first argument is true and the value of the second argument is false.
Implication is written by using character '<image>', and the arguments and the result of the implication are written as '0' (false) and '1' (true... | n = int(input())
c = list(map(int, input().split()))
idx = [i for i in range(n) if c[i] == 0]
one = [i for i in range(n) if c[i] == 1]
if len(idx) >= 1 and idx[-1] == n-1:
if len(idx) >= 2 and idx[-2] == n-2:
if len(idx) >= 3 and idx[-3] <= n-3:
if idx[0] == 0:
print("YES")
... | {
"input": [
"4\n0 1 1 0\n",
"1\n0\n",
"2\n1 1\n",
"5\n0 0 0 0 1\n",
"6\n0 0 0 0 0 1\n",
"4\n1 0 1 1\n",
"20\n1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0\n",
"6\n1 1 1 1 0 0\n",
"5\n1 1 1 1 0\n",
"5\n1 0 1 0 1\n",
"6\n0 0 0 0 0 0\n",
"5\n0 0 0 1 0\n",
"6\n0 1 1 1 0 0\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Implication is a function of two logical arguments, its value is false if and only if the value of the first argument is true and the value of the second argument is false.
Implicat... |
578_A. A Problem about Polyline_23511 | There is a polyline going through points (0, 0) – (x, x) – (2x, 0) – (3x, x) – (4x, 0) – ... - (2kx, 0) – (2kx + x, x) – ....
We know that the polyline passes through the point (a, b). Find minimum positive value x such that it is true or determine that there is no such x.
Input
Only one line containing two positiv... | a,b=map(float,input().split())
if b>a :
print(-1)
exit()
v=((a+b)/2)/((a+b)//(2*b))
print(v);
| {
"input": [
"4 1\n",
"1 3\n",
"3 1\n",
"30 5\n",
"999899988 13\n",
"999999999 111111111\n",
"1000000000 999999999\n",
"999999999 1000000000\n",
"999999998 111111111\n",
"861651807 2239668\n",
"405262931 391908625\n",
"829050416 2523498\n",
"11 3\n",
"836218485 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is a polyline going through points (0, 0) – (x, x) – (2x, 0) – (3x, x) – (4x, 0) – ... - (2kx, 0) – (2kx + x, x) – ....
We know that the polyline passes through the point (a, ... |
59_D. Team Arrangement_23515 | Recently personal training sessions have finished in the Berland State University Olympiad Programmer Training Centre. By the results of these training sessions teams are composed for the oncoming team contest season. Each team consists of three people. All the students of the Centre possess numbers from 1 to 3n, and a... | import sys
I = lambda: int(input())
RL = readline = lambda: sys.stdin.readline().strip('\n')
RM = readmap = lambda x = int: map(x,readline().split(' '))
def f(l,x):
if x==l[0]: return l[1],l[2]
if x==l[1]: return l[0],l[2]
if x==l[2]: return l[0],l[1]
return -1
def delrank(x):
global pre,nxt
... | {
"input": [
"2\n4 1 3 2 5 6\n4 6 5\n1 2 3\n4\n",
"3\n5 4 1 2 6 3 7 8 9\n5 6 2\n9 3 4\n1 7 8\n4\n",
"3\n5 4 1 2 6 3 7 8 9\n5 6 2\n9 3 4\n1 7 8\n8\n",
"1\n2 3 1\n2 3 1\n2\n",
"3\n1 2 3 4 5 6 7 8 9\n1 2 3\n4 5 9\n6 7 8\n5\n",
"2\n6 4 5 1 3 2\n6 1 3\n4 5 2\n6\n",
"5\n5 3 2 7 12 9 4 14 1 10 8 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Recently personal training sessions have finished in the Berland State University Olympiad Programmer Training Centre. By the results of these training sessions teams are composed for... |
621_B. Wet Shark and Bishops_23519 | Today, Wet Shark is given n bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right.
Wet Shark thinks that two bishops attack each other if they share the same diagonal. Note, that this is the onl... | a=[0]*2001
b=[0]*2001
n=int(input())
for i in range(n):
x,y=map(int,input().split())
a[x+y]+=1
b[x-y]+=1
s=0
for i in a:
s=s+(i-1)*i//2
for i in b:
s=s+(i-1)*i//2
print(s) | {
"input": [
"3\n1 1\n2 3\n3 5\n",
"5\n1 1\n1 5\n3 3\n5 1\n5 5\n",
"1\n1 1\n",
"2\n1000 1\n1000 1000\n",
"10\n646 171\n816 449\n375 934\n950 299\n702 232\n657 81\n885 306\n660 304\n369 371\n798 657\n",
"3\n259 770\n448 54\n926 667\n",
"3\n859 96\n634 248\n808 72\n",
"3\n987 237\n891 42... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Today, Wet Shark is given n bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numb... |
66_E. Petya and Post_23524 | Little Vasya's uncle is a postman. The post offices are located on one circular road. Besides, each post office has its own gas station located next to it. Petya's uncle works as follows: in the morning he should leave the house and go to some post office. In the office he receives a portion of letters and a car. Then ... | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
INF = 1000000000000009
ml = INF
mr = INF
i = 0
first = True
cur = 0
while first or i != 0:
cur += a[i]
cur -= b[i]
i += 1
i %= n
ml = min(ml, cur)
first = False
first = True
cur = 0
i = 0
while first or i !... | {
"input": [
"8\n1 2 1 2 1 2 1 2\n2 1 2 1 2 1 2 1\n",
"4\n1 7 2 3\n8 1 1 3\n",
"10\n44 22 14 9 93 81 52 64 3 99\n43 23 13 10 92 82 51 65 2 100\n",
"1\n1\n1\n",
"10\n1 5 4 3 2 1 5 8 2 3\n1 1 1 1 5 5 5 5 5 5\n",
"1\n1000000000\n1000000000\n",
"20\n31 16 20 30 19 35 8 11 20 45 10 26 21 39 29 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Little Vasya's uncle is a postman. The post offices are located on one circular road. Besides, each post office has its own gas station located next to it. Petya's uncle works as foll... |
691_B. s-palindrome_23528 | Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half.
<image> English alphabet
You are given a... | rever = "AHIMOTUVWXYovwx"
rev = ["bd", "pq","db","qp"]
line = input().rstrip()
if len(line) & 1 and line[len(line) // 2] not in rever:
print("NIE")
exit()
l = len(line) // 2 - 1
r = len(line) // 2 if len(line) & 1 == 0 else\
len(line) // 2 + 1
for i in range(len(line) // 2):
if line[l] + line[r] not i... | {
"input": [
"oXoxoXo\n",
"bod\n",
"ER\n",
"oiio\n",
"uuuu\n",
"iOi\n",
"VxrV\n",
"A\n",
"lxl\n",
"o\n",
"iii\n",
"ipOqi\n",
"uu\n",
"uuu\n",
"O\n",
"AAWW\n",
"Db\n",
"OuO\n",
"JL\n",
"tt\n",
"ii\n",
"NNNN\n",
"iIcamjTRFH\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is n... |
716_B. Complete the Word_23532 | ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not n... | s = input()
for i in range(len(s) - 25):
sub = s[i:i+26]
missing = set('ABCDEFGHIJKLMNOPQRSTUVWXYZ') - set(sub)
if len(missing) == sub.count('?'):
while missing:
sub = sub.replace('?', missing.pop(), 1)
print((s[:i] + sub + s[i+26:]).replace('?', 'A'))
brea... | {
"input": [
"WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO\n",
"ABC??FGHIJK???OPQR?TUVWXY?\n",
"AABCDEFGHIJKLMNOPQRSTUVW??M\n",
"??????????????????????????\n",
"LLVYUOXHBHUZSAPUMQEKWSQAFRKSMEENXDQYOPQFXNNFXSRBGXFUIRBFJDSDKQIDMCPPTWRJOZCRHZYZPBVUJPQXHNALAOCJDTTBDZWYDBVPMNSQNVMLHHUJAOIWFSEJEJSR... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English al... |
760_D. Travel Card_23538 | A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare.
The fare is constructed in the following manner. There are three types of tickets:
1. a tic... | #-*- coding:utf-8 -*-
#!/usr/bin/python3
n = int(input())
a = [0,]
for i in range(n):
x = int(input())
a.append(x)
dp = [0] * (n + 1)
dp[0] = 0
p90 = 1
p1440 = 1
for i in range(1, n + 1):
dp[i] = dp[i - 1] + 20
while a[p90] + 90 <= a[i]:
p90 = p90 + 1
dp[i] = min(dp[i], dp[p90 - 1] + 50)
while a[p1440] + 1440... | {
"input": [
"3\n10\n20\n30\n",
"10\n13\n45\n46\n60\n103\n115\n126\n150\n256\n516\n",
"1\n0\n",
"8\n0\n2\n51\n63\n69\n75\n80\n90\n",
"8\n0\n3\n5\n6\n7\n8\n9\n10\n",
"7\n100\n138\n279\n308\n396\n412\n821\n",
"8\n0\n3\n5\n6\n12\n8\n9\n10\n",
"7\n100\n138\n279\n308\n396\n718\n821\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and t... |
804_E. The same permutation _23543 | Seyyed and MoJaK are friends of Sajjad. Sajjad likes a permutation. Seyyed wants to change the permutation in a way that Sajjad won't like it. Seyyed thinks more swaps yield more probability to do that, so he makes MoJaK to perform a swap between every pair of positions (i, j), where i < j, exactly once. MoJaK doesn't ... | n = int(input())
p = lambda a,b: print(a+1,b+1)
if n % 4 > 1:
print("NO")
else:
print("YES")
for i in range(n%4,n,4):
for x in range(2):
for j in range(i): p(j,i+2*x)
p(i+2*x,i+2*x+1)
for j in range(i,0,-1): p(j-1,i+2*x+1)
p(i,i+3)
p(i+1,i+2)
p(i,i+2)
p(i+1,i+3) | {
"input": [
"1\n",
"3\n",
"695\n",
"766\n",
"6\n",
"899\n",
"814\n",
"319\n",
"186\n",
"150\n",
"10\n",
"111\n",
"58\n",
"147\n",
"2\n",
"406\n",
"974\n",
"5\n",
"22\n",
"999\n",
"831\n",
"8\n",
"219\n",
"7\n",
"75\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Seyyed and MoJaK are friends of Sajjad. Sajjad likes a permutation. Seyyed wants to change the permutation in a way that Sajjad won't like it. Seyyed thinks more swaps yield more prob... |
82_D. Two out of Three_23547 | Vasya has recently developed a new algorithm to optimize the reception of customer flow and he considered the following problem.
Let the queue to the cashier contain n people, at that each of them is characterized by a positive integer ai — that is the time needed to work with this customer. What is special about this... | # 82D
def do():
n = int(input())
costs = [int(c) for c in input().split(" ")]
next = {}
memo = {}
def dp(i, pre):
if i == n:
memo[i, pre] = [costs[pre], [pre]]
return memo[i, pre]
if i == n - 1:
memo[i, pre] = [max(costs[pre], costs[i]), [pre, i]... | {
"input": [
"4\n1 2 3 4\n",
"5\n2 4 3 1 4\n",
"55\n33 64 51 38 37 44 63 89 60 90 33 67 82 81 40 41 58 86 47 78 60 86 81 43 57 89 39 72 59 88 47 41 59 79 35 41 67 57 70 55 90 46 37 64 78 55 82 88 81 60 46 75 34 79 51\n",
"8\n100 1 2 3 1000 3 2 1\n",
"25\n8432 7540 8635 101 3810 1892 8633 1640 8440... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya has recently developed a new algorithm to optimize the reception of customer flow and he considered the following problem.
Let the queue to the cashier contain n people, at tha... |
875_B. Sorting the Coins_23553 | Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged in a row in such a way that firstly come coins out of circulation, and then... | from sys import stdin, stdout
n = int(stdin.readline())
values = list(map(int, stdin.readline().split()))
used = [0 for i in range(n)]
right, cnt = n, 0
ans = 1
stdout.write(str(ans) + ' ')
for v in values:
used[v - 1] = 1
ans += 1
while right and used[right - 1]:
ans -= 1
right -= 1... | {
"input": [
"4\n1 3 4 2\n",
"8\n6 8 3 4 7 2 1 5\n",
"1\n1\n",
"11\n10 8 9 4 3 5 1 11 7 2 6\n",
"100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having t... |
89_A. Robbery_23557 | It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive numbers from 1 to n from the left to the right.
Unfortunately, Joe ... | #------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
BUF... | {
"input": [
"3 2 2\n4 1 3\n",
"2 3 1\n2 3\n",
"5 10 7\n98765 78654 25669 45126 98745\n",
"2 7597 8545\n74807 22362\n",
"1 1 1000000000\n100\n",
"5 2 9494412\n5484 254 1838 18184 9421\n",
"95 97575868 5\n4612 1644 3613 5413 5649 2419 5416 3926 4610 4419 2796 5062 2112 1071 3790 4220 3955 2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the pr... |
920_C. Swap Adjacent Elements_23561 | You have an array a consisting of n integers. Each integer from 1 to n appears exactly once in this array.
For some indices i (1 ≤ i ≤ n - 1) it is possible to swap i-th element with (i + 1)-th, for other indices it is not possible. You may perform any number of swapping operations any order. There is no limit on the ... | n=int(input())
l=[int(i) for i in input().split()]
#canswap=[int(i) for i in input().split()]
canswap=input()
maxi=l[0]
for i in range(0,n-1,):
maxi=max(maxi,l[i])
if canswap[i]=='0' and i+1<maxi:
print('NO')
exit()
print('YES') | {
"input": [
"6\n1 2 5 3 4 6\n01110\n",
"6\n1 2 5 3 4 6\n01010\n",
"6\n1 6 3 4 5 2\n01110\n",
"6\n1 2 3 4 6 5\n00001\n",
"6\n6 1 2 3 4 5\n10001\n",
"11\n1 2 3 4 5 6 7 8 9 10 11\n0000000000\n",
"5\n1 4 5 2 3\n1011\n",
"4\n2 4 3 1\n011\n",
"6\n1 5 3 4 2 6\n01010\n",
"5\n4 5 1 2 3... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You have an array a consisting of n integers. Each integer from 1 to n appears exactly once in this array.
For some indices i (1 ≤ i ≤ n - 1) it is possible to swap i-th element with... |
949_A. Zebras_23565 | Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences o... | s = input()
o = -1
sol=[]
p = True
for i in range(0,len(s)):
if s[i]=='0':
if o == -1:
sol.append([i+1])
else:
sol[o].append(i+1)
o-=1
else:
o+=1
if o == len(sol):
p = False
break
else:
sol[o].append(... | {
"input": [
"0010100\n",
"111\n",
"0101001000\n",
"01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends wi... |
996_D. Suit and Tie_23571 | Allen is hosting a formal dinner party. 2n people come to the event in n pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The 2n people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the picture m... | def move(a, i, j):
f = a[i]
for g in range(i, j, -1):
a[g] = a[g - 1]
a[j] = f
n = int(input())
a = list(map(int, input().split()))
c = 0
for i in range(0, 2 * n, 2):
if a[i] != a[i + 1]:
f = a[i + 1:].index(a[i]) + i + 1
move(a, f, i + 1)
c += f - i - 1
print(c) | {
"input": [
"3\n3 1 2 3 1 2\n",
"4\n1 1 2 3 3 2 4 4\n",
"3\n1 1 2 2 3 3\n",
"24\n21 21 22 5 8 5 15 11 13 16 17 9 3 18 15 1 12 12 7 2 22 19 20 19 23 14 8 24 4 23 16 17 9 10 1 6 4 2 7 3 18 11 24 10 13 6 20 14\n",
"1\n1 1\n",
"19\n15 19 18 8 12 2 11 7 5 2 1 1 9 9 3 3 16 6 15 17 13 18 4 14 5 8 10... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Allen is hosting a formal dinner party. 2n people come to the event in n pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The 2n people line... |
p02779 AtCoder Beginner Contest 154 - Distinct or Not_23587 | Given is a sequence of integers A_1, A_2, ..., A_N. If its elements are pairwise distinct, print `YES`; otherwise, print `NO`.
Constraints
* 2 ≤ N ≤ 200000
* 1 ≤ A_i ≤ 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 ... A_N
Output
If the elements... | #154_C
n = int(input())
a = set(input().split())
print('YES' if len(a) == n else 'NO') | {
"input": [
"6\n4 1 3 1 6 2",
"2\n10000000 10000000",
"5\n2 6 1 4 5",
"6\n4 1 3 1 6 1",
"2\n10000100 10000000",
"5\n2 9 1 4 5",
"6\n4 1 3 1 2 1",
"2\n10000100 10001000",
"5\n2 9 1 3 5",
"6\n4 1 3 1 2 0",
"2\n10000100 10101000",
"5\n2 9 0 3 5",
"6\n4 1 3 2 2 0",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Given is a sequence of integers A_1, A_2, ..., A_N. If its elements are pairwise distinct, print `YES`; otherwise, print `NO`.
Constraints
* 2 ≤ N ≤ 200000
* 1 ≤ A_i ≤ 10^9
* All va... |
p02914 AtCoder Beginner Contest 141 - Xor Sum 3_23591 | We have N non-negative integers: A_1, A_2, ..., A_N.
Consider painting at least one and at most N-1 integers among them in red, and painting the rest in blue.
Let the beauty of the painting be the \mbox{XOR} of the integers painted in red, plus the \mbox{XOR} of the integers painted in blue.
Find the maximum possibl... | n = int(input())
a = list(map(int, input().split()))
ans = 0
#even = []
for i in range(60):
cnt = 0
for x in a:
if (x>>i) & 1:
cnt += 1
if cnt%2 == 1:
ans += (1<<i)
for j in range(n):
if (a[j]>>i) & 1:
a[j] -= (1<<i)
#print(ans, even)
yet = 0
for r in range(59, -1, -1):
stood = False
for c in ran... | {
"input": [
"20\n1008288677408720767 539403903321871999 1044301017184589821 215886900497862655 504277496111605629 972104334925272829 792625803473366909 972333547668684797 467386965442856573 755861732751878143 1151846447448561405 467257771752201853 683930041385277311 432010719984459389 319104378117934975 61145129... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We have N non-negative integers: A_1, A_2, ..., A_N.
Consider painting at least one and at most N-1 integers among them in red, and painting the rest in blue.
Let the beauty of the ... |
p03050 diverta 2019 Programming Contest - DivRem Number_23595 | Snuke received a positive integer N from Takahashi. A positive integer m is called a favorite number when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those.
Con... | n=int(input())
print(sum([n//x-1 for x in range(1,int(n**.5)+1) if n%x==0 and n//x-1>x])) | {
"input": [
"8",
"1000000000000",
"1000010000000",
"1000011000000",
"1100011000000",
"1110011000000",
"1110011100000",
"1110011100100",
"1110111100100",
"1110111100101",
"1110111000101",
"1010111000101",
"1010111010101",
"1011111010101",
"1000111010101",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Snuke received a positive integer N from Takahashi. A positive integer m is called a favorite number when the following condition is satisfied:
* The quotient and remainder of N divi... |
p03338 AtCoder Beginner Contest 098 - Cut and Count_23601 | You are given a string S of length N consisting of lowercase English letters. We will cut this string at one position into two strings X and Y. Here, we would like to maximize the number of different letters contained in both X and Y. Find the largest possible number of different letters contained in both X and Y when ... | n=int(input())
s=list(input())
ans=0
for i in range(n):
ans=max(ans,len(set(s[:i])&set(s[i:])))
print(ans) | {
"input": [
"10\naaaaaaaaaa",
"6\naabbca",
"45\ntgxgdqkyjzhyputjjtllptdfxocrylqfqjynmfbfucbir",
"10\naaabaaaaaa",
"6\n`abbca",
"45\ntgxgdqkyjphyzutjjtllptdfxocrylqfqjynmfbfucbir",
"45\ntgxgtqkyjfhyzutjjdllptdpxrbrylqfqjynmfbfucbio",
"45\nbnxgtqkykfhyzutjjdllptdpxrtrylqfqjygmfbftcbio",... | 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 consisting of lowercase English letters. We will cut this string at one position into two strings X and Y. Here, we would like to maximize the num... |
p03659 AtCoder Beginner Contest 067 - Splitting Pile_23607 | Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it.
They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card.
Let th... | n,*a = map(int,open(0).read().split())
total = sum(a)
ans = 10**18
dt = 0
for i in range(n-1):
dt += a[i]
ans = min(ans,abs(total-dt-dt))
print(ans) | {
"input": [
"6\n1 2 3 4 5 6",
"2\n10 -10",
"6\n0 2 3 4 5 6",
"2\n0 -10",
"6\n0 2 3 7 5 6",
"2\n0 -19",
"6\n-1 2 3 7 5 6",
"2\n1 -19",
"2\n1 -33",
"2\n0 -33",
"6\n1 2 3 7 8 8",
"2\n-1 -33",
"6\n1 2 3 7 8 13",
"2\n-1 -47",
"6\n1 3 3 7 8 13",
"2\n-1 -75",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it.
They will share these cards. First, Snuke will take some number of cards from ... |
p03815 AtCoder Beginner Contest 053 - X: Yet Another Die Game_23611 | Snuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7.
Snuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation:
* Operation: Rotate the die 90° tow... | x=int(input())
print((-(-(2*x-1)//11))) | {
"input": [
"7",
"149696127901",
"14",
"86483718001",
"79402108049",
"26",
"59146214190",
"14885609983",
"4",
"19238477126",
"3123061804",
"3577561486",
"2369636804",
"0",
"3247730789",
"1112597576",
"1610699774",
"544563173",
"973659229",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Snuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7.
Snuke will first put the die... |
p00072 Carden Lantern_23617 | Aizuwakamatsu City is known as the "City of History". About 400 years ago, the skeleton of the castle town was created by Gamo Ujisato, but after that, it became the central city of the Aizu clan 230,000 stones, whose ancestor was Hoshina Masayuki, the half-brother of Tokugawa's third shogun Iemitsu. Developed. Many to... | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0072
"""
import sys
from enum import Enum
class Mst(object):
""" minimum spanning tree """
INFINITY = 999999999
class Status(Enum):
""" ?????????????¨??????¶??? """
white = 1 # ????¨????
gray = 2 ... | {
"input": [
"4\n4\n0,1,1500\n0,2,2000\n1,2,600\n1,3,500\n0",
"4\n4\n0,1,1500\n0,2,2000\n1,2,600\n2,3,500\n0",
"4\n4\n0,1,1500\n0,2,2000\n1,2,600\n2,3,400\n0",
"4\n4\n0,1,0500\n0,2,2000\n0,2,600\n2,3,400\n0",
"4\n4\n0,1,0400\n0002,2,0\n0,2,600\n2,3,400\n0",
"4\n4\n0,1,1500\n0,2,2000\n1,2,600\n... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Aizuwakamatsu City is known as the "City of History". About 400 years ago, the skeleton of the castle town was created by Gamo Ujisato, but after that, it became the central city of t... |
p00204 UFO Shooting Down Operation_23621 | In 40XX, the Earth was invaded by aliens! Already most of the Earth has been dominated by aliens, leaving Tsuruga Castle Fortress as the only remaining defense base. Suppression units are approaching the Tsuruga Castle Fortress one after another.
<image>
But hope remains. The ultimate defense force weapon, the ultra... | import math
class Ufo:
def __init__(self, x, y, r, v):
self.dist = get_dist(x, y)
self.angle = get_angle(y, x)
self.rad = r
self.v = v
def get_dist(x, y):
return (x ** 2 + y ** 2) ** (1 / 2)
def get_angle(x, y):
angle = math.atan2(y, x)
if angle < 0:
angle += math.pi * 2
return angle
d... | {
"input": [
"100 5\n101 101 5 5\n110 110 2 3\n-112 -100 9 11\n-208 160 82 90\n-110 108 10 2\n10 11\n15 0 5 1\n25 0 5 1\n35 0 5 1\n45 0 5 1\n55 0 5 1\n65 0 5 1\n75 0 5 1\n85 0 5 1\n95 0 5 1\n-20 0 5 20\n-30 0 500 5\n0 0",
"100 5\n101 101 5 5\n110 110 2 3\n-112 -100 9 11\n-208 160 82 90\n-110 108 10 2\n10 11\n... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In 40XX, the Earth was invaded by aliens! Already most of the Earth has been dominated by aliens, leaving Tsuruga Castle Fortress as the only remaining defense base. Suppression units... |
p00360 Swapping Characters_23624 | You are given a string and a number k. You are suggested to generate new strings by swapping any adjacent pair of characters in the string up to k times. Write a program to report the lexicographically smallest string among them.
Input
The input is given in the following format.
s
k
The first line provides a st... | import sys
def main():
NI = lambda : int(sys.stdin.readline())
SI = lambda : sys.stdin.readline().rstrip()
s = SI()
n = len(s)
k = NI()
def conv(x):
return ord(x) - ord('a')
bit = [0] * (n+1)
def bit_add(i):
while i <= n:
bit[i] += 1
i += i & ... | {
"input": [
"pckoshien\n3",
"pckoshien\n10",
"kcposhien\n3",
"pckoshien\n9",
"kcooshien\n3",
"pckoshien\n16",
"kcooshien\n6",
"pckoshien\n30",
"kcooshien\n4",
"kdooshien\n4",
"kdooshien\n2",
"pckosiien\n26",
"neihsoodk\n2",
"pckosiien\n9",
"neihsoodk\n4",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a string and a number k. You are suggested to generate new strings by swapping any adjacent pair of characters in the string up to k times. Write a program to report the... |
p00571 Art Exhibition_23627 | An art exhibition will be held in JOI. At the art exhibition, various works of art from all over the country will be exhibited.
N works of art were collected as candidates for the works of art to be exhibited. These works of art are numbered 1, 2, ..., N. Each work of art has a set value called size and value. The siz... | N = int(input())
P = [list(map(int, input().split())) for i in range(N)]
P.sort()
su = 0
S = -P[0][0]
ans = -10**19
for a, b in P:
S = min(S, su - a)
ans = max(ans, su + b - a - S)
su += b
print(ans)
| {
"input": [
"3\n2 3\n11 2\n4 5",
"3\n2 3\n11 2\n4 2",
"3\n2 5\n11 2\n4 2",
"3\n2 5\n11 2\n4 3",
"3\n2 9\n11 0\n4 3",
"3\n2 9\n11 0\n7 3",
"3\n2 3\n2 2\n4 5",
"3\n2 2\n11 2\n4 2",
"3\n2 5\n11 2\n4 4",
"3\n2 3\n11 0\n4 3",
"3\n0 16\n54 3\n5 1",
"3\n3 1\n17 1\n6 1",
"... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
An art exhibition will be held in JOI. At the art exhibition, various works of art from all over the country will be exhibited.
N works of art were collected as candidates for the wo... |
p00718 Numeral System_23631 | Prof. Hachioji has devised a new numeral system of integral numbers with four lowercase letters "m", "c", "x", "i" and with eight digits "2", "3", "4", "5", "6", "7", "8", "9". He doesn't use digit "0" nor digit "1" in this system.
The letters "m", "c", "x" and "i" correspond to 1000, 100, 10 and 1, respectively, and ... | ans_list = []
n = int(input())
def mcxl2digit(s):
ans = 0
dig = 1
for i in range(len(s)):
if "2" <= s[i] <= "9":
dig = int(s[i])
else:
if s[i] == "m":
key = 1000
elif s[i] == "c":
key = 100
elif s[i] == "x":
... | {
"input": [
"10\nxi x9i\ni 9i\nc2x2i 4c8x8i\nm2ci 4m7c9x8i\n9c9x9i i\ni 9m9c9x8i\nm i\ni m\nm9i i\n9m8c7xi c2x8i",
"10\nxi x9i\ni 9i\nc2x2i 5c8x8i\nm2ci 4m7c9x8i\n9c9x9i i\ni 9m9c9x8i\nm i\ni m\nm9i i\n9m8c7xi c2x8i",
"10\nxi x9i\ni 9i\nc2x2i 5c8x8i\nm2ci 4m7c9x8i\n9c8x9i i\ni 9m9c9x8i\nm i\ni m\nm9i i\n... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Prof. Hachioji has devised a new numeral system of integral numbers with four lowercase letters "m", "c", "x", "i" and with eight digits "2", "3", "4", "5", "6", "7", "8", "9". He doe... |
p00858 Geometric Map_23634 | Your task in this problem is to create a program that finds the shortest path between two given locations on a given street map, which is represented as a collection of line segments on a plane.
<image>
Figure 4 is an example of a street map, where some line segments represent streets and the others are signs indicat... | from heapq import heappush, heappop
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def dot3(O, A, B):
ox, oy = O; ax, ay = A; bx, by = B
return (ax - ox) * (bx - ox) + (ay - oy) * (by - oy)
def cross3(O, A, B):
ox, oy = O; ax, ay = A; bx, by = B
return (ax - ox) * (by - oy) - (bx - o... | {
"input": [
"8\n1 1\n4 4\n1 1 4 1\n1 1 1 4\n3 1 3 4\n4 3 5 3\n2 4 3 5\n4 1 4 4\n3 3 2 2\n1 4 4 4\n9\n1 5\n5 1\n5 4 5 1\n1 5 1 1\n1 5 5 1\n2 3 2 4\n5 4 1 5\n3 2 2 1\n4 2 4 1\n1 1 5 1\n5 3 4 3\n11\n5 5\n1 0\n3 1 5 1\n4 3 4 2\n3 1 5 5\n2 3 2 2\n1 0 1 2\n1 2 3 4\n3 4 5 5\n1 0 5 2\n4 0 4 1\n5 5 5 1\n2 3 2 4\n0",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Your task in this problem is to create a program that finds the shortest path between two given locations on a given street map, which is represented as a collection of line segments ... |
p01420 Marathon Match_23642 | N people run a marathon. There are M resting places on the way. For each resting place, the i-th runner takes a break with probability P_i percent. When the i-th runner takes a break, he gets rest for T_i time.
The i-th runner runs at constant speed V_i, and the distance of the marathon is L.
You are requested to com... |
import bisect
def nCr(n, r):
r = min(r, n-r)
numerator = 1
for i in range(n, n-r, -1):
numerator *= i
denominator = 1
for i in range(r, 1, -1):
denominator *= i
return numerator // denominator
n,m,l=map(int,input().split())
data = [[0 for i in range(m+1)]for i in range(n)]
for ... | {
"input": [
"2 1 100\n100 100 10\n0 100 1",
"2 2 50\n30 0 1\n30 50 2",
"2 2 50\n30 50 1\n30 50 2",
"3 1 100\n50 1 1\n50 1 1\n50 1 1",
"2 1 100\n100 100 10\n0 100 0",
"2 2 50\n30 0 1\n30 50 1",
"1 2 50\n30 50 1\n30 50 2",
"3 1 100\n50 1 2\n50 1 1\n50 1 1",
"3 1 000\n7 2 2\n50 0 1\n... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
N people run a marathon. There are M resting places on the way. For each resting place, the i-th runner takes a break with probability P_i percent. When the i-th runner takes a break,... |
p01574 Dial Key_23645 | You are a secret agent from the Intelligence Center of Peacemaking Committee. You've just sneaked into a secret laboratory of an evil company, Automated Crime Machines.
Your mission is to get a confidential document kept in the laboratory. To reach the document, you need to unlock the door to the safe where it is kept... | n,m=map(int,input().split())
for _ in range(m):
a=int(input())
while a:n,a=a,n%a
print(['No','Yes'][n==1]) | {
"input": [
"3 1\n1",
"6 2\n2\n5",
"4 2\n2\n4",
"3 1\n0",
"6 2\n1\n6",
"6 2\n2\n6",
"3 0\n0",
"3 0\n-1",
"6 2\n4\n6",
"6 2\n5\n6",
"6 1\n5\n6",
"6 1\n3\n6",
"6 1\n3\n0",
"7 1\n3\n0",
"7 1\n3\n1",
"7 1\n5\n1",
"7 1\n5\n0",
"7 2\n5\n0",
"5 1\n... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are a secret agent from the Intelligence Center of Peacemaking Committee. You've just sneaked into a secret laboratory of an evil company, Automated Crime Machines.
Your mission ... |
p02012 Sum of QQ_23650 | You received a card with an integer $S$ and a multiplication table of infinite size. All the elements in the table are integers, and an integer at the $i$-th row from the top and the $j$-th column from the left is $A_{i,j} = i \times j$ ($i,j \geq 1$). The table has infinite size, i.e., the number of the rows and the n... | #!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
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.stdin.readline().split()]... | {
"input": [
"25",
"5",
"1",
"83160",
"18",
"9",
"0",
"10614",
"3",
"5401",
"2",
"12",
"4",
"6",
"30",
"16",
"65420",
"3315",
"36",
"64",
"32",
"4557",
"3807",
"26789",
"54",
"1584",
"20928",
"90",
"566... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You received a card with an integer $S$ and a multiplication table of infinite size. All the elements in the table are integers, and an integer at the $i$-th row from the top and the ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.