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 numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
i8 = np.int64
i4 = np.int32
def main():
stdin = open('/dev/stdin')
pin = np.fromstring(stdin.read(), i8, sep=' ')
N = pin[0]
M = pin[1]
L = pin[2]
ABC = pin[3: M * 3 + 3].reshape((-1, 3))
A = ABC[:, 0] - 1
B = ABC[:, 1] - 1
C = ABC[:, 2]
Q = pin[M * 3 + 3]
st = (pin[M * 3 + 4: 2 * Q + M * 3 + 4] - 1).reshape((-1, 2))
s = st[:, 0]
t = st[:, 1]
graph = csr_matrix((C, (A, B)), shape=(N, N))
dist = np.array(floyd_warshall(graph, directed=False))
dist[dist > L + 0.5] = 0
dist[dist > 0] = 1
min_dist = np.array(floyd_warshall(dist))
min_dist[min_dist == np.inf] = 0
min_dist = (min_dist + .5).astype(int)
x = min_dist[s, t] - 1
print('\n'.join(x.astype(str).tolist()))
if __name__ == '__main__':
main()
| #coding:utf-8
N = int(input())
taro = 0
hanako = 0
for i in range(N):
strs = input().split()
if strs[0] > strs[1]:
taro += 3
elif strs[0] < strs[1]:
hanako += 3
else:
taro+=1
hanako+=1
print(str(taro) + " " + str(hanako)) | 0 | null | 87,942,485,536,078 | 295 | 67 |
a, b, c, k = map(int,input().split())
if k <= a:
print(k)
elif a < k <= a + b:
print(a)
elif a + b <= k:
print(a*2 - k + b)
| count = input()
#print(len(count))
num = 0
for i in range(len(count)):
num += int(count[i])
if num % 9 == 0:
print("Yes")
else:
print("No") | 0 | null | 13,065,478,437,840 | 148 | 87 |
a = int(input())
print(2*a*3.14)
| import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()
def resolve():
N = I()
S = SS()
ans = [chr((ord(i) - ord('A') + N) % 26 + ord('A')) for i in S]
print(''.join(ans))
if __name__ == '__main__':
resolve()
| 0 | null | 82,736,837,844,320 | 167 | 271 |
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n,k = nm()
MOD = 10**9+7
ans = 0
for kk in range(k,n+2):
# print()
aa = (n-kk+n+1)*kk//2
bb = (0+kk-1)*kk//2
# print(aa)
# print(bb)
a=aa-bb
# print(a)
ans+=a+1%MOD
print(ans%MOD) | import math
while True:
n = int(input())
if n == 0:
break
arr = list(map(int, input().split()))
m = sum(arr) / n
t = 0
for i in range(n):
t += math.pow(arr[i] - m, 2)
a = math.sqrt(t/n)
print("{0:5f}".format(a))
| 0 | null | 16,614,786,942,650 | 170 | 31 |
if __name__ == "__main__":
A,B,C = map(int,input().split())
K = int(input())
count = 0
while A>=B:
B *= 2
count += 1
while B>=C:
C *= 2
count += 1
print("Yes" if count <= K else "No") | N,P = map(int,input().split())
S = list(map(int,list(input())))
if P==2:
cnt = 0
for i in range(N):
if S[i]%2==0:
cnt += i+1
elif P==5:
cnt = 0
for i in range(N):
if S[i]==0 or S[i]==5:
cnt += i+1
else:
A = [0 for _ in range(N)]
a = 0
b = 1
for i in range(N-1,-1,-1):
a = (a+b*S[i])%P
A[i] = a
b = (b*10)%P
C = {i:0 for i in range(P)}
for i in range(N):
C[A[i]] += 1
cnt = 0
for i in range(P):
cnt += (C[i]*(C[i]-1))//2
cnt += C[0]
print(cnt) | 0 | null | 32,486,716,586,782 | 101 | 205 |
import math
n, M= map(int,input().split())
#AB=[]
#N = int(input())
#C = input()
parents = [-1] * n
def find( x):
if parents[x] < 0:
return x
else:
parents[x] = find(parents[x])
return parents[x]
def union(x, y):
x = find(x)
y = find(y)
if x == y:
return
if parents[x] > parents[y]:
x, y = y, x
parents[x] += parents[y]
parents[y] = x
def size( x):
return -parents[find(x)]
def same( x, y):
return find(x) == find(y)
def members( x):
root = find(x)
return [i for i in range(n) if find(i) == root]
def roots():
return [i for i, x in enumerate(parents) if x < 0]
def group_count():
return len(roots())
def all_group_members():
return {r: members(r) for r in roots()}
def __str__():
return '\n'.join('{}: {}'.format(r, members(r)) for r in roots())
C = []
for i in range(M):
A, B = map(int,input().split())
union(A-1,B-1)
'''
c = 0
for p in C:
if A in p:
c = 1
p.add(B)
elif B in p:
c = 1
p.add(A)
if c != 1:
C.append(set([A,B]))
'''
print(group_count()-1)
| order=[]
for number in range(10):
hight=int(input())
order.append(hight)
for j in range(9):
for i in range(9):
if order[i] < order[i+1]:
a = order[i]
b = order[i+1]
order[i] = b
order[i+1] = a
for i in range(3):
print(order[i]) | 0 | null | 1,160,276,538,980 | 70 | 2 |
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7
x,k,d = map(int,readline().split())
x = abs(x)
if (x >= k*d):
print(x-k*d)
elif ((k-x//d)%2):
print(abs(x%d-d))
else:
print(x%d)
| X,K,D=list(map(int,input().split()))
X=abs(X)
import sys
if X > 0 and X-K*D>=0:
print(X-K*D)
sys.exit()
M=X//D
Q=X%D
if M%2 == K%2:
print(Q)
else:
print(D-Q)
| 1 | 5,268,152,556,612 | null | 92 | 92 |
#!/usr/bin/env python3
import sys
from math import gcd
from collections import defaultdict
sys.setrecursionlimit(10**8)
MOD = 1000000007 # type: int
def solve(N: int, A: "List[int]", B: "List[int]"):
def quadrant(a, b):
if a > 0 and b >= 0:
return 0
elif a <= 0 and b > 0:
return 1
elif a < 0 and b <= 0:
return 2
elif a >= 0 and b < 0:
return 3
else:
return None
def norm(a, b):
g = gcd(a, b)
a //= g
b //= g
while quadrant(a, b) != 0:
a, b = -b, a
return a, b
d = defaultdict(lambda: [0, 0, 0, 0])
kodoku = 0
for i, (a, b) in enumerate(zip(A, B)):
if (a, b) == (0, 0):
kodoku += 1
else:
d[norm(a, b)][quadrant(a, b)] += 1
ans = 1
for v in d.values():
buf = pow(2, v[0]+v[2], MOD)
buf += pow(2, v[1]+v[3], MOD)
buf = (buf-1) % MOD
ans *= buf
ans %= MOD
print((ans-1+kodoku) % MOD)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
A = [int()] * (N) # type: "List[int]"
B = [int()] * (N) # type: "List[int]"
for i in range(N):
A[i] = int(next(tokens))
B[i] = int(next(tokens))
solve(N, A, B)
if __name__ == '__main__':
main()
| import sys
input = sys.stdin.readline
import collections
import fractions
from collections import defaultdict
import math
n=int(input())
a= [list(map(int, input().split())) for i in range(n)]
b=defaultdict(int)
c=defaultdict(int)
b0=0
c0=0
mod=1000000007
ans=1
cnt=0
for i,j in a:
if i!=0 and j!=0:
x=i
y=j
i //= math.gcd(x, y)
j //= math.gcd(x, y)
i=abs(i)
j=abs(j)
if x*y>0:
b[(i,j,0)]+=1
c[(j,i,1)]+=1
else:
b[(i,j,1)]+=1
c[(j,i,0)]+=1
elif i==0 and j!=0:
b0+=1
elif i!=0 and j==0:
c0+=1
else:
cnt+=1
w=[]
if c0!=0 or b0!=0:
ans*=pow(2,c0+b0)-((pow(2,c0,mod)-1)*(pow(2,b0,mod)-1))
for k,v in b.items():
if c[k]!=0:
ans*=(pow(2,c[k]+v,mod)-(pow(2,c[k],mod)-1)*(pow(2,v,mod)-1))
w.append((pow(2,c[k]+v,mod)-(pow(2,c[k],mod)-1)*(pow(2,v,mod)-1)))
ans%=mod
else:
ans*=pow(2,v,mod)
ans%=mod
w=collections.Counter(w)
w=list(w.most_common())
for i,j in w:
for k in range(j//2):
ans*=pow(i,mod-2,mod)
ans+=cnt-1
print(int(ans%mod)) | 1 | 20,948,008,818,368 | null | 146 | 146 |
from math import floor
from fractions import Fraction
a,b = input().split()
a = int(a)
b = Fraction(b)
print(floor(a*b)) | a, b = input().split()
a = int(a)
b = int(round(float(b) * 100))
print(a * b // 100) | 1 | 16,522,795,342,362 | null | 135 | 135 |
# ABC160
X = int(input())
ans = 0
coin_500 = 0
coin_5 = 0
coin_500 = X//500
X = X - coin_500*500
coin_5 = X//5
print(coin_500*1000+coin_5*5) | #!/usr/bin/env python3
import sys
def solve(L: int):
return (L / 3) ** 3
def main():
L = int(sys.stdin.readline().strip()) # type: int
print(solve(L))
if __name__ == '__main__':
main()
| 0 | null | 45,126,866,852,000 | 185 | 191 |
class CircleInaRectangle:
def __init__(self, W, H, x, y, r):
if 0 <= x - r and 0 <= y - r and x + r <= W and y + r <= H:
print "Yes"
else:
print "No"
if __name__ == "__main__":
W, H, x, y, r = map(int, raw_input().split())
CircleInaRectangle(W, H, x, y, r) | W,H,x,y,r = map(int ,raw_input().split())
#print ' '.join(map(str,[W,H,x,y,r]))
if x < W and 0 < x and 0<y and y < H and r <= x and r <= (H - x) :
print "Yes"
else:
print "No" | 1 | 449,803,907,940 | null | 41 | 41 |
a = int(input())
if a >= 30:
print("Yes")
else:
print("No") | X = int(input())
print('Yes') if X >= 30 else print('No') | 1 | 5,729,235,409,728 | null | 95 | 95 |
a, b, c = map(int, input().split())
k = int(input())
ans = 0
for i in range(10**5):
if a < b*(2**i):
b = b*(2**i)
break
ans += 1
for i in range(10**5):
if b < c*(2**i):
break
ans += 1
if ans <= k:
print('Yes')
else:
print('No') | a, b, c = [int(x) for x in input().split()]
k = int(input())
while b <= a:
b *= 2
k -= 1
while c <= b:
c *= 2
k -= 1
print("Yes" if k >= 0 else "No") | 1 | 6,892,855,617,210 | null | 101 | 101 |
def main():
num = input()
print(chr(ord(num[0])+1))
main() | c = input()
print(chr(ord(c) + 1))
| 1 | 92,197,023,596,928 | null | 239 | 239 |
import sys
input = sys.stdin.readline
'''
n, m = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
for test in range(int(input())):
'''
inf = 100000000000000000 # 1e17
s = input().strip()
if s[2] == s[3] and s[4] == s[5]:
print("Yes")
else:
print("No")
| S = list(input())
a,b=S.pop(),S.pop()
c,d=S.pop(),S.pop()
if a==b and c==d:
print("Yes")
else:
print("No") | 1 | 42,026,483,700,670 | null | 184 | 184 |
n = input()
for i in range(n):
l = map(int, raw_input().split())
l.sort()
if(l[0] * l[0] + l[1] * l[1] == l[2] * l[2]):
print("YES")
else:
print("NO") | import string
import sys
import math
#??????????????\????????????ip?????\??????
ip = sys.stdin.readlines()
ip_list = {}
#?????????????????§?????????
for i in range(len(ip)):
ip_list[i] = ip[i].strip("\n").split()
for i in range(1,len(ip)):
for j in range(3):
#?????????????????????
for t in range(3):
for k in range(3):
if int(ip_list[i][t]) > int(ip_list[i][k]):
tmp = ip_list[i][t]
ip_list[i][t] = ip_list[i][k]
ip_list[i][k] = tmp
for i in range(1,len(ip)):
if int(ip_list[i][0])**2 == int(ip_list[i][1])**2 + int(ip_list[i][2])**2:
print("YES")
else:
print("NO") | 1 | 311,754,608 | null | 4 | 4 |
import sys
import itertools
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# n = map(int, readline().split())
n = int(readline())
ls = []
rs = []
total = 0
S = list(map(lambda x: x.strip().decode(), readlines()))
for i in range(n):
s = S[i]
b = 0
h = 0
for c in s:
if c == '(':
h += 1
else:
h -= 1
b = min(b, h)
if h >= 0:
ls.append((b, h))
else:
rs.append((b - h, -h))
total += h
if total != 0:
print("No")
exit()
ls = sorted(ls, reverse=True)
rs = sorted(rs, reverse=True)
h = 0
OK = True
for p in ls:
b = h + p[0]
h += p[1]
if b < 0:
OK = False
h = 0
for p in rs:
b = h + p[0]
h += p[1]
if b < 0 or h < 0:
OK = False
if not OK:
print("No")
else:
print("Yes")
| a,b,c = map(int,input().split())
d = 0
if ( a + b - c ) < 0:
if ( a + b - c ) ** 2 > 4 * a * b:
d = 1
if d == 1:
print("Yes")
else:
print("No") | 0 | null | 37,723,414,657,112 | 152 | 197 |
a, b = map(int, input().split())
for i in range(max(a, b)):
print(str(min(a, b)), end="")
| a,b=input().split()
A,B = a*int(b), b*int(a)
if A < B: print(A)
else: print(B) | 1 | 84,528,472,893,018 | null | 232 | 232 |
#!/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):
def manhattan_distance(x1, y1, x2, y2):
return abs(x1-x2) + abs(y1-y2)
return min(manhattan_distance(1, 1, i, N//i) for i in range(1, int(math.sqrt(N))+1) if N % i == 0)
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
print(f'{solve(N)}')
if __name__ == '__main__':
main()
| import math
a,b,c=map(int,input().split())
C=(c/180)*math.pi
S=(a*b*math.sin(C))/2
L=a+b+(a**2+b**2-2*a*b*math.cos(C))**0.5
h=b*math.sin(C)
print("%.5f\n%.5f\n%.5f\n"%(S,L,h)) | 0 | null | 80,897,026,275,670 | 288 | 30 |
a, b = map(int, input().split())
for n in range(1500):
xa = int(n * 0.08)
xb = int(n * 0.1)
if a == xa and b == xb:
print(n)
exit()
print(-1)
| d, t, s = map(int, input().split(" "))
ans = "Yes" if d <= t*s else "No"
print(ans)
| 0 | null | 29,819,915,113,600 | 203 | 81 |
#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 # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(input())
S = input()
k = I()
from itertools import groupby
x = y = 0
g = [len(list(v)) for k,v in groupby(S)]
for c in g:
x += c//2
if S[-1] == S[0]:
if g[-1]%2 == 0 or g[0]%2 == 0:
pass
elif len(S) == 1:
y = k//2
elif len(S) == g[0]:
y = k//2
else:
y = k-1
print(x * k + y)
| def ABC_150_A():
K,X = map(int, input().split())
if 500*K>=X:
print('Yes')
else:
print('No')
if __name__ == '__main__':
ABC_150_A() | 0 | null | 136,876,112,160,928 | 296 | 244 |
N, M, K = map(int, input().split())
mod = 998244353
fact = [1 for i in range(N+1)]
fact_inv = [1 for i in range(N+1)]
for i in range(1, N+1):
fact[i] = fact[i-1] * i %mod
fact_inv[i] = pow(fact[i], mod-2, mod)
ans = 0
for k in range(K+1):
x = M *pow(M-1, N-1-k, mod) *fact[N-1] *fact_inv[k] *fact_inv[N-1-k]
ans += x %mod
ans = ans %mod
print(ans) | def main():
N, M, K = [int(x) for x in input().split()]
if M == 1:
if K == N - 1:
return 1
else:
return 0
if N == 1:
return M
mod = 998244353
fact = [1]
for i in range(1, N):
fact.append(fact[-1] * i % mod)
count = 0
for k in range(K + 1):
current = pow(M - 1, N - k - 1, mod) * M % mod
rev = pow(fact[k] * fact[N - 1 - k] % mod, mod - 2, mod)
current = (current * fact[N - 1] % mod) * rev % mod
count = (count + current) % mod
return count
if __name__ == "__main__":
print(main())
| 1 | 23,166,339,515,604 | null | 151 | 151 |
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
n=int(input())
z=[]
w=[]
for i in range(n):
x,y=nii()
z.append(x-y)
w.append(x+y)
z_ans=max(z)-min(z)
w_ans=max(w)-min(w)
print(max(z_ans,w_ans)) | #Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
threading.stack_size(10**8)
sys.setrecursionlimit(300000)
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#-------------------game starts now-----------------------------------------------------
n=int(input())
ans=0
d=defaultdict(int)
d1=defaultdict(int)
m=-10**13
m1=-10**13
mi=10**13
mi1=10**13
for i in range(n):
a,b=map(int,input().split())
m=max(m,a+b)
mi=min(mi,a+b)
m1=max(m1,a-b)
mi1=min(mi1,a-b)
#print(mi,mi1,m,m1)
print(max(m-mi,m1-mi1)) | 1 | 3,404,597,891,880 | null | 80 | 80 |
import collections
H, W, K = [int(x) for x in input().split()]
S = [input().strip() for _ in range(H)]
ans = float("inf")
for i in range(2 ** (H - 1)):
bundan = {}
bundan[0] = 0
prev = 0
tmp = 0
for j in range(H - 1):
if i >> j & 1 == 1:
prev += 1
bundan[j + 1] = prev
tmp += 1
else:
bundan[j + 1] = prev
c = collections.Counter()
for kk in range(W):
f = False
for k in range(H):
if f:
break
if S[k][kk] == '1':
c[bundan[k]] += 1
if c[bundan[k]] > K:
tmp += 1
f = True
c = collections.Counter()
for kkk in range(H):
if S[kkk][kk] == '1':
c[bundan[kkk]] += 1
break
for k in c.keys():
if c[k] > K:
tmp = float("inf")
break
ans = min(ans, tmp)
print(ans)
| # ALDS1_5_A.
def intinput():
a = input().split()
for i in range(len(a)):
a[i] = int(a[i])
return a
def binary_search(S, k):
a = 0; b = len(S) - 1
if b == 0: return S[0] == k
while b - a > 1:
c = (a + b) // 2
if k <= S[c]: b = c
else: a = c
return S[a] == k or S[b] == k
def show(a):
# 配列aの中身を出力する。
_str = ""
for i in range(len(a) - 1): _str += str(a[i]) + " "
_str += str(a[len(a) - 1])
print(_str)
def main():
n = int(input())
A = intinput()
q = int(input())
m = intinput()
# 配列Aの作る数を調べる。
nCanMake = [0]
for i in range(n):
for k in range(len(nCanMake)):
x = nCanMake[k] + A[i]
if not x in nCanMake: nCanMake.append(x)
# show(nCanMake)
for i in range(q):
if m[i] in nCanMake: print("yes")
else: print("no")
if __name__ == "__main__":
main()
| 0 | null | 24,187,827,878,382 | 193 | 25 |
N, M = map(int, input().split())
print("{}".format("Yes" if N == M else "No")) | class Dictionary_class:
def __init__(self):
self.dic = set()
def insert(self, str):
self.dic.add(str)
def find(self, str):
if str in self.dic:
return True
else:
return False
n = int(input())
answer = ""
dic = Dictionary_class()
for i in range(n):
instruction = input().split()
if instruction[0] == "insert":
dic.insert(instruction[1])
elif instruction[0] == "find":
if dic.find(instruction[1]):
answer += "yes\n"
else:
answer += "no\n"
print(answer, end = "") | 0 | null | 41,668,937,222,500 | 231 | 23 |
# -*- coding:utf-8 -*-
def Selection_Sort(A,n):
for i in range(n):
mini = i
for j in range(i,n): #i以上の要素において最小のAをminiに格納
if int(A[j][1]) < int(A[mini][1]):
mini = j
if A[i] != A[mini]:
A[i], A[mini] = A[mini], A[i]
return A
def Bubble_Sort(A, n):
for i in range(n):
for j in range(n-1,i,-1):
if int(A[j][1]) < int(A[j-1][1]):
A[j], A[j-1] = A[j-1], A[j]
return A
n = int(input())
A = input().strip().split()
B = A[:]
A = Bubble_Sort(A,n)
print (' '.join(A))
print ("Stable")
B =Selection_Sort(B,n)
print (' '.join(B))
if A == B:
print ("Stable")
else:
print ("Not stable") | x=int(input())
cnt=0
money = 100
while(1):
cnt += 1
money += money//100
if money >= x:
print(cnt)
quit() | 0 | null | 13,479,738,923,994 | 16 | 159 |
W, H, x, y, r = map(int, input().split())
if (2*r <= (x+r) <= W) & (2*r <= (y+r) <= H):
print('Yes')
else:
print('No')
| A = sum([int(x) for x in input().split()])
if A >= 22:
print('bust')
else:
print('win')
| 0 | null | 59,769,091,337,878 | 41 | 260 |
K = int(input())
S = input()
M = int(10 ** 9 + 7)
fact = [1]
for i in range(1, K + len(S) + 10):
fact.append(fact[-1] * i % M)
finv = [pow(fact[-1], M - 2, M)]
for i in range(K + len(S) + 9, 0, -1):
finv.append(finv[-1] * i % M)
finv.reverse()
def comb(a, b, m):
return fact[a] * finv[b] % m * finv[a - b] % m
def hcomb(a, b, m):
return comb(a + b - 1, a - 1, m)
ans = 0
for l in range(0, K + 1):
ans += pow(26, l, M) * pow(25, K - l, M) % M * hcomb(len(S), K - l, M) % M
ans %= M
print(ans)
| rooms = [[[0 for k in range(10)] for j in range(3)] for i in range(4)]
n = int(input())
for _ in range(n):
b, f, r, v = map(int, input().split())
rooms[b - 1][f - 1][r - 1] += v
for b in range(4):
for f in range(3):
print(' ' + ' '.join(map(str, rooms[b][f])))
if b is not 3:
print('####################') | 0 | null | 7,024,607,344,328 | 124 | 55 |
a,b = map(int,input().split())
l = [str(a)*b, str(b)*a]
l.sort()
print(l[0]) | def resolve():
a,b = map(int,input().split())
A = str(a)*b
B = str(b)*a
print(A if A<B else B)
resolve() | 1 | 84,583,216,829,658 | null | 232 | 232 |
from collections import deque
k = int(input())
ans=[]
# q = deque([[1],[2],[3],[4],[5],[6],[7],[8],[9]])
q = deque([1,2,3,4,5,6,7,8,9])
while q:
a = q.popleft()
ans.append(a)
if len(ans) > k:
break
tmp = int(str(a)[-1])
if tmp-1 >= 0:
q.append(10*a + tmp-1)
q.append(10*a + tmp)
if tmp+1 <= 9:
q.append(10*a + tmp+1)
print(ans[k-1]) | k = int(input())
num=[1,2,3,4,5,6,7,8,9]
if k<10:
print(num[k-1])
exit()
ans=9
def hantei():
global ans
ans+=1
if ans==k:
print(num[-1])
exit()
for i in range(10**10):
hitoketa=num[0]%10
if hitoketa==0:
num.append(10*num[0]+0)
hantei()
num.append(10*num[0]+1)
hantei()
num.pop(0)
elif hitoketa==9:
num.append(10*num[0]+8)
hantei()
num.append(10*num[0]+9)
hantei()
num.pop(0)
else:
num.append(10*num[0]+(hitoketa-1))
hantei()
num.append(10*num[0]+(hitoketa))
hantei()
num.append(10*num[0]+(hitoketa+1))
hantei()
num.pop(0) | 1 | 39,997,125,277,900 | null | 181 | 181 |
import sys,math
input = sys.stdin.buffer.readline
mod = 1000000007
n = int(input())
ab = []
ang = dict()
rev = dict()
dg = 10**20
zero = 0
for i in range(n):
a,b = map(int,input().split())
if a == 0 and b == 0:
zero += 1
elif a == 0:
if 1 in ang:
ang[1] += 1
else:
ang[1] = 1
elif b == 0:
if 1 in rev:
rev[1] += 1
else:
rev[1] = 1
elif a*b > 0:
if a < 0 and b < 0:
a,b = -a,-b
g = math.gcd(a,b)
a,b = a//g,b//g
if a*dg + b in ang:
ang[a*dg + b] += 1
else:
ang[a*dg + b] = 1
else:
a,b = abs(a),abs(b)
g = math.gcd(a,b)
a,b = a//g,b//g
if b*dg + a in rev:
rev[b*dg + a] += 1
else:
rev[b*dg + a] = 1
rest = n - zero
res = 1
for e in ang:
if e in rev:
res = res*(pow(2,ang[e],mod) + pow(2,rev[e],mod) - 1)%mod
rest -= ang[e] + rev[e]
res = res*pow(2,rest,mod)%mod - 1 + zero
print(res%mod)
| import sys; input = sys.stdin.readline
n = int(input())
lis = list(map(int, input().split()))
ans = 0
for i in range(n):
for j in range(i+1, n):
for k in range(j+1, n):
if lis[i] == lis[j] or lis[j] == lis[k] or lis[i] == lis[k]: continue
s = sorted([lis[i], lis[j], lis[k]])
if s[2] < s[1] + s[0]: ans += 1
print(ans) | 0 | null | 12,968,636,513,120 | 146 | 91 |
a,b = list(map(int, input().split()))
if a > b:
sep = '>'
elif a < b:
sep = '<'
else:
sep = '=='
print('a', sep, 'b') |
splited = input().split(" ")
f = int(splited[0])/int(splited[1])
r = int(splited[0])%int(splited[1])
d = int(splited[0])//int(splited[1])
print(d, r, "{0:.5f}".format(f)) | 0 | null | 477,311,579,792 | 38 | 45 |
n=int(input())
import math
for i in range(int(math.sqrt(n)),0,-1):
if n%i==0:
print(i+n//i-2)
break | n = int(input())
#a, b, c, x, y = map(int, input().split())
#al = list(map(int, input().split()))
#al=[list(input()) for i in range(n)]
x = 1
mn = n-1
while x**2 <= n:
if n % x == 0:
y = n//x
mn = min(mn, x+y-2)
x+=1
print(mn)
| 1 | 161,786,892,504,290 | null | 288 | 288 |
nn=int(input())
nc = [0] * (nn + 1)
for x in range(1, 100):
for y in range(1, 100):
for z in range(1, 100):
a = x * x + y * y + z * z + x * y + x * z + y * z
if a > nn:
break
nc[a] += 1
for i in range(1, nn + 1):
print(nc[i]) | import math
def solve(n,x,t):
if n%x != 0:
return (math.ceil(n/x))*t
else:
return (n//x)*t
n,x,t = map(int, input().strip().split())
print(solve(n,x,t)) | 0 | null | 6,132,533,866,910 | 106 | 86 |
import math
a,b,c=map(float,raw_input().split())
c = c / 180 * math.pi
print "%.10f" % float(a*b*math.sin(c)/2)
x = math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(c))
print "%.10f" % float(a + b + x)
print "%.10f" % float(b*math.sin(c)) | def main():
H, W, K = map(int, input().split())
c = [input() for _ in range(H)]
ans = 0
# 選ばない:0 選ぶ:1
for row in range(2 ** H):
for column in range(2 ** W):
cnt = 0
for i in range(H):
for j in range(W):
if row >> i & 1:
continue
if column >> j & 1:
continue
if c[i][j] == "#":
cnt += 1
if cnt == K:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 4,507,793,966,052 | 30 | 110 |
a, b, c, k = map(int, input().split())
print(max(min(k, a) ,0) - max(min(k - (a + b), c), 0)) | a,b,c,k = (int(a) for a in input().split())
if a >= k :
print(k)
elif a+b >= k :
print(a)
else :
print(a - min(c,(k-(a+b)))) | 1 | 21,951,660,370,120 | null | 148 | 148 |
h, n = map(int, input().split())
a = list(map(int, input().split()))
a_sum = sum(a)
if h <= a_sum:
print('Yes')
else:
print('No')
| import sys
sys.setrecursionlimit(10**6)
N, u, v = map(int, input().split())
tree = [[] for _ in range(N)]
for _ in range(N-1):
a, b = map(int, input().split())
tree[a-1].append(b-1)
tree[b-1].append(a-1)
#print(tree)
def calc_dist(dlist, n, dist, nnode):
for c in tree[n]:
if c == nnode:
continue
dlist[c] = dist
calc_dist(dlist, c, dist+1, n)
u_dist_list = [0] * N
calc_dist(u_dist_list, u-1, 1, -1)
#print(u_dist_list)
v_dist_list = [0] * N
calc_dist(v_dist_list, v-1, 1, -1)
#print(v_dist_list)
ans = 0
for i in range(N):
if (v_dist_list[i] - u_dist_list[i]) > 0 and v_dist_list[i] > ans:
ans = v_dist_list[i] - 1
print(ans) | 0 | null | 97,844,453,921,898 | 226 | 259 |
import math
H,A=map(int,input().split())
if H<=A:
print(1)
else:
print(math.ceil(H/A)) | def main():
h,a = map(int,input().split())
ans = h // a
if h % a != 0:
ans += 1
print(ans)
main() | 1 | 76,934,658,686,722 | null | 225 | 225 |
def combination_mod(n, k, mod=10 ** 9 + 7):
if k > n:
return 1
nu, de = 1, 1
for i in range(k):
nu = nu * (n - i) % mod
de = de * (i + 1) % mod
return nu * pow(de, mod - 2, mod) % mod
n, a, b = map(int, input().split())
mod = 10 ** 9 + 7
ans = pow(2, n, mod) - 1
ans -= combination_mod(n, a)
ans = (ans + mod) % mod
ans -= combination_mod(n, b)
ans = (ans + mod) % mod
print(ans)
| n, a, b = map(int, input().split())
mod = 10 ** 9 + 7
ans = pow(2, n, mod) - 1
for i in [a, b]:
num = 1
den = 1
for p in range(n, n-i, -1):
num = num * p % mod
for q in range(1, i+1):
den = den * q % mod
cmb = num * pow(den, mod-2, mod) % mod
ans -= cmb
ans %= mod
print(ans) | 1 | 66,304,053,736,730 | null | 214 | 214 |
n = int(input())
lst = [0] * 10**6
for x in range(1, 101):
for y in range(1, 101):
for z in range(1, 101):
t = (x**2 + y**2 + z**2 + (x+y+z)**2) // 2
lst[t] += 1
for i in range(1, n+1):
print(lst[i]) | n,m,l = map(int, input().split())
A = [[0 for c in range(m)]for r in range(n)]
B = [[0 for c in range(l)]for r in range(m)]
C = [[0 for c in range(l)]for r in range(n)]
for r in range(n):
A[r][:] = list(map(int, input().split()))
for r in range(m):
B[r][:] = list(map(int, input().split()))
for row in range(n):
for col in range(l):
for i in range(m):
C[row][col] += A[row][i]*B[i][col]
print(*C[row][:])
| 0 | null | 4,700,625,160,180 | 106 | 60 |
import string as st
string=[]
try:
while True:
s = input()#入力
string =list(string)#list変換
if not s :#空入力のときループぬける
break
string.extend(s)#list追加
string=map(str,string)
string="".join(string).lower()#str型変換と小文字
except EOFError:
for i in range(len(st.ascii_lowercase)):
print("{} : {}".format(st.ascii_lowercase[i],string.count(st.ascii_lowercase[i])))
| n, m = map(int, input().split())
route = [[] for _ in range(n+1)]
ans = [0]*n
for _ in range(m):
a, b = map(int, input().split())
route[a].append(b)
route[b].append(a)
q = [1]
l = set()
while True:
if len(q) == 0:
break
p = q.pop(0)
for i in route[p]:
if i not in l:
l.add(i)
ans[i-1] = p
q.append(i)
if ans.count(0) > 1:
print("No")
else:
print("Yes")
for i in range(1, n):
print(ans[i]) | 0 | null | 11,065,775,043,852 | 63 | 145 |
mt = []
for i in range(10):
mt.append(int(input()))
mt.sort()
print( mt[9] )
print( mt[8] )
print( mt[7] ) | import sys
inlist = list(map(int, sys.stdin.readline().split(" ")))
a = inlist[0]
b = inlist[1]
print("{0} {1} {2:f}".format(a // b, a % b, a / b)) | 0 | null | 301,980,108,640 | 2 | 45 |
S = input()
T = input()
time = []
S_list = list(S)
T_list = list(T)
Len = (len(S))
listt = list(range(Len))
for ss in listt:
if S[ss] ==T[ss]:
None
else:
time.append(ss)
print(len(time))
| res = []
n = int(input())
for i in range(n):
r = input()
res.append(r)
ac = res.count("AC")
wa = res.count("WA")
tle = res.count("TLE")
re = res.count("RE")
print("AC x "+str(ac))
print("WA x "+str(wa))
print("TLE x "+str(tle))
print("RE x "+str(re)) | 0 | null | 9,616,761,526,188 | 116 | 109 |
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
lun = [[str(i)] for i in range(10)] + [[]]
olun =[[str(i)] for i in range(10)] + [[]]
ans = [str(i) for i in range(1,10)]
while True:
for i in range(0,10):
lun[i] = list(map(lambda x: str(i) + x, (olun[i-1]+olun[i]+olun[i+1])))
if i>= 1: ans += lun[i]
if len(ans) >= 10**5 + 5: break
olun = copy.deepcopy(lun)
k = int(input())
print(ans[k-1])
| from collections import deque
def main():
k = int(input())
l = list(range(1, 10))
Q = deque(l)
for _ in range(k):
q = Q.popleft()
# 基準-1
if q % 10 != 0:
Q.append(10*q+q%10-1)
# 基準
Q.append(10*q+q%10)
# 基準 + 1
if q % 10 != 9:
Q.append(10*q+q%10+1)
print(q)
if __name__ == '__main__':
main()
| 1 | 39,842,544,380,600 | null | 181 | 181 |
input()
A = [i for i in input().split()]
A.reverse()
print(' '.join(A)) | # coding: utf-8
# Here your code !
def func():
try:
line = input()
line = input().rstrip()
numbers = line.split(" ")
except:
print("input error")
return -1
numbers.reverse()
result=""
for item in numbers:
result += item+" "
print(result.rstrip(" "))
func() | 1 | 968,222,158,072 | null | 53 | 53 |
def InsertSort(A, n, g, cnt):
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j -= g
cnt += 1
A[j+g] = v
return cnt
def ShellSort(A, n):
cnt = 0
G = [1]
h = G[0]
while True:
h = h*3 + 1
if h > n:
break
G.append(h)
print(len(G))
print(' '.join(reversed(list(map(str, G)))))
for h in reversed(G):
cnt = InsertSort(A, n, h, cnt)
print(cnt)
n = int(input())
A = []
for _ in range(n):
A.append(int(input()))
ShellSort(A, n)
for num in A:
print(num)
| n = input()
str_n = list(n)
if str_n[-1] == "3":
print("bon")
elif str_n[-1] == "0" or str_n[-1] == "1" or str_n[-1] == "6" or str_n[-1] == "8":
print("pon")
else:
print("hon") | 0 | null | 9,652,214,426,790 | 17 | 142 |
number=list(map(int,input().split()))
n,m=number[0],number[1]
height=list(map(int,input().split()))
load=[[] for i in range(n+1)]
for i in range(m):
tmp=list(map(int,input().split()))
if tmp[1] not in load[tmp[0]]:
load[tmp[0]].append(tmp[1])
if tmp[0] not in load[tmp[1]]:
load[tmp[1]].append(tmp[0])
box=[]
answer=0
for i in range(1,n+1):
box=[]
if len(load[i])==0:
answer+=1
for j in range(len(load[i])):
box.append(height[load[i][j]-1])
if box!=[]:
if max(box)<height[i-1]:
answer+=1
print(answer) | n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]
ans = [1]*n
for i in range(m):
if h[ab[i][0]-1] == h[ab[i][1]-1]:
ans[ab[i][0]-1] = 0
ans[ab[i][1]-1] = 0
elif h[ab[i][0]-1] > h[ab[i][1]-1]:
ans[ab[i][1]-1] = 0
else:
ans[ab[i][0]-1] = 0
print(sum(ans))
| 1 | 24,977,579,546,204 | null | 155 | 155 |
H, A = (int(x) for x in input().split())
if A >= H:
print(1)
elif H%A == 0:
print(H//A)
else:
print(H//A + 1) | H, A = [int(v) for v in input().rstrip().split()]
r = int(H / A)
if H != (r * A):
r += 1
print(r)
| 1 | 76,603,562,268,758 | null | 225 | 225 |
from math import sqrt
N=int(input())
for i in range(int(sqrt(N)),0,-1):
j = N/i
if j == int(j):
print(int(i+j-2))
break | while True:
n,x = map(int,input().split())
s = 0
if n==0 and x==0:
break
if x <= 3*n-3 and x >= 6:
for i in range(1,min(n-1,x//3)):
s += len(range(max(i+1,x-i-n),min(n,(x-i+1)//2)))
print(s) | 0 | null | 81,463,709,093,088 | 288 | 58 |
A, B = input().split()
# 方針:少数の計算を避け、整数の範囲で計算する
# [A*B] = [A*(100*B)/100]と見る
# Bを100倍して整数に直す操作は、文字列のまま行う
A = int(A)
B = int(B.replace('.', ''))
# 100で割った整数部分を求める操作は、100で割った商を求めることと同じ
ans = (A*B) // 100
print(ans) | a=int(input())
b=a//100
b*=5
c=a%100
print("1" if b>=c else "0") | 0 | null | 71,676,090,218,400 | 135 | 266 |
N = int(input())
ans = [0]*(1+N)
for x in range(1, 10**2+1):
for y in range(1, 10**2+1):
for z in range(1, 10**2+1):
v = x*x+y*y+z*z+x*y+y*z+z*x
if v<=N:
ans[v] += 1
for i in range(1, N+1):
print(ans[i]) | def dfs():
tt = 0
for u in range(N):
if colors[u] == WHITE:
tt = dfs_visit(u, tt)
def dfs_visit(u, tt):
tt += 1
colors[u] = GLAY
d[u] = tt
for v in range(N):
if adjacency_list[u][v] == 1 and colors[v] == WHITE:
tt = dfs_visit(v, tt)
tt += 1
colors[u] = BLACK
f[u] = tt
return tt
N = int(input())
adjacency_list = [[0 for j in range(N)] for i in range(N)]
for _ in range(N):
u, k, *v = map(int, input().split())
for i in v:
adjacency_list[u-1][i-1] = 1
WHITE = 0
GLAY = 1
BLACK = 2
colors = [WHITE for _ in range(N)]
d = [0 for _ in range(N)]
f = [0 for _ in range(N)]
dfs()
for i in range(N):
print("{} {} {}".format(i+1, d[i], f[i]))
| 0 | null | 3,965,360,801,374 | 106 | 8 |
import numpy as np
n, k = map(int, input().split())
aa = list(map(np.int64, input().split()))
aa = np.array(aa)
def mul(dd):
mod = 10**9+7
ret = 1
for d in dd:
ret = (ret*d)%mod
return ret
def sol(aa, n, k):
mod = 10**9+7
aap = aa[aa>0]
aam = aa[aa<0]
if n == k:
return mul(aa)
if len(aap) + 2*(len(aam)//2) < k:
return 0
# マイナスのみ
if len(aam) == n:
aam.sort()
if k%2==1:
return mul(aam[-k:])
else:
return mul(aam[:k])
aap = aa[aa>=0]
aap.sort()
aap = aap[::-1]
aam.sort()
ret=1
if k%2 >0:
k = k-1
ret *= aap[0]
aap = aap[1:]
aap2 = [aap[2*i]*aap[2*i+1] for i in range(len(aap)//2)]
aam2 = [aam[2*i]*aam[2*i+1] for i in range(len(aam)//2)]
aap2.extend(aam2)
aap2.sort(reverse=True)
aap2 = [i%mod for i in aap2]
return (ret*mul(aap2[:k//2]))%mod
print(sol(aa, n, k))
| import sys
def gcm(a,b):
return gcm(b,a%b) if b else a
for s in sys.stdin:
a,b=map(int,s.split())
c=gcm(a,b)
print c,a/c*b | 0 | null | 4,654,470,532,182 | 112 | 5 |
n=int(input())
s=input()
A=[]
for i in range(n):
A.append(s[i])
W=0
R=A.count('R')
ans=float('inf')
for i in range(n+1):
if i!=0:
if A[i-1]=='W':
W+=1
else:
R-=1
ans=min(max(W,R),ans)
print(ans) | N=int(input())
stones = list(input())
l = 0
r = N-1
count = 0
while(True):
while(stones[l] == "R" and l < N-1):
l += 1
while(stones[r] == "W" and r > 0):
r -= 1
if (l >= r):
print(count)
exit()
else:
count += 1
l += 1
r -= 1 | 1 | 6,375,796,079,380 | null | 98 | 98 |
N = int(input())
g = 0
for n in range(1, N + 1):
if n % 2 == 0:
g += 1
ANS = (N - g) / N
print(ANS) | a = int(input())
print(1 / 2 if a % 2 == 0 else (a + 1) / (2 * a))
| 1 | 177,510,752,235,310 | null | 297 | 297 |
n,p=map(int,input().split())
s=input()
if p==2 or p==5:
a=0
for i in range(n):
if int(s[i])%p==0:
a+=i+1
print(a)
else:
a=0
g=[0]*(n+1)
t=[0]*p
t[0]=1
d=1
for i in range(n-1,-1,-1):
g[i]=(g[i+1]+int(s[i])*d)%p
a+=t[g[i]]
t[g[i]]+=1
d*=10
d%=p
print(a) | N,X,M = [int(a) for a in input().split()]
amari = [0]*M
i = 1
A = X
amari[A] = i
l = [X]
ichi = i
while i<=M:
i += 1
A = A**2 % M
if amari[A]: i += M
else:
amari[A] = i
l.append(A)
if i==N: i = M+1
else:
if i>M+1: ni = i-M - amari[A]
else: ni = 0
#for j in range(M):
# if amari[j]: print(j, amari[j])
#print(i,len(l))
ichi = len(l) - ni
#print(l)
if ni:
ni_times, san = divmod((N - ichi), ni)
#print(ichi, '%d*%d'%(ni,ni_times), san)
print(sum(l[:ichi]) +
sum(l[ichi:])*ni_times +
sum(l[ichi:ichi+san]))
else:
#print(ichi, '%d*%d'%(ni,ni_times), san)
print(sum(l)) | 0 | null | 30,584,493,151,872 | 205 | 75 |
from math import sin, cos, pi
def koch_curve(d, p1, p2):
if d == 0:
return
s = [None, None]
u = [None, None]
t = [None, None]
s[0] = (2*p1[0] + p2[0])/3
s[1] = (2*p1[1] + p2[1])/3
t[0] = (p1[0] + 2*p2[0])/3
t[1] = (p1[1] + 2*p2[1])/3
u[0] = (t[0] - s[0])*cos(1/3*pi) - (t[1] - s[1])*sin(1/3*pi) + s[0]
u[1] = (t[0] - s[0])*sin(1/3*pi) + (t[1] - s[1])*cos(1/3*pi) + s[1]
koch_curve(d-1, p1, s)
print(s[0], s[1])
koch_curve(d-1, s, u)
print(u[0], u[1])
koch_curve(d-1, u, t)
print(t[0],t[1])
koch_curve(d-1, t, p2)
num = int(input())
print(0.0, 0.0)
koch_curve(num, [0.0, 0.0], [100.0, 0.0])
print(100.0, 0.0)
| N,K=map(int,input().split())
x=N%K
y=abs(x-K)
print(min(x,y)) | 0 | null | 19,876,576,905,482 | 27 | 180 |
n = int(input())
a = list(map(int, input().split()))
b = 0
c = 0
for i in range(n):
b = max(b,a[i])
c += (b-a[i])
print(c) | from collections import defaultdict
n = int(input())
dic = defaultdict(lambda: 0)
for _ in range(n):
com = input().split(' ')
if com[0]=='insert':
dic[com[1]] = 1
else:
if com[1] in dic:
print('yes')
else:
print('no') | 0 | null | 2,349,978,472,032 | 88 | 23 |
K=int(input())
s =input()
x = len(s)
if x<=K:
print(s)
else:
print(s[:K]+'...') | def ifTriangle(v):
largest = max(v)
smallers_sum = 0
for x in v:
if not x == largest:
smallers_sum += x
if smallers_sum > largest:
return True
return False
N = int(input())
L = [int(x) for x in input().split()]
L.sort()
L.reverse()
count = 0
before_i = -1
before_j = -1
before_k = -1
for i in range(N-2):
for j in range(i+1, N-1):
if L[j] == L[i]:
continue
if L[i]/2 >= L[j]:
break
for k in range(j+1, N):
if L[k] == L[j]:
continue
if ifTriangle([L[i], L[j], L[k]]):
count += 1
print(count)
| 0 | null | 12,301,294,168,800 | 143 | 91 |
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions import gcd
#input=sys.stdin.readline
import bisect
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
b=[0]*(n-k+1)
ans=0
Mod=10**9+7
M=10**6 #書き換え
fac=[0]*M
finv=[0]*M
inv=[0]*M
#finvに逆元、facに階乗のmod
def COMinit():
fac[0]=fac[1]=1
finv[0]=finv[1]=1
inv[1]=1
for i in range(2,M):
fac[i]=(fac[i-1]*i%Mod)%Mod
inv[i]=Mod-inv[Mod%i]*(Mod//i) %Mod
finv[i]=(finv[i-1]*inv[i]%Mod)%Mod
def COM(n,k):
if n<k:
return 0
if n<0 or k<0:
return 0
return (fac[n]*(finv[k]*finv[n-k]%Mod)%Mod)%Mod
COMinit()
b[0]=a[n-1]-a[0]
for i in range(1,n-k+1):
res=a[n-i-1]-a[i]
b[i]=res+b[i-1]
b[i]%=Mod
for i in range(n-k+1):
ans+=(COM(n-2-i,k-2)*b[i])%Mod
ans%=Mod
print(ans)
| import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
fac = [-1] * (10**6+1)
finv = [-1] * (10**6+1)
inv = [-1] * (10**6+1)
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
def initNCMMod(limit):
for i in range(2, limit):
fac[i] = fac[i-1] * i % mod
inv[i] = mod - inv[mod%i] * (mod // i) % mod
finv[i] = finv[i-1] * inv[i] % mod
initNCMMod(10**5 + 3)
def NCMMod(n, k):
if n < k:
return 0
if (n < 0 or k < 0):
return 0
return fac[n] * (finv[k] * finv[n-k] % mod) % mod
def main():
N, K =LI()
A = sorted(LI())
m = A[0]
if m < 0:
for i in range(N):
A[i] -= m
arr = []
cumA = [0] * (N+1)
for i in range(N):
A[i] %= mod
cumA[i+1] = A[i] + cumA[i]
cumA[i+1] %= mod
ans = 0
# [l, r) = A[l] + ... + A[r-1]
if K >= 2:
for d in range(K-2, N):
ans += NCMMod(d, K-2) * (((cumA[N] - cumA[d+1]) % mod - (cumA[N-d-1] - cumA[0]) % mod)) % mod
ans %= mod
print(ans)
main()
| 1 | 95,534,091,503,928 | null | 242 | 242 |
while True:
s = input().split(" ")
H = int(s[0])
W = int(s[1])
if H == 0 and W == 0:
break
for i in range(H):
for j in range(W):
if i % 2 == 0:
if j % 2 == 0:
print("#",end="")
else:
print(".",end="")
else:
if j % 2 == 0:
print(".",end="")
else:
print("#",end="")
print("")
print("") | import sys
while True:
h, w = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
if 0 ==h and 0 == w:
break
pa = [ "#", "." ]
ouput = []
for i in range( h ):
for j in range( w ):
ouput.append( pa[(i+j)%2] )
ouput.append( "\n" )
print( "".join( ouput ) ) | 1 | 880,076,873,440 | null | 51 | 51 |
import numpy as np
if __name__ == "__main__":
N=input()
N=int(N)
l=[]
for i in range(N):
buf=input()
l+=[buf]
l=np.array(l)
print(len(np.unique(l))) | import math
l = int(input())
v = math.pow(l/3.0, 3.0)
print(v) | 0 | null | 38,603,887,572,612 | 165 | 191 |
# abc168_a.py
# https://atcoder.jp/contests/abc168/tasks/abc168_a
# A - ∴ (Therefore) /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点: 100点
# 問題文
# いろはちゃんは、人気の日本製ゲーム「ÅtCoder」で遊びたい猫のすぬけ君のために日本語を教えることにしました。
# 日本語で鉛筆を数えるときには、助数詞として数の後ろに「本」がつきます。この助数詞はどんな数につくかで異なる読み方をします。
# 具体的には、999以下の正の整数 N について、「N本」と言うときの「本」の読みは
# Nの 1 の位が 2,4,5,7,9のとき hon
# Nの 1 の位が 0,1,6,8のとき pon
# Nの 1 の位が 3のとき bon
# です。
# Nが与えられるので、「N本」と言うときの「本」の読みを出力してください。
# 制約
# Nは 999以下の正の整数
# 入力
# 入力は以下の形式で標準入力から与えられる。
# N
# 出力
# 答えを出力せよ。
# 入力例 1
# 16
# 出力例 1
# pon
# 16の 1 の位は 6なので、「本」の読みは pon です。
# 入力例 2
# 2
# 出力例 2
# hon
# 入力例 3
# 183
# 出力例 3
# bon
global FLAG_LOG
FLAG_LOG = False
def log(value):
# FLAG_LOG = True
FLAG_LOG = False
if FLAG_LOG:
print(str(value))
def calculation(lines):
# S = lines[0]
N = int(lines[0])
# N, M = list(map(int, lines[0].split()))
# values = list(map(int, lines[1].split()))
# values = list(map(int, lines[2].split()))
# values = list()
# for i in range(N):
# values.append(int(lines[i]))
# valueses = list()
# for i in range(N):
# valueses.append(list(map(int, lines[i+1].split())))
amari = N % 10
result = 'hon'
if amari == 3:
result = 'bon'
elif amari in [0, 1, 6, 8]:
result = 'pon'
return [result]
# 引数を取得
def get_input_lines(lines_count):
lines = list()
for _ in range(lines_count):
lines.append(input())
return lines
# テストデータ
def get_testdata(pattern):
if pattern == 1:
lines_input = ['16']
lines_export = ['pon']
if pattern == 2:
lines_input = ['2']
lines_export = ['hon']
if pattern == 3:
lines_input = ['183']
lines_export = ['bon']
return lines_input, lines_export
# 動作モード判別
def get_mode():
import sys
args = sys.argv
global FLAG_LOG
if len(args) == 1:
mode = 0
FLAG_LOG = False
else:
mode = int(args[1])
FLAG_LOG = True
return mode
# 主処理
def main():
import time
started = time.time()
mode = get_mode()
if mode == 0:
lines_input = get_input_lines(1)
else:
lines_input, lines_export = get_testdata(mode)
lines_result = calculation(lines_input)
for line_result in lines_result:
print(line_result)
# if mode > 0:
# print(f'lines_input=[{lines_input}]')
# print(f'lines_export=[{lines_export}]')
# print(f'lines_result=[{lines_result}]')
# if lines_result == lines_export:
# print('OK')
# else:
# print('NG')
# finished = time.time()
# duration = finished - started
# print(f'duration=[{duration}]')
# 起動処理
if __name__ == '__main__':
main()
| import decimal
def multply(a: str, b: str) -> int:
return int(decimal.Decimal(a) * decimal.Decimal(b))
a, b = input().split()
print(multply(a, b))
| 0 | null | 17,779,603,244,498 | 142 | 135 |
s = input()
p = input()
s = s + s[:len(p)]
if p in s:
print('Yes')
else:
print('No') | s = input()
cs = list(s)
for c in cs:
if c.islower():
print(c.upper(),end="")
else :
print(c.lower(),end="")
print()
| 0 | null | 1,620,184,503,938 | 64 | 61 |
mod = 998244353
n,k = map(int,input().split())
lr = [[int(i) for i in input().split()] for j in range(k)]
dp = [0]*(n+1)
dp_rui = [0]*(n+1)
dp[1] = 1
dp_rui[1] = 1
for i in range(2,n+1):
for j in range(k):
lft = i - lr[j][1]
rht = i - lr[j][0]
#print(i,lft,rht)
if rht <= 0:
continue
lft = max(1,lft)
dp[i] += dp_rui[rht] - dp_rui[lft-1]
#print(dp_rui[rht],dp_rui[lft-1])
dp[i] %= mod
#print(dp)
#print(dp_rui)
dp_rui[i] = dp_rui[i-1] + dp[i]
dp_rui[i] %= mod
print(dp[n]%mod) | N=int(input())
music=[]
T=[]
ans=0
for i in range(N):
s, t=input().split()
t=int(t)
music.append(s)
T.append(t)
X=input()
num=music.index(X)
for j in range(num+1, N):
ans+=T[j]
print(ans) | 0 | null | 50,070,943,462,670 | 74 | 243 |
# -*- coding: utf-8 -*-
num = int(raw_input())
a = int(raw_input())
b = int(raw_input())
diff = b - a
pre_min = min(a,b)
counter = 2
while counter < num:
current_num = int(raw_input())
if diff < current_num - pre_min:
diff = current_num - pre_min
if pre_min > current_num:
pre_min = current_num
counter += 1
print diff | list = input().split(' ')
OPERATOR = {
'+': lambda a, b: a + b,
'*': lambda a, b: a * b,
'-': lambda a, b: a - b,
'/': lambda a, b: a / b,
}
stack = []
for item in list:
if item in OPERATOR:
b = stack.pop()
a = stack.pop()
stack.append(OPERATOR[item](a, b))
else:
stack.append(int(item))
print(stack.pop())
| 0 | null | 23,573,050,796 | 13 | 18 |
S = input().rstrip()
if S[-1] == 's':
print(S + 'es')
else:
print(S + 's') | # coding:UTF-8
import sys
from math import factorial
MOD = 10 ** 9 + 7
INF = 10000000000
def main():
# ------ 入力 ------#
# 1行入力
a = input() # 文字列
# ------ 出力 ------#
if a[-1] == "s":
print("{}".format(a + "es"))
else:
print("{}".format(a + "s"))
if __name__ == '__main__':
main()
| 1 | 2,356,875,352,000 | null | 71 | 71 |
import sys
from collections import deque
n = int(input())
q = deque()
for i in range(n):
c = sys.stdin.readline()[:-1]
if c[0] == 'i':
q.appendleft(c[7:])
elif c[6] == ' ':
try:
q.remove(c[7:])
except:
pass
elif c[6] == 'F':
q.popleft()
else:
q.pop()
print(*q) | n = int(input())
import collections
d = collections.deque([])
for _ in range(n):
s = input().split()
if s[0] == "deleteFirst":
d.popleft()
elif s[0] == "deleteLast":
d.pop()
elif s[0] == "insert":
d.appendleft(s[1])
else:
try:
d.remove(s[1])
except:
pass
print(" ".join(d))
| 1 | 51,054,995,200 | null | 20 | 20 |
from collections import Counter
S = list(map(int, list(input())))
A = [0]
for i, s in enumerate(S[::-1]):
A.append((A[-1] + s * pow(10, i, 2019)) % 2019)
print(sum([v * (v - 1) // 2 for v in Counter(A).values()]))
| from collections import Counter
S = input()
S = S + '0'
mod = 2019
p = [-1] * len(S)
r = 0
d = 1
for i,s in enumerate(S[::-1]):
t = int(s)%mod
r += t*d
r %= mod
d = d*10%mod
p[i] = r
ans = 0
c = Counter(p)
for k,n in c.most_common():
if n > 1:
ans += n*(n-1)//2
else:break
print(ans) | 1 | 30,865,364,459,898 | null | 166 | 166 |
import sys
Stack = []
MAX = 1000
def push(x):
#if isFull():
# print "ERROR!"
# sys.exit()
Stack.append(x)
def pop():
#if isEmpty():
# print "ERROR!"
# sys.exit()
Stack.pop(-1)
def cul(exp):
for v in exp:
if v == "+":
x = reduce(lambda a,b:int(a)+int(b), Stack[-2:])
for i in range(2):
pop()
push(x)
elif v == "-":
x = reduce(lambda a,b:int(a)-int(b), Stack[-2:])
for i in range(2):
pop()
push(x)
elif v == "*":
x = reduce(lambda a,b:int(a)*int(b), Stack[-2:])
for i in range(2):
pop()
push(x)
else:
push(v)
return Stack[0]
if __name__ == "__main__":
exp = sys.stdin.read().strip().split(" ")
ans = cul(exp)
print ans | ts = input().split(" ")
stack = []
for t in ts:
if t not in ("-", "+", "*"):
stack.append(int(t))
else:
n2 = stack.pop()
n1 = stack.pop()
if t == "-":
stack.append(n1 - n2)
elif t == "+":
stack.append(n1 + n2)
else:
stack.append(n1 * n2)
print(stack.pop()) | 1 | 38,115,223,420 | null | 18 | 18 |
N = int(input())
slist = []
tlist = []
from itertools import accumulate
for _ in range(N):
s, t = input().split()
slist.append(s)
tlist.append(int(t))
cum = list(accumulate(tlist))
print(cum[-1]-cum[slist.index(input())])
| from sys import exit
n, m = map(int, input().split())
s = input()
one_sequence = 0
for i in range(1, n):
if s[i] == "1":
one_sequence += 1
if one_sequence == m:
print(-1)
exit()
else:
one_sequence = 0
pos = n
ans = ""
while pos != 0:
for i in range(1, m+1)[::-1]:
if pos-i < 0:
continue
if s[pos-i] != "1":
ans = str(i) + " " + ans
pos -= i
break
print(ans)
| 0 | null | 118,132,858,336,230 | 243 | 274 |
from sys import stdin
stdin.readline().rstrip()
a = [int(x) for x in stdin.readline().rstrip().split()]
a.reverse()
print(*a)
| a,b,n=[int(x) for x in input().rstrip().split()]
if b<=n:
n=b-1
print(int((a*n)/b)-a*int(n/b))
| 0 | null | 14,540,281,451,472 | 53 | 161 |
W = input().lower()
T = ""
while True:
inp = input().strip()
if inp == 'END_OF_TEXT':
break
T += inp.strip().lower()+' '
print(T.split().count(W)) | # coding:utf-8
W=input()
W=W.lower()
ct=0
while True:
S=map(str,input().split())
for i in S:
if i=="END_OF_TEXT":
print(ct)
exit(0)
elif i.lower()==W:
ct=ct+1 | 1 | 1,858,302,434,912 | null | 65 | 65 |
import math
N,D,A = map(int,input().split())
l = []
for i in range(N):
l.append(list(map(int,input().split())))
l.sort()
lx = []
lc = []
for i in l:
X,H = i[0],i[1]
lx.append(X)
lc.append(math.ceil(H/A))
migi = []
m = 0
i = 0
while i <= N-1:
if lx[m] - lx[i] > 2*D:
migi.append(m)
i += 1
elif m != N-1:
m += 1
elif m == N-1:
migi.append(-1)
i += 1
cnt = 0
dam = [0 for i in range(N)]
for i in range(N):
if dam[i] < lc[i]:
c = lc[i] - dam[i]
dam[i] += c
if migi[i] >= 0:
dam[migi[i]] -= c
cnt += c
if i <=N-2:
dam[i+1] += dam[i]
print(cnt) | a, b, c = map(int, input().split())
print('No' if a != b and b != c and c != a or a == b and b == c else 'Yes') | 0 | null | 74,774,944,525,018 | 230 | 216 |
def main():
N=int(input())
A=list(map(int,input().split()))
mod=10**9+7
ans=0
for i in range(60):
c=0
for j in A:
if j>>i&1:
c+=1
ans+=pow(2,i,mod)*c*(N-c)
ans%=mod
print(ans)
if __name__=='__main__':
main() | n = int(input())
arr = list(map(int, input().split()))
MOD = 10**9 + 7
ans = 0
for i in range(60):
mask = 1 << i
cnt = sum([1 for x in arr if x & mask == mask])
ans += mask * cnt * (n - cnt) % MOD
print(ans % MOD) | 1 | 123,545,497,837,450 | null | 263 | 263 |
n,k = map(int,input().split())
mod = 10**9 +7
sum1 = 0
for i in range(k,n+2):
sum1 +=(-i*(i-1)//2 + i*(2*n-i+1)//2+1)%mod
print(sum1%mod) | N,K = map(int,input().split())
MOD = 10**9+7
s = 1
for k in range(K,N+1):
t = (N+1-k)*k+1
# print(t)
s += t
s = s%MOD
print(s)
| 1 | 33,128,335,517,118 | null | 170 | 170 |
#!python3
import sys
from collections import defaultdict
from math import gcd
iim = lambda: map(int, input().rstrip().split())
def resolve():
N = input()
it = map(int, sys.stdin.read().split())
mod = 10**9 + 7
d1 = [defaultdict(int), defaultdict(int)]
z0 = za = zb = 0
for ai, bi in zip(it, it):
t = ai * bi
if t == 0:
if ai != 0:
za += 1
elif bi != 0:
zb += 1
else:
z0 += 1
continue
ci = gcd(ai, bi)
ai, bi = ai // ci, bi // ci
t = t < 0
if ai < 0:
ai, bi = -ai ,-bi
d1[t][(ai, bi)] += 1
a1, a2 = d1
ans = 1
z1 = 0
for (ai, bi), v in a1.items():
k2 = (bi, -ai)
if k2 in a2:
v2 = a2[k2]
ans *= pow(2, v, mod) + pow(2, v2, mod) - 1
ans %= mod
else:
z1 += v
for (ai, bi), v in a2.items():
k2 = (-bi, ai)
if k2 in a1: continue
z1 += v
ans *= pow(2, za, mod) + pow(2, zb, mod) - 1
ans %= mod
ans *= pow(2, z1, mod)
print((ans-1+z0) % mod)
if __name__ == "__main__":
resolve()
| def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
#from fractions import Fraction
from math import gcd
mod = int(1e9+7)
n = ii()
cnd = {}
azero = 0
bzero = 0
allzero = 0
for _ in range(n):
a,b = iim()
if a == 0:
if b != 0:
azero += 1
else:
allzero += 1
elif b == 0:
bzero += 1
else:
'''
ratio = Fraction(a,b)
before = cnd.get(ratio,False)
if before:
cnd[ratio] = [before[0]+1,before[1]]
else:
invratio = Fraction(-b,a)
check = cnd.get(invratio,False)
if check:
cnd[invratio] = [check[0],check[1]+1]
else:
cnd[ratio] = [1,0]
'''
g = gcd(a,b)
a //= g
b //= g
if a < 0:
a *= -1
b *= -1
cnd[(a,b)] = cnd.get((a,b),0)+1
noreg = 0
if azero == 0 or bzero == 0:
noreg += max(azero,bzero)
ans = 1
else:
ans = (2**azero%mod + 2**bzero%mod - 1)%mod
#print('ans block')
#print(ans,noreg)
#print(cnd)
for k,item in cnd.items():
a,b = k
if b>0:
m = cnd.get((b,-a),False)
if m:
ans *= (2**item%mod+2**m%mod-1)%mod
else:
noreg += item
else:
m = cnd.get((-b,a),False)
if not m:
noreg += item
#print('hoge')
print(int((ans*((2**noreg)%mod)-1+allzero)%mod)) | 1 | 21,004,272,294,212 | null | 146 | 146 |
N=int(input())
ans = "No"
n=0
for _ in range(N):
x, y = map(int, input().split())
if x == y:
n+=1
else:
n = 0
if n >= 3:
ans="Yes"
print(ans)
| def judge():
cnt = 0
for _ in range(N):
x, y = map(int, input().split())
if x == y:
cnt += 1
else:
cnt = 0
if cnt == 3:
return True
return False
N = int(input())
if judge():
print("Yes")
else:
print("No") | 1 | 2,533,095,572,898 | null | 72 | 72 |
N=int(input())
import sys
l=[i.rstrip().split() for i in sys.stdin.readlines()]
l=[list(map(int,i)) for i in l]
l=[[i-j,i+j] for i,j in l]
from operator import itemgetter
l.sort(key=itemgetter(1))
ans=N
end=l[0][1]
for i in range(N-1):
if l[i+1][0] < end:
ans-=1
else:
end=l[i+1][1]
print(ans) | from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time
def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
for i in range(len(mat)):
print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])
yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def main():
N = I()
zero = 0
cnts = defaultdict(int)
used = set()
for i in range(N):
a, b = MI()
if a == 0 and b == 0:
zero += 1
continue
g = gcd(abs(a), abs(b))
a = a // g
b = b // g
if b < 0:
a = -a
b = -b
cnts[(a, b)] += 1
# print(cnts)
ans = 1
for key, c in cnts.items():
if key in used:
continue
a, b = key
if a > 0:
rev = (-b, a)
else:
rev = (b, -a)
if rev in cnts:
# keyの集合から一個以上選ぶ + revの集合から一個以上選ぶ + どれも選ばない
ans *= (pow(2, cnts[key], MOD) - 1) + (pow(2, cnts[rev], MOD) - 1) + 1
# print(key, rev, ans)
ans %= MOD
used.add(rev)
else:
ans *= pow(2, cnts[key], MOD)
ans += zero
ans -= 1
print(ans % MOD)
if __name__ == '__main__':
main()
| 0 | null | 55,204,059,323,250 | 237 | 146 |
(h, n), *m = [[*map(int, i.split())] for i in open(0)]
dp = [0] * 20001
for i in range(1, h + 1):
dp[i] = min(dp[i-a]+b for a, b in m)
print(dp[h])
| row, col, num = map(int, input().split())
tmp_l = []
board = []
for i in range(row):
str = input()
for j in range(col):
if str[j] == '.':
tmp_l.append(0)
if str[j] == '#':
tmp_l.append(1)
board.append(tmp_l)
tmp_l = []
onoff = []
bi = [32, 16, 8, 4, 2, 1]
for i in range(64):
tmp = i
for j in bi:
tmp_l.insert(0, int(tmp / j))
tmp %= j
onoff.append(tmp_l)
tmp_l = []
count = 0
ans = 0
for i in range(2**row):
for j in range(2**col):
for k in range(row):
if onoff[i][k] == 1:
for l in range(col):
if onoff[j][l] == 1:
if board[k][l] == 1:
count += 1
if count == num:
ans += 1
count = 0
print(ans) | 0 | null | 45,138,724,151,140 | 229 | 110 |
def atc_153b(a: str, b: str) -> str:
HN = a.split(" ")
H = int(HN[0])
N = int(HN[1])
A = b.split(" ")
A_int = [int(ai) for ai in A]
damage = sum(A_int)
if (H - damage) <= 0:
return "Yes"
else:
return "No"
a = input()
b = input()
print(atc_153b(a, b)) | import math
A, B, H, M = map(int, input().split())
h_rad = (H / 12 + M / 12 / 60)* 2 * math.pi
m_rad = M / 60 * 2 * math.pi
dif_rad = abs(h_rad - m_rad)
ans = math.sqrt(A**2 + B**2 - 2 * A * B * math.cos(dif_rad))
print(ans) | 0 | null | 48,930,756,548,960 | 226 | 144 |
a=input()
b=input()
c=a*2
if b in c:
print("Yes")
else:
print("No")
| #!usr/bin/env python3
import math
import sys
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LIR(n):
return [LI() for i in range(n)]
class SegmentTree:
def __init__(self, size, f=lambda x,y : x+y, default=0):
self.size = 2**(size-1).bit_length()
self.default = default
self.dat = [default]*(self.size*2)
self.f = f
def update(self, i, x):
i += self.size
self.dat[i] = x
while i > 0:
i >>= 1
self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1])
def get(self, a, b=None):
if b is None:
b = a + 1
l, r = a + self.size, b + self.size
lres, rres = self.default, self.default
while l < r:
if l & 1:
lres = self.f(lres, self.dat[l])
l += 1
if r & 1:
r -= 1
rres = self.f(self.dat[r], rres)
l >>= 1
r >>= 1
res = self.f(lres, rres)
return res
def solve():
n,d,a = LI()
g = LIR(n)
g.sort()
X = [i for (i,_) in g]
s = SegmentTree(n)
ans = 0
for i in range(n):
x = g[i][0]
j = bisect.bisect_left(X,x-2*d)
h = g[i][1]-s.get(j,i)
if h <= 0:
continue
k = math.ceil(h/a)
ans += k
s.update(i,k*a)
print(ans)
return
#Solve
if __name__ == "__main__":
solve()
| 0 | null | 41,845,247,934,688 | 64 | 230 |
import numpy as np
def check_pali(S):
for i in range(0, len(S)):
if S[i] != S[-1 * i + -1]:
return False
elif i > (len(S) / 2) + 1:
break
return True
S = input()
N = len(S)
short_N = (N - 1) // 2
long_N = (N + 3) // 2
if check_pali(S) & check_pali(S[0:short_N]) & check_pali(S[long_N-1:N]):
print("Yes")
else:
print("No") |
H, W, K = [int(n) for n in input().split(" ")]
M = []
for _ in range(H):
a = [n for n in input()]
assert(len(a) == W)
M.append(a)
import copy
import itertools
"""
M = [[".", ".", "#"],
["#", "#", "#"]
]
W = len(M[0])
H = len(M)
K = 2
"""
def makeCombination(candidate, n, lessFlag):
if len(candidate) <= 0:
return [[]]
_candidate = [n for n in candidate]
_candidate = sorted(_candidate)
result = []
if lessFlag is False:
tmp = list(set(list(itertools.combinations(_candidate, n))))
for t in tmp:
result.append(list(t))
else:
for i in range(n):
result += makeCombination(candidate, i + 1, False)
result += [[]]
return result
def check(m, h, w):
MM = copy.deepcopy(m)
for a in h:
for i in range(W):
MM[a][i] = "R"
for a in w:
for i in range(H):
MM[i][a] = "R"
count = 0
for i in range(len(MM)):
for j in range(len(MM[i])):
if MM[i][j] == "#":
count += 1
return count
HHH = makeCombination([n for n in range(H)], H, True)
WWW = makeCombination([n for n in range(W)], W, True)
OK = 0
for i in range(len(HHH)):
for j in range(len(WWW)):
if check(M, HHH[i], WWW[j]) == K:
OK += 1
print(OK)
| 0 | null | 27,736,450,715,470 | 190 | 110 |
n,k=map(int,input().split())
mod=10**9+7
ans=0
for x in range(k,n+2):
min_a=(0+x-1)*x//2
max_a=(n-x+1+n)*x//2
aa=max_a-min_a+1
ans+=aa
print(ans%mod) | def sum_part(N, k):
return k*(2*N-k+1)/2-k*(k-1)/2+1
N, K = map(int, input().split())
ans = 0
for k in range(K,N+2):
ans += sum_part(N, k)
ans = ans % (10**9 + 7)
print(int(ans)) | 1 | 33,061,432,937,920 | null | 170 | 170 |
n = int(input())
l = list(map(int, input().split()))
mod_check=0
mod_check_ =0
for i in l:
if i % 2 == 0 :
mod_check += 1
if i % 3 == 0 or i % 5 == 0:
mod_check_ += 1
else:
pass
else:
pass
print('APPROVED') if mod_check==mod_check_ else print('DENIED')
| import math
# 素数か否かを判定する関数
def is_prime(n):
for i in range(2, int(math.sqrt(n))+1):
if n%i == 0:
return False
return True
# nまでの素数を返す関数(エラトステネスの篩)
def getPrime(n):
n_sqrt = int(math.sqrt(n))
array = [True]*(n_sqrt+1)
result = []
for i in range(2, n_sqrt+1):
if array[i]:
array[i] = False
result.append(i)
for j in range(i*2, n_sqrt+1, i):
array[j] = False
return result
N = int(input())
n = N
prime = getPrime(n)
prime_exp = []
# print(prime)
for p in prime:
cnt = 0
while n%p == 0:
n = int(n/p)
# print(n)
cnt += 1
if cnt != 0:
prime_exp.append([p, cnt])
if is_prime(n) and n != 1:
prime_exp.append([n, 1])
ans = 0
for pe in prime_exp:
ans += int((-1+math.sqrt(1+8*pe[1]))/2)
print(ans) | 0 | null | 43,113,443,791,000 | 217 | 136 |
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
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 -1 * self.parents[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()) - 1
N,M = map(int, input().split())
uf = UnionFind(N)
for i in range(M):
a,b = map(int, input().split())
uf.union(a,b)
ans = uf.group_count() - 1
print(ans)
| n,m = map(int, input().split())
class UnionFind():
# 作りたい要素数nで初期化
# 使用するインスタンス変数の初期化
def __init__(self, n):
self.n = n
# root[x]<0ならそのノードが根かつその値が木の要素数
# rootノードでその木の要素数を記録する
self.root = [-1]*(n+1)
# 木をくっつける時にアンバランスにならないように調整する
self.rnk = [0]*(n+1)
# ノードxのrootノードを見つける
def Find_Root(self, x):
if(self.root[x] < 0):
return x
else:
# ここで代入しておくことで、後の繰り返しを避ける
self.root[x] = self.Find_Root(self.root[x])
return self.root[x]
# 木の併合、入力は併合したい各ノード
def Unite(self, x, y):
# 入力ノードのrootノードを見つける
x = self.Find_Root(x)
y = self.Find_Root(y)
# すでに同じ木に属していた場合
if(x == y):
return
# 違う木に属していた場合rnkを見てくっつける方を決める
elif(self.rnk[x] > self.rnk[y]):
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
# rnkが同じ(深さに差がない場合)は1増やす
if(self.rnk[x] == self.rnk[y]):
self.rnk[y] += 1
# xとyが同じグループに属するか判断
def isSameGroup(self, x, y):
return self.Find_Root(x) == self.Find_Root(y)
# ノードxが属する木のサイズを返す
def Count(self, x):
print(self.root)
return -self.root[self.Find_Root(x)]
def Output(self):
return [i for i in self.root if i < 0]
uf = UnionFind(n)
for i in range(m):
ab = list(map(int, input().split()))
uf.Unite(ab[0],ab[1])
#print(uf.Output())
print(len(uf.Output())-2)
| 1 | 2,298,139,387,072 | null | 70 | 70 |
n = int(input())
s, t = input().split(' ')
q = ''
for i in range(n):
q += s[i]
q += t[i]
print(q)
| n = int(input())
S, T = input().split()
ans = ""
for i in range(n):
ans += S[i]+T[i]
print(ans) | 1 | 111,911,114,337,738 | null | 255 | 255 |
def fibonacci(n):
a, b = 1, 0
for _ in range(0, n):
a, b = b, a + b
return b
n=int(input())
n+=1
print(fibonacci(n))
| def fibonacci(n, memo=None):
if memo==None:
memo = [None]*n
if n<=1:
return 1
else:
if memo[n-2]==None:
memo[n-2] = fibonacci(n-2, memo)
if memo[n-1]==None:
memo[n-1] = fibonacci(n-1, memo)
return memo[n-1] + memo[n-2]
n = int(input())
print(fibonacci(n)) | 1 | 1,826,309,198 | null | 7 | 7 |
n = int(input())
a = ["a","b","c","d","e","f","g","h","i","j"]
def dfs(s):
m = len(s)
if m == n:
ans = ""
for i in range(n):
ans += a[int(s[i])]
print(ans)
else:
for i in range(int(max(list(s)))+2):
dfs(s+str(i))
dfs("0") | N=int(input())
def struct(s,i,n,ma):
if i==n:
print(s)
else:
for j in range(0,ma+2):
struct(s+chr(ord('a')+j),i+1,n,max(j,ma))
struct('a',1,N,0) | 1 | 52,324,884,249,462 | null | 198 | 198 |
import sys
input = sys.stdin.readline
M1,D1 = map(int, input().split())
M2,D2 = map(int, input().split())
if(M1+1==M2):print(1)
else: print(0) | import bisect
n = int(input())
ls = list(map(int,input().split()))
ls = sorted(ls)
ans = 0
for i in range(n):
for j in range(i+1,n):
k = bisect.bisect_left(ls,ls[i]+ls[j])
ans += k-j-1
print(ans) | 0 | null | 147,691,821,901,690 | 264 | 294 |
H, W, K = map(int, input().split())
a = [input() for _ in range(H)]
ans = [[-1 for _ in range(W)] for _ in range(H)]
i_cut_time = 0
j_cut_time = 0
for i in range(H):
if '#' in a[i]:
i_cut_time += 1
i_cut = []
start = 0
goal = -1
for i in range(H):
if len(i_cut) == i_cut_time-1:
break
if '#' in a[i]:
goal = i
i_cut.append([start, goal, i])
start = goal+1
for i in range(start, H):
if '#' in a[i]:
i_cut.append([start, H-1, i])
# print(i_cut)
cnt = 1
for s, g, p in i_cut:
j_cut = []
jstart = 0
jgoal = -1
for i in range(W):
if len(j_cut) == a[p].count('#')-1:
break
if a[p][i] == '#':
jgoal = i
j_cut.append([jstart, jgoal])
jstart = jgoal+1
j_cut.append([jstart, W-1])
# print(s, g, p, j_cut)
# for i in range(s, g+1):
for js, jg in j_cut:
for j in range(js, jg+1):
for i in range(s, g+1):
# print(i, j, cnt)
ans[i][j] = cnt
cnt += 1
# print(*ans, sep='\n')
for i in range(H):
print(*ans[i]) | import sys
def calc_cell(x, y):
return '.' if (x + y) % 2 else '#'
def print_chessboard(height, width):
for y in range(height):
l = []
for x in range(width):
l.append(calc_cell(x, y))
print ''.join(l)
if __name__ == '__main__':
while True:
h, w = map(int, sys.stdin.readline().split())
print_chessboard(h, w)
if not h or not w:
break
print | 0 | null | 72,262,881,270,280 | 277 | 51 |
import math
N = int(input())
M = []
sqr_N = math.floor(math.sqrt(N))
a = 0
for i in range(1, (sqr_N + 1)):
if N % i == 0:
a = i
a_pair = N // a
print(a + a_pair - 2) | #http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_B
x, y = map(int, input().split())
if y > x:
w = y
y = x
x = w
while y > 0:
amari = x % y
x = y
y = amari
print(x) | 0 | null | 81,023,645,267,334 | 288 | 11 |
from sys import stdin
import numpy as np
n, k = map(int, stdin.buffer.readline().split())
a = np.fromstring(stdin.buffer.read(), dtype=np.int, sep=' ')
ng = 0
ok = 10 ** 9 + 1
while ok - ng > 1:
mid = (ok + ng) >> 1
if np.sum(np.ceil(a / mid) - 1) <= k:
ok = mid
else:
ng = mid
print(ok)
| import sys
i = 1
for line in sys.stdin.readlines():
x = line.strip()
if x != "0":
print("Case {}: {}".format(i, x))
i += 1 | 0 | null | 3,476,750,813,692 | 99 | 42 |
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 = False
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] == seen[2] == "O":
over = True
elif seen[3] == seen[6] == "O":
over = True
elif seen[4] == seen[8] == "O":
over = True
elif seen[4] == "O":
if seen[2] == seen[6] == "O":
over = True
elif seen[1] == seen[7] == "O":
over = True
elif seen[3] == seen[5] == "O":
over = True
elif seen[8] == "O":
if seen[6] == seen[7] == "O":
over = True
if seen[2] == seen[5] == "O":
over = True
if not over:
print("No")
else:
print("Yes") | n = int(input())
A = [[False for _ in range(n)] for _ in range(n)]
for _ in range(n):
tmp = list(map(int, input().split()))
for i in range(tmp[1]):
A[tmp[0]-1][tmp[i+2]-1] = True
WHITE = 0
GRAY = 1
BLACK = 2
color = [WHITE for _ in range(n)]
d = [0 for _ in range(n)]
f = [0 for _ in range(n)]
time = 1
def dfs(u):
global dfs_color, d, f, time
color[u] = GRAY
d[u] += time
time += 1
for v in range(n):
if A[u][v]:
if color[v] == WHITE:
dfs(v)
else:
continue
color[u] = BLACK
f[u] = time
time += 1
for u in range(n):
if color[u] == WHITE:
dfs(u)
for i in range(n):
print(str(i+1) + ' ' + str(d[i]) + ' ' + str(f[i]) ) | 0 | null | 29,939,905,590,112 | 207 | 8 |
N, K, S = map(int, input().split())
L = []
if (S < 10**9):
for i in range(K):
L.append(str(S))
for i in range(N - K):
L.append(str(S + 1))
elif (S == 10 ** 9):
for i in range(K):
L.append(str(S))
for i in range(N - K):
L.append(str(1))
print(' '.join(L))
| n=int(input())
array=list(map(int,input().split()))
ans=0
for m in range(n):
if m%2==0 and array[m]%2==1:
ans=ans+1
print(ans) | 0 | null | 49,556,084,046,908 | 238 | 105 |
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])
| K, N = map(int, input().split())
A = list(map(int, input().split()))
c = abs(K - A[N-1] + A[0])
for i in range(N-1):
d = abs(A[i] - A[i+1])
if c < d:
c = d
else:
c = c
print(K-c) | 0 | null | 21,911,101,116,942 | 27 | 186 |
n = int(input())
c = list(input())
r = 0
temp = 0
for i in c:
if i == 'R':
r += 1
w = n - r
for i in range(r):
if c[i] == 'R':
temp += 1
print(r - temp) | n = int(input())
c = input()
count = 0
i, j = 0, n - 1
if c.count('W') == 0:
count=0
elif c.count('R') == 0:
count = 0
else:
white_cnt = []
red_cnt = []
for i in range(n):
if c[i] == 'W':
white_cnt.append(i)
else:
red_cnt.append(i)
while 1:
white_num = white_cnt.pop(0)
red_num = red_cnt.pop()
if white_num < red_num:
count += 1
if len(white_cnt) == 0:
break
if len(red_cnt) == 0:
break
print(count)
| 1 | 6,350,485,138,048 | null | 98 | 98 |
n, m, l = map(int, input().split())
A = [list(map(int, input().split())) for i in range(n)]
B = [list(map(int, input().split())) for i in range(m)]
for ARow in A:
result = []
for BCol in zip(*B):
result.append(sum([ARow[i] * BCol[i] for i in range(m)]))
print(*result) | n,m,l = map(int,input().split())
a = [[0 for i2 in range(m)] for i1 in range(n)]
b = [[0 for i2 in range(l)] for i1 in range(m)]
for i in range(n):
row = list(map(int,input().split()))
for j in range(m):
a[i][j] = row[j]
for i in range(m):
row = list(map(int,input().split()))
for j in range(l):
b[i][j] = row[j]
c = [[0 for i2 in range(l)] for i1 in range(n)]
for i in range(n):
for j in range(l):
for k in range(m):
c[i][j] += a[i][k]*b[k][j]
for i in range(n):
for j in range(l-1):
print(c[i][j],end = ' ')
print(c[i][-1]) | 1 | 1,421,697,517,318 | null | 60 | 60 |
N,M,K=list(map(int,input().split()))
MAXN = 2*(10**5)+10
p = 998244353
MOD = p
f = [1]
for i in range(MAXN):
f.append(f[-1] * (i+1) % MOD)
def nCr(n, r, mod=MOD):
return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod
def power_func(a,n,p):
bi=str(format(n,"b"))#2進表現に
res=1
for i in range(len(bi)):
res=(res*res) %p
if bi[i]=="1":
res=(res*a) %p
return res
out = 0
for i in range(K+1):
out += M*nCr(N-1,i,p)*power_func(M-1,N-1-i,p)
out = out % p
print(out) | N=input()
if int(N[-1]) in [2,4,5,7,9]:
print('hon')
elif int(N[-1]) in [3]:
print('bon')
else:
print('pon') | 0 | null | 21,179,721,460,580 | 151 | 142 |
def havec(x_list, y):
x_list[y-1] = 1
def printc(x_list, s):
for i in range(13):
if x_list[i] == 0:
print("%s %d" %(s, i+1))
n = input()
Sp = [0,0,0,0,0,0,0,0,0,0,0,0,0]
Ha = [0,0,0,0,0,0,0,0,0,0,0,0,0]
Cl = [0,0,0,0,0,0,0,0,0,0,0,0,0]
Di = [0,0,0,0,0,0,0,0,0,0,0,0,0]
for i in range(n):
incard = raw_input()
a, b = incard.split(" ")
b = int(b)
if a == "S":
havec(Sp, b)
elif a == "H":
havec(Ha, b)
elif a == "C":
havec(Cl, b)
else:
havec(Di, b)
printc(Sp, "S")
printc(Ha, "H")
printc(Cl, "C")
printc(Di, "D") | def Fibonacci(n):
if n == 0 or n == 1:
dic[n] = 1
if n in dic.keys():
return dic[n]
dic[n] = Fibonacci(n-1) + Fibonacci(n-2)
return dic[n]
a = int(input())
dic ={}
print(Fibonacci(a))
| 0 | null | 532,026,592,940 | 54 | 7 |
import sys
def gcd(a,b):
if(b):
return gcd(b,(a%b))
else:
return a
def lcm(a,b):
return a*b/gcd(a,b)
a = ""
for input in sys.stdin:
a += input
l = a.split()
for i in range(0,len(l),2):
if(int(l[i]) > int(l[i+1])):
print gcd(int(l[i]),int(l[i+1])),lcm(int(l[i]),int(l[i+1]))
else:
print gcd(int(l[i+1]),int(l[i])),lcm(int(l[i+1]),int(l[i]))
| while True:
try:
As,Bs = map(int,input().split())
a,b = As, Bs
while True:
if a % b == 0:
gcd = b
break
a,b = b, a % b
print(gcd,int(As * Bs / gcd))
except EOFError:
break | 1 | 697,358,958 | null | 5 | 5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.