code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 2
178,025B
⌀ | question_pair_id
float64 27.1M
177,113B
⌀ | code1_group
int64 1
297
| code2_group
int64 1
297
|
---|---|---|---|---|---|---|
def isPrime(n):
i = 2
while i*i <= n:
if n % i == 0:
return False
i += 1
return True
n = int(input())
ans = 0
for i in range(n):
t = int(input())
if isPrime(t):
ans += 1
print(ans)
|
def Qb():
n, k = map(int, input().split())
ans = set()
for v in range(k):
d = int(input())
ns = [int(v) for v in input().split()]
for N in ns:
ans.add(N)
print(n - len(ans))
if __name__ == '__main__':
Qb()
| 0 | null | 12,355,560,955,892 | 12 | 154 |
ary = list(input())
s1 = []
s = 0
s2 = []
cnt = 0
for _ in ary:
if _ == '\\':
s1.append(cnt)
cnt += 1
elif _ == '/':
if s1:
old_cnt = s1.pop()
area = cnt - old_cnt
s += area
while s2:
if old_cnt < s2[-1][0]:
area += s2.pop()[1]
else:
break
s2.append((old_cnt, area))
cnt += 1
else:
cnt += 1
print(s)
print(len(s2), *[_[1] for _ in s2])
|
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])
| 0 | null | 158,581,851,490 | 21 | 34 |
s = input()
l, count = [], 0
for i in s:
if i=='>': count+=1
else:
if count: l.append(count)
count = 0
if count: l.append(count); count = 0
j = 0
ans = []
if s[0]=='<': ans.append(0)
else:
ans.append(l[0])
l[0]-=1
for i in range(len(s)):
if s[i]=='<': ans.append(ans[-1]+1)
else:
if i==0: ans.append(ans[-1]-1); continue
if l[j]==0: j+=1
if ans[-1]>=l[j]:
l[j]-=1
ans.append(l[j])
else:
ans[-1]=l[j]
l[j]-=1
ans.append(l[j])
print(sum(ans))
|
s = input()
inc = 0
dec = 0
increasing = True
ans = 0
for c in s:
if increasing:
if c == '<':
inc += 1
else:
increasing = False
dec += 1
else:
if c == '>':
dec += 1
else:
if inc > dec:
inc, dec = dec, inc
ans += inc * (inc - 1) // 2 + dec * (dec + 1) // 2
increasing = True
inc = 1
dec = 0
else:
if increasing:
ans += inc * (inc + 1) // 2
else:
if inc > dec:
inc, dec = dec, inc
ans += inc * (inc - 1) // 2 + dec * (dec + 1) // 2
print(ans)
| 1 | 157,146,479,594,694 | null | 285 | 285 |
import sys
MOD = 10**9+7
def main():
input = sys.stdin.readline
N,K=map(int, input().split())
ans=Mint()
cnt=[Mint() for _ in range(K+1)]
for g in range(K,0,-1):
cnt[g]+=pow(K//g,N,MOD)
for h in range(g+g,K+1,g):
cnt[g]-=cnt[h]
ans+=g*cnt[g]
print(ans)
class Mint:
def __init__(self, value=0):
self.value = value % MOD
if self.value < 0: self.value += MOD
@staticmethod
def get_value(x): return x.value if isinstance(x, Mint) else x
def inverse(self):
a, b = self.value, MOD
u, v = 1, 0
while b:
t = a // b
b, a = a - t * b, b
v, u = u - t * v, v
if u < 0: u += MOD
return u
def __repr__(self): return str(self.value)
def __eq__(self, other): return self.value == other.value
def __neg__(self): return Mint(-self.value)
def __hash__(self): return hash(self.value)
def __bool__(self): return self.value != 0
def __iadd__(self, other):
self.value = (self.value + Mint.get_value(other)) % MOD
return self
def __add__(self, other):
new_obj = Mint(self.value)
new_obj += other
return new_obj
__radd__ = __add__
def __isub__(self, other):
self.value = (self.value - Mint.get_value(other)) % MOD
if self.value < 0: self.value += MOD
return self
def __sub__(self, other):
new_obj = Mint(self.value)
new_obj -= other
return new_obj
def __rsub__(self, other):
new_obj = Mint(Mint.get_value(other))
new_obj -= self
return new_obj
def __imul__(self, other):
self.value = self.value * Mint.get_value(other) % MOD
return self
def __mul__(self, other):
new_obj = Mint(self.value)
new_obj *= other
return new_obj
__rmul__ = __mul__
def __ifloordiv__(self, other):
other = other if isinstance(other, Mint) else Mint(other)
self *= other.inverse()
return self
def __floordiv__(self, other):
new_obj = Mint(self.value)
new_obj //= other
return new_obj
def __rfloordiv__(self, other):
new_obj = Mint(Mint.get_value(other))
new_obj //= self
return new_obj
if __name__ == '__main__':
main()
|
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce
rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7
a = ri()//200
print(10-a)
| 0 | null | 21,663,427,025,240 | 176 | 100 |
N,A,B = map(int,input().split())
p = N // (A+B)
q = N % (A+B)
if q > A:
r = A
else:
r = q
print(A * p + r)
|
n, a, b = map(int, input().split())
set_num = n // (a + b)
remain_num = n - (a + b) * set_num
print(set_num * a + min(remain_num, a))
| 1 | 55,449,306,166,208 | null | 202 | 202 |
N = int(input())
total = 0
for n in range(1, N+1):
total += N//n * (n + N - N%n)//2
print(total)
|
import math
n = int(input())
ans = 0
for i in range(1,n+1):
ans += (i + i * (n // i)) * (n // i) / 2
print(int(ans))
| 1 | 11,020,134,587,850 | null | 118 | 118 |
N = int(input())
A = list(map(int,input().split()))
flag = True
ans = 0
for i in range(N):
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
ans += 1
if not flag:
break
print(*A)
print(ans)
|
n, k = map(int, input().split())
l = list(map(int, input().split()))
for i in range(1, n - k + 1):
print("Yes" if l[i - 1] < l[i + k - 1] else "No")
| 0 | null | 3,615,917,182,472 | 14 | 102 |
#!usr/bin/env python3
import sys
import re
def main():
s = sys.stdin.readline() # haystack
p = sys.stdin.readline() # needle
s = s.strip('\n') * 2
p = p.strip('\n')
if len(re.findall((p), s)) > 0:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main()
|
s=raw_input()
p=raw_input()
if p in s*2:
print "Yes"
else:
print "No"
| 1 | 1,744,370,848,640 | null | 64 | 64 |
a,b,c,d,e=map(int,input().split())
x=a*60+b
y=c*60+d
print(y-x-e)
|
_ = input()
arr = list(map(int, input().split()))
min = arr[0]
max = arr[0]
sum = 0
for a in arr:
if a < min:
min = a
if max < a:
max = a
sum += a
print(min, max, sum)
| 0 | null | 9,462,299,320,992 | 139 | 48 |
H, W, K = map(int, input().split())
sl = []
for _ in range(H):
sl.append(list(input()))
ans = 10**8
for i in range(2 ** (H-1)):
fail_flag = False
comb = []
for j in range(H-1):
if ((i >> j) & 1):
comb.append(j)
comb.append(H-1)
# print(comb)
sections = []
for k in range(0,len(comb)):
if k == 0:
sections.append( sl[0:comb[0]+1] )
else:
sections.append( sl[comb[k-1]+1:comb[k]+1] )
# print(sections)
partition_cnt = 0
sections_w_cnts = [0]*len(sections)
for w in range(W):
sections_curr_w_cnts = [0]*len(sections)
partition_flag = False
for i, sec in enumerate(sections):
for row in sec:
if row[w] == '1':
sections_curr_w_cnts[i] += 1
sections_w_cnts[i] += 1
if sections_curr_w_cnts[i] > K:
fail_flag = True
break
if sections_w_cnts[i] > K:
partition_flag = True
if fail_flag: break
if fail_flag: break
if partition_flag:
sections_w_cnts = [v for v in sections_curr_w_cnts]
# sections_w_cnts[:] = sections_curr_w_cnts[:]
partition_cnt += 1
if not fail_flag:
ans = min(len(comb)-1+partition_cnt, ans)
print(ans)
|
N,M,X=map(int,input().split())
li=[]
ans=100000000000000000000000000000000
for j in range(N):
a=list(map(int,input().split()))
li.append(a)
for k in range(2**N):
temp=0
skill=[0]*M
k=str(bin(k))
k=k[2:]
while len(k)!=N:
k="0"+k
for l in range(N):
if k[l]=="1":
temp+=li[l][0]
for m in range(1,M+1):
skill[m-1]+=li[l][m]
if min(skill)>=X:
if ans>temp:
ans=temp
if ans==100000000000000000000000000000000:
print(-1)
else:
print(ans)
| 0 | null | 35,405,572,537,808 | 193 | 149 |
N=int(input())
Xlist=list(map(int,input().split()))
ans=10**18
for p in range(1,101):
ans=min(ans,sum(list(map(lambda x:(p-x)**2,Xlist))))
print(ans)
|
import math
N = int(input())
ans = math.ceil(N / 2.0)
print(ans)
| 0 | null | 61,898,839,238,432 | 213 | 206 |
x, n = map(int, input().split())
p = [int(v) for v in input().split()]
ans = None
if x not in p:
ans = x
else:
diff = 101
for i in range(0, max(p) + 2):
if abs(x - i) < diff and i not in p:
ans = i
diff = abs(x - i)
print(ans)
|
x,n = map(int,input().split())
p = list(map(int,input().split()))
dic = {}
lis = []
for i in range(0,102):
if i not in p:
dic[i] = abs(x-i)
lis.append(i)
mini = min(dic.values())
for j in lis:
if mini == dic[j]:
print(j)
break
| 1 | 14,036,856,088,164 | null | 128 | 128 |
lst = raw_input().split()
lst2 = []
for v in lst:
if v == "+":
lst2[len(lst2)-2] += lst2.pop()
elif v == "-":
lst2[len(lst2)-2] -= lst2.pop()
elif v == "*":
lst2[len(lst2)-2] *= lst2.pop()
elif v == "/":
lst2[len(lst2)-2] /= lst2.pop()
else:
lst2.append(int(v))
print lst2[0]
|
n, x, m = map(int, input().split())
v = list(range(m))
p = [-1 for _ in range(m)]
a = x
p[a - 1] = 0
s = [x]
l, r = n, n
for i in range(n):
a = a ** 2 % m
if p[a - 1] >= 0:
l, r = p[a - 1], i + 1
break
else:
s.append(a)
p[a - 1] = i + 1
ans = sum(s[:l])
if l != r:
b = (n - 1 - i) // (r - l) + 1
c = (n - 1 - i) % (r - l)
ans += b * sum(s[l:r]) + sum(s[l:l + c])
print(ans)
| 0 | null | 1,423,043,107,122 | 18 | 75 |
import sys
from collections import deque
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
def main():
N = int(readline())
if N==1:
print('a')
exit()
d = deque(['a'])
ans = []
while d:
s = d.popleft()
last = ord(max(s))
for i in range(97,last+2):
S = s + chr(i)
if len(S)==N:
ans.append(S)
else:
d.append(S)
ans.sort()
for s in ans:
print(s)
if __name__ == '__main__':
main()
|
n = int(input())
w = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
s = {}
s["a"] = 0
ans = [s]
for i in range(2, n+1):
new_s = {}
for t in s.items():
for j in range(1, i):
if t[0][-1] == w[j-1]:
for k in range(t[1] + 2):
new_s[t[0] + w[k]] = max(t[1], k)
ans.append(new_s)
s = new_s
answer = sorted(ans[n-1].keys())
for x in answer:
print(x)
| 1 | 52,377,977,191,222 | null | 198 | 198 |
n = int(input())
y = 1000 - (n % 1000)
if y == 1000:
y = 0
print(y)
|
N, D = map(int, input().split())
x = []
y = []
for i in range(N):
coords = list(map(int, input().split()))
x.append(coords[0])
y.append(coords[1])
count = 0
for i in range(N):
if (x[i]**2 + y[i]**2) ** 0.5 <= D:
count += 1
print(count)
| 0 | null | 7,239,522,987,498 | 108 | 96 |
n = int(input())
mod = 1000000007
if n < 2:
print(0)
else:
print((pow(10, n, mod) - 2 * pow(9, n, mod) + pow(8, n, mod)) % mod)
|
import math
n = int(input())
a = pow(10, n, 10**9+7)
b = pow(9, n, 10**9+7)
c = pow(9, n, 10**9+7)
d = pow(8, n, 10**9+7)
print((a-b-c+d) % (10**9+7))
| 1 | 3,133,521,065,718 | null | 78 | 78 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
S = readline().decode()
if 'A' in S and 'B' in S:
print('Yes')
else:
print('No')
|
from collections import deque
slope = input()
down_slope = deque()
total_slopes = deque()
for i in range(len(slope)):
if slope[i] == '\\':
down_slope.append(i)
elif slope[i] == '/':
area = 0
if len(down_slope) > 0:
while len(total_slopes) > 0 and total_slopes[-1][0] > down_slope[-1]:
area += total_slopes[-1][1]
total_slopes.pop()
area += i-down_slope[-1]
total_slopes.append([down_slope[-1],area])
down_slope.pop()
if len(total_slopes) > 0:
total_slopes = [i[1] for i in total_slopes]
print(sum(total_slopes))
print(len(total_slopes),end=' ')
print(' '.join(map(str,total_slopes)))
else:
print(0)
print(0)
| 0 | null | 27,399,443,398,102 | 201 | 21 |
num=int(input())
if num%1000==0:
print(0)
else:
print(1000-num%1000)
|
n = int(input())
if "7" in str(n):
print("Yes")
else:
print("No")
| 0 | null | 21,292,045,071,242 | 108 | 172 |
X,Y = map(int, input().split())
if 4*X < Y or Y < 2*X or Y%2 != 0:
print('No')
exit()
print('Yes')
|
x, y = map(int, input().split())
a = []
for i in range(0, x+1):
a.append(2 * i + 4 * (x - i))
print("Yes" if y in a else "No")
| 1 | 13,714,769,105,584 | null | 127 | 127 |
a, b, c = map(int, input().split())
if a == b and b != c or b == c and a != b or a == c and a != b:
print('Yes')
else:
print('No')
|
l = list("abcdefghijklmnopqrstuvwxyz")
C = input()
i = l.index(C)
print(l[i+1])
| 0 | null | 80,531,066,562,398 | 216 | 239 |
import sys
I=sys.stdin.readlines()
N,M,L=map(int,I[0].split())
a,b,c=0,0,0
D=[[L+1]*N for i in range(N)]
for i in range(M):
a,b,c=map(int,I[i+1].split())
a,b=a-1,b-1
D[a][b]=c
D[b][a]=c
for i in range(N):
D[i][i]=0
for k in range(N):
for i in range(N):
for j in range(N):
D[i][j]=min(D[i][j],D[i][k]+D[k][j])
D2=[[N*N+2]*N for i in range(N)]
for i in range(N):
D2[i][i]=0
for j in range(N):
if D[i][j]<=L:
D2[i][j]=1
for k in range(N):
for i in range(N):
for j in range(N):
D2[i][j]=min(D2[i][j],D2[i][k]+D2[k][j])
Q=int(I[M+1])
for i in range(Q):
a,b=map(int,I[i+2+M].split())
if N<D2[a-1][b-1]:
print(-1)
else:
print(D2[a-1][b-1]-1)
|
n= int(input())
ans=(n+1)//2
print(ans)
| 0 | null | 115,776,793,448,752 | 295 | 206 |
from collections import deque
# 両端を扱うならdequeが速い
# 内側を扱うならリストが速い
S = input()
q = deque()
for s in list(S):
q.append(s)
Q = int(input())
direction = True
for _ in range(Q):
line = input()
# TrueならFalseに、FalseならTrueに変える
if line == "1":
direction = not direction
else:
if (direction and line[2] == '1') or (not direction and line[2] == '2'):
# 左端に追加する場合
q.appendleft(line[4])
else:
# 右端に追加する場合
q.append(line[4])
if direction:
print("".join(q))
elif not direction:
q.reverse()
print("".join(q))
|
s=input()
q=int(input())
cnt=0
front=[]
rear=[]
for qq in range(q):
l=list(input().split())
if l[0]=='1':
cnt+=1
else:
if (cnt+int(l[1]))%2==1:
front.append(l[2])
else:
rear.append(l[2])
front=''.join(front[::-1])
rear=''.join(rear)
s=front+s+rear
print(s if cnt%2==0 else s[::-1])
| 1 | 57,190,623,548,702 | null | 204 | 204 |
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
if v<w:
print("NO")
elif v==w:
if a==b:
print("YES")
else:
print("NO")
elif v>w:
t0 = abs((a-b)/(v-w))
if t0<=t:
print("YES")
else:
print("NO")
|
a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())
if a > b:
oni = a + (-1*v) * t
nige = b + (-1*w) * t
if oni <= nige:
print("YES")
else:
print("NO")
else:
oni = a + v*t
nige = b + w * t
if oni >= nige:
print("YES")
else:
print("NO")
| 1 | 15,191,997,879,360 | null | 131 | 131 |
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
n = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
ans = A[0]
for i in range(n-2):
ans += A[i//2 + 1]
print(ans)
if __name__=='__main__':
main()
|
N = int(input())
a = list(map(int, input().split()))
a.sort()
arrival = 1
ans = 0
while arrival < N:
score = a.pop()
if arrival == 1:
ans += score
arrival += 1
else:
ans += score*min(2, N - arrival)
arrival += 2
print(ans)
| 1 | 9,180,573,218,462 | null | 111 | 111 |
N = int(input())
i = 1
sum = 0
while True:
if i%3!=0 and i%5!=0:
sum +=i
i+=1
if i==N+1:
break
print (sum)
|
a = input()
iff3 = a[2]
iff4 = a[3]
iff5 = a[4]
iff6 = a[5]
if iff3 == iff4 :
if iff5 == iff6 :
print("Yes")
else :
print("No")
else :
print("No")
| 0 | null | 38,464,553,217,132 | 173 | 184 |
#!/usr/bin/env python3
def main():
N = int(input())
A = list(map(int, input().split()))
p = 10**9 + 7
digit_0 = [0] * 60
digit_1 = [0] * 60
for i in range(N):
for j in range(60):
if (A[i] >> j) & 1:
digit_1[j] += 1
else:
digit_0[j] += 1
ans = 0
for j in range(60):
ans += ((digit_0[j] * digit_1[j] % p) * pow(2,j,p) % p)
ans %= p
print(ans)
if __name__ == "__main__":
main()
|
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
res=0
m=1
for i in a:
b=m-i
if b<0:
print(-1)
exit(0)
res+=i
res+=b
s-=i
m=min(b*2,s)
print(res)
| 0 | null | 70,744,038,160,840 | 263 | 141 |
n=int(input())
while 1:
for i in range(2,int(n**0.5)+1):
if n%i<1: break
else: print(n); break
n+=1
|
n = int(input())
while 1:
for i in range(2, int(n**0.5)+1):
if n % i < 1:
break
else:
print(n)
break
n += 1
| 1 | 105,232,921,273,088 | null | 250 | 250 |
N = int(input())
S = input()
print('Yes' if S[:len(S)//2] == S[len(S)//2:] else 'No')
|
import sys
def main():
while True:
H, W = map(int, sys.stdin.readline().split())
if H == 0 and W == 0: break
for h in range(H):
for w in range(W):
if h % 2 == 0:
if w % 2 == 0:
print('#', end='')
else:
print('.', end='')
else:
if w % 2 == 0:
print('.', end='')
else:
print('#',end='')
print()
print()
return
if __name__ == '__main__':
main()
| 0 | null | 74,048,703,197,348 | 279 | 51 |
import sys
for line in sys.stdin:
n,x = map(int,line.split())
if n==0 and x==0:
break
_range = list(range(1,n+1))
conb = []
for i in _range[::-1]:
d = x - i
if i - 1 <= 0:
continue
for j in _range[:i-1][::-1]:
d2 = d - j
if j - 1 <= 0:
continue
for k in _range[:j-1][::-1]:
if d2 - k == 0:
conb.append((i,j,k))
print(len(conb))
|
# ????????????????????°????±???????????????°??????
import sys
import itertools
def main():
while True:
data = sys.stdin.readline().strip().split(' ')
n = int(data[0])
x = int(data[1])
if n == 0 and x == 0:
break
cnt = 0
for i in itertools.combinations(range(1, n+1), 3):
if sum(i) == x:
cnt += 1
print(cnt)
if __name__ == '__main__':
main()
| 1 | 1,300,051,991,700 | null | 58 | 58 |
h,n = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
dp = [float("inf") for i in range(10**5)]
dp[0] = 0
for a,b in ab:
for k in range(a+1):
dp[k] = min(dp[k], b)
for k in range(a+1,h+1):
dp[k] = min(dp[k], dp[k-a] + b)
print(dp[h])
|
a,b=map(int,input().split())
c,d=map(int,input().split())
t=int(input())
if abs(a-c)<=(b-d)*t:
print('YES')
else:
print('NO')
| 0 | null | 47,904,319,170,160 | 229 | 131 |
n,x, m = map(int, input().split())
mod = [None for _ in range(m)]
count = x
loop = []
rem = [x]
for i in range(1, n):
value = (x * x) % m
rem.append(value)
x = (x * x) % m
if mod[value] != None:
# print(mod)
s_index = mod[value]
loop = rem[s_index : -1]
num = (n - s_index) // len(loop)
amari = (n - s_index) % len(loop)
if amari == 0:
print(sum(rem[:s_index]) + sum(loop) * num)
else:
print(sum(rem[:s_index]) + sum(loop) * num + sum(loop[:amari]))
exit()
else:
mod[value] = i
count += value
print(count)
|
"""
何回足されるかで考えればよい。
真っ二つに切っていく。
各項は必ずM未満。
M項以内に必ずループが現れる。
"""
N,X,M = map(int,input().split())
memo1 = set()
memo2 = []
ans = 0
a = X
flag = True
rest = N
while rest > 0:
if a in memo1 and flag:
flag = False
for i in range(len(memo2)):
if memo2[i] == a:
loopStart = i
setSum = 0
for i in range(loopStart,len(memo2)):
setSum += memo2[i]**2 % M
loopStep = len(memo2)-loopStart
loopCount = rest // loopStep
ans += loopCount*setSum
rest -= loopCount*loopStep
else:
memo1.add(a)
memo2.append(a)
ans += a
a = a**2%M
rest -= 1
print(ans)
| 1 | 2,826,929,524,660 | null | 75 | 75 |
N = int(input())
A = [int(i) for i in input().split()]
maxA=max(A)
pn=list(range(maxA+1))
n=2
while n*n <= maxA:
if n == pn[n]:
for m in range(n, len(pn), n):
if pn[m] == m:
pn[m] = n
n+=1
s=set()
for a in A:
st = set()
while a > 1:
st.add(pn[a])
a//=pn[a]
if not s.isdisjoint(st):
break
s |= st
else:
print("pairwise coprime")
exit()
from math import gcd
n = gcd(A[0], A[1])
for a in A[2:]:
n=gcd(n,a)
if n == 1:
print("setwise coprime")
else:
print("not coprime")
|
k=int(input())
print("ACL"*k)
| 0 | null | 3,131,977,269,618 | 85 | 69 |
x = int(input())
can = x // 100
need = ((x%100) + 4) // 5
print(1 if can >= need else 0)
|
X,Y,Z = map(int,input().split())
print("{0} {1} {2}".format(Z,X,Y))
| 0 | null | 82,417,787,510,400 | 266 | 178 |
n = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
B = sorted(A+A[1:],reverse=True)
print(sum(B[:n-1]))
|
N = int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
sum=0
for i in range(1,N):
sum+=A[i//2]
print(sum)
| 1 | 9,128,950,079,392 | null | 111 | 111 |
n=int(input())
for i in range(1,50001):
if i*108//100 == n:
print(i)
break
else:
print(":(")
|
import math
n = int(input())
x = int(n/1.08)
if math.floor(x*1.08) == n:
print (x)
elif math.floor((x-1)*1.08) == n:
print (x-1)
elif math.floor((x+1)*1.08) == n:
print (x+1)
else:
print (":(")
| 1 | 126,122,873,398,588 | null | 265 | 265 |
def main():
N, M = map(int, input().split())
cond = N == M
print('Yes' if cond else 'No')
if __name__ == '__main__':
main()
|
N = int(input())
def solve_function(N):
if N % 2 == 1:
return 0
it_can_be_divisible = 10
ans = 0
while True:
if it_can_be_divisible > N:
break
ans += N//it_can_be_divisible
it_can_be_divisible *= 5
return ans
if solve_function(N):
print(solve_function(N))
else:
print(0)
| 0 | null | 99,769,998,590,068 | 231 | 258 |
n = int(input())
ans = [0] * 10010
def get_ans(n):
cnt = 0
for x in range(1, 101):
for y in range(1, 101):
for z in range(1, 101):
k = x**2 + y**2 + z**2 + x*y + y*z + z*x
if(k <= 10000):
ans[k] += 1
return ans
ans = get_ans(n)
for i in range(1, n+1):
print(ans[i])
|
h1, m1, h2, m2, k = map(int, input().split())
s = h1*60+m1
t = h2*60+m2
ans = t-s-k
print (max(ans,0))
| 0 | null | 12,927,312,570,872 | 106 | 139 |
n = int(input())
ans = [0]*(n+1)
for x in range(1, 100):
for y in range(1, 100):
for z in range(1, 100):
k = x**2+y**2+z**2+x*y+y*z+z*x
if k<=n: ans[k]+=1
for i in range(1, n+1):
print(ans[i])
|
n=int(input())
p=round(n**0.5)+1
ans=[0]*n
for x in range(1,p):
for y in range(1,p):
for z in range(1,p):
k=x**2+y**2+z**2+x*y+y*z+z*x
k-=1
if 0<=k<=n-1:
ans[k]+=1
for i in ans:
print(i)
| 1 | 7,938,286,113,002 | null | 106 | 106 |
import numpy as np
a = int(input())
print(int( np.ceil((2000-a)/200)))
|
def get_num(n, x):
ans = 0
for n3 in xrange(min(n, x - 3), (x + 2) / 3, -1):
for n2 in xrange(min(n3 - 1, x - n3 - 1), (x - n3 + 1) / 2 - 1, -1):
for n1 in xrange(min(n2 - 1, x - n3 - n2), 0, -1):
if n3 == x - n1 - n2:
ans += 1
break
return ans
data = []
while True:
[n, x] = [int(m) for m in raw_input().split()]
if [n, x] == [0, 0]:
break
if x < 3:
# print(0)
data.append(0)
else:
# print(get_num(n, x))
data.append(get_num(n, x))
for n in data:
print(n)
| 0 | null | 3,985,721,718,342 | 100 | 58 |
n,m=map(int,input().split())
A = list(map(int,input().split()))
A.sort()
A = A[::-1]
for i in range(m):
if A[i]*4*m < sum(A):
print("No")
break
else:
print("Yes")
|
N, M = map(int, input().split())
A = list(map(int, input().split()))
total = sum(A)
print('Yes' if M <= len(list(filter(lambda x: x, map(lambda x: x * 4 * M >= total, A)))) else 'No')
| 1 | 38,545,232,132,484 | null | 179 | 179 |
import math
def main():
n=int(input())
print(math.ceil(n/2)/n)
if __name__ == '__main__':
main()
|
n = int(input())
if n%2 == 0:
print(float((n//2)/n))
elif n == 1:
print(float(1))
else:
print(float((n//2 + 1)/n))
| 1 | 177,112,084,671,602 | null | 297 | 297 |
a,b = input().split()
if 500 * int(a) >= int(b):
print('Yes')
else:
print('No')
|
def func(K, X):
YEN = 500
ans = 'Yes' if YEN * K >= X else 'No'
return ans
if __name__ == "__main__":
K, X = map(int, input().split())
print(func(K, X))
| 1 | 98,120,676,313,088 | null | 244 | 244 |
# Aizu Problem ALDS_1_4_D: Allocation
import sys, math, os
# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
sys.stdin = open("sample-input2.txt", "rt")
def check(n, k, W, p):
idx = 0
for i in range(k):
S = 0
while W[idx] + S <= p:
S += W[idx]
idx += 1
if idx == n:
return True
return False
n, k = [int(_) for _ in input().split()]
W = [int(input()) for _ in range(n)]
left, right = 0, 10**16
while right - left > 1:
mid = (left + right) // 2
if check(n, k, W, mid):
right = mid
else:
left = mid
print(right)
|
def stackable(pack, tmp_p, k):
cur_w = 0
trucks = 1
for i in range(len(pack)):
if tmp_p < pack[i]:
return False
if cur_w + pack[i] <= tmp_p:
cur_w += pack[i]
else:
cur_w = pack[i]
trucks += 1
if k < trucks:
return False
return True
n, k = map(int, input().split())
pack = []
for i in range(n):
pack.append(int(input()))
left = int(sum(pack) / k)
right = max(pack) * n
while left < right - 1:
tmp_p = int((left + right) / 2)
if stackable(pack, tmp_p, k):
right = tmp_p
else:
left = tmp_p
if stackable(pack, left, k):
print(left)
else:
print(right)
| 1 | 86,988,434,808 | null | 24 | 24 |
#import numpy as np
import math
#from decimal import *
#from numba import njit
#@njit
def main():
(N, M, K) = map(int, input().split())
MOD = 998244353
fact = [1]*(N+1)
factinv = [1]*(N+1)
for i in range(1,N+1):
fact[i] = fact[i-1]*i % MOD
factinv[i] = pow(fact[i], MOD-2, MOD)
def comb(n, k):
return fact[n] * factinv[k] * factinv[n-k] % MOD
ans = 0
for k in range(K+1):
ans += (comb(N-1,k)*M*pow(M-1, N-k-1, MOD))%MOD
print(ans%MOD)
main()
|
import sys
sys.setrecursionlimit(1000000)
def main():
a, b, c, d = map(int, input().split())
max_ab = max(a, b)
min_ab = min(a,b)
max_cd = max(c,d)
min_cd = min(c,d)
# ab ++
if min_ab >= 0:
# cd ++
if min_cd >= 0:
# ++
print(max_ab * max_cd)
# cd +-
elif max_cd >= 0:
# ++
print(max_ab * max_cd)
# cd --
else:
# +-
print(min_ab * max_cd)
# ab +-
elif max_ab >= 0:
# cd ++
if min_cd >= 0:
# ++
print(max_ab * max_cd)
# cd +-
elif max_cd >= 0:
# ++ or --
print(max(max_ab * max_cd, min_ab * min_cd))
# cd --
else:
# --
print(min_ab * min_cd)
# ab --
else:
# cd ++
if min_cd >= 0:
# -+
print(max_ab * min_cd)
# cd +-
elif max_cd >= 0:
# --
print(min_ab * min_cd)
# cd --
else:
# --
print(min_ab * min_cd)
main()
| 0 | null | 13,225,409,697,708 | 151 | 77 |
def bingo():
# 初期処理
A = list()
b = list()
comb_list = list()
is_bingo = False
# 入力
for _ in range(3):
dummy = list(map(int, input().split()))
A.append(dummy)
N = int(input())
for _ in range(N):
dummy = int(input())
b.append(dummy)
# ビンゴになる組み合わせ
for i in range(3):
# 横
comb_list.append([A[i][0], A[i][1], A[i][2]])
# 縦
comb_list.append([A[0][i], A[1][i], A[2][i]])
# 斜め
comb_list.append([A[0][0], A[1][1], A[2][2]])
comb_list.append([A[0][2], A[1][1], A[2][0]])
# 集計(出現した数字をnullに置き換え)
for i in b:
for j in range(8):
for k in range(3):
if i == comb_list[j][k]:
comb_list[j][k] = 'null'
# すべてnullのリストの存否
for i in comb_list:
for j in i:
if 'null' != j:
is_bingo = False
break
else:
is_bingo = True
# 一組でもbingoがあれば即座に関数を抜ける
if is_bingo == True:
return 'Yes'
# すべてのリストを確認後
if is_bingo == False:
return 'No'
result = bingo()
print(result)
|
from collections import defaultdict
dic = defaultdict(list)
for i in range(3):
a = list(map(int,input().split()))
for j in range(3):
dic[a[j]].append([i,j])
n = int(input())
B = []
for _ in range(n):
b = int(input())
B.append(b)
h = [0]*3
w = [0]*3
d = 0
di = 0
for b in B:
if b not in dic:
continue
x,y = dic[b][0]
if x== y:
d += 1
if x + y ==2:
di += 1
h[x] += 1
w[y] += 1
for i in range(3):
if h[i]==3 or w[i]==3:
print('Yes');exit()
if d ==3 or di ==3:
print('Yes');exit()
print('No')
| 1 | 59,749,469,022,882 | null | 207 | 207 |
write = open(1, 'w').write
for i in range(1, int(open(0).read())+1):
if i % 3:
if "3" in str(i):
write(" %d" % i)
else:
write(" %d" % i)
write("\n")
|
def check(st):
for d in range(len(st)):
if st[d]=="3":
return True
return False
num = int(input())
str=""
for d in range(3,num+1):
s = "%d"%(d)
if d%3==0 or check(s):
str+=" %d"%(d)
print(str)
| 1 | 928,798,350,938 | null | 52 | 52 |
def row():
c=0
for y in range(HEIGHT):
for x in range(WIDTH):
if A[y][x]!=-1:
break
else:
c+=1
return c
def col():
c=0
for x in range(WIDTH):
for y in range(HEIGHT):
if A[y][x]!=-1:
break
else:
c+=1
return c
def obl():
c=0
for z in range(HEIGHT):
if A[z][z]!=-1:
break
else:
c+=1
y=0
for x in range(WIDTH-1,-1,-1):
if A[y][x]!=-1:
break
y+=1
else:
c+=1
return c
def main():
for b in B:
for y in range(HEIGHT):
for x in range(WIDTH):
if A[y][x]==b:
A[y][x]=-1
cnt=row()+col()+obl()
print('Yes' if cnt else 'No')
if __name__=='__main__':
HEIGHT=3
WIDTH=3
A=[[int(a) for a in input().split()] for y in range(HEIGHT)]
N=int(input())
B=[int(input()) for n in range(N)]
main()
|
s = input()
result = 'No'
if len(s) % 2 == 0:
result = 'Yes'
for i in range(int(len(s) / 2)):
if s[i*2:i*2+2] != 'hi':
result = 'No'
break
print(result)
| 0 | null | 56,518,215,941,038 | 207 | 199 |
n = int(input())
k = n//10
if n%10 == 7:
print("Yes")
elif k%10 == 7:
print("Yes")
elif n//100 == 7:
print("Yes")
else:
print("No")
|
n=list(map(int,input()))
if 7 in n:
print("Yes")
else:
print("No")
| 1 | 34,425,004,985,322 | null | 172 | 172 |
import math
from sys import stdin,stdout
#% 998244353
from heapq import heapify,heappop,heappush
import collections
s = stdin.readline()[:-1]
print(s[:3])
|
print((input())[:3])
| 1 | 14,826,501,462,150 | null | 130 | 130 |
import sys
input = sys.stdin.buffer.readline
N, K = map(int, input().split())
A = [-1] + list(map(int, input().split()))
I = [-1] * (N + 1)
S = []
idx = 1
while I[idx] == -1:
S.append(idx)
I[idx] = len(S)
idx = A[idx]
# print(f'{S=}, {idx=}, {I[idx]=}')
start_idx = I[idx] - 1
num_circles = len(S) - start_idx
# print(f'{start_idx=}, {num_circles=}')
if K < len(S) - 1:
ans = S[K]
else:
K -= start_idx
div, mod = divmod(K, num_circles)
ans = S[start_idx + mod]
print(ans)
|
#
import sys
input=sys.stdin.readline
def main():
N=input().strip("\n")
K=int(input())
# dp[i][j][k]=i桁目 j: nonzero数 k:N以下確定か
dp=[[[0]*(2) for i in range(K+1)] for j in range(len(N))]
dp[0][0][1]=1
dp[0][1][1]=int(N[0])-1
dp[0][1][0]=1
for i in range(len(N)):
dp[i][0][1]=1
for i in range(1,len(N)):
d=int(N[i])
for j in range(1,K+1):
if d!=0:
dp[i][j][1]=dp[i-1][j-1][1]*9+dp[i-1][j-1][0]*(d-1)
# nonzeroを使う場合i-1で既にN以下確定なら好き勝手できる*9
dp[i][j][1]+=dp[i-1][j][1]+dp[i-1][j][0]
# zeroを使う場合
dp[i][j][0]=dp[i-1][j-1][0]
# d未満とったら確定するため。
else:
dp[i][j][1]=dp[i-1][j-1][1]*9+dp[i-1][j][1]
dp[i][j][0]=dp[i-1][j][0]
print(sum(dp[len(N)-1][K]))
if __name__=="__main__":
main()
| 0 | null | 49,270,390,472,040 | 150 | 224 |
#!/usr/bin/env python3
import sys
import numpy as np
def input():
return sys.stdin.readline().rstrip()
def main():
# n, k = map(int, sys.stdin.buffer.readline().split())
n, k = map(int, input().split())
# warps = list(map(int, sys.stdin.buffer.readline().split()))
warps = list(map(int, input().split()))
warps = [0] + warps
warps = np.array(warps, dtype=int)
dp = np.zeros((k.bit_length() + 1, n + 1), dtype=int)
dp[0, :] = warps
for h in range(1, len(dp)):
dp[h] = dp[h - 1][dp[h - 1]]
node = 1
# for i in reversed(range(k.bit_length())):
for i in range(k.bit_length(), -1, -1):
if k >> i & 1:
node = dp[i][node]
print(node)
main()
|
N=int(input())
S=input()
ans=0
for i in range(N-2):
if S[i:i+3]=='ABC':
ans+=1
print(ans)
| 0 | null | 60,893,781,059,712 | 150 | 245 |
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
#import queue
from copy import copy, deepcopy
from operator import itemgetter
import bisect#2分探索
#bisect_left(l,x), bisect(l,x)
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
#dequeを使うときはpython3を使う、pypyはダメ
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#q=heapq.heapify(l),heappush(q,a),heappop(q)
def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s): return sorted(range(len(s)), key=lambda k: s[k])
#mod = 10**9+7
#N = int(input())
N, P = map(int, input().split())
S=input()
#L = [int(input()) for i in range(N)]
#A = list(map(int, input().split()))
#S = [inputl() for i in range(H)]
#q = queue.Queue() #q.put(i) #q.get()
#q = queue.LifoQueue() #q.put(i) #q.get()
#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b=copy.deepcopy(a) #2次元配列はこうコピーする
#w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え
#素数リスト
# n = 100
# primes = set(range(2, n+1))
# for i in range(2, int(n**0.5+1)):
# primes.difference_update(range(i*2, n+1, i))
# primes=list(primes)
#bisect.bisect_left(a, 4)#aはソート済みである必要あり。aの中から4未満の位置を返す。rightだと以下
#bisect.insort_left(a, 4)#挿入
if P!=2 and P!=5:
pc=[0]*P
pc[0]=1
count=0
ans=0
p10=1
for i in range(1,N+1):
count+=int(S[N-i])*p10
count%=P
ans+=pc[count]
pc[count]+=1
p10*=10
p10%=P
print(ans)
else:
ans=0
for i in range(1,N+1):
if int(S[N-i])%P==0:
ans+=N-i+1
print(ans)
|
import sys
def input(): return sys.stdin.readline().rstrip()
from bisect import bisect_left,bisect
def main():
n=int(input())
S=list(input())
q=int(input())
set_s={chr(ord('a')+i):[] for i in range(26)}
for i,s in enumerate(S):
set_s[s].append(i)
for _ in range(q):
query=input().split()
if query[0]=="1":
i,c=int(query[1])-1,query[2]
if S[i]==c:continue
set_s[S[i]].remove(i)
set_s[c].insert(bisect_left(set_s[c],i),i)
S[i]=c
else:
l,r=int(query[1])-1,int(query[2])-1
ans=0
for i in range(26):
ss=chr(ord('a')+i)
if bisect(set_s[ss],r)>bisect_left(set_s[ss],l):
ans+=1
print(ans)
if __name__=='__main__':
main()
| 0 | null | 60,237,630,484,970 | 205 | 210 |
N,K = map(int,input().split())
A = list(map(int,input().split()))
A = sorted(A)
mod = 10**9+7
def p(m,n):
a = 1
for i in range(n):
a = a*(m-i)
return a
def p_mod(m,n,mod):
a = 1
for i in range(n):
a = a*(m-i) % mod
return a
def c(m,n):
return p(m,n) // p(n,n)
def c_mod(m,n,mod):
return (p_mod(m,n,mod)*pow(p_mod(n,n,mod),mod-2,mod)) % mod
C = [0]*(N-K+1) #C[i] = (N-i-1)C_(K-1),予め二項係数を計算しておく
for i in range(N-K+1):
if i == 0:
C[i] = c_mod(N-1,K-1,mod)
else:
C[i] = (C[i-1]*(N-K-i+1)*pow(N-i,mod-2,mod)) % mod
#各Aの元が何回max,minに採用されるかを考える
ans = 0
for i in range(N-K+1):
ans -= (A[i]*C[i]) % mod
A.reverse()
for i in range(N-K+1):
ans += (A[i]*C[i]) % mod
print(ans % mod)
|
import sys
sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7
def input():
return sys.stdin.readline().strip()
class Combination:
"""
O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる
n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
使用例:
comb = Combination(1000000)
print(comb(5, 3)) # 10
"""
def __init__(self, n_max, mod=10 ** 9 + 7):
self.mod = mod
self.modinv = self.make_modinv_list(n_max)
self.fac, self.facinv = self.make_factorial_list(n_max)
def __call__(self, n, r):
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod
def make_factorial_list(self, n):
# 階乗のリストと階乗のmod逆元のリストを返す O(n)
# self.make_modinv_list()が先に実行されている必要がある
fac = [1]
facinv = [1]
for i in range(1, n + 1):
fac.append(fac[i - 1] * i % self.mod)
facinv.append(facinv[i - 1] * self.modinv[i] % self.mod)
return fac, facinv
def make_modinv_list(self, n):
# 0からnまでのmod逆元のリストを返す O(n)
modinv = [0] * (n + 1)
modinv[1] = 1
for i in range(2, n + 1):
modinv[i] = self.mod - self.mod // i * modinv[self.mod % i] % self.mod
return modinv
def main():
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
comb = Combination(n_max=10 ** 5)
ans = 0
for i in range(N - K + 1):
ans -= comb(N - 1 - i, K - 1) * A[i] % MOD
ans += comb(N - 1 - i, K - 1) * A[N - i - 1] % MOD
ans %= MOD
print(ans)
if __name__ == "__main__":
main()
| 1 | 96,000,710,843,060 | null | 242 | 242 |
def main():
N = int(input())
INF = float('inf')
A = [(i+1, a) for i, a in enumerate(map(int, input().split()))]
A = sorted(A, key=lambda x: x[1], reverse = True)
dp = [[-INF] * (N+1) for _ in range(N+1)]
dp[0][0] = 0
for s in range(1, N+1):
for l in range(s+1):
r = s - l
dp[l][r] = max(dp[l-1][r] + A[s-1][1] * abs(A[s-1][0]-l), dp[l][r-1] + A[s-1][1] * abs(N-r+1-A[s-1][0]))
ans = 0
for m in range(N):
if(dp[m][N-m] > ans):
ans = dp[m][N-m]
print(ans)
main()
|
#E
N = int(input())
A = list(map(int,input().split()))
B = []
for i in range(N):
B.append([A[i],i+1])
B.sort(reverse=True)
DP = [[0 for _ in range(N+1)] for _ in range(N+1)] #dp[x][y] x->1,2,3... y->N,N-1,N-2...
for i in range(N):
I = i+1
b,ind = B[i]
for j in range(I+1):
if j == 0:
DP[j][I-j] = DP[j][I-j-1] + b*abs(N-(I-j)-ind+1)
elif I-j == 0:
DP[j][I-j] = DP[j-1][I-j] + b*abs(ind-j)
else:
DP[j][I-j] = max(DP[j][I-j-1]+b*abs(N-(I-j)-ind+1),DP[j-1][I-j]+b*abs(ind-j))
ans = 0
for i in range(N+1):
ans = max(ans,DP[i][N-i])
#print(B)
print(ans)
| 1 | 33,635,106,859,640 | null | 171 | 171 |
a,b,c = map(int, input().split())
print(len(list(filter(lambda x: c%x==0,range(a,b+1)))))
|
def main():
n,p = map(int,input().split())
s = input()
if p == 2:
ans = 0
for i in range(n):
if int(s[i])%2 == 0:
ans += i+1
print(ans)
return
if p == 5:
ans = 0
for i in range(n):
if int(s[i])%5 == 0:
ans += i+1
print(ans)
return
dp = [0 for _ in range(p)]
dp[0] += 1
x = 0
for i in range(n):
x = (x+int(s[n-1-i])*pow(10,i,p))%p
dp[x] += 1
ans = 0
for i in range(p):
ans += (dp[i]*(dp[i]-1))//2
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 29,202,891,717,366 | 44 | 205 |
def check(p):
global k, wlist
loadage = 0
num = 1
for w in wlist:
loadage += w
if loadage > p:
num += 1
if num > k:
return False
loadage = w
return True
n, k = map(int, input().split())
wlist = []
for _ in range(n):
wlist.append(int(input()))
maxw = max(wlist)
sumw = sum(wlist)
p = 0
while maxw < sumw:
p = (maxw + sumw) // 2
if check(p):
sumw = p
else:
maxw = p = p+1
print(p)
|
S=int(input())
T=list(input())
t=S//2
p=0
for i in range(t):
if S%2==1:
p=-1
break
elif T[i]!=T[i+t]:
p=-1
break
if p==-1 or t==0:
print("No")
elif p==0:
print("Yes")
| 0 | null | 73,708,468,101,488 | 24 | 279 |
#!python3
import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
def _cmb(N, mod):
N1 = N + 1
fact = [1] * N1
inv = [1] * N1
for i in range(2, N1):
fact[i] = fact[i-1] * i % mod
inv[N] = pow(fact[N], mod-2, mod)
for i in range(N-1, 1, -1):
inv[i] = inv[i+1]*(i+1) % mod
def cmb(a, b):
return fact[a] * inv[b] % mod * inv[a-b] % mod
return cmb
def resolve():
K = int(input())
s = input()
ls = len(s) - 1
mod = 10**9+7
cmb = _cmb(ls+K, mod)
ans = 0
pp = 1 * pow(26, K, mod) % mod
px = 25 * pow(26, mod-2, mod) % mod
for i in range(K+1):
ans = (ans + cmb(ls+i, ls) * pp % mod) % mod
pp = pp * px % mod
print(ans)
if __name__ == "__main__":
resolve()
|
import sys
from time import time
from random import randint
def func(s, x):
last = [0] * 26
score = 0
for i, v in enumerate(x, 1):
last[v] = i
c = 0
for j in range(26):
c += s[j] * (i - last[j])
score += s[i * 26 + v] - c
return score
def main():
start = time()
d, *s = map(int, sys.stdin.buffer.read().split())
x = ([*range(26)] * 15)[:d]
M = func(s, x)
while time() - start < 1.8:
y = x.copy()
if randint(0, 1):
y[randint(0, d - 1)] = randint(0, 25)
elif randint(0, 1):
i = randint(0, d - 16)
j = randint(i + 1, i + 15)
y[i], y[j] = y[j], y[i]
else:
i = randint(0, d - 15)
j = randint(i + 1, i + 7)
k = randint(j + 1, j + 7)
if randint(0, 1):
y[i], y[j], y[k] = y[j], y[k], y[i]
else:
y[i], y[j], y[k] = y[k], y[i], y[j]
t = func(s, y)
if t > M:
M = t
x = y
for t in x:
print(t + 1)
if __name__ == '__main__':
main()
| 0 | null | 11,151,755,487,732 | 124 | 113 |
import sys
import collections
input = lambda: sys.stdin.readline().rstrip()
def main():
n = int(input())
a = list(map(int, input().split()))
cnt = collections.Counter(a)
all_comb = 0
for i in cnt.keys():
all_comb += cnt[i] * (cnt[i]-1) // 2
for i in range(n):
comb = all_comb
comb -= cnt[a[i]] * (cnt[a[i]]-1) // 2
comb += (cnt[a[i]]-1) * (cnt[a[i]]-2) // 2
print(comb)
if __name__ == '__main__':
main()
|
import heapq
N,K = map(int,input().split())
Hlist = list(map(int,input().split()))
for i in range(len(Hlist)):
Hlist[i] *= -1
heapq.heapify(Hlist)
for _ in range(min(K,N)):
heapq.heappop(Hlist)
print(-sum(Hlist))
| 0 | null | 63,151,486,290,958 | 192 | 227 |
s=input()
a=s[2]
b=s[3]
c=s[4]
d=s[5]
if a==b and c==d:
print("Yes")
else :
print("No")
|
x = int(input())
ans = x
while True:
jud = 0
if(ans <= 2):
print(2)
break
if(ans%2==0):
jud += 1
i = 3
while i < ans**(1/2):
if(jud>0):
break
if(ans%i == 0):
jud += 1
i += 2
if(jud==0):
print(ans)
break
ans += 1
| 0 | null | 73,705,608,663,288 | 184 | 250 |
x, y = map(int, input().split())
def cmb(n, r, mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
def knight(x, y):
s = (0, 0)
if x == y == 0:
return 0
if (x + y) % 3:
return 0
if (2*y-x)%3 or (2*x-y)%3:
return 0
a, b = (2*y-x)//3, (2*x-y)//3
n = (x+y)//3
r = min(a, b)
if a<0 or b<0:
return 0
return cmb(n, r, mod)
print(knight(x,y))
|
#n回,m回 X =n + 2*m Y = 2*n + m
X,Y = map(int,input().split())
import numpy as np
from functools import reduce
import math
a = [[1, 2], [2, 1]]
#次に逆行列を求めます。
mod = pow(10,9)+7
b = np.linalg.inv(a)
Z = np.array([[X],[Y]])
n,m=np.dot(b,Z)
p,q = *n,*m
def comb(n,k,p):
if k==0:
return 1
A = reduce(lambda x,y:x*y%p ,[n-k+1+i for i in range(k)])
B = reduce(lambda x,y:x*y%p ,[i+1 for i in range(k)])
return A*pow(B,p-2,p)%p
if p<0 or q<0:
print(0)
elif not abs(p-round(p))<pow(10,-3) or not abs(q-round(q))<pow(10,-3):
print(0)
elif p==0 and q==0:
print(0)
elif p==0:
print(1)
elif q==0:
print(1)
else:
n = int(round(p))
m = int(round(q))
ans = comb(n+m,m,mod)
print(ans%mod)
| 1 | 150,276,664,156,180 | null | 281 | 281 |
n, a, b = map(int, input().split())
if (a+b) % 2 == 0:
print((b-a)//2)
else:
if b == a + 1:
print(min(b-1, n-a))
else:
cnt_1 = a + (b-a-1)//2
cnt_n = n - b + 1 + (b-a-1)//2
print(min(cnt_1, cnt_n))
|
N, A, B = map(int, input().split())
ans = 0
if abs(B-A) % 2 == 0:
ans = abs(B-A) // 2
else:
if B > A:
ans = min(N-A, B-1,(N-B+1) + (B-A-1)//2, (A-1+1) + (B-A-1)//2)
if A > B:
ans = min(N-B, A-1,(N-A+1) + (A-B-1)//2, (B-1+1) + (A-B-1)//2)
print(ans)
| 1 | 109,852,342,604,200 | null | 253 | 253 |
if __name__ == '__main__':
A, B = map(int, input().split())
print(A*B)
|
A, B = map(int, input().split())
R = A * B
print(R)
| 1 | 15,770,713,863,680 | null | 133 | 133 |
S = int(input())
dp = [0 for _ in range(S+1)]
dp[0] = 1
MOD = 10**9+7
for i in range(3,S+1):
dp[i] = dp[i-1]+dp[i-3]
print(dp[S]%MOD)
|
s=int(input())
a=[0]*(s+1)
a[0]=1
mod=10**9+7
for i in range(3,s+1):
a[i]=a[i-3]+a[i-1]
print(a[s]%mod)
| 1 | 3,259,892,435,194 | null | 79 | 79 |
N, K = map(int, input().split())
H = list(map(int, input().split()))
h = sorted(H, reverse=True)
a = h[K:]
ans = sum(a)
print(ans)
|
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys
INF = float('inf')
def solve(N: int, K: int, H: "List[int]"):
return sum(sorted(H)[:-K]) if K != 0 else sum(H)
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
K = int(next(tokens)) # type: int
H = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
print(f'{solve(N, K, H)}')
if __name__ == '__main__':
main()
| 1 | 79,021,446,631,190 | null | 227 | 227 |
input_line = input()
Line = input_line.split()
Line = [int(s) for s in Line]
if Line[0]*500 >= Line[1]:
print("Yes")
else:
print("No")
|
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))
K, X = input_nums()
if 500*K >= X:
print('Yes')
else:
print('No')
| 1 | 98,248,931,475,072 | null | 244 | 244 |
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
def get_point(x):
if x == 'r':
return P
if x == 's':
return R
if x == 'p':
return S
# think each mod K
ans = 0
for i in range(K):
dp = [0] * 2
pre = ''
for j in range(i, N, K):
dp2 = dp[:]
dp2[0] = max(dp)
if pre == T[j]:
dp2[1] = dp[0] + get_point(T[j])
else:
dp2[1] = max(dp) + get_point(T[j])
pre = T[j]
dp = dp2
ans += max(dp)
print(ans)
|
N, K = map(int, input().split())
R, S, P = map(int, input().split())
POINTS = (R, P, S)
T = [("r", "p", "s").index(c) for c in input()]
WIN = [(t + 1) % 3 for t in T]
ans = 0
for i in range(K):
p = [0] * 3
p[WIN[i]] = POINTS[WIN[i]]
j = i + K
while j < N:
n = [-1] * 3
for px, pp in enumerate(p):
if pp < 0:
continue
for nx in range(3):
if nx == px:
continue
np = pp
if nx == WIN[j]:
np += POINTS[WIN[j]]
n[nx] = max(n[nx], np)
p = n
j += K
ans += max(p)
print(ans)
| 1 | 106,374,206,260,838 | null | 251 | 251 |
x=list(input())
print('Yes' if '7' in x else 'No')
|
data_h = []
data_w = []
while True:
h, w = (int(i) for i in input().split())
if h == w == 0:
break
else:
data_h.append(h)
data_w.append(w)
for i in range(len(data_h)):
h = data_h[i]
w = data_w[i]
for j in range(1,h+1):
for k in range(1,w+1):
if j == 1 or j == h or k == 1 or k == w:
print('#',end='')
else:
print('.',end='')
print('')
print('')
| 0 | null | 17,467,467,154,508 | 172 | 50 |
n,k = map(int,input().split())
person = [0]*n
for i in range(k):
d = int(input())
A = list(map(int,input().split()))
for j in range(len(A)):
person[A[j]-1] = 1
print(person.count(0))
|
if __name__ == '__main__':
n,k = map(int,input().split())
A = [0] * n
for _ in range(k):
m = int(input())
B = list(map(int,input().split()))
for b in B:
A[b-1] += 1
print(A.count(0))
| 1 | 24,635,214,833,372 | null | 154 | 154 |
K = int(input())
A, B = map(int,input().split())
C = A % K
if B - A >= K - 1:
print('OK')
elif C == 0:
print('OK')
elif C + B - A >= K:
print('OK')
else:
print('NG')
|
import math
a,b,c=map(float,input().split())
c=math.radians(c)
h=b*math.sin(c)
s=a*h/2
d=math.sqrt(a**2+b**2-2*a*b*math.cos(c))
l=a+b+d
print(s,l,h)
| 0 | null | 13,451,317,407,008 | 158 | 30 |
def tripleDots(n, string):
string_len = len(string)
if string_len > n :
string = string[ 0 : n ] + "..."
print(string)
arr = ["", ""]
for i in range(2):
arr[i] = input()
tripleDots(int(arr[0]), arr[1])
|
K = int(input())#asking lenght of string wanted to be shorted
S = input()#asking string
if len(S)>K:##set that S must be greater than K
print (S[:K], "...",sep="")# to print only the K number of the string
else:
print (S)
| 1 | 19,643,611,426,038 | null | 143 | 143 |
import sys
from collections import deque
input_lines = sys.stdin.readlines()
doublyLinkedList = deque()
for x in input_lines[1:]:
oneLine = x.split()
if 'insert' in oneLine[0]:
doublyLinkedList.appendleft((int)(oneLine[1]))
elif 'delete' == oneLine[0]:
remove_value = (int)(oneLine[1])
if remove_value in doublyLinkedList:
doublyLinkedList.remove(remove_value)
elif 'deleteFirst'in oneLine[0]:
doublyLinkedList.popleft()
elif 'deleteLast' in oneLine[0]:
doublyLinkedList.pop()
print(*doublyLinkedList)
|
# coding=utf-8
from collections import deque
n = int(input())
deque = deque()
input_lines = [input().split() for x in range(n)]
for i in range(n):
inp = input_lines[i]
if inp[0] == 'deleteFirst':
deque.popleft()
elif inp[0] == 'deleteLast':
deque.pop()
elif inp[0] == 'insert':
deque.appendleft(inp[1])
else:
if inp[1] in deque:
deque.remove(inp[1])
print(*deque)
| 1 | 52,237,696,278 | null | 20 | 20 |
import sys
def dfs(u):
global time
color[u] = "GRAY"
time += 1
d[u] = time
for v in range(n):
if M[u][v] and color[v] == "WHITE":
dfs(v)
color[u] = "BLACK"
time += 1
f[u] = time
if __name__ == "__main__":
n = int(sys.stdin.readline())
color = ["WHITE"] * n
time = 0
d = [-1] * n
f = [-1] * n
M = [[0] * n for i in range(n)]
for inp in sys.stdin.readlines():
inp = list(map(int, inp.split()))
for i in inp[2:]:
M[inp[0]-1][i-1] = 1
for i in range(n):
if d[i] == -1:
dfs(i)
for i in range(n):
print(i+1, d[i], f[i])
|
#!/usr/bin/env python3
from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline
INF = float('inf')
n_nodes = int(input())
graph = [[] for _ in range(n_nodes)]
for _ in range(n_nodes):
line = list(map(int, input().split()))
u, k = line[0], line[1]
if k > 0:
for v in line[2:]:
graph[u - 1].append(v - 1)
# pprint(graph)
def dfs(v):
global time
time += 1
for v_adj in graph[v]:
if d[v_adj] == -1:
d[v_adj] = time
dfs(v_adj)
f[v] = time
time += 1
d = [-1] * n_nodes
f = [-1] * n_nodes
time = 1
for v in range(n_nodes):
if d[v] == -1:
d[v] = time
dfs(v)
# pprint(d)
# pprint(f)
for v in range(n_nodes):
print(f"{v + 1} {d[v]} {f[v]}")
| 1 | 2,492,801,480 | null | 8 | 8 |
if __name__ == '__main__':
N, M = map(int, input().split())
S = []
C = []
for i in range(M):
s, c = map(int, input().split())
s -= 1
S.append(s)
C.append(c)
for num in range(0, pow(10, N)):
st_num = str(num)
if len(str(st_num))!=N: continue
cnt = 0
for m in range(M):
if int(st_num[S[m]])==C[m]:
cnt += 1
if cnt==M:
print(st_num)
quit()
print(-1)
|
N = int(input())
X = list(map(int, input().split()))
P = round(sum(X)/N)
ans = sum(list(map(lambda x: (x-P)**2, X)))
print(ans)
| 0 | null | 62,941,602,488,192 | 208 | 213 |
L, R = input().split()
huga = list(map(int, input().split()))
i=0
gou=0
huga.sort()
for a in range(int(R)):
gou=gou+huga[i]
i+=1
print(gou)
|
N = int(input())
def sum(n):
return (n + 1) * n // 2
print(sum(N) - sum(N // 3) * 3 - sum(N // 5) * 5 + sum(N // 15) * 15)
| 0 | null | 23,168,105,649,332 | 120 | 173 |
K = int(input())
S = input()
if len(S) > K:
ans = S[0: K-len(S)]
ans += "..."
else:
ans = S
print(ans)
|
k = int(input())
l = str(input())
if k >= len(l):
print(l)
else:
print(l[:k]+"...")
| 1 | 19,618,554,711,006 | null | 143 | 143 |
# happendはsetで保持しておき,roopはlistで保持しておく
N, X, M = map(int, input().split()) # modMは10**5以下が与えられる
happend = set()
A = [X]
MOD = M
# 第1~N項まで計N項の和をもとめる
start = 0
for _ in range(N-1):
if A[-1]**2 % MOD not in happend:
happend.add(A[-1]**2 % MOD)
A.append(A[-1]**2 % MOD)
else:
start = A.index(A[-1]**2 % MOD)
break
roop_count = (N-start)//len(A[start:])
ans = sum(A[:start]) + sum(A[start:])*roop_count + sum(A[start:start+(N-start) % len(A[start:])])
# print(A[:start], A[start:], A[start:start+(N-start) % len(A[start:])])
print(ans)
|
from bisect import bisect_left, bisect_right
n = int(input())
stick = list(map(int, input().split()))
stick.sort()
count = 0
for i in range(n):
for j in range(i + 1, n):
l = bisect_right(stick, stick[j] - stick[i])
r = bisect_left(stick, stick[i] + stick[j]) # [l, r) が範囲
if j + 1 >= r:
continue
count += r - max(l, j + 1)
print(count)
| 0 | null | 87,223,343,954,500 | 75 | 294 |
H,W=map(int,input().split())
import sys
N=1
if W==1 or H==1:
print(1)
sys.exit()
if (W-1)%2==0:
N+=(W-1)//2
N+=(W-1)//2
elif (W-1)%2==1:
N+=(W-2)//2
N+=W//2
if H%2==0:
NN=N*(H//2)
elif H%2==1:
if (W-1)%2==0:
NN=N*((H-1)//2)+(W-1)//2+1
elif (W-1)%2==1:
NN=N*((H-1)//2)+(W-2)//2+1
print(NN)
|
s = input()
count = 0
max = 0
for i in range(len(s)):
if s[i] == 'S':
count =0
else:
count += 1
if count > max:
max = count
print(max)
| 0 | null | 27,887,714,296,098 | 196 | 90 |
N = (list(input()))
N =N[::-1]
N_int = [int(i) for i in N]
N_int.append(0)
maisu = 0
keta = False
for i in range(len(N_int)-1):
if keta ==True:
N_int[i] +=1
if N_int[i]<5:
maisu +=N_int[i]
keta =False
elif N_int[i]==5 :
if N_int[i+1]>4:
keta =True
maisu +=(10-N_int[i])
else:
keta =False
maisu += N_int[i]
else:
keta =True
maisu +=(10-N_int[i])
if keta ==True:
maisu +=1
print(maisu)
|
N=input()
inf=float("inf")
dp=[[inf]*(len(N)+1) for i in range(2)]
dp[0][0]=0
for i in range(len(N)):
tmp=int(N[-1-i])
dp[0][i+1]=min(dp[0][i],dp[1][i])+tmp
dp[1][i+1]=min(dp[0][i]+11,dp[1][i]+9)-tmp
print(min(dp[0][-1],dp[1][-1]))
| 1 | 70,930,892,704,790 | null | 219 | 219 |
N = int(input())
L = [i for i in range(1, N + 1) if i % 2 != 0]
A = len(L) / N
print(A)
|
from collections import Counter
#N, K = map(int, input().split( ))
#L = list(map(int, input().split( )))
N = int(input())
A = list(map(int, input().split( )))
Q = int(input())
Sum = sum(A)
#Counterなるものがあるらしい
coun = Counter(A)
#Q個の整数の組(B,C)が与えられてB \to Cとして合計を計算
#合計は(Ci-Bi)*(A.count(Bi))変化する.
for _ in range(Q):
b, c = map(int, input().split( ))
Sum += (c-b)*coun[b]
coun[c] += coun[b]
coun[b] = 0
print(Sum)
# replaceするとタイムエラーになるのか…
# A = [c if a == b else a for a in A]
| 0 | null | 94,604,142,616,302 | 297 | 122 |
def insertion_sort(A, n, g):
cnt = 0
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j + g] = A[j]
j -= g
cnt += 1
A[j + g] = v
return cnt
def shell_sort(A, n):
cnt = 0
G = [1]
for i in range(1, 100):
# https://web.archive.org/web/20170212072405/http://www.programming-magic.com/20100507074241/
# 間隔
delta = 4 ** i + 3 * 2 ** (i - 1) + 1
if delta >= n:
break
G.append(delta)
G.reverse()
m = len(G)
for i in range(m):
cnt += insertion_sort(A, n, G[i])
return m, G, cnt
n = int(input())
A = [int(input()) for _ in range(n)]
m, G, cnt = shell_sort(A, n)
print(m)
print(*G)
print(cnt)
print(*A, sep='\n')
|
cnt = 0
n = int(raw_input())
A = [int(raw_input()) for _ in range(n)]
G = [1] if n < 5 else [1, 4]
while G[-1]*3+1 <= n/5: G.append(G[-1]*3+1)
G.reverse()
def insersionSort(g):
global cnt
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
def shellSort():
for g in G:
insersionSort(g)
shellSort()
print len(G)
print " ".join(map(str, G))
print cnt
print "\n".join(map(str, A))
| 1 | 30,471,243,292 | null | 17 | 17 |
def cmb(n,k,p):
x,y = 1,1
for i in range(k):
x = x * (n-i) % p
y = y * (i+1) % p
res = x * pow(y,p-2,p) % p
return res
N,A,B = map(int,input().split())
mod = 10**9+7
print((pow(2,N,mod)-cmb(N,A,mod)-cmb(N,B,mod)-1)%mod)
|
from sys import stdin, setrecursionlimit
def main():
input = stdin.buffer.readline
n, r = map(int, input().split())
if n >= 10:
print(r)
else:
print(r + 100 * (10 - n))
if __name__ == "__main__":
setrecursionlimit(10000)
main()
| 0 | null | 64,507,074,219,840 | 214 | 211 |
n,m=map(int,input().split())
*s,=map(int,input()[::-1])
i=0
a=[]
while i<n:
j=min(n,i+m)
while s[j]:j-=1
if j==i:
print(-1)
exit()
a+=j-i,
i=j
print(*a[::-1])
|
n,m=map(int,input().split())
s=input()[::-1]
ans=[]
now=0
while(now<n):
t=1
for i in reversed(range(1,m+1)):
if now+i>n or s[now+i]=='1':
continue
now=now+i
ans.append(i)
t=0
break
if t:
print(-1)
exit()
ans.reverse()
print(*ans,sep=' ')
| 1 | 139,274,729,748,742 | null | 274 | 274 |
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if a == b:
print('YES')
else:
if v <= w:
print('NO')
else:
if abs(a-b) / (v - w) <= t:
print('YES')
else:
print('NO')
|
length, time, speed = [int(x) for x in input().split(" ")]
if length / speed <= time:
print("Yes")
else:
print("No")
| 0 | null | 9,414,588,556,764 | 131 | 81 |
def insertion_sort(A, N):
yield A
for i in range(1, N):
v = A[i]
j = i - 1
while j >= 0 and A[j] > v:
# 右にずらす
A[j + 1] = A[j]
j -= 1
A[j + 1] = v
yield A
N = int(input())
A = list(map(int, input().split()))
for li in insertion_sort(A, N):
print(*li)
|
# coding:utf-8
def insertionSort(A, N):
for i in range(1, N):
v = A[i]
j = i - 1
while j >= 0 and A[j] > v:
A[j + 1] = A[j]
j -= 1
A[j + 1] = v
for i in A:
print i,
else:
print
N = input()
A = map(int, raw_input().split())
for i in A:
print i,
else:
print
insertionSort(A,N)
| 1 | 6,374,373,192 | null | 10 | 10 |
import math
A, B, H, M = map(int, input().split())
a = math.pi/360 * (H*60 + M)
b = math.pi/30 * M
# if abs(a - b) > math.pi:
# theta = 2 * math.pi - abs(a-b)
# else:
theta = abs(a-b)
L = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(theta))
print(L)
|
import math
a, b, h, m = map(int,input().split())
time = h * 60 + m
ta = time * 2 * math.pi / (12 * 60)
tb = time * 2 * math.pi / 60
xa = a * math.sin(ta)
ya = a * math.cos(ta)
xb = b * math.sin(tb)
yb = b * math.cos(tb)
ans = math.sqrt((xa-xb)**2 + (ya-yb)**2)
print(ans)
| 1 | 19,929,497,773,860 | null | 144 | 144 |
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15
from collections import deque,defaultdict,Counter
def main():
N = int(input())
G = [[] for _ in range(N)]
for i in range(N):
A = list(map(int,input().split()))
for a in A[2:]:
a -= 1
G[i].append(a)
q = deque([0])
dist = [-1] * N
dist[0] = 0
while q:
v = q.popleft()
for e in G[v]:
if dist[e] >= 0:
continue
dist[e] = dist[v] + 1
q.append(e)
ans = [(i + 1,dist[i]) for i in range(N)]
for t in ans:
print(*t)
if __name__ == '__main__':
main()
|
n = int(input())
MOD = 1000000007
s = [0]*2020
s[0]=1
s[1]=0
s[2]=0
for i in range(3,n+1,1):
s[i] = (s[i] + sum(s[:(i-2)])) % MOD
print(s[n])
| 0 | null | 1,651,084,034,258 | 9 | 79 |
from math import *
from decimal import *
a,b,c=map(int,input().split())
if 4*a*b<(c-a-b)**2 and c-a-b>0:
print("Yes")
else:
print("No")
|
a,b,c = map(int, input().split())
print(str(c)+" "+str(a)+" "+str(b))
| 0 | null | 44,754,885,775,420 | 197 | 178 |
print("YNeos"[len(set(input().split())) != 2::2])
|
a, b, c = map(int, input().split())
ret = "No"
if (a == b and a != c) or (b == c and c != a) or (c == a and a != b):
ret = "Yes"
print("{}".format(ret))
| 1 | 68,279,940,541,062 | null | 216 | 216 |
n = int(input())
movies = {}
summize = 0
for i in range(n):
input_str = input().split()
summize += int(input_str[1])
movies.setdefault(input_str[0], summize)
title = input()
print(summize - movies[title])
|
n=int(input())
slist=[]
tlist=[]
ans=0
yn=0
for i in range(n):
s,t=input().split()
slist.append(s)
tlist.append(int(t))
x=input()
for i in range(n):
if yn==1:
ans+=tlist[i]
if x==slist[i]:
yn=1
print(ans)
| 1 | 96,715,946,209,220 | null | 243 | 243 |
s = input()
n = list(s)
print(n[0]+n[1]+n[2])
|
S = input()
ss = str()
for s in S:
ss = ss + s
if len(ss)==3:
print (ss)
break
| 1 | 14,677,428,258,698 | null | 130 | 130 |
h,a=map(int,input().split())
if h%a!=0:
n=int(h/a)+1
print(n)
else:
n=int(h/a)
print(n)
|
N,K = list(map(int, input().split()))
A = list(map(int, input().split()))
from itertools import accumulate
if K>=50:
print(*[N]*N)
exit()
for _ in range(K):
ans=[0]*(N+1)
for i,a in enumerate(A):
ans[max(0,i-a)]+=1
ans[min(i+a+1,N)]-=1
A = list(accumulate(ans))[:-1]
if all(i == N for i in A):
break
print(*A)
| 0 | null | 46,062,606,964,310 | 225 | 132 |
def main():
mod=1000000007
s=int(input())
m=s*2
inv=lambda x: pow(x,mod-2,mod)
Fact=[1] #階乗
for i in range(1,m+1):
Fact.append(Fact[i-1]*i%mod)
Finv=[0]*(m+1) #階乗の逆元
Finv[-1]=inv(Fact[-1])
for i in range(m-1,-1,-1):
Finv[i]=Finv[i+1]*(i+1)%mod
def comb(n,r):
if n<r:
return 0
return Fact[n]*Finv[r]*Finv[n-r]%mod
ans=0
num=s//3
for i in range(1,num+1):
n=s-i*3
ans+=comb(n+i-1,n)
ans%=mod
print(ans)
if __name__=='__main__':
main()
|
s = int(input())
mod = 10**9+7
import numpy as np
if s == 1 or s == 2:
print(0)
elif s == 3:
print(1)
else:
array = np.zeros(s+1)
array[0] = 1
for i in range(3, s+1):
array[i] = np.sum(array[:i-2]) % mod
print(int(array[s]))
| 1 | 3,275,685,567,950 | null | 79 | 79 |
N = input()
K = int(input())
def solve(N, K):
l = len(N)
dp = [[[0] * (10) for i in range(2)] for _ in range(l+1)]
dp[0][0][0] = 1
for i in range(l):
D = int(N[i])
for j in range(2):
for k in range(K+1):
for d in range(10):
if j == 0 and d > D: break
dp[i+1][j or (d < D)][k if d == 0 else k+1] += dp[i][j][k]
return dp[l][0][K] + dp[l][1][K]
print(solve(N,K))
|
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
ans = 0
Asum = [0 for _ in range(N)]
Asum[0] = A[0]%(10**9+7)
for i in range(1,N):
Asum[i] = (Asum[i-1] + A[i])%(10**9+7)
for i in range(N-1):
ans += (A[i]*(Asum[N-1] - Asum[i]))%(10**9+7)
print(ans%(10**9+7))
| 0 | null | 39,660,698,239,520 | 224 | 83 |
n, d = map(int, input().split())
xy = [map(int, input().split()) for _ in range(n)]
x, y = [list(i) for i in zip(*xy)]
ans = 0
d = d ** 2
for i in range(n):
if ( x[i] ** 2 + y[i] ** 2 ) <= d:
ans += 1
print(ans)
|
#!/usr/bin/env python3
#xy = [map(int, input().split()) for _ in range(5)]
#x, y = zip(*xy)
def main():
nd = list(map(int, input().split()))
ans = 0
for i in range(nd[0]):
xy = list(map(int, input().split()))
if xy[0] * xy[0] + xy[1] * xy[1] <= nd[1] * nd[1]:
ans += 1
print(ans)
if __name__ == '__main__':
main()
| 1 | 5,942,838,532,580 | null | 96 | 96 |
n = list(map(int, list(input())))[::-1] + [0]
sum1 = sum(n)
for i in range(len(n)-1):
if n[i] > 5 or (n[i]==5 and n[i+1]>4):
n[i] = 10-n[i]
n[i+1] += 1
print(min(sum1, sum(n)))
|
#E DPでとく
N = [int(x) for x in input()]
dp = 0,1
for item in N:
a = min(dp[0] + item, dp[1] + 10 - item)
b = min(dp[0] + item + 1, dp[1] + 10 - (item + 1))
dp = a, b
print(dp[0])
| 1 | 71,180,664,953,730 | null | 219 | 219 |
import sys
from collections import defaultdict
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
def main():
X, Y = map(int, readline().split())
ans = 0
if X==1:
ans += 300000
elif X==2:
ans += 200000
elif X==3:
ans += 100000
else:
pass
if Y==1:
ans += 300000
elif Y==2:
ans += 200000
elif Y==3:
ans += 100000
else:
pass
if X==Y==1:
ans += 400000
print(ans)
if __name__ == '__main__':
main()
|
a = input()
print("A" if a == a.upper() else "a")
| 0 | null | 76,098,066,808,258 | 275 | 119 |
H_1, M_1, H_2, M_2, K = list(map(int, input().split(' ')))
print((H_2-H_1)*60+(M_2-M_1)-K)
|
h, m, h2, m2, k = map(int, input().split())
ans = (h2 * 60 + m2) - (h * 60 + m) - k
print(ans)
| 1 | 18,085,444,849,068 | null | 139 | 139 |
N = int(input())
D = list(map(int, input().split()))
mod = 998244353
counter = [0] * N
for d in D:
counter[d] += 1
if counter[0] != 1:
print(0)
exit()
ans = 1
for d in D[1:]:
ans = ans * counter[d-1] % mod
print(ans)
|
N = int(input())
D = list(map(int, input().split()))
M = 998244353
from collections import Counter
if D[0] != 0:
print(0)
exit(0)
cd = Counter(D)
if cd[0] != 1:
print(0)
exit(0)
tmp = sorted(cd.items(), key=lambda x: x[0])
ans = 1
for kx in range(1, max(D)+1):
ans *= pow(cd[kx-1], cd[kx],M)
ans %= M
print(ans)
| 1 | 154,716,371,561,220 | null | 284 | 284 |
from decimal import Decimal
a,b,c = list(map(Decimal,input().split()))
d = Decimal('0.5')
A = a ** d
B = b ** d
C = c ** d
if A + B < C:
print('Yes')
else:
print('No')
|
from decimal import Decimal
from math import sqrt
a, b, c = map(int, input().split())
print('Yes' if Decimal(a).sqrt()+Decimal(b).sqrt() < Decimal(c).sqrt() else 'No')
| 1 | 51,732,128,865,996 | null | 197 | 197 |
S=input()
T=input()
total=0
for i in range(0,len(S)):
if S[i]!=T[i]:
total+=1
print(int(total))
|
sum = []
while True:
text = input()
if text == '0':
break
tmp = 0
for i in range(len(text)):
tmp += int(text[i])
sum.append(tmp)
for r in sum:
print(r)
| 0 | null | 6,005,290,247,194 | 116 | 62 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.