code1
stringlengths 16
24.5k
| code2
stringlengths 16
24.5k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,628B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
n, m = map(int, input().split())
days = input().split()
x = 0
for day in days:
x = x + int(day)
if x <= n:
print(n - x)
else:
print(-1)
|
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
x,y,a,b,c=n1()
P=n1()
Q=n1()
R=n1()
P.sort()
Q.sort()
A=P[-x:]+Q[-y:]+R
A.sort()
print(sum(A[-x-y:]))
| 0 | null | 38,228,081,666,270 | 168 | 188 |
#coding:utf-8
num = input()
print num * num * num
|
# row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()
def resolve():
import sys
input = sys.stdin.readline
x = int(input().rstrip())
if x // 100 * 5 >= x % 100:
print(1)
else:
print(0)
if __name__ == "__main__":
resolve()
| 0 | null | 64,066,726,963,254 | 35 | 266 |
from sys import stdin
from itertools import permutations
n = int(stdin.readline().strip())
rank = dict([(val, i) for i, val in enumerate(sorted([int(''.join([str(v) for v in l])) for l in permutations(list(range(1, n+1)), n)])[::-1])])
p_rank = rank[int(''.join(stdin.readline().split()))]
q_rank = rank[int(''.join(stdin.readline().split()))]
print(abs(p_rank - q_rank))
|
# -*- coding: utf-8 -*-
# ALDS1_3_D_Areas on the Cross-Section Diagram
from collections import deque
def make_h_list(slope):
"""
入力データから高さのリストを作る
"""
h_list =deque([0])
for s in slope:
d = 0
if s == "\\":
d = -1
elif s == "/":
d = 1
h_list.append(h_list[-1] + d)
return h_list
def trim_edge(h_list, left=True):
"""
水溜りの境界を探す
"""
if left:
while h_list:
h = h_list.popleft()
if h not in h_list:
continue
if h_list[0] - h < 0:
h_list.appendleft(h)
return h_list
else:
while h_list:
h = h_list.pop()
if h not in h_list:
continue
if h_list[-1] - h < 0:
h_list.append(h)
return h_list
def make_w_list(h_list):
"""
水たまりのリストを作る
"""
w_list = []
water = []
h_list = trim_edge(h_list)
while h_list:
h = h_list.popleft()
if not water:
water.append(h)
elif water[0] == h:
water.append(h)
w_list.append(water)
water = []
h_list.appendleft(h)
h_list = trim_edge(h_list)
else:
water.append(h)
if water[0] < water[-1]:
water.pop(0)
return w_list
def calc_area(water):
"""
面積計算
"""
h = water[0]
s = 0
for i in range(len(water) - 1):
s += (water[i+1] - h) + (water[i+1] - water[i]) / 2
return abs(int(s))
in_data = str(input())
h_list = make_h_list(in_data)
h_list = trim_edge(h_list, left=False)
if type(h_list) != None:
w_list = make_w_list(h_list)
a_list = [calc_area(water) for water in w_list]
else:
a_list = []
print(sum(a_list))
print(len(a_list), *a_list)
| 0 | null | 50,080,178,853,760 | 246 | 21 |
n=int(input())
s=input()
score = 0
for p in range(1000):
pw = str(p).zfill(3)
start = 0
n_match = 0
for j in range(3):
for i in range(start, len(s)):
if s[i] == pw[j]:
start = i+1
n_match = n_match+1
if j == 3-1:
# print(pw)
score = score+1
break
if n_match <= j:
break
print(score)
|
n=int(input())
s=input()
ans=0
alist=[0]*10
for i in range(n):
alist[int(s[i])]=i
for i in range(10):
flag1=False
for a in range(n-2):
if s[a]==str(i):
flag1=True
break
if flag1:
for j in range(10):
flag2=False
for b in range(a+1,n-1):
if s[b]==str(j):
flag2=True
break
if flag2:
for k in range(10):
if b<alist[k]:
ans+=1
print(ans)
| 1 | 128,115,269,213,848 | null | 267 | 267 |
n = int(input())
for i in range(1,n+1):
ans = int(i*1.08)
if ans == n:
print(i)
break
else:
print(":(")
|
n=int(input())
for x in range(n+1):
if int(x*1.08)==n:
print(x)
exit()
print(":(")
| 1 | 125,776,625,034,788 | null | 265 | 265 |
x,y=map(int,input().split())
if (x*2) <= y <= (x*4) and y%2 ==0:
print('Yes')
else:
print('No')
|
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = min(a) + min(b)
for i in range(M):
x, y, c = map(int, input().split())
p = a[x-1] + b[y-1] - c
if p < ans:
ans = p
print(ans)
| 0 | null | 33,947,809,715,242 | 127 | 200 |
k=int(input())
a,b=map(int,input().split())
count=a
while count <= b:
if count%k == 0:
print("OK")
break
else:
count += 1
else:
print("NG")
|
K = int(input())
A, B = map(int, input().split())
XK = list(x * K for x in range(1, 1000//K + 1))
for i in XK:
if (A <= i) & (i <= B):
print('OK')
break
else:
print('NG')
| 1 | 26,642,825,368,432 | null | 158 | 158 |
s={"a":"b","b":"c","c":"d","d":"e","e":"f","f":"g","g":"h","h":"i","i":"j","j":"k","k":"l","l":"m","m":"n","n":"o","o":"p","p":"q","q":"r","r":"s","s":"t","t":"u","u":"v","v":"w","w":"x","x":"y","y":"z","z":"a"}
print(s[input()])
|
import math
n, a, b = map(int, input().split())
mod = 10**9 + 7
s = pow(2, n, mod) - 1
def cal(n, r):
p = 1
q = 1
for i in range(r):
p = p*(n-i)%mod
q = q*(i+1)%mod
return p*pow(q, mod-2, mod)%mod
print((s - cal(n, a) - cal(n, b))%mod)
| 0 | null | 79,648,750,755,502 | 239 | 214 |
c = str(input())
al = 'abcdefghijklmnopqrstuvwxyz'
for i in range(len(al)):
if c == al[i]:
print(al[i+1])
|
import sys
a,b,c = map(int,input().split())
k = int(input())
for i in range(k+1):
if b * 2**i > a:
n = i
break
for j in range(k-n+1):
if c * 2**j > b * 2**n:
print("Yes")
sys.exit()
print("No")
| 0 | null | 49,752,982,990,310 | 239 | 101 |
def combination(n, r, m):
res = 1
r = min(r, n - r)
for i in range(r):
res = res * (n - i) % m
res = res * pow(i + 1, m - 2, m) % m
return res
mod = 10**9 + 7
n, a, b = map(int, input().split())
total = pow(2, n, mod) - 1
total -= (combination(n, a, mod) + combination(n, b, mod)) % mod
print(total % mod)
|
N = int(input())
C=[[0]*10 for _ in range(10)]
for n in range(1,N+1):
n=str(n)
n_s=int(n[0])
n_e=int(n[-1])
C[n_s][n_e]+=1
ans=0
for c_1 in range(10):
for c_2 in range(10):
ans += C[c_1][c_2]*C[c_2][c_1]
print(ans)
| 0 | null | 76,194,277,846,164 | 214 | 234 |
h, w, k = map(int, input().split())
s = [list(input()) for _ in range(h)]
a = [[0] * w for _ in range(h)]
cnt = 0
for i in range(h):
for j in range(w):
if s[i][j] == '#':
cnt += 1
a[i][j] = cnt
elif j >= 1 and a[i][j-1] > 0:
a[i][j] = a[i][j-1]
if a[i][0] == 0:
for j in range(w-2, -1, -1):
if a[i][j] == 0:
a[i][j] = a[i][j+1]
for i in range(h-2, -1, -1):
if a[i][0] == 0:
for j, v in enumerate(a[i+1]):
a[i][j] = v
for i in range(h):
if a[i][j] == 0:
for j, v in enumerate(a[i-1]):
a[i][j] = v
for i in range(h):
print(*a[i])
|
def LI():
return list(map(int, input().split()))
def LSH(h):
return [list(input()) for _ in range(h)]
H, W, K = LI()
S = LSH(H)
ans = [[0 for i in range(W)]for j in range(H)]
count = 1
for i in range(H):
itigo = 0
ok = 0
for j in range(W):
if S[i][j] == "#":
ok = 1
if itigo == 0:
ans[i][j] = count
itigo = 1
else:
count += 1
ans[i][j] = count
else:
ans[i][j] = count
if ok == 0:
ans[i][0] = 0
else:
count += 1
ok = -1
for i in range(H):
if ans[i][0] == 0:
if ok == -1:
for k in range(i+1, H):
if ans[k][0] != 0:
ok = k
break
for x in range(W):
print(ans[ok][x], end=" ")
print()
else:
ok = i
for j in range(W):
print(ans[i][j], end=" ")
print()
| 1 | 143,277,901,397,400 | null | 277 | 277 |
n=int(input())
taro=0
hanako=0
for i in range(n):
T,H=map(str,input().split())
if T<H:
hanako+=3
elif T>H:
taro+=3
else:
taro+=1
hanako+=1
print(taro, hanako)
|
def main():
N = int(input())
zoro = []
for i in range(N):
a, b = map(int, input().split())
if a == b:
zoro.append(1)
if i >= 2:
if zoro[i-2] == zoro[i-1] and zoro[i-1] == zoro[i]:
print('Yes')
return
else:
zoro.append(0)
print('No')
main()
| 0 | null | 2,223,045,594,970 | 67 | 72 |
s=input()
t=input()
print(["No","Yes"][t[:-1]==s])
|
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
h1,m1,h2,m2,k=nii()
minute=(h2-h1)*60
minute+=m2-m1
minute-=k
print(minute)
| 0 | null | 19,891,460,724,320 | 147 | 139 |
# coding: utf-8
input()
s = list(map(int,input().split()))
input()
t = list(map(int,input().split()))
cnt = 0
for i in t:
if i in s:
cnt += 1
print(cnt)
|
n = int(raw_input())
S = map(int, raw_input().split())
q = int(raw_input())
T = map(int, raw_input().split())
ans = 0
for i in T:
if i in S:
ans += 1
print ans
| 1 | 71,001,559,146 | null | 22 | 22 |
import collections
H, W, K = [int(x) for x in input().split()]
S = [input().strip() for _ in range(H)]
ans = float("inf")
for i in range(2 ** (H - 1)):
bundan = {}
bundan[0] = 0
prev = 0
tmp = 0
for j in range(H - 1):
if i >> j & 1 == 1:
prev += 1
bundan[j + 1] = prev
tmp += 1
else:
bundan[j + 1] = prev
c = collections.Counter()
for kk in range(W):
f = False
for k in range(H):
if f:
break
if S[k][kk] == '1':
c[bundan[k]] += 1
if c[bundan[k]] > K:
tmp += 1
f = True
c = collections.Counter()
for kkk in range(H):
if S[kkk][kk] == '1':
c[bundan[kkk]] += 1
break
for k in c.keys():
if c[k] > K:
tmp = float("inf")
break
ans = min(ans, tmp)
print(ans)
|
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
from itertools import accumulate
INF = float("inf")
def bit(n, k):
return (n >> k) & 1
def bit_sum(n):
wa = 0
while n > 0:
wa += n & 1
n >>= 1
return wa
def border(x):
# xを二進数で与えた時、ビットの立っている位置のリストを1-indexで返す
c = 0
ans = []
while x > 0:
c += 1
if x & 1:
ans.append(c)
x >>= 1
return ans
def main():
H, W, K = map(int, input().split())
S = [[0]*W for _ in range(H)]
for h in range(H):
S[h][:] = [int(c) for c in input()]
acc = [[0]+list(accumulate(S[h])) for h in range(H)]
min_kaisu = +INF
for h in range(1 << (H-1)):
# hは分割方法を与える
# hで与えられる分割方法は、どのような分割なのかを得る。
startend = border(h)
flag = False
division = [0]
# x番目でW方向に分割すると仮定する
for x in range(1, W+1):
# xの位置で分割したとき、左の領域のホワイトチョコレートの数
# まずは行ごとに求める
white = [acc[i][x] - acc[i][division[-1]] for i in range(H)]
# 領域ごとに加算するし、最大値を撮る
white_sum = [sum(white[s:e])
for s, e in zip([0]+startend, startend+[H])]
# print(bin(h), division, x, white_sum)
white_max = max(white_sum)
# Kよりも大きくなるなら、事前に分割するべきであった。
if white_max > K:
division.append(x-1)
# 分割してもなおK以下を達成できないケースを除外する
white = [acc[i][x] - acc[i][division[-1]] for i in range(H)]
white_sum = [sum(white[s:e])
for s, e in zip([0]+startend, startend+[H])]
white_max = max(white_sum)
if white_max > K:
flag = True
break
if flag:
continue
# hによる分割も考慮する
division_tot = len(division)-1 + bit_sum(h)
min_kaisu = min(division_tot, min_kaisu)
print(min_kaisu)
return
if __name__ == '__main__':
main()
| 1 | 48,337,828,847,550 | null | 193 | 193 |
text = input()
tend = len(text)
text2 = ""
if text[len(text)-1:len(text)] == "s":
text2 = text +'es'
else:
text2 = text +'s'
print(text2)
|
s = input()
print("{}".format(s+"es" if s[-1] == "s" else s+"s"))
| 1 | 2,380,969,402,112 | null | 71 | 71 |
n,nWorks,nSp = map(int,input().split())
s = input()
leftList = [0]*n
rightList = [0]*n
num = 0
count = 0
while num < n:
if s[num] == "o":
leftList[num] = 1
count +=1
num += 1 + nSp
else:
num +=1
if count > nWorks:
exit()
num = n-1
count = 0
while num >= 0:
if s[num] == "o":
rightList[num] = 1
count +=1
num -= (1 + nSp)
else:
num -=1
for kk in range(n):
if leftList[kk] and rightList[kk]:
print(kk+1)
|
n , k , c = map(int,input().split())
s = input()
L = []
R = []
i = 0
j = n-1
while i<n and len(L)<k :
if s[i] == "o" :
L.append(i)
i += c
i += 1
while j>-1 and len(R)<k :
if s[j] == "o" :
R.append(j)
j -= c
j -= 1
R.reverse()
for x in range(k):
if R[x] == L[x]:
print(R[x]+1)
| 1 | 40,695,073,282,562 | null | 182 | 182 |
print((int(input())+1)//2)
|
print(-1*(-1*int(input()) // 2))
| 1 | 58,692,753,657,410 | null | 206 | 206 |
a,b=map(int,input().split())
while b:
a,b=b,a%b
print(a)
|
def gcd(a,b):
r = a % b
while r != 0:
a, b = b, r
r = a % b
return b
a,b = list(map(int,input().split()))
print (gcd(a,b))
| 1 | 7,617,965,130 | null | 11 | 11 |
X = int(input())
if 400<=X and X<600:
print(8)
elif 600<=X and X<800:
print(7)
elif 800<=X and X<1000:
print(6)
elif 1000<=X and X<1200:
print(5)
elif 1200<=X and X<1400:
print(4)
elif 1400<=X and X<1600:
print(3)
elif 1600<=X and X<1800:
print(2)
elif 1800<=X and X<2000:
print(1)
|
n = int(input())
if n >= 1800:
print("1")
elif n >= 1600:
print("2")
elif n >= 1400:
print("3")
elif n >= 1200:
print("4")
elif n >= 1000:
print("5")
elif n >= 800:
print("6")
elif n >= 600:
print("7")
elif n >= 400:
print("8")
| 1 | 6,710,981,812,414 | null | 100 | 100 |
N = input()
K = int(input())
l = len(N)
dp = [[[0]*(K+1) for _ in range(2)] for _ in range(l)]
dp[0][0][1] = 1
dp[0][1][1] = int(N[0]) - 1
dp[0][1][0] = 1
#print(dp[0])
for i in range(1,l):
for j in range(K+1):
if int(N[i]) == 0:
if j > 0:
dp[i][0][j] = dp[i-1][0][j]
dp[i][1][j] += 9*dp[i-1][1][j-1]
else:
if j > 0:
dp[i][0][j] = dp[i-1][0][j-1]
dp[i][1][j] += dp[i-1][0][j-1]*(int(N[i])-1) + 9*dp[i-1][1][j-1]
dp[i][1][j] += dp[i-1][0][j]
dp[i][1][j] += dp[i-1][1][j]
#print(dp[i])
print(dp[l-1][0][K]+dp[l-1][1][K])
|
n,m=map(int, input().split())
roads=[]
for _ in range(m):
a,b=map(int, input().split())
roads.append([a,b])
group=[i for i in range(n)]
group2=[]
while group2!=group:
group2=list(group)
for road in roads:
if group[road[1]-1]>group[road[0]-1]:
group[road[1]-1]=group[road[0]-1]
else:
group[road[0]-1]=group[road[1]-1]
counter=1
group.sort()
for i in range(n-1):
if group[i]!=group[i+1]:
counter+=1
print(counter-1)
| 0 | null | 38,873,978,922,460 | 224 | 70 |
def abc159d_banned_k():
def cmb(n, r):
""" nCrの組み合わせ数を返す """
if n - r < r: r = n - r
if r == 0: return 1
if r == 1: return n
numerator = [n - r + k + 1 for k in range(r)]
denominator = [k + 1 for k in range(r)]
for p in range(2,r+1):
pivot = denominator[p - 1]
if pivot > 1:
offset = (n - r) % p
for k in range(p-1,r,p):
numerator[k - offset] /= pivot
denominator[k] /= pivot
result = 1
for k in range(r):
if numerator[k] > 1:
result *= int(numerator[k])
return result
n = int(input())
a = list(map(int, input().split()))
dict_a = {}
for item in a:
if item in dict_a.keys():
dict_a[item] += 1
else:
dict_a[item] = 1
cnt = 0
for k in dict_a:
if dict_a[k] > 1:
cnt += cmb(dict_a[k],2)
for item in a:
if dict_a[item] > 2:
print(cnt - cmb(dict_a[item],2) + cmb(dict_a[item]-1,2))
elif dict_a[item] == 2:
print(cnt - 1)
else:
print(cnt)
abc159d_banned_k()
|
from collections import Counter
import math
def combinations_count(n):
return (n * (n - 1)) // 2
N = int(input())
A = list(map(int, input().split()))
combs = {}
dic = Counter(A)
for k, v in dic.items():
combs[k] = combinations_count(v)
ans = sum(combs.values())
for i in range(N):
a = A[i]
ans_i = ans
if combs[a] < 2:
ans_i -= combs[a]
print(ans_i)
else:
ans_i -= dic[a] - 1
print(ans_i)
| 1 | 47,693,689,011,030 | null | 192 | 192 |
R = int(input())
print(R * 2 * 3.1415)
|
import numpy as np
r=int(input())
print(np.pi*2.0*r)
| 1 | 31,466,460,583,740 | null | 167 | 167 |
n,m = map(int,input().split())
a = 0
for i in range(m):
if n % 2 == 0 and n % 4 != 0 and n-4*i-2 == 0:
a = 1
elif n % 4 == 0 and i == (n//2-1) // 2 + 1:
a = 1
print('{} {}'.format(i+1, n-i-a))
|
H, N = map(int, input().split())
A = []
B = []
for n in range(N):
a, b = map(int, input().split())
A.append(a)
B.append(b)
INF = float('inf')
dp = [INF] * (H + max(A))
dp[0] = 0
# dp[i]を、HP iを減らすために必要な最小の魔力とする
for hp in range(1, H+1):
for n in range(N):
dp[hp] = min(dp[max(hp-A[n],0)] + B[n], dp[hp])
print(dp[H])
| 0 | null | 54,874,068,993,656 | 162 | 229 |
# coding: utf-8
d = {}
N = int(input())
for _ in range(N):
ope, s = map(str, input().split())
if ope == 'insert':
d[s] = 0
elif ope == 'find':
if s in d.keys():
print('yes')
else:
print('no')
|
a,b=map(int,raw_input().split())
men=a*b
syuu=(a+b)*2
print men,syuu
| 0 | null | 188,240,653,262 | 23 | 36 |
def isPrime(n):
i = 2
while i*i <= n:
if n % i == 0:
return False
i += 1
return True
n = int(input())
ans = 0
for i in range(n):
t = int(input())
if isPrime(t):
ans += 1
print(ans)
|
S = input()
if S.upper() == "ABC":
print("ARC")
else:
print("ABC")
| 0 | null | 12,186,430,499,640 | 12 | 153 |
N,A,B = [int(x) for x in input().split()];
#print(A);
#print(B);
#print(N);
#lm = int(A + (B-A-1)/2);
lm = A + (B-A-1)//2;
#print(lm);
#rm = int(N-B+1 + (B-A-1)/2);
rm = N-B+1 + (B-A-1)//2;
#print(rm);
if (B-A)%2 == 0 :
print((B-A)//2);
else :
print(min(lm,rm));
|
N, A, B = map(int, input().split())
dif = abs(A-B)
if dif%2 == 0:
ans = dif//2
else:
#A left
t0 = A - 1 + 1
xa = 0
xb = B - t0
dif = abs(xb - xa)
ans1 = dif//2 + t0
#B left
t0 = B - 1 + 1
xa = A - t0
xb = 0
dif = abs(xb - xa)
ans2 = dif//2 + t0
#A right
t0 = N - A + 1
xa = N
xb = B + t0
dif = abs(xb - xa)
ans3 = dif//2 + t0
#B right
t0 = N - B + 1
xa = A + t0
xb = N
dif = abs(xb - xa)
ans4 = dif//2 + t0
ans = min(ans1, ans2, ans3, ans4)
print(ans)
| 1 | 109,493,282,298,510 | null | 253 | 253 |
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if a[0] == b[0]:
print(0)
else:
print(1)
|
n=int(input())
a=list(map(int,input().split()))
ans=0
tempi=[0]*n
tempj=[0]*n
for i in range(n):
tempi[i]=a[i]+i+1
for i in range(n):
tempj[i]=-a[i]+i+1
import collections
tempid=collections.Counter(tempi)
tempjd=collections.Counter(tempj)
for k in tempid.keys():
a=tempid[k]
b=tempjd[k]
ans=ans+a*b
print(ans)
| 0 | null | 75,575,474,887,714 | 264 | 157 |
k, n = map(int, input().split())
a = list(map(int, input().split()))
a += [k + a[0]]
print(k - max([a[i + 1] - a[i] for i in range(n)]))
|
K, N = map(int, input().split())
A = list(map(int, input().split()))
A.append(K+A[0])
max_dist = max([A[i+1] - A[i] for i in range(N)])
print(K - max_dist)
| 1 | 43,482,037,076,320 | null | 186 | 186 |
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)
|
s = input()
p = input()
bl = True
if p in s:
print("Yes")
bl = False
if bl:
for i in range(1,len(s)+1):
if p[0:i] == s[-i:]:
if p[i:] == s[0:len(p)-i]:
print("Yes")
bl = False
break
if bl:
print("No")
| 0 | null | 85,696,459,004,124 | 293 | 64 |
fact = [1 for _ in range(200000)]
inv = [1 for _ in range(200000)]
fact_inv = [1 for _ in range(200000)]
mod = 998244353
for i in range(2, 200000):
fact[i] = (fact[i-1]*i) % mod
inv[i] = mod - (inv[mod % i] * (mod // i)) % mod
fact_inv[i] = (fact_inv[i-1] * inv[i]) % mod
N, M, K = map(int, input().split())
ans = 0
a = pow(M-1, N-1-K, mod)
for i in range(K, -1, -1):
ans += (fact[N-1] * fact_inv[i] * fact_inv[N-1-i]) * M * a
ans = ans % mod
a *= M-1
a = a % mod
print(ans)
|
def COMinit():
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2,max):
fac[i] = fac[i-1]*i%mod
inv[i] = mod - inv[mod%i]*(mod//i)%mod
finv[i] = finv[i-1]*inv[i]%mod
def COM(n,k):
if n < k:
return 0
if n < 0 or k < 0:
return 0
return fac[n] * (finv[k]*finv[n-k]%mod)%mod
mod = 998244353
N,M,K = map(int,input().split())
max = max(N,2)
fac = [0] * max
finv = [0] * max
inv = [0] * max
COMinit()
ans = 0
for i in range(K+1):
c = COM(N-1,i)
m = pow(M-1,N-i-1,mod)
ans = (ans + ((c*m%mod)*M%mod))%mod
print(ans)
| 1 | 23,358,661,750,258 | null | 151 | 151 |
A = int(input())
B = int(input())
C = [i for i in range(1, 4) if i != A and i != B]
print(*C)
|
a = input()
b = input()
ans = '123'
ans = ans.replace(a, '').replace(b, '')
print(ans)
| 1 | 110,639,318,130,822 | null | 254 | 254 |
# -*- coding: utf-8 -*-
def main():
dictionary = {}
input_num = int(raw_input())
counter = 0
while counter < input_num:
command, key = raw_input().split(' ')
if command == 'insert':
dictionary[key] = True
else:
if key in dictionary:
print 'yes'
else:
print 'no'
counter += 1
if __name__ == '__main__':
main()
|
# -*- coding: utf-8 -*-
from sys import stdin
Dic = {}
n = int(stdin.readline().rstrip())
for i in range(n):
line = stdin.readline().rstrip()
if line[0] == 'i':
Dic[line[7:]] = 0
else:
print('yes' if line[5:] in Dic else 'no')
| 1 | 80,435,141,508 | null | 23 | 23 |
H,W,K=map(int,input().split())
S=[input() for _ in range(H)]
ans=[[0]*W for _ in range(H)]
zero = -1
count = 1
for i in range(H):
if zero == -1 and S[i].count('#')==0:
zero = i
continue
if zero != -1 and S[i].count('#')==0:
continue
last=0
for j in range(W):
if S[i][j]=='.':
if zero != -1:
for k in range(zero,i):
ans[k][j] = count
ans[i][j] = count
if S[i][j]=='#':
if zero != -1:
for k in range(zero,i):
ans[k][j] = count
ans[i][j] = count
if j<W-1 and S[i][j+1:].count('#')==0:
last = 1
else:
count += 1
if j == W-1 and last:
last = 0
count += 1
if j == W-1:
zero = -1
if zero != -1:
for i in range(zero,H):
ans[i] = ans[zero-1]
for i in range(H):
print(*ans[i])
|
H,W,K=map(int,input().split())
L=[]
E=[0 for i in range(W+2)]
L.append(E)
for i in range(H):
l=[0]+list(input())+[0]
L.append(l)
L.append(E)
#print(L)
cnt=1
for i in range(1,H+1):
for j in range(1,W+1):
if L[i][j]=="#":
L[i][j]=cnt
cnt+=1
#print(L)
for i in range(1,H+1):
num=0
for j in range(1,W+1):
if num>0 and L[i][j]==".":
L[i][j]=num
elif L[i][j]!=".":
num=L[i][j]
num=0
for j in range(1,W+1):
if L[i][W+1-j]!=".":
num=L[i][W+1-j]
elif num!=0 and L[i][W+1-j]==".":
L[i][W+1-j]=num
for i in range(1,H):
if L[i+1][1]==".":
L[i+1]=L[i]
for i in range(1,H):
if L[H-i][1]==".":
L[H-i]=L[H-i+1]
for i in range(1,H+1):
print(*L[i][1:W+1])
| 1 | 143,941,524,102,688 | null | 277 | 277 |
string = str(input())
if string.isupper():
print("A")
else:
print("a")
|
a=input()
b='abcdefghijklmnopqrstuvwxyz'
for i in range(len(b)):
if b[i]==a:
print("a")
exit()
print("A")
| 1 | 11,401,617,254,720 | null | 119 | 119 |
x = input()
n = int(x)
print(n*n*n)
|
import math
while True:
try:
a, b = [int(x) for x in input().split()]
print(math.gcd(a,b), a*b // math.gcd(a,b))
except EOFError:
break
| 0 | null | 137,978,274,240 | 35 | 5 |
from collections import deque
n, m = map(int, input().split())
graph = [[] for _ in range(n+1)]
for i in range(m):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
dist = [[-1,0] for _ in range(n+1)]
dist[0][0] = 0
dist[1][0] = 0
d = deque()
d.append(1)
while d:
v = d.popleft()
for i in graph[v]:
if dist[i][0] != -1:
continue
dist[i][0] = dist[v][0] + 1
dist[i][1] = v
d.append(i)
ans = dist[2:]
print('Yes')
for j in range(n-1):
print(ans[j][1])
|
N = int(input())
A = "abcdefghijklmnopqrstuvwxyz"
x = [A[(N-1)%26]]
N -= 26
i = 1
while N > 0:
x.append(A[((N-1)//(26**i))%26])
i += 1
N -= 26**i
ans = ""
for i in range(1,len(x)+1):
ans += x[-i]
print(ans)
| 0 | null | 16,119,815,768,760 | 145 | 121 |
s=input()
print("YNeos"[s == len(s) * s[0]::2])
|
while True:
x = input().split()
x_int = [int(i) for i in x]
if x_int[0] == 0 and x_int[1] ==0:
break
for i in range(x_int[0]):
z = '#' * x_int[1]
print(z)
print()
| 0 | null | 27,613,985,624,160 | 201 | 49 |
x,k,d=list(map(int,input().split()))
#print(x,k,d)
result=abs(x)-k*d
swithn=0
if result<0:
if k%2==1:
x-=d
result=min(x%(2*d),-x%(2*d))
print(result)
|
N=int(input())
A=list(map(int,input().split()))
M=1000050
dp=[0 for i in range(M)]
ans=0
for x in A:
if dp[x]!=0:
dp[x]=2
continue
for i in range(x,M,x):
dp[i]+=1
for x in A:
if dp[x]==1:
ans+=1
print(ans)
| 0 | null | 9,894,601,874,718 | 92 | 129 |
x = [int(x) for x in input().split()]
if (sum(x)>21):
print('bust')
else:
print('win')
|
w=raw_input()
ct=0
while 1:
s=raw_input()
if s=='END_OF_TEXT':
break
s=s.split()
for i in s:
if i.lower()==w :
ct+=1
print(ct)
| 0 | null | 60,167,757,467,788 | 260 | 65 |
from itertools import *
H, W, K = map(int, input().split())
S = [list(map(int, input())) for i in range(H)]
cut_min = H+W-2
for r_cut in range(H):
if cut_min <= r_cut:
continue
for r_pos in combinations(range(1, H), r_cut):
r_pos = (None,)+r_pos+(None,)
r_blocks = [slice(*r_pos[i:i+2]) for i in range(len(r_pos)-1)]
cut = r_cut
prev_sum = [0] * len(r_blocks)
for col in zip(*S):
curr_sum = [sum(col[b]) for b in r_blocks]
if any(map(K.__lt__, curr_sum)):
break
next_sum = [x+y for x,y in zip(prev_sum, curr_sum)]
if any(map(K.__lt__, next_sum)):
cut += 1
if cut_min <= cut:
break
prev_sum = curr_sum
else:
prev_sum = next_sum
else:
cut_min = cut
print(cut_min)
|
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 | 32,757,099,935,680 | 193 | 136 |
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(0,n-k):
if a[i]<a[k+i]:print("Yes")
else :print("No")
|
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
sys.setrecursionlimit(100000000)
def input(): return sys.stdin.readline().rstrip()
N, K, C = map(int, input().split())
S = input()
L = [None] * K
R = [None] * K
i = 0
for j in range(N):
if S[j] == 'o' and i < K and (i == 0 or j - L[i - 1] > C):
L[i] = j
i += 1
i = K - 1
for j in reversed(range(N)):
if S[j] == 'o' and i >= 0 and (i == K - 1 or R[i + 1] - j > C):
R[i] = j
i -= 1
for l, r in zip(L, R):
if l == r:
print(l + 1)
| 0 | null | 23,989,826,981,020 | 102 | 182 |
card_dk = int(input())
block = ['S','H','C','D']
no = [1,2,3,4,5,6,7,8,9,10,11,12,13]
card_st =[]
not_card =[]
for i in range(card_dk):
card = input().split()
card[1] = int(card[1])
card_st.append(card)
for ch_block in block:
for ch_no in no:
flag = 0
for card in card_st:
if card == [ch_block,ch_no]:
flag = 1
if flag == 0:
card = [ch_block,ch_no]
not_card.append(card)
for fud_card in not_card:
print('{} {}'.format(fud_card[0],fud_card[1]))
|
n = int(input())
list_s = [1,2,3,4,5,6,7,8,9,10,11,12,13]
list_h = [1,2,3,4,5,6,7,8,9,10,11,12,13]
list_c = [1,2,3,4,5,6,7,8,9,10,11,12,13]
list_d = [1,2,3,4,5,6,7,8,9,10,11,12,13]
for i in range(n):
zugara, num = input().split()
#print(zugara)
#print(num)
#print(list_s)
if zugara == 'S':
list_s.remove(int(num))
elif zugara == 'H':
list_h.remove(int(num))
elif zugara == 'C':
list_c.remove(int(num))
else:
list_d.remove(int(num))
for i in list_s:
print('S', i)
for i in list_h:
print('H', i)
for i in list_c:
print('C', i)
for i in list_d:
print('D', i)
| 1 | 1,018,831,096,340 | null | 54 | 54 |
import math
# a=int(input())
#b=int(input())
# c=[]
# for i in b:
# c.append(i)
e1,e2 = map(int,input().split())
f = list(map(int,input().split()))
#j = [input() for _ in range(3)]
cal=1
for i in range(e1-e2):
if f[i]>=f[i+e2]:
print("No")
else:
print("Yes")
|
def main():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
for i in range(K, N):
if A[i - K] < A[i]:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main()
| 1 | 7,063,914,297,586 | null | 102 | 102 |
def dijkstra(v, G):
import heapq
ret = [10 ** 10] * len(G)
ret[v] = 0
q = [(ret[i], i) for i in range(len(G))]
heapq.heapify(q)
while len(q):
tmpr, u = heapq.heappop(q)
if tmpr == ret[u]:
for w in G[u]:
if ret[w] > ret[u] + 1:
ret[w] = ret[u] + 1
heapq.heappush(q, (ret[w], w))
return ret
N, M = map(int, input().split())
G, ans = {i: [] for i in range(N)}, [-1] * N
for _ in range(M):
A, B = map(int, input().split())
G[A - 1].append(B - 1)
G[B - 1].append(A - 1)
d = dijkstra(0, G)
for a in range(N):
for b in G[a]:
if d[a] - d[b] == 1:
ans[a] = b + 1
print("Yes")
for a in ans[1:]:
print(a)
|
n = int(input())
ans = 0
count = 0
a, b, c = 1, 1, 1
while a <= n:
# print("A : {0}".format(a))
# print("追加パターン : {0}".format( (n // a) ))
if a == 1 :
ans = ans + ( (n // a) - 1)
else :
if n // a == 1 :
ans = ans + 1
else :
if n % a == 0 :
ans = ans + ( (n // a) - 1)
else :
ans = ans + ( (n // a) )
# if n % a == 0 :
# ans = ans + ( (n / a) - 1 )
# else :
# ans = ans + ( (n // a) - 1 )
# ans = ans + (n / a) - 1
# print("A : {0}".format(a))
# while a * b < n:
# print("B : {0}".format(b))
# ans += 1
# b += 1
# c = 1
a += 1
b, c = 1, 1
# print("計算実行回数 : {0}".format(count))
print(ans - 1)
| 0 | null | 11,520,092,321,052 | 145 | 73 |
s=input()
if s.count('A') and s.count('B'): print('Yes')
else: print('No')
|
S = str(input())
if S == 'AAA':
print('No')
elif S == 'BBB':
print('No')
else:
print('Yes')
| 1 | 55,139,231,791,252 | null | 201 | 201 |
while True:
H, W = map(int, raw_input().split())
if (H+W) == 0:
break
print_dot = "#" + ('.'*(W-2)) + "#"
print "#"*W
for h in range(1, (H-1)):
print print_dot
print "#"*W
print ""
|
while True:
H, W = map(int, input().split())
if (H == W == 0):
break
else:
for j in range(H):
if (j == 0 or j == H - 1):
for i in range(W):
print("#", end='')
else:
for f in range(W):
if (f == 0 or f == W - 1):
print("#", end='')
else:
print(".", end='')
print()
print()
| 1 | 807,508,937,828 | null | 50 | 50 |
#!/usr/bin/env python3
import collections as cl
import sys
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def main():
N = II()
A = LI()
for a in A:
if a % 2 == 0:
if a % 3 != 0 and a % 5 != 0:
print("DENIED")
exit()
print("APPROVED")
main()
|
from bisect import bisect_right
import string
N=int(input())
L=[0]*13
for i in range(1,13):
L[i]=(L[i-1]+1)*26
# print(L)
# やるべきことは26進数
def bisectsearch_right(L,a):
i=bisect_right(L,a)
return(i)
S=string.ascii_lowercase
l=bisectsearch_right(L,N-1)
s=['']*l
tmp=N-1-L[l-1]
# print(l,tmp)
j=l-1
while j>=0:
s[j]=S[tmp%26]
tmp//=26
j-=1
print(''.join(s))
| 0 | null | 40,508,308,503,968 | 217 | 121 |
a, b, m = map(int, input().split())
a_p = list(map(int, input().split()))
b_p = list(map(int, input().split()))
min_price = min(a_p) + min(b_p)
for i in range(m):
x, y, c = map(int, input().split())
min_price = min(min_price, a_p[x-1] + b_p[y-1] - c)
print(min_price)
|
from bisect import *
n,m = map(int,input().split())
S = input()
ok = []
for i,s in enumerate(S[::-1]):
if s == '0':
ok.append(i)
now = 0
ans = []
while now != n:
nxt = ok[bisect_right(ok, now + m) - 1]
if nxt == now:
ans = [str(-1)]
break
else:
ans.append(str(nxt - now))
now = nxt
print(' '.join(ans[::-1]))
| 0 | null | 96,768,870,021,132 | 200 | 274 |
import sys
import bisect
input = sys.stdin.readline
class Bisect(object):
def bisect_max(self, reva, func,M):
ok = 0 # exist
ng = 4*(10**5) # not exist
while abs(ok-ng) > 1:
cnt = (ok + ng) // 2
if func(cnt,reva,M):
ok = cnt
else:
ng = cnt
return ok
def solve1(tgt,reva,M):
res=0
n = len(reva)
for i in range(n):
tmp = bisect.bisect_left(reva,tgt-reva[i])
tmp = n - tmp
res += tmp
if M <= res:
return True
else:
return False
N,M = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)
reva = a[::-1]
bs = Bisect()
Kmax = (bs.bisect_max(reva,solve1,M))
r=[0]
for i in range(N):
r.append(r[i]+a[i])
res = 0
cnt = 0
t = 0
for i in range(N):
tmp = bisect.bisect_left(reva,Kmax-reva[N-i-1])
tmp2 = bisect.bisect_right(reva,Kmax-reva[N-i-1])
if tmp!=tmp2:
t = 1
tmp = N - tmp
cnt += tmp
res += tmp*a[i]+r[tmp]
if t==1:
res -= (cnt-M)*Kmax
print(res)
|
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n,m = inpl()
a = sorted(inpl())
ng = 10**9+1
ok = -1
def sol(x):
cnt = 0
for i,t in enumerate(a):
tmp = x - t
c = bisect.bisect_left(a,tmp)
cnt += n-c
return True if cnt >= m else False
while ng-ok > 1:
mid = (ng+ok)//2
if sol(mid):
ok = mid
else: ng = mid
# print(ok,ng)
# print(ok)
res = 0
cnt = 0
revc = [0]
for i in range(n)[::-1]:
revc.append(revc[-1] + a[i])
# print(revc)
for i in range(n):
j = n-bisect.bisect_left(a,ok-a[i])
res += j*a[i] + revc[j]
cnt += j
res -= (cnt-m) * ok
print(res)
| 1 | 108,380,902,761,012 | null | 252 | 252 |
def bubbleSort(A, N):
flag = True
count = 0
while flag:
flag = 0
for j in range(N-1, 0, -1):
if A[j] < A[j-1]:
tmp = A[j]
A[j] = A[j-1]
A[j-1] = tmp
flag = 1
count += 1
print(*A)
print(count)
arr_length = int(input())
arr_num = [int(i) for i in input().split(" ")]
bubbleSort(arr_num, arr_length)
|
# -*- coding: utf-8 -*-
N=input()
#約数列挙
def make_divisors(n):
divisors=[]
for i in range(1, int(n**0.5)+1):
if n%i==0:
divisors.append(i)
if i!=n/i:
divisors.append(n/i)
return divisors
#整数N-1の約数は全て答えにカウントして良い
ans=set(make_divisors(N-1))
wrong_ans=set(make_divisors(N-1))
K=make_divisors(N) #Nの約数の集合
#整数Nの約数について条件にマッチングするかを1つ1つ調べる
for k in K:
if k==1: continue
n=N
while n%k==0:
n/=k
else:
if n==1 or n%k==1:
ans.add(k)
print len(ans)-1
| 0 | null | 20,774,114,635,860 | 14 | 183 |
import math
p_max = 1000000 * 1000000
n, k = map(int, input().split())
w = [int(input()) for i in range(n)]
def check(p):
i = 0
for j in range(k):
s = 0
while (s + w[i] <= p):
s += w[i]
i += 1
if i == n:
return n
return i
if __name__ == "__main__":
right = p_max
left = 0
mid = 0
while (right - left > 1):
mid = math.floor((right + left) / 2)
v = check(mid)
if v >= n:
right = mid
else:
left = mid
print (right)
|
def resolve():
n = int(input())
ans = 'No'
for i in range(1,10):
for j in range(1,10):
if i*j == n:
ans = 'Yes'
print(ans)
resolve()
| 0 | null | 80,332,379,469,730 | 24 | 287 |
import sys; input = sys.stdin.readline
from math import ceil
d, t, s = map(int, input().split())
u, l = ceil(d/t), d//t
if u == l:
if u <= s: print("Yes")
else: print("No")
else:
if d/t <= s: print("Yes")
else:print("No")
|
text = [int(e) for e in input().split()]
if text[1] * text[2] >= text[0]:
print("Yes")
else:
print("No")
| 1 | 3,522,604,525,872 | null | 81 | 81 |
import numpy as np
H,W,M = map(int,input().split())
#h = np.empty(M,dtype=np.int)
#w = np.empty(M,dtype=np.int)
bomb = set()
hh = np.zeros(H+1,dtype=np.int)
ww = np.zeros(W+1,dtype=np.int)
for i in range(M):
h,w = map(int,input().split())
bomb.add((h,w))
hh[h] += 1
ww[w] += 1
#print(bomb)
h_max = np.max(hh)
w_max = np.max(ww)
h_max_ids = list()
w_max_ids = list()
for i in range(1,H+1):
if hh[i] == h_max:
h_max_ids.append(i)
for j in range(1,W+1):
if ww[j] == w_max:
w_max_ids.append(j)
for i in h_max_ids:
for j in w_max_ids:
if not (i,j) in bomb:
print(h_max + w_max)
exit()
#print("hmax:{} wmax:{}".format(h_max_id, w_max_id))
#print("hmax:{} wmax:{}".format(hh[h_max_id], ww[w_max_id]))
print(h_max + w_max - 1)
|
def main():
H, W, M = (int(i) for i in input().split())
hc = [0]*(H+1)
wc = [0]*(W+1)
maps = set()
for _ in range(M):
h, w = (int(i) for i in input().split())
hc[h] += 1
wc[w] += 1
maps.add((h, w))
mah = max(hc)
maw = max(wc)
ans = mah+maw
hmaps = []
wmaps = []
for i, h in enumerate(hc):
if mah == h:
hmaps.append(i)
for i, w in enumerate(wc):
if maw == w:
wmaps.append(i)
if M < len(hmaps) * len(wmaps):
# 爆破対象の合計が最大になるマスがM個より多ければ,
# 必ず爆破対象がないマスに爆弾を置くことができる
# 逆にM個以下なら3*10^5のループにしかならないので
# このようにif文で分けなくても,必ずO(M)になるのでelse節のforを回してよい
print(ans)
else:
for h in hmaps:
for w in wmaps:
if (h, w) not in maps:
print(ans)
return
else:
print(ans-1)
if __name__ == '__main__':
main()
| 1 | 4,694,217,871,252 | null | 89 | 89 |
n,k = map(int,input().split())
P = list(map(int,input().split()))
s=0
for i in range(k):
s += P[i]
ms=s
for i in range(len(P)-k):
s +=(P[i+k]-P[i])
if s>ms :
ms=s
print( (ms+k)/2)
|
N, K = map(int, input().split())
nums = list(map(int, input().split()))
expect = 0
answer = 0
for i in range(N):
if i < K:
expect += (nums[i]+1)/2
else:
expect += (nums[i]+1)/2 - (nums[i-K]+1)/2
answer = max(answer, expect)
print(answer)
| 1 | 74,636,639,792,090 | null | 223 | 223 |
H = int(input())
a = 1
an = 1
while a < H:
a *= 2
if a<=H:
an += a
else:
break
print(an)
|
H, N = list(map(int, input().split()))
A = [[0]*2 for _ in range(N)]
for _ in range(N):
A[_][0], A[_][1] = list(map(int, input().split()))
# print(A)
# A.sort(key=lambda x: x[1])
INF = float('inf')
dp = [INF]*(H+1)
dp[0] = 0
for i in range(H):
if dp[i] == INF:
continue
for j in range(N):
a = A[j][0]
b = A[j][1]
if i+a >= H:
dp[H] = min(dp[H], dp[i]+b)
else:
dp[i+a] = min(dp[i+a], dp[i]+b)
print(dp[H])
| 0 | null | 80,418,424,743,902 | 228 | 229 |
def y_solver(tmp):
l=len(tmp)
rev=[int(i) for i in tmp[::-1]+"0"]
ans=0
for i in range(l):
num=rev[i]
next_num=rev[i+1]
if (num>5) or (num==5 and next_num>=5):
rev[i+1]+=1
ans+=min(num,10-num)
last=rev[l]
ans+=min(last,10-last)
return ans
s=input()
ans=y_solver(s)
print(ans)
|
combined = input().split(" ")
s = int(combined[0])
w = int(combined[1])
if w >= s:
print("unsafe")
else:
print("safe")
| 0 | null | 50,358,828,323,452 | 219 | 163 |
N = int(input())
S = str(input())
#print(N,S)
stack = []
while len(S) > 0:
if len(stack) == 0:
stack.append(S[0])
S = S[1:]
elif S[0] == stack[-1]:
S = S[1:]
elif S[0] != stack[-1]:
stack.append(S[0])
S = S[1:]
#print(S,stack)
print(len(stack))
|
import sys
n = int(input())
s = list(input())
if n == 1:
print(1)
sys.exit()
a = []
for i in range(n-1):
if s[i] != s[i+1]:
a.append(s[i])
if len(a) == 0:
print(1)
else:
if a[-1] != s[-1]:
a.append(s[-1])
print(len(a))
| 1 | 170,073,130,518,182 | null | 293 | 293 |
n,k=map(int,input().split())
a=list(map(int,input().split()))
def imos(a):
imos_l=[0 for i in range(n)]
for i in range(n):
left=max(i-a[i],0)
right=min(i+a[i],n-1)
imos_l[left]+=1
if right+1!=n:
imos_l[right+1]-=1
b=[0]
for i in range(1,n+1):
b.append(b[i-1]+imos_l[i-1])
return b[1:]
for i in range(k):
a=imos(a)
if a.count(n)==n:
break
print(*a)
|
# https://atcoder.jp/contests/tokiomarine2020/tasks/tokiomarine2020_c
N, K = map(int, input().split())
A = list(map(int, input().split()))
while K > 0:
K -= 1
# imos法 (B)
B = [0] * (N + 1)
for i in range(N):
l = max(0, i - A[i])
r = min(N - 1, i + A[i])
B[l] += 1
if r + 1 < N:
B[r + 1] -= 1
C = 0
for j in range(N):
C += B[j]
A[j] = C
if set(A) == set([N]):
break
print(*A)
| 1 | 15,522,651,568,502 | null | 132 | 132 |
A,B = map(int, input().split())
c = A-(2*B)
if A <= 2*B:
print("0")
else:
print(c)
|
a, b = map(int, input().split())
c = a - (2 * b)
print(c if c >= 0 else 0)
| 1 | 166,913,131,376,578 | null | 291 | 291 |
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
import itertools
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
def main():
h,w,k = map(int,ipt().split())
s = [list(map(int,list(input()))) for _ in [0]*h]
'''
sms = [[0]*w for _ in [0]*h]
for i in range(w):
for j in range(h):
sms[j][i] = sms[j-1][i]+s[j][i]
print(i)
'''
cmi = 10**18
for i in range(2**(h-1)):
pos = [0]*h
for j in range(h-1):
if (i >> j) & 1:
pos[j+1] = pos[j]+1
else:
pos[j+1] = pos[j]
cmii = pos[-1]
si = [0]*h
for jj in range(h):
si[pos[jj]] += s[jj][0]
if max(si) > k:
continue
f = True
for j in range(1,w):
if f:
for ii in range(h):
if si[pos[ii]]+s[ii][j] > k:
cmii += 1
si = [0]*h
for jj in range(h):
si[pos[jj]] += s[jj][j]
if max(si) > k:
f = False
break
else:
si[pos[ii]]+=s[ii][j]
if f and cmii < cmi:
cmi = cmii
print(cmi)
return
if __name__ == '__main__':
main()
|
x = int(input())
if x >= 30:
print("Yes")
else:
print("No")
| 0 | null | 26,979,488,634,342 | 193 | 95 |
W,H,x,y,r=map(int,input().split())
if (0<=x+r<=W and 0<=y+r<=H)and(0<=x-r<=W and 0<=y-r<=H):
print('Yes')
else:
print('No')
|
import math
n = int(input())
vector_x = [float(x) for x in input().split(" ")]
vector_y = [float(y) for y in input().split(" ")]
p1 = sum([abs(x - y) for x, y in zip(vector_x, vector_y)])
p2 = sum([abs(x - y) ** 2 for x, y in zip(vector_x, vector_y)]) ** (1/2)
p3 = sum([abs(x - y) ** 3 for x, y in zip(vector_x, vector_y)]) ** (1/3)
t = max([abs(x - y) for x, y in zip(vector_x, vector_y)])
print("{:.6f}".format(p1))
print("{:.6f}".format(p2))
print("{:.6f}".format(p3))
print("{:.6f}".format(t))
| 0 | null | 341,686,941,960 | 41 | 32 |
from sys import stdin
for l in stdin:
a,b=map(int,l.split())
print(len(str(a+b)))
|
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0]+list(accumulate(lst))
def celi(a,b):
return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]
x=int(input())
def is_prime(n):
if n == 1: return False
for k in range(2, int(math.sqrt(n)) + 1):
if n % k == 0:
return False
return True
ans=x
while not is_prime(ans):
ans+=1
print(ans)
| 0 | null | 52,523,771,820,202 | 3 | 250 |
n = int(input())
list_s = [1,2,3,4,5,6,7,8,9,10,11,12,13]
list_h = [1,2,3,4,5,6,7,8,9,10,11,12,13]
list_c = [1,2,3,4,5,6,7,8,9,10,11,12,13]
list_d = [1,2,3,4,5,6,7,8,9,10,11,12,13]
for i in range(n):
zugara, num = input().split()
#print(zugara)
#print(num)
#print(list_s)
if zugara == 'S':
list_s.remove(int(num))
elif zugara == 'H':
list_h.remove(int(num))
elif zugara == 'C':
list_c.remove(int(num))
else:
list_d.remove(int(num))
for i in list_s:
print('S', i)
for i in list_h:
print('H', i)
for i in list_c:
print('C', i)
for i in list_d:
print('D', i)
|
card = []
suit = ["S","H","C","D"]
for s in suit:
for i in range(1,14):
card.append(s + " " + str(i))
n = int(input())
for i in range(n):
card.remove(input())
for c in card:
print(c)
| 1 | 1,040,894,921,048 | null | 54 | 54 |
a,b=input().split()
X=a*int(b)
Y=b*int(a)
print(min(X,Y))
|
a, b = input().split()
s1 = a*int(b)
s2 = b*int(a)
print(s1 if s1 < s2 else s2)
| 1 | 84,267,088,514,322 | null | 232 | 232 |
s = list(input())
q = int(input())
rvs = []
i = 0
j = 0
p = []
order = []
for i in range(q):
order.append(input().split())
if order[i][0] == "replace":
p = []
p = list(order[i][3])
for j in range(int(order[i][1]), int(order[i][2]) + 1):
s[j] = p[j - int(order[i][1])]
elif order[i][0] == "reverse":
ss = "".join(s[int(order[i][1]):int(order[i][2]) + 1])
rvs = list(ss)
rvs.reverse()
for j in range(int(order[i][1]), int(order[i][2]) + 1):
s[j] = rvs[j - int(order[i][1])]
# temp = s[int(order[i][1])]
# s[int(order[i][1])] = s[int(order[i][2])]
# s[int(order[i][2])] = temp
elif order[i][0] == "print":
ss = "".join(s)
print("%s" % ss[int(order[i][1]):int(order[i][2]) + 1])
|
def my_print(s, a, b):
print(s[a:b+1])
def my_reverse(s, a, b):
return s[:a] + s[a:b+1][::-1] + s[b+1:]
def my_replace(s, a, b, p):
return s[:a] + p + s[b+1:]
if __name__ == '__main__':
s = input()
q = int(input())
for i in range(q):
code = input().split()
op, a, b = code[0], int(code[1]), int(code[2])
if op == 'print':
my_print(s, a, b)
elif op == 'reverse':
s = my_reverse(s, a, b)
elif op == 'replace':
s = my_replace(s, a, b, code[3])
| 1 | 2,079,493,813,300 | null | 68 | 68 |
n = len(input())
print('x' * n)
|
#!/usr/bin python3
# -*- coding: utf-8 -*-
x = int(input())
print(10-x//200)
| 0 | null | 39,557,310,477,152 | 221 | 100 |
#!/usr/bin/env python3
import sys
import heapq
MOD = 1000000007 # type: int
def containPositive(arr):
for a in arr:
if a >= 0:
return True
return False
def solve(N: int, K: int, A: "List[int]"):
if N == K:
m = 1
for a in A:
m = m*a%MOD
print(m)
elif not containPositive(A) and K%2 == 1:
A = list(reversed(sorted(A)))
m = 1
for i in range(K):
m = m*A[i]%MOD
print(m)
else:
m = 1
B = [(abs(a),a) for a in A]
B = list(reversed(sorted(B)))
lastNegative = 0
lastPositive = 1
hadPositive = False
for i in range(K):
a = B[i][1]
if a < 0:
if lastNegative == 0:
lastNegative = a
else:
m = m*lastNegative*a%MOD
lastNegative = 0
else:
if a > 0 and lastPositive != 1:
m = m*lastPositive%MOD
if a > 0:
lastPositive = a
hadPositive = True
else:
m=m*a%MOD
if lastNegative == 0:
print(m*lastPositive%MOD)
else:
nextNegative = 0
for i in range(K,N):
b = B[i][1]
if b < 0:
nextNegative = b
break
if nextNegative == 0:
m = m*B[K][1]
print(m*lastPositive%MOD)
else:
c1 = lastNegative*nextNegative
nextPositive = 0
k = K
while k < N:
a = B[k][1]
if a >=0:
nextPositive = a
break
k+=1
c2 = nextPositive*lastPositive
if not hadPositive: # This array contain some non-negative value. This means the result value could be positive. But if there were no positive values in the first K values sorted by the absolute value, use just next positive value instead of the last negative values.
m = m*nextPositive%MOD
print(m)
exit()
if c1 > c2:
m = m*lastNegative*nextNegative%MOD
print(m)
else:
m =m*nextPositive*lastPositive%MOD
print(m)
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
K = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, K, A)
if __name__ == '__main__':
main()
|
n, k = (int(x) for x in input().split())
A = list(int(x) for x in input().split())
MOD = 10**9 + 7
A.sort()
l = 0
r = n - 1
sign = 1 # 1 or -1
ans = 1
if k % 2 == 1:
ans = A[r]
r -= 1
k -= 1
if ans < 0:
sign = -1
while k:
x = A[l] * A[l + 1]
y = A[r] * A[r - 1]
if x * sign > y * sign:
ans *= x % MOD
ans %= MOD
l += 2
else:
ans *= y % MOD
ans %= MOD
r -= 2
k -= 2
print(ans)
| 1 | 9,418,240,051,892 | null | 112 | 112 |
import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
input = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**9)
#from functools import lru_cache
def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')
def main():
n=II()
A=[]
B=[]
for _ in range(n):
a,b=MI()
A.append(a)
B.append(b)
A.sort()
B.sort()
#print(A,B)
r=n//2
l=(n-1)//2
#print(l,r)
mi=A[l]+A[r]
ma=B[l]+B[r]
ans=(ma-mi)-(ma-mi)*(n%2)//2+1
print(ans)
if __name__ == "__main__":
main()
|
import statistics
n = int(input())
a = []
b = []
for i in range(n):
ai,bi = map(int, input().split())
a.append(ai)
b.append(bi)
ma = statistics.median(a)
mb = statistics.median(b)
if n % 2 == 1:
ans = mb - ma + 1
else:
ma = int(ma * 2)
mb = int(mb * 2)
ans = mb - ma + 1
print(ans)
| 1 | 17,357,903,459,342 | null | 137 | 137 |
N = int(input())
S,T=input().split()
retsu = ""
for i in range(0,N):
mozi = S[i]+T[i]
retsu += mozi
print(retsu)
|
N=int(input())
L=list(map(int,input().split()))
L.sort()
from bisect import bisect_left
ans = 0
for i1 in range(N-2):
for i2 in range(i1+1,N-1):
l1,l2 = L[i1],L[i2]
#th = bisect_left(L[i2+1:],l1+l2)
#print(l1,l2,L[i2+1:],(l2-l1+1)*(-1),th)
th = bisect_left(L,l1+l2)
ans += max(th-i2-1,0)
print(ans)
| 0 | null | 142,165,122,326,012 | 255 | 294 |
class dice:
def __init__(self, X):
self.x = [0] * 6
self.x[0] = X[0]
self.x[1] = X[1]
self.x[2] = X[2]
self.x[3] = X[3]
self.x[4] = X[4]
self.x[5] = X[5]
def roll(self, d):
if d == 'S':
self.x[0], self.x[1], self.x[2], self.x[3], self.x[4], self.x[5] = \
self.x[4], self.x[0], self.x[2], self.x[3], self.x[5], self.x[1]
elif d == 'E':
self.x[0], self.x[1], self.x[2], self.x[3], self.x[4], self.x[5] = \
self.x[3], self.x[1], self.x[0], self.x[5], self.x[4], self.x[2]
elif d == 'W':
self.x[0], self.x[1], self.x[2], self.x[3], self.x[4], self.x[5] = \
self.x[2], self.x[1], self.x[5], self.x[0], self.x[4], self.x[3]
elif d == 'N':
self.x[0], self.x[1], self.x[2], self.x[3], self.x[4], self.x[5] = \
self.x[1], self.x[5], self.x[2], self.x[3], self.x[0], self.x[4]
X = list(map(int, input().split()))
directions = list(input())
d_one = dice(X)
for dist in directions:
d_one.roll(dist)
print(d_one.x[0])
|
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)
# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
return [ int(s) for s in input().split(" ")]
# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
return [ int(input()) for _ in range(n)]
# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
return map(int, open(0).read().split())
def log(*args):
print("DEBUG:", *args, file=sys.stderr)
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])
return arr
n,k = get_nums_l()
MOD = 10**9+7
ans = 0
count = [0] * (k+1)
for x in range(k, 0, -1):
count[x] = pow((k//x),n,MOD)
for y in range(x*2, k+1, x):
count[x] -= count[y]
print(sum([ x*i for i,x in enumerate(count) ]) % MOD)
| 0 | null | 18,357,910,319,320 | 33 | 176 |
tp = hp = 0
for i in range(int(input())):
taro, hana = map(list, input().split())
short = min(len(taro), len(hana))
result = 0
for k in range(short):
if ord(taro[k]) != ord(hana[k]):
result = ord(taro[k]) - ord(hana[k])
break
if not result:
if len(taro) < len(hana):
result = -1
elif len(taro) > len(hana):
result = 1
if result > 0:
tp += 3
elif result < 0:
hp += 3
else:
tp += 1
hp += 1
print(tp, hp)
|
n=int(input())
t=0
h=0
for i in range(n):
a,b=map(str,input().split())
if a<b:
h+=3
elif a>b:
t+=3
else:
t+=1
h+=1
print("{} {}".format(t,h))
| 1 | 2,008,826,340,752 | null | 67 | 67 |
# ????????°??¶???????????? s ???????????????????????????????¨????????????£?¶????????????????????????????????????§???????????? p ??????????????????????????????????????°??????
# ????????°??¶????????????s????¨??????\?????????????????????
s = list(input())
# ??????????±??????????p????¨??????\?????????????????????
p = list(input())
# ?????????s??????????????????????????????????????????s?????????s?????????
s = s + s
# print(s)
# ???????????????????????????????????????????????°
flag = 0
for i in range(len(s) // 2):
if s[i] == p[0]:
for j in range(len(p)):
if s[i + j] != p[j]:
break
if j == len(p) - 1:
flag = 1
if flag == 1:
print("Yes")
else:
print("No")
|
a=[s for s in input()]*2
b=input()
w=False
for j in range(len(a)):
if a[j]==b[0]:
total=1
if len(b)==1:
print("Yes")
w=True
break
for i in range(1,len(b)):
if j+i==len(a):
print("No")
w=True
break
else:
if a[j+i]==b[i]:
total+=1
if total==len(b):
print("Yes")
w=True
break
else:
break
if w==True:
break
if w==False:
print("No")
| 1 | 1,760,143,591,318 | null | 64 | 64 |
import sys
import bisect
def input():
return sys.stdin.readline().rstrip()
def main():
N = int(input())
A = []
B = []
for i in range(N):
a, b = map(int, input().split())
A.append(a)
B.append(b)
pass
A.sort()
B.sort()
if N % 2 == 0:
n = N // 2
mini = (A[n]+A[n-1]) /2
maxi = (B[n]+B[n-1]) /2
print(int((maxi-mini)*2)+1)
else:
n = N//2
mini = A[n]
maxi = B[n]
print(maxi-mini+1)
if __name__ == "__main__":
main()
|
n = int(input())
ls = []
rs = []
for _ in range(n):
x, y = map(int, input().split())
ls.append(x)
rs.append(y)
ls = sorted(ls)
rs = sorted(rs)
if n % 2 == 1:
print(rs[len(rs)//2] - ls[len(ls)//2] + 1)
else:
a = (rs[len(rs)//2-1] * 10 + rs[len(rs)//2] * 10) // 2
b = (ls[len(ls)//2-1] * 10 + ls[len(ls)//2] * 10) // 2
print((a - b) // 5 + 1)
| 1 | 17,172,348,227,570 | null | 137 | 137 |
def bubbles(N):
count = 0
for i in range(len(N)):
for j in range(len(N)-1, i, -1):
if N[j] < N[j-1]:
N[j], N[j-1] = N[j-1], N[j]
count += 1
c = 1
for i in N:
print(i, end='')
if c < len(N):
print(' ', end='')
c += 1
print('')
return count
n = int(input())
numbers = list(map(int, input().split()))
print(bubbles(numbers))
|
n = int(input())
a = list(map(int,input().split()))
cnt = 0
flag = 1
while flag > 0:
flag = 0
for j in range(n-1,0,-1):
if a[j] < a[j-1]:
tmp = a[j]
a[j] = a[j-1]
a[j-1] = tmp
flag = 1
cnt += 1
print(' '.join(map(str,a)))
print(cnt)
| 1 | 16,580,468,748 | null | 14 | 14 |
n = int(input())
S = list(map(int, input().split()))
SENTINEL = 10 ** 9 + 1
count = 0
def merge(S, left, mid, right):
L = S[left:mid] + [SENTINEL]
R = S[mid:right] + [SENTINEL]
i = j = 0
global count
for k in range(left, right):
if (L[i] <= R[j]):
S[k] = L[i]
i += 1
else:
S[k] = R[j]
j += 1
count += right - left
def mergeSort(S, left, right):
if(left + 1 < right):
mid = (left + right) // 2
mergeSort(S, left, mid)
mergeSort(S, mid, right)
merge(S, left, mid, right)
mergeSort(S, 0, n)
print(*S)
print(count)
|
S=input();N=len(S);print(sum(S[i]!=S[N-i-1] for i in range(N//2)))
| 0 | null | 60,184,672,395,132 | 26 | 261 |
# coding: utf-8
import math
#n, k, s = map(int,input().split())
n = int(input())
A = list(map(int,input().split()))
ans = 0
MOD=10**9+7
L0 = [0] * 60
L1 = [0] * 60
for i in range(n):
b = A[i]
#print(b)
b = format(b, '060b')
#print(b)
for j in range(60):
if b[60 - j -1] == "1":
L1[j] += 1
else:
L0[j] += 1
#print(L0)
#print(L1)
for i in range(60):
ans += L0[i] * L1[i] * 2**i
ans %= MOD
print(ans)
|
n=int(input())
x=list(map(int,input().split()))
x.sort()
ans,count=[],0
for i in range(x[0],x[-1]+1):
for j in x:
count+=(j-i)**2
ans.append(count)
count=0
print(min(ans))
| 0 | null | 94,433,369,692,718 | 263 | 213 |
x = int(input())
while x == 0:
x += 1
print(x)
exit(0)
while x == 1:
x -= 1
print(x)
exit(0)
|
r=input()
a=input()
if a in r+r:
print('Yes')
else:
print('No')
| 0 | null | 2,324,350,155,180 | 76 | 64 |
def read_int():
return int(input().strip())
def read_ints():
return list(map(int, input().strip().split(' ')))
def solve():
N = read_int()
L = read_ints()
L.sort()
answer = 0
for i in range(2, N):
for j in range(1, i):
start, end = -1, j
while end-start > 1:
mid = start+(end-start)//2
if L[i]-L[j] < L[mid]: # valid
end = mid
else:
start = mid
answer += j-end
return answer
if __name__ == '__main__':
print(solve())
|
n = int(input())
L = list(map(int,input().split()))
L.sort()
import bisect
ans = 0
for i in range(1,n):
for j in range(i+1,n):
tmp = L[:i]
v = L[j]-L[i]
idv = bisect.bisect_right(tmp,v)
if idv!=len(tmp):
ans += len(tmp)-idv
print(ans)
| 1 | 171,637,359,747,282 | null | 294 | 294 |
'''
Created on 2020/09/14
@author: harurun
'''
def yn(t):
if t:print("yes")
else:print("no")
return
def YN(t):
if t:print("YES")
else:print("NO")
return
def Yn(t):
if t:print("Yes")
else:print("No")
return
def main():
import sys
pin=sys.stdin.readline
pout=sys.stdout.write
perr=sys.stderr.write
x=int(pin())
if x==1:
print(0)
else:
print(1)
return
main()
|
print input()^1
| 1 | 2,969,729,978,590 | null | 76 | 76 |
# カウントと踏破フラグをもっておくと二度目の踏破でループの長さが分かりそう
n, k = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))
count_arr = [0] * n
count = 0
now = 0
loop_length = -1
while True:
if count == k:
print(now + 1)
exit()
if count_arr[now] != 0:
loop_length = count - count_arr[now] + 1
break
count += 1
count_arr[now] = count
now = a[now]
# 真の残り回数
rest = (k - count) % loop_length
# 既にゴールしてると見る場合
if rest == 0:
print(now + 1)
exit()
while rest > 0:
rest -= 1
if rest == 0:
break
now = a[now]
print(a[now] + 1)
# 727202214173249352
|
S = input()
if "AB" in S or "BA" in S:
print("Yes")
else:
print("No")
| 0 | null | 38,873,285,392,972 | 150 | 201 |
import math
A, B = [int(s) for s in input().split(' ')]
def lcm(x, y):
return (x * y) // math.gcd(x, y)
print(lcm(A, B))
|
a,b=map(int,input().split())
m=min(a,b)
kouyakusuu=1
for i in range(1,m+1):
if a%i==0 and b%i==0:
kouyakusuu=i
print(a*b//kouyakusuu)
| 1 | 113,157,978,871,520 | null | 256 | 256 |
import math
a = float(input())
print(2*a*math.pi)
|
n=int(input())
a=list(map(int,input().split()))
ans=0
a.sort()
num=a[-1]
dp=[True]*num
seen=[0]*num
for i in range(n):
num2=a[i]
if dp[num2-1]==True:
if seen[num2-1]==1:
dp[num2-1]=False
for j in range(2,num//num2+1):
dp[j*num2-1]=False
seen[a[i]-1]=1
ans=0
for i in range(n):
if dp[a[i]-1]==True:
ans+=1
print(ans)
| 0 | null | 22,762,429,944,576 | 167 | 129 |
# This code is generated by [Atcoder_base64](https://github.com/kyomukyomupurin/AtCoder_base64)
import base64
import subprocess
import zlib
exe_bin = "c$~#qeQaCR6~DIQ#Ay@9ZBv@IKs}bC7RYN%K1fz&#EzXlgA+<Vy3)11IJVO~aO~*$8It}1VWFs|O&6vK@y9lG+Wy!kZK6^&P2HrWO9x|OTA9Swt=rTgJ{+K;6{G4l8t>fq?tOmm`n|z4q}?b!@BH35=bn4+_jyl7V*O5s1F_;lUqpmktkw8liqCG=MF8tUweWijx*1giUuBTv>2-&hdh~iUy)LK5^Ymt9rVayjBl}XUGgE~8x*qX$s$N5<>is5qlGf{UoAsPj?<mzfO63_vRF6^CzAE}ZLUEpkk(pLey8A69NuKww)_9)U={*Q~)#%d~AEiUIKD)RqP=6U^{jeh~jdix~NGDs;QYJs$GTqhL(%CNLvclb}Pd+NUYj9MRC;iPrMcy}3jJ!WJaPhMDN4JLZ?=%j@!lw)3U8nv^Wb0A6-@u~N0h-iJ)c8VOU+(!DX0oC@1^;U;@SR}rHVb^zMqY4O<G0x0-?6cC)dt^!*hn*%`)us{Y~**^;F3+fwP1e@YC^p}P0L3+_F<&q53kYiCf4E5-#I0jxbsfZ$DIh{LzCGI&M9$O!5HD_$N)~J<kTT4r=;YOfxdJ$lNyPSrBm8F>o@xbhb1`|8Is^}SZPa085L8yq-+k4#dE3lXhu@PfyiSV9_Yx;WD@vsNtpm2l2SG@rkV(JVw}w>aw<NFrA#g*E71g?fy6{y#)=%5lw33si3|bO26m(bla7wykyacT?!>$AA8x~GD?j=)KZcd|L^iLGh$L7rAP$K~abn_8JRX-o87HRWIIg6oC51BMQYN034nw0cQKXTZj6;)m#iF4;e7Df9Kiw^KXwQ51;x?gO=r(eQ%p{lkUj=I+nF21gi=678RvhrO&Y_K$R`_p}q<S**_ERjsNvb7!<Bqbt1C`f>!js#bWTlm<yt4gk9#X?Bm1pY%TkjTEX>^*y7wA4R%i*(B-s3alj6dI?(P~s)H%Pf)z&!^1k^!$Z;6($z%79-n;HwSzbpu{!z}Y+@+e5tpXY+*MUITuT+NnY1HItO@8E}^Yf6;(f8StMNaO1wWXuyr@{;v#pjR6<u-uH;d+#l8Wk$7ZLahA@DbLTuusMPT+K&7q6;kRK+FFX-`f~YKCDnZ%$6~dDyET32T!-OYYvb?DBGT}*6mS0r)M+i@vuzXVG#|TecUtUo8eZY?|Fu#I(f}?>_aAb5CJoG2UV^v$X5qAsW=BB`6aS}Add8N5dobNg10pDMCpQzPZ7@JQvHx~DUz_D<1-I2v7l7WkX%P|o4sjp)5El+~Rd%lJ(uvrE!&n-E+_czx)(Gx3Nixoa7-Ugbn!rNlu<>Cg-NMm=n*_VHP?w5|a8?O9s&yYrm^Bt|w*!R{oY?(zGe+%$uoa%GWjcPwCdQ>NSuEO&f5-70x5?EVR{9vV23M`7pV$DrSv8_&RS-u_u@Bi|F;Qru&;K8NhPeEp3Txi(xwAN4aJ#Ub9LU$Dx;gxu-=RvS5&adC6l8$rg+jE{}8QzXB1TIGluN@Q%Z-{emUfDeon|D9rAXe%>)Qo)tq)O|rx&7$xY8(LC2!=+*dG{J(u=~1LcuUy`L*v(OZD`aVC|xT1b6|;#3X^|-bgPd1&P~j0Ujcpb?21b)ToKO}?-d;{iLb3FO<?djYOszNw6izca}~w|%I^^8dhP`UFbV$DL9-tLuK1f9rBYFZCcNZ+1>_t=UG0Ytm&Voh5b*=c;~=5&!7l~(L<@fijs_tXTTeLErnWo}bU0YJ5rwYb{+2oy&fahp-}x8<eB`p?4_sva#0vj}@ewY35G*zRS%fhocK;>+E(tj6vLIeE^w)<=bZ)7$Nn1w;v*@8z4xTr=cJ|VF_+6;#IM7CD&}pE}Kwkyg4*f&+-Xzfdz$?&_yMTWasN&GhNu)Rq4<X02&#}3##<Sq4@ey1-8-w1RhIwu+5A{)bANVmv1iZd}Z_|AZs~`8wqI);(yrZr8Hl|O`mU}_YxW1Bh5dU@q?k0mg<n^6!hP+MluCUjCyejD3_KZ8|ZJnzQdv`mRS9x0j33~k?0g@rFC%76;6|gQ6KcMXbF?zq(chIZVLhAe(sR!DVLYn=r68k4y5wCx~D&*aE+%0-rpQ#qTU2`=9-d@?;6;x{p8ER4Ysw(hr0_@lx4*!pZ?UVYxNO|M^#z@!E2eua#>7vf|pfKIMHd3DL%j~+w_VZ1YvVEA{t5_d@v{K3v`T`9a+iSMb&4}$Wi}XF)OOI3k*dE$M>3U=?Y_B^?_b1jjY$IUfmhD*^DBW9Q#=EM`e*0<tY|m%)--^s~|0-$ib5Ll7@)u}BOO$7RU7`GG`u-o3H}1`!Wzp}GT)Bxh;C4zoDeb3p52fQC^gk7L?%LJY_XYp9(Xo6+$@}jSI)v7iw!F#(o(Oaat?k=2^wZdMLA1LpCLuYyj#%O@q*&rr`nWXXZhbtO@oIhCn(-RFKh3yD9|vZ<Rv&L>e3d>f&G>44ewy(*^I=uT>(P`Y?nSefc!NIQ&A1Qkw#3)yc>^=P7M--j*Xiqr8E@3r4Ku#pa@@MmP5L}H<1njzR(SayYQ{HKU}U;ip{pexCwE*Y#Eq@10>y7vb(+x3TEDJON{5Y|UTWt`tr-tdymgfsAEo##hd)Z|o#yI2tUg!9^V`(UB4_7^s(fX?*!lmeD!&%JS;xPzmj9FbTRBcHt9B~;_nP{<uEPHshlcZhZgLPimE)mRy;p8PKCa(0PLju{94Ggv`HJ#5XVbgiCQp*L$@6>;5&81`a?_4^j@Wl@(APm$zGY+ol9S+-^YO<v^0HH_m*rL2neDud{ApFbay@yU`pL)bx{aMtr*)nu?bPDW$Jwd&OB0%1YsP1s8qU{y#A#jc4`_SO)A5|5_!*~lp6d5hzL&<6E$eSPt@BYI+tj<+Wo`cs8$9f?wu3@=R~9Q-d|zBj3yG;Igm=Xr2nAyp=kjAXs%36SGAP!Cv6PiEl7bSll2h{I<3a+Jb75GS#0iq~${~!CS$rs+9gC-NQpw6W9M4aqM0Rp2ol;Us;hxU!E^8r@K9X=;mg6%xl~LpwG%m*{Q#hHQoSXp_1BZz#CQ*$0hk^qU92pFgR2|+mIEo`81;y|X!r_Mog9Fh%cxO^hngKOsrN`lc{{G>}2p$QBViB;KO2(Bq!qErRd|U?SbE)JfC+&KBjfpLDri{L$=`aXOE{iAPnWQOkXk|dlyYcGg6kYi((Ha@(W6}96lZYnggzj?gkoTIzj)fPG<#O!VItR&XtNFx4F0c00e@?}gWyyfjv#ypF%Na^Ol$EJp+w`tQD%V^Y5^^(>N_-5cB5QPlJxLibIfaBwR!IrLP_#vfAEMl$OkNnvOX*~bltd~w5zkE^Avu!)dm2?_?agB;IVWW^CI-VhIhBqRLHab6R!Ef)Lh>ja%EAMTB=}WhCCFKIhzqF+I^8Cca+%XqwV9%6uxF?tJ}D*OK~;zDMFPzENtm2g3(tR7$UToNiEO>J`;NwngX2Gsw7V74=f6|=IeGqA9pLoY`JK_`PtYg#{%dfzV*2cy&*(Oav*S5`EFMJK-IM9F`v9X8w87*U?=a}Id*U8s{x-$#4U8V=0>;PhAkyxROrPB^7-jcR=0EqjP(3HE81&gagwcml*?%XhY(F_qRvGNE`wFA%e$2;@wf||VAEG?F*D%WN=S2S|3;h$w_>HcdpJ0^T<5}VRzrg92KLluGij((o^y{2HyH7F7$BQ$MzRBscb0MR@;O>_`Gpl~@GwQSRAfwzhqN4rZN9Os<&bN&6*EC-L6sK?Zz1U9w=bS#f7cwex1D=oPD@gn9!SXxh@5dU?$BU2u>+s)T&}a9G*?Q~xc>TX2E%thTN&h}i0ot%?PLKKZ0@B*g=ckS~X#Dgi)c-E0ub-!V=6ZO2R<2Nt>Feios@Thozg|xNBU(S7kYW1UIovAGXq6}JrTQ0W;K)AHf-2{Kt-*I=X`&Nf;$HIW=NcRRr)a`*g~NIMe*+LGoE`"
open("./kyomu", 'wb').write(zlib.decompress(base64.b85decode(exe_bin)))
subprocess.run(["chmod +x ./kyomu"], shell=True)
subprocess.run(["./kyomu"], shell=True)
|
def main():
H, _ = map(int, input().split())
A = map(int, input().split())
cond = sum(A) >= H
print('Yes' if cond else 'No')
if __name__ == '__main__':
main()
| 0 | null | 40,023,522,254,772 | 72 | 226 |
d, t, s = map(int, input().split())
dist = t * s - d
if dist >= 0:
print("Yes")
elif dist < 0:
print("No")
|
D,T,S=map(int,input().split())
print("Yes" if D<=T*S else "No")
| 1 | 3,523,440,525,490 | null | 81 | 81 |
H1, M1, H2, M2, K = map(int, input().split())
getUpTime = H1 * 60 + M1
goToBed = H2 * 60 + M2
DisposableTime = goToBed - getUpTime
if K > DisposableTime:
print(0)
else:
print(DisposableTime - K)
|
import collections
a=int(input())
b=list(map(int,input().split()))
c=collections.Counter(b)
n,m=zip(*c.most_common())
n,m=list(n),list(m)
result=0
for i in range(len(m)):
result+=(m[i]*(m[i]-1))//2
for i in b:
print(result-c[i]+1)
| 0 | null | 32,828,986,795,960 | 139 | 192 |
n = int(input())
A = list(map(int,input().split()))
data = [0]*3
ans = 1
mod = pow(10,9)+7
for i in A:
ans *= data.count(i)
ans %= mod
if ans == 0:
break
data[data.index(i)] += 1
print(ans)
|
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
n = int(readline())
a = list(map(int, readline().split()))
cnt = [0] * 3
ans = 1
for x in a:
p = cnt.count(x)
if p == 0:
return print(0)
ans *= p
ans %= MOD
cnt[cnt.index(x)] += 1
print(ans)
if __name__ == '__main__':
main()
| 1 | 130,556,045,004,162 | null | 268 | 268 |
r = int(input())
a = (44/7)*r
print(a)
|
r = int(input())
print(r * 3.1416 * 2)
| 1 | 31,152,606,809,180 | null | 167 | 167 |
h,m,H,M,K=map(int,input().split())
pre=60*h+m
post=60*H+M
print(post-pre-K)
|
def g(x):
S=format(x,"22b")
cnt=0
for i in range(20):
if S[-1-i]=="1":
cnt=cnt+1
return x%cnt
n=int(input())
X=input()
a=0
for i in range(n):
if X[i]=="1":
a=a+1
#最初に割るのは a-1 or a+1 -> a==0,1 に注意
if a==0:
for i in range(n):
print(1)
exit()
if a==1:
if X[-1]=="1":
for i in range(n-1):
print(2)
print(0)
exit()
else:
for i in range(n-1):
if X[i]=="1":
print(0)
else:
print(1)
print(2)
exit()
D=[0]*n
E=[0]*n
D[0]=1%(a-1)
E[0]=1%(a+1)
b=int(X[-1])%(a-1)
c=int(X[-1])%(a+1)
for i in range(n-1):
D[i+1]=(D[i]*2)%(a-1)
E[i+1]=(E[i]*2)%(a+1)
if X[-2-i]=="1":
b=(b+D[i+1])%(a-1)
c=(c+E[i+1])%(a+1)
for i in range(n):
if X[i]=="1":
x=(b+a-1-D[-1-i])%(a-1)
ans=1
while x!=0:
x=g(x)
ans=ans+1
print(ans)
else:
x=(c+E[-1-i])%(a+1)
ans=1
while x!=0:
x=g(x)
ans=ans+1
print(ans)
| 0 | null | 13,058,446,790,500 | 139 | 107 |
def koch(n, ax, ay, bx, by):
if n == 0:
return
th = math.pi * 60.0 / 180.0
xx = (2.0 * ax + bx)/3.0
xy = (2.0 * ay + by)/3.0
zx = (ax + 2.0 * bx)/3.0
zy = (ay + 2.0 * by)/3.0
yx = (zx - xx)*math.cos(th) - (zy - xy)*math.sin(th) + xx
yy = (zx - xx)*math.sin(th) + (zy - xy)*math.cos(th) + xy
koch(n-1, ax, ay, xx, xy)
print xx,xy
koch(n-1, xx, xy, yx, yy)
print yx,yy
koch(n-1, yx, yy, zx, zy)
print zx,zy
koch(n-1, zx, zy, bx, by)
import math
n = int(raw_input())
ax = 0.0
ay = 0.0
bx = 100.0
by = 0.0
print ax,ay
koch(n, ax, ay, bx, by)
print bx,by
|
import math
cos60=math.cos(math.radians(60))
sin60=math.sin(math.radians(60))
def koch(d,p1_x,p2_x,p1_y,p2_y):
if d==0:
return
s_x=(2*p1_x+1*p2_x)/3
s_y=(2*p1_y+1*p2_y)/3
t_x=(1*p1_x+2*p2_x)/3
t_y=(1*p1_y+2*p2_y)/3
u_x=(t_x-s_x)*cos60-(t_y-s_y)*sin60+s_x
u_y=(t_x-s_x)*sin60+(t_y-s_y)*cos60+s_y
koch(d-1,p1_x,s_x,p1_y,s_y)
print(s_x,s_y)
koch(d-1,s_x,u_x,s_y,u_y)
print(u_x,u_y)
koch(d-1,u_x,t_x,u_y,t_y)
print(t_x,t_y)
koch(d-1,t_x,p2_x,t_y,p2_y)
d=int(input())
p1_y=0
p1_x=0
p2_x=100
p2_y=0
print(float(p1_x),float(p1_y))
koch(d,p1_x,p2_x,p1_y,p2_y)
print(float(p2_x),float(p2_y))
| 1 | 130,805,111,100 | null | 27 | 27 |
import sys
N=int(input())
A=list(map(int,input().split()))
M=10**9+7
G={k:0 for k in range(-1,max(A)+1)}
G[-1]=3
X=1
for a in A:
X*=G[a-1]-G[a]
X%=M
G[a]+=1
print(X)
|
from collections import *
from heapq import *
import sys
input=lambda :sys.stdin.readline().rstrip()
N=int(input())
A=list(map(int,input().split()))
mod=10**9+7
count=1
lst=[0,0,0]
for a in A:
data=[i for i in range(3) if lst[i] == a]
if not data:
count=0
break
count*=len(data)
count%=mod
i=data[0]
lst[i]+=1
print(count)
| 1 | 130,076,296,278,180 | null | 268 | 268 |
elements = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
th = K-1
print(elements[th])
|
n = '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51'
nn = n.split(', ')
nn = list(map(int, nn))
K = int(input())
print(nn[K-1])
| 1 | 49,940,233,885,948 | null | 195 | 195 |
import math
from collections import deque
N, D, A = list(map(int, input().split()))
data = []
for _ in range(N):
x, h = list(map(int, input().split()))
data.append((x, math.ceil(h/A)))
data = sorted(data, key=lambda x: x[0])
c = 0
damage_que = deque()
attack = 0 # 有効なダメージ合計
for i in range(N):
x, h = data[i]
# 爆破範囲が届いていなければ削除していく
while damage_que and x > damage_que[0][0]:
_, a = damage_que.popleft()
attack -= a
# 有効な過去の爆破攻撃を受ける
remain = max(h - attack, 0)
# 0になるまで爆破
attack += remain
c += remain
# 爆破回数追加
damage_que.append([x+2*D, remain])
print(c)
|
import numpy as np
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T1=input()
T2=T1.replace('r', str(P)+' ').replace('s',str(R)+' ').replace('p',str(S)+' ')[:-1]
T2=np.array(list(map(int, T2.split())))
for i in range(N):
if i >=K and T1[i]==T1[i-K] and T2[i-K] != 0:
T2[i]=0
print(T2.sum())
| 0 | null | 94,757,476,659,978 | 230 | 251 |
# -*- coding: utf-8 -*-
import sys
import os
import math
n = int(input())
p0 = (0, 0)
p1 = (100, 0)
def koch(depth, p0, p1):
if depth == 0:
return
# s = 2/3 p0 + 1/3 p1
sx = 2 / 3 * p0[0] + 1 / 3 * p1[0]
sy = 2 / 3 * p0[1] + 1 / 3 * p1[1]
s = (sx, sy)
tx = 1 / 3 * p0[0] + 2 / 3 * p1[0]
ty = 1 / 3 * p0[1] + 2 / 3 * p1[1]
t = (tx, ty)
theta = math.radians(60)
ux = math.cos(theta) * (tx - sx) - math.sin(theta) * (ty - sy) + sx
uy = math.sin(theta) * (tx - sx) + math.cos(theta) * (ty - sy) + sy
u = (ux, uy)
# ????????? s, u, t?????¨???
koch(depth - 1, p0, s)
print(*s)
koch(depth - 1, s, u)
print(*u)
koch(depth - 1, u, t)
print(*t)
koch(depth - 1, t, p1)
print(*p0)
koch(n, p0, p1)
print(*p1)
|
import itertools
def solve():
s, t = input().split()
return t+s
print(solve())
| 0 | null | 51,884,456,603,788 | 27 | 248 |
num = list(map(int,input().split()))
print("%d %d" % (num[0]*num[1],(num[0]+num[1])*2))
|
_, a = open(0)
mod = 10**9+7
c = 1
l = [3] + [0]*10**6
for a in a.split():
a = int(a)
c = c * l[a] % mod
l[a] -= 1
l[a+1] += 1
print(c)
| 0 | null | 64,932,289,367,008 | 36 | 268 |
def is_good(mid, key):
S = list(map(int, str(mid)))
N = len(S)
dp = [[[0] * 11 for _ in range(2)] for _ in range(N + 1)]
dp[1][1][10] = 1
for k in range(1, S[0]):
dp[1][1][k] = 1
dp[1][0][S[0]] = 1
for i in range(1, N):
for k in range(1, 11):
dp[i + 1][1][k] += dp[i][0][10] + dp[i][1][10]
for is_less in range(2):
for k in range(10):
for l in range(k - 1, k + 2):
if not 0 <= l <= 9 or (not is_less and l > S[i]):
continue
dp[i + 1][is_less or l < S[i]][l] += dp[i][is_less][k]
return sum(dp[N][0][k] + dp[N][1][k] for k in range(10)) >= key
def binary_search(bad, good, key):
while good - bad > 1:
mid = (bad + good) // 2
if is_good(mid, key):
good = mid
else:
bad = mid
return good
K = int(input())
print(binary_search(0, 3234566667, K))
|
import sys
def input(): return sys.stdin.readline().rstrip()
S = input()
if S == "ABC":
print("ARC")
else:
print("ABC")
| 0 | null | 32,097,968,670,998 | 181 | 153 |
n, u, v = map(int, input().split())
matrix = [[] for _ in range(n)]
import sys
sys.setrecursionlimit(10**8)
for _ in range(n-1):
a,b = map(int, input().split())
matrix[a-1].append(b-1)
matrix[b-1].append(a-1)
C = [0]*n
D = [0]*n
def dfs(x, pre, cnt, c):
c[x] = cnt
cnt += 1
for a in matrix[x]:
if a == pre:
continue
dfs(a, x, cnt, c)
dfs(v-1, -1, 0, C)
dfs(u-1, -1, 0, D)
ans=0
for i in range(n):
if C[i] > D[i]:
ans = max(ans, C[i]-1)
print(ans)
|
n,u,v=map(int,input().split())
tree=[[]for _ in range(n)]
for i in range(n-1):
a,b = map(int,input().split())
tree[a-1].append(b-1)
tree[b-1].append(a-1)
va=[-1]*n
q=[v-1]
va[v-1]=0
while q:
x=q.pop()
for j in tree[x]:
if va[j]==-1:
q.append(j)
va[j]=va[x]+1
q=[u-1]
vt=[-1]*n
vt[u-1]=0
ans=0
while q:
x=q.pop()
ans=max(ans,va[x])
for j in tree[x]:
if vt[j]==-1:
if vt[x]+1<va[j]:
q.append(j)
vt[j]=vt[x]+1
elif vt[x]+1==va[j]:
vt[j]=vt[x]+1
print(ans-1)
| 1 | 117,709,633,003,680 | null | 259 | 259 |
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
ans = 0
for i in range(1,N+1):
if i % 3 == 0 or i % 5 == 0:
continue
ans += i
print(ans)
|
n = int(input())
ans = sum(x for x in range(1, n+1) if x % 3 != 0 and x % 5 != 0)
print(ans)
| 1 | 34,864,892,030,682 | null | 173 | 173 |
import numpy
n = int(input())
l = []
ans = n
def is_prime(q):
q = abs(q)
if q == 2: return True
if q < 2 or q&1 == 0: return False
return pow(2, q-1, q) == 1
if is_prime(n) :
print(n-1)
if is_prime(n) == False:
for i in range(2,int(numpy.sqrt(n))+1):
if n%i == 0:
a = i
b = n//i
ans = min(n,a+b-2)
print(ans)
|
A,B = map(int,input().split())
print(max(A-B-B,0))
| 0 | null | 163,405,329,800,828 | 288 | 291 |
# Trick or Treat
N, K = map(int, input().split())
count = [0] * N
for _ in range(K):
d = int(input())
treat = list(map(int, input().split()))
for val in treat:
count[val-1] += 1
ans = 0
for i in range(N):
if count[i] == 0:
ans += 1
print(ans)
|
n, k = map(int, input().split())
have = [False]*n
for _ in range(k):
d = int(input())
A = list(map(int, input().split()))
for a in A:
have[a-1] = True
ans = 0
for i in range(n):
if have[i]==False:
ans += 1
print(ans)
| 1 | 24,741,053,314,340 | null | 154 | 154 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.