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 = int(input())
a = list(map(int, input().split()))
m = 1
if 0 in a:
print(0)
else:
for i in range(n):
m = m * a[i]
if m > 10 ** 18:
print(-1)
break
elif i == n - 1:
print(m)
|
def main():
_ = int(input())
A = [int(i) for i in input().split()]
ans = 1
if 0 in A:
ans = 0
else:
for a in A:
ans *= a
if (10**18 < ans):
ans = -1
break
if (10**18 < ans):
ans = -1
print(ans)
if __name__ == '__main__':
main()
| 1 | 16,139,796,667,140 | null | 134 | 134 |
ABC = list(map(int,input().split()))
red = ABC[0]
green = ABC[1]
blue = ABC[2]
K = int(input())
for i in range(K):
if green <= red:
green *= 2
continue
elif blue <= green:
blue *= 2
if green > red and blue > green:
print('Yes')
else:
print('No')
|
def main():
A, B, C = map(int, input().split())
K = int(input())
while K > 0 and A >= B:
B *= 2
K -= 1
while K > 0 and B >= C:
C *= 2
K -= 1
if A < B < C:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
| 1 | 6,842,912,102,194 | null | 101 | 101 |
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq
def ri():
return int(input())
def rl():
return list(map(int, input().split()))
def solve():
n, m = rl()
A = rl()
print (max(n - sum(A), -1))
mode = 's'
if mode == 'T':
t = ri()
for i in range(t):
solve()
else:
solve()
|
N, M = map(int, input().split())
A = list(map(int, input().split()))
a_sum = sum(A)
if N - a_sum >= 0:
print(N - a_sum)
else:
print('-1')
| 1 | 31,973,819,838,452 | null | 168 | 168 |
count = 0
for i in input():
if i == '7':
count += 1
if count == 0:
print('No')
else:
print('Yes')
|
while True:
n, x = list(map(int,input().split()))
m=0
if n==0 and x==0:
break
else:
for i in range(1,n+1):
for j in range(i+1,n+1):
for k in range(j+1, n+1):
#print(i,j,k)
if i+j+k==x:
m+=1
print(m)
| 0 | null | 17,825,526,890,848 | 172 | 58 |
N=int(input())
S={}
for n in range(N):
s=input()
S[s]=S.get(s,0)+1
maxS=max(S.values())
S=[k for k,v in S.items() if v==maxS]
print('\n'.join(sorted(S)))
|
from collections import Counter
N = int(input())
Alist = list(map(int,input().split()))
numcntlist = [0] * N
numCounter = Counter(Alist)
for i in range(1,N+1):
numcntlist[i-1] = numCounter[i]
sumcomb = 0
for i in numcntlist:
sumcomb += int(i*(i-1)/2)
for i in Alist:
ans = sumcomb -(numCounter[i] - 1)
print(ans)
| 0 | null | 58,778,282,606,300 | 218 | 192 |
import math
from math import cos, sin
a,b,C=map(float,input().split())
C = math.radians(C)
S = 0.5*a*b*sin(C)
L = math.sqrt(b**2+a**2-2*a*b*cos(C))+a+b
h = 2*S / a
print(S)
print(L)
print(h)
|
import math
a,b,c = [float(s) for s in input().split()]
r = c * math.pi / 180
h = math.sin(r) * b
s = a * h / 2
x1 = a
y1 = 0
if c == 90:
x2 = 0
else:
x2 = math.cos(r) * b
y2 = h
d = math.sqrt((math.fabs(x1 - x2) ** 2) + (math.fabs(y1 - y2) ** 2))
l = a + b + d
print(s)
print(l)
print(h)
| 1 | 175,530,436,312 | null | 30 | 30 |
ABC = input().split()
print("Yes" if len(set(ABC)) == 2 else "No")
|
print('Yes' if len(set(map(int, input().split()))) == 2 else 'No')
| 1 | 67,983,850,375,870 | null | 216 | 216 |
n,m = map(int,input().split())
h = list(map(int,input().split()))
judge = [True] * n
for i in range(m):
a,b = map(int,input().split())
if h[a-1] == h[b-1]:
judge[a-1],judge[b-1] =False, False
elif h[a-1] > h[b-1]:
judge[b-1] = False
else:
judge[a-1] = False
print(judge.count(True))
|
N, M = map(int, input().split())
H = [0] + list(map(int, input().split()))
g = [[] for _ in range(N+1)]
for i in range(M):
a, b = map(int, input().split())
g[a].append(b)
g[b].append(a)
ans = 0
for j in range(1, N+1):
for k in g[j]:
if H[j] <= H[k]:
break
else:
ans += 1
print(ans)
| 1 | 25,249,865,513,060 | null | 155 | 155 |
def main():
s = list(input())
k = int(input())
lst = []
cnt = 1
flg = 0
ans = 0
prev = s[0]
for i in range(1, len(s)):
if prev == s[i]:
cnt += 1
else:
lst.append(cnt)
cnt = 1
prev = s[i]
flg = 1
lst.append(cnt)
if len(lst) == 1:
ans = len(s) * k // 2
else:
ans += sum(map(lambda x: x // 2, lst[1:len(lst)-1])) * k
# for l in lst[1: len(lst) - 1]:
# ans += l // 2 * k
if s[-1] == s[0]:
ans += (lst[0] + lst[-1]) // 2 * (k - 1)
ans += lst[0] // 2 + lst[-1] // 2
else:
ans += (lst[0] // 2 + lst[-1] // 2) * k
print(ans)
if __name__ == "__main__":
main()
|
a, b, c = map(int, input().split())
sahen = 4*a*b
uhen = (c-a-b)**2
if c-a-b < 0:
ans = "No"
elif sahen < uhen:
ans = "Yes"
else:
ans = "No"
print(ans)
| 0 | null | 113,366,174,709,344 | 296 | 197 |
s = input().split()
stack = []
for i in s:
if i.isdigit():
stack.append(int(i))
else:
if i == "+":
f = lambda x, y: x + y
elif i == "-":
f = lambda x, y: x - y
elif i == "*":
f = lambda x, y: x * y
y = stack.pop()
x = stack.pop()
stack.append(f(x, y))
print(stack[0])
|
operand = ["+", "-", "*"]
src = [x if x in operand else int(x) for x in input().split(" ")]
stack = []
for s in src:
if isinstance(s, int):
stack.append(s)
elif s == "+":
b, a = stack.pop(), stack.pop()
stack.append(a+b)
elif s == "-":
b, a = stack.pop(), stack.pop()
stack.append(a-b)
elif s == "*":
b, a = stack.pop(), stack.pop()
stack.append(a*b)
print(stack[0])
| 1 | 37,177,199,772 | null | 18 | 18 |
haveTrumps = [[0 for i in range(13)] for j in range(4)]
allCards = int(input())
for i in range(0, allCards):
cardType, cardNum = input().split()
if cardType == "S":
haveTrumps[0][int(cardNum) - 1] = 1
elif cardType == "H":
haveTrumps[1][int(cardNum) - 1] = 1
elif cardType == "C":
haveTrumps[2][int(cardNum) - 1] = 1
elif cardType == "D":
haveTrumps[3][int(cardNum) - 1] = 1
for i in range(0, 4):
for j in range(0, 13):
if haveTrumps[i][j] == 0:
if i == 0:
print("S ", end="")
elif i == 1:
print("H ", end="")
elif i == 2:
print("C ", end="")
elif i == 3:
print("D ", end="")
print("{0}".format(j + 1))
|
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
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 list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)
def main():
n = I()
a = LI()
r = 1
c = collections.defaultdict(int)
c[0] = 3
for b in a:
r *= c[b]
r %= mod
c[b] -= 1
c[b+1] += 1
return r
print(main())
| 0 | null | 65,529,576,178,112 | 54 | 268 |
import math
from collections import deque
N,D,A = map(int,input().split(' '))
XHn = [ list(map(int,input().split(' '))) for _ in range(N)]
ans = 0
XHn.sort()
attacks = deque([]) # (区間,攻撃回数)
attack = 0
ans = 0
for i in range(N):
x = XHn[i][0]
h = XHn[i][1]
while len(attacks) > 0 and x > attacks[0][0]:
distance,attack_num = attacks.popleft()
attack -= attack_num*A
if h > attack:
diff = h - attack
distance_attack = x + D*2
need_attack = math.ceil(diff/A)
attacks.append((distance_attack,need_attack))
attack += A*need_attack
ans += need_attack
print(ans)
|
import math
mod = 10**9 + 7
n,a,b=map(int,input().split())
k=a
modinv_table = [-1] * (k+1)
modinv_table[1] = 1
for i in range(2, k+1):
modinv_table[i] = (-modinv_table[mod % i] * (mod // i)) % mod
def binomial_coefficients(n, k):
ans = 1
for i in range(k):
ans *= n-i
ans *= modinv_table[i + 1]
ans %= mod
return ans
d=binomial_coefficients(n, a)
k=b
modinv_table = [-1] * (k+1)
modinv_table[1] = 1
for i in range(2, k+1):
modinv_table[i] = (-modinv_table[mod % i] * (mod // i)) % mod
def binomial_coefficients(n, k):
ans = 1
for i in range(k):
ans *= n-i
ans *= modinv_table[i + 1]
ans %= mod
return ans
e=binomial_coefficients(n, b)
c = pow(2,n%(10**9+7), 10**9+7)
print((c-d-e-1)%(10**9+7))
| 0 | null | 74,212,982,934,482 | 230 | 214 |
# your code goes here
#dice2
def np(dl,nu):
l=0
while dl[l]!=nu:
l+=1
return l
def si(n1,n2):
if n1==1:
if n2==2:
return 3
elif n2==3:
return 5
elif n2==4:
return 2
else:
return 4
elif n1==2:
if n2==1:
return 4
elif n2==3:
return 1
elif n2==4:
return 6
else:
return 3
elif n1==3:
if n2==2:
return 6
elif n2==5:
return 1
elif n2==1:
return 2
else:
return 5
elif n1==4:
if n2==1:
return 5
elif n2==2:
return 1
elif n2==5:
return 6
else:
return 2
elif n1==5:
if n2==1:
return 3
elif n2==3:
return 6
elif n2==4:
return 1
else:
return 4
elif n1==6:
if n2==3:
return 2
elif n2==2:
return 4
elif n2==5:
return 3
else:
return 5
D=[int(i) for i in input().split()]
q=int(input())
for i in range(q):
n=[int(i) for i in input().split()]
# print(n)
p=[]
for j in range(2):
p.append(np(D,n[j]))
# print(p)
print(D[si(p[0]+1,p[1]+1)-1])
|
class Dice:
def __init__(self, U, S, E, W, N, D):
self.u, self.d = U, D
self.e, self.w = E, W
self.s, self.n = S, N
def roll(self, commmand):
if command == 'E':
self.e, self.u, self.w, self.d = self.u, self.w, self.d, self.e
elif command == 'W':
self.e, self.u, self.w, self.d = self.d, self.e, self.u, self.w
elif command == 'S':
self.s, self.u, self.n, self.d = self.u, self.n, self.d, self.s
else:
self.s, self.u, self.n, self.d = self.d, self.s, self.u, self.n
def rightside(self, upside, forward):
self.structure = {self.u:{self.w: self.s, self.s: self.e, self.e: self.n, self.n: self.w},
self.d:{self.n: self.e, self.e: self.s, self.s: self.w, self.w: self.n},
self.e:{self.u: self.s, self.s: self.d, self.d: self.n, self.n: self.u},
self.s:{self.u: self.w, self.w: self.d, self.d: self.e, self.e: self.u},
self.w:{self.u: self.n, self.n: self.d, self.d: self.s, self.s: self.u},
self.n:{self.u: self.e, self.e: self.d, self.d: self.w, self.w: self.u}}
print(self.structure[upside][forward])
U, S, E, W, N, D = [int(i) for i in input().split()]
turns = int(input())
dice1 = Dice(U, S, E, W, N, D)
for i in range(turns):
upside, forward = [int(k) for k in input().split()]
dice1.rightside(upside, forward)
| 1 | 253,973,520,388 | null | 34 | 34 |
N, K = list(map(int, input().split()))
H = list(map(int, input().split()))
H.sort()
remain = max(0, N-K)
H = H[:remain]
print(sum(H))
|
s,t=map(str,input().split())
print(t+s,sep='')
| 0 | null | 90,890,258,772,992 | 227 | 248 |
x, k, d = map(int, input().split())
x = abs(x)
num = x // d
if num >= k:
ans = x - k*d
else:
if (k-num)%2 == 0:
ans = x - num*d
else:
ans = min(abs(x - num*d - d), abs(x - num*d + d))
print(ans)
|
from itertools import permutations
n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
per = [0] + list(permutations(list(range(1,n+1))))
pnum = per.index(p)
qnum = per.index(q)
ans = abs(pnum-qnum)
print(ans)
| 0 | null | 52,579,090,200,252 | 92 | 246 |
m = []
a = 0
for i in range(input()+1):
if i == 0:
continue
if i % 3 == 0:
m.append(str(i))
else:
a = i
while True:
if a % 10 == 3:
m.append(str(i))
break
a /= 10
if a == 0:
break
print " " + " ".join(m)
|
n = int(raw_input())
output = ""
for i in range(1, n + 1):
x = i
if x % 3 == 0:
output += " "
output += str(i)
continue
while True:
if x % 10 == 3:
output += " "
output += str(i)
break
else:
x /= 10
if x == 0:
break
print output
| 1 | 926,470,190,748 | null | 52 | 52 |
n,k = map(int,input().split())
H = sorted(list(map(int,input().split())))
if n <= k:
print(0)
exit()
if k == 0:
print(sum(H))
exit()
print(sum(H[:-k]))
|
import sys
n,k = map(int,input().split())
ans = 0;
h = [int(x) for x in input().split()]
h.sort(reverse = True)
h = h[k:]
if len(h) > 0:
ans += sum(h)
print(ans)
| 1 | 79,380,425,386,108 | null | 227 | 227 |
def odd(num):
return num//2+num%2
N=int(input())
num = odd(N)/N
print("{:.10f}".format(num))
|
n=int(input())
count=0
for i in range(0,n):
if(i%2==0):
count+=1
else:
count+=0
print(count/n)
| 1 | 177,160,020,109,020 | null | 297 | 297 |
i=0
j = int(input())
numlist = list(int(i) for i in input().split())
while i < j-1:
print(numlist[j-i-1],end='')
print(' ',end='')
i += 1
print(numlist[0])
|
R,C,k = map(int,input().split())
dp0 = [[0]*(C+1) for i in range(R+1)]
dp1 = [[0]*(C+1) for i in range(R+1)]
dp2 = [[0]*(C+1) for i in range(R+1)]
dp3 = [[0]*(C+1) for i in range(R+1)]
item = [[0]*(C+1) for i in range(R+1)]
for i in range(k):
r,c,v = map(int,input().split())
# item[r][c] = v
dp1[r][c] = v
# for i in range(R+1):
# print(item[i])
for i in range(1,R+1):
for j in range(1,C+1):
# a = item[i][j]
# dp0[i][j] = max(dp0[i-1][j],dp1[i-1][j],dp2[i-1][j],dp3[i-1][j],dp0[i][j-1])
# dp1[i][j] = max(dp0[i][j-1]+a,dp1[i][j-1])
# dp2[i][j] = max(dp1[i][j-1]+a,dp2[i][j-1])
# dp3[i][j] = max(dp2[i][j-1]+a,dp3[i][j-1])
# dp0[i][j] = max(dp0[i-1][j],dp1[i-1][j],dp2[i-1][j],dp3[i-1][j],dp0[i][j-1],dp0[i][j])
dp3[i][j] = max(dp2[i][j-1]+dp1[i][j],dp3[i][j-1])
dp2[i][j] = max(dp1[i][j-1]+dp1[i][j],dp2[i][j-1])
dp1[i][j] = max(dp1[i-1][j]+dp1[i][j],dp2[i-1][j]+dp1[i][j],dp3[i-1][j]+dp1[i][j],dp1[i][j-1],dp1[i][j])
# for i in range(R+1):
# print(dp2[i])
print(max(dp0[R][C],dp1[R][C],dp2[R][C],dp3[R][C]))
| 0 | null | 3,235,747,317,532 | 53 | 94 |
import numpy as np
data = np.array([int(x) for x in str(input())])
if data.sum() % 9 == 0:
print("Yes")
else:
print("No")
|
c= '123'
a= str(input())
b= str(input())
c= c.replace(a, '')
c= c.replace(b, '')
print(c)
| 0 | null | 57,721,102,260,930 | 87 | 254 |
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
sum_A = [0] * (N + 1)
sum_B = [0] * (M + 1)
for a in range(1, N + 1):
sum_A[a] = sum_A[a - 1] + A[a - 1]
for b in range(1, M + 1):
sum_B[b] = sum_B[b - 1] + B[b - 1]
count = 0
# print(sum_A)
# print(sum_B)
last_index = M
for a in range(len(sum_A)):
# print("----------------------")
# print("a", a)
if sum_A[a] > K:
count = max(count, a - 1)
break
elif sum_A[a] == K:
count = max(count, a)
now = sum_A[a]
rest = K - now
# print("last_index", last_index)
#able = len([i for i in sum_B[:last_index + 1] if i <= rest]) - 1
while True:
if last_index < 0:
able = 0
break
if sum_B[last_index] > rest:
last_index -= 1
else:
able = last_index
break
# print("now", now, "rest", rest, "able", able)
# print("今回の最大countは", "a + able = ", a + able)
count = max(count, a + able)
# print("これまでの最大count", count)
print(count)
|
MOD = 10**9 + 7
fac = [1 for k in range(200010)]
inv = [1 for k in range(200010)]
finv = [1 for k in range(200010)]
for k in range(2,200010):
fac[k] = (fac[k-1]*k)%MOD
inv[k] = (MOD - inv[MOD%k] * (MOD // k))%MOD
finv[k] = (finv[k - 1] * inv[k]) % MOD;
def nCr(n,r):
return (fac[n]*finv[r]*finv[n-r])%MOD
N, K = map(int,input().split())
A = sorted(list(map(int,input().split())))
m = 0
for k in range(N-K+1):
m += A[k]*nCr(N-k-1,K-1)
m %= MOD
A = A[::-1]
M = 0
for k in range(N-K+1):
M += A[k]*nCr(N-k-1,K-1)
M %= MOD
print(M-m if M>=m else M-m+MOD)
| 0 | null | 52,943,536,923,772 | 117 | 242 |
# abc157_b.py
# https://atcoder.jp/contests/abc157/tasks/abc157_b
# B - Bingo /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点
# 問題文
# 3×3のサイズのビンゴカードがあります。上から i 行目、左から j 列目の数は Ai,jです。
# 続けて、 N個の数 b1,b2,⋯,bNが選ばれます。
# 選ばれた数がビンゴカードの中にあった場合、ビンゴカードのその数に印を付けます。
# N個の数字が選ばれた時点でビンゴが達成されているか、則ち、縦・横・斜めのいずれか 1 列に並んだ 3つの数の組であって、
# 全てに印の付いているものが存在するかどうかを判定してください。
# 制約
# 入力は全て整数
# 1≤Ai,j≤100
# Ai1,j1≠Ai2,j2((i1,j1)≠(i2,j2))
# 1≤N≤10
# 1≤bi≤100
# bi≠bj(i≠j)
# 入力
# 入力は以下の形式で標準入力から与えられる。
# A1,1 A1,2 A1,3
# A2,1 A2,2 A2,3
# A3,1 A3,2 A3,3
# N
# b1
# ⋮
# bN
# 出力
# ビンゴが達成されているならば Yes と、そうでないならば No と出力せよ。
# 入力例 1
# 84 97 66
# 79 89 11
# 61 59 7
# 7
# 89
# 7
# 87
# 79
# 24
# 84
# 30
# 出力例 1
# Yes
# A1,1,A2,1,A2,2,A3,3に印が付けられます。このとき、左上から右下にかけて斜めに 3個の印が並び、ビンゴが成立しています。
# 入力例 2
# 41 7 46
# 26 89 2
# 78 92 8
# 5
# 6
# 45
# 16
# 57
# 17
# 出力例 2
# No
# 印は 1つも付いていません。
# 入力例 3
# 60 88 34
# 92 41 43
# 65 73 48
# 10
# 60
# 43
# 88
# 11
# 48
# 73
# 65
# 41
# 92
# 34
# 出力例 3
# Yes
# 全てのマスに印が付いています。
global FLAG_LOG
FLAG_LOG = False
def log(value):
# FLAG_LOG = True
# FLAG_LOG = False
if FLAG_LOG:
print(str(value))
def calculation(lines):
# S = lines[0]
N = int(lines[3])
# N, M = list(map(int, lines[0].split()))
values_a1 = list(map(int, lines[0].split()))
values_a2 = list(map(int, lines[1].split()))
values_a3 = list(map(int, lines[2].split()))
values = list()
for i in range(N):
values.append(int(lines[i+4]))
# valueses = list()
# for i in range(N):
# valueses.append(list(map(int, lines[i+1].split())))
# ビンゴしているかどうかのフラグs
flags = [0] * 9
for n in range(N):
if values[n] == values_a1[0]:
flags[0] = 1
if values[n] == values_a1[1]:
flags[1] = 1
if values[n] == values_a1[2]:
flags[2] = 1
if values[n] == values_a2[0]:
flags[3] = 1
if values[n] == values_a2[1]:
flags[4] = 1
if values[n] == values_a2[2]:
flags[5] = 1
if values[n] == values_a3[0]:
flags[6] = 1
if values[n] == values_a3[1]:
flags[7] = 1
if values[n] == values_a3[2]:
flags[8] = 1
result = 'No'
# 横
if flags[0] * flags[1] * flags[2] == 1:
result = 'Yes'
if flags[3] * flags[4] * flags[5] == 1:
result = 'Yes'
if flags[6] * flags[7] * flags[8] == 1:
result = 'Yes'
# 縦
if flags[0] * flags[3] * flags[6] == 1:
result = 'Yes'
if flags[1] * flags[4] * flags[7] == 1:
result = 'Yes'
if flags[2] * flags[5] * flags[8] == 1:
result = 'Yes'
# 斜め
if flags[0] * flags[4] * flags[8] == 1:
result = 'Yes'
if flags[2] * flags[4] * flags[6] == 1:
result = 'Yes'
return [result]
# 引数を取得
def get_input_lines():
lines = list()
for _ in range(3):
lines.append(input())
line = input()
N = int(line)
lines.append(line)
for _ in range(N):
lines.append(input())
return lines
# テストデータ
def get_testdata(pattern):
if pattern == 1:
lines_input = ['84 97 66', '79 89 11', '61 59 7', '7', '89', '7', '87', '79', '24', '84', '30']
lines_export = ['Yes']
if pattern == 2:
lines_input = ['41 7 46', '26 89 2', '78 92 8', '5', '6', '45', '16', '57', '17']
lines_export = ['No']
if pattern == 3:
lines_input = ['60 88 34', '92 41 43', '65 73 48', '10', '60', '43', '88', '11', '48', '73', '65', '41', '92', '34']
lines_export = ['Yes']
return lines_input, lines_export
# 動作モード判別
def get_mode():
import sys
args = sys.argv
global FLAG_LOG
if len(args) == 1:
mode = 0
FLAG_LOG = False
else:
mode = int(args[1])
FLAG_LOG = True
return mode
# 主処理
def main():
import time
started = time.time()
mode = get_mode()
if mode == 0:
lines_input = get_input_lines()
else:
lines_input, lines_export = get_testdata(mode)
lines_result = calculation(lines_input)
for line_result in lines_result:
print(line_result)
# if mode > 0:
# print(f'lines_input=[{lines_input}]')
# print(f'lines_export=[{lines_export}]')
# print(f'lines_result=[{lines_result}]')
# if lines_result == lines_export:
# print('OK')
# else:
# print('NG')
# finished = time.time()
# duration = finished - started
# print(f'duration=[{duration}]')
# 起動処理
if __name__ == '__main__':
main()
|
a = [0]*9
a[0],a[1],a[2] = map(int,input().split())
a[3],a[4],a[5] = map(int,input().split())
a[6],a[7],a[8] = map(int,input().split())
n = int(input())
ans = [0]*9
for i in range(n):
b = int(input())
for j in range(9):
if b == a[j]:
ans[j] = 1
if sum(ans[:3]) == 3 or sum(ans[3:6]) == 3 or sum(ans[6:9]) == 3:
print('Yes')
elif sum(ans[0::3]) == 3 or sum(ans[1::3]) == 3 or sum(ans[2::3]) == 3:
print('Yes')
elif sum(ans[0::4]) == 3 or sum(ans[2:7:2]) == 3:
print('Yes')
else:
print('No')
| 1 | 60,122,922,303,858 | null | 207 | 207 |
import sys
input = sys.stdin.readline
def inp():
return(int(input()))
print("Yes" if inp() >=30 else "No")
|
if(int(input()) >= 30):
print('Yes')
else:
print('No')
| 1 | 5,708,564,107,210 | null | 95 | 95 |
x=int(input())
print(x+x*x+x*x*x)
|
n=int(input())
a=list(map(int,input().split()))
nu={}
for i in range(len(a)):
nu[a[i]+1]=i+1
nu=sorted(nu.items())
b=[]
for i in nu:
b.append(str(i[1]))
mojiretu = ' '.join(b)
print(mojiretu)
| 0 | null | 95,786,784,873,188 | 115 | 299 |
def registration():
S = input()
T = input()
for i, j in enumerate(S):
if T[i] != j:
break
else:
print("Yes")
return
print("No")
registration()
|
import sys
import itertools
def resolve(in_):
N, M = map(int, in_.readline().split())
sc = tuple(tuple(map(int, line.split())) for line in itertools.islice(in_, M))
if N == 1:
values = range(10)
else:
values = range(10 ** (N - 1), 10 ** N)
for value in values:
if all(value // (10 ** (N - s)) % 10 == c for s, c in sc):
return value
return -1
def main():
answer = resolve(sys.stdin.buffer)
print(answer)
if __name__ == '__main__':
main()
| 0 | null | 41,355,414,940,778 | 147 | 208 |
A = input().split()
L = int(A[1])*int(A[2])
D = int(A[0])
if L >= D:
print('Yes')
else:
print('No')
|
a,b=map(int,input().split())
l=list(map(int,input().split()))
import itertools
b=min(b,50)
def ku(l):
y=[0]*a
for j,x in enumerate(l):
y[max(0,j-x)]+=1
r=min(j+x,a-1)
if r<a-1:
y[r+1]-=1
return itertools.accumulate(y)
for _ in range(b):
l=ku(l)
print(*l)
| 0 | null | 9,509,877,286,658 | 81 | 132 |
given = input()
target = given*2
keyword = input()
if keyword in target:
print("Yes")
else:
print("No")
|
def main():
N = int(input())
st = [list(input().split()) for i in range(N)]
X = input()
ans = 0
for i in range(N):
if st[i][0] == X:
i += 1
break
for j in range(i,N,1):
ans += int(st[j][1])
return ans
print(main())
| 0 | null | 49,120,789,357,518 | 64 | 243 |
mod = 1000000007
def mod_cmb(n: int, k: int, p: int) -> int:
if n < 0 or k < 0 or n < k: return 0
if n == 0 or k == 0: return 1
if (k > n - k):
return mod_cmb(n, n - k, p)
c = d = 1
for i in range(k):
c *= (n - i)
d *= (k - i)
c %= p
d %= p
return c * pow(d, -1, p) % p
def main():
n, a, b = map(int, input().split())
ans = pow(2, n, mod) - 1
tmp_a = mod_cmb(n , a, mod)
tmp_b = mod_cmb(n , b, mod)
print((ans-tmp_a-tmp_b)%mod)
if __name__ == '__main__':
main()
|
print(f'{"Yes" if int(input()) >= 30 else "No"}')
| 0 | null | 36,135,565,698,690 | 214 | 95 |
n = int(input())
list_A = list(map(int, input().split()))
ans = 0
m = list_A[0]
for i in range(n):
if m > list_A[i]:
ans += m - list_A[i]
m = max(m, list_A[i])
print(ans)
|
N = int(input())
A = list(map(int, input().split()))
cun =0
for i in range(N):
if i == N-1:
break
elif A[i] > A[i+1]:
cun += A[i] - A[i+1]
A[i+1] = A[i]
else:
pass
print(cun)
| 1 | 4,559,628,186,780 | null | 88 | 88 |
from collections import deque
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())),reverse=True)
q=sorted(list(map(int,input().split())),reverse=True)
r=deque(sorted(list(map(int,input().split())),reverse=True))
p=deque(p[:x])
q=deque(q[:y])
ans=sum(p)+sum(q)
while p[-1]<r[0] or q[-1]<r[0]:
if p[-1]<q[-1]:
ans+=r[0]-p[-1]
r.popleft()
p.pop()
else:
ans+=r[0]-q[-1]
r.popleft()
q.pop()
if p==deque([]) or q==deque([]) or r==deque([]):
break
if r==deque([]):
pass
elif p==deque([]):
while q[-1]<r[0]:
ans+=r[0]-q[-1]
r.popleft()
q.pop()
if q==deque([]) or r==deque([]):
break
elif q==deque([]):
while p[-1]<r[0]:
ans+=r[0]-p[-1]
r.popleft()
p.pop()
if p==deque([]) or r==deque([]):
break
print(ans)
|
from math import gcd
mod = 10**9 +7
N = int(input())
dic = {}
zero = 0
for _ in range(N):
a,b = map(int, input().split())
if a ==0 and b == 0:
zero += 1
continue
elif a == 0:
key = (0,1)
elif b == 0:
key = (1,0)
else:
if a<0:
a=-a
b=-b
g = gcd(a,abs(b))
key = (a//g,b//g)
if key not in dic:
dic[key]=0
dic[key] +=1
ans = 1
for k1, v1 in dic.items():
if v1 ==0:
continue
if k1[1] >0:
k2 = (k1[1],-k1[0])
else:
k2 = (-k1[1],k1[0])
if k2 not in dic:
ans *= 2**v1
ans %= mod
else:
ans *= ((2**v1-1) %mod) + ((2**dic[k2]-1) %mod) +1
ans %= mod
dic[k2]=0
ans = (ans + zero -1 )%mod
print(ans)
| 0 | null | 32,987,214,550,030 | 188 | 146 |
MAX = 10 ** 6
MOD = 10 ** 9 + 7
fac = [0] * MAX
finv = [0] * MAX
inv = [0] * MAX
def COMinit():
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
fac[i] = fac[i - 1] * i % MOD
inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
finv[i] = finv[i - 1] * inv[i] % MOD
def COM(n, r):
if n < r or r < 0 or n < 0:
return 0
return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD
def main():
COMinit()
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
i = 0
sum_max = 0
sum_min = 0
while n - i - 1 >= k - 1:
cnt = COM(n - i - 1, k - 1)
sum_max += a[i] * cnt
sum_min += a[n - i - 1] * cnt
i += 1
ans = (sum_max - sum_min) % MOD
print(ans)
if __name__ == '__main__':
main()
|
import sys
input = sys.stdin.readline
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,K=MI()
A=LI()
A.sort()
#0~Nまで逆元などを事前計算
def cmb(n, r, mod):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return (fact[n] * factinv[r] * factinv[n-r])%mod
fact=[1,1]
factinv=[1,1]
inv=[0,1]
for i in range(2, N + 1):
fact.append((fact[-1] * i) % mod)
inv.append((-inv[mod % i] * (mod // i)) % mod)
factinv.append((factinv[-1] * inv[-1]) % mod)
def calc(ii,a):
# ii番目が最大となる時,それの寄与は?
# 0~ii-1のii個からK-1個えらぶ
temp=cmb(ii,K-1,mod)
return (temp*a)%mod
ans=0
for i in range(N):
ans+=calc(i,A[i])
for i in range(N):
A[i]*=-1
A.sort()
for i in range(N):
ans+=calc(i,A[i])
print(ans%mod)
main()
| 1 | 96,056,323,727,298 | null | 242 | 242 |
N = int(input())
NN = [[0]*10 for _ in range(11)]
for i in range(11,100):
As = str(i)[0]
Ae = str(i)[-1]
cnt = 0
for j in range(1,N+1):
if str(j)[-1]== As and str(j)[0] == Ae:
cnt +=1
NN[int(As)][int(Ae)] = cnt
ans = 0
for i in range(1,N+1):
ans += NN[int(str(i)[0])][int(str(i)[-1])]
print(ans)
|
from collections import defaultdict
def main():
n = int(input())
d = defaultdict(int)
for i in range(1, n+1):
s = str(i)
a = s[0]
b = s[-1]
d[a, b] += 1
ans = 0
d_items = list(d.items())
for (a, b), v in d_items:
ans += v * d[b,a]
print(ans)
if __name__ == '__main__':
main()
| 1 | 86,232,345,572,622 | null | 234 | 234 |
import sys
def main():
input = sys.stdin.buffer.readline
a, b = map(int, input().split())
print(max(0, a - 2 * b))
if __name__ == "__main__":
main()
|
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
import math
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math as M
MOD=10**9+7
import sys
#####################################
a,b=INPUT()
if a>=2*b:
print(a-2*b)
else:
print(0)
| 1 | 166,896,077,737,390 | null | 291 | 291 |
n = int(input())
output = ""
for i in range(1,n+1):
if i % 3 == 0:
output += " %s" % (i,)
continue
elif i % 10 == 3:
output += " %s" % (i,)
continue
x = i
while x > 1:
x = int(x/10)
if x % 10 == 3:
output += " %s" % (i,)
break
print(output)
|
n=int(raw_input())
ans=''
for i in range(3,n+1):
if i%3==0 or '3' in str(i):
ans+=(' '+str(i))
print ans
| 1 | 926,721,575,008 | null | 52 | 52 |
from sys import stdin
import numpy as np
def main():
#入力
readline=stdin.readline
n,k=map(int,readline().split())
A=np.array(list(map(int,readline().split())),dtype=np.int64)
A=np.sort(A)[::-1]
F=np.array(list(map(int,readline().split())),dtype=np.int64)
F=np.sort(F)
l=-1
r=10**12
while l<r-1:
x=(l+r)//2
A_after=np.minimum(x//F,A)
cnt=(A-A_after).sum()
if cnt<=k: r=x
else: l=x
print(r)
if __name__=="__main__":
main()
|
n = int(input())
l = [0]*53
for i in range(n):
a, b = input().split()
b = int(b)
if a == "H":
b += 13
elif a == "C":
b += 26
elif a == "D":
b += 39
l[b] = 1
for j in range(1,53):
if l[j] != 1:
ama = j % 13
syou = j // 13
if ama == 0:
ama = 13
syou -= 1
if syou == 0:
zi = "S"
elif syou == 1:
zi = "H"
elif syou == 2:
zi = "C"
else:
zi = "D"
print(zi, ama)
| 0 | null | 82,666,103,719,738 | 290 | 54 |
l = int(input())
ans = 0
for i in range(l * 10 ** 3):
s = ((l * 10 ** 3 - i) / 2) ** 2
ans = max(ans, s * i / (10 ** 9))
print(ans)
|
l=int(input())
temp1=l/3
temp2=(l-l/3)/2
print(temp1*temp2*(l-temp1-temp2))
| 1 | 46,868,486,245,372 | null | 191 | 191 |
n = int(input())
S = list(map(int,input().split(' ')))
q = int(input())
T = list(map(int,input().split(' ')))
C = 0
for i in S:
if i in T:
C += 1
T.remove(i)
print(C)
|
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
count = 0
for i in range(q):
for j in range(n):
if T[i] == S[j]:
count += 1
break
print(count)
| 1 | 67,794,562,180 | null | 22 | 22 |
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import itertools
import math
import sys
INF = float('inf')
def solve(N: int):
h, p, b = 'h', 'p', 'b'
return [p, p, h, b, h, h, p, h, p, h][N % 10] + 'on'
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
print(solve(N))
if __name__ == '__main__':
main()
|
N = int(input())
F = N%10
if F in (2,4,5,7,9):
print('hon')
elif F in (0,1,6,8):
print('pon')
else:
print('bon')
| 1 | 19,414,466,221,352 | null | 142 | 142 |
N, M = map(int, input().split())
A = list(map(int, input().split()))
answer = N - sum(A)
if N >= sum(A):
print(answer)
else:
print('-1')
|
n,m = map(int,input().split())
a = map(int,input().split())
x = n-sum(a)
if x >= 0:
print(x)
else:
print(-1)
| 1 | 31,853,866,508,480 | null | 168 | 168 |
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)
|
def check(i, j):
if s[i][j] == '.':
return 1
else:
return 0
H, W = map(int, input().split())
s = [input() for i in range(H)]
dp = [[0]*W for i in range(H)]
dp[0][0] = int(s[0][0] == '#')
for i in range(H):
for j in range(W):
if s[i][j] == '.':
if i > 0 and j > 0:
dp[i][j] = min(dp[i-1][j], dp[i][j-1])
elif i > 0:
dp[i][j] = dp[i-1][j]
elif j > 0:
dp[i][j] = dp[i][j-1]
else:
if i > 0 and j > 0:
dp[i][j] = min(dp[i-1][j]+check(i-1, j), dp[i][j-1]+check(i, j-1))
elif i > 0:
dp[i][j] = dp[i-1][j]+check(i-1, j)
elif j > 0:
dp[i][j] = dp[i][j-1]+check(i, j-1)
print(dp[H-1][W-1])
| 1 | 49,254,600,716,256 | null | 194 | 194 |
from collections import Counter
S = input()[::-1]
cur = 0
mods = Counter()
mods[0] += 1
MOD = 2019
for i,d in enumerate(S):
cur += int(d) * pow(10, i, MOD)
mods[cur%MOD] += 1
res = 0
for k,v in mods.items():
res += (v * (v-1) // 2)
print(res)
|
import numpy as np
S=input()
N=len(S)
mod=[0 for i in range(2019)]
mod2=0
ten=1
for i in range(N-1,-1,-1):
s=int(S[i])*ten
mod2+=np.mod(s,2019)
mod2=np.mod(mod2,2019)
mod[mod2]+=1
ten=(ten*10)%2019
ans=0
for i in range(2019):
k=mod[i]
if i==0:
if k>=2:
ans+=k*(k-1)//2+k
else:
ans+=k
else:
if k>=2:
ans+=k*(k-1)//2
print(ans)
| 1 | 30,752,044,561,186 | null | 166 | 166 |
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
n, quantum = map(int, sys.stdin.readline().split())
proc_q = list()
for i in range(n):
p_name, length = sys.stdin.readline().split()
proc_q.append([p_name, int(length)])
elapse = 0
while proc_q:
process = proc_q.pop(0) # retrieve 1st element
p_time = min(quantum, process[1])
elapse += p_time
if p_time == process[1]:
print(process[0], elapse)
else:
proc_q.append([process[0], process[1]-quantum])
|
class Queue():
def __init__(self):
self.size = 0
self.Max = 100000
self.queue = [None]
def isEmpty(self):
return self.size == 0
def isFull(self):
return self.size >= self.Max
def enqueue(self, x):
if self.isFull():
print("Queue overflow!")
else:
self.queue.append(x)
self.size += 1
def dequeue(self):
if self.isEmpty():
print("Queue underflow!")
else:
self.size -= 1
return self.queue.pop(1)
p_queue = Queue()
e_time = 0
n, q = map(int, input().split())
for i in range(n):
process = input().split()
process[1] = int(process[1])
p_queue.enqueue(process)
while not p_queue.isEmpty():
process = p_queue.dequeue()
if process[1] <= q:
e_time += process[1]
print(process[0], e_time)
else:
e_time += q
process[1] -= q
p_queue.enqueue(process)
| 1 | 44,995,260,630 | null | 19 | 19 |
import sys
read = lambda: sys.stdin.readline().rstrip()
def counting_tree(N, D):
import collections
tot = 1
cnt = collections.Counter(D)
"""
cnt = [0]*N
for i in D:
cnt[i]+=1
"""
for i in D[1:]:
tot = tot * cnt[i-1]%998244353
return tot if D[0]==0 else 0
def main():
N0 = int(read())
D0 = tuple(map(int, read().split()))
res = counting_tree(N0, D0)
print(res)
if __name__ == "__main__":
main()
|
bingoSheet = [0 for x in range(9)]
for i in range(3):
bingoRow = input().split()
for j in range(3):
bingoSheet[i*3 + j] = int(bingoRow[j])
bingoCount = int(input())
responses = []
for i in range(bingoCount):
responses.append(int(input()))
hasBingo = False
step = 1
initialIndex = 0
for i in range(3):
firstIndex = i*3
subList = [bingoSheet[index] for index in [firstIndex, firstIndex+1, firstIndex+2]]
if (all(elem in responses for elem in subList)):
hasBingo = True
break
for i in range(3):
firstIndex = i
subList = [bingoSheet[index] for index in [firstIndex, firstIndex+3, firstIndex+6]]
if (all(elem in responses for elem in subList)):
hasBingo = True
break
subList = [bingoSheet[index] for index in [0, 4, 8]]
if (all(elem in responses for elem in subList)):
hasBingo = True
subList = [bingoSheet[index] for index in [2, 4, 6]]
if (all(elem in responses for elem in subList)):
hasBingo = True
if hasBingo:
print('Yes')
quit()
print('No')
quit()
| 0 | null | 106,860,142,628,240 | 284 | 207 |
import sys
def resolve(in_):
L = int(in_.read())
return (L / 3.0) ** 3
def main():
answer = resolve(sys.stdin)
print(f'{answer:.12f}')
if __name__ == '__main__':
main()
|
import numpy as np
N = int(input())
mod = 10**9 + 7
A = np.array(input().split(), int)
ans = 0
for i in range(60):
b = np.count_nonzero(A >> i & 1)
ans += 2**i*(b*(N-b))
ans %= mod
c = np.count_nonzero(A >> i & 1)
print(ans)
| 0 | null | 84,633,955,321,000 | 191 | 263 |
S = input()
T = input()
ans = 0
for n in range(len(S)):
if S[n] != T[n]:
ans += 1
print(ans)
|
# -*- 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)
| 0 | null | 5,264,570,248,828 | 116 | 29 |
# abc168_a.py
# https://atcoder.jp/contests/abc168/tasks/abc168_a
# A - ∴ (Therefore) /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点: 100点
# 問題文
# いろはちゃんは、人気の日本製ゲーム「ÅtCoder」で遊びたい猫のすぬけ君のために日本語を教えることにしました。
# 日本語で鉛筆を数えるときには、助数詞として数の後ろに「本」がつきます。この助数詞はどんな数につくかで異なる読み方をします。
# 具体的には、999以下の正の整数 N について、「N本」と言うときの「本」の読みは
# Nの 1 の位が 2,4,5,7,9のとき hon
# Nの 1 の位が 0,1,6,8のとき pon
# Nの 1 の位が 3のとき bon
# です。
# Nが与えられるので、「N本」と言うときの「本」の読みを出力してください。
# 制約
# Nは 999以下の正の整数
# 入力
# 入力は以下の形式で標準入力から与えられる。
# N
# 出力
# 答えを出力せよ。
# 入力例 1
# 16
# 出力例 1
# pon
# 16の 1 の位は 6なので、「本」の読みは pon です。
# 入力例 2
# 2
# 出力例 2
# hon
# 入力例 3
# 183
# 出力例 3
# bon
global FLAG_LOG
FLAG_LOG = False
def log(value):
# FLAG_LOG = True
FLAG_LOG = False
if FLAG_LOG:
print(str(value))
def calculation(lines):
# S = lines[0]
N = int(lines[0])
# N, M = list(map(int, lines[0].split()))
# values = list(map(int, lines[1].split()))
# values = list(map(int, lines[2].split()))
# values = list()
# for i in range(N):
# values.append(int(lines[i]))
# valueses = list()
# for i in range(N):
# valueses.append(list(map(int, lines[i+1].split())))
amari = N % 10
result = 'hon'
if amari == 3:
result = 'bon'
elif amari in [0, 1, 6, 8]:
result = 'pon'
return [result]
# 引数を取得
def get_input_lines(lines_count):
lines = list()
for _ in range(lines_count):
lines.append(input())
return lines
# テストデータ
def get_testdata(pattern):
if pattern == 1:
lines_input = ['16']
lines_export = ['pon']
if pattern == 2:
lines_input = ['2']
lines_export = ['hon']
if pattern == 3:
lines_input = ['183']
lines_export = ['bon']
return lines_input, lines_export
# 動作モード判別
def get_mode():
import sys
args = sys.argv
global FLAG_LOG
if len(args) == 1:
mode = 0
FLAG_LOG = False
else:
mode = int(args[1])
FLAG_LOG = True
return mode
# 主処理
def main():
import time
started = time.time()
mode = get_mode()
if mode == 0:
lines_input = get_input_lines(1)
else:
lines_input, lines_export = get_testdata(mode)
lines_result = calculation(lines_input)
for line_result in lines_result:
print(line_result)
# if mode > 0:
# print(f'lines_input=[{lines_input}]')
# print(f'lines_export=[{lines_export}]')
# print(f'lines_result=[{lines_result}]')
# if lines_result == lines_export:
# print('OK')
# else:
# print('NG')
# finished = time.time()
# duration = finished - started
# print(f'duration=[{duration}]')
# 起動処理
if __name__ == '__main__':
main()
|
n=list(input())
n=n[::-1]
k=int(n[0])
if k==3:
print("bon")
elif k==2 or k==4 or k==5 or k==7 or k==9:
print("hon")
else:
print("pon")
| 1 | 19,119,745,776,018 | null | 142 | 142 |
import statistics
def main():
while True:
try:
N = int(input())
S = tuple(map(int, input().split()))
print(statistics.pstdev(S))
except EOFError:
break
main()
|
MAX = 4*10**5
bikkuri=[1]
mod = 10**9+7
for i in range(1,MAX+1):
bikkuri.append((bikkuri[-1]*i)%mod)
def Comb(n,k):
ans = bikkuri[n]*pow(bikkuri[k],mod-2,mod)*pow(bikkuri[n-k],mod-2,mod)
ans %=mod
return ans
n,k = map(int,input().split())
if n-1 <= k:
ans = Comb(2*n-1,n)
print(ans)
else:
tmp = 0
for i in range(k+1):
tmp += Comb(n,i)*Comb(n-1,i)
tmp %= mod
print(tmp)
| 0 | null | 33,620,190,335,478 | 31 | 215 |
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_C
# Stable Sort
# Result:
# Modifications
# - modify inner loop start value of bubble_sort
# This was the cause of the previous wrong answer.
# - improve performance of is_stable function
import sys
ary_len = int(sys.stdin.readline())
ary_str = sys.stdin.readline().rstrip().split(' ')
ary = map(lambda s: (int(s[1]), s), ary_str)
# a is an array of tupples whose format is like (4, 'C4').
def bubble_sort(a):
a_len = len(a)
for i in range(0, a_len):
for j in reversed(range(i + 1, a_len)):
if a[j][0] < a[j - 1][0]:
v = a[j]
a[j] = a[j - 1]
a[j - 1] = v
# a is an array of tupples whose format is like (4, 'C4').
def selection_sort(a):
a_len = len(a)
for i in range(0, a_len):
minj = i;
for j in range(i, a_len):
if a[j][0] < a[minj][0]:
minj = j
if minj != i:
v = a[i]
a[i] = a[minj]
a[minj] = v
def print_ary(a):
vals = map(lambda s: s[1], a)
print ' '.join(vals)
def is_stable(before, after):
length = len(before)
for i in range(0, length):
for j in range(i + 1, length):
if before[i][0] == before[j][0]:
v1 = before[i][1]
v2 = before[j][1]
for k in range(0, length):
if after[k][1] == v1:
v1_idx_after = k
break
for k in range(0, length):
if after[k][1] == v2:
v2_idx_after = k
break
if v1_idx_after > v2_idx_after:
return False
return True
def run_sort(ary, sort_fn):
ary1 = list(ary)
sort_fn(ary1)
print_ary(ary1)
if is_stable(ary, ary1):
print 'Stable'
else:
print 'Not stable'
### main
run_sort(ary, bubble_sort)
run_sort(ary, selection_sort)
|
S = input()
l = len(S) // 2
former = S[:l]
latter = S[l+1:]
print("Yes" if S == S[::-1] and former == former[::-1] and latter == latter[::-1] else "No")
| 0 | null | 23,008,243,282,310 | 16 | 190 |
a,b,c=map(int,input().split())
if a+b>=c:
print("No")
exit()
print("Yes" if 4*a*b<(c-b-a)**2 else "No")
|
a, b, c = map(int, input().split())
print("No" if c-a-b < 0 or 4*a*b >= (c-a-b)**2 else "Yes")
| 1 | 51,449,548,613,760 | null | 197 | 197 |
n=int(input())
s=input()
c=s[0]
for i in range(1,n):
if s[i]!=s[i-1]:
c=c+s[i]
print(len(c))
|
N, K = map(int,input().split())
ans = 0
MOD = 10**9 + 7
for i in range(K,N+2):
x = (N+1-i) * i + 1
ans += x
ans %= MOD
print (ans)
| 0 | null | 101,315,977,060,740 | 293 | 170 |
n = int(input())
A = list(map(int,input().split()))
from collections import deque
q = deque(A)
i = 1
ans = []
while i <= n and q:
a = q.popleft()
if a==i:
ans.append(a)
i += 1
if len(ans)==0:
print(-1)
else:
print(n-len(ans))
|
def input_array():
return list(map(int,input().split()))
n=int(input())
D=[input_array() for i in range(n)]
count=0
for d in D:
if d[0]==d[1]:
count+=1
else:
count=0
if count==3:
break
if count==3:
print("Yes")
else:
print("No")
| 0 | null | 58,833,651,878,078 | 257 | 72 |
# -*- coding: utf-8 -*-
str = raw_input()
for _ in xrange(input()):
ops = raw_input().split()
na = int(ops[1])
nb = int(ops[2]) + 1
op = ops[0]
if op[0]=="p": print str[na:nb]
elif op[2]=="v":
t = str[na:nb]
str = str[:na] + t[::-1] + str[nb:]
else: str = str[:na] + ops[3] + str[nb:]
|
x, y = map(int, input().split())
ans = 0
def calc(z):
ans = 0
if z == 1:
ans += 300000
elif z == 2:
ans += 200000
elif z == 3:
ans += 100000
return ans
if x == 1 and y == 1:
ans += 400000
print(ans+calc(x)+calc(y))
| 0 | null | 71,541,462,589,908 | 68 | 275 |
n = int(input())
an = [int(num) for num in input().split()]
sum = 0
for i in range(len(an)-1):
if an[i] > an[i+1]:
sum += an[i] - an[i+1]
an[i+1] += an[i] - an[i+1]
print(sum)
|
import sys
from time import time
from random import randrange, random
input = lambda: sys.stdin.buffer.readline()
DEBUG_MODE = False
st = time()
def get_time():
return time() - st
L = 26
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]
ans = [randrange(L) for _ in range(D)]
class BinaryIndexedTree:
def __init__(self, n):
self.n = n
self.data = [0] * (self.n+1)
def sum(self, i):
res = 0
while i > 0:
res += self.data[i]
i -= i & -i
return res
def add(self, i, x):
if i <= 0: raise IndexError
while i <= self.n:
self.data[i] += x
i += i & -i
def lower_bound(self, x):
if x <= 0: return 0
cur, s, k = 0, 0, 1 << (self.n.bit_length()-1)
while k:
nxt = cur + k
if nxt <= self.n and s + self.data[nxt] < x:
s += self.data[nxt]
cur = nxt
k >>= 1
return cur + 1
def rsum(x):
return x*(x+1)//2
b = [BinaryIndexedTree(D) for _ in range(L)]
score = 0
for d, cont in enumerate(ans):
b[cont].add(d+1, 1)
score += S[d][cont]
for i in range(L):
m = b[i].sum(D)
tmp = 0
s = [0]
for j in range(1, m+1):
s.append(b[i].lower_bound(j))
s.append(D+1)
for j in range(len(s)-1):
x = s[j+1] - s[j] - 1
tmp += rsum(x)
score -= tmp*C[i]
def chg(d, p, q):
diff = 0
d += 1
o = b[p].sum(d)
d1 = b[p].lower_bound(o-1)
d2 = b[p].lower_bound(o+1)
diff += rsum(d-d1) * C[p]
diff += rsum(d2-d) * C[p]
diff -= rsum(d2-d1) * C[p]
o = b[q].sum(d)
d1 = b[q].lower_bound(o)
d2 = b[q].lower_bound(o+1)
diff += rsum(d2-d1) * C[q]
diff -= rsum(d-d1) * C[q]
diff -= rsum(d2-d) * C[q]
d -= 1
diff -= S[d][p]
diff += S[d][q]
ans[d] = q
b[p].add(d+1, -1)
b[q].add(d+1, 1)
return diff
while True:
if random() >= 0.8:
d, q = randrange(D), randrange(L)
p = ans[d]
diff = chg(d, p, q)
if diff > 0:
score += diff
else:
chg(d, q, p)
else:
d1 = randrange(D-1)
d2 = randrange(d1+1, min(d1+3, D))
p, q = ans[d1], ans[d2]
diff = chg(d1, p, q)
diff += chg(d2, q, p)
if diff > 0:
score += diff
else:
chg(d1, q, p)
chg(d2, p, q)
if DEBUG_MODE: print(score)
if get_time() >= 1.7: break
if DEBUG_MODE: print(score)
else:
for x in ans: print(x+1)
| 0 | null | 7,169,453,488,978 | 88 | 113 |
N = int(input())
cnt = 0
for a in range(1,N):
for b in range(1,N):
if a * b >= N:
break
else:
cnt +=1
print(cnt)
|
N =int(input())
c = 0
for i in range(N):
c += (N-1)//(i+1)
print(c)
| 1 | 2,588,303,758,560 | null | 73 | 73 |
A = [[[0 for r in range(10)] for f in range(3)] for b in range(4)] # A[b][f][r]
n = int(input())
for i in range(n):
b, f, r, v = map(int, input().split())
A[b-1][f-1][r-1] += v
for b in range(4):
for f in range(3):
for r in range(10):
print(' %d' %(A[b][f][r]), end='')
print('')
if b < 3:
print('#'*20)
|
import math
n = int(input())
a = list(map(int,input().split()))
g = 1
mod = 10**9 + 7
ans = 0
for i in range(n):
u = (g*a[i])//math.gcd(g,a[i])
ans *= u//g
ans %= mod
ans += u//a[i]
ans %= mod
g = u
print(ans)
| 0 | null | 44,581,903,012,882 | 55 | 235 |
n, m = map(int, input().split())
a = sorted(map(int, input().split()))[::-1]
i = 0
for j in range(n):
i = i + a[j]
x = i / (4 * m)
print("Yes" if a[m - 1] >= x else "No")
|
n, m = map(int, input().split())
lis = sorted(list(map(int, input().split())), reverse=True)
limit = sum(lis) / (4 * m)
judge = 'Yes'
for i in range(m):
if lis[i] < limit:
judge = 'No'
break
print(judge)
| 1 | 38,891,249,121,020 | null | 179 | 179 |
#!/usr/bin/env python3
S = input()
total = 0
for i in range(len(S)):
if "R" * (i + 1) in S:
total = i + 1
ans = total
print(ans)
|
s = input()
ans = 0
for i in range(0, 3):
if s[i] == 'R':
ans += 1
if ans == 2 and s[1] == 'S':
ans -= 1
print(ans)
| 1 | 4,880,003,477,550 | null | 90 | 90 |
import sys
buff=sys.stdin.read()
buff=buff.lower()
alp="abcdefghijklmnopqrstuvwxyz"
for i in range(len(alp)):
print(alp[i],':',buff.count(alp[i]))
|
MOD = 10**9+7
N,K = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse = True)
ans = 1
if A[-1] >= 0:
for i in range(K):
ans *= A[i]
ans %= MOD
elif A[0] < 0:
if K % 2 == 0:
for i in range(K):
ans *= A[N-1-i]
ans %= MOD
else:
for i in range(K):
ans *= A[i]
ans %= MOD
else:
r,l = N-1,0
n = 0
while n < K:
if K-n == 1:
ans *= A[l]
ans %= MOD
n += 1
else:
if A[r]*A[r-1] > A[l]*A[l+1]:
ans *= (A[r]*A[r-1])
ans %= MOD
r -= 2
n += 2
else:
ans *= A[l]
ans %= MOD
l += 1
n += 1
print(ans)
| 0 | null | 5,552,602,944,768 | 63 | 112 |
ans = 0
n = 0
h = int(input())
while h != 1:
h = h//2
n += 1
for i in range(n + 1):
ans = ans + 2 ** i
print(ans)
|
def get_num(n, x):
ans = 0
for n3 in xrange(min(n, x - 3), (x + 2) / 3, -1):
for n2 in xrange(min(n3 - 1, x - n3 - 1), (x - n3) / 2, -1):
if n3 + min(n2 - 1, x - n3 - n2):
ans += 1
return ans
data = []
while True:
[n, x] = [int(m) for m in raw_input().split()]
if [n, x] == [0, 0]:
break
# if x < 3:
# print(0)
# else:
print(get_num(n, x))
| 0 | null | 40,603,734,513,120 | 228 | 58 |
a,b=map(int,input().split())
s=list(map(int,input().split()))
ans=0
s=sorted(s)
for i in range(b):
ans+=s[i]
print(ans)
|
print('Yes'if len(set(list(map(int,input().split()))))==1else'No')
| 0 | null | 47,397,676,231,008 | 120 | 231 |
import collections
K = int(input())
if K < 10:
print(K)
exit()
q = collections.deque()
for i in range(1, 10):
q.append(i)
i = 9
while True:
x = q.popleft()
lsk = x % 10
shifted = x * 10
if lsk != 0:
q.append(shifted + lsk - 1)
i += 1
if i == K:
print(shifted + lsk - 1)
break
q.append(shifted + lsk)
i += 1
if i == K:
print(shifted + lsk)
break
if lsk != 9:
q.append(shifted + lsk + 1)
i += 1
if i == K:
print(shifted + lsk + 1)
break
|
from collections import deque
n = int(input())
q = deque(range(1, 10))
for _ in range(n - 1):
x = q.popleft()
r = x % 10
y = 10 * x
if r == 0:
q.extend([y, y+1])
elif r == 9:
q.extend([y+8, y+9])
else:
q.extend([y+r-1, y+r, y+r+1])
print(q.popleft())
| 1 | 40,072,211,783,862 | null | 181 | 181 |
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
def sieve_of_eratosthenes(n):
if not isinstance(n,int):
raise TypeError("n is not int")
if n<2:
raise ValueError("n is not effective")
prime = [1]*(n+1)
for i in range(2,int(math.sqrt(n))+1):
if prime[i] == 1:
for j in range(2*i,n+1):
if j%i == 0:
prime[j] = 0
res = []
for i in range(2,n+1):
if prime[i] == 1:
res.append(i)
return res
class UnionFind:
def __init__(self,n):
self.parent = [i for i in range(n+1)]
self.rank = [0 for i in range(n+1)]
def findroot(self,x):
if x == self.parent[x]:
return x
else:
y = self.parent[x]
y = self.findroot(self.parent[x])
return y
def union(self,x,y):
px = self.findroot(x)
py = self.findroot(y)
if px < py:
self.parent[y] = px
else:
self.parent[px] = py
def same_group_or_no(self,x,y):
return self.findroot(x) == self.findroot(y)
def main(): #startline-------------------------------------------
n, x, y = map(int, input().split())
ans = [0]*(n-1)
for i in range(n-1):
for j in range(i + 1, n):
if j < x - 1 or y - 1 < i:
distance = j - i
else:
distance = min(j - i, abs(x - 1 - i) + abs(y - 1 - j) + 1)
ans[distance - 1] += 1
for i in range(n - 1):
print(ans[i])
if __name__ == "__main__":
main() #endline===============================================
|
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
ans = A[0]
if N%2 == 0:
ans += 2*sum(A[1:(N-2)//2+1])
else:
ans += 2*sum(A[1:(N-2)//2+1])+A[(N-2)//2+1]
print(ans)
| 0 | null | 26,545,608,006,808 | 187 | 111 |
def actual(n, k, h_list):
return len([h for h in h_list if h >= k])
n, k = map(int, input().split())
h_list = map(int, input().split())
print(actual(n, k, h_list))
|
total_people, min_height = map(int, input().split())
height = map(int, input().split())
rideable_people = 0
for i in height:
if i >= min_height:
rideable_people += 1
print(rideable_people)
| 1 | 179,109,427,394,440 | null | 298 | 298 |
N,K = map(int, input().split())
L = [0]*N
R = [0]*N
DP = [0]*(N+10)
DP[0] = 1
SDP = [0]*(N+10)
SDP[1] = 1
MOD=998244353
for i in range(K):
L[i],R[i] = map(int, input().split())
for i in range(1,N):
for j in range(K):
l = max(0,i-R[j])
r = max(0,i-L[j]+1)
DP[i] += SDP[r] - SDP[l]
SDP[i+1] = (SDP[i] + DP[i])%MOD
print(DP[N-1]%MOD)
|
MOD = 998244353
N, K = list(map(int, input().split()))
dp = [0] * (N+1)
dp[1] = 1
LR = []
for i in range(K):
l, r = list(map(int, input().split()))
LR.append([l, r])
for i in range(2, N+1):
dp[i] = dp[i-1]
for j in range(K):
l, r = LR[j]
dp[i] += dp[max(i-l, 0)] - dp[max(i-r-1, 0)]
dp[i] %= MOD
print((dp[N]-dp[N-1]) % MOD)
| 1 | 2,701,651,742,492 | null | 74 | 74 |
n, m = map(int, input().split())
a = list(map(int, input().split()))
num1 = a[0]
num2 = 0
while num1 % 2 == 0:
num1 //= 2
num2 += 1
gc = 2 ** num2
b = []
for i in a:
if i % gc != 0 or (i // gc) % 2 == 0:
print(0)
exit()
else:
b.append(i // gc)
from fractions import gcd
lcm = 1
for i in b:
lcm = (lcm * i) // gcd(lcm, i)
ans = m // (lcm * (gc // 2))
ans = (ans + 1) // 2
print(ans)
|
import sys
import fractions
from functools import reduce
readline = sys.stdin.buffer.readline
def main():
gcd = fractions.gcd
def lcm(a, b):
return a * b // gcd(a, b)
N, M = map(int, readline().split())
A = list(set(map(int, readline().split())))
B = A[::]
while not any(b % 2 for b in B):
B = [b // 2 for b in B]
if not all(b % 2 for b in B):
print(0)
return
semi_lcm = reduce(lcm, (a // 2 for a in A))
print((M // semi_lcm + 1) // 2)
return
if __name__ == '__main__':
main()
| 1 | 101,787,339,749,080 | null | 247 | 247 |
N = int(input())
S = [input() for i in range(N)]
d = {}
m = 0
for i in S:
if i in d:
d[i] += 1
if d[i] > m:
m = d[i]
else:
d[i] = 1
d = dict(sorted(d.items(), reverse=True))
a = {}
for i in d.keys():
if m <= d[i]:
a[i] = 0
a = sorted(a)
for i in a:
print(i)
|
import collections
N = int(input())
S = [input() for i in range(N)]
C = collections.Counter(S)
L = C.most_common()
ans = []
flag = 0
for n in range(len(C)):
if L[n][1] < flag:
break
else:
ans.append(L[n][0])
flag = (L[n][1])
ans.sort()
for i in range(len(ans)):
print(ans[i])
| 1 | 70,050,432,830,300 | null | 218 | 218 |
H1,M1,H2,M2,k = map(int,input().split())
h = ((H2-1)-H1)*60
m = (M2+60)-M1
print((h+m)-k)
|
h1,m1,h2,m2,k = map(int, input().split())
t1 = h1 * 60 + m1
t2 = h2 * 60 + m2
if t2 > t1:
awake = t2 - t1
else:
awake = 24 * 60 - t1 + t2
print(awake - k)
| 1 | 17,955,040,397,668 | null | 139 | 139 |
#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 # (string,3) 3回
#from collections import deque
#from collections import defaultdict
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(input())
H,W,K = readInts()
cake = [input() for _ in range(H)]
ans = []
no = 0
cnt = 0
for h in range(H):
if cake[h] == "."*W:
no += 1
continue
else:
cnt += 1
same = []
arrived = False
for w in range(W):
if cake[h][w] == "#":
if not arrived:
arrived = True
else:
cnt += 1
same.append(cnt)
for _ in range(no+1):
ans.append(same)
no = 0
for _ in range(no):
ans.append(ans[-1])
for a in ans:
print(*a,sep=" ")
|
h, w, k = map(int, input().split())
s = [list(input()) for _ in range(h)]
ans = [[0] * w for _ in range(h)]
start = 0
x = 1
cnt = 0
def sol(ans, s, x):
cnt = 0
start = 0
for i in range(len(s)):
if s[i].count("#") != 0:
y = i
break
for i in range(w):
if s[y][i] == "#":
cnt += 1
if i == w - 1 or (cnt == 1 and s[y][i + 1] == "#"):
for a in range(len(s)):
for b in range(start, i + 1):
ans[a][b] = x
start = i + 1
x += 1
cnt = 0
return x
for i in range(h):
if s[i].count("#") >= 1:
cnt += 1
if i == h - 1 or cnt == 1 and s[i + 1].count("#") >= 1:
x = sol(ans[start: i + 1], s[start: i + 1], x)
start = i + 1
cnt = 0
for i in range(h):
for j in range(w):
print(ans[i][j], end = " ")
print()
| 1 | 143,220,764,287,766 | null | 277 | 277 |
n=int(input())
p=round(n**0.5)+1
ans=[0]*n
for x in range(1,p):
for y in range(1,p):
for z in range(1,p):
k=x**2+y**2+z**2+x*y+y*z+z*x
k-=1
if 0<=k<=n-1:
ans[k]+=1
for i in ans:
print(i)
|
#coding: utf-8
import sys
c = [0 for i in range(26)]
in_list = []
for line in sys.stdin:
in_list.append(line)
for s in in_list:
for i in range(len(s)):
if ord(s[i]) >= ord('a') and ord(s[i]) <= ord('z'):
c[ord(s[i])-97] += 1
elif ord(s[i]) >= ord('A') and ord(s[i]) <= ord('Z'):
c[ord(s[i])-65] += 1
for i in range(26):
print(chr(ord('a')+i) + " : " + str(c[i]))
| 0 | null | 4,832,865,916,290 | 106 | 63 |
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
cnt = 0
for i in range(len(A)):
if i == 0:
continue
cnt += A[int(i/2)]
print(cnt)
|
def main():
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
ans = A[0]
kazu = (N-2)//2
amari = (N-2)%2
for i in range(1,kazu+1,1):
#print(i)
ans += (A[i]*2)
if amari==1:
ans += A[i+1]*amari
print(ans)
main()
| 1 | 9,085,094,159,142 | null | 111 | 111 |
n,k = input().split()
k = int(k)
#print(n,k)
p = [int(s) for s in input().split()]
p.sort()
#print(p)
#print(k)
p2 = p[0:k]
#print(p2)
s = sum(p)
#print(s)
print(sum(p2))
|
import sys
import math
char = "abcdefghijklmnopqrstuvwxyz"
cnt = {}
for S in sys.stdin:
for x in S:
x = x.lower()
if x not in cnt:
cnt[x] = 0
cnt[x] += 1
for c in char:
sys.stdout.write(c + " : ")
if c not in cnt:
print 0
else:
print cnt[c]
| 0 | null | 6,630,719,049,698 | 120 | 63 |
#!usr/bin/env python3
import math
import sys
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LIR(n):
return [LI() for i in range(n)]
class SegmentTree:
def __init__(self, size, f=lambda x,y : x+y, default=0):
self.size = 2**(size-1).bit_length()
self.default = default
self.dat = [default]*(self.size*2)
self.f = f
def update(self, i, x):
i += self.size
self.dat[i] = x
while i > 0:
i >>= 1
self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1])
def get(self, a, b=None):
if b is None:
b = a + 1
l, r = a + self.size, b + self.size
lres, rres = self.default, self.default
while l < r:
if l & 1:
lres = self.f(lres, self.dat[l])
l += 1
if r & 1:
r -= 1
rres = self.f(self.dat[r], rres)
l >>= 1
r >>= 1
res = self.f(lres, rres)
return res
def solve():
n,d,a = LI()
g = LIR(n)
g.sort()
X = [i for (i,_) in g]
s = SegmentTree(n)
ans = 0
for i in range(n):
x = g[i][0]
j = bisect.bisect_left(X,x-2*d)
h = g[i][1]-s.get(j,i)
if h <= 0:
continue
k = math.ceil(h/a)
ans += k
s.update(i,k*a)
print(ans)
return
#Solve
if __name__ == "__main__":
solve()
|
from collections import deque
n , d , a = map(int,input().split())
mon = [tuple(map(int,input().split())) for i in range(n)]
mon.sort()
p = deque(mon)
baku = deque()
cou = 0
ans = 0
while p:
nowx , nowh = p.popleft()
while baku:
bx , bh = baku.popleft()
if bx >= nowx:
baku.appendleft((bx,bh))
break
elif bx < nowx:
cou -= bh
if nowh <= cou:
continue
elif nowh > cou:
k = -((-nowh+cou)//a)
ans += k
cou += a*k
baku.append((nowx+2*d,a*k))
print(ans)
| 1 | 82,292,015,115,548 | null | 230 | 230 |
import math
x1, y1, x2, y2 = map(float, raw_input().split())
L = math.sqrt((x1-x2)**2 + (y1-y2)**2)
print L
|
import math
a,b,c=map(float,input().split())
if c<90:
e=c*math.pi/180
S=a*b*1/2*math.sin(e)
t=a**2+b**2-2*a*b*math.cos(e)
r=math.sqrt(t)
L=a+b+r
h=b*math.sin(e)
print(S)
print(L)
print(h)
if c==90:
e=c*math.pi/180
S=a*b*1/2*math.sin(e)
t=a**2+b**2-2*a*b*math.cos(e)
r=math.sqrt(t)
L=a+b+r
h=b
print(S)
print(L)
print(h)
if c>90:
e=c*math.pi/180
d=180*math.pi/180
f=d-e
S=a*b*1/2*math.sin(e)
t=a**2+b**2-2*a*b*math.cos(e)
r=math.sqrt(t)
L=a+b+r
h=b*math.sin(f)
print(S)
print(L)
print(h)
| 0 | null | 161,689,077,008 | 29 | 30 |
import sys
n = int(input())
dic = set()
input_ = [x.split() for x in sys.stdin.readlines()]
for c, s in input_:
if c == 'insert':
dic.add(s)
else:
if s in dic:
print('yes')
else:
print('no')
|
n=int(input())
dict={}
res=[]
for i in range(n):
ss=input().split()
if ss[0]=='insert':
dict[ss[1]]=i
elif ss[0]=='find':
if dict.__contains__(ss[1]):
res.append('yes')
else:
res.append('no')
for i in res:
print(i)
| 1 | 77,572,271,260 | null | 23 | 23 |
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
ans = 1
cnt = [0] * 3
for i in range(n):
t = 0
first = True
for j in range(3):
if cnt[j] == a[i]:
t += 1
if first:
first = False
cnt[j] += 1
ans = (ans * t) % mod
print(ans)
|
from sys import stdin
readline = stdin.readline
def i_input(): return int(readline().rstrip())
def i_map(): return map(int, readline().rstrip().split())
def i_list(): return list(i_map())
def main():
A, B, C, D = i_map()
print(max([A * C, A * D, B * C, B * D]))
if __name__ == "__main__":
main()
| 0 | null | 66,831,260,712,188 | 268 | 77 |
def mod_pow(a, n, mod):
"""
二分累乗法による a^n (mod m)の実装
:param a: 累乗の底
:param n: 累乗の指数
:param mod: 法
:return: a^n (mod m)
"""
result = 1
a_n = a
while n > 0:
if n & 1:
result = result * a_n % mod
a_n = a_n * a_n % mod
n >>= 1
return result
def mod_inverse(a, mod):
"""
フェルマーの小定理による a^-1 ≡ 1 (mod m)の実装
aの逆元を計算する
a^-1 ≡ 1 (mod m)
a * a^-2 ≡ 1 (mod m)
a^-2 ≡ a^-1 (mod m)
:param a: 逆元を計算したい数
:param mod: 法
:return: a^-1 ≡ 1 (mod m)
"""
return mod_pow(a=a, n=mod - 2, mod=mod)
def mod_combination(n, k, mod):
fact_n = 1
fact_k = 1
for i in range(k):
fact_n *= (n - i)
fact_n %= mod
fact_k *= (i + 1)
fact_k %= mod
fact_n *= mod_inverse(fact_k, mod)
return fact_n % mod
N, A, B = map(int, input().split(' '))
MOD = 10 ** 9 + 7
print((mod_pow(2, N, MOD) - 1 - mod_combination(N, A, MOD) - mod_combination(N, B, MOD)) % MOD)
|
import sys
input = sys.stdin.readline
n=int(input())
L=list(map(int,input().split()))
if len(set(L))!=n:
print('NO')
else:
print('YES')
| 0 | null | 70,091,397,363,870 | 214 | 222 |
N,K=map(int,input().split())
A=list(map(int,input().split()))
a=A[:]
for _ in range(K):
t=[0]*(N+1)
for i in range(N):
ti=a[i]
t[max(0,i-ti)]+=1
t[min(N,i+ti+1)]-=1
for i in range(N):
t[i+1]+=t[i]
a=t[:N]
if min(a)==N:
break
print(*a)
|
import numpy as np
from numba import njit
@njit #処理の並列化_これがない場合は'TLE'
def imos(n, a):
l=np.zeros((n+1), dtype = np.int64)
for i in range(n):
ai = a[i] # 光の強さ_これにより照らせる範囲が決まる
start = max(0, i - ai) #StartIndex_照らせる範囲
end = min(n, i + ai + 1) #EndIndex + 1_照らせる範囲
l[start] += 1 # 各々を'+1'と'-1'で表し...
l[end] -= 1
return np.cumsum(l)[:n] # 累積和をとる_cumulative sum
n, k = map(int, input().split())
a = list(map(int, input().split()))
for _ in range(k):
a = imos(n, a)
if a.min() == n: # すべての要素が最大値'n'になるとbreak
break
print(*a)
| 1 | 15,468,498,470,400 | null | 132 | 132 |
import sys
def input():
return sys.stdin.readline().strip()
sys.setrecursionlimit(20000000)
MOD = 10 ** 9 + 7
INF = float("inf")
def main():
H1, M1, H2, M2, K = map(int, input().split())
if M2 >= M1:
time = (H2 - H1) * 60 + M2 - M1
else:
time = (H2 - H1 - 1) * 60 + M2 + 60 - M1
answer = max(time - K, 0)
print(answer)
if __name__ == "__main__":
main()
|
import sys
sys.setrecursionlimit(300000)
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')
N = I()
A = LMI()
ans = 0
for i, a in enumerate(A):
if i % 2 == 0 and a % 2 != 0:
ans += 1
print(ans)
| 0 | null | 12,951,067,989,080 | 139 | 105 |
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
A.sort(reverse=True)
if A[M-1] >= sum(A)/(4*M) :
print("Yes")
else:
print("No")
|
#! python3
a, b = [int(x) for x in input().strip().split(' ')]
if a > b:
print('a > b')
elif a < b:
print('a < b')
else:
print('a == b')
| 0 | null | 19,534,681,445,568 | 179 | 38 |
n = int(input())
ans = 0
for i in range(1, n):
x = n//i
y = x-1 if n==x*i else x
ans += y
print(ans)
|
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 24 12:23:05 2020
@author: vivek
"""
n,d=[int(i) for i in input().strip().split(" ")]
ans=0
for _ in range(n):
x,y=[int(i) for i in input().strip().split(" ")]
if x*x+y*y<=d*d:
ans+=1
print(ans)
| 0 | null | 4,240,453,796,370 | 73 | 96 |
#B - Mix Juice
N,K = map(int,input().split())
p = list(map(int,input().split()))
p_sorted = sorted(p,reverse = False)
ans = sum(p_sorted[:K])
print(ans)
|
while True:
h,w=map(int,input().split())
if(h==0):
break
for i in range(h):
if i==0 or i==h-1:
for j in range(w):
print("#",end="")
print()
else:
for j in range(w):
if j==0 or j==w-1:
print("#",end="")
else:
print(".",end="")
print()
print()
| 0 | null | 6,290,853,528,636 | 120 | 50 |
inputa = input()
print(inputa.swapcase())
|
import sys
readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')
def solve():
n = ni()
a = sorted(nl(), reverse=True)
print(sum(a[:n//2]) + sum(a[1:(n+1)//2]))
return
solve()
| 0 | null | 5,293,649,901,120 | 61 | 111 |
import math
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
dist = abs(a-b)
pace = abs(v) - abs(w)
if pace <= 0:
print('NO')
elif math.ceil(dist / pace) > t:
print('NO')
else:
print('YES')
|
a,v = map(int, input().split())
b,w = map(int, input().split())
t = int(input())
ans = "NO"
if a > b: a,b = a*(-1), b*(-1)
if a == b: ans = "YES"
elif a < b:
if v > w and (b-a) <= (v-w)*t: ans = "YES"
print(ans)
| 1 | 15,202,458,634,080 | null | 131 | 131 |
import collections
n=int(input())
box=[]
for i in range(n):
tmp=str(input())
box.append(tmp)
l=len(collections.Counter(box))
print(l)
|
N = int(input())
A = [int(i) for i in input().split()]
P = [0]*N
for i in range(N-1):
P[A[i]-1] += 1
for i in range(N):
print(P[i])
| 0 | null | 31,556,314,957,370 | 165 | 169 |
K = input()
S = input()
LS = len(S)
IK = int(K)
if LS <= IK:
print(S)
elif LS > IK:
print(S[0:IK] + '...')
|
N = int(input())
S = list(input())
R = []
G = []
B = [0 for _ in range(N)]
b_cnt = 0
for i in range(N):
if S[i] == 'R':
R.append(i)
elif S[i] == 'G':
G.append(i)
else:
B[i] = 1
b_cnt += 1
answer = 0
for r in R:
for g in G:
answer += b_cnt
if (g-r)%2 == 0 and B[(r+g)//2] == 1:
answer -= 1
if 0 <= 2*g-r < N and B[2*g-r] == 1:
answer -= 1
if 0 <= 2*r-g < N and B[2*r-g] == 1:
answer -= 1
print(answer)
| 0 | null | 28,069,610,574,148 | 143 | 175 |
N=int(input())
lst=list(map(int,input().split(" ")))
now=0
for i in range(N):
if lst[i]==now+1:
now+=1
if now == 0:
print(-1)
else:
print(N-now)
|
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()
| 1 | 115,114,399,788,960 | null | 257 | 257 |
n = int(input())
print(-(-n//2))
|
import math
n = int(input())
paper = math.ceil(n/2)
print(paper)
| 1 | 59,222,453,647,500 | null | 206 | 206 |
import math
mod = 1000000007
n = int(input())
zero = 0
dic = {}
dic[(0, 1.5)] = 0
dic[(1.5, 0)] = 0
for i in range(n):
ai, bi = map(int, input().split())
idx = (ai, bi)
if ai < 0:
ai, bi = -ai, -bi
if idx == (0, 0):
zero += 1
elif idx[0] == 0:
dic[(0, 1.5)] += 1
elif idx[1] == 0:
dic[(1.5, 0)] += 1
else:
g = math.gcd(abs(ai), abs(bi))
ai = ai // g
bi = bi // g
idx = (ai, bi)
if idx in dic:
dic[idx] += 1
else:
dic[idx] = 1
ans = 1
already = set([])
for key, value in dic.items():
if key in already: continue
a, b = key
if a == 1.5 or b == 1.5:
pair1 = dic[(0, 1.5)]
pair2 = dic[(1.5, 0)]
ans = (ans * (pow(2, pair1, mod)+pow(2, pair2, mod)-1)) % mod
already.add((0, 1.5))
already.add((1.5, 0))
else:
if b > 0: idx = (b, -a)
else: idx = (-b, a)
if idx in dic:
pair1 = dic[key]
pair2 = dic[idx]
ans = (ans * (pow(2, pair1, mod)+pow(2, pair2, mod)-1)) % mod
already.add(key)
already.add(idx)
else:
pair1 = dic[key]
ans = (ans * pow(2, pair1, mod)) % mod
already.add(key)
ans = (ans + zero - 1) % mod
print(ans)
|
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**9)
#from functools import lru_cache
def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()
#import numpy as np
from math import gcd
from collections import defaultdict
def main():
n=II()
mod=10**9+7
ans=1
cnt=0
d=defaultdict(int)
for _ in range(n):
a,b=MI()
if a==b==0:
cnt+=1
elif a==0:
d[(1,0)]+=1
elif b==0:
d[(0,-1)]+=1
else:
g=gcd(abs(a),abs(b))
if a*b>0:
d[(abs(a//g),abs(b//g))]+=1
else:
d[(abs(a//g),-abs(b//g))]+=1
s=set()
for a,b in list(d):
#print(a,b,s)
if (a,b) in s:
continue
if b>=0:
x=d[(a,b)]
y=d[(b,-a)]
s.add((a,b))
s.add((b,-a))
else:
x=d[(a,b)]
y=d[(-b,a)]
s.add((a,b))
s.add((-b,a))
ans*=2**x+2**y-1
ans%=mod
ans+=cnt-1
print(ans%mod)
if __name__ == "__main__":
main()
| 1 | 20,932,189,774,900 | null | 146 | 146 |
import math
a,b,H,M=map(int,input().split())
theta_a = math.pi/6 * (H+M/60)
theta_b = math.pi*2*M/60
ans = math.sqrt((b*math.cos(theta_b) - a*math.cos(theta_a))**2 + (b*math.sin(theta_b) - a*math.sin(theta_a))**2)
print(ans)
|
import numpy as np
a,b,h,m=[int(i) for i in input().split()]
def get_angle(h,m):
long_angle=2*np.pi*m/60
short_angle=2*np.pi*h/12+(2*np.pi/12)*m/60
big_angle=max(long_angle,short_angle)
small_angle = min(long_angle, short_angle)
angle=min(big_angle-small_angle,2*np.pi-big_angle+small_angle)
return angle
def yogen(a,b,theta):
ans=a**2+b**2-2*a*b*np.cos(theta)
return ans**0.5
print(yogen(a,b,get_angle(h,m)))
| 1 | 20,245,104,858,368 | null | 144 | 144 |
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
q = int(input())
counter = Counter(a)
sum_res = sum(a) # はじめの合計、名前がsumだとsum関数とかぶってよくないので
# q回操作します。ループ変数は使わないので_とします(Pythonの慣習)
for _ in range(q):
before, after = map(int, input().split())
# 合計を変更します
sum_res -= before * counter[before]
sum_res += after * counter[before]
# 個数を変更します
counter[after] += counter[before]
counter[before] = 0
print(sum_res)
|
from collections import Counter
def solve(string):
n, *aqbc = map(int, string.split())
a, _, bc = aqbc[:n], aqbc[n], aqbc[n + 1:]
s = sum(a)
t = Counter(a)
ans = []
for b, c in zip(*[iter(bc)] * 2):
if b in t.keys():
s += (c - b) * t[b]
t[b], t[c] = 0, t[b] + t[c]
ans.append(s)
return "\n".join(map(str, ans))
if __name__ == '__main__':
import sys
print(solve(sys.stdin.read().strip()))
| 1 | 12,200,807,436,032 | null | 122 | 122 |
def fina(n, fina_list):
if n <= 1:
fina_list[n] = 1
return fina_list[n]
elif fina_list[n]:
return fina_list[n]
else:
fina_list[n] = fina(n-1, fina_list) + fina(n-2, fina_list)
return fina_list[n]
n = int(input())
fina_list = [None]*(n + 1)
print(fina(n, fina_list))
|
print(f'A{["B","R"]["B"==input()[1]]}C')
| 0 | null | 12,126,737,414,286 | 7 | 153 |
from bisect import bisect_right
N,D,A=map(int,input().split())
X,H=[None]*N,{}
for i in range(N):
X[i],H[X[i]]=map(int,input().split())
X.sort()
f=[0]*N
ans=i=0
while i<N:
if i>0:
f[i]+=f[i-1]
if f[i]*A<H[X[i]]:
k=-((f[i]*A-H[X[i]])//A)
f[i]+=k
ans+=k
j=bisect_right(X,X[i]+(D<<1))
if j<N:
f[j]-=k
i+=1
print(ans)
|
N, D, A = map(int, input().split())
H = [list(map(int, input().split())) for i in range(N)]
H.sort(key = lambda x:x[0])
INF = int(1e18)
H.append((INF, INF))
ans = 0
S = [0] * (N + 1)
l, r = 0, 0
while l < N:
while H[r][0] - H[l][0] <= D * 2: r += 1
h = H[l][1] - S[l]
num = (h - 1) // A + 1 if h > 0 else 0
ans += num
S[l] += A * num
S[r] -= A * num
l += 1
S[l] += S[l - 1]
print(ans)
| 1 | 82,470,559,846,728 | null | 230 | 230 |
from collections import deque
mod = int(1e9+7)
def add(a, b):
c = a + b
if c >= mod:
c -= mod
return c
def main():
n, m = map(int,raw_input().split())
adj_list = [[] for _ in range(n+5)]
q = deque()
ans = [-1] * (n+5)
failed = False
for _ in range(m):
a, b = map(int,raw_input().split())
adj_list[a].append(b)
adj_list[b].append(a)
q.append(1)
#print(adj_list)
visited = set()
visited.add(1)
while len(q):
sz = len(q)
for _ in range(sz):
cur = q.popleft()
for nei in adj_list[cur]:
if nei not in visited:
ans[nei] = cur
q.append(nei)
visited.add(nei)
print('Yes')
for i in range(2, n+1):
print(ans[i])
main()
|
def dijkstra(v, G):
import heapq
ret = [10 ** 10] * len(G)
ret[v] = 0
q = [(ret[i], i) for i in range(len(G))]
heapq.heapify(q)
while len(q):
tmpr, u = heapq.heappop(q)
if tmpr == ret[u]:
for w in G[u]:
if ret[w] > ret[u] + 1:
ret[w] = ret[u] + 1
heapq.heappush(q, (ret[w], w))
return ret
N, M = map(int, input().split())
G, ans = {i: [] for i in range(N)}, [-1] * N
for _ in range(M):
A, B = map(int, input().split())
G[A - 1].append(B - 1)
G[B - 1].append(A - 1)
d = dijkstra(0, G)
for a in range(N):
for b in G[a]:
if d[a] - d[b] == 1:
ans[a] = b + 1
print("Yes")
for a in ans[1:]:
print(a)
| 1 | 20,401,356,992,000 | null | 145 | 145 |
from collections import defaultdict
n,k=map(int,input().split())
a=list(map(int,input().split()))
a[0]=(a[0]-1)%k
for i in range(n-1):a[i+1]=(a[i+1]+a[i]-1)%k
d=defaultdict(int)
ans=0
d[0]=1
for i in range(n):
if i==k-1:d[0]-=1
if i>=k:d[a[i-k]]-=1
ans+=d[a[i]]
d[a[i]]+=1
print(ans)
|
from collections import defaultdict
n, k = map(int, input().split())
seq = list(map(int, input().split()))
count = defaultdict(int)
count[0] = 1
prefix = [0]*(n+1)
ans = 0
for i in range(n):
pre = prefix[i+1] = (prefix[i] + seq[i] - 1)%k
if i >= k - 1:
count[prefix[i - k + 1]] -= 1
ans += count[pre]
count[pre] += 1
print(ans)
| 1 | 137,428,929,002,502 | null | 273 | 273 |
from collections import Counter
S = input()
C = Counter()
MOD = 2019
n = 0
for i, s in enumerate(S[::-1]):
s = int(s)
n += pow(10, i, MOD) * s % MOD
C[n % MOD] += 1
C[0] += 1
ans = 0
for v in C.values():
ans += v * (v - 1) // 2
print(ans)
|
s=list(map(int,input()))
c=0
cnt=[0]*2019
cnt[0]+=1
for k in range(len(s)-1,-1,-1):
c=(c+s[k]*pow(10,len(s)-1-k,2019))%2019
cnt[c]+=1
print(sum(x*(x-1)//2 for x in cnt))
| 1 | 30,958,663,064,032 | null | 166 | 166 |
from itertools import combinations_with_replacement as C
N, M, Q = map(int, input().split())
a = [0] * Q
b = [0] * Q
c = [0] * Q
d = [0] * Q
for i in range(Q):
a[i], b[i], c[i], d[i] = map(int, input().split())
A_ = list(range(1, M + 1))
A_ = list(C(A_, N))
ans = 0
ans_ = 0
for A in A_:
ans_ = 0
for i in range(Q):
if A[b[i] - 1] - A[a[i] - 1] == c[i]:
ans_ += d[i]
if ans < ans_:
ans = ans_
print(ans)
|
K=int(input())
S=input()
M=10**9+7
#----------------------------------------------------------------
f=1
Fact=[f]
for i in range(1,len(S)+K+1):
f=(f*i)%M
Fact.append(f)
Inv=[0]*(len(S)+K+1)
g=pow(f,M-2,M)
Inv=[0]*(len(S)+K+1)
Inv[-1]=g
for j in range(len(S)+K-1,-1,-1):
Inv[j]=(Inv[j+1]*(j+1))%M
def nCr(n,r):
if 0<=r<=n:
return (Fact[n]*Inv[r]*Inv[n-r])%M
else:
return 0
A=len(S)
T=0
for i in range(K+1):
T=(T+nCr(A+K-1-i,K-i)*pow(25,K-i,M)*pow(26,i,M))%M
print(T)
| 0 | null | 20,121,632,068,288 | 160 | 124 |
# A - Connection and Disconnection
def count(s, c):
count_ = s.count(c*2)
while c*3 in s:
s = s.replace(c*3, c+'_'+c)
while c*2 in s:
s = s.replace(c*2, c+'_')
return min(count_, s.count('_'))
def get_startswith(s, c):
key = c
while s.startswith(key+c):
key += c
return len(key)
def get_endswith(s, c):
key = c
while s.endswith(key+c):
key += c
return len(key)
import string
S = input()
K = int(input())
lower = string.ascii_lowercase
ans = 0
if S[0] == S[-1:]:
start = get_startswith(S, S[0])
end = get_endswith(S, S[0])
if start == end == len(S):
print(len(S) * K // 2)
else:
ans = 0
ans += start // 2
ans += end // 2
ans += ((start + end) // 2) * (K - 1)
for c in lower:
ans += count(S[start:len(S)-end], c) * K
print(ans)
else:
for c in lower:
ans += count(S, c)
print(ans * K)
|
s = list(input())
k = int(input())
if len(set(s)) == 1:
print((len(s)*k)//2)
exit()
def n_change(sss):
s = sss.copy()
x = 0
for i in range(1, len(s)):
if s[i] == s[i-1]:
s[i] = "X"
x += 1
return x
print(n_change(s) + (k-1) * (n_change(2*s) - n_change(s)))
| 1 | 176,105,648,213,418 | null | 296 | 296 |
n, a, b = map(int, input().split())
c = a + b
div = n // c
mod = n % c
if mod > a:
mod = a
ans = div * a + mod
print(ans)
|
url = "https://atcoder.jp//contests/abc156/tasks/abc156_a"
def main():
n, r = list(map(int, input().split()))
print(r) if n >= 10 else print(r + 100 * (10 - n))
if __name__ == '__main__':
main()
| 0 | null | 59,582,810,599,920 | 202 | 211 |
# h, a = map(int, input().split())
# from collections import OrderedDict
# d = OrderedDict()
# a = list(input().split())
b = list(map(int, input().split()))
print("Yes" if len(set(b)) == 2 else "No")
|
W = input().lower()
ans = 0
while 1:
T = input()
if T == "END_OF_TEXT":
break
ans += T.lower().split().count(W)
print(ans)
| 0 | null | 34,869,876,710,460 | 216 | 65 |
N=int(input())
A=map(int, input().split())
P=1000000007
ans = 1
cnt = [3 if i == 0 else 0 for i in range(N + 1)]
for a in A:
ans=ans*cnt[a]%P
if ans==0:
break
cnt[a]-=1
cnt[a+1]+=1
print(ans)
|
while True:
i = input().split()
m, f, r = map(int, i)
if m == -1 and f == -1 and r == -1:
break
if m == -1 or f == -1:
print('F')
elif m+f >= 80:
print('A')
elif m+f < 80 and m+f >= 65:
print('B')
elif m+f < 65 and m+f >= 50:
print('C')
elif m+f < 50 and m+f >=30:
if r >= 50:
print('C')
else:
print('D')
else:
print('F')
| 0 | null | 65,587,206,425,610 | 268 | 57 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.