code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 6.82M
181,637B
⌀ | question_pair_id
float64 101M
180,471B
⌀ | code1_group
int64 2
299
| code2_group
int64 2
299
|
---|---|---|---|---|---|---|
N = int(input())
s = {}
t = []
for i in range(N):
st = input().split()
s[st[0]] = i
t.append(int(st[1]))
X = input()
print(sum(t[s[X]+1:]))
|
# import bisect
# from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math
import sys
# import numpy as np
ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
n = int(input())
s = [0] * n
t = [0] * n
for i in range(n):
s[i], t[i] = input().split()
t[i] = int(t[i])
x = input()
idx = s.index(x)
ans = 0
for i in range(idx+1, n):
ans += t[i]
print(ans)
if __name__ == '__main__':
main()
| 1 | 97,015,065,754,460 | null | 243 | 243 |
def main():
H1, M1, H2, M2, K = map(int, input().split())
ans = max((H2 * 60 + M2) - (H1 * 60 + M1) - K, 0)
print(ans)
if __name__ == "__main__":
main()
|
a = list(map(int, input().split()))
b = (a[2] * 60 + a[3]) - (a[0] * 60 + a[1])
print(b - a[4])
| 1 | 18,216,788,453,800 | null | 139 | 139 |
import math
r = input()
l = math.pi*r*2.0
s = r*r*math.pi
print "%f %f" %(s, l)
|
x=int(input())
a=x//500
rem=x%500
b=rem//5
ans=a*1000+b*5
print(ans)
| 0 | null | 21,639,538,024,718 | 46 | 185 |
x = int(input())
import math
def check(n):
if n == 1: return False
for i in range(2, int(math.sqrt(n)) + 1):
if n % i == 0:
return False
return True
n = x
while check(n) == False:
n += 1
print(n)
|
import sys
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
N,P = map(int,S().split())
S = LI2()
if P == 2 or P == 5: #10と素でない場合一番右の桁で決まる
ans = 0
for i in range(N):
if S[i] % P == 0:
ans += i+1
print(ans)
exit()
A = [0] #A[i] = 下i桁をPで割った余り
for i in range(1,N+1):
A.append((A[i-1]+pow(10,i,P)*S[N-i]) % P)
from collections import Counter
c = Counter(A)
B = c.values()
ans = 0
for i in B:
ans += (i*(i-1)//2)
print(ans)
| 0 | null | 81,567,430,484,748 | 250 | 205 |
input()
S = set(input().split())
input()
T = set(input().split())
print(len(S & T))
|
n = int(raw_input())
S = map(int, raw_input().split())
q = int(raw_input())
T = map(int, raw_input().split())
ans = 0
for i in T:
if i in S:
ans += 1
print ans
| 1 | 69,828,748,168 | null | 22 | 22 |
import sys
import bisect
stdin = sys.stdin
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))
def naa(N): return [na() for _ in range(N)]
def ns(): return stdin.readline().rstrip() # ignore trailing spaces
N, M = na()
A_array = na()
A_array.sort()
hap_min = 0
hap_max = 3 * (10 ** 5)
while(hap_max - hap_min > 1):
hap = (hap_min + hap_max) // 2
cnt = 0
for a in A_array:
idx = bisect.bisect_left(A_array, hap - a)
cnt += N - idx
# print(hap, hap_max, hap_min, cnt)
if cnt >= M:
hap_min = hap
else:
hap_max = hap
hap = hap_min
# print(hap)
cnt_array = [0] * N
sum_array = [0] * N
for i, a in enumerate(A_array):
idx = bisect.bisect_left(A_array, hap - a)
cnt_array[i] = N - idx
if idx != N:
sum_array[idx] += 1
# print(cnt_array, sum_array)
ans = 0
cusum = 0
cntsum = 0
for a, c, s in zip(A_array, cnt_array, sum_array):
cusum += s
cntsum += c
ans += a * (cusum + c)
print(ans - (cntsum - M) * hap)
|
N = int(input())
# Nを 1以上 9以下の 2つの整数の積として表すことができるなら Yes を、できないなら No を出力せよ。
for i in range(1, 9+1):
for j in range(1, 9+1):
if i * j == N:
print("Yes")
exit()
else:
print("No")
| 0 | null | 133,991,712,672,068 | 252 | 287 |
i = input()
a = int(i)//2
b = int(i)%2
print(a+b)
|
N=int(input())
A=N//2+N%2
print(A)
| 1 | 58,832,820,680,698 | null | 206 | 206 |
from collections import Counter
S1 = input()
K = int(input())
S1C = Counter(S1)
if len(S1C) == 1:
print(len(S1) * K // 2)
exit()
start = S1[0]
end = S1[-1]
now = S1[0]
a1 = 0
flag = False
for s in S1[1:]:
if flag:
flag = False
now = s
continue
else:
if s == now:
a1 += 1
flag = True
now = s
S2 = S1 + S1
start = S2[0]
end = S2[-1]
now = S2[0]
a2 = 0
flag = False
for s in S2[1:]:
if flag:
flag = False
now = s
continue
else:
if s == now:
a2 += 1
flag = True
now = s
b = a2 - 2 * a1
print(a1 * K + b * (K-1))
|
#!/usr/bin/env python3
import sys
from itertools import chain
YES = "Yes" # type: str
NO = "No" # type: str
def solve(H: int, N: int, A: "List[int]"):
if H <= sum(A):
return YES
else:
return NO
def main():
tokens = chain(*(line.split() for line in sys.stdin))
H = int(next(tokens)) # type: int
N = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
answer = solve(H, N, A)
print(answer)
if __name__ == "__main__":
main()
| 0 | null | 126,747,210,827,262 | 296 | 226 |
a = [input().split() for l in range(3)]
n = int(input())
b = list(input() for i in range(n))
c = [[0] * 3 for i in range(3)]
for i in range(n):
for j in range(3):
for k in range(3):
if b[i] == a[j][k]:
c[j][k] = 1
if (c[0][0] == 1 and c[0][1] == 1 and c[0][2] == 1) or(c[1][0] == 1 and c[1][1] == 1 and c[1][2] == 1) or(c[2][0] == 1 and c[2][1] == 1 and c[2][2] == 1) or(c[0][0] == 1 and c[1][0] == 1 and c[2][0] == 1) or(c[0][1] == 1 and c[1][1] == 1 and c[2][1] == 1) or(c[0][2] == 1 and c[1][2] == 1 and c[2][2] == 1) or(c[0][0] == 1 and c[1][1] == 1 and c[2][2] == 1) or (c[0][2] == 1 and c[1][1] == 1 and c[2][0] == 1):
print("Yes")
else:
print("No")
|
a = []
for i in range(3):
a.extend(list(map(int,input().split())))
n = int(input())
b = []
cnt=[]
pattern=[[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]
for i in range(n):
b.append(int(input()))
for j , x in enumerate(a):
if x == b[i]:
cnt.append(j)
for q,w,e in pattern:
if q in cnt and w in cnt and e in cnt:
print('Yes')
break
else:
print('No')
| 1 | 59,596,486,956,740 | null | 207 | 207 |
import math
def merge(S, left, mid, right) -> int:
# n1 = mid - left
# n2 = right - mid
L = S[left: mid]
R = S[mid: right]
# for i in range(n1):
# L.append(S[left + i])
L.append(math.inf)
# for i in range(n2):
# R.append(S[mid + i])
R.append(math.inf)
i = 0
j = 0
for k in range(left, right):
if L[i] <= R[j]:
S[k] = L[i]
i += 1
else:
S[k] = R[j]
j += 1
return right - left
def merge_sort(S, left, right):
count = 0
if left + 1 < right:
mid = int((left + right) / 2)
count += merge_sort(S, left, mid)
count += merge_sort(S, mid, right)
count += merge(S, left, mid, right)
return count
def main():
n = int(input())
S = list(map(int, input().split()))
count = 0
count = merge_sort(S, 0, n)
print(*S)
print(count)
if __name__ == "__main__":
main()
|
import itertools
def solve():
s, t = input().split()
return t+s
print(solve())
| 0 | null | 51,874,982,316,460 | 26 | 248 |
def resolve():
import math
print(2*math.pi*int(input()))
if '__main__' == __name__:
resolve()
|
a=float(input())
print(a*2*3.1415926)
| 1 | 31,507,877,381,858 | null | 167 | 167 |
N = int(input())
st = []
for _ in range(N):
s,t = map(str,input().split())
st.append((s,int(t)))
X = input()
ans = 0
flag = False
for s,t in st:
if flag:
ans += t
if s == X:
flag = True
print(ans)
|
n=int(input())
a=[list(input().split()) for _ in range(n)]
x=input()
s=0
for i in range(n):
if a[i][0]==x:
p=i
break
for i in range(p+1,n):
s+=int(a[i][1])
print(s)
| 1 | 97,086,693,471,350 | null | 243 | 243 |
n = int(input())
ns = [int(i) for i in input().split()]
ns.reverse()
if len(ns) > n:
del ns[:(len(ns) - n)]
for i in ns:
if i != ns[-1]:
print(i,end=' ')
else:
print(i,end='')
print()
|
n = input()
a = list(map(lambda x : int(x), input().split(" ")))
for i, a_ in enumerate(reversed(a)):
if i == 0:
print("%d" % a_, end="")
else:
print(" %d" % a_, end="")
print()
| 1 | 982,763,273,518 | null | 53 | 53 |
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
List=[list(map(int,input().split())) for i in range(M)]
minn=min(a)+min(b)
for i in range(M):
minn=min(minn,a[List[i][0]-1]+b[List[i][1]-1]-List[i][2])
print(minn)
|
S = input()
count = 0
max = 0
for i in range(3):
if S[i] == 'R':
count += 1
if max < count:
max = count
else:
count = 0
print(max)
| 0 | null | 29,506,087,170,252 | 200 | 90 |
#!/usr/bin/env python3
#E
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()))
"""
[本番中]
全体から引くことを考えていたが, 考えることが多く解けなかった
[解説AC]
Ai=0かつBi=0は他の全てと仲が悪いので, 単体で用いるしかない(最後に足す)
Ai*Aj + Bi*Bj = 0の式から内積が思い浮かぶ
仲が悪いペアはAi*Bi >= 0 と Aj*Bj <= 0の場合しかないことがわかる
X: Ai*Bi > 0の場合の(|Ai|, |Bi|)の数
y: Ai*Bi < 0の場合の(|Bi|, |Ai|)の数とすると,
xとyで同じ(A, B)のペアがあると仲が悪い可能性がある
この場合, 以下の3通りのみ使用できる
xのみで使用(少なくとも1つ) or yのみで使用(少なくとも1つ) or xもyも使用しない
つまり, 2**x[(A, B)] - 1 + 2**y[(A, B)] -1 + 1 = 2**x[(A, B)] + 2**y[(A, B)] - 1
これらの積をとり, 最後に全て使用しなかった場合の1を引いた値が答え(最後に(A,B)=(0,0)を足す必要がある)
"""
n = I()
ab = [LI() for _ in range(n)]
x = defaultdict(lambda : 0)
y = defaultdict(lambda : 0)
z = defaultdict(lambda : 0)
tmp = 0
for a, b in ab:
if a == 0 and b == 0:
tmp += 1
elif a == 0:
x[0] += 1
z[0] = 1
elif b == 0:
y[0] += 1
z[0] = 1
else:
if a * b > 0:
g = math.gcd(a, b)
a //= g
b //= g
x[(abs(a), abs(b))] += 1
z[(abs(a), abs(b))] = 1
else:
g = math.gcd(a, b)
a //= g
b //= g
y[(abs(b), abs(a))] += 1
z[(abs(b), abs(a))] = 1
ans = 1
for i in z.keys():
ans *= (2**x[i] + 2**y[i] - 1)
ans %= mod
ans -= 1
ans += tmp
ans %= mod
print(ans)
|
from math import gcd
n = int(input())
ration = dict()
used = dict()
for _ in range(n):
a, b = map(int, input().split())
if a == 0 or b == 0:
if a == b == 0:
r = '0'
elif a == 0:
r = '0a'
else:
r = '0b'
else:
s = '-' if (a < 0) ^ (b < 0) else '+'
a = abs(a)
b = abs(b)
g = gcd(a, b)
r = f'{s} {a//g} {b//g}'
ration[r] = ration.get(r, 0) + 1
used[r] = 0
res = 1
mod = 10**9+7
add = 0
for k, v in ration.items():
if used[k]:
continue
if k == '0':
add += v
used[k] = 1
elif k == '0a' or k == '0b':
res *= 2**ration.get('0a', 0) + 2**ration.get('0b', 0) - 1
used['0a'] = used['0b'] = 1
else:
r = k.split()
l = f'{"-" if r[0]=="+" else "+"} {r[2]} {r[1]}'
res *= 2**v + 2**ration.get(l, 0) - 1
used[k] = used[l] = 1
res %= mod
res += add
res -= 1
if res < 0:
res += mod
print(res)
| 1 | 20,952,687,065,594 | null | 146 | 146 |
import random
import numpy as np
D=int(input())
C=np.array(list(map(int,input().split())))
S=[]
for _ in range(D):
S.append(list(map(int,input().split())))
l=np.zeros(26,int)
def decrease(d):
return np.dot(C,(d-l))
def pick(i,l):
diff=[]
ll=l.copy()
for j in range(26):
ll[j]=i
diff.append(S[i][j]-decrease(i))
return np.argmax(diff)+1
for i in range(D):
p=pick(i,l)
print(p)
l[p-1]=i+1
|
a,b = input().split()
t = a*int(b)
q = b*int(a)
if t < q:
print(t)
else:
print(q)
| 0 | null | 47,132,068,470,722 | 113 | 232 |
A, B = map(int, input().split())
print(max([0, A-2*B]))
|
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
N = int(input())
A = list(map(int, input().split()))
count = 0
pos = 1
for i, a in enumerate(A):
if a == pos:
pos += 1
else:
count += 1
if count <= N - 1:
print(count)
else:
print(-1)
| 0 | null | 140,693,824,010,322 | 291 | 257 |
a, b, c, d = map(int,input().split())
flag = True
while a > 0 and c > 0:
c -= b
if c <= 0:
flag = True
break
a -= d
if a <= 0:
flag = False
break
if flag:
print('Yes')
else:
print('No')
|
# -*- coding: utf-8 -*-
# モジュールのインポート
import itertools
# 標準入力を取得
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
# 求解処理
p = 0
q = 0
order = 1
for t in itertools.permutations(range(1, N + 1), N):
if t == P:
p = order
if t == Q:
q = order
order += 1
ans = abs(p - q)
# 結果出力
print(ans)
| 0 | null | 65,214,818,475,158 | 164 | 246 |
import sys
input = sys.stdin.readline
mod = 10**9 + 7
def main():
n = int(input())
A = list(map(int, input().split()))
candidates = [0] * (n+1)
candidates[0] = 3
ans = 1
for a in A:
ans *= candidates[a]
ans %= mod
candidates[a] -= 1
candidates[a+1] += 1
print(ans)
if __name__ == "__main__":
main()
|
li =[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
a=int(input())
a-=1
print(li[a])
| 0 | null | 89,766,725,467,740 | 268 | 195 |
s = input()
p = input()
p_len = len(p)
if p in s:
print("Yes")
else:
for i in range(p_len):
if (p[:i] == s[-i:]) and (p[i:] == s[:p_len - i]):
print("Yes")
break
else:
print("No")
|
n = input()
n2 = n * 2
x = input()
if x in n2:
print('Yes')
else: print('No')
| 1 | 1,731,162,162,560 | null | 64 | 64 |
t = int(input())
if t >= 30:
print('Yes')
else:
print('No')
|
if int(input()) >= 30:print('Yes')
else:print('No')
| 1 | 5,735,780,976,160 | null | 95 | 95 |
while True:
a, b, c = input().split()
a = int(a)
c = int(c)
if b == "+":
print(a + c)
elif b == "-":
print(a - c)
elif b == '*':
print(a * c)
elif b == '/':
print(a // c)
else:
break
|
if __name__ == '__main__':
while True:
key_in = input()
data = key_in.split(' ')
a = int(data[0])
op = data[1]
b = int(data[2])
if op == '+':
print('{0}'.format(a + b))
if op == '-':
print('{0}'.format(a - b))
if op == '*':
print('{0}'.format(a * b))
if op == '/':
print('{0}'.format(a // b))
if op == '?':
break
| 1 | 680,457,477,180 | null | 47 | 47 |
import math, cmath
def koch(p1, p2, n):
if n == 0:
return [p1, p2]
rad60 = math.pi/3
v1 = (p2 - p1)/3
v2 = cmath.rect(abs(v1), cmath.phase(v1)+rad60)
q1 = p1 + v1
q2 = q1 + v2
q3 = q1 + v1
if n == 1:
return [p1,q1,q2,q3,p2]
else:
x1 = koch(p1,q1,n-1)[:-1]
x2 = koch(q1,q2,n-1)[:-1]
x3 = koch(q2,q3,n-1)[:-1]
x4 = koch(q3,p2,n-1)
x = x1 + x2 + x3 + x4
return x
n = int(raw_input())
p1 = complex(0,0)
p2 = complex(100,0)
for e in koch(p1,p2,n):
print e.real,e.imag
|
import math
def kock(n,p1x,p1y,p2x,p2y):
if n==0:
pass
else:
sx=(2*p1x+p2x)/3
sy=(2*p1y+p2y)/3
tx=(p1x+2*p2x)/3
ty=(p1y+2*p2y)/3
ux=(tx-sx)*math.cos(math.pi*1/3)-(ty-sy)*math.sin(math.pi*1/3)+sx
uy=(tx-sx)*math.sin(math.pi*1/3)+(ty-sy)*math.cos(math.pi*1/3)+sy
kock(n-1,p1x,p1y,sx,sy)
print(sx,sy)
kock(n - 1, sx, sy, ux, uy)
print(ux,uy)
kock(n - 1, ux, uy, tx, ty)
print(tx,ty)
kock(n - 1, tx, ty, p2x, p2y)
n=int(input().strip())
zero=0.0
hundred=100.0
print(zero,zero)
kock(n,0,0,100,0)
print(hundred,zero)
| 1 | 127,983,984,002 | null | 27 | 27 |
a, b = input().split()
a = int(a)
b1, b2 = b.split('.')
b3 = int(b1)*100 + int(b2)
print(a*b3//100)
|
M1, D1 = map(int, input().split())
M2, D2 = map(int, input().split())
print(1 if M1 != M2 else 0)
| 0 | null | 70,666,202,136,980 | 135 | 264 |
a, b, c = map(int, input().split())
k = int(input())
for x in range(k + 1):
for y in range(k + 1):
for z in range(k + 1):
if a * 2**x < b * 2**y and b * 2**y < c * 2**z and x + y + z <= k:
print("Yes")
exit()
print("No")
|
S = input()
print('ABC' if S[1]=='R' else 'ARC')
| 0 | null | 15,475,448,716,702 | 101 | 153 |
import sys
def resolve(in_):
H, W, K = map(int, next(in_).split())
# n_choco = ord(b'0')
w_choco = ord(b'1')
S = [[1 if v == w_choco else 0 for v in line.strip()] for line in in_]
# print(f'{H=} {W=} {K=}')
# print(S)
ans = 10000 # > (Hmax - 1) * (Wmax - 1)
choco = [0] * H
choco_temp = [0] * H
for v in range(2 ** (H - 1)):
# print(f'{v:04b}')
ans_temp = sum(1 if v & (0b01 << i) else 0 for i in range(H - 1))
for w in range(W):
index = 0
for h in range(H):
choco_temp[index] += S[h][w]
if v & (0b01 << h):
index += 1
# print(f'b {choco=} {choco_temp=} {ans_temp=}')
if all(a + b <= K for a, b in zip(choco, choco_temp[:index + 1])):
# for i in range(len(choco)):
for i in range(index + 1):
choco[i] += choco_temp[i]
choco_temp[i] = 0
elif max(choco_temp) > K:
ans_temp = 10000
break
else:
# for i in range(len(choco)):
for i in range(index + 1):
choco[i] = choco_temp[i]
choco_temp[i] = 0
ans_temp += 1
if ans_temp >= ans:
break
# print(f'a {choco=} {choco_temp=} {ans_temp=}')
# print(f'{v:09b} {choco=} {ans_temp=}')
ans = min(ans, ans_temp)
for i in range(len(choco)):
choco[i] = 0
choco_temp[i] = 0
return ans
def main():
ans = resolve(sys.stdin.buffer)
print(ans)
if __name__ == '__main__':
main()
|
sel='E'
#A
if sel=='A':
N,M=map(int,input().split())
ans=0
ans+=M*(M-1)//2
ans+=N*(N-1)//2
print(ans)
#B
if sel=='B':
def ispal(s):
for i in range(len(s)//2+1):
if s[i]!=s[-(i+1)]:
return False
return True
S=input()
N=len(S)
if ispal(S) and ispal(S[:(N-1)//2]) and ispal(S[(N+3)//2-1:]):
print('Yes')
else:
print('No')
#C
if sel=='C':
L=int(input())
print((L**3)/27)
#D
if sel=='D':
N=int(input())
A=[int(i) for i in input().split()]
kin=list(set(A))
cnt={}
for k in kin:
cnt[k]=0
for a in A:
cnt[a]+=1
SUM=0
for k in kin:
SUM+=cnt[k]*(cnt[k]-1)//2
for a in A:
if cnt[a]>=2:
print(SUM-cnt[a]+1)
else:
print(SUM)
#E
if sel=='E':
def add(in1, in2):
return [a + b for a, b in zip(in1, in2)]
def split(ar, k, w):
a = 0
if max(max(ar)) > k:
return -1
tm = ar[0]
for i in range(1, w):
tm = add(tm, ar[i])
if max(tm) > k:
a += 1
tm = ar[i]
return a
h, w, k = map(int, input().split())
s = [[int(i) for i in input()] for j in range(h)]
ans = h*w
for i in range(2**(h-1)):
data = []
temp = s[0]
sp = bin(i+2**h)[4:]
for j in range(1, h):
if sp[j-1] == "0":
temp = add(temp, s[j])
else:
data.append(temp)
temp = s[j]
data.append(temp)
ans_ = split([list(x) for x in zip(*data)], k, w)
if ans_ == -1:
continue
ans_ += sp.count("1")
if ans > ans_:
ans = ans_
print(ans)
# #F
# if sel=='F':
# N,S=map(int,input().split())
# A=[int(i) for i in input().split()]
| 1 | 48,717,557,291,672 | null | 193 | 193 |
import sys
import math
input = sys.stdin.readline
A, B = map(int, input().split())
X = A / 0.08
Y = B/0.1
for i in range(math.floor(min(X, Y)), math.ceil(max(X, Y)) + 1):
if int(i * 0.08) == A and int(i * 0.10) == B:
print(i)
exit()
print(-1)
|
import sys
import math
from collections import deque
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
# アルファベットと数字の対応
alp_to_num = {chr(i+97): i for i in range(26)}
ALP_to_num = {chr(i+97).upper(): i for i in range(26)}
num_to_alp = {i: chr(i+97) for i in range(26)}
num_to_ALP = {i: chr(i+97).upper() for i in range(26)}
def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]
def main():
N = NI()
ans = []
def dfs(s, i, max_num):
if i == N:
ans.append(s)
return
for n in range(max_num+2):
dfs(s + num_to_alp[n], i+1, max(max_num, n))
dfs("a", 1, 0)
ans.sort()
for a in ans:
print(a)
if __name__ == "__main__":
main()
| 0 | null | 54,395,776,553,260 | 203 | 198 |
import math
r = float(input())
print("%f %f"%(math.pi*math.pow(r,2),2*math.pi*r))
|
r = float(input())
s = r**2 * 3.14159265359
l = r*2 * 3.14159265359
print(s, l)
| 1 | 646,652,916,154 | null | 46 | 46 |
from collections import deque
S = input()
Q = int(input())
t = []
f = []
c = []
for i in range(Q):
in_ = list(input().split())
if in_[0] == "1":
t.append(1)
f.append(0)
c.append(0)
else:
t.append(2)
f.append(int(in_[1]))
c.append(in_[2])
acc = [0 for _ in range(Q)]
if t[-1] == 1: acc[-1] = 1
for i in reversed(range(Q - 1)):
if t[i] == 1:
acc[i] = acc[i + 1] + 1
else:
acc[i] = acc[i + 1]
if acc[0] % 2 == 0:
ans = deque(S)
else:
ans = deque(S[::-1])
for i in range(Q):
if t[i] == 2:
if (f[i] + acc[i]) % 2 == 1:
ans.appendleft(c[i])
else:
ans.append(c[i])
print("".join(ans))
|
nums = list(map(int , input().split()))
a = nums[0]
b = nums[1]
print(a // b , end = " ")
print(a % b , end = " ")
print("{0:.5f}".format((a / b)))
| 0 | null | 28,870,154,122,788 | 204 | 45 |
#coding:utf-8
#1_7_B 2015.4.5
while True:
n,x = map(int,input().split())
if n == x == 0:
break
count = 0
for i in range(1 , n + 1):
for j in range(1 , n + 1):
if i < j < (x - i - j) <= n:
count += 1
print(count)
|
from itertools import combinations
def main():
while True:
n, x = map(int, input().split())
if (n, x) == (0, 0):
break
ans = 0
for nums in combinations(range(1, n + 1), 3):
if x == sum(nums):
ans += 1
print(ans)
if __name__ == "__main__":
main()
| 1 | 1,298,039,082,912 | null | 58 | 58 |
# ABC172 C - Walking Takahashi
X,K,D=map(int,input().split())
q=abs(X)//D
if q>K:
print(abs(X)-K*D)
else:
if (K-q)%2==0:
print(abs(X)-q*D)
else:
print(abs(abs(X)-(q+1)*D))
|
a,b=map(int,input().split())
for i in range(2000):
if int(i*0.08)==a and int(i*0.1)==b:
print(i)
exit()
print("-1")
| 0 | null | 30,719,109,614,378 | 92 | 203 |
N = int(input())
Z = []
max = 0
for i in range(N):
A = int(input())
Z.append([list(map(int, input().split())) for i in range(A)])
for a in range(2 ** N):
flag = 1
for i in range(N):
if (((a >> i) + 1) & 1):
continue
z = Z[i]
for x in z:
if not (((a >> (x[0] - 1)) + 1 - x[1]) & 1):
flag = 0
break
if flag == 0:
break
if flag == 1:
x = bin(a).count('1')
if x > max:
max = x
print(max)
|
#!/usr/bin/env python
# coding: utf-8
# In[15]:
N = int(input())
xy_list = []
for _ in range(N):
A = int(input())
xy = []
for _ in range(A):
xy.append(list(map(int, input().split())))
xy_list.append(xy)
# In[16]:
ans = 0
for i in range(2**N):
for j,a_list in enumerate(xy_list):
if (i>>j)&1 == 1:
for k,(x,y) in enumerate(a_list):
if (i>>(x-1))&1 != y:
break
else:
continue
break
else:
ans = max(ans, bin(i)[2:].count("1"))
print(ans)
# In[ ]:
| 1 | 121,383,078,393,240 | null | 262 | 262 |
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))
S, T = input().split()
print(T+S)
|
S, T = input().split()
ans = T + S
print(ans)
| 1 | 103,153,074,863,038 | null | 248 | 248 |
import sys
input = sys.stdin.readline
def main():
ans = 'No'
N = int(input())
c = 0
for _ in range(N):
d1, d2 = map(int, input().split())
if d1 == d2:
c += 1
if c >= 3:
ans = 'Yes'
break
else:
c = 0
print(ans)
if __name__ == '__main__':
main()
|
import sys
N = int(input())
D = [list(map(int, input().split())) for _ in range(N)]
now = D[0]
zorome = 0
if now[0] == now[1]:
zorome += 1
else:
zorome = 0
for i in range(1, N):
now = D[i]
if now[0] == now[1]:
zorome += 1
if zorome == 3:
print('Yes')
sys.exit()
else:
zorome = 0
print('No')
| 1 | 2,468,403,032,316 | null | 72 | 72 |
import sys, bisect
N = int(input())
L = list(map(int, sys.stdin.readline().rsplit()))
L.sort()
res = 0
for i in reversed(range(1, N)):
for j in reversed(range(i)):
l = bisect.bisect_left(L, L[i] + L[j])
# r = bisect.bisect_right(L, abs(L[i] - L[j]))
res += l - 1 - i
print(res)
|
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N = int(input())
Ls = list(mapint())
Ls.sort()
from bisect import bisect_left
ans = 0
for i in range(N-2):
for j in range(i+1, N-1):
idx = bisect_left(Ls, Ls[i]+Ls[j])
ans += idx-1-j
print(ans)
| 1 | 172,116,749,751,200 | null | 294 | 294 |
def main():
n = int(input())
a = [0,0]
for i in range(1, n+1):
a[0] += 1
a[1] = a[1] + 1 if i % 2 != 0 else a[1]
print(a[1] / a[0])
if __name__ == '__main__':
main()
|
def main():
n = int(input())
even = n // 2
print(1 - even / n)
if __name__ == "__main__":
main()
| 1 | 177,260,232,000,652 | null | 297 | 297 |
from math import pi
r = float(input())
print("{0:.6f} {1:.6f}".format(float(r*r*pi), float(2*r*pi)))
|
x = int(input())
n = input()
t = "ABC"
c = 0;
for i in range(x-2):
if n[i] == 'A' and n[i+1] =='B' and n[i+2] == 'C':
c+=1
print(c)
| 0 | null | 50,257,558,652,612 | 46 | 245 |
n = int(input())
s = sorted([int(i) for i in input().split()])
for i, v in enumerate(s[0:-1]):
if v == s[i+1]:
print('NO')
exit()
print('YES')
|
N = int(input())
A = [int(i) for i in input().split()]
B = set(A)
b = len(B)
if N == b:
print('YES')
else:
print('NO')
| 1 | 73,792,255,131,774 | null | 222 | 222 |
num_limit = int(input())
num_list = [0] * num_limit
j_limit = int(num_limit ** 0.5)
for j in range(1,j_limit+1):
for k in range(1,j + 1):
for l in range(1,k+1):
if num_limit >= j**2 + k**2 + l**2 + j*k + k*l + l*j:
if j > k:
if k > l:
num_list[j**2 + k**2 + l**2 + j*k + k*l + l*j-1] += 6
else:
num_list[j**2 + k**2 + l**2 + j*k + k*l + l*j-1] += 3
elif k > l:
num_list[j**2 + k**2 + l**2 + j*k + k*l + l*j-1] += 3
else:
num_list[j**2 + k**2 + l**2 + j*k + k*l + l*j-1] += 1
for i in num_list:
print(i)
|
n=int(input())
ans=[0 for i in range(10**5)]
for x in range(1,100):
for y in range(1,100):
for z in range(1,100):
tmp=x*x+y*y+z*z+x*y+y*z+z*x
ans[tmp]+=1
for i in range(1,n+1):
print(ans[i])
| 1 | 8,047,770,665,818 | null | 106 | 106 |
def GSD(x, y):
while True:
x0 = max(x, y)
y0 = min(x, y)
if x0 % y0 == 0:
return y0
x = x0 % y0
y = y0
x, y = map(int, input().split(' '))
print(GSD(x, y))
|
def gcd(x, y):
if x < y:
x, y = y, x
while y > 0:
r = x % y
x = y
y = r
return x
def main():
x, y = (int(n) for n in input().split())
print(gcd(x, y))
main()
| 1 | 8,153,953,110 | null | 11 | 11 |
a = input()
print(a.replace('P?', 'PD').replace('?D', 'PD').replace('??', 'PD').replace('?', 'D'))
|
def main():
t = input()
ans = ''
for c in t:
if c == '?':
ans += 'D'
else:
ans += c
print(ans)
if __name__ == '__main__':
main()
| 1 | 18,359,790,137,370 | null | 140 | 140 |
import sys
if __name__ == '__main__':
a, b, c = map(int, input().split())
print(c, a, b)
|
import sys
dataset = sys.stdin.readlines()
def gcd(a, b):
if b > a: return gcd(b, a)
if a % b == 0: return b
return gcd(b, a % b)
def lcd(a, b):
return a * b // gcd(a, b)
for item in dataset:
a, b = list(map(int, item.split()))
print(gcd(a, b), lcd(a,b))
| 0 | null | 18,929,929,001,632 | 178 | 5 |
x=float(input())
if x>=0 and x<=1:
if x==0:
print(1)
else:
print(0)
|
print('10'[int(input())])
| 1 | 2,942,899,774,540 | null | 76 | 76 |
n=int(input())
st=[]
for i in range(n):
s,t=input().split()
st.append((s,t))
x=input()
flg=False
ans=0
for i in range(n):
if flg:
ans+=int(st[i][1])
if st[i][0]==x:
flg=True
print(ans)
|
N=int(input())
s=list()
t=list()
st=[]
for i in range(N):
st.append(input().split())
X=input()
ans=0
count=False
for j in range(N):
if count:
ans+=int(st[j][1])
if st[j][0]==X:
count=True
print(ans)
| 1 | 97,010,869,112,112 | null | 243 | 243 |
N,K=input().split()
N=int(N)
K=int(K)
p = [int(i) for i in input().split()]
p.sort()
print(sum(p[0:K]))
|
N=int(input())
a=0
ans=float('inf')
x=list(map(int,input().split()))
for i in range(100):
for j in range(N):
a=a+(x[j]-i-1)**2
#print(a)
ans=min(ans,a)
a=0
print(ans)
| 0 | null | 38,597,883,940,280 | 120 | 213 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
class Combination:
def __init__(self, n_max, mod=10**9+7):
# O(n_max + log(mod))
self.mod = mod
f = 1
self.fac = fac = [f]
for i in range(1, n_max+1):
f = f * i % mod
fac.append(f)
f = pow(f, mod-2, mod)
self.facinv = facinv = [f]
for i in range(n_max, 0, -1):
f = f * i % mod
facinv.append(f)
facinv.reverse()
# "n 要素" は区別できる n 要素
# "k グループ" はちょうど k グループ
def __call__(self, n, r): # self.C と同じ
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
def C(self, n, r):
if not 0 <= r <= n:
return 0
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
def P(self, n, r):
if not 0 <= r <= n:
return 0
return self.fac[n] * self.facinv[n-r] % self.mod
def H(self, n, r):
if (n == 0 and r > 0) or r < 0:
return 0
return self.fac[n+r-1] * self.facinv[r] % self.mod * self.facinv[n-1] % self.mod
def rising_factorial(self, n, r): # 上昇階乗冪 n * (n+1) * ... * (n+r-1)
return self.fac[n+r-1] * self.facinv[n-1] % self.mod
def stirling_first(self, n, k): # 第 1 種スターリング数 lru_cache を使うと O(nk) # n 要素を k 個の巡回列に分割する場合の数
if n == k:
return 1
if k == 0:
return 0
return (self.stirling_first(n-1, k-1) + (n-1)*self.stirling_first(n-1, k)) % self.mod
def stirling_second(self, n, k): # 第 2 種スターリング数 O(k + log(n)) # n 要素を区別のない k グループに分割する場合の数
if n == k:
return 1 # n==k==0 のときのため
return self.facinv[k] * sum((-1)**(k-m) * self.C(k, m) * pow(m, n, self.mod) for m in range(1, k+1)) % self.mod
def balls_and_boxes_3(self, n, k): # n 要素を区別のある k グループに分割する場合の数 O(k + log(n))
return sum((-1)**(k-m) * self.C(k, m) * pow(m, n, self.mod) for m in range(1, k+1)) % self.mod
def bernoulli(self, n): # ベルヌーイ数 lru_cache を使うと O(n**2 * log(mod))
if n == 0:
return 1
if n % 2 and n >= 3:
return 0 # 高速化
return (- pow(n+1, self.mod-2, self.mod) * sum(self.C(n+1, k) * self.bernoulli(k) % self.mod for k in range(n))) % self.mod
def faulhaber(self, k, n): # べき乗和 0^k + 1^k + ... + (n-1)^k
# bernoulli に lru_cache を使うと O(k**2 * log(mod)) bernoulli が計算済みなら O(k * log(mod))
return pow(k+1, self.mod-2, self.mod) * sum(self.C(k+1, j) * self.bernoulli(j) % self.mod * pow(n, k-j+1, self.mod) % self.mod for j in range(k+1)) % self.mod
def lah(self, n, k): # n 要素を k 個の空でない順序付き集合に分割する場合の数 O(1)
return self.C(n-1, k-1) * self.fac[n] % self.mod * self.facinv[k] % self.mod
def bell(self, n, k): # n 要素を k グループ以下に分割する場合の数 O(k**2 + k*log(mod))
return sum(self.stirling_second(n, j) for j in range(1, k+1)) % self.mod
n, m, k = map(int, read().split())
mod = 998244353
comb = Combination(n, mod)
ans = 0
n -= 1
for i in range(k + 1):
ans += comb.C(n, n - i) * m * pow(m - 1, n - i, mod) % mod
ans %= mod
print(ans)
|
import sys
input = sys.stdin.readline
m = [1, 1] + [None]*50
def fibonacci(n):
if m[n-2]:
pass
else:
fibonacci(n-2)
if m[n-1]:
pass
else:
fibonacci(n-1)
m[n] = m[n-1] + m[n-2]
N = int(input())
fibonacci(44)
print(m[N])
| 0 | null | 11,491,987,425,002 | 151 | 7 |
# coding:utf-8
# Round-robin scheduling
def main():
n, q = map(int, input().split())
process = []
finished = []
counter = 0
for _ in range(n):
name, time = input().split()
process.append((name, int(time)))
while len(process) > 0:
name, time = process.pop(0)
temp_q = q
while True:
if time <= 0:
finished.append((name, counter))
break
# q????????§??????????¶????????????£???????????????
# time?????´??°??????process???????°?????§????
if temp_q <= 0:
process.append((name, time))
break
time -= 1
temp_q -= 1
counter += 1
for name, time in finished:
print(name, time)
if __name__ == "__main__":
main()
|
from collections import deque
process_num, qms = map(int ,input().split())
que = deque({})
for i in range(process_num):
name, time = input().split()
time = int(time)
que.append({"name":name, "time":time})
if __name__ == '__main__':
total_time = 0
while len(que)>0:
atop = que.popleft()
spend = min(atop["time"], qms)
atop["time"] -= spend
total_time += spend
if(atop["time"] == 0):
print("{} {}".format(atop["name"], total_time))
else:
que.append(atop)
| 1 | 43,952,436,048 | null | 19 | 19 |
H,N=map(int,input().split())
A=map(int,input().split())
if H<=sum(A):
print('Yes')
else:
print('No')
|
import math
def koch(start,end,n):
if n==0:
return
else:
point1=[0,0]
point2=[0,0]
point3=[0,0]
point1[0]=(end[0]-start[0])/3 +start[0]
point1[1]=(end[1]-start[1])/3 +start[1]
point3[0]=(end[0]-start[0])*2/3+start[0]
point3[1]=(end[1]-start[1])*2/3+start[1]
rad60 = math.radians(60)
point2[0]=(point3[0]-point1[0])* math.cos(rad60) -(point3[1]-point1[1])*math.sin(rad60) +point1[0]
point2[1]=(point3[0]-point1[0])* math.sin(rad60) +(point3[1]-point1[1])*math.cos(rad60) +point1[1]
koch(start,point1,n-1)
print(*point1)
koch(point1,point2,n-1)
print(*point2)
koch(point2,point3,n-1)
print(*point3)
koch(point3,end,n-1)
n=int(input())
start=[0,0]
end=[100,0]
print(*start)
if n>0:
koch(start,end,n)
print(*end)
| 0 | null | 38,983,494,875,328 | 226 | 27 |
def insertion_sort(data, g):
global cnt
for i in range(g, len(data)):
v, j = data[i], i - g
while j >= 0 and data[j] > v:
data[j + g] = data[j]
j = j - g
cnt += 1
data[j + g] = v
def shell_sort(data):
global G
for i in range(1, 100):
tmp = (3 ** i - 1) // 2
if tmp > len(data):
break
G.append(tmp)
for g in list(reversed(G)):
insertion_sort(data, g)
G, cnt = [], 0
n = int(input())
data = list(int(input()) for _ in range(n))
shell_sort(data)
print(len(G))
print(' '.join(map(str, list(reversed(G)))))
print(cnt)
print('\n'.join(map(str, data)))
|
N = int(input())
count = 0
for i in range(1, N):
if i < N - i:
count += 1
print (count)
| 0 | null | 76,488,362,072,072 | 17 | 283 |
n, k = map(int, input().split())
mod = 10 ** 9 + 7
dp = [0] * (k + 1)
ans = 0
for i in range(k, 0, -1):
num = k // i
dp[i] += pow(num, n, mod)
for j in range(1, num):
dp[i] -= dp[(j + 1) * i]
ans += i * dp[i]
ans %= mod
print(ans)
|
N=int(input())
A=[int(a) for a in input().split()]
dp=[-1 for _ in range(N)]
dp[0]=1000
for i in range(1,N):
tmp=dp[i-1]
for j in range(i):
K=dp[j]//A[j]
res=dp[j]-K*A[j]
tmp=max(tmp,res+A[i]*K)
dp[i]=tmp
print(dp[-1])
| 0 | null | 22,121,643,067,618 | 176 | 103 |
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
INF = float("inf")
import bisect
N, M = list(map(int, input().split()))
S = input()
m = N
record = []
while True:
for i in range(M,-1,-1):
if i == 0:
print(-1)
sys.exit()
if m-i < 0: continue
if S[m-i] == "0":
m = m - i
record.append(str(i))
if m == 0:
print(" ".join(reversed(record)))
sys.exit()
break
|
import sys
input = sys.stdin.readline
N,M=map(int,input().split());S=input()[:-1]
if S.find("1"*M)>0:
print(-1)
exit()
k=[N+1]*(N+1)
k[0]=N
c=1
for i in range(N-1,-1,-1):
if int(S[i])==0:
if k[c-1]-i <= M:
k[c]=i
else:
c+=1
k[c]=i
print(*[j-i for i,j in zip(k[c::-1],k[c-1::-1])])
| 1 | 138,741,797,340,772 | null | 274 | 274 |
import sys
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
MOD = 10**9+7
N = int(input())
dic = defaultdict(int)
zero = 0
left_zero = 0
right_zero = 0
for i in range(N):
a, b = map(int, input().split())
if b < 0:
a = -a
b = -b
if a == 0 and b == 0:
zero += 1
elif a == 0:
left_zero += 1
elif b == 0:
right_zero += 1
else:
g = math.gcd(a, b)
a //= g
b //= g
dic[a,b] += 1
done = set()
ans = 1
for a,b in dic:
k = (a, b)
if k in done: continue
rk = (-b, a)
rk2 = (b, -a)
done.add(k)
done.add(rk)
done.add(rk2)
c = pow(2, dic[k], MOD)-1
if rk in dic:
c += pow(2, dic[rk], MOD)-1
if rk2 in dic:
c += pow(2, dic[rk2], MOD)-1
c += 1
ans *= c
ans %= MOD
c1 = pow(2, left_zero, MOD)-1
c2 = pow(2, right_zero, MOD)-1
c = c1+c2+1
ans *= c
ans += zero
print((ans-1)%MOD)
|
from collections import defaultdict
import sys
input = sys.stdin.readline
from math import gcd
MOD = 1000000007
dic1 = defaultdict(int)
All_zero = 0
S = set()
N = int(input())
ans = 0 #仲が悪い数を数える
for i in range(N):
a, b = map(int, input().split())
if a == 0 and b == 0: #なんでもOK
All_zero += 1
elif a == 0:
S.add((0, 1))
dic1[(0, 1)] += 1
elif b == 0:
S.add((1, 0))
dic1[(1, 0)] += 1
else:
GCD = gcd(a, b)
a //= GCD
b //= GCD
if a < 0: #aを必ず正にする
a *= -1
b *= -1
S.add((a, b))
dic1[(a, b)] += 1
lst = []
for a, b in S:
tmp11 = dic1[(a, b)]
A = a
B = b
if B <= 0:
B *= -1
A *= -1
tmp2 = dic1[(B, -A)]
# print (a, b, A, B)
dic1[(B, -A)] = 0
if tmp11 > 0:
lst.append((tmp11, tmp2))
# print (lst)
ans = 1
for a, b in lst:
tmp = (pow(2, a, MOD) - 1) + (pow(2, b, MOD) - 1) + 1 #左側を入れる、右側を入れる、両方入れない
ans *= tmp
ans %= MOD
ans = (ans - 1 + All_zero) % MOD
print (ans % MOD)
# print (S)
| 1 | 20,953,910,917,906 | null | 146 | 146 |
n = int(raw_input())
q = []
bottom = 0
for i in range(n):
cmd = raw_input()
if cmd[0] == 'i':
q.append(cmd[7:])
elif cmd[6] == ' ':
try:
q.pop(~q[::-1].index(cmd[7:]))
except:
pass
elif cmd[6] == 'F':
q.pop()
else:
bottom += 1
print(' '.join(q[bottom:][::-1]))
|
import sys
## 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()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
while y: x,y = y,x%y
return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
"""Return a tuple list of divisor of n"""
return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
"""Return a list of prime numbers n or less"""
is_prime = [True]*(MAX_NUM+1)
is_prime[0] = is_prime[1] = False
for i in range(2, int(MAX_NUM**0.5)+1):
if not is_prime[i]: continue
for j in range(i*2, MAX_NUM+1, i): is_prime[j] = False
return [i for i in range(MAX_NUM+1) if is_prime[i]]
def prime_factor(n):
"""Return a list of prime factorization numbers of n"""
res = []
for i in range(2,int(n**0.5)+1):
while n%i==0: res.append(i); n //= i
if n != 1: res.append(n)
return res
## libs ##
from itertools import accumulate as acc, combinations as combi, product, combinations_with_replacement as combi_dup
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#
def main():
n = II()
xl = [MII() for _ in range(n)]
lr_x = [[x-l, x+l] for x, l in xl]
lr_x.sort(key=lambda x: x[1])
now = -(10**9)
cnt = 0
for l, r in lr_x:
if now <= l:
cnt += 1
now = r
print(cnt)
if __name__ == '__main__':
main()
| 0 | null | 44,752,456,422,852 | 20 | 237 |
import math
import sys
import os
from operator import mul
sys.setrecursionlimit(10**7)
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))
if os.getenv("LOCAL"):
inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
sys.stdin = open(inputFile, "r")
INF = float("inf")
D,T,S = LI()
if T < D/S:
ans = 'No'
else:
ans = 'Yes'
print(ans)
|
n = int(input())
def make_divisors(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
p = make_divisors(n)
x = 0
i = 1
ans = 0
def countf(x):
for j in range(1,x+2):
if (1+j)*j//2 > x:
return j - 1
while n != 1:
if n % p[i] == 0:
x += 1
n = n // p[i]
else:
if x != 0:
ans += countf(x)
x = 0
i += 1
ans += countf(x)
print(ans)
| 0 | null | 10,285,153,264,008 | 81 | 136 |
n,k = map(int, input().split())
lag = []
for l in range(n):
lag.append(int(input()))
w_max = 100000*100000
w_min = 0
while w_min < w_max:
w_mid = (w_max + w_min) // 2
tracks = 0
current = 0
for i in range(n):
if lag[i] > w_mid:
tracks = k
break
elif lag[i] + current > w_mid:
tracks += 1
current = lag[i]
else:
current += lag[i]
if tracks < k:
w_max = w_mid
else:
w_min = w_mid + 1
print(w_max)
|
n,k = map(int,input().split())
a = [int(input()) for s in range(n)]
pmax = sum(a)
pmin = pmax//k-1
def check(ptest):
tk = 1
p = 0
global a,k,n
i = 0
while i < n:
p += a[i]
if p <= ptest:
i += 1
else:
tk += 1
p = 0
if tk > k:
return False
return True
while (pmax-pmin) > 1:
pmid = (pmax+pmin)//2
if check(pmid):
pmax = pmid
else:
pmin = pmid
print(pmax)
| 1 | 88,986,994,212 | null | 24 | 24 |
a, b, c, d = map(int, input().split())
ac = a * c
ad = a * d
bc = b * c
bd = b * d
max_a = max(ac, ad)
max_b = max(bc, bd)
print(max(max_a, max_b))
|
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
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)]
h, w = LI()
s = SRL(h)
ans = []
for i in range(h):
for j in range(w):
if s[i][j] == "#":
continue
v = [[-1] * w for _ in range(h)]
q = deque()
q.append((i, j))
v[i][j] = 1
goal = tuple()
while q:
r, c = q.popleft()
for x, y in ((1, 0), (-1, 0), (0, -1), (0, 1)):
if r + x < 0 or r + x > h - 1 or c + y < 0 or c + y > w - 1 or s[r + x][c + y] == "#" or v[r + x][c + y] > 0:
continue
v[r + x][c + y] = v[r][c] + 1
q.append((r + x, c + y))
ans.append(max(chain.from_iterable(v)) - 1)
print(max(ans))
| 0 | null | 48,901,603,889,588 | 77 | 241 |
a = input()
print(chr(((ord(a)-ord("a")+1)%26)+ord("a")))
|
s = input()
print(chr(ord(s)+1))
| 1 | 92,575,249,300,060 | null | 239 | 239 |
from sys import exit
import copy
#import numpy as np
#from collections import deque
d, = map(int, input().split())
c= list(map(int, input().split()))
s=[list(map(int, input().split())) for _ in range(d)]
# t=[int(input()) for _ in range(d)]
sche=[0 for _ in range(d)]
s_tmp=float("inf")*(-1)
for off in range(0,13):
last=[0 for _ in range(26)]
sche=[0 for _ in range(d)]
for day in range(1,d+1):
idx=day-1
d_tmp=float("inf")*(-1)
i_tmp=0
for t in range(26):
delta=0
l_tmp=copy.copy(last)
delta+=s[idx][t]
l_tmp[t]=day
for l in range(26):
delta-=0.5*(off+1)*c[l]*((day-l_tmp[l])+(day+off-l_tmp[l]))
if delta>=d_tmp:
d_tmp=delta
i_tmp=t
sche[idx]=i_tmp+1
# score+=d_tmp
last[i_tmp]=day
# print(score)
# print(i_tmp+1)
score=0
last=[0 for _ in range(26)]
for i in range(1,d+1):
idx=i-1
score+=s[idx][sche[idx]-1]
for l in range(26):
score-=c[l]*(i-last[l])
last[sche[idx]-1]=i
# print(score)
if score>=s_tmp:
s_tmp=score
sche_tmp=copy.copy(sche)
for i in sche_tmp:
print(i)
# print(s_tmp)
|
# 貪欲法 + 山登り法 + スワップ操作
import time
s__ = time.time()
limit = 1.9
#limit = 10
from numba import njit
import numpy as np
d = int(input())
cs = list(map(int, input().split()))
cs = np.array(cs, dtype=np.int64)
sm = [list(map(int, input().split())) for _ in range(d)]
sm = np.array(sm, dtype=np.int64)
@njit('i8(i8[:], i8)', cache=True)
def total_satisfaction(ts, d):
ls = np.zeros(26, dtype=np.int64)
s = 0
for i in range(d):
t = ts[i]
t -= 1
s += sm[i][t]
ls[t] = i + 1
dv = cs * ((i+1) - ls)
s -= dv.sum()
return s
@njit('i8[:]()', cache=True)
def greedy():
ts = np.array([0] * d, dtype=np.int64)
for i in range(d):
mx = -1e10
mxt = None
for t in range(1, 26+1):
ts[i] = t
s = total_satisfaction(ts, i + 1)
if s > mx:
mx = s
mxt = t
ts[i] = mxt
return ts
@njit('i8(i8, i8[:])', cache=True)
def loop(mxsc, ts):
it = 50
rds = np.random.randint(0, 4, (it,))
rdd = np.random.randint(1, d, (it,))
rdq = np.random.randint(1, 26, (it,))
rdx = np.random.randint(1, 12, (it,))
for i in range(it):
bk1 = 0
bk2 = 0
if rds[0] == 0:
# trailing
di = rdd[i]
qi = rdq[i]
bk1 = ts[di]
ts[di] = qi
else:
# swap
di = rdd[i]
xi = rdx[i]
if di + xi >= d:
xi = di - xi
else:
xi = di + xi
bk1 = ts[di]
bk2 = ts[xi]
ts[di] = bk2
ts[xi] = bk1
sc = total_satisfaction(ts, d)
if sc > mxsc:
#print(mxsc, '->', sc)
mxsc = sc
else:
# 最大値を更新しなかったら戻す
if rds[0] == 0:
ts[di] = bk1
else:
ts[di] = bk1
ts[xi] = bk2
return mxsc
ts = greedy()
mxsc = total_satisfaction(ts, d)
mxbk = mxsc
s_ = time.time()
mxsc = loop(mxsc, ts)
e_ = time.time()
consume = s_ - s__
elapsed = e_ - s_
#print('consume:', consume)
#print('elapsed:', elapsed)
if consume < limit:
lp = int((limit - consume)/ elapsed)
#print('loop', lp)
for _ in range(lp):
mxsc = loop(mxsc, ts)
for t in ts: print(t)
#print(mxbk, mxsc)
#print(time.time() - s__)
| 1 | 9,710,575,570,108 | null | 113 | 113 |
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
ans = 0
for i in range(q):
if T[i] in S:
ans += 1
print(ans)
|
def main():
import sys
asa = sys.stdin.readline
n = int(input())
s = list(map(int, asa().split()))
q = int(input())
t = list(map(int, asa().split()))
c = 0
s.append(0)
for i in t: # tの中のiを探索
j = 0
s[n] = i
while s[j] != i:
j += 1
if j < n:
c += 1
print(c)
if __name__ == '__main__':
main()
| 1 | 66,928,154,060 | null | 22 | 22 |
# -*- coding: utf-8 -*-
#整数値龍力 複数の入力
def input_multiple_number():
return map(int, input().split())
N_given,A_given,B_given = input_multiple_number()
cnt = 0
while True:
if (B_given - A_given)%2 == 0:
print(cnt + (B_given-A_given)//2)
exit(0)
else:
if (N_given - B_given) > (A_given-1):
cnt += (A_given-1)
cnt += 1
A_given = 1
B_given -= cnt
else:
cnt += (N_given - B_given)
cnt += 1
B_given = N_given
A_given += cnt
|
import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
N,A,B = MI()
if (B-A) % 2 == 0:
print((B-A)//2)
else:
if B-1 <= N-A:
print((A+B-1)//2)
else:
print(N-(A+B-1)//2)
| 1 | 109,687,949,537,670 | null | 253 | 253 |
print(['No','Yes'][int(input())>=30])
|
x = int(input())
if x < 30:print("No")
else:print("Yes")
| 1 | 5,703,016,552,102 | null | 95 | 95 |
# encoding: utf-8
input = raw_input().split()
stack = []
for n in input:
if(n.isdigit()):
stack.append(int(n))
else:
a = stack.pop()
b = stack.pop()
if n == '+':
stack.append(b + a)
elif n == '-':
stack.append(b - a)
elif n == '*':
stack.append(b * a)
else:
stack.append(b / a)
print stack.pop()
|
N = int(input())
D = list(map(int, input().split()))
DL = [0] * N
mod = 998244353
if D[0] != 0:
print(0)
exit()
for d in D:
DL[d] += 1
if DL[0] != 1:
print(0)
exit()
ans = 1
for i in range(1, N):
if DL[i] == 0:
if sum(DL[i:]) != 0:
print(0)
exit()
else:
print(ans%mod)
exit()
ans *= pow(DL[i-1], DL[i], mod)
ans %= mod
print(ans % mod)
| 0 | null | 77,288,657,075,070 | 18 | 284 |
mod = 10**9 + 7
n = int(input())
dat = list(map(int, input().split()))
cnt0 = [0] * 64
cnt1 = [0] * 64
for i in range(n):
for j in range(62):
if ((dat[i] >> j) & 1) == 1:
cnt1[j] += 1
else:
cnt0[j] += 1
#print(cnt0)
#print(cnt1)
res = 0
for i in range(62):
res += (cnt0[i] * cnt1[i]) << i
res %= mod
print(res)
|
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
x,k,d = map(int, input().split())
x = abs(x)
if x == 0:
if k % 2 == 0:
print(0)
exit()
else:
print(abs(d))
exit()
bai = x//d
if bai >= k:
print(x-k*d)
exit()
else:
x -= bai*d
if (k-bai)%2==0:
print(x)
exit()
else:
print(abs(x-d))
| 0 | null | 64,037,074,222,220 | 263 | 92 |
import sys
input = sys.stdin.readline
def main():
X = int(input())
for A in range(-119, 120 + 1):
for B in range(-119, 120 + 1):
if A ** 5 - B ** 5 == X:
print(A, B)
exit()
if __name__ == "__main__":
main()
|
# your code goes here
import sys
a=[]
for line in sys.stdin:
line.rstrip('rn')
tmp=line.split(" ")
a.append(int(tmp[-1]))
a.sort(reverse=True)
y=0
for i in a:
if y==3:
break
if i>=0 and i<=10000:
print(i)
y=y+1
| 0 | null | 12,691,733,886,744 | 156 | 2 |
n, a, b = [int(i) for i in input().split()]
a,b=max(a,b),min(a,b)
if (a - b) % 2 == 0:
print((a - b) // 2)
else:
c = b + (a -1- b) // 2
d = n - a + 1 + (n - (n - a + 1) - b) // 2
print(min(c,d))
|
def kaibun(lst):
k = len(lst)//2 + len(lst)%2
for i in range(1,k+1):
if lst[i-1] != lst[-i]:
return False
return True
S = list(input())
N = len(S)
if kaibun(S) and kaibun(S[:(N-1)//2]) and kaibun(S[(N+3)//2-1:]):
print('Yes')
else:
print('No')
| 0 | null | 77,855,282,362,912 | 253 | 190 |
#import sys
#sys.setrecursionlimit(10**9)
H, N = map(int, input().split())
magic = [_ for _ in range(N)]
for k in range(N):
magic[k] = list(map(int, input().split()))
magic[k].append(magic[k][0]/magic[k][1])
magic.sort(key = lambda x: x[2], reverse=True)
ans = [0 for _ in range(H+1)]
visited = [0]
anskouho = [float('inf')]
ans2 = float('inf')
"""
def solve(start, power, point, maryoku):
if start == H:
print(min(point, min(anskouho)))
exit()
elif start > H:
anskouho.append(point)
return 0
elif ans[start] != 0:
return 0
else:
visited.append(start)
ans[start] = point
solve(start+power, power, point+maryoku, maryoku)
"""
for k in range(N):
for item in visited:
#solve(item+magic[k][0], magic[k][0], ans[item] + magic[k][1], magic[k][1])
start = item+magic[k][0]
power = magic[k][0]
point = ans[item]+ magic[k][1]
maryoku = magic[k][1]
for _ in range(10**5):
if start == H:
print(min(point, ans2))
exit()
elif start > H:
ans2 = min(ans2, point)
break
elif ans[start]!=0:
break
else:
visited.append(start)
ans[start] = point
start += power
point += maryoku
print(ans2)
|
(h,n),*c=[[*map(int,i.split())]for i in open(0)]
d=[0]*20002
for i in range(h):d[i]=min(d[i-a]+b for a,b in c)
print(d[h-1])
| 1 | 81,018,334,817,856 | null | 229 | 229 |
X = int(input())
A = 100
for i in range(10**5):
A = A*101//100
if X <= A:
break
print(i+1)
|
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
A = int(input())
B = int(input())
for i in range(1, 4):
if i not in (A, B):
print(i)
| 0 | null | 68,772,510,631,738 | 159 | 254 |
n = input()
a = n[-1]
if a in '3':
print('bon')
elif a in '0168':
print('pon')
else:
print('hon')
|
n = int(input()[-1])
if n in [2,4,5,7,9]:
print("hon")
elif n in [0,1,6,8]:
print("pon")
else:
print("bon")
| 1 | 19,198,245,081,380 | null | 142 | 142 |
#-*- coding:utf-8 -*-
def main():
n , data = input_data()
vMax = float('-inf')
vMin = data.pop(0)
for Rj in data:
if vMax < Rj - vMin:
vMax = Rj - vMin
if vMin > Rj:
vMin = Rj
print(vMax)
def input_data():
n = int(input())
lst = [int(input()) for i in range(n)]
return (n , lst)
if __name__ == '__main__':
main()
|
import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
def main():
N = I()
res = 0
for i in range(N):
a,b = MI()
if a==b:
res+=1
if res==3:
print("Yes")
exit()
else:
res=0
print("No")
if __name__ == "__main__":
main()
| 0 | null | 1,251,455,553,500 | 13 | 72 |
def kton(S):
r = 0
m = 0
for s in S:
r += 1 if s == '(' else -1
m = min(m, r)
return r, m
def main():
N = int(input())
RM = [kton(input()) for _ in range(N)]
pos = 0
negp = []
negn = []
posn = []
for r, m in RM:
if m < 0:
if r >= 0:
negp.append((-m, r))
else:
negn.append((-(r-m), -r, m))
else:
pos += r
negp.sort()
for m, r in negp:
if pos - m < 0:
return False
pos += r
negn.sort()
for _, r, m in negn:
if pos + m < 0:
return False
pos -= r
return pos == 0
print('Yes' if main() else 'No')
|
from operator import itemgetter
N = int(input())
def checkNonnegative(brankets):
curup = 0
for (minup , up) in sorted(brankets , key= itemgetter(0) , reverse = True):
if curup + minup < 0:
return False
curup += up
return True
def canArrangeBranket(brankets):
totup = 0
left_brankets = []
right_brankets = []
for branket in brankets:
up = 0
minup = 0
for c in list(branket):
if c == '(':
up += 1
else:
up -= 1
minup = min(minup , up)
totup += up
if up >= 0:
left_brankets.append((minup , up))
else:
right_brankets.append((minup - up , - up))
if totup != 0:
return False
return checkNonnegative(left_brankets) and checkNonnegative(right_brankets)
branketList = []
for i in range(N):
l = input()
branketList.append(l)
if canArrangeBranket(branketList):
print("Yes")
else:
print("No")
| 1 | 23,650,344,841,760 | null | 152 | 152 |
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()
from math import *
K=k()
ans=0
for i in range(1,K+1):
for j in range(1,K+1):
for k in range(1,K+1):
ans+=gcd(k,gcd(i,j))
print(ans)
|
import math
def main():
K = int(input())
s = 0
for i in range(K):
for j in range(K):
tmp = math.gcd(i+1, j+1)
for k in range(K):
s += math.gcd(tmp, k+1)
print(s)
if __name__=="__main__":
main()
| 1 | 35,589,884,876,070 | null | 174 | 174 |
n=int(input())
dp=[0]*(10**5+1)
dp[100]=1
dp[101]=1
dp[102]=1
dp[103]=1
dp[104]=1
dp[105]=1
for i in range(106,10**5+1):
if dp[i-100]==1:
dp[i]=1
elif dp[i-101]==1:
dp[i]=1
elif dp[i-102]==1:
dp[i]=1
elif dp[i-103]==1:
dp[i]=1
elif dp[i-104]==1:
dp[i]=1
elif dp[i-105]==1:
dp[i]=1
print(dp[n])
|
X = int(input())
flag = 1
if X < 100:
flag = 0
else:
a = X%100
b = a%10
c = (a-b)/10
count = 2*c
if 1 <= b <= 5:
count += 1
elif 6<= b <= 9:
count += 2
if X//100 < count:
flag = 0
print(flag)
| 1 | 126,818,265,067,592 | null | 266 | 266 |
n,m=map(int,input().split())
way=[[] for i in range(n)]
H = list(map(int,input().split()))
for i in range(m):
a,b=map(int,input().split())
way[a-1].append(b-1)
way[b-1].append(a-1)
for i in range(n):
way[i]=list(set(way[i]))
ans=0
for i in range(n):
high=True
for j in way[i]:
if H[i]<=H[j]:
high=0
break
if high:
ans+=1
print(ans)
|
n,k = map(int,input().split())
mod = 10**9 +7
sum1 = 0
for i in range(k,n+2):
sum1 +=(-i*(i-1)//2 + i*(2*n-i+1)//2+1)%mod
print(sum1%mod)
| 0 | null | 29,081,267,873,646 | 155 | 170 |
#!python3
import sys
input = sys.stdin.readline
def resolve():
N = int(input())
S = list(input())
Q = int(input())
c0 = ord('a')
smap = [1<<(i-c0) for i in range(c0, ord('z')+1)]
T = [0]*N + [smap[ord(S[i])-c0] for i in range(N)]
for i in range(N-1, 0, -1):
i2 = i << 1
T[i] = T[i2] | T[i2|1]
ans = []
#print(T)
for cmd, i, j in zip(*[iter(sys.stdin.read().split())]*3):
i = int(i) - 1
if cmd == "1":
if S[i] == j:
continue
S[i] = j
i0 = N + i
T[i0] = smap[ord(j)-c0]
while i0 > 1:
i0 = i0 >> 1
T[i0] = T[i0+i0] | T[i0-~i0]
elif cmd == "2":
i += N
j = int(j) + N
d1 = 0
while i < j:
if i & 1:
d1 |= T[i]
i += 1
if j & 1:
j -= 1
d1 |= T[j]
i >>= 1; j >>=1
ans.append(bin(d1).count('1'))
print(*ans, sep="\n")
if __name__ == "__main__":
resolve()
|
moji = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
moji = moji.split(",")
a = input()
print(int(moji[int(a)-1]))
| 0 | null | 56,376,751,295,150 | 210 | 195 |
A, B, K = map(int, input().split())
if A >= K:
a = A - K
b = B
else:
if K <= A + B:
a = 0
b = B - (K - A)
else:
a = 0
b = 0
print(a, b)
|
a, b, k = map(int, input().split())
if k <= a:
a -= k
elif a < k <= a + b:
temp = a
a = 0
b -= k - temp
else:
a = 0
b = 0
print('{} {}'.format(a, b))
| 1 | 104,095,301,509,980 | null | 249 | 249 |
n, m = map(int, input().split())
num = [''] * n
flag = 0
for i in range(m):
s, c = map(int, input().split())
if num[s - 1] == '' or num[s - 1] == c:
num[s - 1] = c
else:
print(-1)
break
else:
if num[0] == '':
if n > 1:
num[0] = 1
else:
num[0] = 0
for i in range(1, n):
if num[i] == '':
num[i] = 0
if n > 1 and num[0] == 0:
print(-1)
else:
print(''.join(map(str, num)))
|
n, m = map(int, input().split())
s = [0] * m
c = [0] * m
for i in range(m):
s[i], c[i] = map(int, input().split())
for i in range(0, 1000):
x = str(i)
if len(x) != n:
continue
for j in range(m):
if s[j] > len(x) or int(x[s[j] - 1]) != c[j]:
break
else:
print(x)
exit()
print(-1)
| 1 | 60,988,354,045,908 | null | 208 | 208 |
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = [0]*n
r = [0]*n
index = 0
for i in range(1,n+1) :
if b[a[index]-1] != 0 :
break
b[a[index]-1] = i
index = a[index] - 1
for i in range(1,n+1) :
if r[a[index]-1] != 0 :
break
r[a[index]-1] = i
index = a[index] - 1
maxb = max(b)
maxr = max(r)
if k <= maxb :
print(b.index(k)+1)
else :
k = k - maxb
if k%maxr == 0 :
print(r.index(maxr)+1)
else :
print(r.index(k%maxr)+1)
|
n = int(input())
ans = n // 2
ans += 1 if n % 2 != 0 else 0
print(ans)
| 0 | null | 40,844,542,321,440 | 150 | 206 |
n = input()
ans = 0
for nn in n:
ans += int(nn)
print('Yes') if ans%9 == 0 else print('No')
|
import sys
read = sys.stdin.read
#readlines = sys.stdin.readlines
from math import ceil
def main():
n = tuple(map(int, tuple(input())))
if sum(n) % 9 == 0:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main()
| 1 | 4,406,188,708,192 | null | 87 | 87 |
from collections import deque
H, W, K=map(int, input().split())
cake=[input() for _ in range(H)]
rows_list=[]
upper=0
for i in range(H):
for j in range(W):
if cake[i][j]=="#":
rows_list.append([upper, i])
upper=i+1
break
rows_list[-1][-1]=H-1
ans_list=[]
for rows in rows_list:
for i in range(rows[0], rows[1]+1):
left=0
for j in range(W):
if cake[i][j]=="#":
ans_list.append([rows[0], rows[1], left, j])
left=j+1
if ans_list:
ans_list[-1][-1]=W-1
ans=[[0 for _ in range(W)] for _ in range(H)]
key=1
for l in ans_list:
for i in range(l[0], l[1]+1):
for j in range(l[2], l[3]+1):
ans[i][j]=key
key+=1
for a in ans:
print(*a)
|
# B-81
# 標準入力 N
N = int(input())
num_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
j = 0
for i in range(1, 9 + 1):
if (N / i) in num_list:
j += 1
if j == 0:
print('No')
else:
print('Yes')
| 0 | null | 152,300,483,897,788 | 277 | 287 |
A, B = input().split()
# 方針:少数の計算を避け、整数の範囲で計算する
# [A*B] = [A*(100*B)/100]と見る
# Bを100倍して整数に直す操作は、文字列のまま行う
A = int(A)
B = int(B.replace('.', ''))
# 100で割った整数部分を求める操作は、100で割った商を求めることと同じ
ans = (A*B) // 100
print(ans)
|
#decimalを使った別解
import decimal
deci = decimal.Decimal
a,b = input().split()
x,y = deci(a),deci(b)
ans = (x*y).quantize(deci('0'),rounding=decimal.ROUND_FLOOR)
print(ans)
| 1 | 16,588,223,457,760 | null | 135 | 135 |
t1, t2 = map(int, input().split())
a1,a2 = map(int, input().split())
b1, b2 = map(int, input().split())
#t1で生まれる差
P = (a1 - b1) * t1
#t2で生まれる差
Q = (a2 - b2) * t2
#P < 0 のことを仮定する
if P > 0:
P *= -1
Q *= -1
if P + Q < 0:
print(0)
elif P + Q == 0:
print("infinity")
else:
#つぎのPを足したときに、負にいくかどうか?
i = P * (-1)
if i % (P + Q) == 0:
print(2 * (i // (P + Q)))
else:
print(2 * (i // (P + Q)) + 1)
|
a=int(input())
b=a//100
b*=5
c=a%100
print("1" if b>=c else "0")
| 0 | null | 129,545,661,061,010 | 269 | 266 |
strN = input()
s = 0
for c in strN:
s += int(c)
if s % 9 == 0:
print("Yes")
else:
print("No")
|
from collections import deque
n, q = map(int, input().split())
procs = deque([])
for i in range(n):
name, time = input().split()
time = int(time)
procs.append([name, time])
total = 0
while procs:
procs[0][1] -= q
if procs[0][1] > 0:
total += q
procs.append(procs.popleft())
else:
total += q + procs[0][1]
print(procs[0][0], total)
procs.popleft()
| 0 | null | 2,239,198,784,560 | 87 | 19 |
x = int(input())
i=1
while x!=0:
print('Case {0}: {1}'.format(i,x))
x = int(input())
i+=1
|
c = 1
while True:
a = int(raw_input())
if a == 0:
break
print "Case %d: %d" % (c,a)
c = c + 1
| 1 | 496,886,016,132 | null | 42 | 42 |
n,m,q=map(int,input().split())
A=[]
B=[]
C=[]
D=[]
for i in range(q):
a,b,c,d=map(int,input().split())
A.append(a)
B.append(b)
C.append(c)
D.append(d)
ans=0
#print(A)
#print(B)
#print(C)
#print(D)
#mCn
def dfs(l):
global ans # UnboundLocalError: local variable 'ans' referenced before assignment
if len(l)==n+1:
#print(l)
tmp=0
for i in range(q):
#print(l[B[i]],l[A[i]],C[i])
if l[B[i]]-l[A[i]]==C[i]:
tmp+=D[i]
ans=max(ans,tmp)
return
x=l[len(l)-1]
while x<=m:
y=l[:]
y.append(x)
dfs(y)
x+=1
dfs([1])
print(ans)
|
def merge_sort(left, right):
if right-left > 1:
mid = (left + right) // 2
merge_sort(left, mid)
merge_sort(mid, right)
merge(left, mid, right)
def merge(left, mid, right):
left_part = S[left:mid]
right_part = S[mid:right]
left_part.append(inf)
right_part.append(inf)
l, r = 0, 0
for i in range(left, right):
if left_part[l] < right_part[r]:
S[i] = left_part[l]
l += 1
else:
S[i] = right_part[r]
r += 1
num[0] += right-left
if __name__ == "__main__":
num = [0]
inf = float('inf')
n = int(input())
S = list(map(int, input().split()))
merge_sort(0, n)
print(' '.join(list(map(str, S))))
print(num[0])
| 0 | null | 13,851,356,454,600 | 160 | 26 |
N=int(input())
A=list(map(int,input().split()))
total=sum(A)
cost=total
cumulative=0
for i in range(N):
cumulative+=A[i]
cost=min(cost,abs(cumulative-(total-cumulative)))
print(cost)
|
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
import numpy as np
def main():
N=[]
n = int(input())
N=np.array(list(map(int,input().split())))
Ncum=N.cumsum()
L=Ncum[:-1]
R=Ncum[-1]-L
ans=np.abs(L-R).min()
print(ans)
if __name__=="__main__":
main()
| 1 | 142,004,257,694,740 | null | 276 | 276 |
N, M = map(int, input().split())
S = input()[::-1]
l = []
p = 0
chk = True
while p<N:
for i in range(1, min(M, N-p)+1)[::-1]:
if S[p+i]=="0":
break
else:
print(-1)
chk = False
break
l.append(i)
p += i
if chk:
l.reverse()
print(*l)
|
N,M=map(int, input().split())
S=list(input())
T=S[::-1]
D=[0]*N
if N<=M:
print(N)
exit()
renzoku,ma=0,0
for i in range(1,N+1):
if S[i]=='1':
renzoku+=1
else:
ma=max(ma,renzoku)
renzoku=0
if ma>=M:
print(-1)
exit()
r=0
for i in range(1,M+1):
if T[i]!='1':
r=i
ans=[r]
while r+M<N:
for i in range(M,0,-1):
if T[r+i]=='0':
ans.append(i)
r+=i
break
ans.append(N-r)
print(*ans[::-1])
| 1 | 139,152,800,500,822 | null | 274 | 274 |
import sys, bisect
N = int(input())
L = list(map(int, sys.stdin.readline().rsplit()))
L.sort()
res = 0
for i in reversed(range(1, N)):
for j in reversed(range(i)):
l = bisect.bisect_left(L, L[i] + L[j])
# r = bisect.bisect_right(L, abs(L[i] - L[j]))
res += l - 1 - i
print(res)
|
n,m = map(int, input().split())
height = list(map(int, input().split()))
c = 0
net = [[] for i in range(n)]
for j in range(m):
a,b = map(int, input().split())
net[a-1].append(height[b-1])
net[b-1].append(height[a-1])
for i in range(n):
net[i].append(0)
if max(net[i]) < height[i]:
c += 1
print(c)
| 0 | null | 98,489,427,343,664 | 294 | 155 |
s = input()
p = input()
s = s+s
if s.find(p) < 0:
print('No')
else:
print('Yes')
|
s = input()*2
p = input()
print("Yes" if p in s else "No")
| 1 | 1,747,508,116,160 | null | 64 | 64 |
n = int(input())
graph = [[-1 for _ in range(n)] for _ in range(n)]
for i in range(n):
a = int(input())
for _ in range(a):
x, y = map(int, input().split())
graph[i][x-1] = y
ans = 0
for p in range(2**n):
q = p
c = 0
t = []
l = 0
while q:
if q&1:
t.append(graph[c])
l += 1
q >>= 1
c += 1
flag = True
for c in range(n):
if p&1:
for s in t:
if s[c] == 0:
flag = False
else:
for s in t:
if s[c] == 1:
flag = False
p >>= 1
if flag:
ans = max(ans, l)
print(ans)
|
a,b = map(str,input().split())
As = a * int(b)
Bs = b * int(a)
if As<Bs:
print(As)
else:
print(Bs)
| 0 | null | 103,304,561,810,582 | 262 | 232 |
import sys
def main():
read = sys.stdin.buffer.read
k, n, *A = map(int, read().split())
far = k + A[0] - A[-1]
y = A[0]
for x in A[1:]:
dis = x - y
if far < dis:
far = dis
y = x
print(k - far)
if __name__ == "__main__":
main()
|
s=input()
print("Yes"if s==input()[:-1]else"No")
| 0 | null | 32,456,511,074,978 | 186 | 147 |
def II(): return int(input())
def LII(): return list(map(int, input().split()))
n=II()
town=[LII() for _ in range(n)]
distance=0
for i in range(n-1):
for j in range(i+1,n):
[xi,yi]=town[i]
[xj,yj]=town[j]
distance += ((xi-xj)**2+(yi-yj)**2)**0.5
print(distance*2/n)
|
import itertools
N = int(input())
c = []
d = 0
for i in range(N):
x1, y1 = map(int, input().split())
c.append((x1,y1))
cp = list(itertools.permutations(c))
x = len(cp)
for i in range(x):
for j in range(N-1):
d += ((cp[i][j][0]-cp[i][j+1][0])**2 + (cp[i][j][1] - cp[i][j+1][1])**2)**0.5
print(d/x)
| 1 | 148,420,300,650,788 | null | 280 | 280 |
#define S as string
#print S until len is equal to K
#time complexity O(1)
K = int(input())
S = input()
str = S
if len(S) > K:
print (str[0:K]+ "...")
else:
print(str)
|
n = int(input())
p = input()
if n>=len(p):
print(p)
else:
print(p[:n] + '...')
| 1 | 19,679,605,772,524 | null | 143 | 143 |
N,D,A=map(int, input().split())
B=[list(map(int, input().split())) for _ in range(N)]
C=sorted(B)
d,E=zip(*C)
import bisect
Damage=[0]*N
for i in range(N):
e=bisect.bisect_right(d,d[i]+2*D)
Damage[i]=e
dd=[0]*(N+1)
cnt=0
for i in range(N):
if i!=0:
dd[i]+=dd[i-1]
h=E[i]
h-=dd[i]
if h>0:
bomb=-(-h//A)
cnt+=bomb
dd[i]+=A*bomb
dd[Damage[i]]-=A*bomb
print(cnt)
|
N, D, A = map(int, input().split())
X = [0] * N
for i in range(N):
x, h = map(int, input().split())
X[i] = (x, h)
X = sorted(X)
from collections import deque
q = deque()
ans = 0
total = 0
for i in range(N):
x, h = X[i]
while (len(q) > 0 and q[0][0] < x):
total -= q[0][1]
q.popleft()
h -= total
if h > 0:
num = (h + A - 1) // A
ans += num
damage = num * A
total += damage
q.append((x + 2 * D, damage))
print(ans)
| 1 | 82,295,717,922,088 | null | 230 | 230 |
print(("ARC","ABC")[str(input())=="ARC"])
|
print('ABC') if input() == 'ARC' else print('ARC')
| 1 | 24,142,502,801,832 | null | 153 | 153 |
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
ans = 0
MOD = 10**9+7
for i in range(63):
one, zero = 0, 0
for Aj in A:
if (Aj>>i)&1:
one += 1
else:
zero += 1
ans += 2**i*one*zero
ans %= MOD
print(ans)
|
N = int(input())
X = [list(map(int, input().split())) for i in range(N)]
LR = [[x[0]-x[1], x[0] + x[1]] for x in X]
LR.sort(key=lambda x:x[1])
A = 1
right = LR[0][1]
for i in range(1, N):
if right <= LR[i][0]:
A += 1
right = LR[i][1]
print(A)
| 0 | null | 106,666,176,951,558 | 263 | 237 |
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 *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
#############
# Main Code #
#############
N,K = getNM()
ans = 0
rec = [0] * (K + 1)
for X in range(K, 0, -1):
rec[X] = pow(K//X, N, mod)
for i in range(2, K // X + 1):
rec[X] -= rec[i * X] % mod
ans += (X * rec[X]) % mod
print(ans % mod)
|
import sys
input = sys.stdin.buffer.readline
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict
from itertools import combinations, permutations
from itertools import accumulate
from math import ceil, sqrt, pi
MOD = 10 ** 9 + 7
INF = 10 ** 18
def divisors(n) -> list:
res = []
for i in range(1, int(n ** 0.5) + 1):
if n % i == 0:
res.append(i)
if i != n // i:
res.append(n // i)
return res
N, K = map(int, input().split())
MOD = 10 ** 9 + 7
cnt = defaultdict(int)
for k in range(1, K + 1):
for d in divisors(k):
cnt[d] += 1
#print(cnt)
tmp = defaultdict(int)
for k in range(K, 0, -1):
tmp[k] = pow(cnt[k], N, MOD)
for i in range(2, K // k + 1):
tmp[k] -= tmp[i * k]
#print(tmp)
ans = 0
for k in range(1, K + 1):
ans = (ans + k * tmp[k]) % MOD
print(ans)
| 1 | 36,832,952,429,888 | null | 176 | 176 |
n = int(raw_input())
for i in range(0, n):
edge = map(int, raw_input().split(" "))
edge.sort()
if edge[2]*edge[2] == edge[0]*edge[0]+edge[1]*edge[1]: print "YES"
else: print "NO"
|
#coding:UTF-8
def Rec(N,List):
for i in range(N):
a=int(List[i].split(" ")[0])
b=int(List[i].split(" ")[1])
c=int(List[i].split(" ")[2])
if a*a+b*b==c*c or a*a+c*c==b*b or b*b+c*c==a*a:
print("YES")
else:
print("NO")
if __name__=="__main__":
List=[]
N=int(input())
for i in range(N):
List.append(input())
Rec(N,List)
| 1 | 360,606,190 | null | 4 | 4 |
import math
x1,y1,x2,y2=input().split()
x1=float(x1)
y1=float(y1)
x2=float(x2)
y2=float(y2)
r=math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
print(r)
|
import math
x1,y1,x2,y2=map(float,input().split())
a = ((x1-x2)**2)+((y1-y2)**2)
a = math.sqrt(a)
print('{:.8f}'.format(a))
| 1 | 158,362,926,112 | null | 29 | 29 |
S = input()
T = input()
count = 0
for (s,t) in zip(S,T):
if s != t:
count += 1
print(count)
|
N = int(input())
a = list(map(int, input().split()))
i = 1
ans = 0
for aa in a:
if aa != i:
ans += 1
else:
i += 1
if N == ans:
print(-1)
else:
print(ans)
| 0 | null | 62,352,360,819,322 | 116 | 257 |
W, H, x, y, r = map(int, raw_input().split())
if x-r<0 or y-r<0:
print"No"
elif x+r <= W and y+r <= H:
print"Yes"
else:
print"No"
|
while True:
H, W = list(map(int, input().split()))
if H == 0 & W == 0:
break
print("#"*W)
print(("#" + "."*(W-2) + "#\n")*(H-2), end="")
print("#"*W, end="\n\n")
| 0 | null | 637,140,228,946 | 41 | 50 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.