problem stringlengths 29 9.39k | language int64 1 3 | solution stringlengths 7 465k |
|---|---|---|
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 | def func():
name = set(input())
if len(name) % 2 == 0:
return 'CHAT WITH HER!'
return 'IGNORE HIM!'
print(func())
|
You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.)
Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise.
Constraints
* S is... | 3 | S = input()
if int(S[5:7]) <= 4:
print("Heisei")
else:
print("TBD")
|
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red socks and b blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning and ... | 3 | a,b=map(int,input().split())
print(min(a,b),max(a-min(a,b),b-min(a,b))//2) |
Each day in Berland consists of n hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence a_1, a_2, ..., a_n (each a_i is either 0 or 1), where a_i=0 if Polycarp works during the i-th hour of the day and a_i=1 if Polycarp rests during the i-th hour of the day.
Days go ... | 3 | import math
import random
import sys
from collections import defaultdict as dd
mod = 7 + 10 ** 9
col = dd(int)
g = dd(list)
n = int(input())
l = [1 - int(i) for i in input().split()]
m = 0
i = 0
ans = 0
cur = 0
while(i < n):
if l[i] == 0:
cur += 1
i += 1
else:
i += 1
cur = 0
... |
We call two numbers x and y similar if they have the same parity (the same remainder when divided by 2), or if |x-y|=1. For example, in each of the pairs (2, 6), (4, 3), (11, 7), the numbers are similar to each other, and in the pairs (1, 4), (3, 12), they are not.
You are given an array a of n (n is even) positive in... | 3 | #import sys
#sys.stdin =open("input15.txt")
for _ in range(int(input())):
n=int(input())
l=list(map(int, input().split()))
l.sort()
cnt1,cnt2=0,0
for i in range(n):
if i>0:
if l[i]-l[i-1]==1:cnt1+=1
if l[i]%2==0:cnt2+=1
if cnt2%2==0 or cnt1>0:
print("YES")
... |
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Т-prime, if t has exactly three distinct positive divisors.
You are given an array of n positive integers. For each of them determine whether it is Т-prime or not.
Input
The f... | 3 | import math
import os
import random
import re
import sys
limit=1000000
def calculate_prime():
prime_flag = [True] * limit
prime_flag[0] = prime_flag[1] = False
for i in range(2,limit):
if prime_flag[i] == True:
for j in range(i*i, limit, i):
prime_flag[j] = False
retu... |
Takahashi is standing on a multiplication table with infinitely many rows and columns.
The square (i,j) contains the integer i \times j. Initially, Takahashi is standing at (1,1).
In one move, he can move from (i,j) to either (i+1,j) or (i,j+1).
Given an integer N, find the minimum number of moves needed to reach a ... | 3 | N=int(input())
cnt=N-1
for i in range(1,int(N**0.5)+1):
if N%i== 0:
cnt=min(cnt,N//i+i-2)
print(cnt) |
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 | from sys import stdin
input = lambda: stdin.readline().rstrip("\r\n")
from collections import deque as que, defaultdict as vector
from heapq import*
inin = lambda: int(input())
inar = lambda: list(map(int,input().split()))
from types import GeneratorType
'''def bootstrap(f, stack=[]):
def wrappedfunc(*args, **kwarg... |
You are given some Tetris field consisting of n columns. The initial height of the i-th column of the field is a_i blocks. On top of these columns you can place only figures of size 2 × 1 (i.e. the height of this figure is 2 blocks and the width of this figure is 1 block). Note that you cannot rotate these figures.
Yo... | 3 | t=int(input())
for _ in range(t):
n = int(input())
arr = list(map(int, input().split()))
a=max(arr)
c=0
for i in range(n):
if((a-arr[i])%2!=0):
print("No")
c=1
break
if c==0:
print("Yes") |
Given is a positive integer N. How many tuples (A,B,C) of positive integers satisfy A \times B + C = N?
Constraints
* 2 \leq N \leq 10^6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
3
Output
3
Input
100
... | 3 | n = int(input())
res = 0
for a in range(1, n):
res += ((n - 1) // a)
print(res) |
Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k.
In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10k. For example, if k = 3, in the number 30020 it is enough to delete a single digit (2). In this case, the result ... | 3 | n, k = map(str, input().split())
length = len(n)
count0 = 0
count1 = 0
flag = 0
#print("hi")
for x in range(0, length):
#print(x)
if n[length-x-1] == "0":
count0 += 1
#print(length-x-1, "000")
else:
#del(n[length-x-1])
count1 += 1
#print(length-x-1, n)
if count0 == int(k):
flag = 1
break
if flag ==... |
Joisino is about to compete in the final round of a certain programming competition. In this contest, there are N problems, numbered 1 through N. Joisino knows that it takes her T_i seconds to solve problem i(1≦i≦N).
Also, there are M kinds of drinks offered to the contestants, numbered 1 through M. If Joisino takes d... | 1 | n = int(raw_input())
ls = map(int, raw_input().split())
m = int(raw_input())
for _ in range(m):
p, x = map(int, raw_input().split())
print sum(ls) - ls[p-1] + x
|
As the Monk is also taking part in the CodeMonk Series, this week he learned about hashing. Now he wants to practice some problems. So he came up with a simple problem. Firstly, he made a hash function F such that:
F(x) = x % 10
Now using this function he wants to hash N integers and count the number of collisions th... | 1 | x=input()
while x:
n=input()
s=map(int,raw_input().split())
c=0
d={}
for j in s:
k=j%10
d[k]=d.get(k,0)+1
for key in d.keys():
c=c+d[key]-1
print c
x=x-1 |
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program re... | 1 | n = input()
c1 = c2 = x1 = x2 = 0
for i in range(n):
t,x,y = [int(x) for x in raw_input().split()]
if(t == 1):
x1+=x
c1+=1
else:
x2+=x
c2+=1
if(c1*5 <= x1):
print 'LIVE'
else:
print 'DEAD'
if(c2*5 <= x2):
print 'LIVE'
else:
print 'DEAD' |
You are given three positive integers n, a and b. You have to construct a string s of length n consisting of lowercase Latin letters such that each substring of length a has exactly b distinct letters. It is guaranteed that the answer exists.
You have to answer t independent test cases.
Recall that the substring s[l ... | 3 | for test in range(0,int(input())):
n,a,b=[int(x) for x in input().split()]
for i in range(0,n):
print(chr(97+i%b),end="")
print()
|
Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results.
Fortunately, Adilbek can optimize the program. If he spends x (x is a non-negative integer) days opt... | 3 | import math
t = int(input())
for i in range(t):
q = input().split()
n = int(q[0])
d = int(q[1])
c = 0
if n>=d:
print("YES")
else:
for j in range(1,n//2+1):
a = j + int(math.ceil(d/(j+1)))
if a<=n:
print("YES")
c = 1
... |
Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:
(1n + 2n + 3n + 4n) mod 5
for given value of n. Fedya managed to complete the task. Can you? Note that given number n can be extremely large (e.g. it can exceed any integer type of your programming language).
Input
The si... | 1 | n=input()
n=int(n)
ans=1
ans=ans+(pow(2, n, 5))
ans=ans+(pow(3, n, 5))
ans=ans+(pow(4, n, 5))
print ans%5
|
We call two numbers x and y similar if they have the same parity (the same remainder when divided by 2), or if |x-y|=1. For example, in each of the pairs (2, 6), (4, 3), (11, 7), the numbers are similar to each other, and in the pairs (1, 4), (3, 12), they are not.
You are given an array a of n (n is even) positive in... | 3 | for i in range(int(input())):
n=int(input())
l=list(map(int,input().split()))
e=0
c=0
l.sort()
for i in range(len(l)):
if l[i]%2==0:
e+=1
for i in range(len(l)-1):
if l[i+1]-l[i]==1:
c+=1
if e%2==0:
print("YES")
elif c>=1:
... |
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the f... | 3 | for i in range(5):
n,k = map(int,input().split())
if n == 0 and k == 0:
break
else:
ruiseki = [0]*(n+1)
total = 0
maximum = -(10**9+7)
for i in range(n):
p = int(input())
total += p
ruiseki[i+1] = total
for i in range(n-k+1)... |
Being stuck at home, Ray became extremely bored. To pass time, he asks Lord Omkar to use his time bending power: Infinity Clock! However, Lord Omkar will only listen to mortals who can solve the following problem:
You are given an array a of n integers. You are also given an integer k. Lord Omkar wants you to do k ope... | 3 | import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
ans = []
t = ini()
for _ in range(t):
n, k = inm()
a = inl()
k = 1 if k % 2 else 2
for i in range(k):
d ... |
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin.
We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). Both Adil and Bera can c... | 1 | from math import sqrt
def dst(p1, p2):
return sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)
ax, ay, bx, by, tx, ty = map(int, raw_input().split())
n = int(raw_input())
pos = [map(int, raw_input().split()) for bottle in xrange(n)]
dsts = [dst(p, (tx, ty)) for p in pos]
difa = sorted([(dst(pos[i], (ax, ay)) - dsts[i],... |
There are n walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number n.
The presenter has m chips. The presenter... | 3 | n,m=map(int,input().split())
k=[i for i in range(1,n+1)]
i=0
while m>=k[i]:
m-=k[i]
i+=1
if i==n:
i=0
print(m)
|
You are given a huge integer a consisting of n digits (n is between 1 and 3 ⋅ 10^5, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by 2).
For example, if a = 032... | 3 | for t in range(int(input())):
st = input()
li = list(map(int,st))
n = len(li)
odd = []
even = []
i = 0
while i < n:
if li[i] % 2 == 0:
even.append(li[i])
else:
odd.append(li[i])
i = i + 1
od = 0
ev = 0
while od < len(odd) and ev < l... |
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n. It is known that each of the n integers 1,...,n appears at least once in this sequence.
For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given s... | 3 | n = int(input())
a = list(map(int, input().split()))
dup = sum(a) - n * (n + 1) // 2
d1 = a.index(dup)
d2 = a.index(dup, d1 + 1)
N = n + 1
Ndup = d1 + n - d2
MOD = 10 ** 9 + 7
def power(x, n):
ans = 1
while n:
if n % 2 == 1:
ans = (ans * x) % MOD
x = (x * x) % MOD
n //= 2... |
Snuke built an online judge to hold a programming contest.
When a program is submitted to the judge, the judge returns a verdict, which is a two-character string that appears in the string S as a contiguous substring. (The judge can return any two-character substring of S.)
Determine whether the judge can return the ... | 3 | S=input()
if S.find("AC")>-1:
print("Yes")
else:
print("No") |
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called x. Also, there are two operations:
* Operation ++ increases the value of variable x by 1.
* Operation -- decreases the value of variable x by 1.... | 1 | # Name : A. Bit++
# N0# 282
# Contest# 173
# Division: 2
n = int(raw_input())
res = 0
for i in range(n):
a = raw_input()
if '+' in a:
res += 1
else:
res -= 1
print res |
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have n layers. The first layer is hate, seco... | 3 | n = int(input())
r = " ".join(map(lambda x: "I love that" if x % 2 else "I hate that", range(n - 1)))
r += " I hate it" if n % 2 else " I love it"
print(r.strip())
|
You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly x bacteria in the box at some moment.
What is the minimu... | 3 | n=int(input())
x=0
while n>=1:
if n%2==1:
x+=1
n-=1
else:
n/=2
print(x) |
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | 1 | t = raw_input()
t = t.split(", ")
length = len(t)
if(length==1 and t[0]=='{}'):
print 0
else:
if(length==1):
print 1
else:
t[0]=t[0].split('{')[1]
t[length-1]=t[length-1].split('}')[0]
array = []
for i in range(0,26):
array.append(0)
for i in t:
array[ord(i)-ord('a')] = array[ord(i)-ord('a')] + 1
... |
Find bridges of an undirected graph G(V, E).
A bridge (also known as a cut-edge) is an edge whose deletion increase the number of connected components.
Constraints
* 1 ≤ |V| ≤ 100,000
* 0 ≤ |E| ≤ 100,000
* The graph is connected
* There are no parallel edges
* There are no self-loops
Input
|V| |E|
s0 t0
s1 t1
:
s... | 3 | from sys import stdin
readline = stdin.readline
def main():
v, e = map(int, readline().split())
from collections import defaultdict
g = defaultdict(list)
for _ in range(e):
s, t = map(int, readline().split())
g[s].append(t)
g[t].append(s)
visited = set()
lowest = [Non... |
Polycarp is a great fan of television.
He wrote down all the TV programs he is interested in for today. His list contains n shows, i-th of them starts at moment li and ends at moment ri.
Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at any given mom... | 3 | def main():
l, c = [], 0
for _ in range(int(input())):
a, b = map(int, input().split())
l.append(a * 2)
l.append(b * 2 + 1)
l.sort()
for a in l:
if a & 1:
c -= 1
else:
c += 1
if c > 2:
print("NO")
... |
Dreamoon wants to climb up a stair of n steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer m.
What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition?
Input
The single line contains two space separated i... | 1 | n,m = map(int,raw_input().split())
for x in range((n+1)/2, n+1):
if x % m == 0:
print x
exit(0)
print -1 |
Tak performed the following action N times: rolling two dice. The result of the i-th roll is D_{i,1} and D_{i,2}.
Check if doublets occurred at least three times in a row. Specifically, check if there exists at lease one i such that D_{i,1}=D_{i,2}, D_{i+1,1}=D_{i+1,2} and D_{i+2,1}=D_{i+2,2} hold.
Constraints
* 3 \... | 3 | N=int(input())
count=0
ans="No"
while N>0:
d1,d2=map(int,input().split())
if d1==d2:
count+=1
if count==3:
ans="Yes"
else:
count=0
N-=1
print(ans) |
Suppose you are performing the following algorithm. There is an array v_1, v_2, ..., v_n filled with zeroes at start. The following operation is applied to the array several times — at i-th step (0-indexed) you can:
* either choose position pos (1 ≤ pos ≤ n) and increase v_{pos} by k^i;
* or not choose any posit... | 3 |
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
newl... |
There is a house with n flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of n integer numbers a_1, a_2, ..., a_n, where a_i = 1 if in the i-th flat the light is on and a_i = 0 otherwise.
Vova thinks that people in the i-th flats are distur... | 3 | n = int(input())
a = [int(z) for z in input().split()]
s = 0
for i in range(0, n-2):
if a[i] == 1 and a[i+1] == 0 and a[i+2] == 1:
s += 1
a[i+2] = 0
print(s) |
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(1,n+1):
s=input()
l=len(s)
if(l>10):
a=l-2
print(s[0]+str(a)+s[(l-1)])
else:
print(s) |
We have A balls with the string S written on each of them and B balls with the string T written on each of them.
From these balls, Takahashi chooses one with the string U written on it and throws it away.
Find the number of balls with the string S and balls with the string T that we have now.
Constraints
* S, T, and ... | 3 | s = input().split()
a = [int(i) for i in input().split()]
u = input()
a[s.index(u)] -= 1
print(*a) |
You are given a rectangular board of M × N squares. Also you are given an unlimited number of standard domino pieces of 2 × 1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squa... | 3 | m,n = map(int,input().split(' '))
res = (m * n)/2
print(int(res))
|
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't rem... | 3 | n = int(input())
c = list(input())
f = 0
s = 0
for i in range(n-1):
if c[i] == "S" and c[i+1] == "F":
s += 1
elif c[i] == "F" and c[i+1] == "S":
f += 1
if s > f:
print("YES")
else:
print("NO") |
Fox Ciel is playing a game with numbers now.
Ciel has n positive integers: x1, x2, ..., xn. She can do the following operation as many times as needed: select two different indexes i and j such that xi > xj hold, and then apply assignment xi = xi - xj. The goal is to make the sum of all numbers as small as possible.
... | 3 | # coding: utf-8
n = int(input())
x = [int(i) for i in input().split()]
while True:
tmp = min(x)
for i in range(n):
if x[i]%tmp == 0:
x[i] = tmp
else:
x[i] %= tmp
if sum(x) == tmp*n:
break
print(sum(x))
|
After lessons Nastya decided to read a book. The book contains n chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page.
Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number k as the fi... | 3 | t=[]
n=int(input())
for i in range(n):
l,r=[int(x) for x in input().split()]
t.append(r)
k=int(input())
for i in range(n):
if(k<=t[i]):
print(n-i)
break
|
Ataru Oafoot of Aizu Gakuen University High School decided to play with a slot machine.
When you insert a medal on this machine, three reels will start spinning and each reel will stop automatically. In a normal game (normal game), 3 medals are inserted, and when the symbols are aligned, the following medals are obtai... | 1 | while 1:
b,r,g,c,s,t=map(int,raw_input().split())
if t==0:break
print 100+95*b+63*r+7*g+2*c-3*(t-s) |
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't w... | 3 | """Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven'... |
"Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of n participants took part in the contest (n ≥ k), and you already know their scores. Calculate how many ... | 3 | n, k = map(int, input(). split())
a = [int (i) for i in (input().split())]
b = 0
for elem in (a):
if elem >= a[k-1] and elem > 0:
b = b + 1
print(b) |
Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to n. Entrance n and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance a and he decided that during his walk he will move around the house b entrances in the direct... | 3 | n, a, b = map(int, input().split())
ans = ((a - 1 + b) % n) + 1
print(ans) |
Write a program which reads a sequence and prints it in the reverse order.
Note
解説
Constraints
* n ≤ 100
* 0 ≤ ai < 1000
Input
The input is given in the following format:
n
a1 a2 . . . an
n is the size of the sequence and ai is the ith element of the sequence.
Output
Print the reversed sequence in a line. P... | 3 | n=int(input())
a=input().split()
a.reverse()
print(" ".join(map(str,a)))
|
When Serezha was three years old, he was given a set of cards with letters for his birthday. They were arranged into words in the way which formed the boy's mother favorite number in binary notation. Serezha started playing with them immediately and shuffled them because he wasn't yet able to read. His father decided t... | 3 | m = int(input())
s = input()
z = s.count("z")
n = s.count("n")
ans = ''
ans += '1' * n
ans += '0' * z
print(' '.join(ans)) |
Find the minimum area of a square land on which you can place two identical rectangular a × b houses. The sides of the houses should be parallel to the sides of the desired square land.
Formally,
* You are given two identical rectangles with side lengths a and b (1 ≤ a, b ≤ 100) — positive integers (you are given ... | 3 | testy = int(input())
results = []
import math
for i in range(testy):
wejscie = list(map(int, input().split()))
minimalne = max(2 * min(wejscie), max(wejscie))
results.append(minimalne ** 2)
for result in results:
print(result) |
Tomorrow is a difficult day for Polycarp: he has to attend a lectures and b practical classes at the university! Since Polycarp is a diligent student, he is going to attend all of them.
While preparing for the university, Polycarp wonders whether he can take enough writing implements to write all of the lectures and d... | 3 | t=int(input())
for i in range(t):
a,b,x,y,n=map(int,input().split())
from math import ceil
t=ceil(a/x)+ceil(b/y)
if t<=n:
print(ceil(a/x),ceil(b/y))
else:
print(-1) |
The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
* At least one participant should get a dip... | 3 | n = int(input())
arr = list(map(int, input().split(" ")))
arr = list(set(arr))
ans = len(arr)
if 0 in arr:
ans -= 1
print(ans) |
Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define i modulo j as the remainder of division of i by j and denote it by <image>. A Modular Equation, as Hamed's teacher described, is an equation of the form <image> in which a and b are two non-negative integers a... | 3 | import math
a, b = map(int, input().split())
if a == b:
print('infinity')
else:
num = abs(a - b)
i = 1
count = 0
while i < int(math.sqrt(num)) + 1:
if num % i == 0:
if i > b:
count += 1
if num / i > b and i * i != num:
count += 1
i += 1
print(count)
... |
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100)... | 3 | #right preference
q = int(input())
for rwre in range(q):
n = int(input())
dz = []
nn = n
kan = 2
while nn > 1 and kan**2 <= n:
if nn%kan == 0:
nn//= kan
dz.append(kan)
else:
kan += 1
if nn > 1:
dz.append(nn)
dz.append(5252542554254... |
There is a game called "I Wanna Be the Guy", consisting of n levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only p levels of the game. And Little Y can pass only q levels of the game. You are given the indices of levels Little X can pass ... | 3 | n = int(input())
X = list(map(int,input().split()))
x = X[0]
Y = list(map(int,input().split()))
y = Y[0]
l = []
for i in range(1,x+1):
l.append(X[i])
for i in range(1,y+1):
l.append(Y[i])
if(len(set(l))==n):
print('I become the guy.')
else:
print('Oh, my keyboard!') |
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 | a=int(input())
b=""
for i in range(a):
b=input()
if len(b) > 10:
print(str(b[0])+str(len(b)-2)+str(b[-1]))
else:
print(b)
|
Little Petya has a birthday soon. Due this wonderful event, Petya's friends decided to give him sweets. The total number of Petya's friends equals to n.
Let us remind you the definition of the greatest common divisor: GCD(a1, ..., ak) = d, where d represents such a maximal positive number that each ai (1 ≤ i ≤ k) is e... | 3 | from sys import stdin, stdout
n = int(stdin.readline())
challengers = list(map(int, ['2', '3', '5', '7', '11', '13', '17', '19', '23', '29', '31', '37', '41', '43', '47', '53', '59', '61', '67', '71', '73', '79', '83', '89', '97', '101', '103', '107', '109', '113', '127', '131', '137', '139', '149', '151', '157', '163'... |
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point x(x > 0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order ... | 3 | n=int(input())
if(n==1 or n==2 or n==3 or n==4 or n==5):
print("1")
elif(n>5):
s=n//5
r=n%5
if(r==0):
print(s)
else:
print(s+1)
|
Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.
There are two sequences of n strings s_1, s_2, s_3, …, s_{n} and m strings t_1, t_2, t_3, …, t_{m}. ... | 3 | n,m = input().split()
n = int(n)
m = int(m)
s = input().split()
t = input().split()
q = int(input())
qin = []
for x in range(q):
qin.append(int(input()))
for y in qin:
print(s[(y%n)-1]+t[(y%m)-1])
|
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the pho... | 3 | l=input()
print((len(l)+1)*26-len(l)) |
Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1 ≤ i ≤ n) he makes ai money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence ai. Let us remind you that the subsegment of the sequence is it... | 1 | n=input()
l=map(int,raw_input().split())
dp=[0]*100001
dp[0]=1
m=1
for i in range(1,n):
if l[i]>=l[i-1]:
dp[i]=1+dp[i-1]
else:
dp[i]=1
m=max(dp[i],m)
print m |
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.
Reliable sources have informed the financier Anton of some information about the exchange rate of... | 3 | l = list(input())
last = -1
odd = int(l[-1])
for i in range(len(l) - 1):
x = int(l[i])
if(x % 2 == 0):
last = i
if x < odd:
break
if last == -1:
print(-1)
exit()
l[last] , l[-1] = str(odd) , l[last]
ans = "".join(l)
print(ans)
# Qalay(^-^)
#gcd__ |
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 | length = int(input())
word = input()
word = word.lower()
alpha = "abcdefghijklmnopqrstuvwxyz"
flag = True
for item in alpha:
if not(item in word):
flag = False
if flag == True:
print("YES")
else:
print("NO")
|
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())
a=input().split()
count=0
for i in a:
if i=='1':
count+=1
if count>0:
print('HARD')
else:
print('EASY') |
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a.
Will the robot be able to build the fence Emuskald... | 1 | cases = int(raw_input())
while cases > 0:
angle=int(raw_input())
if 360%(180-angle)==0:
print 'YES'
else:
print 'NO'
cases = cases - 1 |
Being stuck at home, Ray became extremely bored. To pass time, he asks Lord Omkar to use his time bending power: Infinity Clock! However, Lord Omkar will only listen to mortals who can solve the following problem:
You are given an array a of n integers. You are also given an integer k. Lord Omkar wants you to do k ope... | 3 | """
pppppppppppppppppppp
ppppp ppppppppppppppppppp
ppppppp ppppppppppppppppppppp
pppppppp pppppppppppppppppppppp
pppppppppppppppppppppppppppppppp
pppppppppppppppppppp... |
Dawid has four bags of candies. The i-th of them contains a_i candies. Also, Dawid has two friends. He wants to give each bag to one of his two friends. Is it possible to distribute the bags in such a way that each friend receives the same amount of candies in total?
Note, that you can't keep bags for yourself or thro... | 3 | # https://codeforces.com/problemset/problem/1230/A
x, y, z, t = input().split()
a = [int(x), int(y), int(z), int(t)]
S = a[0] + a[1] + a[2] + a[3]
found = False
for i in range(len(a)-1):
if found:
break
for j in range(i+1,len(a)):
if a[i] + a[j] == S - a[i] - a[j]:
found = True
... |
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 ... | 3 | t=int(input())
for nt in range(t):
s=input()
i=0
count=0
ans=[]
while i<len(s)-2:
if s[i]=="t" and s[i+1]=="w" and s[i+2]=="o" and i+4>=len(s):
count+=1
ans.append(i+2)
break
elif s[i]=="t" and s[i+1]=="w" and s[i+2]=="o" and s[i+3]=="n" and s[i+4]=="e":
count+=1
ans.append(i+3)
i+=5
elif s... |
Alex enjoys performing magic tricks. He has a trick that requires a deck of n cards. He has m identical decks of n different cards each, which have been mixed together. When Alex wishes to perform the trick, he grabs n cards at random and performs the trick with those. The resulting deck looks like a normal deck, but m... | 3 | n,m=map(int,input().split())
print(1.0 if n==m==1 else 1/n*((n-1)*(m-1)/(n*m-1)+1))
|
Statistics claims that students sleep no more than three hours a day. But even in the world of their dreams, while they are snoring peacefully, the sense of impending doom is still upon them.
A poor student is dreaming that he is sitting the mathematical analysis exam. And he is examined by the most formidable profess... | 3 | al, ar = map(int, input().split())
bl, br = map(int, input().split())
if al-1<=br<=2*al+2 or ar-1<=bl<=2*ar+2:
print("YES")
else:
print("NO")
|
You are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is a_i.
You have to create a team for a new programming competition. As you know, the more students some team has the more probable its victory is! So you have to create a team with the maxi... | 3 | GI = lambda: int(input()); GIS = lambda: map(int, input().split()); LGIS = lambda: list(GIS())
def main():
n = GI()
l = LGIS()
l.sort()
i = j = 0
m = 0
while j < n:
while l[j] - l[i] > 5:
i += 1
j += 1
m = max(j - i, m)
print(m)
main()
|
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn n numbers in a row, a_i is located in the i-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will giv... | 3 | n = int(input())
a = [int(x) for x in input().split()]
MAX_NUM = 100010
met_forw = [False] * MAX_NUM
met_backw = [False] * MAX_NUM
unique_n_backw = [0] * n
for i in range(n - 1, -1, -1):
if i < n - 1:
unique_n_backw[i] = unique_n_backw[i + 1]
if not met_backw[a[i]]:
met_backw[a[i]] = True
... |
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())
sum=a+b+c
mul=a*b*c
p=(a+b)*c
r=a*(b+c)
s=(a*b)+c
u=a+(b*c)
print(max(sum,mul,p,r,s,u))
|
Draw a rectangle which has a height of H cm and a width of W cm. Draw a 1-cm square by single '#'.
Constraints
* 1 ≤ H ≤ 300
* 1 ≤ W ≤ 300
Input
The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space.
The input ends with two 0 (when both H and W are zero)... | 3 | import sys
l = sys.stdin.readlines()[:-1]
for i in l:
h,w = map(int,i.strip().split())
print(("#"*w+"\n")*h) |
A permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a permutation (n=3 but there is 4 in the array).
For a positive integer n, we call a... | 3 | from itertools import combinations
for _ in range(int(input())):
n = int(input())
it = [str(i) for i in range(1, n + 1)]
it.sort(reverse=True)
print(' '.join(it)) |
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 | s=input()
l=[]
n=[]
for i in range(len(s)):
if s[i].isdigit():
l.append(int(s[i]))
l.sort()
for i in range(len(l)-1):
print(l[i],'+',sep="",end="")
print(l[-1])
|
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following.
Iahub wants to draw n distinct points and m segme... | 3 | input()
P=list(map(int,input().split()))
l=sorted([[P.index(p),i%2] for i,p in enumerate(sorted(P))])
for a,b in l:print(b) |
Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.
Your house has n rooms. In the i-th room you can install at most c_i heating radiators. Each radiator can have several sections, but ... | 3 | for i in range(int(input())):
c, su = map(int, input().split())
print((su // c) ** 2 * (c - su % c) + (su // c + 1) ** 2 * (su % c))
|
Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way:
qwertyuiop
asdfghjkl;
zxcvbnm,./
Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally move... | 3 | s="qwertyuiopasdfghjkl;zxcvbnm,./"
c=input()
q=input()
x=0
if c=='R':
x=-1
elif c=='L':
x=1
z=""
for i in q:
z+=s[s.index(i)+x]
print(z) |
In Takahashi Kingdom, there is a east-west railroad and N cities along it, numbered 1, 2, 3, ..., N from west to east. A company called AtCoder Express possesses M trains, and the train i runs from City L_i to City R_i (it is possible that L_i = R_i). Takahashi the king is interested in the following Q matters:
* The ... | 3 | """
区間ごとに前処理しておけばよい
"""
#memo[i][j] => iから出発し、jまでのどこかで終点する電車の数
N,M,Q = map(int,input().split())
memo = [[0]*(N+1) for _ in range(N+1)]
for _ in range(M):
l,r = map(int,input().split())
for j in range(r,N+1):
memo[l][j] += 1
for _ in range(Q):
p,q = map(int,input().split())
ans = 0
for i in ... |
Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length l. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of p meters per second, and the... | 1 | l = input()
p = input()
q = input()
p = float(p)/(p+q)
print l*p |
Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right.
In this table, Vanya chose n rectangles with sides that go along borders of squares (some rectangles probably occur mult... | 1 | n = int(raw_input())
ans = 0
for _ in xrange(n):
x1, y1, x2, y2 = map(int, raw_input().split())
ans += (x2 - x1 + 1) * (y2 - y1 + 1)
print ans
|
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | 3 | first=input()
second=input()
n = len(first)
if first[0]==second[0]:
a ='0'
else:
a ='1'
for i in range(1,n):
if first[i]==second[i]:
a += '0'
else:
a+='1'
print(a) |
Given an integer x, find 2 integers a and b such that:
* 1 ≤ a,b ≤ x
* b divides a (a is divisible by b).
* a ⋅ b>x.
* a/b<x.
Input
The only line contains the integer x (1 ≤ x ≤ 100).
Output
You should output two integers a and b, satisfying the given conditions, separated by a space. If no pair of in... | 3 | T = int(input())
if T != 1: print(2*(T//2), 2)
else: print(-1)
|
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... | 3 | d = {
'A' : 'A',
'b' : 'd',
'd' : 'b',
'H' : 'H',
'I' : 'I',
'M' : 'M',
'O' : 'O',
'o' : 'o',
'X' : 'X',
'x' : 'x',
'Y' : 'Y',
'W' : 'W',
'V' : 'V',
'w' : 'w',
'v' : 'v',
'T' : 'T',
'p' : 'q',
'q' : 'p',
'U' : 'U'
}
g = lambda c : '*' if c not in d.keys() else d[c]
s = input()
fo... |
You are given a string which comprises of lower case alphabets (a-z), upper case alphabets (A-Z), numbers, (0-9) and special characters like !,-.; etc.
You are supposed to find out which character occurs the maximum number of times and the number of its occurrence, in the given string. If two characters occur equal nu... | 1 | from collections import Counter
counts = dict()
max_occur, char = 0, None
for ch in raw_input().strip():
if ch not in counts:
counts[ch] = 1
else:
counts[ch] += 1
if counts[ch] > max_occur:
max_occur = counts[ch]
char = ch
elif counts[ch] == max_occur and ord(ch) < ord(c... |
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all n squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their h... | 3 | n = int(input())
a = list(map(int, input().split()))
smallIndex = 0
bigIndex = 0
smallVal = min(a)
bigVal = max(a)
for small in range(len(a)-1, 0, -1):
if a[small] == smallVal:
smallIndex = small
break
for big in range(len(a)):
if a[big] == bigVal:
bigIndex = big
break
if big... |
You have three tasks, all of which need to be completed.
First, you can complete any one task at cost 0.
Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.
Here, |x| denotes the absolute value of x.
Find the minimum total cost required to complete all the task.
Constrain... | 3 | t=sorted(list(map(int,input().split())))
print(t[2]-t[0]) |
Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called "Mau-Mau".
To play Mau-Mau, you need a pack of 52 cards. Each card has a suit (Diamonds — D, Clubs — C, Spades — S, or ... | 3 | s = input()
a = list(input().split())
for i in a:
if i[0] == s[0] or i[1] == s[1]:
print("YES")
break
else:
print("NO") |
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimi... | 3 | l=[0]*1100001
input()
for i in map(int,input().split()):l[i]+=1
for i in range(1100000):
l[i],l[i+1]=l[i]%2,l[i+1]+l[i]//2
print(sum(l)) |
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 = input()
a = a.upper()
c = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
k = 1
for i in range(len(c)):
if c[i] not in a:
k = 0
break
if k == 0:
print('NO')
else:
print('YES') |
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 | print("+".join(sorted(input().strip().split("+")))) |
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the p... | 3 | n = 4
grid = []
def is_valid(r, c):
return r >= 0 and c >= 0 and r < 4 and c < 4
def test(r, c):
if is_valid(r+1, c) and is_valid(r, c+1) and is_valid(r+1, c+1) and grid[r+1][c] == grid[r][c+1] == grid[r+1][c+1]:
return True
if is_valid(r, c-1) and is_valid(r+1, c) and is_valid(r+1, c-1) and grid[r]... |
The new PIN is hard to remember. I was told that I shouldn't take notes, but I don't think I can remember them. Therefore, I decided to embed a numerical value in the text and make a note of the PIN. Here, the sum of all the numbers is the PIN.
Create a program that reads the memorandum and outputs the PIN code.
In... | 1 | sm = 0
try:
while True:
a = ''
for c in raw_input():
a += c if c.isdigit() else ' '
sm += sum(map(int, a.split()))
except EOFError:
pass
print sm |
Bob loves everything sweet. His favorite chocolate bar consists of pieces, each piece may contain a nut. Bob wants to break the bar of chocolate into multiple pieces so that each part would contain exactly one nut and any break line goes between two adjacent pieces.
You are asked to calculate the number of ways he can... | 1 | n = int(raw_input())
lst = map(int, raw_input().split())
x = -1
ans = 1
for i in range(n):
if lst[i] == 1:
if x != -1:
ans *= (i - x)
x = i
if x == -1:
print 0
else:
print ans
|
You are given an array a[0 … n-1] of length n which consists of non-negative integers. Note that array indices start from zero.
An array is called good if the parity of each index matches the parity of the element at that index. More formally, an array is good if for all i (0 ≤ i ≤ n - 1) the equality i mod 2 = a[i] m... | 3 | t=int(input())
c=[]
for i in range(t):
n=int(input())
a=[int(i) for i in input().split()]
x=0
y=0
for i in range(0,n,2):
if a[i]%2!=0:
x+=1
for i in range(1,n,2):
if a[i]%2==0:
y+=1
if x==y:
c.append(x)
else:
c.append(-1)
for k in... |
Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define i modulo j as the remainder of division of i by j and denote it by <image>. A Modular Equation, as Hamed's teacher described, is an equation of the form <image> in which a and b are two non-negative integers a... | 3 | import itertools
import math
def main():
a, b = list(map(int, input().split()))
if a == b:
print("infinity")
return
if a < b:
print(0)
return
a -= b
n = 0
for i in range(1, math.ceil(math.sqrt(a))):
if (a % i == 0):
n += (i > b) + (a // i > b)
if math.sqrt(a) % 1 == 0 and math.sqrt(a) > b:
n ... |
The only difference between easy and hard versions is the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups i... | 3 | import bisect
from itertools import accumulate, count
import os
import sys
import math
from decimal import *
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 =... |
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 | l = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
k = input()
i = 0
while i+6 <= len(k):
if k[i:i+7] == '0000000' or k[i:i+7] =='1111111... |
Polycarp has guessed three positive integers a, b and c. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: a+b, a+c, b+c and a+b+c.
You h... | 3 | list1 =list(map(int,input().split()))
list1.sort()
a=list1[3]-list1[0]
b=list1[3]-list1[1]
c=list1[3]-list1[2]
print(a,b,c) |
You are given a text consisting of n lines. Each line contains some space-separated words, consisting of lowercase English letters.
We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants. In English alphabet following letters are considered to be vowels:... | 1 | Format=int(raw_input().strip())
sy=list(map(int,raw_input().strip().split()))
flag=True
dic=['a','e','i','o','u','y']
for _ in xrange(Format):
X=list(raw_input().strip())
if flag:
count=0
for i in X:
count+=(1 if i in dic else 0)
if count!=sy[_]:
print 'NO'
flag=False
if flag:
print 'YES' |
Amidakuji is a traditional method of lottery in Japan.
To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 [cm], and the endpoints of the horizontal lines must be at 1, 2, 3, ..., or H [cm] from the top of a vertical l... | 1 | h, w, k = map(int, raw_input().split())
arr = [1, 2, 3, 5, 8, 13, 21, 34]
def p(num):
return max(0, num)
r = [[0 for i in range(w)] for i in range(h+1)]
for i in range(h+1):
for j in range(w):
if i == 0:
if j == 0:
r[i][j] = 1
else:
r[i][j] = 0... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.