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
|
---|---|---|---|---|---|---|
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math
import random
J=10**19
###############################################################################\n=17
d,t,s=INPUT()
if d/s<=t:
print("Yes")
else:
print("No")
|
D, T, S = map(int, input().split())
if (D / S) <= T:
print('Yes')
else:
print('No')
| 1 | 3,544,439,895,712 | null | 81 | 81 |
import math
A, B, X = map(int, input().split())
h = X / (A*A)
r = 0
deg = 0
if (2 * X) - (B * A * A) > 0:
r = math.atan(2 * (B-h) / A)
elif (2 * X) - (B * A * A) == 0:
r = math.atan(B / A)
else:
h = (2 * X) / (A * B)
r = math.atan(B / h)
deg = math.degrees(r)
print(deg)
|
import math
def main():
a, b, x = map(int, input().split())
if (a*b)*a/2 >= x:
y = 2*x/(a*b)
ans = math.degrees(math.atan((b/y)))
else:
y = (2*(a**2*b - x))/(a**2)
ans = math.degrees(math.atan(y/a))
print(ans)
if __name__ == "__main__":
main()
| 1 | 163,481,856,974,140 | null | 289 | 289 |
X = int(input())
q = X // 100
if X%100<=q*5:
print('1')
else:
print('0')
|
class Queue:
def __init__(self, n):
self.values = [None]*n
self.n = n
self.s = 0
self.t = 0
def next(self, p):
ret = p+1
if ret >= self.n:
ret = 0
return ret
def enqueue(self, x):
if self.next(self.s) == self.t:
raise Exception("Overflow")
self.values[self.s] = x
self.s = self.next(self.s)
def dequeue(self):
if self.s == self.t:
raise Exception("Underflow")
ret = self.values[self.t]
self.t = self.next(self.t)
return ret
n, q = map(int, raw_input().split(' '))
queue = Queue(n+1)
for _ in range(n):
name, time = raw_input().split(' ')
time = int(time)
queue.enqueue((name, time))
completed = []
cur = 0
while len(completed) < n:
name, time = queue.dequeue()
res = time-q
if res <= 0:
cur += time
completed.append((name, cur))
else:
cur += q
queue.enqueue((name, res))
for name, time in completed:
print name, time
| 0 | null | 63,424,370,505,340 | 266 | 19 |
n=int(input())
s=input()
ans=0
for i in range(1000):
i='0'*(3-len(str(i)))+str(i)
if i[0] in s:
if i[1] in s[s.index(i[0])+1:]:
if i[2]in s[s.index(i[0])+s[s.index(i[0])+1:].index(i[1])+2:]:
ans+=1
print(ans)
|
n=int(input())
s=input()
ans=0
for i in range(10):
if str(i) in s[:-2]:
s1=s.index(str(i))
for j in range(10):
if str(j) in s[s1+1:-1]:
s2=s[s1+1:].index(str(j))+s1+1
for k in range(10):
if str(k) in s[s2+1:]:
ans+=1
print(ans)
| 1 | 128,798,460,596,190 | null | 267 | 267 |
def solve():
x = int(input())
if x == 1:
print(0)
else:
print(1)
if __name__ == "__main__":
solve()
|
def __main():
x = 1;
while x <= 9 :
y = 1;
while y <= 9 :
z = x * y;
print(str(x) + "x" + str(y) + "=" + str(z) )
y = y + 1
x = x + 1
__main()
| 0 | null | 1,449,805,666,988 | 76 | 1 |
a=int(input())
count1=0
count2=0
count3=0
count4=0
for i in range(a):
b=str(input())
count=0
if b=='AC':
count1+=1
if b=='RE':
count2+=1
if b=='TLE':
count3+=1
if b=='WA':
count4+=1
print('AC x ',end='')
print(count1)
print('WA x ',end='')
print(count4)
print('TLE x ',end='')
print(count3)
print('RE x ',end='')
print(count2)
|
N = int(input())
n = 1
S = []
while n <= N:
s = str(input())
S.append(s)
n += 1
print("AC x", S.count("AC"))
print("WA x", S.count("WA"))
print("TLE x", S.count("TLE"))
print("RE x", S.count("RE"))
| 1 | 8,668,189,987,712 | null | 109 | 109 |
n=int(input())
s=[]
for i in range(n):
s.append(str(input()))
s=set(s)
print(len(s))
|
def main():
line = input()
deepen_x = []
cur_x = 0
ponds = [] # [(水たまりの最初の位置, 水量)]
while len(line) > 0:
#print(cur_x, ponds, deepen_x)
tmp_char = line[0]
if tmp_char == '\\':
deepen_x.append(cur_x)
elif tmp_char == '/' and len(deepen_x) != 0:
pre_x = deepen_x.pop()
volume = cur_x - pre_x
if len(ponds) == 0:
ponds.append([pre_x, volume])
else:
if pre_x < ponds[-1][0]:
# 前の水たまりと結合する
a = list(filter(lambda x: x[0] > pre_x, ponds))
pond = 0
for item in a:
pond += item[1]
[ponds.pop() for x in range(len(a))]
ponds.append([pre_x, pond + volume])
else:
# 新しい水たまりを作成
ponds.append([pre_x, volume])
cur_x += 1
line = line[1:]
print(sum([x[1] for x in ponds]))
if len(ponds) == 0:
print('0')
else:
print("{} ".format(len(ponds)) + " ".join([str(x[1]) for x in ponds]))
return
main()
| 0 | null | 15,300,187,639,920 | 165 | 21 |
import math
def kock(n,p1,p2):
if n==0:
return
s=[(2*p1[0]+p2[0])/3,(2*p1[1]+p2[1])/3]
t=[(p1[0]+2*p2[0])/3,(p1[1]+2*p2[1])/3]
kock(n-1,p1,s)
print(*s)
u=[(t[0]-s[0])*math.cos(math.radians(60))-(t[1]-s[1])*math.sin(math.radians(60))+s[0],(t[0]-s[0])*math.sin(math.radians(60))+(t[1]-s[1])*math.cos(math.radians(60))+s[1]]
kock(n-1,s,u)
print(*u)
kock(n-1,u,t)
print(*t)
kock(n-1,t,p2)
n=int(input())
p1=[0,0]
p2=[100,0]
print(*p1)
kock(n,p1,p2)
print(*p2)
|
S = input()
T = input()
judge = T[0:len(S)]
if judge == S:
print("Yes")
else:
print("No")
| 0 | null | 10,849,201,919,490 | 27 | 147 |
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15
def main():
N = int(input())
word = []
time = []
for _ in range(N):
a,b = input().split()
word.append(a)
time.append(int(b))
X = input()
s = -1
for i in range(N):
if word[i] == X:
s = i + 1
ans = sum(time[s:])
print(ans)
if __name__ == '__main__':
main()
|
import sys, math
from functools import lru_cache
sys.setrecursionlimit(500000)
MOD = 10**9+7
def input():
return sys.stdin.readline()[:-1]
def mi():
return map(int, input().split())
def ii():
return int(input())
def i2(n):
tmp = [list(mi()) for i in range(n)]
return [list(i) for i in zip(*tmp)]
def main():
N = ii()
s, t = [list(i) for i in zip(*[input().split() for i in range(N)])]
t = list(map(int, t))
k = s.index(input())
print(sum(int(t[i]) for i in range(k+1, N)))
if __name__ == '__main__':
main()
| 1 | 97,014,691,353,440 | null | 243 | 243 |
MOD = 10 ** 9 + 7
n, k = map(int, input().split())
alst = list(map(int, input().split()))
alst.sort()
if n == k:
ans = 1
for num in alst:
ans *= num
ans %= MOD
print(ans)
exit()
if k == 1:
print(alst[-1] % MOD)
exit()
if alst[0] >= 0:
ans = 1
alst.sort(reverse = True)
for i in range(k):
ans *= alst[i]
ans %= MOD
print(ans)
exit()
if alst[-1] <= 0:
ans = 1
if k % 2 == 1:
alst = alst[::-1]
for i in range(k):
ans *= alst[i]
ans %= MOD
print(ans)
exit()
blst = []
for num in alst:
try:
blst.append([abs(num), abs(num) // num])
except ZeroDivisionError:
blst.append([abs(num), 0])
blst.sort(reverse = True,key = lambda x:x[0])
if blst[k - 1] == 0:
print(0)
exit()
minus = 0
last_minus = 0
last_plus = 0
ans_lst = []
for i in range(k):
if blst[i][1] == -1:
minus += 1
last_minus = blst[i][0]
elif blst[i][1] == 1:
last_plus = blst[i][0]
else:
print(0)
exit()
ans_lst.append(blst[i][0])
next_minus = 0
next_plus = 0
flg_minus = False
flg_plus = False
for i in range(k, n):
if blst[i][1] == -1 and (not flg_minus):
next_minus = blst[i][0]
flg_minus = True
if blst[i][1] == 1 and (not flg_plus):
next_plus = blst[i][0]
flg_plus = True
if (flg_plus and flg_minus) or blst[i][1] == 0:
break
if minus % 2 == 0:
ans = 1
for num in ans_lst:
ans *= num
ans %= MOD
print(ans)
else:
minus_s = last_minus * next_minus
plus_s = last_plus * next_plus
ans = 1
if minus == k:
ans_lst.remove(last_minus)
ans_lst.append(next_plus)
elif minus_s == plus_s == 0:
if next_minus == 0:
ans_lst.remove(last_minus)
ans_lst.append(next_plus)
else:
print(0)
exit()
elif minus_s > plus_s:
ans_lst.remove(last_plus)
ans_lst.append(next_minus)
else:
ans_lst.remove(last_minus)
ans_lst.append(next_plus)
for num in ans_lst:
ans *= num
ans %= MOD
print(ans)
|
import sys
input = sys.stdin.buffer.readline
MOD = 10**9 + 7
N, K = map(int, input().split())
A = list(map(int, (input().split())))
pos, neg = [], []
for a in A:
if a<0:
neg.append(a) # 負
else:
pos.append(a) # 0以上
if pos:
if N==K: # 全て選択で負の数が奇数ならfalse(正にできない)
ok = (len(neg)%2 == 0)
else:
ok = True
else:
ok = (K%2 == 0) # すべて負で奇数ならfalse(正にできない)
ans = 1
if ok == False: # false(正にできない)場合、絶対値が小さいものからk個かける
A.sort(key=abs)
for i in range(K):
ans *= A[i]
ans %= MOD
else:
pos.sort() # 後ろから取っていくので正は昇順
neg.sort(reverse=True) # 後ろから取っていくので負は降順
if K%2:
ans *= pos.pop() # kが奇数個なら1個は正を選ぶ
p = [] # 2個ずつかけた数を格納
while len(pos)>=2:
p.append(pos.pop() * pos.pop())
while len(neg)>=2: # 負を2回かけるのでxは正
p.append(neg.pop() * neg.pop())
p.sort(reverse=True)
for i in range(K//2): # 降順にk//2個見ていく
ans *= p[i]
ans %= MOD
print(ans)
| 1 | 9,411,639,668,920 | null | 112 | 112 |
H,A = map(int, input().split())
cnt = H//A
if (H%A):
cnt +=1
print(cnt)
|
H,A=map(int,input().split())
print((H-1)//A+1)
| 1 | 77,263,223,149,180 | null | 225 | 225 |
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
mod = 10**9+7
def comb(n, k):
c = 1
for i in range(k):
c *= n - i
c %= mod
d = 1
for i in range(1, k + 1):
d *= i
d %= mod
return (c * pow(d, mod - 2, mod)) % mod
x,y = map(int, input().split())
if (x + y) % 3 != 0:
print(0)
exit()
n = (x + y) // 3
x -= n
y -= n
if x < 0 or y < 0:
print(0)
exit()
print(comb(x + y, x))
|
import sys
import itertools
# import numpy as np
import time
import math
sys.setrecursionlimit(10 ** 7)
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
X, Y = map(int, input().split())
if (X + Y) % 3 != 0:
print(0)
exit()
MAX = 2 * 10 ** 6 + 2
MOD = 10 ** 9 + 7
fac = [0 for i in range(MAX)]
finv = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]
def comInit(mod):
fac[0], fac[1] = 1, 1
finv[0], finv[1] = 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, r, mod):
if n < r:
return 0
if n < 0 or r < 0:
return 0
return fac[n] * (finv[r] * finv[n - r] % mod) % mod
comInit(MOD)
if X < Y:
X, Y = Y, X
b = (2 * X - Y) // 3
a = X - 2 * b
print(com(a + b, b, MOD))
| 1 | 149,988,226,572,532 | null | 281 | 281 |
N=int(input())
print(1000*(N%1000!=0)-N%1000)
|
N, K = list(map(int, input().split()))
if N >= K:
N = N % K
print(min(N, max(N-K, K-N)))
| 0 | null | 23,866,296,212,054 | 108 | 180 |
K = int(input())
def f(n, k, a):
if k == n:
return 1
res = 0
res += f(n, k+1, a)
if a > 0:
res += f(n, k+1, a-1)
if a < 9:
res += f(n, k+1, a+1)
return res
cnt = 0
for n in range(1, 12):
c2 = 0
for a in range(1, 10):
c2 += f(n, 1, a)
if cnt+c2 >= K:
num = n
ini = a
cnt += c2-f(n, 1, a)
c2 = -1
break
if c2 < 0:
break
cnt += c2
ans = [ini]
for k in range(2, num+1):
for a in range(max(0, ans[-1]-1), min(10, ans[-1]+2)):
cnt += f(num, k, a)
if cnt >= K:
ans.append(a)
cnt -= f(num, k, a)
break
for i in range(len(ans)):
ans[i] = str(ans[i])
print("".join(ans))
|
def main():
import sys
import math
input = sys.stdin.buffer.readline
n = int(input())
A = list(map(int, input().split()))
ans = 0
node = 1
max_node = sum(A)
for i in range(n+1):
ans += node
max_node -= A[i]
node = min(max_node,(node-A[i])*2)
if node < 0:
print(-1)
exit(0)
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 29,486,898,748,928 | 181 | 141 |
N, X, M = [int(x) for x in input().split()]
A = [0] * (M + 1)
firstApearAt = {i:0 for i in range(M)}
A[1] = X
firstApearAt[X] = 1
l, r = 1, 2
for i in range(2, M + 1):
A[i] = (A[i - 1] * A[i - 1]) % M
if firstApearAt[A[i]] > 0:
r = i
l = firstApearAt[A[i]]
break
firstApearAt[A[i]] = i
ans = 0
if N <= l - 1:
ans = sum(A[1:N + 1])
else:
q, p = (N - l + 1) // (r - l), (N - l + 1) % (r - l)
ans = sum(A[1:l]) + q * sum(A[l:r]) + sum(A[l:l + p])
print(ans)
|
N = int(input())
num_even = N//2
num_odd = N - num_even
print(num_odd/N)
| 0 | null | 89,994,050,810,488 | 75 | 297 |
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np # cumsum
# from bisect import bisect_left, bisect_right
def solve():
N = II()
S = LS()
R = []
G = []
B = []
for i, s in enumerate(S):
if s == 'R':
R.append(i)
elif s == 'G':
G.append(i)
else:
B.append(i)
len_r = len(R)
len_g = len(G)
len_b = len(B)
def g(lst, r, j):
l = -1
while r - l > 1:
m = (l + r) // 2
if lst[m] <= j:
l = m
else:
r = m
return r
def f(lst, r, out):
l = -1
while r - l > 1:
m = (r + l) // 2
if out < lst[m]:
r = m
elif out > lst[m]:
l = m
else:
return True
return False
ans = 0
for i in range(N):
si = S[i]
for j in range(i+1, N):
sj = S[j]
if si == sj: continue
out = j + j - i
# print(i, j, si, sj, out)
if si == 'R':
if sj == 'G':
# B
k = g(B, len_b, j)
# print(k)
ans += len_b - k
if f(B, len_b, out):
ans -= 1
elif sj == 'B':
# G
k = g(G, len_g, j)
ans += len_g - k
if f(G, len_g, out):
ans -= 1
elif si == 'G':
if sj == 'R':
# B
k = g(B, len_b, j)
ans += len_b - k
if f(B, len_b, out):
ans -= 1
elif sj == 'B':
# R
k = g(R, len_r, j)
ans += len_r - k
if f(R, len_r, out):
ans -= 1
elif si == 'B':
if sj == 'R':
# G
k = g(G, len_g, j)
ans += len_g - k
if f(G, len_g, out):
ans -= 1
elif sj == 'G':
# R
k = g(R, len_r, j)
ans += len_r - k
if f(R, len_r, out):
ans -= 1
print(ans)
if __name__ == '__main__':
solve()
|
n = int(input())
s = input()
r = [0] * (n+1)
g = [0] * (n+1)
b = [0] * (n+1)
for i, c in enumerate(reversed(s), 1):
if c == 'R':
r[i] += r[i-1] + 1
else:
r[i] += r[i-1]
if c == 'G':
g[i] += g[i-1] + 1
else:
g[i] += g[i-1]
if c == 'B':
b[i] += b[i-1] + 1
else:
b[i] += b[i-1]
r = r[:-1][::-1]
g = g[:-1][::-1]
b = b[:-1][::-1]
ans=0
for i in range(n-2):
for j in range(i+1, n-1):
if s[i] == s[j]:
continue
se = set('RGB') - set(s[i] + s[j])
c = se.pop()
if c == 'R':
ans += r[j]
if 2*j-i < n and s[2*j-i] == 'R':
ans -= 1
elif c == 'G':
# print('j=',j,'g[j]=',g[j])
ans += g[j]
if 2*j-i < n and s[2*j-i] == 'G':
ans -= 1
elif c == 'B':
ans += b[j]
if 2*j-i < n and s[2*j-i] == 'B':
ans -= 1
# print('i=',i,'j=',j,'c=',c, 'ans=',ans)
print(ans)
| 1 | 36,072,522,851,300 | null | 175 | 175 |
a, b = int(input()), int(input())
l = [1,2,3]
l.remove(a)
l.remove(b)
print(l[0])
|
import sys
input = sys.stdin.readline
l,r,d=map(int,input().split())
v1 = l//d
if l%d==0:
v1-=1
v2 = r//d
print(v2-v1)
| 0 | null | 59,500,756,336,138 | 254 | 104 |
import random
def name(x):
if len(x) > 20:
return name()
if len(x) < 3:
return name()
if x.isupper() == True:
return name()
if x.isalpha() == False:
return name()
else:
l = list(x)
w = random.randint(0, len(x) - 3)
y = l[w]
z = l.index(y)
print(y + l[z+1] + l[z+2])
S=input()
name(S)
|
s = list(input())
nick = s[0]+s[1]+s[2]
print(nick)
| 1 | 14,797,027,516,358 | null | 130 | 130 |
n=int(input())
for i in range(1,361):
if (n*i)%360==0:
print(i);exit()
|
X = int(input())
for i in range(1,1000000000):
if ( X * i ) % 360 == 0:
print(i)
quit()
| 1 | 13,125,957,493,810 | null | 125 | 125 |
from _collections import deque
n,m,k=map(int,input().split())
fre=[[] for _ in range(n+1)]
bro=[[] for _ in range(n+1)]
for i in range(m):
a,b=map(int,input().split())
fre[a].append(b)
fre[b].append(a)
for i in range(k):
a, b = map(int, input().split())
bro[a].append(b)
bro[b].append(a)
ans=[]
x=[-1]*(n+1)
for i in range(1,n+1):
if x[i]==-1:
x[i]=i
data=deque([i])
while len(data)>0:
p=data.popleft()
for j in fre[p]:
if x[j]==-1:
x[j]=i
data.append(j)
g=[0]*(n+1)
for i in range(1,n+1):
g[x[i]]+=1
for i in range(1,n+1):
g[i]=g[x[i]]
for i in range(1,n+1):
aa=g[i]-1
aa-=len(fre[i])
for j in bro[i]:
if x[i]==x[j]:
aa-=1
ans.append(str(aa))
print(" ".join(ans))
|
from _collections import deque
n,m,k=map(int,input().split())
import sys
sys.setrecursionlimit(10**9) #再帰の上限をあげる
fre=[[] for _ in range(n+1)]
bro=[[] for _ in range(n+1)]
for i in range(m):
a,b=map(int,input().split())
fre[a].append(b)
fre[b].append(a)
for i in range(k):
a, b = map(int, input().split())
bro[a].append(b)
bro[b].append(a)
ans=[]
x=[-1]*(n+1)
def s(y):
global i
if x[y]>0:
return
x[y]=i
for j in fre[y]:
if x[j]==-1:
s(j)
for i in range(1,n+1):
s(i)
g=[0]*(n+1)
for i in range(1,n+1):
g[x[i]]+=1
for i in range(1,n+1):
g[i]=g[x[i]]
for i in range(1,n+1):
aa=g[i]-1
aa-=len(fre[i])
for j in bro[i]:
if x[i]==x[j]:
aa-=1
ans.append(str(aa))
print(" ".join(ans))
| 1 | 61,953,864,780,044 | null | 209 | 209 |
# coding: UTF-8
import sys
import numpy as np
# f = open("input.txt", "r")
# sys.stdin = f
s = str(input())
t = str(input())
ans = 0
for i, j in zip(s,t):
if i != j:
ans += 1
print(ans)
|
def main():
import sys
input=sys.stdin.readline
l=lambda: list(map(int,input().split()))
n,d,a=l()
xh=[]
for i in range(n):
xi,hi=l()
xh.append([xi,hi])
xh.sort()
right_index=[]
#尺取り法
tmp=0
for i in range(n):
j=tmp
while xh[j][0]<=xh[i][0]+2*d:
j+=1
if j==n: break
j-=1
right_index.append(j)
tmp=j
ans=0
cnt=0
damage=[0]*(n+1)
for i in range(n):
xh[i][1]-=(ans-cnt)*a
damage_cnt=max(0,(xh[i][1]-1)//a + 1)
ans+=damage_cnt
damage[right_index[i]]+=damage_cnt
cnt+=damage[i]
print(ans)
if __name__=='__main__':
main()
| 0 | null | 46,402,699,677,880 | 116 | 230 |
import numpy as np
import sys
input = sys.stdin.readline
def main():
N,M = map(int, input().split())
A = np.array(sorted([int(i) for i in input().split()]))
left = 0
right = A[-1] * 2 + 5
while right - left > 1:
x = (left + right) // 2
count = N**2 - np.searchsorted(A, x-A).sum()
if count >= M:
left = x
else:
right = x
bound = np.searchsorted(A, left-A)
count = N**2 - bound.sum()
diff = count - M
ans = ((N - bound) * A * 2).sum() - diff * left
print(ans)
if __name__ == "__main__":
main()
|
n, m = map(int, input().split())
a = list(map(int, input().split()))
def cumsum(s):
n = len(s)
cs = [0] * (n+1)
for i in range(n):
cs[i+1] = cs[i] + s[i]
return cs
def bs_list(a, f):
l, r = -1, len(a)
while r - l > 1:
x = (l + r) // 2
if f(a[x]): r = x
else: l = x
return None if r == len(a) else r
a.sort()
ca = cumsum(a)
def detect(x):
num = 0
for b in a[::-1]:
res = bs_list(a, lambda y: y >= x - b)
if res is None: break
num += n - res
return num <= m
l, r = -1, 10**5*2+10
while r - l > 1:
x = (l+r) // 2
if detect(x): r = x
else: l = x
s, c = 0, 0
for b in a[::-1]:
res = bs_list(a, lambda x: x >= r - b)
if res is None: break
c += (n - res)
s += b * (n - res) + (ca[n] - ca[res])
print(s + (m - c) * l)
| 1 | 108,514,099,571,120 | null | 252 | 252 |
kazu = input().split()
print(int(kazu[0]) * int(kazu[1]))
|
a, b = map(int, input().split())
print(str(a*b))
| 1 | 15,791,246,752,950 | null | 133 | 133 |
import itertools
import math
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
arr = [i for i in itertools.permutations([i for i in range(1, n+1)])]
a = arr.index(p)
b = arr.index(q)
print(abs(a-b))
|
n = int(input())
S = list(map(int,input().split(' ')))
q = int(input())
T = list(map(int,input().split(' ')))
C = 0
for i in S:
if i in T:
C += 1
T.remove(i)
print(C)
| 0 | null | 50,120,170,171,768 | 246 | 22 |
n = int(raw_input())
dp = [1, 1]
for i in range(50):
dp += [dp[-1] + dp[-2]]
print dp[n]
|
def main():
N,P = map(int,input().split())
S = input()[::-1]
ans = 0
if P == 2 or P == 5:
for i,s in enumerate(S):
if int(s) % P == 0:
ans += N - i
else:
mods = [0] * P
mods[0] = 1
current = 0
x = 1
for s in S:
current = (current + x * int(s)) % P
ans += mods[current % P]
mods[current % P] += 1
x = x * 10 % P
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 29,276,100,764,162 | 7 | 205 |
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9
def main():
n = int(input())
s,t = input().split()
ans = ''
for i in range(n):
ans += s[i] + t[i]
print(ans)
if __name__ == '__main__':
main()
|
input();print(*[i+j for i,j in zip(*input().split())],sep='')
| 1 | 111,801,437,311,960 | null | 255 | 255 |
A, B = map(int, input().split())
if A <= 2 * B:
print('0')
else:
print(A - 2 * B)
|
#!/usr/bin/env python3
def main():
N, K = map(int, input().split())
res = N % K
print(min(res, abs(res - K)))
if __name__ == '__main__':
main()
| 0 | null | 102,843,103,949,194 | 291 | 180 |
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = [_ for _ in str(input())]
ans = 0
for i in range(n):
if i - k < 0:
if t[i] == "r":
ans += p
elif t[i] == "s":
ans += r
elif t[i] == "p":
ans += s
else:
if t[i] == "r" and t[i-k] != "r":
ans += p
elif t[i] == "s" and t[i-k] != "s":
ans += r
elif t[i] == "p" and t[i-k] != "p":
ans += s
else:
t[i] = "a"
print(ans)
|
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
wins = {"p":"s", "r":"p", "s":"r"}
points = {"p":S, "r":P, "s":R}
hands = []
ans = 0
for i in range(N):
if i - K < 0:
hands.append(wins[T[i]])
ans += points[T[i]]
else:
if hands[i-K] == wins[T[i]]:
#あいこにするしか無い時
hands.append("-")
else:
#勝てる時
hands.append(wins[T[i]])
ans += points[T[i]]
print(ans)
| 1 | 106,748,059,024,708 | null | 251 | 251 |
n, a, b = map(int, input().split())
c = n//(a+b)
ans = c*a
n = n - c*(a+b)
if n < a:
print(ans + n)
else:
print(ans + a)
|
N, A, B = map(int, input().split())
result = 0
result += N // (A + B) * A
result += min(N % (A + B), A)
print(result)
| 1 | 55,782,467,297,812 | null | 202 | 202 |
#comb_mod(n, r, mod) = nCr % mod
def comb_mod(n, r, mod):
ans = 1
if r <= n/2:
for i in range(n-r+1, n+1):
ans *= i
ans %= mod
for i in range(1, r+1):
ans *= pow(i, mod-2, mod)
ans %= mod
else:
for i in range(r+1, n+1):
ans *= i
ans %= mod
for i in range(1, n-r+1):
ans *= pow(i, mod-2, mod)
ans %= mod
return ans
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
pattern = comb_mod(n-1, k-1, 10**9+7)
for i in range(n-k+1):
ans += (a[-(i+1)] - a[i]) * pattern
pattern *= (n-k-i) * pow(n-1-i, 10**9+5, 10**9+7)
pattern %= 10**9 + 7
print(ans % (10**9+7))
|
X, Y = map(int, input().split())
if Y % 2 == 0 and 2 * X <= Y <= 4 * X:
print("Yes")
else:
print("No")
| 0 | null | 55,032,286,392,100 | 242 | 127 |
X = int(input())
yen_500 = X // 500
yen_5 = (X % 500) // 5
print(yen_500 * 1000 + yen_5 * 5)
|
N = int(input())
A = list(map(int, input().split()))
b = [0] * N
for a in A:
b[a-1] += 1
for i in b:
print(i)
| 0 | null | 37,701,075,636,952 | 185 | 169 |
S = input()
N = len(S)+1
x = [0 for _ in range(N)]
l = 0
while(l<N-1):
r = l+1
while(r<N-1 and S[r]==S[l]):
r += 1
if S[l]=='<':
x[l] = 0
for i in range(l+1, r+1):
x[i] = max(x[i], x[i-1]+1)
else:
x[r] = 0
for i in range(r-1, l-1, -1):
x[i] = max(x[i], x[i+1]+1)
l = r
print(sum(x))
|
N = int(input())
count = [[0] * 10 for _ in range(10)]
for i in range(1, N + 1):
s = str(i)
count[int(s[0])][int(s[-1])] += 1
ans = sum(count[i][j] * count[j][i] for i in range(1, 10) for j in range(1, 10))
print(ans)
| 0 | null | 121,680,122,317,430 | 285 | 234 |
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
N = i()
A = l()
L = []
L2 = [0]*(10**6)
for i in range(N):
if i+A[i]+1 < 10**6:
L.append(i+A[i]+1)
if i-A[i]+1 >= 0 and i-A[i]+1 < 10**6:
L2[i-A[i]+1] += 1
ans = 0
for l in L:
ans += L2[l]
print(ans)
|
S = input()
nick = S[:3]
print(nick)
| 0 | null | 20,239,701,868,342 | 157 | 130 |
N = [int(_) for _ in input()]
dp = [[0, 0] for _ in range(len(N))]
dp[0][0] = min(N[0], 11 - N[0])
dp[0][1] = min(N[0] + 1, 10 - N[0])
for i in range(1, len(N)):
dp[i][0] = min(dp[i - 1][0] + N[i], dp[i - 1][1] + 10 - N[i])
dp[i][1] = min(dp[i - 1][0] + N[i] + 1, dp[i - 1][1] + 9 - N[i])
print(dp[-1][0])
|
s = input()
n = len(s)
ans = 0
sub = 0
judge = False
for i in range(n-1, -1, -1):
key = int(s[i])+sub
if key <= 4:
ans += key
sub = 0
elif key == 5:
ans += 5
if i == 0:
sub = 0
elif int(s[i-1]) <= 4:
sub = 0
else:
sub = 1
else:
ans += 10-key
sub = 1
ans += sub
print(ans)
| 1 | 71,310,364,349,048 | null | 219 | 219 |
import math
radius=int(input())
print(2*math.pi*radius)
|
import math
R = int(input())
circum = R * 2 * math.pi
print(circum)
| 1 | 31,541,537,789,720 | null | 167 | 167 |
x=int(input())
if x>=400 and x<600:
print(8)
elif x>=600 and x<800:
print(7)
elif x>=800 and x<1000:
print(6)
elif x>=1000 and x<1200:
print(5)
elif x>=1200 and x<1400:
print(4)
elif x>=1400 and x<1600:
print(3)
elif x>=1600 and x<1800:
print(2)
elif x>=1800 and x<2000:
print(1)
|
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
N,M=map(int,input().split())
ans = 0
if N >= 2:
ans += len(list(itertools.combinations(range(N), 2)))
if M >= 2:
ans += len(list(itertools.combinations(range(M), 2)))
print(ans)
| 0 | null | 26,231,441,728,360 | 100 | 189 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
X, Y, A, B, C = map(int, readline().split())
P = list(map(int, readline().split()))
Q = list(map(int, readline().split()))
R = list(map(int, readline().split()))
P.sort(reverse=True)
Q.sort(reverse=True)
apple = P[:X] + Q[:Y] + R
apple.sort(reverse=True)
print(sum(apple[: X + Y]))
return
if __name__ == '__main__':
main()
|
X, Y, A, B, C = [int(x) for x in input().split()]
p = sorted([int(x) for x in input().split()], reverse=True)[:X]
q = sorted([int(x) for x in input().split()], reverse=True)[:Y]
r = sorted([int(x) for x in input().split()], reverse=True)[:X + Y]
s = sorted(p + q + r, reverse=True)
ans = sum(s[:X + Y])
print(ans)
| 1 | 44,772,990,704,370 | null | 188 | 188 |
MOD = 998244353
N, M, K = map(int, input().split())
fac = [1] * N
for i in range(1, N):
fac[i] = (fac[i - 1] * i) % MOD
pow_mmm = [1] * N
for i in range(1, N):
pow_mmm[i] = (pow_mmm[i - 1] * (M - 1)) % MOD
ans = 0
for i in range(K + 1):
t = (M * pow_mmm[N - 1 - i]) % MOD
comb = (fac[N - 1] * pow(fac[N - 1 - i], MOD - 2, MOD) * pow(fac[i], MOD - 2, MOD)) % MOD
t = (t * comb) % MOD
ans = (ans + t) % MOD
print(ans)
|
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
mod = 998244353
N, M, K = mapint()
pos = {}
neg = {}
pos[0] = 1
neg[0] = 1
for i in range(1, N+1):
pos[i] = i*pos[i-1]%mod
neg[i] = pow(pos[i], mod-2, mod)
ans = 0
for i in range(K+1):
ans += M*pow((M-1), (N-i-1), mod)*pos[N-1]*neg[i]*neg[N-i-1]
ans %= mod
print(ans)
| 1 | 23,138,684,717,148 | null | 151 | 151 |
n, m, L = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(m)]
q = int(input())
st = [list(map(int, input().split())) for _ in range(q)]
d = [[float('inf') for _ in range(n)] for _ in range(n)]
for a, b, c in abc:
if c > L:
continue
d[a-1][b-1] = c
d[b-1][a-1] = c
def warshall_floyd(d):
for k in range(n):
for i in range(n):
if i == k or d[i][k] > L:
continue
for j in range(n):
if i == j:
continue
d[i][j] = min(d[i][j],d[i][k] + d[k][j])
return d
warshall_floyd(d)
for i in range(n):
for j in range(n):
if i == j:
continue
elif d[i][j] <= L:
d[i][j] = 1
else:
d[i][j] = float('inf')
warshall_floyd(d)
for s, t in st:
if d[s-1][t-1] == float('inf'):
print(-1)
else:
print(d[s-1][t-1] - 1)
|
import sys
input = sys.stdin.readline
N,M,L = map(int,input().split())
ABC = [tuple(map(int,input().split())) for i in range(M)]
Q = int(input())
ST = [tuple(map(int,input().split())) for i in range(Q)]
INF = float('inf')
ds = [[INF]*N for i in range(N)]
for a,b,c in ABC:
a,b = a-1,b-1
ds[a][b] = ds[b][a] = c
for i in range(N):
ds[i][i] = 0
for k in range(N):
for i in range(N):
for j in range(N):
ds[i][j] = min(ds[i][j], ds[i][k]+ds[k][j])
ls = [[INF]*N for i in range(N)]
for i in range(N-1):
for j in range(i+1,N):
if ds[i][j] <= L:
ls[i][j] = ls[j][i] = 1
for i in range(N):
ls[i][i] = 0
for k in range(N):
for i in range(N):
for j in range(N):
ls[i][j] = min(ls[i][j], ls[i][k]+ls[k][j])
ans = []
for s,t in ST:
ans.append(-1 if ls[s-1][t-1]==INF else ls[s-1][t-1] - 1)
print(*ans, sep='\n')
| 1 | 174,100,520,072,292 | null | 295 | 295 |
turn = int(input())
tp, hp = 0, 0
for i in range(turn):
t, h = input().split()
if t == h:
tp += 1
hp += 1
elif t > h:
tp += 3
elif t < h:
hp += 3
print(tp, hp)
|
n=int(input())
arr=list(map(int,input().split()))
x=0
for i in arr:
x^=i
ans=[]
for i in arr:
ans.append(x^i)
print(*ans)
| 0 | null | 7,284,003,713,522 | 67 | 123 |
import math
from decimal import Decimal, ROUND_HALF_UP
def resolve():
a, b, C = map(int, input().split())
x = math.radians(C)
h = b * math.sin(x)
S = Decimal((a * h) / 2).quantize(Decimal('0.00000001'), rounding=ROUND_HALF_UP)
c = Decimal(math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(x))).quantize(Decimal('0.00000001'),
rounding=ROUND_HALF_UP)
L = Decimal(a + b + c).quantize(Decimal('0.00000001'), rounding=ROUND_HALF_UP)
print(S, L, h, sep="\n")
resolve()
|
def main():
N = input()
S, T = input().split()
ans = ""
for s, t in zip(S, T):
ans += s + t
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 56,341,282,630,620 | 30 | 255 |
class ModComb:
def __init__(self, MAX, mod=10 ** 9 + 7):
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
for i in range(2, MAX):
fac.append(fac[i - 1] * i % mod)
inv.append(mod - inv[mod % i] * (mod // i) % mod)
finv.append(finv[i - 1] * inv[i] % mod)
self.fac, self.finv, self.mod = fac, finv, mod
def nCk(self, n, k):
if n < k or n < 0 or k < 0:
return 0
fac, finv, mod = self.fac, self.finv, self.mod
return fac[n] * (finv[k] * finv[n - k] % mod) % mod
mod = 998244353
N, M, K = map(int, input().split())
mc = ModComb(N, mod)
ans = 0
for k in range(K + 1):
ans += M * pow(M - 1, N - 1 - k, mod) * mc.nCk(N - 1, k)
ans %= mod
print(ans)
|
class Combination():
def __init__(self, n, mod=10**9+7):
self.mod = mod
self.fac = [1]*(n+1)
for i in range(1,n+1):
self.fac[i] = self.fac[i-1] * i % self.mod
self.invfac = [1]*(n+1)
self.invfac[n] = pow(self.fac[n], self.mod - 2, self.mod)
for i in range(n-1, 0, -1):
self.invfac[i] = self.invfac[i+1] * (i+1) % self.mod
def combination(self, n, r):
ans = self.fac[n] * self.invfac[r] % self.mod * self.invfac[n-r] % self.mod
if n >= r:
return ans
else:
return 0
def factorial(self, i):
return self.fac[i]
def invfactorial(self, i):
return self.invfac[i]
def main():
import sys
def input(): return sys.stdin.readline().rstrip()
n, m, k = map(int, input().split())
mod = 998244353
c = Combination(n,mod)
ans = 0
mex = [0]*(k+1)
mex[0] = pow(m-1,n-k-1,mod)
for i in range(1,k+1):
mex[i] = mex[i-1]*(m-1)%mod
mex = mex[::-1]
for i in range(k+1):
ans += c.combination(n-1, i)*mex[i]
ans %= mod
ans *= m
ans %= mod
print(ans)
if __name__ == '__main__':
main()
| 1 | 23,065,045,580,292 | null | 151 | 151 |
import math
n = int(input())
a = [0] * 2
b = [0] * 2
a[0] = 0
b[0] = 100
def koch(n, a, b):
if n == 0:
return
s = [0] * 2
t = [0] * 2
u =[0] * 2
s[0] = (2.0 * a[0] + 1.0 * b[0]) / 3.0
s[1] = (2.0 * a[1] + 1.0 * b[1]) / 3.0
t[0] = (1.0 * a[0] + 2.0 * b[0]) / 3.0
t[1] = (1.0 * a[1] + 2.0 * b[1]) / 3.0
u[0] = (t[0] - s[0]) * math.cos(math.pi/3) - (t[1] - s[1]) * math.sin(math.pi/3) + s[0]
u[1] = (t[0] - s[0]) * math.sin(math.pi/3) + (t[1] - s[1]) * math.cos(math.pi/3) + s[1]
koch(n - 1, a, s)
print(s[0], s[1])
koch(n - 1, s, u)
print(u[0], u[1])
koch(n - 1, u, t)
print(t[0], t[1])
koch(n - 1, t, b)
print(a[0], a[1])
koch(n, a, b)
print(b[0], b[1])
|
import sys
from math import sin, cos, radians
input = sys.stdin.readline
deg = radians(60)
def Koch(n, p1_x, p1_y, p2_x, p2_y):
if n != 0:
s_x = (2 * p1_x + p2_x) / 3
s_y = (2 * p1_y + p2_y) / 3
t_x = (p1_x + 2 * p2_x) / 3
t_y = (p1_y + 2 * p2_y) / 3
u_x = (t_x - s_x) * cos(deg) - (t_y - s_y) * sin(deg) + s_x
u_y = (t_x - s_x) * sin(deg) + (t_y - s_y) * cos(deg) + s_y
Koch(n - 1, p1_x, p1_y, s_x, s_y)
print('{:.8f} {:.8f}'.format(s_x, s_y))
Koch(n - 1, s_x, s_y, u_x, u_y)
print('{:.8f} {:.8f}'.format(u_x, u_y))
Koch(n - 1, u_x, u_y, t_x, t_y)
print('{:.8f} {:.8f}'.format(t_x, t_y))
Koch(n - 1, t_x, t_y, p2_x, p2_y)
else:
return
n = int(input())
p1_x, p1_y = 0, 0
p2_x, p2_y = 100, 0
print('{:.8f} {:.8f}'.format(p1_x, p1_y))
Koch(n, p1_x, p1_y, p2_x, p2_y)
print('{:.8f} {:.8f}'.format(p2_x, p2_y))
| 1 | 132,323,502,050 | null | 27 | 27 |
def combination_mod(n, k, mod=10 ** 9 + 7):
if k > n:
return 1
nu, de = 1, 1
for i in range(k):
nu = nu * (n - i) % mod
de = de * (i + 1) % mod
return nu * pow(de, mod - 2, mod) % mod
n, a, b = map(int, input().split())
mod = 10 ** 9 + 7
ans = pow(2, n, mod) - 1
ans -= combination_mod(n, a)
ans = (ans + mod) % mod
ans -= combination_mod(n, b)
ans = (ans + mod) % mod
print(ans)
|
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
import copy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)
def lcm(a, b): return a * b / gcd(a, b)
# 1 2 3
# a, b, c = LI()
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# a = I()
def I(): return int(sys.stdin.buffer.readline())
# abc def
# a, b = LS()
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# a = S()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# 2
# 1
# 2
# [1, 2]
def IR(n): return [I() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]
def LIR(n): return [LI() for i in range(n)]
# 2
# abc
# def
# [abc, def]
def SR(n): return [S() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]
def LSR(n): return [LS() for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]
def SRL(n): return [list(S()) for i in range(n)]
n, a, b = map(int, input().split())
MOD = 10**9+7
def comb(n, r):
p, q = 1, 1
for i in range(r):
p = p * (n-i) % MOD
q = q * (i+1) % MOD
return p * pow(q, MOD-2, MOD) % MOD
ans = (pow(2, n, MOD)-1) % MOD
ans = (ans+MOD-comb(n, a)) % MOD
ans = (ans+MOD-comb(n, b)) % MOD
print(ans)
| 1 | 66,319,562,414,820 | null | 214 | 214 |
from math import ceil
n = int(input())
A = list(map(int,input().split()))[::-1]
mn,mx = A[0], A[0]
step = [[mn,mx]]
for i in range(1, n+1):
mn = ceil(mn/2) + A[i]
mx = mx + A[i]
step.append([mn,mx])
if not mn<=1 and 1<=mx:
print(-1)
else:
step = step[::-1]
A = A[::-1]
now = 1
ans = 1
for i in range(1, n+1):
now = min(step[i][1],
(now-A[i-1])*2)
ans += now
print(ans)
|
N, K = map(int,input().split())
A = list(map(int,input().split()))
check = [0] * (N+1) #対象の町を訪問するのが初めてか
li = [] #町の移動順
i, j = 1, 1 #現在の町の番号と移動回数
while True:
k = A[i-1] #移動先の町の番号
if check[k] == 1:
#前に訪問したことがある場合
n = li.index(k)+1 #ループに入った時点での移動回数
break
check[k] = 1
li.append(k)
i = k
j += 1
if K < n: print(li[K-1])
else: print(li[(K-n) % (j-n) + n - 1])
| 0 | null | 20,780,328,550,924 | 141 | 150 |
S = str(input())
if(S[2] == S[3] and S[4] == S[5]):
print("Yes")
else:
print("No")
|
w = list(input())
if (w[2] == w[3]) and (w[4] == w[5]):
print("Yes")
else:
print("No")
| 1 | 42,127,020,240,218 | null | 184 | 184 |
from collections import deque
n = int(input())
adj = [[]]
for i in range(n):
adj.append(list(map(int, input().split()))[2:])
ans = [-1]*(n+1)
ans[1] = 0
q = deque([1])
visited = [False] * (n+1)
visited[1] = True
while q:
x = q.popleft()
for y in adj[x]:
if visited[y] == False:
q.append(y)
ans[y] = ans[x]+1
visited[y] = True
for j in range(1, n+1):
print(j, ans[j])
|
import math
from functools import reduce
"""[summary]
全体:10^N
0が含まれない:9^N
9が含まれない:9^N
0,9の両方が含まれない:8^N
0,9のどちらか一方が含まれない:9^N + 9^N - 8^N
"""
N = int(input())
mod = (10 ** 9) + 7
calc = (10**N - 9**N - 9**N + 8**N) % mod
print(calc)
| 0 | null | 1,590,745,292,720 | 9 | 78 |
while True:
H, W = [int(i) for i in input().split()]
if H == 0 and W == 0:
break
for i in range(H):
for j in range(W):
if (i + j) % 2 == 0:
print('#', end='')
else:
print('.', end='')
print('')
print('')
|
while True:
H, W = [int(i) for i in input().split()]
if H == W == 0:
break
for i in range(H):
if i % 2 == 0:
for j in range(W):
if j % 2 == 0:
print('#', end='')
else:
print('.', end='')
else:
print('')
else:
for j in range(W):
if j % 2 == 0:
print('.', end='')
else:
print('#', end='')
else:
print('')
print('')
| 1 | 865,222,295,748 | null | 51 | 51 |
import sys
n=int(input())
data=list(map(int,input().split()))
for i in data:
if i%2==1:
continue
if i%3!=0 and i%5!=0:
print("DENIED")
sys.exit()
print("APPROVED")
|
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
def main():
N = int(readline())
A = list(map(int, readline().split()))
R = 0
G = 0
B = 0
ans = 1
for a in A:
if a == R == G == B:
ans *= 3
ans %= MOD
R += 1
else:
if a == R == G:
ans *= 2
ans %= MOD
R += 1
elif a == G == B:
ans *= 2
ans %= MOD
G += 1
elif a == B == R:
ans *= 2
ans %= MOD
B += 1
else:
if a == R:
R += 1
elif a == G:
G += 1
elif a == B:
B += 1
else:
print(0)
sys.exit()
print(ans % MOD)
if __name__ == '__main__':
main()
| 0 | null | 99,395,323,266,140 | 217 | 268 |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
a = input()
if a.upper() == a:
print('A')
else:
print('a')
|
N = int(input())
L = sorted([int(i) for i in input().split()])
count = 0
from bisect import bisect_left as bi
for j in range(N):
for k in range(j + 1,N - 1):
right = L[j] + L[k]
ite_right = bi(L,right)
count = count + (ite_right - k - 1)
print(count)
| 0 | null | 91,743,341,363,360 | 119 | 294 |
MOD = 998244353
N, K = list(map(int, input().split()))
dp = [0] * (N+1)
dp[1] = 1
LR = []
for i in range(K):
l, r = list(map(int, input().split()))
LR.append([l, r])
for i in range(2, N+1):
dp[i] = dp[i-1]
for j in range(K):
l, r = LR[j]
dp[i] += dp[max(i-l, 0)] - dp[max(i-r-1, 0)]
dp[i] %= MOD
print((dp[N]-dp[N-1]) % MOD)
|
M=998244353
f=lambda:[*map(int,input().split())]
n,k=f()
lr=[f() for _ in range(k)]
dp=[0]*n
dp[0]=1
S=[0]
for i in range(1,n):
S+=[S[-1]+dp[i-1]]
for l,r in lr:
dp[i]+=S[max(i-l+1,0)]-S[max(i-r,0)]
dp[i]%=M
print(dp[-1])
| 1 | 2,749,703,749,002 | null | 74 | 74 |
i=1
while True:
x = int(input())
if x==0:
break
print('Case ',i,': ',x,sep='')
i=i+1;
|
list = []
x = 1
while x > 0:
x = input()
if x > 0:
list.append(x)
for i,j in enumerate(list):
print "Case " + str(i+1) + ": " + str(j)
| 1 | 483,051,083,140 | null | 42 | 42 |
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n):
res = [None] * n
for i in range(n):
res[i] = II()
return res
def LIR(n):
res = [None] * n
for i in range(n):
res[i] = LI()
return res
def FR(n):
res = [None] * n
for i in range(n):
res[i] = IF()
return res
def LIR(n):
res = [None] * n
for i in range(n):
res[i] = IF()
return res
def LIR_(n):
res = [None] * n
for i in range(n):
res[i] = LI_()
return res
def SR(n):
res = [None] * n
for i in range(n):
res[i] = S()
return res
def LSR(n):
res = [None] * n
for i in range(n):
res[i] = LS()
return res
mod = 1000000007
inf = float('INF')
#solve
def solve():
def f(n, c):
tmp = n % c
t = tmp
b = 0
while tmp:
if tmp & 1:
b += 1
tmp //= 2
if t:
return f(t, b) + 1
else:
return 1
n = II()
a = S()
b = 0
for ai in a:
if ai == "1":
b += 1
a = a[::-1]
bp = 0
bm = 0
if b != 1:
for i, ai in enumerate(a):
if ai == "1":
bp += pow(2, i, b + 1)
bm += pow(2, i, b - 1)
bp %= b + 1
bm %= b - 1
ans = []
for i, ai in enumerate(a):
if ai == "1":
tmpbm = bm - pow(2, i, b - 1)
tmpbm %= b - 1
ans.append(f(tmpbm, b - 1))
else:
tmpbp = bp + pow(2, i, b + 1)
tmpbp %= b + 1
ans.append(f(tmpbp, b + 1))
for ai in ans[::-1]:
print(ai)
return
else:
for i, ai in enumerate(a):
if ai == "1":
bp += pow(2, i, b + 1)
bp %= b + 1
ans = []
for i, ai in enumerate(a):
if ai == "1":
ans.append(0)
else:
tmpbp = bp + pow(2, i, b + 1)
tmpbp %= b + 1
ans.append(f(tmpbp, b + 1))
for ai in ans[::-1]:
print(ai)
return
#main
if __name__ == '__main__':
solve()
|
s = input()
n = len(s)
l1 = int((n-1)/2)
l2 = int((n+3)/2)
if s == s[::-1] and s[:l1] == s[l2-1:n] :
print('Yes')
else :
print('No')
| 0 | null | 27,218,980,644,840 | 107 | 190 |
n = int(input())
dic = {}
for i in range(1,n+1):
if str(i)[-1] == 0:
continue
key = str(i)[0]
key += "+" + str(i)[-1]
if key in dic:
dic[key] += 1
else:
dic[key] = 1
res = 0
for i in range(1,n+1):
if str(i)[-1] == 0:
continue
key = str(i)[-1]
key += "+" + str(i)[0]
if key in dic:
res += dic[key]
print(res)
|
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,790,819,334,898 | null | 234 | 234 |
S = input()
nick = S[:3]
print(nick)
|
A, B, N = map(int, input().split())
val = min(B-1, N)
ans = (A*val/B/1.0)//1
print(int(ans))
| 0 | null | 21,262,166,040,772 | 130 | 161 |
#ALDS1_3-C Elementary data structures - Doubly Linked List
import collections
q = collections.deque()
cmds={"insert":lambda cmd: q.appendleft(cmd[1]),
"delete":lambda cmd: q.remove(cmd[1]) if (q.count(cmd[1]) > 0) else "none",
"deleteFirst":lambda cmd: q.popleft(),
"deleteLast": lambda cmd: q.pop()
}
n=int(input())
for i in range(n):
cmd=input().split()
cmds[cmd[0]](cmd)
print(*q)
|
n=int(input())
N=10**4+20;M=103
a=[0 for _ in range(N)]
for x in range(1,M):
for y in range(1,M):
for z in range(1,M):
res=x*x+y*y+z*z+x*y+y*z+z*x;
if res<N:a[res]+=1
for i in range(n):
print(a[i+1])
| 0 | null | 4,020,948,126,650 | 20 | 106 |
(x, y, A, B, C) = map(int, raw_input().split())
ps = sorted(map(int, raw_input().split()), reverse=True)[:x]
qs = sorted(map(int, raw_input().split()), reverse=True)[:y]
cs = sorted(map(int, raw_input().split()))
tot = sum(ps) + sum(qs)
while cs and ((ps and cs[-1] > ps[-1]) or (qs and cs[-1] > qs[-1])):
if ps and qs:
if ps[-1] < qs[-1]:
tot -= ps.pop()
tot += cs.pop()
else:
tot -= qs.pop()
tot += cs.pop()
elif ps:
tot -= ps.pop()
tot += cs.pop()
elif qs:
tot -= qs.pop()
tot += cs.pop()
else:
break
# print ps, qs
print tot
|
X,Y,A,B,C=list(map(int,input().split()))
p=sorted(list(map(int,input().split())),reverse=True)
q=sorted(list(map(int,input().split())),reverse=True)
r=sorted(list(map(int,input().split())),reverse=True)
i=X-1
j=Y-1
k=0
ans=sum(p[:X])+sum(q[:Y])
while k<len(r):
if i>-1 and j>-1:
if p[i]<q[j]:
cmin=p[i]
i-=1
else:
cmin=q[j]
j-=1
if r[k]<=cmin:
break
ans+=r[k]-cmin
k+=1
elif i>-1:
cmin=p[i]
i-=1
if r[k]<=cmin:
break
ans+=r[k]-cmin
k+=1
elif j>-1:
cmin=q[j]
j-=1
if r[k]<=cmin:
break
ans+=r[k]-cmin
k+=1
else:
break
print(ans)
| 1 | 44,925,869,276,642 | null | 188 | 188 |
from collections import deque
n=int(input())
que_r=deque()
for i in range(n):
s=input()
l=len(s)
if s[0]=="i":
que_r.appendleft(s[7:])
elif s[6]==" ":
try:
que_r.remove(s[7:])
except: pass
elif l>10:
que_r.popleft()
elif l>6:
que_r.pop()
print(*que_r)
|
n,m = input().split()
n = int(n)
m = int(m)
print(int(n*(n-1)/2+m*(m-1)/2))
| 0 | null | 22,980,794,796,752 | 20 | 189 |
MAX = 10 ** 5 * 2
mod = 10 ** 9 + 7
frac = [1]
inv_frac=[1]
def pow(a, n):
if n == 0 : return 1
elif n == 1 : return a
tmp = pow(a, n//2)
tmp = (tmp * tmp) % mod
if n % 2 == 1 :
tmp = (tmp * a) % mod
return tmp
def inv(x):
return pow(x, mod - 2 )
for i in range(1,MAX + 1 ):
frac.append( (frac[-1] * i) % mod )
inv_frac.append(inv(frac[-1])%mod)
def comb(n, k):
if k >= n or k < 0 : return 1
return (frac[n]*inv_frac[n-k] * inv_frac[k]) %mod
n,k = map(int,input().split())
count=0
b=inv(n)
for i in range(min(n,k+1)):
a=comb(n,i)
count=(count+a*a*(n-i)*b)%mod
print(count)
|
MOD = 1000000007#い つ も の
n,k = map(int,input().split())
nCk = 1#nC0
ans = 1
if k > n-1:
k = n-1
for i in range(1,k+1,1):
nCk = (((nCk*(n-i+1))%MOD)*pow(i,1000000005,1000000007))%MOD
ans = (ans%MOD + ((((nCk*nCk)%MOD)*(n-i)%MOD)*pow(n,1000000005,1000000007)%MOD)%MOD)%MOD
print(ans)
| 1 | 67,000,025,811,246 | null | 215 | 215 |
m1, d1 = map(int, input().split())
m2, d2 = map(int, input().split())
print(1 if m2 == m1 % 12 + 1 and d2 == 1 else 0)
|
# A - November 30
def main():
M1, _, M2, _ = map(int, open(0).read().split())
print(int(M1 != M2))
if __name__ == "__main__":
main()
| 1 | 124,207,881,103,450 | null | 264 | 264 |
h, a = map(int, input().split())
print( - ( - h // a))
|
import sys
input = sys.stdin.readline
class SegTree():
# ここでは操作の都合上根元のindexを1とする
def __init__(self, lists, function, basement):
self.n = len(lists)
self.K = (self.n-1).bit_length()
self.f = function
self.b = basement
self.seg = [basement]*2**(self.K+1)
X = 2**self.K
for i, v in enumerate(lists):
self.seg[i+X] = v
for i in range(X-1, 0, -1):
self.seg[i] = self.f(self.seg[i << 1], self.seg[i << 1 | 1])
def update(self, k, value):
X = 2**self.K
k += X
self.seg[k] = value
while k:
k = k >> 1
self.seg[k] = self.f(self.seg[k << 1], self.seg[(k << 1) | 1])
def query(self, L, R):
num = 2**self.K
L += num
R += num
vL = self.b
vR = self.b
while L < R:
if L & 1:
vL = self.f(vL, self.seg[L])
L += 1
if R & 1:
R -= 1
vR = self.f(self.seg[R], vR)
L >>= 1
R >>= 1
return self.f(vL, vR)
def main():
N = int(input())
S = list(input())
Q = int(input())
que = [tuple(input().split()) for i in range(Q)]
alpha = "abcdefghijklmnopqrstuvwxyz"
Data = {alpha[i]: [0]*N for i in range(26)}
for i in range(N):
Data[S[i]][i] += 1
SEG = {alpha[i]: SegTree(Data[alpha[i]], max, 0) for i in range(26)}
for X, u, v in que:
if X == "1":
u = int(u)-1
NOW = S[u]
S[u] = v
SEG[NOW].update(u, 0)
SEG[v].update(u, 1)
else:
u, v = int(u)-1, int(v)-1
res = 0
for j in range(26):
res += SEG[alpha[j]].query(u, v+1)
print(res)
if __name__ == "__main__":
main()
| 0 | null | 69,560,950,783,100 | 225 | 210 |
# coding: utf-8
import numpy as np
from numba import i8, njit
@njit(i8[:](i8, i8[:]), cache=True)
def f(k, A):
n = len(A)
cur = A
for _ in range(k):
prev = cur
cur = np.zeros_like(A)
for x, p in enumerate(prev):
cur[max(0, x-p)] += 1
if x+p+1 < n:
cur[x+p+1] -= 1
satulated = True
for i in range(1, n):
cur[i] += cur[i-1]
satulated &= cur[i] == n
if satulated:
break
return cur
def solve(*args: str) -> str:
n, k = map(int, args[0].split())
A = np.array(tuple(map(int, args[1].split())))
return ' '.join(map(str, f(k, A)))
if __name__ == "__main__":
print(solve(*(open(0).read().splitlines())))
|
def main():
N, K = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(K):
B = [0] * (N + 1)
for i in range(N):
l = max(0,i-A[i])
r = min(N,i+A[i]+1)
B[l] += 1
B[r] -= 1
for i in range(N):
B[i+1] += B[i]
B.pop(-1)
if A == B:
break
A = B
print(*A)
if __name__ == "__main__":
main()
| 1 | 15,331,550,184,060 | null | 132 | 132 |
_, D1 = map(int, input().split())
_, D2 = map(int, input().split())
print(0 if D1 < D2 else 1)
|
# 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)
| 0 | null | 62,185,833,413,120 | 264 | 22 |
x = int(input())
print("Yes" if x >29 else "No")
|
from collections import Counter
N = int(input())
S = [input() for _ in range(N)]
# 方針:各文字列の出現回数を数え、出現回数が最大なる文字列を昇順に出力する
# Counter(リスト) は辞書型のサブクラスであり、キーに要素・値に出現回数という形式
# Counter(リスト).most_common() は(要素, 出現回数)というタプルを出現回数順に並べたリスト
S = Counter(S).most_common()
max_count = S[0][1] # 最大の出現回数
# 出現回数が最も多い単語を集計する
l = [s[0] for s in S if s[1] == max_count]
# 昇順にソートして出力
for i in sorted(l):
print(i)
| 0 | null | 37,803,539,503,708 | 95 | 218 |
A,B = map(int,input().split())
Flag = True
i = max(A,B)
s = max(A,B)
while Flag == True and i <= A*B:
if i%A ==0 and i%B == 0:
Flag = False
i += s
print(i-s)
|
n = int(input())
st = []
for _ in range(n):
si, ti = input().split()
st.append((si, int(ti)))
name = input()
count = 0
flag = False
for i in range(n):
if flag:
count += st[i][1]
if st[i][0] == name:
flag = True
print(count)
| 0 | null | 104,566,334,254,090 | 256 | 243 |
s=input()
times=int(input())
for _ in range(times):
order=input().split()
a=int(order[1])
b=int(order[2])
if order[0]=="print":
print(s[a:b+1])
elif order[0]=="reverse":
s=s[:a]+s[a:b+1][::-1]+s[b+1:]
else :
s=s[:a]+order[3]+s[b+1:]
|
n=int(input())
s=input()
ans=0
def my_index(l,x,default=-1):
if x in l:
return l.index(x)
else:
return default
for i in range(10**3):
i=str(i).zfill(3)
if my_index(s,i[0])!=-1:
s2=s[my_index(s,i[0])+1:]
if my_index(s2,i[1])!=-1:
s3=s2[my_index(s2,i[1])+1:]
if my_index(s3,i[2])!=-1:
ans+=1
print(ans)
| 0 | null | 65,637,546,079,420 | 68 | 267 |
A, B = input().split()
A = int(A)
B = int(B)
print(A * B)
|
from collections import deque
n = int(input())
d = deque()
for i in range(n):
c = input()
if ' ' in c:
c, num = c.split()
if c == 'insert':
d.appendleft(num)
elif c == 'delete' and num in d:
d.remove(num)
else:
if c == 'deleteFirst' and d:
d.popleft()
elif c == 'deleteLast' and d:
d.pop()
print(' '.join(d))
| 0 | null | 7,946,439,362,058 | 133 | 20 |
K=int(input())
A,B=map(int,input().split())
for i in range(A,B+1):
if i%K==0:
print('OK')
exit()
print('NG')
|
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)
o=c.most_common()
result=[0]*a
for i in range(len(o)):
result[o[i][0]-1]=o[i][1]
for i in result:
print(i)
| 0 | null | 29,703,341,869,040 | 158 | 169 |
x = int(input())
idx = 0
tmp = 0
while 1:
tmp += x
idx += 1
if tmp % 360 == 0:
break
print(idx)
|
N = int(input())
A = N // 2
B = N % 2
print(A + B)
| 0 | null | 35,923,248,927,748 | 125 | 206 |
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
d = defaultdict(int)
v = 0
ans = []
for a in A:
d[a] += 1
v += a
for i in range(Q):
B, C = map(int, input().split())
v += d[B] * (C - B)
d[C] += d[B]
d[B] = 0
ans.append(v)
for a in ans:
print(a)
|
N = int(input())
A = list(map(int, input().split()))
A_MAX = 10 ** 5
idx = [0] * (A_MAX + 1)
sum = 0
for i in A:
idx[i] += 1
sum += i
Q = int(input())
for i in range(Q):
B, C = list(map(int, input().split()))
sub = C - B
num = idx[B]
idx[B] = 0
idx[C] += num
sum += (sub * num)
print(sum)
| 1 | 12,174,786,487,876 | null | 122 | 122 |
N,M,K = map(int,input().split())
MOD = 998244353
MAXN = N+5
fac = [1,1] + [0]*MAXN
finv = [1,1] + [0]*MAXN
inv = [0,1] + [0]*MAXN
for i in range(2,MAXN+2):
fac[i] = fac[i-1] * i % MOD
inv[i] = -inv[MOD%i] * (MOD // i) % MOD
finv[i] = finv[i-1] * inv[i] % MOD
def comb(n,r):
if n < r: return 0
if n < 0 or r < 0: return 0
return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD
ans = 0
for i in range(K+1):
if i==N: break
n = N-i
ans += M * pow(M-1,n-1,MOD) * comb(N-1,i)
ans %= MOD
print(ans)
|
import collections
N = int(input())
A = list(map(int,input().split()))
a = collections.Counter(A)
for i in range(1,len(A)+2):
print(a[i])
| 0 | null | 28,026,565,436,508 | 151 | 169 |
N = int(input())
if N % 10 in [2, 4, 5, 7, 9]:
print("hon")
elif N % 10 in [0, 1, 6, 8]:
print("pon")
else:
print("bon")
|
num = list(map(int,input()))
if num[-1] == 3:
print("bon")
elif num[-1] in (0, 1, 6, 8):
print("pon")
else:
print("hon")
| 1 | 19,219,880,301,772 | null | 142 | 142 |
n = int(input())
a = list(map(int, input().split()))
t1 = 0
t2 = sum(a)
ans = 10**18
for i in a:
t1 += i
t2 -= i
ans = min(ans, abs(t1 - t2))
print(ans)
|
n = int(input())
a = [int(i) for i in input().split()]
b = []
sum_a = sum(a)
cum = 0
for i in a:
cum += i
b.append(abs(sum_a - cum * 2))
print(min(b))
| 1 | 142,096,225,749,130 | null | 276 | 276 |
from fractions import gcd
n, m = map(int, input().split())
lst = list(map(int, input().split()))
norm = 0
tmp = lst[0]
while tmp%2 == 0:
tmp = tmp//2
norm += 1
for i in range(n):
count = 0
tmp = lst[i]
while tmp%2 == 0:
tmp = tmp//2
count += 1
if norm != count:
print(0)
exit()
lst[i] = lst[i]//2
lst = sorted(list(set(lst)))
def lcm(a, b): # a, b の最大公約数を求める
return(a*b//gcd(a, b))
def lcms(List): # list[a[0], a[1], ... , a[n]]の最小公倍数を求める
if len(List) == 1:
return List[0]
ans = lcm(List[0], List[1])
for i in range(2, len(List)):
ans = lcm(ans, List[i])
return ans
lcm = lcms(lst)
ans = m//lcm
if ans%2 == 0:
ans = ans//2
else:
ans = ans//2 + 1
print(ans)
|
n, m = map( int, input().split() )
a = list( map( int, input().split() ) )
def f( a_k ): # 2で割り切れる回数
count = 0
while a_k % 2 == 0:
count += 1
a_k = a_k // 2
return count
b = []
f_0 = f( a[ 0 ] )
for a_k in a:
f_k = f( a_k )
if f_k != f_0:
print( 0 )
exit()
b.append( a_k // pow( 2, f_k ) )
import math
def lcm( x, y ):
return x * y // math.gcd( x, y )
b_lcm = 1
for b_k in b:
b_lcm = lcm( b_lcm, b_k )
a_lcm = b_lcm * pow( 2, f_0 )
# print( b_lcm, f_0, b )
print( ( m + a_lcm // 2 ) // a_lcm )
| 1 | 102,026,450,634,900 | null | 247 | 247 |
n = int(input())
s, t = map(str, input().split())
for i in range(n):
print(s[i]+t[i], end="")
|
N = int(input())
S, T = input().split()
answer = []
for s, t in zip(S, T):
answer.append(s)
answer.append(t)
print(*answer, sep='')
| 1 | 112,614,815,583,410 | null | 255 | 255 |
a,b,c=sorted(list(map(int, input().split())))
print("Yes" if (a==b and b!=c) or (a!=b and b==c) else "No")
|
a = int(input())
b = input().split()
c = []
for i in range(a * 2):
if i % 2 == 0:
c.append(b[0][i // 2])
else:
c.append(b[1][(i - 1) // 2])
for f in c:
print(f,end="")
| 0 | null | 90,206,646,180,700 | 216 | 255 |
n = int(input())
s = input()
cur = s[0]
ans = 0
# if cur*n==s:
# print(1)
# else:
for i in range(1,n):
if s[i]==cur:
pass
else:
cur = s[i]
ans+=1
ans+=1
print(ans)
|
import math
from math import gcd
INF = float("inf")
import sys
input=sys.stdin.readline
import itertools
from collections import Counter
def main():
n = int(input())
s = input().rstrip()
ans = [s[0]]
now = s[0]
for i in s[1:]:
if i != now:
ans.append(i)
now = i
print(len(ans))
if __name__=="__main__":
main()
| 1 | 170,217,081,302,398 | null | 293 | 293 |
def solve(N, S):
ans = 0
R, G, B = 0, 0, 0
for i in range(N):
if S[i] == "R":
R += 1
elif S[i] == "G":
G += 1
else:
B += 1
# print(R, G, B, R*G*B)
ans = R * G * B
dif = 1
while dif <= N//2+1:
idx = 0
while idx + dif + dif < N:
if S[idx] != S[idx + dif] and S[idx+dif] != S[idx+2*dif] and S[idx+2*dif] != S[idx]:
ans -= 1
idx += 1
dif += 1
print(ans)
if __name__ == '__main__':
# N = 4000
# S = 'RGBR' * 1000
N = int(input())
S = input()
solve(N, S)
|
def main():
n = int(input())
s = input()
r_set, g_set, b_set = set(), set(), set()
for i, c in enumerate(s):
if c == "R":
r_set.add(i)
elif c == "G":
g_set.add(i)
elif c == "B":
b_set.add(i)
cnt = 0
for j in range(1, n):
for i in range(j):
k = 2 * j - i
if k >= n:
continue
if s[i] == s[j] or s[j] == s[k] or s[k] == s[i]:
continue
cnt += 1
print(len(r_set) * len(g_set) * len(b_set) - cnt)
if __name__ == "__main__":
main()
| 1 | 36,207,318,858,390 | null | 175 | 175 |
N = int(input())
li = list()
for i in range(N):
li.append(input())
print(len(list(set(li))))
|
n = int(input())
s_array = [input() for _ in range(n)]
s_set = set(s_array)
print(len(s_set))
| 1 | 30,239,840,252,790 | null | 165 | 165 |
s=input()
for i in range(len(s)-1):
if s[i]!=s[i+1]:
print("Yes")
exit()
print("No")
|
from collections import Counter
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
N, P = map(int, readline().split())
S = [int(i) for i in readline().strip()[::-1]]
ans = 0
if P == 2 or P == 5:
for i, s in enumerate(S):
if s % P == 0:
ans += N - i
print(ans)
exit()
a = [0]
s = 0
for i in range(N):
s += S[i] * pow(10, i, P)
a.append(s % P)
t = Counter(a)
ans = 0
for v in t.values():
ans += v * (v-1) // 2
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 56,450,475,496,992 | 201 | 205 |
N=int(input())
A=[0]*N
B=[0]*N
for i in range(N):
A[i], B[i]=map(int, input().split())
A.sort()
B.sort()
if N%2==1:
print(B[N//2]-A[N//2]+1)
else:
print(B[N//2]+B[N//2-1]-A[N//2]-A[N//2-1]+1)
|
from math import sqrt
itl = lambda: list(map(float, input().strip().split()))
def median(N, C):
if N % 2:
return C[N // 2]
else:
return C[N // 2 - 1] + C[N // 2]
def solve():
N = int(input())
A = []
B = []
for _ in range(N):
a, b = itl()
A.append(int(a))
B.append(int(b))
A.sort()
B.sort()
ma = median(N, A)
mb = median(N, B)
return mb - ma + 1
if __name__ == '__main__':
print(solve())
| 1 | 17,368,281,673,908 | null | 137 | 137 |
import math
n = int(input())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
for p in range(1,4):
s = [math.fabs(x[i]-y[i])**p for i in range(n)]
z = math.pow(sum(s), 1/p)
print("{:.6f}".format(z))
t = [math.fabs(x[i]-y[i]) for i in range(n)]
print("{:.6f}".format(max(t)))
|
x = int(input())
h = x // 3600
m = (x -h*3600)//60
s = x - h*3600 - m*60
print(h, ':',m , ':', s, sep="")
| 0 | null | 272,476,211,072 | 32 | 37 |
import sys
def main():
input=sys.stdin.readline
S=input().strip()
dp=[[0,0] for i in range(len(S)+1)]
dp[0][1]=1
for i in range(1,len(S)+1):
for j in (0,1):
if j==0:
dp[i][0]=min(dp[i-1][0]+int(S[i-1]),dp[i-1][1]+10-int(S[i-1]))
elif j==1:
dp[i][1]=min(dp[i-1][0]+int(S[i-1])+1,dp[i-1][1]+10-int(S[i-1])-1)
print(dp[len(S)][0])
if __name__=="__main__":
main()
|
# 解説を見て解き直し
N, K = [int(x) for x in input().split()]
ranges = [tuple(int(x) for x in input().split()) for _ in range(K)]
ranges.sort()
p = 998244353
dp = [0] * (N + 1)
dpsum = [0] * (N + 1)
dp[1] = 1
dpsum[1] = 1
for i in range(2, N + 1):
for l, r in ranges:
rj = i - l
lj = max(1, i - r) # 1以上
if rj <= 0: continue
dp[i] += dpsum[rj] - dpsum[lj - 1]
dp[i] %= p
dpsum[i] = dpsum[i - 1] + dp[i]
dpsum[i] %= p
print(dp[N])
| 0 | null | 36,815,141,648,050 | 219 | 74 |
def f():
n,k=map(int,input().split())
l=list(map(int,input().split()))
now=1
for d in range(k.bit_length()):
k,f=divmod(k,2)
if f:now=l[now-1]
l=tuple(l[i-1]for i in l)
print(now)
if __name__ == "__main__":
f()
|
case_num = 1
while True:
tmp_num = int(input())
if tmp_num == 0:
break
else:
print("Case %d: %d" % (case_num,tmp_num))
case_num += 1
| 0 | null | 11,720,970,473,212 | 150 | 42 |
# ABC178D Manhattan
n = int(input())
z = []
w = []
for i in range(n):
x,y = map(int, input().split())
z.append(x-y)
w.append(x+y)
z_ans = max(z)-min(z)
w_ans = max(w)-min(w)
print(max(z_ans,w_ans))
|
N = int(input())
xs, ys = [], []
for _ in range(N):
x, y = map(int, input().split())
xs.append(x)
ys.append(y)
A = [x + y for x, y in zip(xs, ys)]
B = [x - y for x, y in zip(xs, ys)]
ans = max([max(A) - min(A), max(B) - min(B)])
print(ans)
| 1 | 3,404,659,788,840 | null | 80 | 80 |
n = int(input())
a = list(map(int, input().split()))
t = 1
ans = 0
for i in range(n):
if t != a[i]:
ans += 1
a[i] = -1
else:
t += 1
if all([i == -1 for i in a]):
print(-1)
else:
print(ans)
|
n = int(input())
a = list(map(int, input().split()))
b = [x*x for x in a]
#print(a)
#print(b)
s = sum(a)
s = s * s - sum(b)
s = s // 2
s = s % 1000000007
print(s)
# (a+b+c)^2 = a^2 + b^2 + c^2 + 2ab + 2ac + 2bc
| 0 | null | 59,446,707,171,852 | 257 | 83 |
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
A, B = mapint()
if 1<=A<=9 and 1<=B<=9:
print(A*B)
else:
print(-1)
|
r = int(input()) % 1000
print((1000 - r) % 1000)
| 0 | null | 83,687,506,887,488 | 286 | 108 |
# ALDS_2_B.
# バブルソート。
from math import sqrt, floor
def intinput():
a = input().split()
for i in range(len(a)):
a[i] = int(a[i])
return a
def show(a):
# 配列の中身を出力する。
_str = ""
for i in range(len(a) - 1):
_str += str(a[i]) + " "
_str += str(a[len(a) - 1])
print(_str)
def selection_sort(a):
# 選択ソート。その番号以降の最小値を順繰りにもってくる。
# 交換回数は少ないが比較回数の関係で結局O(n^2)かかる。
count = 0
for i in range(len(a)):
# a[i]からa[len(a) - 1]のうちa[j]が最小っていうjを取る。
# このときiとjが違うならカウントする。
# というかa[i]とa[j]が違う時カウントでしたね。
minj = i
for j in range(i, len(a)):
if a[j] < a[minj]: minj = j
if a[i] > a[minj]: count += 1; a[i], a[minj] = a[minj], a[i]
return count
def main():
N = int(input())
A = intinput()
count = selection_sort(A)
show(A); print(count)
if __name__ == "__main__":
main()
|
#python2.7
N=input()
A=map(int,raw_input().split())
num=0
for i in range(N):
minj=i
for j in range(N-i):
if A[j+i] < A[minj]:
minj=j+i
if i != minj:
A[i],A[minj]=A[minj],A[i]
num+=1
for m in range(N-1):
print str(A[m]),
print A[N-1]
print num
| 1 | 19,936,459,408 | null | 15 | 15 |
from fractions import gcd
n, m = [int(x) for x in input().split()]
a_list = [int(x) for x in input().split()]
a_h_list = [a // 2 for a in a_list]
count = set()
for a_h in a_h_list:
temp = bin(a_h)
count.add(len(temp) - temp.rfind("1"))
if len(count) == 1:
temp = 1
for a_h in a_h_list:
temp *= a_h // gcd(a_h, temp)
ans = (m // temp + 1) // 2
else:
ans = 0
print(ans)
|
import math
import sys
n,m = map(int, input().split())
a = list(map(int, input().split()))
def gcd(x,y):
if x < y:
x,y = y,x
while x%y != 0:
x,y = y,x%y
return y
def lcm(x,y):
return x/gcd(x,y)*y
def f(x):
count = 0
while x%2 == 0:
x /= 2
count += 1
return count
for i in range(n):
if a[i]%2 == 1:
print(0)
sys.exit()
a[i] /= 2
count = f(a[0])
for i in range(n):
if f(a[i]) != count:
print(0)
sys.exit()
a[i] /= 2**count
m /= 2**count
l = 1
for i in range(n):
l = lcm(l,a[i])
if l > m:
print(0)
sys.exit()
m /= l
ans = (m+1)/2
print(int(ans))
| 1 | 101,849,396,141,248 | null | 247 | 247 |
import sys
input = sys.stdin.readline
n,m,l = map(int,input().split())
town = [list(map(int,input().split())) for _ in range(m)]
q = int(input())
query = [list(map(int,input().split())) for _ in range(q)]
inf = (l+1)*n
d = [[inf]*n for _ in range(n)]
for i in range(n):
d[i][i] = 0
for a,b,c in town:
a -= 1
b -= 1
d[a][b] = c
d[b][a] = c
def warshall_floyd(d,n):
for k in range(n):
for j in range(n):
for i in range(n):
d[i][j] = min(d[i][j],d[i][k]+d[k][j])
warshall_floyd(d,n)
d2 = [None]*n
for i,row in enumerate(d):
d2[i] = [1 if val<=l else inf for val in row]
d2[i][i] = 0
warshall_floyd(d2,n)
for s,t in query:
s -= 1
t -= 1
count = (d2[s][t]%inf)-1
print(count)
|
N = int(input())
A = list(map(int, input().split()))
"""
indexのi,jについて、 j - i = A[i] + A[j] になる組の数を数え上げる。
愚直にやると、i,jを全ペアためす。N(O^2)で間に合わない
二つの変数が出てきて、ある式で関係性が表せる場合は、iの式 = jの式 みたいにしてやるとうまくいきことが多い
j - i = A[i] + A[j]
-> A[i] + i = j - A[j]
なので、各参加者について、iとして使う時とjとして使うときで分けて数えていって、最後に組の数を数え上げる
A[i], i >=1 なので、2以上
1 <= j <= N, A[j] >= 1 なので、N未満
の範囲を調べればよい
"""
from collections import defaultdict
I = defaultdict(int)
J = defaultdict(int)
for i in range(N):
I[A[i] + i+1] += 1
J[i+1 - A[i]] += 1
ans = 0
for i in range(2, N):
ans += I[i] * J[i]
print(ans)
| 0 | null | 100,044,776,410,140 | 295 | 157 |
# coding: utf-8
def main():
N = int(input())
A = list(map(int, input().split()))
B = [[a, i + 1] for i, a in enumerate(A)]
B.sort()
for i, j in B:
if i == N:
print(j)
else:
print(j, "", end='')
if __name__ == "__main__":
main()
|
n=int(input())
A=list(map(int,input().split()))
r = [-1]*n
for i,a in enumerate(A):
r[a-1]=i+1
for r2 in r:
print(r2)
| 1 | 180,524,131,663,170 | null | 299 | 299 |
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))
P.sort(reverse=True)
Q.sort(reverse=True)
temp = P[:X] + Q[:Y] + R
temp.sort(reverse=True)
ans = sum(temp[:X+Y])
print(ans)
|
a,b,c=map(int,input().split(' '))
a,b,c=c,a,b
print(str(a)+" "+str(b)+" "+str(c))
| 0 | null | 41,546,006,184,452 | 188 | 178 |
n = int(input())
tp = 0
hp = 0
for i in range(n):
tarou, hanako = map(str,input().split())
if(tarou > hanako):
tp += 3
elif(tarou < hanako):
hp += 3
else:
tp += 1
hp += 1
print("%d %d" %(tp,hp))
|
n = int(input())
x = 0
y = 0
for _ in range(n):
a,b=input().split()
if a < b:
y+=3
elif a ==b:
x+=1
y+=1
else:
x+=3
print (x,y)
| 1 | 1,992,580,716,800 | null | 67 | 67 |
X= int(input())
if(X>=400 and X<=599):
print(8)
elif(X>599 and X<800):
print(7)
elif(X>=800 and X<1000):
print(6)
elif(X>=1000 and X<1200):
print(5)
elif(X>=1200 and X<1400):
print(4)
elif(X>=1400 and X<1600):
print(3)
elif(X>=1600 and X<1800):
print(2)
elif(X>=1800 and X<2000):
print(1)
|
# coding: utf-8
# Your code here!
N,K=map(int,input().split())
A=list(map(float, input().split()))
low=0
high=10**9+1
while high-low!=1:
mid=(high+low)//2
cut_temp=0
ans=-1
for a in A:
cut_temp+=-(-a//mid)-1
if cut_temp>K:
low=mid
else:
high=mid
print(high)
| 0 | null | 6,640,118,995,808 | 100 | 99 |
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy
def main():
n = int(input())
ans = 0
for i in range(1,n):
ans += (n-1)//i
print(ans)
if __name__ == "__main__":
main()
|
num = int(raw_input())
line = raw_input()
A = line.strip().split(" ")
print " ".join(A)
#A = map(int, item_str)
for i in range(1, num):
v = int(A[i])
j = i - 1
for j in range(j, -1, -1):
if int(A[j]) > v:
A[j+1] = A[j]
j -= 1
else:
break
A[j+1] = str(v)
#A_str = map(str, A)
print " ".join(A)
| 0 | null | 1,325,675,222,600 | 73 | 10 |
#設定
import sys
input = sys.stdin.buffer.readline
#ライブラリインポート
from collections import defaultdict
con = 10 ** 9 + 7
#入力受け取り
def getlist():
return list(map(int, input().split()))
#処理内容
def main():
N = int(input())
ansL = [[] for i in range(10)]
ansL[0].append(["a", 1])
for i in range(N - 1):
n = len(ansL[i])
for j in range(n):
for k in range(ansL[i][j][1]):
ansL[i + 1].append([ansL[i][j][0] + chr(97 + k), ansL[i][j][1]])
ansL[i + 1].append([ansL[i][j][0] + chr(97 + ansL[i][j][1]), ansL[i][j][1] + 1])
n = len(ansL[N - 1])
for i in range(n):
print(ansL[N - 1][i][0])
if __name__ == '__main__':
main()
|
A11, A12, A13 = map(int, input().split())
A21, A22, A23 = map(int, input().split())
A31, A32, A33 = map(int, input().split())
N = int(input())
B = {int(input()) for _ in range(N)}
h1 = {A11, A12, A13}
h2 = {A21, A22, A23}
h3 = {A31, A32, A33}
v1 = {A11, A21, A31}
v2 = {A12, A22, A32}
v3 = {A13, A23, A33}
c1 = {A11, A22, A33}
c2 = {A13, A22, A31}
if len(h1 & B)==3 or len(h2 & B)==3 or len(h3 & B)==3 or len(v1 & B)==3 or len(v2 & B)==3 or len(v3 & B)==3 or len(c1 & B)==3 or len(c2 & B)==3:
print("Yes")
else:
print("No")
| 0 | null | 55,878,783,966,448 | 198 | 207 |
import collections
def searchRoot(n):
par = parList[n]
if n == par:
if len(q) > 0:
rootIn(q,n)
return n
else:
q.append(n)
return(searchRoot(par))
def rootIn(q,root):
while len(q) > 0:
parList[q.popleft()] = root
n,m = list(map(int,input().split()))
q = collections.deque()
parList = [i for i in range(n+1)]
for i in range(m):
a,b = list(map(int,input().split()))
aRoot = searchRoot(a)
bRoot = searchRoot(b)
if aRoot != bRoot:
parList[max(aRoot,bRoot)] = min(aRoot,bRoot)
#print(parList)
ansDic = dict()
rootSet = set()
for i in range(1,n+1):
root = searchRoot(i)
if root in rootSet:
ansDic[root] += 1
else:
rootSet.add(root)
ansDic[root] = 1
ans = 1
for i in rootSet:
if ansDic[i] > ans:
ans = ansDic[i]
print(ans)
|
INPUT = input().split()
D = int(INPUT[0])
T = int(INPUT[1])
S = int(INPUT[2])
if D/S <= T:
print("Yes")
else:
print("No")
| 0 | null | 3,751,537,365,540 | 84 | 81 |
#F
def divisor(n):
ass = []
for i in range(1,int(n**0.5)+1):
if n%i == 0:
ass.append(i)
if i**2 == n:
continue
ass.append(n//i)
return ass
n=int(input())
ans1=divisor(n-1)
ans1.remove(1)
as0=divisor(n)
ans0=[]
for x in as0:
if x!=1:
m=n
while m>=x and m%x==0:
m=m//x
if m%x==1:
ans0.append(x)
ans=set(ans0)|set(ans1)
ans=list(ans)
print(len(ans))
"""
ans.sort()
print(ans)
for x in ans:
m=n
while m%x==0:
m=m//x
print(x,m%x)
"""
|
from math import sqrt, log
def factor(number):
i = 2
s = set()
while i * i <= number:
if number % i == 0:
if i != 2:
s.add(i)
if (number // i) != 2:
s.add(number//i)
i += 1
return s
def newFactor(number):
n = number
i = 2
ans = set()
while i * i <= number:
if number % i == 0:
while number % i == 0:
number //= i
if number % i == 1:
ans.add(i)
number = n
i += 1
return ans
n = int(input())
if n == 2:
print(1)
exit()
if n == 3:
print(2)
exit()
s = set()
s.add(2)
s.add(n-1)
s.add(n)
s = s.union(factor(n-1))
s = s.union(newFactor(n))
print(len(s))
| 1 | 41,279,333,353,062 | null | 183 | 183 |
from collections import deque
import sys
n = int(input())
deq = deque()
sub_deq = {}
for cmd in sys.stdin.readlines():
if cmd == 'deleteFirst\n':
while deq:
data = deq.pop()
if data[1]:
data[1] = 0
break
elif cmd == 'deleteLast\n':
while deq:
data = deq.popleft()
if data[1]:
data[1] = 0
break
else:
cmd, val = cmd.split()
if cmd == 'insert':
data = [val, 1]
deq.append(data)
if val not in sub_deq:
sub_deq[val] = [data]
else:
sub_deq[val].append(data)
elif cmd == 'delete':
if val in sub_deq:
deq_v = sub_deq[val]
while deq_v:
data = deq_v.pop()
if data[1]:
data[1] = 0
break
sys.stdout.write(" ".join(data[0] for data in reversed(deq) if data[1]))
sys.stdout.write('\n')
|
# collections.deque is implemented using doubly linked list at C level..
from collections import deque
linkedlist = deque()
for _ in range(int(input())):
input_command = input()
if input_command == 'deleteFirst':
linkedlist.popleft()
elif input_command == 'deleteLast':
linkedlist.pop()
else:
com, num = input_command.split()
if com == 'insert':
linkedlist.appendleft(num)
elif com == 'delete':
try:
linkedlist.remove(num)
except:
pass
print(' '.join(linkedlist))
| 1 | 48,679,259,328 | null | 20 | 20 |
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
max_a = max(A)
max_f = max(F)
left = 0
right = max_a * max_f
while left <= right:
x = (left + right) // 2
sum_ = 0
for i in range(N):
if A[i] * F[i] > x:
sum_ += (A[i] - int(x / F[i]))
if sum_ > K:
left = x + 1
if sum_ <= K:
right = x - 1
print(left)
|
n=int(input())
a=[int(x) for x in input().rstrip().split()]
a.sort()
ma=max(a)
dp=[0]*ma
for i in a:
dp[i-1]+=1
l=[0]*ma
ans=0
for i in a:
j=i
if l[i-1]==0 and dp[i-1]==1:
ans+=1
while(j<=ma):
l[j-1]+=1
if j+i<=ma:
j+=i
else:
break
print(ans)
| 0 | null | 89,953,440,665,532 | 290 | 129 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.