problem stringlengths 29 9.39k | language int64 1 3 | solution stringlengths 7 465k |
|---|---|---|
There are two buttons, one of size A and one of size B.
When you press a button of size X, you get X coins and the size of that button decreases by 1.
You will press a button twice. Here, you can press the same button twice, or press both buttons once.
At most how many coins can you get?
Constraints
* All values i... | 3 | a,b = map(int, input().split())
print(max(a+a-1,a+b,b+b-1,b+a)) |
<image>
While trading on his favorite exchange trader William realized that he found a vulnerability. Using this vulnerability he could change the values of certain internal variables to his advantage. To play around he decided to change the values of all internal variables from a_1, a_2, …, a_n to -a_1, -a_2, …, -a_n... | 3 | for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
print(n*3)
for i in range(1, n, 2):
for j in range(3):
print(1, i, i+1)
print(2, i, i+1)
###### thanking telegram for solutions ######
'''__________ ____ ___ _____________ __.___
\... |
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handk... | 3 | n = int(input())
sp = 2 * n
for i in range(n):
print(' ' * sp + ' '.join(map(str, [i for i in range(i)] + [i] + [i for i in range(i)][::-1])))
sp -= 2
print(' '.join(map(str, [i for i in range(n)] + [n] + [i for i in range(n)][::-1])))
sp = 2
for i in range(n - 1, -1, -1):
print(' ' * sp + ' '.join(map(str,... |
You are given n integers a_1, a_2, ..., a_n, where n is odd. You are allowed to flip the sign of some (possibly all or none) of them. You wish to perform these flips in such a way that the following conditions hold:
1. At least (n - 1)/(2) of the adjacent differences a_{i + 1} - a_i for i = 1, 2, ..., n - 1 are grea... | 3 | for ttt in range(int(input())):
n=int(input())
arr=list(map(int,input().split()))
for i in range(0,n-2,2):
arr[i]=-(abs(arr[i]))
arr[i+1]=abs(arr[i+1])
arr[n-1]=-(abs(arr[n-1]))
print(*arr)
|
You have a garland consisting of n lamps. Each lamp is colored red, green or blue. The color of the i-th lamp is s_i ('R', 'G' and 'B' — colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garlan... | 3 | def main():
if input() == '1':
print(f'0\n{input()}')
return
a, b, *l = map({'R': 0, 'G': 1, 'B': 2}.get, input())
l.append((l[-1] + 1) % 3 if l else a)
res, cnt = ['RGB'[a]], 0
for c in l:
if b == a:
b = a - 2 if a == c else 3 - a - c
cnt += 1
... |
Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restaurant is described by a string of length n which contains characters ... | 3 | t = int(input())
for _ in range(t):
n, k = [int(x) for x in input().split()]
p = input()
s = list(p.split('1'))
count = 0
for i in range(len(s)):
if s[i] == '':
continue
start = k
if i == 0 and p[i] == '0':
start = 0
for j in range(start, len(s... |
Recently you have bought a snow walking robot and brought it home. Suppose your home is a cell (0, 0) on an infinite grid.
You also have the sequence of instructions of this robot. It is written as the string s consisting of characters 'L', 'R', 'U' and 'D'. If the robot is in the cell (x, y) right now, he can move to... | 3 | for _ in range (int(input())):
s=input()
right = s.count('R')
left = s.count('L')
up = s.count('U')
down = s.count('D')
lr = min(right,left)
ud = min(up,down)
if ud==0 and lr!=0:
lr = 1
if lr == 0 and ud!=0:
ud = 1
ans = ''
for i in range (lr):
ans += ... |
In the Kingdom of AtCoder, people use a language called Taknese, which uses lowercase English letters.
In Taknese, the plural form of a noun is spelled based on the following rules:
* If a noun's singular form does not end with `s`, append `s` to the end of the singular form.
* If a noun's singular form ends with `s`... | 1 | s=raw_input()
if s[-1]=='s':
print s+'es'
else:
print s+'s'
|
You are given a positive integer x. Find any such 2 positive integers a and b such that GCD(a,b)+LCM(a,b)=x.
As a reminder, GCD(a,b) is the greatest integer that divides both a and b. Similarly, LCM(a,b) is the smallest integer such that both a and b divide it.
It's guaranteed that the solution always exists. If ther... | 3 | import math
for i in range(int(input())):
n=int(input())
for j in range(1,int(math.sqrt(n)+1)):
c=math.gcd(j,n-j)
if (c+((j*(n-j))//c))==n:
print(j, n-j)
break
else:
continue |
You are given an integer sequence A of length N and an integer K. You will perform the following operation on this sequence Q times:
* Choose a contiguous subsequence of length K, then remove the smallest element among the K elements contained in the chosen subsequence (if there are multiple such elements, choose one ... | 3 | N,K,Q = map(int, input().split())
A = [int(i) for i in input().split()]
S = sorted(A)+[0]
A+=[0]
ans =[]
for i in range(N):
if S[i]==S[i+1]:
continue
mi = S[i]
L =[]
kou=[]
for y in range(N+1):
if A[y]>=mi:
kou.append(A[y])
elif len(kou)<K:
kou =[]
... |
How Many Divisors?
Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
Constraints
* 1 ≤ a, b, c ≤ 10000
* a ≤ b
Input
Three integers a, b and c are given in a line separated by a single space.
Output
Print the number of divisors in a line.
Example
Inp... | 3 | a,b,c = map(int,input().split())
ans = 0
for n in range(a,b+1):
if c % n == 0:
ans += 1
print(ans)
|
You are given an integer K. Print the string obtained by repeating the string `ACL` K times and concatenating them.
For example, if K = 3, print `ACLACLACL`.
Constraints
* 1 \leq K \leq 5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
K
Output
Print the s... | 3 | input = int(input())
ans = "ACL"
print(ans*input) |
There are two types of burgers in your restaurant — hamburgers and chicken burgers! To assemble a hamburger you need two buns and a beef patty. To assemble a chicken burger you need two buns and a chicken cutlet.
You have b buns, p beef patties and f chicken cutlets in your restaurant. You can sell one hamburger for ... | 3 | t = int(input())
for _ in range(t):
b, p, f = map(int, input().split())
b //= 2
h, c = map(int, input().split())
if h < c:
h, c = c, h
p, f = f, p
x = min(b, p)
print(x * h + min(b-x, f) * c)
|
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
Input
The first line contains a nu... | 3 | s = input()
t = ''
i = 0
while True:
if s[i] == '.':
t += '0'
i += 1
elif s[i] == '-':
if s[i + 1] == '-':
t += '2'
else:
t += '1'
i += 2
if i == len(s):
break
print(t)
|
Alfie was a prisoner in mythland. Though Alfie was a witty and intelligent guy.He was confident of escaping prison.After few days of observation,He figured out that the prison consists of (N × N) cells.i.e The shape of prison was (N × N) matrix. Few of the cells of the prison contained motion detectors.So Alfie planned... | 1 | def format_input():
l = raw_input().split(" ")
while '' in l:
l.remove('')
return map(int, l)
def isValid(c, order):
a, b = c
return (0<= a < order) and (0 <= b < order)
def adj(a, b, order):
pos = [(1,0),(0,-1),(-1,0),(0,1)]
return filter(lambda a: isValid(a, order), [(a+i[0], b+i... |
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o... | 1 |
#import time
#the_start_time = time.time()
#import sys
#import random
#import os.path
def main():
import sys
#import math
#from Queue import PriorityQueue
_calories = [ int(d) for d in sys.stdin.readline().strip().split() ]
_sum = 0
for c in sys.stdin.readline().strip():
_sum = _sum + _calories[int... |
For a given array a consisting of n integers and a given integer m find if it is possible to reorder elements of the array a in such a way that ∑_{i=1}^{n}{∑_{j=i}^{n}{(a_j)/(j)}} equals m? It is forbidden to delete elements as well as insert new elements. Please note that no rounding occurs during division, for exampl... | 3 | t = int(input())
answ = []
for i in range(0,t):
n, m = map(int, input().split())
a = []
summ = 0
for j in input().split():
summ += int(j)
a.append(int(j))
if summ < m:
answ.append("NO")
elif summ == m:
answ.append("YES")
elif summ > m:
answ.append("NO"... |
You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it [here](http://tiny.cc/636xmz).
The picture showing the correct sudoku solution:
<image>
Blocks are bordered with bold black color.
Your task is to change at most 9 elements of this field (i.e. choose s... | 3 | import sys
import math
from collections import Counter
from collections import OrderedDict
from collections import defaultdict
from functools import reduce
#from itertools import groupby
sys.setrecursionlimit(10**6)
def inputt():
return sys.stdin.readline().strip()
def printt(n):
sys.stdout.write(str(n)+'\n')
d... |
Try guessing the statement from this picture <http://tiny.cc/ogyoiz>.
You are given two integers A and B, calculate the number of pairs (a, b) such that 1 ≤ a ≤ A, 1 ≤ b ≤ B, and the equation a ⋅ b + a + b = conc(a, b) is true; conc(a, b) is the concatenation of a and b (for example, conc(12, 23) = 1223, conc(100, 11)... | 3 | for i in range(int(input())):
a,b=map(int,input().split());r,z="9",0
while b>=int(r):z+=a;r+="9"
print(z) |
Sean is trying to save a large file to a USB flash drive. He has n USB flash drives with capacities equal to a1, a2, ..., an megabytes. The file size is equal to m megabytes.
Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives.
Input
The first line contai... | 3 | n = int(input())
m = int(input())
a = []
for i in range(n):
t = int(input())
a.append(t)
a.sort()
while m > 0:
m -= a.pop()
print(n-len(a))
|
When preparing a tournament, Codeforces coordinators try treir best to make the first problem as easy as possible. This time the coordinator had chosen some problem and asked n people about their opinions. Each person answered whether this problem is easy or hard.
If at least one of these n people has answered that th... | 3 | n = int(input())
inp = [int(x) for x in input().split()]
false = False
for i in inp:
if i==1:
false = True
break
if false:
print("HARD")
else:
print("EASY") |
There are n cities in Berland and some pairs of them are connected by two-way roads. It is guaranteed that you can pass from any city to any other, moving along the roads. Cities are numerated from 1 to n.
Two fairs are currently taking place in Berland — they are held in two different cities a and b (1 ≤ a, b ≤ n; a ... | 3 | import heapq
import math
from collections import *
from functools import reduce,cmp_to_key
# import sys
# input = sys.stdin.readline
M = mod = 10**9 + 7
def factors(n):return sorted(list(set(reduce(list.__add__,([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))))
def inv_mod(n):return pow(n, mod - 2, mod)
... |
Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.
The phoenix has a rather long lifespan, and reincarnates itself once every a! years. Here a! denotes ... | 3 | a, b = map(int, input().split())
ans = 1
for i in range(b - a):
ans = (((b - i) % 10) * ans) % 10
if ans == 0:
print(0)
exit()
print(ans)
|
You are given n integers a_1, a_2, ..., a_n, where n is odd. You are allowed to flip the sign of some (possibly all or none) of them. You wish to perform these flips in such a way that the following conditions hold:
1. At least (n - 1)/(2) of the adjacent differences a_{i + 1} - a_i for i = 1, 2, ..., n - 1 are grea... | 3 | t=int(input())
for _ in range(t):
n=int(input())
arr=list(map(int,input().split()))
for i in range(len(arr)):
arr[i]=abs(arr[i])
for i in range(len(arr)):
if i%2!=0:
arr[i]=-arr[i]
print(*arr)
|
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while pa... | 1 | n = input()
a = sorted(map(int, raw_input().split()))
max_len = 1
tmp_len = 1
for i in range(1, n):
if a[i-1] != a[i]:
max_len = max(tmp_len, max_len)
tmp_len = 1
else:
tmp_len += 1
max_len = max(tmp_len, max_len)
print(n-max_len)
|
We have two distinct integers A and B.
Print the integer K such that |A - K| = |B - K|.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Constraints
* All values in input are integers.
* 0 \leq A,\ B \leq 10^9
* A and B are distinct.
Input
Input is given from Standard Input in the following format:
... | 3 | A,B = map(int,input().split())
print( (A + B) // 2 if (A + B) % 2 == 0 else 'IMPOSSIBLE' ) |
You have unlimited number of coins with values 1, 2, …, n. You want to select some set of coins having the total value of S.
It is allowed to have multiple coins with the same value in the set. What is the minimum number of coins required to get sum S?
Input
The only line of the input contains two integers n and S ... | 3 | n,s = map(int, input().split())
c=0
r=s%n
q=s//n
if r==0:
print(q)
if r in range(1,n+1):
c=q+1
print(c)
else:
for i in range(n,1):
if r%i==0:
c=+1
break
#print(i)
print(c)
|
There are league games and tournament games in sports competitions. In soccer league games, points are given to each of the wins, losses, and draws, and the rankings are competed based on the points. The points are win (3 points), negative (0 points), and draw (1 point), respectively.
Enter the number of teams and the... | 3 | a = int(input())
while True:
s = []
for i in range(a):
b,c,d,e = input().split()
c = int(c)
e = int(e)
s.append([c*3+e,-(i),b])
s.sort(reverse = True)
for z in s:
print(z[2]+","+str(z[0]))
a = int(input())
if a == 0:
break
else:
print()... |
Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of a-s and others — a gr... | 3 | # ===================================
# (c) MidAndFeed aka ASilentVoice
# ===================================
# import math
# import collections
# ===================================
q = [str(x) for x in input()]
s = set(q)
l = len(s)
flag = 0
if l == 2 or l == 4:
flag = 1
if l == 2 and any(q.count(x) < 2 for x in s... |
Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer n and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer a and subtract it from n such that:
* 1 ≤ a ≤ n.
* If it's Mahmoud's turn, a has to be even, but if it's Ehab's turn, a has... | 3 | n = int(input())
if n % 2 != 0:
print('Ehab')
if n % 2 == 0:
print('Mahmoud')
|
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If... | 3 | s=input()
if s.find("0000000")!=-1:
print("YES")
elif s.find("1111111")!=-1:
print("YES")
else:
print("NO") |
After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the win... | 1 | n =int(raw_input())
a = []
b=map(int,raw_input().split())
for x in b:
ind = -1
for i in range(len(a)):
if a[i][0]==x:
ind=i
if ind == -1:
a.append([x,1])
else:
c = [x,a[ind][1]+1]
a.remove([x,a[ind][1]])
a.append(c)
max = 0
for i in a:
if max<i[1]:... |
Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before ... | 3 | f=lambda:map(int,input().split())
n=int(input())
rt=[]
c=0
while n:
a,b=f()
if a!=b:
c=1
rt.append([a,b])
n-=1
if c==1:
print('rated')
else:
print(['maybe','unrated'][rt[::-1]!=sorted(rt)])
|
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting e... | 3 | A=int(input())
B=int(input())
C=int(input())
P1=A+B+C
P2=A*B*C
P3=A+B*C
P4=A*B+C
P5=A*(B+C)
P6=(A+B)*C
Ar=[P1,P2,P3,P4,P5,P6]
Mayor=P1
for K in range(1,6):
if(Ar[K]>Mayor):
Mayor=Ar[K]
print(Mayor)
|
You've got a 5 × 5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1.... | 3 | m = []
for i in range(5):
fila = list(map(int, input().split()))
m.append(fila)
if 1 in fila:
posx = i
for j in range(5):
if fila[j] == 1:
posy = j
#print(posx, posy)
moves = abs(posx-2)+abs(posy-2)
print(moves) |
Jett is tired after destroying the town and she wants to have a rest. She likes high places, that's why for having a rest she wants to get high and she decided to craft staircases.
A staircase is a squared figure that consists of square cells. Each staircase consists of an arbitrary number of stairs. If a staircase ha... | 3 | def stairs(n):
if n==1:
return 1
k=n
temp=0
cnt=0
p=0
i=1
while n>=0:
temp=(i*(i+1))//2
n-=temp
if n>=0:
cnt+=1
p+=1
i+=2**p
else:
break
return cnt
t=int(input())
for i in range(t):
print(stairs... |
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
Constraints
* 1 \leq N \leq 10^4
* 1 \leq A \leq B \leq 36
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the s... | 3 | n,a,b=map(int,input().split())
ans=0
for i in range(a,n+1):
if a<=sum(map(int,list(str(i))))<=b:
ans+=i
print(ans) |
Today, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from the n integers, the sum is an even integer 0.
Input
The first line of the ... | 1 | #!/usr/bin/env python
#-*- coding:utf-8 -*-
import sys, math, random, operator
from string import ascii_lowercase
from string import ascii_uppercase
from fractions import Fraction, gcd
from decimal import Decimal, getcontext
from itertools import product, permutations, combinations
from Queue import Queue, PriorityQue... |
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 ... | 3 | n,t = list(map(int,input().split()))
a = list(map(int,input().split()))
a.insert(0,0)
c=1
while(True):
if c==t:
print('YES')
break
elif c>t:
print('NO')
break
else:
c = c+a[c] |
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 millis... | 3 | # put your python code here
s, v1, v2, t1, t2 = map(int,input().split())
if s*v1+t1*2 < s*v2+t2*2:
print('First')
elif s*v1+t1*2 > s*v2+t2*2:
print('Second')
else:
print('Friendship') |
On Chocolate day, Chotu wants to give his girlfriend a box of chocolate. Chotu has a N X N square box and N^2 chocolates each having a distinct sweetness value between 1 and N^2.
To make the box look attractive Chotu must fill each row with chocolates arranged in increasing value of sweetness. Chotu also knows that hi... | 1 | '''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'
t=input()
while t>0:
t-=1
n,k=map(int,raw_input().split())
if k==1:
print n+((n*n*(n-1))/2)
else:
x=n+k-2
print (n*n*x+n*(k+1))/2 |
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula
<image>
Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as <image>. For example, for array a = {4, 3, 6,... | 1 | import sys, math, os
from fractions import gcd
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
counts = {}
for x in a:
if x not in counts:
counts[x] = 1
else:
counts[x] += 1
ans = []
while len(ans) < n:
x = max(counts.keys())
counts[x] -= 1
if counts[x] == 0:
... |
You are given n numbers a_1, a_2, ..., a_n. With a cost of one coin you can perform the following operation:
Choose one of these numbers and add or subtract 1 from it.
In particular, we can apply this operation to the same number several times.
We want to make the product of all these numbers equal to 1, in other wo... | 3 | n=int(input())
l=list(map(int,input().split()))
L=[]
zero=0
zf=0
odd=0
pi=0
l.sort()
for i in range(len(l)):
if l[i]<0:
L.append(abs(l[i]+1))
odd+=1
elif l[i]==0:
zero=i
zf=1
L.append(1)
else:
pi=i
L.append(abs(l[i]-1))
if zf==0 and odd%2!=0:
L[pi-... |
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements?
Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the to... | 3 | H,W = map(int, input().split())
if H == 1 or W == 1:
print(1)
else:
print((H*W-1)//2+1)
|
Polycarp knows that if the sum of the digits of a number is divisible by 3, then the number itself is divisible by 3. He assumes that the numbers, the sum of the digits of which is divisible by 4, are also somewhat interesting. Thus, he considers a positive integer n interesting if its sum of digits is divisible by 4.
... | 3 | a = int(input())
def sumN(n):
ans = 0
while(n>0):
ans += n%10
n = n//10
return ans
while(sumN(a)%4 != 0):
a += 1
print(a) |
One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something.
The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people"
Igor just c... | 3 | from collections import defaultdict
from sys import exit
class Graph:
def __init__(self):
self.adj=defaultdict(list)
def add_edge(self,x,y):
self.adj[x].append(y)
self.adj[y].append(x)
def check(self):
for i in range(1,6):
for j in range(i+1,6):
fo... |
Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a × a.
What is the least number of flagstones needed to pave the Square? It'... | 3 | n,m,a = input().split(' ')
n = int(n)
m = int(m)
a = int(a)
if n <= a and m <= a:
print(int(1))
else:
if n > a and m <= a:
c = n // a
if n % a !=0:
c += 1
print(c)
else:
if n <= a and m > a:
c = m // a
if m % a !=0:
c += 1... |
You are given a range of positive integers from l to r.
Find such a pair of integers (x, y) that l ≤ x, y ≤ r, x ≠ y and x divides y.
If there are multiple answers, print any of them.
You are also asked to answer T independent queries.
Input
The first line contains a single integer T (1 ≤ T ≤ 1000) — the number of... | 3 | # my first code in python
a=int(input())
while a>0:
l,r=input().split();
print(l,int(l)+int(l))
a=a-1 |
You are given a matrix with n rows (numbered from 1 to n) and m columns (numbered from 1 to m). A number a_{i, j} is written in the cell belonging to the i-th row and the j-th column, each number is either 0 or 1.
A chip is initially in the cell (1, 1), and it will be moved to the cell (n, m). During each move, it eit... | 3 | import sys
import heapq
def main():
t = int(input())
for _ in range(t):
n, m = map(int, sys.stdin.readline().split())
table = []
for i in range(n):
table.append(list(map(int, sys.stdin.readline().split())))
ans = 0
if n <= m:
for i in range((n + ... |
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | 3 | #
n = int(input())
for i in range(n):
word = input()
replaced = word
length = len(word)
if length > 10:
replaced = f'{word[0]}{length-2}{word[-1]}'
print(replaced)
|
After a probationary period in the game development company of IT City Petya was included in a group of the programmers that develops a new turn-based strategy game resembling the well known "Heroes of Might & Magic". A part of the game is turn-based fights of big squadrons of enemies on infinite fields where every cel... | 3 | n = int(input())
print(((n * (n + 1)) // 2) * 6 + 1)
|
We have N strings of lowercase English letters: S_1, S_2, \cdots, S_N.
Takahashi wants to make a string that is a palindrome by choosing one or more of these strings - the same string can be chosen more than once - and concatenating them in some order of his choice.
The cost of using the string S_i once is C_i, and t... | 3 | # -*- coding: utf-8 -*-
#############
# Libraries #
#############
import sys
input = sys.stdin.readline
import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache
#############
# Const... |
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Roma's got n positive integers.... | 3 | n, k = [int(i) for i in input().split()]
nums = input().split()
count = 0
def less_than_k(num, k):
c = 0
for d in num:
if d in ["4", "7"]:
c += 1
if c > k:
return False
return True
for num in nums:
if less_than_k(num, k):
count += 1
print(count) |
You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis.
Input
The first line contains a single positive integer n (2 ≤ n ≤ 105).
The following n lines contain coordinates of the points. The i-t... | 3 | n = int(input())
up = 0
down = 0
for _ in range(n):
x, y = map(int, input().split())
if x > 0:
up += 1
else:
down += 1
if up <= 1 or down <= 1:
print("Yes")
else:
print("No")
|
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account ow... | 3 | n = input()
if int(n) > 0:
print(n)
else:
c1 = n[:-1]
c2 = n[:-2]+n[-1]
if c1 is '-0' or c2 is '-0':
print(0)
else:
c1 = int(c1)
c2 = int(c2)
if c1 > c2:
print(c1)
else:print(c2)
|
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living... | 3 | n = int(input())
P = []
Q = []
for i in range(n):
p, q = map(int, input().split())
P.append(p)
Q.append(q)
count = 0
for i in range(n):
if Q[i] - P[i] >= 2:
count += 1
print(count) |
You are given two integers n and m. You have to construct the array a of length n consisting of non-negative integers (i.e. integers greater than or equal to zero) such that the sum of elements of this array is exactly m and the value ∑_{i=1}^{n-1} |a_i - a_{i+1}| is the maximum possible. Recall that |x| is the absolut... | 3 | def solve():
n,m=[int(x) for x in input().split()]
if n==1:
print(0)
return
elif n==2:
print(m)
return
else:
print(2*m)
return
t=int(input())
for i in range(t):
solve() |
You are given two integers a and b. Print a+b.
Input
The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow.
Each test case is given as a line of two integers a and b (-1000 ≤ a, b ≤ 1000).
Output
Print t integers — the required numbers a+b.
Example
... | 3 | for _ in range(int(input())):
n,k = map(int, input().split())
print(n+k) |
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, inf... | 3 | n = int(input())
s = list(input())
ans = ''
for i in range(len(s)):
if (len(s) % 2):
if i % 2 == 0:
ans = ans + s[i]
else:
ans = s[i] + ans
else:
if i % 2 == 0:
ans = s[i] + ans
else:
ans = ans + s[i]
print(ans) |
Ramesh and Suresh are best friends. But they are fighting over money now. Suresh has given some money to Ramesh but he has forgotten how much money he had given. So Ramesh made a plan that he will give Re. 1 to every rectangle Suresh makes in a N x M area. Since Suresh is poor in mathematics he needs your help to make ... | 1 | test=input()
while(test>0):
[a,b] = [int(i) for i in raw_input().split()]
res=(a*(a+1)/2)*(b*(b+1)/2)
print res
test-=1; |
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string s consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string s to be distinct. Substring is a string formed by some num... | 3 | n = int(input())
if n > 26:
print(-1)
else:
print(n-len(set(input())))
|
You are given two huge binary integer numbers a and b of lengths n and m respectively. You will repeat the following process: if b > 0, then add to the answer the value a~ \&~ b and divide b by 2 rounding down (i.e. remove the last digit of b), and repeat the process again, otherwise stop the process.
The value a~ \&~... | 3 | import sys
input = sys.stdin.readline
mod = 998244353
n, m = map(int, input().split())
a = input()
b = input()
if(len(a) < len(b)):
a = '0' * (len(b) - len(a)) + a
if(len(b) < len(a)):
b = '0' * (len(a) - len(b)) + b
ans, q = 0, 0
len_ = max(n, m)
#print(a)
#print(b)
#print(len_, "erwrwerwe", len(a), len(b))
f... |
Sasha and Dima want to buy two n-tier cakes. Each cake should consist of n different tiers: from the size of 1 to the size of n. Tiers should go in order from the smallest to the biggest (from top to bottom).
They live on the same street, there are 2 ⋅ n houses in a row from left to right. Each house has a pastry shop... | 3 | def f(w):
return w[0]
def f1(w):
return w[1]
n = int(input())
a = [[int(e)] for e in input().split()]
for i in range(2 * n):
a[i].append(i)
w = a[0]
a.sort(key = f1)
a.sort(key = f)
res = 0
w = 0
w1 = 0
for i in range(0, 2 * n, 2):
q = abs(a[i][1] - w)
q1 = abs(a[i][1] - w1)
q2 = abs(a[i + 1]... |
Bike is interested in permutations. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] is not.
A permutation triple of permutations of length n (a, b, c) is called a... | 3 | n=int(input())
if (n%2==0): print(-1)
else:
for i in range(n): print(i,end=' ')
print('')
for i in range(n): print(i,end=' ')
print('')
for i in range(n): print((2*i)%n,end=' ') |
Two deer, AtCoDeer and TopCoDeer, are playing a game called Honest or Dishonest. In this game, an honest player always tells the truth, and an dishonest player always tell lies. You are given two characters a and b as the input. Each of them is either `H` or `D`, and carries the following information:
If a=`H`, AtCoDe... | 3 | n=input().split()
print("H"if n[0]==n[1] else "D") |
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe... | 3 | # -*- coding: utf-8 -*-
"""
Created on Tue Dec 17 14:05:19 2019
@author: PAVILION
"""
s=input()
a=[]
c=0
for i in s :
if i=="+":
c+=1
else:
a.append(i)
for i in range(0,len(a)):
a[i]=int(a[i])
a.sort()
for i in a:
if c>0:
print(str(i)+"+",end='')
c=c-1
elif c==0:
... |
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites <image>-th boy and... | 1 | from __future__ import print_function
import sys,math,string,itertools,fractions,heapq,collections,re,array,bisect
def debug(*args):
print(args, file=sys.stderr)
if __name__ == '__main__':
n,m = [int(r) for r in raw_input().split()]
X = [int(r) for r in raw_input().split()]
b=X[0]; X=X[1:]
Y = [in... |
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets.
Write a program which reads an integer x and print it as is. Note that multiple datasets are give... | 1 | j = 0
while(True):
temp = raw_input()
i = int(temp)
j += 1
if i != 0:
print("Case " + str(j) + ": " + str(i))
else:
break
|
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
Bu... | 3 | userinput = input()
userlist = list(userinput)
uniquelist = set(userlist)
uniquelistcount = len(uniquelist)
if uniquelistcount % 2 == 0:
print("CHAT WITH HER!")
else:
print("IGNORE HIM!") |
Miyako came to the flea kingdom with a ukulele. She became good friends with local flea residents and played beautiful music for them every day.
In return, the fleas made a bigger ukulele for her: it has n strings, and each string has (10^{18} + 1) frets numerated from 0 to 10^{18}. The fleas use the array s_1, s_2, …... | 3 | from bisect import bisect_left
n = int(input())
s = sorted(int(si) for si in input().split())
ediff = sorted(x - s[i - 1] for i, x in enumerate(s) if i > 0)
cumsum = [0] * n
for i in range(n - 1):
cumsum[i + 1] = cumsum[i] + ediff[i]
for _ in range(int(input())):
l, r = map(int, input().split())
ind = bi... |
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | 3 | n = int(input())
for l in range(n):
a = input()
if len(a) > 10:
l = len(a) - 1
print(a[0] +str(l - 1) + a[l])
else:
print(a) |
Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains 26 buttons (one for each letter of the Latin alphabet). Each button is either working fine or malfunctioning.
To check which buttons need replacement, Polycarp pressed som... | 3 | q=int(input())
for i in range(q):
a=list(input())+[' ']
b=set()
counter=1
for i in range(1,len(a)):
if a[i]!=a[i-1]:
if counter%2==1:
b.add(a[i-1])
counter=1
else:
counter+=1
tot=''
for item in sorted(b):
tot+=item
p... |
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters.... | 3 | string=input()
string=list(string)
string[0]=string[0].upper()
new=""
for i in string:
new+=i
print(new) |
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether thi... | 3 | n=int(input())
a=str(input())
if(len(a)<26):
print("NO")
else:
b=list(a.lower())
c=[]
for i in range(len(b)):
if b[i] not in c:
c.append(b[i])
if(len(c)==26):
print("YES")
else:
print("NO")
|
You've got a 5 × 5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1.... | 3 | for i in range(1,6):
cadena = input().replace(" ","")
posfila = cadena.find("1")
if posfila != -1:
posfila += 1
print(abs(3-i)+abs(3-posfila ))
|
You want to go on a trip with a friend. However, friends who have a habit of spending money cannot easily save travel expenses. I don't know when my friends will go on a trip if they continue their current lives. So, if you want to travel early, you decide to create a program to help your friends save in a planned mann... | 3 | from sys import stdin
readline = stdin.readline
from itertools import accumulate
while True:
trip_cost = int(readline())
if trip_cost == 0:
break
saving = []
for _ in range(12):
income, outgo = map(int, readline().split())
saving.append(income - outgo)
for i, accumulative... |
Walking along a riverside, Mino silently takes a note of something.
"Time," Mino thinks aloud.
"What?"
"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."
"And what are you recording?"
"You see it, tide. Everything has its own period, and I think I've figured... | 3 | n, p = [int(i) for i in input().split()]
s = list(input())
k = 0
for index in range(n - p):
if k != 0:
break
if s[index] == s[index + p] and s[index] == ".":
s[index] = str(0)
s[index + p] = str(1)
k += 1
elif s[index] != s[index + p] and s[index] != "." and s[index + p] != "... |
Kattapa, as you all know was one of the greatest warriors of his time. The kingdom of Maahishmati had never lost a battle under him (as army-chief), and the reason for that was their really powerful army, also called as Mahasena.
Kattapa was known to be a very superstitious person. He believed that a soldier is "lucky"... | 1 | no_of_tests = int(raw_input())
no_even = 0
no_odd = 0
weapon_list = map(int, raw_input().split())
for weapon_no in weapon_list:
if weapon_no % 2 == 0:
no_even += 1
else:
no_odd += 1
if no_even > no_odd:
print "READY FOR BATTLE"
else:
print "NOT READY" |
Mike is trying rock climbing but he is awful at it.
There are n holds on the wall, i-th hold is at height ai off the ground. Besides, let the sequence ai increase, that is, ai < ai + 1 for all i from 1 to n - 1; we will call such sequence a track. Mike thinks that the track a1, ..., an has difficulty <image>. In othe... | 3 | n = map(int, input().split())
l = list(map(int, input().split()))
ans = 1000
for i in range(1,len(l)-1):
li = l[:]
li.remove(l[i])
m = 0
for j in range(len(li)-1):
m = max(li[j+1] - li[j], m)
ans = min(m, ans)
print(ans)
|
This is an interactive problem. Remember to flush your output while communicating with the testing program. You may use fflush(stdout) in C++, system.out.flush() in Java, stdout.flush() in Python or flush(output) in Pascal to flush the output. If you use some other programming language, consult its documentation. You m... | 3 | n = int(input())
nums = list(map(int, input().split()))
pairs = []
for i in range(len(nums)):
for j in range(i+1, len(nums)):
pairs.append((abs(nums[i]-nums[j]), (i+1, j+1)))
pairs.sort(reverse=True)
for _, (i, j) in pairs:
if nums[i-1] > nums[j-1]:
print(f"? {i} {j}", flush=True)
else:
... |
In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to interval (c, d) from our set if and only if c < a < d or c < b < d. Also there is a path from interval I1 from our set to interval I2 from our set if there is a sequence of successive moves starting from I1 so ... | 3 | import math
class Pair:
def __init__(self, x = 0, y = 0):
self.x = x
self.y = y
self.neighbors = []
self.visited = False
def isMedian(pair1, pair2):
if (pair1.x > pair2.x and pair1.x < pair2.y):
return True
elif (pair1.y > pair2.x and pair1.y < pair2.y):
return True
else:
return False
def dfs(star... |
[3R2 - Standby for Action](https://www.youtube.com/watch?v=P2ZVC9aoiKo)
Our dear Cafe's owner, JOE Miller, will soon take part in a new game TV-show "1 vs. n"!
The game goes in rounds, where in each round the host asks JOE and his opponents a common question. All participants failing to answer are eliminated. The sho... | 3 | n=int(input())
sum=0
for i in range(n):
sum+=(1/(i+1))
print(sum) |
There is a n × m grid. You are standing at cell (1, 1) and your goal is to finish at cell (n, m).
You can move to the neighboring cells to the right or down. In other words, suppose you are standing at cell (x, y). You can:
* move right to the cell (x, y + 1) — it costs x burles;
* move down to the cell (x + 1,... | 3 | for _ in range(int(input())):
n,m,k=map(int,input().split())
ans=(n-1)+n*(m-1)
# print(ans)
if ans==k:
print("YES")
else:
print("NO")
|
Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a × a.
What is the least number of flagstones needed to pave the Square? It'... | 3 | from collections import Counter
import string
import math
import sys
from math import gcd as bltin_gcd
def coprime2(a, b):
return bltin_gcd(a, b) == 1
# sys.setrecursionlimit(10**6)
from fractions import Fraction
def array_int():
return [int(i) for i in sys.stdin.readline().split()]
def vary(arrber_of_variable... |
You are given three integers A, B and C.
Determine if there exists an equilateral triangle whose sides have lengths A, B and C.
Constraints
* All values in input are integers.
* 1 \leq A,B,C \leq 100
Input
Input is given from Standard Input in the following format:
A B C
Output
If there exists an equilateral ... | 3 | [x,y,z] = list(map(int,input().split()))
print("Yes" if(x==y and y==z) else "No") |
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c.
You have to find minimum k such that there exists at least one k-dominant character.
Input
The first line contains string s consisting of lowercas... | 3 | import sys
import math
from collections import defaultdict
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
def search(s, n, l):
rec = [0] * 26
for i in range(l + 1):
rec[ord(s[i]) - 97] += 1
i, j = 0, l
while j != n - 1:
j += 1
rec[ord(s[j]) - 97] += 1 if rec[ord(s[j]) - 97] > 0... |
Recall that the sequence b is a a subsequence of the sequence a if b can be derived from a by removing zero or more elements without changing the order of the remaining elements. For example, if a=[1, 2, 1, 3, 1, 2, 1], then possible subsequences are: [1, 1, 1, 1], [3] and [1, 2, 1, 3, 1, 2, 1], but not [3, 2, 3] and [... | 3 | from sys import stdin,stdout
for testcases in range(int(stdin.readline())):
n=int(stdin.readline())
arr=list(map(int,stdin.readline().split()))
total=0
local=arr[0]
for i in range(1,n):
if arr[i] * arr[i-1]>0:
local=max(arr[i],local)
else:
total+=local
... |
Vasya has found a piece of paper with a coordinate system written on it. There are n distinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to n. It turned out that points with coordinates (0, 0) and (ai, ai) are the opposite corners of the i-th square.
Vasya wants to find such... | 1 | n,k=map(int,raw_input().split())
l = map(int,raw_input().split())
l.sort(reverse=True)
if k <= n: print l[k-1],0
else: print -1 |
As you have noticed, there are lovely girls in Arpa’s land.
People in Arpa's land are numbered from 1 to n. Everyone has exactly one crush, i-th person's crush is person with the number crushi.
<image>
Someday Arpa shouted Owf loudly from the top of the palace and a funny game started in Arpa's land. The rules are a... | 1 | n = int(raw_input())
crush = map(int, raw_input().split())
# print n
# print crush
crush = [c - 1 for c in crush]
# print crush
cycle = []
for i in range(n):
t = 1
c = crush[i]
while c != i and t <= n:
c = crush[c]
t += 1
cycle.append(t)
def f(c):
if c % 2 == 0:
return c / ... |
Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance.
The park is a rectangular table with n rows and m columns, where the cells of the... | 3 | test_cases = int(input())
for z in range(test_cases):
n,m=list(map(int,input().split()))
if (n*m)%2==0:
print((m*n)//2)
else:
print(int(((m*n)+1)//2))
|
A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly n pixels.
Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels a and the number of columns of pixels b, so that:
* there are exactly n pixels on the d... | 3 | #!python
n = int(input())
m = n - 1
ii = 1
for i in range(1, int((n+2)/2)):
if n%i == 0:
if m > abs(i - n/i):
ii = i
m = abs(i - n/i)
jj = int(n/ii)
a, b = min(ii, jj), max(ii, jj)
print(a, b) |
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, ...... | 3 | n,m = map(int,input().split())
arr = list(map(int,input().split()))
d= {}
b = set()
for i in range(n):
b.add(arr[n-i-1])
d[n-i]=d.get(n-i,len(b))
for _ in range(m):
x = int(input())
print(d[x])
|
Arya has n opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya... | 3 | n,d=map(int,input().split())
m=[]
for i in range(d):
s=input()
m.append(s)
o=[]
c=0
for i in m:
if '0' in i:
c+=1
else:
o.append(c)
c=0
o.append(c)
print(max(o)) |
Egor wants to achieve a rating of 1600 points on the well-known chess portal ChessForces and he needs your help!
Before you start solving the problem, Egor wants to remind you how the chess pieces move. Chess rook moves along straight lines up and down, left and right, as many squares as it wants. And when it wants, i... | 3 | n = input()
n = int(n)
if n <=2:
print(-1)
elif n%2 ==0:
for row in range(n):
if row ==0:
for i in range(n):
if i ==0:
print(i+1,end = " ")
elif i==n-1:
print(i+1)
else:
print(i+1... |
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number... | 3 | # ossan
def bin_search(li, k, l, h):
m = (l + h) // 2
if k == li[m]:
return m+1
elif li[m-1] < k < li[m] and m != 0:
return m+1
elif k < li[m] and m == 0:
return m+1
elif k > li[m] and m == len(li)-1:
return m+1
elif k > li[m]:
return bin_search(li, k, m... |
Masha has n types of tiles of size 2 × 2. Each cell of the tile contains one integer. Masha has an infinite number of tiles of each type.
Masha decides to construct the square of size m × m consisting of the given tiles. This square also has to be a symmetric with respect to the main diagonal matrix, and each cell of ... | 3 | import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
try:
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
except:
pass
input = lambda: sys.stdin.buffer.readline().rstrip()
for _ in range(int(input())):... |
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Bi... | 3 | n=int(input())
if(n==0 or n==2):
print("NO")
elif(n%2==0):
print("YES")
else:
print("NO") |
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | 3 | def main():
inputNum = int(input())
incrementer = 0
for i in range(inputNum):
n1,n2,n3 = map(int, input().split())
if (n1+n2+n3) >= 2:
incrementer =incrementer+1
print(incrementer)
main()
|
You are a coach of a group consisting of n students. The i-th student has programming skill a_i. All students have distinct programming skills. You want to divide them into teams in such a way that:
* No two students i and j such that |a_i - a_j| = 1 belong to the same team (i.e. skills of each pair of students in t... | 3 | t=int(input())
for i in range(t):
n=int(input())
l=list(map(int,input().split()))
l.sort()
answer=1
for i in range(n-1):
if abs(l[i]-l[i+1])==1:
answer=2
break
print(answer)
|
There are 2000001 stones placed on a number line. The coordinates of these stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordi... | 3 | k,x = map(int,input().split())
[print(i,end=" ") for i in range(x-k+1,x+k)]
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.