Between Two Sets
Source
input()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
m = max(b)
print(len([n for n in range(1, m + 1) if all(n % i == 0 for i in a) and all(i % n == 0 for i in b)]))
Birthday Chocolate
Source
n = int(input())
a = list(map(int, input().split()))
d, m = map(int, input().split())
print(sum([sum(a[i:i+m]) == d for i in range(len(a) - m + 1)]))
Breaking the Records
Source
from itertools import accumulate
input()
score = list(map(int, input().split()))
best = len(set(s for s, b in zip(score, list(accumulate(score, max))) if s == b)) - 1
worst = len(set(s for s, w in zip(score, list(accumulate(score, min))) if s == w)) - 1
print(best, worst)
Kangaroo
Source
x1, v1, x2, v2 = list(map(int, input().split()))
if v1 == v2:
print('YES' if x2 == x1 else 'NO')
else:
t = (x2 - x1) / (v1 - v2)
print('YES' if t >= 0 and t % 1 == 0 else 'NO')
Birthday Cake Candles
Source
from itertools import accumulate
input()
a = list(map(int, input().split()))
m = max(a)
print(sum(i == m for i in a))
Minimax Sum
Source
a = sorted([int(i) for i in raw_input().split()])
print(sum(a[:-1]), sum(a[1:])
Time Conversion
Source
import time
parsed = time.strptime(input(), '%I:%M:%S%p')
print(time.strftime('%H:%M:%S', parsed))
A Very Big Sum
Source
input()
print(sum(map(int, input().split())))
Diagonal Difference
Source
n = int(input())
left, right = 0, 0
for i in range(n):
row = list(map(int, input().split()))
left += row[i]
right += row[-i -1]
diff = left - right
print((-1 if diff < 0 else 1) * diff)```
<a href="https://www.hackerrank.com/challenges/plus-minus" target="\_blank">Source</a>
```python
n = int(input())
nums = list(map(int, input().split()))
pos = sum(x > 0 for x in nums)
neg = sum(x < 0 for x in nums)
nul = sum(x == 0 for x in nums)
print(pos / n, neg / n, nul / n, sep = '\n')
Staircase
Source
n = int(input())
for i in range(1, n + 1):
print(("{:>" + str(n) + "s}").format("#" * i))```
<a href="https://code.google.com/codejam/contest/6254486/dashboard#s=p1" target="\_blank">Source</a>
```python
T = int( raw_input() )
for t in range(T):
cakes = list(raw_input())
moves = 0
while True:
if '-' not in cakes:
break
l = cakes.index('-')
if l > 0:
cakes[:l] = '-'
moves += 1
if '-' not in cakes:
break
r = len(cakes) - 1 - cakes[::-1].index('-')
cakes[:r+1] = ['-' if c == '+' else '+' for c in cakes[r::-1]]
moves += 1
print "Case #%d: %d" % (t + 1, moves)
Counting Sheep
Source
T = int( raw_input() )
for t in range(T):
n = int( raw_input() )
ans = "INSOMNIA"
if n:
ans = n
s = set(str(n))
i = 2
while len(s) < 10 :
ans = i * n
i += 1
s |= set(str(ans))
print "Case #%d: %s" % (t + 1, ans)
Compare the Triplets
Source
#include<iostream>
using namespace std;
int a[6], alice, bob;
int main(){
for(int i = 0; i < 6; i++) cin >> a[i];
for(int i = 0; i < 3; i++) alice += a[i] > a[i+3], bob += a[i] < a[i+3];
cout << alice << " " << bob << endl;
return 0;
}
Manasa and Stones.cpp
Source
#include<bits/stdc++.h>
using namespace std;
set<int> ans;
void f( int a, int b, int c, int x ){
if( !a ){
ans.insert( x );
return;
}
f( a-1, b, c, x+b );
f( a-1, b, c, x+c );
}
int main(){
int t, n, a, b;
cin >> t;
while( t-- ){
cin >> n >> a >> b;
f( n-1, a, b, 0 );
while( !ans.empty() ){
cout << *ans.begin();
ans.erase( ans.begin() );
if( !ans.empty() )
cout << " ";
}
cout << endl;
}
return 0;
}
New Year and Hurry
Source
object NewYearHurry extends App{
val Array(n,k) = io.StdIn.readLine.split("\\s+").map(_.toInt)
val ans = (1 to n).map(5 * _).scanLeft(0)(_ + _).drop(1).takeWhile(_ <= 240 - k).size
println(ans)
}
Bachgold Problem
Source
object BachgoldProblem extends App{
val n = io.StdIn.readInt()
println(n / 2)
println(n match{
case n if n <= 3 => n
case n if n % 2 == 0 => "2" + " 2" * (n / 2 - 1)
case _ => "2" + " 2" * (n / 2 - 2) + " 3"
})
}
Santa Claus and a Place in a Class
Source
object SantaClausAndAPlaceInAClass extends App{
val Array(n, m, k) = io.StdIn.readLine.split("\\s+").map(_.toInt)
val lane = Math.ceil(k / (2.0 * m)).toInt
val desk = Math.ceil((k - (lane - 1) * 2 * m) / 2.0).toInt
println(s"""$lane $desk ${if(k % 2 == 0) "R" else "L"}""")
}
Lesha and Array Splitting.scala
Source
object LeshaAndArraySplitting extends App{
io.StdIn.readLine()
val A : Array[Int] = io.StdIn.readLine().split("\\s+").map(_.toInt)
if(A.count(_ == 0) == A.length){
println("NO")
} else{
if(A.sum != 0) println(
s"""
|YES
|1
|1 ${A.length}
""".stripMargin)
else {
def f(split : Int) : Int = {
A.splitAt(split) match {
case (l, r) if l.sum != 0 && r.sum != 0 => split
case _ => f(split - 1)
}
}
val split = f(A.length)
println(
s"""YES
|2
|1 $split
|${split + 1} ${A.length}
""".stripMargin)
}
}
}
Gotta Catch 'em all
Source
object GottaCatchEmAll extends App{
val textCount = io.StdIn.readLine().groupBy(_.toChar).mapValues(_.length)
val bulbasaur = "Bulbasaur".groupBy(_.toChar).mapValues(_.length)
val ans = bulbasaur.collect{ case (k, v) => textCount.getOrElse(k, 0) / v }.min
println(ans)
}
Some Last Words
- Noticed that neat trick for checking whether a number is integer using the modulo operator? ( ͡° ͜ʖ ͡°)