code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
X, Y = map(int, input().split())
ans = 0
if X <= 3:
ans += (4-X) * 100000
if Y <= 3:
ans += (4-Y) * 100000
if X == Y == 1:
ans += 400000
print(ans) | #
# abc145 c
#
import sys
from io import StringIO
import unittest
import math
import itertools
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """3
0 0
1 0
0 1"""
output = """2.2761423749"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """2
-879 981
-866 890"""
output = """91.9238815543"""
self.assertIO(input, output)
def test_入力例_3(self):
input = """8
-406 10
512 859
494 362
-955 -475
128 553
-986 -885
763 77
449 310"""
output = """7641.9817824387"""
self.assertIO(input, output)
def resolve():
N = int(input())
P = [list(map(int, input().split())) for _ in range(N)]
R = itertools.permutations(range(N))
all = 0
for r in R:
for pi in range(1, len(r)):
all += math.sqrt((P[r[pi]][0]-P[r[pi-1]][0])**2 +
(P[r[pi]][1]-P[r[pi-1]][1])**2)
n = 1
for i in range(1, N+1):
n *= i
print(f"{all/n:.10f}")
if __name__ == "__main__":
# unittest.main()
resolve()
| 0 | null | 144,767,594,426,520 | 275 | 280 |
n=int(input())
stri=[]
time=[]
for _ in range(n):
s,t=input().split()
stri.append(s)
time.append(t)
x=input()
ind=stri.index(x)
ans=0
for i in range(ind+1,n):
ans+=int(time[i])
print(ans) | n = int(input())
playList = []
sumTerm = 0
for i in range(n) :
song = input().split()
song[1] = int(song[1])
playList.append(song)
sumTerm += song[1]
x = input()
tmpSumTerm = 0
for i in range(n) :
tmpSumTerm += playList[i][1]
if playList[i][0] == x :
print(sumTerm - tmpSumTerm)
break
| 1 | 97,086,833,331,836 | null | 243 | 243 |
def ctoi(x):
return ord(x)-ord("a")
n = int(input())
s = list(input())
q = int(input())
bit = [[0]*(n+1) for _ in range(26)]
def update(pos,a,x):
while pos<=n:
bit[a][pos] += x
pos += pos&(-pos)
def query(pos):
ret=[0]*26
for i in range(26):
tmp=0
p=pos
while p>0:
tmp+=bit[i][p]
p-=p&(-p)
ret[i]=tmp
return ret
for i in range(n):
update(i+1,ctoi(s[i]),1)
for _ in range(q):
flag,a,b = input().split()
flag=int(flag)
a=int(a)
if flag==1:
if s[a-1]==b:
continue
else:
update(a,ctoi(s[a-1]),-1)
update(a,ctoi(b),1)
s[a-1]=b
else:
b=int(b)
c1 = query(b)
c2 = query(a-1)
ans = 0
for i in range(26):
if c1[i]-c2[i]>0:
ans += 1
print(ans) |
class BIT:
"""Binary Indexed Tree (Fenwick Tree)
Range Sum QueryにO(log N)時間で答える
1-indexed
"""
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
self.depth = n.bit_length()
def sum(self, i):
"""a[1]~a[i]の区間和を取得"""
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
"""a[i]にxを足す"""
while i <= self.size:
self.tree[i] += x
i += i & -i
def lower_bound(self, x):
""" 累積和がx以上になる最小のindexと、その直前までの累積和 """
sum_ = 0
pos = 0
for i in range(self.depth, -1, -1):
k = pos + (1 << i)
if k <= self.size and sum_ + self.tree[k] < x:
sum_ += self.tree[k]
pos += 1 << i
return pos + 1, sum_
def main():
N = int(input())
S = list(input())
Q = int(input())
alphabets = list("abcdefghijklmnopqrstuvwxyz")
c2n = {c: i for i, c in enumerate(alphabets)}
Trees = [BIT(N+2) for _ in range(26)]
for i in range(N):
Trees[c2n[S[i]]].add(i+1, 1)
for _ in range(Q):
tmp = list(input().split())
if tmp[0] == "1":
_, i, c = tmp
i = int(i)
Trees[c2n[S[i-1]]].add(i, -1)
Trees[c2n[c]].add(i, 1)
S[i-1] = c
else:
ans = 0
_, l, r = tmp
l = int(l)
r = int(r)
for char in range(26):
if Trees[char].sum(r) - Trees[char].sum(l-1) > 0:
ans += 1
print(ans)
if __name__ == "__main__":
main() | 1 | 62,615,998,034,380 | null | 210 | 210 |
def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(input()) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
#############
# Main Code #
#############
N = getN()
A = getList()
# N // 2個の整数をどの2箇所も連続しないように選ぶ
# 和の最大値を求めよ
# 通りの数は? まあまあ多い
# 偶数の場合
# 始点がA[1]なら1通りに定まる
# 始点がA[0]なら?
# 次に3個先を取ると1通りに定まる
# 次に2個先を取り、その次に3個先を取ると1通りに定まる
# dp[i][j]: i回目までに3つ飛ばしをj回使った
# 長さが偶数なら1回まで使える
if N % 2 == 0:
dp = [[-float('inf')] * 2 for i in range(N)]
dp[0][0] = A[0]
dp[1][0] = A[1]
for i in range(2, N):
for j in range(1, -1, -1):
if j == 0:
dp[i][j] = max(dp[i][j], dp[i - 2][j] + A[i])
elif j == 1 and i - 3 >= 0:
dp[i][j] = max(dp[i][j], dp[i - 2][j] + A[i])
if i - 3 >= 0 and j - 1 >= 0:
dp[i][j] = max(dp[i][j], dp[i - 3][j - 1] + A[i])
# 0個飛ばしdp[-2]:奇数個目だけ 0個飛ばしdp[-1]:偶数個目だけ 1個飛ばしdp[-1]
print(max(dp[-2][0], dp[-1][0], dp[-1][1]))
# 長さが奇数なら2回まで使える
else:
dp = [[-float('inf')] * 3 for i in range(N)]
dp[0][0] = A[0]
dp[1][0] = A[1]
for i in range(2, N):
for j in range(2, -1, -1):
if j == 0:
dp[i][j] = max(dp[i][j], dp[i - 2][j] + A[i])
elif j >= 1 and i - 3 >= 0:
dp[i][j] = max(dp[i][j], dp[i - 2][j] + A[i])
if i - 3 >= 0 and j - 1 >= 0:
dp[i][j] = max(dp[i][j], dp[i - 3][j - 1] + A[i])
opt_1 = [A[i] for i in range(N) if i % 2 == 0]
opt_2 = [A[i] for i in range(N) if i % 2 == 1]
# 2個飛ばしならdp[-1]のが該当
# 1個飛ばしならdp[-1], dp[-2]のが該当
# 0個飛ばしは奇数個目だけ - その中の最小値、偶数個目だけ
print(max(dp[-1][2], dp[-1][1], dp[-2][1], sum(opt_1) - min(opt_1), sum(opt_2))) | lst=[int (x) for x in input().split(' ')]
print(lst[0]*lst[1])
| 0 | null | 26,794,160,949,612 | 177 | 133 |
n = input()
k = input()
a = k.count("R")
print(k[:a].count("W")) | import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline()[:-1]
mod = 10**9 + 7
def readInt():return int(input())
def readIntList():return list(map(int,input().split()))
def readStringList():return list(input())
def readStringListWithSpace():return list(input().split())
def readString():return input()
n = readInt()
text = readStringList()
import collections
c = collections.Counter(text)
if c['W'] == 0:
print("0")
exit()
i,j,count = 0,len(text)-1,0
while i <= j and i < len(text):
if text[i] == 'W':
while text[j] != 'R' and j > 0:
j -= 1
if i <= j and j > 0:
text[i],text[j] = text[j],text[i]
count += 1
i += 1
print(count)
| 1 | 6,301,975,138,030 | null | 98 | 98 |
n=int(input())
R=[int(input()) for i in range(n)]
mini=10**10
maxi=-10**10
for r in R:
maxi=max([maxi,r-mini])
mini=min([mini,r])
print(maxi)
| h, w = map(int, input().split())
import math
if h == 1 or w == 1:
print(1)
elif h%2 == 0 and w%2 == 0:
print(h * w // 2)
elif h%2 == 0 or w%2 == 0:
if h%2 == 0:
we = w//2
wo = math.ceil(w/2)
print(we * h//2 + wo * h//2)
else:
he = h//2
ho = math.ceil(h/2)
print(ho * w//2 + he * w//2)
else:
# odd
we = w//2
wo = math.ceil(w/2)
he = h//2
ho = math.ceil(h/2)
print(ho * wo + he * we)
| 0 | null | 25,348,954,320,480 | 13 | 196 |
array = input().split()
stack = []
while True:
if len(array) == 0: break
e = array.pop(0)
if e.isdigit():
stack.append(e)
else:
num1 = stack.pop()
num2 = stack.pop()
stack.append(str(eval(num2 + e + num1)))
print(stack[0]) | A = int(input())
print(A**2) | 0 | null | 72,859,322,568,060 | 18 | 278 |
from sys import stdin
def make_divisors(n):
mod0 = set()
mod1 = set()
for i in range(2, int(n**0.5)+1):
if n%i==0:
mod0.add(i)
mod0.add(n/i)
if (n-1)%i==0:
mod1.add(i)
mod1.add((n-1)/i)
return mod0,mod1
N=list(map(int,(stdin.readline().strip().split())))
num=N[0]
if num==2:print(1)
else:
K=0
mod0,mod1=(make_divisors(num))
# mod0.remove(1)
# mod1.remove(1)
for i in mod0:
num = N[0]
while(num % i == 0):
num/=i
if num%i==1:
K+=1
K+=len(mod1)+2
print(K)
| #!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")
from collections import Counter
def factorial(n):
prime_count = Counter()
for i in range(2, int(n**0.5) + 2):
while n % i == 0:
n /= i
prime_count[i] += 1
if n > 1:
prime_count[int(n)] += 1
return prime_count
def num_divisors(prime_count):
num = 1
for prime, count in prime_count.items():
num *= (count + 1)
return num
def divisors(n):
ret = set()
for i in range(1, int(n ** 0.5) + 1):
d, m = divmod(n, i)
if m == 0:
ret.add(i)
ret.add(d)
return sorted(ret)
def solve(N: int):
f = factorial(N-1)
ans = num_divisors(f)-1
divs = divisors(N)
for k in divs:
if k == 1:
continue
n = N
while n % k == 0:
n = n//k
if n == 1:
break
if n % k == 1:
ans += 1
print(ans)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
solve(N)
if __name__ == '__main__':
main()
| 1 | 41,430,617,921,216 | null | 183 | 183 |
n,x,t=[int(i) for i in input().split()]
k=n//x
if n%x:
print((k+1)*t)
else:
print(k*t) | print("pphbhhphph"[int(input())%10]+"on") | 0 | null | 11,733,095,556,248 | 86 | 142 |
R = int(input())
L = 2*R*3.141592
print(L)
| length = int(input())
targ = [int(n) for n in input().split(' ')]
ans = 0
for l in range(length):
value = l
for init in range(l + 1,length):
if targ[value] > targ[init]:
value = init
if value != l:
disp = targ[l]
targ[l] = targ[value]
targ[value] = disp
ans += 1
print(' '.join([str(n) for n in targ]))
print(ans) | 0 | null | 15,771,734,323,790 | 167 | 15 |
import math
def takoyaki(n, x, t)-> int :
itr = math.ceil(n / x)
return itr * t
if __name__ == "__main__":
input = list(map(int, input().split()))
print(takoyaki(input[0], input[1], input[2]))
| input_line = input().split(" ")
S = int(input_line[0])
W = int(input_line[1])
if S > W:
print("safe")
else:
print("unsafe") | 0 | null | 16,661,476,007,682 | 86 | 163 |
n, k = map(int, input().split())
mod = 10**9 + 7
s = [0]*(n+1)
s[0] = n + 1
for i in range(1, n+1):
s[i] = (s[i-1] + n - 2 * i) % mod
ans = 0
for i in range(k-1, n+1):
ans += s[i]
ans %= mod
print(ans)
| N, K = list(map(int, input().split()))
C = 10**9+7
ans = 0
A = sum(list(range(N, N-K, -1)))
B = sum(list(range(K)))
for i in range(K, N+2):
# print(A,B)
ans += A-B+1
A += N-i
B += i
ans %= C
print(ans) | 1 | 33,258,465,462,278 | null | 170 | 170 |
n, x, m = map(int, input().split())
li = [x]
se = {x}
for i in range(n-1):
x = x*x%m
if x in se:
idx = li.index(x)
break
li.append(x)
se.add(x)
else:
print(sum(li))
exit(0)
ans = sum(li) + sum(li[idx:])*((n-len(li)) // (len(li)-idx)) + sum(li[idx:idx+(n-len(li)) % (len(li)-idx)])
print(ans) | """
何回足されるかで考えればよい。
真っ二つに切っていく。
各項は必ずM未満。
M項以内に必ずループが現れる。
"""
N,X,M = map(int,input().split())
memo1 = set()
memo2 = []
ans = 0
a = X
flag = True
rest = N
while rest > 0:
if a in memo1 and flag:
flag = False
for i in range(len(memo2)):
if memo2[i] == a:
loopStart = i
setSum = 0
for i in range(loopStart,len(memo2)):
setSum += memo2[i]**2 % M
loopStep = len(memo2)-loopStart
loopCount = rest // loopStep
ans += loopCount*setSum
rest -= loopCount*loopStep
else:
memo1.add(a)
memo2.append(a)
ans += a
a = a**2%M
rest -= 1
print(ans) | 1 | 2,820,561,181,452 | null | 75 | 75 |
a = input().split()
b = []
for i in range(len(a)):
if a[i] == "+":
b[-2] = b[-2] + b[-1]
b.pop()
elif a[i] == "-":
b[-2] = b[-2] - b[-1]
b.pop()
elif a[i] == "*":
b[-2] = b[-2] * b[-1]
b.pop()
else:
b.append(int(a[i]))
print(b[-1])
|
import sys
MOD = 998244353
def main():
input = sys.stdin.buffer.readline
n, s = map(int, input().split())
a = list(map(int, input().split()))
dp = [[None] * (s + 1) for _ in range(n + 1)]
# dp[i][j]:=集合{1..i}の空でない部分集合T全てについて,和がjとなる部分集合の個数の和
for i in range(n + 1):
for j in range(s + 1):
if i == 0 or j == 0:
dp[i][j] = 0
continue
if j > a[i - 1]:
dp[i][j] = dp[i - 1][j] * 2 + dp[i - 1][j - a[i - 1]]
elif j == a[i - 1]:
dp[i][j] = dp[i - 1][j] * 2 + pow(2, i - 1, MOD)
else:
dp[i][j] = dp[i - 1][j] * 2
dp[i][j] %= MOD
print(dp[n][s])
if __name__ == '__main__':
main()
| 0 | null | 8,783,151,236,290 | 18 | 138 |
#!/usr/bin/env python3
a, b, c = map(int, input().split())
print("YNeos"[c - a - b < 0 or 0 <= 4 * a * b - (a + b - c)**2::2])
| a,b,c = map(int,input().split())
d = 0
if ( a + b - c ) < 0:
if ( a + b - c ) ** 2 > 4 * a * b:
d = 1
if d == 1:
print("Yes")
else:
print("No") | 1 | 51,635,253,819,292 | null | 197 | 197 |
# coding: utf-8
def bubbleSort(C, N):
for i in xrange(N):
for j in xrange(N-1, i, -1):
if C[j-1][1] > C[j][1]:
C[j], C[j-1] = C[j-1], C[j]
return C
def selectionSort(C, N):
for i in xrange(N):
minj = i
for j in xrange(i, N):
if C[minj][1] > C[j][1]:
minj = j
C[i], C[minj] = C[minj], C[i]
return C
def isStable(in_, out_, N):
for i in xrange(N):
for j in xrange(i + 1, N):
for a in xrange(N):
for b in xrange(a + 1, N):
if in_[i][1] == in_[j][1] and in_[i] == out_[b] and in_[j] == out_[a]:
return False
return True
def main():
N = input()
cards = raw_input().split()
bubble = bubbleSort(cards[:], N)
selection = selectionSort(cards[:], N)
print ' '.join(bubble)
print 'Stable' if isStable(cards, bubble, N) else 'Not stable'
print ' '.join(selection)
print 'Stable' if isStable(cards, selection, N) else 'Not stable'
if __name__ == '__main__':
main() | def buble(lst):
src_list = list(lst)
flag=True
while flag:
flag = False
for idx in range(len(lst)-1, 0, -1):
if int(lst[idx][1]) < int(lst[idx-1][1]):
tmp=lst[idx]
lst[idx]=lst[idx-1]
lst[idx-1]=tmp
flag=True
flag_stable = True
for num in range(0, 9):
tmp1 = []
tmp2 = []
for i in range(0, len(lst)):
if int(lst[i][1]) == num:
tmp1.append(lst[i])
if int(src_list[i][1]) == num:
tmp2.append(src_list[i])
if tmp1 != tmp2:
flag_stable = False
break
print " ".join(lst)
if flag_stable:
print "Stable"
else:
print "Not stable"
def selection(lst):
src_list = list(lst)
for i in range(len(lst)):
m = i
for j in range(i,len(lst)):
if int(lst[m][1]) > int(lst[j][1]):
m=j
tmp=lst[i]
lst[i]=lst[m]
lst[m]=tmp
flag_stable = True
for num in range(0, 9):
tmp1 = []
tmp2 = []
for i in range(0, len(lst)):
if int(lst[i][1]) == num:
tmp1.append(lst[i])
if int(src_list[i][1]) == num:
tmp2.append(src_list[i])
if tmp1 != tmp2:
flag_stable = False
break
print " ".join(lst)
if flag_stable:
print "Stable"
else:
print "Not stable"
n=raw_input()
lst1 = raw_input().split()
lst2 = list(lst1)
buble(lst1)
selection(lst2) | 1 | 25,360,583,492 | null | 16 | 16 |
N,K = map(int,input().split())
A = list(map(int,input().split()))
A = [(a-1) % K for a in A]
S = [0 for i in range(N+1)]
for i in range(1, N+1):
S[i] = (S[i-1] + A[i-1]) % K
kinds = set(S)
counts = {}
ans = 0
for k in kinds:
counts[k] = 0
for i in range(N+1):
counts[S[i]] += 1
if i >= K:
counts[S[i-K]] -= 1
ans += (counts[S[i]] - 1)
print(ans) | import itertools
H, W, K = map(int, input().split())
A = [[int(x) for x in input()] for _ in range(H)]
def solve(blocks):
n_block = len(blocks)
n_cut = n_block - 1
sums = [0 for _ in range(n_block)]
for c in range(W):
adds = [block[c] for block in blocks]
if any(a > K for a in adds):
return H * W
sums = [s + a for s, a in zip(sums, adds)]
if any(s > K for s in sums):
n_cut += 1
sums = adds
return n_cut
ans = H * W
for mask in itertools.product([0, 1], repeat=H - 1):
mask = [1] + list(mask) + [1]
pivots = [r for r in range(H + 1) if mask[r]]
blocks = [A[p1:p2] for p1, p2 in zip(pivots[:-1], pivots[1:])]
blocks = [[sum(row[c] for row in block) for c in range(W)] for block in blocks]
ans = min(ans, solve(blocks))
print(ans)
| 0 | null | 92,990,157,543,488 | 273 | 193 |
from sys import stdin
h, w = [int(x) for x in stdin.readline().strip().split()]
if(h == 1 or w == 1):
print(1)
else:
print((h//2)*(w//2)+((h+1)//2)*((w+1)//2)) | x = [int(s) for s in input().split()]
(a, b) = (x[0], x[1])
if a == b:
print('a == b')
elif a < b:
print('a < b')
else:
print('a > b') | 0 | null | 25,628,509,675,068 | 196 | 38 |
while True:
m, f, r = [int(_) for _ in input().split()]
if m == -1 and f == -1 and r == -1:
break
sum = m+f
if m == -1 or f == -1 or sum < 30:
print("F")
else:
if sum >= 80:
print("A")
elif sum >= 65:
print("B")
elif sum >= 50:
print("C")
else:
if r >= 50:
print("C")
else:
print("D") | while True:
mid, term, add = map(int, input().split())
if mid == -1 and term == -1 and add == -1:
break
if mid == -1 or term == -1:
rank = 'F'
elif mid + term >= 80:
rank = 'A'
elif mid + term >= 65:
rank = 'B'
elif mid + term >= 50:
rank = 'C'
elif mid + term >= 30:
if add >= 50:
rank = 'C'
else:
rank = 'D'
else:
rank = 'F'
print(rank) | 1 | 1,237,181,848,628 | null | 57 | 57 |
def resolve():
MOD = 10 ** 9 + 7
N, K = map(int, input().split())
ans = 0
for k in range(K, N + 2):
min_num = k * (k - 1) // 2
max_num = k * (N * 2 - k + 1) // 2
add = max_num - min_num + 1
ans = (ans + add) % MOD
print(ans)
if __name__ == "__main__":
resolve() | def f(m):
return (((N+1)*((m*(m+1))//2))%p-((m*(m+1)*(2*m+1))//6)%p+m%p)%p
p = 10**9+7
N,K = map(int,input().split())
cnt = (f(N+1)-f(K-1))%p
print(cnt) | 1 | 33,083,374,804,778 | null | 170 | 170 |
# -*- coding: utf-8 -*-
def main():
A, B = map(int, input().split())
ans = A - 2 * B
if ans < 0:
ans = 0
print(ans)
if __name__ == "__main__":
main() | # coding: utf-8
a, b = map(int, input().split())
ans = -1
if a < 10 and b < 10:
ans = a * b
print(ans)
| 0 | null | 162,756,306,866,208 | 291 | 286 |
n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
ans=0
for i in range(0,n-2):
for j in range(i+1,n-1):
left = j
right = n
while right-left>1:
mid = (left + right)//2
if l[i]+l[j]>l[mid] and l[i]+l[mid]>l[j] and l[mid]+l[j]>l[i]:
left = mid
else:
right = mid
#print(i,j,left)
ans+=(left-j)
print(ans) | import sys
from collections import Counter
def ep(*params):
print(*params,file=sys.stderr)
(N,P) = list(map(int,input().split()))
S = input().rstrip()
if 10%P == 0:
ans = 0
for i in range(N):
if int(S[i])%P == 0:
ans += i+1
print(ans)
sys.exit()
ans = 0
d = [0]*(N+1)
cnt = [0]*P
ten = 1
for i in range(N-1,-1,-1):
a = int(S[i]) * ten % P
d[i] = (d[i+1]+a) % P
ten *= 10
ten %= P
#ep(d)
for i in range(N,-1,-1):
ans += cnt[d[i]]
cnt[d[i]] += 1;
#ep(i,ans,cnt)
#ep(cnt)
print(ans) | 0 | null | 114,593,112,011,858 | 294 | 205 |
from numpy import cumsum
n,m=map(int,input().split())
a=list(map(int,input().split()))
result=cumsum(a)[-1]
mi=result/(4*m)
ans=0
for i in range(n):
if a[i]>=mi:
ans+=1
if ans>=m:
print('Yes')
else:
print('No') | import bisect
N, M, X = map(int, input().split())
C = [0] * N
A = [0] * N
for i in range(N):
x = list(map(int, input().split()))
C[i] = x[0]
A[i] = [0] * M
for j in range(M):
A[i][j] = x[j + 1]
cnt = [0] * (2 ** N)
ans_list = []
for i in range(2 ** N):
bag = []
cnt[i] = [0] * M
for j in range(N):
if ((i >> j) & 1):
bag.append(C[j])
for k in range(M):
cnt[i][k] += A[j][k]
cnt[i].sort()
if bisect.bisect_left(cnt[i], X) == 0:
ans_list.append(sum(bag))
if ans_list == []:
print(-1)
else:
print(min(ans_list)) | 0 | null | 30,380,047,388,860 | 179 | 149 |
a, b, c, k = map(int, input().split())
ans = 0
if a >= k:
ans = k * 1
else:
ans = a * 1 + max(0, (k - a)) * 0 + max(0, (k - a - b)) * (-1)
print(ans)
| import sys
def input(): return sys.stdin.readline().rstrip()
A,B,C,K = map(int,input().split())
point = 0
if A <= K:
point += A
K -= A
else:
point += K
K = 0
if B <= K:
K -= B
else:
K = 0
point -= K
print(point) | 1 | 21,828,960,515,712 | null | 148 | 148 |
N, K = list(map(int, input().split()))
H = list(map(int, input().split()))
h = list(filter(lambda x: x >= K, H))
print(len(h))
| import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()
def main():
h,w=LI()
l=[]
l.append('.'*(w+1))
for _ in range(h):
x='.'
x+=S()
l.append(x)
dp=[[inf]*(w+10) for _ in range(h+10)]
if l[1][1]=='#':
dp[1][1]=1
else:
dp[1][1]=0
for i in range(1,h+1):
for j in range(1,w+1):
if i==1 and j==1:
continue
if l[i][j]=='#':
if l[i-1][j]=='.':
dp[i][j]=min(dp[i][j],dp[i-1][j]+1)
else:
dp[i][j]=min(dp[i][j],dp[i-1][j])
if l[i][j-1]=='.':
dp[i][j]=min(dp[i][j],dp[i][j-1]+1)
else:
dp[i][j]=min(dp[i][j],dp[i][j-1])
else:
dp[i][j]=min(dp[i-1][j],dp[i][j-1])
# print(dp)
return dp[h][w]
# main()
print(main())
| 0 | null | 114,240,519,619,460 | 298 | 194 |
ans = []
while True:
tmp = input().split()
a, b = map(int, [tmp[0], tmp[2]])
op = tmp[1]
if op == "?":
break
if op == "+":
ans.append(a + b)
if op == "-":
ans.append(a - b)
if op == "*":
ans.append(a * b)
if op == "/":
ans.append(a // b)
print("\n".join(map(str, ans)))
| #coding:UTF-8
while True:
a,op,b = map(str,raw_input().split())
a = int(a)
b = int(b)
if op == '+':
print(a+b)
elif op == '-':
print(a-b)
elif op == '*':
print(a*b)
elif op == '/':
print(a/b)
else:
break | 1 | 670,977,733,400 | null | 47 | 47 |
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re
N,R=map(int,input().split())
if N >= 10:
print(R)
else:
print( R + ( 100 * ( 10 - N )))
| # Common Raccoon vs Monster
H, N = map(int,input().split())
A = list(map(int, input().split()))
ans = ['No', 'Yes'][sum(A) >= H]
print(ans) | 0 | null | 70,344,377,297,120 | 211 | 226 |
s = list(input())
print("x"*len(s)) | import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
return sys.stdin.readline()[:-1]
mod=10**9+7
n,d,a=map(int,input().split())
xh=[list(map(int,input().split())) for i in range(n)]
xh.sort()
r,tama=[float('inf')]*n,[0]*(n+1)
for i in range(n):
x,h=xh[i]
tmpr=bisect.bisect_left(r,x)
h-=(tama[i]-tama[tmpr])*a
tmp=0
if h>0:
tmp=math.ceil(h/a)
tama[i+1]=tmp
tama[i+1]+=tama[i]
r[i]=x+2*d
print(tama[-1])
# print(r) | 0 | null | 77,433,046,318,412 | 221 | 230 |
s=input()
count=0
for i in s:
count+=1
print('x'*count) | def q_b():
n = int(input())
st = input().split()
s = st[0]
t = st[1]
word = []
for i in range(n):
word.append(s[i])
word.append(t[i])
print("".join(word))
if __name__ == '__main__':
q_b() | 0 | null | 92,259,836,959,980 | 221 | 255 |
n=int(input())
s=input().split()
q=int(input())
t=input().split()
cnt=0
for i in range(q):
for j in range(n):
if s[j]==t[i]:
cnt+=1
break
print(cnt)
| N,M = map(int,input().split())
L = map(int,input().split())
work = 0
for i in L :
work += i
if N >= work :
print ( N - work )
else :
print ("-1") | 0 | null | 15,916,795,403,900 | 22 | 168 |
n=int(input())
x=0
y=1
if n==0 or n==1:
print(1)
else:
for i in range(n):
x,y=y,x+y
i+=1
print(y)
| N = int(input())
A = list(map(int,input().split()))
B = len([i for i in A if i % 2==0])
count = 0
for i in A:
if i % 2 !=0:
continue
elif i % 3 ==0 or i % 5==0:
count +=1
if count == B:
print('APPROVED')
else:
print('DENIED')
| 0 | null | 34,614,971,263,208 | 7 | 217 |
s = input()
cs = list(s)
for c in cs:
if c.islower():
print(c.upper(),end="")
else :
print(c.lower(),end="")
print()
| import math
def average(l):
return sum(l) / len(l)
def var(l):
a = average(l)
return sum(map(lambda x: (x-a)**2, l)) / len(l)
def std(l):
return math.sqrt(var(l))
if __name__ == '__main__':
while True:
n = int(input())
if n == 0:
break
l = [int(i) for i in input().split()]
print("{0:.5f}".format(std(l))) | 0 | null | 846,838,844,010 | 61 | 31 |
n = int(input())
a = map(int,raw_input().split())
p = int(input())
m = map(int,raw_input().split())
def goukei(i,m):
if m ==0:
return True
if i >= n or m > sum(a):
return False
r = goukei(i + 1, m) or goukei(i + 1, m - a[i])
return r
for u in range(0,p):
if goukei(0, m[u]):
print "yes"
else:
print "no" | def stdinput():
from sys import stdin
return stdin.readline().strip()
def main():
from itertools import combinations
n = int(stdinput())
*A, = map(int, stdinput().split(' '))
q = int(stdinput())
*M, = map(int, stdinput().split(' '))
all_canditee = set([sum(c) for i in range(1, n+1) for c in combinations(A, i)])
# print(A)
# print(all_canditee)
for m in M:
if m in all_canditee:
print('yes')
else:
print('no')
# can not pass 9/10
def check(m, a, A):
for i, next_a in enumerate(A):
this_a = a + next_a
if this_a == m:
return True
elif this_a < m:
if check(m, this_a, A[i+1:]):
return True
return False
if __name__ == '__main__':
main()
# import cProfile
# cProfile.run('main()')
| 1 | 95,904,319,098 | null | 25 | 25 |
n, k = map(int, input().split())
def cul(x):
ans = (1 + x)*x/(2*x)
return ans
p = list(map(cul, list(map(int, input().split()))))
cnt = sum(p[0:k])
ans = cnt
for i in range(k, n):
cnt += p[i] - p[i - k]
ans = max(ans, cnt)
print(ans) | a,b,m = map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
Min = (min(A)+min(B))
for _ in range(m):
x,y,c = map(int,input().split())
if Min > A[x-1]+B[y-1]-c:
Min=A[x-1]+B[y-1]-c
print(Min) | 0 | null | 64,338,334,002,002 | 223 | 200 |
n, k = map(int, input().split())
s = ""
while(True):
if n < k :
s += str(n)
break
else :
s += str(n%k)
n = n//k
print(len(s)) | n=int(input())
A=input().split()
def findProductSum(A,n):
product = 0
for i in range (n):
for j in range ( i+1,n):
product = product + int(A[i])*int(A[j])
return product
print(findProductSum(A,n)) | 0 | null | 116,814,396,740,520 | 212 | 292 |
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
n=int(input())
A=list(map(int, input().split()))
ans = 0
mod = 10**9 + 7
for i in range(60):
q = sum(map(lambda x:((x >> i) & 0b1),A))
ans += q*(n-q)*pow(2, i, mod)
ans = ans % mod
print(ans)
if __name__=='__main__':
main() | def main():
N=int(input())
A=list(map(int,input().split()))
mod=10**9+7
ans=0
for i in range(60):
c=0
for j in A:
if j>>i&1:
c+=1
ans+=pow(2,i,mod)*c*(N-c)
ans%=mod
print(ans)
if __name__=='__main__':
main() | 1 | 122,942,643,216,148 | null | 263 | 263 |
from random import randint, random
from math import exp
import sys
input = sys.stdin.readline
INF = 9223372036854775808
def calc_score(D, C, S, T):
"""
開催日程Tを受け取ってそこまでのスコアを返す
コンテストi 0-indexed
d 0-indexed
"""
score = 0
last = [0]*26 # コンテストiを前回開催した日
for d, t in enumerate(T):
last[t] = d + 1
for i in range(26):
score -= (d + 1 - last[i]) * C[i]
score += S[d][t]
return score
def update_score(D, C, S, T, score, ct, ci):
"""
ct日目のコンテストをコンテストciに変更する
スコアを差分更新する
ct: change t 変更日 0-indexed
ci: change i 変更コンテスト 0-indexed
"""
new_score = score
last = [0]*26 # コンテストiを前回開催した日
prei = T[ct] # 変更前に開催する予定だったコンテストi
for d, t in enumerate(T, start=1):
last[t] = d
new_score += (d - last[prei])*C[prei]
new_score += (d - last[ci])*C[ci]
last = [0]*26
for d, t in enumerate(T, start=1):
if d-1 == ct:
last[ci] = d
else:
last[t] = d
new_score -= (d - last[prei])*C[prei]
new_score -= (d - last[ci])*C[ci]
new_score -= S[ct][prei]
new_score += S[ct][ci]
return new_score
def evaluate(D, C, S, T, k):
"""
d日目終了時点での満足度を計算し,
d + k日目終了時点での満足度の減少も考慮する
"""
score = 0
last = [0]*26
for d, t in enumerate(T):
last[t] = d + 1
for i in range(26):
score -= (d + 1 - last[i]) * C[i]
score += S[d][t]
for d in range(len(T), min(len(T) + k, D)):
for i in range(26):
score -= (d + 1 - last[i]) * C[i]
return score
def greedy(D, C, S):
Ts = []
for k in range(7, 10):
T = [] # 0-indexed
max_score = -INF
for d in range(D):
# d+k日目終了時点で満足度が一番高くなるようなコンテストiを開催する
max_score = -INF
best_i = 0
for i in range(26):
T.append(i)
score = evaluate(D, C, S, T, k)
if max_score < score:
max_score = score
best_i = i
T.pop()
T.append(best_i)
Ts.append((max_score, T))
return max(Ts, key=lambda pair: pair[0])
def local_search(D, C, S, score, T):
T0 = 2e3
T1 = 6e2
Temp = T0
for k in range(500, 95000):
if k % 100:
t = (k/95000) / 1.9
Temp = pow(T0, 1-t) * pow(T1, t)
sel = randint(1, 2)
if sel == 1:
# ct 日目のコンテストをciに変更
ct = randint(0, D-1)
ci = randint(0, 25)
new_score = update_score(D, C, S, T, score, ct, ci)
lim = random()
if score < new_score or \
(new_score > 0 and exp((score - new_score)/Temp) > lim):
T[ct] = ci
score = new_score
else:
# ct1 日目と ct2 日目のコンテストをswap
ct1 = randint(0, D-1)
ct2 = randint(0, D-1)
ci1 = T[ct1]
ci2 = T[ct2]
new_score = update_score(D, C, S, T, score, ct1, ci2)
new_score = update_score(D, C, S, T, new_score, ct2, ci1)
lim = random()
if score < \
(new_score > 0 and exp((score - new_score)/Temp) > lim):
score = new_score
T[ct1] = ci2
T[ct2] = ci1
return T
if __name__ == '__main__':
D = int(input())
C = [int(i) for i in input().split()]
S = [[int(i) for i in input().split()] for j in range(D)]
init_score, T = greedy(D, C, S)
T = local_search(D, C, S, init_score, T)
for t in T:
print(t+1)
| N = int(input())
ans = 0
for i in range(1, N+1):
if i % 3 == 0:
continue
if i % 5 == 0:
continue
ans += i
print(ans)
| 0 | null | 22,186,030,614,972 | 113 | 173 |
from collections import deque
from sys import stdin
input = stdin.readline
def main():
N = int(input())
G = [[] for _ in range(N)]
dic = {}
for i in range(N-1):
a, b = map(lambda x: int(x)-1, input().split())
G[a].append(b)
G[b].append(a)
dic[(a, b)] = i
dic[(b, a)] = i
color = [0]*(N-1)
upcol = [0]*(N)
upcol[0] = None
visited = set()
q = deque([0])
max_col = 0
while len(q):
now = q.popleft()
visited.add(now)
c = 0
for next_ in G[now]:
if next_ in visited:
continue
c += 1
if upcol[now] == c:
c += 1
color[dic[(now, next_)]] = c
upcol[next_] = c
q.append(next_)
max_col = max(max_col, c)
print(max_col)
print(*color, sep='\n')
if(__name__ == '__main__'):
main()
| n,k = map(int,input().split())
p = [int(i)-1 for i in input().split()]
c = [int(i) for i in input().split()]
ans = -10**100
for i in range(n):
chk = [0]*n
chk[p[i]] = 1
now = p[i]
cnt = 1
val = [-10**100]*n
val[0] = c[p[i]]
while 1 == 1:
if cnt >= k:
break
#print(p[now])
if chk[p[now]] == 1:
break
else:
chk[p[now]] = 1
val[cnt] = val[cnt-1]+c[p[now]]
now = p[now]
cnt += 1
cnt -= 1
#print(val)
if val[cnt] <= 0:
ans = max(ans,max(val))
else:
num = k // (cnt+1)
amari = k % (cnt+1)
#print(cnt,k)
for j in range(cnt+1):
if j < amari:
tmp = num*val[cnt]
else:
tmp = (num-1)*val[cnt]
ans = max(ans,tmp+val[j])
#print(ans,tmp,val[j],j,cnt,num)
#ans = max(ans,max(val))
print(ans) | 0 | null | 70,587,314,816,812 | 272 | 93 |
n = int(input())
taro = 0
hana = 0
for c in range(0,n):
word = input().split(' ')
taro_w, hana_w = word[0], word[1]
word.sort()
if word[0] == word[1]:
taro += 1
hana += 1
elif taro_w == word[0]:
hana += 3
else:
taro += 3
print("%d %d" % (taro, hana)) | # -*-coding:utf-8
def main():
inputLine = int(input())
taro = hanako = 0
for i in range(inputLine):
tokens = list(input().split())
if(tokens[0] > tokens[1]):
taro += 3
elif(tokens[0] < tokens[1]):
hanako += 3
else:
taro += 1
hanako += 1
print('%d %d' % (taro, hanako))
if __name__ == '__main__':
main() | 1 | 2,009,151,974,140 | null | 67 | 67 |
import sys
n, k = map(int, input().split())
P = int(1e9+7)
def cmb(n, r, P):
r = min(r, n - r)
inv_y = 1
for i in range(1, r + 1):
inv_y = (inv_y * i) % P
inv_y = pow(inv_y, P - 2, P)
x = 1
for i in range(n - r + 1, n + 1):
x = x * i % P
return (x * inv_y) % P
if k >= n:
print(cmb(2*n-1, n, P))
sys.exit()
if k == 1:
print((n * n - 1) % P)
sys.exit()
ans = 1
comb1 = 1
comb2 = 1
for i in range(1, k + 1):
iinv = pow(i, P-2, P)
comb1 = ((comb1 * (n - i)) * (iinv)) % P
comb2 = ((comb2 * (n - i + 1)) * (iinv)) % P
ans = (ans + comb1*comb2) % P
print(ans)
| string = input()
lt = True
ans = 0
l_cnt = 0
m_cnt = 0
if string[0] == ">":
lt = False
for s in string:
if s == "<":
if not lt:
a, b = max(l_cnt, m_cnt), min(l_cnt, m_cnt)
ans += a * (a + 1) // 2 + b * (b - 1) // 2
l_cnt = m_cnt = 0
l_cnt += 1
lt = True
else:
m_cnt += 1
lt = False
a, b = max(l_cnt, m_cnt), min(l_cnt, m_cnt)
ans += a * (a + 1) // 2 + b * (b - 1) // 2
print(ans) | 0 | null | 112,156,077,182,008 | 215 | 285 |
s = input()
if s == 'RRR':
print(3)
elif s[:2] == 'RR' or s[1:] == 'RR':
print(2)
elif s.count('R') >= 1:
print(1)
else:
print(0) | S = input()
sum = 0
for i in range(3):
if S[i]=="R":
sum += 1
if sum == 2 and S[1] == "S":
sum = 1
print(sum)
| 1 | 4,808,978,679,890 | null | 90 | 90 |
#coding: utf-8
n = raw_input()
a = []
for i in range(int(n)):
l = map(int,raw_input().split())
a.append(l)
for l in a:
l = [x * x for x in l]
l.sort()
if l[0] + l[1] == l[2]:
print 'YES'
else:
print 'NO' | a,b = input().split(' ')
if int(a) > int(b):
print('a > b')
elif int(a) < int(b):
print('a < b')
else:
print('a == b') | 0 | null | 180,089,234,500 | 4 | 38 |
def out(data) -> str:
print(' '.join(map(str, data)))
N = int(input())
data = [int(i) for i in input().split()]
out(data)
for i in range(1, N):
tmp = data[i]
j = i - 1
while j >= 0 and data[j] > tmp:
data[j + 1] = data[j]
j -= 1
data[j + 1] = tmp
out(data)
| dic = {}
l = []
n = int(input())
for i in range(n):
s = input()
#sが新規キーか否かで操作を変える
if s in dic:
dic[s] += 1
#新規ではないならvalueを1増やす
else:
dic[s] = 1
m = max(dic.values())
for i in dic:
if dic[i] == m:
l += [i]
print(*sorted(l)) | 0 | null | 35,087,364,350,500 | 10 | 218 |
import sys
from collections import deque
def main():
N,K,C=map(int,input().split())
S=input()
Left=deque([])
Right=deque([])
counter=0
while counter<N and len(Left)<K:
if S[counter]=="o":
if len(Left)<K:
Left.append(counter)
counter+=C
counter+=1
counter=N-1
while counter>=0 and len(Right)<K:
if S[counter]=="o":
if len(Right)<K:
Right.appendleft(counter)
counter-=C
counter-=1
if len(Right)!=K or len(Left)!=K:
sys.exit()
for i in range(K):
l=Left.popleft()
r=Right.popleft()
if l==r:
print(l+1)
if __name__=="__main__":
main() | n,k,c=map(int,input().split())
s=input()
l=[]
r=[]
i=0
j=0
while len(l)<k and i<n:
if s[i]=='o':
l.append(i+1)
i+=c+1
else: i+=1
while len(r)<k and j<n:
if s[-j-1]=='o':
r.append(n-j)
j+=c+1
else: j+=1
for n in range(k):
if l[n]==r[-n-1]:
print(l[n]) | 1 | 40,825,099,634,968 | null | 182 | 182 |
import sys
import numpy as np
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
#======================================================#
def main():
h, w, m = MII()
bombs = [MIIZ() for _ in range(m)]
a = [0]*h
b = [0]*w
for y,x in bombs:
a[y] += 1
b[x] += 1
maxa = max(a)
maxb = max(b)
sumv = maxa + maxb
c = a.count(maxa)*b.count(maxb) - sum(a[y]+b[x] == sumv for y,x in bombs)
print(sumv - (c<=0))
if __name__ == '__main__':
main() | def cal(XL):
N = len(XL)
XL.sort(key = lambda x:x[0])
for i in range(N):
XL[i] = [XL[i][0],XL[i][0]-XL[i][1],XL[i][0]+XL[i][1]]
OP = [XL[0]]
for i in range(1,N):
if OP[len(OP)-1][2] > XL[i][1]:
if OP[len(OP)-1][2] < XL[i][2]:
#右方向により腕が伸びている方がより邪魔
pass
else:
OP.pop()
OP.append(XL[i])
else:
OP.append(XL[i])
return len(OP)
def main():
N = int(input())
XL = [list(map(int,input().split())) for _ in range(N)]
ans = cal(XL)
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 47,447,932,583,520 | 89 | 237 |
from collections import deque
def main():
s = list(input())
q = int(input())
query = []
que = deque(s)
f = False
for i in range(q):
query.append(input().split(" "))
for i in range(q):
if query[i][0] == '1':
f = not f
else:
if f:
if query[i][1] == '2':
que.appendleft(query[i][2])
else:
que.append(query[i][2])
else:
if query[i][1] == '1':
que.appendleft(query[i][2])
else:
que.append(query[i][2])
if f:
que.reverse()
print("".join(que))
if __name__ == "__main__":
main() | from collections import deque
def main():
S = deque(map(str, input()))
Q = int(input())
flag = False
for _ in range(Q):
A = tuple(map(str, input().split()))
if A[0] == "1":
flag = not(flag)
else:
if (A[1] == "1" and not(flag)) or (A[1] == "2" and flag):
S.appendleft(A[2])
else:
S.append(A[2])
if flag:
print("".join(S)[::-1])
else:
print("".join(S))
if __name__ == "__main__":
main() | 1 | 57,412,399,064,860 | null | 204 | 204 |
import collections
N = int(input())
def make_divisors(n):
lower_divisors , upper_divisors = [], []
i = 1
while i*i <= n:
if n % i == 0:
lower_divisors.append(i)
if i != n // i:
upper_divisors.append(n//i)
i += 1
return lower_divisors + upper_divisors[::-1]
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
use_list = []
cnt = 0
while True:
flag = 0
div_list = make_divisors(N)
if len(div_list) == 1:
break
for i in range(1,len(div_list)):
if (len(collections.Counter(prime_factorize(div_list[i]))) == 1) and (div_list[i] not in use_list):
use_list.append(div_list[i])
N = N //div_list[i]
cnt +=1
flag = 1
break
if flag == 0:
break
print(cnt) | import math
while True:
ins = input().split()
x = int(ins[0])
op = ins[1]
y = int(ins[2])
if op == "+":
print(x + y)
elif op == "-":
print(x - y)
elif op == "/":
print(math.floor(x / y))
elif op == "*":
print(x * y)
elif op == "?":
break
else:
break | 0 | null | 8,865,657,508,938 | 136 | 47 |
n = input()
x = input().split()
x_int = [int(i) for i in x]
print('{} {} {}'.format(min(x_int),max(x_int),sum(x_int))) | input()
x=map(int,raw_input().split())
print min(x),max(x),sum(x) | 1 | 722,042,169,168 | null | 48 | 48 |
l = int(input())
ans = (l / 3) ** 3
print(ans)
| import math
l = float(input())/3
print(math.pow(l, 3))
| 1 | 47,077,558,611,342 | null | 191 | 191 |
import sys
while(True):
x, y = map(lambda x: (int, int)[x.isdigit()](x) ,sys.stdin.readline().split(None, 1))
if x == 0 and y == 0:
break
if x < y:
print("%d %d" % (x, y))
else:
print("%d %d" % (y, x)) | b = []
c = []
while True:
inp = input()
a = inp.split()
a[0] = int(a[0])
a[1] = int(a[1])
if a[0] == 0 and a[1] == 0:
break
else:
a.sort()
b.append(a[0])
c.append(a[1])
for i in range(len(b)):
print(b[i],c[i])
| 1 | 517,803,076,308 | null | 43 | 43 |
import sys
# sys.setrecursionlimit(100000)
def input():
return sys.stdin.readline().strip()
def input_int():
return int(input())
def input_int_list():
return [int(i) for i in input().split()]
def main():
n = input_int()
arms = []
# 区間スケジューリング
for _ in range(n):
x, l = input_int_list()
arms.append((x - l, x + l))
arms = sorted(arms, key=lambda x: x[1])
prev_r = -float("inf")
cnt = 0
for left, right in arms:
if prev_r > left:
continue
cnt += 1
prev_r = right
print(cnt)
return
if __name__ == "__main__":
main()
| import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
B=np.sum(A)-np.cumsum(np.append(0, A[:len(A)-1]))
v=0
k=0
for i in range(N+1):
if i==0:
if N==0 and A[0]==1:
k=1
elif A[0]==0:
k=1
else:
print(-1)
break
elif i==N:
if B[i]<=2*(k-A[i-1]):
k=B[i]
else:
k=0
print(-1)
break
else:
k=min(2*(k-A[i-1]),B[i])
if k<=0:
print(-1)
break
v+=k
if k>0:
print(v) | 0 | null | 54,071,662,417,948 | 237 | 141 |
s=list(input())
l=len(s)
ans=0
if len(set(s))==1:
for i in range(1,l+1):
ans+=i
print(ans)
exit()
for i in range(l-1):
if s[i]=="<" and s[i+1]==">":
left=1
right=1
for j in range(i):
if s[i-j-1]=="<":
left+=1
else:
break
for j in range(l-i-2):
if s[i+j+2]==">":
right+=1
else:
break
p=max(left,right)
q=min(left,right)
for j in range(p):
ans+=(j+1)
for j in range(q-1):
ans+=(j+1)
if s[0]==">":
ans+=1
for i in range(1,l):
if s[i]==">":
ans+=(i+1)
else:
break
if s[-1]=="<":
ans+=1
for i in range(2,l+1):
if s[-i]=="<":
ans+=i
else:
break
print(ans) | # -*- coding: utf-8 -*-
# input
a, b = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
o = 0
for i in range(b):
o = o+x[i]
print(o)
| 0 | null | 83,868,729,136,864 | 285 | 120 |
import math
N,K = map(int,input().split())
A = list(map(int,input().split()))
m = 1
M = max(A)
while(M-m>0):
mm = 0
mid = (M+m)//2
for i in range(N):
mm += math.ceil(A[i]/mid)-1
if mm>K:
m = mid+1
else:
M = mid
print(math.ceil(m))
| n,k = map(int, input().split())
alist=list(map(int, input().split()))
def is_ok(arg):
cnt=0
for i in alist:
cnt+=(i-1)//arg
return cnt<=k
def nibun(ng, ok):
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
return ok
print(nibun(0 , 10**9 + 1)) | 1 | 6,463,896,080,260 | null | 99 | 99 |
# PDF参考
# スタックS1
S1 = []
# スタックS2
S2 = []
tmp_total = 0
counter = 0
upper = 0
# 総面積
total_layer = 0
for i,symbol in enumerate(input()):
if (symbol == '\\'):
S1.append(i)
elif (symbol == '/') and S1:
i_p = S1.pop()
total_layer = i - i_p
if S2 :
while S2 and S2[-1][0] > i_p:
cal = S2.pop()
total_layer += cal[1]
S2.append((i, total_layer))
print(sum([j[1] for j in S2]))
if (len(S2) != 0):
print(str(len(S2)) + ' ' + ' '.join([str(i[1]) for i in S2]))
else:
print(str(len(S2)))
| ch = input()
stk1 = []
stk2 = []
ttlar = 0
for i, c in enumerate(ch):
if c == '\\':
stk1.append(i)
elif c == '/' and stk1 != []:
j = stk1.pop()
ttlar += i - j
lar = i - j
while stk2 != [] and stk2[-1][0] > j:
lar += stk2.pop()[1]
stk2.append([j, lar])
print(ttlar)
ans = [len(stk2)]
ans[1:1] = [stk2[i][1] for i in range(len(stk2))]
print(' '.join(map(str, ans)))
| 1 | 58,247,436,030 | null | 21 | 21 |
D = int(input())
# with open("sample1.in") as f:
last = [0 for i in range(26)]
s = [[0 for j in range(26)] for i in range(D)]
c = list(map(int, input().split(" ")))
result = []
total = 0
# opened = [] #開催したやつを保存
for i in range(D):
a = list(map(int, input().split(" ")))
for j, k in enumerate(a):
#print(i, j, k)
s[i][j] = int(k)
# スコア計算
score_max = 0
score_index = 0
for j in range(26):
if j == 0:
score_max = s[i][j] # - (i - last[j]) * c[j]
for k in range(26):
if j != k:
score_max -= (i + 1 - last[k]) * c[k]
score_index = 0
else:
score = s[i][j]
for k in range(26):
if j != k:
score -= (i + 1 - last[k]) * c[k]
if score_max < score:
score_max = score
score_index = j
#print(i, j, score)
result.append(score_index)
#print(score_index, score)
last[score_index] = i + 1
total += score
# print(a.index(max(a)))
# print(total)
for i in range(D):
# print(s.index(max(s[i])))
print(result[i]+1)
| import itertools
N = int(input())
l = list(itertools.permutations(range(1,N+1)))
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
print(abs(l.index(A) - l.index(B))) | 0 | null | 55,283,436,794,692 | 113 | 246 |
n = int(input())
#a, b, h, m = map(int, input().split())
#al = list(map(int, input().split()))
#al=[list(input()) for i in range(h)]
l = 1
total = 26
while n > total:
l += 1
total += 26**l
last = total-26**l
v = n-last-1
ans = ''
# 26進数だと見立てて計算
for i in range(l):
c = v % 26
ans += chr(ord('a')+c)
v = v//26
print("".join(ans[::-1]))
| n=int(input())-1
radix=26
ord_a=97
ans=""
while n>=0:
n,m=divmod(n,radix)
ans=chr(m+ord_a)+ans
n-=1
print(ans) | 1 | 11,822,189,309,028 | null | 121 | 121 |
#E_Picking Goods
R,C,K = map(int,input().split())
A = [[0 for j in range(C)] for i in range(R)]
varr = [[[0 for j in range(C)] for i in range(R)] for k in range(4)]
for inputk in range(K):
r,c,v = map(int,input().split())
A[r-1][c-1] = v
for i in range(R):
for j in range(C):
for k in range(2,-1,-1):
if varr[k][i][j] >= 0:
if varr[k+1][i][j] < varr[k][i][j] + A[i][j]:
varr[k+1][i][j] = varr[k][i][j] + A[i][j]
for kk in range(0,4):
if varr[kk][i][j] >= 0:
if i +1 < R :
if varr[0][i + 1][j] < varr[kk][i][j]:
varr[0][i + 1][j] = varr[kk][i][j]
if j +1 < C :
if varr[kk][i][j + 1] < varr[kk][i][j]:
varr[kk][i][j + 1] = varr[kk][i][j]
ans = 0
for k in range (4):
if ans < varr[k][R-1][C-1]:
ans = varr[k][R-1][C-1]
print(ans)
| import sys
input = sys.stdin.buffer.readline
R, C, K = map(int, input().split())
G = [[None for j in range(C)] for i in range(R)]
for _ in range(K):
r, c, v = map(int, input().split())
G[r - 1][c - 1] = v
dp = [[0, 0, 0, 0] for _ in range(C)]
for i in range(R):
for j in range(C):
if G[i][j] is not None:
dp[j][0], dp[j][1] = max(dp[j]), max(dp[j]) + G[i][j]
dp[j][2], dp[j][3] = 0, 0
else:
dp[j][0] = max(dp[j])
dp[j][1], dp[j][2], dp[j][3] = 0, 0, 0
for j in range(1, C):
if G[i][j] is not None:
dp[j][0] = max(dp[j - 1][0], dp[j][0])
dp[j][1] = max(dp[j - 1][1], dp[j - 1][0] + G[i][j], dp[j][1])
if dp[j - 1][1] != 0:
dp[j][2] = max(dp[j - 1][2], dp[j - 1][1] + G[i][j], dp[j][2])
if dp[j - 1][2] != 0:
dp[j][3] = max(dp[j - 1][3], dp[j - 1][2] + G[i][j], dp[j][3])
else:
dp[j][0] = max(dp[j - 1][0], dp[j][0])
dp[j][1] = max(dp[j - 1][1], dp[j][1])
dp[j][2] = max(dp[j - 1][2], dp[j][2])
dp[j][3] = max(dp[j - 1][3], dp[j][3])
print(max(dp[-1])) | 1 | 5,575,114,569,920 | null | 94 | 94 |
import math
n = int(input())
a = pow(10, n, 10**9+7)
b = pow(9, n, 10**9+7)
c = pow(9, n, 10**9+7)
d = pow(8, n, 10**9+7)
print((a-b-c+d) % (10**9+7)) | from collections import deque
n = int(input())
dq = deque()
for _ in range(n):
query = input()
if query == "deleteFirst":
dq.popleft()
elif query == "deleteLast":
dq.pop()
else:
op, arg = query.split()
if op == "insert":
dq.appendleft(arg)
else:
tmp = deque()
while dq:
item = dq.popleft()
if item == arg:
break
else:
tmp.append(item)
while tmp:
dq.appendleft(tmp.pop())
print(*dq)
| 0 | null | 1,597,154,963,450 | 78 | 20 |
import re
S=input()
pattern = '^(hi)+$'
result = re.match(pattern, S)
if result:
print('Yes')
else:
print('No') | import sys
S = list(input())
if (len(S) % 2 == 1):
print("No")
sys.exit()
pre = S.pop(0)
for s in S:
if(pre == "h"):
if(s != "i"):
print("No")
sys.exit()
elif(pre != "i"):
print("No")
sys.exit()
pre = s
print("Yes")
| 1 | 53,057,940,706,698 | null | 199 | 199 |
while 1:
N = int(input())
if not N:
break
*A, = map(int, input().split())
V = sum(A)/N
print((sum((a - V)**2 for a in A)/N)**0.5)
| import sys
import bisect
N = int(input())
L = list(map(int, input().split()))
LS = sorted(L)
ans = 0
for i in range(N):
for j in range(N):
if i < j:
index = bisect.bisect_left(LS,LS[i]+LS[j])
ans += index-j-1
print(ans) | 0 | null | 85,873,422,518,400 | 31 | 294 |
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
mod = 10 ** 9 +7
N, K = map(int, readline().split())
# s = [0] * (N+1)
# g = [0] * (N+1)
# g[0] = N % mod
# for i in range(1,N+1):
# s[i] += (s[i-1] + i ) % mod
# g[i] += (g[i-1] + N - i) % mod
# ans = (sum(g[K-1:]) % mod - sum(s[K-1:]) % mod + N-K+2) % mod
# print(ans)
k = np.arange(K,N+2,dtype = np.int64)
low = k*(k-1)//2
high = k*(2*N - k + 1) //2
cnt = high-low+1
print(sum(cnt)%mod) | N, K = list(map(int, input().split()))
ans = 0
all_sum = N*(N+1)/2
mod = 10**9+7
for i in range(K,N+2):
min_val = i*(i-1)/2
max_val = N*(N+1)/2 - (N-i+1)*(N-i)/2
ans += (int(max_val) - int(min_val) + 1) % mod
# print(i, min_val, max_val)
print(ans%mod)
| 1 | 33,178,358,652,160 | null | 170 | 170 |
from collections import Counter
#input
N,K = list(map(int,input().split()))
R,S,P = list(map(int,input().split()))
T = list(input())
T_ =T.copy()
# N=2*10**5
# T=[random.choice(['s', 'r', 'p']) for _ in range(N)]
check=set(['s', 'r', 'p'])
#得点
point={'r':P,'s':R,'p':S}
point
T_point = [0]*N
for n in range(N):
T_point[n]=point[T[n]]
for k in range(K,N):
check_out = set()
if T[k] == T[k-K]: # K回前の手と同じ場合
check_out.add(T[k])
if k+K < N:
check_out.add(T[k+K])
check_out=check-check_out
T[k]=list(check_out)[0]
ans=0
for t in range(len(T)):
if T[t] == T_[t]:
ans += point[T[t]]
print(ans)
| N,K=map(int,input().split())
R,S,P=map(int,input().split())
L=input()
T=[]
for i in range(N):
T.append(L[i])
for i in range(K,N):
if T[i]==T[i-K]:
T[i]="0"
p=0
for i in T:
if i=="r":
p+=P
elif i=="s":
p+=R
elif i=="p":
p+=S
print(p) | 1 | 106,735,814,442,880 | null | 251 | 251 |
import math
a, b, C = map(int, input().split())
C = math.radians(C)
S, h = (1/2)*a*b*math.sin(C), b*math.sin(C)
L = a+b+math.sqrt((a**2)+(b**2)-(2*a*b*math.cos(C)))
print("{0:.8f}".format(S))
print("{0:.8f}".format(L))
print("{0:.8f}".format(h)) | from math import sin, cos, radians
a, b, ang = map(int, input().split())
ang = radians(ang)
area = a * b * sin(ang) / 2
c = (a ** 2 + b ** 2 - 2 * a * b * cos(ang)) ** 0.5
circ = a + b + c
height = area * 2 / a
print("%lf\n%lf\n%lf" % (area, circ, height))
| 1 | 170,638,573,348 | null | 30 | 30 |
h = int(input())
w = int(input())
n = int(input())
if n % max(h, w) == 0:
print(int(n//max(h, w)))
else:
print(int(n//max(h, w))+1)
| H = int(input())
W = int(input())
N = int(input())
print(-(-N//max(H,W))) | 1 | 88,686,690,954,910 | null | 236 | 236 |
import sys
sys.setrecursionlimit(10 ** 9)
class UnionFind():
def __init__(self, n):
self.n = n
self.root = [-1]*(n+1)
self.rank = [0]*(n+1)
def find(self, x):#親となる要素を探索
if self.root[x] < 0:
return x
else:
self.root[x] = self.find(self.root[x])#再帰
return self.root[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
elif self.rank[x] > self.rank[y]:#深い木に連結
self.root[x] += self.root[y]
self.root[y] = x#yの親をxとする
else:
self.root[y] += self.root[x]
self.root[x] = y
if self.rank[x] == self.rank[y]:
self.rank[y] += 1
def issame(self, x, y):#x, yが同じ集合か判定
return self.find(x) == self.find(y)
def count(self, x):#要素の個数
return (-1)*self.root[self.find(x)]
n, m = map(int, input().split())
uf = UnionFind(n)
for i in range(m):
a, b = map(int, input().split())
uf.unite(a-1, b-1)
ans = set()
for i in range(n):
ans.add(uf.find(i))
print(len(ans)-1) | n=int(input())
p=10**9+7
total=(10**n)%p
except_0=(9**n)%p
except_9=except_0
except_both=(8**n)%p
# double reduced from [1,8]
# so add that
print((total-except_0-except_9+except_both)%p) | 0 | null | 2,718,348,587,078 | 70 | 78 |
H, W = map(int, input().split())
if H > 1 and W > 1:
if H*W % 2 == 0:
s = (H * W) // 2
elif H*W % 2 != 0:
s = (H * W + 1) // 2
elif H == 1 or W == 1:
s = 1
print(s) | S = input()
arr = [0]*(len(S) + 1)
cn = 0
for i in range(len(S)):
if S[i] == "<":
cn += 1
else:
cn = 0
arr[i+1] = cn
cn = 0
for i in range(len(S)-1, -1, -1):
if S[i] == ">":
cn += 1
else:
cn = 0
arr[i] = max(arr[i], cn)
# print(arr)
print(sum(arr)) | 0 | null | 103,817,322,639,508 | 196 | 285 |
N,R = map(int,input().split())
if N <= 9:
R += 100*(10-N)
print(R) | import itertools
n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
r = list(itertools.permutations([i for i in range(1,n+1)]))
P , Q = (r.index(p)), (r.index(q))
print(abs(P-Q)) | 0 | null | 82,229,075,866,560 | 211 | 246 |
a,b,c=[int(a) for a in input().split()]
if b*c>=a:
print ("Yes")
else:
print("No") |
def main():
d,t,s = map(int, input().split())
if s*t >= d:
print("Yes")
else:
print("No")
if __name__ == '__main__':
main()
| 1 | 3,595,651,941,590 | null | 81 | 81 |
n, k = map(int, input().split())
l = [0] * n
for i in range(k):
d = int(input())
x = list(map(int, input().split()))
for j in range(d):
l[x[j]-1] += 1
print(l.count(0)) | #import time
def main():
N, K = map(int, input().split())
matrix = [list(map(int, input().split())) for i in range(2*K)]
sunuke = [0]*(N+1)
for i in range(K):
for j in matrix[2*i+1]:
sunuke[j] += 1
ans = sunuke.count(0) -1
return ans
if __name__ == '__main__':
#start = time.time()
print(main())
#elapsed_time = time.time() - start
#print("経過時間:{}".format(elapsed_time * 1000) + "[msec]") | 1 | 24,771,447,193,180 | null | 154 | 154 |
n = int(input())
c0, c1, c2, c3 = 0, 0, 0, 0
for i in range(n):
s = input()
if s == 'AC':
c0 += 1
elif s == 'WA':
c1 += 1
elif s == 'TLE':
c2 += 1
else:
c3 += 1
print('AC x',c0)
print('WA x',c1)
print('TLE x',c2)
print('RE x',c3)
| moji=""
while True:
try:
t = input()
moji += t.lower()
except :
break
moji2 = [chr(i) for i in range(97,97+26)]
for j in moji2:
print(j+" : "+str(moji.count(j)))
| 0 | null | 5,142,501,388,320 | 109 | 63 |
S = int(input())
dp = [0] * (S + 1)
dp[0] = 1
M = 10 ** 9 + 7
for i in range(1, S + 1):
num = 0
for j in range(i - 2):
num += dp[j]
dp[i] = num % M
print(dp[S])
|
import sys
from math import gcd
from functools import reduce
def enum_div(n):
ir=int(n**(0.5))+1
ret=[]
for i in range(1,ir):
if n%i == 0:
ret.append(i)
if (i!= 1) & (i*i != n):
ret.append(n//i)
return ret
n=int(input())
ap=list(map(int,input().split()))
amin=min(ap)
amax=max(ap)
if amax==1:
print("pairwise coprime")
sys.exit()
if reduce(gcd,ap)!=1:
print("not coprime")
sys.exit()
if n>=78500 :
print("setwise coprime")
sys.exit()
aa=[0]*(amax+1)
for ai in ap:
aa[ai]+=1
for pp in range(2,amax+1):
psum=sum(aa[pp: :pp])
# print("pp:",pp,psum)
if psum>=2:
print("setwise coprime")
sys.exit()
## max_13.txt ... max_16.txt : "setwise coprime"
print("pairwise coprime")
| 0 | null | 3,640,828,720,256 | 79 | 85 |
n,x,m = map(int,input().split())
mod = m
num = []
ans = 0
cnt = 0
ch = x
#ループの始まりを特定
while True:
if ch not in num:
num.append(ch)
else:
st = ch #ループの開始している配列の初めの数字
break
ch *= ch
ch %= mod
#ループの始まりの配列の添え字を特定
for i in range(len(num)):
if num[i] == st:
stnum = i #ループ開始の最初の配列のの番号
break
else:
stnum = len(num) - 1
if 0 in num:
ans = sum(num[:n])
else:
if (len(num)-stnum) != 0:
rest = (n-stnum)%(len(num)-stnum) #余り
qu = (n-stnum)//(len(num)-stnum) #商
else:
rest = n
qu = 0
if n <= stnum + 1:
ans = sum(num[:n])
else:
ans = sum(num[:stnum]) + sum(num[stnum:stnum+rest]) + sum(num[stnum:])*qu
print(ans) | n,x,m=map(int,input().split())
l=[0]*m
s=[0]*m
t=p=0
while l[x]<1:
t+=1
l[x]=t
s[x]=s[p]+x
p=x
x=pow(p,2,m)
T=t+1-l[x]
S=s[p]+x-s[x]
d,m=divmod(n-l[x],T)
print(S*d+s[l.index(l[x]+m)]) | 1 | 2,816,838,670,426 | null | 75 | 75 |
#coding:utf-8
import math
r=float(input())
print("%.6f"%(math.pi*r**2)+" %.6f"%(2*math.pi*r)) | import math
a, b, x = map(int, input().split(' '))
x = x / a
if x > a * b / 2:
print(math.atan2((a * b - x) * 2, a ** 2) * 180 / math.pi)
else:
print(math.atan2(b ** 2, x * 2) * 180 / math.pi)
| 0 | null | 81,829,000,318,660 | 46 | 289 |
n = input()
p = [0] * 2
for i in range(n):
t, h = raw_input().split()
if(t > h):
p[0] += 3
elif(t < h):
p[1] += 3
else:
p[0] += 1
p[1] += 1
print("%d %d" %(p[0], p[1])) | # coding: utf-8
import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
H, W, K = lr()
S = np.array([list(map(int, sr())) for _ in range(H)])
Scum = np.cumsum(S, axis=1)
INF = 10 ** 10
answer = INF
for pattern in range(1<<H-1):
cnt = 0
Tcum = Scum.copy()
for i in range(H-1):
if pattern>>i & 1: # 切れ目
cnt += 1
else:
Tcum[i+1] += Tcum[i]
prev = -1
w = 0
Tcum = Tcum.tolist()
while w < W:
cut = False
for i in range(H):
if Tcum[i][w] - (Tcum[i][prev] if prev >= 0 else 0) > K:
cut = True
break
if cut:
if prev == w - 1: # 1列でKをオーバー
break
cnt += 1
prev = w - 1
else:
w += 1
else:
answer = min(answer, cnt)
print(answer)
| 0 | null | 25,247,865,728,910 | 67 | 193 |
a=input()
print(str.swapcase(a))
| s = input()
n = len(s)
if n % 2 == 1:
print("No")
exit(0)
for i in range(n):
if i % 2 == 0:
if s[i] != "h":
print("No")
break
elif s[i] != "i":
print("No")
break
else:
print("Yes")
| 0 | null | 27,210,506,228,990 | 61 | 199 |
import sys
import itertools
def resolve(in_):
N, M = map(int, in_.readline().split())
sc = tuple(tuple(map(int, line.split())) for line in itertools.islice(in_, M))
if N == 1:
values = range(10)
else:
values = range(10 ** (N - 1), 10 ** N)
for value in values:
if all(value // (10 ** (N - s)) % 10 == c for s, c in sc):
return value
return -1
def main():
answer = resolve(sys.stdin.buffer)
print(answer)
if __name__ == '__main__':
main()
| import math
a, b, C=map(int,input().split())
S=a*b*math.sin(math.pi*C/180)/2
c=math.sqrt(a**2+b**2-2*a*b*math.cos(math.pi*C/180))
L=a+b+c
h=2*S/a
print('{:.4f}'.format(S))
print('{:.4f}'.format(L))
print('{:.4f}'.format(h))
| 0 | null | 30,662,076,767,610 | 208 | 30 |
X, N = map(int, input().split())
ps = list(map(int, input().split()))
for i in range(100):
if X - i not in ps:
print(X-i)
exit()
elif X + i not in ps:
print(X+i)
exit()
| x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = 9999999999
lists = []
if n == 0:
print(x)
exit()
for i in range(-1000, 1000):
if not i in p:
lists.append(i)
for i in lists:
if ans > abs(x - i):
ans = abs(x-i)
m = i
print(m) | 1 | 14,025,871,134,850 | null | 128 | 128 |
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools
import queue
from collections import deque
from fractions import Fraction
# 10進数表記でnのk進数を求めてlength分0埋め
def ternary (n, k, length):
if n == 0:
nums = ['0' for i in range(length)]
nums = ''.join(nums)
return nums
nums = ''
while n:
n, r = divmod(n, k)
nums += str(r)
nums = nums[::-1]
nums = nums.zfill(length)
return nums
def main():
num = int(input())
data = list(map(int, input().split()))
mod = 10 ** 9 + 7
max_length = len(bin(max(data))) - 2
bit_count = [0 for i in range(max_length)]
for i in range(num):
now_bin = bin(data[i])[2:]
now_bin = now_bin.zfill(max_length)
for j in range(max_length):
if now_bin[j] == "1":
bit_count[j] += 1
flg_data = [0 for i in range(max_length)]
for i in range(max_length):
flg_data[i] += bit_count[i] * (num - bit_count[i])
ans = 0
for j in range(max_length):
pow_num = max_length - 1 - j
bbb = pow(2, pow_num, mod)
ans += bbb * flg_data[j]
ans %= mod
print(ans)
if __name__ == '__main__':
main()
| import queue
import numpy as np
import math
n = int(input())
A = list(map(int, input().split()))
A = np.array(A,np.int64)
ans = 0
for i in range(60 + 1):
a = (A >> i) & 1
count1 = np.count_nonzero(a)
count0 = len(A) - count1
ans += count1*count0 * pow(2, i)
ans%=1000000007
print(ans) | 1 | 122,801,700,063,004 | null | 263 | 263 |
n,m=map(int,input().split())
c=list(map(int,input().split()))
dp=[[10001]*m for i in range(n)] #dp[value][i_coin]
dp.insert(0,[0]*m)
for i in range(m):
for v in range(1,n+1):
if i==0:
dp[v][i]=v//c[i] if v%c[i]==0 else 10001
continue
if v<c[i]:
dp[v][i]=dp[v][i-1]
else:
dp[v][i]=min(dp[v][i-1],dp[v-c[i]][i]+1)
print(dp[n][m-1])
| n, m = map(int, input().split())
c = list(map(int, input().split()))
dp = [float("inf")] * (n+1)
dp[0] = 0
for i in range(1, n + 1):
for j in range(m):
if i >= c[j]:
dp[i] = min(dp[i], dp[i-c[j]]+1)
print(dp[n])
| 1 | 148,652,855,652 | null | 28 | 28 |
a,b,*cc = map(int, open(0).read().split())
if sum(cc) >= a:
print('Yes')
else:
print('No') | H, N = map(int, input().split())
special_move = input().split()
def answer(H: int, N: int, special_move: list) -> str:
damage = 0
for i in range(0, N):
damage += int(special_move[i])
if damage >= H:
return 'Yes'
else:
return 'No'
print(answer(H, N, special_move)) | 1 | 77,992,722,560,534 | null | 226 | 226 |
s=input()
if s[-1]!='s':print(s+'s')
else:print(s+'es') | #
# 179A
#
s = input()
s1 = list(s)
if s1[len(s)-1]=='s':
print(s+'es')
else:
print(s+'s') | 1 | 2,396,567,494,830 | null | 71 | 71 |
# rainy season
def rainy(S):
if 'RRR' in S:
return 3
if 'RR' in S:
return 2
if 'R' in S:
return 1
return 0
if __name__ == "__main__":
input = list(input().split())
print(rainy(input[0]))
| import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
s = str(readline().rstrip().decode('utf-8'))
if s == "RRR":
print(3)
elif s == "RRS" or s == "SRR":
print(2)
elif s.count("R") == 0:
print(0)
else:
print(1)
if __name__ == '__main__':
solve()
| 1 | 4,915,407,707,110 | null | 90 | 90 |
x, y, z = map(int, input().split())
y, x = x, y
z, x = x, z
print(x, y, z)
| A, B, C = map(str, input().split())
print(C+' '+A+' '+B) | 1 | 37,916,919,426,632 | null | 178 | 178 |
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
M = list(map(int, input().split()))
combinations = {}
def create_combinations(idx, sum):
combinations[sum] = 1
if idx >= N:
return
create_combinations(idx+1, sum)
create_combinations(idx+1, sum+A[idx])
return
create_combinations(0, 0)
for target in M:
if target in combinations.keys():
print("yes")
else:
print("no")
| # -*- coding: utf-8 -*-
"""
全探索
・再帰で作る
・2^20でTLEするからメモ化した
"""
N = int(input())
aN = list(map(int, input().split()))
Q = int(input())
mQ = list(map(int, input().split()))
def dfs(cur, depth, ans):
# 終了条件
if cur == ans:
return True
# memo[現在位置]に数値curがあれば、そこから先はやっても同じだからやらない
if cur in memo[depth]:
return False
memo[depth].add(cur)
# 全探索
for i in range(depth, N):
if dfs(cur+aN[i], i+1, ans):
return True
# 見つからなかった
return False
for i in range(Q):
memo = [set() for j in range(N+1)]
if dfs(0, 0, mQ[i]):
print('yes')
else:
print('no')
| 1 | 103,349,943,762 | null | 25 | 25 |
n, p = map(int, input().split())
s = [int(i) for i in input()]
p_cnt = 0
if p == 2 or p == 5:
for i in range(n):
if s[i] % p == 0:
p_cnt += i+1
else:
s = s[::-1]
div_dic = dict(zip(range(p), [0] * p))
tmp = 0
for i in range(n):
tmp += s[i] * pow(10, i, p)
tmp %= p
div_dic[tmp] += 1
for v in div_dic.values():
p_cnt += v * (v - 1)
p_cnt //= 2
p_cnt += div_dic.get(0)
print(p_cnt) | a,b = input().split()
a = int(a)
b = int(b)
ret = a - (b * 2)
if ret < 0:
ret = 0
print(ret)
| 0 | null | 112,525,389,356,900 | 205 | 291 |
x = raw_input()
x = int(x)
x = x ** 3
print x | #! /usr/local/bin/python3
# coding: utf-8
print(int(input()) ** 3)
| 1 | 283,094,412,650 | null | 35 | 35 |
import math, itertools
n = int(input())
X = list(list(map(int,input().split())) for _ in range(n))
L = list(itertools.permutations(range(n),n))
ans = 0
for l in L:
dist = 0
for i in range(n-1):
s,t = l[i],l[i+1]
vx = X[s][0] - X[t][0]
vy = X[s][1] - X[t][1]
dist += math.sqrt(vx**2 + vy**2)
ans += dist
print(ans/len(L)) | n=int(input())
print(*[chr(65+(ord(a)+n-65)%26) for a in input()], sep='') | 0 | null | 141,578,663,193,842 | 280 | 271 |
import sys
input = sys.stdin.buffer.readline
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A = sorted(A)
F = sorted(F)[::-1]
left = -1
right = max(A) * max(F)
while left + 1 < right:
mid = (left + right) // 2
tmp = 0
for i in range(N):
a, f = A[i], F[i]
if a * f > mid:
tmp += -(-(a * f - mid) // f)
if tmp <= K:
right = mid
else:
left = mid
print(right) | n=int(input())
s=[str(input()) for _ in range(n)]
print(len(set(s))) | 0 | null | 97,465,022,865,952 | 290 | 165 |
import sys
n = int(raw_input())
#n = 30
for i in range(1, n+1):
if i % 3 == 0:
sys.stdout.write(" {:}".format(i))
elif str(i).find('3') > -1:
sys.stdout.write(" {:}".format(i))
print("") | n = int(input())
playlist = []
duration = []
for i in range(n):
s, t = input().split()
playlist.append(s)
duration.append(int(t))
index = playlist.index(input())
durations = sum(duration[index + 1: ])
print(durations) | 0 | null | 49,225,994,690,720 | 52 | 243 |
n = int(input())
l = list(map(int,input().split()))
l.reverse()
print(' '.join(map(str,l)))
| n = int(input())
a = list(map(int, input().split(" ")))
for lil_a in a[-1:0:-1]:
print("%d "%lil_a, end="")
print("%d"%a[0]) | 1 | 982,830,078,724 | null | 53 | 53 |
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
for i in range(k, n):
print("Yes" if a[i] > a[i - k] else "No") | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
n,k = LI()
a = LI()
for i in range(k, n):
if a[i] > a[i-k]:
print('Yes')
else:
print('No')
| 1 | 7,122,500,350,198 | null | 102 | 102 |
# abc168_a.py
# https://atcoder.jp/contests/abc168/tasks/abc168_a
# A - ∴ (Therefore) /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点: 100点
# 問題文
# いろはちゃんは、人気の日本製ゲーム「ÅtCoder」で遊びたい猫のすぬけ君のために日本語を教えることにしました。
# 日本語で鉛筆を数えるときには、助数詞として数の後ろに「本」がつきます。この助数詞はどんな数につくかで異なる読み方をします。
# 具体的には、999以下の正の整数 N について、「N本」と言うときの「本」の読みは
# Nの 1 の位が 2,4,5,7,9のとき hon
# Nの 1 の位が 0,1,6,8のとき pon
# Nの 1 の位が 3のとき bon
# です。
# Nが与えられるので、「N本」と言うときの「本」の読みを出力してください。
# 制約
# Nは 999以下の正の整数
# 入力
# 入力は以下の形式で標準入力から与えられる。
# N
# 出力
# 答えを出力せよ。
# 入力例 1
# 16
# 出力例 1
# pon
# 16の 1 の位は 6なので、「本」の読みは pon です。
# 入力例 2
# 2
# 出力例 2
# hon
# 入力例 3
# 183
# 出力例 3
# bon
global FLAG_LOG
FLAG_LOG = False
def log(value):
# FLAG_LOG = True
FLAG_LOG = False
if FLAG_LOG:
print(str(value))
def calculation(lines):
# S = lines[0]
N = int(lines[0])
# N, M = list(map(int, lines[0].split()))
# values = list(map(int, lines[1].split()))
# values = list(map(int, lines[2].split()))
# values = list()
# for i in range(N):
# values.append(int(lines[i]))
# valueses = list()
# for i in range(N):
# valueses.append(list(map(int, lines[i+1].split())))
amari = N % 10
result = 'hon'
if amari == 3:
result = 'bon'
elif amari in [0, 1, 6, 8]:
result = 'pon'
return [result]
# 引数を取得
def get_input_lines(lines_count):
lines = list()
for _ in range(lines_count):
lines.append(input())
return lines
# テストデータ
def get_testdata(pattern):
if pattern == 1:
lines_input = ['16']
lines_export = ['pon']
if pattern == 2:
lines_input = ['2']
lines_export = ['hon']
if pattern == 3:
lines_input = ['183']
lines_export = ['bon']
return lines_input, lines_export
# 動作モード判別
def get_mode():
import sys
args = sys.argv
global FLAG_LOG
if len(args) == 1:
mode = 0
FLAG_LOG = False
else:
mode = int(args[1])
FLAG_LOG = True
return mode
# 主処理
def main():
import time
started = time.time()
mode = get_mode()
if mode == 0:
lines_input = get_input_lines(1)
else:
lines_input, lines_export = get_testdata(mode)
lines_result = calculation(lines_input)
for line_result in lines_result:
print(line_result)
# if mode > 0:
# print(f'lines_input=[{lines_input}]')
# print(f'lines_export=[{lines_export}]')
# print(f'lines_result=[{lines_result}]')
# if lines_result == lines_export:
# print('OK')
# else:
# print('NG')
# finished = time.time()
# duration = finished - started
# print(f'duration=[{duration}]')
# 起動処理
if __name__ == '__main__':
main()
| kazu = ['pon','pon','hon','bon','hon','hon','pon','hon','pon','hon']
n = int(input())
print(kazu[n%10])
| 1 | 19,223,002,744,946 | null | 142 | 142 |
import functools, operator
r,c = tuple(int(n) for n in input().split())
A = [[int(a) for a in input().split()] for i in range(r)]
for a in A:
a.append(sum(a))
R = [functools.reduce(operator.add, x) for x in zip(*A)]
A.append(R)
for j in A:
print(" ".join(map(str,j)))
| # coding: utf-8
row, col = map(int, input().split())
spreadsheet = []
for i in range(row):
val = list(map(int, input().split()))
val.append(sum(val))
spreadsheet.append(val)
for r in spreadsheet:
print(' '.join(map(str, r)))
last_row = []
for j in range(len(spreadsheet[0])):
col_sum = 0
for i in range(len(spreadsheet)):
col_sum += spreadsheet[i][j]
last_row.append(col_sum)
print(' '.join(map(str, last_row)))
| 1 | 1,358,831,146,774 | null | 59 | 59 |
n,m = map(int,input().split())
c = list(map(int,input().split()))
i = 0
dp = [0] * 50001
for i in range(50001):
dp[i] = i
#金額ごとに最小枚数を出す
for i in range(2,n+1):
for j in range(m):
if i - c[j] >= 0:
dp[i] = min(dp[i], dp[i - c[j]] + 1)
print(dp[n])
| N, M = map(int, input().split())
c = list(map(int, input().split()))
dp = [0] + [float('inf')] * N
for m in range(M):
ci = c[m]
for n in range(N + 1):
if n - ci >= 0:
dp[n] = min(dp[n], dp[n - ci] + 1)
print(dp[N])
| 1 | 142,569,737,508 | null | 28 | 28 |
n = int(input())
s = input()
r = [0] * (n+1)
g = [0] * (n+1)
b = [0] * (n+1)
for i, c in enumerate(reversed(s), 1):
if c == 'R':
r[i] += r[i-1] + 1
else:
r[i] += r[i-1]
if c == 'G':
g[i] += g[i-1] + 1
else:
g[i] += g[i-1]
if c == 'B':
b[i] += b[i-1] + 1
else:
b[i] += b[i-1]
r = r[:-1][::-1]
g = g[:-1][::-1]
b = b[:-1][::-1]
ans=0
for i in range(n-2):
for j in range(i+1, n-1):
if s[i] == s[j]:
continue
se = set('RGB') - set(s[i] + s[j])
c = se.pop()
if c == 'R':
ans += r[j]
if 2*j-i < n and s[2*j-i] == 'R':
ans -= 1
elif c == 'G':
# print('j=',j,'g[j]=',g[j])
ans += g[j]
if 2*j-i < n and s[2*j-i] == 'G':
ans -= 1
elif c == 'B':
ans += b[j]
if 2*j-i < n and s[2*j-i] == 'B':
ans -= 1
# print('i=',i,'j=',j,'c=',c, 'ans=',ans)
print(ans) | def solution1():
# https://www.youtube.com/watch?v=aRdGRrsRo7I
n = int(input())
s = input()
r, g, b = 0, 0, 0
for i in s:
if i == 'R': r += 1
elif i == 'G': g += 1
else: b += 1
total = r*g*b
# all permutations of rgb are valid, to check if s[i], s[j], s[k] is a permutation of 'rgb' we could use counter. Or neat trick: ASCII value of the sum of s[i] + s[j] + s[k] is same.
is_rgb = ord('R') + ord('G') + ord('B')
for i in range(n):
for j in range(i+1, n):
# Condition 2 fails when: i - j = k - j --> k = 2*j - i
k = 2*j - i
if k < n:
if ord(s[i]) + ord(s[j]) + ord(s[2*j-i]) == is_rgb:
total -= 1
print(total)
solution1() | 1 | 36,258,796,777,760 | null | 175 | 175 |
H, W, M = map(int, input().split())
HW = []
for _ in range(M):
HW.append(list(map(int, input().split())))
A = [0] * (H + 1)
B = [0] * (W + 1)
for h, w in HW:
A[h] += 1
B[w] += 1
a = max(A)
b = max(B)
cnt = A.count(a) * B.count(b) - len([0 for h, w in HW if A[h] == a and B[w] == b])
print(a + b - (cnt == 0)) | N= int(input())
S = input()
abc = "ABC"
ans = 0
j = 0
for i in range(N):
if S[i] == abc[j]:
j += 1
if S[i] == "C":
j = 0
ans += 1
elif S[i] == "A":
j = 1
else:
j = 0
print(ans) | 0 | null | 51,750,541,562,148 | 89 | 245 |
s = input()
map = {'SSS': 0, 'SSR': 1, 'SRS': 1, 'RSS': 1, 'SRR': 2, 'RSR': 1, 'RRS': 2, 'RRR': 3}
for key in map.keys():
if s == key:
print(map[key])
break | weatherS = input()
serial = 0
dayBefore = ''
for x in weatherS:
if dayBefore != 'R':
if x == 'R':
serial = 1
else:
if x == 'R':
serial += 1
dayBefore = x
print(serial) | 1 | 4,803,595,576,992 | null | 90 | 90 |
import math
a, b, x = map(int, input().split())
sq = a*a*b/2
if sq >= x:
A1 = 2*x/(a*b)
num = math.atan(b/A1)
else:
B1 = 2*x/a**2 - b
num = math.atan((b-B1)/a)
print(math.degrees(num))
| import sys
import math
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
a,b,x = map(int, input().split())
s = a * b
theta = 0
if a * a * b / 2 < x:
theta = math.atan(2 * (a**2 * b - x) / a**3)
else:
theta = math.atan((a * b**2) / (2 * x))
deg = math.degrees(theta)
print('{:.10f}'.format(deg))
| 1 | 162,849,770,116,838 | null | 289 | 289 |
import sys
from collections import Counter
H,W,m = map(int,input().split())
h_ls = [0] * H
w_ls = [0] * W
bombers = [(0,0) for _ in range(m)]
for i in range(m):
h,w = map(int,input().split())
h_ls[h-1] += 1
w_ls[w-1] += 1
bombers[i] = (h-1,w-1)
h_max = max(h_ls)
h_counter = Counter(h_ls)
# Couter使ってみる
h_max_args = [0]*h_counter[h_max]
next_ind = 0
for i in range(H):
if h_ls[i] == h_max:
h_max_args[next_ind] = i
next_ind += 1
w_max = max(w_ls)
w_counter = Counter(w_ls)
w_max_args = [0]*w_counter[w_max]
next_ind = 0
for i in range(W):
if w_ls[i] == w_max:
w_max_args[next_ind] = i
next_ind += 1
bombers = set(bombers)
for h in h_max_args:
for w in w_max_args:
if not (h,w) in bombers:
print(w_max+h_max)
sys.exit()
print(w_max+h_max-1)
| H,W,M=map(int,input().split())
h=[0]*(H+1)
w=[0]*(W+1)
hw=[0]*M
for i in range(M):
y,x=map(int,input().split())
hw[i]=(y,x)
h[y]+=1
w[x]+=1
cnt=0
mxh=max(h)
mxw=max(w)
for hi,wi in hw:
if h[hi]==mxh and w[wi]==mxw:
cnt+=1
if h.count(mxh)*w.count(mxw)==cnt:
print(mxh+mxw-1)
else:
print(mxh+mxw) | 1 | 4,714,994,256,226 | null | 89 | 89 |
import sys
import resource
sys.setrecursionlimit(10000)
n,k=map(int,input().rstrip().split())
p=list(map(int,input().rstrip().split()))
c=list(map(int,input().rstrip().split()))
def find(start,now,up,max,sum,count,flag):
if start==now:
flag+=1
if start==now and flag==2:
return [max,sum,count]
elif count==up:
return [max,sum,count]
else:
count+=1
sum+=c[p[now-1]-1]
if max<sum:
max=sum
return find(start,p[now-1],up,max,sum,count,flag)
kara=[-10000000000]
for i in range(1,n+1):
m=find(i,i,n,c[p[i-1]-1],0,0,0)
if m[2]>=k:
m=find(i,i,k,c[p[i-1]-1],0,0,0)
if m[0]>kara[0]:
kara[0]=m[0]
result=kara[0]
elif m[1]<=0:
if m[0]>kara[0]:
kara[0]=m[0]
result=kara[0]
else:
w=k%m[2]
if w==0:
w=m[2]
spe=find(i,i,w,c[p[i-1]-1],0,0,0)[0]
if m[1]+spe>m[0] and m[1]*(k-w)//m[2]+spe>kara[0]:
kara[0]=m[1]*(k-w)//m[2]+spe
elif m[1]+spe<=m[0] and m[1]*((k-w)//m[2]-1)+m[0]>kara[0]:
kara[0]=m[1]*((k-w)//m[2]-1)+m[0]
result=kara[0]
print(result) | def mod_max(loop, mod):
if mod == 0:
return 0
loop_len = len(loop)
mm = min(loop)
for start in range(loop_len):
current_sum = 0
for i in range(mod):
current_sum += loop[(start + i) % loop_len]
mm = max(current_sum, mm)
return mm
def main():
n, k = map(int, input().split())
p = [int(i) - 1 for i in input().split()]
c = [int(i) for i in input().split()]
seen = set()
loop_list = []
for start in range(n):
v = start
loop = []
while v not in seen:
seen.add(v)
loop.append(c[v])
v = p[v]
seen.add(v)
if loop:
loop_list.append(loop)
ans = min(c)
for loop in loop_list:
loop_len = len(loop)
loop_num = k // loop_len
loop_mod = k % loop_len
loop_sum = sum(loop)
ans = max(mod_max(loop, min(loop_len, k)), ans)
if loop_num > 0:
ans = max(loop_sum * loop_num + mod_max(loop, loop_mod), ans)
ans = max(loop_sum * (loop_num - 1) + mod_max(loop, loop_len), ans)
print(ans)
if __name__ == '__main__':
main()
| 1 | 5,439,346,604,980 | null | 93 | 93 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.