code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 2
178,025B
⌀ | question_pair_id
float64 27.1M
177,113B
⌀ | code1_group
int64 1
297
| code2_group
int64 1
297
|
---|---|---|---|---|---|---|
import numpy as np
raw = input()
rawl = raw.split()
A = int(rawl[0])
B = int(rawl[1])
H = int(rawl[2])
M = int(rawl[3])
theta = 2*np.pi*(H/12+M/720-M/60)
print((A*A+B*B-2*A*B*np.cos(theta))**(0.5))
|
A, B, H, M = map(int, input().split())
import math
theta = (30 * H) - (5.5 * M)
d2 = A * A + B * B - 2 * A * B * math.cos(math.radians(theta))
d = math.sqrt(d2)
print(d)
| 1 | 19,947,558,499,058 | null | 144 | 144 |
def factorization(n):
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
cnt = 0
while n % i == 0:
cnt += 1
n //= i
e[i] = max(e[i], cnt)
if n != 1:
e[n] = max(e[n], 1)
def mod_pow(a, n):
res = 1
while n > 0:
if n & 1:
res = res * a % mod
a = a * a % mod
n >>= 1
return res
n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
e = [0] * 10 ** 6
for v in a:
factorization(v)
lcm = 1
for i, c in enumerate(e):
if c > 0:
lcm = lcm * mod_pow(i, c) % mod
res = 0
for v in a:
res = (res + lcm * mod_pow(v, mod - 2)) % mod
print(res)
|
import math
S = int(input())
mod = 10**9 + 7
dp = [0] * (S + 1)
dp[0] = 1
for i in range(1,S+1):
if i < 3:continue
for j in range(i-2):
dp[i] += dp[j]
dp[i] %= mod
print(dp[S])
| 0 | null | 45,458,206,513,540 | 235 | 79 |
# 入出力から得点を計算する
import sys
input = lambda: sys.stdin.readline().rstrip()
D = int(input())
c = list(map(int, input().split()))
s = [[int(i) for i in input().split()] for _ in range(D)]
t = []
for i in range(D):
tmp = int(input())
t.append(tmp)
# 得点
result = 0
# 最後に開催された日を保存しておく
last_day = [0 for _ in range(26)]
for i in range(len(t)):
# 選んだコンテスト
choose = t[i] - 1
# 最終開催日を更新
last_day[choose] = i + 1
# そのコンテストを選んだ時の本来のポイント
result += s[i][choose]
# そこから満足度低下分をマイナス
for j in range(26):
result -= c[j] * ((i+1) - last_day[j])
# result += tmp_point
print(result)
# print(c,s,t)
|
d=int(input())
c = list(map(int,input().split()))
s=[None]*d
for i in range(d):
s[i] = list(map(int,input().split()))
t=[0]*d
for i in range(d):
t[i]=int(input())
last=[0]*26
satis=0
pena=0
for j in range(d):
ss=s[j]
tt=t[j]
satis += ss[tt-1]
last[tt-1]=j+1
pena += sum(c[i]*(j+1-last[i]) for i in range(26))
print(satis-pena)
| 1 | 9,973,557,017,788 | null | 114 | 114 |
import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for a in range(N):
for b in range(a):
ab = L[a] + L[b]
r = bisect.bisect_left(L, ab)
l = a + 1
ans += max(r - l, 0)
print(ans)
|
import math
while True:
n,x=list(map(int,input().split()))
if n==x==0: break
c=0
for i in range(1,x//3):
if i>n: break
for j in range(i+1,(x-i)//2+1):
if j>n: break
k=x-i-j
if not (n<k or k<=j):
c+=1
print(c)
| 0 | null | 86,779,456,744,098 | 294 | 58 |
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
C_A = Counter(A)
S = 0
for ca in C_A:
S += ca * C_A[ca]
Q = int(input())
for q in range(Q):
b, c = map(int,input().split())
S += (c - b) * C_A[b]
C_A[c] += C_A[b]
C_A[b] = 0
print(S)
|
from collections import Counter
#N, K = map(int, input().split( ))
#L = list(map(int, input().split( )))
N = int(input())
A = list(map(int, input().split( )))
Q = int(input())
Sum = sum(A)
#Counterなるものがあるらしい
coun = Counter(A)
#Q個の整数の組(B,C)が与えられてB \to Cとして合計を計算
#合計は(Ci-Bi)*(A.count(Bi))変化する.
for _ in range(Q):
b, c = map(int, input().split( ))
Sum += (c-b)*coun[b]
coun[c] += coun[b]
coun[b] = 0
print(Sum)
# replaceするとタイムエラーになるのか…
# A = [c if a == b else a for a in A]
| 1 | 12,150,796,014,982 | null | 122 | 122 |
h,n=map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
dp=[float('inf')]*(h+1)
dp[0]=0
for i in range(h):
for j in range(n):
next=i+ab[j][0] if i+ab[j][0]<=h else h
dp[next]=min(dp[next],dp[i]+ab[j][1])
print(dp[-1])
|
H = int(input())
W = int(input())
N = int(input())
m = max(H, W)
ans = int((N - 1) / m) + 1
print(ans)
| 0 | null | 85,031,841,268,818 | 229 | 236 |
s=input()
t=input()
ans=len(t)
for i in range(len(s)):
if i+len(t)>len(s):break
anss=0
for j in range(len(t)):
if t[j]!=s[i+j]:anss+=1
ans=min(ans,anss)
print(ans)
|
S = input()
T = input()
lens = len(S)
lent = len(T)
ans = lent
for i in range(lens - lent + 1):
count = 0
for j in range(lent):
if S[i+j] != T[j]:
count = count + 1
if count < ans:
ans = count
print(ans)
| 1 | 3,634,825,654,780 | null | 82 | 82 |
N=int(input())
A=list(map(int,input().split()))
np,nm=[],[]
for i in range(N):
np.append(A[i]+i)
nm.append(i-A[i])
sp,sm=sorted(np),sorted(nm)
ans=0
for i in range(N):
p,m=np[i],nm[i]
l,r=-1,N
while not l+1==r:
x=(l+r)//2
if sm[x]<=p:
l=x
else:
r=x
tmp=l
l,r=-1,N
while not l+1==r:
x=(l+r)//2
if sm[x]<p:
l=x
else:
r=x
ans+=tmp-l
l,r=-1,N
while not l+1==r:
x=(l+r)//2
if sp[x]<=m:
l=x
else:
r=x
tmp=l
l,r=-1,N
while not l+1==r:
x=(l+r)//2
if sp[x]<m:
l=x
else:
r=x
ans+=tmp-l
print(ans//2)
|
[n, m, l] = [int(x) for x in raw_input().split()]
A = []
B = []
C = []
counter = 0
while counter < n:
A.append([int(x) for x in raw_input().split()])
counter += 1
counter = 0
while counter < m:
B.append([int(x) for x in raw_input().split()])
counter += 1
counter = 0
while counter < n:
C.append([0] * l)
counter += 1
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 data in C:
print(' '.join([str(x) for x in data]))
| 0 | null | 13,737,052,163,002 | 157 | 60 |
# Problem D - String Equivalence
from collections import deque
# input
N = int(input())
char_list = [chr(i) for i in range(97, 97+26)]
def dfs(a_list, a_len):
if a_len==N:
print("".join(a_list))
return
else:
biggest = 97
count = len(set(a_list)) # N<=10だからさほど時間はかからない
for c in range(biggest, biggest + count + 1):
ch = chr(c)
a_list.append(ch)
dfs(a_list, a_len+1)
a_list.pop()
# initialization
a_nums = deque([])
# dfs search
dfs(a_nums, 0)
|
def main():
n, k = map(int, input().split(" "))
p = list(map(int, input().split(" ")))
p.sort()
ans = 0
for i in range(k):
ans += p[i]
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 31,829,059,229,122 | 198 | 120 |
def main():
from functools import lru_cache
import sys
sys.setrecursionlimit(10 ** 7)
inf = 2 * 10 ** 14 + 1
N = int(input())
*a, = map(int, input().split())
@lru_cache(maxsize=None)
def recursion(cur, need):
"""
cur: pickableなindex
"""
if cur >= N:
if need == 0:
return 0
else:
return -inf
rest = N - cur
if (rest + 1) // 2 < need:
return -inf
return max(
a[cur] + recursion(cur + 2, need - 1),
recursion(cur + 1, need)
)
ans = recursion(0, N // 2)
print(ans)
if __name__ == '__main__':
main()
|
mod = 10**9 + 7
X, Y = map(int, input().split())
if (X+Y) % 3 != 0:
print(0)
exit()
a = (2*Y-X)//3
b = (2*X-Y)//3
if a < 0 or b < 0:
print(0)
exit()
m = min(a, b)
ifact = 1
for i in range(2, m+1):
ifact = (ifact * i) % mod
ifact = pow(ifact, mod-2, mod)
fact = 1
for i in range(a+b, a+b-m, -1):
fact = (fact * i) % mod
print(fact*ifact % mod)
| 0 | null | 93,920,166,369,510 | 177 | 281 |
n = int(input())
a = list(map(int, input().split()))
i = 1
if 0 in a:
i = 0
else:
for j in range(n):
if i >= 0:
i = i * a[j]
if i > 10 ** 18:
i = -1
print(int(i))
|
n = int(input())
arr = list(map(int,input().split()))
res = 1
flag = 1
arr.sort()
inf = int(1e18)
for i in range(n):
res = res*arr[i]
if(res > inf):
flag = 0
break
if(flag == 0):
print(-1)
else:
print(res)
| 1 | 16,119,155,213,030 | null | 134 | 134 |
x=int(input())
i=0
ans=0
while(True):
i+=x
ans+=1
if(i%360==0):
print(ans)
break
|
a = int(input())
n = 1
while True:
if a*n % 360 == 0:
break
else:
n += 1
print(n)
| 1 | 13,102,647,191,012 | null | 125 | 125 |
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
N,K = MI()
A = [0] + LI()
for i in range(K+1,N+1):
print('Yes' if A[i] > A[i-K] else 'No')
|
#! /usr/bin/env python
# -*- coding: utf-8 -*-
''' ??????????????? '''
# ????????????????????°?????????N(N-1)/2????????§???
# ?¨???????:O(n^2)
def selection_sort(A, N):
swap_num = 0 # ???????????°
for i in range(N):
minj = i
for j in range(i, N, 1):
if A[j] < A[minj]:
minj = j
# swap
if i != minj:
tmp = A[i]
A[i] = A[minj]
A[minj] = tmp
swap_num += 1
return (A, swap_num)
if __name__ == "__main__":
N = int(input())
A = list(map(int, input().split()))
# A = [5, 2, 4, 6, 1, 3]
# N = len(A)
array_sorted, swap_num = selection_sort(A, N)
print(' '.join(map(str, array_sorted)))
print(swap_num)
| 0 | null | 3,619,095,240,490 | 102 | 15 |
h, w = map(int, input().split())
print(1) if h == 1 or w == 1 else print((h * w) // 2 + (w * h) % 2)
|
a,b= input().split()
a = int(a)
b,c = map(int,b.split("."))
print(a*(100*b+c)//100)
| 0 | null | 33,706,632,822,108 | 196 | 135 |
MOD = 10 ** 9 + 7
n, k = map(int, input().split())
alst = list(map(int, input().split()))
alst.sort()
if n == k:
ans = 1
for num in alst:
ans *= num
ans %= MOD
print(ans)
exit()
if k == 1:
print(alst[-1] % MOD)
exit()
if alst[0] >= 0:
ans = 1
alst.sort(reverse = True)
for i in range(k):
ans *= alst[i]
ans %= MOD
print(ans)
exit()
if alst[-1] <= 0:
ans = 1
if k % 2 == 1:
alst = alst[::-1]
for i in range(k):
ans *= alst[i]
ans %= MOD
print(ans)
exit()
blst = []
for num in alst:
try:
blst.append([abs(num), abs(num) // num])
except ZeroDivisionError:
blst.append([abs(num), 0])
blst.sort(reverse = True,key = lambda x:x[0])
if blst[k - 1] == 0:
print(0)
exit()
minus = 0
last_minus = 0
last_plus = 0
ans_lst = []
for i in range(k):
if blst[i][1] == -1:
minus += 1
last_minus = blst[i][0]
elif blst[i][1] == 1:
last_plus = blst[i][0]
else:
print(0)
exit()
ans_lst.append(blst[i][0])
next_minus = 0
next_plus = 0
flg_minus = False
flg_plus = False
for i in range(k, n):
if blst[i][1] == -1 and (not flg_minus):
next_minus = blst[i][0]
flg_minus = True
if blst[i][1] == 1 and (not flg_plus):
next_plus = blst[i][0]
flg_plus = True
if (flg_plus and flg_minus) or blst[i][1] == 0:
break
if minus % 2 == 0:
ans = 1
for num in ans_lst:
ans *= num
ans %= MOD
print(ans)
else:
minus_s = last_minus * next_minus
plus_s = last_plus * next_plus
ans = 1
if minus == k:
ans_lst.remove(last_minus)
ans_lst.append(next_plus)
elif minus_s == plus_s == 0:
if next_minus == 0:
ans_lst.remove(last_minus)
ans_lst.append(next_plus)
else:
print(0)
exit()
elif minus_s > plus_s:
ans_lst.remove(last_plus)
ans_lst.append(next_minus)
else:
ans_lst.remove(last_minus)
ans_lst.append(next_plus)
for num in ans_lst:
ans *= num
ans %= MOD
print(ans)
|
import sys
mod = 10 ** 9 + 7
N, K = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse = True)
if A[0] < 0 and K % 2 == 1:
ans = 1
for i in range(K):
ans *= A[i]
ans %= mod
print(ans)
sys.exit()
l = 0
r = N-1
ans = 1
if K % 2 == 1:
ans *= A[0]
l += 1
for _ in range(K // 2):
if A[l] * A[l+1] > A[r] * A[r-1]:
ans *= A[l] * A[l+1]
ans %= mod
l += 2
else:
ans *= A[r] * A[r-1]
ans %= mod
r -= 2
print(ans)
| 1 | 9,381,230,270,020 | null | 112 | 112 |
N = int(input())
C = input()
r_n = 0
ans = 0
for c in C:
if c == 'R':
r_n += 1
for i in range(r_n):
if C[i] == 'W':
ans += 1
print(ans)
|
S = input()
N = len(S)
subS1 = S[:int((N - 1) / 2)]
subS2 = S[int((N + 3) / 2) - 1:]
if subS1 == subS1[::-1] and subS2 == subS2[::-1] and S == S[::-1]:
print("Yes")
else:
print("No")
| 0 | null | 26,310,226,182,940 | 98 | 190 |
n = int(input())
L = sorted(list(map(int,input().split())),reverse = True)
ans = 0
for i in L:
for j in L:
for k in L:
if i<j<k:
if i + j>k:
ans += 1
print(ans)
|
n = int(input())
ls = sorted(list(map(int, input().split())))
cnt = 0
for i in range(len(ls) - 2):
a = ls[i]
for j in range(i+1, len(ls) - 1):
b = ls[j]
for k in range(j+1, len(ls)):
c = ls[k]
if a==b or a==c or b==c:
continue
if a+b > c and b+c > a and c+a > b:
cnt += 1
print(cnt)
| 1 | 5,051,238,456,352 | null | 91 | 91 |
a, b = map(int, input().split())
x = 300000
y = 200000
z = 100000
A = [x, y, z]
for i in range(1000):
A.append(0)
a_ = A[a-1]
b_ = A[b-1]
if a == 1 and b == 1:
print(a_ + b_ + 400000)
else:
print(a_ + b_)
|
import math
a = int(input())
b = 0
for i in range(1,a+1):
for j in range(1,a+1):
for k in range(1,a+1):
b+=math.gcd(math.gcd(i,j),k)
print(b)
| 0 | null | 88,112,122,081,022 | 275 | 174 |
from math import *
a, b, x = map(int, input().split())
areatotal = a*a*b
if areatotal / 2 == x: print(45.0)
elif x > areatotal/2:
left = 0.0
right = 90.0
while right-left > 0.00000001:
current = (right+left)/2
if a**2 * tan(radians(current)) / 2 * a < (areatotal - x):
left = current
else:
right = current
print(left)
else:
left = 0.0
right = 90.0
while right-left > 0.00000001:
current = (right+left)/2
if b**2 * tan(radians(90-current))/2*a > x:
left = current
else:
right = current
print(left)
|
n,x,m = map(int,input().split())
mod = m
amari = [-1]*m
a = x
cnt = 1
l = 0
r = 0
while 1:
# print(a)
if cnt == n:
break
if amari[a] != -1:
l = amari[a]
r = cnt
# print(a,amari[a])
break
else:
amari[a] = cnt
cnt += 1
a = ((a % m)**2) % m
# if cnt > m:
# print("error")
# exit()
ans = 0
if cnt == n:
l = 0
r = n
# print(l,r)
a = x
temp = 0
for i in range(l-1):
ans += a
a = (a**2) % mod
# print(ans)
for i in range(r-l):
temp += a
a = (a**2) % mod
ans += temp * ((n-l+1)//(r-l))
# print(ans,a,temp,temp * (n-l)//(r-l),(n-l)//(r-l),temp * ((n-l)//(r-l)))
if r != n:
for i in range((n-l+1)%(r-l)):
ans += a
a = (a**2) % mod
# print(ans)
if n == 1:
ans //=2
print(ans)
| 0 | null | 82,990,307,695,132 | 289 | 75 |
import sys
def insertionSort( nums, n, g ):
cnt = 0
i = g
while i < n:
v = nums[i]
j = i - g
while 0 <= j and v < nums[j]:
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
i += 1
return cnt
def shellSort( nums, n ):
g = []
val = 1
while val <= n:
g.append( val )
val = 3*val+1
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
cnt = 0
for i in range( m ):
cnt += insertionSort( nums, n, g[i] )
print( cnt )
n = int( sys.stdin.readline( ) )
nums = []
for i in range( n ):
nums.append( int( sys.stdin.readline( ) ) )
shellSort( nums, n )
print( "\n".join( map( str, nums ) ) )
|
# -*- coding: utf-8 -*-
#############
# Libraries #
#############
import sys
input = sys.stdin.readline
import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache
#############
# Constants #
#############
MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"
#############
# Functions #
#############
######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]
######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()
#####Shorten#####
def DD(arg): return defaultdict(arg)
#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)
######Combination######
kaijo_memo = []
def kaijo(n):
if(len(kaijo_memo) > n): return kaijo_memo[n]
if(len(kaijo_memo) == 0): kaijo_memo.append(1)
while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
return kaijo_memo[n]
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
return gyaku_kaijo_memo[n]
def nCr(n,r):
if n == r: return 1
if n < r or r < 0: return 0
ret = 1
ret = ret * kaijo(n) % MOD
ret = ret * gyaku_kaijo(r) % MOD
ret = ret * gyaku_kaijo(n-r) % MOD
return ret
######Factorization######
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1: arr.append([temp, 1])
if arr==[]: arr.append([n, 1])
return arr
#####MakeDivisors######
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
return divisors
#####MakePrimes######
def make_primes(N):
max = int(math.sqrt(N))
seachList = [i for i in range(2,N+1)]
primeNum = []
while seachList[0] <= max:
primeNum.append(seachList[0])
tmp = seachList[0]
seachList = [i for i in seachList if i % tmp != 0]
primeNum.extend(seachList)
return primeNum
#####GCD#####
def gcd(a, b):
while b: a, b = b, a % b
return a
#####LCM#####
def lcm(a, b):
return a * b // gcd (a, b)
#####BitCount#####
def count_bit(n):
count = 0
while n:
n &= n-1
count += 1
return count
#####ChangeBase#####
def base_10_to_n(X, n):
if X//n: return base_10_to_n(X//n, n)+[X%n]
return [X%n]
def base_n_to_10(X, n):
return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))
def base_10_to_n_without_0(X, n):
X -= 1
if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
return [X%n]
#####IntLog#####
def int_log(n, a):
count = 0
while n>=a:
n //= a
count += 1
return count
#############
# Main Code #
#############
class BIT:
def __init__(self, logn):
self.n = 1<<logn
self.data = [0]*(self.n+1)
self.el = [0]*(self.n+1)
def sum(self, i):
s = 0
while i > 0:
s += self.data[i]
i -= i & -i
return s
def add(self, i, x):
# assert i > 0
self.el[i] += x
while i <= self.n:
self.data[i] += x
i += i & -i
def get(self, i, j=None):
if j is None:
return self.el[i]
return self.sum(j) - self.sum(i)
def bisect(self, x):
w = i = 0
k = self.n
while k:
if i+k <= self.n and w + self.data[i+k] <= x:
w += self.data[i+k]
i += k
k >>= 1
return i+1
N = I()
A = list(S())
Q = I()
dic = {l:BIT(int_log(N,2)+1) for l in AZ}
for i in range(N):
s = A[i]
dic[s].add(i+1,1)
def change(i,y):
prev = A[i-1]
if prev == y:
pass
else:
A[i-1] = y
dic[prev].add(i,-1)
dic[y].add(i,1)
def count(x,y):
ret = 0
for l in AZ:
if dic[l].sum(x-1) != dic[l].sum(y):
ret += 1
print(ret)
for _ in range(Q):
t,x,y = SL()
if t == "1":
change(int(x),y)
else:
count(int(x),int(y))
| 0 | null | 31,150,471,098,208 | 17 | 210 |
def gcd(u, v):
if (v == 0): return u
return gcd(v, u % v)
def lcm(u, v):
return (u * v) // gcd(u, v)
while 1:
try:
inp = input()
except EOFError:
break
else:
u, v = inp.split(' ')
u = int(u)
v = int(v)
print(gcd(u, v), lcm(u, v))
|
# -*- coding:utf-8 -*-
import sys
def gcd(a, b):
if b == 0: return a
return gcd(b, a % b)
def lcm(a, b):
return a * b / gcd(a, b)
array = []
for i in sys.stdin:
array.append(i)
for i in range(len(array)):
n, m = array[i].split()
n, m = int(n), int(m)
print(int(gcd(n, m)),int(lcm(n, m)))
| 1 | 690,608,180 | null | 5 | 5 |
A = []
B = []
for i in range(3):
a = list(map(int, input().split()))
A.append(a)
N = int(input())
test = [[0]*3 for _ in range(3)]
for i in range(N):
B.append(int(input()))
for b in B:
for m in range(3):
for n in range(3):
if b == A[m][n]:
test[m][n] =1
ans = 'No'
for i in range(3):
if sum(test[i]) == 3:
ans = 'Yes'
if test[0][i]+test[1][i]+test[2][i] == 3:
ans = 'Yes'
if test[0][0]+test[1][1]+test[2][2] == 3:
ans = 'Yes'
if test[2][0]+test[1][1]+test[0][2] == 3:
ans = 'Yes'
print(ans)
|
input()
a=list(map(int, input().split()))
a.reverse()
print(*a)
| 0 | null | 30,531,563,417,838 | 207 | 53 |
print(1 - (int(input())))
|
def FizzBuzz_sum():
# 入力
N = int(input())
# 初期処理
N = [i for i in range(1,N+1)]
sum = 0
# 比較処理
for i in N:
if i % 3 == 0 and i % 5 == 0:
pass
elif i % 3 == 0:
pass
elif i % 5 == 0:
pass
else:
sum += i
return sum
result = FizzBuzz_sum()
print(result)
| 0 | null | 18,809,579,517,888 | 76 | 173 |
n = int(input())
alp = [chr(ord("a") + x) for x in range(26)]
def dfs(S):
if len(S) == n:
print(S)
else:
max_s = ord(max(S)) - 96
#print(max_s)
for i in range(max_s + 1):
dfs(S + alp[i])
dfs("a")
|
a,b,c=map(int,input().split())
import math
d=math.sin(math.radians(c))
print(a*b*d/2)
e=math.cos(math.radians(c))
x=math.sqrt(a**2+b**2-2*a*b*e)
print(a+b+x)
print(2*(a*b*d/2)/a)
| 0 | null | 26,462,459,378,980 | 198 | 30 |
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 9 + 7
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
N, K = map(int, input().split())
A = list(map(int, input().split()))
S = []
T = []
for a in A:
if a < 0:
T.append(a)
else:
S.append(a)
ls = len(S)
lt = len(T)
ok = False
if ls > 0:
if N == K:
ok = lt % 2 == 0
else:
ok = True
else:
ok = K % 2 == 0
ans = 1
if not ok:
A = sorted(A, key=lambda x: abs(x))
for a in A[:K]:
ans *= a
ans %= MOD
else:
S = sorted(S)
T = sorted(T, reverse=True)
if K % 2 == 1: # if K is odd, the answer has at least one positive number.
ans *= S.pop()
ans %= MOD
p = []
# the num of negatives must be even, so positives must do the same
# thus, we can pop 2 items at one time.
while len(S) >= 2:
x = S.pop()
y = S.pop()
p.append(x * y)
while len(T) >= 2:
x = T.pop()
y = T.pop()
p.append(x * y)
p = sorted(p, reverse=True)
for i in range(K // 2):
ans *= p[i]
ans %= MOD
print(ans % MOD)
|
import sys
input = sys.stdin.readline
t = input()
t_update = ""
for i in t:
if i == "?":
i = "D"
t_update += i
print(t_update)
| 0 | null | 13,959,356,402,520 | 112 | 140 |
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
N=I()
from math import gcd
from collections import defaultdict
dd = defaultdict(int)
temp0=0
for i in range(N):
a,b=MI()
if (a,b)==(0,0):
temp0+=1
continue
if a<0:
a*=-1
b*=-1
#(+,+)と(+,-)だけにする
if a*b!=0:
g=gcd(a,b)
a=a//g
b=b//g
if a*b>0:#(+,+)
dd[(a,b)]+=1
dd[b,-a]+=0
else:#(+,-)
dd[(a,b)]+=1
dd[(-b,a)]+=0
elif (a,b)!=(0,0):
#assert 0
if a==0:
b=1
else:
a=1
dd[(a,b)]+=1
dd[(b,a)]+=0
ans=1
for k,v in dd.items():
a,b=k
if b<=0:
continue
#( +,+)と(0,1)だけ見る
if a*b!=0:
v=dd[k]
v2=dd[(b,-a)]
else:
v=dd[k]
v2=dd[(b,a)]
temp=pow(2,v,mod)+pow(2,v2,mod)-1
ans=(ans*temp)%mod
ans=(ans-1+temp0)%mod
print(ans)
#せんぶ0の組みをひく
main()
|
from sys import stdin
from itertools import accumulate
input = stdin.readline
n = int(input())
a = list(map(int,input().split()))
p = [0] + list(accumulate(a))
res = 0
for i in range(n-1,-1,-1):
res += (a[i] * p[i])%(10**9 + 7)
print(res % (10**9 + 7))
| 0 | null | 12,507,303,641,548 | 146 | 83 |
N,K=map(int,input().split())
R,S,P=map(int,input().split())
L=input()
T=[]
for i in range(N):
T.append(L[i])
for i in range(K,N):
if T[i]==T[i-K]:
T[i]="0"
p=0
for i in T:
if i=="r":
p+=P
elif i=="s":
p+=R
elif i=="p":
p+=S
print(p)
|
n, k = input(), int(input())
dp0 = [[0] * (k + 2) for _ in range(len(n) + 1)]
dp1 = [[0] * (k + 2) for _ in range(len(n) + 1)]
dp1[0][0] = 1
for i in range(len(n)):
for j in range(k + 1):
dp0[i + 1][j] += dp0[i][j]
dp0[i + 1][j + 1] += dp0[i][j] * 9
if n[i] != '0':
dp0[i + 1][j] += dp1[i][j]
dp0[i + 1][j + 1] += dp1[i][j] * (int(n[i]) - 1)
dp1[i + 1][j + 1] += dp1[i][j]
elif n[i] == '0':
dp1[i + 1][j] += dp1[i][j]
print(dp0[len(n)][k] + dp1[len(n)][k])
| 0 | null | 91,782,202,803,562 | 251 | 224 |
import sys
N,M = map(int,input().split())
array = list(map(int,input().split()))
if not ( 1 <= M <= 100 and M <= N <= 100 ): sys.exit()
if not (len(array) == len(set(array))): sys.exit()
count = 0
standard = sum(array) * (1/(4*M))
for I in array:
if I >= standard:
count += 1
print('Yes') if count >= M else print('No')
|
import sys
input = sys.stdin.readline
N,M = list(map(int,input().split()))
A = sorted(list(map(int,input().split())),reverse = 1)
print('Yes' if A[M-1]>=sum(A)/(4*M) else 'No')
| 1 | 38,476,122,320,270 | null | 179 | 179 |
s = input()
n = len(s)
t = s[:(n-1)//2]
u = s[(n+3)//2-1:]
if (s == s[::-1]
and t == t[::-1]
and u == u[::-1]):
print('Yes')
else:
print('No')
|
s = list(input())
f1 = s == list(reversed(s))
f2 = s[:(len(s)-1)//2] == list(reversed(s[:(len(s)-1)//2]))
f3 = s[(len(s)+2)//2:] == list(reversed(s[(len(s)+2)//2:]))
print("Yes" if all([f1, f2, f3]) else "No")
| 1 | 46,096,380,611,414 | null | 190 | 190 |
S = input().rstrip()
T = input().rstrip()
count = 0
for i in range(len(S)):
if S[i] != T[i]:
count+=1
print(count)
|
while True:
num = list(map(int,input().split()))
if(num[0] == 0 and num[1] == 0): break
c = 0
for i in range(1,num[0] - 1):
for j in range(i+1,num[0]):
for k in range(j+1,num[0]+1):
if(i+j+k == num[1]): c += 1
print(c)
| 0 | null | 5,862,274,851,218 | 116 | 58 |
a = str(input())
alpha2num = lambda c: ord(c) - ord('A') + 1
b = alpha2num(a)
c = int(b) + 1
num2alpha = lambda c: chr(c+64)
print(num2alpha(c))
|
import math
def kock(n,p1x,p1y,p2x,p2y):
if(n==0):
return
sx = (2*p1x+p2x)/3.0
sy = (2*p1y+p2y)/3.0
tx = (p1x+2*p2x)/3.0
ty = (p1y+2*p2y)/3.0
ux = (tx-sx)*math.cos(math.radians(60)) - (ty-sy)*math.sin(math.radians(60)) + sx
uy = (tx-sx)*math.sin(math.radians(60)) + (ty-sy)*math.cos(math.radians(60)) + sy
kock(n-1,p1x,p1y,sx,sy)
print(sx,sy)
kock(n-1,sx,sy,ux,uy)
print(ux,uy)
kock(n-1,ux,uy,tx,ty)
print(tx,ty)
kock(n-1,tx,ty,p2x,p2y)
n = int(input())
print(0,0)
kock(n,0,0,100,0)
print(100,0)
| 0 | null | 46,332,890,381,024 | 239 | 27 |
from collections import deque
INF = 9999999
N, M = map(int, input().split())
to = [[] for _ in range(N)]
for _ in range(M):
a, b = map(int, input().split())
to[a-1].append(b-1)
to[b-1].append(a-1)
que = deque([0])
dist = [INF] * N
pre = [0] * N
dist[0] = 0
while que:
from_v = que.popleft()
for to_u in to[from_v]:
if dist[to_u] != INF:
continue
dist[to_u] = dist[from_v]+1
pre[to_u] = from_v
que.append(to_u)
print('Yes')
for i in range(N):
if i == 0:
continue
print(pre[i]+1)
|
from decimal import Decimal
'''
def main():
a, b = input().split(" ")
a = int(a)
b = Decimal(b)
print(int(a*b))
'''
def main():
a, b = input().split(" ")
a = int(a)
b = int(b.replace(".","") )
print(a*b // 100)
if __name__ == "__main__":
main()
| 0 | null | 18,608,303,691,262 | 145 | 135 |
def Queue(l, nowtime, sec):
if len(l) == 1:
print(l[0][0], nowtime + l[0][1])
return [], 0
else:
tl = l.pop(0)
if tl[1] <= sec:
nowtime += tl[1]
print(tl[0], nowtime)
return l, nowtime
else:
nowtime += sec
l.append([tl[0], tl[1] - sec])
return l, nowtime
if __name__ == '__main__':
N, sec = input().split()
N, sec = int(N), int(sec)
lists = list()
for i in range(N):
obj, times = input().split()
lists.append([obj, int(times)])
now = 0
while lists:
lists, now = Queue(lists, now, sec)
|
#ALDS1_3-B Elementary data structures - Queue
n,q = [int(x) for x in input().split()]
Q=[]
for i in range(n):
Q.append(input().split())
t=0
res=[]
while Q!=[]:
if int(Q[0][1])<=q:
res.append([Q[0][0],int(Q[0][1])+t])
t+=int(Q[0][1])
else:
Q.append([Q[0][0],int(Q[0][1])-q])
t+=q
del Q[0]
for i in res:
print(i[0]+" "+str(i[1]))
| 1 | 44,281,418,688 | null | 19 | 19 |
D = int(input())
C = list(map(int, input().split()))
S = list(list(map(int, input().split())) for i in range(D))
T = list(int(input()) for i in range(D))
manzoku = 0
yasumi= [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
#1日目
for day in range(D):
yasumi = list(map(lambda x: x + 1, yasumi))
yasumi[T[day] - 1] = 0
manzoku += S[day][T[day] - 1]
for i in range(26):
manzoku -= C[i] * yasumi[i]
print(manzoku)
|
n = int(input())
a = list(map(int, input().split()))
q = int(input())
m = 10**5+1
nums = [0]*m
ans = 0
for i in a:
nums[i] += 1
ans += i
for _ in range(q):
b,c = map(int, input().split())
ans -= b*nums[b]
ans += c*nums[b]
nums[c] += nums[b]
nums[b] = 0
print(ans)
| 0 | null | 11,123,209,999,550 | 114 | 122 |
def main():
r = int(input())
print(r**2)
if __name__ == "__main__":
main()
|
def calc_r(r):
return r*r
r = int(input())
result = calc_r(r)
print(result)
| 1 | 145,582,590,827,524 | null | 278 | 278 |
#158_D
s = input()
q = int(input())
from collections import deque
s = deque(s)
rev = 1
for _ in range(q):
Q = list(input().split())
if Q[0] == "1":
rev *= -1
elif Q[0] == "2":
if (Q[1]=="1" and rev==1) or (Q[1]=="2" and rev==-1):
s.appendleft(Q[2])
elif (Q[1]=="2" and rev==1) or (Q[1]=="1" and rev==-1):
s.append(Q[2])
s = "".join(s)
if rev == -1:
s = s[::-1]
print(s)
|
n=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
d= [abs(x[i] - y[i]) for i in range(n)]
for i in range(1, 4):
a = 0
for j in d:
a += j**i
print("{:.6f}".format(a**(1/i)))
print("{:.6f}".format(max(d)))
| 0 | null | 28,708,376,676,240 | 204 | 32 |
n,k = map(int, input().split())
a = [0]*n
for i in range(k):
c = int(input())
L = list(map(int, input().split()))
for l in L:
a[l-1] = 1
print(a.count(0))
|
n, k = map(int, input().split())
a = [1] * n
for i in range(k):
d = int(input())
tmp = map(int, input().split())
for j in tmp:
a[j - 1] = 0
print(sum(a))
| 1 | 24,586,090,318,230 | null | 154 | 154 |
import sys
input=sys.stdin.readline
class list2D:
def __init__(self, H, W, num):
self.__H = H
self.__W = W
self.__dat = [num] * (H * W)
def __getitem__(self, a):
return self.__dat[a[0]*self.__W+a[1]]
def __setitem__(self, a, b):
self.__dat[a[0]*self.__W+a[1]] = b
def debug(self):
print(self.__dat)
class list3D:
def __init__(self, H, W, D, num):
self.__H = H
self.__W = W
self.__D = D
self.__X = W * D
self.__dat = [num] * (H * W * D)
def __getitem__(self, a):
return self.__dat[a[0]*self.__X+a[1]*self.__D + a[2]]
def __setitem__(self, a, b):
self.__dat[a[0]*self.__X+a[1]*self.__D + a[2]] = b
def debug(self):
print(self.__dat)
def main():
r,c,k=map(int,input().split())
v = list2D(r, c, 0)
for _ in range(k):
ri,ci,a=map(int,input().split())
v[ri-1, ci-1] = a
dp = list3D(r, c, 4, 0)
#print(dp)
if v[0, 0]>0: dp[0, 0, 1]=v[0, 0]
for i in range(r):
for j in range(c):
val = v[i, j]
if i>0:
x = max(dp[i-1, j, 0], dp[i-1, j, 1], dp[i-1, j, 2], dp[i-1, j, 3])
dp[i, j, 1]=max(dp[i, j, 1],x+val)
dp[i, j, 0]=max(dp[i, j, 0],x)
if j>0:
X = dp[i, j-1, 0]
Y = dp[i, j-1, 1]
V = dp[i, j-1, 2]
Z = dp[i, j-1, 3]
dp[i, j, 0]=max(dp[i, j, 0],X)
dp[i, j, 1]=max(dp[i, j, 1],X+val,Y)
dp[i, j, 2]=max(dp[i, j, 2],Y+val,V)
dp[i, j, 3]=max(dp[i, j, 3],V+val,Z)
#print(dp)
ans=0
for i in range(4): ans=max(dp[r-1, c-1, i],ans)
return print(ans)
if __name__=="__main__":
main()
|
r, c, k = map(int, input().split())
rcv = [list(map(int, input().split())) for i in range(k)]
area = [[0] * (c+1) for i in range(r+1)]
for a, b, v in rcv:
area[a-1][b-1] = v
# dp[i][j][k]: その行でiまで拾っており、
# j行k列目に到達時点の最大スコア
dp = [[[-1] * (c+1) for i in range(r+1)] for j in range(4)]
dp[0][0][0] = 0
for rr in range(r+1):
for cc in range(c+1):
for i in range(4):
# 取って右
if i+1<4 and cc<c and area[rr][cc]>0:
dp[i+1][rr][cc+1] = max(dp[i+1][rr][cc+1],
dp[i][rr][cc]+area[rr][cc])
# 取って下
if i+1<4 and rr<r and area[rr][cc]>0:
dp[0][rr+1][cc] = max(dp[0][rr+1][cc],
dp[i][rr][cc]+area[rr][cc])
# 取らずに右
if cc<c:
dp[i][rr][cc+1] = max(dp[i][rr][cc+1],
dp[i][rr][cc])
# 取らずに下
if rr<r:
dp[0][rr+1][cc] = max(dp[0][rr+1][cc],
dp[i][rr][cc])
# ans: r行c列目の最大値(iは問わず)
ans = max([dp[i][r][c] for i in range(4)])
print(ans)
| 1 | 5,566,098,045,248 | null | 94 | 94 |
import math
N= int(input())
if 360%N==0:
print(int(360/N))
elif 360%N!=0:
a = math.gcd(360,N)
print(int(360/a))
|
x = int(input())
for i in range(1,1000):
if (360*i)%x == 0:
print((360*i)//x)
exit()
| 1 | 13,055,384,924,516 | null | 125 | 125 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
A,B = map(int, read().split())
temp = [A,B]
for i in range(1,4):
if i not in temp:
print(i)
|
from collections import Counter
N = int(input())
A = [int(i) for i in input().split()]
maxA = max(A)
dp = {}
for each in A:
dp[each] = True
for i in range(N):
if dp[A[i]]:
tmp = 2 * A[i]
while maxA >= tmp:
if tmp in dp and dp[tmp]:
dp[tmp] = False
tmp += A[i]
counter = 0
t = Counter(A)
for i in range(N):
if dp[A[i]] and t[A[i]] == 1:
counter += 1
print(counter)
| 0 | null | 62,433,698,152,412 | 254 | 129 |
n = input()
d = [0 for i in range(n)]
f = [0 for i in range(n)]
G = [0 for i in range(n)]
M = [[0 for i in range(n)] for j in range(n)]
color = [0 for i in range(n)]
tt = [0]
WHITE = 0
GRAY = 1
BLACK = 2
def dfs_visit(u):
color[u] = GRAY
tt[0] = tt[0] + 1
d[u] = tt[0]
for v in range(n):
if M[u][v] == 0:
continue
if color[v] == WHITE:
dfs_visit(v)
color[u] == BLACK
tt[0] = tt[0] + 1
f[u] = tt[0]
def dfs():
for u in range(n):
if color[u] == WHITE:
dfs_visit(u)
for u in range(n):
print "%d %d %d" %(u + 1, d[u], f[u])
### MAIN
for i in range(n):
G = map(int, raw_input().split())
for j in range(G[1]):
M[G[0]-1][G[2+j]-1] = 1
dfs()
|
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B&lang=ja
import sys
input = sys.stdin.readline
N = int(input())
G = [[a-1 for a in list(map(int, input().split()))[2:]] for _ in [0]*N]
visited = [0]*N
history = [[] for _ in [0]*N]
k = 0
def dfs(v=0, p=-1):
global k
visited[v] = 1
k += 1
history[v].append(k)
for u in G[v]:
if u == p or visited[u]:
continue
dfs(u, v)
k += 1
history[v].append(k)
for i in range(N):
if not visited[i]:
dfs(i)
for i, h in enumerate(history):
print(i+1, *h)
| 1 | 3,232,457,384 | null | 8 | 8 |
N, K = map(int, input().split())
*A, = map(int, input().split())
*F, = map(int, input().split())
A, F = sorted(A), sorted(F, reverse=True)
def cond(x):
k = 0
for a, f in zip(A, F): k += max(a - (x // f), 0)
return True if k <= K else False
MIN = -1
MAX = 10**12 + 1
left, right = MIN, MAX # search range
while right - left > 1:
mid = (left + right) // 2
if cond(mid): right = mid
else: left = mid
print(right)
|
import numpy as np
N, K = map(int, input().split())
A = np.array(tuple(map(int, input().split())))
F = np.array(tuple(map(int, input().split())))
if sum(A) <= K:
print(0)
else:
def solve(N, K, A, F):
A = np.sort(A)
F = np.sort(F)[::-1]
l = -1
r = 10**12
while (r - l) > 1:
mid = (r + l) // 2
# 成績がmidだったとして、修行しなければならない回数を算出
fmid = (np.fmax([0]*N, A - (mid // F))).sum()
if fmid <= K:
r = mid
else:
l = mid
return(r)
print(solve(N, K, A, F))
| 1 | 165,376,520,751,900 | null | 290 | 290 |
import math
def fact(n):
ans = 1
for i in range(2, n+1):
ans*= i
return ans
def comb(n, c):
return fact(n)//(fact(n-c)*c)
N,M=map(int,input().split())
if M%2==0:
for i in range(M//2):
print(i+1,M-i)
for i in range(M//2):
print(M+i+1,2*M-i+1)
else:
for i in range(M//2):
print(i+1,M-i)
for i in range(M//2+1):
print(M+i+1,2*M-i+1)
|
n, m = map(int, input().split())
if n % 2 == 1:
a = [i for i in range(1, m+1)]
b = [i for i in reversed(range(m+1, 2*m+1))]
ab = [(x, y) for x, y in zip(a, b)]
else:
ab = []
x, y = (n-1)//2, n//2
if x % 2 != 0:
x, y = y, x
evenl = 1
evenr = x
while evenl < evenr:
ab.append((evenl, evenr))
evenl += 1
evenr -= 1
oddl = x+1
oddr = n-1
while oddl < oddr:
ab.append((oddl, oddr))
oddl += 1
oddr -= 1
ab = ab[:m]
for a, b in ab:
print(a, b)
| 1 | 28,680,108,241,060 | null | 162 | 162 |
# 問題:https://atcoder.jp/contests/abc145/tasks/abc145_a
print(int(input()) ** 2)
|
AA1 = input().split()
AA2 = input().split()
AA3 = input().split()
AA4 = [AA1[0],AA2[0],AA3[0]]
AA5 = [AA1[1],AA2[1],AA3[1]]
AA6 = [AA1[2],AA2[2],AA3[2]]
AA7 = [AA1[0],AA2[1],AA3[2]]
AA8 = [AA1[2],AA2[1],AA3[0]]
N = int(input())
list1 = []
for i in range(N):
b = input()
list1.append(b)
count = 0
bingo =0
for i in list1:
if i in AA1:
count +=1
if count ==3 :
bingo =1
else:
count =0
for i in list1:
if i in AA2:
count +=1
if count ==3 :
bingo =1
else:
count =0
for i in list1:
if i in AA3:
count +=1
if count ==3 :
bingo =1
else:
count =0
for i in list1:
if i in AA4:
count +=1
if count ==3 :
bingo =1
else:
count =0
for i in list1:
if i in AA5:
count +=1
if count ==3 :
bingo =1
else:
count =0
for i in list1:
if i in AA6:
count +=1
if count ==3 :
bingo =1
else:
count =0
for i in list1:
if i in AA7:
count +=1
if count ==3 :
bingo =1
else:
count =0
for i in list1:
if i in AA8:
count +=1
if count ==3 :
bingo =1
else:
count =0
if bingo ==1:
print('Yes')
else:
print('No')
| 0 | null | 102,858,529,871,100 | 278 | 207 |
print(["No","Yes"][len(set(input().split()))==2])
|
print( 'Yes' if len(set(input().split())) == 2 else 'No')
| 1 | 68,191,665,774,442 | null | 216 | 216 |
def main():
S,W=map(int,input().split())
if S<=W: print('unsafe')
else: print('safe')
return
if __name__=='__main__':
main()
|
s,w = [int(s) for s in input().split()]
if w>=s:
print("unsafe")
else:
print("safe")
| 1 | 29,155,588,876,348 | null | 163 | 163 |
import sys
p = sys.stdin.readlines()
r = 0
for i in p:
n,x = map(int,i.split())
if n==0 and x==0:
break
else:
for a in range(1,n+1):
for b in range(1,n+1):
if a==b:
break
else:
for c in range(1,n+1):
if a==c or b==c:
break
elif a+b+c==x:
r+=1
print r
r = r*0
|
def calc(n, x):
result = 0
for i in range(3, n + 1):
for j in range(2, i):
for k in range(1, j):
if sum([i, j, k]) == x:
result += 1
return str(result)
ans = []
while True:
n, x = map(int, input().split())
if n == x == 0:
break
ans.append(calc(n, x))
print("\n".join(ans))
| 1 | 1,289,892,555,520 | null | 58 | 58 |
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
if(W > V):
print('NO')
exit(0)
# 相対速度、距離
S = V - W
D = abs(A - B)
if(D > S * T):
print('NO')
exit(0)
else:
print('YES')
|
# A - Kth Term
def main():
orig = "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"
seq = list(map(lambda s: s.strip(), orig.split(",")))
K = int(input()) - 1
print(seq[K])
if __name__ == "__main__":
main()
| 0 | null | 32,730,875,450,920 | 131 | 195 |
def sep():
return map(int,input().strip().split(" "))
def lis():
return list(sep())
import sys
sys.setrecursionlimit(10**6)
s=input()
if s[2]==s[3] and s[4]==s[5]:
print("Yes")
else:
print("No")
|
def main():
import sys
n,s,_,*t=sys.stdin.buffer.read().split()
n=int(n)
d=[0]*n+[1<<c-97for c in s]
for i in range(n-1,0,-1):d[i]=d[i+i]|d[i-~i]
r=[]
for q,a,b in zip(*[iter(t)]*3):
i,s=int(a)+n-1,0
if q<b'2':
d[i]=1<<b[0]-97
while i:
i//=2
d[i]=d[i+i]|d[i-~i]
continue
j=int(b)+n
while i<j:
if i&1:
s|=d[i]
i+=1
if j&1:
j-=1
s|=d[j]
i//=2
j//=2
r+=bin(s).count('1'),
print(' '.join(map(str,r)))
main()
| 0 | null | 52,182,337,036,750 | 184 | 210 |
#設定
import sys
input = sys.stdin.buffer.readline
#ライブラリインポート
from collections import defaultdict
con = 10 ** 9 + 7
#入力受け取り
def getlist():
return list(map(int, input().split()))
#処理内容
def main():
N, R = getlist()
if N >= 10:
print(R)
else:
print(R + (10 - N) * 100)
if __name__ == '__main__':
main()
|
n=int(input())
x,y=[list(map(int,input().split()))for _ in range(2)]
d=[abs(s-t)for s,t in zip(x,y)]
f=lambda n:sum([s**n for s in d])**(1/n)
print(f(1),f(2),f(3),max(d),sep='\n')
| 0 | null | 31,827,171,856,912 | 211 | 32 |
n = int(input())
l = list(map(int, input().split()))
ans = [0]*n
for i in l:
ans[i-1] += 1
print("\n".join(map(str,ans)))
|
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,615,755,226,742 | null | 169 | 169 |
n = int(input())
X_MAX = 50001
for x in range(X_MAX):
if int(x * 1.08) == n:
print(x)
exit()
print(":(")
|
n = int(input())
m = (n + 1) // 2
print(m)
| 0 | null | 92,123,809,427,384 | 265 | 206 |
N, M = map(int, input().split())
A = list(map(int, input().split()))
memory = [10**6 for _ in range(N + 1)]
flg = [False for _ in range(N + 1)]
memory[0] = 0
flg[0] = True
for a in A:
m = 0
while m < len(memory) and m + a < len(memory):
if flg:
memory[m + a] = min(memory[m] + 1, memory[m + a])
flg[m + a] = True
m += 1
print(memory[-1])
|
INF = 1e5
n, m = list(map(int, input().split()))
C = list(map(int, input().split()))
dp = [[INF] * (n + 1) for _ in range(m)]
for i in range(m):
dp[i][0] = 0
for j in range(1 + n):
dp[0][j] = j
from itertools import product
for i, j in product(range(1, m), range(1, n + 1)):
dp[i][j] = min(dp[i][j], dp[i - 1][j])
if 0 <= j - C[i]:
dp[i][j] = min(dp[i][j], dp[i][j - C[i]] + 1)
print(dp[i][j])
| 1 | 144,762,763,430 | null | 28 | 28 |
import numpy as np
from numba import njit, prange
#'''
N, K = map(int, input().split())
As = list(map(int, input().split()))
'''
N = 200000
K = 100000
As = [0] * N
#'''
@njit("i8[:](i8[:],)", cache = True)
def update(A_array):
before_csum = np.zeros(N+1, np.int64)
for i, A in enumerate(A_array[:N]):
before_csum[max(0, i-A)] += 1
before_csum[min(N, i+A+1)] -= 1
return np.cumsum(before_csum)
A_array = np.array(As + [0], dtype = np.int64)
for k in range(min(K, 50)):
A_array = update(A_array)
print(*A_array.tolist()[:N])
|
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1 for i in range(n)]
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
N, M=[int(i) for i in input().split(" ")]
uf = UnionFind(N)
for i in range(M):
A,B=[int(i) for i in input().split(" ")]
uf.union(A-1,B-1)
d={}
for i in range(N):
root = uf.find(i)
d[root]=d.get(root,0)+1
print(max(d.values()))
| 0 | null | 9,696,154,760,912 | 132 | 84 |
import sys
sentence = sys.stdin.read().lower()
alf=[chr(i) for i in range(ord('a'), ord('z')+1)]
ans=dict(zip(alf, [0]*26))
for a in sentence:
if a in ans:
ans[a] += 1
for (key, val) in sorted(ans.items()):
print(key ,":" , val)
|
import sys
dataset = sys.stdin.readlines()
for s in range(ord('a'), ord('z') + 1):
count = 0
for data in dataset:
count += data.lower().count(chr(s))
print("{0} : {1}".format(chr(s), count))
| 1 | 1,646,998,759,042 | null | 63 | 63 |
def SUM(num_List):
answer = 0
for i, num in enumerate(num_List):
answer += num*i
return answer
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = list()
C = list()
start = True
num_List = [0 for x in range(100001)]
for a in A:
num_List[a] = num_List[a] + 1
for x in range(Q):
b, c = map(int, input().split())
B.append(b)
C.append(c)
for x in range(Q):
b = B[x]
c = C[x]
if start == True:
num_List[c] = num_List[c] + num_List[b]
num_List[b] = 0
answer = SUM(num_List)
start = False
else:
answer = answer + num_List[b]*(c-b)
num_List[c] = num_List[c] + num_List[b]
num_List[b] = 0
print(answer)
|
import numpy as np
from collections import defaultdict
N = int(input())
A = tuple(map(int, input().split()))
Q = int(input())
BC= [list(map(int,input().split())) for _ in range(Q)]
counter = defaultdict(int)
for x in A:
counter[x] += 1
total = sum(A)
for b, c in BC:
total += (c - b) * counter[b]
counter[c] += counter[b]
counter[b] = 0
print(total)
| 1 | 12,173,781,548,864 | null | 122 | 122 |
lines = list(input())
total = 0
size = 0
stack = []
ponds = []
size = 0
for i in range(len(lines)):
if lines[i] == "\\":
stack.append(i)
elif lines[i] == "/":
if not stack == []:
left_index = stack.pop()
size = i - left_index
target_index = left_index
#order is tricky
while not ponds == [] and ponds[-1][0] > left_index:
direct = ponds.pop()
target_index = direct[0]
size += direct[1]
ponds.append([target_index,size])
ans = []
ans.append(len(ponds))
for _ in ponds:
ans.append(_[1])
print(sum(ans[1:]))
print(" ".join(map(str,ans)))
|
downs, ponds = [], []
for i, s in enumerate(input()):
if s == "\\":
downs.append(i)
elif s == "/" and downs:
i_down = downs.pop()
area = i - i_down
while ponds and ponds[-1][0] > i_down:
area += ponds.pop()[1]
ponds.append([i_down, area])
print(sum(p[1] for p in ponds))
print(len(ponds), *(p[1] for p in ponds))
| 1 | 57,750,828,630 | null | 21 | 21 |
import sys
input = lambda: sys.stdin.readline().rstrip()
def main():
n = int(input())
a = [int(i) for i in input().split()]
mark = 1
remain = 0
for i in range(n):
if a[i] == mark:
remain += 1
mark += 1
if remain == 0:
print(-1)
else:
print(n-remain)
if __name__ == '__main__':
main()
|
n, m, l = map(int, input().split())
A = []
B = []
for _ in range(n):
A.append(list(map(int, input().split())))
for _ in range(m):
B.append(list(map(int, input().split())))
C = [[sum([A[i][k] * B[k][j] for k in range(m)]) for j in range(l)] for i in range(n)]
for row in C:
print(' '.join(map(str, row)))
| 0 | null | 58,332,981,297,540 | 257 | 60 |
n,a,b = map(int, input().split())
m1 = n // (a + b)
m2 = n % (a + b)
if a ==0:
print(0)
elif a >= n:
print(n)
elif a + b >n:
print(a)
else:
if m2 >= a:
print((m1 + 1) * a )
else:
print(m1 * a + m2)
|
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n=ni()
mins=[]
maxs=[]
for i in range(n):
a,b=nm()
mins.append(a)
maxs.append(b)
smn = sorted(mins)
smx = sorted(maxs)
if n%2==1:
mn = smn[(n+1)//2-1]
mx = smx[(n+1)//2-1]
print(round((mx-mn)+1))
else:
mn = (smn[n//2-1]+smn[n//2])/2.0
mx = (smx[n//2-1]+smx[n//2])/2.0
print(round((mx-mn)*2+1))
| 0 | null | 36,631,525,408,060 | 202 | 137 |
N=int(input())
A=list(map(int,input().split()))
M=1000050
dp=[0 for i in range(M)]
ans=0
for x in A:
if dp[x]!=0:
dp[x]=2
continue
for i in range(x,M,x):
dp[i]+=1
for x in A:
if dp[x]==1:
ans+=1
print(ans)
|
int=input()
int=int**3
print int
| 0 | null | 7,398,600,392,198 | 129 | 35 |
M1,D1=[int(i) for i in input().split()]
M2,D2=[int(i) for i in input().split()]
if M1!=M2:print(1)
else:print(0)
|
M1, D1 = map(int, input().split())
M2, D2 = map(int, input().split())
if M1!=M2:
print('1')
else:
print('0')
| 1 | 124,094,863,074,820 | null | 264 | 264 |
n = int(input())
a = list(map(int, input().split()))
last = 0
count = 0
flag = True
while flag:
flag = False
for i in range( n-1, last, -1 ):
if a[i] < a[i-1]:
t = a[i]
a[i] = a[i-1]
a[i-1] = t
count += 1
flag = True
last += 1
print(*a)
print(count)
|
a, b, c = list(map(int, input().split()))
if a < b and b < c:
print("Yes")
else:
print("No")
| 0 | null | 194,771,366,920 | 14 | 39 |
h, w = map(int, input().split())
S = []
for _ in range(h):
s = str(input())
S.append(s)
DP = [[0 for _ in range(w)] for _ in range(h)]
if S[0][0] == '.':
DP[0][0] = 0
else:
DP[0][0] = 1
ren = False
if DP[0][0] == 1:
ren = True
for i in range(1,h):
if S[i][0] == '.':
DP[i][0] = DP[i-1][0]
ren = False
elif ren == False and S[i][0] == '#':
DP[i][0] = DP[i-1][0] + 1
ren = True
elif ren == True and S[i][0] == '#':
DP[i][0] = DP[i-1][0]
ren = True
ren = False
if DP[0][0] == 1:
ren = True
for j in range(1,w):
if S[0][j] == '.':
DP[0][j] = DP[0][j-1]
ren = False
elif ren == False and S[0][j] == '#':
DP[0][j] = DP[0][j-1] + 1
ren = True
elif ren == True and S[0][j] == '#':
DP[0][j] = DP[0][j-1]
ren = True
for i in range(1,h):
for j in range(1,w):
if S[i][j] == '.':
DP[i][j] = min(DP[i-1][j], DP[i][j-1])
elif S[i][j] == '#':
res_i = 0
res_j = 0
if S[i-1][j] == '.':
res_i = 1
if S[i][j-1] == '.':
res_j = 1
DP[i][j] = min(DP[i-1][j] + res_i, DP[i][j-1] + res_j)
print(DP[h-1][w-1])
|
n,k=input().split();print(sum(sorted(list(map(int,input().split())))[:int(k)]))
| 0 | null | 30,544,948,474,010 | 194 | 120 |
a, b, c = list(map(int, input().split()))
ans = 0
for i in range(a, b+1):
if i == 1 or c % i == 0:
ans += 1
print(ans)
|
def main():
a, b, c = map(int,input().split())
_set = set()
if a <= c and b >= c: _set.add(c)
if c // 2 < b:
b = c // 2
if c % 2 == 0:
_set = _set | set(range(a, b+1))
else:
if a % 2 == 0:
_set = _set | set(range(a+1, b+1, 2))
else:
_set = _set | set(range(a, b+1, 2))
print(sum(map(lambda x: c % x == 0, _set)))
main()
| 1 | 570,702,442,464 | null | 44 | 44 |
n, k = list(map(int, input().split()))
if n < k:
ans = min(n, abs(n - k))
else:
q = n // k
ans = min(abs(n - (q * k)), abs(n - (q * k) - k))
print(ans)
|
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))
| 0 | null | 63,374,709,701,410 | 180 | 235 |
def main():
N, K = map(int, input().split())
R, S, P = map(int, input().split())
d = {'r': R, 's': S, 'p': P}
T = input()
scores = []
for t in T:
if t == 'r':
scores.append('p')
elif t == 's':
scores.append('r')
else:
scores.append('s')
for i in range(N-K):
if scores[i] == scores[i+K]:
scores[i+K] = 0
print(sum([d[v] for v in scores if v in ['p', 'r', 's']]))
if __name__ == '__main__':
main()
|
raw_input()
print " ".join([i for i in raw_input().split()][::-1])
| 0 | null | 53,999,771,844,832 | 251 | 53 |
import numpy as np
def main():
k,x = map(int, input().split())
if k*500 >= x:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main()
|
# coding: utf-8
def main():
N = input()
X = list(map(int, input().split()))
ans = 1000001
for i in range(1, 101):
tmp = sum([(x - i) ** 2 for x in X])
if tmp < ans:
ans = tmp
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 81,248,190,512,148 | 244 | 213 |
N, M, K = map(int, input().split(' '))
A_ls = [0] + list(map(int, input().split(' ')))
for i in range(len(A_ls) - 1):
A_ls[i + 1] += A_ls[i]
B_ls = [0] + list(map(int, input().split(' ')))
for i in range(len(B_ls) - 1):
B_ls[i + 1] += B_ls[i]
b_cnt,result = M, 0
for a_cnt in range(N + 1):
if A_ls[a_cnt] > K:
break
while A_ls[a_cnt] + B_ls[b_cnt] > K:
b_cnt -= 1
result = max(result, a_cnt + b_cnt)
print(result)
|
N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))
for i in range(1, N+1):
A[i] += A[i-1]
i = N
total = 0
ans = 0
for j in range(M+1):
total += B[j]
while i >= 0 and A[i]+total > K:
i -= 1
if A[i]+total <= K:
ans = max(ans, i+j)
print(ans)
| 1 | 10,700,396,026,980 | null | 117 | 117 |
a,v,b,w,t=map(int,open(0).read().split())
print('YNEOS'[abs(b-a)>(v-w)*t::2])
|
N = int(input())
lists= []
for i in range(N):
a,b = [x for x in input().split()]
lists.append([a,int(b)])
X = input()
add_time = False
add = 0
for i in range(N):
if add_time == True:
add += lists[i][1]
if X == lists[i][0]:
add_time = True
print(add)
| 0 | null | 55,827,678,336,924 | 131 | 243 |
MOD = 10**9 + 7
N, K = map(int, input().split())
A = sorted([int(i) for i in input().split()])
B = []
plus, zero, minus = 0, 0, 0
for i in range(N):
if A[i] >= 0:
B.append((A[i], 1))
plus += 1
elif A[i] == 0:
B.append((0, 0))
zero += 1
else:
B.append((-A[i], -1))
minus += 1
if plus >= K-(min(K, minus)//2*2):
B = sorted(B, key=lambda x: x[0], reverse=True)
c = 1
for i in range(K):
c *= B[i][1]
if c == 1:
ans = 1
for i in range(K):
ans *= B[i][0]
ans %= MOD
else:
ap, an = 1, 1
skip = []
for i in range(K-1, -1, -1):
if B[i][1] == 1:
ap *= B[i][0]
skip.append(i)
break
else:
skip.append(K-1)
an = 0
for i in range(K-1, -1, -1):
if B[i][1] == -1:
an *= B[i][0]
skip.append(i)
break
else:
skip.append(K-1)
ap = 0
for i in range(K, N):
if B[i][1] == 1:
ap *= B[i][0]
break
for i in range(K, N):
if B[i][1] == -1:
an *= B[i][0]
break
a = max(ap, an)
ans = 1
for i in range(K):
if i not in skip:
ans *= B[i][0]
ans %= MOD
ans *= a
ans %= MOD
elif zero >= K-(min(K, minus)//2*2):
print(0)
exit()
else:
B = sorted(B, key=lambda x: x[0], reverse=False)
ans = 1
for i in range(K):
ans *= B[i][0]*B[i][1]
ans %= MOD
print(ans)
|
# import itertools
import math
# import sys
# import numpy as np
# K = int(input())
# S = input()
# n, *a = map(int, open(0))
A, B, H, M = map(int, input().split())
# H = list(map(int, input().split()))
# Q = list(map(int, input().split()))
# S = input()
# d = sorted(d.items(), key=lambda x:x[0]) # keyでsort
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement([i for i in range(1, M + 1)], N))
# print(a[0][0])
# print(conditions[0])
kakudo_H = (H * 60 + M) / 720 * 360
kakudo_M = M / 60 * 360
print(math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(abs(kakudo_H - kakudo_M)))))
| 0 | null | 14,743,879,639,160 | 112 | 144 |
Str=[]
H=[]
h=[]
while True:
x=input()
if x=='-':
break
Str.append(x)
m=int(input())
for i in range(m):
x=int(input())
h.append(x)
H.append(h)
h=[]
for i in range(len(Str)):
a=Str[i]
for j in range(len(H[i])):
a=''.join([a[H[i][j]:],a[:H[i][j]]])
Str[i]=a
for str in Str:
print(str)
|
def shuffle(index):
global a
a = a[index:]+a[:index]
while True:
a = input()
if a == '-':
break
for i in range(int(input())):
shuffle(int(input()))
print(a)
| 1 | 1,924,911,757,980 | null | 66 | 66 |
n, k = map(int, raw_input().split())
w = []
max = 0
sum = 0
for i in xrange(n):
w_i = int(raw_input())
if w_i > max:
max = w_i
sum += w_i
w.append(w_i)
def can_put(w, p, k):
weight = 0
cnt = 1
for w_i in w:
if weight + w_i <= p:
weight += w_i
else:
cnt += 1
if cnt > k:
return 0
else:
weight = w_i
return 1
low = max
high = sum
while low < high:
mid = (low + high) / 2
#print high, mid, low
if can_put(w, mid, k) == 1:
#print("*1")
high = mid
else:
#print("*0")
low = mid + 1
#print high, mid, low
print high
|
n, k = [ int( val ) for val in raw_input( ).split( " " ) ]
w = []
maxW = sumW = 0
for i in range( n ):
num = int( raw_input( ) )
sumW += num
w.append( num )
if maxW < num:
maxW = num
minP = 0
if 1 == k:
minP = sumW
elif n == k:
minP = maxW
else:
left = maxW
right = 100000*10000
while left <= right:
middle = ( left+right )//2
truckCnt = i = loadings = 0
while i < n:
loadings += w[i]
if middle < loadings:
truckCnt += 1
if k < truckCnt+1:
break
loadings = w[i]
i += 1
if truckCnt+1 <= k:
minP = middle
if k < truckCnt+1:
left = middle + 1
else:
right = middle - 1
print( minP )
| 1 | 85,730,317,062 | null | 24 | 24 |
# 高橋くんが根性ありすぎるので, ループではTLE
# 単純に商と剰余の和と思いがちだが, そうでないことに注意
n, a, b = (int(x) for x in input().split())
if a == 0:
print('0')
exit()
count_a = n // (a + b)
leave = n % (a + b)
# 剰余がaを超えていた場合, aにする
if leave >= a: leave = a
ans = a * count_a + leave
print(ans)
|
NN =input().split()
N =int(NN[0])
A = int(NN[1])
B = int(NN[2])
X =A+B
Y =N//X
Z = N%X
if Z >=A:
ans = A
else:
ans = Z
ans1 = Y*A + ans
print(ans1)
| 1 | 55,711,212,727,548 | null | 202 | 202 |
import math
X = int(input())
def is_prime(x):
a = int(math.sqrt(X)) + 1#ある数が素数かどうかはO(√A)で判定できる
for i in range(2,a):
if x % i == 0:
return False
return True#xは素数
for j in range(X,10**5+4):
if is_prime(j):
ans = j
break
print(ans)
|
import sys
input = sys.stdin.readline
n = int(input())
a_lst = list(map(int, input().split()))
a_lst.sort()
if a_lst[0] == 0:
answer = 0
else:
answer = 1
for i in range(n):
a = a_lst[i]
answer *= a
if answer > 10 ** 18:
answer = -1
break
print(answer)
| 0 | null | 60,856,729,933,692 | 250 | 134 |
def gcd(a, b):
return gcd(b, a%b) if b else a
while True:
try:
a, b = map(int, raw_input().split())
ans = gcd(a, b)
print ans, a*b//ans
except EOFError:
break
|
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
| 1 | 658,215,840 | null | 5 | 5 |
N,K=map(int,input().split())
l=list(map(int,input().split()))
import math
def f(n):
A=0
for i in l:
A+=math.ceil(i/n)-1
return A<=K
def bis(ng,ok):
while abs(ok-ng)>1:
mid=(ok+ng)//2
if f(mid):
ok=mid
else:
ng=mid
return ok
print(bis(0,max(l)))
|
#https://atcoder.jp/contests/abc150/tasks/abc150_b
N= int(input())
s= input()
A= []
A= list(s)
#print(A)
add = 0
for i in range(0, N-2):
if A[i]== 'A' and A[i+1]=='B' and A[i+2]=='C':
add = add + 1
print(add)
| 0 | null | 52,805,255,495,888 | 99 | 245 |
l = len(input())
print("".join(["x" for x in range(l)]))
|
S = input()
T = input()
if len(S) != len(T) - 1:
print('No')
exit(0)
for n in range(len(S)):
if S[n] != T[n]:
print('No')
exit(0)
print('Yes')
| 0 | null | 47,395,721,057,970 | 221 | 147 |
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7
H,W = map(int,readline().split())
s = [readline().rstrip() for i in range(H)]
dp = [[INF] * W for i in range(H)]
dp[0][0] = 0 if s[0][0] == '.' else 1
for i in range(H):
ii = max(0,i-1)
for j in range(W):
jj = max(0,j-1)
dp[i][j] = min(dp[ii][j] + (s[i][j] != s[ii][j]), dp[i][jj] + (s[i][j] != s[i][jj]))
print((dp[H-1][W-1]+1)//2)
|
from itertools import product
from collections import deque
class ZeroOneBFS:
def __init__(self, N):
self.N = N # #vertices
self.E = [[] for _ in range(N)]
def add_edge(self, init, end, weight, undirected=False):
assert weight in [0, 1]
self.E[init].append((end, weight))
if undirected: self.E[end].append((init, weight))
def distance(self, s):
INF = float('inf')
E, N = self.E, self.N
dist = [INF] * N # the distance of each vertex from s
prev = [-1] * N # the previous vertex of each vertex on a shortest path from s
dist[s] = 0
dq = deque([(0, s)]) # (dist, vertex)
n_visited = 0 # #(visited vertices)
while dq:
d, v = dq.popleft()
if dist[v] < d: continue # (s,v)-shortest path is already calculated
for u, c in E[v]:
temp = d + c
if dist[u] > temp:
dist[u] = temp; prev[u] = v
if c == 0: dq.appendleft((temp, u))
else: dq.append((temp, u))
n_visited += 1
if n_visited == N: break
self.dist, self.prev = dist, prev
return dist
def shortest_path(self, t):
P = []
prev = self.prev
while True:
P.append(t)
t = prev[t]
if t == -1: break
return P[::-1]
H, W = map(int, input().split())
zobfs = ZeroOneBFS(H * W)
def vtx(i, j): return i*W + j
def coord(n): return divmod(n, W)
grid = [input() for _ in range(H)] # |string| = W
E = [[] for _ in range(H * W)]
ans = 0 if grid[0][0] == '.' else 1
for i, j in product(range(H), range(W)):
v = vtx(i, j)
check = [vtx(i+dx, j+dy) for dx, dy in [(1, 0), (0, 1)] if i+dx <= H-1 and j+dy <= W-1]
for u in check:
x, y = coord(u)
if grid[i][j] == '.' and grid[x][y] == '#':
zobfs.add_edge(v, u, 1)
else:
zobfs.add_edge(v, u, 0)
dist = zobfs.distance(0)
ans += dist[vtx(H-1, W-1)]
print(ans)
| 1 | 49,056,174,587,940 | null | 194 | 194 |
import sys
input = sys.stdin.readline
N,M=list(map(int,input().split()))
print('Yes' if N == M else 'No')
|
N, M = map(int, input().split())
print("Yes") if N == M else print("No")
| 1 | 83,563,846,277,600 | null | 231 | 231 |
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify
import itertools, bisect
import math, fractions
import sys, copy
def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def S(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007
def main():
N = I()
A = LI()
def lcm(a, b): return a * b // math.gcd(a, b)
l = reduce(lcm, A, 1) % MOD
ans = 0
for ai in A:
ans = (ans + l * pow(ai, MOD - 2, MOD)) % MOD
print(ans)
if __name__ == '__main__':
main()
|
import math
n = int(input())
a = list(map(int, input().split()))
mod = int(1e+9+7)
max_val = int(1e+6+1)
def make_kago(x):
kago = [0 for _ in range(x+1)]
sosuu = []
for i in range(2,x+1):
if kago[i] != 0:
continue
sosuu.append(i)
for j in range(i, x+1, i):
if kago[j] == 0:
kago[j] = i
return kago, sosuu
kago, sosuu = make_kago(max_val)
def prime_factorization(x):
if x==0 or x==1:
return None
soinsuu = []
while x!=1:
soinsuu.append(kago[int(x)])
x = x/kago[int(x)]
soinsuu_dict = dict()
for i in range(len(soinsuu)):
if soinsuu[i] not in soinsuu_dict:
soinsuu_dict[soinsuu[i]] = 1
else:
soinsuu_dict[soinsuu[i]]+=1
return soinsuu_dict
#%%
max_soinsuu = [0 for _ in range(int(1e+6+1))]
#%%
for i in range(n):
soinsuu_dict = prime_factorization(a[i])
if soinsuu_dict == None:
continue
for k, v in soinsuu_dict.items():
if max_soinsuu[k] < v:
max_soinsuu[k] = v
lcm = 1
for i in range(max_val):
if max_soinsuu[i] != 0:
lcm = (lcm*i**max_soinsuu[i])%mod
answer = 0
for i in range(n):
answer = (answer + lcm*pow(a[i],mod-2,mod))%mod
print(answer)
| 1 | 87,824,562,164,640 | null | 235 | 235 |
# B - ... (Triple Dots)
# K
K = int(input())
# S
S = input()
if K >= len(S):
answer = S
else:
answer = S[0:K] + '...'
print(answer)
|
K = int(input())
S = input()
S_len = len(S)
if len(S)<=K:
print(S)
else:
print(S[0:K]+'...')
| 1 | 19,799,196,355,840 | null | 143 | 143 |
import sys
def insertionSort( nums, n, g ):
cnt = 0
i = g
while i < n:
v = nums[i]
j = i - g
while 0 <= j and v < nums[j]:
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
i += 1
return cnt
def shellSort( nums, n ):
g = []
val =0
for i in range( n ):
val = 3*val+1
if n < val:
break
g.append( val )
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
cnt = 0
for i in range( m ):
cnt += insertionSort( nums, n, g[i] )
print( cnt )
n = int( sys.stdin.readline( ) )
nums = []
for i in range( n ):
nums.append( int( sys.stdin.readline( ) ) )
cnt = 0
shellSort( nums, n )
print( "\n".join( map( str, nums ) ) )
|
n,s = map(int,input().split())
A = list(map(int,input().split()))
mod = 998244353
dp = [[0 for i in range(s+1)] for j in range(n+1)]
dp[0][0] = 1
for i in range(n):
for j in range(s+1):
if j - A[i] >= 0:
dp[i+1][j]=(dp[i][j]*2+dp[i][j-A[i]])%mod
else:
dp[i+1][j]=(dp[i][j]*2)%mod
print(dp[n][s])
| 0 | null | 8,782,592,918,624 | 17 | 138 |
import copy
def main():
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
if V <= W:
print('NO')
elif (abs(A-B) / (V-W)) <= T:
print('YES')
else:
print('NO')
main()
|
N=int(input())
A= list(map(int,input().split()))
B=[0 for _ in range(N)]
for a in A:
B[a-1]+=1
for b in B:
print(b)
| 0 | null | 23,904,116,181,892 | 131 | 169 |
N, K = [int(_) for _ in input().split()]
P = [int(_) for _ in input().split()]
ans = 0.0
k = 0
v = 0.0
for i in range(N):
v += (P[i] + 1) / 2
k += 1
if k > K:
v -= (P[i-K] + 1) / 2
k -= 1
ans = max(ans, v)
print(ans)
|
def read_int():
return int(input().strip())
def read_ints():
return list(map(int, input().strip().split(' ')))
def solve():
"""
1 2
/2 = 1.5
1 2 3 4
/4 = 2.5
1 2 3 4 5
/5 = 3
"""
N, K = read_ints()
expectations = [(p+1)/2 for p in read_ints()]
max_e = current = sum(expectations[:K])
for i in range(1, N-K+1):
# remove i-1 add i+K
current = current-expectations[i-1]+expectations[i+K-1]
max_e = max(max_e, current)
return max_e
if __name__ == '__main__':
print(solve())
| 1 | 75,106,926,212,550 | null | 223 | 223 |
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]
#本当に貪欲法か? DP法では??
#本当に貪欲法か? DP法では??
#本当に貪欲法か? DP法では??
h,w=mii()
mat=[list(ss()) for _ in range(h)]
chk=[[0]*w for _ in range(h)]
for i in range(h):
for j in range(w):
if i==0:
if j==0:
if mat[i][j]=="#":
chk[i][j]+=1
else:
if mat[i][j]!=mat[i][j-1] and mat[i][j]=="#":
chk[i][j]=chk[i][j-1]+1
else:
chk[i][j]=chk[i][j-1]
else:
if j==0:
if mat[i][j]!=mat[i-1][j] and mat[i][j]=="#":
chk[i][j]=chk[i-1][j]+1
else:
chk[i][j]=chk[i-1][j]
else:
if mat[i][j]==mat[i-1][j] and mat[i][j]==mat[i][j-1]:
chk[i][j]=min(chk[i-1][j],chk[i][j-1])
elif mat[i][j]!=mat[i-1][j] and mat[i][j]==mat[i][j-1] and mat[i][j]=="#":
chk[i][j]=min(chk[i-1][j]+1,chk[i][j-1])
elif mat[i][j]!=mat[i][j-1] and mat[i][j]==mat[i-1][j] and mat[i][j]=="#":
chk[i][j]=min(chk[i-1][j],1+chk[i][j-1])
elif mat[i][j]=="#":
chk[i][j]=min(chk[i-1][j]+1,1+chk[i][j-1])
else:
chk[i][j]=min(chk[i-1][j],chk[i][j-1])
print(chk[-1][-1])
#print(chk)
|
data = input()
#data = '\\\\///\\_/\\/\\\\\\\\/_/\\\\///__\\\\\\_\\\\/_\\/_/\\'
diff = {'\\':-1, '_':0, '/':1}
height = [0]
[height.append(height[-1]+diff[i]) for i in data]
bottom = min(height)
height = [h-bottom for h in height]
m = max(height)
water = [m for h in height]
height00 = [0] + height + [0]
water00 = [0] + water + [0]
idx = list(range(1,len(water00)-1))
for i in idx + idx[::-1]:
water00[i] = max(height00[i],min(water00[i-1:i+2]))
water = water00[1:-1]
depth = [w-h for w,h in zip(water,height)]
paddles = [0]
for d1,d2 in zip(depth[:-1],depth[1:]):
if d1==0 and d2>0:
paddles.append(0)
paddles[-1] += min(d1,d2) + 0.5*abs(d1-d2)
paddles = [int(p) for p in paddles[1:]]
print(sum(paddles))
print(len(paddles), *paddles)
| 0 | null | 24,753,287,597,390 | 194 | 21 |
# -*- coding: utf-8 -*-
S1 = 1
r = input()
R = int(r)
S2 = R ** 2
result = S2 / S1
print(int(result))
|
from sys import stdin
r = int(stdin.readline())
if r < 1:
print(0)
else:
circle = r * r
print(circle)
| 1 | 144,940,437,906,208 | null | 278 | 278 |
h,w = map(int,input().split())
if (h==1) | (w==1):
print(1)
elif (h*w)%2 == 0:
print((h*w)//2)
else:
print(((h*w)//2)+1)
|
def resolve():
h, w = map(int, input().split())
import math
if w == 1 or h == 1:
print(1)
else:
print(math.ceil(h * w / 2))
if __name__ == '__main__':
resolve()
| 1 | 51,052,930,635,872 | null | 196 | 196 |
n = int(input())
a = list(map(int, input().split()))
x = 0
b = [0] * n
for i in range(n):
b[a[i] - 1] += 1
x = 0
for j in range(n):
x += ((b[j] - 1) * b[j] / 2)
for k in range(n):
print(int(x - b[a[k] - 1] + 1))
|
import decimal
d = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
D_1 = 0
for i in range(d):
L_i = abs(x[i] - y[i])
D_1 += L_i
D_2 = 0
for i in range(d):
L_i = abs(x[i]-y[i])**2
D_2 += L_i
D_2 = (D_2) **(1/2)
D_3 = 0
for i in range(d):
L_i = abs(x[i]-y[i])**3
D_3 += L_i
D_3 = (D_3) ** (1/3)
L =[]
for i in range(d):
L.append(abs(x[i]-y[i]))
D_ = max(L)
print('{:.8f}'.format(D_1))
print('{:.8f}'.format(D_2))
print('{:.8f}'.format(D_3))
print('{:.8f}'.format(D_))
| 0 | null | 24,030,643,613,800 | 192 | 32 |
def resolve():
N = int(input())
ans = 0
for j in range(1,N+1):
Y = int(N // j)
ans += Y * (Y+1) * j // 2
print(ans)
resolve()
|
N = int(input())
ans = 0
def tot(x, i):
base = x//i
n = base*(base+1)//2
return i*n
for i in range(1, N+1):
ans += tot(N, i)
print(ans)
| 1 | 11,166,769,859,502 | null | 118 | 118 |
n,k = map(int,input().split())
m = n%k
a = abs(k - m)
l = [m,a]
print(min(l))
|
n, k = [int(i) for i in input().split()]
ans = min((n % k), (k - n % k))
print(ans)
| 1 | 39,191,532,707,360 | null | 180 | 180 |
import sys
#input = sys.stdin.buffer.readline
def main():
N,M = map(int,input().split())
s = str(input())
s = list(reversed(s))
ans = []
now = 0
while now < N:
for i in reversed(range(min(M,N-now))):
i += 1
if s[now+i] == "0":
now += i
ans.append(i)
break
if i == 1:
print(-1)
exit()
print(*reversed(ans))
if __name__ == "__main__":
main()
|
S=input()
T=input()
if T.find(S)==0:
print("Yes")
else:
print("No")
| 0 | null | 80,416,114,176,256 | 274 | 147 |
N = int(input())
A = list(map(int, input().split()))
dp = [0]*(N)
dp[0] = 1000
for i in range(1,N):
dp[i] = dp[i-1]
for j in range(i):
dp[i] = max(dp[i], (dp[j]//A[j])*A[i]+dp[j]%A[j])
ans = 0
for i in range(N):
ans = max(ans, dp[i])
print(ans)
|
import math
cnt = 0
for i in range(int(input())):
x = int(input())
flg = False # なんらかの数で割り切れるかどうか
if x == 1:
continue
if x == 2:
cnt += 1
continue
for k in range(2, math.floor(math.sqrt(x))+1):
if not(x % k):
flg = True
break
if not flg:
cnt += 1
print(cnt)
| 0 | null | 3,690,486,162,800 | 103 | 12 |
s = input()
n = len(s)
l1 = int((n-1)/2)
l2 = int((n+3)/2)
if s == s[::-1] and s[:l1] == s[l2-1:n] :
print('Yes')
else :
print('No')
|
S = input()
N = len(S)
ans = 'No'
# 文字列strの反転は、str[::-1]
if S == S[::-1] and S[:(N-1)//2] == S[:(N-1)//2][::-1] and S[(N+1)//2:] == S[(N+1)//2:][::-1]:
ans = 'Yes'
print(ans)
| 1 | 46,225,187,563,410 | null | 190 | 190 |
def main():
n, m = (int(i) for i in input().split())
graph = { i: [] for i in range(1, n+1) }
for i in range(m):
src, dst = (int(i) for i in input().split())
graph[src].append(dst)
graph[dst].append(src)
def bfs():
st = [1]
pptr = { 1: 0 }
while st:
room = st.pop(0)
for dest_room in graph[room]:
if dest_room in pptr:
continue
st.append(dest_room)
pptr[dest_room] = room
return pptr
pptr = bfs()
if len(pptr) != n:
print('No')
else:
print('Yes')
for i in sorted(pptr.keys()):
if i == 1:
continue
print(pptr[i])
main()
|
import sys
input = sys.stdin.readline
from collections import *
X = int(input())
dp = [False]*(X+1)
dp[0] = True
for i in range(X+1):
for j in range(100, 106):
if i-j>=0:
dp[i] |= dp[i-j]
if dp[X]:
print(1)
else:
print(0)
| 0 | null | 73,889,557,945,908 | 145 | 266 |
n, k = map(int, input().split())
cnt = 0
while n >= 1:
n = n//k
cnt +=1
print(cnt)
|
a_index, a_v = map(int, input().split())
b_index, b_v = map(int, input().split())
t = int(input())
d = abs(b_index - a_index)
d_v = a_v - b_v
if d == 0 :
print("YES")
elif d_v > 0 and d / d_v <= t :
print("YES")
else :
print("NO")
| 0 | null | 39,497,974,827,068 | 212 | 131 |
s = input()
k = int(input())
ans = 0
lens = len(s)
# n -> n//2
def tansaku(moji, n, m, k):
# n以上 m未満を探索する.
ansr = 0
cntt = 1
for i in range(n, m-1):
if moji[i] == moji[i + 1]:
cntt += 1
else:
ansr += (cntt // 2) * k
cntt = 1
ansr += (cntt // 2) * k
return ansr
cnnt = 1
hentai = False
for i in range(lens-1):
if s[i] == s[i+1]:
cnnt += 1
if cnnt == lens:
hentai = True
if not hentai:
if k >= 2:
zencnts = 0
atocnts = 0
if s[lens-1] == s[0]:
for i in range(lens):
if s[lens-1-i] == s[lens-1]:
zencnts += 1
else:
break
for i in range(lens):
if s[i] == s[0]:
atocnts += 1
else:
break
news = s[atocnts:] + s[:atocnts]
news1 = s[atocnts:]
news2 = s[:atocnts]
ans += tansaku(news, 0, lens, k-1)
ans += tansaku(news1, 0, lens-atocnts, 1)
ans += tansaku(news2, 0, atocnts, 1)
print(ans)
else:
ans += tansaku(s, 0, lens, 1)
print(ans)
else:
print((lens*k)//2)
|
def main():
S = input()
K = int(input())
l = []
t = 1
m = S[0]
if len(S) == 1:
print(K//2)
return
if len(S) == 2:
if S[0] == S[1]:
print(K)
return
else:
print(0)
return
if len(S) == 3:
if S[0] == S[1] == S[2]:
print(3*K//2)
return
elif S[0] == S[1] or S[1] == S[2]:
print(K)
return
elif S[0] == S[2]:
print(K-1)
return
else:
print(0)
return
for v in S[1:]:
if v == m:
t += 1
elif t != 1:
l.append(t)
t = 1
m = v
if t != 1:
l.append(t)
ls = 0
lsm = 0
lsu = 0
if S[0] == S[-1]:
if len(l) == 1 and l[0] == len(S):
print(l[0] * K//2)
return
elif len(l) == 1:
print(((l[0] + 1)//2) *(K-1) + (l[0] // 2))
return
if S[0] == S[1] == S[-2]:
ls = l[-1] + l[0]
lsm = l[0]
lsu = l[-1]
l = l[1:-1]
elif S[-1] == S[-2]:
ls = l[-1] + 1
lsu = l[-1]
l = l[:-1]
elif S[0] == S[1]:
ls = l[0] + 1
lsm = l[0]
l = l[1:]
else:
ls = 2
r = 0
for i in l:
r += i // 2
r *= K
r += (K-1) * (ls // 2)
r += (lsm // 2) + (lsu // 2)
print(r)
main()
| 1 | 175,460,161,614,400 | null | 296 | 296 |
# アルゴリズムは回答を見て作成
n,k = map(int,input().split())
x = n
t = n%k
ans = min(t, k-t)
print(ans)
|
n = int(input())
a, b = map(int, input().split())
i = 0
ans = "NG"
while i <= b:
if i >= a and i % n == 0:
ans = "OK"
i += n
print(ans)
| 0 | null | 32,711,025,763,950 | 180 | 158 |
class Flood:
"""
begin : int
水たまりの始まる場所
area : int
水たまりの面積
"""
def __init__(self, begin, area):
self.begin = begin
self.area = area
down_index_stack = [] # \の場所
flood_stack = [] # (水たまりの始まる場所, 面積)
for i, c in enumerate(input()):
if c == '\\':
down_index_stack.append(i)
if c == '/':
if len(down_index_stack) >= 1: # 現在の/に対応する\が存在したら
l = down_index_stack.pop() # 現在の水たまりの始まる場所
area = i - l # 現在の水たまりの現在の高さの部分の面積はi-l
# 現在の水たまりが最後の水たまりを内包している間は
# (現在の水たまりの始まる場所が最後の水たまりの始まる場所より前にある間は)
while len(flood_stack) >= 1 and l < flood_stack[-1].begin:
# 最後の水たまりを現在の水たまりに取り込む
last_flood = flood_stack.pop()
area += last_flood.area
flood_stack.append(Flood(l, area)) # 現在の水たまりを最後の水たまりにして終了
area_list = [flood.area for flood in flood_stack]
print(sum(area_list))
print(' '.join(list(map(str, [len(area_list)] + area_list))))
|
def main():
h = int(input())
w = int(input())
n = int(input())
a = max(h, w)
print((n + a - 1) // a)
if __name__ == "__main__":
main()
| 0 | null | 44,599,562,413,110 | 21 | 236 |
s = input()
youbi = {"SUN":"7", "MON":"6", "TUE":"5", "WED":"4","THU":"3","FRI":"2", "SAT": "1"}
print(youbi[s])
|
import sys
input = sys.stdin.readline
def main():
H, A = map(int, input().split())
answer = 0
while H > 0:
H -= A
answer += 1
print(answer)
if __name__ == '__main__':
main()
| 0 | null | 105,260,720,060,320 | 270 | 225 |
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = [True] * n
for _ in range(m):
a, b = map(int, input().split())
if h[a-1] > h[b-1]:
ab[b-1] = False
elif h[b-1] > h[a-1]:
ab[a-1] = False
else:
ab[a-1] = False
ab[b-1] = False
print(ab.count(True))
|
import sys
import time
import math
import itertools as it
def inpl():
return list(map(int, input().split()))
st = time.perf_counter()
# ------------------------------
N, M = inpl()
H = inpl()
dp = [True] * N
for _ in range(M):
A, B = inpl()
if H[A-1] > H[B-1]:
dp[B-1] = False
elif H[A-1] < H[B-1]:
dp[A-1] = False
else:
dp[A-1] = False
dp[B-1] = False
ans = 0
for i in dp:
if i:
ans += 1
print(ans)
# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)
| 1 | 25,068,297,725,442 | null | 155 | 155 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.