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
|
---|---|---|---|---|---|---|
import sys
def draw_line(chk, W):
print(chk * int(W / 2) +(chk[0] if W % 2 else ''))
def draw(H, W):
for i in range(H):
draw_line(['#.', '.#'][i % 2], W)
print()
for line in sys.stdin:
H, W = map(int, line.split())
if H == W == 0:
break
draw(H, W) | n,k = map(int,input().split())
a = [0]+list(map(int,input().split()))
for i in range(n):
a[i+1] += a[i]
a[i+1] %=k
cnt = {}
ans = 0
for i in range(n+1):
left = i-k
if left >=0:
ldiff = (a[left] - left)%k
cnt[ldiff] -= 1
x = (a[i] - i)%k
if x <0:x+=k
if x not in cnt:cnt[x] = 0
ans+= cnt[x]
cnt[x] +=1
print(ans)
| 0 | null | 69,254,820,767,186 | 51 | 273 |
import sys
readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')
def solve():
n, k = nm()
p = nl()
_c = nl()
c = [0]*n
for i in range(n):
p[i] -= 1
c[i] = _c[p[i]]
m = 31
MIN = - (1 << 63)
vertex = list()
score = list()
vertex.append(p)
score.append(c)
for a in range(1, m+1):
p_ath = [0] * n
c_ath = [0] * n
for i in range(n):
p_ath[i] = vertex[a-1][vertex[a-1][i]]
c_ath[i] = score[a-1][i] + score[a-1][vertex[a-1][i]]
vertex.append(p_ath)
score.append(c_ath)
prv = [[MIN, 0] for _ in range(n)]
nxt = [[MIN, MIN] for _ in range(n)]
for b in range(m, -1, -1):
for i in range(n):
if (k >> b) & 1:
nxt[vertex[b][i]][0] = max(nxt[vertex[b][i]][0], prv[i][0] + score[b][i])
nxt[vertex[b][i]][1] = max(nxt[vertex[b][i]][1], prv[i][1] + score[b][i])
nxt[i][0] = max(nxt[i][0], prv[i][0], prv[i][1])
else:
nxt[vertex[b][i]][0] = max(nxt[vertex[b][i]][0], prv[i][0] + score[b][i])
nxt[i][0] = max(nxt[i][0], prv[i][0])
nxt[i][1] = max(nxt[i][1], prv[i][1])
prv, nxt = nxt, prv
ans = max(max(x) for x in prv)
if ans == 0:
ans = max(c)
print(ans)
return
solve() | n=int(input())
if n%2==0:
print(int((n/2)-1))
else:
print(int((n-1)/2))
| 0 | null | 79,702,151,690,720 | 93 | 283 |
n, k = map(int, input().split())
ans = 0
for i in range(k, n+2):
l = (i*(i-1))*0.5
h = (i*(2*n-i+1))*0.5
ans += (h-l+1)
print(int(ans) % (10**9+7)) | import sys
from collections import deque
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, p, q, *AB = map(int, read().split())
p -= 1
q -= 1
G = [[] for _ in range(N)]
for a, b in zip(*[iter(AB)] * 2):
G[a - 1].append(b - 1)
G[b - 1].append(a - 1)
if len(G[p]) == 1 and G[p][0] == q:
print(0)
return
dist1 = [-1] * N
dist1[p] = 0
queue = deque([p])
while queue:
v = queue.popleft()
for nv in G[v]:
if dist1[nv] == -1:
dist1[nv] = dist1[v] + 1
queue.append(nv)
dist2 = [-1] * N
dist2[q] = 0
queue = deque([q])
while queue:
v = queue.popleft()
for nv in G[v]:
if dist2[nv] == -1:
dist2[nv] = dist2[v] + 1
queue.append(nv)
max_d = 0
for d1, d2 in zip(dist1, dist2):
if d1 < d2 and max_d < d2:
max_d = d2
print(max_d - 1)
return
if __name__ == '__main__':
main()
| 0 | null | 75,207,548,047,038 | 170 | 259 |
N = int(input())
S = [input() for _ in range(N)]
C0 = 0
C1 = 0
C2 = 0
C3 = 0
for i in range(N):
if S[i] == "AC": C0 += 1
elif S[i] == "WA": C1 += 1
elif S[i] == "TLE": C2 += 1
else: C3 += 1
print("AC x "+ str(C0))
print("WA x "+ str(C1))
print("TLE x "+ str(C2))
print("RE x "+ str(C3))
| N,P=map(int, input().split())
if N<=9:
print(100*(10-N)+P)
else:
print(P) | 0 | null | 36,196,410,828,972 | 109 | 211 |
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()
def resolve():
N=int(input())
A=[]
for i in range(N):
X,L=map(int,input().split())
A.append([X-L,X+L])
A=sorted(A, key=lambda x: x[1])
cur=-(10**10)
cnt=0
for i in range(N):
if A[i][0]<cur: continue
else:
cur=A[i][1]
cnt+=1
print(cnt)
resolve() | T=input()
ans=[]
for i in range(len(T)):
if T[i]=='P':
ans.append('P')
elif T[i]=='D':
ans.append('D')
else:
ans.append('D')
print(''.join(ans)) | 0 | null | 54,207,443,308,698 | 237 | 140 |
import math
while True:
n = int(input())
if n == 0:
break
Student=list(map(float,input().split()))
#print(n)
#print(Student)
#m=average
average=sum(Student)/n
#print(m)
#a^2=dispersion
s=0.0
for i in Student:
s+=(i-average)**2
dispersion=s/n
print("%.6f"%(math.sqrt(dispersion))) | while True:
n = int(input())
s = []
if n == 0:
break
s = list(map(int, input().split()))
m = sum(s) / n
v = 0
for i in s:
v += (i - m) ** 2
ans = (v / n) ** (1/2)
print('{:10f}'.format(ans))
| 1 | 191,327,250,180 | null | 31 | 31 |
import math
a,b,C=map(float,input().split())
C*=math.pi/180
print('%.8f'%(a*b*math.sin(C)/2))
print('%.8f'%(a+b+(a*a+b*b-2*a*b*math.cos(C))**.5))
print('%.8f'%(b*math.sin(C))) | b = []
c = []
while True:
inp = input()
a = inp.split()
a[0] = int(a[0])
a[1] = int(a[1])
if a[0] == 0 and a[1] == 0:
break
else:
a.sort()
b.append(a[0])
c.append(a[1])
for i in range(len(b)):
print(b[i],c[i])
| 0 | null | 348,524,999,692 | 30 | 43 |
x = int(input())
for a in range(-120,121):
for b in range(-120,121):
if a**5 - b**5 == x:
print(a,b)
exit(0) | x = int(input())
y = x
if x == 1:
print('0 -1')
exit()
v = []
for i in range(0,1001):
v.append(i*i*i*i*i)
v.append(i*i*i*i*i*-1)
c = 0
d = 0
for i in range(len(v)):
y -= v[i]
for j in range(len(v)):
if v[j] == y * -1:
c = i
d = j
break
y = x
if c % 2 == 0: c //= 2
else:
c = (c-1) // 2
c *= -1
if d % 2 == 0: d //= 2
else:
d = (d-1) // 2
d *= -1
print(c,d) | 1 | 25,542,125,468,688 | null | 156 | 156 |
# -*-coding:utf-8
import fileinput
import math
def main():
for line in fileinput.input():
a, b, c = map(int, line.strip().split())
count = 0
for i in range(a, b+1):
if(c % i == 0):
count += 1
print(count)
if __name__ == '__main__':
main() | n=int(input())
result=float('inf')
for i in range(1,int(n**.5)+1):
if i*(n//i)==n:
result=min(result,abs(i+n//i)-2)
print(result) | 0 | null | 81,455,212,930,370 | 44 | 288 |
h, n = map(int, input().split())
a, b = [], []
for _ in range(n):
A, B = map(int, input().split())
a.append(A)
b.append(B)
a_max = max(a)
dp = [0]*(h+a_max)
for i in range(h+a_max):
dp[i] = min(dp[i-a] + b for a, b in zip(a, b))
print(min(dp[h-1:])) | from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")
# 処理内容
def main():
H, N = map(int, input().split())
A = [0]*N
B = [0]*N
for i in range(N):
A[i], B[i] = map(int, input().split())
dp = [INF] * 10000100
dp[0] = 0
for i in range(H):
if dp[i] == INF:
continue
for n in range(N):
dp[i+A[n]] = min(dp[i+A[n]], dp[i] + B[n])
ans = INF
for i in range(H, 10000100):
ans = min(ans, dp[i])
print(ans)
if __name__ == '__main__':
main() | 1 | 81,251,978,706,570 | null | 229 | 229 |
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 9 20:50:35 2020
@author: akros
"""
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 9 16:51:42 2020
@author: akros
"""
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
N = int(input())
a = []
for i in range(N):
a.append(int(input()))
if A1[0] == a[i]:
A1[0] = True
elif a[i] == A1[1]:
A1[1] = True
elif a[i] == A1[2]:
A1[2] = True
elif a[i] == A2[0]:
A2[0] = True
elif a[i] == A2[1]:
A2[1] = True
elif a[i] == A2[2]:
A2[2] = True
elif a[i] == A3[0]:
A3[0] = True
elif a[i] == A3[1]:
A3[1] = True
elif a[i] == A3[2]:
A3[2] = True
if A1[0] == True and A1[1] == True and A1[2] == True:
print("Yes")
elif A1[0] == True and A2[0] == True and A3[0] == True:
print("Yes")
elif A1[0] == True and A2[1] == True and A3[2] == True:
print("Yes")
elif A1[1] == True and A2[1] == True and A3[1] == True:
print("Yes")
elif A1[2] == True and A2[2] == True and A3[2] == True:
print("Yes")
elif A2[0] == True and A2[1] == True and A2[2] == True:
print("Yes")
elif A3[0] == True and A3[1] == True and A3[2] == True:
print("Yes")
elif A1[2] == True and A2[1] == True and A3[0] == True:
print("Yes")
else:
print("No")
| def solve(mid):
pos = (d[0] + d[1]) * (mid // 2)
if mid % 2 == 1:
pos += d[0]
if mid % 2 == 1:
nxt_pos = pos + d[1]
else:
nxt_pos = pos + d[0]
if pos * nxt_pos < 0 or nxt_pos == 0:
return True
else:
return False
t = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
v0 = a[0] - b[0]
v1 = a[1] - b[1]
d = [t[0] * v0, t[1] * v1]
if d[0] == -d[1]:
print("infinity")
exit()
ok = 0
ng = 10 ** 60
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if solve(mid):
ok = mid
else:
ng = mid
print(ok)
| 0 | null | 95,662,352,251,700 | 207 | 269 |
A=input()
if str.isupper(A):
print('A')
else:
print('a')
| print("A") if input().isupper() else print("a") | 1 | 11,378,651,040,152 | null | 119 | 119 |
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
d1=t1*a1+t2*a2
d2=t1*b1+t2*b2
import sys
if d1>d2:
dif=d1-d2
gap=(b1-a1)*t1
elif d1<d2:
dif=d2-d1
gap=(a1-b1)*t1
else:
print('infinity')
sys.exit()
if (b1-a1)*(b2-a2)>0 or (b1-a1)*(d2-d1)>0:
print(0)
sys.exit()
if gap%dif!=0:
print(gap//dif*2+1)
else:
print(gap//dif*2) | t1,t2 = map(int,input().split())
a1,a2 = map(int,input().split())
b1,b2 = map(int,input().split())
a1 -= b1
a2 -= b2
if a1 < 0:
a1 *= -1
a2 *= -1
d = a1 * t1 + a2 * t2
if d > 0:
print(0)
elif d == 0:
print('infinity')
else:
d *= -1
l = a1 * t1
if l % d != 0:
print(l//d*2+1)
else:
print(l//d*2)
#print(a1,a2)
#print(d,l) | 1 | 131,682,983,876,760 | null | 269 | 269 |
n=int(input())
print(sum(i*(n//i*(n//i+1))//2 for i in range(1,n+1))) | S = input()
if len(S)==6 :
if S[2] == S[3] and S[4] == S[5] :
print("Yes")
else:
print("No") | 0 | null | 26,416,016,687,522 | 118 | 184 |
n, time=map(int,raw_input().split())
p = []
t = []
for _ in xrange(n):
a = raw_input().split()
p.append(a[0])
t.append(int(a[1]))
alltime = 0
while True:
if len(p)==0:
break
if t[0]<=time:
alltime+=t[0]
print p.pop(0),
t.pop(0)
print alltime
else:
t.append(t[0])
t.pop(0)
t[-1]-=time
alltime += time
p.append(p[0])
p.pop(0) | H, N = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
inf = 10 ** 9 + 7
dp = [[inf] * (H + 1) for _ in range(N + 1)]
dp[0][0] = 0
for i in range(N):
for j in range(H + 1):
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
dp[i + 1][min(j + X[i][0], H)] = min(dp[i + 1][min(j + X[i][0], H)],
dp[i][j] + X[i][1],
dp[i + 1][j] + X[i][1])
print(dp[-1][-1])
| 0 | null | 40,416,433,911,750 | 19 | 229 |
N = int(input())
ans=[0]*N
for x in range(1,101):
for y in range(1,101):
for z in range(1,101):
F=x**2 + y**2 + z**2 + x*y + y*z + z*x
if(N>=F):
ans[F-1] += 1
for i in ans:
print(i) | n=int(input())
a=[0]*(n+1)
d=0
for i in range(1,101):
for j in range(1,101):
for h in range(1,101):
c=i**2+j**2+h**2+i*j+j*h+i*h
if c<=n:
a[c]+=1
for i in a[1:]:
print(i) | 1 | 7,941,946,010,580 | null | 106 | 106 |
def main():
import sys
input = sys.stdin.readline
n = int(input())
D = list(map(int,input().split()))
mod = 998244353
from collections import Counter
node_cnt = Counter(D)
set_d = sorted(list(set(D)))
if D[0]!=0:
print(0);exit()
if set_d[-1]!=len(set_d)-1:
print(0);exit()
ans = 0
pre = 1
if 0 in node_cnt:
if node_cnt[0]==1:
ans = 1
for k,v in sorted(node_cnt.items()):
ans*=pow(pre,v)
ans%=mod
pre = v
print(ans)
if __name__=='__main__':
main() | import sys
line = sys.stdin.read().lower()
al_dict = {}
for al in [chr(i) for i in range(ord('a'), ord('z')+1)]:
al_dict[al] = 0
for al in line:
if al_dict.get(al) != None:
al_dict[al] += 1
for al in al_dict:
print('{} : {}'.format(al, al_dict[al]))
| 0 | null | 78,453,225,501,208 | 284 | 63 |
a, b, c = map(int, input().split())
k = int(input())
for i in range(k):
if a < b < c:
break
elif b <= a:
b = b*2
elif c <= b:
c = c*2
if a < b < c:
print("Yes")
else:
print("No") | n=int(input())
s=input()
R=[]
G={}
B=[]
for i in range(n):
if s[i]=='R':
R.append(i+1)
elif s[i]=='G':
G[i+1]=G.get(i+1,0)+1
else:
B.append(i+1)
res=len(R)*len(G)*len(B)
for i in R:
for j in B:
if ((i+j)%2==0 and G.get((i+j)//2,0)==1):
res-=1
if G.get(2*max(i,j)-min(i,j),0)==1:
res-=1
if G.get(2*min(i,j)-max(i,j),0)==1:
res-=1
print(res) | 0 | null | 21,726,092,647,080 | 101 | 175 |
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): 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)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0
inf = float("inf")
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): 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)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): 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)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0
inf = float("inf")
n,m = I()
g = [[] for _ in range(n)]
for i in range(m):
a,b = I()
g[a-1].append(b-1)
g[b-1].append(a-1)
q = deque([0])
d = [-1]*n
d[0] = 0
while q:
v = q.popleft()
for i in g[v]:
if d[i] != -1:
continue
d[i] = v
q.append(i)
if -1 in d:
print("No")
else:
print("Yes")
for i in d[1:]:
print(i+1)
| R,C,K = map(int, input().split())
d = [[0 for _ in range(C+1)] for _ in range(R+1)]
#dp[行の中でピックした回数][行][列] この順じゃないとTLEする
dp = [[[0 for _ in range(C+1)] for _ in range(R+1)] for _ in range(4)]
for i in range(K):
r, c, v = map(int, input().split())
d[r-1][c-1] = v
for i in range(R):
for j in range(C):
# kが大きい方からやらないとダメ。01ナップサックと同じ考え方。書き換えられた値を見ないように。
for k in range(2, -1, -1):
# 拾う遷移。d[i][j]を取るかどうかという判定
dp[k+1][i][j] = max(dp[k+1][i][j], dp[k][i][j] + d[i][j])
for k in range(4):
dp[0][i+1][j] = max(dp[0][i+1][j], dp[k][i][j])
dp[k][i][j+1] = max(dp[k][i][j+1], dp[k][i][j])
ans = 0
for k in range(4):
ans = max(ans, dp[k][R-1][C-1])
print(ans) | 0 | null | 13,137,034,153,362 | 145 | 94 |
def draw_frame(h, w):
print("#" * w)
print(("#" + "." * (w - 2) + "#\n") * (h - 2), end="")
print("#" * w + "\n")
while True:
H, W = map(int, input().split())
if H == W == 0: break
draw_frame(H, W) | while True:
h,w=map(int,input().split())
if h==w==0:break
for hh in range(h):
ol=''
for ww in range(w):
if hh == 0 or ww == 0 or hh == h - 1 or ww == w - 1:
ol+='#'
else:
ol+='.'
print(ol)
print() | 1 | 829,348,524,650 | null | 50 | 50 |
from itertools import product
n,m,x = map(int, input().split())
al = []
cl = []
for _ in range(n):
row = list(map(int, input().split()))
cl.append(row[0])
al.append(row[1:])
ans = 10**9
bit = 2
ite = list(product(range(bit),repeat=n))
for pattern in ite:
skills = [0]*m
cost = 0
for i, v in enumerate(pattern):
if v == 1:
curr_al = al[i]
cost += cl[i]
for j, a in enumerate(curr_al):
skills[j] += a
if min(skills) >= x:
ans = min(ans,cost)
if ans == 10**9: ans = -1
print(ans) | N,M,X = map(int,input().split())
data = []
ans = 0
for i in range(N):
d = list(map(int,input().split()))
data.append(d)
ans += d[0]
x = 2**N + 1
ans_candidate = []
valid = False
ans += 1
ans_old = ans
for i in range(x):
if i != 0:
for l in range(len(sum)):
if sum[l] >= X and l == len(sum) -1:
valid = True
if sum[l] >= X:
continue
else:
valid = False
break
if valid and price < ans:
ans = price
sum = [0] * M
price = 0
for j in range(N):
if i >> j & 1 == 1:
price += data[j][0]
for k in range(M):
sum[k] += data[j][k+1]
if ans_old == ans:
print(-1)
else:
print(ans)
| 1 | 22,294,680,977,108 | null | 149 | 149 |
def gcd(a,b):
if b==0:
return a
else:
return gcd(b,a%b)
n=int(input())
arr=list(map(int,input().split()))
g=arr[0]
cnt=[0]*(10**6+1)
for val in arr:
g=gcd(g,val)
cnt[val]+=1
for i in range(2,10**6+1):
tmp=0
for j in range(i,10**6+1,i):
tmp+=cnt[j]
if tmp>=2:
break
if i==10**6:
print('pairwise coprime')
elif g==1:
print('setwise coprime')
else:
print('not coprime') | import sys
S = input()
if S == "ABC":
print("ARC")
sys.exit()
else:
print("ABC")
sys.exit()
| 0 | null | 14,050,370,059,072 | 85 | 153 |
N, K = list(map(int, input().split()))
p = sorted(list(map(int, input().split())), reverse=False)
print(sum(p[:K])) | ini = lambda : int(input())
inm = lambda : map(int,input().split())
inl = lambda : list(map(int,input().split()))
gcd = lambda x,y : gcd(y,x%y) if x%y else y
n,k = inm()
p = inl()
p = sorted(p)
print(sum(p[:k]))
| 1 | 11,641,717,920,830 | null | 120 | 120 |
import sys
from collections import deque
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
H, W = map(int, readline().split())
S = [[0] * W for _ in range(H)]
for i in range(H):
S[i] = readline().strip()
dxdy4 = ((-1, 0), (0, -1), (0, 1), (1, 0))
ans = 0
for i in range(H):
for j in range(W):
if S[i][j] == '#':
continue
dist = [[-1] * W for _ in range(H)]
dist[i][j] = 0
queue = deque([(i, j)])
res = 0
while queue:
x, y = queue.popleft()
for dx, dy in dxdy4:
nx, ny = x + dx, y + dy
if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == '.' and dist[nx][ny] == -1:
dist[nx][ny] = dist[x][y] + 1
if res < dist[nx][ny]:
res = dist[nx][ny]
queue.append((nx, ny))
if ans < res:
ans = res
print(ans)
return
if __name__ == '__main__':
main()
| a, b = input().split(' ')
if a <= b:
print(a*int(b))
else:
print(b*int(a)) | 0 | null | 89,822,930,710,018 | 241 | 232 |
import math
a, b, C = map(int, input().split())
S = a * b * math.sin(math.radians(C)) / 2
L = a + b + (a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(C))) ** 0.5
h = b * math.sin(math.radians(C))
print('%.7f\n%.7f\n%.7f\n' % (S, L, h)) | from math import *
a,b,C=map(int,input().split())
C=C*pi/180
S=a*b*sin(C)/2
print(S,a+b+(a*a+b*b-2*a*b*cos(C))**0.5,2*S/a,sep='\n') | 1 | 176,480,423,112 | null | 30 | 30 |
N = int(input())
S = list(input())
check = 0
for i in range(N-1):
if S[i] != "*":
if S[i:i+3] == ["A","B","C"]:
check += 1
S[i:i+3] = ["*"]*3
print(check) | # -*- coding: utf-8 -*-
while True:
s = raw_input()
if s=="0": break
t = 0
for n in s:
t += int(n)
print t | 0 | null | 50,214,491,986,592 | 245 | 62 |
N = int(input())
def S(x):
return(x*(x+1)//2)
print(S(N) - 3*S(N//3) - 5*S(N//5) + 15*S(N//15)) | N=int(input())
a=1
sum=0
while a in range(N+1):
if a%3 !=0 and a%5 !=0:
sum=sum+a
a = a + 1
else:a=a+1
print(sum)
| 1 | 34,907,268,558,522 | null | 173 | 173 |
n,k = map(int,input().split())
h = [int(s) for s in input().split()]
h.sort(key=int)
for _ in range(min(k,len(h))):del h[-1]
print(sum(h)) | from sys import stdin
input = stdin.readline
def main():
N, K = list(map(int, input().split()))
H = list(map(int, input().split()))
H = sorted(H)
if K == 0:
print(sum(H))
return
print(sum(H[:-K]))
if(__name__ == '__main__'):
main()
| 1 | 79,004,025,247,258 | null | 227 | 227 |
while True:
m,f,r=map(int,input().split())
if m==-1 and f==-1 and r==-1:
break
if m==-1 or f==-1:
print('F')
elif m+f>=80:
print('A')
elif 80>(m+f)>=65:
print('B')
elif 65>(m+f)>=50 :
print('C')
elif 50>(m+f)>=30:
if r>=50:
print('C')
else:
print('D')
elif r>=50:
print('C')
elif m+f<30:
print('F')
else:
pass
| while True:
ans = 0
x = raw_input()
if x == "0":
break
for i in x:
ans += int(i)
print ans | 0 | null | 1,401,872,949,600 | 57 | 62 |
a, b, c = map(int,input().split())
if 4*a*b + 2*a*c + 2*b*c < a**2 + b**2 + c**2+ 2*a*b and c-a-b>0:
print("Yes")
else:
print("No") | import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
a, b, c = mapint()
if c-(a+b)>=0:
if 4*a*b<(c-a-b)**2:
print('Yes')
else:
print('No')
else:
print('No') | 1 | 51,845,029,323,890 | null | 197 | 197 |
x = int(input())
def f():
for i in range(x, 10**10):
c = 0
for j in range(2, i):
if i%j != 0:
c += 1
if c == i-2:
return i
else:
break
if x == 2:
print(2)
else:
print(f()) | n = int(input())
if n & 1:
print((n - 1) // 2)
else:
print(n // 2 - 1) | 0 | null | 129,455,928,640,000 | 250 | 283 |
N,K = map(int,input().split())
H = [int(x) for x in input().split()]
H_sort = sorted(H,reverse=True)
print(sum(H_sort[K:])) | a,b=map(int,input().split())
l=list(map(int,input().split()))
z=0
l=sorted(l)
for i in range(a-b):
z+=l[i]
print(z) | 1 | 78,719,074,221,824 | null | 227 | 227 |
def one_int():
return int(input())
N=one_int()
num=int(N/100)
amari = N % 100
if num*5 < amari:
print(0)
else:
print(1) | n,m,l = map(int, input().split())
A = [[0 for c in range(m)]for r in range(n)]
B = [[0 for c in range(l)]for r in range(m)]
C = [[0 for c in range(l)]for r in range(n)]
for r in range(n):
A[r][:] = list(map(int, input().split()))
for r in range(m):
B[r][:] = list(map(int, input().split()))
for row in range(n):
for col in range(l):
for i in range(m):
C[row][col] += A[row][i]*B[i][col]
print(*C[row][:])
| 0 | null | 63,981,902,247,298 | 266 | 60 |
N, K = [int(v) for v in input().split()]
links = []
for k in range(K):
L, R = [int(v) for v in input().split()]
links.append((L, R))
links = sorted(links, key=lambda x: x[1])
count = [1]
sub = [0, 1]
subtotal = 1
for i in range(1, N):
v = 0
for l, r in links:
r2 = i - l + 1
l2 = i - r
if l2 < 0:
l2 = 0
if r2 >= 0:
v += sub[r2] - sub[l2]
count.append(v % 998244353)
subtotal = (subtotal + v) % 998244353
sub.append(subtotal )
print(count[-1])
| h, w, f = list(map(int, input().split()))
c = [input() for i in range(h)]
count = 0
bit_h = []
for k in range(2**h):
hh = []
for l in range(h):
if((k >> l) & 1):
hh.append(1)
else:
hh.append(0)
bit_h.append(hh)
bit_w = []
for i in range(2**w):
ww = []
for j in range(w):
if((i >> j) & 1):
ww.append(1)
else:
ww.append(0)
bit_w.append(ww)
ans = 0
for i in range(len(bit_h)):
for j in range(len(bit_w)):
count = 0
for k in range(h):
for l in range(w):
if bit_h[i][k] == 1 and bit_w[j][l] == 1 and c[k][l] == "#":
count += 1
if count == f:
ans += 1
print(ans)
| 0 | null | 5,847,240,990,404 | 74 | 110 |
import sys
def input(): return sys.stdin.readline().rstrip()
# ライブラリ参照https://atcoder.jp/contests/practice2/submissions/16580070
class SegmentTree:
__slots__ = ["func", "e", "original_size", "n", "data"]
def __init__(self, length_or_list, func, e):
self.func = func
self.e = e
if isinstance(length_or_list, int):
self.original_size = length_or_list
self.n = 1 << ((length_or_list - 1).bit_length())
self.data = [self.e] * self.n
else:
self.original_size = len(length_or_list)
self.n = 1 << ((self.original_size - 1).bit_length())
self.data = [self.e] * self.n + length_or_list + \
[self.e] * (self.n - self.original_size)
for i in range(self.n-1, 0, -1):
self.data[i] = self.func(self.data[2*i], self.data[2*i+1])
def replace(self, index, value):
index += self.n
self.data[index] = value
index //= 2
while index > 0:
self.data[index] = self.func(
self.data[2*index], self.data[2*index+1])
index //= 2
def folded(self, l, r):
left_folded = self.e
right_folded = self.e
l += self.n
r += self.n
while l < r:
if l % 2:
left_folded = self.func(left_folded, self.data[l])
l += 1
if r % 2:
r -= 1
right_folded = self.func(self.data[r], right_folded)
l //= 2
r //= 2
return self.func(left_folded, right_folded)
def all_folded(self):
return self.data[1]
def __getitem__(self, index):
return self.data[self.n + index]
def max_right(self, l, f):
# assert f(self.e)
if l >= self.original_size:
return self.original_size
l += self.n
left_folded = self.e
while True:
# l //= l & -l
while l % 2 == 0:
l //= 2
if not f(self.func(left_folded, self.data[l])):
while l < self.n:
l *= 2
if f(self.func(left_folded, self.data[l])):
left_folded = self.func(left_folded, self.data[l])
l += 1
return l - self.n
left_folded = self.func(left_folded, self.data[l])
l += 1
if l == l & -l:
break
return self.original_size
# 未verify
def min_left(self, r, f):
# assert f(self.e)
if r == 0:
return 0
r += self.n
right_folded = self.e
while True:
r //= r & -r
if not f(self.func(self.data[r], right_folded)):
while r < self.n:
r = 2 * r + 1
if f(self.func(self.data[r], right_folded)):
right_folded = self.func(self.data[r], right_folded)
r -= 1
return r + 1 - self.n
if r == r & -r:
break
return 0
def orr(x, y):
return x | y
def main():
N = int(input())
S = input()
S = list(map(lambda c: 2**(ord(c) - ord('a')), list(S)))
Q = int(input())
seg = SegmentTree(S, orr, 0)
for _ in range(Q):
num, x, y = input().split()
if num == '1':
seg.replace(int(x)-1, 2**(ord(y) - ord('a')))
else:
bits = seg.folded(int(x)-1, int(y))
print(sum(map(int, list(bin(bits))[2:])))
if __name__ == '__main__':
main() | class BIT:
def __init__(self,n):
self.s = [0]*(n+1)
self.n = n
def add(self,val,idx):
while idx < self.n+1:
self.s[idx] = self.s[idx] + val
idx += idx&(-idx)
return
def get(self,idx):
res = 0
while idx > 0:
res = res + self.s[idx]
idx -= idx&(-idx)
return res
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
n = int(input())
S = [ord(s) - ord('a') for s in input()[:-1]]
bits = [BIT(n) for i in range(26)]
for i,s in enumerate(S):
bits[s].add(1,i+1)
Q = int(input())
ans = []
for _ in range(Q):
flag,x,y = input().split()
if flag == "1":
i = int(x)
c = ord(y) - ord('a')
bits[S[i-1]].add(-1,i)
bits[c].add(1,i)
S[i-1] = c
else:
l = int(x)
r = int(y)
res = 0
for i in range(26):
res += (bits[i].get(r) > bits[i].get(l-1))
ans.append(str(res))
print("\n".join(ans)) | 1 | 62,446,667,020,666 | null | 210 | 210 |
H, W, K = map(int, input().split())
blacks = [[None] * W for _ in range(H)]
black_sums = [[0] * W for _ in range(H)]
black_col_sums = [[0] * W for _ in range(H)]
for i in range(H):
for j, item in enumerate(input()):
if item == "#":
blacks[i][j] = 1
else:
blacks[i][j] = 0
ok_count = 0
for i in range(1<<H):
for j in range(1<<W):
# print(f"{i:b}, {j:b}")
black_count = 0
for m in range(H):
for n in range(W):
if (1 & i >> m and 1 & j >> n) == False:
continue
black_count += blacks[m][n]
if black_count == K:
ok_count += 1
print(ok_count) | from copy import deepcopy
import numpy as np
H, W, K = map(int, input().split())
matrix = []
for i in range(H):
matrix.append(input())
matrix_int = np.ones((H, W), dtype=np.uint8)
# 1 == 黒、 0 == 白
for row in range(H):
for column in range(W):
if matrix[row][column] == ".":
matrix_int[row, column] = 0
count = 0
for row_options in range(2**H):
for col_options in range(2**W):
tmp_matrix_int = deepcopy(matrix_int)
tmp_row_options = row_options
tmp_col_options = col_options
for row in range(H):
mod = tmp_row_options % 2
if mod == 0:
tmp_matrix_int[row,:] = 0
tmp_row_options = tmp_row_options // 2
for col in range(W):
mod = tmp_col_options % 2
if mod == 0:
tmp_matrix_int[:,col] = 0
tmp_col_options = tmp_col_options // 2
# print(tmp_matrix_int.sum())
if tmp_matrix_int.sum() == K:
count += 1
print(count) | 1 | 8,853,423,955,100 | null | 110 | 110 |
n, r = [int(_) for _ in input().split()]
print(r if n >= 10 else r + 100 * (10 - n))
| def main():
n = input()
m = int(n[-1])
hon = [2, 4, 5, 7, 9]
pon = [0, 1, 6, 8]
if m in hon:
print('hon')
elif m in pon:
print('pon')
else:
print('bon')
if __name__ == '__main__':
main() | 0 | null | 41,503,941,704,992 | 211 | 142 |
N = int(input())
print(N//2 if N%2==0 else N//2+1) | N = int(input())
ans = -(-N // 2)
print(ans) | 1 | 58,947,159,247,482 | null | 206 | 206 |
n = int(input())
s = str(input())
w = s[0]
num = 0
for i in range(1,n):
if w[0] == s[i]:
w += s[i]
else:
num += 1
w = s[i]
num += 1
print(num) | a = list(map(int, '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'.split(',')))
k = int(input())
print(a[k-1]) | 0 | null | 109,569,569,361,132 | 293 | 195 |
N, K, C = map(int, input().split())
S = input()
S_reverse = S[::-1]
left_justified = [-1 for _ in range(N)]
right_justified = [-2 for _ in range(N)]
for i_justified in (left_justified, right_justified):
if i_justified == left_justified:
i_S = S
nearest_position = 1
positioning = 1
else:
i_S = S_reverse
nearest_position = K
positioning = -1
i_K = 0
while i_K <= N-1:
if i_S[i_K] == 'o':
i_justified[i_K] = nearest_position
i_K += C
nearest_position += positioning
i_K += 1
for i_N in range(N):
if left_justified[i_N] == right_justified[N - i_N - 1]:
print(i_N + 1) | d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(d)]
lastd = [0] * 26
for i in range(1, d + 1):
ans = 0
tmp = 0
for j in range(26):
if tmp < s[i - 1][j] + (i - lastd[j]) * c[j]:
tmp = s[i - 1][j] + (i - lastd[j]) * c[j]
ans = j + 1
lastd[ans - 1] = i
print(ans) | 0 | null | 25,289,086,833,462 | 182 | 113 |
A = list(map(int, input().split()))
H = A[0]
W = A[1]
K = A[2]
colors = []
for line in range(H):
color = input()
color = list(color)
colors.append(color)
ans = 0
for i in range(2**H):
for j in range(2**W):
cnt = 0
for k in range(H):
for l in range(W):
if list(format(i,"0"+str(H)+"b"))[k] == "0" and list(format(j,"0"+str(W)+"b"))[l] == "0":
if colors[k][l] == "#":
cnt += 1
if cnt == K:
ans+= 1
print(ans) | def main():
# n = int(input())
# h, w, k = map(int, input().split())
# a = list(map(int, input().split()))
# s = input()
x = int(input())
i = 1
while (x*i) % 360 != 0:
i += 1
print(i)
if __name__ == '__main__':
main()
| 0 | null | 10,938,219,324,010 | 110 | 125 |
import numpy as np
N, X, Y = [int(_) for _ in input().split()]
X -= 1
Y -= 1
cnt = np.zeros(N, dtype=int)
for i in range(0, (X + Y) // 2):
#t-i<=abs(i-X)+1+Y-t
#2*t<=abs(i-X)+1+Y+i
#t<= tmax = 0 - - (abs(i-X)+1+Y+i)//2
#tmin=abs(i-X)+1
tmin = abs(i - X) + 1
tmax = 0 - -(abs(i - X) + 1 + Y + i) // 2
cnt[1:tmax - i] += 1
cnt[tmin:tmin + Y - tmax + 1] += 1
cnt[tmin + 1:tmin + N - Y] += 1
for i in range((X + Y) // 2, N):
cnt[1:N - i] += 1
print(*cnt[1:], sep='\n')
| # -*- coding: utf-8 -*-
"""
Created on Mon Sep 7 15:49:02 2020
@author: liang
"""
N, X, Y = map(int, input().split())
ans = [0]*(N-1)
for i in range(1,N+1):
for j in range(i+1, N+1):
#print(i,j)
res = min(abs(i-j), abs(X-i) + 1 + abs(Y-j))
#print(i, j, res)
ans[res-1] += 1
for i in ans:
print(i) | 1 | 44,097,235,604,058 | null | 187 | 187 |
S = str(input())
Q = int(input())
flip = 0
front,back = '',''
for i in range(Q):
j = input()
if len(j) == 1:
flip += 1
continue
else:
if j[2] == '1' and flip % 2 == 0:
front = j[4] + front
continue
elif j[2] == '2' and flip % 2 == 0:
back = back + j[4]
continue
elif j[2] == '1' and flip % 2 ==1:
back= back + j[4]
continue
elif j[2] == '2' and flip % 2 ==1:
front = j[4] + front
continue
S = front + S + back
if flip % 2 == 1:
S = S[::-1]
print(S) | S = input()
Q = int(input())
lS = ''
for _ in range(Q):
query = input().split()
if query[0] == '1':
lS, S = S, lS
else:
if query[1] == '1':
lS += query[2]
else:
S += query[2]
print(lS[::-1] + S) | 1 | 57,350,513,047,712 | null | 204 | 204 |
import sys
lines = [list(map(int,line.split())) for line in sys.stdin]
n,m,l = lines[0]
A = lines[1:n+1]
B = [i for i in zip(*lines[n+1:])]
for a in A:
row = []
for b in B:
row.append(sum([i*j for i,j in zip(a,b)]))
print (" ".join(map(str,row))) | n,m,l = map(int, input().split())
A = [[0 for c in range(m)]for r in range(n)]
B = [[0 for c in range(l)]for r in range(m)]
C = [[0 for c in range(l)]for r in range(n)]
for r in range(n):
A[r][:] = list(map(int, input().split()))
for r in range(m):
B[r][:] = list(map(int, input().split()))
for row in range(n):
for col in range(l):
for i in range(m):
C[row][col] += A[row][i]*B[i][col]
print(*C[row][:])
| 1 | 1,438,951,139,572 | null | 60 | 60 |
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
A = [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]
K = ir()
print(A[K-1])
| num = [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]
K = int(input())
N = K - 1
print(num[N]) | 1 | 49,917,071,364,160 | null | 195 | 195 |
#create date: 2020-07-03 10:10
import sys
stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))
def main():
a, b, c, k = na()
if k <= a:
print(k)
elif k <= a + b:
print(a)
else:
print(a-(k-(a+b)))
if __name__ == "__main__":
main() |
s,t = list(map(str, input().split()))
print(t+s) | 0 | null | 62,504,945,190,230 | 148 | 248 |
n = input()
if n[-1]== "2" or n[-1]== "4" or n[-1]== "5" or n[-1]== "7" or n[-1]== "9":
print("hon")
elif n[-1]== "3":
print("bon")
else:
print("pon") | def solve(x):
cnt = 1
while x > 0:
x %= bin(x).count('1')
cnt += 1
return cnt
n = int(input())
x = input()
one = sum(map(int, list(x)))
num = int(x, 2)
up = num%(one+1)
if one == 1:
down = 0
else:
down = num%(one-1)
for i in range(n):
if x[i] == '1':
if one == 1:
print(0)
continue
s = (down - pow(2, n-i-1, one-1))%(one-1)
else:
s = (up + pow(2, n-i-1, one+1))%(one+1)
print(solve(s)) | 0 | null | 13,848,030,715,888 | 142 | 107 |
A_count = int(input());
A = [int(n) for n in input().split()];
M_count = int(input());
M = [int(n) for n in input().split()];
memo = [[None for i in range(2000)] for j in range(A_count + 1)];
def solve(start, target):
if memo[start][target] is not None:
return memo[start][target];
if target == 0:
return True;
elif start >= A_count:
return False;
else:
result = solve(start + 1, target) or solve(start + 1, target - A[start]);
if result:
memo[start][target] = True;
return True;
else:
memo[start][target] = False;
return False;
for m in M:
if solve(0, m):
print("yes");
else:
print("no");
| import time
def sum_A(A, n):
dic = {}
#A_ = A
#n_ = n
def solve(i, m):
if (i, m) in dic:
return dic[(i, m)]
if m == 0:
dic[(i, m)] = True
elif i >= n:
dic[(i, m)] = False
elif solve(i+1, m):
dic[(i, m)] = True
elif solve(i+1, m-A[i]):
dic[(i, m)] = True
else:
dic[(i, m)] = False
return dic[(i, m)]
return solve
if __name__ == '__main__':
n = int(raw_input())
A = map(int, raw_input().split())
q = int(raw_input())
m = map(int, raw_input().split())
#A = sorted(A)
start = time.time()
solve = sum_A(A, n)
for m_i in m:
print "yes" if solve(0, m_i) else "no"
end = time.time()
#print end - start | 1 | 99,841,764,590 | null | 25 | 25 |
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
h,a = map(int, input().split())
# 切り上げ
print((h+a-1)//a)
| m=input().split()
M=input().split()
if int(M[0]) - int(m[0]) == 1:
print('1')
else:
print('0') | 0 | null | 100,364,932,655,818 | 225 | 264 |
def main():
from sys import setrecursionlimit, stdin, stderr
from os import environ
from collections import defaultdict, deque, Counter
from math import ceil, floor
from itertools import accumulate, combinations, combinations_with_replacement
setrecursionlimit(10**6)
dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
input = lambda: stdin.readline().rstrip()
LMIIS = lambda: list(map(int,input().split()))
II = lambda: int(input())
P = 10**9+7
multimul = lambda L,i=0: (L[i] * multimul(L,i+1) % P if i+1 < len(L) else L[i])
INF = 10**18+10
N,K = LMIIS()
A = LMIIS()
if N == K:
print(multimul(A))
return
not_negative = []
negative = []
for a in A:
if a < 0:
negative.append(a)
else:
not_negative.append(a)
if len(negative) == N and K % 2 == 1:
print(multimul(sorted(negative,reverse=True)[:K]))
return
not_negative.sort(reverse=True)
not_negative = deque(not_negative)
negative.sort()
negative = deque(negative)
ans = 1
num_multiplied = 0
while num_multiplied < K:
if num_multiplied == K-1 or len(negative) < 2 or len(not_negative) >= 2 and not_negative[0] * not_negative[1] > negative[0] * negative[1]:
ans = ans * not_negative.popleft() % P
num_multiplied += 1
else:
ans = ans * negative.popleft() * negative.popleft() % P
num_multiplied += 2
print(ans)
main() | import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
from copy import deepcopy
mod = 10**9 + 7
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
a = sorted(a, key=lambda x: abs(x))[::-1]
a_plus = [int(x) for x in a if x > 0]
a_minus = [int(x) for x in a if x < 0]
a_abs = [abs(x) for x in a]
def calc(x):
res = 1
for i in x:
res*=abs(i)
res %= mod
return res
max_a = a[:k]
max_a_minus = []
max_a_plus = []
minus_cnt = 0
for i in max_a:
if i == 0:
print(0)
sys.exit()
if i < 0:
minus_cnt += 1
max_a_minus.append(i)
else:
max_a_plus.append(i)
if minus_cnt % 2 == 0:
print(calc(max_a))
sys.exit()
plus_cnt = k - minus_cnt
if len(a_minus) <= minus_cnt and len(a_plus) <= plus_cnt:
ans = -float('inf')
elif len(a_minus) <= minus_cnt:
if len(max_a_minus) == 0:
ans = -float("inf")
else:
max_a_minus.pop()
max_a_plus.append(a_plus[plus_cnt])
ans = calc(max_a_plus + max_a_minus)
elif len(a_plus) <= plus_cnt:
if len(max_a_plus) == 0:
ans = -float("inf")
else:
max_a_plus.pop()
max_a_minus.append(a_minus[minus_cnt])
ans = calc(max_a_minus + max_a_plus)
else:
flag1 = 1
flag2 = 1
if len(max_a_minus) == 0:
ans1 = -float("inf")
flag1 = 0
if len(max_a_plus) == 0:
ans2 = -float("inf")
flag2 = 0
if flag1:
c1 = deepcopy(max_a_minus)
c2 = deepcopy(max_a_plus)
d1 = abs(c1.pop()); d2 = abs(a_plus[plus_cnt])
c2.append(a_plus[plus_cnt])
ans1 = calc(c1 + c2)
if flag2:
c3 = deepcopy(max_a_minus)
c4 = deepcopy(max_a_plus)
d3 = abs(c4.pop()); d4 = abs(a_minus[minus_cnt])
c3.append(a_minus[minus_cnt])
ans2 = calc(c3 + c4)
if flag1 and flag2:
ans = ans1 if d2*d3 > d1*d4 else ans2
else:
ans = max(ans1, ans2)
a_abs = a_abs[::-1]
ans2 = -calc(a_abs[:k])
if ans != -float("inf"):
print(ans%mod)
else:
print(ans2%mod)
| 1 | 9,397,228,442,940 | null | 112 | 112 |
from collections import deque
n = int(input())
data = deque(list(input() for _ in range(n)))
ans = deque([])
co = 0
for i in data:
if i[6] == ' ':
if i[0] == 'i':
ans.insert(0, i[7:])
co += 1
else:
try:
ans.remove(i[7:])
co -= 1
except:
pass
else:
if i[6] == 'F':
del ans[0]
co -= 1
else:
del ans[-1]
co -= 1
for i in range(0, co-1):
print(ans[i], end=' ')
print(ans[co-1])
| from collections import deque
times = int(input())
stack = deque()
for i in range(times):
op = input().split()
if op[0] == "insert":
stack.appendleft(op[1])
if op[0] == "delete":
if op[1] in stack:
stack.remove(op[1])
if op[0] == "deleteFirst":
stack.popleft()
if op[0] == "deleteLast":
stack.pop()
print(*stack)
| 1 | 49,344,337,592 | null | 20 | 20 |
from scipy.special import comb
n, k = map(int, input().split())
num, ans = 0, 0
for i in range(n+1):
num += n-2*i
if i >= k-1:
ans += num+1
ans = ans%(10**9+7)
print(ans)
| n, k = map(int, input().split())
count = 0
for i in range(k, n + 2):
if i == k:
tot_min = 0
tot_max = 0
for j in range(i):
tot_min += j
tot_max += n - j
else:
tot_min += i - 1
tot_max += n - i + 1
count += tot_max - tot_min + 1
count %= 10 ** 9 + 7
print(count) | 1 | 32,989,662,491,408 | null | 170 | 170 |
while 1:
num = input()
if num == "0":
break
a = []
for i in range(len(num)):
a.append(int(num[i:i+1]))
print(sum(a)) | while True:
string = input().strip()
if string == '0': break
print(sum([int(c) for c in string]))
| 1 | 1,569,864,558,778 | null | 62 | 62 |
import math
a,b,C = map(float,input().split())
rad = math.radians(C)
h = b*math.sin(rad)
S = a*h/2
L = a+b+math.sqrt(a**2+b**2-2*a*b*math.cos(rad))
print("%.5f\n%.5f\n%.5f" % (S,L,h)) | import math
a,b,c = map(float,input().split())
sinc = math.sin(c*math.pi/180)
cosc = math.cos(c*math.pi/180)
c = math.sqrt(a**2+b**2-2*a*b*cosc)
s = a*b*sinc/2.0
print(s)
print(a+b+c)
print(s/a*2.0)
| 1 | 169,787,974,020 | null | 30 | 30 |
i=0
j = int(input())
numlist = list(int(i) for i in input().split())
while i < j-1:
print(numlist[j-i-1],end='')
print(' ',end='')
i += 1
print(numlist[0]) | a=[]
n = int(input())
s = input().rstrip().split(" ")
for i in range(n):
a.append(int(s[i]))
a=a[::-1]
for i in range(n-1):
print(a[i],end=' ' )
print(a[n-1]) | 1 | 986,495,188,604 | null | 53 | 53 |
import sys
from collections import deque
N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for s in sys.stdin.readlines():
a, b = map(lambda x: int(x) - 1, s.split())
edge[a].append(b)
edge[b].append(a)
path = [0] * N
cnt = 0
for i in range(N):
if path[i] == 0:
cnt += 1
q = deque()
path[i] = 1
q.append(i)
while q:
p = q.popleft()
for np in edge[p]:
if path[np] == 0:
path[np] = 1
q.append(np)
print(cnt - 1)
| def resolve():
print("Yes" if "7" in input() else "No")
if '__main__' == __name__:
resolve() | 0 | null | 18,332,523,546,748 | 70 | 172 |
N=int(input())
XY=[[] for _ in range(N)]
for i in range(N):
A=int(input())
for _ in range(A):
x,y = map(int, input().split())
x-=1
XY[i].append([x,y])
ans=0
for bit_state in range(2**N):
flag=True
for i in range(N):
if (bit_state>>i)&1:
for x, y in XY[i]:
if (bit_state >>x)&1 != y:
flag=False
if flag:
ans=max(ans, bin(bit_state).count("1"))
print(ans) | def check(i,N,Ls):
count=0
for j in range(N):
if (i>>j)%2==1:
for k in Ls[j]:
if ((i>>(k[0]-1))%2)!=k[1]:
return 0
count+=1
return count
N=int(input())
A_ls=[]
Ls=[]
for i in range(N):
A=int(input())
A_ls.append(A)
ls=[]
for j in range(A):
x,y=map(int,input().split())
ls.append((x,y))
Ls.append(ls)
ans=0
for i in range(2**N):
num=check(i,N,Ls)
if num>ans:
ans=num
print(ans) | 1 | 121,003,497,774,160 | null | 262 | 262 |
N = int(input())
def answer(N: int) -> str:
x = 0
for i in range(1, 10):
for j in range(1, 10):
if N == i * j:
x = 1
return 'Yes'
if x == 0:
return 'No'
print(answer(N)) | n = int(input())
for i in range(1,10):
if n // i == n/i and n//i in range(1,10):
print('Yes')
break
else:
print('No') | 1 | 159,186,019,658,688 | null | 287 | 287 |
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
A = [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]
K = ir()
print(A[K-1])
| from collections import deque
n = int(input())
d = deque()
for i in range(n):
x = input().split()
if x[0] == "insert":
d.appendleft(x[1])
elif x[0] == "delete":
if x[1] in d:
d.remove(x[1])
elif x[0] == "deleteFirst":
d.popleft()
elif x[0] == "deleteLast":
d.pop()
print(*d)
| 0 | null | 24,960,836,903,200 | 195 | 20 |
N=int(input())
S=input()
s=[]
for i in S:
T=ord(i) - ord('A') + 1+N+64
if T<=90:
t=T
else:
t=T-26
s.append(chr(t))
print(*s,sep='') | N = int(input())
s = input()
a = [chr(i) for i in range(65, 65+26)]
ls = []
for x in a:
ls.append(x)
for x in a:
ls.append(x)
ans = []
for x in s:
ans.append(ls[ls.index(x)+N])
print(''.join(ans)) | 1 | 134,257,920,244,862 | null | 271 | 271 |
import math
k,n= map(int,input().split())
a = list(map(int,input().split()))
ans = a[0]+k-a[n-1]
for i in range(1,len(a)):
s = a[i]-a[i-1]
ans =max(ans,s)
print(k-ans)
| k, n =map(int,input().split())
a = list(map(int,input().split()))
longest = k - a[-1] + a [0]
for i in range(len(a)-1):
longest = max(longest,a[i+1]-a[i])
print(k-longest) | 1 | 43,458,662,836,730 | null | 186 | 186 |
a = input()
print('Yes' if input() in a+a else 'No') | #!/usr/bin/python
s=raw_input()
p=raw_input()
s+=s
print "Yes" if p in s else "No" | 1 | 1,771,408,790,750 | null | 64 | 64 |
list = [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]
num = int(input()) - 1
print(list[num]) | s = "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"
S = s.split(", ")
k = int(input())
print(S[k-1]) | 1 | 50,235,512,840,640 | null | 195 | 195 |
h, w, k = map(int, input().split())
s = [list(input()) for _ in range(h)]
g = 1
for i in range(h):
for j in range(w):
if s[i][j] != '#':
continue
s[i][j] = g
k = j - 1
while k >= 0 and s[i][k]=='.':
s[i][k] = g
k -= 1
k = j + 1
while k < w and s[i][k] == '.':
s[i][k] = g
k += 1
g += 1
for i in range(h - 2)[::-1]:
if s[i][0]=='.':
for j in range(w):
s[i][j] = s[i + 1][j]
for i in range(h):
if s[i][0] == '.':
for j in range(w):
s[i][j] = s[i - 1][j]
for t in s:
print(*t)
| A, B, C, D = map(int, input().split())
takahashi_turn = True
while A > 0 and C > 0:
if takahashi_turn:
C = C - B
else:
A = A - D
takahashi_turn = not takahashi_turn
if A > 0:
print('Yes')
else:
print('No') | 0 | null | 86,820,977,460,042 | 277 | 164 |
x=int(input())
v=len(bin(x))-2
print((1<<v)-1) | H=int(input())
def n_attack(h):
if h==1:return(1)
else:return 1+2*n_attack(h//2)
print(n_attack(H)) | 1 | 79,866,614,865,588 | null | 228 | 228 |
N = int(input())
S = list(input())
check = 0
for i in range(N-1):
if S[i] != "*":
if S[i:i+3] == ["A","B","C"]:
check += 1
S[i:i+3] = ["*"]*3
print(check) | # 140 B
n = int(input())
s = input()
num = 0
for i in range(len(s)):
if s[i] == 'A':
try:
if s[i + 1] == 'B' and s[i + 2] == 'C':
num += 1
except:
pass
print(num) | 1 | 99,035,698,367,460 | null | 245 | 245 |
import sys
import math
import itertools as it
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))
if __name__ == "__main__":
n = I()
a = Intl()
for i in range(n):
if a[i]%2 == 0:
if a[i]%3 == 0 or a[i]%5 == 0:pass
else:
print("DENIED")
exit()
print("APPROVED") | N=input()
A=input()
Alist=A.split()
counts=0
for i in Alist:
if int(i)%2==1:
counts=counts
elif int(i)%3==0:
counts=counts
elif int(i)%5==0:
counts=counts
else:
counts=counts+1
if counts>=1:
print("DENIED")
else:
print("APPROVED") | 1 | 68,999,613,564,820 | null | 217 | 217 |
(d,), cc, *sstt = [list(map(int, s.split())) for s in open(0)]
ss = sstt[:d]
tt = list(map(lambda x: x-1, sum(sstt[d:], [])))
comp = [0]*len(cc)
ans = 0
for i in range(d):
comp = [sum(x) for x in zip(comp, cc)]
t = tt[i]
ans += ss[i][t]
comp[t] = 0
ans -= sum(comp)
print(ans) | D = int(input())
c = list(map(int, input().split()))
S = [list(map(int, input().split())) for i in range(D)]
T = [int(input()) for i in range(D)]
SUM = 0
last = [0] * 28
for d in range(1, D + 1):
i = T[d - 1]
SUM += S[d - 1][i - 1]
SU = 0
last[i] = d
for j in range(1, 27):
SU += (c[j - 1] * (d - last[j]))
SUM -= SU
print(SUM) | 1 | 9,995,228,922,972 | null | 114 | 114 |
n,r = map(int,input().split())
if n > 10:
print(r)
else:
a = r + (100 * (10-n))
print(a)
|
import sys
# 再起回数上限変更
sys.setrecursionlimit(1000000)
N, R = map(int, input().split())
if N >= 10:
print(R)
sys.exit()
print(R + 100 * (10 - N))
| 1 | 63,370,151,776,708 | null | 211 | 211 |
from itertools import permutations
import sys
N = int(sys.stdin.readline().rstrip())
P = [int(x) for x in sys.stdin.readline().rstrip().split()]
Q = [int(x) for x in sys.stdin.readline().rstrip().split()]
def nanba(N, P):
P = tuple(P)
for i, p in enumerate(permutations(range(1, N + 1), N)):
# print(p)
if P == p:
return i
return 0
a = nanba(N, P)
b = nanba(N, Q)
print(abs(a - b))
| import itertools
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
cnt = 0
p_cnt = 0
q_cnt = 0
n_list = [i for i in range(1, n+1)]
for P in itertools.permutations(n_list):
cnt += 1
if p == list(P):
p_cnt = cnt
if q == list(P):
q_cnt = cnt
if p_cnt and q_cnt:
print(abs(q_cnt-p_cnt))
exit() | 1 | 100,421,512,370,848 | null | 246 | 246 |
def INT():
return int(input())
def MI():
return map(int, input().split())
def LI():
return list(map(int, input().split()))
N = INT()
cnt = 0
for _ in range(N):
D1, D2 = MI()
if D1 == D2:
cnt += 1
else:
cnt = 0
if cnt == 3:
print("Yes")
exit()
print("No") | N=int(input())
f=0
for i in range(N):
a,b=map(int,input().split())
if a==b:
f+=1
else:
f=0
if f==3:
print('Yes')
break
else:
print('No') | 1 | 2,483,988,753,282 | null | 72 | 72 |
score = list(map(int,input().split()))
taka = score[0]
aoki = score[2]
while taka > 0:
aoki -= score[1]
if aoki <= 0:
print('Yes')
break
taka -= score[3]
if aoki > 0:
print('No') | from collections import defaultdict
d = defaultdict(lambda: 0)
N = int(input())
for _ in range(N):
ord, str = input().split()
if ord == 'insert':
d[str] = 1
else:
if str in d:
print('yes')
else:
print('no') | 0 | null | 14,847,279,517,620 | 164 | 23 |
n = int(input())
a = ord("a")
def dfs(s, mx):
if len(s) == n:
print(s)
else:
for i in range(a, mx + 2):
if i != mx + 1:
dfs(s + chr(i), mx)
else:
dfs(s + chr(i), mx + 1)
dfs("a", a) | def main():
X = [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]
K = int(input())
return X[K - 1]
print(main()) | 0 | null | 51,264,832,662,782 | 198 | 195 |
x = list(map(int, input().split()))
x0 = [x[0], x[1]]
y0 = [x[2], x[3]]
results = [(x0[0]*y0[0]), (x0[1]*y0[0]), (x0[0]*y0[1]), (x0[1]*y0[1])]
print(max(results)) | a,b,c,d = map(int, input().split())
ac = a * c
ad = a * d
bc = b * c
bd = b * d
print(max([ac, ad, bc, bd]))
| 1 | 3,012,488,252,742 | null | 77 | 77 |
count = 0
while True:
count += 1
num = int(input())
if num == 0:
break
print("Case", str(count) + ":", num) | n = int(input())
n %= 10
if n == 3:
print("bon")
elif n == 0 or n == 1 or n == 6 or n == 8:
print("pon")
else:
print("hon") | 0 | null | 9,889,810,559,948 | 42 | 142 |
#coding: utf-8
import math
a, b, C = (float(i) for i in input().split())
C = math.pi * C / 180
S = a * b * math.sin(C) / 2
h = b * math.sin(C)
L = a + b + math.sqrt(a**2 + b ** 2 - 2 * a * b * math.cos(C))
print("{:.8f}".format(S))
print("{:.8f}".format(L))
print("{:.8f}".format(h))
| while True:
m, f, r = map(int, (input().split()))
score = m + f
if m == f == r == -1:
break
else:
if m == -1 or f == -1:
print("F")
elif score >= 80:
print("A")
elif 80 > score >= 65:
print("B")
elif 65 > score >= 50:
print("C")
elif 50 > score >= 30 and r >= 50:
print("C")
elif 50 > score >= 30 and r < 50:
print("D")
else:
print("F") | 0 | null | 698,623,292,676 | 30 | 57 |
n = int(input())
p = list(map(int, input().split()))
ans = 1
p_min = p[0]
for i in range(1,n):
if p_min >= p[i]:
ans += 1
p_min = min(p_min, p[i])
print(ans) | import sys
class Card:
def __init__(self, kind, num):
self.kind = kind
self.num = num
def __eq__(self, other):
return (self.kind == other.kind) and (self.num == other.num)
def __ne__(self, other):
return not ((self.kind == other.kind) and (self.num == other.num))
def __str__(self):
return self.kind + self.num
def list_to_string(array):
s = ""
for n in array:
s += str(n) + " "
return s.strip()
def swap(array, i, j):
tmp = array[i]
array[i] = array[j]
array[j] = tmp
def is_stable(array1, array2):
if reduce(lambda x, y: x and y, map(lambda x: x[0] == x[1], zip(array1, array2))):
return "Stable"
else:
return "Not stable"
def bubble_sort(array):
for i in range(0, len(array)):
for j in reversed(range(i+1, len(array))):
if array[j].num < array[j-1].num:
swap(array, j, j-1)
return array
def selection_sort(array):
for i in range(0, len(array)):
min_index = i
for j in range(i, len(array)):
if array[min_index].num > array[j].num:
min_index = j
swap(array, i, min_index)
return array
def main():
num = int(sys.stdin.readline().strip())
array = map(lambda x: Card(x[0], x[1]), sys.stdin.readline().strip().split(" "))
a = list(array)
b = list(array)
print list_to_string(bubble_sort(a))
print "Stable"
print list_to_string(selection_sort(b))
print is_stable(a, b)
if __name__ == "__main__":
main() | 0 | null | 42,751,256,553,980 | 233 | 16 |
n = int(input())
s = input()
ok = [0,0,0,0,0,0,0,0,0,0]
ans = 0
for i in range(n):
if sum(ok) == 10:
break
if ok[int(s[i])] == 1:
continue
ok[int(s[i])] = 1
nd = [0,0,0,0,0,0,0,0,0,0]
for j in range(i+1,n):
if sum(nd) == 10:
break
if nd[int(s[j])] == 1:
continue
nd[int(s[j])] = 1
rd = [0,0,0,0,0,0,0,0,0,0]
for k in range(j+1, n):
if sum(rd) == 10:
break
if rd[int(s[k])] == 1:
continue
rd[int(s[k])] = 1
ans += 1
print(ans)
| values = []
while True:
v = int(input())
if 0 == v:
break
values.append(v)
for i, v in enumerate(values):
print('Case {0}: {1}'.format(i + 1, v)) | 0 | null | 64,368,361,673,340 | 267 | 42 |
def main():
c = ord(input())
print(chr(c+1))
main()
| a, b=map(int, input().split())
s=a*b
m=a+a+b+b
print(s, m)
| 0 | null | 46,128,182,372,398 | 239 | 36 |
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
n,m=map(int,input().split())
A=sorted(map(int,input().split()))
B=[0]+A[:]
for i in range(n):
B[i+1]+=B[i]
def solve_binary(mid):
tmp=0
for i,ai in enumerate(A):
tmp+=n-bisect.bisect_left(A,mid-ai)
return tmp>=m
def binary_search(n):
ok=0
ng=n
while abs(ok-ng)>1:
mid=(ok+ng)//2
if solve_binary(mid):
ok=mid
else:
ng=mid
return ok
binresult=binary_search(2*10**5+1)
for i ,ai in enumerate(A):
ans+=ai*(n-bisect.bisect_left(A,binresult-ai))+B[n]-B[bisect.bisect_left(A,binresult-ai)]
count+=n-bisect.bisect_left(A,binresult-ai)
# print(ans,count)
ans-=binresult*(count-m)
print(ans)
# print(binresult) | n,m=map(int,input().split())
su=input()
rev=su[::-1]
if "1"*m in su:
print(-1)
exit()
dist_f_n=[float('inf')]*(n+1)
dist_f_n[0]=0
for i in range(1,m+1):
if rev[i]=="0":
dist_f_n[i]=1
last=i
if i==n:
break
while last<n:
for i in range(last+1,last+m+1):
if rev[i]=="0":
dist_f_n[i]=dist_f_n[last]+1
_last=i
if i==n:
break
last=_last
cur=dist_f_n[-1]
_i=0
ans=[]
for i,x in enumerate(dist_f_n[::-1]):
if x==cur-1:
ans.append(i-_i)
cur-=1
_i=i
print(" ".join(map(str,ans)))
| 0 | null | 123,235,287,965,548 | 252 | 274 |
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
n,k=nii()
a=lnii()
x=0
x_list=[1]
x_table=[0 for i in range(n+1)]
x_table[1]=1
for i in range(k):
nx=a[x]
if x_table[nx]!=0:
inx=x_list.index(nx)
loop=x_list[inx:]
zan=k-i
q=zan%len(loop)
nx=loop[q-1]
break
else:
x=nx-1
x_list.append(nx)
x_table[nx]+=1
print(nx) | from functools import reduce
def match_word(w1, w2):
return w1 == w2 or w1+'.' == w2
def count_if(f, lst):
count = 0
for l in lst:
count += 1 if f(l) else 0
return count
def main():
count = 0
word = input().lower()
while True:
line = input();
if line == 'END_OF_TEXT':
break
count += count_if(lambda w: match_word(word, w.lower()), line.split())
print(count)
if __name__ == '__main__':
main()
| 0 | null | 12,359,647,221,728 | 150 | 65 |
n = int(input())
l = []
for i in range(1,n+1) :
if i%3 != 0 and i%5 != 0 :
l.append(i)
print(sum(l)) | n = int(input())
c = 0
for i in range(1,n+1):
if i%3 or i%5 == 0:
c += 0
if i%3 != 0 and i%5 != 0 :
c += i
print(c) | 1 | 34,842,721,470,938 | null | 173 | 173 |
i = input()
a = int(i)//2
b = int(i)%2
print(a+b) | S = int(input())
q , mod = divmod(S , 2)
print(q+mod) | 1 | 58,821,368,151,290 | null | 206 | 206 |
n=int(input())
s=[input() for _ in range(n)]
d0={}
d1={}
ma=0
mab=0
for si in s:
a,b=0,0
for x in si:
if x=='(':
b+=1
else:
b-=1
a=min(b,a)
a=-a
if b>=0:
if a in d0:
d0[a].append([a,b])
else:
d0[a]=[[a,b]]
ma=max(ma,a)
else:
if a+b in d1:
d1[a+b].append([a,b])
else:
d1[a+b]=[[a,b]]
mab=max(mab,a+b)
now=0
for i in range(ma+1):
if i not in d0:continue
if now>=i:
for a,b in d0[i]:
now+=b
else:
print('No')
exit()
for i in range(mab,-1,-1):
if i not in d1:continue
for a,b in d1[i]:
if now>=a:
now+=b
else:
print('No')
exit()
if now==0:
print('Yes')
else:
print('No') | import sys
from functools import reduce
n=int(input())
s=[input() for i in range(n)]
t=[2*(i.count("("))-len(i) for i in s]
if sum(t)!=0:
print("No")
sys.exit()
st=[[t[i]] for i in range(n)]
for i in range(n):
now,mi=0,0
for j in s[i]:
if j=="(":
now+=1
else:
now-=1
mi=min(mi,now)
st[i].append(mi)
now2=sum(map(lambda x:x[0],filter(lambda x:x[1]>=0,st)))
v,w=list(filter(lambda x:x[1]<0 and x[0]>=0,st)),list(filter(lambda x:x[1]<0 and x[0]<0,st))
v.sort(reverse=True,key=lambda z:z[1])
w.sort(key=lambda z:z[0]-z[1],reverse=True)
#print(now2)
for vsub in v:
if now2+vsub[1]<0:
print("No")
sys.exit()
now2+=vsub[0]
for wsub in w:
if now2+wsub[1]<0:
print("No")
sys.exit()
now2+=wsub[0]
print("Yes") | 1 | 23,597,422,489,422 | null | 152 | 152 |
def main():
h, n = map(int, input().split())
arr = [list(map(int, input().split())) for _ in range(n)]
dp = [[float("inf")]*(2*10**4+1) for _ in range(n+1)]
dp[0][0] = 0
for i in range(n):
p, a, b = i+1, arr[i][0], arr[i][1]
for j in range(2*10**4+1):
if j < a:
dp[p][j] = dp[p-1][j]
else:
if dp[p][j-a] + b < dp[p-1][j]:
dp[p][j] = dp[p][j-a] + b
else:
dp[p][j] = dp[p-1][j]
print(min(dp[-1][h:2*10**4+1]))
if __name__ == "__main__":
main()
| import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict
# import fractions
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)
MOD = 10 ** 9 + 7
MAX = float('inf')
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
H, N = il()
magic = [il() for _ in range(N)]
dp = [0] * (H + 1)
dp[0] = 0
for h in range(1, H + 1):
for n in range(N):
if n == 0:
if magic[n][0] <= h:
dp[h] = dp[h - magic[n][0]] + magic[n][1]
else:
dp[h] = magic[n][1]
else:
if magic[n][0] <= h:
dp[h] = min(dp[h], dp[h - magic[n][0]] + magic[n][1])
else:
dp[h] = min(dp[h], magic[n][1])
print(dp[-1])
if __name__ == '__main__':
main()
| 1 | 81,315,888,804,084 | null | 229 | 229 |
from math import factorial
def modpow(a, n, p):
if n == 0:
return 1
elif n == 1:
return a % p
if n % 2 == 1:
return (a * modpow(a, n-1, p)) % p
tmp = modpow(a, n//2, p)
return (tmp * tmp) % p
def main():
mod = 10 ** 9 + 7
n, a, b = map(int, input().split())
# まずは繰り返し2乗法によって全部の組み合わせを求める
# すべての組み合わせは、花を選ぶ/選ばないで組み合わせを決めれる
ans = (modpow(2, n, mod) - 1) % mod
# a本選んだときの数を引く
c_a = 1
for i in range(n, n-a, -1):
c_a *= i
c_a %= mod
c_a *= modpow(factorial(a), mod-2, mod)
ans -= c_a
ans %= mod
# b本選んだときの数を引く
c_b = 1
for i in range(n, n-b, -1):
c_b *= i
c_b %= mod
c_b *= modpow(factorial(b), mod-2, mod)
ans -= c_b
ans %= mod
print(ans)
if __name__ == "__main__":
main()
| x1, y1, x2, y2 = map(float, input().split())
print(abs(complex(x1-x2, y1-y2)))
| 0 | null | 33,029,865,793,830 | 214 | 29 |
N=int(input())
A=map(int, input().split())
A=list(A)
ans= [0] * len(A)
for i,a in enumerate(A):
ans[a-1]= i+1
print(' '.join(map(str,ans)))
| import sys
N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]
flagN = [False]*N
numN = [0]*N
if N > 1:
numN[0] = 1
for sc in SC:
s, c = sc[0], sc[1]
if flagN[s-1] == False:
flagN[s-1] = True
numN[s-1] = c
elif numN[s-1] == c:
continue
else:
print(-1)
sys.exit()
if N != 1 and numN[0] == 0:
print(-1)
sys.exit()
ans = ''
for n in numN:
ans += str(n)
print(ans) | 0 | null | 121,397,409,614,438 | 299 | 208 |
H, W, K = map(int, input().split())
S = [list(input()) for i in range(H)]
C = [-1] * H
for i, r in enumerate(S):
C[i] = r.count('#')
ans = [[-1] * W for i in range(H)]
first_flg = False
z = []
a = 0
for i in range(H):
if C[i] == 0:
if first_flg is False:
z.append(i)
else:
ans[i] = ans[i-1]
else:
a += 1
c = 0
for j in range(W):
if S[i][j] == '#':
first_flg = True
if c == 0:
c += 1
else:
c += 1
a += 1
ans[i][j] = a
for i in z[::-1]:
ans[i] = ans[i+1]
for i in range(H):
print(*ans[i])
| N = input()
ans = 'No'
for i in range(3):
if int(N[i]) == 7:
ans = 'Yes'
print(ans) | 0 | null | 89,333,546,651,198 | 277 | 172 |
import sys
s = input().strip()
if s[2] == s[3] and s[4] == s[5]:
print("Yes")
else : print("No") | import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
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
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False):
inds=sorted(range(len(s)), key=lambda k: s[k])
if return_sorted: return inds, [s[i] for i in inds]
return inds
#mod = 10**9+7
#w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え
#N = int(input())
#N, K = map(int, input().split())
#L = [int(input()) for i in range(N)]
#A = list(map(int, input().split()))
#S = [list(map(int, input().split())) for i in range(N)]
S=input()
if S[3]==S[2] and S[5]==S[4]:
print('Yes')
exit()
print('No') | 1 | 42,301,044,747,580 | null | 184 | 184 |
import sys
heights = []
for i in range(10):
line = sys.stdin.readline()
height = int(line)
heights.append(height)
heights.sort()
heights.reverse()
for i in range(3):
print (heights[i]) | #List of Top 3 Hills
set = []
a = 9
for i in range(10):
n = int(input())
set.append(n)
set.sort()
while a >= 7:
print(set[a])
a -= 1 | 1 | 18,445,310 | null | 2 | 2 |
import sys
input = sys.stdin.readline
class Combination: # 計算量は O(n_max + log(mod))
def __init__(self, n_max, mod=10**9+7):
self.mod = mod
f = 1
self.fac = fac = [f]
for i in range(1, n_max+1): # 階乗(= n_max !)の逆元を生成
f = f * i % mod # 動的計画法による階乗の高速計算
fac.append(f) # fac は階乗のリスト
f = pow(f, mod-2, mod) # 階乗から階乗の逆元を計算。フェルマーの小定理より、 a^-1 = a^(p-2) (mod p) if p = prime number and p and a are coprime
# python の pow 関数は自動的に mod の下での高速累乗を行ってくれる
self.facinv = facinv = [f]
for i in range(n_max, 0, -1): # 上記の階乗の逆元から階乗の逆元のリストを生成(= facinv )
f = f * i % mod
facinv.append(f)
facinv.reverse()
def __call__(self, n, r): # self.C と同じ
if not 0 <= r <= n: return 0
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
def H(self, n, r): # (箱区別:〇 ボール区別:× 空箱:〇) 重複組み合わせ nHm
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
n, k = map(int, input().split())
MOD = 10**9 + 7
C = Combination(n)
k = min(k,n-1)
res = 0
for l in range(k+1):
res += C(n,l)*C.H(n-l,l)
print(res%MOD)
| N, X, T = map(int, input().split())
ans = T * (N // X)
ans = ans if (N % X) is 0 else ans + T
print(ans)
| 0 | null | 35,796,860,252,640 | 215 | 86 |
print('Yes' if len(set([i for i in input().split()])) == 2 else 'No') | print( 'Yes' if len(set(input().split())) == 2 else 'No') | 1 | 68,081,580,401,562 | null | 216 | 216 |
#!/usr/bin/env python3
class Combination():
# コンストラクタ
def __init__(self, N:int, P:int):
self.N = N
self.P = P
# fact[i] = (i! mod P)
self.fact = [1, 1]
# factinv[i] = ((i!)^(-1) mod P)
self.factinv = [1, 1]
# factinv 計算用
self.inv = [0, 1]
for i in range(2, N+1):
self.fact.append((self.fact[-1] * i) % P)
self.inv.append((-self.inv[P % i] * (P // i)) % P)
self.factinv.append((self.factinv[-1] * self.inv[-1]) % P)
# nCk (mod P) (ただし、n<=N)
def getComb(self, n:int, k:int):
if (k < 0) or (n < k):
return 0
k = min(k, n - k)
return self.fact[n] * self.factinv[k] % self.P * self.factinv[n-k] % self.P
n,k = map(int,input().split())
MOD = 10**9 +7
COMB = Combination(n,MOD)
ans = 0
for i in range(min(n, k+1)):
ans += COMB.getComb(n,i) * COMB.getComb(n-1,i)
ans %= MOD
print(ans) | def main():
from collections import defaultdict
from math import gcd
import sys
input = sys.stdin.readline
mod = 10 ** 9 + 7
n = int(input())
fishes = defaultdict(int)
zero_zero = 0
zero = 0
inf = 0
for _ in range(n):
a, b = map(int, input().split())
if a == 0 and b == 0:
zero_zero += 1
elif a == 0:
zero += 1
elif b == 0:
inf += 1
else:
div = gcd(a, b)
a //= div
b //= div
if b < 0:
a *= -1
b *= -1
key = (a, b)
fishes[key] += 1
def get_bad_pair(fish):
a, b = fish
if a < 0:
a *= -1
b *= -1
return (-b, a)
ans = 1
counted_key = set()
for fish_key, count in fishes.items():
if fish_key in counted_key:
continue
bad_pair = get_bad_pair(fish_key)
if bad_pair in fishes:
pair_count = fishes[bad_pair]
pattern = pow(2, count, mod) + pow(2, pair_count, mod) - 1
counted_key.add(bad_pair)
else:
pattern = pow(2, count, mod)
ans = ans * pattern % mod
ans *= pow(2, zero, mod) + pow(2, inf, mod) - 1
if zero_zero:
ans += zero_zero
ans -= 1
print(ans % mod)
if __name__ == "__main__":
main()
| 0 | null | 44,245,487,111,830 | 215 | 146 |
s = input()
if(s[0].islower()):
print('a')
else:
print('A')
| from itertools import combinations_with_replacement as cwr
[N, M, Q] = [int(i) for i in input().split()]
req = [list(map(int, input().split())) for _ in range(Q)]
ans = 0
for seq in cwr(range(1, M+1), N):
sco = 0
for i in range(Q):
if seq[req[i][1]-1] - seq[req[i][0]-1] == req[i][2]:
sco += req[i][3]
s = max(ans, sco)
ans = s
print(ans) | 0 | null | 19,482,647,774,140 | 119 | 160 |
import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase
"""def gcd(a,b):
if b==0:
return a
else:
return gcd(b,a%b)"""
"""def pw(a,b):
result=1
while(b>0):
if(b%2==1): result*=a
a*=a
b//=2
return result"""
def inpt():
return [int(k) for k in input().split()]
def check(mid,k,ar):
ct=k
for i in ar:
if(i<=mid):
continue
ct-=(i//mid)
return ct>=0
def main():
n,k=map(int,input().split())
ar=inpt()
i,j=1,100000000000
while(i<j):
mid=(i+j)//2
if(check(mid,k,ar)):
j=mid
else:
i=mid+1
print(i)
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
main()
| def main():
n,k = map(int,input().split())
A = list(map(int,input().split()))
left = 0
right = max(A)
while abs(right-left)>1:
cent = (right+left)//2
ct = 0
for a in A:
ct+=a//cent
if a%cent==0:
ct-=1
if ct <= k:
right=cent
else:
left=cent
print(right)
main()
| 1 | 6,538,417,007,132 | null | 99 | 99 |
m,n=map(int,raw_input().split())
if m>n:print'a > b'
elif m<n:print'a < b'
else:print'a == b' | while True:
string = input().strip()
if string == '0': break
print(sum([int(c) for c in string]))
| 0 | null | 967,723,218,978 | 38 | 62 |
def main():
n = int(input())
s_set = set()
for i in range(n):
order = input().split()
if order[0] == "insert":
s_set.add(order[1])
else:
if order[1] in s_set:
print("yes")
else:
print("no")
if __name__ == '__main__':
main()
| matrix = []
for i in range(3):
line = []
line = input().split(" ")
matrix.append(line)
n = int(input())
chosen = 0
for i in range(n):
b = input()
for i in range(3):
for j in range(3):
if matrix[i][j] == b:
chosen += 1
matrix[i][j] = 0
bingo = False
for i in range(3):
if(matrix[i][0] == 0 and matrix[i][1] == 0 and matrix[i][2] == 0):
bingo = True
break
elif(matrix[0][i] == 0 and matrix[1][i] == 0 and matrix[2][i] == 0):
bingo = True
break
if(matrix[1][1] == 0 and matrix[0][0] == 0 and matrix[2][2] == 0):
bingo = True
if(matrix[1][1] == 0 and matrix[2][0] == 0 and matrix[0][2] == 0):
bingo = True
if bingo:
print("Yes")
else:
print("No")
| 0 | null | 30,137,340,146,452 | 23 | 207 |
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
mod = 998244353
N, M, K = mapint()
pos = {}
neg = {}
pos[0] = 1
neg[0] = 1
for i in range(1, N+1):
pos[i] = i*pos[i-1]%mod
neg[i] = pow(pos[i], mod-2, mod)
ans = 0
for i in range(K+1):
ans += M*pow((M-1), (N-i-1), mod)*pos[N-1]*neg[i]*neg[N-i-1]
ans %= mod
print(ans) | # -*- coding: utf-8 -*-
def check_numbers(cargo_weight_list, number_of_all_cargo, number_of_tracks, maximum_weight):
"""check the numbers that are loadable in tracks
Args:
cargo_weight_list: cargo weight list
number_of_tracks: the number of tracks
Returns:
the number of cargos that are loadable in tracks
"""
counter = 0
number_of_loaded_cargo = 0
while counter < number_of_tracks:
current_track_weight = 0
while current_track_weight + cargo_weight_list[number_of_loaded_cargo] <= maximum_weight:
current_track_weight += cargo_weight_list[number_of_loaded_cargo]
number_of_loaded_cargo += 1
if number_of_loaded_cargo == number_of_all_cargo:
return number_of_all_cargo
counter += 1
return number_of_loaded_cargo
def find_the_minimum_of_maximum_weihgt(cargo_weight_list, number_of_all_cargo, number_of_tracks):
"""find the minimum of maximum weight s.t all of the cargos can be loaded into tracks.
(binary search is used. the number of loadable cargos monotonicaly increases as the maximum weight increases)
Args:
cargo_weight_list: cargo weight list
numbef of all cargo: the number of all cargos
number of tracks: the number of tracks
Returns:
minumim number of maximum track weight that are needed to load all of the cargos
"""
left = max(cargo_weight_list)
right = sum(cargo_weight_list)
while (right - left) > 0:
middle = (right + left) / 2
the_number_of_loadable_cagos = check_numbers(cargo_weight_list, number_of_all_cargo, number_of_tracks, middle)
if the_number_of_loadable_cagos >= number_of_all_cargo:
right = middle
else:
left = middle + 1
return right
def main():
number_of_all_cargo, number_of_tracks = [int(x) for x in raw_input().split(' ')]
cargo_weight_list = [int(raw_input()) for _ in xrange(number_of_all_cargo)]
print find_the_minimum_of_maximum_weihgt(cargo_weight_list, number_of_all_cargo, number_of_tracks)
if __name__ == '__main__':
main() | 0 | null | 11,669,438,610,500 | 151 | 24 |
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
def main():
n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
ruiseki = [0]
d = defaultdict(int)
d[0]=1
for i in range(n):
if i - k + 1>= 0:
d[ruiseki[i - k+1]]-=1
ruiseki.append((ruiseki[i] + a[i] - 1)%k)
ans += d[ruiseki[i+1]]
d[ruiseki[i + 1]] += 1
print(ans)
if __name__ == '__main__':
main()
| class UnionFind():
def __init__(self, n):
self.n = n
self.par = list(range(self.n))
self.rank = [1] * n
self.cnt = n
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def unite(self, x, y):
p = self.find(x)
q = self.find(y)
if p == q:
return None
if p > q:
p, q = q, p
self.rank[p] += self.rank[q]
self.par[q] = p
self.cnt -= 1
def same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return self.rank[x]
def count(self):
return self.cnt
n, m = map(int, input().split())
UF = UnionFind(n)
for _ in range(m):
a, b = map(int, input().split())
UF.unite(a - 1, b - 1)
print(UF.count() - 1) | 0 | null | 69,669,350,288,328 | 273 | 70 |
x = input()
if x.endswith("s") == True:
x = x + "es"
else:
x = x + "s"
print(x) | S = list(input())
if S[-1] != "s":
S.append("s")
else:
S.append("es")
print(*S, sep="") | 1 | 2,381,536,560,342 | null | 71 | 71 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.