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 math
r = float(input())
print("{} {}".format(r*r*math.pi,r*2*math.pi))
|
import math
a = float(input())
print(a*a*math.pi, 2*a*math.pi)
| 1 | 639,991,329,748 | null | 46 | 46 |
R,C,K=map(int,input().split())
V=[[0 for _ in range(C)] for _ in range(R)]
for i in range(K):
r,c,v=map(int,input().split())
V[r-1][c-1]=v
dp=[[0 for _ in range(4)] for _ in range(C+1)]
for i in range(R):
ndp=[[0 for _ in range(4)] for _ in range(C+1)]
for j in range(C):
ndp[j][0]=max(dp[j])
for j in range(C):
v=V[i][j]
for n in range(1,4):
ndp[j][n]=max(ndp[j-1][n-1]+v,dp[j][3]+v,ndp[j-1][n])
dp=ndp
print(max(dp[C-1]))
|
r, c, k = map(int, input().split())
atlas = [[0]*c for i in range(r)]
dp = [[[0]*c for i in range(r)] for j in range(4)]
for i in range(k):
x, y, v = map(int, input().split())
atlas[x-1][y-1] = v
def max_sum(r, c, atlas):
global dp
if atlas[0][0] > 0:
dp[1][0][0] = atlas[0][0]
for i in range(r):
for j in range(c):
for h in range(4):
if j+1 < c:
dp[h][i][j+1] = max(dp[h][i][j+1], dp[h][i][j])
if atlas[i][j+1] > 0 and h < 3:
dp[h+1][i][j+1] = max(dp[h+1][i][j+1], dp[h][i][j]+atlas[i][j+1])
if i+1 < r:
dp[0][i+1][j] = max(dp[0][i+1][j], dp[h][i][j])
if atlas[i+1][j] > 0:
dp[1][i+1][j] = max(dp[1][i+1][j], dp[h][i][j]+atlas[i+1][j])
return dp
max_sum(r, c, atlas)
ans = 0
for i in range(4):
ans = max(ans, dp[i][r-1][c-1])
print(ans)
| 1 | 5,607,672,284,050 | null | 94 | 94 |
n = int(input())
s = input()
ans = 0
ans = s.count('R')*s.count('G')*s.count('B')
for i in range(0,n-2):
for j in range(1,n-1):
k = -i + 2*j
if j < k <= n-1:
if s[i] == s[j]:
continue
if s[i] == s[k]:
continue
if s[j] == s[k]:
continue
else:
continue
ans -= 1
print(ans)
|
n = input()
lis = []
bot = 0
for i in xrange(n):
com = raw_input()
if com[0] == 'i':
lis.append(com[7:])
elif com[6] == ' ':
try:
lis.pop(~lis[::-1].index(com[7:]))
except:
pass
elif com[6] == 'F':
lis.pop()
else:
bot += 1
print ' '.join( map(str, reversed(lis[bot:])) )
| 0 | null | 18,028,045,943,898 | 175 | 20 |
N = int(input())
A_list = list(map(int, input().split()))
for i in range(N):
if A_list[i] % 2 == 0:
if A_list[i] % 3 == 0 or A_list[i] % 5 == 0:
continue
else:
print("DENIED")
exit()
if i == N-1:
print("APPROVED")
|
num=int(input())
print(3.14159265359*num*2)
| 0 | null | 50,274,555,670,180 | 217 | 167 |
n = int(input())
if n%2 == 0:
t=(n//2)/n
else:
t=(n//2+1)/n
print('{:.10f}'.format(t))
|
#!/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 | 177,117,200,762,980 | null | 297 | 297 |
# https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_e
import sys
input=sys.stdin.readline
MOD=10**9+7
def main():
N=int(input())
A=list(map(int,input().split()))
cnt=[0]*N
ans=1
for i in range(N):
if A[i]==0:
ans*=3-cnt[0]
ans%=MOD
cnt[A[i]]+=1
else:
ans*=cnt[A[i]-1]-cnt[A[i]]
ans%=MOD
cnt[A[i]]+=1
print(ans)
if __name__=="__main__":
main()
|
n=int(input())
*a,=map(int,input().split())
cnt=[0,0,0]
ans=1
mod=10**9+7
for aa in a:
tmp=0
for c in cnt:
if aa==c:
tmp+=1
if tmp>0:
for i in range(3):
if cnt[i]==aa:
cnt[i]+=1
break
ans*=tmp
ans%=mod
print(ans)
| 1 | 130,133,471,169,618 | null | 268 | 268 |
from collections import deque
S = input()
Q = int(input())
t = []
f = []
c = []
for i in range(Q):
in_ = list(input().split())
if in_[0] == "1":
t.append(1)
f.append(0)
c.append(0)
else:
t.append(2)
f.append(int(in_[1]))
c.append(in_[2])
acc = [0 for _ in range(Q)]
if t[-1] == 1: acc[-1] = 1
for i in reversed(range(Q - 1)):
if t[i] == 1:
acc[i] = acc[i + 1] + 1
else:
acc[i] = acc[i + 1]
if acc[0] % 2 == 0:
ans = deque(S)
else:
ans = deque(S[::-1])
for i in range(Q):
if t[i] == 2:
if (f[i] + acc[i]) % 2 == 1:
ans.appendleft(c[i])
else:
ans.append(c[i])
print("".join(ans))
|
L = int(input())
S = L / 3
print(S**3)
| 0 | null | 51,951,220,047,460 | 204 | 191 |
from decimal import Decimal
p=3.141592653589
r=float(raw_input())
print Decimal(r*r*p),Decimal(r*2*p)
|
import math
pi=math.pi
r=float(input())
menseki=r*r*pi
ensyu=2*r*pi
print(str(menseki)+" "+str(ensyu))
| 1 | 639,330,919,700 | null | 46 | 46 |
import math
a,b,h,m=map(int,input().split())
f=h / 12 * 360 - m / 60 * 360 + m / 60 / 12 * 360
theta=math.radians(f)
print(math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(theta)))
|
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())
N = I()
d = LI()
ans = 0
l = list(itertools.combinations(d,2))
for i, j in l:
ans += i*j
print(ans)
| 0 | null | 94,132,344,593,340 | 144 | 292 |
import math
a,b,c = [int(x) for x in input().split()]
c = math.radians(c)
s = a * b * math.sin(c) / 2
l = a + b + math.sqrt(a**2 + b**2 - 2*a*b*math.cos(c))
h = 2 * s / a
for i in [s,l,h]:
print('{:.12f}'.format(i))
|
import math
def triangle(a, b, deg):
result = {}
rad = math.radians(deg)
c = math.sqrt(a*a+b*b-(2*a*b*math.cos(rad)))
s = (a+b+c)/2
result['area'] = math.sqrt(s*(s-a)*(s-b)*(s-c))
result['perimeter'] = a+b+c
result['height'] = result['area'] * 2 / a
return result
if __name__ == '__main__':
a, b, deg = map(int, input().split())
triangle = triangle(a, b, deg)
print(triangle['area'])
print(triangle['perimeter'])
print(triangle['height'])
| 1 | 179,412,067,772 | null | 30 | 30 |
N=int(input())
S=input()
b=S.count('ABC')
print(b)
|
N=int(input())
S=input()
ans=0
for i in range(N-2):
if S[i]=='A':
i+=1
if S[i]=='B':
i+=1
if S[i]=='C':
ans+=1
print(ans)
| 1 | 99,206,259,969,780 | null | 245 | 245 |
N = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for _ in range(N):
a = input()
if a == "AC":
ac += 1
if a == "WA":
wa += 1
if a == "TLE":
tle += 1
if a =="RE":
re += 1
print(f"AC x {ac}")
print(f"WA x {wa}")
print(f"TLE x {tle}")
print(f"RE x {re}")
|
n = int(input())
s_lst = list(str(input()) for _ in range(n))
count_lst = [0, 0, 0, 0]
for i in range(n):
consequence = s_lst[i]
if consequence == 'AC':
count_lst[0] += 1
elif consequence == 'WA':
count_lst[1] += 1
elif consequence == 'TLE':
count_lst[2] += 1
else:
count_lst[3] += 1
consequence_lst = ['AC x {}'.format(count_lst[0]), 'WA x {}'.format(count_lst[1]), 'TLE x {}'.format(count_lst[2]), 'RE x {}'.format(count_lst[3])]
for i in range(4):
con = consequence_lst[i]
print(con)
| 1 | 8,735,088,103,940 | null | 109 | 109 |
from sys import stdin
import sys
import math
from functools import reduce
import itertools
n,m = [int(x) for x in stdin.readline().rstrip().split()]
check = [0 for i in range(n)]
count = [0 for i in range(n)]
for i in range(m):
p, q = [x for x in stdin.readline().rstrip().split()]
p = int(p)
if q == 'AC':
check[p-1] = 1
if q == 'WA' and check[p-1] == 0:
count[p-1] = count[p-1] + 1
for i in range(n):
if check[i] == 0: count[i] = 0
print(sum(check), sum(count))
|
N,M = map(int, input().split())
AC = [0] * (N+1)
pl = [0] * (N+1)
cole = 0
pena = 0
for target_list in range(M):
ans = input().split()
problem = int(ans[0])
result = ans[1]
if AC[problem] == 0 and result == 'WA':
pl[problem] += 1
elif AC[problem] == 0 and result == 'AC':
pena += pl[problem]
cole += 1
AC[problem] = 1
print(cole, pena)
| 1 | 93,203,204,528,320 | null | 240 | 240 |
import math
a,b,C=map(float,input().split())
print(f'{a*b/2*math.sin(math.radians(C)):.6f}')
print(f'{a+b+(a**2+b**2-2*a*b*math.cos(math.radians(C)))**0.5:.6f}')
print(f'{b*math.sin(math.radians(C)):.6f}')
|
import math
a, b, C = map(int, input().split())
C = math.radians(C)
c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(C))
S = a * b * math.sin(C) / 2
print(f"{S:0.9f}")
print(f"{a+b+c:0.9f}")
print(f"{S*2/a:0.9f}")
| 1 | 179,171,705,478 | null | 30 | 30 |
#AIsing2020 d
def f(n):
cnt = 0
while n:
cnt+= 1
n = n%bin(n).count('1')
return cnt
def main():
N = int(input())
X = input()
X10 = int(X,2)
X10_num1 = X.count('1')
X10_pulse = X10%(X10_num1+1)
X10_ninus = X10%(X10_num1-1) if X10_num1 >1 else 0
for i in range(N,0,-1):
if (X10>>(i-1) & 1) and X10_num1 >1:
mod = X10_num1-1
amari = (X10_ninus - pow(2,i-1,mod))%(mod)
elif (X10>>(i-1) & 1) and X10_num1 ==1:
print(0)
continue
else:
mod = X10_num1+1
amari = (X10_pulse + pow(2,i-1,mod))%(mod)
print(1+f(amari))
main()
|
#0除算
import math
def popcount(x):
s=0
y=int(math.log2(x))+2
for i in range(y):
if(x>>i)&1:
s+=1
return x%s
n=int(input())
x=input()[::-1]
#1がなんこ出るのか
c=x.count("1")
#c+1とc-1だけ考えれば良い
#c=1の時場合分け
#m[i][j]:2^iまで考えたときのmod(c+j-1)
if c!=1:
m=[[1%(c-1),1%(c+1)]]
for i in range(n-1):
m.append([(2*m[-1][0])%(c-1),(2*m[-1][1])%(c+1)])
l=[0,0]
for i in range(n):
if x[i]=="1":
l[0]+=m[i][0]
l[1]+=m[i][1]
l[0]%=(c-1)
l[1]%=(c+1)
else:
m=[[1%(c+1),1%(c+1)]]
for i in range(n-1):
m.append([(2*m[-1][0])%(c+1),(2*m[-1][1])%(c+1)])
l=[0,0]
for i in range(n):
if x[i]=="1":
l[0]+=m[i][0]
l[1]+=m[i][1]
l[0]%=(c+1)
l[1]%=(c+1)
#一個だけ変えたいので全体を求める
#最初以外はpopcount使って間に合う
ans=[0]*n
for i in range(n):
if x[i]=="1":
if c-1==0:
ans[i]=0
continue
p=(l[0]+(c-1)-m[i][0])%(c-1)
ans[i]+=1
while p!=0:
p=popcount(p)
ans[i]+=1
else:
p=(l[1]+m[i][1])%(c+1)
ans[i]+=1
while p!=0:
p=popcount(p)
ans[i]+=1
ans=ans[::-1]
for i in range(n):
print(ans[i])
| 1 | 8,187,462,866,818 | null | 107 | 107 |
# https://atcoder.jp/contests/ddcc2020-qual/tasks/ddcc2020_qual_b
n = int(input())
nums = [int(i) for i in input().split()]
for i in range(n - 1):
nums[i + 1] += nums[i]
ans = float('inf')
for i in range(n - 1):
d = abs(nums[-1] - nums[i] * 2)
ans = min(ans, d)
print(ans)
|
alpha = input()
if alpha.islower():
print('a')
else :
print('A')
| 0 | null | 76,393,933,553,752 | 276 | 119 |
import heapq
from sys import stdin
input = stdin.readline
#入力
# s = input()
n = int(input())
# n,m = map(int, input().split())
# a = list(map(int,input().split()))
# a = [int(input()) for i in range()]
st=[]
for i in range(n):
s,t = map(str, input().split())
t = int(t)
st.append((s,t))
x = input()[0:-1]
def main():
ans = 0
flag = False
for i in st:
s,t = i
if flag:
ans+=t
if s == x:
flag = True
print(ans)
if __name__ == '__main__':
main()
|
n = int(input())
title = []
length = []
for i in range(n):
a,b = map(str, input().split())
title.append(a)
length.append(int(b))
x = input()
ind = title.index(x)
print(sum(length[ind+1:]))
| 1 | 96,552,520,141,432 | null | 243 | 243 |
from collections import deque
n, m = map(int,input().split())
turo = [[] for i in range(n+1)]
sirusi = [-1 for i in range(n+1)]
for i in range(m):
tmp = list(map(int,input().split()))
turo[tmp[0]].append(tmp[1])
turo[tmp[1]].append(tmp[0])
sirusi[1] = 0
q = deque()
q.append(1)
while len(q) != 0:
x = q.popleft()
for i in turo[x]:
if sirusi[i] == -1:
sirusi[i] = x
q.append(i)
print('Yes')
for i in range(n+1):
if i != 0 and i != 1:
print(sirusi[i])
|
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
n,m = LI()
route = [None] + [[] for _ in range(n)]
for _ in range(m):
a,b = LI()
route[a].append(b)
route[b].append(a)
explored = {1}
queue = collections.deque([1])
ans = [None for _ in range(n+1)]
while len(queue)!=0:
nxt = queue.popleft()
for nbh in route[nxt]:
if nbh not in explored:
ans[nbh] = nxt
queue.append(nbh)
explored.add(nbh)
print("Yes")
print(*ans[2:],sep="\n")
main()
| 1 | 20,632,283,337,820 | null | 145 | 145 |
ans=[]
while True:
a=input()
if '?' in a:
break
eval('ans.append(int({0}))'.format(a))
for a in ans:
print(a)
|
while 1 :
a, op, b= raw_input().split()
c = int(a)
d = int(b)
if op == '?': break
elif op == '+': print c + d
elif op == '-': print c - d
elif op == '*': print c * d
elif op == '/': print c / d
| 1 | 676,731,282,032 | null | 47 | 47 |
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
L = I()
len_edge = L/3
print(len_edge**3)
|
import sys
def input(): return sys.stdin.readline().rstrip()
from bisect import bisect
def main():
n,d,a=map(int,input().split())
XH=[list(map(int,input().split())) for i in range(n)]
XH.sort()
X,H=zip(*XH)
right=[0]*n
for i,x in enumerate(X):
right[i]=bisect(X,x+2*d)
damage=[0]*(n+1)
ans=0
for i,(x,h) in enumerate(XH):
if i!=0:
damage[i]+=damage[i-1]
h-=damage[i]
if h>0:
cunt=-(-h//a)
ans+=cunt
damage[i]+=a*cunt
damage[right[i]]-=a*cunt
print(ans)
if __name__=='__main__':
main()
| 0 | null | 64,793,477,457,158 | 191 | 230 |
from sys import stdin, setrecursionlimit
def main():
input = stdin.buffer.readline
n = int(input())
d = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
for j in range(i + 1, n):
ans += d[i] * d[j]
print(ans)
if __name__ == "__main__":
setrecursionlimit(10000)
main()
|
class UnionFind():
def __init__(self, n):
self.par = [i for i in range(n+1)]
self.rank = [0] * (n+1)
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):
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def same(self, x, y):
return self.find(x) == self.find(y)
N,M=map(int,input().split())
city=UnionFind(N)
for i in range(M):
A,B=map(int,input().split())
city.unite(A,B)
ck=[0]*(N+10)
for i in range(1,N+1):
root=city.find(i)
if ck[root]==0:
ck[root]=1
#print(city.par)
#print(ck)
Ans=sum(ck)-1
print(Ans)
| 0 | null | 84,971,748,256,010 | 292 | 70 |
a = sorted(map(int, raw_input().split()))
print '%d %d %d'%(a[0],a[1],a[2])
|
a, b, c = map(int, input().split())
if a > b:
tmp = b
b = a
a = tmp
if b > c:
tmp = c
c = b
b = tmp
if a > b:
tmp = b
b = a
a = tmp
print(a,b,c)
# sortを使って解く -> Presentation error となってしまう。。
"""
A = list(map(int, input().split()))
A.sort()
for a in A:
print(a, end=' ')
"""
| 1 | 419,038,993,104 | null | 40 | 40 |
import sys
input = sys.stdin.readline
def main():
ans = 'No'
N = int(input())
c = 0
for _ in range(N):
d1, d2 = map(int, input().split())
if d1 == d2:
c += 1
if c >= 3:
ans = 'Yes'
break
else:
c = 0
print(ans)
if __name__ == '__main__':
main()
|
n = int(input())
s = 0
for i in range(n):
x,y = map(int,input().split())
if x == y:
s += 1
if s == 3:
print("Yes")
quit()
else:
s = 0
print("No")
| 1 | 2,477,453,843,488 | null | 72 | 72 |
def lcm(x, y):
from fractions import gcd
return (x * y) // gcd(x, y)
a,b = map(int,input().split())
print(lcm(a,b))
|
def lcm(x, y):
import math
return (x * y) // math.gcd(x, y)
def abc148c_snack():
a, b = map(int, input().split())
print(lcm(a, b))
abc148c_snack()
| 1 | 113,427,850,132,690 | null | 256 | 256 |
n = int(input())
t, h = 0, 0
for i in range(n):
s1, s2 = input().split()
if s1 > s2:
t += 3
elif s1 < s2:
h += 3
else:
t += 1
h += 1
print(t, h)
|
#!/usr/bin/env python
# coding: utf-8
# In[15]:
N = int(input())
xy_list = []
for _ in range(N):
A = int(input())
xy = []
for _ in range(A):
xy.append(list(map(int, input().split())))
xy_list.append(xy)
# In[16]:
ans = 0
for i in range(2**N):
for j,a_list in enumerate(xy_list):
if (i>>j)&1 == 1:
for k,(x,y) in enumerate(a_list):
if (i>>(x-1))&1 != y:
break
else:
continue
break
else:
ans = max(ans, bin(i)[2:].count("1"))
print(ans)
# In[ ]:
| 0 | null | 61,788,220,601,020 | 67 | 262 |
Q = 10**9+7
def main():
N, K = map( int, input().split())
ANS = [0]*(K+1)
for x in range(K,0,-1):
ans = pow(K//x,N,Q)
for i in range(2, K+1):
if x*i > K:
break
ans -= ANS[x*i]
ANS[x] = ans%Q
print( sum( [ANS[i]*i%Q for i in range(K+1)])%Q)
if __name__ == '__main__':
main()
|
n, k = map(int, input().split())
mod = 10**9 + 7
s = [0 for i in range(k+1)]
ret = 0
for i in range(k, 0, -1):
p = int(k/i)
c = pow(p, n, mod)
for j in range(2, k+1):
if i*j <= k:
c -= s[i*j]
else:
break
s[i] = c%mod
ret = (ret + (c%mod)*i)%mod
print(ret)
| 1 | 36,601,244,872,040 | null | 176 | 176 |
def main():
a, b = map(int, input().split())
if a == b:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
|
n, k = map(int, input().split())
H = list(map(int, input().split()))
H.sort()
print(sum(H[:max(n-k, 0)]))
| 0 | null | 81,207,338,116,252 | 231 | 227 |
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N = int(input())
Ls = list(mapint())
Ls.sort()
from bisect import bisect_left
ans = 0
for i in range(N-2):
for j in range(i+1, N-1):
idx = bisect_left(Ls, Ls[i]+Ls[j])
ans += idx-1-j
print(ans)
|
A11,A12,A13 = map(int,input().split())
A21,A22,A23 = map(int,input().split())
A31,A32,A33 = map(int,input().split())
Alist = []
Alist.append(A11)
Alist.append(A12)
Alist.append(A13)
Alist.append(A21)
Alist.append(A22)
Alist.append(A23)
Alist.append(A31)
Alist.append(A32)
Alist.append(A33)
bingolist =[0]*9
N = int(input())
#print (N)
for i in range(N):
b = int(input())
#print (b)
for j in range(len(bingolist)):
if b ==Alist[j]:
bingolist[j] = 1
if sum(bingolist[0:3])==3 or sum(bingolist[3:6])==3 or sum(bingolist[6:9])==3 or (bingolist[0]+bingolist[3]+bingolist[6])==3 or (bingolist[1]+bingolist[4]+bingolist[7])==3 or (bingolist[2]+bingolist[5]+bingolist[8])==3 or (bingolist[0]+bingolist[4]+bingolist[8])==3 or (bingolist[2]+bingolist[4]+bingolist[6])==3:
print ("Yes")
else :
print ("No")
#print (bingolist[0:3])
#print (bingolist[3:6])
#print (bingolist[6:9])
#print (bingolist)
| 0 | null | 116,187,122,345,368 | 294 | 207 |
import networkx as nx
H, W = map(int, input().split())
maze = [input() for _ in range(H)]
G = nx.grid_2d_graph(H, W)
for h in range(H):
for w in range(W):
# 壁に入る辺を削除
if maze[h][w] == '#':
for dh, dw in ((1, 0), (0, 1), (-1, 0), (0, -1)):
if ((h - dh, w - dw), (h, w)) in G.edges():
G.remove_edge((h - dh, w - dw), (h, w))
def bfs(sy, sx):
d = dict()
d[(sy, sx)] = 0
for coordinate_from, coordinate_to in nx.bfs_edges(G, (sy, sx)):
d[coordinate_to] = d[coordinate_from] + 1
return max(d.values())
ans = 0
for y in range(H):
for x in range(W):
if maze[y][x] == '.':
ans = max(ans, bfs(y, x))
print(ans)
|
from collections import deque
import copy
H, W = map(int, input().split())
S = [input() for _ in range(H)]
def warshall_floyd(d):
#d[i][j]: iからjへの最短距離
for k in range(H*W):
for i in range(H*W):
for j in range(H*W):
d[i][j] = min(d[i][j],d[i][k] + d[k][j])
return d
d = [[float("inf")]*(H*W) for i in range(H*W)]
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(H-1):
for j in range(W-1):
if S[i][j] == ".":
if S[i+1][j] == ".":
d[i*W+j][(i+1)*W+j] = 1
d[(i+1)*W+j][i*W+j] = 1
if S[i][j+1] == ".":
d[i*W+j][i*W+(j+1)] = 1
d[i*W+(j+1)][i*W+j] = 1
for i in range(W-1):
if S[H-1][i] == "." and S[H-1][i+1] == ".":
d[(H-1)*W+i][(H-1)*W+(i+1)] = 1
d[(H-1)*W+(i+1)][(H-1)*W+i] = 1
for i in range(H-1):
if S[i][W-1] == "." and S[i+1][W-1] == ".":
d[i*W+(W-1)][(i+1)*W+(W-1)] = 1
d[(i+1)*W+(W-1)][i*W+(W-1)] = 1
for i in range(H*W):
d[i][i] = 0 #自身のところに行くコストは0
ans = 0
data = warshall_floyd(d)
for items in data:
for item in items:
if item != float("inf"):
ans = max(ans, item)
print(ans)
| 1 | 94,656,372,434,968 | null | 241 | 241 |
import heapq
n,k = map(int,input().split())
a = [int(i) for i in input().split()]
low = 0
high = 10**9
if k == 0:
print(max(a))
exit()
while low+1 < high:
tmp = 0
mid = (low + high) //2
for i in range(n):
tmp += ((a[i]+mid-1) // mid)-1
if tmp <= k:
high = mid
else:
low = mid
print(high)
|
# 2butan renshuu 0812
def f(m):
cut=0
for aa in a:
cut+=(aa-1)//m
if cut > k:
return False
return True
n,k=map(int,input().split())
a=list(map(int,input().split()))
l=0
r=10**9+1
while r-l>1:
m=(l+r)//2
# right move
if f(m):
r=m
else:
l=m
print(r)
| 1 | 6,428,543,861,308 | null | 99 | 99 |
n, q = map(int , input().split())
queue = []
for _ in range(n):
line = input().split()
queue.append([line[0], int(line[1])])
class my_queue:
def __init__(self, queue):
self.queue = queue
def enqueue(self, item):
self.queue = self.queue + [item]
self.queue.append(item)
def dequeue(self):
if len(self.queue) != 0:
item = self.queue[0]
self.queue = self.queue[1:]
else :
item = None
return item
time = 0
finish_task = []
while(len(queue) != 0):
item = queue.pop(0)
if item == None:
break
elif item[1] <= q:
time += item[1]
finish_task.append([item[0], time])
else :
time += q
queue.append([item[0], item[1] - q])
for item in finish_task:
print(item[0], item[1])
|
from collections import deque
n, q = map(int, input().split())
procs = deque([])
for i in range(n):
name, time = input().split()
time = int(time)
procs.append([name, time])
total = 0
while procs:
procs[0][1] -= q
if procs[0][1] > 0:
total += q
procs.append(procs.popleft())
else:
total += q + procs[0][1]
print(procs[0][0], total)
procs.popleft()
| 1 | 41,447,607,276 | null | 19 | 19 |
# ????????????
n,m,l = list(map(int,input().split()))
matrixA,matrixB = [],[]
for i in range(n):
matrixA.append(list(map(int,input().split())))
for j in range(m):
matrixB.append(list(map(int,input().split())))
matrix = []
for i in range(l):
mtr = []
for j in range(m):
mtr.append(matrixB[j][i])
matrix.append(mtr)
matrixC = []
for i in range(l):
mtr = []
for j in range(n):
num_sum = 0
# print(matrixA[j],matrix[i])
for a,b in zip(matrixA[j],matrix[i]):
num_sum += a*b
mtr.append(num_sum)
matrixC.append(mtr)
matrix = []
for i in range(n):
out = ''
for j in range(l):
out += str(matrixC[j][i]) + ' '
print(out[:-1])
|
n, m, l = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(n)]
B = [list(map(int, input().split())) for _ in range(m)]
C = []
B_T = list(zip(*B))
for a_row in A:
C.append([sum(a * b for a, b, in zip(a_row, b_column)) for b_column in B_T])
for row in C:
print(' '.join(map(str, row)))
| 1 | 1,440,004,767,450 | null | 60 | 60 |
import sys
import decimal # 10進法に変換,正確な計算
def input():
return sys.stdin.readline().strip()
def main():
a, b = map(int, input().split())
c = a - b*2
if c < 0:
print(0)
return
print(c)
main()
|
#!/usr/bin/env python
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**6)
INF = float("inf")
def main():
A,B = map(int,input().split())
print(max(0, A-B*2))
if __name__ == "__main__":
main()
| 1 | 166,421,215,438,620 | null | 291 | 291 |
#2-8
while True:
try:
def gcd(a,b):
if b == 0:
return a
else:
return gcd(b,a%b)
a = list(map(int,input().split()))
a.sort()
a.reverse()
ans1 = gcd(a[0],a[1])
ans2 = int(a[0]*a[1]/ans1)
print(ans1,ans2)
except:
break
|
import math
def curve(inp):
ret = []
n = len(inp)
cos60 = math.cos(math.radians(60))
sin60 = math.sin(math.radians(60))
for i in range(n - 1):
p1x, p1y = inp[i]
p2x, p2y = inp[i+1]
diffx = (p2x - p1x) / 3
diffy = (p2y - p1y) / 3
sx, sy = p1x + diffx, p1y + diffy
ux = sx + diffx * cos60 - diffy * sin60
uy = sy + diffx * sin60 + diffy * cos60
tx, ty = p2x - diffx, p2y - diffy
ret.extend([(p1x, p1y), (sx, sy), (ux, uy), (tx, ty)])
ret.append(inp[-1])
return ret
if __name__=="__main__":
inp = [(0.0, 0.0), (100.0, 0.0)]
N = int(input())
for i in range(N):
inp = curve(inp)
for i in inp:
print(*i)
| 0 | null | 61,161,324,450 | 5 | 27 |
a, b, c = map(int, input().split())
if(a < b and b < c):
print('Yes')
else:
print('No')
|
a,b,c = raw_input().strip().split(" ")
if int(a) < int(b) < int(c):
print "Yes"
else:
print "No"
| 1 | 376,171,926,760 | null | 39 | 39 |
from collections import defaultdict
def bfs(s):
q = [s]
while q != []:
p = q[0]
del q[0]
for node in adj[p]:
if not visited[node]:
visited[node] = True
q.append(node)
n,m = map(int,input().split())
adj = defaultdict(list)
visited = [False]*(n+1)
comp = 0
for _ in range(m):
a,b = map(int,input().split())
adj[a].append(b)
adj[b].append(a)
for i in range(1,n+1):
if not visited[i]:
comp+=1
bfs(i)
print(comp-1)
|
import math
a, b, n = list(map(int, input().split()))
output = 0
if n < b:
output = math.floor(a * n / b)
else:
output = math.floor(a * (b-1) / b)
print(output)
| 0 | null | 15,239,576,938,318 | 70 | 161 |
n = int(input())
cnt = 0
for i in range(1, n+1):
if i % 15 != 0:
if i % 3 != 0:
if i % 5 != 0:
cnt += i
print(cnt)
|
def main():
N = int(input())
total = 0
for i in range(N):
i = i + 1
if i % 3 == 0 and i % 5 == 0:
continue
elif i % 3 == 0:
continue
elif i % 5 == 0:
continue
total = total + i
print(total)
main()
| 1 | 35,052,723,570,738 | null | 173 | 173 |
import math
from math import gcd
INF = float("inf")
import sys
input=sys.stdin.readline
import itertools
from collections import Counter
def main():
n = int(input())
p = list(map(int, input().split()))
min = p[0]
cnt = 0
for i in p:
if i <= min:
cnt += 1
min = i
else:
pass
print(cnt)
if __name__=="__main__":
main()
|
#ABC172-B
S = str(input())
T = str(input())
L = int(len(T))
for i in range(L):
if S[i] == T[i]:
L -= 1
print(L)
| 0 | null | 48,139,917,566,830 | 233 | 116 |
import numpy as np
from numba import njit
@njit
def main(N):
spf = np.zeros(N+1,np.int32)
prime = np.zeros(N+1,np.int32)
index = 0
for i in range(2,N+1):
if not spf[i]:
spf[i] = i
prime[index] = i
index += 1
for j in range(index):
if prime[j] > i or i*prime[j] > N:
break
spf[i*prime[j]] = prime[j]
ans = 0
for k in range(1,N+1):
n = k
before = spf[n]
count = 0
fk = 1
while n > 1:
if spf[n] == before:
count += 1
n //= spf[n]
else:
fk *= (count+1)
before = spf[n]
count = 1
n //= spf[n]
fk *= (count+1)
ans += k*fk
print(ans)
N = int(input())
main(N)
|
from numba import njit
import numpy as np
@njit("i8(i8,i8,i8[:])")
def f(n,ans,l):
for i in range(2,n+1):
for j in range(i,n+1,i):
l[j] += 1
ans += (l[i]*i)
return ans
n = int(input())
l = [1]*(n+1)
l[0] = 0
ans = l[1]
l_np = np.array(l,dtype="i8")
print(f(n,ans,l_np))
| 1 | 10,940,792,555,560 | null | 118 | 118 |
target = raw_input()
count = 0
while True:
line = raw_input()
if line == 'END_OF_TEXT':
break
if line[-1] == '.':
line = line[:-1]
for word in line.lower().split():
if target == word:
count += 1
print count
|
x = int(input())
balance = 100
cnt = 0
while balance < x:
balance += int(balance//100)
cnt += 1
print(cnt)
| 0 | null | 14,536,841,537,736 | 65 | 159 |
H, N = map(int, input().split())
A_list = []
for i in range(1, N+1):
A_list.append("A_" + str(i))
A_list = map(int, input().split())
A_total = sum(A_list)
if A_total >= H:
print("Yes")
else:
print("No")
|
#153_B
h, n = map(int, input().split())
a = list(map(int, input().split()))
sum = 0
for i in range(n):
sum += a[i]
if sum >= h:
print('Yes')
else:
print('No')
| 1 | 78,051,187,960,350 | null | 226 | 226 |
def main():
k = int(input())
if k<10:
print(k)
return
que = [i for i in range(1,10)]
cnt = 0
while True:
q = que.pop(0)
cnt += 1
if cnt==k:
print(q)
return
if q%10==0:
que.append(q*10)
que.append(q*10+1)
elif q%10==9:
que.append(q*10+9-1)
que.append(q*10+9)
else:
que.append(q*10+q%10-1)
que.append(q*10+q%10)
que.append(q*10+q%10+1)
if __name__ == "__main__":
main()
|
a,b,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=10**6
for i in range(m):
x,y,c=map(int,input().split())
ans=min(ans,a[x-1]+b[y-1]-c)
print(min(ans,min(a)+min(b)))
| 0 | null | 46,789,519,582,348 | 181 | 200 |
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
N, M = map(int, input().split())
A = list(sorted(map(int, input().split())))
S = sum(A)
acc = [0] * (N + 1)
for i in range(1, N + 1):
acc[i] = acc[i - 1] + A[i - 1]
def check(x):
total = 0
cnt = 0
for a in A:
l = -1
r = N
while r - l > 1:
m = (l + r) // 2
if A[m] + a >= x:
r = m
else:
l = m
cnt += N - r
total += acc[N] - acc[r]
total += a * (N - r)
return (total, cnt)
left = 0
right = 10 ** 6
while right - left > 1:
mid = (left + right) // 2
res = check(mid)
if res[1] >= M:
left = mid
else:
right = mid
res = check(left)
ans = res[0]
print(ans - (res[1] - M) * left)
|
S = int(input())
mod = 10**9+7
dp = [1]+[0]*S
for i in range(1, S+1):
for j in range(0, i-2):
dp[i] += dp[j]
print(dp[S]%mod)
| 0 | null | 55,498,785,018,118 | 252 | 79 |
while True:
m,f,r=map(int,input().split())
p=m+f
if m+f+r==-3:
break
if m==-1 or f==-1:
print("F")
elif p>=80:
print("A")
elif 65<=p and p<80:
print("B")
elif 50<=p and p<65:
print("C")
elif 30<=p and p<50:
if r>=50:
print("C")
else:
print("D")
else:
print("F")
|
result = []
while True:
(m, f, r) = [int(i) for i in input().split()]
sum = m + f
if m == f == r == -1:
break
if m == -1 or f == -1:
result.append('F')
elif sum >= 80:
result.append('A')
elif sum >= 65:
result.append('B')
elif sum >= 50:
result.append('C')
elif sum >= 30:
if r >= 50:
result.append('C')
else:
result.append('D')
else:
result.append('F')
[print(result[i]) for i in range(len(result))]
| 1 | 1,225,859,601,100 | null | 57 | 57 |
# get input from user and convert in to int
current_temp = int(input())
# Check that the restriction per task instruction is met
if (current_temp <= 40) and (current_temp >= -40):
# Check if current_temp is greater than or equal to 30
if current_temp >= 30:
print("Yes")
else:
print("No")
|
ondo = int(input())
if 30 <= ondo:
print("Yes")
else:
print("No")
| 1 | 5,757,511,594,978 | null | 95 | 95 |
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = int(input())
diff = (a[1]-b[1])*t # 1秒ごとに縮まる
adiff = abs(a[0]-b[0]) # 元々の差
if diff >= adiff:
print('YES')
else:
print('NO')
|
count = 0
while True:
count+=1
a = int(input())
if a == 0:
break
print("Case %d: %d" % (count, a))
| 0 | null | 7,867,309,230,848 | 131 | 42 |
N, M, X = map(int,input().split())
C = []
A = []
for i in range(N):
ca = list(map(int,input().split()))
C.append(ca[0])
A.append(ca[1:])
INF = 10**18
ans = INF
for mask in range(1<<N):
skill = [0 for i in range(M)]
cost = 0
for i in range(N):
if mask&(1<<i):
cost += C[i]
for j in range(M):
skill[j] += A[i][j]
if min(skill) >= X:
ans = min(ans,cost)
print(-1 if ans==INF else ans)
|
def main():
n, m, x = map(int, input().split(" "))
ca =[]
a = []
c = []
INF = 1e7
ans = INF
for i in range(n):
ca.append(list(map(int, input().split(" "))))
for i in range(n):
c.append(ca[i][0])
a.append(ca[i][1:])
for i in range(1<<n):
a_sum = [0]*m
c_sum = 0
for j in range(n):
if i >> j & 1 == 1:
for k in range(m):
a_sum[k] += a[j][k]
c_sum += c[j]
if min(a_sum) >= x and c_sum < ans:
ans = c_sum
if ans == INF:
print(-1)
else:
print(ans)
if __name__ == "__main__":
main()
| 1 | 22,219,716,091,738 | null | 149 | 149 |
n = int(input())
slimes = input()
fusion = [slimes[0]]
cnt = 0
for i in range(1,n):
if fusion[cnt] != slimes[i]:
fusion.append(slimes[i])
cnt += 1
print(cnt+1)
|
import sys
input = sys.stdin.readline
def marge(A, left, right, mid):
cnt = 0
n1 = mid - left
n2 = right - mid
L = [0] * (n1 + 1)
R = [0] * (n2 + 1)
for i in range(n1):
L[i] = A[left + i]
for i in range(n2):
R[i] = A[mid + i]
L[n1] = 10 ** 9 + 1
R[n2] = 10 ** 9 + 1
i = 0
j = 0
for k in range(left, right):
cnt += 1
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
return cnt
def margesort(A, left, right):
if left + 1 < right:
mid = (left + right) // 2
cnt1 = margesort(A, left, mid)
cnt2 = margesort(A, mid, right)
return cnt1 + cnt2 + marge(A, left, right, mid)
return 0
def main():
n = int(input())
A = list(map(int, input().split()))
cnt = margesort(A, 0, n)
print(' '.join(list(map(str, A))))
print(cnt)
if __name__ == '__main__': main()
| 0 | null | 85,003,472,334,688 | 293 | 26 |
n, m, l = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [list(map(int, input().split())) for _ in range(m)]
for i in range(n):
for j in range(l):
print(sum(a[i][k] * b[k][j] for k in range(m)), end='')
if j != l - 1:
print(' ', end='')
print('')
|
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,452,904,600,758 | null | 60 | 60 |
K = int(input())
verbose = False
path = set()
a = 0
step = 0
while True:
step += 1
a = (a*10 + 7) % K
if verbose: print (step, ':', a)
if a == 0:
print (step)
break
if a in path:
print ('-1')
break
path.add(a)
|
a=int(input())
b=0
c=int(a**(1/2))
for i in range(-1000,1000):
for j in range(-1000,1000):
if((i**5)-(j**5)==a):
b=1
break
if(b==1):
break
print(i,j)
| 0 | null | 15,735,198,535,518 | 97 | 156 |
N = int(input())
X_bin = input()
#N = 10**5
#X_bin = '1' * N
X_int = int(X_bin, 2) # bin => int
def calc_bin_cnt(next_int):
if next_int == 0:
return 0
next_bin = bin(next_int)[2:]
# popcount
cnt = 0
for i in next_bin:
if i == '1':
cnt += 1
return cnt
def calc_ans(next_int, cnt=None):
if next_cnt == 0:
return 0
if next_int == 0:
return 1
if cnt is None:
cnt = calc_bin_cnt(next_int)
next_int = next_int % cnt
if next_int > 0:
ans = calc_ans(next_int) + 1
else:
ans = 1
return ans
X_cnt = calc_bin_cnt(X_int)
f_p = X_int % (X_cnt+1)
if X_cnt-1 == 0:
f_m = 0
else:
f_m = X_int % (X_cnt-1)
for i in range(N):
if X_bin[i] == '1':
next_cnt = X_cnt - 1
if next_cnt == 0:
next_int = 0
else:
next_int = f_m - pow(2, (N-i-1), next_cnt) # マイナスでも正しく求まる?
else:
next_cnt = X_cnt + 1
next_int = f_p + pow(2, (N-i-1), next_cnt)
print(calc_ans(next_int, next_cnt))
#calc_ans(next_cnt, next_cnt)
|
def solve():
N = int(input())
X = input()
X_10 = int(X,2)
r = X.count("1")
r0 = r-1
r1 = r+1
ans = []
s0 = X_10 % r0 if r != 1 else None
s1 = X_10 % r1
for i in range(N):
if X[i] == '0':
ans.append(f((s1 + pow(2,N-1-i,r1)) % r1))
else:
if r0 == 0:
ans.append(0)
else:
ans.append(f((s0 - pow(2,N-1-i,r0)) % r0))
print(*ans, sep='\n')
def f(N):
cnt = 1
while N != 0:
N = N % popcount(N)
cnt += 1
return cnt
def popcount(N):
b = bin(N)
cnt = 0
for i in range(2,len(b)):
if b[i] == '1':
cnt += 1
return cnt
if __name__ == '__main__':
solve()
| 1 | 8,201,600,655,328 | null | 107 | 107 |
def prime_factorization(n):
"""do prime factorization using trial division
Returns:
[[prime1,numbers1],[prime2,numbers2],...]
"""
res = []
for i in range(2,int(n**0.5)+1):
if n%i==0:
cnt=0
while n%i==0:
cnt+=1
n//=i
res.append([i,cnt])
if n!=1:
res.append([n,1])
return res
def main():
import sys
input = sys.stdin.readline
N = int(input())
prime_factors = prime_factorization(N)
ans = 0
for p in prime_factors:
i = 1
while i <= p[1]:
ans += 1
N /= p[0]**i
p[1] -= i
i += 1
print(ans)
if __name__ == '__main__':
main()
|
N = int(input())
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
ans = 0
soinsu_list = factorization(N)
#print(soinsu_list)
for i in range(len(soinsu_list)):
cnt = 0
while soinsu_list[i][0] != 1:
cnt += 1
soinsu_list[i][1] -= cnt
if soinsu_list[i][1] < 0:
cnt -= 1
break
ans += cnt
print(ans)
| 1 | 16,910,954,660,110 | null | 136 | 136 |
x,y = map(int,input().split())
def point(a):
if a == 1:
return 300000
elif a == 2:
return 200000
elif a == 3:
return 100000
else:
return 0
c = point(x)
b = point(y)
if x == 1 and y == 1:
print(1000000)
else:
print(c+b)
|
X, Y = map(int, input().split())
award = [300000, 200000, 100000]
ans = 0
if X <= 3:
ans += award[X-1]
if Y <= 3:
ans += award[Y-1]
if X == 1 and Y == 1:
ans += 400000
print(ans)
| 1 | 140,409,578,515,602 | null | 275 | 275 |
def myAnswer(N:int,A:int,B:int) -> int:
ans = 0
BN = N - B
A1 = A - 1
while True:
if((B - A) % 2== 0):
ans += (B - A)//2
break
elif(A == 1):
ans += 1
B -= 1
elif(B == N):
ans += 1
A += 1
else:
if(BN > A1):
ans +=A1
B -= A1
A = 1
else:
ans += BN
A += BN
B = N
return ans
def modelAnswer():
tmp=1
def main():
N,A,B = map(int,input().split())
print(myAnswer(N,A,B))
if __name__ == '__main__':
main()
|
l=map(str,raw_input().split())
chk=[]
op='-+*'
while len(l):
k=l.pop(0)
if k in op:
b=chk.pop()
a=chk.pop()
chk.append(str(eval(a+k+b)))
else:
chk.append(k)
print chk[0]
| 0 | null | 54,647,688,388,058 | 253 | 18 |
n = int(input())
c = []
for i in range(n):
c.append(input())
ac = c.count("AC")
wa = c.count("WA")
tle = c.count("TLE")
re = c.count("RE")
print("AC x", ac)
print("WA x", wa)
print("TLE x", tle)
print("RE x", re)
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
from collections import deque
def main():
n, *a = map(int, read().split())
a.sort(reverse=True)
a = deque(a)
circle_joined = deque()
next_score = a.popleft()
r = 0
flag = False
while a:
circle_joined.append(a.popleft())
if flag:
next_score = circle_joined.popleft()
r += next_score
flag = False
else:
r += next_score
flag = True
print(r)
if __name__ == '__main__':
main()
| 0 | null | 9,023,010,874,260 | 109 | 111 |
n=int(input())
ans=10**12
d=2
while d<=n**(1/2):
if n%d==0:
ans=min(ans,d+n//d-2)
d+=1
if ans==10**12:
print(n-1)
exit()
print(ans)
|
import sys
n = int(input())
ans = float("inf")
flag = 0
for i in range(2,int(n**(1/2))+1):
if n%i == 0:
ans = min(ans, i+(n//i)-2)
flag = 1
if flag:
print(ans)
else:
print(n-1)
| 1 | 160,767,720,745,870 | null | 288 | 288 |
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools as fts
import itertools as its
import math
import sys
INF = float('inf')
def solve(N: int, K: int, h: "List[int]"):
return len([x for x in h if x >= K])
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
K = int(next(tokens)) # type: int
h = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
print(f'{solve(N, K, h)}')
if __name__ == '__main__':
main()
|
import math
import sys
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
n = inp()
print (math.pi * 2 * n)
| 0 | null | 105,172,500,934,642 | 298 | 167 |
#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())
H = I()
def monster(n):
if n == 1:
return 1
return 1 + 2*(monster(n//2))
print(monster(H))
|
h = int(input())
ans = 0
n = 0
while h != 0:
ans += 2**n
n += 1
h = h//2
print(ans)
| 1 | 79,898,263,134,810 | null | 228 | 228 |
seen = [0,0,0,0,0,0,0,0,0]
seen[0],seen[1],seen[2] = (map(int,input().split()))
seen[3],seen[4],seen[5] = (map(int,input().split()))
seen[6],seen[7],seen[8] = (map(int,input().split()))
over = "No"
N = int(input())
for x in range(N):
num = int(input())
if num in seen:
seen[seen.index(num)] = "O"
if seen[0] == "O":
if seen[1] == "O" and seen[2] == "O":
over = "Yes"
if seen[3] == "O" and seen[6] == "O":
over = "Yes"
if seen[4] == "O" and seen[8] == "O":
over = "Yes"
if seen[8] == "O":
if seen[6] == "O" and seen[7] == "O":
over = "Yes"
if seen[2] == "O" and seen[5] == "O":
over = "Yes"
if seen[4] == "O":
if seen[6] == "O" and seen[2] == "O":
over = "Yes"
if seen[1] == "O" and seen[7] == "O":
over = "Yes"
if seen[3] == "O" and seen[5] == "O":
over = "Yes"
print(over)
|
board=[0,0,0,0,0,0,0,0,0]
board[0],board[1],board[2] = map(int,input().split())
board[3],board[4],board[5] = map(int,input().split())
board[6],board[7],board[8] = map(int,input().split())
for _ in range(int(input())):
x = int(input())
if x in board:
board[board.index(x)] = "X"
found = "No"
if board[0] == "X":
if board[1] == "X" and board[2] == "X":
found = "Yes"
elif board[4] == "X" and board[8] == "X":
found = "Yes"
elif board[3] == "X" and board[6] == "X":
found = "Yes"
if board[8] == "X":
if board[5] == "X" and board[2] == "X":
found = "Yes"
elif board[7] == "X" and board[6] == "X":
found = "Yes"
if board[4] == "X":
if board[1] == "X" and board[7] == "X":
found = "Yes"
elif board[3] == "X" and board[5] == "X":
found = "Yes"
elif board[2] == "X" and board[6] == "X":
found = "Yes"
print(found)
| 1 | 59,943,454,781,000 | null | 207 | 207 |
a, b = input().split(" ")
a = int(a)
b = int(b)
if a-2*b < 0:
print(0)
else:
print(a-2*b)
|
import sys
sys.setrecursionlimit(10**6)
a,b = map(int, input().split())
if 2*b > a:
print(0)
else:
print(a-2*b)
| 1 | 166,809,688,195,042 | null | 291 | 291 |
def main():
a, b, c, d = map(int, input().split())
ans = max(max(a*c, a*d), max(b*c, b*d))
print(ans)
if __name__ == '__main__':
main()
|
import math
import collections
K = int(input())
S = input()
L = list(S)
if len(L) <= K:
print(S)
else:
M = L[:K]
print(''.join(M)+'...')
| 0 | null | 11,315,806,175,728 | 77 | 143 |
k = int(input())
def gcd1 (a, b):
while True:
if (a < b):
a, b = b, a
c = a%b
if (c == 0):
return (b)
else:
a = b
b = c
count = 0
for i in range(k):
for j in range(k):
tmp = gcd1(i + 1, j + 1)
if (tmp == 1):
count = count + k
else:
for l in range(k):
tmp2 = gcd1(tmp, l + 1)
count = count + tmp2
print(count)
|
a,b,c,d=map(int, input().split())
if b<0 and c>0:
print(c*b)
elif d<0 and a>0:
print(d*a)
elif b>=0 or d>=0:
print(max(b*d,a*c))
else:
print(a*c)
| 0 | null | 19,187,722,620,528 | 174 | 77 |
a, b = map(int, input().split())
def gcd(a, b):
if a > b:
a, b = b, a
if b % a == 0:
return a
else:
return gcd(a, b % a)
print(gcd(a, b))
|
a,b=sorted(list(map(int, input().split())))
m=b%a
while m>=1:
b=a
a=m
m=b%a
print(a)
| 1 | 7,739,327,850 | null | 11 | 11 |
MOD = 10**9 + 7
def main():
N, K = map(int , input().split())
A = list(map(int, input().split()))
if max(A) < 0 and K % 2 == 1:
A.sort(reverse = True)
ans = 1
for i in range(K):
ans = ans*A[i]%MOD
print(ans%MOD)
elif K == N:
ans = 1
for i in A:
ans = ans*i%MOD
print(ans%MOD)
else:
A_p = []
A_m = []
for i in A:
if i >= 0:A_p.append(i)
else:A_m.append(abs(i))
A_p.sort(reverse = True)
A_m.sort(reverse = True)
num = 0
ans = 1
posi_p = 0
posi_m = 0
sign = 0
while (num < K):
if posi_m == len(A_m) and posi_p < len(A_p):
ans = ans*A_p[posi_p]%MOD
posi_p += 1
num += 1
elif posi_p == len(A_p) and posi_m < len(A_m):
ans = ans*A_m[posi_m]%MOD
sign += 1
posi_m += 1
num += 1
elif A_p[posi_p] >= abs(A_m[posi_m]):
ans = ans*A_p[posi_p]%MOD
posi_p += 1
num += 1
else:
ans = ans*A_m[posi_m]%MOD
sign += 1
posi_m += 1
num += 1
if num == K and sign % 2 == 1:
if K == 1:
ans = A_p[0]
elif posi_m == len(A_m):
ans = ans*pow(A_m[posi_m-1], MOD-2, MOD) % MOD
ans = ans*A_p[posi_p] % MOD
elif posi_p == len(A_p):
ans = ans*pow(A_p[posi_p-1], MOD-2, MOD)
ans = ans*A_m[posi_m] % MOD
elif A_p[posi_p]*A_p[posi_p-1] >= A_m[posi_m]*A_m[posi_m-1]:
ans = ans*pow(A_m[posi_m-1], MOD-2, MOD)%MOD
ans = ans*A_p[posi_p] % MOD
else:
if posi_p != 0:
ans = ans*pow(A_p[posi_p-1], MOD-2, MOD)%MOD
ans = ans*A_m[posi_m]%MOD
else:
ans = ans*pow(A_m[posi_m-1], MOD-2, MOD)%MOD
ans = ans *A_p[posi_p]%MOD
print(ans%MOD)
if __name__ == "__main__":
main()
|
A=list(input())
n=int(input())
tmp=0
if len(set(A)) == 1:
print(len(A)*n//2)
exit()
sum_n=0
tmp3=0
while A[0] == A[tmp3]:
tmp3+=1
sum_n+=tmp3
tmp3=0
while A[-1] == A[-1-tmp3]:
tmp3+=1
sum_n+=tmp3
for i in range(len(A)-1):
if A[i] == A[i+1]:
A[i+1]="1"
tmp+=1
tmp2=0
if A[0] == A[-1]:
tmp2=n-1
if sum_n%2 == 1:
tmp2-=n-1
print(tmp*n+tmp2)
| 0 | null | 92,188,289,962,330 | 112 | 296 |
a = int(input())
print(int(a + (a * a) + (a * a * a)))
|
a = int(input())
ans = 0
for i in range(1, 4):
ans += (a ** i)
print(ans)
| 1 | 10,270,500,823,690 | null | 115 | 115 |
n,k=map(int,input().split())
a=list(map(int,input().split()))
l,r=10**9,0
while l-r>1:
t=(l+r)//2
if sum((i-1)//t for i in a)>k:
r=t
else:
l=t
print(l)
|
n,a,b=map(int, input().split())
if a==0:
print(0)
elif b==0:
print(n)
else:
quo=n//(a+b)
#商
if n%(a+b)==0:
rem=0
elif 1<=n%(a+b)<=a:
rem=n%(a+b)
else:
rem=a
print(quo*a+rem)
| 0 | null | 30,878,186,184,592 | 99 | 202 |
n = int(input())
c = 0
for _ in range(n):
r = [int(e) for e in input().split(" ")]
if(r[0] == r[1]):
c += 1
else:
c = 0
if(c == 3):
print("Yes")
break
else:
print("No")
|
n, m = map(int, input().split())
p = []
s = []
for i in range(m):
p_i, s_i = input().split()
p.append(int(p_i))
s.append(s_i)
correct = [0]*n
penalty = [0]*n
for i in range(m):
no = p[i]
if correct[no-1] == 1:
continue
elif s[i] == 'WA':
penalty[no-1] += 1
elif s[i] == 'AC':
correct[no-1] = 1
pen = 0
for i in range(n):
if correct[i] == 1:
pen += penalty[i]
print(sum(correct), pen)
| 0 | null | 47,652,966,504,998 | 72 | 240 |
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()
|
def main():
from functools import reduce
def a_comb_mod(n, r):
mod = 1000000007
r = min(n-r,r)
if r == 0: return 1
numer = reduce(lambda x, y: x * y % mod, range(n, n - r, -1), 1)
denom = reduce(lambda x, y: x * y % mod, range(1,r + 1), 1)
denom_inv = pow(denom, mod - 2, mod)
return numer * denom_inv % mod
n, a, b = list(map(int, input().split()))
mod = 1000000007
print((pow(2, n, mod) - 1 - a_comb_mod(n, a) - a_comb_mod(n, b)) % mod)
if __name__ == '__main__':
main()
| 1 | 66,025,735,746,458 | null | 214 | 214 |
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()
n = k()
a = l()
sum = 1000
for i in range(n-1):
if a[i] > a[i+1]:
xx = a[cnt:i+1]
b = sum//min(xx)
sum += (max(xx)-min(xx))*b
cnt = i+1
xx = a[cnt:]
b = sum//min(xx)
sum += (max(xx)-min(xx))*b
print(sum)
|
import math
a, b, c = map(float, input().split())
r = math.radians(c)
S = (a * b * math.sin(r)) / 2
print(S)
d = (a**2 + b**2 - 2 * a * b * math.cos(r))
d = math.sqrt(d)
L = a + b + d
print(L)
h = 2 * S / a
print(h)
| 0 | null | 3,789,704,498,580 | 103 | 30 |
A, B, C = list(map(int, input().split()))
s = set([A, B, C])
if len(s) == 1 or len(s) == 3:
print('No')
else:
print('Yes')
|
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 | 38,326,163,709,190 | 216 | 110 |
X,N=map(int,input().split())
p=list(map(int,input().split()))
i=0
j=0
while X+i in p:
i+=1
while X-j in p:
j+=1
if i>j:
print(X-j)
elif i<j:
print(X+i)
else:
print(min([X+i,X-j]))
|
from collections import deque
n = int(input())
d = deque()
for i in range(n):
cmd = input().split()
if cmd[0] == 'insert':
d.appendleft(cmd[1])
elif cmd[0] == 'delete':
try:
d.remove(cmd[1])
except:
pass
elif cmd[0] == 'deleteFirst':
d.popleft()
elif cmd[0] == 'deleteLast':
d.pop()
print(' '.join(d))
| 0 | null | 6,999,941,626,340 | 128 | 20 |
H,N = map(int,input().split())
i = map(int,input().split())
if sum(i) >= H :
print("Yes")
else :
print("No")
|
h,n = (int(a) for a in input().split())
a = list(map(int,input().split()))
if sum(a) >= h :
print("Yes")
else : print("No")
| 1 | 77,726,972,248,210 | null | 226 | 226 |
N = int(input())
A = list(map(int,input().split()))
SUM = sum(A)
half = SUM//2
acc = 0;dif = SUM
for i in range(N):
acc += A[i]
dif = min(dif,abs(SUM-2*acc))
print(dif)
|
K = int(input())
S = input()
if len(S) <= K:
print(S)
else:
print("{0}...".format(S[0:K]))
| 0 | null | 80,901,099,316,658 | 276 | 143 |
# import time
N,P = list(map(int,input().split()))
S = input()
if P == 2:
c = 0
for i in range(N):
u = int(S[i])
if u % 2 == 0:
c += i+1
print(c)
elif P == 5:
c = 0
for i in range(N):
u = int(S[i])
if u % 5 == 0:
c += i+1
print(c)
else:
U = [0]
a = 0
t = 1
for i in range(N):
t %= P
a += int(S[-i-1])*t
a %= P
t *= 10
U.append(a)
U.append(10001)
# print(U)
# t3 = time.time()
c = 0
"""
for i in range(P):
m = U.count(i)
c += m*(m-1)//2
print(c)
"""
U.sort()
# print(U)
idx = 0
q = -1
for i in range(N+2):
if q != U[i]:
q = U[i]
m = i - idx
idx = i
c += m*(m-1)//2
print(c)
# t4 = time.time()
# print(t4-t3)
# 10032
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
N, P = map(int, readline().split())
S = [int(i) for i in readline().strip()[::-1]]
ans = 0
if P == 2 or P == 5:
for i, s in enumerate(S):
if s % P == 0:
ans += N - i
print(ans)
exit()
a = {}
a[0] = 1
t = 0
x = 1
for s in S:
t += s * x
t %= P
if t in a:
a[t] += 1
else:
a[t] = 1
x *= 10
x %= P
ans = 0
for v in a.values():
ans += v * (v-1) // 2
print(ans)
if __name__ == "__main__":
main()
| 1 | 58,322,542,609,440 | null | 205 | 205 |
x = 0
while x == 0:
m = map(int,raw_input().split())
if m[0] == 0 and m[1] == 0:
break
print "#" * m[1]
for i in xrange(m[0]-2):
print "#" + "." * (m[1]-2) + "#"
print "#" * m[1]
print ""
|
while True:
H, W = map(int, input().split())
if not(H or W):
break
print('#' * W)
for i in range(H-2):
print('#' + '.' * (W - 2) + '#')
print('#' * W, end='\n\n')
| 1 | 820,326,608,010 | null | 50 | 50 |
a, b = map(str, input().split())
a = int(a)
c, d = map(int, b.split('.'))
b = c * 100 + d
b *= a
print(int(("00" + str(b))[:-2]))
|
h, n = map(int, input().split())
items = [tuple(map(int, input().split())) for _ in range(n)]
#dp[i][j] := i番目までの物でjの価値を実現するのに必要な最小コスト
dp = [[0] * (h+1) for _ in range(n+1)]
for j in range(1, h+1):
dp[0][j] = float("inf")
for i in range(n):
for j in range(h+1):
if j < items[i][0]:
dp[i+1][j] = min(dp[i][j], items[i][1])
else:
dp[i+1][j] = min(dp[i][j], dp[i+1][j-items[i][0]] + items[i][1])
print(dp[n][h])
| 0 | null | 48,540,648,156,000 | 135 | 229 |
h,*s=open(0)
h,w,k,*m=map(int,h.split())
b=512
while b:
b-=1;r=t=j=0;d=[0]*h
while w-j:
i=c=0
while h-i:
d[c]+=s[i][j]>'0';f=d[c]>k
if(t<j)&f:r+=1;t=j;d=[0]*h;break
r+=h*w*f;c+=b>>i&1;i+=1
else:j+=1
m+=r+bin(b).count('1'),
print(min(m))
|
nm = list(map(lambda x:int(x),input().split(" ")))
a = list()
b = list()
count = nm[0]
while count > 0:
a += list(map(lambda x:int(x), input().split(" ")))
count -= 1
count = nm[1]
while count > 0:
b += {int(input())}
count -= 1
for m in range(nm[0]):
c = 0
for k in range(nm[1]):
c += a[k+m*nm[1]]*b[k]
print(c)
| 0 | null | 24,762,800,616,358 | 193 | 56 |
def main():
mod = 1000000007
n = int(input())
cnt = [0] * (n + 2)
cnt[0] = 3
res = 1
for x in input().split():
v = int(x)
res *= cnt[v] - cnt[v + 1]
res %= mod
cnt[v + 1] += 1
print(res)
main()
|
import sys
n=int(input())
A=list(map(int,input().split()))
p=10**9+7
status=[1,0,0]
ans=3
if A[0]!=0:
print(0)
sys.exit()
for i in range(1,n):
count=status.count(A[i])
if count==0:
print(0)
sys.exit()
ans=(ans*count)%p
status[status.index(A[i])]+=1
print(ans)
| 1 | 130,624,168,800,826 | null | 268 | 268 |
from math import sqrt
x = int(input())
while True:
f = 1
s = int(sqrt(x))
for i in range(2, s+1):
if x % i == 0:
f = 0
break
if f == 1:
print(x)
break
x += 1
|
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
import math
def is_prime(n):
if n == 1:
return False
for k in range(2, int(math.sqrt(n)) + 1):
if n % k == 0:
return False
return True
def main():
x = int(input())
for i in range(x,100004):
if is_prime(i)==True:
print(i)
break
if __name__=="__main__":
main()
| 1 | 105,836,403,279,348 | null | 250 | 250 |
import collections
N, M = map(int, input().split())
WA_CNT = {}
CLEAR = {}
for i in range(M):
P, S = input().split()
if P in CLEAR:
continue
if S == "AC":
CLEAR[P] = 1
continue
if not P in WA_CNT:
WA_CNT[P] = 0
WA_CNT[P] += 1
num = len(CLEAR)
try_num = 0
for i in CLEAR:
if i in WA_CNT:
try_num += WA_CNT[i]
print("{} {}".format(num, try_num))
|
# D
N = int(input())
A = list(map(int,input().split()))
next_number = 1
cnt = 0
for a in A:
if a == next_number:
next_number += 1
else:
cnt += 1
if cnt == len(A):
print('-1')
else:
print(cnt)
| 0 | null | 103,784,867,505,782 | 240 | 257 |
h,w,k=map(int,input().split())
S=[input() for i in range(h)]
LIS=[]
def saiki(x,st):
if x==h-1:
LIS.append(st)
return
else:
saiki(x+1,st+st[-1])
saiki(x+1,st+str(int(st[-1])+1))
saiki(0,"0")
DIC1={c:0 for c in "0123456789"}
DIC2={c:0 for c in "0123456789"}
ans=10**9
for cod in LIS:
for ele in DIC1:
DIC1[ele]=0
cnt=int(cod[-1])
end=False
for i in range(w):
for ele in DIC2:
DIC2[ele]=0
for q in range(h):
if S[q][i]=="1":
DIC2[cod[q]]+=1
if max(DIC2.values())>k:
end=True
break
flg=True
for ele in DIC1:
if DIC1[ele]+DIC2[ele]>k:
flg=False
break
if flg:
for ele in DIC1:
DIC1[ele]+=DIC2[ele]
else:
for ele in DIC1:
DIC1[ele]=DIC2[ele]
cnt+=1
if end:
continue
ans=min(ans,cnt)
#print(cod,cnt)
print(ans)
|
from collections import defaultdict
from itertools import product
H,W,K = map(int,input().split())
S = [input() for i in range(H)]
C = [[int(S[i][k]) for i in range(H)] for k in range(W)]
answer = H*W #出力がこれを超えることはない
for X in product([False,True],repeat = H-1):
M = [[0]]
ans = sum(X)
if ans > answer:#初期値がanswerよりも大きかったら考える必要がない
continue
for i,x in enumerate(X):#配列Mの作成
if x:
M.append([])
M[-1].append(i+1)
D = [0]*len(M)
for c in C:
for k,m in enumerate(M):
D[k] += sum(c[i] for i in m)#k番目の要素に足していく
#Dにどんどん代入することによってどの列まで足すことができるか算出することができる
if any(d>K for d in D):#一つでもKを超えていたら
ans += 1
if ans >answer:
break
D = [sum(c[i] for i in m) for m in M]#超えた行について再び調査
if any(d>K for d in D):
ans = answer + 1
#デフォルトanswerの結果より高い値にしてこの結果が出力にならないように設定する
break
answer = min(answer,ans)#あるXに対してanswerを算出(更新)
print(answer)
| 1 | 48,644,408,470,918 | null | 193 | 193 |
def plus(x):
yen = 0
if x < 4:
yen = yen + 100000
if x < 3:
yen = yen + 100000
if x < 2:
yen = yen + 100000
return yen
x, y = map(int, input().split())
res = plus(x) + plus(y)
if x == 1 and y == 1:
res = res + 400000
print(res)
|
x, y = map(int, input().split())
ans = max(4 - x, 0) + max(4 - y, 0)
print(ans * 10**5 if ans != 6 else 10**6)
| 1 | 140,588,861,248,540 | null | 275 | 275 |
from collections import Counter
def mpow(a,b,mod):
ret=1
while b>0:
if b&1:
ret=(ret*a)%mod
a=(a*a)%mod
b>>=1
return ret
n,p=map(int,input().split())
s=[int(i) for i in input()]
if p==2 or p==5:
ans=0
for i in range(n):
if s[i]%p==0:
ans+=i+1
print(ans)
else:
ans=0
d=Counter()
d[0]+=1
num=0
for i in range(n-1,-1,-1):
num=(num+s[i]*mpow(10,n-1-i,p))%p
ans+=d[num]
d[num]+=1
print(ans)
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
N, P = map(int, readline().split())
S = [int(i) for i in readline().strip()[::-1]]
ans = 0
if P == 2 or P == 5:
for i, s in enumerate(S):
if s % P == 0:
ans += N - i
print(ans)
exit()
a = {}
a[0] = 1
t = 0
x = 1
for s in S:
t += s * x
t %= P
if t in a:
a[t] += 1
else:
a[t] = 1
x *= 10
x %= P
ans = 0
for v in a.values():
ans += v * (v-1) // 2
print(ans)
if __name__ == "__main__":
main()
| 1 | 58,319,704,353,472 | null | 205 | 205 |
import math
n = int(input())
f = list(map(int,input().split()))
f.sort()
ans = 0
for i in range(1,n):
ans += f[n-math.floor(i/2)-1]
print(ans)
|
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
ans = 0
for i in range(N-1):
if i == 0:
ans += A[i]
else:
ans += A[1+(i-1)//2]
print(ans)
| 1 | 9,166,799,120,430 | null | 111 | 111 |
n,a,b = map(int,input().split())
if (b-a)%2==0:
print((b-a)//2)
else:
m = min(b-1,n-a)
M = min(a-1,n-b)+(b-a-1)//2+1
print(min(m,M))
|
n,a,b = map(int,input().split())
if (b-a) % 2 == 0:
ans = (b-a) // 2
else:
if a-1 < n-b:
ans = b-1
x = b-(a-1)-1
ans = min(ans, a + (x-1) // 2)
else:
ans = n-a
x = a + (n-b) + 1
ans = min(ans, (n-b) + 1 + (n-x) // 2)
print(ans)
| 1 | 109,368,248,837,342 | null | 253 | 253 |
input()
S=input()
while True:
x=''
ans=''
for i in S:
if (x==''):
x=i
continue
if x!=i:
ans+=x
x=i
ans+=x
if ans==S:
break
else:
S=ans
print(len(ans))
|
n=int(input())
ans=0
m=1
while n>1:
n=n//2
ans+=m
m*=2
print(ans+m)
| 0 | null | 124,811,830,929,020 | 293 | 228 |
INF = int(10e20)
def main():
N, K = tuple([int(_x) for _x in input().split()])
minval = N
sub = N // K - 5
if sub > 0:
N = N - K * sub
for i in range(20):
N = abs(N - K)
minval = min(N, minval)
print(minval)
main()
|
l=input("").split(" ")
n=int(l[0])
k=int(l[1])
s=n%k
ss=k-s
if(s<ss):
print(s)
else:
print(ss)
| 1 | 39,390,062,319,418 | null | 180 | 180 |
while(1):
n = input()
if n == '-':
exit()
m = int(input())
for i in range(m):
h = int(input())
n = n[h:] + n[0:h]
print(n)
|
N, M, X = map(int, input().split())
CA = [list(map(int, input().split())) for _ in range(N)]
sum_money = float("inf")
for i in range(2 ** N):
money = 0
algorithm = [0]*M
for j in range(N):
if (i >> j) & 1 == 1:
money += CA[j][0]
for k in range(M):
algorithm[k] += CA[j][k+1]
check = True
for l in algorithm:
if l < X:
check = False
if check:
sum_money = min(sum_money, money)
print(sum_money if sum_money != float("inf") else -1)
| 0 | null | 12,086,970,628,200 | 66 | 149 |
N=int(input())
S=list(map(str, input()))
li=['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']
answer=[]
for i in range(len(S)):
for j in range(len(li)):
if S[i]==li[j] and j<len(li)-N:
answer.append(li[j+N])
elif S[i]==li[j] and j>=len(li)-N:
answer.append(li[j+N-len(li)])
print("".join(answer))
|
#coding:utf-8
m = 0
f = 0
r = 0
while m + f + r >-3:
m , f, r =[int(i) for i in input().rstrip().split(" ")]
if m+f+r == -3:
break
if m == -1:
print("F")
elif f == -1:
print("F")
elif m+f <30:
print("F")
elif m+f <50:
if r>=50:
print("C")
else:
print("D")
elif m+f <65:
print("C")
elif m+f <80:
print("B")
else:
print("A")
| 0 | null | 67,715,984,798,858 | 271 | 57 |
W, c = input(), 0
for line in iter(input, 'END_OF_TEXT'):
for Ti in line.lower().split():
if W == Ti:
c +=1
print(c)
|
import sys
from collections import deque
n,q = map(int,input().split())
f = lambda n,t: (n,int(t))
queue = deque(f(*l.split()) for l in sys.stdin)
t = 0
while queue:
name,time = queue.popleft()
t += min(q, time)
if time > q:
queue.append((name, time-q))
else:
print(name,t)
| 0 | null | 955,766,963,866 | 65 | 19 |
n = int(input())
s = input()
if len(s) > n:
print(s[:n] + '...')
else:
print(s)
|
n = int(input())
txt = input()
print(txt[:n]+"..." if bool(txt[n:]) else txt)
| 1 | 19,599,328,350,668 | null | 143 | 143 |
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
max_a = max(a)
mod = 10**9 + 7
inverse = [1] * (max_a + 1)
for i in range(2, max_a + 1):
inverse[i] = -inverse[mod % i] * (mod // i) % mod
lcm = 1
for i in range(n):
lcm = lcm * a[i] // gcd(lcm, a[i])
lcm %= mod
sum_b = 0
for i in range(n):
sum_b = (sum_b + lcm * inverse[a[i]]) % mod
print(sum_b)
|
from functools import reduce
from math import gcd
MOD = 10 ** 9 + 7
_ = int(input())
la = list(map(int, input().split()))
def inv(a):
return pow(a, MOD - 2, MOD)
def lcm(a, b):
return a * b // gcd(a, b)
def addmod(a, b):
return (a + b) % MOD
l = reduce(lcm, la) % MOD
answer = reduce(addmod, (l * inv(a) for a in la), 0)
print(answer)
| 1 | 87,932,966,620,348 | null | 235 | 235 |
import sys
n = input()
for a,b,c in map(lambda x: sorted(map(int,x.split())),sys.stdin.readlines()):
print("YES" if a*a+b*b==c*c else "NO")
|
n,u,v=map(int,input().split())
tree=[[]for _ in range(n)]
for i in range(n-1):
a,b = map(int,input().split())
tree[a-1].append(b-1)
tree[b-1].append(a-1)
va=[-1]*n
q=[v-1]
va[v-1]=0
while q:
x=q.pop()
for j in tree[x]:
if va[j]==-1:
q.append(j)
va[j]=va[x]+1
q=[u-1]
vt=[-1]*n
vt[u-1]=0
ans=0
while q:
x=q.pop()
ans=max(ans,va[x])
for j in tree[x]:
if vt[j]==-1:
if vt[x]+1<va[j]:
q.append(j)
vt[j]=vt[x]+1
elif vt[x]+1==va[j]:
vt[j]=vt[x]+1
print(ans-1)
| 0 | null | 58,923,094,063,360 | 4 | 259 |
def main():
n = int(input())
a = sorted(list(map(int,input().split())),reverse=True)
ans = a[0]
for i in range(3,n+1):
if i%2==0:
ans += a[i//2-1]
else:
ans += a[(i-1)//2]
print(ans)
if __name__ == "__main__":
main()
|
from collections import deque
n = int(input())
l = list(map(int,input().split()))
l.sort()
largest = l[-1]
que = deque(l)
cnt = n
ans = 0
while cnt > 0:
x = que.pop()
ans += x
cnt -= 1
if cnt != 0:
ans += x
cnt -= 1
print(ans-largest)
| 1 | 9,165,192,999,380 | null | 111 | 111 |
#python 3.7.1
N=int(input())
if (N%2)==0:
ans=N//2-1
else:
ans=N//2
print(ans)
|
N = int(input())
amari = N % 2
count = int( N // 2 )
print( count + amari )
| 0 | null | 106,219,554,238,332 | 283 | 206 |
H1, M1, H2, M2, K = map(int, input().split())
T1, T2 = (H1 * 60 + M1), (H2 * 60 + M2)
print("{}".format((T2 - K) - T1))
|
from collections import Counter
N=int(input())
S=input()
c=Counter(S+'RGB')
ans = (c['R']-1)*(c['G']-1)*(c['B']-1)
max_d = (N-3)//2+1
for d in range(1,max_d+1):
for i in range(N-2):
j = i+d
k = j+d
if k > N-1:break
if len(set([S[i],S[j],S[k]]))==3:
ans -= 1
print(ans)
| 0 | null | 27,168,275,475,744 | 139 | 175 |
from collections import deque
d=deque()
N=int(input())
for n in range(N):
a=input()
if a=="deleteFirst":
d.popleft()
elif a=="deleteLast":
d.pop()
else:
a,b=a.split()
if a=="insert":
d.appendleft(b)
elif a=="delete":
if d.count(b):
d.remove(b)
print(' '.join(list(d)))
|
from collections import deque
n = int(input())
Q= deque()
for _ in range(n):
str = input()
if str == "deleteFirst":
Q.popleft()
elif str == "deleteLast":
Q.pop()
else:
cmd,key = str.split()
if cmd == "insert":
Q.appendleft(key)
elif cmd == "delete":
try:
Q.remove(key)
except:
pass
print(" ".join(list(Q)))
| 1 | 47,803,337,750 | null | 20 | 20 |
from functools import reduce
n=int(input())
A=list(map(int, input().split()))
sumxor=reduce(lambda x,y:x^y,A)
for AA in A:
print(sumxor ^ AA)
|
n, x, y = map(int, input().split())
x -= 1
y -= 1
def main():
ans = {}
for i in range(1, n):
ans[i] = 0
for i in range(0, n - 1):
for j in range(i + 1, n):
ans[solve(i, j)] += 1
for k in range(1, n):
print(ans[k])
def solve(i, j):
"""
最短距離を計算する
O(1)
"""
dist = min(abs(i - j), abs(x - i) + abs(y - j) + 1, abs(y -i) + abs(x - j) + 1)
return dist
if __name__ == '__main__':
main()
| 0 | null | 28,132,547,556,216 | 123 | 187 |
# -*- coding: utf-8 -*-
S1 = 1
r = input()
R = int(r)
S2 = R ** 2
result = S2 / S1
print(int(result))
|
int = int(input())
print(int*int)
| 1 | 145,249,174,360,076 | null | 278 | 278 |
SN=[5,1,2,6]
WE=[4,1,3,6]
def EWSN(d):
global SN,WE
if d == "S" :
SN = SN[3:4] + SN[0:3]
WE[3] = SN[3]
WE[1] = SN[1]
elif d == "N":
SN = SN[1:4] + SN[0:1]
WE[3] = SN[3]
WE[1] = SN[1]
elif d == "E":
WE = WE[3:4] + WE[0:3]
SN[3] = WE[3]
SN[1] = WE[1]
elif d == "W":
WE = WE[1:4] + WE[0:1]
SN[3] = WE[3]
SN[1] = WE[1]
dice = list(map(int,input().split(" ")))
op = input()
for i in op:
EWSN(i)
print(dice[SN[1] - 1])
|
N = int(input())
ans = 0
for x in range(1, N + 1):
n = N // x
#ans += n * (2 * x + (n - 1) * x) // 2
ans += n * ( x + n * x) // 2
print(ans)
| 0 | null | 5,641,690,613,252 | 33 | 118 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.