code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
_, lis = input(), list(input().split())[::-1]
print(*lis)
| n, k = map(int, input().split())
h = list(map(int, input().split()))
h = sorted(h, reverse=True)
if k >= n:
print(0)
else:
print(sum(h[k:])) | 0 | null | 40,225,709,964,220 | 53 | 227 |
x = int(input())
mod =10**9 + 7
ans = pow(10,x,mod)
ans -= 2 * pow(9,x,mod)
ans += pow(8,x,mod)
ans %=mod
print(ans) | N = int(input())
MOD = 10**9 + 7
print((pow(10, N, MOD) - ( (pow(9, N, MOD)*2)%MOD - pow(8, N, MOD) )%MOD )%MOD) | 1 | 3,213,925,431,652 | null | 78 | 78 |
# -*- coding: utf-8 -*-
buf = str(raw_input())
char_list = list(buf)
res = ""
for i in char_list:
if i.isupper():
res += i.lower()
elif i.islower():
res += i.upper()
else:
res += i
print res | from string import ascii_lowercase as LOW
from string import ascii_uppercase as UP
a = {l:u for l,u in zip(list(LOW),list(UP))}
b = {u:l for u,l in zip(list(UP),list(LOW))}
a.update(b)
data = input()
data = [a[s] if s in a else s for s in data]
data = ''.join(data)
print(data) | 1 | 1,527,605,253,570 | null | 61 | 61 |
n = input()
ans = 0
for i in range(len(n)):
ans += int(n[i])
ans %= 9
print("Yes" if ans % 9 == 0 else "No") | def main() :
N = input()
sum = 0
for i in range(len(N)):
sum += int(N[i])
if sum % 9 == 0:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main() | 1 | 4,380,962,190,462 | null | 87 | 87 |
nums = input().split()
print(int(nums[0]) * int(nums[1]))
| a,b=(int(x) for x in input().split())
print(a*b) | 1 | 15,777,875,010,308 | null | 133 | 133 |
lines = list(input())
total = 0
size = 0
stack = []
ponds = []
size = 0
for i in range(len(lines)):
if lines[i] == "\\":
stack.append(i)
elif lines[i] == "/":
if not stack == []:
left_index = stack.pop()
size = i - left_index
target_index = left_index
#order is tricky
while not ponds == [] and ponds[-1][0] > left_index:
direct = ponds.pop()
target_index = direct[0]
size += direct[1]
ponds.append([target_index,size])
ans = []
ans.append(len(ponds))
for _ in ponds:
ans.append(_[1])
print(sum(ans[1:]))
print(" ".join(map(str,ans)))
| n, m, l = map(int, input().split())
a = [[int(num) for num in input().split()] for i in range(n)]
b = [[int(num) for num in input().split()] for i in range(m)]
c = [[0 for i in range(l)] for j in range(n)]
for i in range(l):
for j in range(n):
for k in range(m):
c[j][i] += a[j][k] * b[k][i]
for i in range(n):
for j in range(l):
if j == l - 1:
print(c[i][j])
else:
print("{0} ".format(c[i][j]), end = "") | 0 | null | 727,863,796,118 | 21 | 60 |
print((1999-int(input()))//200+1) | print("Yes" if input().count("7") != 0 else "No") | 0 | null | 20,324,284,470,140 | 100 | 172 |
from collections import Counter
s=input()[::-1]
DP=[0]
num,point=0,1
for i in s:
num +=int(i)*point
num %=2019
DP.append(num)
point *=10
point %=2019
ans=0
DP=Counter(DP)
for v,m in DP.items():
if m>=2:
ans +=m*(m-1)//2
print(ans) | data = list(map(int, input().split()))
a,b = max(data), min(data)
r = a % b
while r != 0:
a = b
b = r
r = a % b
print(b) | 0 | null | 15,289,873,451,608 | 166 | 11 |
import sys
def main():
for line in sys.stdin:
A = list(map(int,line.split()))
C = A[0]+A[1]
count = 0
while True:
C/=10
if C < 1:
break
count += 1
print(count+1)
if __name__ == '__main__':
main() | while True:
try:
value = input().split(" ")
result = str(int(value[0]) + int(value[1]))
print(len(result))
except EOFError:
break | 1 | 135,474,190 | null | 3 | 3 |
a,b,c,k=map(int,input().split())
if k < a:
print(k)
elif k <= a+b:
print(a)
else:
print(2*a+b-k) | A, B, C, K = map(int, input().split())
# 1:A枚, 0:B枚, -1:C枚, K枚を選ぶ
A = min(A, K)
B = min(K - A, B)
C = min(K - A - B, C)
assert A + B + C >= K
#print(A, B, C)
print(A - C) | 1 | 21,861,851,234,012 | null | 148 | 148 |
n = int(input())
ans = 0
for i in range(1, n + 1):
if i % 2 == 0:
continue
else:
ans += 1
print(ans / n)
| import math
radius=int(input())
print(2*math.pi*radius) | 0 | null | 104,322,165,082,528 | 297 | 167 |
n=int(input())
if(n%2==0):
print((n//2)/n)
else:
print((n//2+1)/n) | a=int(input())
if a%2==0:
print(1/2)
else:
print(((a+1)/2)/a) | 1 | 177,653,965,869,148 | null | 297 | 297 |
s = list(map(int, input().split()))
q = int(input())
# 上面をnとして時計回りにサイコロを回したときの正面のindexの一覧[a_1,a_2,a_3,a_4]
# 正面がa_nのとき右面はa_n+1
dm = {0: [1, 2, 4, 3, 1],
1: [0, 3, 5, 2, 0],
2: [0, 1, 5, 4, 0],
3: [0, 4, 5, 1, 0],
4: [0, 2, 5, 3, 0],
5: [1, 3, 4, 2, 1]}
for i in range(q):
t, f = map(lambda x: s.index(int(x)), input().split())
print(s[dm[t][dm[t].index(f)+1]])
| def f(d, D):
i = 0
while i < 6:
if d == D[i]:
return i
else:
i += 1
Q0 = [1,2,4,3,1]
Q1 = [0,3,5,2,0]
Q2 = [0,1,5,4,0]
ans = ''
D = list(map(int, input().split(' ')))
n = int(input())
i = 0
while i < n:
d0, d1 = map(int, input().split(' '))
L0 = f(d0, D)
L1 = f(d1, D)
if L0 == 0:
q = 0
while q < 4:
if L1 == Q0[q]:
ans += str(D[Q0[q + 1]]) + '\n'
break
q += 1
elif L0 == 1:
q = 0
while q < 4:
if L1 == Q1[q]:
ans += str(D[Q1[q + 1]]) + '\n'
break
q += 1
elif L0 == 2:
q = 0
while q < 4:
if L1 == Q2[q]:
ans += str(D[Q2[q + 1]]) + '\n'
break
q += 1
elif L0 == 3:
q = 0
while q < 4:
if L1 == Q2[4-q]:
ans += str(D[Q2[4-q-1]]) + '\n'
break
q += 1
elif L0 == 4:
q = 0
while q < 4:
if L1 == Q1[4-q]:
ans += str(D[Q1[4-q-1]]) + '\n'
break
q += 1
elif L0 == 5:
q = 0
while q < 4:
if L1 == Q0[4-q]:
ans += str(D[Q0[4-q-1]]) + '\n'
break
q += 1
i += 1
if ans != '':
print(ans[:-1])
| 1 | 262,585,085,540 | null | 34 | 34 |
n, k, c = map(int, input().split())
s = input()
l = len(s) - 1
i = 0
lb = []
le = []
while i < len(s) and len(lb) < k:
if s[i] == 'o':
lb.append(i)
i += c + 1
continue
i += 1
while l > -1 and len(le) < k:
if s[l] == 'o':
le.append(l)
l -= (c + 1)
continue
l -= 1
le.sort()
for j in range(0, len(lb)):
if lb[j] == le[j]:
print(lb[j]+1) | import sys
sys.setrecursionlimit(10**9)
def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))
INF=10**20
def main():
N,K,C=mi()
S=list(input())
ok,ng = "o","x"
OK = []
for i in range(N):
if S[i] == ok:
OK.append(i+1) # 1-index
greeds = [OK[0]]
for i in range(1,len(OK)):
x = OK[i]
if x - greeds[-1] > C:
greeds.append(x)
if len(greeds) > K:
break
inv_greeds = [OK[-1]]
inv_OK = OK[::-1]
for i in range(1,len(OK)):
x = inv_OK[i]
if -x + inv_greeds[-1] > C:
inv_greeds.append(x)
if len(inv_greeds) > K:
break
if len(greeds) < K or len(inv_greeds) < K:
exit()
greeds = greeds[:K]
inv_greeds = inv_greeds[:K][::-1]
# print(greeds,inv_greeds)
for i in range(len(greeds)):
if greeds[i] == inv_greeds[i]:
print(greeds[i])
if __name__ == "__main__":
main() | 1 | 40,639,589,869,248 | null | 182 | 182 |
N = int(input())
dp = [None] * (N + 1)
def fib(n):
if dp[n] != None:
return dp[n]
if n == 0 or n == 1:
dp[n] = 1
else:
dp[n] = fib(n - 2) + fib(n - 1)
return dp[n]
print(fib(N))
| H = int(input())
W = int(input())
N = int(input())
a = max(H, W)
print(N // a + min(1, N % a))
| 0 | null | 44,359,119,737,728 | 7 | 236 |
n=int(input())
l=list(map(int,input().split()))
a=[0]*(10**6+1)
for i in range(n):
if(a[l[i]]==0):
for j in range(2*l[i],10**6+1,l[i]):
a[j]=2
a[l[i]]+=1
print(a.count(1))
| K=int(input())
S=input()
N=len(S)
if N<=K:
print(S)
else:
ans=[]
for i in range(K):
ans.append(S[i])
print(''.join(ans)+'...') | 0 | null | 17,084,852,931,394 | 129 | 143 |
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
scores = {'r': P, 's': R, 'p': S, 'default': 0}
win_flag = [False]*(N+1)
ans = 0
# Kの剰余で別々に考えていい
for i_k in range(K):
prev = 'default'
for i_n in range(i_k, N, K):
# K個前と違う手 もしくは K個前で勝たないことにした 場合
# => 点がもらえる
if (T[i_n] != prev) or (not win_flag[i_n-K]):
win_flag[i_n] = True
ans += scores[T[i_n]]
prev = T[i_n]
print(ans) | N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
wins = {"p":"s", "r":"p", "s":"r"}
points = {"p":S, "r":P, "s":R}
hands = []
ans = 0
for i in range(N):
if i - K < 0:
hands.append(wins[T[i]])
ans += points[T[i]]
else:
if hands[i-K] == wins[T[i]]:
#あいこにするしか無い時
hands.append("-")
else:
#勝てる時
hands.append(wins[T[i]])
ans += points[T[i]]
print(ans)
| 1 | 106,684,367,047,048 | null | 251 | 251 |
import sys
import os
for line in sys.stdin:
H, W = map(int, line.split())
if H == 0 and W == 0:
break
print(('#' * W + '\n') * H)
| a,b,m = map(int,input().split())
a_list = [int(x.strip()) for x in input().split()]
b_list = [int(x.strip()) for x in input().split()]
ans = min(a_list)+min(b_list)
for i in range(m):
ai,bi,ci = map(int,input().split())
ch = a_list[ai-1]+b_list[bi-1]-ci
if ch < ans:
ans = ch
print(ans) | 0 | null | 27,342,848,312,020 | 49 | 200 |
while True:
try:
a, b = list(map(int, input().split()))
print(len(str(a + b)))
except EOFError:
break
except ValueError:
break
| def main():
line = input()
s1 = []
s2 = []
sum = 0
for i, s in enumerate(line):
if s == "\\":
# 谷の位置をスタックに積む
s1.append(i)
elif s == "/" and len(s1) > 0:
# 山で対応する谷があるなら、面積に追加
j = s1.pop()
sum += i - j # 谷から山の距離を水たまりの面積に追加
# jより前に位置する水たまりの面積を追加
a = i - j
while len(s2) > 0 and s2[-1][0] > j:
a += s2.pop()[1]
# (水たまりの左端の位置, 水たまりの面積)のタプルをスタックに積む
s2.append((j, a))
print(sum)
print(len(s2), end="")
for x in s2:
print(f" {x[1]}", end="")
print()
if __name__ == "__main__":
main()
| 0 | null | 30,217,203,410 | 3 | 21 |
n,k,c=map(int,input().split())
s=input()
l=len(s)
cand=[]
for i in range(l):
if s[i]=='o':
cand.append(i+1)
cnt1=[0]*(n+c+2)
cnt2=[0]*(n+c+2)
for i in range(l):
if s[i]=='o':
cnt1[i+1]=max(cnt1[i],cnt1[i-c]+1)
else:
cnt1[i+1]=cnt1[i]
for i in range(l-1,-1,-1):
if s[i]=='o':
cnt2[i+1]=max(cnt2[i+2],cnt2[i+c+2]+1)
else:
cnt2[i+1]=cnt2[i+2]
ans=[]
for i in range(len(cand)):##嘘に見える
tmp=cand[i]
if cnt1[tmp-1]+cnt2[tmp+1]<k:
print(tmp)
|
n, k, c = map(int, input().split())
s = input()
l = [0] * k
r = [0] * k
p = 0
# for i in range(n):
i = 0
while i < n:
if s[i] == "o":
l[p] = i
p += 1
if (p >= k):
break
i += c
i += 1
p = k-1
# for i in range(n - 1, -1, -1):
i = n - 1
while i >= 0:
if s[i] == "o":
r[p] = i
p -= 1
if (p < 0):
break
i -= c
i -= 1
#print(l, r)
for i in range(k):
if l[i] == r[i]:
print(l[i]+1)
| 1 | 40,742,255,387,420 | null | 182 | 182 |
n = list(input())
ans = 0
for i in n:
ans += int(i)
ans = ans%9
print('Yes' if ans == 0 else 'No') | from collections import deque
S = input()
Q = int(input())
a = deque([])
for i in S:
a.append(i)
# is_reverse: 反転しているか
is_reverse = False
for i in range(Q):
query = input().split()
if query[0] == "1":
is_reverse = not is_reverse
else:
if query[1] == "1":
if is_reverse:
a.append(query[2])
else:
a.appendleft(query[2])
else:
if is_reverse:
a.appendleft(query[2])
else:
a.append(query[2])
if is_reverse:
while len(a)>0:
print(a.pop(), end="")
else:
while len(a)>0:
print(a.popleft(), end="")
print() | 0 | null | 30,999,833,463,292 | 87 | 204 |
from collections import *
from copy import *
H,W = map(int,input().split())
S = [(W+2)*["#"]]+[["#"]+list(input())+["#"] for h in range(H)]+[(W+2)*["#"]]
D = [[1,0],[-1,0],[0,1],[0,-1]]
ans = 0
P = deque([])
Q = deque([])
for h in range(1,H+1):
for w in range(1,W+1):
if S[h][w]==".":
P+=[[h,w]]
while P:
T = deepcopy(S)
sx,sy = P.popleft()
T[sx][sy] = 0
Q = deque([[sx,sy]])
while Q:
x,y = Q.popleft()
for dx,dy in D:
if T[x+dx][y+dy]==".":
T[x+dx][y+dy] = T[x][y]+1
Q+=[[x+dx,y+dy]]
ans = max(ans,T[x+dx][y+dy])
print(ans) | A=list()
B=list()
n,m=map(int,input().split())
if m==0:
print([0, 10, 100][n - 1])
exit()
for i in range(m):
a,b=map(int,input().split())
A.append(a)
B.append(b)
if a==1 and b==0 and n!=1:
print(-1)
exit()
for i in range(1000):
c=str(i)
if len(c)==n:
for j in range(m):
if c[A[j]-1]!=str(B[j]):
break
if j==m-1:
print(i)
exit()
print(-1) | 0 | null | 77,667,365,847,930 | 241 | 208 |
a,b,c,k = map(int,input().split())
if k < a:
print(k)
elif a + b > k:
print(a)
else:
print(a - (k - a - b)) | A,B,C,K = [int(x) for x in input().split()]
if(A >= K):
print(K)
exit()
K = K - A
if(B >= K):
print(A)
exit()
K = K - B
print(A-K)
| 1 | 21,969,472,735,618 | null | 148 | 148 |
from decimal import *
import math
a, b = map(Decimal, input().split())
print(math.floor(a * b))
| # -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
sys.setrecursionlimit(10**6)
def zz():
return list(map(int, sys.stdin.readline().split()))
def z():
return int(sys.stdin.readline())
def S():
return sys.stdin.readline()
def C(line):
return [sys.stdin.readline() for _ in range(line)]
N = z()
A = [0]*N
X = {}
Y = {}
for i in range(N):
A[i] = z()
X[i] = [0]*A[i]
Y[i] = [0]*A[i]
for j in range(A[i]):
x, y = zz()
X[i][j] = x-1
Y[i][j] = y
ans = 0
for bits in itertools.product([0, 1], repeat=N):
# print("================")
# print(bits)
false_flg = False
for i, b in enumerate(bits):
if (b == 1):
# print('i=', i)
for x, y in zip(X[i], Y[i]):
# print(x, y)
if (bits[x] != y):
# print(False)
false_flg = True
if false_flg:
break
if false_flg:
break
if false_flg:
continue
else:
ans = max(ans, sum(bits))
print(ans) | 0 | null | 68,803,547,747,418 | 135 | 262 |
n, k, c = map(int, input().split())
s = input()
work = [1]*n
rest = 0
for i in range(n):
if rest:
rest -= 1
work[i] = 0
continue
if s[i] == 'x':
work[i] = 0
elif s[i] == 'o':
rest = c
rest = 0
for i in reversed(range(n)):
if rest:
rest -= 1
work[i] = 0
continue
if s[i] == 'o':
rest = c
if k < sum(work):
print()
else:
for idx, bl in enumerate(work):
if bl:
print(idx+1)
| def main():
N, K, C=map(int, input().split())
S = input()[::-1]
R=[0]*K
n, k=0, 0
while k < K:
if S[n]=='o':
R[k]=N-n
k+=1
n += C
n+=1
R=R[::-1]
S=S[::-1]
n, k=0, 0
while k < K:
if S[n]=='o':
if n+1 == R[k]:
print(n+1)
k+=1
n += C
n+=1
#print(L)
if __name__=='__main__':
main()
| 1 | 40,626,056,738,820 | null | 182 | 182 |
input = raw_input()
input = int(input)
ans = input**3
print ans | from math import gcd
magic = [2, 7, 61]
def mul(a, b, n):
# calculate (a * b) % n
r, a, b = 0, a % n, b % n
while b:
if b & 1:
r = (a + r) % n
a = (a + a) % n
b >>= 1
return r
def bigmod(a, p, n):
# calculate (a ** p) % n
if p == 0:
return 1
if p == 1:
return a % n
return mul(bigmod(mul(a, a, n), p // 2, n), a if p % 2 else 1, n)
def miller_rabin(n, a):
if gcd(a, n) == n:
return True
if gcd(a, n) != 1:
return False
d, r = n-1, 0
while d % 2 == 0:
d /= 2
r += 1
res = bigmod(a, d, n)
if res == 1 or res == n-1:
return True
while r:
r -= 1
res = mul(res, res, n)
if res == n-1:
return True
return False
def isPrime(n):
for a in magic:
if not miller_rabin(n, a):
return False
return True
num = int(input())
ans = sum(map(int, [isPrime(int(input())) for _ in range(num)]))
print(ans)
| 0 | null | 140,717,718,468 | 35 | 12 |
def scan(s):
m = 0
a = 0
for c in s:
if c == '(':
a += 1
elif c == ')':
a -= 1
m = min(m, a)
return m, a
def key(v):
m, a = v
if a >= 0:
return 1, m, a
else:
return -1, a - m, a
N = int(input())
S = [input() for _ in range(N)]
c = 0
for m, a in sorted([scan(s) for s in S], reverse=True, key=key):
if c + m < 0:
c += m
break
c += a
if c == 0:
print('Yes')
else:
print('No')
| n = (int)(input())
base = (int)(n**(1/2))
a=0
b=0
for i in range(base, 0, -1):
if n % i == 0:
a = i
b = n // i
break
#print(a,b)
print(a + b - 2) | 0 | null | 92,266,566,919,320 | 152 | 288 |
val = [int(i) for i in input().split()]
result = 0
for i in range(val[0], val[1] + 1):
if val[2] % i == 0:
result += 1
print(result)
| num = [int(x) for x in input().split() if x.isdigit()]
count = 0
for i in range(num[0], num[1]+1):
if num[2] % i == 0:
count += 1
print(count) | 1 | 558,650,914,432 | null | 44 | 44 |
import math
def checkPrime(n):
for i in range(2, int(math.sqrt(n)) + 1):
if n % i == 0:
return False
return True
if __name__ == "__main__":
N = input()
cnt = 0
for i in range(N):
n = input()
if checkPrime(n):
cnt += 1
print cnt | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
?´???°
?´???°??? 1 ??¨????????°??????????????§????????????????????¶??°????´???°??¨?¨?????????????
n ????????´??°???????????????????????????????????????????´???°?????°???????????????????????°????????????????????????????????????
"""
import math
def isPrime(x):
""" ??¨???????????????????¢¨?´???°?????? """
if x == 2: # ??¶??°??§?´???°??????????????°
return True
if x % 2 == 0: # 2??\????????¶??°????´???°??§?????????
return False
rx = int(math.sqrt(x)) + 1
for i in range(3, rx, 2): # ?????????????????°?????????????????????
if x % i == 0:
return False
return True
# ?????????
n = int(input().strip())
a = []
for i in range(n):
a.append(int(input().strip()))
cnt = 0
for i in a:
if isPrime(i) == True:
cnt += 1
print(cnt) | 1 | 10,742,945,500 | null | 12 | 12 |
S=list(input())
T=list(input())
A=[]
for i in range(len(S)-len(T)+1):
B=0
for j in range(len(T)):
if T[j]==S[i+j]:
continue
else:
B =B+1
A.append(B)
A.sort()
print(A[0])
| S = input()
T = input()
ans = float('inf')
for i in range(len(S) - len(T) + 1):
s = list(S[i:i + len(T)])
t = list(T)
count = 0
for j in range(len(T)):
if s[j] != t[j]:
count += 1
ans = min(ans, count)
print(ans) | 1 | 3,730,375,756,940 | null | 82 | 82 |
n = int(input())
s = list(input() for _ in range(n))
print(len(list(set(s)))) | from sys import stdin
import sys, math
n = int(stdin.readline().rstrip())
s = set()
for i in range(n):
s.add(stdin.readline().rstrip())
print(len(s))
| 1 | 30,222,954,232,380 | null | 165 | 165 |
N = input()
n = int(N)
even =int(n//2)
odd = int(n-even)
print(odd/n)
| n=int(input())
print((n//2+n%2)/n)
| 1 | 177,910,908,419,520 | null | 297 | 297 |
from sys import stdin
n = int(input())
xs = [int(input()) for _ in range(n)]
ans = 0
for x in xs:
flg = True
for y in range(2, int(x**0.5+1)):
if x % y == 0:
flg = False
break
if flg:
ans += 1
print(ans) | S = input()
flg = True
for i in range(len(S)):
if flg == True and S[i] == "h":
flg = False
continue
elif flg == False and S[i] == "i":
flg = True
continue
else:
print("No")
break
else:
if flg == False:
print("No")
else:
print("Yes") | 0 | null | 26,680,021,393,948 | 12 | 199 |
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
n = inp()
P = inpl()
min = 10**5 * 2 + 10
cnt = 0
for p in P:
if min >= p:
min = p
cnt += 1
print(cnt) | N = int(input())
P = list(map(int, input().split()))
pj = P[0]
cnt = 1
for pi in P[1:]:
if pi < pj:
cnt += 1
pj = pi
print(cnt) | 1 | 85,419,743,090,180 | null | 233 | 233 |
temp = int(input())
print("Yes" if temp>= 30 else "No") | for i in range(1, 10):
for j in range(1, 10):
print(f"{i}x{j}={i*j}")
| 0 | null | 2,886,336,549,360 | 95 | 1 |
from itertools import product
H, W, K = map(int, input().split())
S = [input() for _ in range(H)]
S_T = [[int(s[w]) for s in S] for w in range(W)]
sumS = sum(map(sum, S_T))
ans = (H - 1) * (W - 1)
if sumS <= K:
print(0)
else:
for i in product([True, False], repeat=H-1):
cnt = sum(i)
if cnt >= ans:
continue
M = [[0]]
for j, k in enumerate(i):
if k:
M.append([])
M[-1].append(j+1)
A = [0] * len(M)
for s_t in S_T:
for l, m in enumerate(M):
A[l] += sum(s_t[i] for i in m)
if any(a > K for a in A):
cnt += 1
if cnt >= ans:
break
A = [sum(s_t[i] for i in m) for m in M]
if any(a > K for a in A):
cnt = ans + 1
break
ans = min(cnt, ans)
print(ans)
| N = int(input())
"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
def factorization(n):
if (n == 1):
return []
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
#print(factorization(N))
list_a = factorization(N)
count = 0
for i in range(len(list_a)):
num = list_a[i][1]
cal = 1
while(num > 0):
num -= cal
cal += 1
if(num < 0) :
break
count += 1
#print(num,count)
print(count)
| 0 | null | 32,619,698,159,578 | 193 | 136 |
n = int(input())
m = n
primes = {}
for i in range(2, int(n**0.5+2)):
while m % i == 0:
m //= i
if i not in primes:
primes[i] = 1
else:
primes[i] += 1
if i > m:
break
if m != 1:
primes[m] = 1
cnt = 0
num = 0
flag = True
while flag == True:
num += 1
flag = False
for i in primes:
if 0 < primes[i] <= num*2:
cnt += 1
primes[i] = 0
elif primes[i] > num*2:
cnt += 1
flag = True
primes[i] -= num
print(cnt) | D, T, S = input().split()
D = int(D)
T = int(T)
S = int(S)
if D <= (T*S):
print("Yes")
else:
print("No") | 0 | null | 10,253,023,116,590 | 136 | 81 |
import math
n=int(input())
XY=[list(map(int,input().split())) for _ in range(n)]
ans=0
for i in range(n-1):
for j in range(i+1,n):
disx=XY[i][0]-XY[j][0]
disy=XY[i][1]-XY[j][1]
dis=math.sqrt(disx**2+disy**2)
ans+=dis
print(2*ans/n) | from itertools import permutations
import math
n = int(input())
x,y = [],[]
for _ in range(n):
x_, y_ =map(int,input().split())
x.append(x_)
y.append(y_)
c = list(permutations([i for i in range(1,n+1)],n))
g = [[-1]*(n+1) for _ in range(n+1)]
sum = 0
for ci in (c):
tmp = 0
for i in range(len(ci)-1):
if g[ci[i]][ci[i+1]] == -1:
tmp += math.sqrt((x[ci[i]-1]-x[ci[i+1]-1])**2
+ (y[ci[i]-1]-y[ci[i+1]-1])**2)
else:
tmp += g[ci[i]][ci[i+1]]
sum += tmp
print(sum/len(c)) | 1 | 148,652,802,927,570 | null | 280 | 280 |
D, T, S = map(int,input().split())
Distance = T * S
if(D <= Distance):
print('Yes')
else:
print('No') | def solve(string):
n, k, *p = map(int, string.split())
p = sorted(p)
return str(sum(p[:k]))
if __name__ == '__main__':
import sys
print(solve(sys.stdin.read().strip()))
| 0 | null | 7,531,469,909,838 | 81 | 120 |
s = range(1,14)
h = range(1,14)
c = range(1,14)
d = range(1,14)
n = int(raw_input())
for i in range(0,n):
input_line = raw_input().split()
mark = input_line[0]
num = int(input_line[1])
if mark == "S":
s.remove(num)
elif mark == "H":
h.remove(num)
elif mark == "C":
c.remove(num)
elif mark == "D":
d.remove(num)
for i in s:
print "S " + str(i)
for i in h:
print "H " + str(i)
for i in c:
print "C " + str(i)
for i in d:
print "D " + str(i) | n,m=map(int,input().split())
a=list(map(int,input().split()))
c=0
for i in a:
if i>=sum(a)*(1/(4*m)):
c+=1
if c>=m:
print('Yes')
else:
print('No') | 0 | null | 19,807,323,109,262 | 54 | 179 |
X = input()
l = len(X)
m = l//2
if (X == 'hi'*m):
print("Yes")
else:
print("No") | # ========== //\\ //|| ||====//||
# || // \\ || || // ||
# || //====\\ || || // ||
# || // \\ || || // ||
# ========== // \\ ======== ||//====||
# code
# 1 -> 1,2 2,1 3,
# 2 -> 1,1
def solve():
n = int(input())
cnt = 0
for i in range(1, n + 1):
k = n // i
if n % i:
cnt += k
else:
cnt += max(0, k - 1)
print(cnt)
return
def main():
t = 1
# t = int(input())
for _ in range(t):
solve()
if __name__ == "__main__":
main() | 0 | null | 27,858,400,519,652 | 199 | 73 |
def main():
S, W = map(int, input().split(' '))
if S > W:
print('safe')
else:
print('unsafe')
main() | S,W = map(int, input().split())
print("suanfsea f e"[S<=W::2]) | 1 | 28,987,543,750,880 | null | 163 | 163 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def main():
values = []
total = 0
for _ in range(int(input())):
s = input().strip()
open_required = len(s)
close_required = len(s)
open_close = 0
for i, c in enumerate(s):
if c == '(':
open_required = min(i, open_required)
open_close += 1
else:
close_required = min(len(s) - i - 1, close_required)
open_close -= 1
total += open_close
values.append([open_required, close_required, open_close, 0])
if total != 0:
print('No')
return
if len(values) > 500000:
print('Yes')
return
fvals = values.copy()
bvals = values
fvals.sort(key=lambda x: (x[0], -x[2]))
bvals.sort(key=lambda x: (x[1], x[2]))
findex = 0
bindex = 0
while True:
while findex < len(fvals) and fvals[findex][3] != 0:
findex += 1
while bindex < len(bvals) and bvals[bindex][3] != 0:
bindex += 1
if findex >= len(fvals) and bindex >= len(bvals):
break
fvals[findex][3] = 1
bvals[bindex][3] = -1
values = [v for v in fvals if v[3] == 1] + [v for v in bvals if v[3] == -1][::-1]
open_close_f = 0
open_close_b = 0
for (oreq_f, _, ocval_f, _), (_, creq_b, ocval_b, _) in zip(values, values[::-1]):
if oreq_f > open_close_f:
print('No')
return
if creq_b > open_close_b:
print('No')
return
open_close_f += ocval_f
open_close_b -= ocval_b
print('Yes')
if __name__ == '__main__':
main()
| import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
N = ir()
pos = []
neg = []
tot = 0
for i in range(N):
tmp = 0
b = 0
for c in sr():
if c == '(':
tmp += 1
else:
tmp -= 1
b = min(b, tmp)
if tmp > 0:
pos.append([tmp, b])
else:
neg.append([-tmp, b-tmp])
tot += tmp
if tot != 0:
print('No')
return
pos = sorted(pos, key=lambda x: (x[1], x[0]))[::-1]
neg = sorted(neg, key=lambda x: (x[1], x[0]))[::-1]
c = 0
for p in pos:
t, b = p
if c+b < 0:
print('No')
return
c += t
c = 0
for n in neg:
t, b = n
if c+b < 0:
print('No')
return
c += t
print('Yes')
return
resolve() | 1 | 23,734,491,828,740 | null | 152 | 152 |
h=int(input())
num=1
cnt=0
while h!=1:
h=h//2
cnt+=num
num*=2
cnt+=num
print(cnt) | mod = 10 ** 9 + 7
mod2 = 2**61+1
from collections import deque
import heapq
from bisect import bisect_left, insort_left, bisect_right
def iip(listed=True):
ret = [int(i) for i in input().split()]
if len(ret) == 1 and not listed:
return ret[0]
return ret
def iip_ord():
return [ord(i) - ord("a") for i in input()]
def main():
ans = solve()
if ans is not None:
print(ans)
def solve():
N, T = iip()
dp1 = [[0 for _ in range(T)] for _ in range(N + 1)]
dp2 = [[0 for _ in range(T)] for _ in range(N + 1)]
AB = [iip() for i in range(N)]
for i, ab in enumerate(AB, 1):
a, b = ab
for j in range(T):
dp1[i][j] = dp1[i-1][j]
for j in reversed(list(range(T))):
if j+a >= T:
continue
dp1[i][j + a] = max(dp1[i][j + a], dp1[i][j] + b)
for i, ab in enumerate(reversed(AB), 1):
a, b = ab
for j in range(T):
dp2[i][j] = dp2[i-1][j]
for j in reversed(list(range(T))):
if j + a >= T:
continue
dp2[i][j + a] = max(dp2[i][j + a], dp2[i][j] + b)
#dp2.reverse()
mm = 0
for i in range(N):
for j in range(T):
ii1 = i
ii2 = N-i-1
ii3 = i
ij1 = j
ij2 = T-j-1
a = dp1[ii1][ij1]
b = dp2[ii2][ij2]
c = AB[ii3][1]
#print(ii1, ii2, ij1, ij2, ii3, a, b, c, a+b+c)
#print(a, b, c)
mm = max(a+b+c, mm)
#print(i, j, cur, a, b)
#print(dp1)
#print(dp2)
print(mm)
#####################################################ライブラリ集ここから
def fprint(s):
for i in s:
print(i)
def split_print_space(s):
print(" ".join([str(i) for i in s]))
def split_print_enter(s):
print("\n".join([str(i) for i in s]))
def koenai_saidai_x_index(sorted_list, n):
l = 0
r = len(sorted_list)
if len(sorted_list) == 0:
return False
if sorted_list[0] > n:
return False
while r - l > 1:
x = (l + r) // 2
if sorted_list[x] == n:
return x
elif sorted_list[x] > n:
r = x
else:
l = x
return l
def searchsorted(sorted_list, n, side):
if side not in ["right", "left"]:
raise Exception("sideはrightかleftで指定してください")
l = 0
r = len(sorted_list)
if n > sorted_list[-1]:
# print(sorted_list)
return len(sorted_list)
if n < sorted_list[0]:
return 0
while r - l > 1:
x = (l + r) // 2
if sorted_list[x] > n:
r = x
elif sorted_list[x] < n:
l = x
else:
if side == "left":
r = x
elif side == "right":
l = x
if side == "left":
if sorted_list[l] == n:
return r - 1
else:
return r
if side == "right":
if sorted_list[l] == n:
return l + 1
else:
return l
def soinsuu_bunkai(n):
ret = []
for i in range(2, int(n ** 0.5) + 1):
while n % i == 0:
n //= i
ret.append(i)
if i > n:
break
if n != 1:
ret.append(n)
return ret
def conbination(n, r, mod, test=False):
if n <= 0:
return 0
if r == 0:
return 1
if r < 0:
return 0
if r == 1:
return n
ret = 1
for i in range(n - r + 1, n + 1):
ret *= i
ret = ret % mod
bunbo = 1
for i in range(1, r + 1):
bunbo *= i
bunbo = bunbo % mod
ret = (ret * inv(bunbo, mod)) % mod
if test:
# print(f"{n}C{r} = {ret}")
pass
return ret
def inv(n, mod):
return power(n, mod - 2)
def power(n, p, mod_= mod):
if p == 0:
return 1
if p % 2 == 0:
return (power(n, p // 2, mod_) ** 2) % mod_
if p % 2 == 1:
return (n * power(n, p - 1, mod_)) % mod_
if __name__ == "__main__":
main() | 0 | null | 115,926,578,357,600 | 228 | 282 |
import copy
n, k = map(int, input().split())
P = list(map(int, input().split()))
U = [0]*n
for i in range(n):
U[i] = (P[i]+1)/2
ans = sum(U[:k])
t = copy.copy(ans)
for i in range(n-k):
t = t+U[k+i]-U[i]
ans = max(ans, t)
print(ans)
| T1,T2=[int(i) for i in input().split()]
A1,A2=[int(i) for i in input().split()]
B1,B2=[int(i) for i in input().split()]
if((B1-A1)*((B1-A1)*T1+(B2-A2)*T2)>0):
print(0);
exit();
if((B1-A1)*T1+(B2-A2)*T2==0):
print("infinity")
exit();
ans=(abs((B1-A1)*T1)//abs((B1-A1)*T1+(B2-A2)*T2))*2+1
if(abs((B1-A1)*T1)%abs((B1-A1)*T1+(B2-A2)*T2)==0):
ans-=1
print(ans)
| 0 | null | 103,550,259,615,908 | 223 | 269 |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# F - Select Half
n = int(input())
a = list(map(int, input().split()))
assert len(a) == n
# memo[i][m] a[0:i+1]からm個選ぶときの最大値
memo = [{} for i in range(n)]
memo[0] = {0: 0, 1: a[0]}
memo[1] = {1: max(a[:2])}
for i in range(2, n):
m = (i + 1) // 2
memo[i][m] = max(memo[i - 1][m], memo[i - 2][m - 1] + a[i])
if i % 2 == 0:
memo[i][m + 1] = memo[i - 2][m] + a[i]
print(memo[-1][n // 2])
| N = int(input())
def Prime_Factorize(n):
primes = []
while n%2 == 0:
n//=2
primes.append(2)
f = 3
while f*f <= n:
if n%f == 0:
n//=f
primes.append(f)
else:
f += 2
if n != 1:
primes.append(n)
return primes
Primes = Prime_Factorize(N)
cnt = 0
for p in Primes:
e = 1
z = p
while (N%z == 0) and (N >= z):
N //= z
e += 1
z = p**e
cnt += 1
while N%p == 0:
N //= p
print(cnt) | 0 | null | 27,224,635,217,920 | 177 | 136 |
'''
Created on 2020/09/26
@author: harurun
'''
#UnionFind(要素数)で初期化
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
#parents 各要素の親番号を格納するリストを返す
#要素xが属するグループを返す
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
#要素xとyが属するグループを併合する
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
#要素xが属するグループのサイズ
def size(self, x):
return -self.parents[self.find(x)]
#要素xとyが同じグループに属するかどうか
def same(self, x, y):
return self.find(x) == self.find(y)
#要素xが属するグループを返す
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
#すべての根の要素
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
#グループの数
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def main():
import sys
pin=sys.stdin.readline
pout=sys.stdout.write
perr=sys.stderr.write
N,M=map(int,pin().split())
ans=0
uf=UnionFind(N)
for i in range(M):
A,B=map(int,pin().split())
uf.union(A-1, B-1)
print(uf.group_count()-1)
return
main()
| import math
print(360//math.gcd(int(input()),360)) | 0 | null | 7,658,498,632,668 | 70 | 125 |
n = int(input())
arr = [int(input()) for _ in range(n)]
def insertionSort(arr, n, g):
cnt = 0
for i in range(g, n):
key = arr[i]
j = i - g
while j >= 0 and arr[j] > key:
arr[j + g] = arr[j]
j -= g
cnt += 1
arr[j + g] = key
return cnt
def shellSort(arr, n):
G = []
g = 1
cnt = 0
while g < n or g == 1:
G.append(g)
g = 3*g + 1
G = G[::-1]
print(len(G))
for i in range(len(G)):
cnt += insertionSort(arr, n, G[i])
print(*G)
print(cnt)
for a in arr:
print(a)
shellSort(arr, n)
| def insertionSort(A, n, g):
for i in range(g,n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
global cnt
cnt += 1
A[j+g] = v
def shellSort(A, n):
global cnt
cnt = 0
G =[]
g = 0
for h in range(100):
g = 3*g + 1
if g <= n:
G.insert(0,g)
m = len(G)
for i in range(m):
insertionSort(A, n, G[i])
print(m)
print(*G)
print(cnt)
print(*A,sep="\n")
n = int(input())
A = [int(input()) for i in range(n)]
shellSort(A, n)
| 1 | 32,433,054,044 | null | 17 | 17 |
from math import gcd
K = int(input())
sum = 0
for a in range(1, K+1):
for b in range(1, K+1):
p = gcd(a, b)
for c in range(1, K+1):
sum += gcd(p, c)
print(sum) | import math
from functools import reduce
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
k=INT()
ans=0
for i in range(1,k+1):
for j in range(1,k+1):
for h in range(1,k+1):
ans+=math.gcd(math.gcd(i,j),h)
#print(ans,i,j,h)
print(ans)
if __name__ == '__main__':
do() | 1 | 35,692,329,094,390 | null | 174 | 174 |
def main():
N = int(input())
S = input()
fusion = [S[0]]
prev = S[0]
for s in S[1:]:
if s == prev:
continue
fusion.append(s)
prev = s
print(len(fusion))
main() | n, x, m = map(int, input().split())
def solve(n, x, m):
if n == 1:
return x
arr = [x]
for i in range(1, n):
x = x*x % m
if x in arr:
rem = n-i
break
else:
arr.append(x)
else:
rem = 0
sa = sum(arr)
argi = arr.index(x)
roop = arr[argi:]
nn, r = divmod(rem, len(roop))
return sa + nn*sum(roop) + sum(roop[:r])
print(solve(n, x, m)) | 0 | null | 86,289,679,095,360 | 293 | 75 |
H,W=map(int,input().split())
if H%2==0:
if W%2==0:
ans=W//2*H
else:
ans=H//2*W
else:
if W%2==0:
ans=W//2*H
else:
ans=(W//2+1)*H-H//2
if H==1 or W==1:
ans=1
print(ans) | N,K = map(int,input().split())
A = list(map(int,input().split()))
for i in range(N-K):
print('Yes' if A[i] < A[i+K] else 'No')
| 0 | null | 29,022,424,841,970 | 196 | 102 |
from copy import deepcopy
def getval():
r,c,k = map(int,input().split())
item = [[0 for i in range(c)] for i in range(r)]
for i in range(k):
ri,ci,vi = map(int,input().split())
item[ri-1][ci-1] = vi
return r,c,k,item
def main(r,c,k,item):
#DP containing the information of max value given k items picked in i,j
prev = [[0 for i in range(4)]]
inititem = item[0][0]
prev[0] = [0,inititem,inititem,inititem]
for i in range(1,r):
initval = prev[i-1][3]
temp = []
cur = item[i][0]
for j in range(4):
temp.append(initval)
for j in range(1,4):
temp[j] += cur
prev.append(temp)
for j in range(1,c):
init = deepcopy(prev[0])
for i in range(1,4):
init[i] = max(prev[0][i],prev[0][i-1]+item[0][j])
curcol = [init]
for i in range(1,r):
cur = item[i][j]
left = curcol[-1]
down = prev[i]
temp = [max(left[3],down[0])]
for k in range(1,4):
temp.append(max(max(left[3],down[k-1])+cur,down[k]))
curcol.append(temp)
prev = curcol
print(max(prev[-1]))
if __name__=="__main__":
r,c,k,item = getval()
main(r,c,k,item) | from copy import copy
C,R,K=map(int,input().split())
dp=[[0]*(R+1) for i1 in range(4)]
M=[[0]*R for i in range(C)]
for i in range(K):
r,c,v=map(int,input().split())
M[r-1][c-1]=v
for i,l in enumerate(M):
for num in range(1,4):
for j in range(R):
if num==1:
dp[num][j]= max(dp[num][j-1],dp[num-1][j-1]+M[i][j])
else:
dp[num][j]= max(dp[num][j-1],dp[num-1][j],dp[num-1][j-1]+M[i][j])
dp[0]=dp[-1][1:-1]+[0,dp[-1][0]]
print(dp[-1][-2]) | 1 | 5,605,257,712,196 | null | 94 | 94 |
def coin_change(coins, payment):
T = [0] + [50001] * payment
for c in coins:
for i, t in enumerate(zip(T[c:], T), start=c):
a, b = t
T[i] = min(a, b + 1)
return T[payment]
n, m = map(int, input().split())
c = list(map(int, input().split()))
ans = coin_change(c, n)
print(ans) | n,m=map(int,input().split())
c=list(map(int,input().split()))
c.sort(reverse=True)
#print(c)
dp=[0]
for i in range(1,n+1):
mini=float("inf")
for num in c:
if i-num>=0:
mini=min(mini,dp[i-num]+1)
dp.append(mini)
#print(dp)
print(dp[-1])
| 1 | 143,671,548,578 | null | 28 | 28 |
n,k = map(int, input().split())
L = [i for i in range(1,n+1)]
for _ in range(k):
d = int(input())
a = sorted(list(map(int, input().split())))
for e in a:
if e in L:
L.remove(e)
print(len(L)) | S=input()[::-1]
ans=0
#支払う枚数
array = list(map(int, S))
L=len(array)
for i,n in enumerate(array):
if n< 5 :
ans+=n
elif n > 5:
ans+= 10-n
if i <L-1:
array[i+1] +=1
else:
ans +=1
else:
ans+=5
if i < L-1:
if array[i+1] >=5:
array[i+1] +=1
print( ans)
| 0 | null | 47,420,402,272,430 | 154 | 219 |
N = int(input())
A = list(map(int, input().split()))
dp = [0]*N
cum = A[0]
for i in range(N):
if i == 0:
dp[i] = 0
continue
if i == 1:
dp[i] = max(A[0],A[1])
continue
if i%2==0: #奇数の時
cum += A[i]
dp[i] = max(dp[i-1],dp[i-2]+A[i])
if i%2==1: #偶数の時
dp[i] = max(dp[i-2]+A[i],cum)
ans = dp[-1]
print(ans)
#print(*ans, sep='\n') | def main():
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
n = int(input())
a = [int(x) for x in input().split()]
from collections import defaultdict
dp = defaultdict(lambda : -float('inf'))
dp[(0, 0, 0)] = 0
for i in range(1, n + 1):
max_j = i//2 if i % 2 == 0 else i//2 + 1
min_j = n//2 - (n - i)//2 if (n - i) % 2 == 0 else n//2 - ((n - i)//2 + 1)
for j in range(min_j, max_j + 1):
dp[(i, j, 0)] = max(dp[(i - 1, j, 0)], dp[(i - 1, j, 1)])
dp[(i, j, 1)] = dp[(i - 1, j - 1, 0)] + a[i - 1]
print(max(dp[(n, n//2, 0)], dp[(n, n//2, 1)]))
main()
| 1 | 37,464,410,687,648 | null | 177 | 177 |
def main():
nums = list(map(int, input().split(' ')))
directs = input()
d = Dice(nums)
for c in directs:
if 'N' == c:
d.toN()
if 'S' == c:
d.toS()
if 'E' == c:
d.toE()
if 'W' == c:
d.toW()
print(d.top)
class Dice:
def __init__(self, labels):
self.labels = labels
self._top = 0
self._front = 1
self._right = 2
self._left = 3
self._back = 4
self._bottom = 5
def toN(self):
self._back, self._top, self._front, self._bottom = self._top, self._front, self._bottom, self._back
return self
def toS(self):
self._back, self._top, self._front, self._bottom = self._bottom, self._back, self._top, self._front
return self
def toW(self):
self._left, self._top, self._right, self._bottom = self._top, self._right, self._bottom, self._left
return self
def toE(self):
self._left, self._top, self._right, self._bottom = self._bottom, self._left, self._top, self._right
return self
def get_top(self):
return self.labels[self._top]
top = property(get_top)
if __name__ == '__main__':
main() | class Dice:
top = 0
def __init__(self,one,two,three,four,five,six):
self.one = one
self.two = two
self.three = three
self.four = four
self.five = five
self.six = six
def role(self,direction):
global top
if(direction == 'S'):
t1 = self.one
self.one = self.five
t2 = self.two
self.two = t1
t3 = self.six
self.six = t2
t4 = self.five
self.five = t3
top = self.one
if(direction == 'E'):
t1 = self.one
self.one = self.four
t2 = self.three
self.three = t1
t3 = self.six
self.six = t2
self.four = t3
top = self.one
if(direction == 'N'):
t1 = self.one
t2 = self.two
t5 = self.five
t6 = self.six
self.one = t2
self.two = t6
self.six = t5
self.five = t1
top = self.one
if(direction == 'W'):
t1 = self.one
t3 = self.three
t4 = self.four
t6 = self.six
self.one = t3
self.four = t1
self.six = t4
self.three = t6
top = self.one
return(top)
arr = [int(i) for i in input().split()]
op = str(input())
final = 0
a = Dice(arr[0],arr[1],arr[2],arr[3],arr[4],arr[5])
for i in range(len(op)):
final = a.role(op[i])
print(final)
| 1 | 232,295,181,412 | null | 33 | 33 |
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))
| n = int(input())
s = []
for i in range(1, n+1):
if i % 3 == 0:
continue
elif i % 5 == 0:
continue
else:
s.append(i)
print(sum(s)) | 0 | null | 23,089,454,987,480 | 118 | 173 |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def main():
nums = input().split(" ")
fst , snd ,trd = int(nums[0]),int(nums[1]),int(nums[2])
if fst < snd < trd :
return "Yes"
else:
return "No"
if __name__ == '__main__':
print(main()) | def isIncremental(a, b, c):
"""
a: int
b: int
c: int
returns "Yes" if a < b < c, otherwise "No"
>>> isIncremental(1, 3, 8)
'Yes'
>>> isIncremental(3, 8, 1)
'No'
>>> isIncremental(1, 1, 1)
'No'
"""
if a >= b:
return "No"
elif b >= c:
return "No"
else:
return "Yes"
if __name__ == '__main__':
# import doctest
# doctest.testmod()
ival = input().split(' ')
print(isIncremental(int(ival[0]), int(ival[1]), int(ival[2]))) | 1 | 389,385,295,342 | null | 39 | 39 |
n = int(input())
L = list(map(int, input().split()))
a = L[0]
b = 0
for i in range(n-1):
if L[i+1] < a:
b = b + (a - L[i+1])
else:
a = L[i+1]
print(b) | N=int(input())
A=list(map(int,input().split()))
a=0
s=[]
for i in A:
if i<a:
s.append(a-i)
else:
a=i
print(sum(s))
| 1 | 4,607,793,664,290 | null | 88 | 88 |
n = int(input())
s, t = input().split()
ans = ""
for x in range(n):
ans = ans + s[x]
ans = ans + t[x]
print(ans) | #16D8102008K 1-D Greatest Common Divisor 柳生 葉月 Yagyu Hauzki
import math
a,b=map(int,input().split())
def f(x,y):
while(1):
tmp=x%y
x=y
y=tmp
if tmp==0:
gcd=x
break
return gcd
print(f(a,b))
| 0 | null | 56,269,848,134,588 | 255 | 11 |
n,k = map(int,input().split())
mod = 10**9+7
ans = 0
for i in range(k,n+2):
ans += n*i - i*(i-1) + 1
ans %= mod
print(ans) | import math
import sys
import itertools
from collections import deque
# import numpy as np
def main():
S = sys.stdin.readline()
len_S = len(S)
index = 0 # 操作しているSのインデックス
DOWN = [] # 下り文字をスタック
POOL = [] # 水たまりごとの面積
area = 0 # 総面積
for s in S:
if s == '\\':
DOWN.append(index)
elif s == '/' and len(DOWN) > 0:
pool_start = DOWN.pop()
pool_end = index
tmp_area = pool_end - pool_start
area += tmp_area
while True:
if len(POOL) == 0:
break
if POOL[-1]['start'] > pool_start and POOL[-1]['end'] < pool_end:
tmp_area += POOL[-1]['area']
POOL.pop()
else:
break
POOL.append({'start': pool_start, 'end': pool_end, 'area': tmp_area})
index += 1
print(area)
if len(POOL) > 0:
print(len(POOL), end=" ")
for i in range(len(POOL)-1):
print(POOL[i]['area'], end=" ")
print(POOL[-1]['area'])
else:
print(0)
if __name__ == '__main__':
main()
| 0 | null | 16,711,055,653,852 | 170 | 21 |
N, K = map(int, input().split())
A = list(map(int, input().split()))
r = max(A)
l = 0
while l+1 < r:
mid = (l+r)//2
cnt = 0
for a in A:
if(a > mid):
if(a%mid == 0):
cnt += (a//mid)-1
else:
cnt += a//mid
if(cnt > K):
l = mid
else:
r = mid
print(r) | X = int(input())
eikaku = X if X < 180 else X - 180
cnt = 0
ans = 0
while True:
ans += 1
cnt += eikaku
if cnt % 360 == 0:
print(ans)
break | 0 | null | 9,814,458,611,552 | 99 | 125 |
# -*- coding:utf-8 -*-
def solve():
N = int(input())
"""
■ 解法
N = p^{e1} * p^{e2} * p^{e3} ...
と因数分解できるとき、
z = p_i^{1}, p_i^{2}, ...
としていくのが最適なので、それを数えていく
(例) N = 2^2 * 3^2 * 5 * 7
のとき、
2,3,5,7の4回割れる。(6で割る必要はない)
■ 計算量
素因数分解するのに、O(√N)
割れる回数を計算するのはたかだか素因数分解するより少ないはずなので、
全体としてはO(√N+α)くらいでしょ(適当)
"""
def prime_factor(n):
"""素因数分解する"""
i = 2
ans = {}
while i*i <= n:
while n%i == 0:
if not i in ans:
ans[i] = 0
ans[i] += 1
n //= i
i += 1
if n != 1:
ans[n] = 1
return ans
pf = prime_factor(N)
ans = 0
for key, value in pf.items():
i = 1
while value-i >= 0:
value -= i
ans += 1
i += 1
print(ans)
if __name__ == "__main__":
solve()
| n,k=map(int,input().split())
a=list(map(int,input().split()))
l,r=10**9,0
while l-r>1:
t=(l+r)//2
if sum((i-1)//t for i in a)>k:
r=t
else:
l=t
print(l) | 0 | null | 11,727,906,215,652 | 136 | 99 |
arr = map(int,raw_input().split())
if arr[0] < arr[1] and arr[1] < arr[2] :
print "Yes"
else :
print "No" | # coding: utf-8
# Here your code !
a,b,c = input().split()
if(a < b < c):
print('Yes')
else:
print('No') | 1 | 389,823,288,608 | null | 39 | 39 |
n = int(input())
c=0
for i in range(1,(n//2)+1):
if((n-i) != i):
c+=1
print(c) | #import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline
def main():
n=int(input())
ans=0
for i in range(1,n):
if (i!=n-i and i<n-i):
ans+=1
elif i>n-1:
break
print(ans)
if __name__ == '__main__':
main()
| 1 | 153,255,931,765,682 | null | 283 | 283 |
def main():
H, W, M = [int(s) for s in input().split()]
cols = [0] * W
rows = [0] * H
bombs = set()
for _ in range(M):
x, y = [int(s)-1 for s in input().split()]
bombs.add((x, y))
cols[y] += 1
rows[x] += 1
sc = sorted([(c, i) for i, c in enumerate(cols)], reverse=True)
sr = sorted([(c, i) for i, c in enumerate(rows)], reverse=True)
best = 0
for v1, c in sc:
for v2, r in sr:
if v1 + v2 <= best:
break
score = v1 + v2
if (r, c) in bombs:
score -= 1
best = max(best, score)
print(best)
main() | from collections import defaultdict
h, w, m = map(int, input().split())
rowsum = [0] * h
rowmax = 0
colsum = [0] * w
colmax = 0
targets = defaultdict(int)
for _ in range(m):
hi, wi = map(int, input().split())
hi -= 1
wi -= 1
rowsum[hi] += 1
rowmax = max(rowmax, rowsum[hi])
colsum[wi] += 1
colmax = max(colmax, colsum[wi])
targets[(hi, wi)] = 1
rowindices = []
for i, v in enumerate(rowsum):
if v == rowmax:
rowindices.append(i)
colindices = []
for i, v in enumerate(colsum):
if v == colmax:
colindices.append(i)
ans = rowmax + colmax - 1
for ri in rowindices:
for ci in colindices:
if targets[(ri, ci)]:
continue
print(rowmax + colmax)
exit()
print(ans) | 1 | 4,742,181,357,898 | null | 89 | 89 |
n = int(input())
s = []
for i in range(n):
x, y = map(int, input().split())
s.append([x + y, x - y])
t = sorted(s)
u = sorted(s, key=lambda x: x[1])
res = 0
tmp1 = t[-1][0] - t[0][0]
tmp2 = u[-1][1] - u[0][1]
print(max(tmp1, tmp2))
| l = [int(i) for i in input().split()]
a = l[0]
b = l[1]
c = l[2]
yaku = 0
for i in range(b-a+1):
if c % (i+a) == 0:
yaku = yaku + 1
print(yaku) | 0 | null | 2,013,573,302,300 | 80 | 44 |
from operator import itemgetter
N, T = [int(i) for i in input().split()]
data = []
for i in range(N):
data.append([int(i) for i in input().split()])
data.sort(key=itemgetter(0))
dp = [[0]*(T) for i in range(N)]
ans = data[0][1]
for i in range(1, N):
for j in range(T):
if j >= data[i-1][0]:
value1 = dp[i-1][j]
value2 = dp[i-1][j-data[i-1][0]] + data[i-1][1]
dp[i][j] = max(value1, value2)
else:
dp[i][j] = dp[i-1][j]
value3 = dp[i][T-1] + data[i][1]
ans = max(value3, ans)
print(ans)
| N,T = list(map(int,input().split()))
A =[list(map(int,input().split())) for i in range(N)]
A.sort(key = lambda x:x[0])
INF = float("inf")
DP = [[-INF]*(T+3001) for i in range(N+1)]
DP[0][0] = 0
for i in range(N):
for j in range(T):
DP[i+1][j] = max(DP[i+1][j],DP[i][j])
DP[i+1][j+A[i][0]] = max(DP[i+1][j+A[i][0]],DP[i][j+A[i][0]],DP[i][j]+A[i][1])
score = 0
for i in range(N):
for j in range(T+A[i][0]):
score = DP[i+1][j] if DP[i+1][j]>score else score
print(score) | 1 | 151,218,342,107,522 | null | 282 | 282 |
n = int(input())
ans = 360 / n
i = 1
while int(ans * i) != ans * i:
i += 1
print(int(ans * i)) | [N,D],*li = [list(map(int,i.split())) for i in open(0)]
D = D**2
ans = 0
for x,y in li:
if x**2 + y**2 <= D:ans += 1
print(ans) | 0 | null | 9,544,342,456,320 | 125 | 96 |
N = int(input())
S, T = input().split()
mix = []
for i in range(N):
mix.append(S[i])
mix.append(T[i])
print(*mix, sep='') | N = int(input())
S, T = input().split()
str_list = []
for i in range(N):
str_list += S[i], T[i]
print("".join(str_list)) | 1 | 112,144,064,215,900 | null | 255 | 255 |
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
@njit((i8[:],i8[:],i8[:],i8[:]), cache=True)
def main(lis_h,lis_w,bomb_h,bomb_w):
bomb = {}
for h,w in zip(bomb_h,bomb_w):
bomb[(h,w)] = 1
m_h = max(lis_h)
m_w = max(lis_w)
m_h_lis = []
m_w_lis = []
for i,l in enumerate(lis_h):
if l==m_h:
m_h_lis.append(i)
for i,l in enumerate(lis_w):
if l==m_w:
m_w_lis.append(i)
ans = m_h+m_w
for h in m_h_lis:
for w in m_w_lis:
if (h,w) not in bomb:
return ans
return ans-1
H, W, M = map(int, input().split())
bombh = np.zeros(M, np.int64)
bombw = np.zeros(M, np.int64)
lis_h = np.zeros(H, np.int64)
lis_w = np.zeros(W, np.int64)
for i in range(M):
h,w = map(int, input().split())
h -= 1
w -= 1
bombh[i], bombw[i] = h,w
lis_h[h] += 1
lis_w[w] += 1
print(main(lis_h,lis_w,bombh,bombw))
| N = int(input())
A = str(input())
if (N % 2 == 0):
if (A[:N//2] == A[N//2:]):
print("Yes")
else:
print("No")
else:
print("No")
| 0 | null | 76,133,553,532,246 | 89 | 279 |
import sys,queue,math,copy,itertools,bisect,collections,heapq
def main():
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
N,K = LI()
A = LI()
c = 0
d = collections.Counter()
d[0] = 1
ans = 0
r = [0] * (N+1)
for i,x in enumerate(A):
if i >= K-1:
d[r[i-(K-1)]] -= 1
c = (c + x - 1) % K
ans += d[c]
d[c] += 1
r[i+1] = c
print(ans)
if __name__ == '__main__':
main() | import collections
n,k=map(int,input().split())
a=list(map(int,input().split()))
m=[0]
for i in range(n):
m.append((m[-1]+a[i]))
for i in range(n+1):
m[i]-=i
m[i]%=k
ans=0
dict=collections.defaultdict(int)
for i in range(1,n+1):
x=m[i]
if i<=k-1:
dict[m[i-1]]+=1
else:
dict[m[i-1]]+=1
dict[m[i-k]]-=1
ans+=dict[x]
print(ans) | 1 | 137,393,903,875,738 | null | 273 | 273 |
n = int(input())
numlist = []
i = 2
ans = 0
while i * i <= n + 1:
count = 0
while n % i == 0:
count += 1
n //= i
i += 1
if count != 0:
numlist.append(count)
if n != 1:
numlist.append(1)
while len(numlist) != 0:
i = 1
a = numlist.pop(0)
while a - i >= 0:
a -= i
i += 1
ans += 1
print(ans) | 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
candidates = factorization(N)
# print(candidates)
li = []
for item in candidates:
for i in range(item[1]):
li.append(item[0]**(i+1))
li.sort()
# print(li)
cnt = 0
for i in range(len(li)):
if N % li[i] == 0:
N /= li[i]
cnt += 1
print(cnt)
| 1 | 16,995,570,339,956 | null | 136 | 136 |
N = int(input())
X = []
L = []
for i in range(N):
x, l = map(int, input().split())
X.append(x)
L.append(l)
# できるだけ少ないロボットを取り除いて条件を満たすようにしたい
ranges = [[x - l, x + l] for x, l in zip(X, L)]
ranges = sorted(ranges, key=lambda x:x[1])
ans = N
for i in range(1, N):
if ranges[i][0] < ranges[i - 1][1]:
ranges[i][1] = ranges[i - 1][1]
ans -= 1
print(ans)
| for i in range(int(input())):
temp = [int(x) for x in input().split()]
stemp = sorted(temp)
if stemp[2]**2 == stemp[1]**2 + stemp[0]**2:
print('YES')
else:
print('NO')
| 0 | null | 45,087,783,735,170 | 237 | 4 |
a,b = map(int,input().split())
if(a-(2*b)<0):
print(0)
else:
print(a-(2*b)) | import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
A, B = M()
if A < 2*B:
print(0)
else:
print(A-2*B) | 1 | 166,329,083,067,892 | null | 291 | 291 |
n = int(input())
lis = list(map(int,input().split()))
sum = 0
for i in range(n-1):
if int(lis[i])>int(lis[i+1]):
sum += lis[i]-lis[i+1]
lis[i+1] = lis[i]
else:
continue
print(sum) | n = int(input()); s = input().split()
q = int(input()); t = input().split()
cnt = 0
for i in t:
if i in s:
cnt += 1
print(cnt)
| 0 | null | 2,311,455,766,828 | 88 | 22 |
N = int(input())
S = input()
l = [S[i:i+3] for i in range(0, len(S)-2)]
print(l.count('ABC'))
| N = int(input())
Ss = input().rstrip()
ans = Ss.count('ABC')
print(ans)
| 1 | 99,416,399,301,944 | null | 245 | 245 |
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_C&lang=jp
#??????
if __name__ == "__main__":
n_line = int(input())
l = set([])
for i in range(n_line):
input_line = input().split()
if input_line[0] == "insert":
l.add(input_line[1])
else:
if input_line[1] in l:
print("yes")
else:
print("no") | X = int(input())
ans=0
if X < 500:
print((X // 5) * 5)
else:
ans += (X // 500)*1000
X -= (X//500)*500
ans += (X//5)*5
print(ans)
| 0 | null | 21,267,682,593,140 | 23 | 185 |
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mat = lambda x, y, v: [[v]*y for _ in range(x)]
ten = lambda x, y, z, v: [mat(y, z, v) for _ in range(x)]
mod = 1000000007
sys.setrecursionlimit(1000000)
N, X, M = rl()
Xs = [None] * M
ans = 0
dif_i = 0
dif_v = 0
cur_i = 0
for i in range(1, N+1):
ans += X
if Xs[X] != None:
cur_i = i
dif_v = ans - Xs[X][1]
dif_i = i - Xs[X][0]
cur_x = X
break
Xs[X] = (i, ans)
X = (X**2) % M
if cur_i > 0 and cur_i < N:
remain = N - cur_i
ans += (remain // dif_i) * dif_v
X = cur_x
for i in range(remain % dif_i):
X = (X**2) % M
ans += X
print(ans)
| N, X, M = map(int, input().split())
ans = 0
C = [0]
Xd = [-1] * (M+1)
for i in range(N):
x = X if i==0 else x**2 % M
if Xd[x] > -1:
break
Xd[x] = i
ans += x
C.append(ans)
loop_len = i - Xd[x]
if loop_len > 0:
S = C[i] - C[Xd[x]]
loop_num = (N - i) // loop_len
ans += loop_num * S
m = N - loop_num * loop_len - i
ans += C[Xd[x]+m] - C[Xd[x]]
print(ans) | 1 | 2,826,106,047,960 | null | 75 | 75 |
a=int(input())
b=list(map(int,input().split()))
c=[0,0,0]
ans=1
mod=1000000007
for i in b:
d=0
for j in c:
if i==j:
d+=1
if d==0:
ans = 0
break
else:
ans=ans*d%mod
for j in range(3):
if i==c[j]:
c[j]+=1
break
print(ans) | #!/usr/bin/env python3
def main():
import sys
input = sys.stdin.readline
X = int(input())
for a in range(-150, 151):
for b in range(-150, 151):
if a ** 5 - b ** 5 == X:
print(a, b, sep=' ')
return
if __name__ == '__main__':
main()
| 0 | null | 78,162,001,655,230 | 268 | 156 |
# coding: utf-8
# Here your code !
array = []
for i in range(10):
line = int(input())
array += [line]
result = sorted(array)[::-1]
print(result[0])
print(result[1])
print(result[2]) | k, x = map(int, input().split())
print(["No", "Yes"][500 * k >= x]) | 0 | null | 49,116,378,342,180 | 2 | 244 |
stations = input()
if 'A' in stations and 'B' in stations:
print('Yes')
else:
print('No') | S = input()
if "A" in S and "B" in S:
print("Yes")
else:
print("No")
| 1 | 54,577,154,242,056 | null | 201 | 201 |
X = int(input())
if (X < 30):
print('No')
else:
print('Yes') | n, x, m = (int(x) for x in input().split())
A = [x]
used = {x, }
while True:
x = pow(x, 2, m)
if x in used:
index = A.index(x)
break
else:
A.append(x)
used.add(x)
if n <= len(A):
print(sum(A[:n]))
else:
ans = sum(A)
n -= len(A)
m = len(A) - index
ans += (n // m) * sum(A[index:])
ans += sum(A[index:index + (n % m)])
print(ans) | 0 | null | 4,253,224,715,268 | 95 | 75 |
natural = list(map(int, input().split()))
natural.sort
x = natural[1]
y = natural[0]
while (y != 0):
x, y = y, x % y
print(x) | a,b=sorted(list(map(int, input().split())))
m=b%a
while m>=1:
b=a
a=m
m=b%a
print(a) | 1 | 7,704,328,970 | null | 11 | 11 |
N = int(input())
ans = 0
for x in range(1, N + 1):
n = N // x
#ans += n * (2 * x + (n - 1) * x) // 2
ans += n * ( x + n * x) // 2
print(ans)
| N = int(input())
sum_ = lambda n:(n*(n+1))//2
ret = sum(d*sum_(N//d) for d in range(1,N+1))
# print([d*sum_(N//d) for d in range(1,N+1)])
print(ret) | 1 | 11,106,531,851,914 | null | 118 | 118 |
a,b,k=map(int,input().split())
if a<k:
b-=k-a
a=0
if b<0:
b=0
else:
if a-k>0:
a-=k
else:
a=0
print(a,b) | import sys
[print(len(str(sum(map(int, line.split()))))) for line in sys.stdin] | 0 | null | 51,987,069,908,048 | 249 | 3 |
#https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/3/ALDS1_3_D
s = str(input())
l = len(s)
h = [0]
for i in range(l):
if s[i] == '\\':
h.append(h[i]-1)
elif s[i] == '/':
h.append(h[i]+1)
else:
h.append(h[i])
a = []
m = -200000
n = 0
for i in range(l+1):
if m == h[i] and i != 0:
a.append([n,i,m])
m = -200000
if m < h[i] or i == 0:
m = h[i]
n = i
if (m in h[i+1:]) == False:
m = -200000
b = []
tmp = 0
for i in range(len(a)):
for j in range(a[i][0],a[i][1]):
tmp += a[i][2] - h[j]
if s[j] == '/':
tmp += 1 / 2
elif s[j] == '\\':
tmp -= 1 / 2
b.append(int(tmp))
tmp = 0
if len(b) != 0:
i=0
while True:
if b[i] == 0:
del b[i]
i -= 1
i += 1
if i == len(b):
break
A = sum(b)
k = len(b)
print(A)
print(k,end = '')
if k != 0:
print(' ',end='')
for i in range(k-1):
print(b[i],end=' ')
print(b[len(b)-1])
else:
print('')
| N, M = [int(v) for v in input().rstrip().split()]
r = 'Yes' if N == M else 'No'
print(r)
| 0 | null | 41,783,666,455,398 | 21 | 231 |
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
from itertools import combinations_with_replacement
INF = float('inf')
def main():
N, M, Q = map(int, readline().split())
abcd = []
for _ in range(Q):
a,b,c,d = map(int, readline().split())
abcd.append([a,b,c,d])
As = combinations_with_replacement(range(1,M+1),N)
ans = 0
for A in As:
score = 0
for a,b,c,d in abcd:
if A[b-1] - A[a-1] == c:
score += d
ans = max(ans, score)
print(ans)
if __name__ == '__main__':
main()
| from math import sqrt
from math import ceil
from math import floor
def divisors(n):
count=0
lis=[]
for i in range(1,ceil(sqrt(n))+1):
if n%i==0:
if n//i==i:
count+=1
lis.append(i)
else:
lis.append(i)
lis.append(n//i)
count+=2
lis=set(lis)
lis.remove(1)
return lis
def main():
n=int(input())
ol=n-1
ans=0
case1div=divisors(ol)
case2div=divisors(n)
for i in case2div:
newn=n
if newn%i==0:
while newn%i==0:
newn//=i
if newn%i==1:
ans+=1
ans+=len(case1div)
print(ans)
main() | 0 | null | 34,393,882,342,768 | 160 | 183 |
N,K=map(int,input().split())
P=list(map(lambda x: (int(x)+1)/2,input().split()))
s=tmp=sum(P[:K])
for i in range(K,N):
tmp=tmp-P[i-K]+P[i]
s=max(s,tmp)
print(s) | n = int(input())
arms = []
for _ in range(n):
x, l = map(int, input().split())
arms.append((x - l, x + l))
arms.sort(key = lambda x : x[1])
last_right = arms[0][1]
ans = 1
for i in range(1, n):
left, right = arms[i]
if left < last_right:
continue
last_right = right
ans += 1
print(ans) | 0 | null | 82,445,122,264,934 | 223 | 237 |
# input
N, M = map(int, list(input().split()))
A = list(map(int, input().split()))
# process
A.sort(reverse=True)
# 1回の握手の幸福度がx以上となるものの数、幸福度の合計を求める
def calc(x):
count, sum = 0, 0
j, t = 0, 0
for i in reversed(range(N)):
while j < N and A[i]+A[j] >= x:
t += A[j]
j += 1
count += j
sum += A[i]*j + t
return (count, sum)
# 2分探索で答えを求める
def binary_search(x, y):
mid = (x+y)//2
count, sum = calc(mid)
if count < M:
return binary_search(x, mid)
else:
if x == mid:
print(sum-(count-M)*mid)
else:
return binary_search(mid, y)
# 実行
binary_search(0, A[0]*2+1)
| import numpy as np
from numpy.fft import rfft,irfft
N,M = map(int,input().split())
A = list(map(int,input().split()))
a = np.zeros(10**5+1)
for i in range(N):
a[A[i]] += 1
b = rfft(a,2*10**5+1)
b = irfft(b*b,2*10**5+1)
b = np.rint(b).astype(np.int64)
c = 0
ans = 0
for n in range(2*10**5,1,-1):
if c+b[n]<M:
c += b[n]
ans += b[n]*n
else:
ans += (M-c)*n
c = M
break
print(ans) | 1 | 107,630,704,686,988 | null | 252 | 252 |
R, C, K = map(int, input().split())
items = [[0] * C for _ in range(R)]
for i in range(K):
r, c, v = map(int, input().split())
items[r-1][c-1] = v
dp = [[0] * 4 for _ in range(C)]
for i in range(R):
dp2 = [[0] * 4 for _ in range(C)]
for j in range(C):
if j != 0:
dp2[j] = dp2[j-1][:]
dp2[j][0] = max(dp2[j][0], max(dp[j]))
for k in range(3, 0, -1):
dp2[j][k] = max(dp2[j][k], dp2[j][k-1] + items[i][j])
dp = dp2
print(max(dp[-1]))
| import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
l = [A[0]]
for i in range(1, N):
l.append(A[i])
l.append(A[i])
print(sum(l[:N-1])) | 0 | null | 7,295,072,375,768 | 94 | 111 |
n = int(input())
my_dict = {}
for i in range(n):
order, key = input().split(' ')
if order == 'insert':
my_dict[key] = True
elif order== 'find':
if key in my_dict.keys():
print('yes')
else:
print('no')
| n = int(input())
D = set()
for _ in range(n):
q, s = map(str, input().split())
if q == 'insert':
D.add(s)
elif q == 'find':
if s in D:
print('yes')
else:
print('no')
| 1 | 76,427,498,000 | null | 23 | 23 |
n, k = map(int,input().split())
count = 0
while True:
n = n//k
count += 1
if n <1:
break
print(count) | n,k = map(int, input().split())
ans = 0
while n > 0:
n /= k
n = int(n)
ans += 1
print(ans)
| 1 | 64,172,550,487,892 | null | 212 | 212 |
s=[int(_) for _ in input()]
m = [0 for i in range(2019)]
d=0
m[d]+=1
p=1
for i in range(len(s)):
d=(d+s[-i-1]*p)%2019
m[d]+=1
p=(p*10)%2019
#print(d)
ans=0
for i in range(2019):
ans+=m[i]*(m[i]-1)//2
print(ans) | S = input()
ans = {0:1}
memo = [0]
last = 1
for ind, s in enumerate(S[::-1]):
memo.append((int(s) * last + memo[-1]) % 2019)
last *= 10
last %= 2019
if(memo[-1] in ans):
ans[memo[-1]] += 1
else:
ans[memo[-1]] = 1
res = 0
for key in ans.keys():
res += ans[key]*(ans[key]-1)//2
print(res) | 1 | 30,672,351,718,460 | null | 166 | 166 |
[n, m] = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
b = [int(input()) for i in range(m)]
d = [sum([a[i][j]*b[j] for j in range(m)]) for i in range(n)]
for i in range(n):
print(d[i]) | n,m = map(int,raw_input().split(" "))
a = []
for i in range(0,n):
b = map(int,raw_input().split(" "))
a.append(b)
for j in range(0,m):
k = input()
for i in range(0,n):
a[i][j] = a[i][j] * k
for i in range(0,n):
s = 0
for j in range(0,m):
s = s + a[i][j]
print str(s) | 1 | 1,147,718,431,680 | null | 56 | 56 |
def main():
a, b = input().split()
if a < b:
ans = a * int(b)
else:
ans = b * int(a)
print(ans)
if __name__ == '__main__':
main()
| import sys
input = sys.stdin.readline
a,b=map(int,input().split())
if a>b:
print(str(b)*a)
else:
print(str(a)*b)
| 1 | 84,492,015,906,712 | null | 232 | 232 |
s, w = map(int, input().split())
ans = "safe" if s > w else 'unsafe'
print(ans)
| a, b, c = map(int, input().split())
i = a
ans = 0
while i <= b:
if c % i == 0:
ans += 1
i += 1
print(ans)
| 0 | null | 14,788,903,399,938 | 163 | 44 |
import sys
input=sys.stdin.readline
count=0
res=""
str=input()
list=[]
for i in range(len(str)):
list.append(str[i])
for i in range(len(str)):
if str[i]=="?":
if i==0:
if list[1]=="D":
list[0]="P"
else:
list[0]="D"
elif i+1==len(str):
list[i]="D"
else:
if list[i-1]=="P":
list[i]="D"
else:
if list[i+1]=="D" or list[i+1]=="?":
list[i]="P"
else:
list[i]="D"
for i in range(len(str)):
res+=list[i]
print(res)
| t=list(input())
if t[0]=='?':
t[0]=t[0].replace('?','D')
for i in range(1,len(t)-1):
if t[i]=='?' and t[i+1]=='D' and t[i-1]=='P':
t[i]=t[i].replace('?','D')
elif t[i]=='?' and t[i+1]=='P' and t[i-1]=='P':
t[i]=t[i].replace('?','D')
elif t[i]=='?' and t[i+1]=='D' and t[i-1]=='D':
t[i]=t[i].replace('?','P')
elif t[i]=='?' and t[i+1]=='P' and t[i-1]=='D':
t[i]=t[i].replace('?','D')
elif t[i]=='?' and t[i+1]=='?' and t[i-1]=='D':
t[i]=t[i].replace('?','P')
elif t[i]=='?' and t[i+1]=='?' and t[i-1]=='P':
t[i]=t[i].replace('?','D')
if t[-1]=='?':
t[-1]=t[-1].replace('?','D')
for i in t:
print(i,end='') | 1 | 18,568,460,949,430 | null | 140 | 140 |
x,k,d = map(int, input().split())
if x == 0:
if k % 2 == 1:
x = d
elif x > 0:
if x >= k*d:
x -= k*d
else:
n = x//d
x -= n*d
k -= n
if k%2 ==1:
x -= d
else:
if x <= -(k*d):
x += k*d
else:
n = abs(x)//d
x += n*d
k -= n
if k%2 ==1:
x += d
print(abs(x)) | import sys
import copy
def print_data(data):
last_index = len(data) - 1
for idx, item in enumerate(data):
print(item, end='')
if idx != last_index:
print(' ', end='')
print('')
def bubbleSort(data, N):
for i in range(N):
j = N -1
while j >= i+1:
if data[j][1] < data[j-1][1]:
hoge = data[j]
data[j] = data[j-1]
data[j-1] = hoge
j -= 1
return data
def selectSort(data, N):
for i in range(N):
mini = i
for j in range(i, N):
if data[j][1] < data[mini][1]:
mini = j
if i == mini:
pass
else:
hoge = data[mini]
data[mini] = data[i]
data[i] = hoge
return data
def isStable(inData, outData, N):
for i in range(N):
for j in range(i+1, N):
if inData[i][1] == inData[j][1]:
a = outData.index(inData[i])
b = outData.index(inData[j])
if a > b :
return False
return True
def main():
N = int(input())
data0 = list(input().split())
data1 = copy.deepcopy(data0)
data2 = copy.deepcopy(data0)
bubbleData = bubbleSort(data1, N)
selectData = selectSort(data2, N)
print_data(bubbleData)
if isStable(data0, bubbleData, N):
print('Stable')
else:
print('Not stable')
print_data(selectData)
if isStable(data0, selectData, N):
print('Stable')
else:
print('Not stable')
if __name__ == '__main__':
main()
| 0 | null | 2,617,844,974,876 | 92 | 16 |
def main():
n = input()
a, b = 0, 1
for i in n:
x = int(i)
a, b = min(a + x, b + 10 - x), min(a + x + 1, b + 10 - x - 1)
print(a)
main()
| def main():
s = input()
dp = [0, 1]
for c in s:
x = int(c)
a = dp[0] + x
if a > dp[1] + 10 - x:
a = dp[1] + 10 - x
b = dp[0] + x + 1
if b > dp[1] + 10 - x - 1:
b = dp[1] + 10 - x - 1
dp[0] = a
dp[1] = b
dp[1] += 1
print(min(dp))
if __name__ == "__main__":
main()
| 1 | 70,956,665,287,452 | null | 219 | 219 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.