problem
stringlengths
29
9.39k
language
int64
1
3
solution
stringlengths
7
465k
New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows h hours and m minutes, where 0 ≀ hh < 24 and 0 ≀ mm < 60. We use 24-hour time format! Your task is to find the number of minutes before the New Year. You know that New Year comes when the...
3
time=1440 for _ in range(int(input())): h,m=map(int,input().split()) if h!=0 or m!=0: print(time-(h*60+m)) else: print(0)
You are enthusiastic about the popular web game "Moonlight Ranch". The purpose of this game is to grow crops in the fields, sell them to earn income, and use that income to grow the ranch. You wanted to grow the field quickly. Therefore, we decided to arrange the crops that can be grown in the game based on the income...
3
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 998244353 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF...
Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the characters at the odd-numbered positions, and the other contains the...
3
o=input() e=input() ans="" for i in range(len(o)+len(e)): ans+=o[i//2] if i%2<1 else e[i//2] print(ans)
Another Codeforces Round has just finished! It has gathered n participants, and according to the results, the expected rating change of participant i is a_i. These rating changes are perfectly balanced β€” their sum is equal to 0. Unfortunately, due to minor technical glitches, the round is declared semi-rated. It means...
3
# cook your dish here t=int(input()) c=0 while(t): t-=1 n=int(input()) if(n%2==0): print(n//2) else: if(c%2==0): print(n//2+1) else: print(n//2) c+=1
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ...
1
a=raw_input() j=0 if (int(a)%4)==0 or (int(a)%7)==0 or (int(a)%47)==0 or (int(a)%74)==0 or (int(a)%447)==0 or (int(a)%477)==0 or (int(a)%774)==0: print "YES" else: for i in range(len(a)): if a[i]=='4' or a[i]=='7': j+=1 if j==len(a): print "YES" else: print "NO"
Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1...
3
n, k = map(int, input().split()) p = 10 ** 9 + 7 cnt = [0] * (k + 1) for i in range(k, 0, -1): cnt[i] = pow((k // i), n, p) for j in range(i * 2, k + 1, i): cnt[i] -= cnt[j] print(sum((i * cnt[i] for i in range(1, k + 1))) % p)
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity. There are n columns of toy cubes in the box arranged in a line. The i-th column contains ai cubes. At first, the gravity in the box is pulling...
3
n = int(input()) s = sorted([int(x) for x in input().split()]) print(*s)
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th...
3
horseshoes = list(map(int, input().split())) extra_horseshoes = 0 for i in range(len(horseshoes)-1): for j in range(1+i, len(horseshoes)): if horseshoes[i] == horseshoes[j]: extra_horseshoes += 1 break print(extra_horseshoes)
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() prev = "" count = 1 status = 'NO' for el in s: if el == prev: count += 1 else: count = 1 if count == 7: status = 'YES' prev = el print(status)
You are given a bracket sequence s of length n, where n is even (divisible by two). The string s consists of n/2 opening brackets '(' and n/2 closing brackets ')'. In one move, you can choose exactly one bracket and move it to the beginning of the string or to the end of the string (i.e. you choose some index i, remov...
3
for _ in range(int(input())): n = int(input()) a = list(str(input())) c = 0 d = [] for i in range(len(a)): if a[i] == ')': c += 1 else: c -= 1 d.append(c) #print(d) print(max(d))
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ...
3
def solve(num): for i in [4,7,47,74,477,744]: if num % i == 0: return "YES" return "NO" num = int(input()) print(solve(num))
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
a = list(map(int, input().strip().split())) print(a[0]*a[1]//2)
Ujan has been lazy lately, but now has decided to bring his yard to good shape. First, he decided to paint the path from his house to the gate. The path consists of n consecutive tiles, numbered from 1 to n. Ujan will paint each tile in some color. He will consider the path aesthetic if for any two different tiles wit...
3
import math from collections import Counter,defaultdict I =lambda:int(input()) M =lambda:map(int,input().split()) LI=lambda:list(map(int,input().split())) def prime(n): for i in range(2,int(math.sqrt(n))+1): if n%i==0: return False return True def fact(n): s=[];j=2 while j*j<=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 math n,k=map(int,input().split()) l=list(map(int,input().split())) l.sort(reverse=True) su=sum(l) if su<k: print(-1) elif su==k: print(n) else: for i in range(1,n+1): no=int(math.ceil(n/i)) r=0 kk=0 for i1 in range(no): for j in range(i): r...
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
from sys import stdin, stdout a = int(stdin.readline().strip()) b = int(stdin.readline().strip()) c = int(stdin.readline().strip()) r = [0, 0, 0, 0] r[0] = a + b + c r[1] = a*b*c r[2] = (a + b) * c r[3] = a * (b + c) stdout.write(str(max(r)))
Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β€” he just leaves some blank space to mark them. Help him;...
1
from sys import stdin a = stdin.readline()[:-1] b = stdin.readline()[:-1].translate(None, ' ') rv = 'YES' for c in b: i = a.find(c) if i == -1: rv = "NO" break a = a[:i] + a[i+1:] print rv
M-kun has the following three cards: * A red card with the integer A. * A green card with the integer B. * A blue card with the integer C. He is a genius magician who can do the following operation at most K times: * Choose one of the three cards and multiply the written integer by 2. His magic is successful if...
3
a, b, c, k = map(int, open(0).read().split()) while a >= b: b *= 2 k -= 1 while b >= c: c *= 2 k -= 1 if k >= 0: print('Yes') else: print('No')
You are given an undirected graph with N vertices and 0 edges. Process Q queries of the following types. * `0 u v`: Add an edge (u, v). * `1 u v`: Print 1 if u and v are in the same connected component, 0 otherwise. Constraints * 1 \leq N \leq 200,000 * 1 \leq Q \leq 200,000 * 0 \leq u_i, v_i \lt N Input Input is ...
3
# UnionFind import sys def input(): return sys.stdin.readline().rstrip() sys.setrecursionlimit(1000000) class UnionFind: def __init__(self, n): self.n = [-1]*n self.r = [0]*n self.siz = n def find_root(self, x): if self.n[x] < 0: return x else: self.n[x] = self.find_root(self.n[x]) ...
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones. Once he thought about a string of length n consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and ...
3
def get_value(): length = int(input()) text = input() ones = int(text.count('1')) zeros = int(text.count('0')) return abs(ones - zeros) if __name__ == "__main__": print(get_value())
Returning back to problem solving, Gildong is now studying about palindromes. He learned that a palindrome is a string that is the same as its reverse. For example, strings "pop", "noon", "x", and "kkkkkk" are palindromes, while strings "moon", "tv", and "abab" are not. An empty string is also a palindrome. Gildong lo...
3
from collections import defaultdict n,m=map(int,input().split()) l1=[] for i in range(n): l1.append([i for i in input()]) l2=l1[:] reverse=[] for j in l1: l=[] for i in reversed(j): l.append(i) reverse.append(l) counter=0 same=0 a,b,c=[],[],[] for j in range(len(reverse)): #print(j) for ...
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
s=input() a=set() for c in s: a.add(c) if len(a)%2==0: print("CHAT WITH HER!") else: print("IGNORE HIM!")
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones. Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions: * For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \le...
3
import sys input = sys.stdin.readline p=int(input()) A=[int(i) for i in input().split()] B=[0]*p for i in range(p): a,c=A[i],1 B[0]-=a for j in range(1,p): c=c*i%p B[j]-=a*c if j==p-1: B[j]+=a B=B[::-1] for i in range(p): B[i]=B[i]%p print(*B)
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum nu...
3
import math n=input() sequence=input() sequence=sequence.split(' ') four=0 three=0 two=0 one=0 carcount=0 for x in sequence: if x=='4': four=four+1 if x=='3': three=three+1 if x=='2': two=two+1 if x=='1': one=one+1 if three>one: one=0 else: one=one-three two=float(two)/2+float(one)/4 two=math.ceil(two...
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of ea...
1
n = int(raw_input()) m = 1000001 s = raw_input() l = s.split() for i in range(n): x = int(l[i]) if m > x: m = x if m == 1: print -1 else: print 1
Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones b...
1
pattern = raw_input() first = pattern[0] search = 'W' if first == 'B' else 'B' moves = 0 spot = pattern.find(search) while spot != -1: search = 'W' if search == 'B' else 'B' moves += 1 pattern = pattern[spot:] spot = pattern.find(search) print moves
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it. But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than n. Can you help me to find th...
3
import sys,os,io import math,bisect,operator inf,mod = float('inf'),10**9+7 # sys.setrecursionlimit(10 ** 6) from itertools import groupby,accumulate from heapq import heapify,heappop,heappush from collections import deque,Counter,defaultdict input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ Neo = la...
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo...
3
n = int(input()) p = k = 0 for _ in range(n): x=input() if x!=p: k+=1 p=x print(k)
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
#!/usr/bin/env python # https://github.com/cheran-senthil/PyRival/blob/master/templates/template_py3.py import os import sys,math from io import BytesIO, IOBase def main(): # t=int(input()) for case in range(1): n=int(input()) print("YES") if(n%2==0 and n>2) else print("NO") # region fastio ...
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ...
1
# Codeforces Round #140 # Problem B -- Effective Approach n = input() positions = [0] * n for i, p in enumerate(map(int, raw_input().split())): positions[p - 1] = i m = input() a, b = 0, 0 for k in map(int, raw_input().split()): a += 1 + positions[k - 1] b += n - positions[k - 1] print a, b
Valera has got a rectangle table consisting of n rows and m columns. Valera numbered the table rows starting from one, from top to bottom and the columns – starting from one, from left to right. We will represent cell that is on the intersection of row x and column y by a pair of integers (x, y). Valera wants to place...
1
n, m, k = [int(c) for c in raw_input().strip().split()] cnt = 0 cells = m * n print k == 1 and cells or 2, for x in xrange(1,n+1): yrange = x % 2 == 1 and xrange(1,m+1) or xrange(m,0,-1) for y in yrange: print x, y, cnt += 1 if cnt >= 2 and k > 1: print '' k, cnt, cells = k - 1, 0, cells - 2 print k ==...
After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game Β«Call of Soldiers 3Β». The game has (m + 1) players and n types of soldiers in total. Players Β«Call of Soldiers 3Β» are numbered form 1 to (m + 1). Types of soldiers are numbered from 0 to n - 1. Each ...
3
n,m,k = map(int, input().split()) arr = [] for _ in range(m+1): arr.append(int(input())) lol = arr[m] res = 0 for i in range(m): tmp = 0 for j in range(n+1): if((lol^arr[i])&(2**j)!=0): tmp+=1 if(tmp<=k): res+=1 print(res)
You have n gifts and you want to give all of them to children. Of course, you don't want to offend anyone, so all gifts should be equal between each other. The i-th gift consists of a_i candies and b_i oranges. During one move, you can choose some gift 1 ≀ i ≀ n and do one of the following operations: * eat exactly...
3
from math import log2 def readGenerator(): while True: tokens = input().split(' ') for t in tokens: yield t reader = readGenerator() def readWord(): return next(reader) def readInt(): return int(next(reader)) def readFloat(): return float(next(reader)) def readLine(): ...
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...
3
s=input() s1=set() for i in s: if(i==' ' or i=='{' or i=='}' or i==","): continue else: s1.add(i) print(len(s1))
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
a=input() t=list(a) if(ord(t[0])>=97): t[0]=chr(ord(t[0])-32) l=''.join(t) print(l)
You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined <image>. You have to perform exactly k1 operations on array A and exactly k2 operations on array B. In one operation, you have to choose one element of the array and increase or decrease it by 1. Output the minimum poss...
3
from operator import itemgetter class CodeforcesTask960BSolution: def __init__(self): self.result = '' self.n_k_k = 0 self.A = 0 self.B = 0 def read_input(self): self.n_k_k = [int(x) for x in input().split(" ")] self.A = [int(x) for x in input().split(" ")] ...
You are given an array of n elements, you must make it a co-prime array in as few moves as possible. In each move you can insert any positive integral number you want not greater than 109 in any place in the array. An array is co-prime if any two adjacent numbers of it are co-prime. In the number theory, two integer...
3
from math import gcd n=int(input()) a=list(map(int, input().split())) ans=list() k=0 for i in range(n - 1): ans.append(a[i]) if gcd(a[i],a[i + 1])>1: ans.append(1) k += 1 ans.append(a[-1]) print(k) print(*ans)
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
1
n=raw_input() flag=0 c74=str(n.count('7')+n.count('4')) for i in range (10): if i == 4 or i == 7: continue if str(i) in c74: flag=1 if flag: print "NO" else: print "YES"
Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a power of A_i. Takahashi has decided to perform M handshakes to increase the happiness of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses o...
3
from bisect import bisect_left from itertools import accumulate N,M = map(int,input().split()) A = sorted(list(map(int,input().split()))) A_r = list(reversed(A)) B = [0] + list(accumulate(A_r)) def func(x): count = 0 for Ai in A: idx = bisect_left(A,x-Ai) count += N-idx if count >= M: ...
Anton likes to play chess, and so does his friend Danik. Once they have played n games in a row. For each game it's known who was the winner β€” Anton or Danik. None of the games ended with a tie. Now Anton wonders, who won more games, he or Danik? Help him determine this. Input The first line of the input contains a...
3
n = int(input()) s = input() A = s.count('A') D = s.count('D') if A > D: print('Anton') elif D > A: print('Danik') else: print('Friendship')
Eshag has an array a consisting of n integers. Eshag can perform the following operation any number of times: choose some subsequence of a and delete every element from it which is strictly larger than AVG, where AVG is the average of the numbers in the chosen subsequence. For example, if a = [1 , 4 , 3 , 2 , 4] and ...
3
for i in range(int(input())): n=int(input()) a=list(map(int,input().split())) m=min(a) print(n-a.count(m))
You are given an array a consisting of n integers. Your task is to say the number of such positive integers x such that x divides each number from the array. In other words, you have to find the number of common divisors of all elements in the array. For example, if the array a will be [2, 4, 6, 2, 10], then 1 and 2 ...
3
# A Better (than Naive) Solution to find all divisiors import math # method to print the divisors def printDivisors(n) : count=0 # Note that this loop runs till square root i = 1 while i <= math.sqrt(n): if (n % i == 0) : # If divisors are equal,...
The Little Girl loves problems on games very much. Here's one of them. Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: * The players move in turns; In one move the player can remove an arbitrary letter from string s. * If the pl...
3
s = input() d = {} count = 0 for i in range(len(s)): if s[i] not in d : d[s[i]] = 1 else: d[s[i]] +=1 for i in d.values(): if i % 2 != 0 : count +=1 if count == 0 or count % 2 != 0: print('First') else: print('Second')
In some game by Playrix it takes t minutes for an oven to bake k carrot cakes, all cakes are ready at the same moment t minutes after they started baking. Arkady needs at least n cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can bui...
1
n, t, k, d = map(int, raw_input().split()) p = (d + t) / t print "YES" if k * p < n else "NO"
Consider the following process. You have a binary string (a string where each character is either 0 or 1) w of length n and an integer x. You build a new binary string s consisting of n characters. The i-th character of s is chosen as follows: * if the character w_{i-x} exists and is equal to 1, then s_i is 1 (forma...
3
for _ in range(int(input())): s=input() x=int(input()) w1='1'*len(s) w=list(w1) f=0 for i in range(len(s)): if(s[i]=='0'): if(i-x >=0 and (i+x)<=(len(s)-1)): w[i-x]='0' w[i+x]='0' elif(i-x < 0 and (i+x)<=(len(s)-1)): ...
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 _ in range(t): a,b,c,d,k = map(int,input().split()) pens = 0 pencils = 0 if a<c: pens = 1 else: if a%c == 0: pens = a//c else: pens = a//c + 1 if b<d: pencils = 1 else: if b%d == 0: pencils = (...
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied: * For any two vertices p...
3
n=int(input());e=[[]for _ in[0]*-~n];q=[(1,0)];f=[-1]*n while n>1:v,w,c=map(int,input().split());e[v]+=(w,c),;e[w]+=(v,c),;n-=1 while q: v,c=q.pop();f[v-1]=c%2 for w,d in e[v]:q+=[(w,c+d)]*(f[w-1]<0) print(*f)
Lee is going to fashionably decorate his house for a party, using some regular convex polygons... Lee thinks a regular n-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the OX-axis and at least one of its edges is parallel to the OY-axis a...
3
x=int(input()) for i in range(x): b=int(input()) if b%4==0: print('Yes') else: print('No')
The little girl loves the problems on array queries very much. One day she came across a rather well-known problem: you've got an array of n elements (the elements of the array are indexed starting from 1); also, there are q queries, each one is defined by a pair of integers l_i, r_i (1 ≀ l_i ≀ r_i ≀ n). You need to f...
3
import sys input = sys.stdin.buffer.readline def I(): return(list(map(int,input().split()))) def sieve(n): a=[1]*n for i in range(2,n): if a[i]: for j in range(i*i,n,i): a[j]=0 return a n,q = I() arr = I() weights = [0]*(n+1) for i in range(q): l,r = I() weights[l-1]+=1 weights[r]-=1 c...
Let's define a split of n as a nonincreasing sequence of positive integers, the sum of which is n. For example, the following sequences are splits of 8: [4, 4], [3, 3, 2], [2, 2, 1, 1, 1, 1], [5, 2, 1]. The following sequences aren't splits of 8: [1, 7], [5, 4], [11, -3], [1, 1, 4, 1, 1]. The weight of a split is t...
1
n=int(raw_input()) print n/2+1 #just a try akkjlahfafhajkhaldfuiafjahfareke
There are n students standing in a circle in some order. The index of the i-th student is p_i. It is guaranteed that all indices of students are distinct integers from 1 to n (i. e. they form a permutation). Students want to start a round dance. A clockwise round dance can be started if the student 2 comes right after...
3
import sys q = int(input()) for i in range(q): pp = True n = int(sys.stdin.readline()) a = [*map(int,sys.stdin.readline().split())] a.append(a[0]) if a[1]-a[0]==-1 or a[1]-a[0]==n-1: for j in range(n-1,0,-1): if a[j]-a[j+1] == 1 or a[j]-a[j+1]==-(n-1): pass ...
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
s = input() ch_set = set() for ch in s: ch_set.add(ch) if len(ch_set) % 2 == 0: print("CHAT WITH HER!") else: print("IGNORE HIM!")
Recently Vova found n candy wrappers. He remembers that he bought x candies during the first day, 2x candies during the second day, 4x candies during the third day, ..., 2^{k-1} x candies during the k-th day. But there is an issue: Vova remembers neither x nor k but he is sure that x and k are positive integers and k >...
3
t = int(input()) for iii in range(t) : n = int(input()) k = 2 while n%((2**k)-1)!=0 : k = k+1 print(int(n/((2**k)-1)))
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
lst=[] for i in range(5): n=input().split() lst.append(n) for i in range(5): for j in range(5): if lst[i][j] == '1': print(abs(2 - i) + abs(2 - j))
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo...
3
t=int(input()) lst=[] while t: t-=1 lst.append(int(input())) x=lst[0] c=1 i=0 while i < (len(lst)): if lst[i]!=x: c+=1 x=lst[i] i+=1 else: i+=1 print(c)
On a chessboard with a width of n and a height of n, rows are numbered from bottom to top from 1 to n, columns are numbered from left to right from 1 to n. Therefore, for each cell of the chessboard, you can assign the coordinates (r,c), where r is the number of the row, and c is the number of the column. The white ki...
3
import math n = int(input()) x = list(map(int, input().split())) dist_black = n-x[0] + n-x[1] dist_white = x[0]-1 + x[1]-1 if dist_black < dist_white: print("Black") else: print("White")
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers β€” amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number. For each two integer numbers ...
3
l,r,x,y,k=map(int,input().split()) for i in range(x,y+1): q=k*i if q<=r and q>=l: print('YES') exit() print('NO')
There are three friend living on the straight line Ox in Lineland. The first friend lives at the point x1, the second friend lives at the point x2, and the third friend lives at the point x3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to...
1
a,b,c=map(int,raw_input().split()) x=map(abs,[a-b,b-c,a-c]) k=min(x) x.remove(k) print k+min(x)
Mahmoud has n line segments, the i-th of them has length ai. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments, check ...
3
n = int(input() ) a = sorted(list(map(int, input().split() ) ) ) for i in range(n-2): if a[i] + a[i+1] > a[i+2]: print('YES') exit() print('NO')
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick. He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substr...
3
n = int(input()) s = 'a' for i in range(n//2): if i%2 == 0: s = s+'bb' else: s = s+"aa" if n%2 != 0: print(s) else: s = s.replace(s[0],"",1) print(s)
Let's call a number k-good if it contains all digits not exceeding k (0, ..., k). You've got a number k and an array a containing n numbers. Find out how many k-good numbers are in a (count each number every time it occurs in array a). Input The first line contains integers n and k (1 ≀ n ≀ 100, 0 ≀ k ≀ 9). The i-th ...
3
def check(s,k): for i in range(k+1): if chr(ord('0')+i) not in s: return False return True n, k = map(int,input().split()) ans = 0 for i in range(n): ss = input() if check(ss,k): ans +=1 print(ans)
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc....
3
#traslation a = str(input()) b = str(input()) c = b[::-1] if a == c: print('YES') else: print('NO')
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
nb_cups, nb_task = [int(x) for x in input().split()] caffines = sorted([int(x) for x in input().split()], reverse=True) if nb_task > sum(caffines): print(-1) else: for days in range(1, 101): task_done = 0 for curr in range(nb_cups): task_done += max(0, caffines[curr] - curr // da...
As a token of his gratitude, Takahashi has decided to give his mother an integer sequence. The sequence A needs to satisfy the conditions below: * A consists of integers between X and Y (inclusive). * For each 1\leq i \leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i. Find the maximum possible ...
1
#!/bin/env python def main(): X, Y = map(int, raw_input().split(" ")) retval = 0 while X <= Y: X *= 2 retval += 1 print retval if __name__ == '__main__': main()
You are given two strings s and t both of length 2 and both consisting only of characters 'a', 'b' and 'c'. Possible examples of strings s and t: "ab", "ca", "bb". You have to find a string res consisting of 3n characters, n characters should be 'a', n characters should be 'b' and n characters should be 'c' and s and...
3
n = int(input()) a = input() b = input() if b in ['ab', 'bc', 'ca'] and a in ['ac', 'cb', 'ba']: temp = a a = b b = temp if a in ['ab', 'bc', 'ca'] and b in ['ac', 'ba', 'cb']: if a == 'ab' and b == 'ac': print("YES") for _ in range(n): print('bc', end='') for _ in r...
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
w = int(input()) summ = 0 for i in range(w): s = input().split(' ') if sum(int(j) for j in s) >= 2: summ += 1 print(summ)
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
matrix = [] for i in range(0,5): matrix.append(input().split()) sum = 0 for i in range(0,5): for j in range(0,5): if( int(matrix[i][j]) == 1): sum = abs(i-2) + abs(j-2) print(sum) break;
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
num=int(input()) if (num>0 and num!=2 and num%2==0): print("YES") else: print("NO")
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately. Organizers are stil...
1
n = input() f = [0]*100 f[0], f[1] = 1, 2 for i in range(2, len(f)): f[i] = f[i-1]+f[i-2] for i in range(len(f)): if f[i] > n: print i-1 break
George woke up and saw the current time s on the digital clock. Besides, George knows that he has slept for time t. Help George! Write a program that will, given time s and t, determine the time p when George went to bed. Note that George could have gone to bed yesterday relatively to the current time (see the second...
3
ti = input() duration = input() hh = int(ti[:2])-int(duration[:2]) mm = int(ti[3:])-int(duration[3:]) if hh < 0 and mm >= 0: if len(str(mm)) == 1: mm = "0" + str(mm) print(str(24+hh)+":"+str(mm)) elif hh >= 0 and mm >= 0: if len(str(mm))==1: mm = "0" + str(mm) if len(str(hh)) == 1: hh = "0" + str(hh) print(s...
The only difference between easy and hard versions are constraints on n and k. You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most k most recent conversations with your friends. Initially, the screen is empty (i.e. the number of displayed conversations equals 0...
3
from sys import stdin, stdout from collections import * def read(): return list(map(int, stdin.readline().split())) n, k = read() inque = set() q = deque() ids = read() for i in range(len(ids)): id = ids[i] if id in inque: continue if len(q) == k: inque.remove(q.pop()) q.appendleft(id) inque.add...
You are given two strings of equal length s and t consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings. During each operation you choose two adjacent characters in any string and assign the value of the first character to the value of the second or vice versa. ...
3
q = int(input()) cons = ord("a") for j in range(q): s = input() t = input() masS = [0] * 34 masT = [-1] * 34 for i in range(len(s)): masS[ord(s[i]) - cons] = 1 masT[ord(t[i]) - cons] = 1 i = 0 answer = "NO" while i<34 : if masS[i] == masT[i] : answer ...
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
s = input() #print(s) mir = 'xXAoOWwTYIMUvVH' def ch(a, b, x): return (s[x] == 'b' and s[-x - 1] == 'd') or (s[x] == 'p' and s[-x - 1] == 'q') or (s[x] == 'd' and s[-x - 1] == 'b') or (s[x] == 'q' and s[-x - 1] == 'p') def ispal(s): flag = True for x in range(len(s)//2): if ((s[x] == s[-x - 1] and (s[x] in mir)...
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got? Jeff must make the number without leading zero. At that, we assume that number ...
3
import collections n=int(input()) a=[int(i) for i in input().split()] b=[] d=collections.Counter(a) c=d[5] flag=0 while c!=0: if c%9==0: flag=1 break c-=1 if flag==1 and d[0]!=0: for i in range(0,c): b.append(5) for i in range(0,d[0]): b.append(0) print(*b,sep='') eli...
There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis. You planned a trip along the axis. In this plan, you first depart from...
3
n=int(input()) a=list(map(int,input().split())) a.append(0) bbefore=0 before=a.pop(0) s=abs(before-bbefore) lst=[] for i in a: s+=abs(i-before) lst.append(abs(i-before)+abs(before-bbefore)-abs(i-bbefore)) bbefore=before before=i for i in lst: print(s-i)
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides,...
3
from math import * def area(radi): return pow(radi, 2) * pi N = int(input()) A = list(map(int, input().split())) A.append(0) A.sort() ans = 0 cur = 0 for i in range(N, 0, -1): if cur == 1: cur = 0 else: ans += area(A[i]) - area(A[i - 1]) cur = 1 print(ans)
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium. The scales is in equilibrium ...
1
import sys import fractions import string ls, rs = raw_input().split('|') ds = raw_input() l,r,d = [len(i) for i in [ls,rs,ds]] if abs(l - r) > d or (l+r+d) % 2 != 0: print("Impossible") else: print ls+ds[:(r+d-l)/2]+"|"+rs+ds[(r+d-l)/2:]
You are given a string a, consisting of n characters, n is even. For each i from 1 to n a_i is one of 'A', 'B' or 'C'. A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting charac...
3
for _ in range(int(input())): s=input() n=len(s) new=[] a=['(',')'] b=['(',')'] c=['(',')'] ans=False for i in range(2): A=a[i] for j in range(2): B=b[j] for k in range(2): C=c[k] samp="" for l in ran...
Given are a positive integer N and a string S of length N consisting of lowercase English letters. Determine whether the string is a concatenation of two copies of some string. That is, determine whether there is a string T such that S = T + T. Constraints * 1 \leq N \leq 100 * S consists of lowercase English letter...
3
n=int(input()) s=input() x=s[:n//2] s=s[n//2:] if x==s: print("Yes") else: print("No")
You are given a set of all integers from l to r inclusive, l < r, (r - l + 1) ≀ 3 β‹… 10^5 and (r - l) is always odd. You want to split these numbers into exactly (r - l + 1)/(2) pairs in such a way that for each pair (i, j) the greatest common divisor of i and j is equal to 1. Each number should appear in exactly one o...
3
l,r=map(int,input().split());print("YES");print("\n".join([str(i)+" "+str(i+1) for i in range(l,r,2)]))
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....
3
p= input('') x=0 for i in range(int(p)): line= input('') if '++' in line: x=x+1 elif '--' in line: x=x-1 print(x)
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minut...
3
from sys import stdin n, working, screensaving, sleep, touched_time, screensaving_time = map(int, input().split()) last = list(map(int, input().split())) rest = (last[1]-last[0]) * working for i in range(1, n): current = list(map(int, stdin.readline().split())) d = current[0] - last[1] rest += min(d, tou...
Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0). Split the artists into two performance...
3
n = int(input()) c = input() a = input() c00=c01=c10=c11=0 d00=[] d01=[] d10=[] d11=[] for i in range(n): if c[i] == '1' and a[i] == '1': c11 +=1 d11.append(i) elif c[i] == '0' and a[i] == '1': c01 += 1 d01.append(i) elif c[i] == '1' and a[i] == '0': c10 += 1 ...
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
prime = [1]*(10**6 + 1) def sie_era(n): p = 2 while p**2 <= n: if prime[p] == True: for i in range(p*2,n+1,p): prime[i] = 0 p += 1 ans = [] _ = input() n = list(map(int,input().split())) sie_era(10**6) for i in n: key = False if i < 4: ans.app...
Olesya loves numbers consisting of n digits, and Rodion only likes numbers that are divisible by t. Find some number that satisfies both of them. Your task is: given the n and t print an integer strictly larger than zero consisting of n digits that is divisible by t. If such number doesn't exist, print - 1. Input T...
3
n,t = map(int,input().split()) X = 10**(n) ans = t*(X//t) # print(ans) if len(str(ans)) ==n and ans>0: print(ans) elif len(str(ans-t)) ==n and ans-t>0: print(ans-t) else: print(-1)
Everyone knows that agents in Valorant decide, who will play as attackers, and who will play as defenders. To do that Raze and Breach decided to play t matches of a digit game... In each of t matches of the digit game, a positive integer is generated. It consists of n digits. The digits of this integer are numerated f...
3
t=int(input()) while t: n=int(input()) num=int(input()) if n==1: if num%2==0: print(2) else: print(1) t-=1 continue lst=[] for i in str(num): lst.append(int(i)) printed=False if n%2==0: for i in range(len(lst))...
You are given a board of size n Γ— n, where n is odd (not divisible by 2). Initially, each cell of the board contains one figure. In one move, you can select exactly one figure presented in some cell and move it to one of the cells sharing a side or a corner with the current cell, i.e. from the cell (i, j) you can move...
3
t=int(input()) while(t>0): n=int(input()) k=n sum1=0 while k>1: k=k//2 sum1+=(k*n*4)-k*4 n-=2 k=n print(sum1) t-=1
Polycarp has n coins, the value of the i-th coin is a_i. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket. For example, if Polycarp has got six coins represented as an array a = [1, 2, 4, 3, 3, 2], he can distribute the coins into two ...
1
r=1 e=0 q=int(input()) w=[int(o) for o in raw_input().split()] w.sort() for i in range(q-1): if w[i]==w[i+1]: e=e+1 i=i+1 if r<=e: r=r+1 else: e=0 print r
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
n=int(input()) count=0 for i in range(n): lis=list(map(int,input().split())) if lis.count(1)>=2: count+=1 print(count)
A and B are preparing themselves for programming contests. An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to deal with the contests. Therefore, during the next team training A decided to make teams so that newbies are solvi...
1
import sys n, m = map(int, raw_input().split()) ans = 0 for x in range(n): maxy = min(n-2*x, (m-x)/2); if maxy>=0: ans = max(ans, x + maxy) print ans
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()) n=n-2 if(n==0): print('NO') elif(n%2==0): print("YES") else: print("NO")
There is a road with length l meters. The start of the road has coordinate 0, the end of the road has coordinate l. There are two cars, the first standing at the start of the road and the second standing at the end of the road. They will start driving simultaneously. The first car will drive from the start to the end ...
3
from bisect import bisect for _ in range(int(input())): n, l = map(int, input().split()) A = [0] + list(map(int, input().split())) + [l] X = [0] * (n + 2) Y = [0] * (n + 2) for i in range(1, n + 2): X[i] = X[i - 1] + (A[i] - A[i - 1]) / i Y[-i - 1] ...
A telephone number is a sequence of exactly 11 digits such that its first digit is 8. Vasya and Petya are playing a game. Initially they have a string s of length n (n is odd) consisting of digits. Vasya makes the first move, then players alternate turns. In one move the player must choose a character and erase it fro...
1
from sys import stdin n, a = int(input()), stdin.readline().strip() eight, rem = a.count('8'), n - 11 if eight <= (rem >> 1): print('NO') else: num, cur = (rem >> 1) + 1, 0 for i in range(n): if a[i] == '8': num -= 1 else: cur += 1 if not num: bre...
Lunar New Year is approaching, and you bought a matrix with lots of "crosses". This matrix M of size n Γ— n contains only 'X' and '.' (without quotes). The element in the i-th row and the j-th column (i, j) is defined as M(i, j), where 1 ≀ i, j ≀ n. We define a cross appearing in the i-th row and the j-th column (1 < i...
3
n=int(input()) mat=[] res=0 for s in range(n): mat.append(list(input())) for i in range(1,n-1): for j in range(1,n-1): if mat[i][j]==mat[i-1][j-1]==mat[i-1][j+1]==mat[i+1][j-1]==mat[i+1][j+1]=='X': res+=1 print(res)
Implication is a function of two logical arguments, its value is false if and only if the value of the first argument is true and the value of the second argument is false. Implication is written by using character '<image>', and the arguments and the result of the implication are written as '0' (false) and '1' (true...
3
#!/usr/bin/env python3 N = int(input()) A = list(map(int, input().split(' '))) def write_as_0(A): assert(len(A)) if len(A) == 1: if A[0] == 0: return 0 if A[0] == 1: return False if len(A) == 2: if A == [1, 0]: return (1, 0) else: return False ...
You are given an array a consisting of n positive integers, numbered from 1 to n. You can perform the following operation no more than 3n times: 1. choose three integers i, j and x (1 ≀ i, j ≀ n; 0 ≀ x ≀ 10^9); 2. assign a_i := a_i - x β‹… i, a_j := a_j + x β‹… i. After each operation, all elements of the array s...
3
# ---------------------------iye ha aam zindegi--------------------------------------------- import math import random import heapq, bisect import sys from collections import deque, defaultdict from fractions import Fraction import sys import threading from collections import defaultdict # threading.stack_size(10**8) ...
You are given a problemset consisting of n problems. The difficulty of the i-th problem is a_i. It is guaranteed that all difficulties are distinct and are given in the increasing order. You have to assemble the contest which consists of some problems of the given problemset. In other words, the contest you have to as...
3
n = int(input()) arr = list(map(lambda x: int(x), input().split())) m = 1 if n == 0: m = 0 prev = -1 count = 1 for i in range(1,n): if arr[i] > 2*arr[i-1]: if count > m: m = count count = 1 else: count += 1 if count > m: m = count print(m)
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
3
n = int(input()) x,y,z=0,0,0 for i in range(n): X,Y,Z= map(int,input().split()) x+=X y+=Y z+=Z if x==y==z==0: print("YES") else : print("NO")
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
print("YES" if (int(input()) - 2) in range(2, 101, 2) else "NO")
Bob is decorating his kitchen, more precisely, the floor. He has found a prime candidate for the tiles he will use. They come in a simple form factor β€” a square tile that is diagonally split into white and black part as depicted in the figure below. <image> The dimension of this tile is perfect for this kitchen, as h...
1
import sys,os,math from collections import Counter, defaultdict import bisect from sys import stdin, stdout from itertools import repeat # n, k = map(int, raw_input().split()) # da = map(int, raw_input().split()) # db = map(int, raw_input().split()) def main(): w, h = map(int, raw_input().split()) ans = 4...
There are five people playing a game called "Generosity". Each person gives some non-zero number of coins b as an initial bet. After all players make their bets of b coins, the following operation is repeated for several times: a coin is passed from one player to some other player. Your task is to write a program that...
3
""" Codeforces Contest 273 Div 2 Problem A Author : chaotic_iak Language: Python 3.3.4 """ def main(): a = sum(read()) if a == 0 or a % 5: print(-1) else: print(a // 5) ################################### NON-SOLUTION STUFF BELOW def read(mode=2): # 0: String # 1: List of string...