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
|
---|---|---|---|---|---|---|
import math
r = input()
l = math.pi*r*2.0
s = r*r*math.pi
print "%f %f" %(s, l) | import math
t = float(input())
a = math.pi * t**2
b = 2 * t * math.pi
print(str("{0:.8f}".format(a)) + " " + "{0:.8f}".format(b)) | 1 | 650,904,118,258 | null | 46 | 46 |
l, r, d = [int(x) for x in input().split()]
print(r // d - (l - 1) // d) | while True:
a, b = map(int,raw_input().split())
if a == 0 and b == 0:
break
if a > b:
print str(b) +" "+ str(a)
else:
print str(a) +" "+ str(b) | 0 | null | 4,061,014,234,760 | 104 | 43 |
X,Y,Z=map(str,input().split())
XX=Y
Y=X
X=XX
XX=Z
Z=X
X=XX
print(X,Y,Z) | import math
r = input()
S = math.pi * r ** 2
L = math.pi * r * 2
print "%f %f" %(S, L) | 0 | null | 19,333,604,075,864 | 178 | 46 |
import sys
input = lambda: sys.stdin.readline().rstrip()
def solve():
N = int(input())
ans = int(N / 2 + 0.6)
print(ans)
if __name__ == '__main__':
solve()
| x=int(input())
a=1
while True:
if (a*x%360==0):
print(a)
break
a+=1
| 0 | null | 36,002,866,244,572 | 206 | 125 |
import sys
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
if (a1-b1)*t1+(a2-b2)*t2 == 0:
print("infinity")
sys.exit()
e1 = (a1-b1)*t1
e2 = e1 + (a2-b2)*t2
if e1*e2 > 0:
print(0)
sys.exit()
e1, e2 = abs(e1), abs(e2)
if e1%e2:
print(1+2*(e1//e2))
else:
print(2*(e1//e2)) | s,t = map(int,input().split())
k,l = map(int,input().split())
m,n = map(int,input().split())
a = (k-m)*s
b = (l-n)*t
if a+b == 0:
print("infinity")
elif a>0 and a+b>0:
print(0)
elif a<0 and a+b<0:
print(0)
else:
div = abs(a) // abs(a+b)
if div == abs(a) / abs(a+b):
print(div*2)
else:
print(div*2+1) | 1 | 131,761,059,336,992 | null | 269 | 269 |
N, M = map(int, input().split())
A_list = list(map(int, input().split()))
for i in range(M):
N -= A_list[i]
if N < 0:
print(-1)
break
if i == M-1:
print(N) | N,M=map(int,input().split())
A=input()
List_A=A.split()
day=0
for i in range(0,M):
day=day+int(List_A[i])
if N>=day:
print(N-day)
else:
print(-1) | 1 | 32,175,877,720,012 | null | 168 | 168 |
x = int(input())
for i in range(-200,201):
for j in range(-200,201):
if i**5 - j**5 == x:
print(i,j)
exit()
| x = input()
a, b = [int(z) for z in x.split()]
x = a // b
y = a % b
z = ('{:.5f}'.format(a / b))
print('{} {} {}'.format(x, y, z)) | 0 | null | 13,131,143,018,620 | 156 | 45 |
import sys
d_num = int(sys.stdin.readline().strip())
graph_list = []
for _ in range(0, d_num):
array = sys.stdin.readline().strip().split(" ")
if len(array) <= 2:
graph_list.append([])
else:
graph_list.append([int(array[i]) - 1 for i in range(2, len(array))])
t = 1
result = [[] for _ in range(0, d_num)]
searched_list = []
stack = []
while True:
if len(stack) == 0:
ll = filter(lambda x: x not in searched_list, range(0, d_num))
if len(ll) == 0:
break
stack.append(ll[0])
result[ll[0]].append(t)
searched_list.append(ll[0])
else:
node = stack[-1]
children = filter(lambda x: x not in searched_list, graph_list[node])
if len(children) != 0:
next_node = children[0]
stack.append(next_node)
result[next_node].append(t)
searched_list.append(next_node)
else:
stack.pop()
result[node].append(t)
t += 1
s = ""
for i in range(0, len(result)):
print str(i+1) + " " + str(result[i][0]) + " " + str(result[i][1]) | # http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B&lang=ja
import sys
input = sys.stdin.readline
N = int(input())
G = [[a-1 for a in list(map(int, input().split()))[2:]] for _ in [0]*N]
visited = [0]*N
history = [[] for _ in [0]*N]
k = 0
def dfs(v=0, p=-1):
global k
visited[v] = 1
k += 1
history[v].append(k)
for u in G[v]:
if u == p or visited[u]:
continue
dfs(u, v)
k += 1
history[v].append(k)
for i in range(N):
if not visited[i]:
dfs(i)
for i, h in enumerate(history):
print(i+1, *h)
| 1 | 3,180,023,652 | null | 8 | 8 |
N = int(input())
print(input().count("ABC"))
""" 3文字ずつスライスし判定
S = input()
count = 0
# スライスでi+2文字目まで行くのでfor文範囲はN-2でとどめる
for i in range(N-2):
if S[i:i+3] == "ABC":
count += 1
print(count) """ | # +1/-1の折れ線で表したとき
# 「0で終わる」かつ「途中で0未満にならない」を満たせば良い
# あとは貪欲を上手い事使う
def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
import math
#from math import gcd
#inf = 10**17
#mod = 10**9 + 7
n = int(input())
a = []
b = []
for _ in range(n):
s = input().rstrip()
# 最終的に上がる量/最下点
up, down = 0, 0
for i in s:
if i == ')':
up -= 1
if down > up:
down = up
else:
up += 1
if up >= 0:
a.append((down, up))
else:
b.append((up-down, down, up))
a.sort(reverse=True)
b.sort(key=lambda a: a[0],reverse=True)
c = 0
for d, u in a:
if c+d < 0:
print('No')
break
else:
c += u
else:
for _, d, u in b:
if c+d < 0:
print('No')
break
else:
c += u
else:
if c == 0:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main()
| 0 | null | 61,314,858,962,460 | 245 | 152 |
from sys import stdin
def ip(): return [int(i) for i in stdin.readline().split()]
def sp(): return [str(i) for i in stdin.readline().split()]
s = str(input())
c = 0
for i in s:
c += int(i)
if (c % 9) == 0: print("Yes")
else: print("No")
| n = int(input())
from collections import deque
graph = [deque([]) for _ in range(n+1)]
for _ in range(n):
u, k, *v = [int(x) for x in input().split()]
v.sort()
for i in v:
graph[u].append(i)
arrive = [-1 for i in range(n+1)]
finish = [-1 for i in range(n+1)]
times = 0
def dfs(v):
global times
times += 1
arrive[v] = times
stack = [v]
while stack:
v = stack[-1]
if graph[v]:
w = graph[v].popleft()
if arrive[w] == -1:
times += 1
arrive[w] = times
stack.append(w)
else:
times += 1
finish[v] = times
stack.pop()
return
for i in range(n):
if arrive[i+1] == -1:
dfs(i+1)
for j in range(n):
tmp = [j+1, arrive[j+1], finish[j+1]]
print(*tmp)
| 0 | null | 2,210,618,120,350 | 87 | 8 |
n = int(raw_input())
C = {'S':range(13), 'H':range(13), 'C':range(13), 'D':range(13)}
for i in range(n):
suit, num = raw_input().split()
num = int(num)
C[suit][num-1] = 14
for i in ['S', 'H', 'C', 'D']:
for j in range(13):
if C[i][j] != 14:
print "%s %d" %(i, j+1) | n = int(input())
l = [0]*53
for i in range(n):
a, b = input().split()
b = int(b)
if a == "H":
b += 13
elif a == "C":
b += 26
elif a == "D":
b += 39
l[b] = 1
for j in range(1,53):
if l[j] != 1:
ama = j % 13
syou = j // 13
if ama == 0:
ama = 13
syou -= 1
if syou == 0:
zi = "S"
elif syou == 1:
zi = "H"
elif syou == 2:
zi = "C"
else:
zi = "D"
print(zi, ama) | 1 | 1,054,054,590,390 | null | 54 | 54 |
n=int(input())
a=sorted(list(map(int,input().split())))
c=0
for i in range(n-1):
c+=a[-1-(i+1)//2]
print(c)
| N = int(input())
A = list(map(int,input().split()))
A.sort()
if N==2:
print(max(A))
exit()
ans = A.pop()
n = N-2
while A:
a = A.pop()
for _ in range(2):
n -= 1
ans += a
if n==0:
print(ans)
exit() | 1 | 9,130,489,682,402 | null | 111 | 111 |
days = ["MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"]
S = input()
if S == "SUN":
print(7)
else:
print(days.index("SUN") - days.index(S))
| L = int(input())
a = L / 3
ans = a**3
print("{:.10f}".format(ans))
| 0 | null | 90,205,359,924,262 | 270 | 191 |
def main(a, b,c,k):
m = 0
if k <=a:
m = k
elif k <=(a+b):
m = a
elif k <= a+b+c:
m = (a-(k-(a+b)))
return m
a, b, c , k = map(int, input().split())
print(main(a,b,c,k)) | a,b,c,k = map(int,input().split())
if k < a:
print(str(k))
elif k < (a + b):
print(str(a))
else:
print(str(2*a + b - k)) | 1 | 21,959,117,304,320 | null | 148 | 148 |
N=int(input())
f=0
for i in range(N):
a,b=map(int,input().split())
if a==b:
f+=1
else:
f=0
if f==3:
print('Yes')
break
else:
print('No') | counter = int(input())
result_flg = False
fir_fir, fir_sec = map(int, input().split())
sec_fir, sec_sec = map(int, input().split())
for i in range(2, counter):
thi_fir, thi_sec = map(int, input().split())
if fir_fir == fir_sec:
if sec_fir == sec_sec:
if thi_fir == thi_sec:
result_flg = True
break
# reset content
fir_fir = sec_fir
fir_sec = sec_sec
sec_fir = thi_fir
sec_sec = thi_sec
if result_flg == True:
print('Yes')
else:
print('No') | 1 | 2,523,651,329,244 | null | 72 | 72 |
class Dice:
TOP, SOUTH, EAST, WEST, NORTH, BOTTOM = 0, 1, 2, 3, 4, 5
def __init__(self, d):
self.dice = d
self.top = d[0]
self.south = d[1]
self.east = d[2]
self.west = d[3]
self.north = d[4]
self.bottom = d[5]
def set_top_front(self, top, front):
for i, n in enumerate(self.dice):
if n == top:
if i == Dice.TOP: pass
elif i == Dice.SOUTH: self.move("N")
elif i == Dice.EAST: self.move("W")
elif i == Dice.WEST: self.move("E")
elif i == Dice.NORTH: self.move("S")
elif i == Dice.BOTTOM:
self.move("S")
self.move("S")
break
for i, n in enumerate(self.dice):
if n == front:
if i == Dice.TOP: print("error.")
elif i == Dice.SOUTH: pass
elif i == Dice.EAST: self.move("R")
elif i == Dice.WEST: self.move("L")
elif i == Dice.NORTH:
self.move("R")
self.move("R")
elif i == Dice.BOTTOM: print("error.")
break
def move(self, d):
if d == "N":
self.move_north()
elif d == "W":
self.move_west()
elif d == "S":
self.move_south()
elif d == "E":
self.move_east()
elif d == "R":
self.move_right()
elif d == "L":
self.move_left()
self.dice = [
self.top,
self.south,
self.east,
self.west,
self.north,
self.bottom,
]
def move_right(self):
self.north, self.west, self.south, self.east \
= self.west, self.south, self.east, self.north
def move_left(self):
self.north, self.west, self.south, self.east \
= self.east, self.north, self.west, self.south
def move_north(self):
self.top, self.south, self.bottom, self.north \
= self.south, self.bottom, self.north, self.top
def move_south(self):
self.top, self.south, self.bottom, self.north \
= self.north, self.top, self.south, self.bottom
def move_east(self):
self.top, self.east, self.bottom, self.west \
= self.west, self.top, self.east, self.bottom
def move_west(self):
self.top, self.east, self.bottom, self.west \
= self.east, self.bottom, self.west, self.top
if __name__ == "__main__":
import re
nums = [int(n) for n in re.split(r"\s+", input().strip())]
dice = Dice(nums)
n = int(input().strip())
for i in range(n):
top, front = [int(n) for n in re.split(r"\s+", input().strip())]
dice.set_top_front(top, front)
print(dice.east)
| dice = list(map(int,input().split()))
n=int(input())
for i in range(n):
qa,qb = map(int,input().split())
if qa==dice[0]:
if qb==dice[1]:
print(dice[2])
elif qb==dice[2]:
print(dice[4])
elif qb==dice[4]:
print(dice[3])
else:
print(dice[1])
elif qa==dice[1]:
if qb==dice[0]:
print(dice[3])
elif qb==dice[3]:
print(dice[5])
elif qb==dice[5]:
print(dice[2])
else:
print(dice[0])
elif qa==dice[2]:
if qb==dice[0]:
print(dice[1])
elif qb==dice[1]:
print(dice[5])
elif qb==dice[5]:
print(dice[4])
else:
print(dice[0])
elif qa==dice[3]:
if qb==dice[0]:
print(dice[4])
elif qb==dice[4]:
print(dice[5])
elif qb==dice[5]:
print(dice[1])
else:
print(dice[0])
elif qa==dice[4]:
if qb==dice[0]:
print(dice[2])
elif qb==dice[2]:
print(dice[5])
elif qb==dice[5]:
print(dice[3])
else:
print(dice[0])
else:
if qb==dice[4]:
print(dice[2])
elif qb==dice[2]:
print(dice[1])
elif qb==dice[1]:
print(dice[3])
else:
print(dice[4])
| 1 | 252,834,679,768 | null | 34 | 34 |
import sys
num = int(sys.stdin.readline())
ans = num ** 3
print ans | n = int(input())
print(n * n * n) | 1 | 284,392,892,212 | null | 35 | 35 |
N, M = map(int, raw_input().split())
matrix = []
array = []
for n in range(N):
tmp = map(int, raw_input().split())
if len(tmp) > M:
print 'error'
matrix.append(tmp)
for m in range(M):
tmp = input()
array.append(tmp)
for n in range(N):
multi = 0
for m in range(M):
multi += matrix[n][m] * array[m]
print multi | import sys
def main():
lines = sys.stdin.readlines()
A = []
B = []
C = []
n = 0
m = 0
for i, line in enumerate(lines):
# print(line)
# rm '\n' from string of a line
line = line.strip('\n')
elems = line.split(" ")
if i == 0:
n = int(elems[0])
m = int(elems[1])
elif 0 < i and i < n + 1:
A.append([int(e) for e in elems])
elif n < i:
B.append([int(elems[0])])
c = []
for i in range(0, n):
num = 0
for index, e in enumerate(A[i]):
num += e * B[index][0]
c.append(num)
for i in range(0, n):
print c[i]
if __name__ == "__main__":
main() | 1 | 1,167,018,412,768 | null | 56 | 56 |
n,k = map(int, input().split())
num = []
for i in range(k):
d = int(input())
num += list(map(int, input().split()))
Q = list(set(num))
print(n-len(Q)) |
def resolve():
N = int(input())
if N % 2 == 1:
return print(0)
ans = 0
tmp = N // 2
while tmp:
tmp //= 5
ans += tmp
print(ans)
if __name__ == "__main__":
resolve() | 0 | null | 70,578,722,108,960 | 154 | 258 |
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
aMax = a[-1]
l = len(a)
count = 0
k = 0
kSet = set()
for i in range(n):
value = a[i]
if not(value in kSet):
if i != 0 and a[i-1] == value:
count -= 1
kSet.add(value)
continue
count += 1
j = 2
k = 0
while k < aMax:
k = a[i] * j
kSet.add(k)
j += 1
print(count) | #!/usr/bin/env python
from math import *
n, m = list(map(int, input().split()))
c = list(map(int, input().split()))
DP = [n for i in range(n + 1)]
DP[0] = 0
for cost in c:
for i in range(cost, n + 1):
DP[i] = min(DP[i], DP[i - cost] + 1)
print(DP[n])
| 0 | null | 7,211,713,193,582 | 129 | 28 |
N, M = [int(_) for _ in input().split()]
l = 1
r = N
ans = []
for _ in range(M - M // 2):
ans += [l, r]
l += 1
r -= 1
if (r - l) % 2 == (l + N - r) % 2:
r -= 1
for _ in range(M // 2):
ans += [l, r]
l += 1
r -= 1
ans = ans[:2 * M]
print('\n'.join(f'{a} {b}' for a, b in zip(ans[::2], ans[1::2])))
| print(' '.join((lambda x:[str((x[2]-1)) if x[4] == x[0] else str(x[2]),str((x[3]-1)) if x[4] == x[1] else str(x[3])])(input().split()+list(map(int,input().split()))+[input()]))) | 0 | null | 50,558,794,835,538 | 162 | 220 |
import sys
from collections import deque
def LS():
return list(input().split())
S = deque(input())
Q = int(input())
rev = 0
for i in range(Q):
A = LS()
if A[0] == "1":
rev += 1
rev %= 2
else:
if A[1] == "1":
if rev == 0:
S.appendleft(A[2])
else:
S.append(A[2])
else:
if rev == 0:
S.append(A[2])
else:
S.appendleft(A[2])
if rev == 0:
print(''.join(S))
else:
S.reverse()
print(''.join(S))
| import statistics
from collections import Counter
N = int(input())
A = [list(map(int, input().split(" "))) for i in range(N)]
xMIN = []
xMAX = []
for i in range(N):
xMIN.append(A[i][0])
for j in range(N):
xMAX.append(A[j][1])
if N % 2 != 0:
medianMIN = statistics.median(xMIN)
medianMAX = statistics.median(xMAX)
print(int(medianMAX-medianMIN+1))
else:
medianMIN_LOW = statistics.median_low(xMIN)
medianMIN_HIGH = statistics.median_high(xMIN)
medianMAX_LOW = statistics.median_low(xMAX)
medianMAX_HIGH = statistics.median_high(xMAX)
print((medianMAX_LOW+medianMAX_HIGH)-(medianMIN_LOW+medianMIN_HIGH)+1)
| 0 | null | 37,410,281,425,920 | 204 | 137 |
def dist(x, y, i, j):
dx = x[i] - x[j]
dy = y[i] - y[j]
return (dx * dx + dy * dy) ** 0.5
n = int(input())
x = [0] * n
y = [0] * n
for i in range(n):
x[i], y[i] = map(int, input().split())
ans = 0
for i in range(n):
for j in range(i + 1, n):
ans += dist(x, y, i, j) * 2 / n
print(ans)
| from itertools import combinations
import math
N = int(input())
x = []
y = []
for i in range(N):
_x, _y = map(int, input().split())
x.append(_x)
y.append(_y)
s = 0
for c in combinations(zip(x, y), 2):
s += math.sqrt((c[0][0] - c[1][0]) ** 2 + (c[0][1] - c[1][1]) ** 2)
print(s * 2 / N) | 1 | 148,240,023,529,344 | null | 280 | 280 |
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
from typing import Iterable
import sys
def main(N, M, K, AB, CD):
friend_chain = UnionFindTree(N)
friend_count = [0] * N
block_count = [0] * N
for a, b in AB:
a, b = a - 1, b - 1
friend_chain.union(a, b)
friend_count[a] += 1
friend_count[b] += 1
for c, d in CD:
c, d = c - 1, d - 1
if friend_chain.same(c, d):
block_count[c] += 1
block_count[d] += 1
print(*[friend_chain.size(i) - 1 - friend_count[i] - block_count[i] for i in range(N)])
class UnionFindTree:
def __init__(self, n: int) -> None:
self.parent = [-1] * n
def find(self, x: int) -> int:
p = self.parent
while p[x] >= 0: x, p[x] = p[x], p[p[x]]
return x
def union(self, x: int, y: int) -> bool:
x, y, p = self.find(x), self.find(y), self.parent
if x == y: return False
if p[x] > p[y]: x, y = y, x
p[x], p[y] = p[x] + p[y], x
return True
def same(self, x: int, y: int) -> bool:
return self.find(x) == self.find(y)
def size(self, x: int) -> int:
return -self.parent[self.find(x)]
def same_all(self, indices: Iterable[int]) -> bool:
f, v = self.find, self.find(indices[0])
return all(f(i) == v for i in indices)
if __name__ == '__main__':
input = sys.stdin.readline
N, M, K = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(M)]
CD = [tuple(map(int, input().split())) for _ in range(K)]
main(N, M, K, AB, CD)
| D = int(input())
for i in range(D):
print(i%26+1) | 0 | null | 35,617,878,219,416 | 209 | 113 |
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
"""
親が同じか判別する
"""
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
"""
yをxの根に繋ぐ
"""
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def same(self, x, y):
"""
xとyが同じ連結成分か判別する
"""
return self.find(x) == self.find(y)
def size(self, x):
"""
xの連結成分の大きさを返す
"""
return -self.parents[self.find(x)]
def kruskal(self, edge):
"""
:param edge: edge = [(コスト, 頂点1, 頂点2),...]の形で重み付き隣接リストを渡して下さい
:return: 最小全域木のコストの和
"""
edge.sort()
cost_sum = 0
for cost, node1, node2 in edge:
if not self.same(node1, node2):
cost_sum += cost
self.union(node1, node2)
return cost_sum
def resolve():
n, m, k = map(int, input().split())
uf = UnionFind(n)
edge = [[] for _ in range(n)]
for _ in range(m):
a, b = map(int, input().split())
edge[a - 1].append(b - 1)
edge[b - 1].append(a - 1)
uf.union(a - 1, b - 1)
block = [[] for _ in range(n)]
for _ in range(k):
c, d = map(int, input().split())
block[c - 1].append(d - 1)
block[d - 1].append(c - 1)
res = []
for i in range(n):
cnt = uf.size(i) - len(edge[i]) - 1
for j in block[i]:
if uf.same(i, j):
cnt -= 1
res.append(cnt)
print(*res)
if __name__ == '__main__':
resolve()
| # Distance II
dimension = int(input())
vectors = [[float(i) for i in input().rstrip().split()] for j in range(2)]
x = vectors[0]
y = vectors[1]
absoluteValues = [abs(x[k] - y[k]) for k in range(dimension)]
# print(absoluteValues)
# xとyのミンコフスキー距離を求める関数(a: 有限)
def mink(a):
totalValue = 0
for i in range(dimension):
totalValue += absoluteValues[i] ** a
distance = totalValue ** (1 / a)
return distance
# xとyのChebyshev距離を求める関数
def chev():
maxValue = 0
for i in range(dimension):
# print(absoluteValues[i])
if absoluteValues[i] > maxValue:
maxValue = absoluteValues[i]
print(maxValue)
for i in range(1, 3 + 1):
dist = mink(i)
print(dist)
chev()
| 0 | null | 30,801,391,715,600 | 209 | 32 |
import math
while True:
a = int(input())
if a == 0:
break
b = list(map(float, input().split()))
m = sum(b)/a
s = 0
for i in range(int(a)):
s += (b[i]-m)**2
s = s / (int(a))
s = math.sqrt(s)
print(s) | import math
(a,b,C) = [int(i) for i in input().split()]
c = math.sqrt(a ** 2 + b ** 2 - (2 * a * b) * math.cos(C * math.pi / 180))
h = float(b * math.sin(C * math.pi / 180))
s = float(a * h / 2)
l = float(a + b + c)
print(s)
print(l)
print(h) | 0 | null | 186,779,057,558 | 31 | 30 |
def main():
n, m = map(int, input().split())
# マイナスの場合は leader であり、同時にサイズ(*-1)を保持する
uf = [-1] * (n+1)
def uf_leader(a):
if uf[a]<0:
return a
uf[a] = uf_leader(uf[a])
return uf[a]
def uf_unite(a, b):
ua, ub = uf_leader(a), uf_leader(b)
if ua==ub:
return False
if uf[ua] > uf[ub]:
ua, ub = ub, ua
uf[ua] += uf[ub]
uf[ub] = ua
return True
def uf_leaders():
return [v for v in range(1,n+1) if uf[v]<0]
# print(uf[1:])
for _ in range(m):
a, b = map(int, input().split())
uf_unite(a, b)
# print(uf[1:])
# print(uf_leaders())
ans = len(uf_leaders())-1
print(ans)
main()
| N=int(input())
A=list(map(int,input().split()))
B=[0]*N
for x in range(N-1):
B[A[x]-1] += 1
for y in range(N):
print(B[y]) | 0 | null | 17,446,690,785,960 | 70 | 169 |
# -*- coding:utf-8 -*-
def solve():
"""しゃくとり法で解く"""
N = int(input())
As = list(map(int, input().split()))
# 数列Aの要素aが何個あるかを保持する辞書dic
dic = {}
for a in As:
if not a in dic:
dic[a] = 0
dic[a] += 1
S = sum(As) # 総和
# 各クエリでしゃくとりする
Q = int(input())
for q in range(Q):
b, c = list(map(int, input().split()))
if b in dic:
if not c in dic:
dic[c] = 0
S -= b*dic[b]
S += c*dic[b]
dic[c] += dic[b]
dic[b] = 0
print(S)
if __name__ == "__main__":
solve()
| n = int(input())
s = input()
if n % 2 != 0:
print("No")
else:
t = s[:int((n / 2))]
u = t + t
print("Yes" if s == u else "No") | 0 | null | 79,362,178,171,628 | 122 | 279 |
n, u, v = map(int, input().split())
matrix = [[] for _ in range(n)]
import sys
sys.setrecursionlimit(10**8)
for _ in range(n-1):
a,b = map(int, input().split())
matrix[a-1].append(b-1)
matrix[b-1].append(a-1)
C = [0]*n
D = [0]*n
def dfs(x, pre, cnt, c):
c[x] = cnt
cnt += 1
for a in matrix[x]:
if a == pre:
continue
dfs(a, x, cnt, c)
dfs(v-1, -1, 0, C)
dfs(u-1, -1, 0, D)
ans=0
for i in range(n):
if C[i] > D[i]:
ans = max(ans, C[i]-1)
print(ans) | from math import ceil
t1,t2 = map(int,input().split())
a1,a2 = map(int,input().split())
b1,b2 = map(int,input().split())
a1 -= b1
a2 -= b2
a1 *= t1
a2 *= t2
if a1 + a2 == 0:
print("infinity")
exit()
if a1*(a1+a2) > 0:
print(0)
exit()
x = -a1/(a1+a2)
n = ceil(x)
if n == x:
print(2*n)
else:
print(2*n-1) | 0 | null | 124,427,758,568,828 | 259 | 269 |
# Begin Header {{{
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement
# }}} End Header
# _________コーディングはここから!!___________
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for x in combinations(l, 3):
if x[0]!=x[1] and x[0]!=x[2] and x[1]!=x[2]:
if x[0] + x[1] > x[2]:
ans+=1
print(ans) | N = int(input())
L = list(map(int, input().split()))
le = len(L)
score = 0
for i in range(le):
for j in range(i+1,le):
for k in range(j+1,le):
if (L[i] + L[j] > L[k] and
L[i] + L[k] > L[j] and
L[k] + L[j] > L[i] ):
if (L[i] != L[j] and
L[i] != L[k] and
L[k] != L[j]):
score += 1
print(score) | 1 | 5,053,234,351,560 | null | 91 | 91 |
n = raw_input()
S = set(raw_input().split())
q = raw_input()
T = set(raw_input().split())
print len(S & T) | n = int(input())
li1 = list(map(int,input().split()))
m = int(input())
li2 = list(map(int,input().split()))
cnt = 0
for i in li2:
if i in li1:
cnt +=1
print(cnt) | 1 | 69,649,261,710 | null | 22 | 22 |
import sys
input = lambda: sys.stdin.readline().rstrip()
def resolve():
class BinaryIndexedTree():
def __init__(self, n):
self.n = n
self.bit = [0]*(n+1)
def add(self, item, pos):
index = pos
while index < self.n+1:
self.bit[index] += item
index += index & (-index)
def sum(self, pos):
ret = 0
index = pos
while index > 0:
ret += self.bit[index]
index -= index & -index
return ret
N = int(input())
S = list(input())
Q = int(input())
Query = [input().split() for _ in range(Q)]
pos_bit_list = [BinaryIndexedTree(len(S)) for _ in range(26)]
for i, c in enumerate(S):
pos_bit_list[ord(c)-ord('a')].add(1, i+1)
for q in Query:
if q[0] == '1':
pos_bit_list[ord(S[int(q[1])-1])-ord('a')].add(-1, int(q[1]))
pos_bit_list[ord(q[2])-ord('a')].add(1, int(q[1]))
S[int(q[1])-1] = q[2]
else:
print(len([p for p in pos_bit_list if p.sum(int(q[2])) - p.sum(int(q[1])-1) > 0]))
if __name__ == '__main__':
resolve()
| #!/usr/bin/env python3
class Bit:
# Binary Indexed Tree
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def __iter__(self):
psum = 0
for i in range(self.size):
csum = self.sum(i + 1)
yield csum - psum
psum = csum
raise StopIteration()
def __str__(self): # O(nlogn)
return str(list(self))
def sum(self, i):
# [0, i) の要素の総和を返す
if not (0 <= i <= self.size): raise ValueError("error!")
s = 0
while i>0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
if not (0 <= i < self.size): raise ValueError("error!")
i += 1
while i <= self.size:
self.tree[i] += x
i += i & -i
def __getitem__(self, key):
if not (0 <= key < self.size): raise IndexError("error!")
return self.sum(key+1) - self.sum(key)
def __setitem__(self, key, value):
# 足し算と引き算にはaddを使うべき
if not (0 <= key < self.size): raise IndexError("error!")
self.add(key, value - self[key])
(n,), (s,), _, *q = map(str.split, open(0))
*s, = s
BIT = [Bit(int(n)) for _ in [0] * 26]
for e, t in enumerate(s):
BIT[ord(t) - 97].add(e, 1)
for a, b, c in q:
if a == "1":
i = int(b)
BIT[ord(s[i - 1]) - 97].add(i - 1, -1)
s[i - 1] = c
BIT[ord(c) - 97].add(i - 1, 1)
else:
l, r = int(b), int(c)
print(sum(BIT[i].sum(r) - BIT[i].sum(l - 1) > 0 for i in range(26)))
| 1 | 62,634,142,211,740 | null | 210 | 210 |
input()
a = input().split()
a.reverse()
print(' '.join(a)) | a=[]
n = int(input())
s = input().rstrip().split(" ")
for i in range(n):
a.append(int(s[i]))
a=a[::-1]
for i in range(n-1):
print(a[i],end=' ' )
print(a[n-1]) | 1 | 991,904,951,322 | null | 53 | 53 |
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1 for i in range(n)]
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
N, M=[int(i) for i in input().split(" ")]
uf = UnionFind(N)
for i in range(M):
A,B=[int(i) for i in input().split(" ")]
uf.union(A-1,B-1)
d={}
for i in range(N):
root = uf.find(i)
d[root]=d.get(root,0)+1
print(max(d.values()))
| import sys
x = int(sys.stdin.read())
c500, x = divmod(x, 500)
c5 = x // 5
print(c500 * 1000 + c5 * 5) | 0 | null | 23,425,156,398,384 | 84 | 185 |
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_sum = [0]
B_sum = [0]
A_now = 0
B_now = 0
for i in range(N):
A_now = A[i] + A_now
A_sum.append(A_now)
for i in range(M):
B_now = B[i] + B_now
B_sum.append(B_now)
ans = 0
for i in range(N+1):
book_count = i
remain_time = K - A_sum[i]
ok = 0
ng = M
if remain_time >= B_sum[M]:
ans = book_count + M
while ng - ok > 1:
mid = (ok+ng)//2
if remain_time >= B_sum[mid]:
ok = mid
else:
ng = mid
book_count += ok
if remain_time >= 0:
if book_count > ans:
ans = book_count
# print(mid,remain_time,B_sum[ok])
print(ans)
| def get_cusum(lst):
cusum = [0] + lst
for i in range(1, len(cusum)):
cusum[i] = cusum[i] + cusum[i-1]
return cusum
def main():
n, m, k = map(int, input().split(" "))
book_a = get_cusum(list(map(int, input().split(" "))))
book_b = get_cusum(list(map(int, input().split(" "))))
ans = 0
top = m
# print(book_a)
# print(book_b)
for i in range(n + 1):
if book_a[i] > k:
break
while book_b[top] > k - book_a[i]:
top -= 1
ans = max(ans, i+top)
print(ans)
main()
| 1 | 10,723,402,435,820 | null | 117 | 117 |
X,N = map(int,input().split())
min = 100
if N !=0:
Plist = list(map(int,input().split()))
anslist = [i for i in range(102)]
anslist.append(-1)
#anslist.remove(0)
Plist = sorted(Plist)
#print (anslist)
for i in range(N):
anslist.remove(Plist[i])
temp =100
for i in range(len(anslist)):
if min >abs(anslist[i]-X) :
min = abs(anslist[i]-X)
temp = anslist[i]
print (temp)
else :
print (X) | x, n = map(int, input().split())
p = list(map(int, input().split()))
for i in range(x+1):
for j in [-1, 1]:
ans = x + i*j
if not p.count(ans):
print(ans)
exit(0)
| 1 | 14,088,470,362,288 | null | 128 | 128 |
n = int(input())
s = list(map(int, input().split()))
q = int(input())
t = list(map(int, input().split()))
c = 0
for num in t:
if num in s:
c += 1
print(c)
| n = input()
S = raw_input().split()
q = input()
T = raw_input().split()
s = 0
for i in T:
if i in S:
s+=1
print s | 1 | 68,427,200,278 | null | 22 | 22 |
N, K = map(int, input().split())
ans = 0
bigint = 10**9+7
for k in range(K,N+2):
ans += N-k+2+(N-k+1)*(k-1)
ans %= bigint
print(ans) | import sys
from io import StringIO
import unittest
import os
# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)
# 実装を行う関数
def resolve(test_def_name=""):
n, k = map(int, input().split())
ans = 0
min_num = 0
desk_list = list(reversed(range(n + 1)))
max_num = 0
ack_list = list(range(n + 1))
for i in range(1, n + 1):
min_num = (min_num + desk_list.pop()) % (pow(10, 9) + 7)
max_num = (max_num + ack_list.pop()) % (pow(10, 9) + 7)
if k <= i:
ans = (ans + max_num - min_num + 1) % (pow(10, 9) + 7)
print(ans+1)
# テストクラス
class TestClass(unittest.TestCase):
def assertIO(self, assert_input, output):
stdout, sat_in = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
resolve(sys._getframe().f_back.f_code.co_name)
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, sat_in
self.assertEqual(out, output)
def test_input_1(self):
test_input = """3 2"""
output = """10"""
self.assertIO(test_input, output)
def test_input_2(self):
test_input = """200000 200001"""
output = """1"""
self.assertIO(test_input, output)
def test_input_3(self):
test_input = """141421 35623"""
output = """220280457"""
self.assertIO(test_input, output)
# 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
def tes_t_1original_1(self):
test_input = """データ"""
output = """データ"""
self.assertIO(test_input, output)
# 実装orテストの呼び出し
if __name__ == "__main__":
if os.environ.get("USERNAME") is None:
# AtCoder提出時の場合
resolve()
else:
# 自PCの場合
unittest.main()
| 1 | 33,190,244,965,252 | null | 170 | 170 |
from sys import exit
import math
import collections
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
a,b,c = mi()
if a + b + c >=22:
print('bust')
else:
print('win') | from collections import deque
n = int(input())
data = deque(list(input() for _ in range(n)))
ans = deque([])
co = 0
for i in data:
if i[6] == ' ':
if i[0] == 'i':
ans.insert(0, i[7:])
co += 1
else:
try:
ans.remove(i[7:])
co -= 1
except:
pass
else:
if i[6] == 'F':
del ans[0]
co -= 1
else:
del ans[-1]
co -= 1
for i in range(0, co-1):
print(ans[i], end=' ')
print(ans[co-1])
| 0 | null | 59,635,052,733,970 | 260 | 20 |
from sys import stdin, stdout # only need for big input
def solve():
s = input()
left = 0
right = len(s) - 1
count = 0
while left < right:
count += (s[left] != s[right])
left += 1
right -= 1
print(count)
def main():
solve()
if __name__ == "__main__":
main() | N = int(input())
cities = []
for n in range(N):
cities.append(tuple(map(int, input().split())))
import math
def distance(i, j):
xi,yi = cities[i]
xj,yj = cities[j]
xd,yd = xi - xj, yi - yj
return math.sqrt(xd * xd + yd * yd)
# path: これまでに通過した街の番号
def search(path):
total = 0
count = 0
for i in range(N):
if i not in path:
count += 1
path.append(i)
total += (0 if len(path) == 1 else distance(i, path[-2])) + search(path)
path.remove(i)
if count == 0:
return 0
else:
return total / count
print(search([])) | 0 | null | 134,437,169,518,820 | 261 | 280 |
X, K, D = map(int, input().split())
if X - K * D >= 0:
ans = abs(X - K * D)
elif X + K * D <= 0:
ans = abs(X + K * D)
else:
n = int(abs(X - K * D) / (2 * D))
ans = min(abs(X - K * D + n * 2 * D), abs(X - K * D + (n + 1) * 2 * D))
print(ans) | def solve(string):
x, k, d = map(int, string.split())
if k % 2:
x = min(x - d, x + d, key=abs)
k -= 1
x, k, d = abs(x), k // 2, d * 2
return str(min(x % d, abs((x % d) - d))) if x < k * d else str(x - k * d)
if __name__ == '__main__':
import sys
print(solve(sys.stdin.read().strip()))
| 1 | 5,194,143,986,818 | null | 92 | 92 |
n = int(input())
p = list(map(int,input().split()))
ans = 1
dotira = False
s = 10**18
if 0 in p :
print(0)
else:
for x in p:
ans = ans * x
if ans > s:
dotira = True
break
if dotira:
print(-1)
else:
print(ans)
| N = int(input())
A = [int(x) for x in input().split()]
for i in range(N):
if A[i] == 0:
print(0)
exit()
ans = A[0]
for i in range(1, N):
ans *= A[i]
if ans > 10**18:
print(-1)
exit()
print(ans)
| 1 | 16,111,931,908,652 | null | 134 | 134 |
N = int(input())
S,T = input().split()
ans = ["a"]*(N*2)
for i in range(N) :
ans[2*i] = S[i]
ans[2*i+1] = T[i]
print(''.join(ans)) | def main():
N = input()
S, T = input().split()
ans = ""
for s, t in zip(S, T):
ans += s + t
print(ans)
if __name__ == '__main__':
main()
| 1 | 112,144,270,211,950 | null | 255 | 255 |
n = int(input())
s = input()
ans = s.count('R') * s.count('G') * s.count('B')
for i in range(n-2):
for j in range(i+1, n-1):
k = 2*j-i
if k < n:
if s[k] != s[i] and s[k] != s[j] and s[i] != s[j]:
ans -= 1
else:
break
print(ans) | def paint(h, w):
print("\n".join(["#" * w] * h))
while True:
H, W = map(int, input().split())
if H == W == 0: break
paint(H, W)
print()
| 0 | null | 18,316,604,162,180 | 175 | 49 |
R, C, K = map(int, input().split())
Items = [[0] * (C + 1) for _ in range(R + 1)]
for _ in range(K):
r, c, v = map(int, input().split())
Items[r][c] = v
DP = [[0] * 4 for _ in range(R + 1)]
for x in range(1, C+1):
for y in range(1, R+1):
v = Items[y][x]
if v:
DP[y][3] = max(DP[y][3], DP[y][2] + v)
DP[y][2] = max(DP[y][2], DP[y][1] + v)
DP[y][1] = max(max(DP[y][1], DP[y][0] + v), max(DP[y-1]) + v)
DP[y][0] = max(DP[y][0], max(DP[y-1]))
else:
DP[y][0] = max(DP[y][0], max(DP[y-1]))
print(max(DP[R])) | def solve():
N = int(input())
X = input()
X_10 = int(X,2)
r = X.count("1")
r0 = r-1
r1 = r+1
ans = []
s0 = X_10 % r0 if r != 1 else None
s1 = X_10 % r1
for i in range(N):
if X[i] == '0':
ans.append(f((s1 + pow(2,N-1-i,r1)) % r1))
else:
if r0 == 0:
ans.append(0)
else:
ans.append(f((s0 - pow(2,N-1-i,r0)) % r0))
print(*ans, sep='\n')
def f(N):
cnt = 1
while N != 0:
N = N % popcount(N)
cnt += 1
return cnt
def popcount(N):
b = bin(N)
cnt = 0
for i in range(2,len(b)):
if b[i] == '1':
cnt += 1
return cnt
if __name__ == '__main__':
solve() | 0 | null | 6,908,537,296,180 | 94 | 107 |
x, n = map(int, input().split())
p = list(map(int, input().split()))
l = [i - x for i in p]
m = [0]
for i in range(1, 101):
m.append(-i)
m.append(i)
for i in range(201):
if (m[i] in l) == True:
continue
if (m[i] in l) == False:
print(x + m[i])
break | S = int(input())
if S <= 2:
print(0)
elif S <= 5:
print(1)
else:
series = [0,0,0,1,1,1]
m = 10**9 +7
for i in range(6,S+1):
series.append((series[i-3] + series[i-1]) %m)
print(series[S]) | 0 | null | 8,669,326,549,308 | 128 | 79 |
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
def cumsum(a):
"""※ aを破壊する
l[i] = sum(a[:i]) なるlを返す
sum(a[i:j]) == l[j+1] - l[i]
"""
c = 0
n = len(a)
a.insert(0, 0)
for i in range(1, n+1):
a[i] = a[i-1]+a[i]
return a
a = cumsum(a)
aa = [((item - i)%k) for i,item in enumerate(a)]
ans = 0
from collections import defaultdict
c = defaultdict(int)
for i in range(min(k, len(aa))):
c[aa[i]] += 1
for i,item in enumerate(aa):
c[item] -= 1
# print(c, item)
ans += c[item]
if i+k<n+1:
c[aa[i+k]] += 1
print(ans) | import itertools, collections
N, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
C = list(itertools.accumulate([0] + A))
D = [(v - i) % K for i, v in enumerate(C)]
#D[i]==D[j] and i-j<K
dp = collections.Counter(D[:K])
ans = 0
for i in range(N):
dp[D[i]] -= 1
ans += dp[D[i]]
if i + K < len(D):
dp[D[i + K]] += 1
print(ans)
| 1 | 137,424,238,045,468 | null | 273 | 273 |
# coding=utf-8
a, b = map(int, input().split())
if a > b:
big_num = a
sml_num = b
else:
big_num = b
sml_num = a
while True:
diviser = big_num % sml_num
if diviser == 0:
break
else:
big_num = sml_num
sml_num = diviser
print(sml_num) | x, y = map(int, input().split())
def gcd(x, y):
if x % y == 0:
return y
elif x % y == 1:
return 1
else:
return gcd(y, x % y)
if x >= y:
n = gcd(x, y)
print(n)
else:
n = gcd(y, x)
print(n) | 1 | 7,184,909,730 | null | 11 | 11 |
import sys
#import numpy as np
import math
#from fractions import Fraction
#import itertools
#from collections import deque
#import heapq
#from fractions import gcd
input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
ans=1
d={x:0 for x in range(n)}
for i in range(n):
if a[i]==0:
d[0]+=1
else:
m=a[i]
ans=(ans*(d[m-1]-d[m]))%mod
if ans<=0:
print(0)
exit()
d[m]+=1
if d[a[i]]>3:
print(0)
exit()
if d[0]==1:
print(ans*3%mod)
elif d[0]==2:
print(ans*6%mod)
elif d[0]==3:
print(ans*6%mod) | n=int(input())
a=list(map(int,input().split()))
#R,B,Gの順に埋めていく
#R,B,Gの現在の数を保存する
cnt={'R':0,'B':0,'G':0}
ans=1
for i in range(n):
count=0
edi=0
for j in 'RBG':
if cnt[j]==a[i]:
count+=1
if edi==0:
cnt[j]+=1
edi=1
ans*=count
print(ans%(10**9+7)) | 1 | 130,390,739,207,260 | null | 268 | 268 |
n = int(input())
s = input()
ans=[]
for i in s:
a = chr(ord('A')+(ord(i)-ord('A')+n)%26)
ans.append(a)
print(('').join(ans)) | def main():
N = int(input())
S = str(input())
ans = ''
alphabet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
for i in range(len(S)):
c = alphabet.index(S[i]) + N
if c > 25:
c = c - 26
ans = ans + alphabet[c]
print(ans)
main() | 1 | 134,461,808,142,912 | null | 271 | 271 |
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
n, k = map(int, input().split())
sunuke = [0] * n
for _ in range(k):
d = int(input())
a = tuple(map(int, input().split()))
for ae in a:
sunuke[ae-1] += 1
r = sunuke.count(0)
print(r)
if __name__ == '__main__':
main()
| n,k,s=map(int,input().split())
sMax=10**9
if k==0:
if s==sMax:
print("1 "*n)
else:
print((str(sMax)+" ")*n)
else:
if s==sMax:
print((str(s)+" ")*k+"1 "*(n-k))
else:
print((str(s)+" ")*k+(str(sMax)+" ")*(n-k)) | 0 | null | 57,559,068,414,528 | 154 | 238 |
# -*- coding: utf-8 -*-
def main():
S = input()
listS = S.split()
if S[0] == S[1] and S[1] == S[2]:
ans = 'No'
else:
ans = 'Yes'
print(ans)
if __name__ == "__main__":
main() | A,B=input().split()
A = int(A)
B = int(float(B)*100+.5)
print(A*B//100) | 0 | null | 35,754,851,150,910 | 201 | 135 |
L,R,d = map(int,input().split())
A = 0
for _ in range(L,R+1):
if _ %d == 0:
A += 1
print(A) | import math
def LI():
return list(map(int, input().split()))
L, R, d = LI()
Ld = (L-1)//d
Rd = R//d
ans = Rd-Ld
print(ans)
| 1 | 7,487,566,208,320 | null | 104 | 104 |
a = 0
for i in input():
a += int(i)
print("Yes" if a%9==0 else "No") | n = int(input())
mod = 10 ** 9 + 7
start,zero,nine,ans = 1,0,0,0
for i in range(n):
ans = (ans * 10 + zero + nine) % mod
zero = (zero * 9 + start) % mod
nine = (nine * 9 + start) % mod
start = (start * 8) % mod
print(ans) | 0 | null | 3,844,984,552,380 | 87 | 78 |
import sys
n = int(sys.stdin.readline())
xs = []
for _ in range(n):
v = [int(x) for x in sys.stdin.readline().split(" ")]
xs.append(v)
xs.sort(key=lambda x: x[0])
if n % 2 == 0:
m1 = n // 2 - 1
m2 = m1 + 1
a1 = xs[m1][0]
a2 = xs[m2][0]
xs.sort(key=lambda x: x[1])
b1 = xs[m1][1]
b2 = xs[m2][1]
a = (a1 + a2)
b = (b1 + b2)
c = (b - a) + 1
#print(m1, m2, a1, a2, b1, b2, "*", a, b, c)
print(c)
else:
m = (n + 1) // 2 - 1
a = xs[m][0]
xs.sort(key=lambda x: x[1])
b = xs[m][1]
c = b - a + 1
#print(m, a, b, c)
print(c) | while True:
h, w = map(int, input().split())
if w+h == 0:
break
line = "#"*w
for y in range(h):
print(line)
print()
| 0 | null | 8,980,452,604,942 | 137 | 49 |
from decimal import Decimal
A, B = input().split()
A = int(A)
if len(B) == 1:
B = int(B[0] + '00')
elif len(B) == 3:
B = int(B[0] + B[2] + '0')
else:
B = int(B[0]+B[2]+B[3])
x = str(A*B)
print(x[:-2] if len(x) > 2 else 0)
| import sys
s = sys.stdin.read()
for c in [chr(i) for i in range(97,97+26)]:
print(c, ":", s.lower().count(c)) | 0 | null | 9,130,266,234,880 | 135 | 63 |
def magic(a,b,c,k):
for i in range(k):
if(a>=b):
b*=2
elif(b>=c):
c*=2
if(a < b and b < c):
print("Yes")
else:
print("No")
d,e,f = map(int,input().split())
j = int(input())
magic(d,e,f,j)
| import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n,k = map(int , input().split())
i = 0
while pow(k, i)<=n:
i += 1
print(i) | 0 | null | 35,702,511,079,300 | 101 | 212 |
from scipy.sparse.csgraph import floyd_warshall
n, m, l = map(int, input().split())
inf = 10**12
d = [[inf for i in range(n)] for i in range(n)]
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(m):
x,y,z = map(int,input().split())
d[x-1][y-1] = z
d[y-1][x-1] = z
for i in range(n):
d[i][i] = 0 #自身のところに行くコストは0
dd = floyd_warshall(d)
ddd = [[inf for i in range(n)] for i in range(n)]
for i in range(n):
for j in range(n):
if dd[i][j] <= l:
ddd[i][j] = 1
dddd =floyd_warshall(ddd)
q = int(input())
for i in range(q):
s, t = map(int, input().split())
if dddd[s-1][t-1] == inf:
print(-1)
else:
print(int(dddd[s-1][t-1]-1)) | import sys
from copy import deepcopy
def main():
INF = 10**18
input = sys.stdin.readline
N, M, L = [int(x) for x in input().split()]
d = [set() for _ in range(N+1)]
ds = [[INF] * (N+1) for _ in range(N+1)]
bs = [[INF] * (N+1) for _ in range(N+1)]
for _ in range(M):
A, B, C = [int(x) for x in input().split()]
A, B = sorted([A, B])
d[A].add(B)
if L >= C:
ds[A][B] = C
nes = set()
for k in range(1, N+1):
for i in range(1, N+1):
for j in range(i+1, N+1):
ds[i][j] = min(ds[i][j], ds[min(i, k)][max(i, k)] + ds[min(k, j)][max(k, j)])
if ds[i][j] <= L:
bs[i][j] = 1
for k in range(1, N+1):
for i in range(1, N+1):
for j in range(i+1, N+1):
bs[i][j] = min(bs[i][j], bs[min(i, k)][max(i, k)] + bs[min(k, j)][max(k, j)])
Q, = [int(x) for x in input().split()]
for _ in range(Q):
s, t = sorted(int(x) for x in input().split())
print(bs[s][t]-1 if bs[s][t] < INF else -1)
if __name__ == '__main__':
main()
| 1 | 173,753,795,826,038 | null | 295 | 295 |
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
H, W, K = lr()
S = []
for i in range(H):
S.append([int(s) for s in sr()])
ans = 2000
idx = [0]*H
for div in range(1<<(H-1)):
g = 0
for i in range(H):
idx[i] = g
if div>>i&1:
g += 1
g += 1
c = [[0]*W for i in range(g)]
for i in range(H):
for j in range(W):
c[idx[i]][j] += S[i][j]
ok = True
for i in range(g):
for j in range(W):
if c[i][j] > K:
ok = False
if not ok:
continue
num = g-1
now = [0]*g
def add(j):
for i in range(g):
now[i] += c[i][j]
for i in range(g):
if now[i] > K:
return False
return True
for j in range(W):
if not add(j):
num += 1
now = [0]*g
add(j)
ans = min(ans, num)
print(ans)
resolve() | h, w, k = map(int, input().split())
s = []
for _ in range(h):
s.append(input())
sum = [[0] * (w+1) for _ in range(h+1)]
for i in range(h):
for j in range(w):
sum[i+1][j+1] = sum[i][j+1] + sum[i+1][j] - sum[i][j] + (1 if s[i][j] == '1' else 0)
ans = h + w - 2
for ptn in range(1<<h-1):
cand = 0
sep = [0]
for i in range(h-1):
if((ptn >> i) & 1):
sep.append(i+1)
cand += 1
sep.append(h)
left = 0
for pos in range(w):
cur = []
for i in range(len(sep)-1):
cur.append(sum[sep[i+1]][pos+1] - sum[sep[i+1]][left] - sum[sep[i]][pos+1] + sum[sep[i]][left])
if max(cur) > k:
if left == pos:
cand = h * w
break
else:
cand += 1
left = pos
ans = cand if cand < ans else ans
print(ans)
| 1 | 48,503,952,467,202 | null | 193 | 193 |
l,r,f = map(int,input().split())
count = 0
for i in range(l,r+1):
if i % f == 0 :
count = count + 1
print(count) | from itertools import accumulate
#acumulate [a[0], a[0]+a[1], a[0]+...]
n, k = map(int, input().split())
p = [int(x) - 1 for x in input().split()]
c = list(map(int, input().split()))
ans = -(10 ** 18)
for i in range(n):
pos = i
scores = []
while True:
pos = p[pos]
scores.append(c[pos])
if pos == i:
break
m = len(scores)
s = list(accumulate(scores))
for j in range(min(m, k)):
x = (k - j - 1) // m
ans = max(ans, s[j], s[j] + s[-1] * x)
print(ans) | 0 | null | 6,442,290,716,838 | 104 | 93 |
def printComparison(a, b):
"""
a: int
b: int
outputs the comparison result of a and b
>>> printComparison(1, 2)
a < b
>>> printComparison(4, 3)
a > b
>>> printComparison(5, 5)
a == b
>>> printComparison(-20, -10)
a < b
"""
operator = ''
if a > b:
operator = '>'
elif a < b:
operator = '<'
else:
operator = '=='
print('a', operator, 'b')
if __name__ == '__main__':
ival = input().split(' ')
printComparison(int(ival[0]), int(ival[1])) | import sys
a, b = map(int, sys.stdin.readline().split())
if(a < b):
print("a < b")
elif(a > b):
print("a > b")
else:
print("a == b") | 1 | 358,393,621,850 | null | 38 | 38 |
N = int(input())
lst = "abcdefghijklmnopqrstuvwxyz"
ans = ""
while N > 0:
ans = lst[(N-1)%26] + ans
N = (N-1)//26
print(ans) | import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
X = int(input())
big_coin, amari = divmod(X, 500)
print(big_coin*1000+(amari//5)*5) | 0 | null | 27,257,640,601,848 | 121 | 185 |
a=[input() for i in range(2)]
a1=[int(i) for i in a[0].split()]
a2=[int(i) for i in a[1].split()]
k=a1[1]
for i in range(a1[0]-a1[1]):
if a2[i]<a2[i+k]:
print("Yes")
else:
print("No") | N,D = (int(x) for x in input().split())
count = 0
for i in range(N):
x,y = (int(z) for z in input().split())
dist = x**2 + y**2
if dist <= D**2:
count += 1
print(count) | 0 | null | 6,480,987,416,142 | 102 | 96 |
from decimal import *
import math
a, b, c = list(map(int, input().split()))
print('Yes' if c - a - b> 0 and 4*a*b < (c - a - b)**2 else 'No') | import math
def main():
a,b,c = map(int,input().split())
left = 4*a*b
right = (c-a-b)**2
if (c-a-b)<0:
return 'No'
if left < right:
return 'Yes'
else:
return 'No'
print(main())
| 1 | 51,556,722,229,672 | null | 197 | 197 |
from sys import stdin
def isPrime(x):
if x == 2: return 1
elif x % 2 == 0: return 0
return pow(2, x - 1, x) == 1
n = int(stdin.readline())
print(sum([isPrime(int(stdin.readline())) for _ in range(n)])) | n,k=map(int,input().split())
A=[0]*k
mod=10**9+7
def power(a,x): #a**xの計算
T=[a]
while 2**(len(T))<mod: #a**1,a**2.a**4,a**8,...を計算しておく
T.append(T[-1]**2%mod)
b=bin(x) #xを2進数表記にする
ans=1
for i in range(len(b)-2):
if int(b[-i-1])==1:
ans=ans*T[i]%mod
return ans
for i in range(k):
cnt=power(k//(k-i),n)
now=(k-i)*2
while now<=k:
cnt-=A[now-1]
now+=k-i
A[k-i-1]=cnt
ans=0
for i in range(k):
ans+=(i+1)*A[i]%mod
ans%=mod
print(ans) | 0 | null | 18,279,917,153,080 | 12 | 176 |
n = int(input())
values = [int(input()) for i in range(n)]
maxv = -999999999
minimum = values[0]
for i in range(1, n):
if values[i] - minimum > maxv:
maxv = values[i] - minimum
if values[i] < minimum:
minimum = values[i]
print(maxv) | import sys
num = int(sys.stdin.readline().strip())
r0 = int(sys.stdin.readline().strip())
r1 = int(sys.stdin.readline().strip())
max_dis = r1 - r0
min_num = min(r0, r1)
for i in range(0, num-2):
r = int(sys.stdin.readline().strip())
max_dis = max(max_dis, r - min_num)
min_num = min(min_num, r)
print max_dis | 1 | 12,715,886,040 | null | 13 | 13 |
n=int(input())
A=list(map(int,input().split()) )
A.sort()
furui = [0] * (max(A) + 1)
for i in A:
if furui[i] >= 2:
continue
for j in range(i,len(furui),i):
furui[j] += 1
ans=0
for i in A:
if furui[i]==1:
ans+=1
print(ans) | res_list = [[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]]
n = int(input())
for i in range(n):
io_rec = list(map(int, input().split(" ")))
bld_num = io_rec[0] - 1
floor_num = io_rec[1] - 1
room_num = io_rec[2] - 1
io_headcnt = io_rec[3]
res_list[bld_num][floor_num][room_num] += io_headcnt
for i in range(4):
if i:
print("#" * 20)
bld = res_list[i]
for j in bld:
floor_str = map(str, j)
print(" " + " ".join(floor_str)) | 0 | null | 7,733,403,825,052 | 129 | 55 |
N = int(input())
judge = []
for i in range(N):
judge.append(input())
counter = [0, 0, 0, 0]
for i in range(N):
if judge[i] == "AC":
counter[0] += 1
if judge[i] == "WA":
counter[1] += 1
if judge[i] == "TLE":
counter[2] += 1
if judge[i] == "RE":
counter[3] += 1
print("AC x " + str(counter[0]))
print("WA x " + str(counter[1]))
print("TLE x " + str(counter[2]))
print("RE x " + str(counter[3])) | N, K, C = map(int, input().split())
S = input()
work_day_front = []
work_day_back = []
rest = 0
for i, c in enumerate(S):
if rest > 0:
rest -= 1
continue
if c == 'o':
rest = C
work_day_front.append(i)
max_work = len(work_day_front)
rest = 0
for i, c in enumerate(S[::-1]):
if rest > 0:
rest -= 1
continue
if c == 'o':
rest = C
work_day_back.append(N-i-1)
work_day_back = work_day_back[::-1]
if len(work_day_front) > K:
print()
exit()
ans = []
for i in range(len(work_day_back)):
if work_day_back[i] == work_day_front[i]:
ans.append(str(work_day_back[i]+1))
print("\n".join(ans))
| 0 | null | 24,750,762,764,792 | 109 | 182 |
import sys
from collections import defaultdict
def solve():
input = sys.stdin.readline
N, P = map(int, input().split())
S = input().strip("\n")
modSum = 0
modDict = defaultdict(int)
modDict[0] += 1
ans = 0
if P == 2 or P == 5:
for i in range(N):
if int(S[i]) % P == 0:
ans += i + 1
else:
for i in range(N):
modSum += int(S[N-i-1]) * pow(10, i, P)
modSum %= P
modDict[modSum] += 1
for key in modDict:
v = modDict[key]
ans += v * (v - 1) // 2
print(ans)
return 0
if __name__ == "__main__":
solve() | n,p=map(int,input().split())
s=input()
ans=0
if p==2:
for i in range(n):
if int(s[i])%2==0:
ans+=i+1
print(ans)
elif p==5:
for i in range(n):
if int(s[i])%5==0:
ans+=i+1
print(ans)
else:
s=s[::-1]
accum=[0]*n
d=dict()
for i in range(n):
accum[i]=int(s[i])*pow(10,i,p)%p
for i in range(n-1):
accum[i+1]+=accum[i]
accum[i+1]%=p
accum[-1]%=p
#print(accum)
for i in range(n):
if accum[i] not in d:
if accum[i]==0:
ans+=1
d[accum[i]]=1
else:
if accum[i]==0:
ans+=1
ans+=d[accum[i]]
d[accum[i]]+=1
#print(d)
print(ans) | 1 | 57,942,478,590,788 | null | 205 | 205 |
S = str(input())
if S[len(S)-1] == "s":
S += "es"
else:
S += "s"
print(S) | # coding:UTF-8
import sys
from math import factorial
MOD = 10 ** 9 + 7
INF = 10000000000
def main():
# ------ 入力 ------#
# 1行入力
a = input() # 文字列
# ------ 出力 ------#
if a[-1] == "s":
print("{}".format(a + "es"))
else:
print("{}".format(a + "s"))
if __name__ == '__main__':
main()
| 1 | 2,366,900,181,220 | null | 71 | 71 |
teki, hissatsu = list(map(int, input().split(' ')))
l = sorted(list(map(int, input().split(' '))))[:max(0, teki-hissatsu)]
print(sum(l)) | from math import cos, radians, sin, sqrt
def g(a, b, c):
c_rad = radians(c)
yield a * b * sin(c_rad) / 2
yield a + b + sqrt(a ** 2 + b ** 2 - 2 * a * b * cos(c_rad))
yield b * sin(c_rad)
a, b, c = list(map(int, input().split()))
for i in g(a, b, c):
print("{:.8f}".format(i)) | 0 | null | 39,728,000,934,820 | 227 | 30 |
import math
import itertools
from statistics import mean
n = int(input())
p = [list(map(int,input().split())) for i in range(n)]
ans = []
for v in itertools.permutations(p):
length = 0
for i in range(n-1):
length += math.sqrt((v[i+1][0] - v[i][0])**2 + (v[i+1][1] - v[i][1])**2)
ans.append(length)
print(mean(ans)) | s=input()
print(s+'es' if s[-1]=='s' else s+'s') | 0 | null | 75,428,328,443,300 | 280 | 71 |
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np # cumsum
# from bisect import bisect_left, bisect_right
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def solve():
N, M = MI()
uf = UnionFind(N)
for i in range(M):
a, b = MI1()
uf.union(a, b)
print(uf.group_count()-1)
if __name__ == '__main__':
solve()
| class UnionFind:
from typing import List, Set
def __init__(self, n):
self.n = n
self.parent = [-1] * n
def union(self, x, y) -> int:
x = self.leader(x)
y = self.leader(y)
if x == y:
return 0
if self.parent[x] > self.parent[y]:
x, y = y, x
self.parent[x] += self.parent[y]
self.parent[y] = x
return self.parent[x]
def same(self, x, y) -> bool:
return self.leader(x) == self.leader(y)
def leader(self, x) -> int:
if self.parent[x] < 0:
return x
else:
self.parent[x] = self.leader(self.parent[x])
return self.parent[x]
def size(self, x) -> int:
return -self.parent[self.leader(x)]
def groups(self) -> List[Set[int]]:
groups = dict()
for i in range(self.n):
p = self.leader(i)
if not groups.get(p):
groups[p] = set()
groups[p].add(i)
return list(groups.values())
n, m = map(int, input().split())
uf = UnionFind(n)
for i in range(m):
a, b = map(int, input().split())
uf.union(a-1, b-1)
print(len(uf.groups()) - 1) | 1 | 2,295,557,216,160 | null | 70 | 70 |
while True:
case=input().split()
x=int(case[0])
y=int(case[1])
if x==0 and y==0:
break
else:
if x<y:
print(x,y)
else:
print(y,x) | n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=-10**10
for i in range(n):
loop=[0]
now=i
while True:
now=p[now]-1
loop.append(loop[-1]+c[now])
if now==i:
break
L=len(loop)-1
if k<=L:
score=max(loop[1:k+1])
ans=max(score,ans)
else:
score=max(loop[-1],0)*(k//L-1)
ans=max(ans,score)
for j in range(k%L+L):
score+=loop[j%L+1]-loop[j%L]
ans=max(score,ans)
print(ans) | 0 | null | 2,987,979,918,980 | 43 | 93 |
import itertools
n = int(input())
a = [list(map(int, input().split(" "))) for i in range(n)]
ans = 0
for [ix,iy], [jx, jy] in itertools.combinations(a, 2):
ans += ((jx-ix)**2+(jy-iy)**2)**0.5*2
print(ans/n) | from itertools import permutations as per
n=int(input())
ans=[]
l=list(per(list(range(1,n+1))))
xy=[[] for i in range(n+1)]
for i in range(n):
x,y=map(int,input().split())
xy[i+1].append(x)
xy[i+1].append(y)
def f(x):
m=1
while x>0:
m*=x
x=x-1
return m
for i in range(f(n)):
dis=0
for j in range(n-1):
dis+=((xy[l[i][j]][0]-xy[l[i][j+1]][0])**2+(xy[l[i][j]][1]-xy[l[i][j+1]][1])**2)**(0.5)
ans.append(dis)
print(sum(ans)/f(n))
| 1 | 148,722,118,709,300 | null | 280 | 280 |
a=int(input())
List=[]
for i in range(a):
p,q=map(int,input().split())
List.append([p-q,p+q])
List=sorted(List, key=lambda x:x[1])
ans=0
t=-10000000000
for i in range(a):
if t<=List[i][0]:
ans+=1
t=List[i][1]
print(ans) | N=int(input())
LR=[]
for i in range(N):
X,L=map(int,input().split())
LR.append([X-L,X+L])
LR.sort(key=lambda x:x[1])
nin=LR[0][1]
ans=1
for i in range(1,N):
if nin<=LR[i][0]:
nin=LR[i][1]
ans+=1
print(ans) | 1 | 90,049,873,757,118 | null | 237 | 237 |
N = int(input())
A = list(map(int, input().split()))
dicA = {}
for i in range(1, N+1):
dicA[i] = A[i-1]
sort_dicA = sorted(dicA.items(), key=lambda x:x[1])
for i in range(N):
print(sort_dicA[i][0], end=' ')
| N = int(input())
A = list(map(int, input().split()))
idx = [0] * N
for i, val in enumerate(A):
idx[val-1] = i + 1
for i in idx:
print(i,end=" ") | 1 | 180,802,945,839,908 | null | 299 | 299 |
import math
n = int(input())
x = [int(i) for i in input().split()]
y = [int(j) for j in input().split()]
p_1 = p_2 = p_3 = p_m = 0
for i in range(n):
diff = math.fabs(x[i]-y[i])
p_1 += diff
p_2 += diff*diff
p_3 += diff*diff*diff
if p_m < diff:
p_m = diff
p_2 = math.sqrt(p_2)
p_3 = math.pow(p_3, 1/3)
print('%.5f\n%.5f\n%.5f\n%.5f'% (p_1, p_2, p_3, p_m)) | #!/usr/bin/env python3
import sys
import collections
input = sys.stdin.readline
def ST():
return input().rstrip()
def I():
return int(input())
def MI():
return map(int, input().split())
def LI():
return list(MI())
N = I()
A = LI()
A.sort()
cnt = collections.Counter(A)
end = A[-1] + 1
for a in A:
if cnt[a] >= 2:
del cnt[a]
for i in range(a * 2, end, a):
del cnt[i]
print(sum(cnt.values()))
| 0 | null | 7,332,490,503,712 | 32 | 129 |
# coding: utf-8
# Here your code !
def func():
try:
line = input()
except:
print("input error")
return -1
marks = ("S","H","C","D")
cards = []
while(True):
try:
line = input().rstrip()
elements = line.split(" ")
if(elements[0] in marks):
elements[1]=int(elements[1])
cards.append(elements)
else:
print("1input error")
return -1
except EOFError:
break
except :
print("input error")
return -1
result=""
for mark in marks:
for i in range(1,14):
if([mark,i] not in cards):
result += mark+" "+str(i)+"\n"
if(len(result)>0):
print(result.rstrip())
func() | if __name__ == '__main__':
a, b, c = [int(i) for i in input().split()]
ans = [1 if c % i == 0 else 0 for i in range(a, b + 1)]
print(sum(ans)) | 0 | null | 801,585,075,620 | 54 | 44 |
x=int(raw_input())
print x*x*x | N=int(input())
lis=[chr(i) for i in range(97, 97+26)]
ans=''
while N>0:
N-=1
ans+=lis[N%26]
N=N//26
print(ans[::-1]) | 0 | null | 6,026,815,263,810 | 35 | 121 |
import math
import sys
n = int(input())
found = False
if(n <= 12):
print(n)
sys.exit()
for y in range(n):
if n == math.floor(y*1.08):
print(y)
found = True
break
if (found == False):
print(":(")
| n = int(input())
for i in range(1,50000):
if int(i*1.08)==n:
print(i)
exit()
else:
print(":(")
| 1 | 126,427,292,866,992 | null | 265 | 265 |
MAXN = 45
fibs = [-1] * MAXN
def fib(n):
"""Returns n-th fibonacci number
>>> fib(3)
3
>>> fib(10)
89
>>> fib(20)
10946
"""
if n == 0:
return 1
elif n == 1:
return 1
elif fibs[n] == -1:
fibs[n] = fib(n-1) + fib(n-2)
return fibs[n]
def run():
n = int(input())
print(fib(n))
if __name__ == '__main__':
run()
| def Fibonacci(n):
if n == 0 or n == 1:
dic[n] = 1
if n in dic.keys():
return dic[n]
dic[n] = Fibonacci(n-1) + Fibonacci(n-2)
return dic[n]
a = int(input())
dic ={}
print(Fibonacci(a))
| 1 | 1,844,671,780 | null | 7 | 7 |
import math
r = float(float(input())) #??´??°??§?????????????????\???????????¨??? int?????????????????????????????????
#menseki
a = r*r*math.pi
#ensyu
b = 2*r*math.pi
print("%.6f %.6f" % (a, b)) | n=int(input())
def m_div(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
divisors.sort()
return divisors
def check(num,k):
if k==1:
return False
while num>=k:
if num%k==0:
num=num//k
else:
break
num%=k
return num==1
n1divs = m_div(n-1)
ndivs = m_div(n)
ans=[]
for num in n1divs:
if check(n,num):
ans.append(num)
for num in ndivs:
if check(n,num):
ans.append(num)
print(len(set(ans))) | 0 | null | 20,914,549,568,210 | 46 | 183 |
def main():
n = [x for x in input().split(' ')]
s = []
for i in n:
if i == '+':
a = s.pop()
b = s.pop()
s.append(a + b)
elif i == '-':
b = s.pop()
a = s.pop()
s.append(a - b)
elif i == '*':
a = s.pop()
b = s.pop()
s.append(a * b)
else:
s.append(int(i))
print(s.pop())
if __name__ == '__main__':
main() | S = []
A = raw_input().split()
for i in range(len(A)):
if A[i] == '+':
S.append(int(S.pop()) + int(S.pop()))
elif A[i] == '-':
S.append(-int(S.pop()) + int(S.pop()))
elif A[i] == '*':
S.append(int(S.pop()) * int(S.pop()))
else:
S.append(A[i])
print S[0] | 1 | 36,641,586,200 | null | 18 | 18 |
n, m = map(int, input().split())
D = list(map(int, input().split()))
INF = int(1e18)
# dp[i]: i円をDで支払うときの最小枚数
dp = [INF] * (n + 1)
dp[0] = 0
for i in range(1, n + 1):
for d in D:
if i - d >= 0:
dp[i] = min(dp[i], dp[i - d] + 1)
else:
dp[i] = dp[i]
print(dp[n])
| n, m = map(int, input().split())
c = list(map(int, input().split()))
INF = 10**9
MAX = n + 1
dp = [INF for _ in range(MAX)]
dp[0] = 0
for i in range(m):
for j in range(len(dp)):
if j + c[i] < MAX:
dp[j+c[i]] = min(dp[j] + 1, dp[j+c[i]])
min_v = dp[-1]
for i in range(len(dp)):
idx = len(dp) - 1 - i
min_v = min(min_v, dp[idx])
dp[idx] = min_v
print(dp[n])
| 1 | 142,485,643,370 | null | 28 | 28 |
import sys
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
class BIT:
def __init__(self, L):
self.n = len(L)
self.bit = [0] * (self.n + 1)
def update(self, idx, x):
while idx <= self.n:
self.bit[idx] += x
idx += idx & (-idx)
def query(self, idx):
res = 0
while idx > 0:
res += self.bit[idx]
idx -= idx & (-idx)
return res
def sec_sum(self, left, right):
return self.query(right) - self.query(left - 1)
def debug(self):
print(*[self.sec_sum(i, i) for i in range(1, self.n + 1)])
def resolve():
n = int(input())
S = list(input().rstrip())
q = int(input())
bits = [BIT(S) for _ in range(26)]
for idx in range(1, n + 1):
s = S[idx - 1]
bits[ord(s) - ord("a")].update(idx, 1)
for _ in range(q):
query = list(input().split())
if query[0] == "1":
i, c = int(query[1]), query[2]
prev = S[i - 1]
bits[ord(prev) - ord("a")].update(i, -1)
bits[ord(c) - ord("a")].update(i, 1)
S[i - 1] = c
else:
l, r = int(query[1]), int(query[2])
res = 0
for j in range(26):
if bits[j].sec_sum(l, r):
res += 1
print(res)
if __name__ == '__main__':
resolve()
| # coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
import copy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)
def lcm(a, b): return a * b / gcd(a, b)
# 1 2 3
# a, b, c = LI()
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# a = I()
def I(): return int(sys.stdin.buffer.readline())
# abc def
# a, b = LS()
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# a = S()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# 2
# 1
# 2
# [1, 2]
def IR(n): return [I() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]
def LIR(n): return [LI() for i in range(n)]
# 2
# abc
# def
# [abc, def]
def SR(n): return [S() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]
def LSR(n): return [LS() for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]
def SRL(n): return [list(S()) for i in range(n)]
n = I()
a = LI()
mx = max(a)
table = [0] * (mx + 1) # num of factors
for x in a:
table[x] += 1
g = 0
# check
for x in a:
g = gcd(g, x)
for i in range(2, mx + 1):
c = 0
# 因数iの倍数がaにいくつ含まれるか(c)
for j in range(i, mx + 1, i):
c += table[j]
# cが2以上=iの倍数となるaが複数存在する
if c > 1:
if g == 1:
print("setwise coprime")
else:
print("not coprime")
exit(0)
print("pairwise coprime")
| 0 | null | 33,078,741,939,940 | 210 | 85 |
# 10^100のクソデカ数値がクソデカすぎるため、+0,+1..+Nが束になってもいたくも痒くもない
# なのでもはや無視していい
# 最初の例でいうと、2つ選ぶのは[0,1,2,3]からなので、和のバリエーションは最小値1~最大値5の5つ
# 3つ選ぶのは最小値3~最大値6の4つ
# 4つ選ぶのは1つ
# 毎回最大値と最小値を計算して差+1を加えてやるとできあがり
# 計算には数列の和を使う
n, k = map(int, input().split())
mod = 10**9 + 7
ans = 1
for i in range(k, n + 1):
# 初項0,公差1,末項i-1までの和
min_s = i * (i - 1) // 2
# 初項n+1-i, 公差1, 末項i-1までの和
max_s = i * (2 * (n + 1 - i) + (i - 1)) // 2
ans += max_s - min_s + 1
ans %= mod
print(ans)
| S,W = map(int,input().split())
print(("safe","unsafe")[W >= S]) | 0 | null | 31,372,627,276,200 | 170 | 163 |
a = int(input())
c=0
for i in range(a + 1):
if bool(i%3!=0 and i % 5 != 0):
c += i
print(c) | sm=0
for i in range(1,int(input())+1):
if (i%3)*(i%5)>0:
sm+=i
print(sm) | 1 | 34,860,881,173,328 | null | 173 | 173 |
n = int(input())
a = 100000
while n>0:
a *= 1.05
if a % 1000 != 0:
a = int(a + 1000 - (a%1000))
n -= 1
print(a) | #!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
n = int(sys.stdin.readline())
debt = 100000
for i in range(n):
debt += debt // 20
fraction = debt % 1000
if fraction > 0:
debt += 1000 - fraction
print(debt) | 1 | 1,176,387,342 | null | 6 | 6 |
N=int(input())
alp=["a","b","c","d","e","f","g","h","i","j"]
alp=alp[:N]
ans=[]
def dfs(now):
if len(now)==N:
ans.append(now)
return
for i,s in enumerate(alp):
if len(set(now))>=i:
next_s=now+s
dfs(next_s)
dfs("a")
ans=sorted(ans)
for a in ans:
print(a)
| def modinv(a,m):
return pow(a,m-2,m)
n,k = map(int,input().split())
P = 10**9+7
ans = 1
nCl = 1
n1Cl = 1
for l in range(1,min(k+1,n)):
nCl = nCl*(n+1-l)*modinv(l,P)%P
n1Cl = n1Cl*(n-l)*modinv(l,P)%P
ans = (ans+nCl*n1Cl)%P
print(ans)
| 0 | null | 59,387,890,793,362 | 198 | 215 |
N = int(raw_input())
A = map(int, raw_input().split())
i = 0
flag = 1
while flag:
flag = 0
for j in range(N-1, 0, -1):
if A[j] < A[j-1]:
A_j = A[j]
A[j] = A[j-1]
A[j-1] = A_j
flag = 1
i += 1
print " ".join(map(str, A))
print i | # -*- coding: utf-8 -*-
def bubbleSort(A, N):
flag = True # 未ソートの可能性があるか
i = 0 # 未ソート部分の先頭
inv_num = 0 # 転倒数
while flag:
flag = False
for j in range(N - 1, i, -1):
if A[j] < A[j - 1]:
A[j], A[j - 1] = A[j - 1], A[j]
flag = True
inv_num += 1
i += 1
return A, inv_num
if __name__ == '__main__':
N = int(input())
A = [int(a) for a in input().split(" ")]
A, inv_num = bubbleSort(A, N)
print(" ".join(map(str, A)))
print(inv_num)
| 1 | 15,519,042,460 | null | 14 | 14 |
while True:
s = input().rstrip().split(' ')
a = int(s[0])
b = int(s[2])
op = s[1]
if op == "?":
break
elif op == "+":
print(str(a + b))
elif op == "-":
print(str(a - b))
elif op == "*":
print(str(a * b))
elif op == "/":
print(str(int(a / b))) | a = int(input())
b_list = list(map(int, input().split()))
count = 0
mini=a
for i in range(len(b_list)):
if b_list[i] <= mini:
count += 1
mini = b_list[i]
print(count) | 0 | null | 43,115,427,242,052 | 47 | 233 |
#!/usr/bin/env python3
X = int(input())
for i, v in enumerate([1800, 1600, 1400, 1200, 1000, 800, 600, 400]):
if X >= v:
print(i + 1)
break
| N,M = map(int,input().split())
A = [0]*M
B = [0]*M
for i in range(M):
A[i],B[i] = map(int,input().split())
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
uf = UnionFind(N)
for i in range(M):
uf.union(A[i]-1,B[i]-1)
answer = 1
uflist = uf.parents
for i in range(N):
time = uf.size(uflist[i])
answer = max(time,answer)
print(answer) | 0 | null | 5,336,979,381,540 | 100 | 84 |
m = input()
c = m[-1]
if c == 's':
print(m+'es')
else:
print(m+'s') | n = int(input())
if n % 1000 == 0:
if n > 1000:
print(0)
else:
print(1000 - n)
else:
k = n % 1000
print(1000 - k) | 0 | null | 5,461,473,528,322 | 71 | 108 |
import math
n= int(input())
x=n+1
for i in range(2,int(math.sqrt(n)+1)):
if n%i==0:
x= i+ (n/i)
print(int(x)-2) | ans = list(map(int, input().split(' '))).index(0) + 1
print(ans) | 0 | null | 87,628,410,897,920 | 288 | 126 |
N = int(raw_input())
nums = map(int, raw_input().split(" "))
count = 0
for i in range(0, len(nums)):
for j in range(len(nums)-1, i, -1):
if nums[j-1] > nums[j]:
temp = nums[j-1]
nums[j-1] = nums[j]
nums[j] = temp
count += 1
nums = map(str, nums)
print(" ".join(nums))
print(count) | import math
#n個からr個とるときの組み合わせの数
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
S = int(input())
ans = 0
mod = 10 ** 9 + 7
for i in range(1,S // 3 + 1): #長さiの数列のとき
x = S - 3 * i #3を分配後の余り
ans += (combinations_count(x + i - 1, i - 1)) % mod #重複組み合わせを足す
ans %= mod
print(ans)
| 0 | null | 1,634,241,136,942 | 14 | 79 |
import sys
#UnionFindTreeクラスの定義
class UnionFind():
#クラスコンストラクタ
#selfはインスタンス自身
def __init__(self, n):
#親ノードを-1に初期化する
self.parents = [-1] * n
#根を探す(再帰関数)
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
#xとyの木を併合する
def union(self, x, y):
#x,yの根をX,Yとする
X = self.find(x)
Y = self.find(y)
#根が同じなら結合済み
if X == Y:
return
#ノード数が多い方をXとする
if self.parents[X] > self.parents[Y]:
X, Y = Y, X
#XにYのノード数を足す
self.parents[X] += self.parents[Y]
#Yの根を X>0 とする
self.parents[Y] = X
N, M = map(int, input().split())
info = [tuple(map(int, s.split())) for s in sys.stdin.readlines()]
#UnionFindインスタンスの生成
uf = UnionFind(N)
for a, b in info:
#インデックスを調整し、a,bの木を結合
a -= 1; b -= 1
uf.union(a, b)
c = 0
for i in range(N):
if uf.parents[i] < 0:
c += 1
print(c-1) | import copy
def main():
N, M, Q = [int(n) for n in input().split(" ")]
q = [[int(a) for a in input().split(" ")] for i in range(Q)]
all_series = get_series(N, M)
points = [0]
for l in all_series:
points.append(get_score(l, q))
print(max(points))
def get_score(l, q):
return sum([q[i][3] if l[q[i][1] - 1] - l[q[i][0] - 1] == q[i][2] else 0 for i in range(len(q))])
def get_series(N, M):
# N: number of elms
# M: upper limit of val of elm
all_series = []
checked = [[0] * M for i in range(N)]
to_check = [[0, j + 1] for j in range(M)]
series = [0 for k in range(N)]
while len(to_check) > 0:
checking = to_check.pop(-1)
series[checking[0]] = checking[1]
if checking[0] == N - 1:
l = copy.deepcopy(series)
all_series.append(l)
else:
to_check.extend([[checking[0] + 1, k] for k in range(checking[1], M + 1)])
return all_series
main() | 0 | null | 14,955,779,865,838 | 70 | 160 |
def reverse_polish_calculator(s):
"""Calculate a reverse polish notation s.
+ - * operators can be used in s. Only positive integer is
supported for operand.
>>> reverse_polish_calculator("1 2 +")
3
>>> reverse_polish_calculator("1 2 + 3 4 - *")
-3
"""
def calc(val1, op, val2):
if op == '+':
return val1 + val2
elif op == '-':
return val1 - val2
elif op == '*':
return val1 * val2
else:
raise ValueError()
stack = []
for c in s.split():
if c.isnumeric():
stack.append(int(c))
else:
v2 = stack.pop()
v1 = stack.pop()
stack.append(calc(v1, c, v2))
return stack.pop()
def run():
s = input()
print(reverse_polish_calculator(s))
if __name__ == '__main__':
run()
| S = input()
print(S.replace('?', 'D'))
| 0 | null | 9,209,151,450,900 | 18 | 140 |
n = map(int,raw_input().split())
for i in range(0,3):
for k in range(i,3):
if n[i]>n[k]:
temp = n[i]
n[i] = n[k]
n[k]= temp
for j in range(0,3):
print str(n[j]), | s=input()
n=len(s)+1
mountain=[0,0]
count=[0,0]
sum=0
for i in range(n-1):
if s[i]=="<":
mountain[1]+=1
else:
if mountain[1]>0:
sum+=(mountain[0]*(mountain[0]-1)+mountain[1]*(mountain[1]+1))//2+max([0,mountain[0]-count[1]])
count=mountain
mountain=[1,0]
else:
mountain[0]+=1
sum+=(mountain[0]*(mountain[0]-1)+mountain[1]*(mountain[1]+1))//2+max([0,mountain[0]-count[1]])
print(sum)
| 0 | null | 78,226,635,389,370 | 40 | 285 |
import math
import numpy
a,b,c = map(int, input().split())
d = c - a - b
if d > 0 and d*d > 4 * a * b:
print("Yes")
else:
print("No")
| from decimal import Decimal
a,b,c=[Decimal(int(i)) for i in input().split()]
l=a.sqrt()+b.sqrt()
r=c.sqrt()
print("Yes" if l < r else "No")
| 1 | 51,326,537,548,220 | null | 197 | 197 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.