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
|
---|---|---|---|---|---|---|
# coding: utf-8
ring = input()
pattern = input()
ring *= 2
if pattern in ring:
print('Yes')
else:
print('No') | n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(0,n,2):
if a[i]&1:
ans+=1
print(ans) | 0 | null | 4,724,508,653,060 | 64 | 105 |
H,W=list(map(int,input().split()))
l=[list(input()) for i in range(H)]
inf=10**9
DP=[[inf]*W for i in range(H)]
DP[0][0]=0 if l[0][0]=="." else 1
for i in range(H):
for j in range(W):
if i>0:
DP[i][j]=min(DP[i][j],DP[i-1][j]+1) if l[i-1][j] == "." and l[i][j]=="#" else min(DP[i][j],DP[i-1][j])
if j>0:
DP[i][j]=min(DP[i][j],DP[i][j-1]+1) if l[i][j-1] == "." and l[i][j]=="#" else min(DP[i][j],DP[i][j-1])
print(DP[H-1][W-1]) | import sys
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()
XY=[LI() for _ in range(n)]
A=[]
B=[]
for x,y in XY:
A.append(x+y)
B.append(x-y)
A.sort()
B.sort()
a=A[-1]-A[0]
b=B[-1]-B[0]
print(max(a,b))
if __name__=="__main__":
main()
| 0 | null | 26,463,206,957,440 | 194 | 80 |
import sys
S = list(input())
lis = [0] * (len(S)+1)
if len(S) == 1:
print(1)
sys.exit()
#最初は < を処理する
for i in range(len(S)):
if S[i] == "<":
lis[i+1] = lis[i] + 1
for j in range(len(S)-1,-1,-1):
if S[j] == ">":
lis[j] = max(lis[j],lis[j+1] + 1)
print(sum(lis)) | n = int(input())
a_nums = list(map(int, input().split()))
money = 1000
stock = 0
for i in range(n):
if i != n - 1 and a_nums[i] < a_nums[i + 1]:
times = money // a_nums[i]
stock += times
money -= a_nums[i] * times
elif i == n - 1 or a_nums[i] > a_nums[i + 1]:
money += stock * a_nums[i]
stock = 0
print(money) | 0 | null | 81,967,540,811,300 | 285 | 103 |
r, g, b = list(map(int, input().split()))
k = int(input())
count = 0
while r >= g:
g *= 2
count += 1
while g >= b:
b *= 2
count += 1
if k >= count:
print('Yes')
else:
print('No') | R, G, B = map(int, input().split())
K = int(input())
cnt = 0
while not(R < G):
G *= 2
cnt += 1
while not(G < B):
B *= 2
cnt += 1
if cnt <= K:
print('Yes')
else:
print('No') | 1 | 6,895,483,706,078 | null | 101 | 101 |
card = []
for i in range(3):
row = list(map(int,input().split()))
card.append(row)
n = int(input())
ans = False
for i in range(n):
b = int(input())
for j in range(3):
if b in card[j]:
card[j][card[j].index(b)] = 0
def judge(lst):
return lst == [0,0,0]
for i in range(3):
ans |= judge(card[i])
for i in range(3):
ans |= judge([card[j][i] for j in range(3)])
ans |= judge([card[i][i] for i in range(3)])
ans |= judge([card[i][2-i] for i in range(3)])
print("Yes" if ans else "No") | A = []
for i in [0]*3:
A.append(list(map(int,input().split())))
N = int(input())
B = []
for i in [0]*N:
B.append(int(input()))
for b in B:
for i in range(3):
for j in range(3):
if A[i][j] == b:
A[i][j] = -1
#ヨコ
for i in range(3):
if A[i] == [-1,-1,-1]:
print("Yes")
exit()
#タテ
for i in range(3):
if [A[0][i],A[1][i],A[2][i]] == [-1,-1,-1]:
print("Yes")
exit()
#ナナメ
if [A[0][0],A[1][1],A[2][2]] == [-1,-1,-1]:
print("Yes")
exit()
if [A[0][2],A[1][1],A[2][0]] == [-1,-1,-1]:
print("Yes")
exit()
print("No")
| 1 | 60,001,416,605,880 | null | 207 | 207 |
x,y = map(int,input().split())
if (x+y)%3!=0:print(0);exit()
mod = 10**9+7
n = (x+y)//3
m = min(x-n,y-n)
frac = [1]*(n+1)
finv = [1]*(n+1)
for i in range(n):
frac[i+1] = (i+1)*frac[i]%mod
finv[-1] = pow(frac[-1],mod-2,mod)
for i in range(1,n+1):
finv[n-i] = finv[n-i+1]*(n-i+1)%mod
def nCr(n,r):
if n<0 or r<0 or n<r: return 0
r = min(r,n-r)
return frac[n]*finv[n-r]*finv[r]%mod
print(nCr(n,m)%mod) | mod = 10 ** 9 + 7
x, y = map(int, input().split())
if (x + y) % 3 != 0 or x * 2 < y or y * 2 < x:
print(0)
exit()
l = [1]
for i in range(1, (x + y) // 3 + 100):
l.append(l[-1] * i % mod)
def comb(n, r, m):
return l[n] * pow(l[r], m - 2, m) * pow(l[n - r], m - 2, m) % m
a, b = y - (x + y) // 3, x - (x + y) // 3
print(comb(a + b, a, mod) % mod) | 1 | 150,436,551,901,900 | null | 281 | 281 |
X,N = map(int, input().split())
P = list(map(int, input().split()))
table = [0] * 102
ans = X
dist = 102
for p in P:
table[p] = 1
for i in range(102):
if table[i] != 0:
continue
if abs(i - X) < dist:
ans = i
dist = abs(i - X)
elif abs(i - X) == dist:
ans = min(i, ans)
print(str(ans)) | list = []
while True:
n, x = map(int, input().split())
if n == x == 0:
break
cnt = 0
for a in range(1, n + 1):
for b in range(a + 1, n + 1):
for c in range(b + 1, n + 1):
if a + b + c == x:
cnt += 1
list.append(cnt)
for s in list:
print(s) | 0 | null | 7,685,655,496,128 | 128 | 58 |
t=input()
s1=[]
s2=[]
pond=[]
totalsum=0
for i in range(len(t)):
if t[i]=="\\" :
s1.append(i)
elif t[i]=="/" and len(s1)!=0:
p1=s1.pop()
sum=i-p1
totalsum+=sum
while len(s2)>0:
if s2[-1]>p1:
s2.pop()
sum+=pond.pop()
else:
break
pond.append(sum)
s2.append(i)
print(totalsum)
print(len(pond),*pond)
| # 全探索
n=int(input())
class People:
def __init__(self):
self.type=None
peoples=[People() for i in range(n+1)]
def change_10to2(i):
ans=format(i, '#0' + str(n + 3) + 'b')[2:]
return ans
def set_people_type(binary_list,peoples):
for i,people in enumerate(peoples):
if i!=0:
people.type=binary_list[i]
def get_statement():
shougen={}
for i in range(1,n+1):
ai=int(input())
ans=[]
for j in range(ai):
kumi=[int(k) for k in input().split()]
ans.append(kumi)
shougen[str(i)]=ans
return shougen
shougens=get_statement()
def shougen_dicide(peoples,shougens):
for i in range(1,n+1):
shougen=shougens[str(i)]
for shou in shougen:
people,type=shou
people=int(people)
type=str(type)
# 正直者のとき
if peoples[i].type=="1":
if peoples[people].type!=type:
return False
# #嘘つきのとき
# else:
# if peoples[people].type==type:
# return False
return True
ans=0
for i in range(2**n):
binary_list=change_10to2(i)
set_people_type(binary_list,peoples)
if shougen_dicide(peoples,shougens):
ans=max(ans,binary_list.count("1"))
print(ans)
| 0 | null | 60,910,657,205,518 | 21 | 262 |
n = int( raw_input( ) )
minv = int( raw_input( ) )
maxv = 0 - 1000000000
for j in range( n-1 ):
num = int( raw_input( ) )
diff = num - minv
if maxv < diff:
maxv = diff
if num < minv:
minv = num
print maxv | import sys
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]
def main():
a, b = MI()
L = sorted([a, b])
if L[0] == a:
ans = int(str(a)*b)
else:
ans = int(str(b)*a)
print(ans)
if __name__ == "__main__":
main() | 0 | null | 42,448,948,952,872 | 13 | 232 |
from fractions import gcd
def lcm(*args):
ans = 1
for x in args:
ans = ans * x // gcd(ans, x)
return ans
n, m = map(int, input().split())
a = [int(x) for x in input().split()]
def log(x):
ans = 0
while x % 2 == 0:
ans += 1
x //= 2
return ans
def solve(a):
tmp = None
for ta in a:
if tmp is None:
tmp = log(ta)
else:
if tmp == log(ta):
continue
else:
print(0)
return
l = lcm(*a)
print(m // (l//2) - m // l)
solve(a) | import sys
input = sys.stdin.readline
import bisect
import math
# 持っているビスケットを叩き、1枚増やす
# ビスケット A枚を 1円に交換する
# 1円をビスケット B枚に交換する
def main():
a, b, n = input_list()
x = min(b-1, n)
aa = math.floor((a*x)/b) - (a * math.floor(x/b))
print(aa)
def bi(num, a, b, x):
print((a * num) + (b * len(str(b))))
if (a * num) + (b * len(str(b))) <= x:
return False
return True
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
if __name__ == "__main__":
main()
| 0 | null | 64,888,164,912,480 | 247 | 161 |
li = []
for i in range(2):
a,b = map(int, input().split())
li.append(a)
if li[1] == li[0]+1:
print(1)
else:
print(0) | m1,_ = input().split()
m2,_ = input().split()
ans = 0
if m1 != m2:
ans = 1
print(ans) | 1 | 123,958,547,988,618 | null | 264 | 264 |
def gcd(x, y):
if x % y == 0:
return y
else:
return gcd(y, x % y)
x, y = map(int, input().split())
print(gcd(x, y))
| def gcm(x, y):
if x == 0:
return y
if y == 0:
return x
if x==y:
return x
if x>y:
return gcm(x%y,y)
else:
return gcm(y%x,x)
x, y = list(map(int, input().split()))
print(gcm(x, y))
| 1 | 7,697,381,902 | null | 11 | 11 |
N=int(input())
A=list(map(int,input().split()))
I=0
for a in A:
if a==I+1:
I+=1
if I==0:
print(-1)
else:
print(N-I)
| # coding: utf-8
def main():
N = int(input())
A = list(map(int, input().split()))
ans = -1
tmp = 1
flg = False
for a in A:
if a == tmp:
tmp += 1
flg = True
if flg:
ans = N - tmp + 1
print(ans)
if __name__ == "__main__":
main()
| 1 | 114,641,907,886,450 | null | 257 | 257 |
S = input()
length = len(S)
print('x' * length)
| N=int(input())
n500=N//500
n5=(N%500)//5
print(1000*n500+5*n5) | 0 | null | 57,492,370,960,920 | 221 | 185 |
N, K = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(K)]
# dpの高速化 => 累積和によって、O(N)で解く
dp = [0] * N
acc = [0]* (N+1)
dp[0], acc[1] = 1, 1
# acc[0] = 0
# acc[1] = dp[0]
# acc[2] = dp[0] + dp[1]
# acc[n] = dp[0] + dp[1] + dp[n-1]
# dp[0] = acc[1] - acc[0]
# dp[1] = acc[2] - acc[1]
# dp[n-1] = acc[n] - acc[n-1]
mod = 998244353
for i in range(1, N):
# acc[i] = dp[0] + ... + dp[i-1] が既知
# 貰うdp
for j in range(K):
r = i - X[j][0]
l = i - X[j][1]
if r < 0: continue
l = max(l, 0)
dp[i] += acc[r+1] - acc[l] # s = dp[L] + ... + dp[R]
dp[i] %= mod
acc[i+1] = acc[i] + dp[i] # acc[i+1] = dp[0] + ... + dp[i]
print(dp[N-1]) | from sys import stdin
import sys
sys.setrecursionlimit(10**7)
def main():
_in = [_.rstrip() for _ in stdin.readlines()]
N, K = list(map(int, _in[0].split(' '))) # type:list(int)
L_R_arr = []
for i in range(K):
_ = list(map(int, _in[i+1].split(' '))) # type:list(int)
L_R_arr.append(_)
# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
dp = [0] * N
sdp = [0] * (N+1)
dp[0] = 1
for i in range(N):
for L, R in L_R_arr:
right = max(0, i-L+1)
left = max(0, i-R)
dp[i] += sdp[right] - sdp[left]
else:
sdp[i+1] = (sdp[i] + dp[i]) % 998244353
ans = dp[-1] % 998244353
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
print(ans)
if __name__ == "__main__":
main()
| 1 | 2,712,926,343,400 | null | 74 | 74 |
g = int(input("")) # get
a = False
for i in range(1,10):
if (g % i == 0 and (g // i >= 1) and (g // i <= 9)):
a = True
print("Yes" if (a) else "No") | n = int(input())
A = list(map(int, input().split()))
B = [(i+1, A[i]) for i in range(n)]
B.sort(key=lambda x: x[1])
print (" ".join(list(map(str, [B[i][0] for i in range(n)])))) | 0 | null | 171,009,935,108,146 | 287 | 299 |
#D
N=int(input())
ans=0
D=[[0 for i in range(10)] for j in range(10)]
for i in range(1,10):
for j in range(1,10):
for k in range(1,N+1):
if str(i)==str(k)[0] and str(j)==str(k)[-1]:
D[i][j]+=1
for i in range(1,10):
for j in range(1,10):
ans+=D[i][j]*D[j][i]
print(ans) | N = int(input())
c = [[0]*10 for _ in range(10)]
for i in range(1, N+1):
end = i%10
head = int(str(i)[0])
c[head][end] += 1
ans = 0
for i in range(10):
for j in range(10):
ans += c[i][j]*c[j][i]
print(ans)
| 1 | 86,602,552,623,860 | null | 234 | 234 |
#!/usr/bin/env python3
def pow(N,R,mod):
ans = 1
i = 0
while((R>>i)>0):
if (R>>i)&1:
ans *= N
ans %= mod
N = (N*N)%mod
i += 1
return ans%mod
def main():
N,K = map(int,input().split())
li = [0 for _ in range(K)]
mod = 10**9+7
ans = 0
for i in range(K,0,-1):
mm = K//i
mm = pow(mm,N,mod)
for j in range(2,(K//i)+1):
mm -= li[i*j-1]
li[i-1] = mm
ans += (i*mm)%mod
ans %= mod
print(ans)
if __name__ == '__main__':
main()
| n,k = map(int,input().split())
mod = 10**9+7
"""
dp[i] := gcd(a1,...,an) = i となるものがいくつあるか
"""
dp = [0 for _ in range(k+1)]
subdp = [0 for _ in range(k+1)]
for i in range(1, k+1)[::-1]:
target = pow(k//i, n, mod)
for j in range(2*i, k+1, i):
target -= dp[j]
dp[i] = target
ans = 0
for i in range(k+1):
ans = (ans + dp[i]*i) % mod
print(ans) | 1 | 36,745,171,094,942 | null | 176 | 176 |
(L,R,d) = map(int, input().split())
out=int(R/d)-int(L/d)+1
if ( L%d == 0):
print (out)
else:
print(out-1) | L, R, d = map(int, input().split())
a = 0
for i in range(L,R+1):
if i%d==0:
a += 1
else:
a += 0
print(a) | 1 | 7,470,842,408,928 | null | 104 | 104 |
import sys,math
#DEBUG=True
DEBUG=False
if DEBUG:
f=open("202007_2nd/C_input.txt")
else:
f=sys.stdin
# Find the number of triples of integers (x,y,z) such that
# (x+y)**2 + (y+z)**2 + (x+z)**2 = 2*N
N=int(f.readline().strip())
ans=[0 for _ in range(N)]
I=int(math.sqrt(N))
for __ in range(I):
A2=N-((__+1)**2)
if A2<=0:
break
I2=int(math.sqrt(A2))
for ___ in range(I2):
A3=A2-((___+1)**2)
if A3<=0:
break
I3=int(math.sqrt(A3))
for ____ in range(I3):
tmp=((__+___+2)**2)+((___+____+2)**2)+((__+____+2)**2)
if tmp<=2*N:
ans[int(tmp/2)-1]+=1
else:
break
for _ in range(N):
print(ans[_])
f.close() | import sys
input = sys.stdin.readline
def log(*args):
print(*args, file=sys.stderr)
def main():
n = int(input().rstrip())
ans = [0 for _ in range(n)]
for x in range(1, 101):
for y in range(x, 101):
for z in range(y, 101):
tmp = pow(x, 2) + pow(y, 2) + pow(z, 2) + x * y + y * z + z * x
if tmp > n:
break
if x == y == z:
ans[tmp - 1] += 1
elif x == y or y == z or z == x:
ans[tmp - 1] += 3
else:
ans[tmp - 1] += 6
for v in ans:
print(v)
if __name__ == '__main__':
main()
| 1 | 7,950,987,748,272 | null | 106 | 106 |
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)
| n = int(input())
a = list(map(int,input().split()))
count = 0
for i in range(n):
minij =i
for j in range(i,n):
if a[j] < a[minij]:
minij = j
if a[i] > a[minij]:
count+=1
a[i],a[minij] = a[minij],a[i]
print(' '.join(map(str,a)))
print(count)
| 0 | null | 20,461,252,575,260 | 182 | 15 |
list = ["1", "1", "1", "2", "1", "2", "1", "5", "2", "2", "1", "5", "1", "2", "1", "14", "1", "5", "1", "5", "2", "2", "1", "15", "2", "2", "5", "4", "1", "4", "1", "51"]
K = input()
a = int(K)-1
print(list[a]) |
if __name__ == "__main__":
K = int(input())
num_ls = [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]
ret = num_ls[K-1]
print(ret)
| 1 | 49,771,181,492,638 | null | 195 | 195 |
#f = open("C:/Users/naoki/Desktop/Atcoder/input.txt")
N = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)
select_num = N//2
inf = -10e+100
Dp_f = [[inf] * (3) for _ in range(N+1)]
Dp_s = [[inf] * (3) for _ in range(N+1)]
# 3 次元はそれぞれStart~3つに該当
pre_margin = 0
for i in range(1,N+1):
Start = (i-1)//2
End = (i+1)//2
cur_margin = Start
for j in range(Start,End+1):
Dp_f[i][j-cur_margin] = max(Dp_s[i-1][j-pre_margin], Dp_f[i-1][j-pre_margin])
# [0] in 3rd dimension not chosen at last num
# must be transfered from [i-1]
for j in range(Start,End+1):
if j-1 == 0:
Dp_s[i][j-cur_margin] = 0 + A[i]
else:
Dp_s[i][j-cur_margin] = Dp_f[i-1][j-1-pre_margin]+A[i]
pre_margin = cur_margin
print(max(Dp_f[-1][select_num - cur_margin], Dp_s[-1][select_num - cur_margin]))
| def main():
INF = 10 ** 18
N = int(input())
A = list(map(int, input().split(' ')))
K = 1 + N % 2 # 余分な×を入れられる個数
# dp[i][j]: i個目までの要素で余分な×をj個使った際の最大値
dp = [[- INF for _ in range(K + 1)] for _ in range(N + 1)]
dp[0][0] = 0
for i in range(N):
for j in range(K + 1):
if j < K:
# 余分な×を使う場合
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j])
# 余分な×を使わない場合
now = dp[i][j]
if (i + j) % 2 == 0:
# 基本はi % 2 == 0の時にA[i]を足していく
# ただ、余分な×がj個入っていると、その分ずれる
now += A[i]
dp[i + 1][j] = max(dp[i + 1][j], now)
print(dp[N][K])
if __name__ == '__main__':
main()
| 1 | 37,515,205,041,620 | null | 177 | 177 |
S, T = map(str,input().split())
A, B = map(int,input().split())
U = str(input())
if S == U:
A -= 1
l = [A,B]
print(' '.join(map(str,l)))
elif T == U:
B -= 1
l = [A, B]
print(' '.join(map(str, l))) | def main():
S, T = input().split()
A, B = map(int, input().split())
U = input()
if U == S:
return " ".join(map(str, [A-1, B]))
else:
return " ".join(map(str, [A, B-1]))
if __name__ == '__main__':
print(main())
| 1 | 72,109,568,180,640 | null | 220 | 220 |
A, B, M = map(int, input().split())
an = list(map(int, input().split()))
bn = list(map(int, input().split()))
ans = min(an)+min(bn)
for i in range(M):
x, y, c = map(int, input().split())
ans = min(ans, an[x-1] + bn[y-1] - c)
print(ans)
| import itertools
line1 = input().split()
rei = input().split()
rei =list(map(int,rei))
den =input().split()
den =list(map(int,den))
cupon =[list(map(int,input().split())) for i in range(int(line1[2]))]
rei_mi = min(rei)
den_mi =min(den)
no_total =rei_mi +den_mi
for s in range(int(line1[2])):
yes_total =int(rei[cupon[s][0]-1]) +int(den[cupon[s][1]-1]) - cupon[s][2]
if no_total > yes_total:
no_total =yes_total
print(no_total)
| 1 | 54,281,352,153,952 | null | 200 | 200 |
from collections import deque
def BFS():
color=["white" for _ in range(h)]
D=[-1 for _ in range(h)]
M=[[] for _ in range(h)]
for i in range(h-1):
M[i].append(i+1)
M[i+1].append(i)
queue=deque([])
for i in line:
queue.append(i)
D[i]=i
color[i]="gray"
while len(queue)>0:
u=queue.popleft()
for i in M[u]:
if D[i]==-1 and color[i]=="white":
D[i]=D[u]
color[i]="gray"
queue.append(i)
return D
h,w,k=map(int,input().split())
S=[list(input()) for _ in range(h)]
M=[[0 for _ in range(w)] for _ in range(h)]
num,line=0,[]
for i in range(h):
if S[i].count("#")!=0:
p=num
for j in range(w):
if S[i][j]=="#":
num +=1
elif num==p:
M[i][j]=num+1
continue
M[i][j]=num
line.append(i)
D=BFS()
for i in range(h):
M[i]=M[D[i]]
for i in range(h):
print(*M[i]) | from sys import stdin
while True:
h, w = (int(n) for n in stdin.readline().rstrip().split())
if h == w == 0:
break
for cnt in range(h):
print(('#.' * ((w + 2) // 2))[cnt % 2: w + cnt % 2])
print()
| 0 | null | 72,648,632,731,168 | 277 | 51 |
i = 0
while True:
x = int(input()); i += 1
if x == 0:
break
print("Case {}: {}".format(i, x))
| n = int(input())
plus_bracket = []
minus_bracket = []
for _ in range(n):
mini = 0
cur = 0
for bracket in input():
if bracket == '(':
cur += 1
else:
cur -= 1
if cur < mini:
mini = cur
if cur > 0:
plus_bracket.append([-mini, cur])
else:
minus_bracket.append([cur - mini, -cur])
success = True
cur = 0
plus_bracket.sort()
minus_bracket.sort()
for bracket in plus_bracket:
if cur < bracket[0]:
success = False
break
cur += bracket[1]
back_cur = 0
for bracket in minus_bracket:
if back_cur < bracket[0]:
success = False
break
back_cur += bracket[1]
if cur != back_cur:
success = False
if success:
print('Yes')
else:
print('No') | 0 | null | 11,948,523,046,788 | 42 | 152 |
n = int(input())
c = list(input())
x = c.count("R")
ans = 0
for i in range(x):
if c[i] == "W":
ans += 1
print(ans) | X = int(input())
K = 1
while K > 0:
if X * K % 360 == 0:
print(K)
break
else:
K += 1
| 0 | null | 9,663,850,054,540 | 98 | 125 |
import heapq
N, D, A = map(int, input().split(" "))
proc_que = []
for _ in range(N):
x, h = map(int, input().split(" "))
heapq.heappush(proc_que, (x, h))
damaged = 0
ans = 0
while len(proc_que) > 0:
x, h = heapq.heappop(proc_que)
if h > 0:
# monster
num_bomb_use = max(0, (h - damaged + A - 1) // A)
ans += num_bomb_use
damaged += num_bomb_use * A
heapq.heappush(proc_que, (x + 2 * D + 1, -num_bomb_use * A))
else:
# damaged end
damaged += h
print(ans) | from bisect import bisect_right
N,D,A=map(int,input().split())
X,H=[None]*N,{}
for i in range(N):
X[i],H[X[i]]=map(int,input().split())
X.sort()
f=[0]*N
ans=i=0
while i<N:
if i>0:
f[i]+=f[i-1]
if f[i]*A<H[X[i]]:
k=-((f[i]*A-H[X[i]])//A)
f[i]+=k
ans+=k
j=bisect_right(X,X[i]+(D<<1))
if j<N:
f[j]-=k
i+=1
print(ans) | 1 | 82,227,354,480,116 | null | 230 | 230 |
# AtCoder Beginner Contest 146
# E - Rem of Sum is Num
# https://atcoder.jp/contests/abc146/tasks/abc146_e
from collections import defaultdict
N, K = map(int, input().split())
*A, = map(int, input().split())
A = [0]+A
d = []
c = defaultdict(int)
x = 0
ans = 0
for i, a in enumerate(A):
x += a - 1
x %= K
d.append(x)
if i-K >= 0:
c[d[i-K]] -= 1
ans += c[x]
c[x] += 1
print(ans) | import sys, os
import collections
MOD = 10 ** 9 + 7
def solve(input_stream):
N, K = read_ints(input_stream)
numbers = [int(i) - 1 for i in input_stream.readline().strip().split()]
cumulative_sum = [0 for i in range(N + 1)]
mods = {}
ans = 0
for index, number in enumerate(numbers):
cumulative_sum[index + 1] = (cumulative_sum[index] + number) % K
queue = []
for index in range(N+1):
if cumulative_sum[index] not in mods:
mods[cumulative_sum[index]] = 0
ans += mods[cumulative_sum[index]]
mods[cumulative_sum[index]] += 1
queue.append(cumulative_sum[index])
if len(queue) == K:
target = queue.pop(0)
mods[target] -= 1
return [str(ans)]
def read_ints(input_stream):
return [i for i in map(int, input_stream.readline().strip().split())]
def read_int(input_stream):
return int(input_stream.readline().strip())
if __name__ == "__main__":
outputs = solve(sys.stdin)
for line in outputs:
print(line) | 1 | 137,524,763,778,608 | null | 273 | 273 |
x,y=map(int,input().split())
k=[1,2,3]
l=[0,300000,200000,100000]
p=0
if x in k:
p+=l[x]
if y in k:
p+=l[y]
if x==1 and y==1:
p+=400000
print(p)
| class Combination:
def __init__(self, size, mod=10**9 + 7):
self.size = size + 2
self.mod = mod
self.fact = [1, 1] + [0] * size
self.factInv = [1, 1] + [0] * size
self.inv = [0, 1] + [0] * size
for i in range(2, self.size):
self.fact[i] = self.fact[i - 1] * i % self.mod
self.inv[i] = -self.inv[self.mod % i] * (self.mod // i) % self.mod
self.factInv[i] = self.factInv[i - 1] * self.inv[i] % self.mod
def npr(self, n, r):
if n < r or n < 0 or r < 0:
return 0
return self.fact[n] * self.factInv[n - r] % self.mod
def ncr(self, n, r):
if n < r or n < 0 or r < 0:
return 0
return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.mod) % self.mod
def nhr(self, n, r): # 重複組合せ
return self.ncr(n + r - 1, n - 1)
def factN(self, n):
if n < 0:
return 0
return self.fact[n]
N, K = map(int, input().split())
K = min(K, N)
MOD = 10**9 + 7
comb = Combination(N + 100)
ans = 0
for k in range(K + 1):
ans += comb.ncr(N, k) * comb.nhr(N - k, k)
ans %= MOD
print(ans)
| 0 | null | 104,130,242,417,240 | 275 | 215 |
import math
a,b,x = map(int,input().split())
if x <= a*a*b/2:
print(math.atan((a*b*b/2/x))*180/math.pi)
else:
print(math.atan((a*a*b-x)/(a**3)*2)*180/math.pi) | import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
#from collections import defaultdict
def main():
n = int(input())
s = tuple(map(int, tuple(input())))
num_pos = [] # 各数字がs中に最後にあらわれる位置。
for num in range(10):
if num in s:
num_pos.append(n - s[::-1].index(num) - 1)
unique_num = [0] * n # sの各桁でその桁以降にある数字の種類。
for i1 in range(n):
unique_num[i1] = sum([np >= i1 for np in num_pos])
unique_num.append(0)
r = 0
for keta1 in range(10):
if keta1 in s:
keta1_pos = s.index(keta1)
for keta2 in range(10):
if keta2 in s[keta1_pos + 1:]:
keta2_pos = s[keta1_pos + 1:].index(keta2) + keta1_pos + 1
r += unique_num[keta2_pos + 1]
print(r)
if __name__ == '__main__':
main() | 0 | null | 145,440,091,930,882 | 289 | 267 |
l = map(int, raw_input().split())
a, b, c = sorted(l)
print a, b, c | a = map(int, raw_input().split())
for i in range(len(a)):
point = a[i:].index(min(a[i:])) + i
temp = a[i];
a[i] = a[point]
a[point] = temp
print '%s %s %s' % (str(a[0]), str(a[1]), str(a[2])) | 1 | 416,318,418,792 | null | 40 | 40 |
def main():
s, t = input().split()
a, b = map(int, input().split())
u = input()
if u == s:
a -= 1
else:
b -= 1
print(a, b)
if __name__ == '__main__':
main() | s, t = input().split()
a, b = list(map(int, input().split()))
u = input()
if s == u:
print('{} {}'.format(a - 1, b))
else:
print('{} {}'.format(a, b - 1))
| 1 | 72,044,419,215,104 | null | 220 | 220 |
N = int(input())
A = list(map(int, input().split()))
ans = "APPROVED"
for n in range(N):
if A[n] % 2 == 1:
pass
elif A[n] % 3 == 0:
pass
elif A[n] % 5 == 0:
pass
else:
ans = "DENIED"
break
print(ans) | def main():
a=int(input())
print(a*(1+a+a*a))
main() | 0 | null | 39,725,901,866,880 | 217 | 115 |
L, R, d = map(int,input().split())
ans = 0
while L <= R:
if L % d == 0:
ans += 1
L += 1
print(ans) | a = input()
b, c, d = [int(x) for x in a.split()]
x = [x for x in range(b, c + 1) if x % d == 0]
print(len(x)) | 1 | 7,632,326,125,212 | null | 104 | 104 |
n,k=map(int,input().split())
L=[1]*n
for i in range(k):
d=int(input())
A=list(map(int,input().split()))
for a in A:
L[a-1] = 0
print(sum(L)) | n, k = map(int, input().split())
okashi = set()
for _ in range(k):
d = int(input())
lst = [int(i) for i in input().split()]
for i in range(d):
if lst[i] not in okashi:
okashi.add(lst[i])
count = 0
for i in range(n):
if i + 1 not in okashi:
count += 1
print(count) | 1 | 24,469,144,773,190 | null | 154 | 154 |
def solve():
H1, M1, H2, M2, K = map(int, input().split())
print((H2*60 + M2) - (H1*60 + M1) - K)
if __name__ == '__main__':
solve()
| import collections
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
query = []
for _ in range(Q):
query.append(tuple(map(int, input().split())))
dict_A = collections.Counter(A)
# print(dict_A)
ans = sum(A)
for i in range(Q):
if query[i][0] in dict_A.keys():
val = dict_A.pop(query[i][0])
if query[i][1] in dict_A.keys():
dict_A[query[i][1]] += val
else:
dict_A[query[i][1]] = val
ans = ans - (val*query[i][0]) + (val*query[i][1])
print(ans)
| 0 | null | 15,069,868,794,188 | 139 | 122 |
N = int(input())
S = [int(s) for s in input().split()]
snt = 10 ** 9 + 1
cnt = 0
# L, R = [0] * 500000, [0] * 500000
def merge(S, N, left, mid, right):
global cnt
# N1 = mid - left
# N2 = right - mid
# for i in range(N1):
# L[i] = S[left + i]
# for i in range(N2):
# R[i] = S[mid + i]
# L[N1] = R[N2] = snt
L = S[left:mid] + [snt]
R = S[mid:right] + [snt]
i, j = 0, 0
for k in range(left, right):
cnt += 1
if L[i] <= R[j]:
S[k] = L[i]
i += 1
else:
S[k] = R[j]
j += 1
def merge_sort(S, N, left, right):
if left + 1 < right:
mid = int((left + right) / 2)
merge_sort(S, N, left, mid)
merge_sort(S, N, mid, right)
merge(S, N, left, mid, right)
merge_sort(S, N, 0, N)
print(*S)
print(cnt)
| def merge(A,left,mid,right):
global cnt
L=A[left:mid]
R=A[mid:right]
L.append(float("inf"))
R.append(float("inf"))
i=0
j=0
for k in range(left, right):
cnt+=1
if L[i]<=R[j]:
A[k]=L[i]
i+=1
else:
A[k]=R[j]
j+=1
def mergeSort(A,left,right):
if left+1<right:
mid=(left+right)//2
mergeSort(A,left,mid)
mergeSort(A,mid,right)
merge(A,left,mid,right)
n = int(input())
S=list(map(int,input().split()))
cnt=0
mergeSort(S,0,n)
print(" ".join(map(str,S)))
print(cnt) | 1 | 112,490,457,510 | null | 26 | 26 |
s = str(input())
ans = "No"
for i in range(2):
if(s[i]!=s[i+1]):
ans = "Yes"
print(ans) | print('Yes') if len(set(input()))==2 else\
print('No') | 1 | 54,909,934,309,780 | null | 201 | 201 |
import sys
input = sys.stdin.readline
N, P = map(int, input().split())
S = list(input().rstrip())
if P in {2, 5}:
ans = 0
for i, s in enumerate(S):
if int(s) % P == 0:
ans += i+1
else:
ans = 0
T = [0]*P
T[0] = 1
tmp = 0
k = 1
for s in reversed(S):
tmp = (tmp + k * int(s)) % P
k = k * 10 % P
ans += T[tmp]
T[tmp] += 1
print(ans) | from collections import defaultdict
def main():
N, P = map(int, input().split())
S = list(map(int,list(input())))
S_mod = [0] * N
if P == 2:
for i in range(N-1,-1,-1):
if S[i] % 2 == 0:
S_mod[i] = 1
S_mod.reverse()
ans = 0
cnt = 0
for i in range(N):
if S_mod[i] == 1:
cnt += 1
ans += cnt
else:
ans += cnt
print(ans)
exit()
if P == 5:
for i in range(N-1,-1,-1):
if S[i] % 5 == 0:
S_mod[i] = 1
S_mod.reverse()
ans = 0
cnt = 0
for i in range(N):
if S_mod[i] == 1:
cnt += 1
ans += cnt
else:
ans += cnt
print(ans)
exit()
ten = 1
for i in range(N-1,-1,-1):
S_mod[i] = (S[i] * ten) % P
ten *= 10
ten %= P
S_mod.reverse()
S_acc = [0] * (N+1)
for i in range(N):
S_acc[i+1] = (S_acc[i] + S_mod[i]) % P
d = defaultdict(int)
for i in range(N+1):
d[S_acc[i]] += 1
ans = 0
for i, j in d.items():
if j >= 2:
ans += (j * (j-1)) // 2
print(ans)
if __name__ == "__main__":
main() | 1 | 58,496,014,350,242 | null | 205 | 205 |
s = input()
if s[-1] == "s":
s += "e"
print(s + "s") | K = int(input())
A, B = map(int, input().split())
a, mod_a = divmod(A, K)
b, mod_b = divmod(B, K)
if mod_a == 0 or mod_b == 0:
print('OK')
exit()
if a == b:
print('NG')
else:
print('OK')
| 0 | null | 14,493,635,286,512 | 71 | 158 |
print "\n".join(['%dx%d=%d'%(x,y,x*y) for x in range(1,10) for y in range(1,10)]) | S = input()
T = input()
time = []
S_list = list(S)
T_list = list(T)
Len = (len(S))
listt = list(range(Len))
for ss in listt:
if S[ss] ==T[ss]:
None
else:
time.append(ss)
print(len(time))
| 0 | null | 5,303,526,425,758 | 1 | 116 |
import sys
def f(x):
p=0
cnt=0
for i in range(n-1,-1,-1):
while p<n and a[i]+a[p]<x:
p+=1
cnt+=n-p
return cnt
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
l,r=a[0]*2,a[n-1]*2
while True:
if r-l<=1:
if f(r)==m: md=r;break
else: md=l;break
md=(r+l)//2
k=f(md)
if k==m: break
elif k>m: l=md
else: r=md
p=0
cnt=0
ans=0
for q in range(n-1,-1,-1):
while p<n and a[q]+a[p]<=md:
p+=1
if p==n: break
cnt+=n-p
ans+=a[q]*(n-p)*2
ans+=(m-cnt)*md
print(ans)
| #coding = utf-8
import math
a, b, c = map(float, raw_input().split())
h = b * math.sin(math.pi*c/180)
s = a * h / 2
x = math.sqrt(h**2 + (a-b*math.sin(math.pi*(90-c)/180))**2)
l = a + b + x
#print "%.8f, %.8f, %.8f" % (s, l, h)
print "\n".join([str(s), str(l), str(h)])
#print "%.1f, %.1f, %.1f" % (s, l, h) | 0 | null | 53,840,221,056,658 | 252 | 30 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *
N = INT()
ab = [LIST() for _ in range(N-1)]
graph = [[] for _ in range(N)]
for a, b in ab:
graph[a-1].append(b-1)
graph[b-1].append(a-1)
length = [len(x) for x in graph]
ans = max(length)
color = defaultdict(int)
q = deque([])
cnt = 1
for x in graph[0]:
q.append((x, 0, cnt))
cnt += 1
while q:
n, previous, col = q.popleft()
cnt = 1
for x in graph[n]:
if x == previous:
color[(n, x)] = col
color[(x, n)] = col
else:
if cnt == col:
cnt += 1
color[(n, x)] = cnt
color[(x, n)] = cnt
q.append((x, n, cnt))
cnt += 1
print(ans)
for a,b in ab:
print(color[(a-1, b-1)])
| def make_divisors(n: int):
lower_divs = []
upper_divs = []
i = 1
while i**2 <= n:
if n % i == 0:
lower_divs.append(i)
if i != n // i:
upper_divs.append(n // i)
i += 1
return lower_divs + upper_divs[::-1]
n = int(input())
ans = len(make_divisors(n - 1)) - 1
for x in make_divisors(n)[1:]:
if x == 1:
continue
z = n
while z % x == 0:
z = z // x
z = z % x
if z == 1:
ans += 1
print(ans)
| 0 | null | 89,043,852,854,290 | 272 | 183 |
from math import pi
r = float(input())
z = r*r*pi
l = 2*r*pi
print('{} {}'.format(z,l)) | import sys
read = sys.stdin.read
INF = 1 << 60
def main():
H, N, *AB = map(int, read().split())
dp = [INF] * (H + 1)
dp[0] = 0
for a, b in zip(*[iter(AB)] * 2):
for i in range(H + 1):
if i >= a:
if dp[i] > dp[i - a] + b:
dp[i] = dp[i - a] + b
else:
if dp[i] > dp[0] + b:
dp[i] = dp[0] + b
print(dp[H])
return
if __name__ == '__main__':
main()
| 0 | null | 40,853,628,083,950 | 46 | 229 |
S = input()
a = "RRR"
b = "RR"
c = "R"
if a == S:
print(3)
elif b in S:
print(2)
elif c in S:
print(1)
else:
print(0) | a = input()
print(a[0] + a[1] + a[2]) | 0 | null | 9,910,876,579,890 | 90 | 130 |
n = int(input())
a = list(map(int, input().split()))
q = int(input())
sums = sum(a)
d = {}
for i in a:
if i in d:
d[i] += 1
else:
d[i] = 1
for i in range(q):
b,c = map(int, input().split())
if b in d:
sums += d[b]*(c-b)
if c in d:
d[c] += d[b]
else:
d[c] = d[b]
d[b] = 0
print(sums) | def main():
import sys
from collections import Counter
input = sys.stdin.readline
input()
a = Counter(map(int, input().split()))
ans = sum(k * v for k, v in a.items())
for _ in range(int(input())):
b, c = map(int, input().split())
if b in a:
ans += (c - b) * a[b]
print(ans)
a[c] = a[c] + a[b] if c in a else a[b]
del a[b]
else:
print(ans)
if __name__ == "__main__":
main() | 1 | 12,288,153,133,298 | null | 122 | 122 |
n,k = list(map(int,input().split()))
r,s,p = list(map(int,input().split()))
t = str(input())
t_list = []
for i in range(k):
t_list.append(t[i])
for i in range(k,n):
if t[i] != t_list[i-k] or t_list[i-k] == 'all':
t_list.append(t[i])
else:
t_list.append('all')
print(t_list.count('r') * p + t_list.count('s') * r + t_list.count('p') * s)
| N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
T_split = [[] for i in range(K)]
for i in range(N):
T_split[i%K].append(T[i])
#print(T_split)
ans = 0
flag = 0
for i in range(len(T_split)):
for j in range(len(T_split[i])):
if flag == 1:
flag = 0
continue
if T_split[i][j] == 'r':
point = P
elif T_split[i][j] == 's':
point = R
elif T_split[i][j] == 'p':
point = S
ans += point
if j != len(T_split[i]) - 1:
if T_split[i][j] == T_split[i][j+1]:
flag = 1
print(ans)
| 1 | 106,365,699,781,900 | null | 251 | 251 |
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() | #!/usr/bin/env python
#coding: UTF-8
while True:
h,w = map(int,raw_input().split())
if h+w==0:
break
else:
print w*'#'# ??????####
for hight in range(h-2):
print '#'+(w-2)*'.'+'#'
print w*'#'#????????????####
print | 1 | 824,374,630,688 | null | 50 | 50 |
n = int(input())
brackets_plus = []
brackets_minus = []
right = 0
left = 0
for i in range(n):
s = input()
cur = 0
m = 0
for j in range(len(s)):
if s[j] == "(":
left += 1
cur += 1
else:
right += 1
cur -= 1
m = min(m,cur)
if cur >= 0:
brackets_plus.append((m,cur))
else:
brackets_minus.append((m,cur,m-cur))
if right != left:
print("No")
exit()
cur = 0
brackets_plus.sort(reverse = True)
for i in brackets_plus:
if i[0] + cur < 0:
print("No")
exit()
cur += i[1]
brackets_minus.sort(key = lambda x:x[2])
for i in brackets_minus:
if i[0] + cur < 0:
print("No")
exit()
cur += i[1]
print("Yes") | import sys
input = sys.stdin.readline
# up_list = []
# down_list = []
def count_scan(s):
max_min = 0
compare = 0
for c in s:
if c == '(':
compare += 1
elif c == ')':
compare -= 1
max_min = min(max_min, compare)
return min(max_min, compare), compare
def key(lst):
m, c = lst
if c > 0:
return 1, m
else:
return -1, c - m
def main():
n = int(input())
lst = [input() for _ in range(n)]
# up_list.sort(key=lambda x: x[1], reverse=True)
# down_list.sort(key=lambda x: x[1], reverse=False)
txt = 'No'
ans = 0
# print(lst)
# print(sorted([count_scan(lst) for i in lst],
# reverse=True,
# key=key))
for max_min, c in sorted([count_scan(s) for s in lst],
reverse=True,
key=key):
# print(f"{max_min = }, {c = }, {ans = }")
if max_min + ans < 0:
break
ans += c
else:
if ans == 0:
txt = 'Yes'
print(txt)
if __name__ == '__main__':
main() | 1 | 23,588,114,267,100 | null | 152 | 152 |
N, A, B = [int(_) for _ in input().split()]
mod = 10**9 + 7
c = [1, N]
for i in range(1, B + 1):
c += [c[-1] * (N - i) * pow(i + 1, mod - 2, mod) % mod]
ans = pow(2, N, mod) - c[A] - c[B] - 1
ans %= mod
print(ans)
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def com_once(n, r, MOD):
if n < r or n < 0 or r < 0:
return 0
r = min(r, n - r)
numer = denom = 1
for i in range(r):
numer = numer * (n - i) % MOD
denom = denom * (i + 1) % MOD
return numer * pow(denom, MOD - 2, MOD) % MOD
def main():
n, a, b = map(int, read().split())
ans = (pow(2, n, MOD) - com_once(n, a, MOD) - com_once(n, b, MOD) - 1) % MOD
print(ans)
return
if __name__ == '__main__':
main()
| 1 | 66,257,486,492,732 | null | 214 | 214 |
A,B = map(int,input().split())
if A <= 2*B:
x = 0
else: x = A - 2*B
print(x) | n = int(input())
alphabet = [chr(i) for i in range(97, 97+26)]
ans = ""
i = 0
# 次26**iを引いたらマイナスになるよ、というところで抜ける
while n - 26**i >= 0:
n -= 26**i
i += 1
# ここを抜けた時,iは桁数、nは「i桁の中でn番目」を表す
# したからk番目は、26**kで割った余り(に対応するアルファベット)
# 「上の桁で表現しきれなかった数」=「その桁での表現」
# これ、10進法をn進法に変換するアルゴリズムの正当性の説明を適用するとしっかりわかるわ!
for _ in range(i):
q,r = divmod(n,26)
n = q
ans += alphabet[r]
print(ans[::-1]) | 0 | null | 89,597,476,649,812 | 291 | 121 |
a = []
while True:
b = list(map(int,input().split()))
if b[0] == 0 and b[1]==0:
break
b.sort()
a.append(b)
for i in a:
print(i[0],i[1]) | while 1:
a,b=map(int,input().split())
if a+b==0:
break
elif a>b:
print(b,a)
continue
print(a,b) | 1 | 523,603,187,426 | null | 43 | 43 |
n = int(input())
a = [int(s) for s in input().split()]
ans = 0
for i in range(len(a)):
if i % 2 == 0 and a[i] % 2 == 1:
ans += 1
print(ans) | import sys
readline = sys.stdin.readline
N = int(readline())
ans = 0
for a in list(map(int,readline().split()))[::2]:
ans += (a & 1)
print(ans) | 1 | 7,804,306,861,168 | null | 105 | 105 |
def composite(d,n,s):
for a in (2,3,5,7):
probably_prime = False
if pow(a,d,n) == 1:
continue
for i in range(s):
if pow(a, 2**i * d, n) == n-1:
probably_prime = True
break
return not probably_prime
return False
def is_prime(n):
if n == 2:
return True
elif n % 2 == 0:
return False
else:
d,s = n-1, 0
while not d%2:
d, s = d>>1, s+1
return not composite(d,n,s)
r = []
n = int(input())
for i in range(n):
n = int(input())
if is_prime(n):
if n not in r:
r.append(n)
print(len(r)) | X = int(input())
prime = []
for n in range(3, X, 2):
lim = int(n ** 0.5)
f = True
for p in prime:
if p > lim:
break
if n % p == 0:
f = False
break
if f:
prime.append(n)
if X >= 3:
prime = [2] + prime
for n in range(X, X+10**5):
for p in prime:
if n % p == 0:
break
else:
print(n)
break | 0 | null | 52,740,139,263,550 | 12 | 250 |
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15
def main():
K = int(input())
S = input()
M = len(S)
N = M + K
MAXN = N + 2
fact = [1]
for i in range(1,MAXN + 1):
fact.append(fact[-1]*i%MOD)
inv_fact = [-1] * (MAXN + 1)
inv_fact[-1] = pow(fact[-1],MOD - 2,MOD)
for i in range(MAXN - 1,-1,-1):
inv_fact[i] = inv_fact[i + 1]*(i + 1)%MOD
nck = lambda N,K: 0 if K > N or K < 0 else fact[N]*inv_fact[N - K]*inv_fact[K]%MOD
power25 = [1]
power26 = [1]
for i in range(N):
power25.append(power25[-1]*25%MOD)
power26.append(power26[-1]*26%MOD)
ans = 0
for i in range(M,N + 1):
ans += nck(i - 1,M - 1) * power25[i - M] * power26[N - i] % MOD
ans %= MOD
print(ans)
if __name__ == '__main__':
main() | N, M = map(int, input().split())
Pajew = [i for i in range(N)]
import sys
sys.setrecursionlimit(1000000)
def find(x, Pajew):
if Pajew[x] == x:
return x
else:
a = find(Pajew[x], Pajew)
Pajew[x] =a
return a
def unite(x, y):
x = find(x, Pajew)
y = find(y, Pajew)
if x != y:
Pajew[x] = y
for _ in range(M):
a, b = map(int, input().split())
unite(a-1, b-1)
grou = 0
for i in range(N):
if i == Pajew[i]:
grou +=1
print(grou-1) | 0 | null | 7,604,301,029,930 | 124 | 70 |
from collections import Counter
mod=998244353
n=int(input())
D=list(map(int,input().split()))
Count=Counter(D)
if D[0]!=0 or Count[0]!=1:print(0);exit()
ans=1
for i in range(1,max(D)+1):
ans *=Count[i-1]**Count[i]
ans %=mod
print(ans) | from collections import defaultdict
n = int(input())
d = list(map(int, input().split()))
cnt = defaultdict(int)
if d[0] != 0:
print(0)
else:
ans = 1
for i in range(n):
cnt[d[i]] += 1
for i in range(1, n):
ans = (ans * cnt[d[i] - 1] % 998244353)
print(ans) | 1 | 155,233,659,620,260 | null | 284 | 284 |
import math
a,b,C = map(float,input().split())
S = 1/2*a*b*math.sin(C*math.pi/180)
c = math.sqrt(a**2+b**2-2*a*b*math.cos(C*math.pi/180))
L = a+b+c
h = 2*S/a
print(format(S,'.8f'))
print(format(L,'.8f'))
print(format(h,'.8f'))
| #S, L, h
import math
a, b, C = map(int, input().split())
S = a*b*math.sin(C*math.pi/180)*(1/2)
L = a+b+math.sqrt(a*a+b*b-2*a*b*math.cos(C*math.pi/180))
h = 2*S/a
print('%.4f'% S)
print('%.4f'% L)
print('%.4f'% h) | 1 | 175,784,476,678 | null | 30 | 30 |
n,m = map(int, input().split())
matrix = []
vector = []
for i in range(n):
a = list(map(int, input().split()))
matrix.append(a)
for j in range(m):
vector.append(int(input()))
for k in range(n):
entry = 0
for l in range(m):
entry += (matrix[k][l] * vector[l])
print(entry)
| S = input()
result = ''
for _ in S:
result += 'x'
print(result) | 0 | null | 37,048,279,702,152 | 56 | 221 |
inputs = [int(d) for d in input().split()]
results = []
for i in (0, 1):
for j in (2, 3):
results.append(inputs[i] * inputs[j])
print(max(results))
| #!/usr/bin/env python
# coding: utf-8
# In[22]:
X = int(input())
# In[23]:
if -(-(X%100)//5) <= X//100:
print(1)
else:
print(0)
# In[ ]:
| 0 | null | 65,410,360,331,424 | 77 | 266 |
import math
x,k,d = map(int,input().split())
abs_x = abs(x)
max_len = math.ceil(abs_x/d)*d
min_len = max_len-d
if abs_x-k*d >= 0:
print(abs_x-k*d)
exit()
if (math.ceil(abs_x/d)-1)%2 == k%2:
print(abs(abs_x-min_len))
else:
print(abs(abs_x-max_len)) | import sys
from bisect import bisect_left,bisect_right
sys.setrecursionlimit(10**9)
INF=10**18
def input():
return sys.stdin.readline().rstrip()
def main():
N,M=map(int,input().split())
A=sorted(list(map(int,input().split())))
S=[0]*(N+1)
for i in range(N):
S[i+1]=S[i]+A[i]
def nibutan(ok,ng):
while abs(ok-ng) > 1:
mid = (ok + ng) // 2
if solve(mid):
ok = mid
else:
ng = mid
return ok
def solve(mid):
c=0
for i in range(N):
c+=N-bisect_left(A,mid-A[i])
if c>=M:
return True
else:
return False
x=nibutan(0,10**11)
ans=0
count=0
for i in range(N):
b_l=bisect_left(A,x-A[i])
count+=(N-b_l)
ans+=S[N]-S[b_l]+A[i]*(N-b_l)
if count==M:
print(ans)
else:
print(ans+(M-count)*x)
if __name__ == '__main__':
main()
| 0 | null | 56,471,071,843,670 | 92 | 252 |
n,k = map(int,input().split());
kk = n-k+2
a = [0]*kk
for i in range(kk):
ii = i + k
p = ii*(ii-1);
q = ii*(2*n+1-ii);
a[i] = (q//2)-(p//2)+1;
con = 0;
for v in range(kk):
con = (con+a[v]) % 1000000007;
print(con); | s=input()[::-1]
n=len(s)
cnts=[0]*2019
cnts[0]=1
num=0
for i in range(n):
num+=int(s[i])*pow(10,i,2019)
num%=2019
cnts[num]+=1
ans=0
for cnt in cnts:
ans+=cnt*(cnt-1)//2
print(ans)
| 0 | null | 32,032,739,900,292 | 170 | 166 |
n = int(input())
A = list(map(int, input().split()))
from collections import defaultdict
dic = defaultdict(int)
dic[0] = 3
ans = 1
mod = 1000000007
for a in A:
ans *= dic[a]
ans = ans % mod
dic[a] -= 1
dic[a+1] += 1
print(ans) | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
n = I()
a = LI()
ans = 1
cnt = [0] * (n+1)
for i in range(n):
if a[i] == 0:
ans *= 3 - cnt[0]
ans %= mod
else:
ans *= cnt[a[i]-1] - cnt[a[i]]
ans %= mod
cnt[a[i]] += 1
print(ans) | 1 | 129,837,862,674,310 | null | 268 | 268 |
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
d1 = T1 * (A1 - B1)
d2 = T2 * (A2 - B2)
if d1 > 0 and d1 + d2 > 0:
print(0)
elif d1 < 0 and d1 + d2 < 0:
print(0)
elif d1 + d2 == 0:
print("infinity")
else:
if d1 < 0:
d1 = -d1
d2 = -d2
ok = 0
ng = (d1 + d1) // (-d1 - d2) + 1
x = 0
while ok + 1 < ng:
mid = (ok + ng) // 2
s = mid * (d1 + d2)
if s + d1 > 0:
ok = mid
elif s + d1 == 0:
ok = mid
ng = ok + 1
x = -1
else:
ng = mid
print(ng * 2 - 1 + x) | import itertools
a=int(input())
b=list(map(int,input().split()))
c=list(map(int,input().split()))
n=sorted(b)
m=list(itertools.permutations(n))
m=[list(i) for i in m]
print(abs(m.index(b)-m.index(c))) | 0 | null | 115,505,566,384,548 | 269 | 246 |
counter = [0 for i in range(10**6+1)]
n = int(input())
a = sorted(list(map(int,input().split())))
for i in a:
counter[i] += 1
l = [0 for i in range(10**6+1)]
cou = 0
for i in range(n):
b = a[i]
if l[b]==0:
cou += 1
for j in range(b,10**6+1,b):
l[j] = 1
if counter[b]>=2:
cou -=1
print(cou) | #C - Count Order
#DFS
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
a = 0
b = 0
cnt = 0
def dfs(A):
global cnt
global a
global b
if len(A) == N:
cnt += 1
if A == P:
a = cnt
if A == Q:
b = cnt
return
for v in range(1,N+1):
if v in A:
continue
A.append(v)
dfs(A)
A.pop()
dfs([])
print(abs(a-b)) | 0 | null | 57,590,717,395,248 | 129 | 246 |
n = int(input())
mod = 10**9+7
def pow(n, num):
s = num
for i in range(1,n):
s = s*num%mod
return s
print((pow(n,10) - 2*pow(n,9) + pow(n,8))%mod)
| import math
n = int(input())
a = pow(10, n, 10**9+7)
b = pow(9, n, 10**9+7)
c = pow(9, n, 10**9+7)
d = pow(8, n, 10**9+7)
print((a-b-c+d) % (10**9+7)) | 1 | 3,128,275,486,912 | null | 78 | 78 |
n = int(raw_input())
intervals = [[u-l,u+l] for u,l in [map(int, raw_input().split()) for _ in range(n)] ]
intervals.sort(key = lambda x:x[1])
count = 1
i = 1
cur= intervals[0]
while(i < len(intervals)):
while(i < len(intervals) and cur[1] > intervals[i][0]): i += 1
if i < len(intervals):
cur = intervals[i]
count +=1
print count | import collections
N = int(input())
A_list = list(map(int, input().split()))
c = collections.Counter(A_list)
c_value_list = list(c.values())
#print(c_value_list)
ans = 0
for i in range(len(c_value_list)):
ans += c_value_list[i]*(c_value_list[i] - 1) // 2
for k in range(N):
ans_temp = ans - c[A_list[k]] + 1
print(ans_temp)
| 0 | null | 68,862,947,484,652 | 237 | 192 |
A, B, C = map(int, input().split())
print('Yes' if len(set([A, B, C]))==2 else 'No')
| n = int(input())
str_list = list(map(list,input().split(' ')))
ans_list = []
for i in range(n):
ans_list.append(str_list[0][i])
ans_list.append(str_list[1][i])
ans_str = ''.join(ans_list)
print(ans_str)
| 0 | null | 90,231,031,604,480 | 216 | 255 |
n, m = map(int, input().split())
a = (n - 1) // 2
d = 1
memo = set([])
cnt = 0
for i in range(m):
if (n - d in memo) or (2*d == n):
cnt += 1
d += 1
memo.add(d)
if cnt > 1 or a < 1 or a+d > n:
print(1/0)
print(a, a+d)
a -= 1
d += 2
| n, m = map(int, input().split())
def check_ans(list_pairs):
dict_people = {i: i for i in range(1, n+1)}
for i in range(n):
for k in range(m):
val1 = dict_people[list_pairs[k][0]]
val2 = dict_people[list_pairs[k][1]]
if val1>val2:
print(val2, val1, end=" / ")
else:
print(val1, val2, end=" / ")
print("")
for j in range(1, n+1):
dict_people[j] = (dict_people[j]+1)%n
if dict_people[j] == 0: dict_people[j] = n
ans = list()
if n%2 == 1:
for i in range(m):
node1 = (1-i)%n
if node1 == 0: node1 = n
node2 = 2+i
ans.append((node1, node2))
else:
distance = -1
node2 = 1
for i in range(m):
node1 = (1-i)%n
if node1 == 0: node1 = n
node2 = node2+1
distance += 2
if distance == n//2 or distance == n//2 + 1:
node2 += 1
ans.append((node1, node2))
[print(str(values[0])+" "+str(values[1])) for values in ans]
# check_ans(ans) | 1 | 28,568,778,268,318 | null | 162 | 162 |
L,R,d = [int(i) for i in input().split()]
ans = 0
for i in range(L,R+1):
if i%d == 0:
ans += 1
print(ans)
| l,r,d = map(int,input().split())
count = 0
for i in range(l,r + 1):
if i % d == 0:
count += 1
else:
pass
print(count) | 1 | 7,473,070,155,990 | null | 104 | 104 |
a,b,*cc = map(int, open(0).read().split())
if sum(cc) >= a:
print('Yes')
else:
print('No') | import sys
readline = sys.stdin.readline
def main():
N, X, M = map(int, readline().split())
P = N.bit_length()
pos = [[0] * M for _ in range(P)]
value = [[0] * M for _ in range(P)]
for r in range(M):
pos[0][r] = r * r % M
value[0][r] = r
for p in range(P - 1):
for r in range(M):
pos[p + 1][r] = pos[p][pos[p][r]]
value[p + 1][r] = value[p][r] + value[p][pos[p][r]]
ans = 0
cur = X
for p in range(P):
if N & (1 << p):
ans += value[p][cur]
cur = pos[p][cur]
print(ans)
return
if __name__ == '__main__':
main()
| 0 | null | 40,244,916,493,332 | 226 | 75 |
K,N=map(int,input().split())
A=[int(i) for i in input().split()]
dlist=[]
for i in range(1,N):
d=A[i]-A[i-1]
dlist.append(d)
dlist.append(A[0]+K-A[N-1])
print(K-max(dlist)) | N = int(input())
X = []
for i in range(N):
X.append(input().split())
S = input()
flg = False
ans = 0
for x in X:
if flg:
ans += int(x[1])
if S == x[0]:
flg = True
print(ans) | 0 | null | 69,975,257,470,528 | 186 | 243 |
def main():
TaroScore = HanaScore = 0
n = int(input())
for _ in range(n):
[Taro, Hana] = list(input().lower().split())
lenT = len(Taro)
lenH = len(Hana)
lenMin = min(lenT, lenH)
if Taro == Hana:
TaroScore += 1
HanaScore += 1
else:
for i in range(lenMin+1):
if Taro == '':
HanaScore += 3
break
elif Hana == '':
TaroScore += 3
break
elif ord(Taro[0]) > ord(Hana[0]):
TaroScore += 3
break
elif ord(Taro[0]) < ord(Hana[0]):
HanaScore += 3
break
else:
Taro = Taro[1:]
Hana = Hana[1:]
print(TaroScore, HanaScore)
if __name__ == '__main__':
main()
| n=int(input())
tp = 0
hp = 0
for _ in range(n):
taro,hanaco = input().split()
if taro == hanaco :
tp +=1
hp +=1
elif taro > hanaco :
tp += 3
else: hp += 3
print('{} {}'.format(tp,hp)) | 1 | 2,035,919,510,768 | null | 67 | 67 |
import math
A,B = map(int,input().split())
ans = 0
AT = 0.08
BT = 0.1
a = A/AT
b = B/BT
aPlus = (A+1)/AT
bPlus = (B+1)/BT
if a == b :
ans = a
elif a < b :
if aPlus <= b :
ans = -1
else :
ans = b
elif b < a :
if bPlus <= a :
ans = -1
else :
ans = a
# print(a,b)
# print(aPlus,bPlus)
print(math.ceil(ans)) | a,b=map(int,input().split())
a_s=a/0.08
a_t=(a+1)/0.08
b_s=b/0.1
b_t=(b+1)/0.1
a0=int(a_s)
a1=int(a_t)
b0=int(b_s)
b1=int(b_t)
if (a_s-a0)>0:
a0+=1
if (a_t-a1)<=0:
a1-=1
if (b_s-b0)>0:
b0+=1
if (b_t-b1)<=0:
b1-=1
lista=[i for i in range(a0,a1+1)]
listb=[i for i in range(b0,b1+1)]
ansl=[]
for j in range(len(lista)):
if lista[j] in listb:
ansl.append(lista[j])
if not ansl==[]:
ans=ansl[0]
print(ans)
else:
print(-1) | 1 | 56,572,553,110,930 | null | 203 | 203 |
from collections import Counter
from itertools import accumulate
N, K = map(int,input().split())
A = list(map(int,input().split()))
d = Counter()
A = [0] + list(accumulate(A))
A = [a % K for a in A]
ans = 0
for i in range(N+1):
ans += d[(A[i]-i) % K]
d[(A[i]-i) % K] += 1
if i-K+1 >= 0:
d[(A[i-K+1] - (i-K+1)) % K] -= 1
print(ans) | from itertools import product
n = int(input())
data = {}
for p in range(1, n+1):
a = int(input())
# 人p=1~の証言
data[p] = [list(map(int, input().split())) for _ in range(a)]
# パターン生成
ans = 0
for honest in product(range(2), repeat=n):
for p,hk in enumerate(honest, 1):
if hk == 1:
# 証言の矛盾をチェック
if not all([honest[x-1] == y for x,y in data[p]]):
break
else:
ans = max(ans, sum(honest))
print(ans) | 0 | null | 129,564,839,190,790 | 273 | 262 |
from sys import stdin
readline = stdin.readline
def i_input(): return int(readline().rstrip())
def i_map(): return map(int, readline().rstrip().split())
def i_list(): return list(i_map())
def main():
X, N = i_map()
if N == 0:
print(X)
exit()
P = i_list()
p = list(map(lambda x: abs(x - X), P))
p.sort()
for i, j in enumerate(p, 1):
if i // 2 != j:
ans = X - (i // 2)
if ans in P:
ans = X + (i // 2)
break
else:
if N % 2 == 1:
ans = X - ((N + 1) // 2)
else:
ans = X - (N // 2)
if ans in P:
ans = X + (N // 2)
print(ans)
if __name__ == "__main__":
main()
| A, B = map(int, input().split())
if A > 9 or B > 9:
ans = -1
else:
ans = A*B
print(ans)
| 0 | null | 85,812,041,750,954 | 128 | 286 |
import math
n=int(input())
s=0
for i in range(n):
a=int(input())
#b=int(a**0.5)
b=math.ceil(a**0.5)
#print(str(b), '??O')
if a==2:
s+=1
# print(str(a),'!!!!')
elif a%2==0 or a < 2:
continue
else:
j=3
c=0
while j <= b:
if a%j==0:
c+=1
break
j+=2
if c==0:
s+=1
"""
for j in range(3,b+1,2):
if a%j==0:
break
if j==b:
s+=1
print(str(a),'!!!!')
"""
print(s) | n=int(input())
a=list(map(int,input().split()))
ans=[]
p=0
for i in range(n):
p=p^a[i]
for i in range(n):
k=p^a[i]
ans.append(k)
print(*ans) | 0 | null | 6,180,485,350,940 | 12 | 123 |
s = input()
s = 'x'*len(s)
print(s)
| # -*- coding: utf-8 -*-
class Dice:
def __init__(self, n):
self.upper = n[0]
self.backward = n[1]
self.right = n[2]
self.left = n[3]
self.ahead = n[4]
self.bottom = n[5]
def roll_north(self):
self.upper, self.ahead, self.bottom, self.backward = self.backward, self.upper, self.ahead, self.bottom
def roll_south(self):
self.upper, self.ahead, self.bottom, self.backward = self.ahead, self.bottom, self.backward, self.upper
def roll_east(self):
self.upper, self.right, self.bottom, self.left = self.left, self.upper, self.right, self.bottom
def roll_west(self):
self.upper, self.right, self.bottom, self.left = self.right, self.bottom, self.left, self.upper
dice_info = Dice(list(map(int, input().split())))
order = list(input())
for i in range(len(order)):
if 'N' in order[i]:
dice_info.roll_north()
elif 'S' in order[i]:
dice_info.roll_south()
elif 'E' in order[i]:
dice_info.roll_east()
elif'W' in order[i]:
dice_info.roll_west()
print(dice_info.upper)
| 0 | null | 36,606,664,473,330 | 221 | 33 |
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
SA = [0]
SB = [0]
tmp_A, tmp_B = 0 ,0
for i in range(N):
tmp_A += A[i]
if tmp_A <= K:
SA.append(tmp_A)
else:
break
for i in range(M):
tmp_B += B[i]
if tmp_B <= K:
SB.append(tmp_B)
else:
break
ans = 0
cursol_B = len(SB) - 1
for i in range(len(SA)):
while SA[i] + SB[cursol_B] > K:
cursol_B -= 1
ans = max(ans, i + cursol_B)
print(ans) | N = int(input())
XY = []
for _ in range(N):
A = int(input())
xy = []
for _ in range(A):
x, y = map(int, input().split())
x -= 1
xy.append((x, y))
XY.append(xy)
ans = 0
for s in range(1<<N):
for i in range(N):
if s>>i&1:
for x, y in XY[i]:
if s>>x&1 != y:
break
else:
continue
break
else:
ans = max(ans, bin(s).count("1"))
print(ans)
| 0 | null | 66,042,331,471,200 | 117 | 262 |
import copy
n, k = map(int,input().split())
a = [0] + list(map(int,input().split()))
dist = [-1] * (n+1)
dist[1] = 0
cn = 1
d = 0
cycle = 0
while True:
d += 1
nn = a[cn]
if d == k:
ans = nn
break
if dist[nn] == -1:
dist[nn] = copy.deepcopy(d)
elif cycle == 0:
cycle = d - dist[nn]
k = (k - d) % cycle + d
if d == k:
ans = nn
break
cn = nn
print(ans) | a = [list(map(int, input().split())) for i in range(3)]
n =int(input())
for k in range(n):
b = int(input())
for i in range(3):
for j in range(3):
if a[i][j] == b:
a[i][j] = 0
row0 = a[0] == [0, 0, 0]
row1 = a[1] == [0, 0, 0]
row2 = a[2] == [0, 0, 0]
colum0 = [a[0][0], a[1][0], a[2][0]] == [0, 0, 0]
colum1 = [a[0][1], a[1][1], a[2][1]] == [0, 0, 0]
colum2 = [a[0][2], a[1][2], a[2][2]] == [0, 0, 0]
diag0 = [a[0][0], a[1][1], a[2][2]] == [0, 0, 0]
diag1 = [a[2][0], a[1][1], a[0][2]] == [0, 0, 0]
if row0 or row1 or row2 or colum0 or colum1 or colum2 or diag0 or diag1:
print('Yes')
break
else:
print('No') | 0 | null | 41,469,533,676,590 | 150 | 207 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')
INF = 10**9 + 7
def main():
N = in_n()
arms = [tuple()] * N
for i in range(N):
x, l = in_nn()
arms[i] = (x - l, x + l)
arms.sort(key=lambda x: x[1])
# print(arms)
r_max = -INF
count = 0
for i in range(N):
l, r = arms[i]
if r_max <= l:
r_max = r
count += 1
print(count)
if __name__ == '__main__':
main()
| N, *A = map(int, open(0).read().split())
X = [(x-l, x+l) for x, l in zip(*[iter(A)]*2)]
X.sort()
ans = 1
L, R = X[0]
for l, r in X[1:]:
if R <= l:
ans += 1
L = l
R = r
elif R > r:
R = r
print(ans)
| 1 | 90,023,405,946,472 | null | 237 | 237 |
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
if a[i]%2==0:
if (a[i]%3==0 or a[i]%5==0): pass
else: print('DENIED'); exit()
print('APPROVED') | print(int(not bool(int(input())))) | 0 | null | 35,804,501,881,720 | 217 | 76 |
s=input()
t=input()
for i in range(len(s)):
if s[i]!=t[i]:
print("No")
exit()
if len(t)==len(s)+1:
print("Yes")
| #!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import itertools
import math
import sys
INF = float('inf')
YES = "Yes" # type: str
NO = "No" # type: str
def solve(S: str, T: str):
return [NO, YES][len(S)+1 == len(T) and S == T[:-1]]
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
S = next(tokens) # type: str
T = next(tokens) # type: str
print(solve(S, T))
if __name__ == '__main__':
main()
| 1 | 21,449,175,090,970 | null | 147 | 147 |
from collections import deque
def dfs(q):
if len(q)==N:
print(''.join(q))
return
for i in range(min(26, ord(max(q))-ord('a')+2)):
q.append(alpha[i])
dfs(q)
q.pop()
N = int(input())
alpha = 'abcdefghijklmnopqrstuvwxyz'
dfs(deque(['a'])) | # パナソニック2020D
import sys
def write(x):
sys.stdout.write(x)
sys.stdout.write("\n")
from queue import deque
n = int(input())
q = deque([("a", "a")])
while True:
s, m = q.pop()
if len(s)==n:
write(s)
elif len(s)>=n+1:
break
for o in range(ord("a"), ord(m)+2):
if ord(m)<o:
m = chr(o)
q.appendleft((s + chr(o), m)) | 1 | 52,068,714,620,608 | null | 198 | 198 |
N = int(input())
xs, ys = [], []
for _ in range(N):
x, y = map(int, input().split())
xs.append(x)
ys.append(y)
U = [x + y for x, y in zip(xs, ys)]
V = [x - y for x, y in zip(xs, ys)]
ans = max([max(U) - min(U), max(V) - min(V)])
print(ans) | def main():
today = input().split()
tomo = input().split()
if today[0] == tomo[0]:
print(0)
else:
print(1)
if __name__ == '__main__':
main()
| 0 | null | 63,717,558,805,780 | 80 | 264 |
n, k = map(int, input().split())
ans = 0
a = []
for _ in range(n):
a.append(0)
for i in range(k):
d = int(input())
treat = list(map(int, input().split()))
for snuke in treat:
a[snuke-1] += 1
for j in range(n):
if a[j] == 0:
ans += 1
print(ans) | N,K=list(map(int,input().split()))
ans_=[0]*N
for k in range(0,2*K,2):
k_ = int(input())
A = list(map(int,input().split()))
for a in A:
ans_[a-1]+=1
ans=0
for a in ans_:
if a == 0:
ans+=1
print(ans) | 1 | 24,731,435,009,708 | null | 154 | 154 |
s = input()
t = input()
flag = True
for i in range(len(s)):
if s[i] != t[i]:
flag = False
if flag == True:
print("Yes")
else:
print("No")
| S = list(input())
T = list(input())
count = 0
for i in range(len(S)):
if S[i] != T[i]:
count += 1
break
if count == 0:
print("Yes")
else:
print("No") | 1 | 21,319,270,203,840 | null | 147 | 147 |
a=0
b=0
n=int(input())
for i in range(n):
x=input().split()
y=x[0]
z=x[1]
if y>z:a+=3
elif y<z:b+=3
else:
a+=1
b+=1
print(a,b) | n = int(input())
tp = hp = 0
while n:
t, h = input().split()
if t > h:
tp += 3
elif t < h:
hp += 3
else:
tp += 1
hp += 1
n -= 1
print(tp, hp) | 1 | 1,996,632,681,172 | null | 67 | 67 |
while True:
x = input()
if x == '-' :
break
m = int(input())
for i in range(m):
h = int(input())
y = x[0:h]
z = x[h:len(x)+1]
x = list(z+y)
x = ''.join(x)
print(x)
| while True:
n=input()
if n=='-':
break
else:
m=int(input())
for i in range(m):
h=int(input())
n=n[h:len(n)]+n[:h]
print(n)
| 1 | 1,879,798,609,832 | null | 66 | 66 |
n, a, b = map(int, input().split())
ans = 0
if (a - b) % 2 == 0:
ans = (b - a)// 2
else:
ans = min(a + (b - a - 1) // 2, n - b + (b - a + 1) // 2)
print(ans) | N,A,B=map(int,input().split())
if (B-A)%2==0:
ans =(B-A)//2
else:
if A-1 > N-B:
ans = N-B+1
A+=ans
ans+=(N-A)//2
else:
ans =A
B-=ans
ans+=(B-1)//2
print(ans)
| 1 | 109,614,594,822,410 | null | 253 | 253 |
from itertools import permutations
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
perm = list(permutations(p))
perm.sort()
a = perm.index(p)
b = perm.index(q)
print(abs(a- b))
| N = int(input())
print(N//2 + N % 2) | 0 | null | 79,981,865,109,482 | 246 | 206 |
import sys
input = sys.stdin.readline
h, w, kk = map(int, input().split())
ss = [[0 for _ in range(h)] for _ in range(w)]
for i in range(h):
for j, c in enumerate(list(input().strip())):
if c == '1':
ss[j][i] = 1
ans = 100000
for i in range(2 ** (h - 1)):
end = []
for j in range(h - 1):
if i & 2 ** j:
end.append(j + 1)
end.append(h)
start = [0]
for j in end:
start.append(j)
start.pop()
sums = [0] * len(start)
tans = len(start) - 1
imp = False
for j in range(w):
reset = False
for k, (s, e) in enumerate(zip(start, end)):
sums[k] += sum(ss[j][s:e])
if sums[k] > kk:
reset = True
break
if reset:
tans += 1
for k, (s, e) in enumerate(zip(start, end)):
sums[k] = sum(ss[j][s:e])
if sums[k] > kk:
imp = True
if imp:
break
if not imp:
ans = min(ans, tans)
print(ans)
| s = input()
output = s.islower()
if output == True:
print("a")
else:
print("A") | 0 | null | 30,043,355,801,248 | 193 | 119 |
N, M = map(int, input().split())
if N % 2 == 1:
for m in range(1, M + 1):
print(m, N - m + 1)
count = 1
if N % 2 == 0:
for m in range(1, M + 1):
if m <= (N // 2 - 1) // 2:
start = m
end = N // 2 - m
print(start, end)
else:
start = N // 2 + count
end = N - count + 1
print(start, end)
count += 1
| a = int(input())
if a >= 30:
print("Yes")
else:
print("No") | 0 | null | 17,101,886,169,728 | 162 | 95 |
n=int(input())
arr=list(map(int,input().strip().split()))
ans=[0]*n
for i in range(n):
ans[arr[i]-1]=i+1
print(*ans,sep=" ") | N=int(input())
A=map(int, input().split())
A=list(A)
ans= [0] * len(A)
for i,a in enumerate(A):
ans[a-1]= i+1
print(' '.join(map(str,ans)))
| 1 | 180,977,981,184,870 | null | 299 | 299 |
"""
入力例 1
11 3 2
ooxxxoxxxoo
->6
入力例 2
5 2 3
ooxoo
->1
->5
入力例 3
5 1 0
ooooo
->
入力例 4
16 4 3
ooxxoxoxxxoxoxxo
->11
->16
"""
n,k,c = map(int,input().split())
s = input()
r=[0]*n
l=[0]*n
ki=0
ci=100000
for i in range(n):
ci += 1
if s[i]=='x':
continue
if ci > c:
ci = 0
ki+=1
l[i]=ki
if ki == k:
break
ki=k
ci=100000
for i in range(n):
ci += 1
if s[n-1-i]=='x':
continue
if ci > c:
ci = 0
r[n-1-i]=ki
ki-=1
if ki == 0:
break
ret=[]
for i in range(n):
if r[i]==l[i] and r[i]!=0:
ret.append(i+1)
# print(l)
# print(r)
for i in range(len(ret)):
print(ret[i])
| 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)
| 1 | 40,427,348,305,862 | null | 182 | 182 |
S,W = map(int,input().split())
print(("safe","unsafe")[W >= S]) | from collections import Counter
def main():
n = int(input())
S = [input() for _ in range(n)]
S_c = Counter(S)
num = list(S_c.values()).count(max(list(S_c.values())))
anss = S_c.most_common()[:num]
for ans in sorted(anss):
print(ans[0])
if __name__ == '__main__':
main()
| 0 | null | 49,579,170,955,200 | 163 | 218 |
# -*- coding: utf-8 -*-
INF = 2**62-1
def read_int_n():
return list(map(int, input().split()))
def slv(N, M):
if N % 2 != 0:
ans = [(i+1, N-i) for i in range(M)]
else:
ans = [(i+1 +(1 if i+1 > N//4 else 0), N-i) for i in range(M)]
for a in ans:
print(*a)
def main():
N, M = read_int_n()
(slv(N, M))
if __name__ == '__main__':
main()
| def gcd(a,b):
if a%b==0:
return b
return gcd(b,a%b)
while True:
try:
a,b=sorted(map(int,input().split()))
except:
break
print(gcd(a,b),a//gcd(a,b)*b) | 0 | null | 14,324,497,097,712 | 162 | 5 |
k, n = map(int, input().split())
a = list(map(int, input().split()))
diff = []
for i in range(len(a)):
if (i == len(a) - 1):
distance = a[0] + (k - a[-1])
else:
tar2 = a[i + 1]
tar1 = a[i]
distance = tar2 - tar1
diff.append(distance)
# スタート位置を見つける
index = diff.index(max(diff))
ans = sum(diff) - max(diff)
print(ans)
# print(index)
# > 2なので、15~5は避ける。
# if (index == len(diff)):
| import bisect
from itertools import accumulate
N, M = map(int, input().split())
A = sorted(map(int, input().split()))
S = [0] + list(accumulate(A))
def calc(x):
_total = 0
_num = 0
for i in range(N):
j = bisect.bisect_left(A, x - A[i])
_num += N - j
_total += S[N] - S[j]
_total += A[i] * (N - j)
return _total, _num
left = 0
right = 200005
while right - left > 1:
center = (left + right) // 2
if calc(center)[1] >= M:
left = center
else:
right = center
total, num = calc(left)
ans = total
ans -= (num - M) * left
print(ans)
| 0 | null | 75,338,614,463,908 | 186 | 252 |
# from math import factorial
from sys import exit
n,m,k = map(int, input().split())
if m == 1:
if k == n-1:
print(1)
else:
print(0)
exit()
MOD = 998244353
ans = tmp = (m * (m-1) ** (n-1)) % MOD
for i in range(k):
tmp *= (n-1-i)
tmp %= MOD
tmp *= pow((m-1) * (i+1), -1, MOD)
ans += tmp
ans %= MOD
print(ans) | def main():
N, M, K = map(int, input().split())
MOD = 998244353
fac = [0] * 10 ** 6
inv = [0] * 10 ** 6
finv = [0] * 10 ** 6
def COM_init():
fac[0] = 1
fac[1] = 1
inv[1] = 1
finv[0] = 1
finv[1] = 1
for i in range(2, 2 * 10**5 +10):
fac[i] = fac[i-1] * i % MOD
inv[i] = -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[n-k] * finv[k] % MOD) % MOD
COM_init()
ans = 0
for i in range(K+1):
ans += M * pow(M-1, N-i-1, MOD) * COM(N-1, i)
ans %= MOD
print(ans)
if __name__ == "__main__":
main() | 1 | 23,221,482,006,600 | null | 151 | 151 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.