code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 6.82M
181,637B
⌀ | question_pair_id
float64 101M
180,471B
⌀ | code1_group
int64 2
299
| code2_group
int64 2
299
|
---|---|---|---|---|---|---|
# ac
import sys
import numpy as np
from numba import njit
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
@njit('(i8[::1],)', cache=True)
def update(a):
n = len(a)
b = np.zeros_like(a) # aと同じ形状の配列を生成(https://deepage.net/features/numpy-zeros.html)
for i, x in enumerate(a): # enumerateはindex, valueを返す
l = max(0, i - x) # lampの照らす範囲の下限(左側)
r = min(n - 1, i + x) # lampの上限(右側)
b[l] += 1 # 以下imos法
if r + 1 < n: # r+1はx=nの時(最後のサイクル)r+1=nでindexの指定に失敗するから弾く(indexは0~n-1)
b[r + 1] -= 1
b = np.cumsum(b) # bの要素の累積和(フィボナッチ数列みたいな)(imos法の締め)
return b
n, k = map(int, readline().split())
a = np.array(read().split(), np.int64)
k = min(k, 41) # 今回の制限範囲のnなら41回も試行すればaの値が全て上限に達するのでそれ以上の試行は不要(解説PDF)
for _ in range(k):
a = update(a)
print(' '.join(map(str, a))) # joinメソッドはstrを''で区切って連結する
|
from itertools import accumulate
N, K = map(int, input().split())
A = list(map(int, input().split()))
def calc_imos(arr):
imos = [0] * (N + 1)
for i, a in enumerate(arr):
l = max(0, i - a)
r = min(N - 1, i + a)
imos[l] += 1
imos[r + 1] -= 1
new_arr = list(accumulate(imos))[:-1]
return new_arr
for k in range(K):
A = calc_imos(A)
if all([a == N for a in A]):
print(*([N] * N), sep=' ')
exit()
print(*A, sep=' ')
| 1 | 15,298,897,406,998 | null | 132 | 132 |
def main():
n = int(input())
d_lst = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
for j in range(i + 1, n):
ans += d_lst[i] * d_lst[j]
print(ans)
if __name__ == "__main__":
main()
|
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 11 17:23:36 2020
@author: Aruto Hosaka
"""
N = int(input())
S = input()
color = ['R','G','B']
k = 1
A = {color[0]:0,color[1]:0,color[2]:0}
for c1 in color:
for c2 in color:
for c3 in color:
if c1 != c2 and c2 != c3 and c1 != c3:
A[(c1,c2,c3)] = 0
for c1 in color:
for c2 in color:
if c1!=c2:
A[(c1,c2)] = 0
for i in range(N):
if S[i] == 'R':
A[('G','B','R')] += A[('G','B')]
A[('B','G','R')] += A[('B','G')]
A[('B','R')] += A['B']
A[('G','R')] += A['G']
if S[i] == 'G':
A[('R','B','G')] += A[('R','B')]
A[('B','R','G')] += A[('B','R')]
A[('B','G')] += A['B']
A[('R','G')] += A['R']
if S[i] == 'B':
A[('G','R','B')] += A[('G','R')]
A[('R','G','B')] += A[('R','G')]
A[('R','B')] += A['R']
A[('G','B')] += A['G']
A[S[i]] += 1
counter = 0
for c1 in color:
for c2 in color:
for c3 in color:
if c1 != c2 and c2 != c3 and c1 != c3:
counter += A[(c1,c2,c3)]
dc = 0
for i in range(N-2):
k = 1
while k*2+i < N:
if S[i+k] != S[i] and S[i] != S[i+k*2] and S[i+k] != S[i+k*2]:
dc += 1
k += 1
print(counter-dc)
| 0 | null | 101,930,579,933,920 | 292 | 175 |
a, b, k = map(int, input().split())
print(a - min(a, k), b - min(b, k - min(a, k)))
|
a,b,n= map(int, input().split())
if a<n:
if (n-a)>b:
print(0,0)
else:
print(0,b-(n-a))
else:
print(a-n,b)
| 1 | 104,304,662,100,562 | null | 249 | 249 |
import sys
import bisect
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())
class SegTree:
def __init__(self, init_val, segfunc, ide_ele):
n = len(init_val)
self.ide_ele = ide_ele
self.segfunc = segfunc
self.num = 2**(n - 1).bit_length()
self.seg = [self.ide_ele] * 2 * self.num
for i in range(n):
self.seg[i + self.num - 1] = init_val[i]
for i in range(self.num - 2, -1, -1):
self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])
def update(self, k, x):
k += self.num - 1
self.seg[k] += x
while k:
k = (k - 1) // 2
self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])
def query(self, p, q):
if q <= p:
return self.ide_ele
p += self.num - 1
q += self.num - 2
res = self.ide_ele
while q - p > 1:
if p & 1 == 0:
res = self.segfunc(res, self.seg[p])
if q & 1 == 1:
res = self.segfunc(res, self.seg[q])
q -= 1
p = p // 2
q = (q - 1) // 2
if p == q:
res = self.segfunc(res, self.seg[p])
else:
res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
return res
def main():
N, D, A = in_nn()
XH = sorted(in_nl2(N))
X = [0] * N
H = [0] * N
for i in range(N):
x, h = XH[i]
X[i] = x
H[i] = h
seg = SegTree([0] * N, segfunc=lambda a, b: a + b, ide_ele=0)
ans = 0
for i in range(N):
x, h = X[i], H[i]
j = bisect.bisect_right(X, x + 2 * D)
cnt_bomb = seg.query(0, i + 1)
h -= A * cnt_bomb
if h <= 0:
continue
cnt = -(-h // A)
ans += cnt
seg.update(i, cnt)
if j < N:
seg.update(j, -cnt)
# print(i, j)
# print(seg.seg)
print(ans)
if __name__ == '__main__':
main()
|
x, k, d = map(int, input().split())
x = -x if x <= 0 else x
if x - d * k >= 0:
print(x - d * k)
else:
a = x // d
b = a + 1
rest_cnt = k - a
if rest_cnt % 2 == 0:
print(abs(x - d * a))
else:
print(abs(x - d * b))
| 0 | null | 43,713,761,314,330 | 230 | 92 |
import math
N = int(input())
max_D = int(2 + math.sqrt(N))
count = []
ans = 1
for i in range(2, max_D):
if N % i == 0:
count.append(0)
while N % i == 0:
N = N // i
count[-1] += 1
if N < i:
ans = 0
break
l = len(count)
for i in range(l):
E = 2*count[i]
j = 0
while j * (j + 1) <= E:
j += 1
ans += j - 1
print(ans)
|
def II(): return int(input())
N=II()
d=2
ans=0
while d*d<=N:
if N%d!=0:
d+=1
continue
z=d
while N%z==0:
ans+=1
N//=z
z*=d
while N%d==0:
N//=d
if N!=1:
ans+=1
print(ans)
| 1 | 16,869,774,931,744 | null | 136 | 136 |
import itertools
import sys
from collections import Counter
sys.setrecursionlimit(10 ** 9)
M = 1000000007
N = int(sys.stdin.readline())
left = list(map(int, sys.stdin.read().split()))
counter = Counter(left)
def dp(t, ns):
cached = t.get(ns)
if cached is not None:
return cached
remaining = sum(ns)
assert remaining > 0
last_cnt = left[remaining - 1] + 1
n1, n2, n3 = ns
res = 0
if last_cnt == n1:
res += dp(t, tuple(sorted([n1 - 1, n2, n3])))
res %= M
if last_cnt == n2:
res += dp(t, tuple(sorted([n1, n2 - 1, n3])))
res %= M
if last_cnt == n3:
res += dp(t, tuple(sorted([n1, n2, n3 - 1])))
res %= M
# print(f"{remaining}: ({n1},{n2},{n3}) => {res}")
t[ns] = res
return res
def solve():
h = [0, 0, 0]
for i in range(N):
k = counter[i]
if k == 3:
h[0] = h[1] = h[2] = i + 1
elif k == 2:
h[0] = h[1] = i + 1
elif k == 1:
h[0] = i + 1
else:
break
if sum(h) != N:
return 0
t = dict()
t[0, 0, 0] = 1
res = dp(t, tuple(sorted(h)))
return (res * len(set(itertools.permutations(h)))) % M
print(solve())
|
import sys
import collections
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
n = int(readline())
a = list(map(int, readline().split()))
d = collections.defaultdict(int)
d[-1] = 3
mt = 1
for v in a:
mt *= d[v-1]
mt %= mod
d[v-1] -= 1
d[v] += 1
print(mt)
if __name__ == '__main__':
solve()
| 1 | 130,556,210,249,670 | null | 268 | 268 |
list_2d=[]
for i in range(3):
list_2d.append([int(i) for i in input().split()])
n=int(input())
b=[int(input()) for i in range(n)]
#print(list_2d)
#print(b)
#印をつける
for i in range(3):
for j in range(3):
if list_2d[i][j] in b:
list_2d[i][j]="x"
#print(list_2d)
#ビンゴかどうかチェックする
#横
if list_2d[0]==["x","x","x"] or list_2d[1]==["x","x","x"] or list_2d[2]==["x","x","x"]:
ans="Yes"
#縦
elif list_2d[0][0]==list_2d[1][0]==list_2d[2][0]=="x" or list_2d[0][1]==list_2d[1][1]==list_2d[2][1]=="x" or list_2d[0][2]==list_2d[1][2]==list_2d[2][2]=="x":
ans="Yes"
#斜め
elif list_2d[0][0]==list_2d[1][1]==list_2d[2][2]=="x" or list_2d[0][2]==list_2d[1][1]==list_2d[2][0]=="x":
ans="Yes"
else:
ans="No"
print(ans)
|
import numpy as np
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]
for i in range(3):
for j in range(3):
for k in range(n):
if a[i][j] == b[k]:
a[i][j] = 0
c = []
c.append(np.sum(a,axis = 0))
c.append(np.sum(a,axis = 1))
d = np.prod(c)
if d == 0:
print("Yes")
elif (a[0][0] == 0 and a[1][1] == 0 and a[2][2] == 0) or (a[2][0] == 0 and a[1][1] == 0 and a[0][2] == 0):
print("Yes")
else:
print("No")
| 1 | 59,680,221,729,828 | null | 207 | 207 |
n, a, b = [int(x) for x in input().split()]
if (b - a) % 2 == 0:
print((b - a) // 2)
else:
print(min(a, n - b + 1) + (b - a - 1) // 2)
|
s = list(map(int, input().split()))
N = s[0]
A = s[1]
B = s[2]
if (B - A) % 2 == 0:
print((B - A) // 2)
else:
print(min(A - 1,N - B) + 1 + (B - A - 1) // 2)
| 1 | 109,553,503,318,132 | null | 253 | 253 |
a,b = map(int,input().split())
print(a-2*b if a > 2*b else 0)
|
a, b, c, k = map(int, input().split())
if k <= a:
ans = k
elif k <= a + b:
ans = a
else:
ans = a * 2 + b - k # a-(k-(a+b))
print(ans)
| 0 | null | 94,224,377,650,300 | 291 | 148 |
def resolve():
S, T = input().split()
print(T+S)
if '__main__' == __name__:
resolve()
|
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9
def main():
s,t = input().split()
print(t+s)
if __name__ == '__main__':
main()
| 1 | 102,567,964,091,818 | null | 248 | 248 |
N, K = map(int, input().split())
MOD = 10**9 + 7
ans = 0
A = [0 for _ in range(K+1)]
for i in range(1,K+1):
ans += pow(K//i, N, MOD) * (i - A[i])
ans %= MOD
#print(ans, i)
j = 2*i
while j <= K:
A[j] += i - A[i]
j += i
print(ans)
|
N, M = map(int, input().split())
if N <= 1: a = 0
else: a = N*(N-1) // 2
if M <= 1: b = 0
else: b = M*(M-1) // 2
print(a+b)
| 0 | null | 40,986,954,431,210 | 176 | 189 |
import sys
N, R = map(int, sys.stdin.buffer.read().split())
rate = R
if N < 10:
rate += 100 * (10 - N)
print(rate)
|
a, b, c, k = map(int,input().split())
ans = 0
if a > k:
print(k)
elif a+b > k:
print(a)
else:
print(a-(k-a-b))
| 0 | null | 42,372,357,194,972 | 211 | 148 |
k,n=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
a.append(k+a[0])
b=[0]*(n)
for i in range(n):
b[i]=a[i+1]-a[i]
print(k-max(b))
|
s = input()
a = input()
print("Yes" if a[:-1]==s else "No")
| 0 | null | 32,394,951,644,260 | 186 | 147 |
#ARC162 C:Sum of gcd of Tuples(Easy)
import math
import numpy as np
import itertools
k = int(input())
ans = 0
if k == 1:
ans = 1
else:
for i in range(1,k+1):
for j in range(1,k+1):
a = math.gcd(i,j)
for k in range(1,k+1):
b = math.gcd(a,k)
ans += b
print(ans)
|
import sys
input = sys.stdin.readline
s = list(input().rstrip())
k = int(input())
n = len(s)
group = []
cnt = 0
from collections import Counter
c = Counter(s)
if len(c) == 1:
print(n*k//2)
sys.exit()
for i in range(n):
if i == 0:
cnt += 1
continue
elif i == n - 1:
if s[i] == s[i - 1]:
cnt += 1
group.append(cnt)
else:
group.append(cnt)
group.append(1)
continue
if s[i] == s[i - 1]:
cnt += 1
else:
group.append(cnt)
cnt = 1
ans = 0
if k == 1:
for i in group:
ans += i//2
print(ans)
sys.exit()
from copy import deepcopy
first = deepcopy(group)
last = deepcopy(group)
if s[0] == s[-1]:
first[-1] += last[0]
last[0] = 0
for i in first:
ans += i//2
for i in last:
ans += i//2
if k == 2:
print(ans)
sys.exit()
mid = deepcopy(first)
if s[0] == s[-1]:
mid[0] = 0
temp = 0
for i in mid:
temp += i//2
ans += temp*(k - 2)
print(ans)
| 0 | null | 105,159,389,032,382 | 174 | 296 |
n = int(input())
a = list(map(int,input().split()))
m = 1000
stocks = 0
drops = [False]*(n-1)
for i in range(n-1):
if a[i] > a[i+1]:
drops[i] = True
for i in range(n-1):
if drops[i]:
m+=stocks*a[i]
stocks = 0
else:
stocks+=m//a[i]
m -= (m//a[i])*a[i]
print(m + stocks*a[-1])
|
import sys
from collections import deque
def input():
return sys.stdin.readline().strip()
def main():
H,W = map(int,input().split())
S = [list(input()) for _ in range(H)]
dp = [[float('inf') for _ in range(W)] for _ in range(H)]
def bfs(x,y):
que = deque()
que.append((x,y))
if S[y][x] == '.':
dp[y][x] = 0
else:
dp[y][x] = 1
while que.__len__():
x,y = que.popleft()
for dx,dy in ((1,0),(0,1)):
sx = x + dx
sy = y + dy
if sx == W or sy == H:
continue
if S[y][x] == '.' and S[sy][sx] == '#':
tmp = 1
else:
tmp = 0
dp[sy][sx] = min(dp[y][x]+tmp,dp[sy][sx])
if (sx,sy) not in que:
que.append((sx,sy))
bfs(0,0)
print(dp[H-1][W-1])
if __name__ == "__main__":
main()
| 0 | null | 28,238,412,639,656 | 103 | 194 |
S,T = input().split()
T+=S
print(T)
|
s,t=input().split();print(t+s)
| 1 | 102,945,507,669,678 | null | 248 | 248 |
from itertools import combinations as comb
N = int(input())
L = list(map(int,input().split()))
count = 0
for a, b, c in comb(L, 3):
if a != b and b != c and c != a and a + b > c and b + c > a and c + a > b:
count += 1
print(count)
|
def rotate(arr,i):
if i=='W':
arr=[arr[k-1] for k in [3,2,6,1,5,4]]
if i=='E':
arr=[arr[k-1] for k in [4,2,1,6,5,3]]
if i=='N':
arr=[arr[k-1] for k in [2,6,3,4,1,5]]
if i=='S':
arr=[arr[k-1] for k in [5,1,3,4,6,2]]
return arr
arr=input().split()
deck=[]
for i in 'W'*4:
arr=rotate(arr,i)
for k in 'NNNN':
arr=rotate(arr,k)
deck.append(arr)
arr=rotate(arr,'N')
arr=rotate(arr,'W')
for k in 'NNNN':
arr=rotate(arr,k)
deck.append(arr)
arr=rotate(arr,'W')
arr=rotate(arr,'W')
for k in 'NNNN':
arr=rotate(arr,k)
deck.append(arr)
n=int(input())
for i in range(n):
query=input().split()
for v in deck:
if v[0]==query[0] and v[1]==query[1]:
print(v[2])
break
| 0 | null | 2,691,185,858,108 | 91 | 34 |
print(sum([i for i in range(1,int(input())+1) if not ((i%3==0 and i%5==0) or i%3==0 or i%5==0)]))
|
n = int(input())
l = list(range(0,n+1))
print(sum([i for i in l if i % 3 != 0 and i % 5 != 0]))
| 1 | 34,865,369,798,436 | null | 173 | 173 |
from collections import defaultdict
from math import gcd
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
mod = 10 ** 9 + 7
p = defaultdict(int)
m = defaultdict(int)
ab0 = 0
for a, b in ab:
if a == 0 and b == 0:
ab0 += 1
elif a == 0:
m[(0, 1)] += 1
p[(1, 0)]
elif b == 0:
p[(1, 0)] += 1
else:
g = gcd(a, b)
a //= g
b //= g
sign = a * b
a = abs(a)
b = abs(b)
if sign < 0:
m[(a, b)] += 1
p[(b, a)]
else:
p[(a, b)] += 1
ans = 1
for (a, b), v in p.items():
ans *= pow(2, v, mod) + pow(2, m[(b, a)], mod) - 1
ans %= mod
ans -= 1
ans += ab0
ans %= mod
print(ans)
|
import math
n=int(input())
D={}
for _ in range(n):
a,b=map(int, input().split())
if a==0 and b==0:
key=(0,0)
elif a==0:
key=(0,1)
elif b==0:
key=(1,0)
else:
if a<0:
a=-a
b=-b
g=math.gcd(a, abs(b))
key=(a//g, b//g)
if key not in D:
D[key]=0
D[key]+=1
mod=10**9+7
ans=1
zz=0
for k1, v1 in D.items():
if v1==0:
continue
if k1==(0,0):
zz+=v1
continue
if k1[1]>0:
k2=(k1[1], -k1[0])
else:
k2=(-k1[1], k1[0])
if k2 not in D:
ans=ans*pow(2, v1, mod)%mod
else:
v2=D[k2]
m=(pow(2, v1, mod)+pow(2, v2, mod)-1)%mod
ans=ans*m%mod
D[k2]=0
print((ans+zz-1)%mod)
| 1 | 21,053,013,185,848 | null | 146 | 146 |
def az15():
n = input()
xs = map(int,raw_input().split())
xs.reverse()
for i in range(0,len(xs)):
print xs[i],
az15()
|
_, lis = input(), list(input().split())[::-1]
print(*lis)
| 1 | 986,078,442,400 | null | 53 | 53 |
x = int(input())
a = x//100
b = x%100
l = list(range(1,6))[::-1]
i = 0
cnt = 0
while b > 0:
if l[i] > b: i += 1
cnt += b//l[i]
b = b % l[i]
print(1 if cnt <= a else 0)
|
N = int(input())
S, T = input().split()
L = [S[i]+T[i] for i in range(N)]
print(*L, sep="")
| 0 | null | 119,382,409,481,532 | 266 | 255 |
import sys
import bisect
input = sys.stdin.readline
class Bisect(object):
def bisect_max(self, reva, func,M):
ok = 0 # exist
ng = 4*(10**5) # not exist
while abs(ok-ng) > 1:
cnt = (ok + ng) // 2
if func(cnt,reva,M):
ok = cnt
else:
ng = cnt
return ok
def solve1(tgt,reva,M):
res=0
n = len(reva)
for i in range(n):
tmp = bisect.bisect_left(reva,tgt-reva[i])
tmp = n - tmp
res += tmp
if M <= res:
return True
else:
return False
N,M = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)
reva = a[::-1]
bs = Bisect()
Kmax = (bs.bisect_max(reva,solve1,M))
r=[0]
for i in range(N):
r.append(r[i]+a[i])
res = 0
cnt = 0
t = 0
for i in range(N):
tmp = bisect.bisect_left(reva,Kmax-reva[N-i-1])
tmp2 = bisect.bisect_right(reva,Kmax-reva[N-i-1])
if tmp!=tmp2:
t = 1
tmp = N - tmp
cnt += tmp
res += tmp*a[i]+r[tmp]
if t==1:
res -= (cnt-M)*Kmax
print(res)
|
n, x, m = map(int, input().split())
a = []
check = [-1] * m
i = 0
while check[x] == -1:
a.append(x)
check[x] = i
x = x * x % m
i += 1
if n <= i:
print(sum(a[:n]))
else:
print(
sum(a[:check[x]])
+ (n - check[x]) // (i - check[x]) * sum(a[check[x]:])
+ sum(a[check[x] : check[x] + (n - check[x]) % (i - check[x])]))
| 0 | null | 55,516,115,924,960 | 252 | 75 |
MOD = 998244353
N, S = map(int, input().split())
A = list(map(int, input().split()))
dp = [[0] * (S + 1) for i in range(N)]
dp[0][0] = 2
if A[0] < S + 1:
dp[0][A[0]] = 1
for i in range(1, N):
for j in range(S + 1):
dp[i][j] = (2 * dp[i - 1][j]) % MOD
if 0 <= j - A[i] <= S:
dp[i][j] = (dp[i][j] + dp[i - 1][j - A[i]]) % MOD
print(dp[-1][-1])
|
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()
n,s = na()
a = na()
mod = 998244353
dp = [0]*(s+1)
dp[0] = 1
for i in range(n):
pd = [0]*(s+1)
for j in range(s+1):
if j+a[i] <= s:
pd[j+a[i]] += dp[j]
pd[j] += dp[j]*2%mod
dp = pd
print(dp[s]%mod)
| 1 | 17,719,302,028,960 | null | 138 | 138 |
def inp():
return input()
def iinp():
return int(input())
def inps():
return input().split()
def miinps():
return map(int,input().split())
def linps():
return list(input().split())
def lmiinps():
return list(map(int,input().split()))
def lmiinpsf(n):
return [list(map(int,input().split()))for _ in range(n)]
n,x,t = miinps()
ans = (n + (x - 1)) // x
ans *= t
print(ans)
|
l ='abcdefghijklmnopqrstuvwxyz'
c = input()
x = l.index(c)
print(l[x + 1])
| 0 | null | 48,373,448,963,968 | 86 | 239 |
while(1):
comb = []
count =0
inp = raw_input().split(" ")
if inp[0] == "0" and inp[1] == "0":
break
for i in range(1,int(inp[0])+1):
for j in range(1,int(inp[0])+1):
if i == j:
break
sum = i + j
if sum > int(inp[1]):
j = int(inp[0])
break
for k in range(1,int(inp[0])+1):
if i == j or i == k or j == k:
break
sum = i + j + k
if sum > int(inp[1]):
k = int(inp[0])
break
if sum == int(inp[1]):
if not ([i,j,k] in comb or [i,k,j] in comb or [j,k,i] in comb or [j,i,k] in comb or [k,i,j] in comb or [k,j,i] in comb):
comb.append([i,j,k])
count += 1
print count
|
while True:
k=map(int,raw_input().split(" "))
if k[0]==k[1]==0:
break
ct=0
a=0
b=0
c=0
max=k[0]
sum=k[1]
a=max+1
while True:
a-=1
b=a-1
c=sum-a-b
if not a>c:
print ct
break
while b>c:
if c>0:
ct+=1
b-=1
c+=1
| 1 | 1,272,334,232,620 | null | 58 | 58 |
import sys
input = sys.stdin.readline
from bisect import *
def judge(x):
cnt = 0
for Ai in A:
cnt += N-bisect_left(A, x-Ai+1)
return cnt<M
def binary_search():
l, r = 0, 2*max(A)
while l<=r:
m = (l+r)//2
if judge(m):
r = m-1
else:
l = m+1
return l
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
border = binary_search()
acc = [0]*(N+1)
for i in range(N):
acc[i+1] = acc[i]+A[i]
cnt = 0
ans = 0
for Ai in A:
j = bisect_left(A, border-Ai+1)
cnt += N-j
ans += (N-j)*Ai+acc[N]-acc[j]
ans += (M-cnt)*border
print(ans)
|
t1, t2 = [ int(v) for v in input().split() ]
a1, a2 = [ int(v) for v in input().split() ]
b1, b2 = [ int(v) for v in input().split() ]
if a1*t1 + a2*t2 == b1*t1 + b2*t2:
ans = -1
else:
if a1*t1 + a2*t2 < b1*t1 + b2*t2:
a1, b1 = b1, a1
a2, b2 = b2, a2
mind = a1*t1 - b1*t1
if mind > 0:
ans = 0
else:
lastd = a1*t1 + a2*t2 - b1*t1 - b2*t2
mind = abs(mind)
if mind % lastd == 0:
ans = 2 * (mind // lastd)
else:
ans = 2 * (mind // lastd) + 1
print(ans if ans != -1 else "infinity")
| 0 | null | 119,545,292,058,852 | 252 | 269 |
n = int(input())
p = list(map(int, input().split()))
cnt = 0
p_min = 2*10**5+1
for i in range(n):
if p_min >= p[i]:
cnt += 1
p_min = min(p_min, p[i])
print(cnt)
|
#template
def inputlist(): return [int(j) for j in input().split()]
def listinput(): return input().split()
#template
N,R = inputlist()
if N >= 10:
print(R)
else:
print(R + 100*(10-N))
| 0 | null | 74,600,621,852,988 | 233 | 211 |
import sys
from math import gcd
n = int(input())
a = list(map(int, input().split()))
b = gcd(a[0], a[1])
for i in range(2, n):
b = gcd(b, a[i])
if b != 1:
print('not coprime')
else:
c = set()
num = max(a)
m = 1000000
vals = [0]*(m+1)
for i in range(2, m):
if vals[i] != 0:
continue
j = 1
while True:
t = i*j
if t > m:
break
if vals[t] == 0:
vals[t] = i
j += 1
d = dict()
for i in a:
p = i
while p != 1:
if p in d:
print("setwise coprime")
sys.exit()
d[p] = 1
p = int(p/vals[p])
print("pairwise coprime")
|
import sys
import math
from functools import reduce
N = str(input())
A = list(map(int, input().split()))
M = 10 ** 6
sieve = [0] * (M+1)
for a in A:
sieve[a] += 1
def gcd(*numbers):
return reduce(math.gcd, numbers)
d = 0
for i in range(2, M+1):
tmp = 0
for j in range(i,M+1,i):
tmp += sieve[j]
if tmp > 1:
d = 1
break
if d == 0:
print('pairwise coprime')
exit()
if gcd(*A) == 1:
print('setwise coprime')
exit()
print('not coprime')
| 1 | 4,155,622,762,542 | null | 85 | 85 |
import sys
readline = sys.stdin.readline
import numpy as np
N = int(readline())
A = np.array(readline().split(),dtype=int)
DIV = 10 ** 9 + 7
# 各桁の1と0の数を数えて、((1の数) * (0の数)) * (2 ** i桁目(1桁目を0とする))を数える
K = max(A)
j = 0
ans = 0
while K:
bits = (A >> j) & 1
one = np.count_nonzero(bits)
ans += (one % DIV) * ((N - one) % DIV) * pow(2,j,DIV)
ans %= DIV
j += 1
K >>= 1
print(ans)
|
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
ans = 0
MOD = 10**9+7
for i in range(63):
one, zero = 0, 0
for Aj in A:
if (Aj>>i)&1:
one += 1
else:
zero += 1
ans += 2**i*one*zero
ans %= MOD
print(ans)
| 1 | 122,708,360,701,788 | null | 263 | 263 |
a,b,c,k = (int(a) for a in input().split())
if a >= k :
print(k)
elif a+b >= k :
print(a)
else :
print(a - min(c,(k-(a+b))))
|
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B&lang=ja
import sys
input = sys.stdin.readline
N = int(input())
G = [[a-1 for a in list(map(int, input().split()))[2:]] for _ in [0]*N]
visited = [0]*N
history = [[] for _ in [0]*N]
k = 0
def dfs(v=0, p=-1):
global k
visited[v] = 1
k += 1
history[v].append(k)
for u in G[v]:
if u == p or visited[u]:
continue
dfs(u, v)
k += 1
history[v].append(k)
for i in range(N):
if not visited[i]:
dfs(i)
for i, h in enumerate(history):
print(i+1, *h)
| 0 | null | 10,979,699,876,772 | 148 | 8 |
N, X, T = map(int, input().split())
import math
number_of_times = math.ceil(N/X)
total_time = T * number_of_times
print(total_time)
|
import math
N=int(input())
A=list(map(int,input().split()))
a=max(A)
def era(n):
prime=[]
furui=list(range(2,n+1))
while furui[0]<math.sqrt(n):
prime.append(furui[0])
furui=[i for i in furui if i%furui[0]!=0]
return prime+furui
b=A[0]
for i in range(1,N):
b=math.gcd(b,A[i])
if b!=1:
print("not coprime")
exit()
furui=era(10**6+7)
minfac=list(range(10**6+7))
for i in furui:
for j in range(i,(10**6+7)//i):
if minfac[i*j]==i*j:
minfac[i*j]=i
dummy=[False]*(10**6+7)
for i in range(N):
k=A[i]
while k!=1:
if dummy[minfac[k]]==True:
print("setwise coprime")
exit()
else:
dummy[minfac[k]]=True
f=minfac[k]
while k%f==0:
k//=f
print("pairwise coprime")
| 0 | null | 4,167,487,686,088 | 86 | 85 |
n = int(input())
s = list(map(int, input()))
ans = 0
for i in range(10):
for j in range(10):
for k in range(10):
p = 0
while p < len(s) and s[p] != i: p += 1
p += 1
while p < len(s) and s[p] != j: p += 1
p += 1
while p < len(s) and s[p] != k: p += 1
if p < len(s):
ans += 1
print(ans)
|
n = int(input())
s = input()
ans = 0
for i in range(10):
if str(i) in s:
index_i = s.index(str(i))
for j in range(10):
if str(j) in s[index_i + 1:]:
index_j = s[index_i + 1:].index(str(j)) + index_i + 1
for k in range(10):
if str(k) in s[index_j + 1:]:
ans += 1
print(ans)
| 1 | 128,804,069,740,964 | null | 267 | 267 |
import numpy as np
from numba import njit
@njit('i8(i8)', cache=True)
def solve(x):
count = np.zeros(x + 1, dtype=np.int64)
for i in range(1, x + 1):
for j in range(i, x + 1, i):
count[j] += j
return count.sum()
if __name__ == "__main__":
x = int(input())
print(solve(x))
|
import math
a, b, n = map(int, input().split())
x = min(b - 1, n)
ans = math.floor(a * x / b) - a * math.floor(x / b)
print(ans)
| 0 | null | 19,522,513,321,350 | 118 | 161 |
import sys
X, Y, Z = map(int, sys.stdin.readline().split())
print(Z, X, Y)
|
XYZ = list(map(int, input().split()))
ABC = [0]*3
for i in range(3):
ABC[i] = XYZ[(i+2)%3]
print(" ".join(map(str,ABC)))
| 1 | 38,039,028,189,602 | null | 178 | 178 |
def fib(n):
if n==0:
return 1
elif n==1:
return 1
else:
a,b=1,2
for i in range(n-2):
a,b=b,a+b
return b
print(fib(int(input())))
|
def fib(n):
a = 1
b = 1
if n == 0:
print(a)
elif n == 1:
print(b)
else:
for i in range(n-1):
c = a + b
a , b = b , c
print(c)
n = int(input())
fib(n)
| 1 | 1,657,699,332 | null | 7 | 7 |
'''
Date : 2020-08-09 00:46:52
Author : ssyze
Description :
'''
n, k = map(int, input().split())
a = list(map(int, input().split()))
def check(m):
sum = 0
for i in range(len(a)):
sum += (a[i] - 1) // m
if sum > k:
return False
else:
return True
l = 1
r = 10**9
ans = 10**9
while l < r:
mid = (l + r) // 2
if check(mid) == 1:
r = mid
ans = mid
else:
l = mid + 1
print(ans)
|
from math import sqrt
a,b,c,d = map(float,input().split())
print(sqrt((c-a)**2+(d-b)**2))
| 0 | null | 3,353,602,360,010 | 99 | 29 |
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N, K, C = [int(x) for x in input().strip().split()]
S = [i == 'o' for i in list(input().strip())]
a = [0] * K
b = [2 * 10 ** 5] * K
c = 0
k = 0
for i, s in enumerate(S, start=1):
if c > 0:
c -= 1
continue
if s:
a[k] = i
k += 1
c = C
if k == K:
break
c = 0
k = 0
for i, s in enumerate(S[::-1], start=1):
if c > 0:
c -= 1
continue
if s:
b[K-k-1] = N-i+1
k += 1
c = C
if k == K:
break
for aa, bb in zip(a, b):
if aa == bb:
print(aa)
|
import sys
def input():
return sys.stdin.readline().rstrip()
def main():
n = int(input())
items = {input() for _ in range(n)}
print(len(items))
if __name__ == "__main__":
main()
| 0 | null | 35,412,596,802,320 | 182 | 165 |
import sys
sys.setrecursionlimit(10**7)
import fileinput
def gcd(a, b):
while b:
a, b = b, a % b
return a
def lcm(a, b):
return a * b // gcd(a, b)
for line in sys.stdin:
x, y = map(int, line.split())
print(gcd(x,y),lcm(x,y))
|
def gcd(a,b):
while b: a,b=b,a%b
return a
while True:
try:
a,b = map(int,input().split())
print(gcd(a,b),a*b//gcd(a,b))
except:
break;
| 1 | 663,278,868 | null | 5 | 5 |
n = int(input())
x = input()
x_popcnt = x.count('1')
one_popcnt = x_popcnt - 1
zero_popcnt = x_popcnt + 1
one_mod = 0
zero_mod = 0
for b in x:
if one_popcnt != 0:
one_mod = (one_mod*2 + int(b)) % one_popcnt
zero_mod = (zero_mod*2 + int(b)) % zero_popcnt
f = [0]*220000
popcnt = [0]*220000
for i in range(1, 220000):
popcnt[i] = popcnt[i//2] + i % 2
f[i] = f[i % popcnt[i]] + 1
for i in range(n-1, -1, -1):
if x[n-1-i] == '1':
if one_popcnt != 0:
nxt = one_mod
nxt -= pow(2, i, one_popcnt)
nxt %= one_popcnt
print(f[nxt]+1)
else:
print(0)
if x[n-1-i] == '0':
nxt = zero_mod
nxt += pow(2, i, zero_popcnt)
nxt %= zero_popcnt
print(f[nxt]+1)
|
N = int(input())
pl = []
mi = []
for i in range(N):
_m = 0
_t = 0
s = input()
for c in s:
if c == ")":
_t -= 1
_m = min(_m, _t)
else:
_t += 1
if _t > 0:
pl.append([-_m, -_t]) # sortの調整のために負にしている
else:
mi.append([- _t + _m, _m, _t])
pl = sorted(pl)
mi = sorted(mi)
#import IPython;IPython.embed()
if len(pl) == 0:
if mi[0][0] == 0:
print("Yes")
else:
print("No")
exit()
if len(mi) == 0:
print("No")
exit()
tot = 0
for m, nt in pl:
if tot - m < 0: # これはひくではないのでは?
print("No")
exit()
else:
tot -= nt
for d, m, nt in mi:
if tot + m <0:
print("No")
exit()
else:
tot += nt
if tot != 0:
print("No")
else:
print("Yes")
# どういう時できるか
# で並べ方
# tot, minの情報が必要
# totが+のものはminとtotを気をつける必要がある
# minがsum以上であればどんどん足していけばいい.
# なのでminが大きい順にsortし,totの大きい順にsort
# その次はtotがminusの中ではminが小さい順に加える
# 合計が0になる時Yes,それ意外No.
| 0 | null | 16,026,037,007,892 | 107 | 152 |
A,B = map(int,input().split())
print(max(0,A-B*2))
|
x = list(map(int,input().split()))
a = x[0]
b = x[1]
if(2*b < a):
print(a-2*b)
else:
print(0)
| 1 | 167,164,881,692,780 | null | 291 | 291 |
memo = {}
def fib(n):
"""
:param n: non-negative integer
:return: n-th fibonacci number
"""
if n == 0 or n == 1:
return 1
try:
return memo[n]
except KeyError:
pass
res = fib(n-1) + fib(n-2)
memo[n] = res
return res
n = int(input())
print(fib(n))
|
while True:
a,b = map(int,input().split())
if a == 0 and b == 0:
break
if a < b:
print(a,b)
elif b < a:
print(b,a)
else:
print(a,b)
| 0 | null | 262,676,987,052 | 7 | 43 |
A = [list(map(int,input().split())) for _ in range(3)]
N = int(input())
B = [[0 for _ in range(3)] for _ in range(3)]
for _ in range(N):
b = int(input())
for i in range(3):
for j in range(3):
if A[i][j]==b:
B[i][j] = 1
flag = 0
for i in range(3):
if sum(B[i])==3:
flag = 1
break
for j in range(3):
cnt = 0
for i in range(3):
cnt += B[i][j]
if cnt==3:
flag = 1
break
if B[0][0]+B[1][1]+B[2][2]==3:
flag = 1
if B[2][0]+B[1][1]+B[0][2]==3:
flag = 1
if flag==1:
print("Yes")
else:
print("No")
|
a = input()
a = a.split()
b = input()
b = b.split()
c = input()
c = c.split()
d = [a[0],b[0],c[0]]
e = [a[1],b[1],c[1]]
f = [a[2],b[2],c[2]]
g = [a[0],b[1],c[2]]
h = [a[2],b[1],c[0]]
n = int(input())
for i in range(n):
j = int(input())
for k in range(3):
if int(a[k])==j:
a.pop(k)
a.insert(k,0)
if int(b[k])==j:
b.pop(k)
b.insert(k,0)
if int(c[k])==j:
c.pop(k)
c.insert(k,0)
if int(d[k])==j:
d.pop(k)
d.insert(k,0)
if int(e[k])==j:
e.pop(k)
e.insert(k,0)
if int(f[k])==j:
f.pop(k)
f.insert(k,0)
if int(g[k])==j:
g.pop(k)
g.insert(k,0)
if int(h[k])==j:
h.pop(k)
h.insert(k,0)
if a == [0,0,0] or b == [0,0,0] or c == [0,0,0] or d == [0,0,0] or e == [0,0,0] or f == [0,0,0] or g == [0,0,0] or h == [0,0,0]:
print("Yes")
else:
print("No")
| 1 | 59,851,249,094,026 | null | 207 | 207 |
H, W, K = map(int, input().split())
c = []
b_h = [0] * H
b_w = [0] * W
b = 0
for h in range(H):
c.append(input().rstrip())
for w in range(W):
if c[h][w] == "#":
b_h[h] += 1
b_w[w] += 1
b += 1
ans = 0
for hi in range(2 ** H):
for wi in range(2 ** W):
bsum = b
for h in range(H):
if hi & (2 ** h) != 0:
bsum -= b_h[h]
for w in range(W):
if wi & 2 ** w != 0:
if c[h][w] == '#':
bsum += 1
for w in range(W):
if wi & (2 ** w) != 0:
bsum -= b_w[w]
if bsum == K:
ans += 1
print(ans)
|
# -*- coding: utf-8 -*-
def f(c, h_patterns, w_patterns, black_count):
used = [[False for _ in range(len(w_patterns))]
for _ in range(len(h_patterns))]
for index, h_pattern in enumerate(h_patterns):
if h_pattern != 1:
continue
for w_dash in range(len(w_patterns)):
if not used[index][w_dash] and c[index][w_dash] == '#':
used[index][w_dash] = True
black_count -= 1
for index, w_pattern in enumerate(w_patterns):
if w_pattern != 1:
continue
for h_dash in range(len(h_patterns)):
if not used[h_dash][index] and c[h_dash][index] == '#':
used[h_dash][index] = True
black_count -= 1
return black_count
def main():
from itertools import product
h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]
black_count = 0
ans = 0
for hi in range(h):
for wi in range(w):
if c[hi][wi] == '#':
black_count += 1
for h_patterns in product([1, 0], repeat=h):
for w_patterns in product([1, 0], repeat=w):
fi = f(c, h_patterns, w_patterns, black_count)
if fi == k:
ans += 1
print(ans)
if __name__ == '__main__':
main()
| 1 | 8,966,531,049,850 | null | 110 | 110 |
N = int(input())
A = [int(i) for i in input().split()]
A.sort()
S = -A[-1]
for i in range(N):
S += A[N-i//2-1]
print(S)
|
n = int(input())
al = list(map(int, input().split()))
al.sort(reverse=True)
ans = al[0]
for i in range(n-2):
ans += al[i//2+1]
print(ans)
| 1 | 9,102,380,867,808 | null | 111 | 111 |
c = input()
alphabet = 'abcdefghijklmnopqrstuvwxyz'
list_a = list(alphabet)
num_c = list_a.index(c)
print(list_a[num_c + 1])
|
C = ord(input())
C += 1
print(chr(C))
| 1 | 91,996,343,602,780 | null | 239 | 239 |
A = int(input())
B = int(input())
lis = [1, 2, 3]
x = lis.index(A)
y = lis.index(B)
lis[x] = 0
lis[y] = 0
ans = sum(lis)
print(ans)
|
def roundone(a, b):
abc = "123"
return abc.replace(a, "").replace(b, "")
def main():
a = str(input())
b = str(input())
print(roundone(a, b))
if __name__ == '__main__':
main()
| 1 | 110,817,790,096,750 | null | 254 | 254 |
MOD = 1000000007
N, K = map(int, input().split())
ans = 0
f = [0] * (K+1)
g = [0] * (K+1)
for t in range(K, 0, -1):
f[t] = pow(K//t, N, MOD)
g[t] = f[t]
for s in range(2 * t, K+1, t):
g[t] -= g[s]
ans = (ans + t * g[t]) % MOD
print(ans)
|
n = int(input())
print("Yes" if n % 9 == 0 else "No")
| 0 | null | 20,627,492,415,896 | 176 | 87 |
S = input()
if S == "RRR":
print(3)
elif S == "RRS" or S == "SRR":
print(2)
elif "R" in S:
print(1)
else:
print(0)
|
S = input()
if ("RRR" in S):
print("3")
elif ("RR" in S):
print("2")
elif ("R" in S):
print("1")
else:
print("0")
| 1 | 4,896,201,998,070 | null | 90 | 90 |
N = int(input())
ans = 0
for a in range(1, 10 ** 6 + 1):
for b in range(1, 10 ** 6 + 1):
if a * b >= N:
break
ans += 1
print(ans)
|
N=int(input())
A=[int(a) for a in input().split()]
dp=[-1 for _ in range(N)]
dp[0]=1000
for i in range(1,N):
tmp=dp[i-1]
for j in range(i):
K=dp[j]//A[j]
res=dp[j]-K*A[j]
tmp=max(tmp,res+A[i]*K)
dp[i]=tmp
print(dp[-1])
| 0 | null | 5,002,692,555,448 | 73 | 103 |
N=int(input())
S,T=input().split()
list=[]
for i in range(N):
list.append(S[i]+T[i])
print(''.join(list))
|
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n,m = inpl()
s = list(input())[::-1]
res = []
now = 0
while now != n:
nex = min(now + m, n)
while s[nex] == '1':
nex -= 1
if nex == now:
print(-1)
quit()
res += [nex - now]
now = nex
print(*res[::-1])
| 0 | null | 125,977,276,623,552 | 255 | 274 |
import sys
input = sys.stdin.readline
from collections import *
S = input()[:-1]
K = int(input())
if S==S[0]*len(S):
print(len(S)*K//2)
exit()
l = []
cnt = 1
for i in range(len(S)-1):
if S[i]!=S[i+1]:
l.append((S[i], cnt))
cnt = 1
else:
cnt += 1
l.append((S[-1], cnt))
if K==1 or l[0][0]!=l[-1][0]:
ans = 0
for _, c in l:
ans += c//2*K
else:
ans = (l[0][1]+l[-1][1])//2*(K-1)
ans += l[0][1]//2
ans += l[-1][1]//2
for _, c in l[1:-1]:
ans += c//2*K
print(ans)
|
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))
S = input()
N = len(S)
K = ii()
cnt = 0
#for i in range(1, N):
i = 1
flag = 0
if S.count(S[0]) == N:
print(N * K // 2)
exit()
while i < N:
if S[i] == S[i-1]:
cnt += 1
if i + 1 < N and S[i] == S[i+1]:
i += 1
if i == N-1:
flag = 1
i += 1
if flag and S[0] == S[-1]:
cnt += 1
cnt_sub = 0
S = S[1:] + S[0]
i = 1
flag = 0
while i < N:
if S[i] == S[i-1]:
cnt_sub += 1
if i + 1 < N and S[i] == S[i+1]:
i += 1
i += 1
print(cnt + cnt_sub * (K-2) + cnt_sub - 1)
else:
print(cnt * K)
| 1 | 175,270,427,564,100 | null | 296 | 296 |
S = input()
K = int(input())
ss = []
seq = 1
for a,b in zip(S,S[1:]):
if a==b:
seq += 1
else:
ss.append(seq)
seq = 1
ss.append(seq)
if len(ss)==1:
print(len(S)*K//2)
exit()
if S[0] != S[-1]:
ans = sum([v//2 for v in ss]) * K
print(ans)
else:
ans = sum([v//2 for v in ss[1:-1]]) * K
ans += (ss[0]+ss[-1])//2 * (K-1)
ans += ss[0]//2 + ss[-1]//2
print(ans)
|
d = int(input())
*C, = map(int, input().split())
S = [list(map(int, input().split())) for i in range(d)]
X = [int(input()) - 1 for i in range(d)]
L = [-1 for j in range(26)]
score = 0
for i in range(d):
L[X[i]] = i
score += S[i][X[i]]
score -= sum([C[j] * (i - L[j]) for j in range(26)])
print(score)
| 0 | null | 92,638,182,185,442 | 296 | 114 |
# 解説AC
# 解説放送と
# https://twitter.com/kyopro_friends/status/1274710268262547456?s=20
# で理解
MOD = 10**9 + 7
def main():
K = int(input())
S = input()
N = len(S)
m = N+K + 5
fac = [0] * m
finv = [0] * m
inv = [0] * m
def COMBinitialize(m):
fac[0] = 1
finv[0] = 1
if m > 1:
fac[1] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, m):
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 COMB(n, k):
if n < k:
return 0
if n < 0 or k < 0:
return 0
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
COMBinitialize(m)
ans = 0
for i in range(K+1):
v = COMB(N-1+K-i, N-1)
v %= MOD
v *= pow(25, (K-i), MOD)
v %= MOD
v *= pow(26, i, MOD)
v %= MOD
ans += v
ans %= MOD
print(ans)
if __name__ == '__main__':
main()
|
n=int(input(""))
lista=[0]*n
a=input("").split(" ")
for i in a:
lista[int(i)-1]+=1
for i in lista:
print(i)
| 0 | null | 22,801,067,545,464 | 124 | 169 |
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
def ceil(a, b):
return (a + b - 1) // b
def sum_of_arithmetic_progression(s, d, n):
return n * (2 * s + (n - 1) * d) // 2
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def lcm(a, b):
g = gcd(a, b)
return a / g * b
def ok(t, s):
N = len(t)
for i in range(N):
if t[i]:
for x, y in s[i]:
if y == 1:
if not t[x]:
return False
elif y == 0:
if t[x]:
return False
return True
def solve():
N = int(input())
s = defaultdict(list)
for i in range(N):
A = int(input())
for _ in range(A):
X, Y = map(int, input().split())
X -= 1
s[i].append((X, Y))
ans = 0
for b in range(2 ** N):
t = [0] * N
num = 0
for i in range(N):
if (b >> i) & 1:
t[i] = 1
num += 1
if ok(t, s):
ans = max(ans, num)
print(ans)
def main():
solve()
if __name__ == '__main__':
main()
|
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF = float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353
def popcount(x):
'''xの立っているビット数をカウントする関数
(xは64bit整数)'''
# 2bitごとの組に分け、立っているビット数を2bitで表現する
x = x - ((x >> 1) & 0x5555555555555555)
# 4bit整数に 上位2bit + 下位2bit を計算した値を入れる
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f # 8bitごと
x = x + (x >> 8) # 16bitごと
x = x + (x >> 16) # 32bitごと
x = x + (x >> 32) # 64bitごと = 全部の合計
return x & 0x0000007f
N = int(input())
x = [[] for i in range(N)]
for i in range(N):
A = int(input())
for j in range(A):
p, q = map(int, input().split())
x[i].append([p-1, q])
ans = 0
for i in range(0,2**N):
flag = 1
for j in range(N):
if ((i >> j) & 1):
for xx in x[j]:
if xx[1] == 1:
if not ((i >> xx[0]) & 1):
flag = 0
break
else:
if ((i >> xx[0]) & 1):
flag = 0
break
if flag == 0:
break
if flag == 0:
continue
else:
ans = max(ans, popcount(i))
print(ans)
| 1 | 121,323,170,851,960 | null | 262 | 262 |
x,k,d = map(int, input().split())
x = abs(x)
if x - d*k >= 0:
print(abs(x-d*k))
else:
a = x // d
if k % 2 == 0:
if a % 2 == 0:
print(abs(x - d*a))
else:
print(abs(x - d * (a+1)))
else:
if a % 2 == 0:
print(abs(x - d * (a + 1)))
else:
print(abs(x - d * a))
|
# coding: utf-8
# Your code here!
class Dice:
def __init__(self,lst):
self.face=lst
self.order="NNNNWNNNWNNNENNNENNNWNNN"
def roll(self,x):
tmp=self.face
if x=="E":
self.face=[tmp[3],tmp[1],tmp[0],tmp[5],tmp[4],tmp[2]]
if x=="W":
self.face=[tmp[2],tmp[1],tmp[5],tmp[0],tmp[4],tmp[3]]
if x=="N":
self.face=[tmp[1],tmp[5],tmp[2],tmp[3],tmp[0],tmp[4]]
if x=="S":
self.face=[tmp[4],tmp[0],tmp[2],tmp[3],tmp[5],tmp[1]]
def showDown(self):
return self.face[0]
def query(self,lst):
tmp=self.face
ans=-1
for i in self.order:
self.roll(i)
if self.face[0]==lst[0] and self.face[1]==lst[1]:
ans=self.face[2]
break
self.face=tmp
return ans
dice=Dice(list(map(int,input().split(" "))))
num=int(input())
q=[list(map(int,input().split())) for i in range(num)]
for i in q:
print(dice.query(i))
| 0 | null | 2,749,398,912,500 | 92 | 34 |
n = int(input())
a = list(map(int, input().split()))
ans = [None]*n
all = 0
for i in range(n):
all = all^a[i]
for i in range(n):
ans[i]=str(all^a[i])
print(' '.join(ans))
|
n,k = map(int,input().split())
a = list(map(int,input().split()))#消化コスト
f = list(map(int,input().split()))#食べにくさ
a.sort(reverse = True)
f.sort()
top = 10**13
bot = -1
def ok(x):
res = 0
for i in range(n):
res += max(0,a[i] - (x//f[i]))
return res <=k
while top - bot > 1:
mid = (top + bot) //2
if ok(mid):top = mid
else:bot = mid
print(top)
| 0 | null | 88,641,437,227,662 | 123 | 290 |
n = int(input())
print((n - (n+1)%2)//2)
|
s = input(); t= input()
if(s == t[0:-1] and len(s)+1==len(t)):
print("Yes")
else:
print("No")
| 0 | null | 87,519,414,826,272 | 283 | 147 |
n = int(input())
A = list(map(int, input().split()))
N = sorted(range(1, n + 1), key=lambda x: A[x - 1])
print(*N)
|
N = int(input())
A = list(map(int,input().split()))
B = [[A[i],i+1]for i in range(N)]
B.sort()
ans = [B[i][1]for i in range(N)]
print(" ".join(map(str,ans)))
| 1 | 180,832,181,695,452 | null | 299 | 299 |
input()
ls = input().split()
print(' '.join(reversed(ls)))
|
N,K=map(int,input().split())
ans=[0]*(K+1)
mod=10**9+7
for i in range(K,0,-1):
ans[i]=pow((K//i),N,mod)
ind=2
while i*ind<=K:
ans[i]-=ans[i*ind]
ans[i]%=mod
ind+=1
res=0
for i in range(1,K+1):
res+=i*ans[i]
res%=mod
print(res)
| 0 | null | 18,949,214,222,618 | 53 | 176 |
# A - Kth Term
def main():
orig = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
seq = list(map(lambda s: s.strip(), orig.split(",")))
K = int(input()) - 1
print(seq[K])
if __name__ == "__main__":
main()
|
print [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
][int(raw_input())-1]
| 1 | 50,248,320,869,428 | null | 195 | 195 |
import os
import sys
from io import BytesIO, IOBase
def main():
n, m = getints()
g = [0] * n
for i in range(n):
g[i] = i
def find(u):
if u == g[u]:
return u
else:
g[u] = find(g[u])
return g[u]
def merge(u, v):
g[find(u)] = find(v)
for _ in range(m):
a, b = getints()
merge(a - 1, b - 1)
cnt = 0
for i in range(n):
if i == g[i]:
cnt += 1
print(cnt - 1)
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def input(): return sys.stdin.readline().rstrip("\r\n")
def getint(): return int(input())
def getints(): return list(map(int, input().split()))
def getint1(): return list(map(lambda x: int(x) - 1, input().split()))
# endregion
if __name__ == "__main__":
main()
|
import sys
from collections import defaultdict
from math import gcd
def input(): return sys.stdin.readline().strip()
mod = 1000000007
def main():
N = int(input())
fish = defaultdict(int)
"""
b / aで値を管理するのは浮動小数点誤差が怖いので、
g = gcd(a, b) として(a//g, b//g)のタプルで管理するのが良い。
"""
zero = 0
for _ in range(N):
a, b = map(int, input().split())
if a == 0 and b == 0: zero += 1
elif a == 0: fish[(0, 1)] += 1
elif b == 0: fish[(1, 0)] += 1
else:
g = gcd(a, b)
if a < 0: a, b = -a, -b
fish[(a // g, b // g)] += 1
#print(fish)
"""
仲の悪い組を(S1, T1), (S2, T2),...とすれば(Si, Ti)からの魚の選び方と
(Sj, Tj)からの魚の選び方は独立じゃん。
なぜ気づかなかったのか。。。
"""
ans = 1
finished = set([])
for a, b in fish:
if (a, b) in finished: continue
finished.add((a, b))
s = fish[(a, b)]
if b > 0:
t = fish[(b, -a)] if (b, -a) in fish else 0
finished.add((b, -a))
else:
t = fish[(-b, a)] if (-b, a) in fish else 0
finished.add((-b, a))
ans *= pow(2, s, mod) + pow(2, t, mod) - 1
ans %= mod
#print("(a, b)=({}, {}) -> s={}, t={}, val={}".format(a, b, s, t, pow(2, s, mod) + pow(2, t, mod) - 1))
print((ans + zero - 1) % mod)
if __name__ == "__main__":
main()
| 0 | null | 11,637,525,174,838 | 70 | 146 |
from itertools import combinations
N = int(input())
L = list(map(int, input().split()))
count = 0
for C in combinations(L, 3):
l_list = list(C)
l_list.sort()
if l_list[2] > l_list[1] and l_list[1] > l_list[0]:
if l_list[2] < l_list[1] + l_list[0]:
count += 1
print(count)
|
import itertools
n = int(input())
l = list(map(int, input().split()))
p_list = list(itertools.permutations(l, 3))
results = [x for x in p_list if max(x) < (sum(x) - max(x)) and len(x) == len(set(x))]
print(int(len(results) / 6))
| 1 | 5,109,576,086,572 | null | 91 | 91 |
A,B,C,K = map(int,input().split())
if K-A > 0:
if K-A-B > 0:
print(A-(K-A-B))
else:
print(A)
else:
print(K)
|
a,b,c,k=map(int,input().split())
ans=a
if k-a<=0:
print(k)
exit()
if k-a-b<=0:
print(ans)
exit()
if k-a-b-c<0:
ans=ans+(k-a-b)*(-1)
print(ans)
else:
ans=ans-c
print(ans)
| 1 | 21,696,337,203,258 | null | 148 | 148 |
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)
|
import math
def rotate(x, y, theta):
return (round(x*math.cos(theta) -1*y*math.sin(theta), 5), round(x*math.sin(theta) + y*math.cos(theta), 5))
def koch(p1, p2, n):
s = (round((2*p1[0] + p2[0])/3, 5), round((2*p1[1] + p2[1])/3, 5))
t = (round((p1[0] + 2*p2[0])/3, 5), round((p1[1] + 2*p2[1])/3, 5))
rotated = rotate(t[0]-s[0], t[1]-s[1], math.pi/3)
u = (s[0] + rotated[0], s[1] + rotated[1])
if n == 0:
print(round(p1[0], 5), round(p1[1], 5))
elif n == -1:
return None
koch(p1, s, n-1)
koch(s, u, n-1)
koch(u, t, n-1)
koch(t, p2, n-1)
n = int(input())
koch((0.0, 0.0), (100, 0.0), n)
print(100, 0.0)
| 1 | 126,761,442,030 | null | 27 | 27 |
n,m = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
if n >= sum(a):
print(n - sum(a))
else:
print(-1)
|
#!/usr/bin/env python3
from collections import defaultdict
n,k = map(int,input().split())
a = list(map(int,input().split()))
cum_sum = [0]*(n+1)#累積和 - i (要素すう)modk
for i in range(n):
cum_sum[i+1] = (cum_sum[i]+a[i]-1) % k#cum_sum[i]-iが一定
D = defaultdict(int)
count = 0
for i in range(n+1):
count += D[cum_sum[i]] #key が場所、val がcum_sumの値
D[cum_sum[i]] += 1
if i-k+1 >= 0:#区間の長さがあまりよりも小さいなら
D[cum_sum[i-k+1]] -=1
print(count)
| 0 | null | 85,087,060,169,118 | 168 | 273 |
H, N = map(int, input().split())
As = list(map(int, input().split()))
sumA = sum(As)
if sumA >= H:
print('Yes')
else:
print('No')
|
H,N=map(int,input().split())
list=[]
for i in map(int,input().split()):
list.append(i)
if H - sum(list) <= 0:
print('Yes')
else:
print('No')
| 1 | 78,013,260,847,616 | null | 226 | 226 |
n = int(input())
a = list(map(int, input().split()))
p = 1000
k = 0
for i in range(n-1):
if k>0 and a[i]>a[i+1]:
p += k*a[i]
k = 0
elif k==0 and a[i]<a[i+1]:
k = p//a[i]
p %= a[i]
if k>0:
p += k*a[-1]
print(p)
|
n,*A=map(int,open(0).read().split());m=1000
for x,y in zip(A,A[1:]):
if x<y:m=m//x*y+m%x
print(m)
| 1 | 7,318,971,116,960 | null | 103 | 103 |
def resolve():
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]
good = [True for i in range(N)]
for a, b in AB:
a, b = a-1, b-1
if H[a] < H[b]:
good[a] = False
elif H[a] == H[b]:
good[a] = False
good[b] = False
else:
good[b] = False
cnt = 0
for g in good:
if g:
cnt += 1
print(cnt)
if '__main__' == __name__:
resolve()
|
import bisect
class Peaks:
def __init__(self, N, H, next_obs_heights):
self.N = N
self.H = H
self.next_obs_heights = next_obs_heights
def solve(self):
result = 0
for i in range(N):
if len(next_obs_heights[i]) == 0:
result += 1
continue
next_num = len(next_obs_heights[i])
if self.H[i] > next_obs_heights[i][next_num-1]:
result += 1
print(result)
N, M = map(int, input().split())
H = list(map(int, input().split()))
next_obs_heights = [ [] for i in range(N) ]
for i in range(M):
a, b = map(int, input().split())
a, b = a-1, b-1
bisect.insort(next_obs_heights[a], H[b])
bisect.insort(next_obs_heights[b], H[a])
peaks = Peaks(N, H, next_obs_heights)
peaks.solve()
| 1 | 25,057,222,164,028 | null | 155 | 155 |
from collections import deque
h, w = list(map(int, input().split()))
grid = [input() for _ in range(h)]
ans = [[10000]*w for _ in range(h)]
ans[0][0] = 0 if grid[0][0] == "." else 1
queue = deque([(0, 0)])
while len(queue) > 0:
x, y = queue.popleft()
for xo, yo in [(0, 1), (1, 0)]:
xnext, ynext = x+xo, y+yo
if xnext >= w or ynext >= h:
continue
if grid[y][x] == "." and grid[ynext][xnext] == "#":
if ans[y][x] + 1 < ans[ynext][xnext]:
ans[ynext][xnext] = ans[y][x] + 1
queue.append((xnext, ynext))
else:
if ans[y][x] < ans[ynext][xnext]:
ans[ynext][xnext] = ans[y][x]
queue.append((xnext, ynext))
print(ans[h-1][w-1])
|
#入力の高速化
import sys
input = sys.stdin.readline
# ユニオンファインド
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
n,m= map(int, input().split())
g= [list(map(int, input().split())) for i in range(m)]
UF=UnionFind(n)
for a,b in g:
a-=1
b-=1
UF.union(a,b)
ans=UF.group_count()-1
print(ans)
| 0 | null | 25,633,500,184,368 | 194 | 70 |
import sys
from collections import Counter
input = sys.stdin.readline
N = int(input())
C = list(input().strip())
counter = Counter(C)
if len(counter) == 1:
print(0)
else:
red_n = counter["R"]
ans = 0
for i in range(N):
if red_n <= i:
break
if C[i] == "W":
ans += 1
print(ans)
|
n, s = input(), input()
print(s[:s.count("R")].count("W"))
| 1 | 6,306,625,577,616 | null | 98 | 98 |
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
mod = 10 ** 9 +7
N, K = map(int, readline().split())
# s = [0] * (N+1)
# g = [0] * (N+1)
# g[0] = N % mod
# for i in range(1,N+1):
# s[i] += (s[i-1] + i ) % mod
# g[i] += (g[i-1] + N - i) % mod
# ans = (sum(g[K-1:]) % mod - sum(s[K-1:]) % mod + N-K+2) % mod
# print(ans)
k = np.arange(K,N+2,dtype = np.int64)
low = k*(k-1)//2
high = k*(2*N - k + 1) //2
cnt = high-low+1
print(sum(cnt)%mod)
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
# prepare combs upto 10000
mod = 10**9 + 7
facts = [1] * 100001
for i in range(0, 100000):
facts[i+1] = facts[i] * (i + 1) % mod
ifacts = [1] * 100001
ifacts[100000] = pow(facts[100000], mod - 2, mod)
for i in range(100000, 0, -1):
ifacts[i-1] = ifacts[i] * i % mod
def comb(n, k):
return facts[n] * ifacts[n-k] % mod * ifacts[k] % mod
ans = 0
for i in range(k-1, n):
# take k-1 from i
ans = (ans + a[i] * comb(i, k-1)) % mod
for i in range(0, n-k+1):
# take k-1 from n-i-1
ans = (ans - a[i] * comb(n-i-1, k-1)) % mod
print(ans)
| 0 | null | 64,752,201,871,518 | 170 | 242 |
def resolve():
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]
a = [0] * 100001
for i in A:
a[i] += i
ans = sum(a)
for b, c in BC:
if a[b] == 0:
print(ans)
continue
move = a[b] // b
a[b] = 0
a[c] += c * move
ans += (c - b) * move
print(ans)
if __name__ == "__main__":
resolve()
|
import sys
input = sys.stdin.readline
x, y = [int(x) for x in input().split()]
ans = 0
for i in [x, y]:
if i == 1:
ans += 300000
elif i == 2:
ans += 200000
elif i == 3:
ans += 100000
if x == 1 and y == 1:
ans += 400000
print(ans)
| 0 | null | 76,232,621,281,362 | 122 | 275 |
import sys
import itertools
sys.setrecursionlimit(10000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
if __name__ == "__main__":
a,b,c,d = map(int,input().split())
e = a*c
f = a*d
g = b*c
h = b*d
ans = max(e,f)
ans = max(ans,g)
ans = max(ans,h)
print(ans)
|
a,b,c,d = map(int,input().split())
answers = []
one = a*c
two = a*d
three = b*c
four = b*d
answers.append(one)
answers.append(two)
answers.append(three)
answers.append(four)
print(max(answers))
| 1 | 3,028,683,645,568 | null | 77 | 77 |
l = []
for i in range(int(input())): l.append(input())
print(len(set(l)))
|
N=int(input())
se=set(input() for _ in range(N))
print(len(se))
| 1 | 30,290,620,111,850 | null | 165 | 165 |
h, w, k = map(int, input().split())
s = [[int(i) for i in input()] for _ in range(h)]
ans = (h-1)+(w-1)
for i in range(2**(h-1)):
d = [(i >> j) & 1 for j in range(h-1)]
count, count_tmp = [0]*(sum(d)+1), [0]*(sum(d)+1)
ans_, res = 0, 0
flag = False
for w_ in range(w):
count[0] += s[0][w_]
count_tmp[0] += s[0][w_]
res += 1
tmp = 0
for h_ in range(1, h):
if d[h_-1]: tmp += 1
if s[h_][w_]:
count[tmp] += 1
count_tmp[tmp] += 1
for j in count:
if j > k:
if res==1:
flag = True
break
else:
for idx in range(sum(d)+1):
count[idx] = count_tmp[idx]
ans_ += 1
res = 1
break
if flag: break
count_tmp = [0]*(sum(d)+1)
if flag: continue
ans_ += sum(d)
ans = min(ans, ans_)
print(ans)
|
h,w,k=map(int,input().split())
cho=[]
for _ in range(h):
a=list(input())
for f in range(w):
a[f]=int(a[f])
cho.append(a)
ans=1000000000009
for i in range(2**(h-1)):
cut=0
cut_n=[]
b=[]
for j in range(h-1):
if (i>>j)&1:
cut_n.append(j+1)
cut+=1
if len(cut_n)==0:
ok=1
dp=0
for i in range(w):
wa=0
for j in range(h):
wa+=cho[j][i]
if dp+wa>k:
cut+=1
dp=wa
else:
dp+=wa
if wa>k:
ok+=1
break
if ok==1:
ans=min(ans,cut)
else:
st=0
for t in range(len(cut_n)):
if t==len(cut_n)-1:
b.append(cut_n[t]-st)
b.append(h-cut_n[t])
else:
b.append(cut_n[t]-st)
st=cut_n[t]
dp=[0 for _ in range(len(b))]
ok=1
for y in range(w):
for g in dp:
if g>k:
ok+=1
break
st=0
ch=0
c=[]
for e in range(len(b)):
p=b[e]
temp=0
for q in range(p):
temp+=cho[st+q][y]
dp[e]+=cho[st+q][y]
c.append(temp)
st+=p
for g in dp:
if g>k:
ch+=1
if ch!=0:
cut+=1
dp=c
for last in c:
if last>k:
ok+=1
if ok==1:
ans=min(ans,cut)
print(ans)
| 1 | 48,481,080,441,618 | null | 193 | 193 |
n, k = map(int, input().split())
if n % k == 0:
print(0)
else:
ans = n % k
#print(ans)
while ans > k//2:
n = abs(ans - k)
ans = min(n, ans)
print(ans)
|
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
n,k = map(int, input().split())
m = n % k
m = 0 if m == 0 else abs(m - k)
print(min(n, m))
| 1 | 39,204,411,071,102 | null | 180 | 180 |
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import combinations
def run():
n,k = map(int, input().split())
mod = 10 ** 9 + 7
ret = 0
inv = generate_inv(n, mod)
if k >= n-1:
k = n-1
left = 1
right = 1
ret = 1
for h in range(1, k+1):
right *= (n - h) * inv[h]
right %= mod
left *= (n - h + 1) * inv[h]
left %= mod
ret += right * left
ret %= mod
print(ret)
def generate_inv(n,mod):
"""
逆元行列
n >= 2
"""
ret = [0, 1]
for i in range(2,n+1):
next = -ret[mod%i] * (mod // i)
next %= mod
ret.append(next)
return ret
def comb_mod(n, a, mod):
"""
return: [n, a] % mod
Note: mod must be a prime number
"""
up = 1
down = 1
for i in range(a):
up *= n - i
up %= mod
down *= i + 1
down %= mod
down = pow_mod(down, mod - 2, mod)
return (up * down) % mod
def pow_mod(n, k, mod):
res = 1
while True:
if k // 2 >= 1:
if k % 2 == 1:
res = (res * n) % mod
n = (n ** 2) % mod
k = k // 2
else:
break
return (n * res) % mod
if __name__ == "__main__":
run()
|
# get input from user and convert in to int
current_temp = int(input())
# Check that the restriction per task instruction is met
if (current_temp <= 40) and (current_temp >= -40):
# Check if current_temp is greater than or equal to 30
if current_temp >= 30:
print("Yes")
else:
print("No")
| 0 | null | 36,347,175,141,180 | 215 | 95 |
N = int(input())
A = sorted(list(map(int,input().split())),reverse=True)
if N%2==0:
cnt = A[0]
for i in range(1,N//2):
cnt += 2*A[i]
print(cnt)
else:
cnt = A[0]
for i in range(1,N//2):
cnt += 2*A[i]
cnt += A[N//2]
print(cnt)
|
def main():
n = int(input())
s = input()
one_set = set([])
two_set = set([])
three_set = set([])
count = 0
for i in range(n):
if i==0:
one_set.add(s[0])
continue
if 2<=i:
for two in two_set:
if two + s[i] not in three_set:
three_set.add(two + s[i])
count+=1
for one in one_set:
two_set.add(one + s[i])
one_set.add(s[i])
print(count)
if __name__=="__main__":
main()
| 0 | null | 69,275,700,851,112 | 111 | 267 |
n=int(input())
lipp = []
lipm = []
limm = []
allcnt = 0
for _ in range(n):
s = input()
cnt = 0
mi = 0
for x in s:
cnt += 1 if x == '(' else -1
mi = min(mi,cnt)
if cnt >= 0:
lipm.append([mi,cnt])
else:
limm.append([mi - cnt, -cnt])
allcnt += cnt
if allcnt != 0:
print('No')
exit()
lipm.sort(reverse = True)
limm.sort(reverse = True)
def solve(l):
now = 0
for mi, cnt in l:
if mi + now < 0:
print('No')
exit()
now += cnt
solve(lipm)
solve(limm)
print("Yes")
|
from collections import deque,defaultdict
import bisect
N = int(input())
S = [input() for i in range(N)]
def bend(s):
res = 0
k = 0
for th in s:
if th == '(':
k += 1
else:
k -= 1
res = min(k,res)
return res
species = [(bend(s),s.count('(')-s.count(')')) for s in S]
ups = [(b,u) for b,u in species if u > 0]
flats = [(b,u) for b,u in species if u == 0]
downs = [(b,u) for b,u in species if u < 0]
ups.sort()
high = 0
for b,u in ups[::-1] + flats:
if high + b < 0:
print('No')
exit()
high += u
rdowns = [(b-u,-u) for b,u in downs]
rdowns.sort()
high2 = 0
for b,u in rdowns[::-1]:
if high2 + b < 0:
print('No')
exit()
high2 += u
if high == high2:
print('Yes')
else:
print('No')
| 1 | 23,718,744,172,122 | null | 152 | 152 |
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools as fts
import itertools as its
import math
import sys
INF = float('inf')
def solve(S: str):
return sum([S == "RRR", "RR" in S, "R" in S])
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
S = next(tokens) # type: str
print(f'{solve(S)}')
if __name__ == '__main__':
main()
|
d=input().split()
s={'N':"152304",'W':"215043",'E':"310542",'S':"402351"}
for o in input():
d=[d[int(i)]for i in s[o]]
print(d[0])
| 0 | null | 2,587,924,434,040 | 90 | 33 |
N = int(input())
Alist = list(map(int,input().split()))
XorPro = 0
for i in Alist:
XorPro = XorPro^i
Answer = []
for i in Alist:
Answer.append(XorPro^i)
print(*Answer)
|
line = input()
s, t = line.split(" ")
ans = t + s
print(ans)
| 0 | null | 57,417,929,204,440 | 123 | 248 |
a, b, c, d = map(int, input().split())
flg = False
while True:
if c - b <= 0:
flg = True
break
if a - d <= 0:
flg = False
break
a -= d
c -= b
print('Yes' if flg else 'No')
|
import math
from math import gcd
INF = float("inf")
import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque
def main():
a,b,c,d = map(int, input().split())
while True:
c -= b
if c<= 0:
print("Yes")
exit()
a -= d
if a <= 0:
print("No")
exit()
if __name__=="__main__":
main()
| 1 | 29,748,464,921,828 | null | 164 | 164 |
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
H,W,K=map(int, sys.stdin.readline().split())
S=[ sys.stdin.readline().strip() for _ in range(H) ]
#print H,W,K
#print S
ans=float("inf")
for bit in range(2**H):
cnt=0
group_num=0
GROUP={}
for i,s in enumerate(S):
if i==0:
GROUP[i]=group_num
else:
if bit>>i-1&1==1:
cnt+=1 #境目のカウントに+1
group_num+=1
GROUP[i]=group_num
#print "GROUP :: ",GROUP
ok=None
VALUE=defaultdict(lambda: 0)
w=0
for w in range(W):
for h in range(H):
VALUE[GROUP[h]]+=int(S[h][w])
#現在の値がKを超えていないか
for v in VALUE.values():
if v<=K:
pass
else:
#print "NG!",w
if ok is None: #okに値がない場合は、このパターンは成り立たない
#print "IMPOSSIBLE!"
cnt=float("inf") #不可能なパターンなのでカウントに無限大を代入
else: #以前の列で成り立たっていた場合
cnt+=1 #境目のカウントに+1
VALUE=defaultdict(lambda: 0) #NGの場合は値を初期化して入れなおし
for h in range(H):
VALUE[GROUP[h]]+=int(S[h][w])
break
else:
ok=w
#print "w,ok,cnt,VALUE :: ",w,ok,cnt,VALUE
ans=min(ans,cnt)
print ans
|
h,w,K = map(int,input().split())
s = [[int(i) for i in list(input())] for _ in range(h)]
ssum = [[0]*w for _ in range(h)]
for i in range(h):
for j in range(w):
if i == 0:
ssum[i][j] = s[i][j]
else:
ssum[i][j] = ssum[i-1][j] + s[i][j]
def cnt(line,i,j):
if i == 0:
return ssum[j-1][line]
else:
return ssum[j-1][line] - ssum[i-1][line]
ans = 10**6
for i in range(2**(h-1)):
l = [0]
s = 0
for j in range(h):
if i >> j & 1:
s += 1
l.append(j+1)
l.append(h)
d = [0]*(len(l)-1)
for j in range(w):
nxt = [cnt(j,l[k],l[k+1]) for k in range(len(l)-1)]
d2 = [nxt[i]+d[i] for i in range(len(l)-1)]
if max(nxt) > K:
s = 10**7
break
if max(d2) > K:
d = nxt
s += 1
else:
d = d2
ans = min(ans,s)
print(ans)
| 1 | 48,566,375,540,732 | null | 193 | 193 |
N, M, X = list(map(int, input().split()))
list = [list(map(int, input().split())) for i in range(N)]
def calc_cost(li):
"""
与えられた部分リストが各アルゴリズムの条件を
満たすか確認し、そのコストを計算。
条件満たさないときは100000000を出力
"""
# flag = True
cost = 0
for item in li:
cost += item[0]
for i in range(M):
algo_sum = 0
for item in li:
algo_sum += item[i + 1]
if algo_sum < X:
return 100000000
return cost
cost = 100000000
for i in range(2 ** N):
in_list = []
for j in range(N):
if (i >> j) & 1:
in_list.append(list[j])
temp_cost = calc_cost(in_list)
if temp_cost == -1:
break
cost = min(cost, temp_cost)
if cost == 100000000:
cost = -1
print(cost)
|
D = int(input())
c = [*map(int, input().split())]
s = [0] + [[*map(int, input().split())] for _ in range(D)]
t = [0] + [int(input()) for _ in range(D)]
v = 0
last = [0] * 26
for d in range(1, D+1):
select = t[d] - 1
v += s[d][select]
last[select] = d
v -= sum(c[i] * (d - last[i]) for i in range(26))
print(v)
| 0 | null | 16,088,869,343,404 | 149 | 114 |
# def insertionsort(A,n,g):
# global cnt
# for i in range(g,n):
# v = A[i]
# j = i - g
# while j >= 0 and A[j] > v:
# A[j+g] = A[j]
# j = j - g
# cnt += 1
# A[j+g] = v
def insertionsort(A,n,g):
global cnt
for i in range(g,n):
right = i
left = i - g
while left >= 0 and A[left] > A[right]:
A[right],A[left] = A[left],A[right]
right = left
left -= g
cnt += 1
def shellsort(A,n):
G = [1]
x = 0
while G[x]*3 + 1 <= n:
G.append(G[x]*3 + 1)
x += 1
G = G[::-1]
for i in range(len(G)):
insertionsort(A,n,G[i])
return A,G,cnt
if __name__ == '__main__':
import math
n = int(input())
A = []
cnt = 0
for i in range(n):
x = int(input())
A.append(x)
ans,G,cnt = shellsort(A,n)
#answer
print(len(G))
for i in range(len(G)):
if i == len(G) - 1:
print(G[i])
else:
print(G[i],end = " ")
print(cnt)
for i in range(n):
print(ans[i])
|
def main(N):
x = 0
for i in range(1,N+1):
for j in range(i,N+1,i):
x += j
return x
N = int(input())
print(main(N))
| 0 | null | 5,524,757,249,092 | 17 | 118 |
import math
a,b,n = list(map(int,input().split()))
if b <= n:
x = b - 1
else:
x = n
ans = math.floor(a * x / b)
print(ans)
|
while(1):
x,y = map(int, raw_input().split())
if x == 0 and y == 0:
break;
if x > y:
temp = x
x = y
y = temp
print x, y
| 0 | null | 14,314,794,063,150 | 161 | 43 |
S = list(map(str, input()))
T = list(map(str, input()))
ans = 0
for i in range(len(S)):
if S[i]!=T[i]:
ans += 1
print(ans)
|
S = input()
T = input()
num = 0
length = len(S)
for i in range(length):
if S[i] != T[i]:
num += 1
print(num)
| 1 | 10,352,740,684,088 | null | 116 | 116 |
def main():
N,M=map(int,input().split())
S=input()
c,l=N,[]
while c>0:
for i in range(M,0,-1):
if i<=c and S[c-i]=='0':
l+=[i]
c-=i
break
else:
l=[-1]
break
print(*l[::-1])
main()
|
N,M = map(int,input().split())
S = input()
c = 0
flag = 0
for i in S:
if i == '0':
if c >= M:
flag = 1
break
c = 0
else:
c += 1
if flag == 1:
print(-1)
else:
T = S[::-1]
now = 0
ans = []
while now != N:
delta = 0
for i in range(1,M+1):
if now + i == N:
delta = i
break
if T[now+i] == '0':
delta = i
ans.append(delta)
now += delta
Answer = ans[::-1]
print(*Answer)
| 1 | 139,025,521,838,882 | null | 274 | 274 |
while 1:
n=int(input())
if n==0:break
s=list(map(int,input().split()))
print((sum([(m-sum(s)/n)**2 for m in s])/n)**.5)
|
import statistics
while True:
n = int(input())
if n == 0: break
s = list(map(int, input().split()))
print(statistics.pstdev(s))
| 1 | 196,541,226,992 | null | 31 | 31 |
n = int(input())
taro,hanako = 0,0
for i in range(n):
t,h = input().split(' ')
if t > h:
taro += 3
elif t < h:
hanako += 3
else:
taro += 1
hanako += 1
print('{0} {1}'.format(taro,hanako))
|
n = int(input())
a = 0
b = 0
for i in range(n):
t1,t2 = input().split()
if t1>t2:
a+=3
elif t1==t2:
a+=1
b+=1
else:
b+=3
print(a,b)
| 1 | 1,995,656,294,380 | null | 67 | 67 |
import math
N = int(input())
total = N/2*(N+1)
f = math.floor(N/3)
f = (3*f+3)*f/2
b = math.floor(N/5)
b = (5*b+5)*b/2
fb = math.floor(N/15)
fb = (15*fb+15)*fb/2
print(int(total-f-b+fb))
|
def resolve():
n = int(input())
ans = 0
for i in range(1,n+1):
if i%3!=0 and i%5!=0:
ans += i
print(ans)
resolve()
| 1 | 34,901,764,691,508 | null | 173 | 173 |
n,m = map(int,input().split())
s = input()
ans = []
p = n
flag = 1
while flag:
for j in range(m,0,-1):
if p-j<=0:
ans.append(p)
flag = 0
break
elif s[p-j]=='0':
ans.append(j)
p-=j
break
elif j == 1:
ans.append(-1)
flag = 0
break
print(' '.join(map(str,reversed(ans))) if ans[-1]!=-1 else -1)
|
n, m = map(int,input().split())
s = list(input())
s.reverse()
ng = False
c = 0
ans = []
while ng == False and c < n:
for i in range(m, 0, -1):
if c+i < n+1 and s[c+i] == '0':
c += i
ans.append(str(i))
break
elif i == 1:
ng = True
if ng:
print(-1)
else:
ans.reverse()
print(' '.join(ans))
| 1 | 139,284,661,110,980 | null | 274 | 274 |
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from collections import Counter
def resolve():
n = int(input())
sieve = list(range(n + 1))
primes = []
for i in range(2, n + 1):
if sieve[i] == i:
primes.append(i)
for p in primes:
if p * i > n or sieve[i] < p:
break
sieve[p * i] = p
ans = 0
for i in range(1, n):
C = Counter()
while i > 1:
C[sieve[i]] += 1
i //= sieve[i]
score = 1
for val in C.values():
score *= val + 1
ans += score
print(ans)
resolve()
|
N, M, X = list(map(int, input().split()))
list = [list(map(int, input().split())) for i in range(N)]
def calc_cost(li):
"""
与えられた部分リストが各アルゴリズムの条件を
満たすか確認し、そのコストを計算。
条件満たさないときは100000000を出力
"""
# flag = True
cost = 0
for item in li:
cost += item[0]
for i in range(M):
algo_sum = 0
for item in li:
algo_sum += item[i + 1]
if algo_sum < X:
return 100000000
return cost
cost = 100000000
for i in range(2 ** N):
in_list = []
for j in range(N):
if (i >> j) & 1:
in_list.append(list[j])
temp_cost = calc_cost(in_list)
if temp_cost == -1:
break
cost = min(cost, temp_cost)
if cost == 100000000:
cost = -1
print(cost)
| 0 | null | 12,426,991,549,280 | 73 | 149 |
import sys
def input(): return sys.stdin.readline().rstrip()
class SegTree:
X_unit = 0
def __init__(self, N, X_f=min):
self.N = N
self.X = [self.X_unit] * (N + N)
self.X_f = X_f
def build(self, seq):
for i, x in enumerate(seq, self.N):
self.X[i] = x
for i in range(self.N - 1, 0, -1):
self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])
def set_val(self, i, x):
i += self.N
self.X[i] = x
while i > 1:
i >>= 1
self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])
def fold(self, L, R):
L += self.N
R += self.N
vL = self.X_unit
vR = self.X_unit
while L < R:
if L & 1:
vL = self.X_f(vL, self.X[L])
L += 1
if R & 1:
R -= 1
vR = self.X_f(self.X[R], vR)
L >>= 1
R >>= 1
return self.X_f(vL, vR)
def orr(x, y):
return x | y
def main():
N = int(input())
S = input()
S = list(map(lambda c: 2**(ord(c) - ord('a')), list(S)))
Q = int(input())
seg = SegTree(N, orr)
seg.build(S)
for _ in range(Q):
num, x, y = input().split()
if num == '1':
seg.set_val(int(x)-1, 2**(ord(y) - ord('a')))
else:
bits=seg.fold(int(x)-1, int(y))
print(sum(map(int, list(bin(bits))[2:])))
if __name__ == '__main__':
main()
|
n,m = map(int,input().split())
dac = {}
for i in range(1,n+1):
dac[str(i)] = 0
dwa = {}
for i in range(1,n+1):
dwa[str(i)] = 0
for i in range(m):
p,s = input().split()
if s == 'AC':
dac[p] = 1
if s == 'WA' and dac[p] == 0:
dwa[p] += 1
ac = 0
wa = 0
for k,v in dac.items():
ac += v
for k,v in dwa.items():
if dac[k] == 1:
wa += v
print(ac,wa)
| 0 | null | 77,947,805,323,840 | 210 | 240 |
diceA = list(map(int, input().split()))
diceB = [[1,2,3,5,4,2],[2,1,4,6,3,1],[3,1,2,6,5,1],[4,1,5,6,2,1],[5,1,3,6,4,1],[6,2,4,5,3,2]]
q = int(input())
for i in range(q):
quest = list(map(int, input().split()))
ans = 0
for j in range(6):
if quest[0] == diceA[j]:
for k in range(6):
if quest[1] == diceA[k]:
for l in range(1,5):
if diceB[j][l] == k+1:
ans = diceB[j][l+1]
print(diceA[ans-1])
|
from sys import stdin
from copy import deepcopy
import queue
class Dice:
def __init__(self, nums):
self.labels = [None] + [ nums[i] for i in range(6) ]
self.pos = {
"E" : 3,
"W" : 4,
"S" : 2,
"N" : 5,
"T" : 1,
"B" : 6
}
def rolled(dice, queries):
d = deepcopy(dice)
for q in queries:
if q == "E":
d.pos["T"], d.pos["E"], d.pos["B"], d.pos["W"] = d.pos["W"], d.pos["T"], d.pos["E"], d.pos["B"]
elif q == "W":
d.pos["T"], d.pos["E"], d.pos["B"], d.pos["W"] = d.pos["E"], d.pos["B"], d.pos["W"], d.pos["T"]
elif q == "S":
d.pos["T"], d.pos["S"], d.pos["B"], d.pos["N"] = d.pos["N"], d.pos["T"], d.pos["S"], d.pos["B"]
elif q == "N":
d.pos["T"], d.pos["S"], d.pos["B"], d.pos["N"] = d.pos["S"], d.pos["B"], d.pos["N"], d.pos["T"]
else:
return d
nums = [int(x) for x in stdin.readline().rstrip().split()]
q = int(stdin.readline().rstrip())
dice = Dice(nums)
# TとSに対応するクエリを記憶し, resをすぐに呼び出せるようにする
memo = [[False] * 7 for i in range(7)]
memo[dice.pos["T"]][dice.pos["S"]] = ""
# クエリとさいころの東面を記憶
res = { "" : dice.labels[dice.pos["E"]] }
# BFSで探索, 解を求めたらreturn Trueで抜け出す
# diceの中身をいじってはならない
def solve(T, S):
que = queue.Queue()
que.put(dice)
sol_q = ["E", "N", "S", "W"]
while not que.empty():
d = que.get()
if d.pos["T"] == T and d.pos["S"] == S:
break
else:
for i in sol_q:
d_next = Dice.rolled(d, i)
que.put(d_next)
memo[d_next.pos["T"]][d_next.pos["S"]] = memo[d.pos["T"]][d.pos["S"]] + i
res[memo[d_next.pos["T"]][d_next.pos["S"]]] = d_next.labels[d_next.pos["E"]]
else:
return memo[T][S]
for i in range(q):
ts = [int(x) for x in stdin.readline().rstrip().split()]
T = dice.labels.index(ts[0])
S = dice.labels.index(ts[1])
if solve(T, S) != False:
print(res[memo[T][S]])
| 1 | 263,364,347,950 | null | 34 | 34 |
N, K = map(int, input().split())
*A, = map(int, input().split())
b = [i for i in A]
for c in range(K):
buf = [0]*(N+1)
for i, j in enumerate(b):
buf[max(i-j, 0)] += 1
buf[min(i+j+1, N)] -= 1
for i in range(1, N+1):
buf[i] += buf[i-1]
b = [buf[i] for i in range(N)]
if all([i==N for i in b]):
break
print(*b)
|
import sys
i=1
while True:
x=sys.stdin.readline().strip()
if x=="0":
break;
print("Case %d: %s"%(i,x))
i+=1
| 0 | null | 7,974,297,989,800 | 132 | 42 |
N = int(input())
ans = 0
for a in range(1,N):
ans += (N-1)//a
print("{}".format(ans))
|
n = int(input())
D = [0] * n
for i in range(1, n):
for j in range(i, n, i):
D[j] += 1
print(sum(D))
| 1 | 2,571,979,366,138 | null | 73 | 73 |
n = int(input())
cnt = 0
for a in range(1, n):
cnt += ~-n//a
print(cnt)
|
import math
K = int(input())
# gcd(a, b, c)=gcd(gcd(a,b), c) が成り立つ
s = 0
for a in range(1, K+1):
for b in range(1, K+1):
d = math.gcd(a, b) # gcd(a, b)は先に計算しておく
for c in range(1, K+1):
s += math.gcd(d, c)
print(s)
| 0 | null | 18,991,137,985,950 | 73 | 174 |
while True:
H,W = [int(x) for x in input().split()]
if (H,W)==(0,0): break
for i in range(H):
if i==0 or i==H-1:
print("#"*W)
else:
print("#" + "."*(W-2) + "#")
print("")
|
while True:
H, W = list(map(int, input().split()))
if H == 0 and W == 0:
break
else:
for i in range(H):
if i == 0 or i == (H-1):
print('#'*W)
else:
print('#'+'.'*(W-2)+'#')
print()
| 1 | 815,986,024,490 | null | 50 | 50 |
a = int(input())
b = input()
print(b.count('ABC'))
|
# 140 B
n = int(input())
s = input()
num = 0
for i in range(len(s)):
if s[i] == 'A':
try:
if s[i + 1] == 'B' and s[i + 2] == 'C':
num += 1
except:
pass
print(num)
| 1 | 99,209,631,884,132 | null | 245 | 245 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.