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
|
---|---|---|---|---|---|---|
import sys
input_line = sys.stdin.readline()
input_arr = input_line.split()
x = int(input_arr[0])
y = int(input_arr[1])
print str(x*y) + " " + str(2*x+2*y)
|
a, b = map(int, input().split())
print(str(a * b) + " " + str(2 * a + 2 * b))
| 1 | 297,614,116,996 | null | 36 | 36 |
n,k=map(int,input().split())
i=0
while n//k**(i+1)>=1:
i+=1
print(i+1)
|
n,k = map(int,input().split())
for i in range(10**9):
if n < k**i:
print(i)
exit()
| 1 | 64,042,325,196,540 | null | 212 | 212 |
n = int(input())
ans = 0
for a in range(1, n+1):
b=1
while n-a*b>0:
ans += 1
b+=1
print(ans)
|
N=int(input())
ans=0
for a in range(1,N):
q,m=divmod(N,a)
ans+=(N//a)-(m==0)
print(ans)
| 1 | 2,606,144,282,110 | null | 73 | 73 |
x,y = map(int,input().split())
if y % 2 != 0:
print('No')
elif x * 2 <= y <= x * 4:
print('Yes')
else:
print('No')
|
import sys
x,y = map(int,input().split())
for n in range(x+1):
kame = x - n
tsuru_leg = n*2
kame_leg = kame*4
if y == tsuru_leg + kame_leg:
print('Yes')
sys.exit()
print('No')
| 1 | 13,659,661,324,882 | null | 127 | 127 |
for x in range(1, 10):
for y in range(1, 10):
print(x , "x" , y , "=" , x*y, sep = "")
|
from __future__ import absolute_import, print_function, unicode_literals
for a in xrange(1, 10):
for b in xrange(1, 10):
print('{}x{}={}'.format(a, b, a * b))
| 1 | 219,286 | null | 1 | 1 |
n = int(input())
a = [int(i) for i in input().split()]
ball_count = [0] * (n + 1)
for i in a:
ball_count[i] += 1
def nCr(i):
if i<=1:
return 0
else:
return i*(i-1)//2
def get_total(ball_count):
ans = 0
for i in ball_count:
ans += nCr(i)
return ans
total = get_total(ball_count)
for i in range(1, n + 1):
num = ball_count[a[i - 1]]
ans = total - nCr(num) + nCr(num-1)
print(ans)
|
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
c=Counter(A)
s=0
for v in c.values():
s+=v*(v-1)//2
for i in range(n):
ans=s-(c[A[i]])+1
print(ans)
| 1 | 47,932,695,353,232 | null | 192 | 192 |
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip.split())
def main():
sys.setrecursionlimit(10**5)
n = I()
s = S()
global cnt
cnt = 0
def tansaku(st,depth):
global cnt
for i in range(10):
index = st.find(str(i))
if index != -1:
if depth == 0:
cnt += 1
# print(i)
# print(st,i,index,depth)
else:
tansaku(st[index+1:],depth-1)
tansaku(s,2)
print(cnt)
main()
|
N=int(input())
div = [0] * (N+1)
for d in range(1, N+1):
for n in range(d, N, d):
div[n] += 1
ans = sum(div[:N])
print(ans)
| 0 | null | 65,282,112,835,292 | 267 | 73 |
n = int(input())
array = list(map(int,input().split()))
q = int(input())
sums = sum(array)
cnt = [0]*(10**5+1)
for i in array:
cnt[i] += 1
for j in range(q):
b,c = map(int,input().split())
sums += cnt[b]*(c-b)
cnt[c] += cnt[b]
cnt[b] = 0
print(sums)
|
n = int(input())
A = list(map(int, input().split()))
S = sum(A)
D = {c:0 for c in range(1, 10**5+1)}
for a in A:
D[a] += 1
for _ in range(int(input())):
B, C = map(int, input().split())
S += (C-B)*D[B]
D[C] += D[B]
D[B] = 0
print(S)
| 1 | 12,170,977,820,858 | null | 122 | 122 |
def main():
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
sieve = [False for _ in range(1000001)]
for i in range(n):
if sieve[a[i]]:
continue
for j in range(a[i], 1000001, a[i]):
sieve[j] = True
if i > 0:
if a[i] == a[i-1]:
continue
if i < n-1:
if a[i] == a[i+1]:
continue
ans += 1
print(ans)
if __name__ == '__main__':
main()
|
n = int(input())
lst = [int(i) for i in input().split()]
lst.sort()
#print(lst)
if 1 in lst:
count = 0
for i in range(n):
if lst[i] == 1:
count += 1
if count == 2:
break
if count == 1:
print(1)
else:
print(0)
else:
tf_lst = [1] * lst[n - 1]
count = 0
if n > 1:
pre = 0
for i in range(n):
tf_lst[pre:lst[i] - 1] = [0] * (lst[i] - pre - 1)
pre = lst[i]
if tf_lst[lst[i] - 1] == 0:
continue
if i <= n - 2:
if lst[i] == lst[i + 1]:
tf_lst[lst[i] - 1] = 0
for j in range(lst[i] * 2, lst[n - 1] + 1, lst[i]):
tf_lst[j - 1] = 0
#print(tf_lst)
for i in tf_lst:
count += i
else:
count += 1
print(count)
| 1 | 14,436,852,861,120 | null | 129 | 129 |
from math import sqrt
n=int(input())
ans=float('inf')
for i in range(1,int(sqrt(n))+1):
if n%i==0:
res=i+n//i-2
ans=min(ans,res)
print(ans)
|
import math
N = int(input())
N_ = int(math.sqrt(N)) + 1
min_distance = N - 1
for i in range(1, N_):
p, r = divmod(N, i)
if r == 0:
if 1 <= p <= N:
distance = (i-1) + (p-1)
min_distance = min(min_distance, distance)
else:
continue
print(min_distance)
| 1 | 161,658,761,621,842 | null | 288 | 288 |
numbers = input()
numbers = numbers.split(" ")
W = int(numbers[0])
H = int(numbers[1])
x = int(numbers[2])
y = int(numbers[3])
r = int(numbers[4])
if (r <= x <= W - r) and (r <= y <= H - r):
print("Yes")
else:
print("No")
|
H, W, M = map(int, input().split())
row = [0] * (H + 1)
col = [0] * (W + 1)
bom = []
for i in range(M):
h, w = map(int, input().split())
bom.append([h, w])
row[h] += 1
col[w] += 1
rmax = max(row)
cmax = max(col)
cnt = row.count(rmax) * col.count(cmax)
for h, w in bom:
if rmax == row[h] and cmax == col[w]:
cnt -= 1
print(rmax + cmax - (cnt == 0))
| 0 | null | 2,592,894,309,220 | 41 | 89 |
f=lambda:map(int,input().split())
N,K=f()
r,s,p=f()
T=list(input())
F=[0]*N
res=0
for i in range(N):
if F[i]==1:
continue
if i+K<N:
if T[i]==T[i+K]:
F[i+K]=1
if T[i]=='s':
res+=r
elif T[i]=='p':
res+=s
else:
res+=p
print(res)
|
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
points = {'r': P, 's': R, 'p': S}
is_changed = [False] * K + [False] * (N - K)
score = 0
for i in range(K):
score += points[T[i]]
for i in range(K, N):
if T[i] == T[i - K] and not is_changed[i - K]:
is_changed[i] = True
else:
score += points[T[i]]
print(score)
| 1 | 106,960,763,130,968 | null | 251 | 251 |
import sys
sys.setrecursionlimit(10**7)
readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))
from math import ceil
h,w = readints()
s = [readstr() for i in range(h)]
dp = [[0]*w for i in range(h)]
if s[0][0] == '.':
dp[0][0] = 0
else:
dp[0][0] = 1
for i in range(1,h):
if s[i][0] != s[i-1][0]:
dp[i][0] = dp[i-1][0] + 1
else:
dp[i][0] = dp[i-1][0]
for i in range(1,w):
if s[0][i] != s[0][i-1]:
dp[0][i] = dp[0][i-1] + 1
else:
dp[0][i] = dp[0][i-1]
for i in range(1,h):
for j in range(1,w):
if s[i][j] != s[i-1][j]:
dp[i][j] = dp[i-1][j] + 1
else:
dp[i][j] = dp[i-1][j]
if s[i][j] != s[i][j-1]:
dp[i][j] = min(dp[i][j-1] + 1,dp[i][j])
else:
dp[i][j] = min(dp[i][j-1],dp[i][j])
print(ceil(dp[-1][-1]/2))
|
H,W = (int(x) for x in input().split())
lines = [input() for i in range(H)]
dp = [[0] * W for _ in range(H)]
if lines[0][0] == "#":
dp[0][0] = 1
q = r = dp[0][0]
for i in range(H):
for j in range(W):
if i == j == 0: continue
if j > 0:
q = dp[i][j-1]
if lines[i][j] == "#" and lines[i][j-1] == ".":
q = dp[i][j-1] + 1
if i > 0:
r = dp[i-1][j]
if lines[i][j] == "#" and lines[i-1][j] == ".":
r = dp[i-1][j] + 1
if j == 0:
dp[i][j] = r
elif i == 0:
dp[i][j] = q
else:
dp[i][j] = min(q,r)
print(dp[H-1][W-1])
| 1 | 49,208,218,869,810 | null | 194 | 194 |
N=int(input())
l=[]
S=[input() for _ in range(N)]
S=list(set(S))
print(len(S))
|
while True:
s = raw_input()
if s == '0':
break
n = 0
for i in s:
n += int(i)
print n
| 0 | null | 15,798,306,183,360 | 165 | 62 |
n = int(input())
#lis = list(map(int,input().split()))
for i in range(1,10):
q = n // i
r = n % i
if r == 0 and q < 10:
print("Yes")
exit()
print("No")
|
import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
n, m = list(map(int, readline().split()))
s = str(readline().rstrip().decode('utf-8'))
res = []
start = n
while True:
b = False
for j in range(max(0, start - m), start):
if s[j] == "0":
res.append(start - j)
start = j
b = True
break
if not b:
print(-1)
exit()
else:
if j == 0:
res.reverse()
print(*res)
exit()
if __name__ == '__main__':
solve()
| 0 | null | 148,916,928,609,460 | 287 | 274 |
from collections import Counter
N=int(input())
S=input()
c=Counter(S+'RGB')
ans = (c['R']-1)*(c['G']-1)*(c['B']-1)
max_d = (N-3)//2+1
for d in range(1,max_d+1):
for i in range(N-2):
j = i+d
k = j+d
if k > N-1:break
if len(set([S[i],S[j],S[k]]))==3:
ans -= 1
print(ans)
|
n = int(input())
s = input()
r = s.count('R')
g = s.count('G')
b = s.count('B')
cnt = 0
for i in range(n):
j = 1
while i + 2*j <= n-1:
if s[i] != s[i+j] and s[i+j] != s[i+2*j] and s[i+2*j] != s[i]:
cnt += 1
j += 1
print(r*g*b-cnt)
| 1 | 36,254,442,365,692 | null | 175 | 175 |
S=input()
if(S.isupper()):
print('A')
else:
print('a')
|
a = input()
if a.isupper():
print('A')
else:
print('a')
| 1 | 11,284,529,708,090 | null | 119 | 119 |
from collections import defaultdict
n = int(input())
results = defaultdict(lambda: 0)
for _ in range(n):
s = input()
results[s] += 1
for judge in ['AC', 'WA', 'TLE', 'RE']:
print(judge, ' x ', results[judge])
|
import numpy as np
N, T = map(int, input().split())
menu = []
for _ in range(N):
m = tuple(map(int, input().split()))
menu.append(m)
menu = sorted(menu, key=lambda m: m[0])
# 料理i-1をj-1分までに完食するときの満足度最大値
dp = np.zeros((N, T), dtype='int64')
anss = []
for i in range(1, N):
# 一つまえのメニューについて
ai, bi = menu[i-1]
dp[i][:ai] = dp[i-1][:ai] # 時間が足りないので注文しない
dp[i][ai:] = np.fmax(
dp[i-1][ai:], # 何も注文しない
dp[i-1][:-ai] + bi # 注文した場合, ai分かかっても大丈夫な範囲から取得
)
# 加えて自身を最後に食べた場合を記録
anss.append(dp[i][-1] + menu[i][1])
print(max(anss))
| 0 | null | 79,781,127,724,156 | 109 | 282 |
import sys
import math
def main():
r = float(sys.stdin.readline())
print(math.pi * r**2, 2 * math.pi * r)
return
if __name__ == '__main__':
main()
|
r = float(input())
pi = 3.141592653589793
print(pi*r**2, 2*pi*r)
| 1 | 633,117,602,630 | null | 46 | 46 |
a, b = map(int, input().split())
c = str(a)*b
d = str(b)*a
my_list = [c, d]
my_list.sort()
print(my_list[0])
|
s = input()
t = input()
s_len = len(s)
t_len = len(t)
out = t_len
for i in range(0, s_len - t_len + 1):
diff = 0
for j in range(0, t_len):
if t[j] != s[i + j]:
diff += 1
out = min(out, diff)
print(out)
| 0 | null | 43,908,936,796,020 | 232 | 82 |
#!/usr/bin/env python3
import sys
input = sys.stdin.buffer.readline
N = int(input())
A = list(map(int,input().split()))
XY = list()
for i in range(N):
XY.append((A[i], i+1))
XY.sort()
Ans = list()
for x,y in XY:
Ans.append(y)
print(*Ans)
|
n=int(input());a=list(map(int,input().split()));dict={i+1:a[i] for i in range(n)}
print(*[i[0] for i in sorted(dict.items(),key=lambda x:x[1])],sep=' ')
| 1 | 180,608,894,482,402 | null | 299 | 299 |
import math
x, y = map(int, input().split())
MOD = 10**9+7
def combination(n, r, mod):
r = min(r, n-r)
num = 1
d = 1
for i in range(1, r+1):
num = num * (n+1-i) % mod
d = d * i % mod
return num * pow(d, mod-2, mod) % mod
if (x+y)%3 != 0:
print (0)
exit()
n = (x+y)/3
yy = (2*x-y)/3
xx = (2*y-x)/3
if yy < 0:
print (0)
exit()
if xx < 0:
print (0)
exit()
if xx.is_integer() and yy.is_integer():
print (combination(int(xx+yy),int(xx),MOD))
else:
print (0)
|
from math import factorial as fac
x,y=map(int,input().split())
a=2*y-x
b=2*x-y
mod=10**9+7
if a>=0 and b>=0 and a%3==0 and b%3==0:
a=a//3
b=b//3
a1=1
a2=1
n3=10**9+7
for i in range(a):
a1*=a+b-i
a2*=i+1
a1%=n3
a2%=n3
a2=pow(a2,n3-2,n3)
print((a1*a2)%n3)
else:
print(0)
| 1 | 150,137,984,274,348 | null | 281 | 281 |
MOD = int(1e9) + 7
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(60):
cnt = 0
for j in range(n):
if a[j] >> i & 1 == 1:
cnt += 1
ans += (cnt * (n-cnt) * (2**i)) % MOD
ans %= MOD
print(ans)
|
import math , sys
N = int( input() )
A = list(map(int, input().split() ) )
def Prime(x):
ub=int(math.sqrt(x))+2
if x==2 or x==3 or x==5 or x==7:
return True
for i in range(2,ub):
if x%i==0:
return False
return True
y = N
while not Prime(y):
y+=1
def h1(x):
return x % y
def h2(x):
return 1+ x%(y-1)
def h(x,i):
return (h1(x) + i*h2(x)) % y
def insert(T,x):
i=0
while True:
j=h(x,i)
if T[j][0]== -1:
T[j][0]=x
T[j][1]=1
return j
elif x ==T[j][0]:
T[j][1]+=1
return j
else:
i+=1
def search(T,x):
i=0
while True:
j=h(x,i)
if T[j][0] == x:
return T[j][1]
elif T[j][0] == -1:
return -1
else:
i+=1
T = [[-1,0] for _ in range(y)]
for i in range(N):
insert(T , i + A[i])
ans =0
for j in range(N):
if j - A[j]>=0:
s = search(T, j - A[j])
if s >=0:
ans+=s
print(ans)
| 0 | null | 74,719,896,804,000 | 263 | 157 |
# similar to problem if n person are arranged in a row and have 3 different hats to wear
# no of ways of wearing hats so that every adjacent person wears different hats
# so ith person cannot wear more than 3 no of different ways
mod = 10**9+7
def main():
ans =1
n = int(input())
arr = list(map(int , input().split()))
col=[0 for i in range(0 , 6)]
for i in range(0 , n):
cnt , cur =0 , -1
if arr[i]==col[0]:
cnt = cnt+1
cur = 0
if arr[i]==col[1]:
cnt = cnt+1
cur = 1
if arr[i]==col[2]:
cnt = cnt+1
cur = 2
if cur ==-1:
print(0)
exit()
col[cur]=col[cur]+1
ans = (ans*cnt)%mod
ans = ans%mod
print(ans)
if __name__ =="__main__":
main()
|
MOD = 10 ** 9 + 7
class ModFactorial:
"""
階乗, 組み合わせ, 順列の計算
"""
def __init__(self, n, MOD=10 ** 9 + 7):
"""
:param n: 最大の要素数.
:param MOD:
"""
kaijo = [0] * (n + 10)
gyaku = [0] * (n + 10)
kaijo[0] = 1
kaijo[1] = 1
for i in range(2, len(kaijo)):
kaijo[i] = (i * kaijo[i - 1]) % MOD
gyaku[0] = 1
gyaku[1] = 1
for i in range(2, len(gyaku)):
gyaku[i] = pow(kaijo[i], MOD - 2, MOD)
self.kaijo = kaijo
self.gyaku = gyaku
self.MOD = MOD
def nCm(self, n, m):
return (self.kaijo[n] * self.gyaku[n - m] * self.gyaku[m]) % self.MOD
def nPm(self, n, m):
return (self.kaijo[n] * self.gyaku[n - m]) % self.MOD
def factorial(self, n):
return self.kaijo[n]
N, K = [int(_) for _ in input().split()]
modf = ModFactorial(N)
A = [int(_) for _ in input().split()]
A.sort()
i = 1
maxv = 0
for i in range(N):
if K - 1 <= i:
maxv += modf.nCm(i, K - 1) * A[i]
maxv %= MOD
# print(maxv)
A.reverse()
minv=0
for i in range(N):
if K - 1 <= i:
minv += modf.nCm(i, K - 1) * A[i]
minv %= MOD
print((maxv-minv)%MOD)
| 0 | null | 112,815,655,685,802 | 268 | 242 |
from collections import deque
n = int(input())
d = deque()
for i in range(n):
x = input().split()
if x[0] == "insert":
d.appendleft(x[1])
elif x[0] == "delete":
if x[1] in d:
d.remove(x[1])
elif x[0] == "deleteFirst":
d.popleft()
elif x[0] == "deleteLast":
d.pop()
print(*d)
|
from collections import deque
d = deque()
for _ in range(int(input())):
a = input()
if "i" == a[0]: d.appendleft(int(a[7:]))
elif "F" == a[6]: d.popleft()
elif "L" == a[6]: d.pop()
else:
try: d.remove(int(a[7:]))
except: pass
print(*d)
| 1 | 52,306,399,600 | null | 20 | 20 |
MI = lambda :(map(int,input().split()))
x = int(input())
if x>1799:
print(1)
elif x>1599:
print(2)
elif x>1399:
print(3)
elif x>1199:
print(4)
elif x>999:
print(5)
elif x>799:
print(6)
elif x>599:
print(7)
else:
print(8)
|
def main(x):
for i in range(9):
_min = 2000 - (200 * (i + 1))
if _min <= x:
print(i + 1)
return
if __name__ == "__main__":
x = int(input())
main(x)
| 1 | 6,746,703,901,910 | null | 100 | 100 |
def main():
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
visited_list = [-1] * n # 何ワープ目で訪れたか
visited_list[0] = 0
city, loop, non_loop = 1, 0, 0 # 今いる街、何ワープでループするか、最初にループするまでのワープ数
for i in range(1, n + 1):
city = a_list[city - 1]
if visited_list[city - 1] != -1:
loop = i - visited_list[city - 1]
non_loop = visited_list[city - 1] - 1
break
else:
visited_list[city - 1] = i
city = 1
if k <= non_loop:
for _ in range(k):
city = a_list[city - 1]
else:
for _ in range(non_loop + (k - non_loop) % loop + loop):
city = a_list[city - 1]
print(city)
if __name__ == "__main__":
main()
|
#import time
def main():
N, K = map(int, input().split())
As = list(map(int, input().split()))
As = [0]+As
ikisaki = As[1]
aru = {1}
itta = [1]
imaitta = 1
while not ikisaki in aru:
imaitta = ikisaki
ikisaki = As[ikisaki]
itta.append(imaitta)
aru.add(imaitta)
ind = itta.index(ikisaki)
kurikaesi = itta[ind:]
itidokiri = itta[:ind]
ans = itidokiri[K] if len(itidokiri) > K else kurikaesi[(K-len(itidokiri))%len(kurikaesi)]
return ans
if __name__ == '__main__':
#start = time.time()
print(main())
#elapsed_time = time.time() - start
#print("経過時間:{}".format(elapsed_time * 1000) + "[msec]")
| 1 | 22,755,443,780,222 | null | 150 | 150 |
ABC = input().split()
a = int(ABC[0])
b = int(ABC[1])
c = int(ABC[2])
i = 0
while a<=b:
if c%a==0:
i = i+1
a = a+1
print(i)
|
K = int(input())
AB = input().split()
A = int(AB[0])
B = int(AB[1])
if int(B / K) * K >= A:
print("OK")
else:
print("NG")
| 0 | null | 13,592,451,998,048 | 44 | 158 |
x=int(input())
i=0
while (i+1)*100 <= x:
i+=1
nokori = x-i*100
num = ((nokori - 1) // 5) + 1
if num <= i:
print(1)
exit()
print(0)
|
import sys
if __name__ == "__main__":
n = int(input())
if n == 0 or n == 1:
print(1)
sys.exit(0)
dp = [0] * (n + 1)
dp[0] = 1
dp[1] = 1
for i in range(2, n + 1):
dp[i] = dp[i - 1] + dp[i - 2]
print(dp[n])
| 0 | null | 63,369,359,604,730 | 266 | 7 |
S = input().split()
M = int(S[0])
N = int(S[1])
a = int((M*(M-1)/2) + (N*(N-1)/2))
print(a)
|
N, M = [int(x) for x in input().split()]
result = N * (N - 1) // 2 + M * (M - 1) // 2
print(result)
| 1 | 45,438,598,926,010 | null | 189 | 189 |
h1, m1, h2, m2, k = map(int, input().split())
H = h2 - h1
if m1 <= m2:
M = m2 - m1
else:
M = 60 - m1 + m2
H -= 1
print(H*60 + M - k)
|
H1,M1,H2,M2,K = map(int,input().split())
start,end = 60*H1+M1,60*H2+M2
print(abs(start-end) - K) if end-K>0 else print(0)
| 1 | 18,086,527,083,680 | null | 139 | 139 |
score = []
# 提出用の入力
while True:
m, f, r = map(int, input().split())
if m == -1 and f == -1 and r == -1:
break
score.append((m, f, r))
# # 動作確認用の入力
# with open('input_itp1_7_a_1.txt', mode='r', encoding='utf8') as input:
# while True:
# m, f, r = map(int, next(input).split())
# if m == -1 and f == -1 and r == -1:
# break
# score.append((m, f, r))
# print(score)
for i in range(len(score)):
sum = score[i][0] + score[i][1]
if score[i][0] == -1 or score[i][1] == -1 or sum < 30:
print('F')
elif sum >= 80:
print('A')
elif sum >= 65:
print('B')
elif sum >= 50:
print('C')
elif sum >= 30:
if score[i][2] >= 50:
print('C')
else:
print('D')
|
N = int(input())
num_odd = int(N/2+0.5)
print(num_odd/N)
| 0 | null | 89,077,017,326,280 | 57 | 297 |
r = int(input())
print((r * 2) * 3.141592)
|
R = int(input())
print(R * 2 * 3.1415)
| 1 | 31,240,649,422,620 | null | 167 | 167 |
def main():
n = int(input())
a_lst = list(map(int, input().split()))
dic = dict()
for i in range(n - 1):
if a_lst[i] in dic:
dic[a_lst[i]] += 1
else:
dic[a_lst[i]] = 1
dic_keys = dic.keys()
for i in range(1, n + 1):
if i in dic_keys:
print(dic[i])
else:
print(0)
if __name__ == "__main__":
main()
|
n = int(input())
A = list(map(int,input().split()))
L = [0] * n
for i in A:
L[i - 1] += 1
for j in L:
print(j)
| 1 | 32,548,870,439,870 | null | 169 | 169 |
while True:
try:
a, b = map(int, input().split())
except EOFError:
break
count=1
k=a+b
while k>=10:
k//=10
count+=1
print(count)
|
import sys
for line in sys.stdin:
l = map(int, line.split())
print len(str(l[0]+l[1]))
| 1 | 146,987,244 | null | 3 | 3 |
def modpow(a, n, p):
if n == 1:
ans = a % p
else:
if n % 2 == 0:
ans = (modpow(a, n // 2, p) ** 2) % p
else: # n % 2 == 1
ans = (a * (modpow(a, n // 2, p) ** 2)) % p
return ans
p = 10 ** 9 + 7
n, a, b = [int(x) for x in input().split()]
tot = modpow(2, n, p)
Xa, Ya = 1, 1
for i in range(a):
Xa = (Xa * (n - i)) % p
Ya = (Ya * (i + 1)) % p
Za = modpow(Ya, p - 2, p)
nCa = (Xa * Za) % p
Xb, Yb = 1, 1
for i in range(b):
Xb = (Xb * (n - i)) % p
Yb = (Yb * (i + 1)) % p
Zb = modpow(Yb, p - 2, p)
nCb = (Xb * Zb) % p
ans = (tot - nCa -nCb - 1) % p
print(ans)
|
SENTINEL = 10**9 + 1
def merge_sort(alist):
"""Sort alist using mergesort.
Returns a tuple of the number of comparisons and sorted list.
>>> merge_sort([8, 5, 9, 2, 6, 3, 7, 1, 10, 4])
(34, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
"""
def _sort(left, right):
count = 0
if left + 1 < right:
mid = (left + right) // 2
count += _sort(left, mid)
count += _sort(mid, right)
count += merge(left, mid, right)
return count
def merge(left, mid, right):
count = 0
ll = alist[left:mid] + [SENTINEL]
rl = alist[mid:right] + [SENTINEL]
i = j = 0
for k in range(left, right):
count += 1
if ll[i] <= rl[j]:
alist[k] = ll[i]
i += 1
else:
alist[k] = rl[j]
j += 1
return count
comp = _sort(0, len(alist))
return (comp, alist)
def run():
_ = int(input()) # flake8: noqa
li = [int(i) for i in input().split()]
(c, s) = merge_sort(li)
print(" ".join([str(i) for i in s]))
print(c)
if __name__ == '__main__':
run()
| 0 | null | 33,322,641,791,684 | 214 | 26 |
N = int(input())
a = list(map(int,input().split()))
ans = []
x = a[0]
for i in range(1,N):
x ^= a[i]
for i in a:
ans.append(x^i)
print(*ans)
|
n = int(input())
a = list(map(int, input().split()))
x = 0
for i in a:
x ^= i
for i in range(n):
a[i] ^= x
print(*a)
| 1 | 12,492,563,525,770 | null | 123 | 123 |
X,Y,A,B,C=map(int,input().split())
ls_a=sorted(list(map(int,input().split())))
ls_b=sorted(list(map(int,input().split())))
ls_c=sorted(list(map(int,input().split())))
ls_x=ls_a[A-X:A]
ls_y=ls_b[B-Y:B]
ls_c.reverse()
ans=sum(ls_x)+sum(ls_y)
a=b=c=0
for _ in range(min([X+Y,C])):
if a==len(ls_x):
m=min([ls_y[b],ls_c[c]])
if m==ls_y[b]:
ans+=(-ls_y[b]+ls_c[c])
b+=1
c+=1
else:
break
elif b==len(ls_y):
m=min([ls_x[a],ls_c[c]])
if m==ls_x[a]:
ans+=(-ls_x[a]+ls_c[c])
a+=1
c+=1
else:
break
else:
m=min([ls_x[a],ls_y[b],ls_c[c]])
if m==ls_x[a]:
ans+=(-ls_x[a]+ls_c[c])
a+=1
c+=1
elif m==ls_y[b]:
ans+=(-ls_y[b]+ls_c[c])
b+=1
c+=1
else:
break
print(ans)
|
import sys
sys.setrecursionlimit(10**9)
def main():
X,Y,A,B,C = map(int,input().split())
P = sorted(list(map(int,input().split())),reverse=True)
Q = sorted(list(map(int,input().split())),reverse=True)
R = list(map(int,input().split()))
print(sum(sorted(P[:X]+Q[:Y]+R,reverse=True)[:X+Y]))
if __name__ == "__main__":
main()
| 1 | 44,908,932,132,552 | null | 188 | 188 |
n=int(input(''))
p=0
for i in range(n-1):
a=i+1
p=p+(n-1)//a
print(p)
|
n = int(input())
count = 0
if n%2==0:
for i in range(int(n/2)-1):
count += int((n-1)/(i+1))
count += int(n/2)
else:
for i in range(int(n/2)):
count += int((n-1)/(i+1))
count += int(n/2)
print(count)
| 1 | 2,597,603,436,808 | null | 73 | 73 |
N=int(input())
if N%2:
print(0)
else:
ans=0
tmp=10
while tmp<=N:
ans+=N//tmp
tmp*=5
print(ans)
|
import sys
N = int(input())
if N % 2 != 0:
print(0)
sys.exit()
N //= 2
ans = 0
while N != 0:
ans += N//5
N //= 5
print(ans)
| 1 | 116,092,030,292,380 | null | 258 | 258 |
n=int(input())
s = ''
for i in range(11):
if n != 0:
n -= 1
s += chr(ord('a') + n % 26)
n //= 26
print(s[::-1])
|
from math import ceil
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
def is_ok(x):
c=0
for i in a:
c+=ceil(i/x)-1
if c>k:
return False
return True
def binary_search(m):
left=0
right=m+1
while left<=right:
center=(left+right)//2
if right-left==1:
return right
elif is_ok(center):
right=center
else:
left=center
if k==0:
print(max(a))
else:
print(binary_search(max(a)))
| 0 | null | 9,139,125,703,552 | 121 | 99 |
K = int(input())
if K % 2 == 0 or K % 5 == 0:
print(-1)
exit()
now = 0
count = 0
while True:
now = (now * 10 + 7) % K
count += 1
if now % K == 0:
print(count)
exit()
|
K = int(input())
if K % 2 == 0:
print(-1)
else:
seen = set()
ans = 1
num = 7
while ans <= K:
mod = num % K
if mod in seen:
ans = -1
break
else:
seen.add(mod)
if mod == 0:
break
else:
num = mod * 10 + 7
ans += 1
print(ans)
| 1 | 6,130,197,123,948 | null | 97 | 97 |
n=int(input())
a=[None] * (n+1)
a[0] = 1
a[1] = 1
for i in range(n-1):
a[i+2]=a[i]+a[i+1]
print(a[n])
|
F = {}
def fib(n):
global F
if n < 0:
print("error")
exit()
if n < 2:
F[n] = 1
return F[n]
# F[n] = fib(n-1) + fib(n-2)
F[n] = F[n-1] + F[n-2]
return F[n]
n = int(input())
#print(fib(n))
#n = int(input())
#print(fib(n))
#fib(44)
for i in range(n+1):
result = fib(i)
print(result)
# print(F[i])
| 1 | 1,958,627,290 | null | 7 | 7 |
N,K,C = map(int,input().split())
S = input()
L = []
R = []
i = 0
while i < N:
if S[i] == "o":
L.append(i)
if len(L) == K:
break
i += C+1
else:
i += 1
i = N-1
while i >= 0:
if S[i] == "o":
R.append(i)
if len(R) == K:
break
i -= C+1
else:
i -= 1
R.reverse()
for i in range(K):
if L[i] == R[i]:
print(L[i]+1)
|
n, k, c = map(int, input().split())
s = input()
s2 = s[::-1]
dp1 = [0] * (n + 2)
dp2 = [0] * (n + 2)
for (dp, ss) in zip([dp1, dp2], [s, s2]):
for i in range(n):
if ss[i] == 'x':
dp[i+1] = dp[i]
elif i <= c:
dp[i+1] = min(1, dp[i] + 1)
else:
dp[i+1] = max(dp[i-c] + 1, dp[i])
dp2 = dp2[::-1]
for i in range(1, n+1):
if s[i-1] == 'o' and dp1[i-1] + dp2[i+1] < k:
print(i)
| 1 | 40,663,804,510,030 | null | 182 | 182 |
def gcd(a, b):
while b:
a, b = b, a % b
return a
def div_ceil(x, y): return (x + y - 1) // y
N, M = map(int, input().split())
*A, = map(int, input().split())
A = list(set([a // 2 for a in A]))
L = A[0]
for a in A[1:]:
L *= a // gcd(L, a)
for a in A:
if (L // a) % 2 == 0:
ans = 0
break
else:
ans = div_ceil(M // L, 2)
print(ans)
|
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, gcd
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 heapq import heappush, heappop
from functools import reduce, lru_cache
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 TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = 10**6#float('inf')
#mod = 10 ** 9 + 7
mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
N, M = MAP()
a = LIST()
A = sorted([x//2 for x in a], reverse=True)
lcm = A[-1]
for x in A:
lcm = lcm*x//gcd(lcm, x)
r = lcm//A[0]
n = M//A[0]
for x in A:
if lcm//x%2 == 0:
print(0)
exit()
#2p+1が1<=2p+1<=n の範囲で rの倍数となるpの個数
if r%2 == 0:
print(0)
else:
print(n//r - n//(2*r))
| 1 | 102,381,718,973,842 | null | 247 | 247 |
X=int(input())
N=X%100
if N%5==0:
if N//5<=X//100:
print('1')
else:
print('0')
else:
if N//5+1<=X//100:
print('1')
else:
print('0')
|
N = int(input())
A = list(map(int, input().split()))
kabu = 0
yen = 1000
for i in range(N-1):
if A[i] < A[i+1]:
buy = yen//A[i]
kabu += buy
yen -= buy * A[i]
elif A[i] > A[i+1]:
yen += kabu * A[i]
kabu = 0
if kabu > 0:
yen += A[-1] * kabu
kabu = 0
print(yen)
| 0 | null | 67,488,486,787,190 | 266 | 103 |
s = input()
q = int(input())
#+---+---+---+---+---+---+
#| P | y | t | h | o | n |
#+---+---+---+---+---+---+
#0 1 2 3 4 5 6
#-6 -5 -4 -3 -2 -1
for i in range(0, q):
l = list(input().split())
a = int(l[1])
b = int(l[2]) + 1
if l[0] == "print":
print(s[a: b])
elif l[0] == "reverse":
rev = s[a: b]
rev = rev[::-1]
s = s[:a] + rev + s[b:]
else:
s = s[:a] + l[3] + s[b:]
|
import sys
def reverse(str, a, b):
head = str[0:a]
tail = str[b + 1:]
mid = str[a:b + 1]
reversed_str = head + mid[::-1] + tail
return reversed_str
def replace(str, a, b, rstr):
head = str[0:a]
tail = str[b + 1:]
replaced_str = head + rstr + tail
return replaced_str
#fin = open("test.txt", "r")
fin = sys.stdin
str = fin.readline()
q = int(fin.readline())
for i in range(q):
query_list = fin.readline().split()
op = query_list[0]
a = int(query_list[1])
b = int(query_list[2])
if op == "print":
print(str[a:b + 1])
elif op == "reverse":
str = reverse(str, a, b)
else:
str = replace(str, a, b, query_list[3])
| 1 | 2,085,864,748,018 | null | 68 | 68 |
H, W = map(int, input().split())
w1, w2 = W // 2, W % 2
h1, h2 = H // 2, H % 2
if H > 1 and W > 1:
num = 2 * w1 * h1 + w2 * h1 + w1 * h2 + w2 * h2
else:
num = 1
print(num)
|
def MI(): return map(int, input().split())
from collections import deque
def bfs(field,s):
q=deque([(0,s)])
dist=[[-1]*W for _ in range(H)]
d,i,j=-1,-1,-1
MOVE=[(-1,0),(0,-1),(1,0),(0,1)]
while q:
d,(i,j)=q.popleft()
if dist[i][j]!=-1:
continue
dist[i][j]=d
for di,dj in MOVE:
ni,nj=i+di,j+dj
if not 0<=ni<H or not 0<=nj<W:
continue
if field[ni][nj]=='#':
continue
if dist[ni][nj]!=-1:
continue
q.append((d+1,(ni,nj)))
return d,i,j
H,W=MI()
field=[input() for _ in range(H)]
ans=0
for i in range(H):
for j in range(W):
if field[i][j]=='.':
d,i,j=bfs(field,(i,j))
ans=max(ans,d)
print(ans)
| 0 | null | 72,569,878,363,090 | 196 | 241 |
a,b,c=input().split()
if(a==b)+(b==c)+(c==a)==1:
print('Yes')
else:
print('No')
|
import sys
def main():
input = sys.stdin.buffer.readline
a, b, c = map(int, input().split())
if len(set([a, b, c])) == 2:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
| 1 | 67,977,245,502,390 | null | 216 | 216 |
x = int(raw_input())
print (x**3)
|
import sys
import math
n=int(input())
A=[]
xy=[[]]*n
for i in range(n):
a=int(input())
A.append(a)
xy[i]=[list(map(int,input().split())) for _ in range(a)]
ans=0
for bit in range(1<<n):
tmp=0
for i in range(n):
if bit>>i & 1:
cnt=0
for elem in xy[i]:
if elem[1]==1:
if bit>>(elem[0]-1) & 1:
cnt+=1
else:
if not (bit>>(elem[0]-1) & 1):
cnt+=1
if cnt==A[i]:
tmp+=1
else:
continue
if tmp==bin(bit).count("1"):
ans=max(bin(bit).count("1"),ans)
print(ans)
| 0 | null | 60,728,699,663,170 | 35 | 262 |
from sys import stdin
def main():
readline = stdin.readline
n = int(readline())
s = tuple(readline().strip() for _ in range(n))
plus, minus = [], []
for c in s:
if 2 * c.count('(') - len(c) > 0:
plus.append(c)
else:
minus.append(c)
plus.sort(key = lambda x: x.count(')'))
minus.sort(key = lambda x: x.count('('), reverse = True)
plus.extend(minus)
sum = 0
for v in plus:
for vv in v:
sum = sum + (1 if vv == '(' else -1)
if sum < 0 : return print('No')
if sum != 0:
return print('No')
return print('Yes')
if __name__ == '__main__':
main()
|
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, acos, asin, atan, sqrt, tan, cos, pi
from operator import mul
from functools import reduce
from pprint import pprint
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7
n = I()
plus = []
minus = []
for _ in range(n):
s = S()
ret = 0
ret2 = 0
for i in s:
if ret and i == ')':
ret -= 1
elif i == '(':
ret += 1
else:
ret2 += 1
if ret2 > ret:
plus += [(ret, ret2)]
else:
minus += [(ret, ret2)]
plus.sort()
minus.sort(key=lambda x:x[1], reverse=True)
L = plus + minus
now = 0
for x, y in L:
now -= x
if now < 0:
print("No")
exit()
now += y
if now:
print("No")
else:
print("Yes")
| 1 | 23,615,947,375,680 | null | 152 | 152 |
S = input()
if S >= 0 and S <= 86400:
a = S // 3600
b = S % 3600
c = b // 60
d = b % 60
print "%d:%d:%d" % (a, c, d)
|
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
#import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, 10**5 + 1):
fact.append((fact[-1] * i) % Mod)
inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
factinv.append((factinv[-1] * inv[-1]) % Mod)
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n - r] % p
def sieve_of_eratosthenes(n):
if not isinstance(n,int):
raise TypeError("n is not int")
if n<2:
raise ValueError("n is not effective")
prime = [1]*(n+1)
for i in range(2,int(math.sqrt(n))+1):
if prime[i] == 1:
for j in range(2*i,n+1):
if j%i == 0:
prime[j] = 0
res = []
for i in range(2,n+1):
if prime[i] == 1:
res.append(i)
return res
class UnionFind:
def __init__(self,n):
self.parent = [i for i in range(n+1)]
self.rank = [0 for i in range(n+1)]
def findroot(self,x):
if x == self.parent[x]:
return x
else:
y = self.parent[x]
y = self.findroot(self.parent[x])
return y
def union(self,x,y):
px = self.findroot(x)
py = self.findroot(y)
if px < py:
self.parent[y] = px
else:
self.parent[px] = py
def same_group_or_no(self,x,y):
return self.findroot(x) == self.findroot(y)
def pow_k(x, n):
if n == 0:
return 1
K = 1
while n > 1:
if n % 2 != 0:
K *= x
x *= x
n //= 2
return K * x
def main(): #startline-------------------------------------------
n = int(input())
a = list(map(int, input().split()))
accum = sum(a)
ans = 1
b = [0] * (n + 1)
b[0] = 1
for i in range(1, n + 1):
accum -= a[i]
b[i] = min(2 * b[i - 1] - a[i], accum)
if b[i] < 0:
ans = -1
break
ans += b[i] + a[i]
if a[0] == 1:
ans = -1
if n == 0:
if a[0] == 1:
ans = 1
else:
ans = -1
print(ans)
if __name__ == "__main__":
main() #endline===============================================
| 0 | null | 9,643,826,728,590 | 37 | 141 |
N, M = map(int, input().split())
C = list(map(int, input().split()))
hw = 0
for i in range(M):
hw += C[i]
d = N - hw
if d >= 0:
print(d)
else:
print('-1')
|
N = int(input())
S = input()
if len(S) % 2 == 0 :
for i in range(len(S)//2) :
if S[i] != S[i+len(S)//2] :
print("No")
exit()
print("Yes")
exit()
print("No")
| 0 | null | 89,761,521,527,064 | 168 | 279 |
import collections
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
N=int(input())
D = collections.Counter(prime_factorize(N))
A=0
for d in D:
e=D[d]
for i in range(40):
if (i+1)*(i+2)>2*e:
A=A+i
break
print(A)
|
N=int(input())
arr=[list(map(int,input().split())) for i in range(N)]
za,wa=-10**10,-10**10
zi,wi=10**10,10**10
for i in range(N):
z=arr[i][0]+arr[i][1]
w=arr[i][0]-arr[i][1]
za=max(z,za)
zi=min(z,zi)
wa=max(w,wa)
wi=min(w,wi)
print(max(za-zi,wa-wi))
| 0 | null | 10,231,836,754,944 | 136 | 80 |
X = int(input())
eikaku = X if X < 180 else X - 180
cnt = 0
ans = 0
while True:
ans += 1
cnt += eikaku
if cnt % 360 == 0:
print(ans)
break
|
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 | 19,665,669,325,532 | 125 | 157 |
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
import bisect
# import heapq # priolity-queue
# from time import time
# from itertools import product,permutations,\
# combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce
# mod = int(1e9+7)
mod = 998244353
INF = 1<<50
def readInt():
return list(map(int,input().split()))
def main():
n,k = readInt()
l = []
r = []
for i in range(k):
a,b = readInt()
l.append(a)
r.append(b)
dp = [0 for i in range(n+1)]
dp[1] = 1
dpsum = [0 for i in range(n+1)]
dpsum[1] = 1
for i in range(2,n+1):
for j in range(k):
lj = max(1,i - r[j])
rj = i - l[j]
if rj<1:
continue
dp[i] += dpsum[rj] - dpsum[lj-1]
dp[i] %= mod
dpsum[i] = dpsum[i-1] + dp[i]
print(dp[n])
return
if __name__=='__main__':
main()
|
a,b,m = input().split()
a = list(map(int,input().split()))
b = list(map(int,input().split()))
xyc =[]
for i in range(int(m)):
xyc.append(input())
min = min(a) + min(b)
for i in xyc:
x,y,c = map(int, i.split())
if min > a[x-1] + b[y-1] - c :
min = a[x-1] + b[y-1] - c
print(min)
| 0 | null | 28,335,400,624,232 | 74 | 200 |
X , Y = map(int,input().split())
a = 0
ans = "No"
for a in range(0,X+1):
if (a * 2)+((X-a) * 4)==Y:
ans = "Yes"
print(ans)
|
x, y = map(int, input().split())
ans = 'No'
for i in range(x + 1):
j = x - i
if i * 2 + j * 4 == y:
ans = 'Yes'
break
print(ans)
| 1 | 13,688,781,205,060 | null | 127 | 127 |
nums = list(map(int, input().split()))
print(nums.index(0)+1)
|
import sys
X=map(int, sys.stdin.readline().split())
print X.index(0)+1
| 1 | 13,419,136,953,570 | null | 126 | 126 |
while 1:
m, f, r = [int(i) for i in input().split()]
if m == -1 and f == -1 and r == -1:
break
elif m == -1 or f == -1:
print("F")
elif m + f >= 80:
print("A")
elif 65 <= m + f < 80:
print("B")
elif 50 <= m + f < 65:
print("C")
elif 30 <= m + f < 50:
if r >= 50:
print("C")
else:
print("D")
elif m + f < 30:
print("F")
|
while 1:
(a,b,c) = map(int,raw_input().split())
if a == -1 and b == -1 and c == -1:
break
if a == -1 or b == -1:
print 'F'
elif a+b >= 80:
print 'A'
elif a+b >= 65:
print 'B'
elif a+b >= 50:
print 'C'
elif a+b >= 30:
if c >= 50:
print 'C'
else:
print 'D'
else:
print 'F'
| 1 | 1,197,728,094,332 | null | 57 | 57 |
import sys
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def MAP(): return map(int, input().split())
inf = sys.maxsize
h, w, k = MAP()
s = [[int(i) for i in STR()] for _ in range(h)]
ans = inf
for i in range(2 ** (h - 1)): #縦方向の割り方を全探索 O(500)
hdiv = [1 for _ in range(h)]
for j in range(h - 1):
tmp = 2 ** j
hdiv[j] = 1 if i & tmp else 0
sh = sum(hdiv)
tmpans = sh - 1
wdiv = [0 for _ in range(w - 1)]
partsum = [0 for _ in range(sh + 1)]
j = 0
cnt = 0
while j < w: #O(2 * 10 ** 4)
tmp = 0
idx = 0
for kk in range(h): #O(10)
tmp += s[kk][j]
if hdiv[kk]:
partsum[idx] += tmp
tmp = 0
idx += 1
flag = True
for kk in range(sh + 1):
if partsum[kk] > k:
tmpans += 1
partsum = [0 for _ in range(sh + 1)]
flag = False
if flag:
j += 1
cnt = 0
else:
cnt += 1
if cnt > 2:
tmpans = inf
break
ans = min(ans, tmpans)
print(ans)
|
N=int(input())
A=[]
for i in range(N):
D=list(map(int,input().split()))
A.append(D)
for i in range(N-2):
if A[i][0]==A[i][1] and A[i+1][0]==A[i+1][1] and A[i+2][0]==A[i+2][1]:
print('Yes')
break
else:
print('No')
| 0 | null | 25,495,421,663,530 | 193 | 72 |
import math
n=int(input())
x=list(map(int, input().split()))
y=list(map(int, input().split()))
print(sum([abs(a-b) for (a,b) in zip(x,y)]))
print(math.sqrt(sum([abs(a-b)**2 for (a,b) in zip(x,y)])))
print(math.pow(sum([abs(a-b)**3 for (a,b) in zip(x,y)]), 1/3))
print((max([abs(a-b) for (a,b) in zip(x,y)])))
|
# coding: utf-8
# Here your code !
import collections
s=int(input())
deq =collections.deque()
for i in range(s):
n=input().split()
if n[0]=="insert":
deq.appendleft(n[1])
elif n[0]=="delete":
try:
deq.remove(n[1])
except ValueError:
pass
elif n[0]=="deleteFirst":
deq.popleft()
elif n[0]=="deleteLast":
deq.pop()
print(" ".join(list(deq)))
| 0 | null | 135,377,462,640 | 32 | 20 |
X, Y = map(int, input().split())
X1, Y1 = map(int, input().split())
if Y1 == 1:
print("1")
else:
print("0")
|
def main() -> None:
s = input()
t = input()
print('Yes' if s == t[:-1] else 'No')
if __name__ == '__main__':
main()
| 0 | null | 72,694,029,093,950 | 264 | 147 |
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
input = lambda: given().rstrip()
LMIIS = lambda: list(map(int,input().split()))
II = lambda: int(input())
XLMIIS = lambda x: [LMIIS() for _ in range(x)]
YN = lambda c : print('Yes') if c else print('No')
MOD = 10**9+7
n,a,b = LMIIS()
def cmb(n,r):
if r == 0:
return 0
res = 1
r = min(r,n-r)
for i in range(n-r+1,n+1):
res *= i
res %= MOD
for i in range(1,r+1):
res *= pow(i,(MOD-2),MOD)
res %= MOD
return res
print((pow(2,n,MOD)-cmb(n,a)-cmb(n,b)-1)%MOD)
if __name__ == '__main__':
main()
|
n, a, b = map(int, input().split())
ans = pow(2,n,10**9+7)
bunshi = 1
bunbo = 1
for i in range(a):
bunshi = (bunshi * (n-i)) % (10**9+7)
bunbo = (bunbo * (i+1)) % (10**9+7)
ans = (ans - bunshi*pow(bunbo,-1,10**9+7) - 1) % (10**9+7)
for i in range(a,b):
bunshi = (bunshi * (n-i)) % (10**9+7)
bunbo = (bunbo * (i+1)) % (10**9+7)
ans = (ans - bunshi*pow(bunbo,-1,10**9+7)) % (10**9+7)
print(ans)
| 1 | 66,390,788,996,740 | null | 214 | 214 |
while True:
h,w=map(int,raw_input().split())
if h==w==0: break
for i in xrange(h):
if i==0 or i==h-1: print '#'*w
else: print '#'+'.'*(w-2)+'#'
print ""
|
while True:
h, w = map(int, raw_input().split())
if h == 0 and w == 0:
break
print(("#" * w + "\n") + ("#" + "." * (w-2) + "#" + "\n") * (h-2) + ("#" * w + "\n"))
| 1 | 820,535,075,668 | null | 50 | 50 |
#coding: utf-8
def GCM(m, n):
while 1:
if n == 0: return m
m -= (m/n)*n
m,n = n,m
while 1:
try:
a,b = map(int, raw_input().split())
x = GCM(a,b)
y = a*b / x
print "%d %d" % (x, y)
except EOFError:
break
|
import fractions
while True:
try:
x,y = map(int,raw_input().split())
print '%d %d' % (fractions.gcd(x,y),x/fractions.gcd(x,y)*y)
except EOFError:
break
| 1 | 620,985,020 | null | 5 | 5 |
import math
def isprime(x):
if x == 2:
return True
elif x < 2 or x % 2 == 0:
return False
else:
for i in range(3, int(math.sqrt(x)) + 1,2):
if x % i == 0:
return False
return True
n = int(input())
cnt = 0
for i in range(n):
x = int(input())
if isprime(x):
cnt += 1
print(str(cnt))
|
N = int(input())
S = str(input())
r_cnt = S.count('R')
g_cnt = S.count('G')
b_cnt = S.count('B')
ans = r_cnt*g_cnt*b_cnt
for i in range(N):
for d in range(1, N):
j = i + d
k = j + d
if k >= N:break
if S[i]!=S[j] and S[i]!=S[k] and S[j]!=S[k]:
ans -= 1
print(ans)
| 0 | null | 17,997,549,133,310 | 12 | 175 |
while True:
m, f, r = map(int, raw_input().split())
if (m+f+r) == -3:
break
if (m * f) < 0:
print "F"
elif (m + f) >= 80:
print 'A'
elif 65 <= (m + f) < 80:
print 'B'
elif 50 <= (m + f) < 65:
print 'C'
elif 30 <= (m + f) < 50:
if r < 50:
print 'D'
else:
print 'C'
elif (m + f) < 30:
print 'F'
|
# -*- coding: utf-8 -*-
def judge(m, f, r):
if m==-1 or f==-1: return "F"
ttl = m + f
if ttl >= 80: return "A"
elif ttl >= 65: return "B"
elif ttl >= 50: return "C"
elif ttl >= 30:
return "C" if r>=50 else "D"
else: return "F"
if __name__ == "__main__":
while True:
m, f, r = map(int, raw_input().split())
if m==-1 and f==-1 and r==-1: break
print judge(m, f, r)
| 1 | 1,233,684,720,150 | null | 57 | 57 |
print((1000 - int(input())%1000)%1000)
|
n = int(input())
a = raw_input().split()
a.reverse()
for i in range(len(a)-1):
print a[i],
print a[len(a)-1]
| 0 | null | 4,750,377,087,680 | 108 | 53 |
N = int(input())
A = list(map(int, input().split()))
flag = True
for n in A:
if n % 2 == 0 and (n % 3 != 0 and n % 5 != 0):
flag = False
print("APPROVED" if flag else "DENIED")
|
A = int(input())
B = int(input())
for i in range(1, 4):
if i in [A, B]:
continue
else:
print(i)
break
| 0 | null | 89,769,325,694,620 | 217 | 254 |
h, w, k = map(int, input().split())
s = [input() for _ in range(h)]
ans = []
vacant = 0
cnt = 0
for x in range(h):
if s[x] == '.' * w:
vacant += 1
continue
else:
cnt += 1
tmp = []
yet = False
for y in range(w):
if s[x][y] == '#':
if not yet:
yet = True
else:
cnt += 1
tmp.append(cnt)
for _ in range(vacant + 1):
ans.append(tmp)
vacant = 0
for _ in range(vacant):
ans.append(ans[-1])
for a in ans:
print(*a, sep=" ")
|
def resolve():
H, W, K = map(int, input().split())
G = [list(input()) for _ in range(H)]
ans = [[None] * W for _ in range(H)]
cnt = 1
for h in range(H):
for w in range(W):
if G[h][w] == "#":
ans[h][w] = cnt
cnt += 1
# 左から右
for h in range(H):
for w in range(1, W):
if ans[h][w] is None:
if ans[h][w - 1] is not None:
ans[h][w] = ans[h][w - 1]
# 右から左
for h in range(H):
for w in range(W - 1)[::-1]:
if ans[h][w] is None:
if ans[h][w + 1] is not None:
ans[h][w] = ans[h][w + 1]
# 上から下
for h in range(1, H):
for w in range(W):
if ans[h][w] is None:
ans[h][w] = ans[h - 1][w]
# 下から上
for h in range(H - 1)[::-1]:
for w in range(W):
if ans[h][w] is None:
if ans[h + 1][w] is not None:
ans[h][w] = ans[h + 1][w]
for h in range(H):
print(*ans[h])
if __name__ == "__main__":
resolve()
| 1 | 143,599,835,654,788 | null | 277 | 277 |
x,n = map(int,input().split())
p = list(map(int,input().split()))
dic = {}
lis = []
for i in range(0,102):
if i not in p:
dic[i] = abs(x-i)
lis.append(i)
mini = min(dic.values())
for j in lis:
if mini == dic[j]:
print(j)
break
|
x,n=map(int,input().split())
p=set(list(map(int,input().split())))
if x not in p :
print(x)
exit()
i=1
while True:
if x-i not in p:
print(x-i)
exit()
if x+i not in p:
print(x+i)
exit()
i+=1
| 1 | 14,134,776,285,112 | null | 128 | 128 |
while True:
h, w = map(int, input().split())
if h == 0 and w == 0:
break
for y in range(h):
isOddLine = True
if y % 2 == 0:
isOddLine = False
else:
isOddLine = True
for x in range(w):
if isOddLine:
if x % 2 == 0:
print('.', end='')
else:
print('#', end='')
else:
if x % 2 == 0:
print('#', end='')
else:
print('.', end='')
print('')
print('')
|
while True:
a=[int(x) for x in input().split()]
if a[0]==a[1]==0:
break
else:
for x in range(a[0]):
if x%2!=0:
for y in range(a[1]):
if y%2!=0:
print("#", end="")
else:
print(".", end="")
print("\n",end="")
elif x%2==0:
for y in range(a[1]):
if y%2!=0:
print(".", end="")
else:
print("#", end="")
print("\n",end="")
print("")
| 1 | 877,815,782,762 | null | 51 | 51 |
import sys
import math
import fractions
from collections import defaultdict
stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
A=int(input())
B=int(input())
A2=min(A,B)
B2=max(A,B)
if(A2==1 and B2==2):
print(3)
sys.exit(0)
if(A2==2 and B2==3):
print(1)
sys.exit(0)
if(A2==1 and B2==3):
print(2)
sys.exit(0)
|
l=[]
for i in range(2): l.append(int(input()))
for i in range(1, 4):
if i not in l: print(i)
| 1 | 110,377,819,446,468 | null | 254 | 254 |
import math
def comb(x,y):
return math.factorial(x)//(math.factorial(x-y)*math.factorial(y))
n,m = map(int,input().split())
ans1=0
ans2=0
if n > 1:
ans1=comb(n,2)
if m > 1:
ans2=comb(m,2)
print(ans1+ans2)
|
import math
N,M=map(int,input().split())
def comb(num,k):
if num<2:
return 0
return math.factorial(num)/(math.factorial(k)*math.factorial(num-k))
ans=int(comb(N,2)+comb(M,2))
print(ans)
| 1 | 45,587,992,378,460 | null | 189 | 189 |
N, M, L = map(int, raw_input().split())
nm = [map(int, raw_input().split()) for n in range(N)]
ml = [map(int, raw_input().split()) for m in range(M)]
ml_t = []
for l in range(L):
tmp = []
for m in range(M):
tmp.append(ml[m][l])
ml_t.append(tmp)
for n in range(N):
tmp1 = nm[n]
col = [0]*L
for l in range(L):
tmp2 = ml_t[l]
for m in range(M):
col[l] += tmp1[m] * tmp2[m]
print ' '.join(map(str, col))
|
n,m,l = map(int,input().split())
A = []
for i in range(n):
a = [int(j) for j in input().split()]
A.append(a)
B = []
for j in range(m):
b = [int(k) for k in input().split()]
B.append(b)
for i in range(n):
c = []
for k in range(l):
x = 0
for j in range(m):
x += A[i][j]*B[j][k]
c.append(str(x))
print(" ".join(c))
| 1 | 1,433,846,433,572 | null | 60 | 60 |
# -*- coding: utf-8 -*-
def main():
X, Y, Z = map(int, input().split())
X, Y = change(X, Y)
X, Z = change(X, Z)
print(X, Y ,Z)
def change(a, b):
num = a
a = b
b = num
return(a, b)
if __name__ == "__main__":
main()
|
S = input()
if len(S)==6 :
if S[2] == S[3] and S[4] == S[5] :
print("Yes")
else:
print("No")
| 0 | null | 39,817,543,357,910 | 178 | 184 |
n = int(input())
print(n//2 + n%2)
|
N=int(input())
S=list(input())
a=0#色変化
for i in range(N-1):
if not S[i]==S[i+1]:
a=a+1
print(a+1)
| 0 | null | 114,110,698,708,172 | 206 | 293 |
S = input()
if S == "ABC":
print("ARC")
else:
print("ABC")
|
import sys
n=int(input())
s=[list(input()) for i in range(n)]
L1=[]
L2=[]
for i in range(n):
ct3=0
l=[0]
for j in s[i]:
if j=='(':
ct3+=1
l.append(ct3)
else:
ct3-=1
l.append(ct3)
if l[-1]>=0:
L1.append((min(l),l[-1]))
else:
L2.append((min(l)-l[-1],-l[-1]))
L1.sort()
L1.reverse()
ct4=0
for i in L1:
if ct4+i[0]<0:
print('No')
sys.exit()
ct4+=i[1]
L2.sort()
L2.reverse()
ct5=0
for i in L2:
if ct5+i[0]<0:
print('No')
sys.exit()
ct5+=i[1]
if ct4!=ct5:
print('No')
sys.exit()
print('Yes')
| 0 | null | 23,980,629,795,950 | 153 | 152 |
from sys import stdin, setrecursionlimit
WEEK = {
'SUN': 0,
'MON': 1,
'TUE': 2,
'WED': 3,
'THU': 4,
'FRI': 5,
'SAT': 6
}
def main():
input = stdin.buffer.readline
s = input()[:-1].decode()
print(7 - WEEK[s])
if __name__ == "__main__":
setrecursionlimit(10000)
main()
|
k = int(input())
from collections import deque
d = deque()
c = 0
for i in range(1, 10):
d.append(i)
while True:
tmp = d.popleft()
c += 1
if c == k:
ans = tmp
break
if tmp % 10 != 0:
d.append(tmp * 10 + (tmp % 10 - 1))
d.append(tmp * 10 + tmp % 10)
if tmp % 10 != 9:
d.append(tmp * 10 + (tmp % 10 + 1))
print(ans)
| 0 | null | 86,934,355,888,910 | 270 | 181 |
m_1, d_1 = map(int, input().split())
m_2, d_2 = map(int, input().split())
month = 12
if (m_1 % month + 1) == m_2 and d_2 == 1:
print("1")
else:
print("0")
|
import sys
def input(): return sys.stdin.readline().rstrip()
N = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(N):
s = input()
if s == "AC":
ac += 1
elif s == "WA":
wa += 1
elif s == "TLE":
tle += 1
else:
re += 1
print("AC x " + str(ac))
print("WA x " + str(wa))
print("TLE x " + str(tle))
print("RE x " + str(re))
| 0 | null | 66,224,447,467,948 | 264 | 109 |
n = int(input())
buffer = []
i = 0
while i<n:
b,f,r,v = map(int,input().split())
buffer.append([b,f,r,v])
i = i + 1
room = []
for h in range(15):
if h == 3 or h == 7 or h == 11:
room.append(['**']*10)
else:
room.append([0]*10)
for y in range(n):
if buffer[y][0] == 1:
room[buffer[y][1]-1][buffer[y][2]-1] = buffer[y][3] + room[buffer[y][1]-1][buffer[y][2]-1]
elif buffer[y][0] == 2:
room[buffer[y][1]-1+4][buffer[y][2]-1] = buffer[y][3] + room[buffer[y][1]-1+4][buffer[y][2]-1]
elif buffer[y][0] == 3:
room[buffer[y][1]-1+8][buffer[y][2]-1] = buffer[y][3] + room[buffer[y][1]-1+8][buffer[y][2]-1]
elif buffer[y][0] == 4:
room[buffer[y][1]-1+12][buffer[y][2]-1] = buffer[y][3] + room[buffer[y][1]-1+12][buffer[y][2]-1]
for x in range(15):
if x == 3 or x == 7 or x == 11:
print("####################")
else:
for y in range(10):
print(" "+str(room[x][y]), end = "")
print()
|
N = int(input())
A = map(int, input().split())
AI = sorted(((a, i) for i, a in enumerate(A, 1)), reverse=True)
def solve(a, i, prev):
pl, pr, ps = i, 0, 0
for l, r, s in prev:
yield l, r-1, max(s+abs(r-i)*a, ps+abs(i-pl)*a)
pl, pr, ps = l, r, s
yield pl+1, pr, ps+abs(i-pl)*a
prev = [(1, N, 0)]
for a,i in AI:
prev = [*solve(a,i, prev)]
print(max(s for l, r, s in prev))
| 0 | null | 17,554,828,832,628 | 55 | 171 |
a,b,c=map(int,input().split())
list=[a,b,c]
list.sort()
print(list[0],list[1],list[2])
|
# 入力
a = int(input())
# 定義
answer = 0
# 処理
for i in range(1, a + 1):
if i % 3 == 0 and i % 5 == 0:
continue
elif i % 3 == 0:
continue
elif i % 5 == 0:
continue
else:
answer += i
# 出力
print(answer)
| 0 | null | 17,767,132,311,658 | 40 | 173 |
import math
def main():
N = int(input())
d = {}
za = zb = zab = r = 0
mod = 10**9 + 7
for i in range(N):
a, b = map(int, input().split())
if a== 0 and b == 0:
zab += 1
elif b == 0:
zb += 1
elif a == 0:
za += 1
else:
if a < 0:
a, b = -a, -b
x = math.gcd(abs(a), abs(b))
d[(a//x, b//x)] = d.get((a//x, b//x), 0) + 1
used = set()
l = []
for x in d:
if x in used:
continue
a, b = x[0], x[1]
used.add(x)
if a * b > 0:
t = (abs(b), -abs(a))
else:
t = (abs(b), abs(a))
used.add(t)
l.append((d[x], d.get(t, 0)))
r = pow(2, za) + pow(2, zb) - 1
for i in l:
r *= (pow(2, i[0]) + pow(2, i[1]) - 1)
r %= mod
return (r - 1 + zab) % mod
print(main())
|
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 | 64,419,687,269,718 | 146 | 252 |
while (True):
s = list(map(int, input().strip().split(' ')))
if s[0] == 0 and s[1] == 0:
break
else:
for i in range(s[0]):
for j in range(s[1]):
if j % 2 == 0 and i % 2 == 0:
print("#", end="")
elif j % 2 == 1 and i % 2 == 0:
print(".", end="")
elif j % 2 == 0 and i % 2 == 1:
print(".",end="")
else:
print("#", end="")
print()
print()
|
N,M = map(int,input().split())
print(sum(range(0,N))+sum(range(0,M)))
| 0 | null | 23,266,043,388,060 | 51 | 189 |
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline ####
int1 = lambda x: 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)]
INF = float('inf')
def solve():
s, w = MI()
if w >= s:
print('unsafe')
else:
print('safe')
if __name__ == '__main__':
solve()
|
import numpy as np
n = int(input())
arr = np.array([[int(x) for x in input().split()] for _ in range(n)])
med_a = np.median(arr[:, 0])
med_b = np.median(arr[:, 1])
if n % 2 == 0:
print(int(med_b * 2 - med_a * 2 + 1))
else:
print(int(med_b - med_a + 1))
| 0 | null | 23,231,879,261,756 | 163 | 137 |
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = [0] * q
c = [0] * q
for i in range(q):
b[i], c[i] = map(int, input().split())
ans = sum(a)
a_c = Counter(a)
for i in range(q):
b_num = a_c[b[i]]
ans += (c[i] - b[i]) * b_num
a_c[c[i]] += b_num
a_c[b[i]] = 0
print(ans)
|
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
ans = sum(A)
num = Counter(A)
for i in range(Q):
b,c = map(int,input().split())
ans += (c-b)*num[b]
num[c] += num[b]
num[b] = 0
print(ans)
| 1 | 12,226,859,622,210 | null | 122 | 122 |
from collections import deque
def isPa(w,k,p):
tr = 0
c = 0
d = deque(w)
while(d):
tmp = d.popleft()
if(tmp > p):
return False
if( tr + tmp > p):
tr = tmp
c += 1
else:
tr += tmp
if c+1>k:
return False
return True
def MaxInP(w,k,p):
maxinp = 0
tmp = 0
d = deque(w)
while(d):
tmp += d.popleft();
if(tmp > p):
if(tmp > maxinp):
maxinp = tmp
tmp = 0
return maxinp
n,k = [int(x) for x in input().split()]
w = deque()
for i in range(n):
w.append(int(input()))
mean = int(sum(w)/k)
maxinp = MaxInP(w,k,mean)
if k == 1:
print(mean)
else:
minP = mean
maxP = maxinp
while(True):
m = int ((minP + maxP)/2)
if ( isPa(w,k,m) ):
maxP = m
else:
minP = m
if (minP+1 == maxP or minP == maxP):
print(maxP)
break
|
def main():
S = list(input().rstrip())
N = len(S)
if S != list(reversed(S)):
print("No")
elif S[:int((N-1)/2)] != list(reversed(S[:int((N-1)/2)])):
print("No")
elif S[int((N+3)/2) - 1:] != list(reversed(S[int((N+3)/2) - 1:])):
print("No")
else:
print("Yes")
if __name__ == '__main__':
main()
| 0 | null | 23,102,881,564,648 | 24 | 190 |
n=int(input())
s=[str(input()) for _ in range(n)]
from collections import Counter
results = Counter(s)
max_num = results.most_common()[0][1]
max_key_list = [kv[0] for kv in results.items() if kv[1] == max_num]
for i in sorted(max_key_list):
print(i)
|
import collections
N = int(input())
L = [input() for i in range(N)]
c = collections.Counter(L)
max_L = max(list(c.values()))
keys = [k for k, v in c.items() if v == max_L]
keys.sort()
for key in keys:
print(key)
| 1 | 69,851,940,537,250 | null | 218 | 218 |
a=[]
for i in range(10):
a.append(int(input()))
a=sorted(a)[::-1]
for i in range(3):
print(a[i])
|
s = input()
n = len(s)
entire = s == s[::-1]
left = s[:int((n-1)/2)] == s[:int((n-1)/2)][::-1]
right = s[int((n+3)/2-1):] == s[int((n+3)/2-1):][::-1]
if entire and left and right:
print("Yes")
else:
print("No")
| 0 | null | 23,054,235,762,404 | 2 | 190 |
def isprime(x):
if x == 2:
return True
elif x < 2 or x%2 == 0:
return False
i = 3
while i <= pow(x,1/2):
if x%i == 0:
return False
i = i + 2
return True
count = 0
for s in range(int(input())):
if isprime(int(input())):
count += 1
print(count)
|
def isPrime(num):
flag = True
if(num==1):
return False
for i in range(2,int(num**0.5)+1):
if(num%i==0):
flag = False
break
return flag
a = []
temp = 0
n = int(input().strip())
for i in range(n):
temp = int(input().strip())
if isPrime(temp):
a.append(temp)
print(len(a))
| 1 | 9,993,812,218 | null | 12 | 12 |
a = input()
b = input().split()
for i in b:
i = int(i)
b.reverse()
c = " ".join(b)
print(c)
|
N = int(input())
A = list(map(int, input().split()))
node = 1
# 作成しなければならない葉の残りの数
leaf = sum(A)
max_node = 1
judge = True
ans = 0
for i, a in enumerate(A):
ans += node
leaf -= a
if node < a+1 and leaf > 0:
judge = False
break
# 次の深さのノード
max_node = (node - a) * 2
node = min(leaf, max_node)
if judge and max_node == 0:
print(ans)
else:
print(-1)
| 0 | null | 9,949,571,480,868 | 53 | 141 |
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import sys
def get_ints():
return map(int, sys.stdin.readline().strip().split())
def main():
L, R, d = get_ints()
ans = 0
for i in range(L, R + 1):
if i % d == 0:
ans += 1
print(ans)
if __name__ == "__main__":
main()
|
n = int(input())
C = list(input())
W = C.count("W")
R = C.count("R")
# 仕切りより左側にある白石の数
w = 0
# 仕切りより右側にある赤石の数
r = R
ans = r
for i in range(n):
if C[i] == "W":
w += 1
else:
r -= 1
ans = min(ans, max(w, r))
print(ans)
| 0 | null | 6,858,537,364,800 | 104 | 98 |
S = input()
s = len(S)
ct = 0
for i in range(s):
if S[i] != S[(-i-1)]:
ct += 1
print(ct//2)
|
n, m = map(int, input().split())
A = [input().split() for _ in range(n)]
b = [input()for _ in range(m)]
for a in A:
print(sum(int(x)*int(y) for x, y in zip(a,b)))
| 0 | null | 60,566,200,601,100 | 261 | 56 |
n=int(input())
s,t=map(str, input().split())
a=[]
for i in range(n):
a.append(s[i]+t[i])
a = "".join(a)
print(a)
|
n = int(input())
s, t = input().split()
for i in range(n):
print(s[i], t[i], sep="", end="")
print("")
| 1 | 112,209,846,315,970 | null | 255 | 255 |
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')
K = int(input())
# indexは桁数
luns = [[]]
luns.append(list("123456789"))
for keta in range(2, 11):
keta_lun = []
for s in luns[-1]:
lst = int(s[-1])
if lst - 1 >= 0:
keta_lun.append(s + str(lst - 1))
keta_lun.append(s + str(lst))
if lst + 1 < 10:
keta_lun.append(s + str(lst + 1))
luns.append(keta_lun)
index = 0
for keta_luns in luns:
for lun in keta_luns:
index += 1
if index == K:
print(lun)
quit()
|
# 解説を参考に作成
from collections import deque
def solve(K):
lunlun = deque([i for i in range(1, 10)])
ans = 0
for _ in range(K):
ans = lunlun.popleft()
x = ans * 10 + ans % 10
if x % 10 != 0:
lunlun.append(x - 1)
lunlun.append(x)
if x % 10 != 9:
lunlun.append(x + 1)
print(ans)
if __name__ == '__main__':
K = int(input())
solve(K)
| 1 | 40,070,355,424,960 | null | 181 | 181 |
#!/usr/bin/env python
# coding: utf-8
# In[1]:
N = int(input())
# In[15]:
def func(i,j,N):
ans = []
for x in range(1,N+1):
x_ = str(x)
if x_[0] == str(i) and x_[-1] == str(j):
ans += [x]
return ans
# In[23]:
ans = 0
for i in range(10):
for j in range(10):
ans += len(func(i,j,N))*len(func(j,i,N))
print(ans)
# In[ ]:
|
import sys
def input():
return sys.stdin.readline().strip()
def main():
N = int(input())
C = [[0] * 10 for _ in range(10)]
for i in range(10):
for j in range(10):
for n in range(1, N + 1):
L = len(str(n)) - 1
a = n // (10 ** L)
b = n % 10
if a == i and b == j:
C[i][j] += 1
answer = 0
for i in range(10):
for j in range(10):
answer += C[i][j] * C[j][i]
print(answer)
if __name__ == "__main__":
main()
| 1 | 86,214,048,996,572 | null | 234 | 234 |
X = int(input())
item_num = X // 100
if item_num * 5 >= X - item_num * 100:
print('1')
else:
print('0')
|
N = int(input())
if N%1000 == 0:
print(0)
else:
print(1000-(N%1000))
| 0 | null | 67,525,670,631,470 | 266 | 108 |
N,K = map(int, input().split())
A = list(map(int, input().split()))
for cnt in range(K):
B = [0] * (N+1)
for i in range(N):
bright = A[i]
l = max(i-bright,0)
r = min(i+bright+1, N)
B[l] += 1
B[r] -= 1
for i in range(N):
B[i+1] += B[i]
A = B[:-1]
#print(A)
if min(A) == N:
#print(cnt)
break
print(" ".join(map(str,A)))
|
N = int(input())
memo = [-1]*500
def fibo(x):
if memo[x] != -1:
return memo[x]
if x == 0 or x == 1:
ans=1
memo[x] = ans
return ans
ans = fibo(x-1) + fibo(x-2)
memo[x] = ans
return ans
print(fibo(N))
| 0 | null | 7,698,849,369,630 | 132 | 7 |
# coding:UTF-8
import sys
from math import factorial
MOD = 998244353
INF = 10000000000
def main():
n, k = list(map(int, input().split())) # スペース区切り連続数字
lrList = [list(map(int, input().split())) for _ in range(k)] # スペース区切り連続数字(行列)
s = []
for l, r in lrList:
for i in range(l, r+1):
s.append(i)
s.sort()
sum = [0] * (n + 1)
Interm = [0] * (2 * n + 1)
sum[1] = 1
for i in range(1, n):
for j in range(k):
l, r = lrList[j][0], lrList[j][1]
Interm[i+l] += sum[i]
Interm[i+r+1] -= sum[i]
sum[i+1] = (sum[i] + Interm[i+1]) % MOD
# result = Interm[n]
result = (sum[n] - sum[n-1]) % MOD
# ------ 出力 ------#
print("{}".format(result))
if __name__ == '__main__':
main()
|
n, k = list(map(int, input().split()))
s = []
for i in range(k):
a, b = list(map(int, input().split()))
s.append((a, b))
dp = [0]*(n+1)
v = 0
mod = 998244353
for i in range(1, n+1):
if i == 1:
for l, r in s:
if i+l <= n:
dp[i+l] += 1
if i+r+1 <= n:
dp[i+r+1] -= 1
else:
v += dp[i]
v %= mod
for l, r in s:
if i+l <= n:
dp[i+l] += v
if i+r+1 <= n:
dp[i+r+1] -= v
print(v % mod)
| 1 | 2,718,776,834,970 | null | 74 | 74 |
import math
A, B, C, D = map(int, input().split())
print('Yes') if math.ceil(A / D) >= math.ceil(C / B) else print('No')
|
t_HP, t_A, a_HP, a_A = map(int,input().split())
ans = False
while True:
a_HP -= t_A
if a_HP <= 0:
ans = True
break
t_HP -= a_A
if t_HP <= 0:
break
if ans == True:
print("Yes")
else:
print("No")
| 1 | 29,806,861,645,626 | null | 164 | 164 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.