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
|
---|---|---|---|---|---|---|
def main():
alphabets = "abcdefghijklmnopqrstuvwxyz"
c = input()
print(alphabets[alphabets.index(c)+1])
main() | # 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) | 0 | null | 45,848,882,864,080 | 239 | 16 |
def answer(k:int, s:str) -> str:
if len(s) <= k:
return s
else:
return s[:k] + '...'
k = int(input())
s = input()
print(answer(k, s)) | while(True):
n=int(input())
if(n==0):
break
val=list(map(int, input().split()))
sum=0
for i in val:
sum+=i
mean=sum/n
disp=0
for i in val:
disp+=(i-mean)**2
disp=disp/n
print(disp**0.5)
| 0 | null | 10,015,585,057,988 | 143 | 31 |
N = int(input())
D = [list(map(int,input().split())) for _ in range(N)]
cnt = 0
for i in range(N):
cnt = cnt + 1 if D[i][0] == D[i][1] else 0
if cnt == 3:
print('Yes')
exit()
print('No') | N=int(input())
ans = "No"
n=0
for _ in range(N):
x, y = map(int, input().split())
if x == y:
n+=1
else:
n = 0
if n >= 3:
ans="Yes"
print(ans)
| 1 | 2,525,384,494,468 | null | 72 | 72 |
import sys
import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict
# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846
def read_str(): return sys.stdin.readline().strip()
def read_int(): return int(sys.stdin.readline().strip())
def read_ints(): return map(int, sys.stdin.readline().strip().split())
def read_ints2(x): return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)
def Main():
n, m = read_ints()
a = read_int_list()
a = [x // 2 for x in a]
lcm = 1
for x in a:
lcm *= x // math.gcd(lcm, x)
for x in a:
if lcm // x % 2 == 0:
print(0)
exit()
print(math.ceil((m // lcm) / 2))
if __name__ == '__main__':
Main() | X,K,D = map(int, input().split())
X = abs(X)
if X//D > K:
print(X-(D*K))
exit()
if (K-X//D)%2:
print(D-X%D)
else:
print(X%D) | 0 | null | 53,242,309,860,740 | 247 | 92 |
import math,sys
for e in sys.stdin:
a,b=list(map(int,e.split()));g=math.gcd(a,b)
print(g,a*b//g)
| # coding=utf-8
def solve_gcd(number1: int, number2: int) -> int:
two_list = [number1, number2]
two_list.sort()
if two_list[1] % two_list[0] == 0:
return two_list[0]
r = two_list[1] % two_list[0]
return solve_gcd(two_list[0], r)
def solve_lcm(number1: int, number2: int, number3: int) -> int:
return number1*number2//number3
if __name__ == '__main__':
while True:
try:
a, b = map(int, input().split())
except EOFError:
break
gcd = solve_gcd(a, b)
lcm = solve_lcm(a, b, gcd)
print(gcd, lcm) | 1 | 582,146,460 | null | 5 | 5 |
A,B = map(int, input().split())
if A < B:
print(str(A) * B)
else:
print(str(B) * A)
| a,b=map(int,input().split())
s=[''.join([str(a)]*b),''.join([str(b)]*a)]
print(sorted(s)[0]) | 1 | 84,790,762,773,252 | null | 232 | 232 |
# cording: utf-8
num = []
while True:
list = input().rstrip().split(" ")
if str(list[1]) == "?":
break
num.append(list)
for i in range(len(num)):
if str(num[i][1]) == "+":
print(int(num[i][0]) + int(num[i][2]))
elif str(num[i][1]) == "-":
print(int(num[i][0]) - int(num[i][2]))
elif str(num[i][1]) == "*":
print(int(num[i][0]) * int(num[i][2]))
else:
print(int(num[i][0]) // int(num[i][2])) | import sys
n = int(input())
A=[[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)]
#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 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 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 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 0 0 0 0 0 0 0],
# [0 0 0 0 0 0 0 0 0 0]]]
#?£? Building = b
#??? Floor = f
#??? Room = r
#??° Number = num
for i in range(n):
b,f,r,num = input().strip().split()
A[int(b)-1][int(f)-1][int(r)-1]+=int(num)
for i in range(4):
for j in range(3):
print('',' '.join(map(str,A[i][j])))
if i!=3:
print('#'*20) | 0 | null | 888,939,488,890 | 47 | 55 |
# coding: utf-8
import sys
from collections import deque
n, q = map(int, input().split())
total_time = 0
tasks = deque(map(lambda x: x.split(), sys.stdin.readlines()))
for task in tasks:
task[1] = int(task[1])
while tasks:
t = tasks.popleft()
if t[1] <= q:
total_time += t[1]
print(t[0], total_time)
else:
t[1] -= q
total_time += q
tasks.append(t) | import sys
from collections import deque
n,q = map(int,input().split())
f = lambda n,t: (n,int(t))
queue = deque(f(*l.split()) for l in sys.stdin)
t = 0
while queue:
name,time = queue.popleft()
t += min(q, time)
if time > q:
queue.append((name, time-q))
else:
print(name,t)
| 1 | 41,882,707,218 | null | 19 | 19 |
import numpy as np
a,b=map(int,input().split())
print(max(a-2*b,0)) | import sys
import numpy as np
from collections import Counter
# 全探索なら、 2**6 * 2**6 (4000)
# > 4000 * (6**2)
# bit全探索でOK
# ------------------------------------------
h, w, num = map(int, input().split())
data = []
for _ in range(h):
# 一文字ずつListへ格納
temp = list(input())
data.append(temp)
#data = [input() for _ in range(h)]
# print(data)
'''
count = Counter(data)
most = count.most_common()
print(most)
'''
ans = 0
# 縦の全Loop
for i in range(2 ** h):
for j in range(2 ** w):
#print(i, j)
*temp, = data
temp = np.array(temp)
for k in range(h):
if (i >> k & 1):
temp[k, :] = 'aa'
for l in range(w):
if (j >> l & 1):
temp[:, l] = 'aa'
count = np.where(temp == '#')[0]
#print(count, len(count))
if (len(count) == num):
# print('add')
ans += 1
else:
pass
print(ans)
| 0 | null | 88,186,384,841,440 | 291 | 110 |
x,y=map(int,input().split())
c=0
d=0
if x==1:
c=300000
elif x==2:
c=200000
elif x==3:
c=100000
if y==1:
d=300000
elif y==2:
d=200000
elif y==3:
d=100000
print(c+d if c+d!=600000 else 1000000) | def main():
N, P = (int(i) for i in input().split())
L = [int(s) for s in input()][::-1]
ans = 0
if P == 2 or P == 5:
for i, e in enumerate(L):
if e % P == 0:
ans += N-i
else:
A = [0]*N
d = 1
for i, e in enumerate(L):
A[i] = (e*d) % P
d *= 10
d %= P
S = [0]*(N+1)
for i in range(N):
S[i+1] = S[i] + A[i]
S[i+1] %= P
from collections import Counter
c = Counter(S)
for v in c.values():
ans += v*(v-1)//2
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 99,168,658,453,682 | 275 | 205 |
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0
N = k()
ans = N-1
for i in range(1,int(N**0.5)+1):
if N % i == 0:
b = N // i
ans = min(ans, b+i-2)
print(ans)
| a = int(input())
b = int(input())
if a == 2 and b == 3 or b == 2 and a == 3:
print('1')
elif a == 1 and b == 2 or b == 1 and a == 2:
print('3')
else:
print('2')
| 0 | null | 135,834,704,374,238 | 288 | 254 |
N = int(input())
if N == 1:
print(0)
exit()
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
ans = 0
l = factorization(N)
for i,j in l:
k = 1
while j >= k:
ans += 1
j -= k
k += 1
print(ans) |
def printComparison(a, b):
"""
a: int
b: int
outputs the comparison result of a and b
>>> printComparison(1, 2)
a < b
>>> printComparison(4, 3)
a > b
>>> printComparison(5, 5)
a == b
>>> printComparison(-20, -10)
a < b
"""
operator = ''
if a > b:
operator = '>'
elif a < b:
operator = '<'
else:
operator = '=='
print('a', operator, 'b')
if __name__ == '__main__':
ival = input().split(' ')
printComparison(int(ival[0]), int(ival[1])) | 0 | null | 8,677,394,895,742 | 136 | 38 |
n=str(input())
a=list(n)
b=0
for i in a:
b=b+int(i)
if b%9==0:
print("Yes")
else:
print("No") | import sys
a, b, c = map(int, sys.stdin.readline().split())
if(a < b < c):
print("Yes")
else:
print("No") | 0 | null | 2,358,231,420,648 | 87 | 39 |
# ABC168D
# https://atcoder.jp/contests/abc168/tasks/abc168_d
n,m=map(int, input().split())
ab=[[]for _ in range(n)]
for i in range(m):
a,b = list(map(int, input().split()))
a,b = a-1, b-1
ab[a].append(b)
ab[b].append(a)
'''
まず両方を追加する考えがなかった。
浅い部屋からも深い部屋からも参照できる。
その代わりに visitedで考えなくて良い部屋を記録している。
部屋1につながっているのはもっとも浅い部屋でそこから考えることがきっかけになる?
'''
#print(ab)
ans = [0]*n
visited={0}
stack=[0]
for i in stack:
'''
現在考えている部屋を stack、そこにつながる部屋 ab[i]として考える。
stack=[0]なので1の部屋から始める。なので深さ1の部屋が ab[i](ab[0])で分かる。
i==0の始めの一周では、ab[i]は深さ1の部屋のリストであり、それぞれの部屋を jとして順番に考える。
(このように深さ1から考えられる+次に深さ2の部屋を求めるというのが上手くいく)
その現在考えている部屋 i(stackの循環)とそこにつながる部屋 j(abの循環)なので、
部屋 jはより浅い部屋 iを道しるべにすればよい。
しかし、ab[a], ab[b]と両方を追加しているので、浅い部屋も深い部屋も abには含まれている。
浅い部屋から順に考えているので、過去に調べた abの値は無視するために visitedを導入する。たぶん。
'''
for j in ab[i]:
#print(i,j,'----------------------')
if j in visited:
continue
stack.append(j)
visited.add(j)
ans[j]=i+1
#print('stack', stack)
#print('visited', visited)
#print('ans', ans)
check=0
for i in ans[1:]:
if i==0:check==1
if check:
print('No')
else:
print("Yes")
print(*ans[1:])
| from collections import deque
n, m = map(int, input().split())
eg = [[] for _ in range(n + 1)]
for _ in range(m):
a, b = map(int, input().split())
eg[a].append(b)
eg[b].append(a)
xs = [0] * (n + 1)
q = deque()
q.append(1)
seen = {1}
while len(q) > 0:
v = q.popleft()
for t in eg[v]:
if t in seen:
continue
q.append(t)
seen.add(t)
xs[t] = v
print("Yes")
print(*xs[2:], sep="\n")
| 1 | 20,565,448,781,052 | null | 145 | 145 |
s=input()
si=s[::-1]
a=s[:(len(s)-1)//2]
b=s[(len(s)+1)//2:]
if s == si :
if a == a[::-1] and b == b[::-1]:
print(("Yes"))
exit()
print("No") | x=input()
if x[-1]==("s"):
print(x+"es")
elif x[-1]!=("s"):
print(x+"s") | 0 | null | 24,163,334,028,512 | 190 | 71 |
import string
import sys
text = sys.stdin.read().lower()
for char in string.ascii_lowercase:
print(char, ':', text.count(char))
| h,w,K = map(int,input().split())
sij = [input() for j in range(h)]
num = 2**(h-1)
hon = 10**18
for i in range(num):
tmp = format(i,'0'+str(h)+'b')
#print(tmp,tmp,tmp,tmp)
yoko_hon = sum(list(map(int,tmp)))+1
blk = [0]*(yoko_hon)
#blk_num = 0
tmp_col = 0
tmp_hon = yoko_hon-1
flag = True
ok_flag = True
for j in range(w):
tmp_blk = [0]*(yoko_hon)
blk_num = 0
for k in range(h):
if tmp[k] == str(1):
blk_num += 1
#print(blk_num,tmp_blk)
tmp_blk[blk_num] += int(sij[k][j])
#print(blk[blk_num] , tmp_blk[blk_num],k)
if blk[blk_num] + tmp_blk[blk_num] > K:
flag = False
continue
#print(ok_flag,flag,tmp_blk,blk)
if flag == False:
for l in range(yoko_hon):
if tmp_blk[l] > K:
ok_flag = False
break
blk[l] = tmp_blk[l]
tmp_hon += 1
tmp_col = 0
flag = True
else:
for l in range(yoko_hon):
blk[l] += tmp_blk[l]
tmp_col += 1
if ok_flag == False:
break
#print(ok_flag)
if ok_flag == False:
ok_flag = True
continue
#exit()
hon = min(tmp_hon,hon)
print(hon) | 0 | null | 25,023,255,176,388 | 63 | 193 |
n = int(input())
s = input()
ans = 0
for i in range(1000):
i = str(i).zfill(3)
f = True
x = -1
for j in range(3):
x = s.find(i[j],x+1)
f = f and bool(x >= 0)
ans += f
print(ans)
| n=int(input())
s=input()
ans=0
for i in range(10):
if str(i) in s[:-2]:
s1=s.index(str(i))
for j in range(10):
if str(j) in s[s1+1:-1]:
s2=s[s1+1:].index(str(j))+s1+1
for k in range(10):
if str(k) in s[s2+1:]:
ans+=1
print(ans)
| 1 | 128,735,837,316,250 | null | 267 | 267 |
n = int(input())
ans = 0
ans += n // 500 * 1000
n %= 500
ans += n // 5 * 5
print(ans)
| n,k=[int(x) for x in input().split()]
d=[int(x) for x in input().split()]
t=[x for x in d if x>=k]
print(len(t)) | 0 | null | 110,820,981,877,748 | 185 | 298 |
n, x, m = map(int, input().split())
lis = [x]
flag = [-1 for i in range(m)]
flag[x] = 0
left = -1
right = -1
for i in range(n-1):
x = x**2 % m
if flag[x] >= 0:
left = flag[x]
right = i
break
else:
lis.append(x)
flag[x] = i+1
ans = 0
if left == -1:
ans = sum(lis)
else:
ans += sum(lis[0:left])
length = right - left + 1
ans += sum(lis[left:]) * ((n-left)//length)
ans += sum(lis[left:left+((n-left)%length)])
print(ans) | K=int(input())
S=input()
if len(S)<=K:
print(S)
else:
for i in range(K):
print(S[i],end="")
print("...") | 0 | null | 11,298,463,474,188 | 75 | 143 |
#!/usr/bin/env python3
import collections as cl
import sys
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def main():
N, M, Q = MI()
targets = [[] for i in range(Q)]
for i in range(Q):
target = LI()
targets[i] = target
ans = 0
for i in range(1, 2**(M+N)):
i_str = format(i, f"0{M+N-1}b")
A = []
tmp = 1
for k in range(len(i_str)):
if i_str[k] == "1":
tmp += 1
else:
A.append(tmp)
if len(A) != N:
continue
score = 0
for query in targets:
a, b, c, d = query
if A[b-1] - A[a-1] == c:
score += d
ans = max(ans, score)
print(ans)
main()
| N = input()
d = -999999999
R = input()
for i in range(N-1):
r = input()
d = max(d,(r-R))
R = min(R,r)
print d | 0 | null | 13,683,293,240,340 | 160 | 13 |
n, k = map(int, input().split())
a = list(map(int, input().split()))
def is_ok(l):
cnt = 0
for L in a:
cnt += L // l - 1
if L % l != 0:
cnt += 1
return cnt <= k
def meguru_bisect(ng, ok):
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
return ok
print(meguru_bisect(0, max(a))) | import sys
import math
def input():
return sys.stdin.readline().rstrip()
def main():
N, K = map(int, input().split())
A = list(map(int, input().split()))
ng = 0
ok = 10 ** 9 + 1
while ok - ng > 1:
mid = (ok + ng) // 2
ans = sum(list(map(lambda x: math.ceil(x / mid) - 1, A)))
# for i in range(N):
# ans += A[i]//mid -1
# if A[i]%mid !=0:
# ans +=1
if ans <= K:
ok = mid
else:
ng = mid
print(ok)
if __name__ == "__main__":
main()
| 1 | 6,492,857,713,628 | null | 99 | 99 |
A,B,C=map(int,input().split())
result=0
if A == B:
if A != C and B != C:
result+=1
elif A == C:
if A != B and B != C:
result+=1
elif B == A:
if B != A and C != B:
result+=1
elif B ==C:
if B != A and A != C:
result+=1
elif C == A:
if C != B and A == B:
result+=1
elif C == B:
if C != A and A == B:
result+=1
if result==1:
print('Yes')
else:
print('No') | a, b, c = map(int, input().split())
print("No" if a == b == c or a != b != c != a else "Yes") | 1 | 67,870,302,889,318 | null | 216 | 216 |
N,M,K = map(int, input().split())
MOD = 998244353
fact = [0] * (N+1)
inv = [0] * (N+1)
fact[0] = fact[1] = 1
inv[1] = 1
for i in range(2, N+1):
fact[i] = fact[i-1] * i % MOD
inv[i] = MOD - inv[MOD%i] * (MOD//i) % MOD # //で良いのかな?
def main():
if N == 1:
print(M)
return
num = M
nums = [M]
for i in reversed(range(1,N)):
num *= i*(M-1)
num *= inv[N-i]
num %= MOD
nums.append(num)
nums.reverse()
print(sum(nums[:K+1])%MOD)
if __name__ == "__main__":
main() | class Combination:
def __init__(self, n_max, mod=10**9+7):
self.mod = mod
self.modinv = self.make_modinv_list(n_max)
self.fac, self.facinv = self.make_factorial_list(n_max)
def __call__(self, n, r):
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
def make_factorial_list(self, n):
# 階乗のリストと階乗のmod逆元のリストを返す O(n)
# self.make_modinv_list()が先に実行されている必要がある
fac = [1]
facinv = [1]
for i in range(1, n+1):
fac.append(fac[i-1] * i % self.mod)
facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
return fac, facinv
def make_modinv_list(self, n):
# 0からnまでのmod逆元のリストを返す O(n)
modinv = [0] * (n+1)
modinv[1] = 1
for i in range(2, n+1):
modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
return modinv
if __name__ == "__main__":
N, M, K = map(int, input().split())
MOD = 998244353
ans = 0
comb = Combination(1000000, MOD)
for i in range(K+1):
ans += M * pow(M-1, N-i-1, MOD) * comb(N-1, i)
ans %= MOD
print(ans)
| 1 | 23,220,210,924,460 | null | 151 | 151 |
N = int(input())
ans = 0
for i in range(1, N + 1):
temp = i
while(temp <= N):
ans += temp
temp += i
print(ans) | target_word = raw_input()
text = ''
while True:
raw = raw_input()
if raw == "END_OF_TEXT":
break
# text += raw.strip('.') + ' '
text += raw + ' '
# ans = 0
print(text.lower().split().count(target_word))
# for word in text.lower().split():
# if word == target_word:
# ans += 1
# print(ans) | 0 | null | 6,442,366,716,238 | 118 | 65 |
import math
a,b,h,m = map(int,input().split())
x_h = a * math.sin(math.radians(0.5 * (60 * h + m)))
y_h = a * math.cos(math.radians(0.5 * (60 * h + m)))
x_m = b * math.sin(math.radians(6 * m))
y_m = b * math.cos(math.radians(6 * m))
print(math.sqrt((x_h-x_m)**2 + (y_h-y_m)**2)) | import math
A, B, H, M = map(int, input().split())
a = math.pi/360 * (H*60 + M)
b = math.pi/30 * M
# if abs(a - b) > math.pi:
# theta = 2 * math.pi - abs(a-b)
# else:
theta = abs(a-b)
L = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(theta))
print(L) | 1 | 19,903,111,517,932 | null | 144 | 144 |
while True:
n = int(input())
if n == 0:
break
s = list(map(int,input().split()))
m = 0
sum = 0
for i in range(n):
sum += s[i]
m = sum/n
tmp = 0
for i in range(n):
tmp += (s[i]-m)**2
print((tmp/n)**0.5) | import math
a, b, h, m = map(int, input().split())
ang = h * 30 - m * 5.5
ans = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(ang)))
print(ans)
| 0 | null | 10,212,068,953,470 | 31 | 144 |
N,K=map(int,input().split())
if N%K != 0:
if abs(K-N%K)<N:
print(K-N%K)
else:
print(N)
else:
print(0)
| def main():
N,K = map(int,input().split())
syo = N//K
amari = N%K
N = abs(amari-K)
ans = min(N,amari)
return ans
print(main())
| 1 | 39,287,447,453,628 | null | 180 | 180 |
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)
| import sys
from collections import deque
input = lambda: sys.stdin.readline().rstrip()
def main():
s = deque(input())
q = int(input())
reverse = False
for _ in range(q):
query = list(input().split())
if query[0] == '1':
reverse ^= True
else:
if reverse:
if query[1] == '1':
s.append(query[2])
else:
s.appendleft(query[2])
else:
if query[1] == '1':
s.appendleft(query[2])
else:
s.append(query[2])
s = ''.join(s)
if reverse:
s = s[::-1]
print(s)
if __name__ == '__main__':
main() | 0 | null | 53,151,389,807,428 | 194 | 204 |
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
AM=A[0:M]
asum=sum(A)
rate=asum/4/M
for idx in AM:
if idx<rate:
print('No')
break
else:
print('Yes') | S = input()
T = input()
if len(S) != len(T): quit()
sum = 0
for i in range(len(S)):
if T[i] != S[i]:
sum = sum + 1
print(sum) | 0 | null | 24,533,207,422,692 | 179 | 116 |
n, m, x = map(int, input().split())
c = [0] * n
a = [[]] * n
for i in range(n):
c[i], *a[i] = map(int, input().split())
ans = 2**32
for mask in range(1 << n):
res = [0] * m
cost = 0
for i in range(n):
if mask >> i & 1:
cost += c[i]
for j in range(m):
res[j] += a[i][j]
if all(v >= x for v in res):
ans = min(ans, cost)
print(ans if ans != 2**32 else -1) | INF = 10**9 + 7
def main():
N, M, X = (int(i) for i in input().split())
CA = [[int(i) for i in input().split()] for j in range(N)]
ans = INF
for bit in range(1 << N):
wakaru = [0]*M
cur = 0
for i in range(N):
if bit & (1 << i):
c, *A = CA[i]
cur += c
for j in range(M):
wakaru[j] += A[j]
if all(m >= X for m in wakaru):
ans = min(ans, cur)
if ans == INF:
print(-1)
else:
print(ans)
if __name__ == '__main__':
main()
| 1 | 22,277,814,129,682 | null | 149 | 149 |
n, k = (int(x) for x in input().split())
P = list(int(x) - 1 for x in input().split())
C = list(int(x) for x in input().split())
ans = -1e18
for si in range(n):
S = [C[si]]
x = P[si]
while x != si:
S.append(S[-1] + C[x])
x = P[x]
m = len(S)
if k <= m:
tmp = max(S[:k])
else:
loop = k // m
r = k % m
tmp = max(S[-1] * (loop - 1) + max(S), max(S))
if r != 0:
tmp = max(tmp, S[-1] * loop + max(S[:r]))
ans = max(ans, tmp)
print(ans) | n,k,c=map(int,input().split())
s=input()
l=[0]*k
r=[0]*k
ld=0
rd=n-1
for i in range(k):
j=k-1-i
while s[ld]=='x':
ld+=1
while s[rd]=='x':
rd-=1
l[i]=ld
ld+=1+c
r[j]=rd
rd-=1+c
for i in range(k):
if l[i]==r[i]:
print(l[i]+1)
| 0 | null | 23,046,263,377,500 | 93 | 182 |
import math
def standard_deviation() :
while True :
n = input()
if n==0 :
break
s_d = [0]*n
average = 0
standard = 0
s_d= map(float,raw_input().split())
for i in range(n):
average += s_d[i]
average /= float(n)
for i in range(n):
standard += pow(s_d[i]-average,2) / float(n)
print(math.sqrt(standard))
standard_deviation() | while True:
n = int(input())
s = []
if n == 0:
break
s = list(map(int, input().split()))
m = sum(s) / n
v = 0
for i in s:
v += (i - m) ** 2
ans = (v / n) ** (1/2)
print('{:10f}'.format(ans))
| 1 | 190,764,467,652 | null | 31 | 31 |
K, N = map(int, input().split())
A = list(map(int, input().split()))
max_d = 0
for a in range(1, N):
d = A[a] - A[a-1]
if d > max_d:
max_d = d
last_d = K - A[-1] + A[0]
if last_d > max_d:
max_d = last_d
print(K - max_d) | #! /usr/bin/env python3
import sys
sys.setrecursionlimit(10**9)
YES = "Yes" # type: str
NO = "No" # type: str
INF=10**20
def solve(A: int, B: int, C: int, D: int):
while True:
C-=B
if C <= 0:
print(YES)
break
A-=D
if A <= 0:
print(NO)
break
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
A = int(next(tokens)) # type: int
B = int(next(tokens)) # type: int
C = int(next(tokens)) # type: int
D = int(next(tokens)) # type: int
solve(A, B, C, D)
if __name__ == "__main__":
main()
| 0 | null | 36,593,956,151,010 | 186 | 164 |
input()
data = input().split()
data.reverse()
print(' '.join(data)) | N = int(raw_input())
n = map(int, raw_input().split())
for f in reversed(n):
print f, | 1 | 1,001,724,005,786 | null | 53 | 53 |
def main():
X = int(input())
ans = 0
money = 100
while money < X:
ans += 1
money = money * 101 // 100
print(ans)
if __name__ == '__main__':
main() | # -*- coding: utf-8 -*-
"""
Created on Sun Jun 18 10:01:05 2017
@author: syaga
"""
if __name__ == "__main__":
N = int(input())
C = list(input().split())
D = C[:]
# Bunbble Sort
for i in range(0, N):
for j in range(N-1, i, -1):
if int(C[j][1]) < int(C[j-1][1]):
temp = C[j]
C[j] = C[j-1]
C[j-1] = temp
print(" ".join(C))
print("Stable")
# Selection Sort
for i in range(0, N):
minj = i
for j in range(i, N):
if int(D[j][1]) < int(D[minj][1]):
minj = j
temp = D[i]
D[i] = D[minj]
D[minj] = temp
print(" ".join(D))
flag = 0
for (i, j) in zip(C, D):
if i != j:
flag = 1
break
if flag == 1:
print("Not stable")
else:
print("Stable") | 0 | null | 13,550,773,159,590 | 159 | 16 |
n=int(input())
s='*'+input()
r=s.count('R')
g=s.count('G')
b=s.count('B')
cnt=0
for i in range(1,n+1):
for j in range(i,n+1):
k=2*j-i
if k>n:
continue
if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
cnt+=1
print(r*g*b-cnt) | N = int(input())
S = input()
R = set()
G = set()
B = set()
for i, s in enumerate(S):
if s == 'R':
R.add(i)
elif s == 'G':
G.add(i)
elif s == 'B':
B.add(i)
ans = 0
for r in R:
for g in G:
ans += len(B)
d = abs(r-g)
if (r+g) % 2 == 0 and (r+g)//2 in B:
ans -= 1
if r+d in B or g+d in B:
ans -= 1
if r-d in B or g-d in B:
ans -= 1
print(ans)
| 1 | 36,341,448,812,020 | null | 175 | 175 |
S = input()
n = len(S)
s1 = S[:(n-1)//2]
s2 = S[(n+3)//2-1:]
if S[::-1]==S and s1[::-1]==s1 and s2[::-1]==s2:
print("Yes")
else:
print("No") | hankei = input()
print(int(hankei)**2) | 0 | null | 95,486,942,413,500 | 190 | 278 |
#11_A
import random
class Dice:
def __init__(self):
self.dice=[i for i in range(6)]
self.workspace=[i for i in range(6)]
self.top=self.dice=[0]
def set(self,numbers):
self.dice=[i for i in numbers]
self.workspace=[i for i in numbers]
def rotate(self,command):
if command == "W":
self.workspace=[self.dice[2], self.dice[1], self.dice[5], self.dice[0], self.dice[4], self.dice[3]]
self.dice=self.workspace
elif command == "E":
self.workspace=[self.dice[3], self.dice[1], self.dice[0], self.dice[5], self.dice[4], self.dice[2]]
self.dice = self.workspace
if command == "S":
self.workspace=[self.dice[4], self.dice[0], self.dice[2], self.dice[3], self.dice[5], self.dice[1]]
self.dice=self.workspace
elif command == "N":
self.workspace=[self.dice[1], self.dice[5], self.dice[2], self.dice[3], self.dice[0], self.dice[4]]
self.dice=self.workspace
def get_top(self):
self.top=self.dice[0]
print(self.top)
def predict(self, num):
for i in range(num):
top, front = map(int, input().split())
while(True):
if top == self.dice[0] and front == self.dice[1]:
break
command_num=random.randint(1,4)
if command_num == 1:
self.rotate("W")
elif command_num == 2:
self.rotate("E")
elif command_num == 3:
self.rotate("S")
elif command_num == 4:
self.rotate("N")
print(self.dice[2])
def getter(self):
return self.dice[0], self.dice[1], self.dice[2]
def predict_same(self, top, front, right):
for n in range(30):
if top ==self.dice[0] and front== self.dice[1] and right ==self.dice[2]:
print("Yes")
break
command_num=random.randint(1,4)
if command_num == 1:
self.rotate("W")
elif command_num == 2:
self.rotate("E")
elif command_num == 3:
self.rotate("S")
elif command_num == 4:
self.rotate("N")
if top!=self.dice[0] or front!=self.dice[1] or front!=self.dice[2]:
print("No")
numbers=list(map(int,input().split()))
dice=Dice()
dice.set(numbers)
# commands=input()
# for i in range(len(commands)):
# dice.rotate(commands[i])
# dice.get_top()
q=int(input())
dice.predict(q)
| import bisect
N,K=map(int,input().split())
A=list(map(int,input().split()))
S=[0 for i in range(N+1)]
for i in range(N):
S[i+1]=S[i]+A[i]
S[i+1]%=K
X=[(S[i]-i)%K for i in range(N+1)]
D=dict()
for i in range(N+1):
if X[i] in D:
D[X[i]].append(i)
else:
D[X[i]]=[i]
ans=0
for k in D:
for i in D[k]:
L=bisect.bisect_left(D[k],i-K+1)
R=bisect.bisect_right(D[k],i+K-1)
ans+=R-L-1
print(ans//2)
| 0 | null | 68,988,069,135,598 | 34 | 273 |
n=int(input())
xy=[list(map(int, input().split())) for i in range(n)]
z=list(map(lambda x: x[0]+x[1], xy))
w=list(map(lambda x: x[0]-x[1], xy))
print(max(max(z)-min(z), max(w)-min(w))) | import sys
import itertools
def resolve(in_):
N = int(next(in_))
xy = (tuple(map(int, line.split())) for line in itertools.islice(in_, N))
zw = tuple((x + y, x - y) for x, y in xy)
zmax = zmin = zw[0][0]
wmax = wmin = zw[0][1]
for z, w in zw[1:]:
zmax = max(zmax, z)
zmin = min(zmin, z)
wmax = max(wmax, w)
wmin = min(wmin, w)
ans = max(zmax - zmin, wmax - wmin)
return ans
def main():
answer = resolve(sys.stdin.buffer)
print(answer)
if __name__ == '__main__':
main()
| 1 | 3,393,313,510,052 | null | 80 | 80 |
import math
def lcm(a,b):
return (a*b)//math.gcd(a,b)
def co(num):
return format(num, 'b')[::-1].find('1')
N,M=map(int,input().split())
L=list(map(int,input().split()))
L2=[co(i) for i in L]
if len(set(L2))!=1:
print(0)
exit()
L=[i//2 for i in L]
s=L[0]
for i in range(N):
s=lcm(s,L[i])
c=M//s
print((c+1)//2) | X = int(input())
k = 0
res = 100
for i in range (1, 4200):
res += res // 100
if res >= X:
k = i
break
print(k) | 0 | null | 64,629,858,558,148 | 247 | 159 |
def main():
N = int(input())
print((N-1)//2)
if __name__ == '__main__':
main() | N = int(input())-1
print(N//2) | 1 | 153,082,201,946,464 | null | 283 | 283 |
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]) | # @oj: atcoder
# @id: hitwanyang
# @email: [email protected]
# @date: 2020-09-15 19:45
# @url:
import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
from decimal import *
# region fastio
BUFSIZE = 8192
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
## 注意嵌套括号!!!!!!
## 先有思路,再写代码,别着急!!!
## 先有朴素解法,不要有思维定式,试着换思路解决
def main():
x=int(input())
dp=[0]*(x+1)
mod=10**9+7
for i in range(x+1):
if i<3:
dp[i]=0
continue
dp[i]=1
for j in range(3,i-3+1):
if i-j>5:
dp[i]+=(1+dp[i-j]%mod-1)
else:
dp[i]+=dp[i-j]%mod
print (dp[-1]%mod)
if __name__ == "__main__":
main() | 1 | 3,278,573,718,628 | null | 79 | 79 |
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
S=[list(map(int,input().split())) for i in range(Q)]
l=[0]*10**6
total=0
for i in range(N) :
l[A[i]]+=1 #各数字の個数
total+=A[i] #初期総和
for i in range(Q) :
s0=S[i][0] #Bの値、交換した値
s1=S[i][1] #Cの値、交換する値
total+=s1*l[s0]-s0*l[s0]
l[s1]+=l[s0]
l[s0]=0
print(total) | from collections import deque
def main():
k = int(input())
l = list(range(1, 10))
Q = deque(l)
for _ in range(k):
q = Q.popleft()
# 基準-1
if q % 10 != 0:
Q.append(10*q+q%10-1)
# 基準
Q.append(10*q+q%10)
# 基準 + 1
if q % 10 != 9:
Q.append(10*q+q%10+1)
print(q)
if __name__ == '__main__':
main()
| 0 | null | 26,083,514,542,560 | 122 | 181 |
H1,M1,H2,M2,k = map(int,input().split())
h = ((H2-1)-H1)*60
m = (M2+60)-M1
print((h+m)-k) | h_1, m_1, h_2, m_2, k = map(int, input().split())
time_m = h_2*60 + m_2 - (h_1*60 + m_1) - k
print(time_m) | 1 | 18,065,751,283,008 | null | 139 | 139 |
import sys
readline = sys.stdin.readline
a,b,c,K = map(int,readline().split())
print(min(a,K) - max(K - (a + b),0)) | #http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_A&lang=jp
#????????????
#????????????python???????????????????????????????????????push???pop?????????
#??????????????????????????°????????§??????????§£???????????\??£???
def rpn(formula):
stack = Stack()
for d in formula:
if d == "+":
stack.push(stack.pop() + stack.pop())
elif d == "-":
stack.push(-stack.pop() + stack.pop())
elif d == "*":
stack.push(stack.pop() * stack.pop())
else:
stack.push(int(d))
return stack.pop()
class Stack:
def __init__(self):
self.data = []
def push(self, d):
#print(self.data)
self.data.append(d)
def pop(self):
#print(self.data)
r = self.data[-1]
self.data = self.data[:-1]
return r
def main():
formula = input().split()
print(rpn(formula))
if __name__ == "__main__":
main() | 0 | null | 10,986,717,132,120 | 148 | 18 |
l = int(input())
ans = 0
edge = l/3
ans = edge**3
print(ans) | from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
n = int(input())
l_list = list(map(int, input().split()))
l_combo = itertools.combinations(l_list, 3)
ans = 0
for i in l_combo:
if i[0] + i[1] > i[2] and i[1]+i[2] > i[0] and i[0] + i[2] > i[1] and i[0] != i[1] and i[1] != i[2] and i[0] != i[2]:
ans += 1
print(ans)
| 0 | null | 26,054,018,904,082 | 191 | 91 |
def main():
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
if A[i] % 2 == 0 and (A[i] % 3 != 0 and A[i] % 5 != 0):
return "DENIED"
return "APPROVED"
if __name__ == '__main__':
print(main())
| import sys
def input(): return sys.stdin.readline().strip()
def resolve():
n,a,b=map(int, input().split())
if (abs(a-b))%2==0:
print((abs(a-b))//2)
else:
ue=max(a,b)-1
sita=n-min(a,b)
hokasita=((n-max(a,b))*2+1+abs(b-a))//2
hokaue=(((min(a,b))-1)*2+1+abs(b-a))//2
print(min(ue,sita,hokasita,hokaue))
resolve()
| 0 | null | 89,278,523,581,952 | 217 | 253 |
import math
def check(A, x, k):
cut_count = 0
for number in A:
cut_count += (math.ceil(number / x)) -1
return cut_count <= k
n, k = map(int,input().split())
a = list(map(int, input().split()))
ans = 0
l = 0
r = 10 ** 9
while r - l > 1:
x = (r + l) // 2
if check(a, x, k):
r = x
else:
l = x
print(r) | import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
N = int(readline())
def enum_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
divs = enum_divisors(N)
ans = INF
for div1 in divs:
div2 = N // div1
score = (div1 + div2 - 2)
ans = min(score, ans)
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 84,114,532,907,402 | 99 | 288 |
line = input()
for ch in line:
n = ord(ch)
if ord('a') <= n <= ord('z'):
n -= 32
elif ord('A') <= n <= ord('Z'):
n += 32
print(chr(n), end='')
print() | mod = 998244353
n, s = map(int, input().split())
A = list(map(int, input().split()))
dp = [[0]*(3001) for _ in range(n+1)]
dp[0][0] = 1
for i in range(n):
for j in range(s+1):
dp[i+1][j] = 2*dp[i][j] % mod
if j-A[i] >= 0:
dp[i+1][j] = (dp[i+1][j]+dp[i][j-A[i]]) % mod
print(dp[n][s])
| 0 | null | 9,570,575,133,800 | 61 | 138 |
k =int(input())
seq = '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'
li = list(map(int,seq.split(', ')))
print(li[k-1]) | number_list = [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]
k = int(input())
out = number_list[k-1]
print(out) | 1 | 50,153,531,969,120 | null | 195 | 195 |
s = input()
t = input()
# S_r = ''.join(list(reversed(S)))
cont = 0
for i in range(len(s)):
if s[i] == t[i]:
cont += 1
print(len(s)-cont) | s = list(input())
t = list(input())
cnt = 0
for x,y in zip(s,t):
if x != y:
cnt += 1
print(cnt)
| 1 | 10,437,501,637,690 | null | 116 | 116 |
#C
def gcd(a, b):
while b:
a, b = b, a % b
return a
K = int(input())
ans = 0
for a in range(1,K+1):
for b in range(a,K+1):
for c in range(b,K+1):
if a != b and b != c and a != c:
ans += 6*gcd(gcd(a,b),c)
elif a == b or b == c or a == c:
if a == b and b == c:
ans += gcd(gcd(a,b),c)
else:
ans += 3*gcd(gcd(a,b),c)
print(ans) | a, b = (int(x) for x in input().split())
print(a*b, (2*a)+(2*b))
| 0 | null | 17,778,707,629,208 | 174 | 36 |
print(int(input())**2) | a = int(input(""))
print(int(a*a)) | 1 | 145,254,074,249,248 | null | 278 | 278 |
h,w,k = map(int,input().split())
m=[list(input()) for i in range(h)]
o=0
for h_bit in range(2**h):
for w_bit in range(2**w):
c=0
for i in range(h):
for j in range(w):
if (h_bit>>i)&1==0 and (w_bit>>j)&1==0 and m[i][j]=='#':
c+=1
if c==k:
o+=1
print(o) | while True:
a = input()
if a == '0':
break
print(sum(map(int,*a.split()))) | 0 | null | 5,261,605,638,948 | 110 | 62 |
A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())
print("YES" if A+T*V>= B+T*W and A-T*V <= B-T*W else "NO") | import sys
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if (a == b):
print('YES')
sys.exit(0)
if (v <= w):
print('NO')
sys.exit(0)
res = abs(a - b) / (v - w)
if (res > t):
print('NO')
else:
print('YES')
sys.exit(0)
| 1 | 15,122,547,680,820 | null | 131 | 131 |
#!/usr/bin/env python3
import sys
from itertools import chain
def solve(N: int, A: "List[int]"):
cnt = 0
for a in A:
if a == cnt + 1:
cnt += 1
if cnt == 0:
return -1
return N - cnt
def main():
tokens = chain(*(line.split() for line in sys.stdin))
N = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
answer = solve(N, A)
print(answer)
if __name__ == "__main__":
main()
| s = input()
t = input()
cnt = 0
for i in range (len(s)):
if s[i] == t[i]:
cnt += 1
if cnt == len(s) and len(t) - len(s) == 1:
print("Yes")
else:
print("No")
| 0 | null | 67,908,199,474,512 | 257 | 147 |
class Node:
def __init__(self,key):
self.key = key
self.prev = None
self.next = None
class DoublyLinkedList:
def __init__(self):
self.nil = Node(None)
self.nil.prev = self.nil
self.nil.next = self.nil
def insert(self,key):
new = Node(key)
new.next = self.nil.next
self.nil.next.prev = new
self.nil.next = new
new.prev = self.nil
def listSearch(self,key):
cur = self.nil.next
while cur != self.nil and cur.key != key:
cur = cur.next
return cur
def deleteNode(self, t):
if t == self.nil:
return
t.prev.next = t.next
t.next.prev = t.prev
def deleteFirst(self):
self.deleteNode(self.nil.next)
def deleteLast(self):
self.deleteNode(self.nil.prev)
def deleteKey(self, key):
self.deleteNode(self.listSearch(key))
if __name__ == '__main__':
import sys
input = sys.stdin.readline
n = int(input())
d = DoublyLinkedList()
for _ in range(n):
c = input().rstrip()
if c[0] == "i":
d.insert(c[7:])
elif c[6] == "F":
d.deleteFirst()
elif c[6] =="L":
d.deleteLast()
else:
d.deleteKey(c[7:])
ans = []
cur = d.nil.next
while cur != d.nil:
ans.append(cur.key)
cur = cur.next
print(" ".join(ans))
| from collections import deque
n = int(input())
d = deque()
for _i in range(n):
line = input().split()
order = line[0]
if order in ('insert', 'delete'):
key = line[1]
if order == 'insert':
d.appendleft(key)
elif order == 'delete':
try:
d.remove(key)
except ValueError:
pass
elif order == 'deleteFirst':
d.popleft()
elif order == 'deleteLast':
d.pop()
else:
raise ValueError('Invalid order: {order}')
print(' '.join(d))
| 1 | 50,546,363,408 | null | 20 | 20 |
mod = pow(10, 9) + 7
def main():
N, K = map(int, input().split())
table = [0]*(K+1)
for k in range(K, 0, -1):
m = K//k
tmp = pow(m, N, mod)
for l in range(2, m+1):
tmp -= table[l*k]
tmp %= mod
table[k] = tmp
ans = 0
for i in range(len(table)):
ans += (i * table[i])%mod
ans %= mod
#print(table)
print(ans)
if __name__ == "__main__":
main()
| # ALDS1_5_A.
def intinput():
a = input().split()
for i in range(len(a)):
a[i] = int(a[i])
return a
def binary_search(S, k):
a = 0; b = len(S) - 1
if b == 0: return S[0] == k
while b - a > 1:
c = (a + b) // 2
if k <= S[c]: b = c
else: a = c
return S[a] == k or S[b] == k
def show(a):
# 配列aの中身を出力する。
_str = ""
for i in range(len(a) - 1): _str += str(a[i]) + " "
_str += str(a[len(a) - 1])
print(_str)
def main():
n = int(input())
A = intinput()
q = int(input())
m = intinput()
# 配列Aの作る数を調べる。
nCanMake = [0]
for i in range(n):
for k in range(len(nCanMake)):
x = nCanMake[k] + A[i]
if not x in nCanMake: nCanMake.append(x)
# show(nCanMake)
for i in range(q):
if m[i] in nCanMake: print("yes")
else: print("no")
if __name__ == "__main__":
main()
| 0 | null | 18,282,811,433,262 | 176 | 25 |
import math
x=int(input())
ans=0
for i in range (1,x+1):
for j in range(1,x+1):
chk=math.gcd(i,j)
for k in range (1,x+1):
ans=ans+math.gcd(chk,k)
print(ans) | import math
import itertools
k = int(input())
l = list(range(1,k+1))
y = list(itertools.combinations_with_replacement(l,3))
n = len(y)
t = 0
for i in range(n):
a = y[i][0]
b = y[i][1]
c = y[i][2]
d = math.gcd(math.gcd(a,b),c)
if a != b != c:
t += d * 6
elif a == b == c:
t += d
else:
t += d * 3
print(t) | 1 | 35,430,906,885,660 | null | 174 | 174 |
def main():
A1, A2, A3 = map(int, input().split())
if A1 + A2 + A3 >= 22:
ans = "bust"
else:
ans = "win"
print(ans)
if __name__ == "__main__":
main()
| H = ''
W = ''
i = j = 0
while True:
line = input()
line = line.split()
H = int(line[0])
W = int(line[1])
if H == 0 and W == 0:
break
while i < H:
if i == 0 or i == H-1:
print('#'*W)
else:
print('#',end='')
print('.'*(W-2),end='')
print('#')
i += 1
i = 0
print() | 0 | null | 59,545,773,809,340 | 260 | 50 |
n, m = map(int, input().split())
li = [list(map(int,input().split())) for i in range(n)]
c = []
for i in range(n):
li[i].append(sum(li[i]))
for j in range(m+1):
t = 0
for i in range(n):
t += li[i][j]
c.append(t)
li.append(c)
for i in range(n+1):
print(*li[i]) | def calcTotalOfRowAndCol(matrix, r, c):
for l in matrix:
total = 0
for val in l:
total += val
l.append(total)
matrix.append([])
for i in range(c + 1):
total = 0
j = 0
while j < r:
total += matrix[j][i]
j += 1
matrix[r].insert(i, total)
return matrix
if __name__ == '__main__':
matrix = []
row, col = [int(x) for x in input().split()]
i = row
while i > 0:
matrix.append([int(y) for y in input().split()])
i -= 1
matrix2 = calcTotalOfRowAndCol(matrix, row, col)
for l in matrix:
print(' '.join(str(x) for x in l)) | 1 | 1,378,105,439,120 | null | 59 | 59 |
N = int(input())
A = list(map(int, input().split()))
for a in A:
if a % 2 == 0:
if a % 3 != 0 and a % 5 != 0:
print('DENIED')
break
else:
print('APPROVED') | input()
print('APPROVED' if all(map(lambda x: x % 3 == 0 or x % 5 == 0, filter(lambda x: x % 2 == 0, map(int, input().split())))) else 'DENIED') | 1 | 69,088,498,075,200 | null | 217 | 217 |
n,m=map(int,input().split())
li=[]
if n==1:
score="0"
else:
score="1"+"0"*(n-1)
for i in range(m):
s,c=map(int,input().split())
if n!=1 and (s,c)==(1,0):
print("-1")
quit()
li.append([s,c])
for j in range(len(li)):
if li[j][0]==s and li[j][1]!=c:
print("-1")
quit()
score=score[:s-1]+str(c)+score[s:]
print(int(score))
| import sys
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))
n, m = inm()
sc = [tuple(inm()) for i in range(m)]
def digits(x):
if x < 10:
return 1
if x < 100:
return 2
return 3
def solve():
for x in range(1000):
if digits(x) != n:
continue
sx = str(x)
ok = True
for i in range(m):
s, c = sc[i]
if sx[s - 1] != str(c):
ok = False
break
if ok:
return x
return -1
print(solve())
| 1 | 60,500,595,550,328 | null | 208 | 208 |
import math
import sys
import collections
import bisect
readline = sys.stdin.readline
def main():
n = int(readline().rstrip())
S = [readline().rstrip() for _ in range(n)]
c = collections.Counter(S)
keys = sorted(c.keys())
maxS = c.most_common()[0][1]
for key in keys:
if c[key] == maxS:
print(key)
if __name__ == '__main__':
main()
| N, K = map(int, input().split())
MOD = 998244353
S = []
for _ in range(K):
S.append(tuple(map(int, input().split())))
dp = [0] * (N + 1)
dp[1] = 1
sum_list = [0] * (N + 1)
sum_list[1] = 1
for i in range(2, N+1):
for L, R in S:
RR = i - L
if RR <= 0:
continue
LL = max(1, i-R)
if LL <= RR:
t = sum_list[RR] - sum_list[LL-1]
dp[i] += t
dp[i] %= MOD
sum_list[i] = (sum_list[i-1] + dp[i]) % MOD
print(dp[N])
| 0 | null | 36,428,833,721,764 | 218 | 74 |
a = input()
b = a.split(' ')
b[0] = int(b[0])
b[1] = int(b[1])
b[2] = int(b[2])
b.sort()
print(str(b[0])+' '+str(b[1])+' '+str(b[2])) | sortingThreeNum = list(map(int, input().split()))
sortingThreeNum.sort()
print(sortingThreeNum[0], sortingThreeNum[1], sortingThreeNum[2])
| 1 | 423,208,716,310 | null | 40 | 40 |
from itertools import accumulate
n = int(input())
a = list(map(int, input().split()))
a_acc = list(accumulate(a))
ans = 2020202020
for i in range(n):
ans = min(abs(a_acc[-1] - a_acc[i] - a_acc[i]), ans)
print(ans)
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
half = s / 2
cum = 0
for v in a:
if abs(half - cum) < abs(half - (cum + v)):
break
cum += v
print(abs((s - cum) - cum))
| 1 | 142,549,510,716,402 | null | 276 | 276 |
x, k, d = map(int, input().split())
cur = x
numTimes = x // d
if numTimes == 0:
cur -= d
k -= 1
else:
numTimes = min(abs(numTimes), k)
if x < 0:
numTimes *= -1
cur -= numTimes * d
k -= numTimes
if k % 2 == 0:
print(abs(cur))
else:
result = min(abs(cur - d), abs(cur + d))
print(result) | N=int(input())
print(int((N+2-1)/2))
| 0 | null | 31,971,591,356,820 | 92 | 206 |
n,m=map(int,input().split())
li=[]
if n==1:
score="0"
else:
score="1"+"0"*(n-1)
for i in range(m):
s,c=map(int,input().split())
if n!=1 and (s,c)==(1,0):
print("-1")
quit()
li.append([s,c])
for j in range(len(li)):
if li[j][0]==s and li[j][1]!=c:
print("-1")
quit()
score=score[:s-1]+str(c)+score[s:]
print(int(score))
| a, b = map(str, input().split())
a = int(a)
c, d = map(int, b.split('.'))
b = c * 100 + d
b *= a
print(int(("00" + str(b))[:-2])) | 0 | null | 38,477,151,294,008 | 208 | 135 |
#!/usr/bin/env python
label = list(map(int, input().split()))
command = list(input())
faces = [1, 2, 3, 4, 5, 6]
def dice(command):
if command == "N":
faces[0], faces[1], faces[4], faces[5] = faces[1], faces[5], faces[0], faces[4]
elif command == "S":
faces[0], faces[1], faces[4], faces[5] = faces[4], faces[0], faces[5], faces[1]
elif command == "E":
faces[0], faces[2], faces[3], faces[5] = faces[3], faces[0], faces[5], faces[2]
else: # command W
faces[0], faces[2], faces[3], faces[5] = faces[2], faces[5], faces[0], faces[3]
for c in command:
dice(c)
print(label[faces[0] - 1])
| import sys
dice = [int(i) for i in sys.stdin.readline().split()]
command = sys.stdin.readline().strip()
for c in command:
if c == "N":
dice = (dice[1], dice[5], dice[2], dice[3], dice[0], dice[4])
elif c == "S":
dice = (dice[4], dice[0], dice[2], dice[3], dice[5], dice[1])
elif c == "W":
dice = (dice[2], dice[1], dice[5], dice[0], dice[4], dice[3])
elif c == "E":
dice = (dice[3], dice[1], dice[0], dice[5], dice[4], dice[2])
print(dice[0]) | 1 | 223,542,538,268 | null | 33 | 33 |
N = int(input())
X = [list(map(int,input().split())) for _ in range(N)]
A = []
for i in range(N):
x,l = X[i]
A.append((x-l,x+l))
B1 = sorted(A,key=lambda x:x[1])
B1 = [(B1[i][0],B1[i][1],i) for i in range(N)]
B2 = sorted(B1,key=lambda x:x[0])
hist = [0 for _ in range(N)]
cnt = 0
i = 0
for k in range(N):
if hist[k]==0:
r = B1[k][1]
hist[k] = 1
cnt += 1
while i<N:
l,j = B2[i][0],B2[i][2]
if hist[j]==1:
i += 1
continue
if l<r:
hist[j] = 1
i += 1
else:
break
print(cnt) | def main():
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(A[K-1])
if __name__ == '__main__':
main()
| 0 | null | 69,989,963,449,180 | 237 | 195 |
h, n = map(int, input().split())
print("Yes" if sum(map(int, input().split())) >= h else "No")
| '''
ITP-1_5-D
?§???????????????°???????????°
goto ?????????C/C++?¨????????????§???????????¨?????§???????????§????????????????????¨????????¶????????????????????????????????????????£?????????????????????° goto CHECK_NUM; ??¨?????????????????????????????¨???????????°??????????????§ CHECK_NUM: ??¨????????????????????????????§?????????????????????????????????£????????°?????????????????????????????????????????¨?????§????????????
?????????goto ???????????±??????????????????????????°?????????????????§?????±??????????????????????????????????????????????????¨?????¨?\¨?????????????????????
?¬????C++?¨???????????????°????????¨?????????????????????????????°????????????????????????????????????????????????goto ????????????????????§????£?????????????????????????
void call(int n){
int i = 1;
CHECK_NUM:
int x = i;
if ( x % 3 == 0 ){
cout << " " << i;
goto END_CHECK_NUM;
}
INCLUDE3:
if ( x % 10 == 3 ){
cout << " " << i;
goto END_CHECK_NUM;
}
x /= 10;
if ( x ) goto INCLUDE3;
END_CHECK_NUM:
if ( ++i <= n ) goto CHECK_NUM;
cout << endl;
}
???Input
???????????´??° nn ?????????????????????????????????
???Output
????¨?????????°???????????\????????´??° nn ????????????????????????????????????????????????
'''
# import
import sys
inputData = int(input())
outputData = []
cntVal = 1
while True:
# CHECK_NUM
checkVal = cntVal
if checkVal % 3 == 0:
outputData.append(str(cntVal))
else:
while True:
# INCLUDE3
if checkVal % 10 == 3:
outputData.append(str(cntVal))
break
checkVal = int(checkVal / 10)
# EndChek
if checkVal != 0:
continue
else:
break
# increment
cntVal += 1
# EndChek
if cntVal <= inputData:
continue
else:
break
# Output
print(" " + " ".join(outputData)) | 0 | null | 39,671,867,979,130 | 226 | 52 |
N=int(input())
S=input()
ans=0
for i in range(N-2):
if S[i:i+3]=='ABC':
ans+=1
print(ans) | N, M = map(int, input().split())
data = [0]*N
solved = [False]*N
for _ in range(M):
p, S = input().split()
p = int(p) - 1
if solved[p] == False and S == "WA":
data[p] += 1
if solved[p] == False and S == "AC":
solved[p] = True
print(sum(solved),sum( x*y for x, y in zip(data, solved)) )
| 0 | null | 96,138,396,659,744 | 245 | 240 |
import math
N = int(input())
x = []
y = []
for i in range(N):
tmp = input().split(" ")
x.append(int(tmp[0]))
y.append(int(tmp[1]))
d = 0
for i in range(N):
for j in range(N):
d += math.sqrt((x[j]-x[i]) ** 2 + (y[j]-y[i]) ** 2)
print(d/N) | from itertools import permutations
N=int(input())
arr=[list(map(int,input().split())) for i in range(N)]
def dis(x):
c=0
for i in range(N-1):
aa=arr[x[i]][0]-arr[x[i+1]][0]
bb=arr[x[i]][1]-arr[x[i+1]][1]
c+=(aa**2+bb**2)**(0.5)
return c
count=0
ans=0
for i in permutations(range(0,N),N):
count+=1
ans+=dis(i)
print(ans/count)
| 1 | 148,668,828,888,426 | null | 280 | 280 |
# Circle Pond
R = int(input())
print(R*2 * 3.14159265)
| r = int(input())
print(2*r*3.14159265358) | 1 | 31,562,350,913,358 | null | 167 | 167 |
X, K, D = map(int,input().split())
X = abs(X)
if X > K*D:
print( X - K*D )
else:
a = X//D
K -= a
X -= D*a
if K%2 == 0:
print(X)
else:
print(abs(X-D)) | import math
X,K,D = map(int,input().split())
X = abs(X)
if X > K*D:
print(X-K*D)
else:
c=math.floor(X/D)
print( abs(X-D*c-((K-c)%2)*D) )
| 1 | 5,208,889,401,380 | null | 92 | 92 |
k,x = map(int,input().split())
yen = k * 500
if yen < x:
print('No')
else:
print('Yes') | K,X= map(int,input().split())
if 500*K >= X:
print("Yes")
else:
print("No") | 1 | 98,172,672,648,232 | null | 244 | 244 |
# フェルマーの小定理
def main():
from builtins import pow
K = int(input())
S = input()
m = 1000000007
result = 0
a = 1
b = 1
t = pow(26, K, m)
u = pow(26, m - 2, m) * 25 % m
l = len(S)
for i in range(K + 1):
# result += pow(26, K - i, m) * mcomb(len(S) - 1 + i, i) * pow(25, i, m)
result += t * (a * pow(b, m - 2, m))
result %= m
t *= u
t %= m
a *= l + i
a %= m
b *= i + 1
b %= m
print(result)
main()
| val = input()
valf=val[-1]
if(valf=="s"):
print(val+"es")
else:
print(val+"s") | 0 | null | 7,602,574,740,602 | 124 | 71 |
n=int(input())
def ans(x):
a=26
b=1
k=1
ch=0
while ch==0:
if b<= x <= b+a**k-1:
ch+=1
return k,x-(b-1)
else:
b=b+a**k
k+=1
s,t=ans(n)
ans1=''
c='abcdefghijklmnopqrstuvwxyz'
for i in range(1,s+1):
q=0
f=26**(s-i)
if i!=s:
cc=0
while cc==0:
e=t-f*(q+1)
if e>0:
q+=1
else:
cc+=1
if q==25:
break
t-=f*q
g=c[q]
ans1=ans1+g
else:
g=c[t-1]
ans1=ans1+g
print(ans1) | n = int(input())
ans = ''
for i in range(13):
if n >= 26 and n%26 == 0:
ans = 'z' + ans
n -= 26
else:
ans = chr(97 -1 + n%26) + ans
n -= n%26
n = n //26
print(ans.replace("`", ""))
| 1 | 11,916,588,435,036 | null | 121 | 121 |
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
mod = 998244353
n, k = map(int, input().split())
l = []
r = []
for _ in range(k):
l_, r_ = map(int, input().split())
l.append(l_)
r.append(r_)
dp = [0] * (n + 1)
dp_csum = [0] * (n + 1)
dp[1] = 1
dp_csum[1] = 1
for i in range(2, n + 1):
for j in range(k):
left = i - r[j]
right = i - l[j]
if right >= 1:
dp[i] += dp_csum[right] - dp_csum[max(left, 1) - 1]
dp[i] %= mod
dp_csum[i] = dp_csum[i - 1] + dp[i]
dp_csum[i] %= mod
print(dp[-1]) | while 1:
s,t = map(int,input().split())
if s>t:
s,t = t,s
if (s,t)==(0,0):
break
print(s,t) | 0 | null | 1,625,968,869,840 | 74 | 43 |
import math
n = int(input())
t = [0] * (n + 1)
m = math.floor(math.sqrt(n))
for i in range(1,m):
for j in range(1,m):
for k in range(1,m):
p = i*i+j*j+k*k+i*j+j*k+i*k
if p <= n:
t[p] += 1
for i in range(1,n + 1):
print(t[i]) | MOD = 10**9+7
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
#print(a)
kai = [1]
gai = []
for i in range(n):
j = (kai[i] * (i+1)) % MOD
kai.append(j)
for i in range(n+1):
j = kai[i]
l = pow(j, MOD-2, MOD)
gai.append(l)
#print(kai)
#print(gai)
ans = 0
for i in range(n):
if i <= (n-k):
#print('xあり')
x = (a[i] * kai[n-i-1] * gai[n-i-k] * gai[k-1]) % MOD
else:
x = 0
#print('xha', x)
if i >= (k-1):
#print('yあり')
y = (a[i] * kai[i] * gai[i-k+1] * gai[k-1]) % MOD
else:
y = 0
#print('yha', y)
ans = (ans + y - x) % MOD
#print(ans)
print(ans) | 0 | null | 51,699,514,454,240 | 106 | 242 |
n = int(input())
A = [input() for _ in range(n)]
print("AC x " + str(A.count("AC")))
print("WA x " + str(A.count("WA")))
print("TLE x " + str(A.count("TLE")))
print("RE x " + str(A.count("RE")))
| n = int(input())
ACs = 0
WAs = 0
TLEs = 0
REs = 0
for i in range(n):
result = input()
if result == "AC":
ACs += 1
elif result == "WA":
WAs += 1
elif result == "TLE":
TLEs += 1
else:
REs += 1
print("AC x " + str(ACs))
print("WA x " + str(WAs))
print("TLE x " + str(TLEs))
print("RE x " + str(REs))
| 1 | 8,686,528,241,442 | null | 109 | 109 |
from math import floor
S = input()
K = int(input())
# Sが1文字しかない
if len(set(S)) == 1:
print(floor(len(S) * K / 2))
exit()
ans = 0
if S[0] != S[-1]:
# Sの中での答え × K回数
c = "0"
count = 0
for i in range(len(S)):
if c == S[i]:
count += 1
else:
# floor(連続した文字の回数 / 2)だけ書き換える
ans += count // 2
c = S[i] # 情報更新
count = 1
ans += count // 2 # 最後の分
ans = ans * K
else:
# 先頭と末端もある
c1 = 1
for i in range(1, len(S)):
if S[i] == S[0]:
c1 += 1
else:
break
c2 = 1
for j in reversed(range(len(S) - 1)):
if S[j] == S[-1]:
c2 += 1
else:
break
ans = (c1 // 2) + (c2 // 2) + ((c1 + c2) // 2 * (K - 1))
c3 = 0
c = "0"
for k in range(i, j + 1):
if S[k] == c:
c3 += 1
else:
ans += c3 // 2 * K
c = S[k]
c3 = 1
ans += c3 // 2 * K
print(ans) | N = int(input())
sum = 0
if (1 <= N and N <= 10 ** 6):
for i in range(1,N + 1):
if ( i % 3 == 0) and ( i % 5 == 0):
#if i % 15 ==0:
N = 'Fizz Buzz'
elif i % 3 == 0:
N = 'Fizz'
elif i % 5 == 0:
N = 'Buzz'
else:
sum += i
print(sum)
| 0 | null | 105,229,209,348,500 | 296 | 173 |
import sys
def main():
input = sys.stdin.buffer.readline
a, b, c = map(int, input().split())
print("Yes" if 4 * a * b < (c - a - b) ** 2 and c - a - b > 0 else "No")
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())
def main():
a, b, c = in_nn()
t1 = c - (a + b)
t2 = 4 * a * b
if t1 <= 0:
print('No')
exit()
else:
t1 = t1**2
if t2 < t1:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main()
| 1 | 51,441,462,640,194 | null | 197 | 197 |
n,m=map(int,input().split())
d={}
ind=[0]*n
for i in range(n):
d[i+1]='*'
for j in range(m):
s,c=map(int,input().split())
if ind[s-1]==0:
d[s]=c
ind[s-1]=1
else:
if d[s]!=c:
print(-1)
exit(0)
ans=''
if n>=2:
if d[1]==0:
print(-1)
exit(0)
for k in range(n):
if k==0:
if n>=2:
if d[k+1]=='*':
ans+='1'
else:
ans+=str(d[k+1])
else:
if d[k+1]=='*':
ans+='0'
else:
ans+=str(d[k+1])
else:
if d[k+1]=='*':
ans+='0'
else:
ans+=str(d[k+1])
print(ans) | N, M = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(M)]
ans = [10] * N
for l in lst:
if ans[l[0]-1] < 10 and ans[l[0]-1] != l[1]:
print(-1)
exit()
ans[l[0]-1] = l[1]
if ans[0] == 10:
if N == 1:
ans[0] = 0
else:
ans[0] = 1
for i in range(1, N):
if ans[i] == 10:
ans[i] = 0
if N != 1 and ans[0] == 0:
print(-1)
exit()
ans = list(map(str, ans))
print("".join(ans)) | 1 | 60,842,285,939,402 | null | 208 | 208 |
import sys
def gcd(a,b):
r= b % a
while r != 0:
a,b = r,a
r = b % a
return a
def lcm(a,b):
return int(a*b/gcd(a,b))
for line in sys.stdin:
a,b = sorted(map(int, line.rstrip().split(' ')))
print("{} {}".format(gcd(a,b),lcm(a,b))) | from collections import deque
n,m = map(int, input().split())
graph = [[] for _ in range(n+1)]
dist = [0] * (n+1)
visited = [0] * (n+1)
for _ in range(m):
a,b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
root = 1
visited[root] = 1
d = deque([root])
while d:
v = d.popleft()
for i in graph[v]:
if visited[i]:
continue
visited[i] = 1
dist[i] = v
d.append(i)
print('Yes')
ans = dist[2:]
print(*ans, sep="\n") | 0 | null | 10,336,386,926,190 | 5 | 145 |
def main():
n = int(input())
a = sorted(list(map(int,input().split())),reverse=True)
ans = a[0]
for i in range(3,n+1):
if i%2==0:
ans += a[i//2-1]
else:
ans += a[(i-1)//2]
print(ans)
if __name__ == "__main__":
main()
|
N= int(input())
st = [list(map(str,input().split())) for _ in range(N)]
x = input()
ans = 0
flag = False
for s,t in st:
if flag:
ans += int(t)
else:
if s == x:
flag = True
print(ans) | 0 | null | 52,827,059,056,980 | 111 | 243 |
#!/usr/bin/env python
#coding: UTF-8
import sys
while True:
hight,width = map (int,raw_input().split())
if hight+width == 0:
break
else:
for h in range(hight):
if h%2 == 0:
for w in range(width):
if w%2 == 0:
sys.stdout.write("#")
else:
sys.stdout.write(".")
print ""
else:
for w in range(width):
if w%2 == 0:
sys.stdout.write(".")
else:
sys.stdout.write("#")
print ""
print "" | import sys
write=sys.stdout.write
while True:
h,w=map(int,raw_input().split())
if h==w==0: break
for i in xrange(h):
l=[('#' if i%2==j%2==0 else ('.' if (i%2==1 and j%2==0) or (i%2==0 and j%2==1) else '#')) for j in xrange(w)]
for i in l:
write(i)
print ""
print "" | 1 | 874,664,093,510 | null | 51 | 51 |
li =[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]
a=int(input())
a-=1
print(li[a])
| l = "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"
li = [int(x.strip()) for x in l.split(',')]
print(li[int(input())-1]) | 1 | 49,850,516,368,380 | null | 195 | 195 |
# (c) midandfeed
q = []
for i in range(4):
b = []
for j in range(3):
a = [0 for x in range(10)]
b.append(a)
q.append(b)
t = int(input())
for _ in range(t):
b, f, r, v = [int(x) for x in input().split()]
q[b-1][f-1][r-1] += v
a = 0
for x in q:
a += 1
for y in x:
for z in range(len(y)):
print(" {}".format(y[z]), end='')
if (z==(len(y))-1):
print()
if (a!=4):
print("#"*20) | l=[0]*120
s="#"*20
for i in range(input()):b,f,r,v=map(int,raw_input().split());l[b*30+f*10+r-41]+=v
print "",
for i in range(120):
print l[i],;j=i+1
if j==120:break
if j%30==0:print;print s,
if j%10==0:print;print "", | 1 | 1,095,289,214,672 | null | 55 | 55 |
a = []
for i in range(0,2):
l = list(map(int,input().split()))
a.append(l)
d = a[1][::-1]
print(' '.join(map(str,d))) | #from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
return list(map(int,readline().split()))
def readTuples():
return tuple(map(int,readline().split()))
def I():
return int(readline())
h,n = readInts()
A = [readInts() for _ in range(n)]
dp = [INF] * (h+1)
dp[h] = 0
for idx in range(h,-1,-1):
for i in range(n):
a,b = A[i]
dp[max(0,idx-a)] = min(dp[max(0,idx-a)], dp[idx] + b)
print(dp[0])
| 0 | null | 40,990,585,489,282 | 53 | 229 |
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)
def read_values():
return map(int, input().split())
def read_index():
return map(lambda x: x - 1, map(int, input().split()))
def read_list():
return list(read_values())
def read_lists(N):
return [read_list() for n in range(N)]
def functional(N, mod):
F = [1] * (N + 1)
for i in range(N):
F[i + 1] = (i + 1) * F[i] % mod
return F
INV = dict()
def inv(a, mod):
if a in INV:
return INV[a]
i = pow(a, mod - 2, mod)
INV[a] = i
return i
def C(F, a, b, mod):
return F[a] * inv(F[a - b], mod) * inv(F[b], mod) % mod
def main():
N, K = read_values()
mod = 10 ** 9 + 7
F = functional(5 * 10 ** 5, mod)
res = 0
if N <= K:
res = C(F, 2 * N - 1, N - 1, mod)
else:
for k in range(K + 1):
res += C(F, N, k, mod) * C(F, N - 1 , k, mod) % mod
print(res % mod)
if __name__ == "__main__":
main() | n,k=map(int,input().split())
mi = min(n-1,k)
di = 10**9+7
def pow_k(x,i):
if i==0:
return 0
K=1
while i>1:
if i % 2 != 0:
K = (K*x)%di
x = (x*x)%di
i //= 2
return (K * x)%di
lis = [i for i in range(n+1)]
lisr = [i for i in range(n+1)]
lis[0]=1
for i in range(1,n+1):
lis[i]=(lis[i-1]*lis[i])%di
lisr[i] = pow_k(lisr[i],di-2)
lisr[0]=1
for i in range(1,n+1):
lisr[i]=(lisr[i-1]*lisr[i])%di
#print(lis,lisr)
su = 1
for i in range(1,mi+1):
pl = ((((lis[n-1]*lisr[i])%di)*lisr[n-1-i])%di)
plu = (pl*((((lis[n]*lisr[i])%di)*lisr[n-i])%di))%di
su+=plu
su%=di
print(su)
| 1 | 66,760,078,132,928 | null | 215 | 215 |
x, y = input().split()
x = int(x)
z = round(float(y)*100)
print(x*z//100) | A, B = map(float, input().split())
A = int(A)
B = int(B * 100 + 0.01)
print((A * B) // 100)
| 1 | 16,490,942,519,270 | null | 135 | 135 |
a, b, c = map(int, input().split())
k = int(input())
ans = False
for i in range(k + 1):
for j in range(k-i+1):
for l in range(k-i-j+1):
aa = a * pow(2,i)
bb = b * pow(2,j)
cc = c * pow(2,l)
# print("{0} {1} {2}".format(aa,bb,cc))
if(aa < bb and bb < cc):
ans = True
if(ans):
print("Yes")
else:
print("No") | a,b,c=map(int,input().split())
k=int(input())
i=0
while True:
if a<b:
break
b*=2
i+=1
while True:
if b<c:
break
c*=2
i+=1
if i<=k:
print("Yes")
elif i>k:
print("No") | 1 | 6,861,372,261,568 | null | 101 | 101 |
S = list(input())
NS = [s for s in S]
K = int(input())
L = len(S)
if "".join(S) == S[0] * L:
print(L * K // 2)
exit()
ans = 0
for i in range(L-1):
f_s = S[i]
s_s = S[i+1]
if f_s == s_s:
S[i+1] = '-'
ans += 1
# 先頭と末尾が異なる
if S[0] != S[-1]:
ans *= K
# 一緒
else:
a = 0
for i in range(L):
if NS[i] == NS[0]:
a += 1
else:
break
b = 0
for i in range(L)[::-1]:
if NS[i] == NS[-1]:
b += 1
else:
break
ans *= K
#t = (- (-a // 2)) + (- (-b // 2)) - (- (-a-b) // 2)
#t = -(-a // 2) - (-b // 2) + (-(a+b) // 2)
t = a // 2 + b // 2 - (a+b) // 2
ans -= t * (K-1)
print(ans)
| #from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(input())
S = input()
k = I()
from itertools import groupby
x = y = 0
g = [len(list(v)) for k,v in groupby(S)]
for c in g:
x += c//2
if S[-1] == S[0]:
if g[-1]%2 == 0 or g[0]%2 == 0:
pass
elif len(S) == 1:
y = k//2
elif len(S) == g[0]:
y = k//2
else:
y = k-1
print(x * k + y)
| 1 | 175,862,328,504,992 | null | 296 | 296 |
N = int(input())
count = 0
L = list(map(int, input().split()))
for i,li in enumerate(L[:-2]):
for j,lj in enumerate(L[i+1:-1]):
for k,lk in enumerate(L[i+j+1:]):
if (li != lj) and (lj != lk) and (li != lk):
# la,lb,lc = sorted([li,lj,lk])
if li + lj > lk and lj + lk > li and lk + li > lj:
# print(i+1,i+j+1,i+j+k+1,li,lj,lk)
count += 1
print(count) | N,K=map(int,input().split())
A=list(map(int,input().split()))
F=list(map(int,input().split()))
A.sort()
F.sort(reverse=True)
l=-1
r=10**13
while r-l!=1:
m=(l+r)//2
x=0
for i in range(N):
x+=max(0,A[i]-m//F[i])
if x<=K:
r=m
else:
l=m
print(r)
| 0 | null | 85,164,324,241,360 | 91 | 290 |
n = int(input())
a = list(map(int, input().split()))
rbg = [0]*3
ans = 1
MOD = 1000000007
for i in a:
count=0
flg=True
for j in range(3):
if rbg[j]==i:
count+=1
if flg:
rbg[j]+=1
flg=False
ans*=count
ans%=MOD
print(ans) | x, y = map(int, input().split())
l = max(x, y)
s = min(x, y)
for i in range(x):
olds = s
oldl = l
s = oldl % olds
l = olds
if s == 0:
print(l)
break
| 0 | null | 65,026,784,683,010 | 268 | 11 |
a,b=map(int,input().split())
list=[[0 for i in range(2)] for j in range(a)]
for i in range(a):
list[i]=input().split()
n=0
s=0
while n!=a:
if int(list[n][1])>b:
list[n][1]=int(list[n][1])-b
list.append(list[n])
list.pop(n)
s+=b
else:
print(list[n][0],s+int(list[n][1]))
s+=int(list[n][1])
n+=1
| # coding: utf-8
# Here your code !
import collections
p,q=map(int,input().split())
count =0
deq = collections.deque()
finished=[]
while 1:
try:
deq.append(input().split())
except EOFError:
break
while deq:
d = deq.popleft()
d[1]=int(d[1])
if d[1]<=q:
count+=d[1]
d[1]=count
finished.append(map(str,d))
elif d[1]>q:
d[1]-=q
count+=q
deq.append(d)
for f in finished:
print(" ".join(f)) | 1 | 44,651,870,412 | null | 19 | 19 |
n = int(input())
a = list(map(int, input().split()))
left = a[0]
right = a[-1]
center = 0
sum_a = sum(a)
flg = False
for i in range(1, n-1):
if left + a[i] > sum_a/2 and flg is False:
flg = True
center = a[i]
right -= a[i]
elif left + a[i] == sum_a / 2:
print(0)
exit()
if flg is False:
left += a[i]
else:
right += a[i]
print(abs(min(left+center-right, right+center-left)))
| D, T, S = list(map(int, input().split()))
if D / S <= T: print('Yes')
else: print('No') | 0 | null | 72,522,456,787,722 | 276 | 81 |
n = int(input())
x = list(map(int,input().split()))
a = min(x)
b = max(x) + 1
ans = 10 ** 8
for p in range(a,b):
m = 0
for i in range(n):
m += (x[i] - p) ** 2
ans = min(ans,m)
print(ans) | N = int(input())
X_ls = list(map(int, input().split(' ')))
rst = -1
for i in range(min(X_ls), max(X_ls) + 1):
val = 0
for j in X_ls:
val += (i - j) ** 2
if rst == -1:
rst = val
else:
rst = min(rst, val)
print(rst) | 1 | 65,250,824,892,740 | null | 213 | 213 |
def comb(n,r,m):
if r == 0: return 1
return memf[n]*pow(memf[r],m-2,m)*pow(memf[n-r],m-2,m)
def mempow(a,b):
temp = 1
yield temp
for i in range(b):
temp = temp * a % 998244353
yield temp
def memfact(a):
temp = 1
yield temp
for i in range(1,a+1):
temp = temp * i % 998244353
yield temp
N,M,K = (int(x) for x in input().split())
memp = []
memf = []
mpappend = memp.append
mfappend = memf.append
for x in mempow(M-1,N-1):
mpappend(x)
for x in memfact(N-1):
mfappend(x)
ans = 0
if M == 1:
if K + 1 < N:
print('0')
else:
print('1')
else:
i = 0
for i in range(K+1):
ans = (ans + (comb(N-1,i,998244353)*M*memp[N-i-1])) % 998244353
print(ans) | N,M,K=list(map(int,input().split()))
MAXN = 2*(10**5)+10
p = 998244353
MOD = p
f = [1]
for i in range(MAXN):
f.append(f[-1] * (i+1) % MOD)
def nCr(n, r, mod=MOD):
return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod
def power_func(a,n,p):
bi=str(format(n,"b"))#2進表現に
res=1
for i in range(len(bi)):
res=(res*res) %p
if bi[i]=="1":
res=(res*a) %p
return res
out = 0
for i in range(K+1):
out += M*nCr(N-1,i,p)*power_func(M-1,N-1-i,p)
out = out % p
print(out) | 1 | 23,023,589,632,008 | null | 151 | 151 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.