code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,629B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
N, M = map(int, input().split())
coins = map(int, input().split())
dp = [0] + [50001 for i in range(N)]
for coin in coins:
for index in range(N-coin+1):
dp[index+coin] = min(dp[index+coin], dp[index]+1)
print(dp[N])
|
n, m = map(int, input().split())
C = sorted(tuple(map(int, input().split())))
dp = list(range(0, n+1))
for i in range(m):
c = C[i]
ndp = [50000] * (n+1)
for j in range(n+1):
if j < c:
ndp[j] = dp[j]
else:
ndp[j] = min(dp[j], ndp[j-c] + 1)
dp = ndp
print(ndp[-1])
| 1 | 139,039,845,396 | null | 28 | 28 |
import math
n = int(input())
values = list(map(int, input().split(' ')))
values.sort(reverse=True)
sum = 0
for i in range(1, n):
sum += values[math.floor(i/2)]
print(sum)
|
#coding:utf-8
import itertools
r = range(1,10)
for (x,y) in itertools.product(r,r):
print('{}x{}={}'.format(x,y,x*y))
| 0 | null | 4,619,917,214,158 | 111 | 1 |
i = 1
while True:
n = input()
if n != 0:
print 'Case %s: %s' % (str(i), str(n))
i = i + 1
else:
break
|
import sys
i=1
while True:
x = int( sys.stdin.readline() )
if 0 != x:
print( "Case {}: {}".format( i, x) )
else:
break
i += 1
| 1 | 477,853,180,540 | null | 42 | 42 |
i=map(int,raw_input().split())
if i[0]>i[1]:
print "a > b"
if i[0]<i[1]:
print "a < b"
if i[0]==i[1]:
print "a == b"
|
s = input()
n = len(s)
kotae = "x"*n
print(kotae)
| 0 | null | 36,454,806,042,980 | 38 | 221 |
n = int(input())
s=0
a = list(map(int, input().split()))
b = sum(a)
for i in range(n):
b -= a[i]
s += a[i]*b
s = s % ((10**9)+7)
print(s)
|
n = int(input())
a = list(map(int, input().split()))
length = len(a)
total = sum(a)
ans = 0
for i in range(0,length):
total -= a[i]
ans += (a[i] * total)
print(ans % (10**9 + 7))
| 1 | 3,808,176,362,382 | null | 83 | 83 |
import re
s = re.sub('(hi)+','',input())
print('No' if s else 'Yes')
|
n, W = map(int, input().split())
ab = [tuple(map(int, input().split()))for _ in range(n)]
ab.sort()
dp = [[0]*W for _ in range(n+1)]
for i in range(1, n+1):
w, v = ab[i-1]
for j in range(W):
if dp[i][j] < dp[i-1][j]:
dp[i][j] = dp[i-1][j]
if 0 <= j-w and dp[i][j] < dp[i-1][j-w]+v:
dp[i][j] = dp[i-1][j-w]+v
ans = 0
for i in range(n):
a, b = ab[i]
if ans < dp[i][W-1]+b:
ans = dp[i][W-1]+b
print(ans)
| 0 | null | 101,946,733,695,252 | 199 | 282 |
def main():
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
v = {0: 1}
n = [0]
r = 0
t = 0
for i, a in enumerate(A, 1):
if i >= K:
v[n[i - K]] -= 1
t += a
j = (t - i) % K
r += v.get(j, 0)
v[j] = v.get(j, 0) + 1
n.append(j)
return r
print(main())
|
import sys
input = sys.stdin.readline
from collections import deque
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = [0]
for a in A:
b = (B[-1] + (a-1)) % K
B.append(b)
ans = 0
dic = {}
for i, b in enumerate(B):
if b in dic:
dic[b].append(i)
else:
dic[b] = deque()
dic[b].append(i)
while len(dic[b]) > 0 and dic[b][0] <= i - K:
dic[b].popleft()
ans += len(dic[b])-1
print(ans)
| 1 | 137,620,998,166,708 | null | 273 | 273 |
H1,M1,H2,M2,K = map(int,input().split())
A1 = H1*60+M1
A2 = H2*60+M2
print(max(0,A2-A1-K))
|
h1, m1, h2, m2, k = list(map(int, input().split()))
if m2 < m1:
while m2 < m1:
h2 -= 1
m2 += 60
tm = m2 - m1
th = h2 - h1
if k > (th*60 + tm):
print (0)
else:
print(th*60 + tm - k)
| 1 | 17,960,273,730,630 | null | 139 | 139 |
s=input()
t=input()
count=0
for i in range(0,len(s)):
if(s[i]==t[i]):
continue
else:
count+=1
print(count)
|
while True:
a, op, b = input().split()
if(op == '+'):
print(int(a) + int(b))
elif(op == '-'):
print(int(a) - int(b))
elif(op == '*'):
print(int(a) * int(b))
elif(op == '/'):
print(int(a) // int(b))
else:
break
| 0 | null | 5,554,091,430,020 | 116 | 47 |
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)
|
a,b,c = map(int, input().split())
s =c-a-b
t = s**2 - 4*a*b
if s >=0 and t > 0:
print('Yes')
else:
print('No')
| 0 | null | 90,991,972,640,046 | 268 | 197 |
from math import ceil
n = int(input())
a = [chr(i) for i in range(97, 97+26)]
s = 0
for i in range(1,100):
l = n - s
s += 26**i
if n <= s:
m = i
break #第m群l番目
name = [0] * m
div = [0] * m
rem = [0] * m
rem[-1] = l
for j in range(m):
div[j] = ceil(rem[j-1] / (26**(m-j-1)))
rem[j] = rem[j-1] % (26**(m-j-1))
if rem[j] == 0:
rem[j] == 26**(m-j-1)
name[j] = a[div[j]-1]
print(''.join(name))
|
# -*-coding:utf-8
def main():
while True:
n, x = map(int, input().split())
if ((n == 0) and (x == 0)):
break
count = 0
for i in range(1, n+1):
for j in range(1, n+1):
for k in range(1, n+1):
if((i<j) and (j<k) and i+j+k == x):
count += 1
print(count)
if __name__ == '__main__':
main()
| 0 | null | 6,548,283,538,012 | 121 | 58 |
List=list(input())
if List[2]==List[3] and List[4]==List[5]:
print("Yes")
else:print("No")
|
#!/usr/bin/env python3
n = input()
if n[2] == n[3] and n[4] == n[5]:
print('Yes')
else:
print('No')
| 1 | 42,037,789,653,860 | null | 184 | 184 |
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from functools import reduce, lru_cache
import collections, heapq, itertools, bisect
import math, fractions
import sys, copy
sys.setrecursionlimit(1000000)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline().rstrip())
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline().rstrip())
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007
def divisors(N):
divs = set([1, N])
i = 2
while i ** 2 <= N:
if N % i == 0:
divs.add(i)
divs.add(N//i)
i += 1
return sorted(list(divs))
def is_ok(N, K):
if K <= 1:
return False
while N % K == 0:
N //= K
return N % K == 1
def main():
N = I()
ans = 0
for divisor in divisors(N-1):
if is_ok(N, divisor):
ans += 1
for divisor in divisors(N):
if is_ok(N, divisor):
ans += 1
print(ans)
if __name__ == '__main__':
main()
|
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353
def ddprint(x):
if DBG:
print(x)
a,b,c = inm()
k = inn()
x = 0
while b<=a:
b *= 2
x += 1
while c<=b:
c *= 2
x += 1
print('Yes' if x<=k else 'No')
| 0 | null | 24,277,333,570,230 | 183 | 101 |
print(("a","A")[str(input()).isupper()])
|
a=input()
b='abcdefghijklmnopqrstuvwxyz'
for i in range(len(b)):
if b[i]==a:
print("a")
exit()
print("A")
| 1 | 11,328,291,348,220 | null | 119 | 119 |
def main():
S = input()
L = len(S)
print('x' * L)
if __name__ == '__main__':
main()
|
s=len(input());print('x'*s)
| 1 | 72,997,611,349,764 | null | 221 | 221 |
n,k=map(int,input().split())
A=list(map(int,input().split()))
C=[n for _ in range(n)]
for loop in range(k):
B=[0 for _ in range(n)]
for i in range(n):
l,r=max(0,i-A[i]),i+A[i]+1
B[l] +=1
if r<n:B[r] -=1
for i in range(n-1):
B[i+1]=B[i]+B[i+1]
A=B
if A==C:break
print(*A)
|
import itertools
N, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
for _ in range(K):
cumsum = [0] * (N + 2)
for i, a in enumerate(A):
i += 1
cumsum[max(0, i - a)] += 1
cumsum[min(i + a + 1, N + 1)] -= 1
A = list(itertools.accumulate(cumsum))[1:N + 1]
if min(A) == N:
break
print(' '.join(map(str, A)))
| 1 | 15,414,538,388,260 | null | 132 | 132 |
import math
def rotate(x, y, theta):
return (round(x*math.cos(theta) -1*y*math.sin(theta), 5), round(x*math.sin(theta) + y*math.cos(theta), 5))
def koch(p1, p2, n):
s = (round((2*p1[0] + p2[0])/3, 5), round((2*p1[1] + p2[1])/3, 5))
t = (round((p1[0] + 2*p2[0])/3, 5), round((p1[1] + 2*p2[1])/3, 5))
rotated = rotate(t[0]-s[0], t[1]-s[1], math.pi/3)
u = (s[0] + rotated[0], s[1] + rotated[1])
if n == 0:
print(round(p1[0], 5), round(p1[1], 5))
elif n == -1:
return None
koch(p1, s, n-1)
koch(s, u, n-1)
koch(u, t, n-1)
koch(t, p2, n-1)
n = int(input())
koch((0.0, 0.0), (100, 0.0), n)
print(100, 0.0)
|
n = int(input())
def three_points(p1,p2):
q1 = ((2*p1[0]+p2[0])/3, (2*p1[1]+p2[1])/3)
q2 = ((p1[0]+2*p2[0])/3, (p1[1]+2*p2[1])/3)
dx,dy = p2[0]-p1[0], p2[1]-p1[1]
q3 = (p1[0]+dx/2-3**0.5/6*dy, p1[1]+dy/2+3**0.5/6*dx)
return [q1,q3,q2]
m = [(0,0),(100,0)]
for i in range(n):
tmpm = []
for j in range(len(m)-1):
tmpm += [m[j]] + three_points(m[j],m[j+1])
tmpm += [m[-1]]
m = tmpm
for x in m:
print(x[0], x[1])
| 1 | 128,867,132,122 | null | 27 | 27 |
n = int(input())
a = list(map(int,input().split()))
x = 1
if 0 in a:
print(0)
exit()
for e in a:
x *= e
if x > 10**18:
print(-1)
exit()
print(x)
|
import numpy as np
N = int(input())
A = list(map(int, input().split()))
ans = 1
if 0 in A:
ans = 0
for i in range(N):
ans *= A[i]
if ans > 1000000000000000000:
ans = -1
break
print(ans)
| 1 | 16,179,578,942,958 | null | 134 | 134 |
N = int(raw_input())
for i in range(N):
a = range(3)
a[0],a[1],a[2] = map(int, raw_input().split())
a.sort()
if a[0]**2 + a[1]**2 == a[2]**2:
print "YES"
else:
print "NO"
|
import sys
def solve():
input = sys.stdin.readline
N = int(input())
S = input().strip("\n")
Left = [set() for _ in range(N)]
Right = [set() for _ in range(N)]
Left[0] |= {S[0]}
Right[N-1] |= {S[N-1]}
for i in range(1, N):
Left[i] = Left[i-1] | {S[i]}
Right[N-i-1] = Right[N-i] | {S[N-i-1]}
used = set()
for i in range(1, N - 1):
mid = S[i]
for l in Left[i-1]:
for r in Right[i+1]:
used |= {l + mid + r}
print(len(used))
return 0
if __name__ == "__main__":
solve()
| 0 | null | 64,038,621,568,310 | 4 | 267 |
x = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
r = x.split(", ")
z = int(input())
print(r[z-1])
|
import sys
rline = sys.stdin.readline
def solve():
K = int(input())
lst = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(lst[K - 1])
if __name__ == '__main__':
solve()
| 1 | 49,958,449,849,728 | null | 195 | 195 |
sheep, wolves = map(int, input().split())
if sheep > wolves:
print("safe")
elif sheep <= wolves:
print("unsafe")
|
NX = input().split()
n = int(NX[0])
x = int(NX[1])
while n!=0 or x!=0:
out = 0
for ii in range(n-2):
i = ii+1 #i:1~n-2
for jj in range(n-1-i):
j = jj+1+i #j:i+1~i+1+n-2-i=i+1~n-1
for kk in range(n-j):
k = kk+1+j #k:j+1~n-j+j+1 =
if k !=i and k!=j and i+j+k == x:
out = out+1
print(out)
NX = input().split()
n = int(NX[0])
x = int(NX[1])
| 0 | null | 15,179,143,655,260 | 163 | 58 |
# -*- coding: utf-8 -*-
import sys
import os
a, b = list(map(int, input().split()))
d = a // b
r = a % b
f = a / b
print('{} {} {:.10f}'.format(d, r, f))
|
a,b=map(int,raw_input().split())
print a/b,a%b,"%.6f"%(1.*a/b)
| 1 | 592,293,797,110 | null | 45 | 45 |
n = int(input())
a = list(map(int,input().split()))
m = 1000
stocks = 0
drops = [False]*(n-1)
for i in range(n-1):
if a[i] > a[i+1]:
drops[i] = True
for i in range(n-1):
if drops[i]:
m+=stocks*a[i]
stocks = 0
else:
stocks+=m//a[i]
m -= (m//a[i])*a[i]
print(m + stocks*a[-1])
|
from time import time
from random import randint
from numba import njit
from numpy import int64
@njit('i8(i8[:],i8[:])')
def func(s,x):
last=[0]*26
score=0
for i,v in enumerate(x,1):
last[v]=i
c=0
for j in range(26):
c+=s[j]*(i-last[j])
score=score+s[i*26+v]-c
print(score)
return score
def main():
start=time()
d,*s=map(int,open(0).read().split())
s=int64(s)
func(s,s[-d:]-1)
main()
| 0 | null | 8,690,568,734,458 | 103 | 114 |
while True:
N,X = map(int,input().split())
if N == 0 and X == 0:
break
ans = 0
for a in range(1,N+1):
for b in range(1,N+1):
if b <= a:
continue
c = X-(a+b)
if c > b and c <= N:
ans += 1
print("%d"%(ans))
|
n,a,b = map(int,input().split())
q = n//(a+b)
r = n%(a+b)
if r < a:
ans = a*q + r
else:
ans = a*q + a
print(ans)
| 0 | null | 28,473,498,205,900 | 58 | 202 |
import sys
sys.setrecursionlimit(10**6)
n,k = map(int, input().split())
h = list(map(int, input().split()))
h.sort()
l = -1; r = n # 二分探索時は探索範囲は取り得る値+-1しておく
while l+1 < r:
c = (l+r)//2
if h[c] < k:
l = c
else:
r = c
print(n-(l+1))
|
number, req = map(int, input().split())
friends = list(map(int, input().split()))
allowed = 0
for i in friends:
if i >= req: allowed += 1
print(allowed)
| 1 | 178,953,274,190,118 | null | 298 | 298 |
H=int(input())
if H==1:
print(1)
else:
i=1
count=1
while H//2!=1:
i*=2
count+=i
H=H//2
i*=2
count+=i
print(count)
|
def resolve():
H = int(input())
ans = 1
while H > 0:
ans *= 2
H //= 2
print(ans - 1)
resolve()
| 1 | 80,168,494,950,658 | null | 228 | 228 |
from math import sqrt
n=int(input())
while 1:
k=0
for i in range(2,int(sqrt(n))+1):
if(n%i==0):
k=1
break
if(k==0):
print(n)
break
n+=1
|
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
x = int(input())
while True:
p = prime_factorize(x)
if len(p) == 1:
print(p[0])
break
x += 1
| 1 | 105,536,920,716,008 | null | 250 | 250 |
n = int(input())
A, B = map(list,zip(*[map(int,input().split()) for i in range(n)]))
A.sort()
B.sort()
if n&1:
print(B[n//2]-A[n//2]+1)
else:
print(B[n//2]+B[n//2-1]-(A[n//2]+A[n//2-1])+1)
|
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n=ni()
mins=[]
maxs=[]
for i in range(n):
a,b=nm()
mins.append(a)
maxs.append(b)
smn = sorted(mins)
smx = sorted(maxs)
if n%2==1:
mn = smn[(n+1)//2-1]
mx = smx[(n+1)//2-1]
print(round((mx-mn)+1))
else:
mn = (smn[n//2-1]+smn[n//2])/2.0
mx = (smx[n//2-1]+smx[n//2])/2.0
print(round((mx-mn)*2+1))
| 1 | 17,296,060,824,768 | null | 137 | 137 |
g = input()
l = []
q = []
n = 0
for x in range(len(g)):
if g[x] == '\\':
if n:
l.append(n)
n = 0
if q:
q.append(-1)
q.append(x)
elif g[x] == '/':
if q:
while True:
p = q.pop()
if p == -1:
n += l.pop()
else:
break
n += x-p
else:
pass
if n:
l.append(n)
for j in range(l.count(0)):
l.remove(0)
print(sum(l))
print(len(l), *l)
|
li1 = []
li2 = []
ans = 0
for i, s in enumerate(input()):
if s == "\\":
li1.append(i)
elif s == "/" and li1:
j = li1.pop()
c = i - j
ans += c
while li2 and li2[-1][0] > j:
c += li2[-1][1]
li2.pop()
li2.append((j, c))
print(ans)
if li2:
print(len(li2), *list(zip(*li2))[1])
else:
print(0)
| 1 | 57,904,176,792 | null | 21 | 21 |
icase=0
if icase==0:
r=int(input())
print(r*r)
|
def main():
N = int(input()) # 文字列または整数(一変数)
print(N**2)
if __name__ == '__main__':
main()
| 1 | 145,080,869,633,782 | null | 278 | 278 |
from collections import defaultdict
from math import gcd
N = int(input())
MOD = 10**9 + 7
L = defaultdict(lambda: [0,0])
zero = 0
for _ in range(N):
A, B = map(int, input().split())
if A==0: d=B
elif B==0: d=A
else: d=gcd(A,B)
if d != 0:
A, B = A//d, B//d
if A<0: A, B = -A, -B
if B>0: L[(A,B)][0] += 1
else: L[(-B,A)][1] += 1
else: zero += 1
res = 1
for x,y in L.values():
res *= pow(2,x,MOD) + pow(2,y,MOD) -1
res %= MOD
print((res+zero-1)%MOD)
|
import sys
from collections import defaultdict
sys.setrecursionlimit(500000)
class Fraction:
def gcd(self, a ,b):
a,b = max(a,b),min(a,b)
while a%b!=0:
a,b = b,a%b
return b
def frac(self,a,b):
if a==0 and b==0:
return (0,0)
elif a==0:
return (0,1)
elif b==0:
return (1,0)
else:
d = self.gcd(abs(a),abs(b))
if a<0:
a = -a
b = -b
return (a//d,b//d)
def __init__(self, a, b):
self.value = self.frac(a,b)
def v(self):
return self.value
def __lt__(self, other):
assert self.value!=(0,0) and other.value!=(0,0), 'value (0,0) cannot be compared.'
a,b = self.value
c,d = other.value
return a*d < b*c
def __le__(self, other):
assert self.value!=(0,0) and other.value!=(0,0), 'value (0,0) cannot be compared.'
a,b = self.value
c,d = other.value
return a*d <= b*c
def __eq__(self, other):
a,b = self.value
c,d = other.value
return a==c and b==d
def __ne__(self, other):
a,b = self.value
c,d = other.value
return not (a==c and b==d)
def __gt__(self, other):
assert self.value!=(0,0) and other.value!=(0,0), 'value (0,0) cannot be compared.'
a,b = self.value
c,d = other.value
return a*d > b*c
def __ge__(self, other):
assert self.value!=(0,0) and other.value!=(0,0), 'value (0,0) cannot be compared.'
a,b = self.value
c,d = other.value
return a*d >= b*c
def __add__(self, other):
a,b = self.value
c,d = other.value
return Fraction(a*d + b*c, b*d)
def __sub__(self, other):
a,b = self.value
c,d = other.value
return Fraction(a*d - b*c, b*d)
def __mul__(self, other):
a,b = self.value
c,d = other.value
return Fraction(a*c, b*d)
def __truediv__(self, other):
a,b = self.value
c,d = other.value
return Fraction(a*d, b*c)
def __neg__(self):
a,b = self.value
return Fraction(-a,b)
def inv(self):
return Fraction(1,1) / self
def input():
return sys.stdin.readline()[:-1]
def main():
N = int(input())
vec = [list(map(int,input().split())) for i in range(N)]
arg = defaultdict(int)
zero = 0
for v in vec:
if v[0] == 0 and v[1] == 0:
zero += 1
else:
f = Fraction(v[0],v[1])
arg[f.v()] += 1
arg[(-f.inv()).v()] += 0
pair = []
fd = lambda : False
checked_list = defaultdict(fd)
for key in arg:
if not checked_list[key]:
inv = (-Fraction(*key).inv()).v()
pair.append([arg[key],arg[inv]])
checked_list[inv] = True
mod = 1000000007
ans = 1
for p1,p2 in pair:
ans *= pow(2,p1,mod) + pow(2,p2,mod) - 1
ans %= mod
ans += zero
ans %= mod
print((ans+mod-1)%mod)
if __name__ == '__main__':
main()
| 1 | 20,767,548,455,642 | null | 146 | 146 |
import sys
N = int(input())
mod = pow(10, 9)+7
if N < 3:
print(0)
sys.exit()
ans = 1
for j in range(2, N//3+1):
r = j-1
n = N-j*3+r
bunshi = 1
bunbo = 1
for i in range(r):
bunshi = (bunshi*(n-i)) % mod
bunbo = (bunbo*(i+1)) % mod
ans = (ans+(bunshi*pow(bunbo, -1, mod))) % mod
print(ans)
|
from collections import Counter
n = int(input())
s = [input() for _ in range(n)]
data = Counter(s)
print(len(data.keys()))
| 0 | null | 16,900,795,005,952 | 79 | 165 |
def maybe_prime(d,s,n):
for a in (2,3,5,7):
p = False
x = pow(a,d,n)
if x==1 or x==n-1:
continue
for i in range(1,s):
x = x*x%n
if x==1: return False
elif x == n-1:
p = True
break
if not p: return False
return True
def is_prime(n):
if n in (2,3,5,7): return True
elif n%2==0: return False
else:
d,s = n-1, 0
while not d%2:
d,s = d>>1,s+1
return maybe_prime(d,s,n)
cnt = 0
n = int(input())
for i in range(n):
n = int(input())
if is_prime(n): cnt+=1
print(cnt)
|
import sys
from io import StringIO
import unittest
import os
from collections import deque
# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)
# 実装を行う関数
def resolve(test_def_name=""):
# 数値取得サンプル
# 1行1項目 n = int(input())
# 1行2項目 h, w = map(int, input().split())
# 1行N項目 x = list(map(int, input().split()))
# N行1項目 x = [int(input()) for i in range(n)]
# N行N項目 x = [list(map(int, input().split())) for i in range(n)]
# 文字取得サンプル
# 1行1項目 x = input()
# 1行1項目(1文字ずつリストに入れる場合) x = list(input())
h, w = map(int, input().split())
maze = [list(input()) for i in range(h)]
start_list = []
for i_len, i in enumerate(range(h)):
for j_len, j in enumerate(range(w)):
route = 4
# 自分が壁なら対象外
if maze[i][j] == "#":
continue
# 上下端なら-1
route -= 1 if i_len == 0 else 0
route -= 1 if i_len + 1 == h else 0
# 上下が壁なら-1
route -= 1 if not i_len == 0 and maze[i - 1][j] == "#" else 0
route -= 1 if not i_len + 1 == h and maze[i + 1][j] == "#" else 0
# 左右端なら-1
route -= 1 if j_len == 0 else 0
route -= 1 if j_len + 1 == w else 0
# 左右が壁なら-1
route -= 1 if not j_len == 0 and maze[i][j - 1] == "#" else 0
route -= 1 if not j_len + 1 == w and maze[i][j + 1] == "#" else 0
if route <= 2:
start_list.append((i, j))
ans = 0
que = deque()
for start in start_list:
que.appendleft(start)
ed_list = [[-1 for i in range(w)] for j in range(h)]
ed_list[start[0]][start[1]] = 0
# BFS開始
while len(que) is not 0:
now = que.pop()
# 各方向に移動
for i, j in [(1, 0), (0, 1), (0, -1), (-1, 0)]:
# 処理対象の座標
target = [now[0] + i, now[1] + j]
# 処理対象のチェック
# 外なら何もしない
if not 0 <= target[0] < h or not 0 <= target[1] < w:
continue
# 距離が設定されているなら何もしない
if ed_list[target[0]][target[1]] != -1:
continue
# 壁なら何もしない
if maze[target[0]][target[1]] == "#":
continue
# 処理対象に対する処理
# キューに追加(先頭に追加するのでappendleft())
que.appendleft(target)
# 距離を設定(現在の距離+1)
ed_list[target[0]][target[1]] = ed_list[now[0]][now[1]] + 1
ans = max(ans, ed_list[target[0]][target[1]])
print(ans)
# テストクラス
class TestClass(unittest.TestCase):
def assertIO(self, assert_input, output):
stdout, sat_in = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
resolve(sys._getframe().f_back.f_code.co_name)
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, sat_in
self.assertEqual(out, output)
def test_input_1(self):
test_input = """3 3
...
...
..."""
output = """4"""
self.assertIO(test_input, output)
def test_input_2(self):
test_input = """3 5
...#.
.#.#.
.#..."""
output = """10"""
self.assertIO(test_input, output)
# 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
def test_1original_1(self):
test_input = """1 2
.."""
output = """1"""
self.assertIO(test_input, output)
# 実装orテストの呼び出し
if __name__ == "__main__":
if os.environ.get("USERNAME") is None:
# AtCoder提出時の場合
resolve()
else:
# 自PCの場合
unittest.main()
| 0 | null | 47,497,788,955,948 | 12 | 241 |
import re
from itertools import product
import itertools
q1 = int(input())
q2 = input()
q3 = int(input())
q4 = input()
S = re.split(r' ',q2)
S=list(map(int, S))
T = re.split(r' ',q4)
T=list(map(int, T))
S_len = len(S)
T_len = len(T)
array = []
for j in range(q1+1):
x = list(itertools.combinations(S, j))
for k in range(len(x)):
y = sum(x[k])
array.append(y)
for i in range(T_len):
if(T[i] in array):
print("yes")
else:
print("no")
|
import math
def factorization(n):
arr = []
temp = n
for i in range(2, int(math.ceil(n**0.5))):
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
n = int(input())
if n == 1:
print(0)
exit(0)
fact_1i = factorization(n)
res = 0
for _, num in fact_1i:
temp_num = 1
while temp_num <= num:
res += 1
num -= temp_num
temp_num += 1
print(res)
| 0 | null | 8,540,573,282,240 | 25 | 136 |
a = []
for i in range(3):
a.append(list(map(int, input().split())))
n = int(input())
for i in range(n):
b = int(input())
for j in range(3):
for k in range(3):
if a[j][k] == b:
a[j][k] = 0
for i in range(3):
if sum(a[i]) == 0:
print("Yes")
exit()
for i in range(3):
if sum([a[0][i], a[1][i], a[2][i]]) == 0:
print("Yes")
exit()
if sum([a[0][0], a[1][1], a[2][2]]) == 0 or sum([a[0][2], a[1][1], a[2][0]]) == 0:
print("Yes")
exit()
print("No")
|
import sys
from itertools import product
def main():
input = sys.stdin.buffer.readline
card = [[0] * 3 for _ in range(3)]
for i in range(3):
line = list(map(int, input().split()))
card[i] = line
mark = [[0] * 3 for _ in range(3)]
n = int(input())
for _ in range(n):
b = int(input())
for i, j in product(range(3), repeat=2):
if card[i][j] == b:
mark[i][j] = 1
break
for i in range(3):
s = 0
for j in range(3):
s += mark[i][j]
if s == 3:
print("Yes")
sys.exit()
for j in range(3):
s = 0
for i in range(3):
s += mark[i][j]
if s == 3:
print("Yes")
sys.exit()
s = 0
for i in range(3):
s += mark[i][i]
if s == 3:
print("Yes")
sys.exit()
s = 0
for i in range(3):
s += mark[i][2 - i]
if s == 3:
print("Yes")
sys.exit()
print("No")
if __name__ == "__main__":
main()
| 1 | 60,027,146,182,908 | null | 207 | 207 |
def main():
k, n = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
d =[min(a)+k-max(a)]
for i in range(n-1):
d.append(a[i+1]-a[i])
print(k-max(d))
if __name__ == "__main__":
main()
|
x=input().split()
y=list(map(int,x))
a=y[0]
b=y[1]
c=y[2]
if a < b and b < c:
print('Yes')
else:
print('No')
| 0 | null | 21,780,603,375,872 | 186 | 39 |
N = int(input())
multiple_list = {i*j for i in range(1,10) for j in range(1,10)}
print(['No','Yes'][N in multiple_list])
|
s = list(input())
n = len(s)
flag = 0
for i in range(n//2):
if s[i] != s[n-i-1]:
flag = 1
if flag == 0:
s2 = s[:(n-1)//2]
n2 = len(s2)
for i in range(n2//2):
if s2[i] != s2[n2-i-1]:
flag = 1
#print(n, n2, s, s2)
if flag == 0:
if flag == 0:
s2 = s[(n+3)//2-1:]
n2 = len(s2)
for i in range(n2//2):
if s2[i] != s2[n2-i-1]:
flag = 1
#print(s2)
if flag == 0:
print("Yes")
else:
print("No")
| 0 | null | 102,671,521,896,188 | 287 | 190 |
X = int(input())
flag = False
for A in range(-120, 120):
for B in range(-120, 120):
if A**5 - B**5 == X:
flag = True
break
if flag:
break
print(A, B)
|
import math
x = int(input())
for i in range(1, 121):
for j in range(-120, 121):
if i**5 - j**5 == x:
print(i, j)
quit(0)
| 1 | 25,632,379,468,832 | null | 156 | 156 |
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
#from operator import itemgetter
#from heapq import heappush, heappop
#import numpy as np
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
#from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
import sys
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
stdin = sys.stdin
ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
K = ni()
S = ns()
if len(S) <= K:
print(S)
else:
print(S[:K] + '...')
|
from sys import stdin
from collections import defaultdict as dd
from collections import deque as dq
import itertools as it
from math import sqrt, log, log2
from fractions import Fraction
# t = int(stdin.readline())
# for _ in range(t):
# n, m = map(int, stdin.readline().split())
# nums = list(map(int, stdin.readline().split()))
# n = int(input())
# if n%10 in [2, 4, 5, 7, 9]:
# print('hon')
# elif n%10 in [0, 1, 6, 8]:
# print('pon')
# else:
# print('bon')
k = int(input())
s = input()
ans = s[:k] + ('...' if len(s) > k else '')
print(ans)
| 1 | 19,723,301,468,948 | null | 143 | 143 |
n = int(input())
s = input()
ans = ''
for c in s:
nc_ord = ord(c) + n
while nc_ord > ord('Z'):
nc_ord -= 26
ans += chr(nc_ord)
print(ans)
|
n = int(input())
dp = [0]*(n+1)
for i in range(n+1):
if i == 0:
dp[i] = 1
elif i == 1:
dp[i] = 1
else:
dp[i] = dp[i-1] + dp[i-2]
print(dp[n])
| 0 | null | 66,944,336,203,696 | 271 | 7 |
s = input()
x = ["hi", "hihi", "hihihi", "hihihihi", "hihihihihi"]
if s in x:
print("Yes")
else:
print("No")
|
S=input()
if S=="hi" or S=="hihi" or S=="hihihi" or S=="hihihihi" or S=="hihihihihi":
print("Yes")
else:
print("No")
| 1 | 53,341,225,518,380 | null | 199 | 199 |
for str in iter(input, "0"):
print(sum(int(c) for c in str))
|
a, b = map(int, input().split())
print((f"{a}" * b, f"{b}" * a)[b <= a])
| 0 | null | 43,035,099,392,612 | 62 | 232 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = [int(x)-48 for x in read().rstrip()]
ans = 0
dp = [[0]*(len(N)+1) for i in range(2)]
dp[1][0] = 1
dp[0][0] = 0
for i in range(1, len(N)+1):
dp[0][i] = min(dp[0][i-1] + N[i-1],
dp[1][i-1] + (10 - N[i-1]))
dp[1][i] = min(dp[0][i-1] + N[i-1] + 1,
dp[1][i-1] + (10 - (N[i-1] + 1)))
print(dp[0][len(N)])
|
str = raw_input()
li = []
for c in list(str):
if c.isupper():
li.append(c.lower())
elif c.islower():
li.append(c.upper())
else:
li.append(c)
print ''.join(li)
| 0 | null | 36,382,338,754,838 | 219 | 61 |
import sys, re
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from collections import deque, defaultdict, Counter
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop, heapify
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
class UnionFind():
def __init__(self, n):
self.n = n
# parents[i]: 要素iの親要素の番号
# 要素iが根の場合、parents[i] = -(そのグループの要素数)
self.parents = [-1] * n
def find(self, x):
if 0 > self.parents[x]:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
# 要素xが属するグループの要素数を返す
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
# 要素xが属するグループに属する要素をリストで返す
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
# 全ての根の要素をリストで返す
def roots(self):
return [i for i, x in enumerate(self.parents) if 0 > x]
# グループの数を返す
def group_count(self):
return len(self.roots())
# 辞書{根の要素: [そのグループに含まれる要素のリスト], ...}を返す
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
# print()での表示用
# all_group_members()をprintする
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
N, M, K = MAP()
tree = UnionFind(N)
friends = [[] for _ in range(N)]
for _ in range(M):
A, B = MAP()
tree.union(A-1, B-1)
friends[A-1].append(B-1)
friends[B-1].append(A-1)
blocks = [[] for _ in range(N)]
for _ in range(K):
C, D = MAP()
blocks[C-1].append(D-1)
blocks[D-1].append(C-1)
for i in range(N):
blocks_cnt = sum([tree.same(i, j) for j in blocks[i]])
print(tree.size(i) - len(friends[i]) - 1 - blocks_cnt, end=" ")
print()
|
from collections import deque
def init_tree(x, par):
for i in range(x + 1):
par[i] = i
def find(x, par):
q = deque()
q.append(x)
while len(q) > 0:
v = q.pop()
if v == par[v]:
return v
q.append(par[v])
def union(x, y, par, rank):
px, py = find(x, par), find(y, par)
if px == py:
return
if rank[px] < rank[py]:
par[px] = py
return
elif rank[px] == rank[py]:
rank[px] += 1
par[py] = px
n, m, k = map(int, input().split())
par = [0] * (n + 1)
rank = [0] * (n + 1)
init_tree(n, par)
eg = [[] for _ in range(n + 1)]
for _ in range(m):
a, b = map(int, input().split())
union(a, b, par, rank)
eg[a].append(b)
eg[b].append(a)
for _ in range(k):
a, b = map(int, input().split())
eg[a].append(b)
eg[b].append(a)
xs = [0] * (n + 1)
ys = [0] * (n + 1)
for i in range(1, n + 1):
p = find(i, par)
xs[p] += 1
for v in eg[i]:
if p == find(v, par):
ys[i] += 1
ans = [-1] * (n + 1)
for i in range(1, n + 1):
ans[i] += xs[find(i, par)] - ys[i]
print(*ans[1:])
| 1 | 61,228,720,134,638 | null | 209 | 209 |
import sys
def input(): return sys.stdin.readline().rstrip()
def per(n, r, mod=10**9+7): # 順列数
per = 1
for i in range(r):
per = per*(n-i) % mod
return per
def com(n, r, mod=10**9+7): # 組み合わせ数
r = min(n-r, r)
bunshi = per(n, r, mod)
bunbo = 1
for i in range(1, r+1):
bunbo = bunbo*i % mod
return bunshi*pow(bunbo, -1, mod) % mod
def comH(n, r, mod=10**9+7): # n種類からr個取る重複組み合わせ数
return com(n+r-1,r,mod)
def main():
s = int(input())
ans = 0
for i in range(1, (s//3)+1):
k = s-3*i
ans += comH(i,k)
#print(com(k+i,k),k+i,i)
print(ans % (10**9+7))
if __name__ == '__main__':
main()
|
def cmb(n,r,mod):
if r<0 or r>n:
return 0
r=min(r,n-r)
return g1[n]*g2[r]*g2[n-r]%mod
k=int(input())
s=list(input())
n=len(s)
mod=10**9+7
g1=[1,1]
g2=[1,1]
inverse=[0,1]
for i in range(2,2*10**6+1):
g1.append((g1[-1]*i)%mod)
inverse.append((-inverse[mod%i]*(mod//i))%mod)
g2.append((g2[-1]*inverse[-1])%mod)
pow25=[1]
for i in range(n+k+1):
pow25.append((pow25[-1]*25)%mod)
pow26=[1]
for i in range(n+k+1):
pow26.append((pow26[-1]*26)%mod)
ans=0
for i in range(n,n+k+1):
ans+=cmb(i-1,n-1,mod)*pow25[i-n]*pow26[n+k-i]
ans%=mod
print(ans)
| 0 | null | 8,047,679,128,358 | 79 | 124 |
import sys
sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7
def input():
return sys.stdin.readline().strip()
class UnionFind:
def __init__(self, n_nodes):
self.n_nodes = n_nodes
# self.parents[x] < 0 の時,xが根である.
# また,xが根の時,(-1) * (同一グループの要素数) が格納されるようになる.
self.parents = [-1] * n_nodes
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
# 常にxの方が要素数が多くなるように,スワップする
if self.parents[x] > self.parents[y]:
x, y = y, x
# 要素数の少ない方のグループを,要素数が多い方の木に貼る.
self.parents[x] += self.parents[y]
self.parents[y] = x
def get_size(self, x):
return -self.parents[self.find(x)]
def is_same(self, x, y):
return self.find(x) == self.find(y)
def get_members(self, x):
parent = self.find(x)
return [i for i in range(self.n_nodes) if self.find(i) == parent]
def get_parent_list(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def get_n_groups(self):
return len(self.get_parent_list())
def get_members_dict(self):
return {par: self.get_members(par) for par in self.get_parent_list()}
def main():
N, M, K = map(int, input().split())
tree = UnionFind(N)
friends = [[] for _ in range(N)]
for _ in range(M):
a, b = map(int, input().split())
a -= 1
b -= 1
tree.unite(a, b)
friends[a].append(b)
friends[b].append(a)
ng = [[] for _ in range(N)]
for _ in range(K):
c, d = map(int, input().split())
c -= 1
d -= 1
ng[c].append(d)
ng[d].append(c)
ans = []
for i in range(N):
n_ng = 0
for j in ng[i]:
if tree.is_same(i, j):
n_ng += 1
n_member = tree.get_size(i)
n_friends = len(friends[i])
# 自分を引くのを忘れない
ans.append(n_member - n_friends - n_ng - 1)
print(*ans, sep=" ")
if __name__ == "__main__":
main()
|
class Unionfind():
def __init__(self, n):
self.n = n
self.parents = [-1] * (n+1)
def find(self, x):
if(self.parents[x] < 0):
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if(x == y):
return
if(self.parents[x] > self.parents[y]):
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}:{}'.format(r, self.members(r)) for r in self.roots())
N, M, K = map(int, input().split())
uf = Unionfind(N)
f = [0 for _ in range(N)]
n = [0 for _ in range(N)]
for _ in range(M):
a, b = map(int, input().split())
a -= 1
b -= 1
uf.union(a, b)
f[a] += 1
f[b] += 1
for _ in range(K):
c, d = map(int, input().split())
c -= 1
d -= 1
if(uf.same(c, d)):
n[c] += 1
n[d] += 1
ans = []
for i in range(N):
ans.append(uf.size(i)-f[i]-n[i]-1)
print(*ans)
| 1 | 61,437,424,657,038 | null | 209 | 209 |
A = input()
print('A') if A.isupper() else print('a')
|
S = input()
print( 'A' if S.isupper() else 'a' )
| 1 | 11,399,777,972,572 | null | 119 | 119 |
t=input()
print(t.replace("?","D"))
|
import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10**7)
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()
def modpow(n, p, m):
if p == 0:
return 1
if p % 2 == 0:
t = modpow(n, p // 2, m)
return t * t % m
return n * modpow(n, p - 1, m) % m
n = ni()
A = modpow(9, n, mod)
B = A
C = modpow(8, n, mod)
D = modpow(10, n, mod)
ans = (D - A - B + C) % mod
print(ans)
| 0 | null | 10,778,886,548,780 | 140 | 78 |
S = input()
T = input()
U = [0] * (len(S)-len(T)+1)
for j in range(len(S)-len(T)+1):
for i in range(len(T)):
if(S[i+j] != T[i]):
U[j] += 1
print(min(U))
|
import math
while True:
n=int(input())
if n==0:
break
else:
s=list(map(int,input().split()))
S=sum(s)
m=S/n
a2=0
for j in range(n):
a2+=(s[j]-m)**2
a2=a2/n
a=math.sqrt(a2)
print(f'{a:.4f}')
| 0 | null | 1,959,467,900,700 | 82 | 31 |
n = int(input())
sp, sm = [], []
res = 0
for _ in range(n):
s = input()
m = len(s)
l, tl = 0, 0
for i in range(m):
if s[i] == ')':
tl -= 1
else:
tl += 1
l = min(l, tl)
r, tr = 0, 0
for i in range(m):
if s[m-1-i] == '(':
tr -= 1
else:
tr += 1
r = min(r, tr)
res += tl
if tl >= 0:
sp.append((l, tl))
else:
sm.append((r, tr))
if res != 0:
print('No')
exit()
sp.sort(key=lambda x: -x[0])
sm.sort(key=lambda x: -x[0])
xp = len(sp)
cur = 0
for l, tl in sp:
if cur + l < 0:
print('No')
exit()
cur += tl
cur = 0
for r, tr in sm:
if cur + r < 0:
print('No')
exit()
cur += tr
print('Yes')
|
#coding: utf-8
x=input()
y=x*x*x
print y
| 0 | null | 11,942,485,493,078 | 152 | 35 |
N = int(input())
D = list(map(int, input().split()))
mod = 998244353
ans = 1
A = [0]*(max(D)+1)
for i in range(N):
A[D[i]] += 1
#if D[0] != 0 or not all(D[1:]) or not all(A):
# print(0)
# exit()
if D[0] != 0 or not all(D[1:]):
print(0)
exit()
for i in range(1, max(D)+1):
# print(A[i])
if A[i] == 0:
print(0)
exit()
ans = ans * pow(A[i-1], A[i], mod) % mod
print(ans % mod)
|
from collections import Counter
N = int(input())
D = list(map(int, input().split()))
mod = 998244353
c = Counter(D)
m = max(c.keys())
if D[0] == 0 and c[0] == 1:
ans = 1
for i in D[1:]:
ans *= c[i-1]
ans %= mod
print(ans)
else:
print(0)
| 1 | 155,501,205,804,618 | null | 284 | 284 |
n,a,b=list(map(int,input().split()))
#2^n-nCa-nCbを求める
#冪乗を求める関数を求める
#2のn乗をmで割ったあまりを求める
def pow(a,n,m):
if n==0:
return 1
else:
k=pow(a*a%m,n//2,m)
if n%2==1:
k=k*a%m
return k
#次は組み合わせを計算する
#まずは前処理をする
inv=[0 for i in range(200001)]
finv=[0 for i in range(200001)]
inv[1]=1
finv[1]=1
for i in range(2,200001):
#逆元の求め方p=(p//a)*a+p%a a^(-1)=-(p//a)*(p%a)^(-1)
inv[i]=(-(1000000007//i)*inv[1000000007%i])%1000000007
finv[i]=finv[i-1]*inv[i]%1000000007
#nが10^7程度であればnCk=n!*(k!)*((n-k)!)を求めればいい
#nがそれより大きい時は間に合わない。ここでkが小さいことに着目すると
#nCk=n*(n-1).....*(n-k+1)*(k!)^(-1)で求められることがわかる
a_num=1
b_num=1
for i in range(n-a+1,n+1):
a_num=i*a_num%1000000007
for i in range(n-b+1,n+1):
b_num=i*b_num%1000000007
print((pow(2,n,1000000007)-1-a_num*finv[a]-b_num*finv[b])%1000000007)
|
N = int(input())
A = list(map(int, input().split()))
length = len(A)
find_next = 1
for i in range(N):
if A[i] == find_next:
find_next += 1
if find_next == 1:
print(-1)
else:
print(length - find_next + 1)
| 0 | null | 90,585,376,002,002 | 214 | 257 |
X = int(input())
if X >= 400 and X < 600:
print('8')
elif X >= 600 and X < 800:
print('7')
elif X >= 800 and X < 1000:
print('6')
elif X >= 1000 and X < 1200:
print('5')
elif X >= 1200 and X < 1400:
print('4')
elif X >= 1400 and X < 1600:
print('3')
elif X >= 1600 and X < 1800:
print('2')
elif X >= 1800 and X < 2000:
print('1')
|
x = int(input())
if 400 <= x and x <= 599:
ans = 8
elif 600 <= x and x <= 799:
ans = 7
elif 800 <= x and x <= 999:
ans = 6
elif 1000 <= x and x <= 1199:
ans = 5
elif 1200 <= x and x <= 1399:
ans = 4
elif 1400 <= x and x <= 1599:
ans = 3
elif 1600 <= x and x <= 1799:
ans = 2
else:
ans = 1
print(ans)
| 1 | 6,704,921,417,986 | null | 100 | 100 |
num = [[0 for i in range(101)] for j in range(101)]
r, c = map(int, input().split())
for i in range(r):
num[i][:c] = list(map(int, input().split()))
for j in range(c):
num[i][c] += num[i][j]
for j in range(c+1):
for i in range(r):
num[r][j] += num[i][j]
for i in range(r+1):
for j in range(c):
print(num[i][j], end=' ')
print(num[i][c])
|
r,c=map(int,input().split())
a = []
for i in range(r):
a.append(list(map(int, input().split())))
a[i]+=[sum(a[i])]
print(*a[i])
a=list(zip(*a[::-1]))
for i in range(c):print(sum(a[i]),end=' ')
print(sum(a[c]))
| 1 | 1,353,298,388,830 | null | 59 | 59 |
from math import *
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def div3(a,b):
c1=(2*a+b)/3
c2=(a+2*b)/3
return [c1,c2]
def main():
n=int(input())
xy=[[0,0],[100,0]]
#aa=list(map(int, input().split()))
for _ in range(n):
nxy=[[0,0]]
for [x0,y0],[x4,y4] in zip(xy,xy[1:]):
x1,x3=div3(x0,x4)
y1,y3=div3(y0,y4)
a=((x3-x1)**2+(y3-y1)**2)**0.5
rad=atan2(y3-y1,x3-x1)
x2=x1+a*cos(rad+pi/3)
y2=y1+a*sin(rad+pi/3)
nxy+=[[x1,y1],[x2,y2],[x3,y3],[x4,y4]]
xy=nxy
for x,y in xy:
print(x,y)
main()
|
T1, T2 = [int(i) for i in input().split()]
A1, A2 = [int(i) for i in input().split()]
B1, B2 = [int(i) for i in input().split()]
d1 = T1*(A1-B1)
d2 = T2*(B2-A2)
if d1 == d2:
print('infinity')
if d1 * (d2 - d1) < 0:
print(0)
if d1 * (d2 - d1) > 0:
if d1 % (d2 - d1) != 0:
print(d1 // (d2 - d1) * 2+ 1)
else:
print(d1 // (d2 - d1) * 2)
| 0 | null | 66,100,620,158,210 | 27 | 269 |
import math
n, a, b = map(int, input().split())
mod = 10**9 + 7
ans = pow(2, n, mod) - 1
x = 1
y = 1
for i in range(a):
x = x*(n - i)%mod
y = y*(i + 1)%mod
ans -= x*pow(y, mod - 2, mod)%mod
x = 1
y = 1
for i in range(b):
x = x*(n - i)%mod
y = y*(i + 1)%mod
ans -= x*pow(y, mod - 2, mod)%mod
print(ans%mod)
|
n=input()
s=''
for i in range(1,int(n)+1):
s += (' '+str(i)) if i%3==0 or '3' in str(i) else ''
print(s)
| 0 | null | 33,661,199,120,900 | 214 | 52 |
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
INF=float('inf')
N,M=MAP()
C=LIST()
dp=[INF]*(N+1)
dp[0]=0
for i in range(N):
for j in range(M):
if i+C[j]<=N:
dp[i+C[j]]=min(dp[i+C[j]], dp[i]+1)
print(dp[N])
|
def main():
N, M = map(int, input().split())
C = list(map(int, input().split()))
INF = 10**10
"""
使い回さない方
dp = [[INF]*(N+1) for _ in range(M+1)]
dp[0][0] = 0
for i in range(M):
for y in range(N+1):
if C[i] > y:
dp[i+1][y] = dp[i][y]
else:
dp[i+1][y] = min(dp[i][y], dp[i+1][y-C[i]]+1)
print(min([dp[j][N] for j in range(1, M+1)]))
"""
""" 使い回す方 """
dp = [INF]*(N+1)
dp[0] = 0
for i in range(M):
for y in range(N+1):
if C[i] <= y:
dp[y] = min(dp[y], dp[y-C[i]]+1)
print(dp[N])
if __name__ == "__main__":
main()
| 1 | 143,103,217,966 | null | 28 | 28 |
a, b, c, d = map(int, input().split())
if a>=0 and c>=0:
print(b*d)
elif b<=0 and d<=0:
print(a*c)
elif b<=0 and c>=0:
print(b*c)
elif a>=0 and d<=0:
print(a*d)
elif a<=0 and b>=0 and c<=0 and d>=0:
print(max([a*c, b*d]))
elif b<=0 and c<=0 and d>=0:
print(a*c)
elif a<=0 and b>=0 and d<=0:
print(a*c)
elif a<=0 and b>=0 and c>=0:
print(b*d)
elif a>=0 and c<=0 and d>=0:
print(b*d)
|
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
aMax = a[-1]
l = len(a)
count = 0
k = 0
kSet = set()
for i in range(n):
value = a[i]
if not(value in kSet):
if i != 0 and a[i-1] == value:
count -= 1
kSet.add(value)
continue
count += 1
j = 2
k = 0
while k < aMax:
k = a[i] * j
kSet.add(k)
j += 1
print(count)
| 0 | null | 8,685,296,611,338 | 77 | 129 |
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))
|
N,M = map(int,input().split())
ac = (N+1)*[0]
wa = (N+1)*[0]
pt = 0
for i in range(M):
p,s = input().split()
p = int(p)
if ac[p] == 0 and s == "AC":
ac[p] = 1
pt += wa[p]
wa[p] += 1
print(sum(ac),pt)
| 1 | 93,133,321,572,292 | null | 240 | 240 |
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
def main():
houses=[]
k,n=map(int,input().split())
houses=list(map(int,input().split()))
distance=[]
for i in range(1,n):
distance.append(houses[i]-houses[i-1])
distance.append(k-(houses[-1]-houses[0]))
max_length=max(distance)
print(sum(distance)-max_length)
if __name__=="__main__":
main()
|
def modpow(a, n, p):
if n == 0: return 0
elif n == 1: return a % p
elif n % 2: return (a * modpow(a, n - 1, p)) % p
else:
t = modpow(a, n // 2, p)
return (t * t) % p
def calc(n, r):
p, q = 1, 1
for i in range(r):
p = p * (n - i) % MOD
q = q * (i + 1) % MOD
return p * modpow(q, MOD - 2, MOD) % MOD
MOD = 10 ** 9 + 7
N, a, b = map(int, input().split())
s = modpow(2, N, MOD) - 1
print((s - (calc(N, a) + calc(N, b))) % MOD)
| 0 | null | 54,740,647,964,010 | 186 | 214 |
h, a = map(int, input().split())
l = list( map(int, input().split()))
if h - sum(l) <= 0:
print("Yes")
else:
print("No")
|
K, N = map(int, input().split())
A = list(map(int, input().split()))
A.append(K+A[0])
max_dist = max([A[i+1] - A[i] for i in range(N)])
print(K - max_dist)
| 0 | null | 60,627,512,313,828 | 226 | 186 |
line = list(input())
N = len(line)
i = 1
for i in range(N):
if line[i] == "?":
line[i] = "D"
print("".join(line))
|
import itertools
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
a = b = 0
for i, list_ in enumerate(list(itertools.permutations([i for i in range(1, n + 1)]))):
if tuple(p) == list_:
a = i + 1
if tuple(q) == list_:
b = i + 1
print(abs(a - b))
| 0 | null | 59,864,298,642,948 | 140 | 246 |
#!/usr/bin/env python3
X, Y = map(int, input().split())
if (X + Y) % 3:
exit(print(0))
m = (2*X - Y) // 3
n = X - 2*m
if n < 0 or m < 0:
exit(print(0))
## class
def egcd(a, b):
if a == 0:
return (b, 0, 1)
else:
g, y, x = egcd(b % a, a)
return (g, x - (b // a) * y, y)
def modinv(a, m):
g, x, y = egcd(a, m)
if g != 1:
raise Exception('modular inverse does not exist')
else:
return x % m
def power(a, b, c):
try:
return pow(a, b, c)
except (ValueError, TypeError) as e:
if b < 0:
return pow(modinv(a, c), -b, c)
else:
print(e)
class Factorial:
def __init__(self, n, mod):
self.f = f =[0] * (n + 1)
f[0] = b = 1
for i in range(1, n + 1):f[i] = b = b * i % mod
self.inv = inv = [0] * (n + 1)
inv[n] = b = power(self.f[n], -1, mod)
for i in range(n,0,-1):inv[i-1] = b = b * i % mod
self.mod = mod
def factorial(self, i):
return self.f[i]
def ifactorial(self, i):
return self.inv[i]
def comb(self, n, k):
if n >= k:return self.f[n] * self.inv[n - k] * self.inv[k] % self.mod
else:return 0
def nCr(n, r, mod = None, limit = None):
if mod and limit:
return Factorial(limit, mod).comb(n, r)
elif mod:
r = min(r, n - r)
a = 1
for i in range(r):
a = a * (n - i) * power(i + 1, mod - 2, mod) % mod
return a
else:
from math import factorial as f
return f(n) // (f(n - r) * f(r))
MOD = 10**9+7
print(nCr(m + n, n, MOD, 2*10**6))
|
n,m=map(int,input().split())
a=list(map(int,input().split()))
h=sum(a)
if n<h:
print('-1')
else:
print(n-h)
| 0 | null | 90,590,369,382,940 | 281 | 168 |
s = input()
days = ["", "SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"]
print(days.index(s))
|
import itertools
import math
N = int(input())
citys = []
for i in range(N):
citys.append([int(x) for x in input().split()])
a = list(itertools.permutations(range(N), N))
ans = 0
for i in a:
b = 0
for j in range(N-1):
b += math.sqrt((citys[i[j]][0] - citys[i[j+1]][0])**2 + (citys[i[j]][1] - citys[i[j+1]][1])**2)
ans += b
print(ans/len(a))
| 0 | null | 140,794,192,841,720 | 270 | 280 |
N, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
result = 0
mod = 10**9+7
def cmb(n, r, mod=mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
n = 10**5+1
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, n+1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
if k==1:
print(0)
else:
result = 0
for i in range(N-k+1):
result += (a[N-i-1]-a[i])*cmb(N-1-i, k-1)
result %= mod
print(result%mod)
|
n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = input()
last = ["" for _ in range(k)]
move = {"r": "p", "p": "s", "s": "r"}
pts = {"r": r, "p": p, "s": s}
score = 0
for i in range(n):
if move[t[i]] != last[i%k]:
score += pts[move[t[i]]]
last[i%k] = move[t[i]]
else:
last[i%k] = ""
print(score)
| 0 | null | 101,148,741,646,560 | 242 | 251 |
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))
K, X = input_nums()
if 500*K >= X:
print('Yes')
else:
print('No')
|
import math
A,B,H,M = map(int,input().split())
print((A**2+B**2-2*A*B*math.cos(math.radians(6*M-30*(H+(M/60)))))**(1/2))
| 0 | null | 59,222,104,388,810 | 244 | 144 |
input()
A = [int(i) for i in input().split()]
c = 0
def bubble_sort(A):
global c
flag = True
while flag:
flag = False
for i in range(len(A)-1, 0, -1):
if A[i] < A[i -1]:
A[i], A[i -1] = A[i -1], A[i]
c += 1
flag = True
bubble_sort(A)
print(*A)
print(c)
|
n = int(input())
m = list(map(int, input().split()))
count = 0
flag = 1
while flag:
flag = 0
for j in range(n-1, 0, -1):
if m[j] < m[j-1]:
m[j], m[j-1] = m[j-1], m[j]
count += 1
flag = 1
print(" ".join(str(x) for x in m))
print(count)
| 1 | 17,207,088,628 | null | 14 | 14 |
while 1:
x, y =map(int,input().split())
if not x+y:break
if x>y:x,y=y,x
print(x,y)
|
while True:
a,b=map(int,input().split())
if not(a) and not(b):break
if a>b:a,b=b,a
print(a,b)
| 1 | 515,437,798,304 | null | 43 | 43 |
input()
*l,=map(int,input().split())
print((pow(sum(l),2)-sum([pow(x,2) for x in l]))//2)
|
import itertools,numpy as np,sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
A = LI()
sum_A = sum(A)
accumulate_A = np.array(list(itertools.accumulate(A)))
sub_A1 = sum_A-accumulate_A
sub_A2 = sum_A-sub_A1
print(np.abs(sub_A1-sub_A2).min())
| 0 | null | 154,510,936,112,608 | 292 | 276 |
import sys
ERROR_INPUT = 'input is invalid'
def main():
n = get_length()
arr = get_array(length=n)
sourtLi, count = bubbleSort(li=arr, length=n)
print(*sourtLi)
print(count)
return 0
def get_length():
n = int(input())
if n < 0 or n > 100:
print(ERROR_INPUT)
sys.exit(1)
else:
return n
def get_array(length):
nums = input().split(' ')
return [str2int(string=n) for n in nums]
def str2int(string):
n = int(string)
if n < 0 or n > 100:
print(ERROR_INPUT)
sys.exit(1)
else:
return n
def bubbleSort(li, length):
count = 0
for n in range(length):
for n in range(1, length - n):
if li[n] < li[n - 1]:
li[n], li[n - 1] = li[n - 1], li[n]
count += 1
return li, count
main()
|
print(*{"ABC","ARC"}-{input()})
| 0 | null | 11,977,749,292,818 | 14 | 153 |
N,K=map(int,input().split())
p=list(map(int,input().split()))
res=0
s=sum(p[:K])
for i in range(N-K+1):
res=max(res,(s+K)/2)
if i!=N-K:
s=s+p[i+K]-p[i]
print(res)
|
n,k = map(int,input().split())
p = [int(x) for x in input().split()]
sum1 = sum(p[:k])
num = k-1
max1 = sum1
for i in range(k,n):
sum1 = sum1 - p[i-k] + p[i]
if sum1 >= max1:
max1 = sum1
num = i
#print(max1,sum1,i)
sum2 = sum(p[num-k+1:num+1])
def goukei(j):
return 1/2 * j * (j+1)
print(float((goukei(sum2)-goukei(k-1))/(sum2 -k +1)))
| 1 | 75,241,299,264,560 | null | 223 | 223 |
N=int(input())
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
# divisors.sort()
return divisors
#print(make_divisors(3141))
#N, N-1, 2
#%*==1
ans=[2]
if N not in ans:
ans.append(N)
if (N%(N-1)!=0) and (N-1 not in ans):
ans.append(N-1)
D=make_divisors(N)
for d in D:
now=N
if d==1:
continue
while now%d==0:
now=now//d
if now%d==1:
if d not in ans:
ans.append(d)
#print(ans)
ans2=[]
for a in ans:
i=1
while a**i<=N:
x=a**i
now=N
while now%x==0:
now=now//x
if now%x==1:
if x not in ans2:
ans2.append(x)
i+=1
#print(ans2)
d2=make_divisors(N-1)
for d in d2:
if d!=1 and (d not in ans2):
ans2.append(d)
#print(ans2)
print(len(ans2))
|
n,m=list(map(int,input().split()))
mA=[list(map(int,input().split())) for i in range(n)]
mB=[int(input()) for j in range(m)]
for ma in mA:
print(sum([a*b for a, b in zip(ma,mB)]))
| 0 | null | 21,176,620,428,992 | 183 | 56 |
from collections import defaultdict
from math import gcd
MOD = 1000000007
N = int(input())
zeros = 0
bads = defaultdict(lambda: [0, 0])
for _ in range(N):
x, y = map(int, input().split())
# 両方ゼロの時の例外処理
if x == 0 and y == 0:
zeros += 1
continue
# 180度回転
if y < 0 or (y == 0 and x < 0):
x, y = -x, -y
g = gcd(x, y)
x, y = x // g, y // g
if x > 0:
bads[(x, y)][0] += 1
else:
bads[(y, -x)][1] += 1
ans = 1
for k, l in bads.values():
ans *= (pow(2, k, MOD) - 1) + (pow(2, l, MOD) - 1) + 1
ans %= MOD
print((ans + zeros - 1) % MOD)
|
import sys
from collections import defaultdict
from math import gcd
sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline
MOD = 10 ** 9 + 7
def solve():
N = int(rl())
AB = tuple(tuple(map(int, rl().split())) for _ in range(N))
zero_pare = 0
zero_a, zero_b = 0, 0
counter = defaultdict(int)
for a, b in AB:
if a == b == 0:
zero_pare += 1
elif a == 0:
zero_a += 1
elif b == 0:
zero_b += 1
else:
cd = gcd(a, b)
a, b = a // cd, b // cd
if b < 0:
a, b = -a, -b
counter[(a, b)] += 1
ans = pow(2, zero_a, MOD) + pow(2, zero_b, MOD) - 1
memo = set()
for a, b in list(counter):
if (a, b) in memo:
continue
pa, pb = -b, a
if pb < 0:
pa, pb = -pa, -pb
memo.add((a, b))
memo.add((pa, pb))
ans *= pow(2, counter[(a, b)], MOD) + pow(2, counter[(pa, pb)], MOD) - 1
ans %= MOD
ans = (ans + zero_pare - 1) % MOD
print(ans)
if __name__ == '__main__':
solve()
| 1 | 21,008,371,393,832 | null | 146 | 146 |
from collections import Counter
def main():
n = int(input())
S = [input() for _ in range(n)]
c = Counter(S).most_common()
V = c[0][1]
ans = [k for k, v in c if v == V]
[print(a) for a in sorted(ans)]
if __name__ == '__main__':
main()
|
import math
import sys
import collections
import bisect
readline = sys.stdin.readline
def main():
n = int(readline().rstrip())
S = [readline().rstrip() for _ in range(n)]
c = collections.Counter(S)
keys = sorted(c.keys())
maxS = c.most_common()[0][1]
for key in keys:
if c[key] == maxS:
print(key)
if __name__ == '__main__':
main()
| 1 | 70,169,220,287,332 | null | 218 | 218 |
def main():
from random import sample
from operator import itemgetter
e=enumerate
n,a=open(0)
n=int(n)
d=[0]+[-2**64]*n
for j,(a,i)in e(sorted(sample([(a,i)for i,a in e(map(int,a.split()))],n),key=itemgetter(0),reverse=1)):
d=[max(t+a*(~i-j+k+n),d[k-1]+a*abs(~i+k))for k,t in e(d)]
print(max(d))
main()
|
while True:
H, W = map(int, input().split())
if H == W == 0:
break
print('#'*W)
for _ in range(H-2):
print('#'+'.'*(W-2)+'#')
print('#'*W, end='\n\n')
| 0 | null | 17,120,590,562,822 | 171 | 50 |
s = input()
if s.count('B') == 3 or s.count("A") == 3:
print("No")
else:
print("Yes")
|
#Macで実行する時
import sys
import os
if sys.platform=="darwin":
base = os.path.dirname(os.path.abspath(__file__))
name = os.path.normpath(os.path.join(base, '../atcoder/input.txt'))
sys.stdin = open(name)
l = list(input())
#print(l)
set_l = set(l)
if len(set_l)==1:
print("No")
else:
print("Yes")
| 1 | 54,991,509,560,560 | null | 201 | 201 |
N = int(input())
S = []
for _ in range(N):
S.append(input())
ac = 0
wa = 0
tle = 0
re = 0
for s in S:
if s == "AC":
ac += 1
if s == "WA":
wa += 1
if s == "TLE":
tle += 1
if s == "RE":
re += 1
print("AC x ",ac)
print("WA x ",wa)
print("TLE x ",tle)
print("RE x ",re)
|
N = int(input())
S = [input() for _ in range(N)]
C0 = 0
C1 = 0
C2 = 0
C3 = 0
for i in range(N):
if S[i] == "AC": C0 += 1
elif S[i] == "WA": C1 += 1
elif S[i] == "TLE": C2 += 1
else: C3 += 1
print("AC x "+ str(C0))
print("WA x "+ str(C1))
print("TLE x "+ str(C2))
print("RE x "+ str(C3))
| 1 | 8,702,509,949,992 | null | 109 | 109 |
import sys
for line in sys.stdin:
H, W = map(int, line.split())
if H == 0 and W == 0:
break
for _ in range(H):
print( '#' * W )
print("")
|
while 1:
h,w = map(int,raw_input().split())
if h==w==0: break
print ("#"*w+"\n")*h
| 1 | 783,214,848,224 | null | 49 | 49 |
def main():
H, N = map(int, input().split(' '))
A = input().split(' ')
total = 0
for i in A:
total += int(i)
if total >= H:
print('Yes')
else:
print('No')
main()
|
H, N = map(int, input().split())
A = list(map(int, input().split()))
SUM = 0
for i in range(len(A)):
SUM = SUM + A[i]
if SUM >= H:
print('Yes')
else:
print('No')
| 1 | 77,858,425,087,880 | null | 226 | 226 |
i=0
while True:
N=int(input())
if N==0:
break
else:
a = list(map(float,input().split()))
m=sum(a)/N
#print(m)
for i in range(N):
a[i]=(float)(a[i]-m)**2
#print(a[i])
i+=1
A=(sum(a)/N)**(1/2)
print(A)
|
while 1:
n=int(input())
if n==0:break
s=list(map(int,input().split()))
print((sum([(m-sum(s)/n)**2 for m in s])/n)**.5)
| 1 | 191,019,502,814 | null | 31 | 31 |
def main():
K, X = map(int, input().split())
m = K * 500
if m >= X:
print('Yes')
else:
print('No')
main()
|
H1, M1, H2, M2, K = list(map(int,input().split()))
a = 60*H1 + M1
b = 60*H2 + M2
print(b - a - K)
| 0 | null | 58,455,313,378,720 | 244 | 139 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
SS = ['SUN','MON','TUE','WED','THU','FRI','SAT']
S = readline().decode().rstrip()
for i in range(7):
if S == SS[i]:
print(7-i)
sys.exit()
|
k, n = map(int, input().split())
a = sorted(list(map(int, input().split())))
x = [(a[i]-a[i-1]) for i in range(1,n)]
x.append(k-a[n-1]+a[0])
y=sorted(x)
print(sum(y[:-1]))
| 0 | null | 88,753,395,653,692 | 270 | 186 |
#!/usr/bin/env python3
# from numba import njit
import sys
sys.setrecursionlimit(10**8)
# input = stdin.readline
# @njit
def solve(n,k,r,s,p,t):
winHand = {"r":"p", "s":"b", "p":"s"}
bestHandMemo = [""]*(n+1) # i手目の勝ち手
memo = [-1]*(n+1)
def calcPoint(char):
if char == "r":
return p
elif char == "s":
return r
elif char == "p":
return s
else:
raise ValueError
def dp(i):
if i == 0:
return 0
elif memo[i] != -1:
return memo[i]
elif i <= k:
bestHandMemo[i-1] = winHand[t[i-1]] # 自由に出せる
return dp(i-1) + calcPoint(t[i-1])
elif winHand[t[i-1]] == bestHandMemo[i-k-1]:
bestHandMemo[i-1] = "" # あいこでも負けても同じこと
return dp(i-1)
else: # 勝てる
bestHandMemo[i-1] = winHand[t[i-1]]
return dp(i-1) + calcPoint(t[i-1])
for i in range(n+1):
memo[i] = dp(i)
return memo[n]
def main():
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
print(solve(N,K,R,S,P,T))
return
if __name__ == '__main__':
main()
|
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
ret = 0
for i in range(k):
last = 'x'
for c in t[i::k]:
if last != c:
ret += p if c == 'r' else r if c == 's' else s
last = c
else:
last = 'x'
print(ret)
| 1 | 106,727,095,146,684 | null | 251 | 251 |
i = 1
while True:
x, y = map(int, input().split())
if x == 0 and y == 0:
break
else:
print(min(x,y), max(x,y))
|
while 1:
s,t = map(int,input().split())
if s>t:
s,t = t,s
if (s,t)==(0,0):
break
print(s,t)
| 1 | 526,265,202,240 | null | 43 | 43 |
while True:
n, x = map(int, input().split())
if n == 0 and x == 0:
break
c = 0
for i in range(1, int(x/3)+2):
for j in range(i+1, int(x/2)+2):
k = x - i - j
if k <= j:
break
elif k <= n:
c += 1
print(c)
|
while True:
n, x = map(int, input().split())
if n == x == 0:
break
cnt = 0
for a in range(1, x // 3):
for b in range(a + 1, x // 2):
c = x - a - b
if b < c <= n:
cnt += 1
print(cnt)
| 1 | 1,299,627,586,520 | null | 58 | 58 |
n,m =map(int,input().split())
if n <= m:
print('unsafe')
else:
print("safe")
|
from math import factorial
def combination(n, r):
return factorial(n)//(factorial(n-r) * factorial(r))
def answer(n,k):
ans = 0
if k>1:
if n=='':
return 0
# 先頭が0の時
if n[0]=='0':
ans += answer(n[1:],k)
else:
# 先頭以外で3つ使う
if len(n)>k:
ans += combination(len(n)-1,k)*9**k
# 先頭で一つ使うが、先頭はNの先頭より小さい
if len(n)>k-1:
ans += (int(n[0])-1)*combination(len(n)-1,k-1)*9**(k-1)
# 先頭で、Nの先頭と同じ数を使う
ans += answer(n[1:],k-1)
else:
if n=='':
return 0
if n[0]=='0':
ans += answer(n[1:],k)
else:
if len(n)>1:
ans += combination(len(n)-1,1)*9
ans += int(n[0])
return ans
n = input()
k = int(input())
print(answer(n,k) if len(n)>=k else 0)
| 0 | null | 52,637,835,519,400 | 163 | 224 |
from itertools import accumulate
a=[]
for i in range(12):
a.append(26**i)
b=list(accumulate(a))
alpha=['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())
num=0
for i in range(12):
if N < b[i] :
num=i
break
M=N-b[num-1]
r=M
for i in range(num):
q=r//26**(num-i-1)
r=r%26**(num-i-1)
print(alpha[q],end='')
|
def main():
N = int(input())
result = []
while N > 0:
N -= 1
mod = N % 26
result.append(chr(mod + ord('a')))
N //= 26
result_str = ""
for i in range(len(result)-1, -1, -1):
result_str += result[i]
print(result_str)
main()
| 1 | 11,935,321,277,630 | null | 121 | 121 |
import sys
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 998244353
def resolve():
n = int(input())
D = list(map(int, input().split()))
tree = [0 for _ in range(max(D) + 1)]
for i in range(n):
idx = D[i]
tree[idx] += 1
if D[0] != 0 or tree[0] != 1 or 0 in tree:
print(0)
exit()
res = 1
for i in range(len(tree) - 1):
res *= pow(tree[i], tree[i + 1], mod)
print(res % mod)
if __name__ == '__main__':
resolve()
|
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))
P.sort(reverse=True)
Q.sort(reverse=True)
temp = P[:X] + Q[:Y] + R
temp.sort(reverse=True)
ans = sum(temp[:X+Y])
print(ans)
| 0 | null | 99,866,669,428,932 | 284 | 188 |
X = int(input())
while True:
flag = True
for i in range(2, X):
if X % i == 0:
flag = False
if flag: break
X += 1
print(X)
|
X = int(input())
while True:
flag = True
for i in range(2,X):
if X%i == 0:
flag = False
break
if flag:
break
X += 1
print(X)
| 1 | 105,110,592,300,160 | null | 250 | 250 |
W, H, x, y, r = [int(a) for a in input().split()]
if r <= x and x <= W - r and r <= y and y <= H - r:
print('Yes')
else:
print('No')
|
from decimal import Decimal
a,b,c=map(Decimal,input().split())
if (a.sqrt()+b.sqrt())<c.sqrt():
print("Yes")
else:
print("No")
| 0 | null | 25,870,750,926,010 | 41 | 197 |
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A, reverse = True)
for i in range(min(K, N)):
A[i] = 0
ans = sum(A)
print(ans)
|
import heapq
(N,K) = map(int,input().split())
h = [int(x)*-1 for x in input().split()]
ans = 0
heapq.heapify(h)
if K <= N:
for i in range(K):
heapq.heappop(h)
while h != []:
ans -= heapq.heappop(h)
print(ans)
| 1 | 79,007,513,365,470 | null | 227 | 227 |
a = list(map(int, input().split()))
kishou = a[0] * 60 + a[1]
shuusin = a[2] * 60 + a[3]
print(shuusin - kishou - a[4])
|
class Com:
def __init__(self, MAX = 1000000, MOD = 1000000007):
self.MAX = MAX
self.MOD = MOD
self._fac = [0]*MAX
self._finv = [0]*MAX
self._inv = [0]*MAX
self._fac[0], self._fac[1] = 1, 1
self._finv[0], self._finv[1] = 1, 1
self._inv[1] = 1
for i in range(2,self.MAX):
self._fac[i] = self._fac[i - 1] * i % self.MOD
self._inv[i] = self.MOD - self._inv[self.MOD%i] * (self.MOD // i) % self.MOD
self._finv[i] = self._finv[i - 1] * self._inv[i] % self.MOD
def com(self, n, k):
if (n < k):
return 0
if (n < 0 or k < 0):
return 0
return self._fac[n] * (self._finv[k] * self._finv[n - k] % self.MOD) % self.MOD
a,b = list(map(int,input().split()))
if 2*a-b >= 0 and (2*a-b)%3 == 0 and a-2*((2*a-b)//3) >= 0:
x = (2*a-b)//3
y = a-2*x
com = Com()
print(com.com(x+y, x))
exit()
a,b = b,a
if 2*a-b >= 0 and (2*a-b)%3 == 0 and a-2*((2*a-b)//3) >= 0:
x = (2*a-b)//3
y = a-2*x
com = Com()
print(com.com(x+y, x))
exit()
print(0)
| 0 | null | 84,269,803,947,600 | 139 | 281 |
A, B = [int(x) for x in input().split()]
if A >= 10 or B >= 10:
print(-1)
else:
print(A*B)
|
a = [int(i) for i in input().split()]
if(max(a) > 9):
print("-1")
else:
print(a[0] * a[1])
| 1 | 157,940,699,315,238 | null | 286 | 286 |
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
array_sum = sum(a) % mod
ans = 0
for i in range(n):
ans += a[i] * array_sum % mod
ans -= a[i] * a[i] % mod
print((ans * pow(2,-1,mod)) % mod)
|
# coding: utf-8
# 日本語を入力できるようにするために上記一文が必要
N = int(input())
A_input = list(map( int, input().split()))
j_sum = 0
for j in range(N):
j_sum = j_sum + A_input[j]
sum = 0
for i in range(N - 1 ):
j_sum = j_sum - A_input[i]
sum = sum + A_input[i] * j_sum
print(sum % (10**9 + 7) )
| 1 | 3,843,500,114,420 | null | 83 | 83 |
house1 = [[0 for x in range(10)], [0 for x in range(10)], [0 for x in range(10)]]
house2 = [[0 for x in range(10)], [0 for x in range(10)], [0 for x in range(10)]]
house3 = [[0 for x in range(10)], [0 for x in range(10)], [0 for x in range(10)]]
house4 = [[0 for x in range(10)], [0 for x in range(10)], [0 for x in range(10)]]
houses = [house1, house2, house3, house4]
n = int(input())
for i in range(n):
b, f, r, v = [int(x) for x in input().split()]
houses[b - 1][f - 1][r - 1] += v
cnt = 0
for house in houses:
for floor in house:
floor = [str(x) for x in floor]
print(' ' + ' '.join(floor))
if cnt != 3:
print('#' * 20)
cnt += 1
|
K=int(input())
A,B=map(int,input().split())
ans=0
i=1
while K*i<=1000:
if A<=K*i and K*i<=B:
ans=1
break
i+=1
if ans==1:
print("OK")
else:
print("NG")
| 0 | null | 13,941,387,440,110 | 55 | 158 |
def backtrack(nums, step, result):
if len(step) == 3:
if len(set(step)) == 3:
sorted_step = sorted(step)
a,b,c = sorted_step
if a+b > c:
result.append(step[:])
else:
for i in range(len(nums)):
step.append(nums[i])
backtrack(nums[i+1:], step, result)
step.pop()
def solve():
N = int(input())
L = [int(i) for i in input().split()]
result = []
backtrack(L, [], result)
print(len(result))
if __name__ == "__main__":
solve()
|
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) #二個目の要素で降順並び替え
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)) #改行行列
s=input()
ls=len(s)
tot=pow(26,ls+K,mod)
def extgcd1(a0,b0):#計算量log(b0),フェルマーの小定理より早い
u,v,a,b=1,0,a0,b0
while b:
t=a//b; a-=t*b; a,b=b,a; u,v=v,u-t*v
if a!=1: return -1#互いに素じゃない
return u%b0
N=ls+K
fact=[0]*(N+1)#NはnCrの最大のn
ifact=[0]*(N+1)
fact[0],fact[1],ifact[0],ifact[1]=1,1,1,1
for i in range(2,N+1):
x=(fact[i-1]*i)%mod
fact[i]=x
ifact[i]=extgcd1(x,mod)
pows=[1]*(N+1)
for i in range(1,N+1):
pows[i]=pows[i-1]*25%mod
def comb(n,r): return (fact[n]*ifact[r]%mod)*ifact[n-r]%mod
for i in range(0,ls):
tot-=comb(ls+K,i)*pows[ls+K-i]
tot%=mod
print(tot)
if __name__ == "__main__":
main()
| 0 | null | 8,891,255,968,518 | 91 | 124 |
kyu = [2000, 1800, 1600, 1400, 1200, 1000, 800, 600, 400, 0]
x = int(input())
for k, num in enumerate(kyu):
if num > x >= kyu[k+1]:
print(k + 1)
break
|
import sys
n=int(input())
l=n//100
d=n%100
for i in range(5, 0, -1):
if d // i > 0:
l = l - (d // i)
d = d - i * (d // i)
if d == 0 and l >= 0:
print(1)
sys.exit()
if l < 0:
break
print(0)
| 0 | null | 66,971,989,483,360 | 100 | 266 |
#ABC156B
n,k = map(int,input().split())
ans = 0
while n > 0 :
n = n // k
ans = ans + 1
print(ans)
|
n, k = map(int, input().split())
ans = 0
while n != 0:
n //= k
ans += 1
print(ans)
| 1 | 64,248,831,950,116 | null | 212 | 212 |
N, K = map(int,input().split())
A = list(map(int,input().split()))
B = [0];BB=[0]
S = set([]);S.add(0)
now = 0
Flag = False
loop_start = -1
if K <= 2*pow(10,5)+10:
for i in range(K):
nxt = A[now]-1
BB.append(nxt)
now = nxt
#print(BB)
print(BB[K]+1)
exit()
for i in range(N*2):
nxt = A[now]-1
#print(now,nxt)
if nxt in S:
if Flag:
if nxt == loop_start:
#print(nxt,i)
loop_cycle = i-loop_num
break
else:
loop_start = nxt
loop_num = i
B.append(nxt)
#print(loop_num,loop_start,B)
Flag = True
else:
B.append(nxt);S.add(nxt)
now = nxt
loop_num += 1-loop_cycle
#print(B,loop_start,loop_cycle,loop_num)
loc = (K-loop_num)%loop_cycle+loop_num
#print(loc)
#print(len(B))
print(B[loc]+1)
|
n, k = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))
ls = [-1] * n
now = 0
cnt = 0
path = []
while 1:
if ls[now] != -1:
b = ls[now]
break
ls[now] = cnt
path.append(now)
now = a[now]
cnt += 1
loop = path[b:]
if k <= b:
print(path[k] + 1)
else:
print(loop[(k - b) % len(loop)] + 1)
| 1 | 22,924,324,495,940 | null | 150 | 150 |
N , D = map(int, input(). split())
Z = [list(map(int, input().split())) for i in range(N)]
total = 0
for point in Z:
if point[0]**2 + point[1]**2 <= D**2:
total += 1
else:
continue
print(total)
|
import numpy as np
def main(Z, D):
lengthes = np.linalg.norm(Z, axis=1)
ans = np.sum(lengthes<=D)
return ans
if __name__ == '__main__':
N, D = map(int, input().split())
Z = np.zeros([N, 2])
for i in range(N):
X, Y = map(int, input().split())
Z[i][0] = X
Z[i][1] = Y
#print(Z)
ans = main(Z, D)
print(ans)
| 1 | 5,959,092,611,238 | null | 96 | 96 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.