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
|
---|---|---|---|---|---|---|
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect
import itertools
import heapq
sys.setrecursionlimit(4100000)
def inputs(num_of_input):
ins = [input() for i in range(num_of_input)]
return ins
def int_inputs(num_of_input):
ins = [int(input()) for i in range(num_of_input)]
return ins
def solve(input):
nums = string_to_int(input)
def euclid(large, small):
if small == 0:
return large
l = large % small
return euclid(small, l)
nums.sort(reverse=True)
eee = euclid(nums[0], nums[1])
return int((nums[0] * nums[1]) / eee)
def string_to_int(string):
return list(map(lambda x: int(x), string.split()))
if __name__ == "__main__":
ret = solve(input())
print(ret)
|
import math
import numpy as np
A,B = np.array(input().split(),dtype = int)
def gcd(x,y):
if y == 0:
return x
else:
return gcd(y,x%y)
print(int(A*B/(gcd(A,B))))
| 1 | 113,207,059,007,328 | null | 256 | 256 |
a=map(int,raw_input().split())
print(str(a[0]*a[1])+" "+str(2*(a[0]+a[1])))
|
def print_func(s, order):
print(s[order[1]:order[2]+1])
def reverse_func(s, order):
ans = list(s[order[1]:order[2]+1])
ans.reverse()
s = s[:order[1]]+''.join(ans)+s[order[2]+1:]
return s
def replace_func(s, order):
cnt = 0
s = list(s)
for i in range(order[1], order[2]+1):
s[i] = str(order[3])[cnt]
cnt += 1
s = ''.join(s)
return s
if __name__ == '__main__':
s = input()
for i in range(int(input())):
order = input().split()
order[1] = int(order[1])
order[2] = int(order[2])
if order[0] == 'print':
print_func(s, order)
elif order[0] == 'reverse':
s = reverse_func(s, order)
else:
s = replace_func(s, order)
| 0 | null | 1,219,422,653,018 | 36 | 68 |
def a():
x = int(input())
k = 1
while (k * x) % 360 != 0:
k += 1
print(k)
a()
|
import itertools
from typing import List
def main():
h, w, k = map(int, input().split())
c = []
for _ in range(h):
c.append(list(input()))
print(hv(c, h, w, k))
def hv(c: List[List[str]], h: int, w: int, k: int) -> int:
ret = 0
for comb_h in itertools.product((False, True), repeat=h):
for comb_w in itertools.product((False, True), repeat=w):
cnt = 0
for i in range(h):
for j in range(w):
if comb_h[i] and comb_w[j] and c[i][j] == '#':
cnt += 1
if cnt == k:
ret += 1
return ret
if __name__ == '__main__':
main()
| 0 | null | 11,023,262,994,920 | 125 | 110 |
#coding:utf-8
input()
data = [int(x) for x in input().split()]
print(str(min(data))+" "+str(max(data)) + " "+str(sum(data)))
|
from itertools import groupby
def main():
S = input()
K = int(input())
a = [len(tuple(s)) for _, s in groupby(S)]
ans = 0
if S[0] == S[-1] and K > 1:
if len(a) == 1:
ans = a[0] * K // 2
else:
ans = a[0] // 2 + a[-1] // 2 + (a[0] + a[-1]) // 2 * (K - 1)
ans += sum(n // 2 for n in a[1:-1]) * K
else:
ans += sum(n // 2 for n in a) * K
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 87,655,040,964,258 | 48 | 296 |
i = input()
print(i.swapcase())
|
s=list(input())
ans=""
for i in s:
ans+=i.swapcase()
print(ans)
| 1 | 1,511,369,287,958 | null | 61 | 61 |
"""
n=int(input())
s=[int(x) for x in input().split()]
q=int(input())
t=[int(x) for x in input().split()]
#print(s)
c=0
for i in t:
if i in s:
c+=1
print(c)
"""
"""
n=int(input())
s=[int(x) for x in input().split()]
q=int(input())
t=[int(x) for x in input().split()]
#binary search
a=0
for i in range(q):
L=0
R=n-1#探索する方の配列(s)はソート済みでないといけない
while L<=R:
M=(L+R)//2
if s[M]<t[i]:
L=M+1
elif s[M]>t[i]:
R=M-1
else:
a+=1
break
print(a)
"""
#Dictionary
#dict型オブジェクトに対しinを使うとキーの存在確認になる
n=int(input())
d={}
for i in range(n):
command,words=input().split()
if command=='find':
if words in d:
print('yes')
else:
print('no')
else:
d[words]=0
|
n = int(input())
if n>=3:
if n%2==0:
print(n//2-1)
else:
print(n//2)
else:
print(0)
| 0 | null | 76,399,517,654,770 | 23 | 283 |
#!/usr/bin/python3
import sys
input = lambda: sys.stdin.readline().strip()
L = int(input())
print(f'{(L / 3) ** 3:.6f}')
|
s = input()
q = int(input())
for i in range(q):
command = input().split()
command[1] = int(command[1])
command[2] = int(command[2])
if command[0] == 'print':
print(s[command[1]:command[2]+1])
elif command[0] == 'reverse':
s = s[command[1]:command[2]+1][::-1].join([s[:command[1]], s[command[2]+1:]])
elif command[0] == 'replace':
s = command[3].join([s[:command[1]], s[command[2]+1:]])
| 0 | null | 24,700,101,896,620 | 191 | 68 |
N = int(input())
print(input().count("ABC"))
""" 3文字ずつスライスし判定
S = input()
count = 0
# スライスでi+2文字目まで行くのでfor文範囲はN-2でとどめる
for i in range(N-2):
if S[i:i+3] == "ABC":
count += 1
print(count) """
|
##### ABC 160
K,N = map(int, input().split())
A = list(map(int,input().split()))
dist = []
for i in range(N-1):
dist.append(A[i+1]-A[i])
dist.append(K-A[-1]+A[0])
dist.sort()
ans = 0
for i in range(N-1):
ans += dist[i]
print(ans)
| 0 | null | 71,232,320,990,908 | 245 | 186 |
n = int(input())
count = 0
for i in range(0, n):
tmp = input()
if tmp.split()[0] == tmp.split()[1]:
count += 1
if count == 3:
break
else:
count = 0
if count == 3:
print('Yes')
else:
print('No')
|
#!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
n = I()
a = LI()
L = [1]
if a[-1] > 2**n:
print(-1)
quit()
if n == 0:
if a[0] == 0:
print(-1)
quit()
L2 = [a[-1]]
for i in range(n)[::-1]:
L2.append(min(L2[-1] + a[i], 2**i))
L2 = L2[::-1]
ans = 0
for i in range(n+1):
if i == 0:
tmp = 1
else:
tmp = (L[-1] - a[i-1]) * 2
if tmp <= 0:
print(-1)
quit()
ans += min(tmp, L2[i])
L.append(tmp)
if L[-1] - a[-1] < 0:
print(-1)
quit()
print(ans)
| 0 | null | 10,612,991,040,160 | 72 | 141 |
A,B,C,D,E,F = map(int, input().split())
q = int(input())
for i in range(q):
x, y = map(int, input().split())
while A != x:
A,B,C,D,E,F = D,B,A,F,E,C #E
if A == x:
break
A,B,C,D,E,F = B,F,C,D,A,E #N
while B != y:
A,B,C,D,E,F = A,C,E,B,D,F #R
print(C)
|
A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())
if A < B:
if A + (V*T) >= B + (W*T):
print("YES")
else:
print("NO")
else:
if A - (V*T) <= B - (W*T):
print("YES")
else:
print("NO")
| 0 | null | 7,629,963,661,920 | 34 | 131 |
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT() : return int(input())
def MAP() : return map(int,input().split())
def LIST() : return list(MAP())
def NIJIGEN(H): return [list(input()) for i in range(H)]
N,M=MAP()
H=LIST()
L=[[0] for i in range(N)]
for i in range(M):
a,b=MAP()
a-=1
b-=1
L[a].append(H[b])
L[b].append(H[a])
ans=0
for i in range(N):
if max(L[i])<H[i]:
ans+=1
print(ans)
|
n, m = list(map(int, input().split()))
h = list(map(int, input().split()))
routes = [[] for _ in range(len(h) + 1)]
for _ in range(m):
a, b = list(map(int, input().split()))
routes[a].append(b)
routes[b].append(a)
good = 0
for i in range(1, len(routes)):
if len(routes[i]) == 0:
good += 1
continue
if h[i - 1] > max([h[j - 1] for j in routes[i]]):
good += 1
print(good)
| 1 | 25,111,846,674,360 | null | 155 | 155 |
N = int(input())
S = input()
ans = "Yes"
if N % 2 != 0:
ans = "No"
else:
N = int(N/2)
for i in range(0, N):
if S[i] != S[i+N]:
ans = "No"
break
print(ans)
|
n = int(input())
s = input()
if len(s) % 2 == 0:
if s[:int(n/2)] == s[int(n/2):]:
print("Yes")
else:
print("No")
else:
print("No")
| 1 | 146,967,824,975,632 | null | 279 | 279 |
#template
from sys import setrecursionlimit
setrecursionlimit(10**6)
from collections import Counter
def inputlist(): return [int(i) for i in input().split()]
#template
li = ['hi','hihi','hihihi','hihihihi','hihihihihi']
S = input()
if S in li:
print("Yes")
else:
print("No")
|
import base64
import subprocess
exe_bin = "e??420s#R400000000000{}h%0RR91&<Owl00000KmY&$00000s2czP0000000000Kma%Z2>?I<9RM5v1^@s61ONa4KmY&$00000KmY&$00000KmY&$00000_yGU_00000_yGU_000002mk;8000000{{R31ONa4I066w00000I066w00000I066w000008~^|S000008~^|S000000RR91000000RR911poj5000000000000000000000000000000*bD#w00000*bD#w00000001BW000000RR911^@s6Xbk`W00000Xbm6$00000Xbm6$00000r~&{0000007zF?T00000001BW000000ssI21^@s6fDHfu00000fDIr300000fDIr30000000IC20000000IC2000002mk;8000001ONa41ONa4R004100000R004100000R004100000L;wH)00000L;wH)000001ONa400000P~~)F1ONa4YzqJY00000YzqJY00000YzqJY00000L;wH)00000L;wH)000001ONa400000QRQ@G1^@s6000000000000000000000000000000000000000000000000005C8xG00000Qss1H1ONa4Xbk`W00000Xbm6$00000Xbm6$00000m;wL*00000m;wL*000000RR9100000FKlUIHZ(76WG!rIZgqGqcsMpKHZ(4CZ!R(b1ONa45C8xG0RR91M^04$000000{{R30ssI2000001ONa46aWAK0{{R3M^04$66o;Pv0SFPAbMN%YxTqg6IY|L0ssI24gdfE0RR911^@s6000mI0RRL54gdfE000006qpP{bCw4J000000000000000000000000000000fdBvi5&!@I00000000000000000000LID5(A^-pY00000000000000000000E&%`l5&!@I00000000000000000000RR9105&!@I00000000000000000000H30ws5&!@I000000000000000000009RUCU5&!@I00000000000000000000qW}N^5&!@I00000000000000000000@c;k-5&!@I000000000000000000009{>OVAOHXW00000000000000000000Q2_t|5&!@I000000000000000000005C8xGAOHXW00000000000000000000I{*LxAOHXW00000000000000000000X#fBK5&!@I000000000000000000002>}2A5datfKoB4R000005CH%H00000U;qFB5datfU=bhy000007y$qP000000BmVub97{5D=RK@Z!R_fUtec!Z*E_6bYXIIUta)UNmNZ=WMy(?XK8bEWpY$aLu_wuWmI8eY-IpnNmNZ=a%E>}b97~LR82!{Z*FB&VPb4$0AE^8Q)zN@MN(-1Us_XiGh=CP0AE^8Q*=0KZ*yN_VRL0PNp5L$L@`Bn0AE^8Q*=0KZ*yN_VRL0MHFJ4xV_$b^bZB35bYy97MPdM7T2pi}HeX+Fb98cLVQpV&ZgXXFbV*}VbTKhwXkl_+baG*7baP2#MMY9mbTKnxVRLC?UvG1Ca%Ev{NmO4{FkeMeHeXOnQ!`&|0AE^8Q*=0KZ*yN_VRL0PNp5L$Lor2m0AE^DbTngcb#wr1X<}n8b8jv-0AF8obYWv_Ut?%%UuI!xYyfj~a%^R80AF8Ycwt{*bY*yHbO2vpV|Za-W@&C=Y-xIB0AF8hX<}nvb97;HbYE>@X>I^VOi4mRUotK<07pzoLPK9NE;24P07pzoLPJ<sUo$Q=E;#^4Oi4mRSXf^(E;IlD000620{{a60ssR51ONp90ssI20{{R3000620ssO4000000RRF369E7K5C8xGFaQ7m6lrM<000C4V*vmF5C8xGbsA|200093Z2<rP000000RRF30RR915C8xG00000iGL{q000F5c>w?b5C8xGbSaVu00062hXDWp00000Xbm6$000002mk;800000&<X$m00000a19^;000002mk;800000pa}o~00000cnu%`000002mk;800000kO}|*000002oN9u000002mk;8000002oN9u00000&<`L0000001^@s60ssI20000000000*bg88000001^@s62><{90000000000;13`G000001^@s63IG5A0000000000=no(O000001^@s63jhEB0000000000@DCsW000001^@s63;+NC0000000000_zxfe000001^@s64FCWD0000000000KoB4R000001poj54gdfE0000000000U=bhy000001poj54*&oF0000000000m=7QT000002LJ#70RR910000000000pbsDb000002LJ#70{{R30000000000s1G0j000002LJ#71ONa40000000000un!;r000002LJ#71poj50000000000xDOxz000002LJ#71^@s60000000000zz-k*000002LJ#72LJ#70000000000$PXX@000002LJ#72mk;80000000000NQ3MMNQ(u%2Ot1Qg}`(I|IkQ-#0bLx0000000000|20AfAOQa*L<b-M4<A4P|0O~PAOL6p0002#;Q#;s|0OyHAOL6q0002#(EtDc|0Oa9AOL6r0002#!2kdM|0OC1AOL6s0002#u>b%6|0N;^AOL6t0002#p#T5>|0Nm+AOL6u0002#kpKVx|0NO!AOL6v0002#fdBvh|0N0sAOL2N0000000000Q!)QYjU9~w002mX>>y-Fiv%So0000;i9{qAF~I0u|Ns9;jdUaoNR2&V2p|AR#|1tKAOHXW008J=|Ns9;jdUasNQuYjRR90~NR4zP6iA83=tuwm|BFN<6iAIVFaiJo53fWd5IaO93`h@5-bjhx=okP0|45BJ@CG0NNQuHoiQec%|Ns9;jdUanNR2(&1|R^s0RR91#zZ6w3g{~T|NlsfOe7d&NHYv2C;$KebqGj<#2_)iTf^x6{{R0E9{^@94<Cd800000NR2(x2p|ARgX{?C0RR90NQ*r|1|R@PjTK4;AOJ{>HM9sI07!$x2<fu^|Nmx?G3`l-(OyW2;z)z!@K97tjRk4}002mh4f6m107#8J-2VUn{}tv1AOQ3aA4C8ENR2%S1|R@cNR0&n1|R@PIrvD4<#ZWHiv_v`AOJ{(z;q2=|KMgW4<Cd800000UBeF_KmcYg4<Cd800000NR2(o1t0)OjWxmrAOKZJDgH=_<w(K)14xPRNWthoNCC!3(f)K8NQ(u51t0)Og}`(SUH{-_4<Cd800000UBeF_KmcYg4<Cd800000fIZ;{AOHY$FGzzuF9jd~098nd<#Y^4i#=KeAOPqM{{R2zNdN!;#s#?tAOHbf!w(;T00000^TTEjA4C8ERY-~DUFl~3|NmwWA4C8EL03UmNr~4%RY6otjU{#hAOKZJjV*oxAOKTAiTz25_Dm_|NQ3MMNWuLB=nwt>|44=HbRaR?4<Cd800000Oo{qTiS|T^??L|*+(?7N0Z2LBb?Qii#0XnmL0myyL0&;$!;oe!4<Cd800000^TPlDNQ3MMNQ1-(!vFvP0RRF3PHzBNWpe-k0UHB5KmY&$2LJ#7)cpVdi~s-tRQ><|v;Y7AWc~mD%m4rYH2(kp@Bjb+Wd8sETmS$7bpQYV3;_TD<p2NwQ~>}06aWAK000000eVsZ0eBDr8w>{skO2n}6aWAK8~^|S0RI2~D*ylh00000000006aWAK000000eVsZ0eBDr8w>{skO2SyBme*a8~^|SK>YvzfB*mh01gmF4j4)g3wH>B06!W#Dl;S^000006aWAKL;wH)nEe0$2mk;80000000000AOHXWTmS$7ko^Du!vFvP06`8Ag91$sFaoR!4iG~Q2tf+~7ytkOfB*mhJpKRwE&u=k080)KUJeKV00000L;wH)oB#j-VE+IAWdHyG074EBj{-st7>)x)4j_#LLJla51xOAsh6YFuID-dG4nT4aI6)3DK@KQF4j@7f7(xyZLJkN35C8xG<NyEwi2nco0ssI20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000&<X$m00000pa}o~00000kO}|*000000RR91000000RR91000000RR910000069E7K000003;+NC00000AP4{e000004FCWD00000R0{wA0000082|tP00000Xbm6$000008vp<R000005C8xG000008UO$Q00000cnu%`000008~^|S000002mk;800000_5S~F00000m;wL*000001poj500000Km-5)000001^@s600000zybgO000003IG5A00000lK}t#000003jhEB000007ytkO000006#xJL0000000000000000{{R300000fDa%5000000ssI200000r~m)}000006aWAK000002LJ#7000007XSbN00000cn1Ig000002LJ#700000SOx$9000002mk;800000AOQdX000002><{9000007ytkO000009smFU000002mk;800000`~UxM000000RR9900000{{R1P00000_yqs}00000|NsAQ000000ssI200000@c;jB00000)CB+l00000`TzfK000001ONa4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000fDIr30000000000000000000000000RtNw900000W(WWP00000b_f6f00000h6n%v00000mIwd<00000rU(E400000wg><K0000000000000000000000000000000000000000000000000000000000000000000000000002oN9u00000M?*t8AShL0b#8QZAU7^GE-)=Kbz*gHbagR)F*q(TG$|lAE;TMN0000000000000000000000000000000000000000000000{{U4I066w000000000000000000000{{X5R0041000000000000000000000{{a6bOHbX000000000000000000000{{d7m;wL*000000000000000000000{{g8zybgO000000000000000000000{{j9Km-5)000000000000000000000{{mA)CB+l000000000000000000000{{pB_yqs}000000000000000000000{{sCSOx$9000000000000000000000{{vDcn1Ig000000000000000000000{{yEAP4{e000000000000000000000{{#FKnMT;000000000000000000000{{&Gzz6^U000000000000000000000{{*H&<Fqk000000000000000000000{{;IR0{wA000000000000000000000{{>JU<&{M000000000000000000000{{^KYzqJY000000000000000000000{{{LunPbH000000000000000000000{{~MXbm6$000000000000000000000{|2Ncnu%`000000000000000000000{|5OfDIr3000000000000000000000{|8PfDa%5000000000000000000000{|BQ01zMm000000000000000000000{|ERKoB4R000000000000000000000{|HS000000000000000000000RR911OV~>000000000000000000002><{90ssyGpa}o~00000E&u=k000009RL6T0RR{Pc@iK1000000RR9100000EC2ui1OV~>00000000000000000000Hvj+t0ssyG015yA000000000000000IRF3v0ssyGKnef=000000000000000OaK4?0ssyGkO}|*000000000000000VgLXD0RR{PcoHB0000000RR9100000aR2}S0RR*Lcnu%`000000000000000m;e9(0ssyG&<X$m000000000000000qyPW_0RR&KXbm6$000000000000000EC2ui1OV~>00000000000000000000!vFvP0RR#J)C>Rs000000000000000000001OV~>00000000000000000000(EtDd000pHYzqJY000000000000000<NyEw0RR;MfDIr3000000000000000?EnA(000vJcnu%`000000000000000{r~^~000vJXbm6$0000000000000005di=I0RR>NfDa%5000000000000000CjkHe5C9hd5D*{$000000000000000c>(|cAOIHt01zMm000000000000000E&%`l5daVXU<&{M000001ONa400000Jplj!5&!@I00000000000000000000YykiOA^-pY00000000000000000000hyefq5&!@I000000000000000000007ytkO5&#YW&<Fqk00000!vFvP00000oB;p;5ds$g2oN9u000000000000000sQ~~05&!@I00000000000000000000>jD4(5&#bXR0{wA000000000000000!2tjO5&!@I00000000000000000000eF6Xg5&#YW&<Owl00000D*ylh00000+W`Oo5&!@I00000000000000000000zXAXN5&#PTAP4{e000000000000000_W=L^5ds$g5D*{$0000000000000000|Ed55&!@I00000000000000000000U;+RD5datfKoB4R000005CH%H00000cLD$a5C9hd01zMm000000000000000`2YX_5C9kefD#}8000000000000000gaQBn5C9ke5D*{$000000000000000kOBYz5&!@I00000000000000000000wE_SD5&#YW;0gc$00000WdHyG00000#R32TAOHXW00000000000000000000;Q{~v5&#YWPzwM6000000ssI200000@d5w<5datfU=bhy000007y$qP000002Lk{A5&!@I00000000000000000000CIbKfAOHXW00000000000000000000H3I+uAOHXW00000000000000000000PXhn|5&!@I000000000000000000000BvDuZZ2bE0AEK;PeMUVUte=|VqZyLZDDC{0AE^DbWAv3Uukb?ZfSG?V{&wJbaiHCE@J>>WpZU_X>)XCa$j_9Ut?@<Ze?=-UteTzUuSG@Vqt7wWOQ$Gb6;U~cmQK>ZE$R5bY)~NH#Rvq0AF8ZZ(nC@Z(?C=Uu1M|a&uo{b$DN9X>Ms>VRCX|d0%C2baHtBW^!R|WnW}<ZEbk~UteZ&VQpn!WOZ$Ad0%O6X>?y<a&lpLUuAA|a(Mt>Uq(_vO+{ZtPDEc{0AF86PE}t;NMA-$K}|(pNJLTqUqo3>K}|_R0AF8eZfSI1VRCX|d0%C2WB^}ZX>MtBUtw}`VR>J3bYXII0AEK;PeMUVUr$CxQ$<u?R6#;aMPC44Wn^J=VE|uAPhWF%WNB_+b#rB80AE^8Q*=0KZ*yN_VRL0MHFJ4xV_$b^bZB35bYy97MPfieM@&gVLs(c}GcGg$UteQ*VP9rxZeeU`dSyUBM@&gVLtip3GA=a$b98cSWo|$~M@&gVLtip3GA=a$UteT%Z(nF(Ze(m_0AE^8Q)zN@MN(-%Ku1hTLPJ<sUo$Q=0AF8Ycwt{*bY*yHbU;8yOi4mRUotK-E;RsOUvqR}V{2byXlq|)VQFkYKu1hTLPK9NE;ImNUsO#)UqwztUta)UT2pi}HeX+Fb98cLVQpV&ZgXXFbV*}VbTKhwXkl_+baG*7baP2#MMY9mbTKnxVRLC?UvG1Ca%Ev{NmO4{FkeMeHeXOnQ!`&|KtM-KNkT(dSYI<PG%h&+Us_XiG-GddbU;8yOi4mRSXf^(E;ImNUu0o)VPA7}VRCc;UteN#b6<0GVRCc;Us_I6bU0~mb6;X%b7eG1ZfSHwF-3MjKu1hTLPJ<sUo$Q=0AF8hX<}nvV{>(1X>MtB0AEQ|O<!bXa%E>}b97~LR82!{Z*FB&VPb4$0AF8hX<}nvV{>(1W@&C|0AE^DbTeaVZa_dsOi4mRSXf^(E;ImNUu<b&V_$Q0VRCd|ZDDC{KtM-KNkT(kGA=SMH2_~<XKin8UvqR}a&%u`0AEQ|O<!_lXK8bEWpY$aLu_wuWmI8eY-IpnT251RIB9QlUt(c%Wi&}{X>>#}MRq_yM@&gVLs(c}GcGg$04{TRZFFH`04{TMa&%#004{TAb98caVPXI-X>N37a&Q1HZf|sDE<r*`Ep%aL04{ECbY(7QZgnnVb!lv5Eoo!`E@y6aE@)wMXaFu`d2VxgZ2&H0d2VxbasV!8ZgnnpWpZ<AZ*BlCXKr;ac4cyNX>V>{asV!JWo%(CWO;4?E^=jTVJ>iNbO0`CZfSG?E^usgE@y9a04{W8cys_RW@&C|04{QGWMOn+04`-{UuJS)ZDn6*WO4v5WoTb!a$#*{04`~6X>?y<a&lpL04`=}ZfRd(a&lpL04`*CZeeX{V*oB>VRT^tE@E?Y04`&1ZEa<4bN~PV00000000000000000000000000000000000000000000000000000000000000000000000000000000000008vp<R0RR910ssI200000I066w00000I066w000008~^|S0000000000000000RR91000000000000000BLDyZ2LJ#70ssI200000R004100000R004100000AOHXW0000000000000001ONa4000000000000000F#rGn2LJ#70ssI200000bOHbX00000bOHbX00000Bme*a0000000000000001ONa4000000000000000L;wH)_W%EH0ssI200000m;wL*00000m;wL*00000C;$Ke000001poj5000002mk;8000000000000000P5=M^3jhEB0ssI200000zybgO00000zybgO00000fB^si000001^@s60RR912mk;8000007ytkO00000RsaA10{{R30ssI200000Km-5)00000Km-5)00000lK}t#0000000000000000RR91000000000000000UH||9|NsAQ0ssI200000)CB+l00000)CB+l00000AOHXW000001poj5000000ssI2000000ssI200000YXATM{{R1P0ssI200000_yqs}00000_yqs}00000U;qFB000001^@s60ssI22mk;8000000000000000dH?_b1ONa40ssI200000SOx$900000SOx$900000AOQdX000001poj5000002mk;8000007ytkO00000ga7~l1ONa4LI3~&00000cn1Ig00000cn1Ig00000r~m)}000001poj5761SM2mk;8000007ytkO00000jsO4v0RR911^@s600000AP4{e00000AP4{e000007XSbN0000000000000001ONa4000000000000000i2wiq0RR911^@s600000KnMT;00000KnMT;00000fB*mh0000000000000005C8xG000005C8xG00000lmGw#0RR911^@s600000zz6^U00000zz6^U000002mk;80000000000000002mk;8000002mk;800000od5s;0RR911^@s600000&<Fqk00000&<Fqk00000f&u^l0000000000000005C8xG000000000000000qW}N^0RR911^@s600000R0{wA00000R0{wA000002><{90000000000000001ONa4000000000000000sQ>@~0RR910ssI200000U<&{M00000U<&{M000003jhEB0000000000000001ONa4000000000000000u>b%70RR910ssI200000YzqJY00000YzqJY00000L;wH)0000000000000001ONa4000000000000000zW@LL0RR910ssI200000unPbH00000unPbH00000C;<Qf0000000000000002mk;8000000000000000$p8QV4gdfE0{{R300000Xbm6$00000Xbk`W000005C8xG0000000000000002mk;8000002mk;800000)c^nh4*&oF0{{R300000cnu%`00000cntsm000002mk;80000000000000002mk;8000002mk;800000;Q#;t1^@s60{{R300000fDIr300000fDHfu0000000IC2000001^@s6000002mk;8000005C8xG00000m;e9(0RR910{{R300000fDa%500000fDZrw00000fB*mh0000000000000002mk;8000002mk;800000>Hq)$0RR910{{R30000001zMm0000001yBG000005C8xG0000000000000002mk;8000000000000000@Bjb+2mk;80{{R300000KoB4R000005D)+W00000Kmq^&000000000000000KmY&$000000000000000^#A|>0RR91FaQ7m0000000000000005D)+W00000DF6Tf0000000000000000RR91000000RR91000000RR910ssI200000000000000000000Ko9@`00000@CE<?000008vp<REdT%j2mk;8000007ytkO000002><{90{{R300000000000000000000Fc$y-00000bOQhY0000000000000000RR910000000000000005dZ)H0{{R300000000000000000000q#6JK00000{r~^~0000000000000000RR91000000000000000"
open("./kyomu", 'wb').write(base64.b85decode(exe_bin))
subprocess.run(["chmod +x ./kyomu"], shell=True)
subprocess.run(["./kyomu"], shell=True)
| 0 | null | 28,196,420,841,312 | 199 | 81 |
X, Y = map(int, input().split())
ans = 0
if X <= 3:
ans += (4-X) * 100000
if Y <= 3:
ans += (4-Y) * 100000
if X == Y == 1:
ans += 400000
print(ans)
|
print(~-int(input())//2)
| 0 | null | 146,847,586,219,052 | 275 | 283 |
import math
a, b, h, m = [int(i) for i in input().split()]
theta = math.radians(h / 12 * 360 - m / 60 * 360 + m / 60 / 12 * 360)
print(math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(theta)))
|
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n,a,b = map(int, input().split())
if (b-a)%2==0:
ans = (b-a)//2
else:
m = b-1
M = n-a
m1 = (n-b) + 1 + (b-a-1)//2
m2 = (a-1) + 1 + (b-a-1)//2
ans = min(m,M, m1, m2)
print(ans)
| 0 | null | 64,956,185,073,806 | 144 | 253 |
import sys
def allocate(count, weights):
"""allocate all packages of weights onto trucks.
returns maximum load of trucks.
>>> allocate(2, [1, 2, 2, 6])
6
>>> allocate(3, [8, 1, 7, 3, 9])
10
"""
def loadable_counts(maxweight):
n = 0
l = 0
c = count
for w in weights:
l += w
if l > maxweight:
l = w
c -= 1
if c <= 0:
return n
n += 1
return n
i = max(weights)
j = max(weights) * len(weights) // count
while i < j:
mid = (i + j) // 2
if loadable_counts(mid) < len(weights):
i = mid + 1
else:
j = mid
return i
def run():
k, n = [int(i) for i in input().split()]
ws = []
for i in sys.stdin:
ws.append(int(i))
print(allocate(n, ws))
if __name__ == '__main__':
run()
|
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
x = 1
for i in range(N):
x = (x*A[i]) // gcd(x, A[i])
ans = 0
for a in A:
ans += x//a
#ans %= mod
print(ans%mod)
| 0 | null | 43,962,157,994,810 | 24 | 235 |
import statistics
import sys
data_sets = sys.stdin.read().split("\n")
for i in data_sets[1:-1:2]:
data_set = [int(j) for j in i.split()]
print(statistics.pstdev(data_set))
|
#!/usr/bin/python3
def find(id, V, d, dist):
i = id - 1
dist[i] = d
for v in V[i]:
if dist[v - 1] == -1 or dist[v - 1] > d + 1:
find(v, V, d + 1, dist)
n = int(input())
# [isFind, d, f]
A = [[False, 0, 0] for i in range(n)]
U = []
V = []
dist = [-1] * n
for i in range(n):
l = list(map(int, input().split()))
U.append(l[0])
V.append(l[2:])
find(1, V, 0, dist)
for u in U:
print(u, dist[u - 1])
| 0 | null | 94,157,320,532 | 31 | 9 |
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)
|
import copy
N, M = map(int, input().split())
res = [[] for i in range(N+5)]
for i in range(M) :
a,b = map(int, input().split())
a -= 1
b -= 1
res[a].append(b)
res[b].append(a)
pre = [-1] * N
dist = [-1] * N
d = 1
dl = []
pre[0] = 0
dist[0] = 0
dl.append(0)
while(len(dl) != 0) :
a = dl[0]
dl.pop(0)
for i in res[a] :
if(dist[i] != -1):
continue
dist[i] = dist[a] + 1
pre[i] = a
dl.append(i)
for i in range(N) :
if(i == 0) :
print("Yes")
continue
print(pre[i] + 1)
| 0 | null | 11,968,079,648,352 | 79 | 145 |
print((int(input())**2))
|
r = int(input())
ans = int(r ** 2)
print(ans)
| 1 | 145,587,781,813,236 | null | 278 | 278 |
N = int(input())
An = list(map(int, input().split()))
money = 1000
stock = 0
for i in range(N-1):
if An[i+1] > An[i]:
stock = money // An[i]
money += (An[i+1] - An[i]) * stock
print(money)
|
N = int(input())
X = list(map(int, input().split()))
cur = 1000
stock = 0
state = 0 # 1=increase, 0=decrease
for i in range(N - 1):
if state == 1 and X[i] > X[i + 1]:
cur += X[i] * stock
stock = 0
state = 0
elif state == 0 and X[i] < X[i + 1]:
n = cur // X[i]
cur -= X[i] * n
stock += n
state = 1
print(cur + stock * X[-1])
| 1 | 7,225,839,151,702 | null | 103 | 103 |
import sys
input = sys.stdin.readline
s = list(input())
a = 0
#print(len(s))
for i in range((len(s) - 1) // 2):
#print(s[i], s[-2-i])
if s[i] != s[-2-i]:
a += 1
print(a)
|
s = list(input())
s1 = s[:len(s)//2]
s2 = s[-(-len(s)//2):][::-1]
cnt = 0
while True:
if s1 == s2:
break
for i in range(len(s1)):
if s1[i] != s2[i]:
s1[i] = s2[i]
cnt += 1
print(cnt)
| 1 | 120,390,011,848,550 | null | 261 | 261 |
X, Y = map(int, input().split())
print(400000*(X==1)*(Y==1) + max(0, 400000-100000*X) + max(0, 400000-100000*Y))
|
X, Y = tuple(map(int, input().split()))
# Calculate prize for "Coding Contest"
prize_code = 0;
if X == 1:
prize_code = 300000;
elif X == 2:
prize_code = 200000;
elif X == 3:
prize_code = 100000;
# Calculate prize for "Robot Maneuver"
prize_device = 0;
if Y == 1:
prize_device = 300000;
elif Y == 2:
prize_device = 200000;
elif Y == 3:
prize_device = 100000;
# Calculate prize for "two victories"
prize_both = 0
if X == 1 and Y == 1:
prize_both = 400000
# Calculate the sum and print the answer
prize_total = prize_code + prize_device + prize_both
print(prize_total)
| 1 | 140,246,230,239,332 | null | 275 | 275 |
k = int(input())
s = input()
if len(s)>k:
print('{}...'.format(s[:k]))
else:
print(s)
|
A,B,K = map(int,input().split())
a = A-K
if a < 0:
A = 0
B = max(0, B+a)
print(max(0,a), B)
| 0 | null | 61,745,099,126,952 | 143 | 249 |
N=int(input())
S=input()
kouho=[]
for n in range(1000):
st=str(n)
if len(st)<=2:
st='0'*(3-len(st))+st
kouho.append(st)
ans=0
for k in kouho:
number=0
for s in S:
if k[number]==s:
number+=1
if number==3:
break
if number == 3:
ans += 1
print(ans)
|
a=int(input())
print(-(-a//2))
| 0 | null | 93,637,603,601,660 | 267 | 206 |
H, W = list(map(int, input().split()))
while H != 0 or W != 0 :
print('#' * W)
for i in range(H-2) :
print('#', end = '')
print('.' * (W - 2), end = '')
print('#')
print('#' * W)
print()
H, W = list(map(int, input().split()))
|
def draw(h,w):
s = "#" * w
k = "#" + "." * (w-2) + "#"
print s
for i in range(0,h-2):
print k
print s
print
if __name__ == "__main__":
while True:
h,w = map(int, raw_input().split())
if h==0 and w==0:
break
else:
draw(h,w)
| 1 | 814,420,657,568 | null | 50 | 50 |
N, K = map(int, input().split())
P = int(1e9+7)
cnt = [0]*(K+1)
ans = 0
for i in range(K, 0, -1):
c = pow(K//i, N, P) - sum(cnt[::i])
cnt[i] = c
ans = (ans+i*c)%P
print(ans%P)
|
X,K,D = map(int,input().split())
y = abs(X)//D
if K<=y:
print(abs(abs(X)-K*D))
else :
a = (abs(X)-y*D)
b = (abs(X)-(y+1)*D)
C = abs(a)
D = abs(b)
if (K-y)%2==0:
print(C)
else:
print(D)
#print(y+1)
#print(1000000000000000)
| 0 | null | 21,013,128,123,670 | 176 | 92 |
N = int(input())
if(N % 2 == 0):
print(0.5000000000)
else:
M = (N+1)/2
print(M/N)
|
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(read())
odd = 0
for n in range(N):
n += 1
if n%2==1:
odd += 1
print(odd/N)
| 1 | 176,950,627,920,740 | null | 297 | 297 |
K=int(input())
res=1
x=0
for i in range(K):
x+=7*res
x%=K
if x%K==0:
print(i+1)
break
res*=10
res%=K
else:
print(-1)
|
X,K,D = map(int,input().split())
X = abs(X)
if X >= K*D:
ans = X - K*D
else:
k = X // D
if (K - k) % 2 == 0:
ans = X - k*D
else:
ans = abs(X-(k+1)*D)
print(ans)
| 0 | null | 5,657,855,692,496 | 97 | 92 |
import math
n = int(input())
x = list(map(float, (input().split())))
y = list(map(float, (input().split())))
l = [0.0]*n
for i in range(n):
l[i] = abs(x[i]-y[i])
print(sum(l))
che = max(l)
for i in range(n):
l[i] = abs(x[i]-y[i])**2
print(math.sqrt(sum(l)))
for i in range(n):
l[i] = abs(x[i]-y[i])**3
print(math.pow(sum(l), 1.0/3.0))
print(che)
|
#
# 10d
#
import math
def main():
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
d1 = 0
d2 = 0
d3 = 0
dn = 0
for i in range(n):
d1 += abs(x[i] - y[i])
d2 += (x[i] - y[i])**2
d3 += abs(x[i] - y[i])**3
dn = max(dn, abs(x[i] - y[i]))
d2 = math.sqrt(d2)
d3 = math.pow(d3, 1/3)
print(f"{d1:.5f}")
print(f"{d2:.5f}")
print(f"{d3:.5f}")
print(f"{dn:.5f}")
if __name__ == '__main__':
main()
| 1 | 213,879,714,468 | null | 32 | 32 |
from collections import deque
N = int(input())
A = list(map(int, input().split()))
A = deque(A)
left = 0
right = 0
while len(A) > 1:
if (left <= right):
left += A.popleft()
else:
right += A.pop()
if left < right:
left += A.pop()
else:
right += A.pop()
print(max(left, right) - min(left, right))
|
import math
from math import gcd,pi,sqrt
INF = float("inf")
import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def main():
n, x, y = i_map()
ans = [0] * n
for fr in range(1, n+1):
for to in range(fr+1, n+1):
cost = min(to - fr, abs(x-fr) + abs(to - y) + 1)
ans[cost] += 1
print(*ans[1:], sep="\n")
if __name__=="__main__":
main()
| 0 | null | 93,207,239,629,920 | 276 | 187 |
X,Y=map(int,input().split())
mod = 10**9+7
if 2*X < Y or 2*Y < X:print(0)
elif (X+Y) % 3 != 0:print(0)
else:
n = (X+Y) // 3
X,Y=X-n,Y-n
factorial=[1 for i in range(X+Y+1)]
for i in range(1,X+Y+1):
if i==1:factorial[i]=1
else:factorial[i] = factorial[i-1]*i % mod
print(factorial[X+Y]*pow(factorial[X]*factorial[Y],-1,mod)%mod)
|
N, M, *HAB = map(int, open(0).read().split())
H, AB = [0] + HAB[:N], HAB[N:]
good = [False] + [True] * N
for a, b in zip(*[iter(AB)] * 2):
if H[a] >= H[b]:
good[b] = False
if H[b] >= H[a]:
good[a] = False
print(sum(good))
| 0 | null | 87,511,587,449,730 | 281 | 155 |
t = input()
n = len(t)
res = ''
for i in range(n):
if t[i] == '?':
res += 'D'
else:
res += t[i]
print(res)
|
def main():
T = input()
T = T.replace('?', 'D')
# cnt = 0
# cnt_pd = t.count('PD')
# cnt_d = t.count('D')
# cnt = cnt_d + cnt_pd
print(T)
main()
| 1 | 18,482,501,564,580 | null | 140 | 140 |
import math
a,b,C=map(float,input().split())
S = a*b*math.sin(C*math.pi/180)/2
c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(C*math.pi/180))
h = 2*S/a
print("{:10f}".format(S))
print("{:10f}".format(a+b+c))
print("{:10f}".format(h))
|
import math
a, b, c = [float(i) for i in input().split()]
print(a * b * math.sin(math.radians(c)) / 2)
print(a + b + math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(math.radians(c))))
print(b * math.sin(math.radians(c)))
| 1 | 180,440,466,180 | null | 30 | 30 |
sheep_str,wolf_str= input().split()
sheep = float(sheep_str)
wolf = float(wolf_str)
if sheep <= wolf:
print("unsafe")
else:
print("safe")
|
S,W=map(int,input().split())
if W>=S:
print('unsafe')
exit()
print('safe')
| 1 | 29,329,546,304,802 | null | 163 | 163 |
s = input()
if s[0]==s[1] and s[0]==s[2]:
print("No")
else:
print("Yes")
|
print(sum(i**4%15%2*i for i in range(int(input())+1)))
| 0 | null | 44,974,286,725,942 | 201 | 173 |
import math
N = int(input())
x = math.ceil(N/1000)
print(x*1000-N)
|
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from decimal import *
input = sys.stdin.readline
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]
inf = float('inf')
mod = 1000000007
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
def main():
D = inputInt()
C = inputList()
S = []
for i in range(D):
s = inputList()
S.append(s)
ans1 = []
ans2 = []
ans3 = []
ans4 = []
for i in range(D):
bestSco1 = 0
bestSco2 = 0
bestSco3 = 0
bestSco4 = 0
bestI1 = 1
bestI2 = 1
bestI3 = 1
bestI4 = 1
for j,val in enumerate(S[i]):
if j == 0:
tmpAns = ans1 + [j+1]
tmpSco = findScore(tmpAns, S, C)
if bestSco1 < tmpSco:
bestSco4 = bestSco3
bestI4 = bestI3
bestSco3 = bestSco2
bestI3 = bestI2
bestSco2 = bestSco1
bestI2 = bestI1
bestSco1 = tmpSco
bestI1 = j+1
else:
tmpAns1 = ans1 + [j+1]
tmpAns2 = ans2 + [j+1]
tmpAns3 = ans3 + [j+1]
tmpAns4 = ans4 + [j+1]
tmpSco1 = findScore(tmpAns1, S, C)
tmpSco2 = findScore(tmpAns2, S, C)
tmpSco3 = findScore(tmpAns3, S, C)
tmpSco4 = findScore(tmpAns4, S, C)
if bestSco1 < tmpSco1:
bestSco1 = tmpSco1
bestI1 = j+1
if bestSco2 < tmpSco2:
bestSco2 = tmpSco2
bestI2 = j+1
if bestSco3 < tmpSco3:
bestSco3 = tmpSco3
bestI3 = j+1
if bestSco4 < tmpSco4:
bestSco4 = tmpSco4
bestI4 = j+1
ans1.append(bestI1)
ans2.append(bestI2)
ans3.append(bestI3)
ans4.append(bestI4)
aa = []
aa.append(bestSco1)
aa.append(bestSco2)
aa.append(bestSco3)
aa.append(bestSco4)
aa.sort()
aa = aa[::-1]
if aa[0] == bestSco1:
for i in ans1:
print(i)
elif aa[0] == bestSco2:
for i in ans2:
print(i)
elif aa[0] == bestSco3:
for i in ans3:
print(i)
elif aa[0] == bestSco4:
for i in ans4:
print(i)
def findScore(ans, S, C):
scezhu = [inf for i in range(26)]
sco = 0
for i,val in enumerate(ans):
tmp = S[i][val-1]
scezhu[val-1] = i
mins = 0
for j,vol in enumerate(C):
if scezhu[j] == inf:
mins = mins + (vol * (i+1))
else:
mins = mins + (vol * ((i+1)-(scezhu[j]+1)))
tmp -= mins
sco += tmp
return sco
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
main()
| 0 | null | 9,121,266,377,900 | 108 | 113 |
#!/usr/bin/env python
n, k = map(int, input().split())
a = list(map(int ,input().split()))
def check(x):
now = 0
for i in range(n):
now += (a[i]-1)//x
return now <= k
l = 0
r = int(1e9)
while r-l > 1:
mid = (l+r)//2
if check(mid):
r = mid
else:
l = mid
print(r)
|
import math
def resolve():
N, K = map(int, input().split())
A = list(map(int, input().split()))
def _f(length: int) -> bool:
count = 0
for a in A:
count += int((a-1) / length)
return count <= K
l = 0
r = 10**9
while (r-l) > 1:
mid = (l+r) // 2
if _f(mid):
r = mid
else:
l = mid
print(r)
if __name__ == "__main__":
resolve()
| 1 | 6,529,905,008,430 | null | 99 | 99 |
n = int(input())
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))
ds = [abs(x - y) for x, y in zip(xs, ys)]
for i in range(1, 4):
ans = 0
for d in ds:
ans += d**i
print(ans**(1/i))
print(max(ds))
|
import math
n = int(input())
a = [float(x) for x in list(input().split())]
b = [float(x) for x in list(input().split())]
result = 0
for aa, bb in zip(a, b):
result += abs(aa - bb)
print(round(result, 6))
result = 0
for aa, bb in zip(a, b):
result += abs(aa - bb) ** 2
print(round(math.sqrt(result), 8))
result = 0
for aa, bb in zip(a, b):
result += abs(aa - bb) ** 3
print(round(math.pow(result, 1/3), 8))
result = []
for aa, bb in zip(a, b):
result.append(abs(aa - bb))
print(max(result))
| 1 | 215,917,550,210 | null | 32 | 32 |
s = input()
print('ARC' if s[1]=='B' else 'ABC')
|
X, Y, Z = map(int, input().split())
ans = [Z, X, Y]
print(*ans)
| 0 | null | 31,059,313,923,500 | 153 | 178 |
def make_divisors(n):
divisors = []
for i in range(1, int(n ** 0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
return divisors
def main():
n = int(input())
# 1回も割り算しない場合は n mod k = 1でkは(n-1)の約数
ans = len(make_divisors(n - 1)) - 1
# 割り算をする場合
l = make_divisors(n)[1:]
for i in l:
num = n
while num % i == 0:
num //= i
if num % i == 1:
ans += 1
print(ans)
if __name__ == '__main__':
main()
|
import math
n=int(input())
a=360/n
b=a-360//n
print(int(n*360/math.gcd(n,360)/n))
| 0 | null | 27,174,224,760,452 | 183 | 125 |
n, m = map(int, input().split())
if n == m:
print('Yes')
elif n > m:
print('No')
|
n,a,b = map(int,input().split())
answer = 0
answer = a*(n//(a+b))
n = n%(a+b)
answer += min(a,n)
print(answer)
| 0 | null | 69,271,705,952,930 | 231 | 202 |
a, b = map(int, input().split())
print(a * b, (a + b) << 1)
|
a,b = map(int, input().split())
print("%d %d %0.10f" %(a//b, a%b, a/b) )
| 0 | null | 445,682,030,300 | 36 | 45 |
S = input()
day = ['SUN','MON','TUE','WED','THU','FRI','SAT']
for i in range(len(day)):
if S == day[i]:
print(7-i)
break
|
D=['MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN']
S=input()
ans=6-D.index(S)
if ans == 0:
ans=7
print(ans)
| 1 | 133,170,530,672,070 | null | 270 | 270 |
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint,time,random
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def cal(T):
res = 0
last = [0] * 26
for day in range(D):
t = T[day]; t -= 1
last[t] = 0
res += s[day][t]
for i in range(26):
if i == t: continue
last[i] += 1
res -= c[i] * last[i]
return res
def check_change(td,tq):
global score,res
old_q = res[td]
res[td] = tq
now = cal(res)
if now > score:
score = now
else:
res[td] = old_q
def out():
global res
for x in res:
print(x)
quit()
start_time = time.time()
n = 26
D = inp()
c = inpl()
s = []
max_s = []
for i in range(D):
tmp = inpl()
mx = 0; ind = -1
for j in range(n):
if tmp[j] > mx:
mx = tmp[j]
ind = j
max_s.append(ind+1)
s.append(tmp)
last = [0] * n
res = [-1] * D
for d in range(D):
ans = -1
mx = -INF
for i in range(n):
now = s[d][i]
for j in range(n):
if i == j: continue
now -= s[d][j] * (last[j]+1)
if now > mx:
mx = now
ans = i
res[d] = ans+1
for j in range(n):
last[j] += 1
if j == ans: last[j] = 0
score = cal(res)
# print(now_score)
while True:
if time.time() - start_time > 1.3: break
td,tq = random.randrange(0,D), random.randrange(1,n+1)
check_change(td,tq)
for x in itertools.combinations(range(D), 2):
if time.time() - start_time > 1.83: out()
old = []
if sum(x^y for x,y in zip(res,max_s)) == 0: continue
for i in range(2):
old.append(res[x[i]])
res[x[i]] = max_s[x[i]]
now = cal(res)
if now > score:
score = now
else:
for i in range(2):
res[x[i]] = old[i]
|
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
from numba import njit
def getInputs():
D = int(readline())
CS = np.array(read().split(), np.int32)
C = CS[:26]
S = CS[26:].reshape((-1, 26))
return D, C, S
@njit('(i8, i4[:], i4[:, :], i4[:], )', cache=True)
def _compute_score1(D, C, S, out):
score = 0
last = np.zeros(26, np.int32)
for d in range(len(out)):
i = out[d]
score += S[d, i]
last[i] = d + 1
score -= np.sum(C * (d + 1 - last))
return last, score
def _update_score():
pass
@njit('(i8, i4[:], i4[:, :], i4[:], i8, )', cache=True)
def _random_update(D, C, S, out, score):
d = np.random.randint(0, D)
q = np.random.randint(0, 26)
p = out[d]
if p == q:
return out, score
out[d] = q
_, new_score = _compute_score1(D, C, S, out)
if score < new_score:
score = new_score
else:
out[d] = p
return out, score
@njit('(i8, i4[:], i4[:, :], i4[:], i8, i8, )', cache=True)
def _random_swap(D, C, S, out, score, delta):
d1 = np.random.randint(0, D)
d2 = np.random.randint(max(0, d1 - delta), min(D, d1 + delta))
#p, q = out[[d1, d2]]
p = out[d1]
q = out[d2]
if d1 == d2 or p == q:
return out, score
#out[[d1, d2]] = (q, p)
out[d1] = q
out[d2] = p
_, new_score = _compute_score1(D, C, S, out)
if score < new_score:
score = new_score
else:
#out[[d1, d2]] = (p, q)
out[d1] = p
out[d2] = q
return out, score
def step1(D, C, S):
out = []
LAST = 0
for d in range(D):
max_score = -10000000
best_i = 0
for i in range(26):
out.append(i)
last, score = _compute_score1(D, C, S, np.array(out, np.int32))
if max_score < score:
max_score = score
LAST = last
best_i = i
out.pop()
out.append(best_i)
return np.array(out), LAST, max_score
def step2(D, C, S, out, score):
for _ in range(48 * 10 ** 3):
flag = np.random.rand() >= 0.5
out = out.astype(np.int32)
if flag:
out, score = _random_update(D, C, S, out, score)
else:
out, score = _random_swap(D, C, S, out, score, 13)
return out, score
def output(out):
out += 1
print('\n'.join(out.astype(str).tolist()))
D, C, S = getInputs()
out, _, score = step1(D, C, S)
#print(score)
out, score = step2(D, C, S, out, score)
output(out)
#print(score)
| 1 | 9,650,193,654,080 | null | 113 | 113 |
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]
def f():
if m == 0:
if n == 1:
return 0
elif n == 2:
return 10
elif n == 3:
return 100
else:
for i in range(1000):
x = str(i)
if len(x) == n:
cnt = 0
for j in range(m):
if x[sc[j][0] - 1] == str(sc[j][1]):
cnt += 1
if cnt == m:
return x
elif x[sc[j][0] - 1] != str(sc[j][1]):
break
return -1
print(f())
|
#! /usr/bin/env python
# -*- coding: utf-8 -*-
h, w = map(int, raw_input().split())
print h * w, (h + w) * 2
| 0 | null | 30,694,409,784,100 | 208 | 36 |
print(int((int(input())+1)/2))
|
h, w, k = map(int, input().split())
board = [[-1 for j in range(w)] for i in range(h)]
for i in range(h):
color = input()
for j in range(w):
if color[j] == "#":
board[i][j] = 1 #黒=1
else:
board[i][j] = 0 #白=0
ans = 0
for row_choose in range(1<<h):
for col_choose in range(1<<w):
count = 0
for i in range(h):
for j in range(w):
if not (row_choose & (1<<i)) and not (col_choose & (1<<j)) and board[i][j]:
count += 1
if count == k:
ans += 1
print(ans)
| 0 | null | 34,164,772,060,958 | 206 | 110 |
A=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
n=int(input())
s=str(input())
t=""
for i in range(len(s)):
for j in range(26):
if s[i]==A[j]:
if j+n<=25:
t+=A[j+n]
break
else:
t+=A[j+n-26]
break
print(t)
|
n = int(input())
s = list(input())
a = []
for i in s:
num = ord(i)+n
if num > 90:
num -= 26
a.append(chr(num))
print(''.join(a))
| 1 | 134,277,998,063,758 | null | 271 | 271 |
s=list(input())
t=list(input())
n=len(s)
m=len(t)
if m==n+1:
for i in range(n):
if s[i]==t[i]:
continue
if s[i]!=t[i]:
print('No')
exit()
print('Yes')
else:
print('No')
|
S = input()
T = input()
T = T[0:-1]
if S != T:
print("No")
else:
print("Yes")
| 1 | 21,450,613,924,860 | null | 147 | 147 |
H, W, K = map(int, input().split(' '))
ls, rst = [], 0
for i in range(H):
ls.append(input())
for i in range(1 << H):
for j in range(1 << W):
cnt = 0
for s in range(H):
if i >> s & 1:
continue
for t in range(W):
if j >> t & 1:
continue
if ls[s][t] == '#':
cnt += 1
if cnt == K:
rst += 1
print(rst)
|
def resolve():
n, m = map(int, input().split())
h = list(map(int, input().split()))
ans = {i for i in range(n)}
for i in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
if h[a] <= h[b]:
ans.discard(a)
if h[b] <= h[a]:
ans.discard(b)
print(len(ans))
return
if __name__ == "__main__":
resolve()
| 0 | null | 16,949,021,202,360 | 110 | 155 |
# -*- coding: utf-8 -*-
import sys
def main():
N = int( sys.stdin.readline() )
A_list = list(map(int, sys.stdin.readline().split()))
A_list.sort(reverse=True)
arrived_idx = 1
comfort = A_list[0]
for i in range(1, len(A_list)):
if ( len(A_list) - 1 - arrived_idx ) >= 2:
comfort += (A_list[i] * 2)
arrived_idx += 2
elif ( len(A_list) - 1 - arrived_idx ) == 1:
comfort += A_list[i]
break
else: # ( len(A_list) - 1 - arrived_idx ) == 0:
break
print(comfort)
if __name__ == "__main__":
main()
|
N = int(input())
A = 2*list(map(int, input().split()))
A.sort()
print(sum(A[N:-1]))
| 1 | 9,180,090,104,132 | null | 111 | 111 |
n, m, x = map(int,input().split())
CA = [list(map(int, input().split())) for i in range(n)]
ch = [0]*m
res = 10**5*12 + 5
for i in range(2**n):
money = 0
ch = [0]*m
for j in range(n):
if ((i >> j) & 1):
money += CA[j][0]
for k in range(m):
ch[k] += CA[j][k+1]
if min(ch) >= x:
res= min(money,res)
if res == 10**5*12 + 5:
print(-1)
else:
print(res)
|
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(input())
n,m,x = readInts()
C = [readInts() for _ in range(n)]
INF = float('inf')
ans = INF
for bit in range(1 << n):
all = [0] * m
money = 0
for i in range(n):
if bit & (1 << i):
money += C[i][0]
for j in range(m):
all[j] += C[i][j+1]
flag = True
for k in range(m):
if all[k] >= x:
pass
else:
flag = False
break
if flag:
ans = min(ans, money)
print(ans if ans != INF else '-1')
| 1 | 22,316,953,104,980 | null | 149 | 149 |
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
return list(map(int,readline().split()))
def readTuples():
return tuple(map(int,readline().split()))
def I():
return int(readline())
n = I()
s = input()
C = Counter(s)
w,r = 0,0
for k,v in C.items():
if k == 'W':
w += v
else:
r += v
p = 'R' * r + 'W' * w
ans = 0
for i in range(n):
if p[i] == s[i]:
pass
else:
ans += 1
print(ans//2)
|
N = int(input())
c = input()
red = 0
for i in c:
if i=="R":
red += 1
br = 0
ans = 10**12 if red else 0
for i in range(red):
if c[i]=="R":
br += 1
white = i+1 - br
disappear = red - br - white
ans = min(ans, white+disappear)
print(ans)
| 1 | 6,321,336,375,592 | null | 98 | 98 |
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
n, a, b = na()
if a == 0:
print(0)
else:
print((n//(a+b))*a + min(n%(a+b), a))
|
N,A,B=map(int,input().split())
if A==0:
print("0")
elif B==0:
print(N)
elif N%(A+B)>A:
print(A*int(N/(A+B))+A)
else:
print(A*int(N/(A+B))+N%(A+B))
| 1 | 56,022,747,922,240 | null | 202 | 202 |
import numpy as np
a = int(input())
print(int( np.ceil((2000-a)/200)))
|
X = int(input())
up = 599
down = 400
i=8
while(i>=1):
if(X <= up and X >= down):
print(i)
break
else:
up += 200
down += 200
i -= 1
| 1 | 6,710,354,104,958 | null | 100 | 100 |
N = int(input())
A = map(int, input().split())
sortA = sorted(A)
result = 0
for i in range(1, N):
result += sortA[N - (i // 2) - 1]
print(result)
|
import sys
read = sys.stdin.readline
import time
import math
import itertools as it
def inp():
return int(input())
def inpl():
return list(map(int, input().split()))
start_time = time.perf_counter()
# ------------------------------
n, a, b = inpl()
l = n // (a + b)
m = n % (a + b)
print(a * l + min(m, a))
# -----------------------------
end_time = time.perf_counter()
print('time:', end_time-start_time, file=sys.stderr)
| 0 | null | 32,542,814,858,510 | 111 | 202 |
import math
a = int(input())
for i in range(50001):
if math.floor(i*1.08) == a:
print(i)
exit()
print(":(")
|
# coding: utf-8
def areas_calc(strings):
stack1 = []
stack2 = []
total_m = 0
for i, s in enumerate(strings):
if s == "\\":
stack1.append(i)
elif s == "_":
continue
elif s == '/':
if len(stack1) > 0:
previous_i = stack1.pop()
m = i - previous_i
total_m += m
while len(stack2) > 0:
stacked_i, stacked_m = stack2.pop()
if previous_i < stacked_i:
m += stacked_m
else:
stack2.append((stacked_i, stacked_m))
stack2.append((previous_i, m))
break
else:
stack2.append((previous_i, m))
print(total_m)
k = len(stack2)
for_output = [str(k)] + [str(m) for i, m in stack2]
print(' '.join(for_output))
if __name__ == "__main__":
areas_calc(input())
| 0 | null | 62,593,725,532,448 | 265 | 21 |
#coding:utf-8
nyu =""
moji =[]
s1 =[]
s2 =[]
n= 0
a= 0
while nyu != "-":
nyu = input().rstrip()
if nyu =="-":
# print("".join(moji))
break
n = int(input().rstrip())
moji = list(nyu)
for i in range(n):
a = input().rstrip()
s1 =moji[:int(a)]
s2 =moji[int(a):]
moji= list("".join(s2) + "".join(s1))
# print(moji)
print("".join(moji))
|
A, B, K= list(map(int, input().split()))
if A>= K:
print(A-K, end=" ")
print(B)
else:
print(0, end=" ")
print(max(B-(K-A),0))
| 0 | null | 53,320,907,136,680 | 66 | 249 |
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect
MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 8)
n = int(input())
dis = [-1] * n
info = [list(map(int, input().split())) for _ in range(n)]
stack = [[0, 0]]
ans = 0
while len(stack) > 0:
num = stack.pop(0)
if dis[num[0]] == -1:
dis[num[0]] = num[1]
for i in info[num[0]][2:]:
if dis[i-1] == -1:
stack.append([i - 1, num[1] + 1])
for i in range(n):
print(str(i+1) + " " + str(dis[i]))
|
def resolve():
N, M, Q = list(map(int, input().split()))
Q = [list(map(int, input().split())) for _ in range(Q)]
import itertools
maxpoint = 0
for seq in itertools.combinations_with_replacement(range(1, M+1), N):
point = 0
for a, b, c, d in Q:
if seq[b-1] - seq[a-1] == c:
point += d
maxpoint = max(maxpoint, point)
print(maxpoint)
if '__main__' == __name__:
resolve()
| 0 | null | 13,726,235,380,598 | 9 | 160 |
import math as m
def plot(x,y):
print(f'{x:.8f} {y:.8f}')
def koch(n,x1,y1,x2,y2):
if n==0:
plot(x1,y1)
return
sx=(2*x1+x2)/3
sy=(2*y1+y2)/3
tx=(x1+2*x2)/3
ty=(y1+2*y2)/3
ux=(tx-sx)*m.cos(m.radians(60))-(ty-sy)*m.sin(m.radians(60))+sx
uy=(tx-sx)*m.sin(m.radians(60))+(ty-sy)*m.cos(m.radians(60))+sy
koch(n-1,x1,y1,sx,sy)
koch(n-1,sx,sy,ux,uy)
koch(n-1,ux,uy,tx,ty)
koch(n-1,tx,ty,x2,y2)
n=int(input())
koch(n,0,0,100,0)
plot(100,0)
|
n, m, k = map(int, input().split(" "))
a = [0]+list(map(int, input().split(" ")))
b = [0]+list(map(int, input().split(" ")))
for i in range(1, n+1):
a[i] += a[i - 1]
for i in range(1, m+1):
b[i] += b[i - 1]
j,mx= m,0
for i in range(n+1):
if a[i]>k:
break
while(b[j]>k-a[i]):
j-=1
if (i+j>mx):
mx=i+j
print(mx)
| 0 | null | 5,461,125,424,418 | 27 | 117 |
#!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
def main():
K = I()
ans = 0
for i in range(1, K+1):
for j in range(1, K+1):
for k in range(1, K+1):
ans += math.gcd(math.gcd(i, j), k)
print(ans)
main()
|
print input()^1
| 0 | null | 19,185,279,048,858 | 174 | 76 |
n,m=map(int,input().split())
lange=[1]*(n+1)
for i in range(1,n+1):
a=i
b=n-a
if lange[a]:lange[b]=0
langes=[]
for i in range(1,n):
if lange[i]:
if len(langes)%2:langes.append(i)
else:langes.append(n-i)
langes.sort(reverse=1)
for i in range(m):print(i+1,i+1+langes[i])
|
N = int(input())
dct = {}
A = list(map(int, input().split()))
for a in A:
if a in dct.keys():
dct[a] += 1
else:
dct[a] = 1
for n in range(1, N+1):
print(dct.get(n, 0))
| 0 | null | 30,764,345,612,592 | 162 | 169 |
import math
N = int(input())
Xlist = list(map(int,input().split()))
min =10**5
meandown = math.floor(sum(Xlist)/N)
meanup = math.ceil(sum(Xlist)/N)
sumdown=0
sumup = 0
for i in range(len(Xlist)):
sumdown+= (Xlist[i]-meandown)**2
sumup+= (Xlist[i]-meanup)**2
if sumdown<sumup:
print(sumdown)
else:
print (sumup)
|
from itertools import accumulate
def max_from_acc(A, b):
r = -10**9-1
acc = [0] + list(accumulate(A + A[:b]))
for i in range(len(A)):
for j in range(1, b+1):
r = max(r, acc[i+j]-acc[i])
return r
n, k = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
P = [p - 1 for p in P]
checked = [False] * n
loops = []
for i in range(n):
if checked[i]:
continue
checked[i] = True
tmp = [i]
next = P[i]
while next != i:
tmp.append(next)
checked[next] = True
next = P[next]
loops.append(tmp)
# print(loops)
ans = -10**9-1
for loop in loops:
t =len(loop)
div, mod = divmod(k, t)
if mod == 0:
mod = t
div -= 1
C_loop = [C[p] for p in loop]
loop_score = sum(C_loop)
if t >=k:
ans = max(ans, max_from_acc(C_loop, k))
else:
if loop_score > 0:
ans = max(ans, max_from_acc(C_loop, mod)+loop_score*div)
else:
ans = max(ans, max_from_acc(C_loop, t))
print(ans)
| 0 | null | 35,159,715,730,814 | 213 | 93 |
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
idx_B = M-1
m = sum(B)
an = M
ans = 0
for a in [0] + A:
m += a
while idx_B >= 0 and m > K:
m -= B[idx_B]
idx_B -= 1
an -= 1
if m > K:
break
if an > ans:
ans = an
an += 1
print(ans)
|
import numpy as np
from numba import njit
@njit("i8[:](i8, i8[:], i8[:])", cache=True)
def cumsum(K, A, cA):
for i, a in enumerate(A):
cA[i] += cA[i - 1] + A[i]
if cA[i] > K:
break
cA = cA[cA != 0]
cA = np.append(0, cA)
return cA
@njit("i8(i8, i8[:], i8[:])", cache=True)
def solve(K, cA, cB):
ans = np.searchsorted(cA, K - cB, side="right") - 1
ans += np.arange(len(cB))
return ans.max()
N, M, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)
B = np.array(input().split(), dtype=np.int64)
cA = np.zeros(N, dtype=np.int64)
cB = np.zeros(M, dtype=np.int64)
# np.cumsumだとoverflowする
cA = cumsum(K, A, cA)
cB = cumsum(K, B, cB)
ans = solve(K, cA, cB)
print(ans)
| 1 | 10,786,899,163,898 | null | 117 | 117 |
from math import gcd, sqrt
from functools import reduce
n, *A = map(int, open(0).read().split())
def f(A):
sup = max(A)+1
table = [i for i in range(sup)]
for i in range(2, int(sqrt(sup))+1):
if table[i] == i:
for j in range(i**2, sup, i):
table[j] = i
D = set()
for a in A:
while a != 1:
if a not in D:
D.add(a)
a //= table[a]
else:
return False
return True
if reduce(gcd, A) == 1:
if f(A):
print('pairwise coprime')
else:
print('setwise coprime')
else:
print('not coprime')
|
from math import *
K=int(input())
ans=0
for a in range(1,K+1):
for b in range(1,K+1):
for c in range(1,K+1):
ans+=gcd(gcd(a,b),c)
print(ans)
| 0 | null | 19,845,395,464,228 | 85 | 174 |
letters = {
"a": 0,
"b": 0,
"c": 0,
"d": 0,
"e": 0,
"f": 0,
"g": 0,
"h": 0,
"i": 0,
"j": 0,
"k": 0,
"l": 0,
"m": 0,
"n": 0,
"o": 0,
"p": 0,
"q": 0,
"r": 0,
"s": 0,
"t": 0,
"u": 0,
"v": 0,
"w": 0,
"x": 0,
"y": 0,
"z": 0,
}
while True:
try:
l = list(input())
if len(l) == 0:
break
for c in l:
cl = c.lower()
if cl in letters:
letters[cl] += 1
except EOFError:
break
ks = list(letters.keys())
vs = list(letters.values())
for i in range(len(ks)):
print("%s : %s" % (ks[i], vs[i]))
|
alphabets = "abcdefghijklmnopqrstuvwxyz"
#print(len(alphabets))
#a = len(alphabets)
#print(a)
x = ''
while True:
try:
x += input().lower()
except EOFError:
break
for i in range(len(alphabets)):
print("{0} : {1}".format(alphabets[i], int(x.count(alphabets[i]))))
| 1 | 1,662,655,245,170 | null | 63 | 63 |
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 = [10**9]*(h+1)
dp[0] = 0
for i in range(h):
for j in range(n):
dp[min(i+a[j],h)] = min(dp[min(i+a[j],h)],dp[i]+b[j])
print(dp[h])
|
H, N = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
dp = [10 ** 18] * (H + 1)
dp[0] = 0
for i in range(H + 1):
for A, B in AB:
if i + A >= H:
dp[H] = min(dp[H], dp[i] + B)
else:
dp[i + A] = min(dp[i + A], dp[i] + B)
res = dp[H]
print(res)
| 1 | 80,866,187,725,510 | null | 229 | 229 |
N = int(input())
n = 0
for i in range(1,N+1):
if i % 3 == 0 and i % 5 == 0:
continue
elif i % 3 == 0:
continue
elif i % 5 == 0:
continue
else:
n += i
print(n)
|
N = int(input())
result = 0
for i in range(1, (N + 1)):
if i % 15 == 0:
'Fizz Buzz'
elif i % 3 == 0:
'Fizz'
elif i % 5 == 0:
'Buzz'
else:
result = result + i
print(result)
| 1 | 34,776,174,661,550 | null | 173 | 173 |
N, K, *A = map(int, open(0).read().split())
for a, b in zip(A[K:], A):
if a > b:
print("Yes")
else:
print("No")
|
# coding: utf-8
import sys
from math import log
def change_into_int(lists):
tmps = lists.split(' ')
num_list = []
for n in tmps:
num_list.append(int(n))
return num_list
if __name__ == "__main__":
lines = []
result_list = []
# 入力
for l in sys.stdin:
lines.append(l.rstrip('\r\n'))
# int
num1 = change_into_int(lines[0])
data = change_into_int(lines[1])
i = 0
while(True):
ans = data[i] - data[i+num1[1]]
if ans < 0:
print("Yes")
else:
print("No")
i = i + 1
if i+num1[1] == len(data):
break
| 1 | 7,133,824,657,542 | null | 102 | 102 |
import sys
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
n, a, b = MI()
d = b - a
ans = 0
if d%2:
temp = min(a-1, n-b)
ans = (d-1)//2 + temp + 1
else:
ans = d//2
print(ans)
if __name__ == '__main__':
main()
|
N = int(input())
A = map(int,input().split())
ans = 1
for x in A:
ans *= x
if ans > 10**18:
ans = 10**18+1
print(-1 if ans > 10**18 else ans)
| 0 | null | 62,704,089,775,718 | 253 | 134 |
import numpy as np
D = int(input())
c = np.array(list( map(int,input().split())))
S = np.zeros((D,26))
for i in range(D):
S[i] = np.array(list( map(int,input().split())))
T = np.array([])
for i in range(D):
T = np.append(T,int(input()))
"""
D = 365
c = np.random.randint(0,100,size=(26))
S = np.random.randint(0,20000,size=(D,26))
"""
def calc_score(T,D,c,S):
last = np.ones(26) * (-1)
scores = []
score = 0
for d in range(D):
i = int(T[d])-1
score += S[d,i]
last[i] = d
score -= np.sum(c*(d-last))
scores.append(score)
score = max([10**6+score,0])
return score,scores
_,ans = calc_score(T,D,c,S)
for a in ans:
print(int(a))
|
D = int(input())
c = list(map(int, input().split()))
#増加する満足度表 [日数][種類]
s = []
for i in range(D):
l = list(map(int, input().split()))
s.append(l)
#開催するコンテストタイプ[日数]
t = [int(input()) for j in range(D)]
last = [0]*26 #最後に開催した日
SP = 0
dis = 0
for k in range(D): #満足度の計算
SP += s[k][t[k]-1]
last[t[k]-1] = k + 1 #開催日の更新
for m in range(26):
SP -= c[m] * (k + 1 - last[m])
print(SP)
| 1 | 9,959,254,622,366 | null | 114 | 114 |
import copy
N = int(input())
bscs = [(int(c[-1]), c) for c in input().split(" ")]
sscs = copy.copy(bscs)
for i in range(N):
j = N - 1
while j > i:
if bscs[j][0] < bscs[j - 1][0]:
tmp = bscs[j]
bscs[j] = bscs[j - 1]
bscs[j - 1] = tmp
j -= 1
print(" ".join([c[1] for c in bscs]))
print("Stable")
for i in range(N):
minj = i
for j in range(i, N):
if sscs[j][0] < sscs[minj][0]:
minj = j
tmp = sscs[i]
sscs[i] = sscs[minj]
sscs[minj] = tmp
print(" ".join([c[1] for c in sscs]))
print("Stable" if bscs == sscs else "Not stable")
|
def bubbleSort(A):
N = len(A)
for i in range(N):
for j in range(N - 1, i, -1):
if A[j][1] < A[j - 1][1]:
A[j], A[j - 1] = A[j - 1], A[j]
return A
def selectionSort(A):
N = len(A)
for i in range(N):
min_i = i
for j in range(i, N):
if A[j][1] < A[min_i][1]:
min_i = j
if min_i != i:
A[i], A[min_i] = A[min_i], A[i]
return A
def is_stable(A, B):
for i in range(len(B) - 1):
if B[i][1] == B[i + 1][1]:
if A.index(B[i]) > A.index(B[i + 1]):
return False
return True
N = int(input())
A = list(input().split())
B = bubbleSort(A[:])
print(*B)
if is_stable(A, B):
print('Stable')
else:
print('Not stable')
S = selectionSort(A[:])
print(*S)
if is_stable(A, S):
print('Stable')
else:
print('Not stable')
| 1 | 24,211,246,528 | null | 16 | 16 |
S = input()
mod = 2019
array = []
for i in range(len(S)):
x = (int(S[len(S)-1-i])*pow(10,i,mod))%mod
array.append(x)
array2 = [0]
y = 0
for i in range(len(S)):
y = (y+array[i])%mod
array2.append(y)
array3 = [0] * 2019
ans = 0
for i in range(len(array2)):
z = array2[i]
ans += array3[z]
array3[z] += 1
print(ans)
#3*673
|
from collections import Counter
S = input()
S = S + '0'
mod = 2019
p = [-1] * len(S)
r = 0
d = 1
for i,s in enumerate(S[::-1]):
t = int(s)%mod
r += t*d
r %= mod
d = d*10%mod
p[i] = r
ans = 0
c = Counter(p)
for k,n in c.most_common():
if n > 1:
ans += n*(n-1)//2
else:break
print(ans)
| 1 | 30,787,475,176,440 | null | 166 | 166 |
N, K = map(int, input().split())
d = [0]*K
A = []
for i in range(K):
d[i] = int(input())
A.append(list(map(int, input().split())))
ans = 0
for i in range(1,N+1):
got = False
for j in A:
for k in j:
if i == k:
got = True
if not got:
ans += 1
print(ans)
|
n, k = map(int,input().split())
have = [False] * n
for _ in range(k):
d = input()
a = list(map(lambda x: int(x)-1, input().split()))
for x in a:
have[x] = True
print(have.count(False))
| 1 | 24,560,439,258,598 | null | 154 | 154 |
N,K=input().split()
N=int(N)
K=int(K)
p = [int(i) for i in input().split()]
p.sort()
print(sum(p[0:K]))
|
NK = input()
num = NK.split()
N = num[0]
K = num[1]
P = input()
Pn = P.split()
#print(Pn)
Pn_a = [int(i) for i in Pn]
Pn_b = sorted(Pn_a)
price = 0
for i in range(int(K)):
price += int(Pn_b[i])
print(price)
| 1 | 11,638,748,981,630 | null | 120 | 120 |
from collections import Counter
n, m = map(int, input().split())
group = [None for _ in range(n)]
connected = [[] for i in range(n)]
for i in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
connected[a].append(b)
connected[b].append(a)
# print(connected)
for i in range(n):
if group[i] is not None: continue
newly_visited = [i]
group[i] = i
while len(newly_visited) > 0:
new = newly_visited.pop()
for j in connected[new]:
if group[j] is not None: continue
group[j] = i
newly_visited.append(j)
# print(Counter(group))
print(len(Counter(group)) - 1)
|
a,b,n = map(int,input().split())
if n < b:
print(a*n//b)
else:
print(a*(b-1)//b)
| 0 | null | 15,171,072,861,630 | 70 | 161 |
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
x = I()
ans = 0
wa = 0
cont = True
while cont:
wa += x
ans += 1
if wa % 360 == 0:
cont = False
print(ans)
|
N=int(input())
L=list(map(int,input().split()))
A=1
if 0 in L:
print(0)
exit()
for i in range(N):
A=A*L[i]
if 10**18<A:
print(-1)
exit()
if 10**18<A:
print(-1)
else:
print(A)
| 0 | null | 14,519,012,835,680 | 125 | 134 |
import sys
from math import gcd
from collections import Counter
read = sys.stdin.read
readline = sys.stdin.readline
N, *AB = map(int, read().split())
mod = 10 ** 9 + 7
ab = []
zero = 0
for A, B in zip(*[iter(AB)] * 2):
if A == 0 and B == 0:
zero += 1
continue
if A == 0:
B = -1
elif B == 0:
A = 1
else:
g = gcd(A, B)
A //= g
B //= g
if A < 0:
A, B = -A, -B
ab.append((A, B))
cnt = Counter(ab)
answer = 1
checked = set()
ok = 0
for (i, j), n in cnt.items():
if (i, j) in checked:
continue
if j < 0:
c, d = -j, i
else:
c, d = j, -i
if (c, d) in cnt:
m = cnt[(c, d)]
answer = (answer * (pow(2, n, mod) + pow(2, m, mod) - 1)) % mod
checked.add((c, d))
else:
ok += n
answer *= pow(2, ok, mod)
answer -= 1
answer += zero
answer %= mod
print(answer)
|
import sys
from math import gcd
from collections import defaultdict
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
N = I()
mod = 10**9+7
plus = defaultdict(int)
minus = defaultdict(int)
flag = defaultdict(int)
A_zero,B_zero = 0,0
zero_zero = 0
for i in range(N):
a,b = MI()
if a == b == 0:
zero_zero += 1
elif a == 0:
A_zero += 1
elif b == 0:
B_zero += 1
else:
if a < 0:
a,b = -a,-b
a,b = a//gcd(a,b),b//gcd(a,b)
if b > 0:
plus[(a,b)] += 1
else:
minus[(a,b)] += 1
flag[(a,b)] = 1
ans = 1
for a,b in plus.keys():
ans *= pow(2,plus[(a,b)],mod)+pow(2,minus[(b,-a)],mod)-1
ans %= mod
flag[(b,-a)] = 0
for key in minus.keys():
if flag[key] == 1:
ans *= pow(2,minus[key],mod)
ans %= mod
ans *= pow(2,A_zero,mod)+pow(2,B_zero,mod)-1
ans %= mod
ans += zero_zero-1
ans %= mod
print(ans)
| 1 | 21,047,341,621,760 | null | 146 | 146 |
import sys
input = sys.stdin.readline
N, M, L = (int(i) for i in input().split())
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix
graph = [[0]*N for i in range(N)]
for i in range(M):
a, b, c = (int(i) for i in input().split())
graph[a-1][b-1] = c
graph[b-1][a-1] = c
graph = csr_matrix(graph)
d = floyd_warshall(csgraph=graph, directed=False)
new_graph = [[0]*N for i in range(N)]
for i in range(N):
for j in range(N):
if d[i][j] <= L:
new_graph[i][j] = 1
new_graph[j][i] = 1
graph = csr_matrix(new_graph)
d = floyd_warshall(csgraph=graph, directed=False)
Q = int(input())
for i in range(Q):
s, t = (int(i) for i in input().split())
if d[s-1][t-1] == float("inf"):
print("-1")
else:
print(int(d[s-1][t-1]-1))
|
from scipy.sparse.csgraph import floyd_warshall
N,M,L = list(map(int, input().split()))
edges = [[0] * N for _ in range(N)]
for _ in range(M):
A,B,C = list(map(int, input().split()))
edges[A-1][B-1] = C
edges[B-1][A-1] = C
Q = int(input())
queries = []
for _ in range(Q):
queries.append(list(map(int,input().split())))
# use flord warshall to find min path between all towns
edges = floyd_warshall(edges)
# if the two towns can be travelled to on one tank, add to our fuel graph with distance 1
for i in range(N):
for j in range(N):
if edges[i][j] <= L:
edges[i][j] = 1
else:
edges[i][j] = 0
# use flord warshall to find min number of fuel tanks to travel between two towns
edges = floyd_warshall(edges)
for query in queries:
s = query[0] - 1
t = query[1] - 1
num_tanks = edges[s][t] - 1
if num_tanks != float('inf'):
print(int(num_tanks))
else:
print("-1")
| 1 | 172,907,037,868,490 | null | 295 | 295 |
n,k=map(int,input().split())
dp2=list(map(int,input().split()))
k=min(k,41)
for ki in range(1,k+1):
ims=[0]*(n+1)
for ni in range(n):
if 0>ni-dp2[ni]:
ims[0]+=1
else:
ims[ni-dp2[ni]]+=1
if n<ni+dp2[ni]+1:
ims[n]-=1
else:
ims[ni+dp2[ni]+1]-=1
dp2[0]=ims[0]
for ni in range(1,n):
dp2[ni]=dp2[ni-1]+ims[ni]
for i in range(n):
print(dp2[i],end=" ")
print()
|
y, x = map(int, input().split())
box = []
y_sum = [[]]
for i in range(y):
box.append(list(map(int, input().split())))
box[i].append(sum(box[i]))
box_replace = list(map(list, zip(*box)))
[y_sum[0].append(sum(box_replace[i])) for i in range(x+1)]
box += y_sum
[print( " ".join(map(str, box[i])) ) for i in range(y+1)]
| 0 | null | 8,414,686,286,592 | 132 | 59 |
def inp():
return input()
def iinp():
return int(input())
def inps():
return input().split()
def miinps():
return map(int,input().split())
def linps():
return list(input().split())
def lmiinps():
return list(map(int,input().split()))
def lmiinpsf(n):
return [list(map(int,input().split()))for _ in range(n)]
n,x,t = miinps()
ans = (n + (x - 1)) // x
ans *= t
print(ans)
|
import sys
#+++++
def main():
n, m = map(int, input().split())
s=input()
s=s[::-1]
#arch=[len(s)+100]*len(s)
pos=0
ret=[]
while pos < len(s)-1:
for mi in range(m,0,-1):
if pos+mi >= len(s):
pass
elif s[pos+mi]=='0':
pos += mi
ret.append(mi)
#print(pos)
break
else:
pass
else:
return -1
r=ret[::-1]
print(*r)
'''
def main2():
n, m = map(int, input().split())
s = input()
tt=[-1]*len(s)
t_parent=[-1]*len(s)
rs=s[::-1]
open_list=[0]
max_dist = 0
while True#len(open_list) > 0:
st, parent, count = open_list.pop()
for i in range(m, 0, -1):
aa = st + i
if aa > n+1:
pass
#gmマス
if rs[aa] == 1:
continue
#アクセス済み
if tt[aa] > 0:
break
tt[aa] = count+1
t_parent[aa] = st
open_list.append(aa, st, count+1)
print(1)
'''
#+++++
isTest=False
def pa(v):
if isTest:
print(v)
if __name__ == "__main__":
if sys.platform =='ios':
sys.stdin=open('inputFile.txt')
isTest=True
else:
pass
#input = sys.stdin.readline
ret = main()
if ret is not None:
print(ret)
| 0 | null | 71,904,135,836,000 | 86 | 274 |
r=input().split()
N=int(r[0])
K=int(r[1])
d=[input().split() for i in range(2*K)]
d_2=[]
d_ans=[0]*N
for i in range(2*K):
d_pre=[int(s) for s in d[i]]
d_2.append(d_pre)
for i in range(2*K):
if i%2==0:
for j in range(d_2[i][0]):
d_ans[d_2[i+1][j]-1]=1
print(d_ans.count(0))
|
N, K = map(int, input().split())
cnts = [0] * N
for _ in range(K):
di = int(input())
A = list(map(int, input().split()))
for i in range(di):
cnts[A[i]-1] += 1
ans = cnts.count(0)
print(ans)
| 1 | 24,430,935,511,852 | null | 154 | 154 |
S,T=map(str, input().split())
a,b=map(int, input().split())
U = str(input())
if S == U :
a -= 1
if T == U:
b -= 1
print(a,b)
|
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
t = [int(input()) for _ in range(D)]
last_di = [0] * 26
v = 0
for d in range(D):
i = t[d]
v += s[d][i - 1]
last_di[i - 1] = d + 1
S = 0
for j in range(len(c)):
S += c[j] * (d + 1 - last_di[j])
v -= S
print(v)
| 0 | null | 41,084,762,139,258 | 220 | 114 |
s,w=map(int,input().split(" "))
if s>w:
print("safe")
else:
print("unsafe")
|
import math
import collections
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
cumax=(2*10**5)+10
cuml=[0]*cumax
#print(A)
ind=0
l=[]
c=collections.Counter(A)
values=list(c.values()) #aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
key=list(c.keys()) #先のvalue値に相当する要素のリスト(要素1,要素2,…)
for i in range(len(key)):
l.append([key[i],values[i]])#lは[要素i,n_i]の情報を詰めたmatrix
lr=[]
v=[]
for i in range(len(key)):
lr.append([0,l[i][0]])
v.append(l[i][1])
for i in range(len(v)):
l=lr[i][0]
r=lr[i][1]
cuml[l]=cuml[l]+v[i]
if r+1<cumax:
cuml[r+1]=cuml[r+1]-v[i]
for i in range(cumax-1):
cuml[i+1]=cuml[i+1]+cuml[i]
#print(cuml)
maxind=2*10**5+10
minind=0
while maxind-minind>1:
piv=minind+(maxind-minind)//2 #pivは握手の幸福度
cnt=0
for i in range(N):
x=piv-A[i]
cnt=cnt+cuml[max(x,0)]
if cnt<=M:
maxind=piv
else:
minind=piv
#print(cnt,maxind,piv,minind)
#print(minind)
thr=minind
cuml2=[0]*(N+1)
A.sort(reverse=True)
for i in range(N):
cuml2[i+1]=cuml2[i]+A[i]
#print(cuml2,thr,A)
ans=0
counts=0
#print(cuml[0:10])
for i in range(N):
x=thr-A[i]
#print(x)
cnt=cuml[max(x,0)]
#print(cnt)
ans=ans+(A[i]*cnt)+cuml2[cnt]
counts=counts+cnt
ans=ans-(counts-M)*thr
#print()
print(ans)
| 0 | null | 68,410,457,427,520 | 163 | 252 |
x = int(input())
q = x // 100
r = x % 100
r -= 5 * q
print(1 if r <= 0 else 0)
|
#70 C - 100 to 105 WA
X = int(input())
dp = [0]*(100010)
lst = [100,101,102,103,104,105]
for i in range(100,106):
dp[i] = 1
# dp[v] が存在するなら 1, しないなら 0
for v in range(100,X+1):
for w in range(6):
n = lst[w]
if dp[v-n] == 1:
dp[v] = 1
print(dp[X])
| 1 | 127,683,623,474,212 | null | 266 | 266 |
H,A = map(int,input().split())
t = 0
for i in range(H):
H -= A
t += 1
if H<=0:
print(t)
exit()
|
N=int(input())
S=input()
count=0
for i in range(N):
if S[i]=='A' and i!=N-1:
if S[i+1]=='B' and i!=N-2:
if S[i+2]=='C':
count+=1
print(count)
| 0 | null | 88,533,953,046,626 | 225 | 245 |
S = input()
N = len(S)
s = 'x'*N
print(s)
|
weatherS = input()
serial = 0
dayBefore = ''
for x in weatherS:
if dayBefore != 'R':
if x == 'R':
serial = 1
else:
if x == 'R':
serial += 1
dayBefore = x
print(serial)
| 0 | null | 39,071,114,026,802 | 221 | 90 |
n = int(input())
for i in range(1, n + 1):
if i % 3 == 0 or str(i).find("3") != -1:
print(" {}".format(i), end = '')
print()
|
n = int(input())
p = list(map(int, input().split()))
ans = 0
m = p[0]
for i in p:
if m >= i:
ans += 1
m = i
print(ans)
| 0 | null | 43,445,270,960,740 | 52 | 233 |
while True:
data = input()
if(data == "-"):break
m = int(input())
tmp = []
for i in range(m):
num = int(input())
if(len(tmp) == 0):
tmp = data[num:] + data[:num]
data = ""
else:
data = tmp[num:] + tmp[:num]
tmp = ""
if(data): print(data)
else: print(tmp)
|
from collections import deque
while True:
str = input()
if str == "-":
break
dq = deque(char for char in list(str))
shuffle_count = int(input())
for i in range(shuffle_count):
h = int(input())
dq.rotate(h * -1)
print(''.join(dq))
| 1 | 1,913,184,795,460 | null | 66 | 66 |
a= list(map(int,input().split()))
N = a[0]
K = a[1]
a = [0]*K
mod = 10**9+7
for x in range(K,0,-1):
a[x-1] = pow(K//x, N,mod)
for t in range(2,K//x+1):
a[x-1] -= a[t*x-1]
s = 0
for i in range(K):
s += (i+1)*a[i]
ans = s%mod
print(ans)
|
def resolve():
n,k = map(int,input().split())
print(min(n-k*(n//k),abs(n-k*(n//k)-k)))
resolve()
| 0 | null | 38,167,126,121,440 | 176 | 180 |
import math
a, b, h, m = map(int, input().split())
ang_a = (360 * h / 12) + (0.5 * m)
ang_b = 360 * m / 60
ang = abs(ang_a - ang_b)
ans = math.sqrt((a ** 2 + b ** 2) - (2*a*b*math.cos(math.radians(ang))))
print(ans)
|
#!/usr/bin/env python3
def main():
import sys
import numpy as np
input = sys.stdin.readline
A, B, H, M = map(int, input().split())
pi = np.pi
time = 60 * H + M
theta_H = (time * 2 * pi) / (12 * 60)
theta_M = (M * 2 * pi) / 60
res = abs(theta_H - theta_M)
theta = min(res, 2 * pi - res)
ans = np.sqrt(A ** 2 + B ** 2 - 2 * A * B * np.cos(theta))
print(ans)
if __name__ == '__main__':
main()
| 1 | 20,113,589,446,170 | null | 144 | 144 |
string = input()
lt = True
ans = 0
l_cnt = 0
m_cnt = 0
if string[0] == ">":
lt = False
for s in string:
if s == "<":
if not lt:
a, b = max(l_cnt, m_cnt), min(l_cnt, m_cnt)
ans += a * (a + 1) // 2 + b * (b - 1) // 2
l_cnt = m_cnt = 0
l_cnt += 1
lt = True
else:
m_cnt += 1
lt = False
a, b = max(l_cnt, m_cnt), min(l_cnt, m_cnt)
ans += a * (a + 1) // 2 + b * (b - 1) // 2
print(ans)
|
N = int(input())
S = input()
s = list(S)
for i in range(len(S)):
if (ord(s[i]) - 64 + N) % 26 == 0:
p = 90
else:
p = (ord(s[i]) - 64 + N) % 26 + 64
s[i] = chr(p)
print("".join(s))
| 0 | null | 145,467,437,158,968 | 285 | 271 |
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
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)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal
def input():
x=sys.stdin.readline()
return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
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
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
K,N,M=len(B),len(A),len(B[0])
return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
N,size=len(v),len(M)
return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
n,m=len(M),len(M[0])
return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
mod = 1000000007
#w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え
s = input()
K= int(input())
#N, K = map(int, input().split())
#A = tuple(map(int, input().split())) #1行ベクトル
#L = tuple(int(input()) for i in range(N)) #改行ベクトル
#S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
keta=len(s)
dp=[[[0,0] for _ in range(K+1)] for _ in range(keta+1)]
#dp[i][j][k]前からi桁目まで決め、j個の条件を満たす桁を含み、k=1:i文字目まで一致 k=0:対象の数以下
dp[0][0][0]=1
for i in range(0,keta):
ni=i+1
nd=int(s[i])
for j in range(0,K+1):
for k in range(0,2):
for d in range(10):
nj=j
nk=k
if d!=0:nj+=1
if nj>K:continue
if k==0:
if d>nd:break
elif d<nd:nk=1
dp[ni][nj][nk]+=dp[i][j][k]
if K<=keta:
ans=dp[keta][K][1]+dp[keta][K][0]
else:
ans=0
#与えられた数未満で条件を満たすもの+与えられた数が条件を満たす場合1
print(ans)
#print(dp)
if __name__ == "__main__":
main()
|
import sys
read = sys.stdin.read
def main():
N, K = map(int, read().split())
dp1 = [0] * (K + 1)
dp2 = [0] * (K + 1)
dp1[0] = 1
for x in map(int, str(N)):
for j in range(K, -1, -1):
if j > 0:
dp2[j] += dp2[j - 1] * 9
if x != 0:
dp2[j] += dp1[j - 1] * (x - 1) + dp1[j]
dp1[j] = dp1[j - 1]
else:
dp1[j] = 0
dp2[j] = 1
print(dp1[K] + dp2[K])
return
if __name__ == '__main__':
main()
| 1 | 75,991,683,279,158 | null | 224 | 224 |
n = int(input())
s = list(input())
s = [ord(i)-97 for i in s]
dic = {}
for i in range(26):
dic[i] = []
for i in range(n):
dic[s[i]].append(i)
for i in range(26):
dic[i].append(float('inf'))
from bisect import bisect_left
q = int(input())
for i in range(q):
x, y, z = input().split()
if x == '1':
y, z = int(y) - 1, ord(z) - 97
p = bisect_left(dic[s[y]], y)
dic[s[y]].pop(p)
dic[z].insert(bisect_left(dic[z], y), y)
s[y] = z
else:
res = 0
y, z = int(y) - 1, int(z) - 1
for i in range(26):
p = dic[i][bisect_left(dic[i], y)]
if p <= z:
res += 1
print(res)
|
import sys
input = sys.stdin.readline
def main():
N, A, B = map(int, input().split())
if (B - A) % 2 == 0:
ans = (B - A) // 2
else:
a = (A - 1) + 1 + ((B - ((A - 1) + 1)) - 1) // 2
b = (N - B) + 1 + (N - (A + ((N - B) + 1))) // 2
ans = min(a, b)
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 85,945,286,600,700 | 210 | 253 |
# -*- coding: utf-8 -*-
k = int(input())
ans = 0
n = 7
if k % 2 == 0 or k % 5 == 0:
print(-1)
exit(0)
c = 1
while True:
if n % k == 0:
break
n = (n * 10 + 7) % k
c += 1
print(c)
|
import math
n = input()
for i in range(n):
flag = 0
a = map(int, raw_input().split())
if(pow(a[0],2)+pow(a[1],2) == pow(a[2],2)):
flag = 1
if(pow(a[1],2)+pow(a[2],2) == pow(a[0],2)):
flag = 1
if(pow(a[2],2)+pow(a[0],2) == pow(a[1],2)):
flag = 1
if flag == 1:
print "YES"
else:
print "NO"
| 0 | null | 3,082,299,868,900 | 97 | 4 |
n=int(input())
sums=0
for i in str(n):
sums+=int(i)
print('Yes' if sums%9==0 else 'No')
|
k, m = list(map(int, input().split()))
if 500 * k >= m:
print('Yes')
elif 500 * k < m:
print('No')
else:
print('No')
| 0 | null | 51,539,290,669,054 | 87 | 244 |
a=str(input())
if a[0]==a[1] and a[2]==a[0] :
print('No')
else:
print('Yes')
|
n = input()
if len(n) < 3:
print(1000 - int(n))
else:
hasuu = n[len(n) - 3:]
if hasuu == '000':
print('0')
else:
print(1000-int(hasuu))
| 0 | null | 31,501,832,815,040 | 201 | 108 |
import math
k = int(input())
ans = 0
for h in range(1, k+1):
for i in range(1, k+1):
g = math.gcd(h, i)
for j in range(1, k+1):
ans += math.gcd(g, j)
print(ans)
|
# Coffee
S = list(input())
ans = ['No', 'Yes'][(S[2] == S[3]) & (S[4] == S[5])]
print(ans)
| 0 | null | 38,842,611,481,970 | 174 | 184 |
import sys
from collections import deque
N, M = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(M):
a, b = map(int, sys.stdin.readline().split())
G[a-1].append(b-1)
G[b-1].append(a-1)
ars = [0] * N
todo = deque([0])
done = {0}
while todo:
p = todo.popleft()
for np in G[p]:
if np in done:
continue
todo.append(np)
ars[np] = p + 1
done.add(np)
if len(done) == N:
print("Yes")
for i in range(1, N):
print(ars[i])
else:
print("No")
|
#D
from collections import deque
n, m = map(int, input().split())
ans = [0] * (n+1)
g = [[] for _ in range(n + 1)]
for i in range(m):
a, b = map(int, input().split())
g[a].append(b)
g[b].append(a)
#BPS幅優先探索を行う -> 前の座標を記入
nque = deque([1])
while nque:
now_cave = nque.popleft()
for next_cave in g[now_cave]:
if ans[next_cave] == 0:
ans[next_cave] = now_cave
nque.append(next_cave)
# print(nque)
# print(ans)
print("Yes")
for i in range(2, n + 1):
print(ans[i])
| 1 | 20,483,598,874,492 | null | 145 | 145 |
n, m = map(int, input().split())
a = list(map(int, input().split()))
dp = [float('inf') for _ in range(n+1)]
dp[0] = 0
for i in range(n):
for money in a:
next_money = i + money
if next_money > n:
continue
dp[next_money] = min(dp[i] + 1, dp[next_money])
print(dp[n])
|
import sys
n, m = map(int, sys.stdin.readline().strip().split())
c = list(map(int, sys.stdin.readline().strip().split()))
dp = [float("inf") for _ in range(n+1)]
dp[0] = 0
for i in range(n+1):
for c_i in c:
if i - c_i >= 0:
dp[i] = min(dp[i], dp[i - c_i] + 1)
print(dp[n])
| 1 | 139,740,869,740 | null | 28 | 28 |
from collections import Counter
MOD = 998244353
N = int(input())
D = list(map(int, input().split()))
cnt_D = Counter(D)
if D[0] != 0 or cnt_D.get(0, 0) != 1:
print(0)
else:
prev = 1
ans = 1
for i in range(1, max(D) + 1):
v = cnt_D.get(i, 0)
ans *= pow(prev, v, MOD)
ans %= MOD
prev = v
print(ans)
|
N=int(input())
if N%2==1:
print(int(float(N-1)/2))
else:
print(int(float(N-2)/2))
| 0 | null | 153,787,766,895,060 | 284 | 283 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.