code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 6.82M
181,637B
⌀ | question_pair_id
float64 101M
180,471B
⌀ | code1_group
int64 2
299
| code2_group
int64 2
299
|
---|---|---|---|---|---|---|
import math
def main():
"""
/|
b / | h
/ |
/??????|???_
<- a -->
??????a, ??????b, a??¨b??????????§?C(???)
C???????????????radian????±???????
??????1????????????: x
??????: h (b?????????????????¨????????????sin????????¨???????±???????
??¢???: S (??????)
L (x + a + b): ??????????????????????????¨??????
x = sqrt(a_ ** 2 + h ** 2)
??????a??????????????????h?????§???????????? a_ ??¨????????¨
a_ = a - b * cos(rad)
??? ??????????????¨?????????????????? ??§??°??°??£??????????????????
"""
a, b, C = map(int, input().split())
# ????§???¢????????? 0 < C < 180
rad = math.pi * C / 180
sin = math.sin(rad)
h = b * sin
S = a * h / 2
a_ = a - b * math.cos(rad)
len_d = math.sqrt(a_ ** 2 + h ** 2)
print("{:.8f}".format(S))
print("{:.8f}".format(a + b + len_d))
print("{:.8f}".format(h))
if __name__ == "__main__":
main()
|
import math
a,b,c = map(float, input().split())
cc = math.radians(c)
h = b * math.sin(cc)
S = a * h / 2
L = a + b + math.sqrt(h**2 + (a-b*math.cos(cc))**2)
print("{0:.10f}\n{1:.10f}\n{2:.10f}\n".format(S, L, h))
| 1 | 179,965,464,938 | null | 30 | 30 |
def BubbleSort(lists, num):
cards = lists[:]
for i in xrange(num):
for j in xrange(num - 1, i, -1):
if cards[j].value < cards[j - 1].value:
cards[j], cards[j - 1] = cards[j - 1], cards[j]
return cards
def SelectionSort(lists, num):
cards = lists[:]
for i in xrange(num):
minj = i
for j in xrange(i, num):
if cards[j].value < cards[minj].value:
minj = j
cards[i], cards[minj] = cards[minj], cards[i]
return cards
class Card(object):
"""docstring for Card"""
def __init__(self, arg):
self.mark = arg[0]
self.value = int(arg[1])
num = int(raw_input())
inputs = raw_input().split()
cards = [Card(inputs[x]) for x in xrange(num)]
bubble_ans = ""
bubble_cards = BubbleSort(cards, num)
for x in bubble_cards:
bubble_ans += x.mark + str(x.value) + " "
print bubble_ans.rstrip()
print "Stable"
select_ans = ""
select_cards = SelectionSort(cards, num)
for x in select_cards:
select_ans += x.mark + str(x.value) + " "
print select_ans.rstrip()
flag = True
for x in xrange(num):
if bubble_cards[x].mark != select_cards[x].mark:
flag = False
break
print "Stable" if flag else "Not stable"
|
# Aizu Problem ALDS_1_2_C: Stable Sort
#
import sys, math, os
# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
sys.stdin = open("sample-input2.txt", "rt")
def printA(A):
print(' '.join([str(a) for a in A]))
def bubble_sort(A):
for i in range(len(A) - 1):
for j in range(len(A) - 1, i, -1):
if A[j][1] < A[j - 1][1]:
A[j], A[j - 1] = A[j - 1], A[j]
return A
def selection_sort(A):
for i in range(len(A)):
mini = i
for j in range(i, len(A)):
if A[j][1] < A[mini][1]:
mini = j
if mini != i:
A[i], A[mini] = A[mini], A[i]
return A
def is_stable(A, B):
for val in range(1, 10):
v = str(val)
if [a[0] for a in A if a[1] == v] != [b[0] for b in B if b[1] == v]:
return False
return True
N = int(input())
A = list(input().split())
A_bubble = bubble_sort(A[:])
printA(A_bubble)
print("Stable" if is_stable(A, A_bubble) else "Not stable")
A_select = selection_sort(A[:])
printA(A_select)
print("Stable" if is_stable(A, A_select) else "Not stable")
| 1 | 25,304,843,840 | null | 16 | 16 |
N,K = map(int, input().split())
P=list(map(int, input().split()))
print(sum(sorted(P)[0:K]))
|
n = int(input())
A = list(map(int, input().split()))
total = 0
min_ = A[0]
for i in range(n):
if A[i] > min_:
min_ = A[i]
else:
total += (min_ - A[i])
print(total)
| 0 | null | 8,159,608,854,600 | 120 | 88 |
s = input()
d = {'ABC': 'ARC', 'ARC': 'ABC'}
print(d[s])
|
S = ["ABC","ARC"]
print(S[S.index(input())-1])
| 1 | 24,066,857,124,138 | null | 153 | 153 |
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]
|
import sys
chash = {}
for i in range( ord( 'a' ), ord( 'z' )+1 ):
chash[ chr( i ) ] = 0
while True:
line = sys.stdin.readline().rstrip()
if not line:
break
for i in range( len( line ) ):
if line[i].isalpha():
chash[ line[i].lower() ] += 1
for i in range( ord( 'a' ), ord( 'z' )+1 ):
print( "{:s} : {:d}".format( chr( i ), chash[ chr( i ) ] ) )
| 1 | 1,636,124,255,040 | null | 63 | 63 |
n, x, m = [int(_) for _ in input().split()]
d = {}
d_rev = {}
d[x] = 0
d_rev[0] = x
c = 0
while True:
c += 1
x = (x ** 2) % m
if x in d:
roop_idx = d[x]
break
else:
d[x] = c
d_rev[c] = x
ans = 0
if roop_idx >= n:
for i in range(n):
ans += d_rev[i]
print(ans)
else:
for i in range(roop_idx):
ans += d_rev[i]
roop_num = len(d) - roop_idx
roop_sum = 0
for i in range(roop_idx, len(d)):
roop_sum += d_rev[i]
ans += ((n-roop_idx)//roop_num) * roop_sum
roop_last = (n-roop_idx)%roop_num
for i in range(roop_last):
ans += d_rev[roop_idx + i]
print(ans)
|
#import numpy as np
import math
import collections
import bisect
def main():
a = int(input())
print(a + a**2 + a**3)
if __name__ == '__main__':
main()
| 0 | null | 6,462,092,649,500 | 75 | 115 |
t = input() * 2
if input() in t:
print('Yes')
else:
print('No')
|
s = input()
p = input()
if p in s*2:
print('Yes')
else:
print('No')
| 1 | 1,703,403,694,310 | null | 64 | 64 |
x = int(input())
print((x == 0) * 1 + (x == 1) * 0)
|
N = int(input())
li = []
for i in input().split():
li.append(int(i))
a = 1
count = 0
for i in li:
if a % 2 == 1 and i % 2 == 1:
count += 1
a += 1
print(count)
| 0 | null | 5,324,580,364,224 | 76 | 105 |
import sys
n = int(sys.stdin.readline().strip())
S = map(int, sys.stdin.readline().strip().split(" "))
n = int(sys.stdin.readline().strip())
T = map(int, sys.stdin.readline().strip().split(" "))
res = []
for t in T:
res.append(int(S.count(t) != 0))
print sum(res)
|
import math
def is_prime(x):
root = int(math.sqrt(x))+1
if x == 2:
return True
else:
for i in range(2, root+1):
if x % i == 0:
return False
return True
'''
def find_prime(x):
while True:
if x == 2:
return x
else:
for i in range(2, x+1):
if x % i == 0:
if i == x:
return x
else:
break
else:
continue
x += 1
'''
def main():
x = int(input())
while True:
if is_prime(x) == False:
x += 1
else:
print(x)
break
if __name__ == "__main__":
main()
| 0 | null | 52,846,188,075,720 | 22 | 250 |
n = int(input())
pr = {}
for i in range(n):
s = input()
if pr != s:
pr[s] = True
print(len(pr))
|
import sys
sys.setrecursionlimit(10**8)
N = int(input())
X = input()
if X == '0':
for _ in range(N):
print(1)
exit()
mem = [None] * (200005)
mem[0] = 0
def f(n):
if mem[n] is not None: return mem[n]
c = bin(n).count('1')
r = 1 + f(n%c)
mem[n] = r
return r
for i in range(200005):
f(i)
cnt = X.count('1')
a,b = cnt+1, cnt-1
ans = [None] * N
x = int(X,2)
n = x % a
for i,c in reversed(list(enumerate(X))):
if c=='1': continue
ans[i] = mem[(n+pow(2,N-i-1,a))%a] + 1
if b:
n = x % b
for i,c in reversed(list(enumerate(X))):
if c=='0': continue
ans[i] = mem[(n-pow(2,N-i-1,b))%b] + 1
else:
for i in range(N):
if ans[i] is None:
ans[i] = 0
print(*ans, sep='\n')
| 0 | null | 19,317,559,531,592 | 165 | 107 |
def main():
X, K, D = map(int, input().split())
X = abs(X)
a = X // D
ans = 0
if a <= K:
K -= a
ans = X - D * a
if K % 2 != 0:
ans = abs(ans - D)
else:
ans = X - D * K
print(ans)
if __name__ == "__main__":
main()
|
while 1:
H,W = map(int,input().split())
if H == 0 and W == 0:
break
col1 = "#." * ((W + 1) // 2)
col2 = ".#" * ((W + 1) // 2)
print((col1[:W] + "\n" + col2[:W] + "\n") * (H // 2) + (col1[:W] + "\n") * (H % 2))
| 0 | null | 3,038,444,096,668 | 92 | 51 |
s = int(input())
a = [0] * (s+1)
if s == 1:
print(0)
else:
a[0]=1
a[1]=0
a[2]=0
mod = 10**9+7
for i in range(3,s+1):
a[i] = a[i-1]+a[i-3]
print(int(a[s] % mod))
|
import sys
n, k = map(int, input().split())
P = int(1e9+7)
def cmb(n, r, P):
r = min(r, n - r)
inv_y = 1
for i in range(1, r + 1):
inv_y = (inv_y * i) % P
inv_y = pow(inv_y, P - 2, P)
x = 1
for i in range(n - r + 1, n + 1):
x = x * i % P
return (x * inv_y) % P
if k >= n:
print(cmb(2*n-1, n, P))
sys.exit()
if k == 1:
print((n * n - 1) % P)
sys.exit()
ans = 1
comb1 = 1
comb2 = 1
for i in range(1, k + 1):
iinv = pow(i, P-2, P)
comb1 = ((comb1 * (n - i)) * (iinv)) % P
comb2 = ((comb2 * (n - i + 1)) * (iinv)) % P
ans = (ans + comb1*comb2) % P
print(ans)
| 0 | null | 35,305,648,456,480 | 79 | 215 |
X=int(input())
for i in range(1,10000):
if (i*X)%360==0:
print(i)
break
|
import math
def average(l):
return sum(l) / len(l)
def var(l):
a = average(l)
return sum(map(lambda x: (x-a)**2, l)) / len(l)
def std(l):
return math.sqrt(var(l))
if __name__ == '__main__':
while True:
n = int(input())
if n == 0:
break
l = [int(i) for i in input().split()]
print("{0:.5f}".format(std(l)))
| 0 | null | 6,582,244,637,370 | 125 | 31 |
#!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations_with_replacement, compress
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
def main():
N, M, Q = LI()
abcd = [LI() for _ in range(Q)]
ans = 0
for A in combinations_with_replacement(range(1, M + 1), N):
tmp = 0
for (a, b, c, d) in abcd:
tmp += d if (A[b-1] - A[a-1] == c) else 0
ans = max(ans, tmp)
print(ans)
main()
|
n = int(input())
S = [int(i) for i in input().split(' ')]
q = int(input())
T = [int(i) for i in input().split(' ')]
result = 0
for t in T:
for s in S:
if t == s:
result += 1
break
print(result)
| 0 | null | 13,815,682,636,712 | 160 | 22 |
import bisect
from itertools import accumulate
N, M = map(int, input().split())
A = sorted(map(int, input().split()))
S = [0] + list(accumulate(A))
def calc(x):
_total = 0
_num = 0
for i in range(N):
j = bisect.bisect_left(A, x - A[i])
_num += N - j
_total += S[N] - S[j]
_total += A[i] * (N - j)
return _total, _num
left = 0
right = 200005
while right - left > 1:
center = (left + right) // 2
if calc(center)[1] >= M:
left = center
else:
right = center
total, num = calc(left)
ans = total
ans -= (num - M) * left
print(ans)
|
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
import bisect
n, m = map(int, input().split())
a = [int(item) for item in input().split()]
a.sort()
a_rev = sorted(a, reverse=True)
cumsum = [0]
for item in a:
cumsum.append(cumsum[-1] + item)
# Use pair which sum goes over mid
l = 0; r = 10**10
while r - l > 1:
mid = (l + r) // 2
to_use = 0
for i, item in enumerate(a_rev):
useless = bisect.bisect_left(a, mid - item)
to_use += n - useless
if to_use >= m:
l = mid
else:
r = mid
ans = 0
total_use = 0
for i, item in enumerate(a_rev):
useless = bisect.bisect_left(a, l - item)
to_use = n - useless
total_use += to_use
ans += item * to_use + cumsum[n] - cumsum[n - to_use]
print(ans - l * (total_use - m))
| 1 | 107,986,605,388,640 | null | 252 | 252 |
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, combinations, chain, product
from functools import lru_cache
from collections import deque, defaultdict
from operator import itemgetter
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7
DEBUG = 'ONLINE_JUDGE' not in sys.argv
def meg(f, ok, ng):
while abs(ok-ng)>1:
mid = (ok+ng)//2
if f(mid):
ok=mid
else:
ng=mid
return ok
def get_inv(n, modp):
return pow(n, modp-2, modp)
def factorials_list(n, modp): # 10**6
fs = [1]
for i in range(1, n+1):
fs.append(fs[-1] * i % modp)
return fs
def invs_list(n, fs, modp): # 10**6
invs = [get_inv(fs[-1], modp)]
for i in range(n, 1-1, -1):
invs.append(invs[-1] * i % modp)
invs.reverse()
return invs
def comb(n, k, modp):
num = 1
for i in range(n, n-k, -1):
num = num * i % modp
den = 1
for i in range(2, k+1):
den = den * i % modp
return num * get_inv(den, modp) % modp
def comb_from_list(n, k, modp, fs, invs):
return fs[n] * invs[n-k] * invs[k] % modp
#
class UnionFindEx:
def __init__(self, size):
#正なら根の番号、負ならグループサイズ
self.roots = [-1] * size
def getRootID(self, i):
r = self.roots[i]
if r < 0: #負なら根
return i
else:
r = self.getRootID(r)
self.roots[i] = r
return r
def getGroupSize(self, i):
return -self.roots[self.getRootID(i)]
def connect(self, i, j):
r1, r2 = self.getRootID(i), self.getRootID(j)
if r1 == r2:
return False
if self.getGroupSize(r1) < self.getGroupSize(r2):
r1, r2 = r2, r1
self.roots[r1] += self.roots[r2] #サイズ更新
self.roots[r2] = r1
return True
Yes = 'Yes'
No = 'No'
def dprint(*args, **kwargs):
if DEBUG:
print(*args, **kwargs)
def main():
N, K = mis()
P = list(map(lambda x: x-1, mis()))
C = lmis()
ans = -INF
for i in range(N):
p = i
tmp_score = 0
k = K
cycle = 0
while k:
p = P[p]
tmp_score += C[p]
ans = max(ans, tmp_score)
k -= 1
cycle += 1
if p==i:
if tmp_score < 0:
break
elif k > cycle*2:
skip_loop = (k - cycle)//cycle
tmp_score *= skip_loop + 1
k -= skip_loop * cycle
ans = max(ans, tmp_score)
print(ans)
main()
|
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
G = [-1 for i in range(N+1)]
for i, v in enumerate(P):
G[i+1] = (v, C[v-1])
ans = -float("inf")
for i in range(1, N+1):
loop = []
S = i
visited = [False for i in range(N+1)]
while visited[S] == False:
loop.append(G[S][-1])
visited[S] = True
S = G[S][0]
circle_sum = sum(loop)
this_case_ans = -float("inf")
if circle_sum < 0:
pass_sum = 0
for i in range(len(loop)):
pass_sum += loop[i]
this_case_ans = max(this_case_ans, pass_sum)
ans = max(ans, this_case_ans)
continue
else:
L = len(loop)
for i in range(1, L):
loop[i] += loop[i-1]
loop.insert(0, -float("inf"))
for i in range(1, L+1):
loop[i] = max(loop[i], loop[i-1])
loop[0] = 0
if K//L > 0:
this_case_ans = max(K//L * circle_sum +
loop[K % L], (K//L-1)*circle_sum + loop[-1])
else:
for i in range(1, K+1):
this_case_ans = max(this_case_ans, loop[i])
ans = max(ans, this_case_ans)
print(ans)
| 1 | 5,393,929,632,448 | null | 93 | 93 |
#!/usr/bin/env python3
import sys
s = input()
s2 = s[:(len(s) - 1) // 2]
s3 = s[(len(s) + 3) // 2 - 1 :]
if s == s[::-1]:
if s2 == s2[::-1]:
if s3 == s3[::-1]:
print("Yes")
sys.exit()
print("No")
|
K = int(input())
num = 0
for i in range(0,K):
num = num*10 + 7
if num % K == 0:
print(i + 1)
exit()
num %= K
print(-1)
| 0 | null | 26,175,087,917,888 | 190 | 97 |
n = input()
c = input()
i = 0
while 1:
l = c.find('W')
r = c.rfind('R')
if l == -1 or r == -1 or l >= r:
break
c = c[:l] + 'R' + c[l + 1:r] + 'W' + c[r + 1:]
i += 1
print(i)
|
# 初期入力
from bisect import bisect_left
import sys
#input = sys.stdin.readline #文字列では使わない
N = int(input())
c =input().strip()
ans =0
r =[i for i, x in enumerate(c) if x == 'R'] #全体の中でRのIndex
r_num =len(r) #全体でRの数
ans =bisect_left(r,r_num) #呪われないためのRとWの境界
print(r_num -ans) #境界より右側のRの数
| 1 | 6,242,836,447,392 | null | 98 | 98 |
MOD = 998244353
N = int(input())
D = list(map(int, input().split()))
if D[0] != 0:
print(0)
exit()
D_2 = [0]*(max(D)+1)
for i in D:
D_2[i] += 1
if D_2[0] != 1:
print(0)
exit()
ans = 1
for i in range(1,max(D)+1):
ans *= D_2[i-1]**D_2[i]
ans %= MOD
print(ans)
|
def my_pow(base, n, mod):
if n == 0:
return 1
x = base
y = 1
while n > 1:
if n % 2 == 0:
x *= x
n //= 2
else:
y *= x
n -= 1
x %= mod
y %= mod
return x * y % mod
N = int(input())
D = list(map(int, input().split()))
dmax = max(D)
MOD = 998244353
cnt = [0] * (10 ** 5 + 1)
for d in D:
cnt[d] += 1
if D[0] or cnt[0] != 1:
print(0)
exit()
ans = cnt[0]
for i in range(1, dmax + 1):
now = my_pow(cnt[i - 1], cnt[i], MOD)
ans *= now
ans %= MOD
print(ans)
| 1 | 155,102,940,212,242 | null | 284 | 284 |
import math
class point:
def __init__(self, p):
self._x = p[0]
self._y = p[1]
def disp(self):
print("{0:f} {1:f}".format(self._x, self._y))
@property
def x(self):
return self._x
@property
def y(self):
return self._y
def get_s(p1, p2):
p = point((p1.x/3*2 + p2.x/3, p1.y/3*2 + p2.y/3))
return p
def get_t(p1, p2):
p = point((p1.x/3 + p2.x/3*2, p1.y/3 + p2.y/3*2))
return p
def get_u(s, t):
x = (t.x - s.x)*math.cos(math.radians(60)) - (t.y - s.y)*math.sin(math.radians(60)) + s.x
y = (t.x - s.x)*math.sin(math.radians(60)) + (t.y - s.y)*math.cos(math.radians(60)) + s.y
return point((x, y))
def kock(n, p1, p2):
if n == 0:
return
else:
s = get_s(p1, p2)
t = get_t(p1, p2)
u = get_u(s, t)
kock(n-1, p1, s)
s.disp()
kock(n-1, s, u)
u.disp()
kock(n-1, u, t)
t.disp()
kock(n-1, t, p2)
return
if __name__ == '__main__':
n = int(input())
p1 = point((0, 0))
p2 = point((100, 0))
p1.disp()
kock(n, p1, p2)
p2.disp()
|
while 1:
H, W = map(int, input().split())
if H == 0 and W == 0:
break
print("#"*W)
line = '#' + ('.' * (W - 2)) + '#'
for i in range(0, H - 2):
print(line)
print("#"*W)
print()
| 0 | null | 485,375,368,960 | 27 | 50 |
N = int(input())
S = input()
A = []
x = 0
for i in range(N):
A.append(S[i])
for i in range(N):
if i != N - 1:
if A[i + 1] == A[i]:
x += 1
print(len(A) - x)
|
N=int(input())
S=list(input())
a=0#色変化
for i in range(N-1):
if not S[i]==S[i+1]:
a=a+1
print(a+1)
| 1 | 169,492,530,947,202 | null | 293 | 293 |
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = [map(int, input().split()) for _ in range(M)]
x, y, c = [list(x) for x in zip(*xyc)]
m = min(a)+min(b)
for i in range(M):
tmp = a[x[i]-1]+b[y[i]-1]-c[i]
m = min(m, tmp)
print(m)
|
N = input()
print('Yes' if '7' in N else 'No')
| 0 | null | 44,426,561,584,470 | 200 | 172 |
while True:
H, W = map(int, input().split())
if not(H or W):
break
print('#' * W)
for i in range(H-2):
print('#', end='')
for j in range(W-2):
print('.', end='')
print('#')
print('#' * W, end='\n\n')
|
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))
n = ini()
a = inl()
ans = [0] * n
for i in a:
ans[i-1] += 1
out(ans)
| 0 | null | 16,730,852,086,688 | 50 | 169 |
import math
a,b,c,d=map(int,input().split())
print("Yes") if math.ceil(c/b)<=math.ceil(a/d) else print("No")
|
import math
A,B,C,D = map(int, input().split())
Taka=A/D
Aoki=C/B
if math.ceil(Taka)>=math.ceil(Aoki):
print("Yes")
else:
print("No")
| 1 | 29,665,336,084,020 | null | 164 | 164 |
a, b, c, d = map(int, input().split())
ans = -float("INF") # 答えがマイナスになることがあるので、負の無限大を初期値にしておきます
for x in (a, b):
for y in (c, d):
ans = max(ans, x * y)
print(ans)
|
a, b, c, d = map(int, input().split())
ac = a * c
ad = a * d
bc = b * c
bd = b * d
ans_1 = max(ac,ad)
ans_2 = max(bc, bd)
ans = max(ans_1, ans_2)
print(ans)
| 1 | 3,071,274,968,708 | null | 77 | 77 |
alp_count = [0]*26
string = open(0).read()
string = string.lower()
alp = [chr(ord("a")+i) for i in range(26)]
c = 0
for j in range(26):
c = string.count(alp[j])
alp_count[j] += c
print("%s : %d"%(alp[j],alp_count[j]))
|
import sys
a = [0]*26
s = sys.stdin.read().lower()
for i in map(chr, range(ord('a'), ord('z')+1)):
print(i, ':', s.count(i))
| 1 | 1,656,482,509,348 | null | 63 | 63 |
from sys import stdin
line = stdin.readline()
input = [int(x) for x in line.rstrip().split()]
if input[0] * 500 >= input[1]:
print('Yes')
else:
print('No')
|
A, B = map(int, input().split())
if(500*A >= B):
print('Yes')
else:
print('No')
| 1 | 98,011,747,426,682 | null | 244 | 244 |
h, w, k = map(int, input().split())
s = [list(map(int, list(input()))) for _ in range(h)]
result = []
if h*w<=k:
result.append(0)
else:
for i in range(2**(h-1)):
checker, num, p = 0, i ,[0]
for _ in range(h):
p.append(p[-1]+num%2)
checker += num%2
num >>= 1
x = 0
c = [0 for _ in range(checker+1)]
for j in range(w):
num = i
nex = [0 for _ in range(checker+1)]
for m in range(h):
nex[p[m]] += s[m][j]
if max(nex) > k:
x = float('inf')
break
if all(nex[m]+c[m] <= k for m in range(checker+1)):
c = [c[I]+nex[I] for I in range(checker+1)]
else:
x += 1
c = nex
result.append(checker+x)
print(min(result))
|
N,*A = map(int, open(0).read().split())
if len(set(A)) == len(A):
print('YES')
else:
print('NO')
| 0 | null | 61,253,649,787,950 | 193 | 222 |
n,k=list(map(int ,input().split()))
h=list(map(int ,input().split()))
count=0
for i in range(0,len(h)):
if(h[i] == k or h[i] >=k ):
count+=1
else:
count+=0
print(int(count))
|
number, req = map(int, input().split())
friends = list(map(int, input().split()))
allowed = 0
for i in friends:
if i >= req: allowed += 1
print(allowed)
| 1 | 178,731,630,053,380 | null | 298 | 298 |
while(True):
m, f, r = map(int, input().split())
if(m == f == r == -1): break
score = m + f
if(m==-1 or f==-1): print('F')
elif(score >= 80): print('A')
elif(score >= 65): print('B')
elif(score >= 50): print('C')
elif(score >= 30):
if(r >= 50): print('C')
else: print('D')
else: print('F')
|
#65
import math
while True:
n=int(input())
if n==0:
break
s=list(map(int,input().split()))
m=sum(s)/n
a=0
for i in range(n):
a+=(s[i]-m)**2
b=math.sqrt(a/n)
print(b)
| 0 | null | 726,606,757,150 | 57 | 31 |
def fib(n):
if n==0:
return 1
elif n==1:
return 1
else:
a,b=1,2
for i in range(n-2):
a,b=b,a+b
return b
print(fib(int(input())))
|
memo = [1, 1]
def fib(n):
if (n < len(memo)):
return memo[n]
memo.append(fib(n-1) + fib(n-2))
return memo[n]
N = int(input())
print(fib(N))
| 1 | 1,585,588,812 | null | 7 | 7 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: C_fix
# CreatedDate: 2020-06-27 13:59:01 +0900
# LastModified: 2020-06-27 14:04:38 +0900
#
import os
import sys
# import numpy as np
# import pandas as pd
def main():
n = int(input())
s = []
for i in range(n):
s.append(input())
s = list(set(s))
print(len(s))
if __name__ == "__main__":
main()
|
n = input()
for i in range(n):
s = map(int, raw_input().split())
s.sort()
if s[2]**2 == (s[0]**2) + (s[1]**2): print "YES"
else: print "NO"
| 0 | null | 15,168,367,414,936 | 165 | 4 |
N = int(input())
A = list(map(int,input().split()))
a = [0]*N
for i in range(N):
a[A[i]-1] = i + 1
print(*a)
|
N, M = map(int, input().split())
H = list(map(int, input().split()))
OK = [True] * N
for _ in range(M):
A, B = map(lambda x: int(x)-1, input().split())
if H[A] < H[B]:
OK[A] = False
elif H[A] > H[B]:
OK[B] = False
else:
OK[A] = False
OK[B] = False
ans = sum(OK)
print(ans)
| 0 | null | 103,035,655,148,218 | 299 | 155 |
input()
a = [int(x) for x in input().split(" ")]
print(*a[::-1])
|
input()
numbers = input().split()
numbers.reverse()
print(" ".join(numbers))
| 1 | 968,039,292,122 | null | 53 | 53 |
from decimal import Decimal
a, b = map(Decimal,input().split())
ans = int(a * b)
print(ans)
|
A, B, C = map(int, input().split())
print(C, A, B)
| 0 | null | 27,422,450,873,610 | 135 | 178 |
N = input()
S = set(map(int, input().split()))
Q = input()
T = set(map(int, input().split()))
intersection = S & T
print(len(intersection))
|
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):
s.append(t[i])
j = 0
while t[i] != s[j]:
j += 1
if j != n:
count += 1
del s[n]
print(count)
| 1 | 67,265,967,070 | null | 22 | 22 |
N=int(input())
alpha='abcdefghijklmnopqrstuvwxyz'
ans=''
while 26<N:
s=(N-1)%26
ans=alpha[s]+ans
N=int(N-1)//26
ans=alpha[N-1]+ans
print(ans)
|
x = int(input())
import math
print(360*x//math.gcd(360,x)//x)
| 0 | null | 12,448,367,260,198 | 121 | 125 |
k = int(input())
from collections import deque
q = deque() # FIFOキューの作成
for i in range(1,10):
q.append(str(i))
for i in range(k-1):
a = q.popleft()
last = int(a[-1:])
if last == 0:
q.append(a+"0")
q.append(a + "1")
elif last ==9:
q.append(a+"8")
q.append(a + "9")
else:
q.append(a + str(last - 1))
q.append(a + str(last ))
q.append(a + str(last + 1))
print(q.popleft())
|
from collections import deque
K = int(input())
nums = deque([])
for i in range(1, 10):
nums.appendleft(i)
count = 1
while count < K:
num = nums.pop()
last = int(str(num)[-1])
for i in range(max(0, last-1), min(10, last+2)):
nums.appendleft(int(str(num)+str(i)))
count += 1
print(nums.pop())
| 1 | 39,961,788,635,258 | null | 181 | 181 |
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)
|
import itertools
N = int(input())
L = list(map(int, input().split()))
combinations = list(itertools.combinations(range(N), 3))
count = 0
for cmb in combinations:
flag = True
for i in range(3):
if L[cmb[i]] + L[cmb[(i + 1) % 3]] > L[cmb[(i + 2) % 3]] and L[cmb[i]] != L[cmb[(i + 1) % 3]]:
continue
else:
flag = False
break
if flag:
count += 1
print(count)
| 1 | 5,073,812,063,618 | null | 91 | 91 |
S = input()
T = input()
if(S == T[0:-1] and len(S) + 1 == len(T)):
print("Yes")
else:
print("No")
|
S = input()
T = input()
S = list(S)
T = list(T)
for i in range(len(S)):
if S[i] != T[i]:
print('No')
exit()
print('Yes')
| 1 | 21,447,384,306,248 | null | 147 | 147 |
h,w,y=map(int,input().split())
c=[input() for _ in range(h)]
black=0
for i in range(h):
for j in range(w):
if c[i][j]=="#":
black+=1
if black<y:
print("0")
exit()
hb=[]
wb=[]
for i in range(h):
hb.append(c[i].count("#"))
for i in range(w):
count=0
for j in range(h):
if c[j][i]=="#":
count+=1
wb.append(count)
bit=[]
for i in range(2**(h+w)): #行:[:h]、列:[h+1:]
bit.append(bin(i)[2:].zfill(h+w))
ans=0
for i in bit:
x=black
for j in range(h):
if i[j]=="1":
for k in range(w):
if i[h+k]=="1" and c[j][k]=="#":
x+=1
for j in range(h):
if i[j]=="1":
x-=hb[j]
for j in range(w):
if i[h+j]=="1":
x-=wb[j]
if x==y:
ans+=1
print(ans)
|
def main():
n = int(input())
S, T = [], []
for _ in range(n):
s, t = input().split()
S.append(s)
T.append(int(t))
x = input()
print(sum(T[S.index(x) + 1:]))
if __name__ == '__main__':
main()
| 0 | null | 53,237,138,653,032 | 110 | 243 |
listA=[]
listOP=[]
listB=[]
count=0
while True:
a,op,b=input().split()
listA.append(int(a))
listOP.append(op)
listB.append(int(b))
if op=="?":
del listA[len(listA)-1]
del listOP[len(listOP)-1]
del listB[len(listB)-1]
break
#入力パートここまで。計算出力パートここから
while count<=len(listA)-1:
if listOP[count]=="+":
print(listA[count]+listB[count])
elif listOP[count]=="-":
print(listA[count]-listB[count])
elif listOP[count]=="*":
print(listA[count]*listB[count])
elif listOP[count]=="/":
print(listA[count]//listB[count])
else:
print("ERROR")
count+=1
|
while True:
H, W = [int(i) for i in input().split()]
if H == 0 and W == 0:
break
for i in range(H):
for j in range(W):
if (i + j) % 2 == 0:
print('#', end='')
else:
print('.', end='')
print('')
print('')
| 0 | null | 763,562,261,030 | 47 | 51 |
import sys
import math
input = sys.stdin.readline
ceil = math.ceil
def main():
def isok(z,val):##適宜変更
return (z-val<=2*d)
def bisect(ls,val): ##valの関数isok(x,val)がTrueとなる一番右のindex を返す 全部Falseなら-1
ok = -1
ng = len(ls)
idx = (ok+ng)//2
while ng-ok>1:
num = ls[idx]
if isok(num,val):
ok = idx
else:
ng = idx
idx = (ok+ng)//2
return ok ##一番右のTrueのindex Trueの個数はok+1こ
n,d,a = map(int,input().split())
mon = []
for i in range(n):
x,h = map(int,input().split())
mon.append((x,h))
mon.sort()
keys = [ls[0] for ls in mon] #bisect用の配列
damage = [0]*(n+1)
ans = 0
for i in range(n):
x,h = mon[i]
res = h-damage[i]
if res>0:##体力が残ってたら
c = ceil(res/a)
ans+=c
idx = bisect(keys,x) ##爆風が届くぎりぎりの位置
if idx==-1:continue
damage[i] +=a*c
damage[idx+1] -=a*c
damage[i+1] += damage[i]
print(ans)
if __name__=="__main__":
main()
|
import sys,queue,math,copy,itertools,bisect,collections,heapq
def main():
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
SI = lambda : sys.stdin.readline().rstrip()
N,D,A = LI()
X = []; XH = []
for _ in range(N):
x,h = LI()
X.append(x); XH.append((x,h))
XH.sort()
X.sort()
down = [0] * (N+1)
p = 0
ans = 0
for i in range(N):
if p < XH[i][1]:
b = -(-(XH[i][1]-p)//A)
ans += b
p += b * A
down[bisect.bisect(X,X[i]+2*D)-1] += b*A
p -= down[i]
print(ans)
if __name__ == '__main__':
main()
| 1 | 82,006,203,142,852 | null | 230 | 230 |
w = input().lower()
t = ""
while True:
tmp = input()
t += " "+tmp.lower()
if tmp=="END_OF_TEXT":
break
t=t.split()
print(t.count(w))
|
import re
W = input()
T = []
count = 0
while(1):
line = input()
if (line == "END_OF_TEXT"):
break
words = list(line.split())
for word in words:
T.append(word)
for word in T:
matchOB = re.fullmatch(W, word.lower())
if matchOB:
count += 1
print(count)
| 1 | 1,813,521,031,030 | null | 65 | 65 |
#C - Welcome to AtCoder
N,M = map(int,input().split())
S_P_list = []
for _ in range(M):
p,s = input().split()
S_P_list.append((int(p),s))
#Pに着目して安定ソート
S_P_list = sorted(S_P_list,key = lambda x:x[0],reverse = False)
#ACが存在するPの集合
AC_list = list(set([i[0] for i in S_P_list if i[1] == 'AC']))
WA = 0
AC = 0
for i in range(M):
if (S_P_list[i][0] in AC_list):
if S_P_list[i][1] == 'AC':
AC += 1
AC_list.remove(S_P_list[i][0])
else:
WA += 1
print(AC,WA)
|
def MI(): return map(int, input().split())
N,X,T=MI()
if N%X!=0:
ans=(N//X+1)*T
else:
ans=N//X*T
print(ans)
| 0 | null | 48,857,142,219,658 | 240 | 86 |
x = int(input())
cnt, ans = 100, 0
while cnt < x:
ans += 1
cnt = cnt * 101 // 100
print(ans)
|
import math
X = int(input())
count = 0
s = 100
while s < X:
#s = math.floor(s*1.01)
s += s//100
count += 1
print(count)
| 1 | 27,271,307,821,482 | null | 159 | 159 |
iterator = [["NS", "S"], ["NT", "T"]]
var = {}
for i, j in iterator:
var[i] = int(input())
var[j] = [int(k) for k in input().split()]
res = 0
for T in var["T"]:
if T in var["S"]:
res += 1
print(res)
|
n =int(input())
S = list(map(int, input().split(' ')))
q = int(input())
T = list(map(int, input().split(' ')))
count = 0
for t in T:
if t in S:
count += 1
print(count)
| 1 | 66,140,602,730 | null | 22 | 22 |
N = int(input())
A = list(map(int,input().split()))
minval = 0
ans = 1000
for i in range(1, N):
if A[i] > A[minval]:
pstock = ans // A[minval]
ans = ans%A[minval] + A[i]*pstock
minval = i
print(ans)
|
#親要素を示す
par = {}
sum_union = {}
len_union = {}
# 初期化 -- すべての要素が根である --
def init(n):
for i in range(n):
par[i] = i
sum_union[i] = Cs[i]
len_union[i] = 1
return
# 根を求める
def root(x):
if par[x] == x:
return x
else:
#根の直下にxを置く
par[x] = root(par[x])
return par[x]
# 同じ集合に属するかどうかは根が同じかで判定
def same(x, y):
return root(x) == root(y)
# 別々のUnion同士を融合する
def unite(x, y):
rx = root(x)
ry = root(y)
if rx == ry:
return
else:
par[rx] = ry
tmp_sum = sum_union[rx] + sum_union[ry]
tmp_len = len_union[rx] + len_union[ry]
sum_union[ry] = tmp_sum
len_union[ry] = tmp_len
return
N, K = map(int, input().split())
Ps = list(map(lambda x: int(x) - 1, input().split()))
Cs = list(map(int, input().split()))
init(N)
# 結合
for i in range(N):
unite(i, Ps[i])
max_result = -(10**9+1)
for i in range(N):
ri = root(i)
if sum_union[ri] <= 0:
partial_range = min(K, len_union[ri])
roop_sum = 0
elif K < len_union[ri]:
partial_range = K
roop_sum = 0
else:
partial_range = (K % len_union[ri]) + len_union[ri]
roop_sum = sum_union[ri] * ((K // len_union[ri])-1)
pc = i
sum_list = []
sum_c = 0
for _ in range(partial_range):
pn = Ps[pc]
sum_c += Cs[pn]
sum_list.append(sum_c)
pc = pn
max_result = max(max_result, roop_sum + max(sum_list))
print(max_result)
| 0 | null | 6,343,458,404,298 | 103 | 93 |
def main():
S = input()
# my swapcase
for s in S:
o = ord(s)
if 97 <= o < 97 + 26:
o -= 32
elif 65 <= o < 65 + 26:
o += 32
print(chr(o), end="")
print("")
if __name__ == "__main__":
main()
|
s=input()
res=''
for i in s:
if i.islower():
i=i.upper()
elif i.isupper():
i=i.lower()
res+=i
print(res)
| 1 | 1,475,079,723,260 | null | 61 | 61 |
n=int(input())
l=[0]*(n+1)
for i in range(1,101):
for j in range(1,101):
for k in range(1,101):
s=i**2+j**2+k**2+i*k+i*j+j*k
if(s<=n):
l[s]+=1
for i in range(1,n+1):
print(l[i])
|
import collections
import sys
A = []
n = int(input())
for i in range(1,100):
for j in range(1,100):
for k in range(1,100):
A.append(i**2+j**2+k**2+i*j+j*k+k*i)
c = collections.Counter(A)
for x in range(1,n+1):
print(c[x])
sys.exit()
| 1 | 7,978,895,618,720 | null | 106 | 106 |
# coding: utf-8
# Your code here!
n,m=input().split()
a=n*int(m)
b=m*int(n)
nlist=[a,b]
nlist.sort()
print(nlist[0])
|
a,b = map(str, input().split())
a2 = a*int(b)
b2 = b*int(a)
print(a2) if a2 < b2 else print(b2)
| 1 | 84,834,530,761,500 | null | 232 | 232 |
#!python3
from time import perf_counter
tick = perf_counter() + 1.92
import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
from random import randrange
from bisect import bisect
def resolve():
G = 26
it = map(int, sys.stdin.read().split())
D = next(it)
C = [next(it) for i in range(G)]
S = [[next(it) for i in range(G)] for i in range(D)]
L = [[-1] for i in range(G)]
T = [0] * D
def update(di, qi):
score = 0
t0 = T[di]
score += S[di][qi]-S[di][t0]
a1 = li = L[t0][:]
ii = li.index(di)
la = D if len(li)-1 == ii else li[ii+1]
score -= C[t0] * (di-li[ii-1])*(la-di)
li.pop(ii)
a2 = li = L[qi][:]
ii = bisect(li, di)
li.insert(ii, di)
la = D if len(li)-1 == ii else li[ii+1]
score += C[qi] * (di-li[ii-1])*(la-di)
return score, (a1, a2)
U = 7
def calc(i, j):
score = S[i][j]
for k in range(G):
u = k - L[k][-1]
score -= C[k] * (u + u + U) * U // 2
score += C[k] * U * (i-L[j][-1])
return score
for di in range(D):
i, score = 0, calc(di, 0)
for qi in range(1, G):
x = calc(di, qi)
if x > score:
i, score = qi, x
T[di] = i
L[i].append(di)
while perf_counter() < tick:
di, qi = randrange(0, D), randrange(0, G)
diff, swap = update(di, qi)
if diff > 0:
score += diff
q0, T[di] = T[di], qi
L[q0], L[qi] = swap
print(*(i+1 for i in T), sep="\n")
if __name__ == "__main__":
resolve()
|
from time import time
from random import random
limit_secs = 2
start_time = time()
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
def calc_score(t):
score = 0
S = 0
last = [-1] * 26
for d in range(len(t)):
S += s[d][t[d]]
last[t[d]] = d
for i in range(26):
S -= c[i] * (d - last[i])
score += max(10 ** 6 + S, 0)
return score
def solution1():
return [i % 26 for i in range(D)]
def solution2():
t = None
score = -1
for i in range(26):
nt = [(i + j) % 26 for j in range(D)]
if calc_score(nt) > score:
t = nt
return t
#def solution3():
# t = []
# for _ in range(D):
# for i in range(26):
def optimize0(t):
return t
def optimize1(t):
score = calc_score(t)
while time() - start_time + 0.15 < limit_secs:
d = int(random() * D)
q = int(random() * 26)
old = t[d]
t[d] = q
new_score = calc_score(t)
if new_score < score:
t[d] = old
else:
score = new_score
return t
t = solution2()
t = optimize0(t)
print('\n'.join(str(e + 1) for e in t))
| 1 | 9,693,514,876,830 | null | 113 | 113 |
#!/usr/bin/env python3
def main():
from math import gcd
N = int(input())
A = []
INF = 10 ** 6 + 5
frequency = [0] * INF
for a in [int(x) for x in input().split()]:
A.append(a)
frequency[a] += 1
pairwise = True
for i in range(2, INF):
cnt = 0
for j in range(i, INF, i):
cnt += frequency[j]
if cnt > 1:
pairwise = False
if pairwise:
print("pairwise coprime")
return
g = 0
for i in range(N):
g = gcd(g, A[i])
if g == 1:
print('setwise coprime')
return
print('not coprime')
if __name__ == '__main__':
main()
|
R, C, K = map(int, input().split())
# = int(input())
p = []
for k in range(K):
p.append(list(map(int, input().split())))
maps = [[0 for _ in range(C)] for _ in range(R)]
for k in range(K):
maps[p[k][0]-1][p[k][1]-1] += p[k][2]
point1 = [[0 for _ in range(C)] for _ in range(R)]
point2 = [[0 for _ in range(C)] for _ in range(R)]
point3 = [[0 for _ in range(C)] for _ in range(R)]
point1[0][0] = maps[0][0]
for r in range(R):
for c in range(C):
a, b, d = point1[r][c], point2[r][c], point3[r][c]
if c < C - 1:
x = maps[r][c+1]
point1[r][c+1] = max(point1[r][c+1], x, a)
point2[r][c+1] = max(point2[r][c+1], a + x, b)
point3[r][c+1] = max(point3[r][c+1], b + x, d)
if r < R - 1:
point1[r+1][c] = maps[r+1][c] + max(a, b, d)
print(max(point1[-1][-1], point2[-1][-1], point3[-1][-1]))
| 0 | null | 4,841,435,541,666 | 85 | 94 |
import sys
N = int(input())
p = 0
for i in range(N):
A,B = list(map(int, input().split()))
if A == B:
p += 1
else:
p = 0
if p == 3:
print("Yes")
sys.exit()
print("No")
|
import sys
import math
from collections import defaultdict
from collections import deque
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def main():
N = NI()
ans = 0
for a in range(1, N):
ans += N // a
if N % a == 0:
ans -= 1
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 2,540,479,934,940 | 72 | 73 |
a,b,c,k=[int(i) for i in input().split()]
if a>=k:
print(k)
elif a+b>=k:
print(a)
else:
print(a-(k-a-b))
|
a,b,c,d = map(int,input().split())
cnt = d-a
if cnt > 0:
num = 1*a
cnt -=b
if cnt > 0:
num = a + (d-a-b)*(-1)
else:
num = 1*d
print(num)
| 1 | 21,939,865,015,038 | null | 148 | 148 |
import statistics
while True:
n = int(input())
if n == 0:
break
else:
data = [float(s) for s in input().split()]
print(statistics.pstdev(data))
|
import math
while True:
n = int(input())
if n == 0: break
points = list(map(int, input().split()))
mean = sum(points) / n
s = 0
for point in points:
s += (point - mean) ** 2
std = math.sqrt(s / n)
print(std)
| 1 | 193,845,516,522 | null | 31 | 31 |
def main():
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
class Combination:
def __init__(self, n_max, mod=10**9+7):
# O(n_max + log(mod))
self.mod = mod
f = 1
self.fac = fac = [f]
for i in range(1, n_max+1):
f = f * i % mod
fac.append(f)
f = pow(f, mod-2, mod)
self.facinv = facinv = [f]
for i in range(n_max, 0, -1):
f = f * i % mod
facinv.append(f)
facinv.reverse()
# "n 要素" は区別できる n 要素
# "k グループ" はちょうど k グループ
def __call__(self, n, r): # self.C と同じ
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
def C(self, n, r):
if not 0 <= r <= n:
return 0
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
def P(self, n, r):
if not 0 <= r <= n:
return 0
return self.fac[n] * self.facinv[n-r] % self.mod
def H(self, n, r):
if (n == 0 and r > 0) or r < 0:
return 0
return self.fac[n+r-1] * self.facinv[r] % self.mod * self.facinv[n-1] % self.mod
def rising_factorial(self, n, r): # 上昇階乗冪 n * (n+1) * ... * (n+r-1)
return self.fac[n+r-1] * self.facinv[n-1] % self.mod
def stirling_first(self, n, k): # 第 1 種スターリング数 lru_cache を使うと O(nk) # n 要素を k 個の巡回列に分割する場合の数
if n == k:
return 1
if k == 0:
return 0
return (self.stirling_first(n-1, k-1) + (n-1)*self.stirling_first(n-1, k)) % self.mod
def stirling_second(self, n, k): # 第 2 種スターリング数 O(k + log(n)) # n 要素を区別のない k グループに分割する場合の数
if n == k:
return 1 # n==k==0 のときのため
return self.facinv[k] * sum((-1)**(k-m) * self.C(k, m) * pow(m, n, self.mod) for m in range(1, k+1)) % self.mod
def balls_and_boxes_3(self, n, k): # n 要素を区別のある k グループに分割する場合の数 O(k + log(n))
return sum((-1)**(k-m) * self.C(k, m) * pow(m, n, self.mod) for m in range(1, k+1)) % self.mod
def bernoulli(self, n): # ベルヌーイ数 lru_cache を使うと O(n**2 * log(mod))
if n == 0:
return 1
if n % 2 and n >= 3:
return 0 # 高速化
return (- pow(n+1, self.mod-2, self.mod) * sum(self.C(n+1, k) * self.bernoulli(k) % self.mod for k in range(n))) % self.mod
def faulhaber(self, k, n): # べき乗和 0^k + 1^k + ... + (n-1)^k
# bernoulli に lru_cache を使うと O(k**2 * log(mod)) bernoulli が計算済みなら O(k * log(mod))
return pow(k+1, self.mod-2, self.mod) * sum(self.C(k+1, j) * self.bernoulli(j) % self.mod * pow(n, k-j+1, self.mod) % self.mod for j in range(k+1)) % self.mod
def lah(self, n, k): # n 要素を k 個の空でない順序付き集合に分割する場合の数 O(1)
return self.C(n-1, k-1) * self.fac[n] % self.mod * self.facinv[k] % self.mod
def bell(self, n, k): # n 要素を k グループ以下に分割する場合の数 O(k**2 + k*log(mod))
return sum(self.stirling_second(n, j) for j in range(1, k+1)) % self.mod
k = int(readline())
s = readline().rstrip().decode()
n = len(s)
ans = 0
mod = 10 ** 9 + 7
comb = Combination(n + k)
v = 1
for i in range(k + 1):
ans += comb(n + k, i) * v
ans %= mod
v *= 25
v %= mod
print(ans)
if __name__ == '__main__':
main()
|
n = int(input())
def cal(i):
s = (i + i*(n//i))*(n//i)*0.5
return s
ans = 0
for i in range(1, n+1):
ans += cal(i)
print(int(ans))
| 0 | null | 11,994,135,154,468 | 124 | 118 |
status = ['AC','WA','TLE','RE']
li = []
N = int(input())
for n in range(N):
li.append(input())
for s in status:
print(s,'x',li.count(s))
|
def main():
N, M = tuple([int(_x) for _x in input().split()])
print(N*(N-1)//2 + M*(M-1)//2)
main()
| 0 | null | 27,182,788,929,592 | 109 | 189 |
s = input()
p = list(s)
if p[len(p) - 1] == "?": #最後が?だったら
p[len(p) - 1] = "D" # Dにする
for i in range(len(p) - 1):
if p[i] == "?": # ?だったら
if i == 0: # 最初の文字
if p[i + 1] == "D" or p[i + 1] == "?": # 二番目の文字がDか?
p[i] = "P"
else: # 二番目の文字がDか?でなかったら
p[i] = "D"
else:
p[i] = "D" # D
print("".join(p))
|
import sys
input = lambda: sys.stdin.readline().rstrip()
def main():
k, x = map(int, input().split())
if x <= k * 500:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main()
| 0 | null | 58,133,937,518,538 | 140 | 244 |
A, B, C, D = map(int, input().split())
is_turn_of_takahashi = True
while A > 0 and C > 0:
if is_turn_of_takahashi:
C -= B
else:
A -= D
is_turn_of_takahashi = not is_turn_of_takahashi
print("Yes" if A > 0 else "No")
|
class monster:
def __init__(self, hp: int, ap: int):
self.hit_point = hp
self.attack_point = ap
self.status = 'healthy'
def attack(self, enemy: 'monster'):
enemy.defend(self.attack_point)
def defend(self, enemy_ap: int):
self.hit_point -= enemy_ap
if self.hit_point <= 0:
self.status = 'dead'
def is_alive(self) -> bool:
return not self.is_dead()
def is_dead(self) -> bool:
return self.status == 'dead'
def answer(t_hp: int, t_ap: int, a_hp: int, a_ap: int) -> str:
taka_monster = monster(t_hp, t_ap)
aoki_monster = monster(a_hp, a_ap)
while taka_monster.is_alive() and aoki_monster.is_alive():
taka_monster.attack(aoki_monster)
if aoki_monster.is_dead():
return 'Yes'
aoki_monster.attack(taka_monster)
if taka_monster.is_dead():
return 'No'
def main():
a, b, c, d = map(int, input().split())
print(answer(a, b, c, d))
if __name__ == '__main__':
main()
| 1 | 29,790,214,690,452 | null | 164 | 164 |
kuku = []
for i in range(1,10):
for j in range(1,10):
if i * j not in kuku:
kuku.append(i*j)
n = int(input())
if n in kuku:
print('Yes')
else:
print('No')
|
import sys
input = sys.stdin.readline
n = int(input())
flag = False
for i in range(1, 10):
if n % i == 0 and 1 <= n // i <= 9:
flag = True
break
if flag:
print("Yes")
else:
print("No")
| 1 | 160,248,666,338,020 | null | 287 | 287 |
import math
N=int(input())
a=1
sum=N
flag=True
while flag:
if a>math.sqrt(N):
break
if N%a==0:
b=N//a
if sum>a+b-2:
sum=a+b-2
a+=1
print(sum)
|
N=int(input())
move=10**12
for n in range(1,int(N**.5)+1):
if N%n==0:
move=min(move,N//n+n-2)
print(move)
| 1 | 160,935,500,962,810 | null | 288 | 288 |
n, x, m = map(int, input().split())
X = [-1] * m
P = []
sum_p = 0
while X[x] == -1: # preset
X[x] = len(P) # pre length
P.append(sum_p) # pre sum_p
sum_p += x # now sum_p
x = x*x % m
P.append(sum_p) # full sum_p
p_len = len(P) - 1
if n <= p_len:
print(P[n]) # sum_p
exit()
cyc_times, nxt_len = divmod(n - X[x], p_len - X[x])
cyc = (sum_p - P[X[x]]) * cyc_times
remain = P[X[x] + nxt_len]
print(cyc + remain)
|
from sys import stdin
class DList:
class Cell:
def __init__(self, k):
self.key = k
self.prev = None
self.next = None
def __init__(self):
self.head = DList.Cell(None)
self.last = DList.Cell(None)
self.head.next = self.last
self.last.prev = self.head
def insert(self, x):
c = DList.Cell(x)
c.prev = self.head
c.next = self.head.next
c.next.prev = c
self.head.next = c
def delete(self, x):
c = self.__find(x)
if c != None:
self.__delete(c)
def __delete(self, c):
c.prev.next = c.next
c.next.prev = c.prev
def __find(self, x):
c = self.head.next
while c != None and c.key != x:
c = c.next
return c
def deleteFirst(self):
self.__delete(self.head.next)
def deleteLast(self):
self.__delete(self.last.prev)
def __iter__(self):
self.it = self.head.next
return self
def __next__(self):
if self.it == self.last:
raise StopIteration
k = self.it.key
self.it = self.it.next
return k
dlist = DList()
n = int(stdin.readline())
for i in range(n):
cmd = stdin.readline()
if cmd.startswith('insert'):
dlist.insert(cmd[7:-1])
elif cmd.startswith('deleteFirst'):
dlist.deleteFirst()
elif cmd.startswith('deleteLast'):
dlist.deleteLast()
elif cmd.startswith('delete'):
dlist.delete(cmd[7:-1])
print(' '.join(dlist))
| 0 | null | 1,452,124,716,208 | 75 | 20 |
N, K = map(int, input().split())
numgcd = [0]*(K+1)
sumgcd = 0
mod = 10**9+7
for i in range(1, K+1)[::-1]:
numgcd[i] = pow(K//i, N, mod)
count = 2
while count*i <= K:
numgcd[i] -= numgcd[count*i]
count += 1
sumgcd += numgcd[i]*i
print(sumgcd%mod)
|
n = int(input())
lr_cnt = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1, n + 1):
str_i = str(i)
start = int(str_i[0])
end = int(str_i[-1])
lr_cnt[start][end] += 1
ans = 0
for i in range(10):
for j in range(10):
ans += lr_cnt[i][j] * lr_cnt[j][i]
print(ans)
| 0 | null | 61,598,647,940,522 | 176 | 234 |
def main():
mod = 998244353
N, K = map(int,input().split())
v = []
for _ in range(K):
L, R = map(int,input().split())
# for d in range(L, R+1):
# moves.append(d)
v.append((L, R))
v.sort()
dp = [0] * N # マスi-1に到達するまでの操作列の個数
sdp = [0] * (N + 1) # dp[i]までの累積和
dp[0] = 1
sdp[1] = 1
for n in range(1, N):
for p in v:
left = max(0, n - p[1])
right = max(0, n - p[0]+1)
dp[n] += (sdp[right] - sdp[left]) % mod
sdp[n+1] = (sdp[n] + dp[n]) % mod
print(dp[-1] % mod)
if __name__ == "__main__":
main()
|
n,k=map(int,input().split())
lst=[list(map(int,input().split())) for i in range(k)]
mod=998244353
dp=[0]*(2*n+10)
dp[0]=1
dp[1]=-1
for i in range(n):
for l,r in lst:
dp[i+l]+=dp[i]
dp[i+r+1]-=dp[i]
dp[i+1]+=dp[i]
dp[i+1]%=mod
print(dp[n-1])
| 1 | 2,706,982,757,372 | null | 74 | 74 |
input()
l = [int(i) for i in input().split()]
print(" ".join(map(str,l[::-1])))
|
# swag
from collections import deque
class SWAG_Stack():
def __init__(self, F):
self.stack1 = deque()
self.stack2 = deque()
self.F = F
self.len = 0
def push(self, x):
if self.stack2:
self.stack2.append((x, self.F(self.stack2[-1][1], x)))
else:
self.stack2.append((x, x))
self.len += 1
def pop(self):
if not self.stack1:
while self.stack2:
x, _ = self.stack2.pop()
if self.stack1:
self.stack1.appendleft((x, self.F(x, self.stack1[0][1])))
else:
self.stack1.appendleft((x, x))
self.stack1.popleft()
self.len -= 1
def sum_all(self):
if self.stack1 and self.stack2:
return self.F(self.stack1[0][1], self.stack2[-1][1])
elif self.stack1:
return self.stack1[0][1]
elif self.stack2:
return self.stack2[-1][1]
else:
raise IndexError
n,m = map(int, input().split())
s = input()
stack = SWAG_Stack(min)
stack.push((0,n))
turn = [-1]*(n+1)
turn[-1] = 0
for i in range(n-1, -1, -1):
if s[i] == "1":
stack.push((float("inf"), i))
else:
cost, ind = stack.sum_all()
if cost == float("inf"):
break
turn[i] = cost+1
stack.push((cost+1, i))
if stack.len > m:
stack.pop()
# print(turn)
if turn[0] == -1:
print(-1)
exit()
prev_turn=turn[0]
prev_ind = 0
ans = []
for i in range(1, n+1):
if prev_turn-turn[i] == 1:
ans.append(i-prev_ind)
prev_ind = i
prev_turn = turn[i]
print(*ans)
| 0 | null | 69,899,873,238,400 | 53 | 274 |
L = []
m, f, r = map(int, input().split())
while not(m == -1 and f == -1 and r == -1):
L.append([m, f, r])
m, f, r = map(int, input().split())
for i in L:
if i[0] == -1 or i[1] == -1:
print("F")
elif i[0] + i[1] >= 80:
print("A")
elif i[0] + i[1] >= 65:
print("B")
elif i[0] + i[1] >= 50:
print("C")
elif i[0] + i[1] >= 30 and i[2] >=50:
print("C")
elif i[0] + i[1] >= 30:
print("D")
else:
print("F")
|
m=f=r=0
while 1:
m,f,r=map(int,input().split())
x=m+f
if m==f==r==-1:break
elif m==-1 or f==-1 or x<30:print('F')
elif x>=80:print('A')
elif 65<=x<80:print('B')
elif 50<=x<65 or r>=50:print('C')
else:print('D')
| 1 | 1,231,339,283,708 | null | 57 | 57 |
x, n = map(int, input().split())
p = list(map(int, input().split()))
l = [i - x for i in p]
m = [0]
for i in range(1, 101):
m.append(-i)
m.append(i)
for i in range(201):
if (m[i] in l) == True:
continue
if (m[i] in l) == False:
print(x + m[i])
break
|
x,n = map(int,input().split())
p = list(map(int,input().split()))
dic = {}
lis = []
for i in range(0,102):
if i not in p:
dic[i] = abs(x-i)
lis.append(i)
mini = min(dic.values())
for j in lis:
if mini == dic[j]:
print(j)
break
| 1 | 14,055,489,659,032 | null | 128 | 128 |
def main():
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
n, k = map(int, readline().split())
a = list(map(int, readline().split()))
memo = [0] * (n + 1)
for _ in range(k):
flag = True
for i, aa in enumerate(a):
bf = (i - aa if i - aa >= 0 else 0)
af = (i + aa + 1 if i + aa < n else n)
memo[bf] += 1
memo[af] -= 1
for i in range(n):
memo[i + 1] += memo[i]
a[i] = memo[i]
if a[i] != n:
flag = False
memo[i] = 0
if flag:
break
print(*a)
if __name__ == '__main__':
main()
|
import numpy as np
from numba import njit
N, K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
a = np.array(A, dtype=int)
fin = [N] * N
@njit(cache=True)
def calc_b(a):
b = np.zeros(N, dtype=np.int64)
for i, _a in enumerate(a):
l = max(0, i - _a)
r = min(N - 1, i + _a)
# imos hou
b[l] += 1
if r + 1 < N:
b[r + 1] -= 1
b = np.cumsum(b)
# print('b_sum', b)
return b
for k in range(min(K,100)):
# print('a', a)
a = calc_b(a)
# if all(a == fin):
# break
a = [str(_) for _ in a]
print(' '.join(a))
# print('step=', k)
| 1 | 15,571,876,494,560 | null | 132 | 132 |
D,T,S=map(int,input().split())
print('Yes' if S*T>=D else 'No')
|
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools
import queue
from collections import deque
from fractions import Fraction
def main():
a, b , c = map(int, input().split())
if a / c <= b:
print("Yes")
else:
print("No")
if __name__ == '__main__':
main()
| 1 | 3,595,213,123,110 | null | 81 | 81 |
n = int(input())
s = list(input())
r = 0
g = 0
b = 0
for c in s:
if c == "R":
r += 1
if c == "G":
g += 1
if c == "B":
b += 1
ans = r*g*b
for i in range(n):
for j in range(i+1,n):
k = 2*j - i
if k > n-1:
continue
x = s[i]
y = s[j]
z = s[k]
if x!= y and y != z and z != x:
ans -= 1
print(ans)
|
N, K, S = map(int, input().split())
ans = [None] * N
for i in range(N):
if i < K:
ans[i] = S
else:
if S + 1 <= 1000000000:
ans[i] = S + 1
else:
ans[i] = 1
print(' '.join(map(str, ans)))
| 0 | null | 63,499,834,186,950 | 175 | 238 |
from collections import Counter
def prime_factorization(n):
A = []
while n % 2 == 0:
n //= 2
A.append(2)
i = 3
while i * i <= n:
if n % i == 0:
n //= i
A.append(i)
else:
i += 2
if n != 1:
A.append(n)
return A
n = int(input())
A = list(Counter(prime_factorization(n)).values())
ans = 0
e = 1
while True:
cnt = 0
for i in range(len(A)):
if A[i] >= e:
A[i] -= e
cnt += 1
if cnt == 0:
break
ans += cnt
e += 1
print(ans)
|
n = int(input())
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
if n == 1:
print(0)
exit()
primes = prime_factorize(n)
max_primes = primes[-1]
dic = {}
tmp = 0
for i in primes:
if i not in dic:
dic[i] = 1
tmp = 0
continue
if tmp == 0:
tmp = i
else:
tmp *= i
if tmp not in dic:
dic[tmp] = 1
tmp = 0
print(len(dic))
| 1 | 16,755,596,009,580 | null | 136 | 136 |
# get line input split by space
def getLnInput():
return input().split()
# ceil(a / b) for a > b
def ceilDivision(a, b):
return (a - 1) // b + 1
def main():
getLnInput()
nums = list(map(int, getLnInput()))
print(min(nums), max(nums), sum(nums))
return
main()
|
n = input()
if n != 0:
l = [int(x) for x in raw_input().split()]
print min(l), max(l), sum(l)
else:
print "0 0 0"
| 1 | 725,415,466,850 | null | 48 | 48 |
N, S=list(map(int,input().split()))
A=list(map(int,input().split()))
A=[0]+A
dp=[[0 for j in range(S+1)] for i in range(N+1)]
dp[0][0]=1
for i in range(1,N+1):
for j in range(S+1):
dp[i][j]=(dp[i][j]+2*dp[i-1][j]) %998244353 # x[i]を入れないが、大きい方に入れるか入れないかが二通り
for j in range(S-A[i]+1):
dp[i][j+A[i]]=(dp[i][j+A[i]]+dp[i-1][j]) %998244353 # x[i]を入れる
print(dp[N][S])
|
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop, heapify
import copy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)
def lcm(a, b): return a * b / gcd(a, b)
# 1 2 3
# a, b, c = LI()
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# a = I()
def I(): return int(sys.stdin.buffer.readline())
# abc def
# a, b = LS()
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# a = S()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# 2
# 1
# 2
# [1, 2]
def IR(n): return [I() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]
def LIR(n): return [LI() for i in range(n)]
# 2
# abc
# def
# [abc, def]
def SR(n): return [S() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]
def LSR(n): return [LS() for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]
def SRL(n): return [list(S()) for i in range(n)]
def main():
n = I()
ranges = []
for i in range(n):
x, l = LI()
ranges.append([x - l, x + l])
ranges.sort(key=lambda x: x[1])
ans = n
for i in range(1, n):
if ranges[i - 1][1] > ranges[i][0]:
ans -= 1
ranges[i][1] = ranges[i - 1][1]
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 53,630,133,172,000 | 138 | 237 |
n = int(input())
ans = 0
for i in range(1, n):
if i >= n - i:
break
ans += 1
print(ans)
|
a,b=input().split()
A=int(a)
bb=b.replace(".","")
B=int(bb)
C=A*B
c=C//100
print(int(c))
| 0 | null | 84,892,366,516,058 | 283 | 135 |
# https://atcoder.jp/contests/abc157/tasks/abc157_e
from string import ascii_lowercase
from bisect import bisect_left, insort
from collections import defaultdict
N = int(input())
S = list(input())
Q = int(input())
locs = {c: [] for c in ascii_lowercase}
for i in range(N):
locs[S[i]].append(i + 1)
for _ in range(Q):
qt, l, r = input().split()
l = int(l)
if int(qt) == 1:
if S[l - 1] != r:
locs[S[l - 1]].remove(l)
S[l - 1] = r
insort(locs[r], l)
else:
count = 0
r = int(r)
for ch in ascii_lowercase:
if len(locs[ch]) > 0:
left = bisect_left(locs[ch], l)
if left != len(locs[ch]):
if locs[ch][left] <= r:
count += 1
print(count)
|
h,n = map(int,input().split())
Mag = []
for i in range(n):
AB = list(map(int,input().split()))
Mag.append(AB)
dp = [[float("inf")]*(h+1) for i in range(n+1)]
dp[0][0] = 0
for i in range(n):
for j in range(h+1):
dp[i+1][j] = min(dp[i+1][j],dp[i][j])
dp[i+1][min(j+Mag[i][0],h)] = min(dp[i+1][min(j+Mag[i][0],h)],dp[i+1][j]+Mag[i][1])
print(dp[n][h])
| 0 | null | 71,494,646,878,772 | 210 | 229 |
import math
def main():
A, B = map(int,input().split())
print(int(A*B/math.gcd(A,B)))
if __name__ =="__main__":
main()
|
def lcm(x, y):
return x / gcd(x, y) * y
def gcd(a, b):
if (b == 0):
return a
return gcd(b, a % b);
a, b = [int(i) for i in input().split()]
print(int(lcm(a, b)))
| 1 | 113,507,664,518,842 | null | 256 | 256 |
def main():
N=int(input())
A=[int(_) for _ in input().split()]
left=0
right=sum(A)
ans=right
for i in range(N):
left+=A[i]
right-=A[i]
ans = min(ans, abs(left-right))
print(ans)
main()
|
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
A=[int(i) for i in input().split()]
mon=1000
stk=0
for i in range(n-1):
if A[i]<=A[i+1]:
stk+=mon//A[i]
mon%=A[i]
else:
mon+=stk*A[i]
stk=0
mon+=stk*A[-1]
print(mon)
| 0 | null | 74,519,247,652,252 | 276 | 103 |
import math
while(1):
a=0
n=int(input())
if n==0: break;
s=list(map(int,input().split()))
m=sum(s)/len(s)
for i in range(n):
a=a+pow(s[i]-m,2)
print(math.sqrt(a/n))
|
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 | 358,990,595,260 | 31 | 43 |
H, W = map(int,input().split())
S = [list(input()) for i in range(H)]
N = [[10**9]*W]*H
l = 0
u = 0
if S[0][0] == '#' :
N[0][0] = 1
else :
N[0][0] = 0
for i in range(H) :
for j in range(W) :
if i == 0 and j == 0 :
continue
#横移動
l = N[i][j-1]
#縦移動
u = N[i-1][j]
if S[i][j-1] == '.' and S[i][j] == '#' :
l += 1
if S[i-1][j] == '.' and S[i][j] == '#' :
u += 1
N[i][j] = min(l,u)
print(N[-1][-1])
|
a,v = map(int, input().split())
b,w = map(int, input().split())
t = int(input())
if abs(a-b)+w*t <= v*t: print('YES')
else: print('NO')
| 0 | null | 32,125,572,235,360 | 194 | 131 |
def solve():
# tmp_max = P[0]
tmp_min = P[0]
cnt = 1
for i in range(0,N):
if P[i] < tmp_min:
tmp_min = P[i]
cnt += 1
print(cnt)
if __name__ == "__main__":
N = int(input())
P = list(map(int, input().split()))
solve()
|
N = int(input())
P = list(map(int, input().split()))
temp = P[0]
res = 1
for i in range(1,N):
if P[i] <= temp:
temp = P[i]
res += 1
print(res)
| 1 | 85,474,965,273,050 | null | 233 | 233 |
import math
X = int(input())
okane = 100
year = 0
while okane < X:
okane = okane * 101 // 100
year = year + 1
print(year)
|
import math
x = int(input())
a = 100
year = 0
while a < x:
a = (a * 101)//100
year += 1
print(year)
| 1 | 27,124,309,903,070 | null | 159 | 159 |
n = int(input())
s, t = map(str, input().split())
new_word_list = []
for i in range(n):
new_word_list.append(s[i])
new_word_list.append(t[i])
print(''.join(new_word_list))
|
N = int(input())
n = input().split()
a = []
for i in range(N):
a.append(int(n[i]))
a = sorted(a)
print('{0} {1} {2}'.format(a[0], a[-1], sum(a)))
| 0 | null | 56,085,643,244,722 | 255 | 48 |
N = int(input())
A = sorted(map(int, input().split()))
X = 0
Y = 0
B = []
for i in range(N-2):
X = i + 1
for j in range(X,N-1):
Y = j + 1
for k in range(Y, N):
if A[k] < A[i] + A[j]:
if A[k] != A[i] and A[i] != A[j] and A[k] != A[j]:
B.append((A[i],A[j],A[k]))
print(len(B))
|
import itertools
n = int(input())
l = list(map(int, input().split()))
count = 0
c_list = list(itertools.combinations(l, 3))
for c in c_list:
if (c[0]+c[1])>c[2] and (c[1]+c[2])>c[0] and (c[2]+c[0])>c[1]:
if len(set(c)) == 3:
count += 1
print(count)
| 1 | 5,019,275,899,978 | null | 91 | 91 |
N = int(input())
S = str(input())
r_cnt = S.count('R')
g_cnt = S.count('G')
b_cnt = S.count('B')
ans = r_cnt*g_cnt*b_cnt
for i in range(N):
for d in range(1, N):
j = i + d
k = j + d
if k >= N:break
if S[i]!=S[j] and S[i]!=S[k] and S[j]!=S[k]:
ans -= 1
print(ans)
|
from collections import Counter
N = int(input())
S = list(input())
cnt = Counter(S)
ans = 1
for s in list('RGB'):
ans *= cnt[s]
for i in range(N):
for j in range(i + 1, N):
K = 2*j - i
if K >= N:
break
if (S[i] != S[j]) & (S[j] != S[K]) & (S[i] != S[K]):
ans -= 1
print(ans)
| 1 | 36,062,258,905,630 | null | 175 | 175 |
import sys
N = int(input())
A = list(map(int,input().split()))
fin = 1
if 0 in A:
fin = 0
else:
for i in A:
fin *= i
if fin > 10**18:
print(-1)
sys.exit()
print(fin)
|
n=int(input())
array=list(map(int,input().split()))
ans=1
if 0 in array:
ans=0
else:
for i in range(n):
if ans>10**18:
break
else:
ans=ans*array[i]
if ans>10**18:
print(-1)
else:
print(ans)
| 1 | 16,200,184,029,148 | null | 134 | 134 |
H, W= map(int, input().split())
A=[]
b=[]
ans=[0 for i in range(H)]
for i in range(H):
A.append(list(map(int, input().split())))
for j in range(W):
b.append(int(input()))
for i in range(H):
for j in range(W):
ans[i]+=A[i][j]*b[j]
print(ans[i])
|
n = int(input())
s = input()
ans = 0
ans = s.count('R')*s.count('G')*s.count('B')
for i in range(0,n-2):
for j in range(1,n-1):
k = -i + 2*j
if j < k <= n-1:
if s[i] == s[j]:
continue
if s[i] == s[k]:
continue
if s[j] == s[k]:
continue
else:
continue
ans -= 1
print(ans)
| 0 | null | 18,585,904,119,410 | 56 | 175 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
def gcd( a, b ):
while b > 0:
a, b = b, a%b
return a
def lcm( a, b ):
return a*b/gcd( a, b )
for s in sys.stdin:
d = map(int, s.split())
a,b = d[0],d[1]
print gcd(a,b),lcm(a,b)
|
import sys
for m,n in [map(int,x.split()) for x in list(sys.stdin)]:
g,r = m,n
while r!=0:
g,r = r,g%r
print(g,m//g*n)
| 1 | 713,638,270 | null | 5 | 5 |
N,K = map(int,input().split())
n = N - K * (N//K)
n = min(n, abs(n-K))
print(n)
|
N,K=map(int,input().split())
x=N%K
y=abs(x-K)
print(min(x,y))
| 1 | 39,451,633,875,372 | null | 180 | 180 |
print((lambda x: (x[0]-1)//x[1]+1)(list(map(int,input().split()))))
|
H,A = map(int, input().split())
cnt = H//A
if (H%A):
cnt +=1
print(cnt)
| 1 | 77,211,814,869,310 | null | 225 | 225 |
n=int(input())
num_list1=list(map(str,input().split()))
num_list2=[]
input_list=[]
for k in num_list1:
num_list2.append(k)
input_list.append(k)
def bubble(num_list):
i=0
flag=True
while flag:
flag=False
for j in range(len(num_list)-1,i,-1):
if int(num_list[j-1][1])>int(num_list[j][1]):
tmp=num_list[j-1]
num_list[j-1]=num_list[j]
num_list[j]=tmp
flag=True
return num_list
def select(num_list):
for i in range(0,len(num_list)):
min=i
for j in range(min+1,len(num_list)):
if int(num_list[min][1])>int(num_list[j][1]):
min=j
tmp=num_list[i]
num_list[i]=num_list[min]
num_list[min]=tmp
return num_list
def stable(input_list,output_list):
for i in range(0,len(input_list)):
for j in range(i+1,len(output_list)):
for k in range(0,len(output_list)):
for l in range(k+1,len(output_list)):
if input_list[i][1]==input_list[j][1] and input_list[i]==output_list[l] and input_list[j]==output_list[k]:
return "Not stable"
return "Stable"
bubble=bubble(num_list1)
select=select(num_list2)
print(" ".join(bubble))
print(stable(input_list,bubble))
print(" ".join(select))
print(stable(input_list,select))
|
n,m=map(int,input().split())
a =map(int,input().split())
x = sum(a)
if x > n:
print('-1')
else:
print(n-x)
| 0 | null | 16,029,862,859,300 | 16 | 168 |
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
#======================================================#
def main():
k = II()
sevens = 7%k
for i in range(1, k+1):
if sevens % k == 0:
print(i)
return
sevens = (10*sevens + 7)%k
print(-1)
if __name__ == '__main__':
main()
|
def ALDS1_3A():
stk, RPexp = [], list(input().split())
for v in RPexp:
if v in '+-*':
n2, n1 = stk.pop(), stk.pop()
stk.append(str(eval(n1+v+n2)))
else:
stk.append(v)
print(stk.pop())
if __name__ == '__main__':
ALDS1_3A()
| 0 | null | 3,100,985,190,618 | 97 | 18 |
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools
import queue
from collections import deque
from fractions import Fraction
def main():
a, b , c = map(int, input().split())
if a / c <= b:
print("Yes")
else:
print("No")
if __name__ == '__main__':
main()
|
def main():
S=int(input())
mod=10**9+7
resList=[1,0,0,1,1,1]
n=6
if S>=n:
for i in range(n,S+1):
resList.append(resList[i-1]+resList[i-3])
print(resList[len(resList)-1]%mod)
else:
print(resList[S])
if __name__=="__main__":
main()
| 0 | null | 3,433,433,203,952 | 81 | 79 |
q=list(map(int,input().split()))
X=q[0]
Y=q[1]
A=q[2]
B=q[3]
C=q[4]
r=list(map(int,input().split()))
g=list(map(int,input().split()))
n=list(map(int,input().split()))
r=sorted(r,reverse=True)
g=sorted(g,reverse=True)
n=sorted(n,reverse=True)
A=[]
for i in range(X):
A.append(r[i])
for i in range(Y):
A.append(g[i])
A=sorted(A,reverse=True)
s=0
for i in range(min(len(A),len(n))):
if A[-1]>=n[i]:
s=i
break
A.pop(-1)
s=i+1
for i in range(s):
A.append(n[i])
print(sum(A))
|
n, m = map(int, input().split())
a = list(map(int, input().split()))
total = sum(a)
cnt = 0
for _a in a:
if _a * 4 * m >= total:
cnt += 1
if cnt >= m:
print("Yes")
else:
print("No")
| 0 | null | 41,596,772,572,192 | 188 | 179 |
while True:
x,y=sorted([int(x) for x in input().split()])
if (x,y)==(0,0): break
print(x,y)
|
while True:
x,y = raw_input().split()
x,y = map(int,(x,y))
if x == 0 and y == 0:
break
if x > y:
x,y = map(str,(x,y))
print y + " " + x
else:
x,y = map(str,(x,y))
print x + " " + y
| 1 | 518,181,789,750 | null | 43 | 43 |
n = input()
data_list = list(input("").split())
min_array = min(map(int,data_list))
max_array = max(map(int,data_list))
sum_array = sum(map(int,data_list))
print("{0} {1} {2}".format(min_array, max_array, sum_array))
|
n, m, l = map(int, input().split())
A, B = [], []
for _ in range(n):
A.append(list(map(int, input().split())))
for _ in range(m):
B.append(list(map(int, input().split())))
C = []
B_T = list(zip(*B))
for a_row in A:
C.append([sum(a * b for a, b, in zip(a_row, b_column)) for b_column in B_T])
for row in C:
print(' '.join(map(str, row)))
| 0 | null | 1,092,953,234,762 | 48 | 60 |
n = int(input())
a = list(map(int, input().split()))
tmp = 0
sum = 0
for i in a:
if tmp > i:
dif = tmp - i
sum += dif
else:
tmp = i
print(sum)
|
import sys
n=int(input())
d=list(map(int,input().split()))
if d[0]!=0:
print(0)
sys.exit(0)
if n==1:
print(1)
sys.exit(0)
for i in range(1,n):
if d[i]==0:
print(0)
sys.exit(0)
dist=[0]*(n)
for i in range(1,n):
dist[d[i]]+=1
if dist[1]==0:
print(0)
sys.exit(0)
ans=1
mod=998244353
bef=dist[1]
total=dist[1]+1
for i in range(2,n):
for j in range(dist[i]):
ans=ans*bef
ans=ans%mod
total+=dist[i]
bef=dist[i]
if total==n:
break
if ans==0:
break
print(ans)
#print(dist)
| 0 | null | 79,468,761,785,578 | 88 | 284 |
N, M = map(int, input().split(' '))
ac_set = set()
wa_cnt, wa_cnt_ls = 0, [ 0 for i in range(N) ]
for i in range(M):
p, s = input().split(' ')
idx = int(p) - 1
if not idx in ac_set:
if s == 'AC':
ac_set.add(idx)
wa_cnt += wa_cnt_ls[idx]
else:
wa_cnt_ls[idx] += 1
print(len(ac_set), wa_cnt)
|
a,b=input().split()
a=int(a)
b=int(b)
if a>=10:
print(b)
if a<10:
print(b+(100*(10-a)))
| 0 | null | 78,595,082,215,140 | 240 | 211 |
def abc150c_count_order():
import bisect, itertools
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
pattern = list(itertools.permutations(range(1, n+1)))
p_idx = bisect.bisect(pattern, p)
q_idx = bisect.bisect(pattern, q)
print(abs(p_idx-q_idx))
abc150c_count_order()
|
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 16 18:45:04 2017
@author: syaga
"""
if __name__ == "__main__":
n = int(input())
a = []
for i in range(n):
a.append(int(input()))
max = a[1] - a[0]
mini = a[0]
for i in range(1, len(a)):
diff = a[i] - mini
if diff > max:
max = diff
if mini > a[i]:
mini = a[i]
print(max)
| 0 | null | 50,281,995,068,970 | 246 | 13 |
import sys
input = sys.stdin.readline
P = 2019
def main():
S = input().rstrip()
N = len(S)
count = [0] * P
count[0] += 1
T = 0
for i in range(N):
T = (T + int(S[(N - 1) - i]) * pow(10, i, mod=P)) % P
count[T] += 1
ans = 0
for k in count:
ans = (ans + k * (k - 1) // 2)
print(ans)
if __name__ == "__main__":
main()
|
n=int(input())
if(n%2==0):
print((n//2)/n)
else:
print((n//2+1)/n)
| 0 | null | 104,331,544,392,108 | 166 | 297 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.