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
|
---|---|---|---|---|---|---|
n, k = map(int, input().split())
mod = 1000000007
b = mod-2
blis = []
c = 0
while b >0:
if b & 1 == 1:
blis.append(c)
c += 1
b >>= 1
def modinv(a):
if a == 1:
return 1
else:
res = 1
li = []
for _ in range(c):
li.append(a%mod)
a = a*a%mod
for item in blis:
res = res *li[item] %mod
return res
if k >=n:
L = 2*n-1
ansbunsi =1
for j in range(n-1):
ansbunsi = ansbunsi*L%mod
L -= 1
ansbunbo = 1
L = n - 1
for j in range(n-1):
ansbunbo = ansbunbo*L%mod
L -= 1
ansbunbo = modinv(ansbunbo)
print(ansbunsi*ansbunbo%mod)
else:
kaijou = [1, 1]
for j in range(2, n):
kaijou.append(kaijou[-1]*j%mod)
ans = 0
for m in range(k+1):
ansbunsi = (kaijou[n-1]**2)*n%mod
ansbunbo = kaijou[n-m-1]*kaijou[m]%mod
ansbunbo = ansbunbo*ansbunbo%mod*(n-m)%mod
ansbunbo = modinv(ansbunbo)
ans += ansbunbo*ansbunsi%mod
ans %= mod
print(ans)
| from collections import deque
k = int(input())
q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
for i in range(k):
a = q.popleft()
b = a % 10
if b == 0:
q.append(a * 10)
q.append(a * 10 + b + 1)
elif b == 9:
q.append(a * 10 + b - 1)
q.append(a * 10 + b)
else:
q.append(a * 10 + b - 1)
q.append(a * 10 + b)
q.append(a * 10 + b + 1)
print(a) | 0 | null | 53,904,661,754,060 | 215 | 181 |
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
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")
# ------------------- fast io --------------------
from math import gcd, ceil
def pre(s):
n = len(s)
pi = [0] * n
for i in range(1, n):
j = pi[i - 1]
while j and s[i] != s[j]:
j = pi[j - 1]
if s[i] == s[j]:
j += 1
pi[i] = j
return pi
def prod(a):
ans = 1
for each in a:
ans = (ans * each)
return ans
def lcm(a, b): return a * b // gcd(a, b)
def binary(x, length=16):
y = bin(x)[2:]
return y if len(y) >= length else "0" * (length - len(y)) + y
def solve(h, w, k, board):
ans = 0
for row in range(1 << h):
for col in range(1 << w):
count = 0
for i in range(h):
for j in range(w):
if (row >> i) & 1 == 0:
continue
if (col >> j) & 1 == 0:
continue
if board[i][j] == '#':
count += 1
if count == k:
ans += 1
return ans
h, w, k = map(int, input().split())
board = []
for i in range(h):
board += [list(input())]
print(solve(h, w, k, board))
| 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]
y = input()
K = int(y)
print(x[K-1]) | 0 | null | 29,498,455,722,358 | 110 | 195 |
import math
def main():
r = int(input())
print(math.pi *r *2)
if __name__ == "__main__":
main() | hankei = input()
print(int(hankei)**2) | 0 | null | 88,088,700,863,292 | 167 | 278 |
n = int( input() )
x = input()
x_pop = x.count( "1" )
x_pls = x_pop + 1
x_mns = x_pop - 1
# 2の冪乗のリスト.ただし後々に備えてpopcountで割った余りにしてある
rp = [ pow( 2, i, x_pls ) for i in range( n + 1 ) ]
if x_mns > 0:
rm = [ pow( 2, i, x_mns ) for i in range( n + 1 ) ]
else:
rm = [ 0 ] * ( n + 1 )
x = x[ : : -1 ]
rem_p = 0
rem_m = 0
for i in range( n ):
if x[ i ] == "1":
rem_p += rp[ i ]
rem_m += rm[ i ]
for i in range( n - 1, -1, -1 ):
if x[ i ] == "0":
tmp = ( rem_p + rp[ i ] ) % x_pls
elif x_mns > 0:
tmp = ( rem_m - rm[ i ] ) % x_mns
else: # popcount( X_i ) == 0
print( 0 )
continue
ans = 1
while tmp > 0:
tmp = tmp % bin( tmp ).count( "1" )
ans += 1
print( ans ) | print('No' if sum(map(int, input())) % 9 else 'Yes') | 0 | null | 6,328,551,944,990 | 107 | 87 |
while True:
H, W = map(int, input().split())
if not(H or W):
break
for j in range(W):
print('#', end='')
print()
for i in range(H-2):
print('#', end='')
for j in range(W-2):
print('.', end='')
print('#')
for j in range(W):
print('#', end='')
print('\n') | judge = True
while judge:
h,w = map(int, input().split(" "))
if h == 0 and w == 0:
judge = False
else:
for i in range(h):
if i == 0 or i+1 == h:
print("#"*w)
else:
print("#"+"."*(w-2)+"#")
print() | 1 | 826,330,172,528 | null | 50 | 50 |
import sys
from heapq import heapify, heappop, heappush
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, U, V = lr()
graph = [[] for _ in range(N+1)] # 1-indexed
for _ in range(N-1):
a, b = lr()
graph[a].append(b)
graph[b].append(a)
def dijkstra(start):
INF = 10 ** 15
dist = [INF] * (N+1)
dist[start] = 0
que = [(0, start)]
while que:
d, prev = heappop(que)
if dist[prev] < d:
continue
for next in graph[prev]:
d1 = d + 1
if dist[next] > d1:
dist[next] = d1
heappush(que, (d1, next))
return dist
dist_U = dijkstra(U)
dist_V = dijkstra(V)
answer = max(v for u, v in zip(dist_U, dist_V) if v > u) - 1
print(answer)
# 25 | n, u, v = map(int, input().split())
u, v = u-1, v-1
edges = [[] for i in range(n)]
for i in range(n-1):
ai, bi = map(int, input().split())
ai, bi = ai-1, bi-1
edges[ai].append(bi)
edges[bi].append(ai)
depth = 0
already = [0 for i in range(n)]
already[v] = 1
nodes = [v]
while nodes != []:
depth += 1
next_nodes = []
for node in nodes:
children = edges[node]
for child in children:
if already[child] == 0:
already[child] = depth
next_nodes.append(child)
nodes = next_nodes
already[v] = 0
depth = 0
already_u = [0 for i in range(n)]
already_u[u] = 1
nodes = [u]
while nodes != []:
depth += 1
next_nodes = []
for node in nodes:
children = edges[node]
for child in children:
if already_u[child] == 0:
already_u[child] = depth
next_nodes.append(child)
nodes = next_nodes
already_u[u] = 0
maxi = 0
for i in range(n):
if already_u[i] < already[i]:
maxi = max(maxi, already[i])
print(maxi-1) | 1 | 117,134,135,930,908 | null | 259 | 259 |
s=input()
ans='No'
if s[2]==s[3] and s[4]==s[5]:
ans='Yes'
print(ans) | n=list(input())
#print(n)
if n[2]==n[3] and n[4]==n[5]:
#if n[2]!=n[4]:
print('Yes')
else:
print('No')
| 1 | 41,880,559,667,012 | null | 184 | 184 |
import sys
buildings = [[[0 for i in xrange(10)] for j in xrange(3)] for k in xrange(4)]
n = input()
for i in xrange(n):
b, f, r, v = map(int, raw_input().split())
buildings[b-1][f-1][r-1] += v
for i in xrange(4):
if i != 0:
print "####################"
for j in xrange(3):
for k in xrange(10):
sys.stdout.write(" "+str(buildings[i][j][k]))
print | # coding: utf-8
def showBuilding(mansion):
for i, building in enumerate(mansion):
for line in building:
for room in line:
print(' ' + str(room), end='')
print()
if i != 3:
print('####################')
if __name__ == '__main__':
mansion = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)]
for _ in range(int(input())):
b, f, r, v = map(int, input().split())
mansion[b-1][f-1][r-1] += v
showBuilding(mansion)
| 1 | 1,111,031,681,372 | null | 55 | 55 |
S=int(input())
T=list(input())
t=S//2
p=0
for i in range(t):
if S%2==1:
p=-1
break
elif T[i]!=T[i+t]:
p=-1
break
if p==-1 or t==0:
print("No")
elif p==0:
print("Yes")
| import sys
def input(): return sys.stdin.readline().rstrip()
def ctoi(c):
return ord(c)-97
class BIT:
def __init__(self, n):
self.unit_sum=0 # to be set
self.n=n
self.dat=[0]*(n+1)#[1,n]
def add(self,a,x): #a(1-)
i=a
while i<=self.n:
self.dat[i]+=x
i+=i&-i
def sum(self,a,b=None):
if b!=None:
return self.sum(b-1)-self.sum(a-1) #[a,b) a(1-),b(1-)
res=self.unit_sum
i=a
while i>0:
res+=self.dat[i]
i-=i&-i
return res #Σ[1,a] a(1-)
def __str__(self):
self.ans=[]
for i in range(1,self.n):
self.ans.append(self.sum(i,i+1))
return ' '.join(map(str,self.ans))
def main():
n=int(input())
S=list(input())
q=int(input())
BIT_tree=[]
for i in range(26):
obj=BIT(n+1)
BIT_tree.append(obj)
for i in range(n):
BIT_tree[ctoi(S[i])].add(i+1,1)
for _ in range(q):
query=input().split()
if query[0]=="1":
index,x=int(query[1])-1,query[2]
BIT_tree[ctoi(S[index])].add(index+1,-1)
BIT_tree[ctoi(x)].add(index+1,1)
S[index]=x
else:
l,r=int(query[1])-1,int(query[2])-1
ans=0
for c in range(26):
if BIT_tree[c].sum(l+1,r+2):
ans+=1
print(ans)
if __name__=='__main__':
main() | 0 | null | 105,118,198,390,982 | 279 | 210 |
a = str(input())
b = str(input())
if a[:len(a)] == b[:len(a)] and len(b)==len(a)+1:
print("Yes")
else:
print("No") |
def main():
s = input()
t = input()
if s == t[:-1]:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main() | 1 | 21,409,690,195,492 | null | 147 | 147 |
import numpy as np
h, a = map(int, input().split())
print(int(np.ceil(h / a))) | H, A = map(int, input().split())
count = 0
while True:
H -= A
count += 1
if H <= 0:
print(count)
exit() | 1 | 77,321,545,503,860 | null | 225 | 225 |
input()
list = input().split()
list.reverse()
print (' '.join(list)) | S = input()
ans = ""
for s in range(len(S)):
if S[s] == "?":
print("D", end="")
else:
print(S[s], end="")
print("") | 0 | null | 9,729,314,756,110 | 53 | 140 |
for i in range(int(input())):
temp = [int(x) for x in input().split()]
stemp = sorted(temp)
if stemp[2]**2 == stemp[1]**2 + stemp[0]**2:
print('YES')
else:
print('NO')
| class cmbs(object):
def __init__(self, mod):
self.mod = mod
self.g1 = [1, 1]
self.g2 = [1, 1]
inverse = [0, 1]
for i in range(2, 2 * (10 ** 6) + 1):
self.g1.append((self.g1[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod // i)) % mod)
self.g2.append((self.g2[-1] * inverse[-1]) % mod)
def cmb(self, n, r):
if n > 2 * (10 ** 6):
return self.cmbl(n, r)
return self.cmbr(n, r)
def cmbr(self, n, r):
if r < 0 or r > n:
return 0
r = min(r, n - r)
return self.g1[n] * self.g2[r] * self.g2[n-r] % self.mod
def cmbl(self, n, r):
t = 1
r = min(r, n-r)
for i in range(n - r + 1, n + 1):
t = t * i % self.mod
return t * self.g2[r] % self.mod
def main():
K = int(input())
S = input()
l = len(S)
mod = 10**9 + 7
c = cmbs(mod)
r = 0
x25 = 1
x26 = pow(26, K, mod)
inv26 = pow(26, mod-2, mod)
for i in range(K+1):
r = (r + c.cmb(l+i-1, i) * x25 * x26) % mod
x25 = x25 * 25 % mod
x26 = x26 * inv26 % mod
return r % mod
print(main())
| 0 | null | 6,469,344,365,660 | 4 | 124 |
n = int(input())
a = input().split()
min = int(a[0])
max = int(a[0])
sum = 0
for i in a:
if min > int(i):
min = int(i)
if max < int(i):
max = int(i)
sum += int(i)
print("{0} {1} {2}".format(min, max, sum)) | n = input()
a = list(map(int, raw_input().split(" ")))
print("%d %d %d" % (min(a), max(a), sum(a))) | 1 | 735,575,518,118 | null | 48 | 48 |
import copy
H, W, K = map(int, input().split())
tiles = [list(input()) for _ in range(H)]
answer = 0
for h in range(2**H):
for w in range(2**W):
b_cnt = 0
for i in range(H):
for j in range(W):
if not (h>>i&1 or w>>j&1) and tiles[i][j] == '#':
b_cnt += 1
if b_cnt == K:
answer += 1
print(answer) | def fib(n,memo={}):
if n==0 or n==1:
return 1
elif n in memo:
return memo[n]
else:
memo[n]= fib(n-1,memo)+fib(n-2,memo)
return memo[n]
n=int(input())
print(fib(n))
| 0 | null | 4,409,411,323,812 | 110 | 7 |
# A Curtain
a, b = map(int, input().split())
x = a-(b * 2)
if x > 0:
print(x)
else:
print(0)
| import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
A, B = M()
if A < 2*B:
print(0)
else:
print(A-2*B) | 1 | 166,391,905,425,380 | null | 291 | 291 |
a,b = list(map(int, input().split()))
c = 2 * (a+ b)
d = a * b
print(str(d) + " " + str(c)) | import sys
ans=0
A, B, C, K = (int(x) for x in input().split())
if A>K:
print(K)
sys.exit(0)
else:
K-=A
ans+=A
if B>K:
print(ans)
sys.exit(0)
else:K-=B
if C>K:
print(ans-K)
sys.exit()
else:
ans-=C
print(ans) | 0 | null | 11,124,742,075,010 | 36 | 148 |
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
A = list(map(int, readline().split()))
if sum(A) >= 22:
print("bust")
else:
print("win")
if __name__ == '__main__':
main()
| import itertools
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
l = [i+1 for i in range(N)]
for i, tpl in enumerate(itertools.permutations(l, N)):
if tpl == P:
a = i
if tpl == Q:
b = i
print(abs(a-b)) | 0 | null | 109,399,880,370,142 | 260 | 246 |
nums = input().split(' ')
a = int(nums[0])
b = int(nums[1])
c = int(nums[2])
d = int(nums[3])
multi = []
multi.append(a * c)
multi.append(a * d)
multi.append(b * c)
multi.append(b * d)
ans = - 10 ** 18
for i in range(4):
if multi[i] > ans:
ans = multi[i]
print(ans) | N = input()
num = N.split(' ')
a = int(num[0])
b = int(num[1])
c = int(num[2])
d = int(num[3])
e = a * c
f = a * d
g = b * c
h = b * d
num_max = max([e, f, g, h])
print(num_max) | 1 | 3,017,220,249,660 | null | 77 | 77 |
K,N=map(int,input().split())
A=[int(x) for x in input().split()]
A+=[K+A[0]]
print(K-max(A[i+1]-A[i] for i in range(N)))
| K, N = map(int, input().split())
A = list(map(int, input().split()))
ans = K
for i in range(N):
start = A[i]
end = K+A[i-1] if A[i-1] < A[i] else A[i-1]
path = end-start
ans = min(path, ans)
print(ans) | 1 | 43,395,606,342,452 | null | 186 | 186 |
n = int(input())
a = list(map(int, input().split()))
ans = [0]*n
for i in range(n):
ans[a[i]-1] += i+1
ans[a[i]-1] = str(ans[a[i]-1])
print(" ".join(ans)) | #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 decimal
import re
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(input())
n = I()
A = readInts()
nya = []
for i in range(n):
nya.append((i+1,A[i]))
nya = sorted(nya,key = lambda x:x[1])
ans = []
for (idx,po) in nya:
ans.append(idx)
print(*ans)
| 1 | 180,664,081,764,100 | null | 299 | 299 |
N = int(input())
A = list(map(int, input().split()))
from collections import Counter
def factorize(n):
b = 2
fct = []
while b * b <= n:
while n % b == 0:
n //= b
fct.append(b)
b = b + 1
if n > 1:
fct.append(n)
c = Counter(fct)
return c
def solve(N,A):
ans = 0
mod = 10**9+7
fcts = [0]*10**6
for a in A:
c = factorize(a)
for k,v in c.items():
fcts[k] = max(fcts[k],v)
prod = 1
for i,f in enumerate(fcts):
if f==0:
continue
prod *= pow(i,f)
prod %= mod
for a in A:
ans += prod*pow(a,mod-2,mod)
ans %= mod
return ans
print(solve(N,A)) | from collections import Counter
N = int(input())
A = list(map(int,input().split()))
memo = []
for i in range(N):
tmp = []
a = A[i]
d = 2
while d*d <= a:
while a%d == 0:
tmp.append(d)
a //= d
d += 1
if a!=1:
tmp.append(a)
memo.append(Counter(tmp))
lcm = Counter([])
for count in memo:
for k,v in count.items():
if k not in lcm:
lcm[k] = v
else:
lcm[k] = max(lcm[k],v)
mod = 10**9 +7
LCM = 1
for k,v in lcm.items():
LCM = LCM*pow(k,v)%mod
ans = 0
for a in A:
ans = (ans + LCM*pow(a,mod-2,mod))%mod
print(int(ans)) | 1 | 87,492,835,102,988 | null | 235 | 235 |
N,M=map(int,input().split())
H=list(map(int,input().split()))
L=[0]*N
for i in range(M):
A,B=map(int,input().split())
L[A-1]=max(L[A-1],H[B-1])
L[B-1]=max(L[B-1],H[A-1])
ans=0
for j in range(N):
if H[j]>L[j]:
ans+=1
print(ans)
| from collections import Counter
N = int(input())
A = list(map(int,input().split()))
count_a = Counter(A)
ans_list = [0] * (N+1)
for k, v in count_a.items():
ans_list[k] = int(v * (v-1) / 2)
all_sum = sum(ans_list)
for i in range(N):
print(all_sum - count_a[A[i]] + 1)
| 0 | null | 36,313,510,147,750 | 155 | 192 |
w = raw_input().lower()
s = 0
while 1:
in_str = raw_input()
if in_str == "END_OF_TEXT":
break
in_str = map(str, in_str.split())
for i in in_str:
if i.lower() == w:
s+=1
print s | n = int(input())
tp = ((1,1),(1,-1))
for i in range(200):
for j in range(200):
for k in tp:
a,b = i*k[0],j*k[1]
if((a**5 - b**5)==n):
print(a,b)
exit() | 0 | null | 13,701,977,756,570 | 65 | 156 |
k, n = map(int, input().split())
a = list(map(int, input().split()))
a.append(a[0] + k)
dist = [a[i + 1] - a[i] for i in range(n)]
print(sum(dist) - max(dist))
| import sys
from array import array
read = sys.stdin.buffer.read
k, n, *A = map(int, read().split())
A += [k + A[0]]
far = max(array("l", [x - y for x, y in zip(A[1:], A)]))
print(k-far) | 1 | 43,265,129,537,518 | null | 186 | 186 |
a,b = [int(n) for n in input().split()]
if a == b:
print("a == b")
elif a > b:
print("a > b")
else:
print("a < b") | a,b = map(int,input().split())
if a > b:
op = '>'
elif a < b:
op = '<'
else:
op = '=='
print("a %s b"%op)
| 1 | 363,478,194,240 | null | 38 | 38 |
k=int(input())
num=7
i=1
while True:
if k%2==0 or k%5==0:
i=-1
break
num%=k
if num==0:
break
else:
num*=10
num+=7
i+=1
print(i) | N, K = list(map(int, input().split()))
price_list = list(map(int, input().split()))
price_list.sort()
answer = 0
for i in range(K):
answer += price_list[i]
print(answer) | 0 | null | 8,901,002,705,970 | 97 | 120 |
while True:
n = int(input())
if n == 0:
break
s = list(map(float, input().split()))
m = sum(s) / n
v = sum([(x - m) ** 2 for x in s]) / n
print(v ** 0.5) | while True:
n = int(input())
if n == 0:
break
s = list(map(int,input().split()))
m = 0
sum = 0
for i in range(n):
sum += s[i]
m = sum/n
tmp = 0
for i in range(n):
tmp += (s[i]-m)**2
print((tmp/n)**0.5) | 1 | 188,831,459,320 | null | 31 | 31 |
n = int(input())
s = []
t = []
for i in range(n):
si, ti = input().split()
s.append(si)
t.append(int(ti))
x = input()
insleep = s.index(x)
ans = sum(t[insleep+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 | 58,765,113,491,382 | 243 | 146 |
k,n = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
d = []
for i in range(n-1):
d.append(a[i+1]-a[i])
d.append(k-a[n-1]+a[0])
d.sort()
for i in range(len(d)-1):
ans += d[i]
print(ans) | k,n,*a=map(int,open(0).read().split())
dist=10**7
for i in range(n):
if i==0:
# print(a[-1]-a[0])
dist=min(dist,a[-1]-a[0])
else:
# print(a[-1+i]+k-a[i])
dist=min(dist,a[-1+i]+k-a[i])
print(dist) | 1 | 43,463,438,112,468 | null | 186 | 186 |
from collections import defaultdict
n = int(input())
alst = list(map(int, input().split()))
ans = 0
dd = defaultdict(int)
for a in alst:
dd[a] += 1
for _, num in dd.items():
ans += num * (num - 1) // 2
for a in alst:
num = dd[a]
ret = ans - num * (num - 1) // 2 + (num - 1) * (num - 2) // 2
print(ret) | h,n=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
mx=max(a for a,b in ab)
dp=[10**10]*(h+1+mx)
dp[0]=0
for i in range(1,h+1+mx):
dp[i]=min(dp[i-a]+b for a,b in ab)
print(min(dp[h:])) | 0 | null | 64,280,497,533,490 | 192 | 229 |
t,T,a,A,b,B=map(int, open(0).read().split())
x,y=(a-b)*t,(A-B)*T
if x+y==0:
r="infinity"
else:
s,t=divmod(-x, x+y)
r=0 if s<0 else s*2+(1 if t else 0)
print(r) | # coding: utf-8
from collections import defaultdict
def main():
N = int(input())
dic = defaultdict(int)
max_p = 0
for i in range(N):
dic[input()] += 1
d = dict(dic)
l = []
for key, value in d.items():
l.append([key, value])
if max_p < value: max_p = value
l.sort(key=lambda x: (-x[1], x[0]), reverse=False)
for i, j in l:
if j == max_p:
print(i)
else:
break
if __name__ == "__main__":
main()
| 0 | null | 100,573,918,757,730 | 269 | 218 |
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1: #素数の場合はここ
arr.append([temp, 1])
if arr==[]: #1の場合はここ
arr.append([n, 1])
return arr
def count(X):
cnt = 0
now = 1
while cnt+now <=X:
cnt += now
now += 1
return now-1
#print(count(3))
N = int(input())
if N == 1:
print(0)
exit()
A = factorization(N)
#print(A)
ans = 0
for i in range(len(A)):
ans += count(A[i][1])
print(ans)
| n = int(input())
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
import collections
c = collections.Counter(prime_factorize(n))
ans = 0
for _,value in c.items():
i = 0
while value>i:
i += 1
value -= i
ans += i
print(ans) | 1 | 17,001,834,597,660 | null | 136 | 136 |
def gcd(a, b):
while b:
a, b = b, a%b
return a
x, y = map(int,input().split())
print(gcd(x, y)) | a,b=(input().split())
print(b+a) | 0 | null | 51,807,223,340,212 | 11 | 248 |
n = int(input())
a = list(map(int, input().split()))
l = [0] * n
for i in range(n - 1):
if a[i] > 0:
l[a[i] - 1] += 1
for i in range(n):
print(l[i])
| N = int(input())
result = [0] * (N + 1)
for i in list(map(int, input().split())):
result[i] += 1
result.pop(0)
for r in result:
print(r)
| 1 | 32,523,494,781,510 | null | 169 | 169 |
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
a = [[False] * 3 for _ in range(3)]
for _ in range(N):
b = int(input())
for i in range(3):
for j in range(3):
if A[i][j] == b:
a[i][j] = True
ans = False
for i in range(3):
if a[i][0] and a[i][1] and a[i][2] or a[0][i] and a[1][i] and a[2][i]:
print('Yes')
exit()
if a[0][0] and a[1][1] and a[2][2] or a[2][0] and a[1][1] and a[0][2]:
print('Yes')
exit()
print('No')
| # import sys
# readline = sys.stdin.readline
# generator = (readline().strip() for _ in range(N))
# N, M = map(int, input().split())
# As = list(map(int, input().split()))
# queries = (input() for _ in range(N))
def solve():
h1, m1, h2, m2, k = map(int, input().split())
period = (h2-h1)*60 + (m2-m1)
return period - k
def main():
print(solve())
if __name__ == "__main__":
main()
| 0 | null | 38,923,375,456,154 | 207 | 139 |
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
a = [int(i) for i in input().split()]
a = sorted(list(set(a)))
from fractions import gcd
lc = a[0]
if n != 1:
for num,i in enumerate(a[1:]):
if lc == 0:
break
lc = lc * i // gcd(lc, i)
if gcd(lc, i) == min(i,lc):
for j in a[:num+1]:
if (i/j)%2 == 0:
lc = 0
break
if lc == 0:
print(0)
else:
print((m+lc//2)//lc)
| s = input()
print('Yes' if (s[2] == s[3]) and (s[4] == s[5]) else 'No')
| 0 | null | 71,844,429,236,510 | 247 | 184 |
n, d, a = map(int, input().split())
l = [[0, 0] for _ in range(n)]
for i in range(n):
x, h = map(int, input().split())
l[i][0] = x
l[i][1] = h
l.sort()
from collections import deque
d = 2*d
q = deque([])
total = 0
ans = 0
for i in range(n):
x = l[i][0]
h = l[i][1]
if q:
while q[0][0] < x:
total -= q[0][1]
q.popleft()
if not q:
break
h -= total
if h > 0:
num = (h+a-1)//a
ans += num
damage = num*a
total += damage
q.append([x+d, damage])
print(ans) | dic = {}
l = []
n = int(input())
for i in range(n):
s = input()
#sが新規キーか否かで操作を変える
if s in dic:
dic[s] += 1
#新規ではないならvalueを1増やす
else:
dic[s] = 1
m = max(dic.values())
for i in dic:
if dic[i] == m:
l += [i]
print(*sorted(l)) | 0 | null | 76,005,569,142,750 | 230 | 218 |
def inpl():
return list(map(int, input().split()))
A = [
1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15,
2, 2, 5, 4, 1, 4, 1, 51
]
print(A[int(input()) - 1])
| def agc043_a():
''' 解説放送見てやってみた '''
H, W = map(int, input().split())
grid = []
grid.append(['#'] * (W+2)) # 周辺埋め
for _ in range(H):
grid.append(['#'] + [c for c in str(input())] + ['#'])
grid.append(['#'] * (W+2))
grid[1][0] = grid[H][W+1] = '.' # グリッド外側に白を置く, (1,1)(H,W)が黒の場合に反転カウントするため
# 白黒が反転する回数を数える
cost = [[10**6] * (W+2) for _ in range(H+2)]
cost[1][0] = 0
for i in range(1, H+1):
for j in range(1, W+2):
if i != H and j == W+1: continue # ゴールの外側のときだけ通過
rt = cost[i][j-1]
if grid[i][j-1] != grid[i][j]: rt += 1
dw = cost[i-1][j]
if grid[i-1][j] != grid[i][j]: dw += 1
cost[i][j] = min(rt, dw)
ans = cost[H][W+1] // 2 # 区間の始まりと終わりを両方カウントしているので半分にする
print(ans)
agc043_a() | 0 | null | 49,925,770,145,008 | 195 | 194 |
s = input()*2
print('Yes' if input() in s else 'No') | s = input()
p = input()
if (s*2).count(p) == 0 :
print('No')
else :
print('Yes')
| 1 | 1,722,908,186,780 | null | 64 | 64 |
N = int(input())
P = list(map(int, input().split()))
m = P[0]
S = 0
for p in P:
if m>=p:
S += 1
m = min(m, p)
print(S) | n = int(input())
p = list(map(int, input().split()))
ret = 1
minp = p[0]
for i in range(1, n):
if p[i] <= minp:
ret += 1
minp = min(minp, p[i])
print(ret)
| 1 | 85,606,773,849,572 | null | 233 | 233 |
s = input()
count = 1; memo = 0; x = 0
for i in range(1, len(s)):
if s[i-1] == "<" and s[i] == ">":
x += count*(count-1)//2
memo = count
count = 1
elif s[i-1] == ">" and s[i] == "<":
x += count*(count-1)//2+max(count, memo)
memo = 0
count = 1
else:
count += 1
else:
if s[-1] == "<":
x += count*(count+1)//2
else:
x += count*(count-1)//2+max(count, memo)
print(x) | #入力部
C= 998244353
N,M,K=map(int,input().split())
#定義部
U=max(N+1,K)
F=[0]*U
G=[0]*U
F[0]=1
for i in range(1,U):
F[i]=(F[i-1]*i)%C
G[i]=pow(F[-1],C-2,C)
for j in range(U-2,-1,-1):
G[j]=(G[j+1]*(j+1))%C
def nCr(n,r):
if r<0 or n<r:
return 0
else:
return (F[n]*G[r]*G[n-r])
#メイン部
S=0
for k in range(0,K+1):
S=(S+M*pow(M-1,N-k-1,C)*nCr(N-1,k))%C
print(S%C)
| 0 | null | 89,594,668,140,770 | 285 | 151 |
from collections import deque
h,w = map(int, input().split())
hw = [input() for _ in range(h)]
def bfs(s):
que = deque([s])
m = [[-1]*w for _ in range(h)]
sh, sw = s
m[sh][sw] = 0
ret = 0
while que:
now_h, now_w = que.popleft()
for dh, dw in [(1,0), (-1,0), (0,-1), (0,1)]:
nh = now_h + dh
nw = now_w + dw
if not (0<=nh<h and 0<=nw<w) or m[nh][nw] != -1 or hw[nh][nw] == '#':
continue
m[nh][nw] = m[now_h][now_w] + 1
que.append((nh,nw))
ret = max(ret, m[now_h][now_w] + 1)
return ret
ans = 0
for y in range(h):
for x in range(w):
if hw[y][x] == '#':
continue
s = (y, x)
ans = max(bfs(s), ans)
print(ans) | from sys import stdin
a, b = [int(x) for x in stdin.readline().rstrip().split()]
print(a*b, 2*(a+b))
| 0 | null | 47,228,243,799,122 | 241 | 36 |
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1
N,M=map(int,input().split())
h=list(map(int,input().split()))
edge=[[] for _ in range(N)]
for _ in range(M):
a,b=map(int1,input().split())
edge[a].append(b)
edge[b].append(a)
ans=0
for i in range(N):
for nv in edge[i]:
if h[nv]>=h[i]:
break
else:
ans+=1
print(ans) | def main():
n, m = map(int, input().split())
h_lst = list(map(int, input().split()))
ab_dict = dict() # 展望台i : [展望台iに隣接する展望台の標高]
for _ in range(m):
a, b = map(int, input().split())
if a not in ab_dict:
ab_dict[a] = [h_lst[b - 1]]
else:
ab_dict[a].append(h_lst[b - 1])
if b not in ab_dict:
ab_dict[b] = [h_lst[a - 1]]
else:
ab_dict[b].append(h_lst[a - 1])
cnt = 0
ab_dict_keys = ab_dict.keys()
for i in range(1, n + 1):
if i not in ab_dict_keys:
cnt += 1
continue
if h_lst[i - 1] > max(ab_dict[i]):
cnt += 1
print(cnt)
if __name__ == "__main__":
main()
| 1 | 25,227,085,236,508 | null | 155 | 155 |
import sys,queue,math,copy
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in input().split()]
_LI = lambda : [int(x)-1 for x in input().split()]
N = int(input())
A = LI()
c =[0,0,0]
cnt = [0 for _ in range(N)]
for i in range(N):
cnt[i] = c.count(A[i])
if cnt[i] == 0:
print (0)
exit (0)
for j in range(3):
if c[j] == A[i]:
c[j] += 1
break
ans = 1
for i in range(N):
ans = (ans * cnt[i]) % MOD
print (ans) | M = 1000000007
N = int(input())
A = list(map(int, input().split()))
ans = 1
rgb = [0, 0, 0]
for i in range(N):
c = rgb.count(A[i])
if c == 0:
ans = 0
break
p = rgb.index(A[i])
ans *= c
rgb[p] += 1
print(ans % M) | 1 | 130,366,447,324,770 | null | 268 | 268 |
X = int(input())
Y = X % 500
answer = (X // 500 * 1000 + Y // 5 * 5)
print(answer) | n = int(input())
res = 0
a = n // 500
n %= 500
b = n // 5
print(1000*a + 5*b) | 1 | 42,874,936,859,062 | null | 185 | 185 |
n=int(input())
A=[{} for _ in range(n)]
for i in range(n):
for _ in range(int(input())):
x,y=map(int,input().split())
A[i][x]=y
a=0
for i in range(2**n):
t=0
for j in range(n):
if i>>j&1:
if A[j] and any(i>>~-k&1!=A[j][k] for k in A[j]): break
else: t+=1
else: a=max(a,t)
print(a) | t = input()
if t[2]==t[3]:
if t[4]==t[5]:
print('Yes')
else:
print('No')
else:
print('No') | 0 | null | 82,099,200,689,140 | 262 | 184 |
n=int(input())
a=[1,1]
def fib(n):
if n <= 1:
return a[n]
for i in range(2,n+1):
a.append(a[i-1]+a[i-2])
return a[n]
print(fib(n))
| 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))
| 1 | 1,653,400,498 | null | 7 | 7 |
List=list(input())
if List[2]==List[3] and List[4]==List[5]:
print("Yes")
else:print("No") | def execute(X, K, D):
for i in range(K):
if X > 0:
X -= D
else:
X += D
return abs(X)
def execute2(X, K, D):
T = int(abs(X) / D)
if X > 0:
if K < T:
return X - K * D
else:
Y = X - T * D
if (K - T) % 2 == 0:
return Y
else:
return D - Y
else:
if K < T:
return (X + K * D) * -1
else:
Y = X + T * D
if (K - T) % 2 == 0:
return -1 * Y
else:
return D + Y
if __name__ == '__main__':
X, K, D = map(int, input().split())
print(execute2(X, K, D)) | 0 | null | 23,610,418,543,088 | 184 | 92 |
# 160 A
S = input()
print('Yes') if S[2:3] == S[3:4] and S[4:5] == S[5:6] else print('No') | s=input()
print('YNeos'[s[2]!=s[3] or s[4]!=s[5]::2]) | 1 | 41,992,555,784,650 | null | 184 | 184 |
X = int(input())
q = X // 100
if X%100<=q*5:
print('1')
else:
print('0')
| X = int(input())
dp = [0] * (X + 110)
dp[0] = 1
for i in range(X):
if dp[i]:
for j in range(100, 106):
dp[i + j] = 1
print(dp[X])
| 1 | 127,147,810,057,820 | null | 266 | 266 |
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a%b)
def lcm(a, b):
return a*b/gcd(a, b)
try :
while True :
(a,b) = map(int, raw_input().split())
print gcd(a,b), lcm(a,b)
except EOFError :
pass | import fractions
lst = []
for i in range(200):
try:
lst.append(input())
except EOFError:
break
nums = [list(map(int, elem.split(' '))) for elem in lst]
# gcd
res_gcd = [fractions.gcd(num[0], num[1]) for num in nums]
# lcm
res_lcm = [nums[i][0] * nums[i][1] // res_gcd[i] for i in range(len(nums))]
for (a, b) in zip(res_gcd, res_lcm):
print('{} {}'.format(a, b)) | 1 | 581,877,230 | null | 5 | 5 |
N,M = map(int,input().split())
d,ans,wrong = [0]*N,0,0
for _ in range(M):
p,s = input().split()
p = int(p)-1
if d[p] != -1:
if s == "WA":
d[p] += 1
else:
wrong += d[p]
d[p] = -1
ans += 1
print(ans,wrong) | N, M = map(int, input().split())
countlis = [0] * (N+1)
penalty = 0
clear = 0
checkset = set()
for i in range(1,M+1):
p,s = input().split()
p = int(p)
if p in checkset:
continue
if s == "WA":
countlis[p] += 1
elif s == "AC":
penalty += countlis[p]
clear += 1
checkset.add(p)
print("{0} {1}".format(clear, penalty)) | 1 | 93,141,118,941,860 | null | 240 | 240 |
n,a,b = map(int,input().split())
if a < b:
a,b = b,a
if (a - b) %2 == 0:
print((a-b)//2)
else:
print(min(a-1,n-b)+1+(b-a)//2) | N=int(input())
A = list(map(int, input().split()))
c=0
for i in range(0,len(A),2):
if A[i]%2==1:
c+=1
print(c) | 0 | null | 58,329,040,111,384 | 253 | 105 |
import bisect
from itertools import accumulate
N,M = map(int,input().split())
A = sorted(list(map(int,input().split())))
A2 = [0]+list(accumulate(A))
def judge(mid):
count = 0
for i in range(N):
border = mid - A[i]
ind = bisect.bisect_left(A,border)
count += N-ind
if count < M:
return True
else:
return False
mina = 0
maxa = 2*(10**5) + 1
while maxa-mina > 1:
mid = (maxa+mina)//2
if judge(mid):
maxa = mid
else:
mina = mid
count = 0
ans = 0
for i in range(N):
border = maxa - A[i]
ind = bisect.bisect_left(A,border)
count += N-ind
ans += A[i]*(N-ind) + A2[N]-A2[ind]
if count == M:
print(ans)
else:
rem = M-count
print(ans+rem*mina) | N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
def count_bigger_x(x):
cnt = 0
piv = N-1
for a in A:
while piv >= 0 and a + A[piv] >= x:
piv -= 1
cnt += N - piv - 1
return cnt
def is_ok(x):
cnt = count_bigger_x(x)
return cnt >= M
def bisect(ng, ok):
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
return ok
x = bisect(2 * A[-1] + 1, 2 * A[0] - 1)
ans = 0
piv = N-1
for a in A:
while piv >= 0 and a + A[piv] >= x:
piv -= 1
ans += (N - piv - 1) * a
ans *= 2
ans -= 1 * x * (count_bigger_x(x) - M)
print(ans)
| 1 | 107,699,211,452,850 | null | 252 | 252 |
n = int(input())
m = (n + 1) // 2
print(m) | import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
N = I()
print(int(N/2) if N%2==0 else int(N/2)+1)
main()
| 1 | 59,030,444,220,592 | null | 206 | 206 |
MOD = 10**9 + 7
k = int(input())
s = input()
n = len(s)
MAX = 2 * 10**6 + 5
fact = [1] * (MAX + 1) # i!
finv = [1] * (MAX + 1) # (i!)^{-1}
iinv = [1] * (MAX + 1) # i^{-1}
for i in range(2, MAX + 1):
fact[i] = fact[i - 1] * i % MOD
iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD
finv[i] = finv[i - 1] * iinv[i] % MOD
def comb(n: int, k: int) -> int:
if n < k or n < 0 or k < 0:
return 0
return (fact[n] * finv[k] % MOD) * finv[n - k] % MOD
ans = 0
for i in range(k + 1):
ans += comb(n + k - i - 1, k - i) * pow(25, k - i, MOD) % MOD * pow(
26, i, MOD) % MOD
ans %= MOD
print(ans)
| from collections import deque
n,m = map(int, input().split())
graph = [[] for _ in range(n+1)]
dist = [0] * (n+1)
visited = [0] * (n+1)
for _ in range(m):
a,b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
root = 1
visited[root] = 1
d = deque([root])
while d:
v = d.popleft()
for i in graph[v]:
if visited[i]:
continue
visited[i] = 1
dist[i] = v
d.append(i)
print('Yes')
ans = dist[2:]
print(*ans, sep="\n") | 0 | null | 16,773,983,838,300 | 124 | 145 |
S,T = open(0).read().split()
print(T+S) | s, t = map(str, input().split())
print('{}{}'.format(t, s)) | 1 | 102,567,954,060,508 | null | 248 | 248 |
def solve():
from collections import deque
K = int(input())
q = deque([])
cnt = 1
while cnt <= K:
if cnt < 10:
q.append(cnt)
cnt += 1
else:
base = q.popleft()
last_digit = base % 10
for diff in [-1, 0, 1]:
if cnt > K:
continue
new_last_digit = last_digit + diff
if 0 <= new_last_digit <= 9:
new_lunlun = base*10 + new_last_digit
q.append(new_lunlun)
cnt += 1
print(q[-1])
if __name__ == "__main__":
solve() | # -*- coding: utf-8 -*-
import queue
K = int(input())
q = queue.Queue()
count = 0
for i in range(1, 10):
q.put(i)
a = 0
while count < K:
a = q.get()
fp = int(str(a)[-1])
if fp == 0:
q.put(a*10)
q.put(a*10 + 1)
elif fp == 9:
q.put(a*10 + 8)
q.put(a*10 + 9)
else:
q.put(a*10 + fp - 1)
q.put(a*10 + fp)
q.put(a*10 + fp + 1)
count += 1
print(a) | 1 | 39,924,521,954,020 | null | 181 | 181 |
A,B=map(int, input().split())
if A-B*2<0:
print('0')
else:
print(A-B*2) | a,b = (int(x) for x in input().split())
i = a - b * 2
if i <= 0:
print('0')
else:
print(i)
| 1 | 167,176,487,790,588 | null | 291 | 291 |
x = int(input())
if x >= 30:
ans = 'Yes'
else:
ans = 'No'
print(ans) | from collections import Counter
n=int(input())
A=list(map(int,input().split()))
c=Counter(A)
s=0
for v in c.values():
s+=v*(v-1)//2
for i in range(n):
ans=s-(c[A[i]])+1
print(ans) | 0 | null | 26,838,832,914,114 | 95 | 192 |
n = int(input())
ls = list(map(int,input().split()))
ls.sort(reverse=True)
p = len(ls)
if len(ls)%2 == 1:
p += 1
p //= 2
q = 0
for i in range(1,p+1):
if i == 1:
q += ls[0]
else:
if i == p:
if len(ls)%2 == 1:
q += ls[p-1]
else:
q += 2*ls[p-1]
else:
q += 2*ls[i-1]
print(q) | import sys
input = sys.stdin.readline
def main():
N = int(input())
R = [[] for i in range(N)]
for i in range(N):
A = int(input())
R[i] = [list(map(int, input().split())) for i in range(A)]
ans = 0
for i in range(1<<N):
CNT = 0
for j in range(N):
if not (i>>j & 1):
continue
CNT += 1
for x, y in R[j]:
if y == 1 and (i>>(x-1) & 1):
continue
elif y == 0 and (not (i>>(x-1) & 1)):
continue
else:
CNT = 0
break
else:
continue
break
ans = max(ans, CNT)
print(ans)
if __name__ == '__main__':
main() | 0 | null | 65,478,785,504,572 | 111 | 262 |
n,q = map(int,input().split())
A = [list(map(str,input().split())) for i in range(n)]
time = 0
flag = 1
while len(A) > 0:
if int(A[0][1]) <= q: #プロセスが完了する場合
time += int(A[0][1])
print(A[0][0],time)
del A[0]
else: #プロセスが完了しない場合
time += q
A[0][1] = str(int(A[0][1])-q)
A.append(A[0])
del A[0]
| x, n = map(int, input().split())
p = list(map(int, input().split()))
if x not in p:
print(x)
else:
a, b = 1, 1
while True:
if (x + a) not in p:
break
else:
a += 1
while True:
if (x - b) not in p:
break
else:
b += 1
if a >= b:
print(x - b)
else:
print(x + a) | 0 | null | 7,110,183,760,862 | 19 | 128 |
N,A,B = map(int,input().split())
if A%2 != 0 and B%2 == 0:
ans = (B-A-1)//2 + min(A-1,N-B) + 1
elif A%2 == 0 and B%2 != 0:
ans = (B-A-1)//2 + min(A-1,N-B) + 1
else:
ans = (B-A)//2
print(ans) | N,A,B = map(int,input().split())
if (B-A)%2 == 0:
ans = [N-A,(B-A)//2,B-1]
print(min(ans))
else:
ans = [N-A,B-1,((B-A-1)//2)+(N-B+1),((B-A-1)//2)+A]
print(min(ans)) | 1 | 109,622,839,924,884 | null | 253 | 253 |
# coding: utf-8
import math
n = int(raw_input())
def vector_rot(vector, radian):
new_x = vector[0] * math.cos(radian) - vector[1] * math.sin(radian)
new_y = vector[0] * math.sin(radian) + vector[1] * math.cos(radian)
return [new_x, new_y]
def vector_add(v1, v2):
new_v = []
for i in range(2):
add = v1[i] + v2[i]
new_v.append(add)
return new_v
def makepoint(p_A1, p_A2):
x_p_C1 = (p_A2[0] - p_A1[0]) / 3 + p_A1[0]
y_p_C1 = (p_A2[1] - p_A1[1]) / 3 + p_A1[1]
x_p_C3 = (p_A2[0] - p_A1[0]) * 2 / 3 + p_A1[0]
y_p_C3 = (p_A2[1] - p_A1[1]) * 2 / 3 + p_A1[1]
p_C1 = [x_p_C1, y_p_C1]
p_C3 = [x_p_C3, y_p_C3]
v01 = [x_p_C1 - p_A1[0], y_p_C1 - p_A1[1]]
rot_v01 = vector_rot(v01, 60 * math.pi / 180)
v02 = vector_add(v01, rot_v01)
p_C2 = vector_add(p_A1, v02)
C = [p_C1, p_C2, p_C3]
return C
A = [[0., 0.],[100., 0.]]
for i in range(n):
B = []
for j in range(len(A)-1): #A[j]??¨A[j+1]
C = makepoint(A[j], A[j+1]) #C = [p_C1, p_C2, p_C3]
B.append(A[j])
for p in C:
B.append(p)
#A[j+1]????¬????makepoint?????????append??????
B.append(A[-1]) #??????????????\?????\??????
A = B
for x in A:
print("{:.8f}".format(x[0])),
print("{:.8f}".format(x[1])) | t1, t2 = [ int(v) for v in input().split() ]
a1, a2 = [ int(v) for v in input().split() ]
b1, b2 = [ int(v) for v in input().split() ]
if a1*t1 + a2*t2 == b1*t1 + b2*t2:
ans = -1
else:
if a1*t1 + a2*t2 < b1*t1 + b2*t2:
a1, b1 = b1, a1
a2, b2 = b2, a2
mind = a1*t1 - b1*t1
if mind > 0:
ans = 0
else:
lastd = a1*t1 + a2*t2 - b1*t1 - b2*t2
mind = abs(mind)
if mind % lastd == 0:
ans = 2 * (mind // lastd)
else:
ans = 2 * (mind // lastd) + 1
print(ans if ans != -1 else "infinity") | 0 | null | 65,715,419,446,372 | 27 | 269 |
def insertion_sort(A,n,g):
cnt = 0
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 = j - g
cnt += 1
A[j + g] = v
return cnt
def shell_sort(A,n):
cnt = 0
G = []
val = 1
while True:
G.append(val)
val = (3 * val) + 1
if val > (n // 3) + 1:
break
G.reverse()
m = len(G)
for g in G:
cnt += insertion_sort(A,n,g)
#output
print(m)
print(*G)
print(cnt)
for a in A:
print(a)
n = int(input())
#print(f"#dbg n:{n}")
A = []
for i in range(n):
A.append(int(input()))
#print("#dbg A:",*A)
shell_sort(A,n)
| def insertionSort(table, g):
global cnt
for i in range(g, len(table)):
v = table[i]
j = i - g
while j >= 0 and table[j] > v:
table[j + g] = table[j]
j = j - g
cnt += 1
table[j + g] = v
def shellSort(table):
gap = [1]
while gap[0] * 3 + 1 < len(table):
gap.insert(0, (gap[0] * 3 + 1))
for g in gap:
insertionSort(table, g)
return gap
n = int(input())
table = []
cnt =0
for i in range(n):
table.append(int(input()))
gap = shellSort(table)
print(len(gap))
print(' '.join(map(str, gap)))
print(cnt)
print('\n'.join(map(str, table)))
| 1 | 28,064,932,128 | null | 17 | 17 |
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n,k = inpl()
res = 0
cnt = [0] * (k+5)
for i in reversed(range(1,k+1)):
tmp = pow(k//i,n,mod)
cnt[i] = tmp
now = i
while True:
now += i
if now > k:
break
cnt[i] -= cnt[now]
res += cnt[i] * i
res %= mod
print(res) | N, K = map(int, input().split())
mod = 10 ** 9 + 7
cnt = [0] * (K + 1)
answer = 0
for i in range(K, 0, -1):
tmp = pow(K // i, N, mod) - sum(cnt[::i])
cnt[i] = tmp
answer = (answer + tmp * i) % mod
print(answer)
| 1 | 36,663,808,251,530 | null | 176 | 176 |
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import deque
n,u,v=nii()
u-=1
v-=1
tree=[[] for i in range(n)]
for i in range(n-1):
a,b=nii()
a-=1
b-=1
tree[a].append(b)
tree[b].append(a)
def BFS(s):
dist=[-1 for i in range(n)]
dist[s]=0
que=deque()
que.append(s)
while que:
x=que.popleft()
for i in tree[x]:
if dist[i]==-1:
que.append(i)
dist[i]=dist[x]+1
return dist
dist_t=BFS(u)
dist_a=BFS(v)
ans=0
for i in range(n):
if dist_a[i]>dist_t[i]:
ans=max(ans,dist_a[i]-1)
print(ans) | n,k = (int(x) for x in input().split())
h = [int(x) for x in input().split()]
count = 0
for i in range(len(h)):
if k <= h[i]:
count += 1
print(count) | 0 | null | 147,719,237,249,472 | 259 | 298 |
a = int(input())
b = int(input())
if a == 1:
if b == 2:
print(3)
else:
print(2)
elif a == 2:
if b == 1:
print(3)
else:
print(1)
else:
if b == 2:
print(1)
else:
print(2) | m1, _ = [int(i) for i in input().split()]
m2, _ = [int(i) for i in input().split()]
if m1 == m2:
print(0)
else:
print(1) | 0 | null | 117,620,944,011,780 | 254 | 264 |
l = int(input())
print((l/3)**3) | # L = x + y + z
# S = x*y*z
#これをSが最大となるようにyとLの式で表すと
# S_max = 1/2 * (L - y) * y * 1/2 * (L - y) = 1/4 * (y**3 - 2*L*y**2 +L**2 * y)
L = int(input())
S_list = []
for y in range(L*10**3):
y_cal = y / 10**3
s = 1/4 * (y_cal**3 - 2*L*y_cal**2 +L**2 * y_cal)
S_list.append(s)
S_max = max(S_list)
print(S_max) | 1 | 47,230,440,606,880 | null | 191 | 191 |
# coding: utf-8
# ????´¢????±? W
target_word = input()
# ??????
words = []
while (1):
input_text = input().strip()
if (input_text == 'END_OF_TEXT'):
break
words.extend(input_text.split())
counter = 0
for w in words:
if (w.lower() == target_word.lower()):
counter += 1
print(counter) | m, d = map(int,input().split())
n, e = map(int,input().split())
print(int(e == 1)) | 0 | null | 63,362,286,191,220 | 65 | 264 |
import time as ti
class MyQueue(object):
"""
My Queue class
Attributes:
queue: queue
head
tail
"""
def __init__(self):
"""Constructor
"""
self.length = 50010
self.queue = [0] * self.length
# counter = 0
# while counter < self.length:
# self.queue.append(Process())
# counter += 1
self.head = 0
self.tail = 0
# def enqueue(self, name, time):
def enqueue(self, process):
"""enqueue method
Args:
name: enqueued process name
time: enqueued process time
Returns:
None
"""
self.queue[self.tail] = process
# self.queue[self.tail].name = name
# self.queue[self.tail].time = time
self.tail = (self.tail + 1) % self.length
def dequeue(self):
"""dequeue method
Returns:
None
"""
# self.queue[self.head].name = ""
# self.queue[self.head].time = 0
self.queue[self.head] = 0
self.head = (self.head + 1) % self.length
def is_empty(self):
"""check queue is empty or not
Returns:
Bool
"""
if self.head == self.tail:
return True
else:
return False
def is_full(self):
"""chech whether queue is full or not"""
if self.tail - self.head >= len(self.queue):
return True
else:
return False
class Process(object):
"""process class
"""
def __init__(self, name="", time=0):
"""constructor
Args:
name: name
time: time
"""
self.name = name
self.time = time
def forward_time(self, time):
"""time forward method
Args:
time: forward time interval
Returns:
remain time
"""
self.time -= time
return self.time
def time_forward(my_queue, interval, current_time,):
"""
Args:
my_queue: queue
interval: time step interval
current_time: current time
"""
value = my_queue.queue[my_queue.head].forward_time(interval)
if value <= 0:
current_time += (interval + value)
print my_queue.queue[my_queue.head].name, current_time
my_queue.dequeue()
elif value > 0:
current_time += interval
# name, time = my_queue.queue[my_queue.head].name, \
# my_queue.queue[my_queue.head].time
my_queue.enqueue(my_queue.queue[my_queue.head])
my_queue.dequeue()
return current_time
my_queue = MyQueue()
n, q = [int(x) for x in raw_input().split()]
counter = 0
while counter < n:
name, time = raw_input().split()
my_queue.enqueue(Process(name, int(time)))
counter += 1
# end_time_list = []
current_time = 0
while not my_queue.is_empty():
current_time = time_forward(my_queue, q, current_time) | class Queue:
def __init__(self):
self.data = []
def enqueue(self, data):
self.data.append(data)
def dequeue(self):
res = self.data.pop(0)
return res
def getLength(self):
return len(self.data)
n, q = map(int, input().split())
time = 0
processes = Queue()
for i in range(n):
name, cost = input().split()
processes.enqueue([name, int(cost)])
while processes.getLength() > 0:
currentProcess = processes.dequeue()
processName = currentProcess[0]
processCost = currentProcess[1]
if processCost <= q:
time += processCost
print(' '.join([processName, str(time)]))
continue
time += q
processes.enqueue([processName, processCost - q]) | 1 | 44,642,950,908 | null | 19 | 19 |
from sys import stdin, setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)
INF = int(1e10)
MOD = int(1e9 + 7)
def main():
from builtins import int, map
N, K, S = map(int, input().split())
# al + ... ar = SがちょうどK個
# S S S S S 1 1 1 1 1 1みたいな感じでいい?
if S == 10 ** 9:
ans = [S] * K + [1] * (N - K)
else:
ans = [S] * K + [S + 1] * (N - K)
print(*ans)
if __name__ == '__main__':
main()
| # input
N, K, C = map(int, input().split())
S = input()
# process
l = [i+1 for i in range(N) if S[i] == 'o']
left = [l[0]]
right = [l[-1]]
for i in range(1, len(l)):
if l[i] > left[-1]+C:
left.append(l[i])
if l[-i-1] < right[-1]-C:
right.append(l[-i-1])
# output
# print(l)
# print(left)
# print(right)
if len(left) == K:
for i in range(len(left)):
if left[i] == right[-i-1]:
print(left[i])
| 0 | null | 65,865,741,368,772 | 238 | 182 |
N, M = map(int, input().split())
progress = {}
# initialize
for i in range(N):
progress[str(i+1)] = ["notCorrect",0]
correct = 0
for i in range(M):
question, result = map(str, input().split())
if (progress[question][0] == "notCorrect"):
if (result == "WA"):
progress[question][1] += 1
else:
progress[question][0] = "correct"
correct += 1
else:
continue
penalty = 0
for i in range(N):
if (progress[str(i+1)][0] == "correct"):
penalty += progress[str(i+1)][1]
print(str(correct)+" "+str(penalty)) | import itertools
n = int(input())
answers = []
for i in range(n):
a = int(input())
answers.append((i, []))
for j in range(a):
(x, y) = [int(k) for k in input().split()]
answers[i][1].append((x, y))
lst = []
combi_lst = [i for i in range(n)]
for i in range(n, -1, -1):
for balls in itertools.combinations(combi_lst, i):
lst = [True if j in balls else False for j in range(n)]
success = True
for i, ans in enumerate(answers):
if lst[i] == False:
continue
for x, y in ans[1]:
if y == 1 and lst[x - 1] == False:
success = False
if y == 0 and lst[x - 1] == True:
success = False
if success:
print(sum(lst))
exit() | 0 | null | 107,838,116,500,370 | 240 | 262 |
import time
MOD = 10 ** 9 + 7
K = int(input())
S = input()
l = len(S)
fac = [1] * (K + l + 1)
invfac = [1] * (K + l + 1)
for i in range(1, K + l + 1):
fac[i] = (fac[i - 1] * i) % MOD
invfac[i] = pow(fac[i], MOD - 2, MOD)
p25 = [1] * (K + 1)
p26 = [1] * (K + 1)
for i in range(1, K + 1):
p25[i] = (p25[i - 1] * 25) % MOD
p26[i] = (p26[i - 1] * 26) % MOD
ans = 0
for en in range(l - 1, l + K):
t = (fac[en] * invfac[en - l + 1]) % MOD
t = (t * invfac[l - 1]) % MOD
t = (t * p25[en - l + 1]) % MOD
t = (t * p26[l + K - 1 - en]) % MOD
ans = (ans + t) % MOD
print(ans) | def main():
mod = pow(10, 9)+7
k = int(input())
s = input()
n = len(s)
ans = 0
key = pow(26, k, mod)
sub = 1
c = 1
for i in range(k+1):
ans += key*sub*c
ans %= mod
sub *= 25
sub %= mod
key = key*pow(26, mod-2, mod)%mod
c *= (n+i)
c *= pow(i+1, mod-2, mod)
c %= mod
print(ans)
if __name__ == "__main__":
main()
| 1 | 12,804,533,225,148 | null | 124 | 124 |
while True:
a,op,b=raw_input().split()
if op == "?":break
if op == "+":print int(a) + int(b)
if op == "-":print int(a) - int(b)
if op == "*":print int(a) * int(b)
if op == "/":print int(a) / int(b) | while True:
( a, op, b) = input().split()
a = int(a)
b = int(b)
if op == '?':
break
elif op == '+':
print( '{0}'.format( a + b))
elif op == '-':
print( '{0}'.format( a - b))
elif op == '*':
print( '{0}'.format( a * b))
elif op == '/':
print( '{0}'.format( a // b)) | 1 | 681,525,271,352 | null | 47 | 47 |
N,A,B = map(int,input().split())
if (B-A) % 2 == 0:
print((B-A)//2)
elif A-1 <= N-B:
print((A+B-1)//2)
else:
print(N+1-(B+A+1)//2) | # D - Teleporter
N,K = map(int,input().split())
A = [0]+list(map(int,input().split()))
s = {1:0}
l = [1]
i = 1
for j in range(1,10**10):
i = A[i]
if i in s:
sigma = j-s[i]
break
s[i] = j
l.append(i)
if K<s[i]:
print(l[K])
else:
K -= s[i]
mod = l[s[i]:]
print(mod[K%sigma]) | 0 | null | 66,067,378,870,206 | 253 | 150 |
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) | import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()
com_mx=200005
mod=998244353
fac=[0]*com_mx
finv=[0]*com_mx
inv=[0]*com_mx
fac[0]=1
fac[1]=1
finv[0]=1
finv[1]=1
inv[1]=1
for i in range(2,com_mx):
fac[i]=fac[i-1]*i%mod
inv[i]=-inv[mod%i]*(mod//i)%mod
finv[i]=finv[i-1]*inv[i]%mod
def com(n,k):
if n<k or n<0 or k<0:
return 0
return fac[n]*(finv[k]*finv[n-k]%mod)%mod
def main():
n,m,k=LI()
res=0
tmp=m*pow(m-1,n-k-1,mod)
for r in range(n-k-1,n):
res=(res+tmp*com(n-1,r)%mod)%mod
tmp=tmp*(m-1)%mod
return res
# main()
print(main())
| 1 | 23,217,290,096,910 | null | 151 | 151 |
a = []
for i in range(3):
l,m,n = map(int,input().split())
a.append([l,m,n])
n = int(input())
b = []
for i in range(n):
b.append(int(input()))
#print(a)
#print(b)
for i in range(3):
for j in range(3):
for k in range(n):
if a[i][j] == b[k]:
a[i][j] = 0
tmp = 0
for i in range(3):
if a[i][0]+a[i][1]+a[i][2] == 0:
tmp = 1
elif a[0][i]+a[1][i]+a[2][i] == 0:
tmp = 1
if a[0][0]+a[1][1]+a[2][2] ==0:
tmp = 1
elif a[0][2]+a[1][1]+a[2][0] ==0:
tmp = 1
if tmp == 1:
print('Yes')
else:
print('No')
| import sys
l = sys.stdin.readlines()
for i in l:
if "?" in i:
break
else:
str = i.replace('/','//')
print(eval(str)) | 0 | null | 30,464,419,397,058 | 207 | 47 |
n = list(input())
print("Yes") if any([i == "7" for i in n]) else print("No")
| import math
N, D = [int(x) for x in input().split()]
Z = []
for i in range(N):
Z.append([int(x) for x in input().split()])
ans = 0
for i in range(N):
if math.sqrt(Z[i][0]**2 + Z[i][1]**2) <= D:
ans += 1
print(ans)
| 0 | null | 20,137,521,260,160 | 172 | 96 |
n = int(input())
l = list(map(int, input().split()))
ans = 0
for i in range(n):
for ii in range(i+1, n):
ans += l[i]*l[ii]
print(ans) | n = int(input())
oi = list(map(int,input().split()))
total = 0
for i in range(n-1):
for j in range(i+1,n):
total += oi[i]*oi[j]
print(total) | 1 | 168,494,043,601,088 | null | 292 | 292 |
import sys
import math
t1, t2 = [int(i) for i in sys.stdin.readline().split()]
a1, a2 = [int(i) for i in sys.stdin.readline().split()]
b1, b2 = [int(i) for i in sys.stdin.readline().split()]
a1 -= b1
a2 -= b2
_sum = a1 * t1 + a2 * t2
if _sum == 0:
print("infinity")
elif _sum * a1 > 0:
print("0")
else:
cnt = (-a1 * t1) / _sum
res = math.ceil(cnt) * 2 - 1 + (cnt % 1 == 0)
print(res) | t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
if a1>b1 and a2>b2:
print(0)
elif b1>a1 and b2>a2:
print(0)
elif a1*t1+a2*t2==b1*t1+b2*t2:
print("infinity")
else:
ans=-1
num2=-1
num3=-1
if a1*t1+a2*t2>b1*t1+b2*t2:
if a1>b1:
ans=0
else:
num2=(b1-a1)*t1
num3=((a1-b1)*t1)+((a2-b2)*t2)
if num2//num3==num2/num3:
ans=(num2//num3)*2
else:
ans=(num2//num3)*2+1
else:
if b1>a1:
ans=0
else:
num2=(a1-b1)*t1
num3=((b1-a1)*t1)+((b2-a2)*t2)
if num2//num3==num2/num3:
ans=(num2//num3)*2
else:
ans=(num2//num3)*2+1
print(ans)
| 1 | 130,945,509,467,698 | null | 269 | 269 |
# -*- coding: utf-8 -*-
def maximum_profit(profits):
max_v = profits[1] - profits[0]
min_v = profits[0]
for j in range(1, len(profits)):
max_v = max(max_v, profits[j]-min_v)
min_v = min(min_v, profits[j])
print(max_v)
def to_int(v):
return int(v)
if __name__ == '__main__':
l = to_int(input())
profits = [to_int(input()) for i in range(l)]
maximum_profit(profits) | def insertionSort(A, n, g):
cnt_local = 0
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 = j - g
cnt_local += 1
A[j+g] = v
return cnt_local
cnt_all = 0
n = int(input())
A = []
for _ in range(n):
A.append(int(input()))
G = [int((3**i-1)/2)for i in range(17,0,-1)]
G = [v for v in G if v <= n]
m = len(G)
for i in range(m):
cnt_all += insertionSort(A, n, G[i])
print(m)
print(*G)
print(cnt_all)
print(*A, sep='\n')
| 0 | null | 21,787,843,298 | 13 | 17 |
# -*- coding: utf-8 -*-
import sys
import os
import math
x1, y1, x2, y2 = list(map(float, input().split()))
x_diff = x1 - x2
y_diff = y1 - y2
d = math.sqrt(x_diff ** 2 + y_diff ** 2)
print(d) | N = int(input())
a = input().split(" ")
print(" ".join(reversed(a))) | 0 | null | 564,117,386,976 | 29 | 53 |
N,M = map(int, input().split())
A = list(map(int, input().split()))
total = sum(A)
A.sort(reverse=True)
if A[M-1] >= total / (4*M):
print('Yes')
else:
print('No') | n,m=map(int,input().split())
a=list(map(int,input().split()))
s = sum(a)
ans =0
for i in a:
if i>=s/4/m:
ans+=1
if ans>=m:
print('Yes')
else:
print('No')
| 1 | 38,789,603,740,030 | null | 179 | 179 |
#41
import math
N = int(input())
p = list(map(int,input().split()))
cou = 0
x = math.inf
for j in range(N):
if min(x,p[j]) == p[j]:
x = p[j]
cou += 1
print(cou)
| from collections import deque
N = int(input())
c = [chr(ord("a") + i) for i in range(26)]
q = deque("a")
ans = []
while q:
s = q.pop()
if len(s) == N:
ans.append(s)
continue
for x in c[:c.index(max(s)) + 2]:
q.append(s + x)
[print(a) for a in sorted(ans)] | 0 | null | 68,579,397,449,242 | 233 | 198 |
# -*- coding: utf-8 -*-
str = raw_input()
for _ in xrange(input()):
ops = raw_input().split()
a = int(ops[1])
b = int(ops[2]) + 1
op = ops[0]
if op[0]=="p": print str[a:b]
elif op[2]=="v": str = str[:a] + str[a:b][::-1] + str[b:]
else: str = str[:a] + ops[3] + str[b:] | string = input()
n = int(input())
for _ in range(n):
query = input().split()
if query[0] == 'replace':
op, a, b, p = query
a, b = int(a), int(b)
string = string[:a] + p + string[b + 1:]
elif query[0] == 'reverse':
op, a, b = query
a, b = int(a), int(b)
string = string[:a] + ''.join(reversed(string[a:b + 1])) + string[b + 1:]
elif query[0] == 'print':
op, a, b = query
a, b = int(a), int(b)
print(string[a: b + 1]) | 1 | 2,107,160,693,092 | null | 68 | 68 |
DP = [False]*100001
DP[0] = True
for TN in range(0,100001):
if TN>=100 and DP[TN-100]:
DP[TN] = True
continue
if TN>=101 and DP[TN-101]:
DP[TN] = True
continue
if TN>=102 and DP[TN-102]:
DP[TN] = True
continue
if TN>=103 and DP[TN-103]:
DP[TN] = True
continue
if TN>=104 and DP[TN-104]:
DP[TN] = True
continue
if TN>=105 and DP[TN-105]:
DP[TN] = True
continue
print([0,1][DP[int(input())]]) | X = int(input())
N = X // 100
for n in range(N + 1):
M = X - n * 100
if M > n * 5:
continue
else:
print(1)
break
else:
print(0) | 1 | 126,966,123,537,568 | null | 266 | 266 |
x = int(input())
import math
def check(n):
if n == 1: return False
for i in range(2, int(math.sqrt(n)) + 1):
if n % i == 0:
return False
return True
n = x
while check(n) == False:
n += 1
print(n)
| #submit 16999743
a, b = input().split()
a = int(a)
b1, b2 = b.split('.')
ans = a * (int(b1) * 100 + int(b2)) // 100
print(ans)
| 0 | null | 60,903,192,768,458 | 250 | 135 |
from collections import deque
H,W=map(int,input().split())
S=[input() for _ in range(H)]
ans=0
d=deque([])
for i in range(H):
for j in range(W):
if S[i][j]=='#':
continue
d.append((i,j,0))
visited=[[-1]*W for _ in range(H)]
visited[i][j]=0
while d:
x,y,c=d.popleft()
for dx,dy in [(0,1),(1,0),(0,-1),(-1,0)]:
nx,ny=x+dx,y+dy
if 0<=nx<H and 0<=ny<W and visited[nx][ny]==-1 and S[nx][ny]=='.':
visited[nx][ny]=c+1
d.append((nx,ny,c+1))
ans=max(ans,c)
print(ans) | from collections import deque
import copy
H,W=map(int,input().split())
S=[list(input()) for _ in range(H)]
S1=copy.deepcopy(S)
ans=[]
sy=0
sx=0
for i in range(H):
for j in range(W):
c=0
route=deque([(i,j,0)])
S=copy.deepcopy(S1)
while route:
a,b,n=route.popleft()
c=n
if 0<=a<=H-1 and 0<=b<=W-1:
if S[a][b]=='.':
S[a][b]='#'
route.append((a+1,b,n+1))
route.append((a-1,b,n+1))
route.append((a,b+1,n+1))
route.append((a,b-1,n+1))
ans.append(c-1)
print(max(ans))
| 1 | 94,887,909,054,122 | null | 241 | 241 |
a, b, c = map(int, input().split())
if c-a-b <= 0:
print("No")
else: print("Yes") if (c-a-b)*(c-a-b) > 4*a*b else print("No") | a,b,c=map(int,input().split())
print('Yes' if c>a+b and 4*a*b<(c-a-b)**2 else 'No') | 1 | 51,588,367,106,302 | null | 197 | 197 |
import sys
#DEBUG=True
DEBUG=False
if DEBUG:
f=open("202007_2nd/B_input.txt")
else:
f=sys.stdin
N=int(f.readline().strip())
A=list(map(int,f.readline().split()))
ans=0
for _ in range(N):
ans=ans+1 if (_+1)%2 and (A[_]%2) else ans
print(ans)
f.close() | N = int(input())
ans = 0
A = list(map(int, input().split()))
for a in A[::2]:
if a%2 != 0:
ans += 1
print(ans) | 1 | 7,865,433,144,708 | null | 105 | 105 |
a,b = map(int,input().split())
d,r = divmod(a,b)
print("{} {} {:.6f}".format(d,r,a/b)) | import sys
a, b = [ int( val ) for val in sys.stdin.readline().split( ' ' ) ]
print( "{:d} {:d} {:7f}".format( a//b, a%b, a/b ) ) | 1 | 606,876,910,588 | null | 45 | 45 |
from sys import exit
X = int(input())
x = 100
i = 0
while True:
i += 1
x *= 101
x = x // 100
if X <= x:
print(i)
exit()
| X = int(input())
a = 100
year = 0
import math
while True:
a = a*101//100
year += 1
if a >= X:
break
print(year) | 1 | 26,930,355,535,052 | null | 159 | 159 |
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
m = reduce(lambda a, b: a^b, A)
l = list(map(str, [a ^ m for a in A]))
ans = ' '.join(l)
print(ans) | N=int(input())
A=list(map(int,input().split()))
mlt=0
for a in A:
mlt^=a
for i in range(N):
print(mlt^A[i],end=" ") | 1 | 12,534,553,671,932 | null | 123 | 123 |
def hash1(m, key):
return key % m
def hash2(m, key):
return 1 + key % (m - 1)
def hash(m, key, i):
return (hash1(m, key) + i * hash2(m, key) ) % m
def insert(T, key):
i = 0
l = len(T)
while True:
h = hash(1046527,key,i)
if (T[h] == None ):
T[h] = key
return h
elif (T[h] == key):
return h
else:
i += 1
def search(T,key):
l = len(T)
i = 0
while True:
h = hash(1046527,key,i)
if(T[h] == key):
return h
elif(T[h] is None or h >= l):
return -1
else:
i += 1
def find(T, key):
a = search(T,key)
if(a == -1):
print('no')
else:
print('yes')
dict = {'A' : '1', 'C' : '2', 'G' : '3', 'T' : '4'}
data = []
T = [None]*1046527
n = int(input())
while n > 0:
st = input()
d = list(st.split())
### convert key to num(1~4)
tmp_key = ''
for x in list(d[1]):
tmp_key += dict[x]
data.append([d[0],int(tmp_key)])
n -= 1
for com in data:
if(com[0] == 'insert'):
insert(T,com[1])
else:
find(T,com[1]) | import itertools
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
cnt = 0
p_cnt = 0
q_cnt = 0
n_list = [i for i in range(1, n+1)]
for P in itertools.permutations(n_list):
cnt += 1
if p == list(P):
p_cnt = cnt
if q == list(P):
q_cnt = cnt
if p_cnt and q_cnt:
print(abs(q_cnt-p_cnt))
exit() | 0 | null | 50,302,794,176,920 | 23 | 246 |
def resolve():
def dfs(v):
dist = [-1] * N
stack = [v]
dist[v] = 0
while stack:
v = stack.pop()
for to in G[v]:
if dist[to] != -1:
continue
dist[to] = dist[v] + 1
stack.append(to)
return dist
N, taka, aoki = map(int, input().split())
taka -= 1
aoki -= 1
G = [[] for _ in range(N)]
for i in range(N - 1):
a, b = map(lambda x: int(x) - 1, input().split())
G[a].append(b)
G[b].append(a)
dist_Tk = dfs(taka)
dist_Ao = dfs(aoki)
ans = 0
for i in range(N):
if dist_Tk[i] < dist_Ao[i]:
ans = max(ans, dist_Ao[i] - 1)
print(ans)
if __name__ == "__main__":
resolve() | def main():
N = int(input())
A = list(map(int,input().split()))
list_a = [0]*N
for i in range(len(A)):
list_a[A[i]-1] += 1
for i in range(N):
print(list_a[i])
main()
| 0 | null | 75,343,215,706,308 | 259 | 169 |
x=input().split()
n=int(x[0])
k=int(x[1])
def fact_inverse(n,p):
fact=[1]*(n+1)
inv=[1]*(n+1)
inv_fact=[1]*(n+1)
inv[0]=0
inv_fact[0]=0
for i in range(2,n+1):
fact[i]=(fact[i-1]*i)%p
#compute the inverse of i mod p
inv[i]=(-inv[p%i]*(p//i))%p
inv_fact[i]=(inv_fact[i-1]*inv[i])%p
return fact,inv_fact
def combi2(n,p):
f,inv=fact_inverse(n,p)
combis=[1]*(n+1)
for k in range(1,n+1):
if k >=n//2+1:
combis[k]=combis[n-k]
else:
combis[k]=(((f[n]*inv[n-k])%p)*inv[k])%p
return combis
p=10**9+7
combis1=combi2(n,p)
combis2=combi2(n-1,p)
s=0
L=min(n,k+1)
for i in range(L):
s=(s+(combis1[i]*combis2[i])%p)%p
print(s)
| n,k = map(int,input().split())
MOD = 10**9+7
FAC = [1]
INV = [1]
for i in range(1,2*n+1):
FAC.append((FAC[i-1]*i) % MOD)
INV.append(pow(FAC[-1],MOD-2,MOD))
def nCr(n,r):
return FAC[n]*INV[n-r]*INV[r]
ans = 0
for i in range(min(n-1,k)+1):
ans += nCr(n,i)*nCr(n-1,n-i-1)
ans %= MOD
print(ans)
| 1 | 67,003,016,505,380 | null | 215 | 215 |
from collections import deque
N, M, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
da = deque()
i = 0
tmpK = 0
while tmpK <= K and i < N:
tmpK += A[i]
da.append(A[i])
i += 1
# 一冊多い場合がある
if (tmpK > K):
i -= 1
tmpK -= da.pop()
# Bを増やしていく
db = deque()
j = 0
while tmpK <= K and j < M:
tmpK += B[j]
db.append(B[j])
j += 1
# 一冊多い場合がある
if (tmpK > K):
j -= 1
tmpK -= db.pop()
tmptot = i+j
while len(da) > 0:
tmpK -= da.pop()
i -= 1
while tmpK <= K and j < M:
tmpK += B[j]
db.append(B[j])
j += 1
# 一冊多い場合がある
if (tmpK > K):
j -= 1
tmpK -= db.pop()
if tmptot < i+j:
tmptot = i+j
print(tmptot) | import sys
i = 1
while(True):
x = int(sys.stdin.readline())
if(x == 0):
break
print("Case %d: %d" % (i, x))
i += 1 | 0 | null | 5,678,987,799,614 | 117 | 42 |
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7
N = int(readline())
a = list(map(int,readline().split()))
s = 0
for ai in a:
s = s^ai
ans = []
for ai in a:
ans.append(s^ai)
print(' '.join(map(str,ans)))
| from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right
import sys,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n = inp()
a = inpl()
now = a[0]
for i in range(1,n):
now ^= a[i]
for i in range(n):
print(now ^ a[i]) | 1 | 12,524,149,555,200 | null | 123 | 123 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.