code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 2
178,025B
⌀ | question_pair_id
float64 27.1M
177,113B
⌀ | code1_group
int64 1
297
| code2_group
int64 1
297
|
---|---|---|---|---|---|---|
K=int(input())
A,B=map(int, input().split())
cnt=0
for i in range(B//K+1):
if A<=K*i and K*i<=B:
cnt+=1
print('OK' if cnt>0 else 'NG') | N,K,S=[int(x) for x in input().rstrip().split()]
ans=[]
if S==10**9:
for i in range(N):
if i+1<=K:
ans.append(S)
else:
ans.append(1)
else:
for i in range(N):
if i+1<=K:
ans.append(S)
else:
ans.append(S+1)
print(*ans)
| 0 | null | 58,940,405,135,890 | 158 | 238 |
num = list(map(int,input().split()))
sum = 500*num[0]
if num[1] <= sum:
print("Yes")
else:
print("No") | n = int(input())
s = input()
if(n % 2 == 0 and s[n//2:] * 2 == s):
print("Yes")
else:
print("No") | 0 | null | 121,942,056,117,540 | 244 | 279 |
import copy
import random
D = list(map(int, input().split()))
q = int(input())
for x in range(q):
y, z = map(int, input().split())
while True:
r = random.randint(0,3)
if r == 0:
Dt = copy.copy(D)
temp = Dt[0]
Dt[0] = Dt[4]
Dt[4] = Dt[5]
Dt[5] = Dt[1]
Dt[1] = temp
elif r== 1:
Dt = copy.copy(D)
temp = Dt[0]
Dt[0] = Dt[2]
Dt[2] = Dt[5]
Dt[5] = Dt[3]
Dt[3] = temp
elif r== 2:
Dt = copy.copy(D)
temp = Dt[0]
Dt[0] = Dt[3]
Dt[3] = Dt[5]
Dt[5] = Dt[2]
Dt[2] = temp
elif r == 3:
Dt = copy.copy(D)
temp = Dt[0]
Dt[0] = Dt[1]
Dt[1] = Dt[5]
Dt[5] = Dt[4]
Dt[4] = temp
D = copy.copy(Dt)
if Dt[0] == y and Dt[1] == z:
print(Dt[2])
break
| class Dice:
def __init__(self, state):
self.state = state
def vertical(self, direction):
s = self.state
state = [s[1], s[5], s[0], s[4]]
if direction < 0:
s[0], s[1], s[4], s[5] = state
elif 0 < direction:
s[0], s[1], s[4], s[5] = reversed(state)
return self
def lateral(self, direction):
s = self.state
state = [s[2], s[5], s[0], s[3]]
if direction < 0:
s[0], s[2], s[3], s[5] = state
elif 0 < direction:
s[0], s[2], s[3], s[5] = reversed(state)
return self
def north(self):
self.vertical(-1)
return self
def south(self):
self.vertical(1)
return self
def east(self):
self.lateral(1)
return self
def west(self):
self.lateral(-1)
return self
init_state = input().split()
for i in range(int(input())):
dice = Dice(init_state)
up, front = input().split()
if up == dice.state[0] \
and front == dice.state[1]:
print(dice.state[2])
else:
for c in list('NNNNWNNNWNNNENNNENNNWNNN'):
if c == 'N':
dice.north()
elif c == 'S':
dice.south()
elif c == 'W':
dice.west()
elif c == 'E':
dice.east()
if up == dice.state[0] \
and front == dice.state[1]:
print(dice.state[2])
break
| 1 | 256,052,136,922 | null | 34 | 34 |
n=int(input())
a=list(map(int,input().split()))
f={}
f2={}
for i in range(n):
z=i+a[i]
z1=i-a[i]
#print(z,z1)
try:
f[z]+=1
except:
f[z]=1
try:
f2[z1]+=1
except:
f2[z1]=1
s=0
for i in f.keys():
if(i in f2):
s+=f[i]*f2[i]
print(s)
| import collections
N = int(input())
hList = list(map(int, input().split()))
count = 0
n_p = collections.Counter([ i + hList[i] for i in range(len(hList))])
for i in range(N):
if i - hList[i] > 0:
count += n_p.get(i - hList[i], 0)
print(count) | 1 | 26,023,876,098,818 | null | 157 | 157 |
n = int(input())
graph = [-1] + [list(map(int, input().split())) for _ in range(n)]
seen = [False]*(n+1)
seen[0] = True
d = [-1]*(n+1)
f = [-1]*(n+1)
time = 0
def dfs(v):
global time
time += 1
d[v] = time
seen[v] = True
k = graph[v][1]
if k > 0:
for i in range(k):
w = graph[v][i+2]
if seen[w] is False:
dfs(w)
time += 1
f[v] = time
v = 0
while v <= n:
if seen[v] is False:
dfs(v)
v += 1
for i in range(1, n+1):
print(i, d[i], f[i])
| # AtCoder
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, K = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
CD = [list(map(int, input().split())) for _ in range(K)]
uf = UnionFind(N)
friend = [0]*N
blocked = [0]*N
for a, b in AB:
uf.union(a-1, b-1)
friend[a-1] += 1
friend[b-1] += 1
for c, d in CD:
if uf.same(d-1, c-1):
blocked[c-1] += 1
blocked[d-1] += 1
ans = [uf.size(i)-friend[i]-blocked[i]-1 for i in range(N)]
print(' '.join(map(str, ans)))
| 0 | null | 31,025,943,910,328 | 8 | 209 |
n=int(input())
s=str(input())
d=s.count('ABC')
print(d) | n = int(raw_input())
for i in range(n):
num = map(int, raw_input().split())
num.sort(reverse=True)
if num[0]**2 == num[1]**2 + num[2]**2:
print "YES"
else:
print "NO"
| 0 | null | 49,528,045,604,338 | 245 | 4 |
from collections import Counter
P = 998244353
N = int(input())
D = [int(x) for x in input().split()]
def solve():
if D[0] != 0:
return 0
total = 1
max_d = max(D)
counter = Counter(D)
if counter[0] != 1:
return 0
for i in range(max_d + 1):
if i not in counter:
return 0
if i > 1:
total *= (counter[i - 1] ** counter[i] % P)
total %= P
return total
print(solve()) | import sys
for n in sys.stdin:
l=map(int,n.split())
b=l[0]*l[1]
u=[max(l),min(l)]
while u[1]!=0:
u=[u[1],u[0]%u[1]]
print "%d %d"%(u[0],b/u[0]) | 0 | null | 77,303,586,731,136 | 284 | 5 |
N, K = map(int, input().split())
c = 1
while N//K != 0:
N = N//K
c += 1
print(c) | from sys import stdin, stdout
import math,sys,heapq
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict
from os import path
import bisect as bi
def yes():print('YES')
def no():print('NO')
if (path.exists('input.txt')):
#------------------Sublime--------------------------------------#
sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');
def I():return (int(input()))
def In():return(map(int,input().split()))
else:
#------------------PYPY FAst I/o--------------------------------#
def I():return (int(stdin.readline()))
def In():return(map(int,stdin.readline().split()))
def dict(a):
d={}
for x in a:
if d.get(x,-1)!=-1:
d[x]+=1
else:
d[x]=1
return d
def find_gt(a, x):
'Find leftmost value greater than x'
i = bi.bisect_right(a, x)
if i != len(a):
return i
else:
return -1
def main():
try:
n=I()
if n<=599:print(8)
elif n<=799:print(7)
elif n<=999:print(6)
elif n<=1199:print(5)
elif n<=1399:print(4)
elif n<=1599:print(3)
elif n<=1799:print(2)
elif n<=1999:print(1)
except:
pass
M = 998244353
P = 1000000007
if __name__ == '__main__':
#for _ in range(I()):main()
for _ in range(1):main()
| 0 | null | 35,459,132,807,790 | 212 | 100 |
x = input()
a = x[::-1]
b = 0
c = 0
d = int(len(x))
while b + 1 <= d:
if x[b] == a[b]:
c = c
b = b + 1
else:
c = c + 1
b = b + 1
c = int(c/2)
print(c) | X = input()
if X.isupper():
print("A")
else:
print("a") | 0 | null | 65,511,639,358,880 | 261 | 119 |
while True:
H, W = map(int, raw_input().split())
if H == 0 or W == 0:
break
for _ in range(H):
print '#' * W
print '' | mod = 10**9 + 7
max_N = 2 * 10**5
def power(b, e):
if e == 0: return 1
half = power(b, e // 2)
if e % 2 == 0:
return (half * half) % mod
else:
return (((half * half) % mod) * b) % mod
def mod_inv(n):
return power(n, mod - 2)
fac = [1] * (max_N + 1)
for i in range(1, max_N + 1):
fac[i] = (i * fac[i - 1]) % mod
fac_inv = [1] * (max_N + 1)
fac_inv[max_N] = mod_inv(fac[max_N])
for i in range(max_N - 1, -1, -1):
fac_inv[i] = (fac_inv[i + 1] * (i + 1)) % mod
def choose(n, k):
return (((fac[n] * fac_inv[k]) % mod) * fac_inv[n - k]) % mod
if __name__ == "__main__":
line = input().split(" ")
N, K = int(line[0]), int(line[1])
K = min(K, N - 1)
ans = 0
for i in range(K + 1):
ans = (ans + (choose(N, i) * choose(N - i - 1 + i, i)) % mod) % mod
print(ans) | 0 | null | 33,741,617,180,778 | 49 | 215 |
# Binary Search
def isOK(i, key):
'''
問題に応じて返り値を設定
'''
cnt = 0
for v in a:
cnt += (v + i - 1) // i - 1
return cnt <= key
def binary_search(key):
'''
条件を満たす最小/最大のindexを求める
O(logN)
'''
ok = 10 ** 9 # 条件を満たすindexの上限値/下限値
ng = 0 # 条件を満たさないindexの下限値-1/上限値+1
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if isOK(mid, key): # midが条件を満たすか否か
ok = mid
else:
ng = mid
return ok
n, k = map(int, input().split())
a = list(map(int, input().split()))
print(binary_search(k)) | from math import ceil
N, K = map(int, input().split())
A = list(map(int, input().split()))
def f(x):
cnt = 0
for a in A:
cnt += ceil(a / x) - 1
return True if cnt <= K else False
OK, NG = 10**9, 0
while OK - NG > 1:
mid = (OK + NG) // 2
if f(mid):
OK = mid
else:
NG = mid
print(OK)
| 1 | 6,500,083,699,500 | null | 99 | 99 |
def resolve():
k,n = map(int,input().split())
a = list(map(int,input().split()))
l = a[0]+k-a[-1]
for i in range(1,n):
l = max(l,a[i]-a[i-1])
print(k-l)
resolve() | from sys import stdin, stdout
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
INF, NINF = float('inf'), float('-inf')
def binom_tables(n, q):
fact = [1 for _ in range(n + 1)]
inv = [1 for _ in range(n + 1)]
for i in range(1, n+1):
fact[i] = (fact[i-1] * i) % q
inv[i] = pow(fact[i], q-2, q)
return fact, inv
def main():
MOD = 998244353
n, m, k = rli()
F, I = binom_tables(n, MOD)
def binom(n, k, q):
return (F[n]*((I[k]*I[n-k])%q))%q
ans = 0
for i in range(n-k, n+1):
ans += (binom(n-1, i-1, MOD)*m*pow(m-1, i-1, MOD))%MOD
print(ans % MOD)
if __name__ == "__main__":
main() | 0 | null | 33,456,205,462,452 | 186 | 151 |
# 171 A
X = input()
print('a') if X.islower() else print('A') | c = input()
if c.isupper():
print('A')
else:
print('a') | 1 | 11,284,498,304,480 | null | 119 | 119 |
n=int(input())
al='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ans=[]
s=input()
for i in range(len(s)):
ans.append(al[(ord(s[i])-65+n)%26])
print(''.join(ans)) | import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
just, less = 0, INF
for d in input()[::-1]:
d = int(d)
njust = min(just + d, less + d + 1)
nless = min(just + (10-d), less + (9-d))
just, less = njust, nless
print(min(just, less + 1))
resolve() | 0 | null | 102,173,972,142,592 | 271 | 219 |
def resolve():
N, K = map(int, input().split())
H = list(map(int, input().split()))
h = sorted(H)[::-1]
ans = h[K:]
print(sum(ans))
resolve() | a, b = [int(i) for i in input().split(' ')]
answer1 = a // b
answer2 = a % b
answer3 = round(float(a) / float(b), 5)
print(answer1, answer2, answer3)
| 0 | null | 39,978,801,065,280 | 227 | 45 |
def insertion_sort(a, n, g, cnt):
for i in range(g,n,1):
v = a[i]
j = i - g #initial value
while j>=0 and a[j]>v:
a[j+g]=a[j]
j -= g
cnt += 1
a[j+g] = v
return a, cnt
def shell_sort(a,n,m,g):
cnt = 0
for i in range(m):
sorted_list, cnt = insertion_sort(a,n,g[i],cnt)
return sorted_list, cnt
def seqforshell(n):
seq = [1]
next_num = 3*seq[0] + 1
while next_num<n:
seq.insert(0, next_num)
next_num = 3*next_num + 1
return seq
if __name__ == "__main__":
a = []
n = int(input())
for i in range(n):
a.append(int(input()))
g = seqforshell(n)
m = len(g)
res, cnt = shell_sort(a,n,m,g)
print(m)
print(*g)
print(cnt)
for i in range(n):
print(res[i])
| n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
ans = 0
c = n - 1
for a in range(n - 2):
c = n - 1
for b in range(a + 1, n - 1):
# 各a,bに対してのcを尺取法で探索
while l[a] >= l[b] + l[c]:
c -= 1
if c <= b:
break
else:
# print(l[a], l[b], l[c])
ans += c - b
continue
break
print(ans) | 0 | null | 85,619,209,092,730 | 17 | 294 |
MOD = 998244353
def main():
# もらうdp + 累積和
N, K = (int(i) for i in input().split())
LR = [[int(i) for i in input().split()] for j in range(K)]
dp = [0] * (N+2)
dpsum = [0] * (N+1)
dp[1] = 1
dpsum[1] = 1
for i in range(2, N+1):
for le, ri in LR:
L = max(0, i - ri - 1)
R = i - le
if R < 1:
continue
dp[i] += dpsum[R] - dpsum[L]
dp[i] %= MOD
dpsum[i] += dpsum[i-1] + dp[i]
dpsum[i] %= MOD
print(dp[N])
# print(dpsum)
if __name__ == '__main__':
main()
| pi = 3.1415926535897
r = float(input())
print(pi*r**2, 2*pi*r)
| 0 | null | 1,692,157,650,672 | 74 | 46 |
N = int(input())
A = list(map(int, input().split()))
B = []
if N == 0:
if A[0] != 1:
print(-1)
exit()
else:
print(1)
exit()
else:
if A[0] != 0:
print(-1)
exit()
else:
B.append(1)
for i in range(1, N + 1):
B.append((B[i - 1] - A[i - 1]) * 2)
if (A[i] > B[i] or (A[i] == B[i] and i != N)):
print(-1)
exit()
ans = 0
ans += A[N]
B[N] = A[N]
for i in range(N - 1, -1, -1):
ans += min(B[i], B[i + 1] + A[i])
B[i] = min(B[i], B[i + 1] + A[i])
print(ans)
exit()
| # coding: utf-8
def solve(*args: str) -> str:
n = int(args[0])
A = list(map(int, args[1].split()))
if 0 < A[0]:
return '1' if n == 0 and A[0] == 1 else '-1'
R = [0]*(n+1)
R[0] = 1
for i in range(1, n+1):
R[i] = 2*(R[i-1]-A[i-1])
prev = 0
ret = 0
for i in range(n, -1, -1):
if R[i] < A[i]:
ret = -1
break
prev = min(R[i], A[i]+prev)
ret += prev
return str(ret)
if __name__ == "__main__":
print(solve(*(open(0).read().splitlines())))
| 1 | 18,854,946,285,500 | null | 141 | 141 |
import sys
num = []
for i in sys.stdin:
H, W = i.split()
if H == W == '0':
break
num.append((int(H), int(W)))
for cnt in range(len(num)):
for h in range(num[cnt][0]):
for w in range(num[cnt][1]):
if w == 0 or w == num[cnt][1] - 1 or h == 0 or h == num[cnt][0] - 1:
print('#',end='')
else:
print('.',end='')
print()
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 | 825,824,773,076 | null | 50 | 50 |
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,raw_input().split())
matA=[map(int,raw_input().split()) for i in range(n)]
matB=[map(int,raw_input().split()) for j in range(m)]
for i in range(n):
for j in range(l):
print sum([matA[i][k]*matB[k][j] for k in range(m)]),
print | 1 | 1,401,400,680,992 | null | 60 | 60 |
import sys
input = sys.stdin.readline
import math
def INT(): return int(input())
def MAPINT(): return map(int, input().split())
def LMAPINT(): return list(map(int, input().split()))
def STR(): return input()
def MAPSTR(): return map(str, input().split())
def LMAPSTR(): return list(map(str, input().split()))
f_inf = float('inf')
x = LMAPINT()
for i, y in enumerate(x):
if y == 0:
print(i+1)
exit() | x=list(map(int,input().split()))
for i in range(len(x)):
if x[i]==0:
su=i+1
print(su) | 1 | 13,478,010,968,048 | null | 126 | 126 |
N = int(input())
ans = 0
if N % 2 == 0:
ans += N//10
ans += N//50
N //= 50
while N > 0:
N //= 5
ans += N
print(ans) | class queue():
def __init__(self):
self.head = 0
self.tail = 0
self.MAX = 100000
self.Q = [[0] for i in range(self.MAX)]
def is_empty(self):
return self.head == self.tail
def is_full(self):
return self.head == (self.tail + 1) % self.MAX
def enqueue(self, x):
if self.is_full():
raise ValueError("エラー(オーバーフロー)")
self.Q[self.tail] = x
if self.tail + 1 == self.MAX:
self.tail = 0
else:
self.tail += 1
def dequeue(self):
if self.is_empty():
raise ValueError("エラー(アンダーフロー)")
x = self.Q[self.head]
if self.head + 1 == self.MAX:
self.head = 0
else:
self.head += 1
return x
n, q = input().split(" ")
n = int(n)
q = int(q)
q_name = queue()
q_val = queue()
for i in range(n):
name, t = input().split(" ")
t = int(t)
q_name.enqueue(name)
q_val.enqueue(t)
results = []
end_time = 0
while True:
process_val = q_val.dequeue()
process_name = q_name.dequeue()
if process_val <= q:
end_time += process_val
results.append([process_name, end_time])
else:
end_time += q
rest_val = process_val - q
q_name.enqueue(process_name)
q_val.enqueue(rest_val)
if q_val.head == q_val.tail:
break
for v in results:
print("{} {}".format(v[0],v[1]))
| 0 | null | 57,999,716,226,258 | 258 | 19 |
S = input()
a = S[0] == 'S'
b = S[1] == 'S'
c = S[2] == 'S'
if (a and b and c ):
print(0)
elif ( b or(a and c)):
print(1)
elif(a or c):
print(2)
else:
print(3) | s = input()
ans = 0
strek = 0
for i in range(3):
if s[i] == 'R':
tmp = "R"
strek += 1
ans = max(strek, ans)
else:
strek = 0
print(ans) | 1 | 4,904,429,178,660 | null | 90 | 90 |
x,y=map(int,input().split())
if ((4*x-y)%2==0 and (-2*x+y)%2==0) and (1<=(4*x-y)//2<=100 and 1<=(-2*x+y)//2<=100):
print('Yes')
elif ((4*x-y)%2==0 and (-2*x+y)%2==0) and (1<=(4*x-y)//2<=100 and (-2*x+y)//2==0):
print('Yes')
elif ((4*x-y)%2==0 and (-2*x+y)%2==0) and ((4*x-y)//2==0 and 1<=(-2*x+y)//2<=100):
print('Yes')
else :
print('No')
| s, t = input(), input()
print('Yes' if s == t[:-1] else 'No') | 0 | null | 17,535,195,986,322 | 127 | 147 |
# C - management
n = int(input())
al = list(map(int,input().split()))
s = [0]*n
level = 1
al.sort()
for i in range(len(al)):
if al[i] == level:
s[level-1] += 1
elif al[i] >= level:
level = al[i]
s[level-1] += 1
for j in s:
print(j)
| import sys
input()
for a,b,c in map(lambda x:sorted(map(int,x.split())),sys.stdin):
print(['NO','YES'][a*a+b*b==c*c])
| 0 | null | 16,342,788,485,220 | 169 | 4 |
def main():
n=int(input())
d=[0]+[-10**18]*n
for j,(a,i)in enumerate(sorted((-a,i)for i,a in enumerate(map(int,input().split())))):
d=[max(t-a*abs(~i-j+k+n),d[k-1]-a*abs(~i+k))for k,t in enumerate(d)]
print(max(d))
main() | import sys
n = int(input())
for i in range(1, n + 1):
x = i
if x % 3 == 0:
sys.stdout.write(" %d" % i)
else:
while x > 1:
if x % 10 == 3:
sys.stdout.write(" %d" % i)
break
x //= 10
print() | 0 | null | 17,250,188,531,524 | 171 | 52 |
A = str(input())
B = str(input())
sum=0
for i in range(len(A)):
if A[i]!=B[i]:
sum+=1
print(sum) | s = input()
t = input()
n = len(s)
ans = n
for i in range(n):
if s[i] == t[i]:
ans -= 1
print(ans) | 1 | 10,508,990,014,020 | null | 116 | 116 |
n,m,x = map(int,input().split())
ca = [list(map(int,input().split())) for i in range(n)]
c = [0]*n
a = [0]*n
for i in range(n):
c[i],a[i] = ca[i][0],ca[i][1:]
INF = 10**9
ans = INF
for i in range(1<<n):
understanding = [0]*m
cost = 0
for j in range(n):
if ((i>>j)&1):
cost += c[j]
for k in range(m):
understanding[k] += a[j][k]
ok = True
for s in range(m):
if understanding[s] < x:
ok = False
if ok:
ans = min(ans, cost)
if ans == INF:
ans = -1
print(ans)
| n, m, x = map(int,input().split())
c = [0] *(n)
a = [[0] for _ in range(n)]
ans = 10**10
for i in range(n):
ca = list(map(int,input().split()))
c[i] = ca[0]
a[i] = ca[1:]
for i in range(1 << n):
skill = [0] * m
total_cost = 0
for j in range(n):
if (i>>j) & 1:
total_cost += c[j]
skill = [skill[t] + a[j][t] for t in range(m)]
if all (y >= x for y in skill):
ans = min(ans, total_cost)
if ans == 10**10:
print(-1)
else:
print(ans) | 1 | 22,186,835,934,230 | null | 149 | 149 |
n = int(input())
S = input()
r = S.count('R')
w = 0
ans = r
for i in range(n):
if S[i] == "W":
w += 1
elif S[i] == "R":
r -= 1
ans = min(ans,max(r,w))
print(ans) | from sys import stdin
rs = stdin.readline
ri = lambda : int(rs())
ril = lambda : list(map(int, rs().split()))
def main():
N = ri()
c = rs()
x = 0
y = c.count('R')
for e in c:
if x == y:
break
elif e == 'W':
x += 1
else:
y -= 1
print(y)
if __name__ == '__main__':
main()
| 1 | 6,330,590,801,360 | null | 98 | 98 |
H, N = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
dp = [10 ** 18] * (H + 1)
dp[0] = 0
for i in range(H + 1):
for A, B in AB:
if i + A >= H:
dp[H] = min(dp[H], dp[i] + B)
else:
dp[i + A] = min(dp[i + A], dp[i] + B)
res = dp[H]
print(res)
| # This code is generated by [Atcoder_base64](https://github.com/kyomukyomupurin/AtCoder_base64)
import base64
import subprocess
import zlib
exe_bin = "c%1E9e{@q-p1&_iX@NEgTA-*55euhXAQC9p3e|+B@ZzS>fiQyzKGGy@Gqy=hUZ6PaSWl?(wi9Gr*X4}Pk>l>!(b;occh2tmW1O|6NR>HzmNI8XX4DnkQBzUD6|w%H+3)whd(-z`6ZAOyr<X&%_xpL@@ArQ1_ulut@7;HMce8)JNe~DxW^xljZtx0~cQZWe%!>e4Po~4~cgTD)4S0)2&Pc}vJuS<(qw3Y0RNhFhA$lrkXbCA^gepBH#F5uSUu)*8Xw7_wj-F@jZY$C2nV6oN>A9Iar*@{tDes?!{SPqQNWDZ)EsVClEr+o_I9uh7G(hx}>wOpWrjf5-?2K+^?G=m5Y347dd>pRtingt;yS^*DtScHz^)BnJU%hN~oiiDCuAn~Ine2v*Td6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dYyL5#*@I!1zPiAYxv1zD}9OU5Q4_E>dx#GwL{34Up;oQXKSi=B~9mQgyxiAfHuheA@MHx%iSC7Jf$Ihh_*8@vu}2D_sns8EA2Q-~819j4wwYt1((xDSI%VSc}($a!^M1Ot!n58AV1#`E9~gS_#z)n(A<@5h{0e}z7Nhq#!_#koFzkLI+7;e5YH`wa%mMxyQwaee;2&1nszxW6Q5^!Yx{_lW)sIDaqabiU#J-59^yiMqGL#rXR>r~JK&`)@MPJBYehlpnuRJw3whGCz&|#}DNejXk~}z$xFqGRBYhe?QY-$9TSPz^PV$ZUOy+M0*x~a{rK1<7<_1{1t;f--qDzj6vRRpbr}K`F;hb#(0$(=+6xL{Jomfg@%0;yPhR~Z_wxO8JrroVT}EMg6QvG{=UYk+c4oA2K|3A=okCDjAHG-V9@9LE}TAYXx|vmmyPYu)l-i_-gy7KO4M_)d|!0(?>toA7;oeFy-U>dyj-8ZXV=d!?5|P(V={SfVVV3p8rHrhe`xi%Ux!(rjQh{63snB8uW0{EgMR+KjgkDH3mNoyF|iHjy#GwUis`!z`O9t4FBR1GjT@$1zt(^k`mRvuk6lFGK64n?p_OE6{+O=uU0V*Y#D9z7Q?POV%qpUPYMDyy1_h)3{{iJ9@00"
open("./kyomu", 'wb').write(zlib.decompress(base64.b85decode(exe_bin)))
subprocess.run(["chmod +x ./kyomu"], shell=True)
subprocess.run(["./kyomu"], shell=True) | 0 | null | 41,819,699,109,830 | 229 | 74 |
import functools
from math import gcd
N = int(input())
A = list(map(int, input().split()))
MAX = 10 ** 6 + 10
if functools.reduce(gcd, A) != 1:
print("not coprime")
exit()
prime_list = [i for i in range(MAX + 1)]
p = 2
while p * p <= MAX:
if prime_list[p] == p:
for q in range(2*p, MAX+1, p):
if prime_list[q] == q:
prime_list[q] = p
p += 1
prime = set()
for a in A:
tmp = set()
while a > 1:
tmp.add(prime_list[a])
a //= prime_list[a]
for p in tmp:
if p in prime:
print("setwise coprime")
exit()
prime.add(p)
else:
print("pairwise coprime")
| def li():
return [int(x) for x in input().split()]
N = int(input())
A = li()
import math
from functools import reduce
from collections import defaultdict
# 最大公約数(リスト引数)
# 空のリストを渡さないよう注意
def GCD_list(numbers):
return reduce(math.gcd, numbers)
# 数列全ての高速素因数分解
MAX = 10 ** 6
is_prime = [True] * (MAX + 1)
divs = [1] * (MAX + 1)
is_prime[0], is_prime[1] = False, False
i = 1
while i * i <= MAX:
if not is_prime[i]:
i += 1
continue
for j in range(2 * i, MAX + 1, i):
is_prime[j] = False
divs[j] = i
i += 1
pairwise_coprime = True
all_primes = defaultdict(int)
for k in range(N):
n = A[k]
p = divs[n]
primes = defaultdict(int)
while p > 1:
primes[p] += 1
n = n // p
p = divs[n]
# 最後に残った数は1か素数にしかならない
if n != 1:
primes[n] += 1
for key in primes:
if all_primes[key] > 0 and primes[key] > 0:
pairwise_coprime = False
break
all_primes[key] += primes[key]
gcd = GCD_list(A)
setwise_comprime = (gcd == 1)
if pairwise_coprime:
print('pairwise coprime')
elif setwise_comprime:
print('setwise coprime')
else:
print('not coprime') | 1 | 4,062,542,321,892 | null | 85 | 85 |
import sys
sys.setrecursionlimit(9**9)
n=int(input())
T=[[] for _ in range(n)]
for i in range(n-1):
a,b=map(int,input().split())
T[a-1].append([b-1,i])
C=[0]*(n-1)
def f(i,r):
c=1
for (x,y) in T[i]:
c+=(c==r)
C[y]=c
f(x,c)
c+=1
f(0,0)
print(max(C))
for c in C:
print(c) | N = int(input())
graph = [[] for _ in range(N+1)]
AB = []
for _ in range(N-1):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
AB.append((a, b))
root = 1
parent = [0] * (N+1)
order = []
stack = [root]
while stack:
x = stack.pop()
order.append(x)
for y in graph[x]:
if y == parent[x]:
continue
parent[y] = x
stack.append(y)
color = [-1] * (N+1)
K = -1
for x in order:
ng = color[x]
c = 1
for y in graph[x]:
if y == parent[x]:
continue
if c == ng:
c += 1
K = max(c, K)
color[y] = c
c += 1
ans = []
for a, b in AB:
if parent[a] == b:
ans.append(color[a])
else:
ans.append(color[b])
print(K)
for i in ans:
print(i)
| 1 | 135,754,738,006,768 | null | 272 | 272 |
K = input(str())
a = 'ACL'
if K == '1':
print(a)
if K == '2':
print(a * 2)
if K == '3':
print(a * 3)
if K == '4':
print(a * 4)
if K == '5':
print(a * 5)
| Lists = [1, 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]
x = int(input())
print(Lists[x]) | 0 | null | 25,965,510,380,180 | 69 | 195 |
n = int(input().rstrip())
ans = [0 for x in range(10000)]
for x in range(1,101):
for y in range(1,101):
for z in range(1,101):
f = ((x+y)**2 + (y+z)**2 + (z+x)**2)//2
if f <= 10000:
ans[f-1] += 1
for i in range(n):
print(ans[i]) | N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
mod=10**9+7
ans=1
if K%2==1 and A[-1]<0:
for i in range(K):
ans=ans*A[N-(i+1)]%mod
print(ans)
exit()
l=0
r=N-1
if K%2==1:
ans=ans*A[r]
r-=1
for _ in range(K//2):
ml=A[l]*A[l+1]
mr=A[r]*A[r-1]
if ml>mr:
ans=ans*ml%mod
l+=2
else:
ans=ans*mr%mod
r-=2
print(ans)
| 0 | null | 8,751,860,571,312 | 106 | 112 |
s = list(input())
t = list(input())
leng = len(s)
if s[0:leng] == t[0:leng]:
print("Yes")
else:
print("No") | li = []
for i, s in enumerate(input()):
if s == "\\":
li.append([i, 0])
elif s == "/":
if li:
if li[-1][1] == 0:
li[-1][1] = i - li[-1][0]
else:
for j in range(len(li) - 1, -1, -1):
if li[j][1] == 0:
li = li[:j] + [[li[j][0], sum(tuple(zip(*li[j + 1:]))[1]) + i - li[j][0]]]
break
ans = []
for a in li:
if a[1] != 0:
ans.append(a[1])
print(sum(ans))
print(len(ans), *ans)
| 0 | null | 10,826,123,847,098 | 147 | 21 |
n = int(input())
lis = input().split()
dic = {}
for i in range(n):
if lis[i] not in dic:
dic[lis[i]] = 1
else:
dic[lis[i]] += 1
for x in dic.values():
if x != 1:
print("NO")
exit()
print("YES") | N = input()
A = list(int(x) for x in input().split())
if len(set(A)) == len(A):
print('YES')
else:
print('NO')
| 1 | 73,913,035,333,842 | null | 222 | 222 |
from math import *
PI = 3.1415926535898
while True:
try:
a, b = map(float, raw_input().strip().split(' '))
print "%d %d" % (a*b, 2*(a+b))
except EOFError:
break | N,M,K = list(map(int, input().split()))
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())
uf = UnionFind(N)
V = [[] for _ in range(N)]
for _ in range(M):
a,b = map(int, input().split())
a,b = a-1, b-1
V[a].append(b)
V[b].append(a)
uf.union(a,b)
for _ in range(K):
a,b = map(int, input().split())
a,b = a-1, b-1
if uf.same(a,b):
V[a].append(b)
V[b].append(a)
ans = [-1] * N
for i in range(N):
ans[i] = uf.size(i) - len(V[i]) - 1
print(" ".join(list(map(str, ans))))
| 0 | null | 30,884,362,373,370 | 36 | 209 |
N, M = map(int, input().split())
print('Yes') if N == M else print('No') | A, B = map(int, input().split())
if A == B:
print('Yes')
else:
print('No') | 1 | 83,289,614,288,352 | null | 231 | 231 |
import sys
input = lambda: sys.stdin.readline().rstrip()
def main():
s = input()
days = ['','SAT','FRI','THU','WED','TUE','MON','SUN']
print(days.index(s))
if __name__ == '__main__':
main() | s = input()
day = ['SAT','FRI','THU','WED','TUE','MON','SUN']
for i in range(7):
if s == day[i]:
print(i + 1)
exit() | 1 | 133,372,783,197,328 | null | 270 | 270 |
n,k = map(int,input().split())
A = [int(i) for i in input().split()]
A.sort()
F = [int(i) for i in input().split()]
F.sort(reverse=True)
left = -1
right = 10**12
def f(x): return sum(max(A[i]-x//F[i],0) for i in range(n)) <= k
while right - left > 1:
mid = (left+right)//2
if f(mid): right = mid
else: left = mid
print(right) | import sys,math
input = sys.stdin.readline
n,k = map(int,input().split())
a = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]
a.sort()
f.sort(reverse=True)
c = [(i*j,j) for i,j in zip(a,f)]
m = max(c)
def is_ok(arg):
# 条件を満たすかどうか?問題ごとに定義
chk = 0
for i,j in c:
chk += math.ceil(max(0,(i-arg))/j)
return chk <= k
def bisect_ok(ng, ok):
'''
初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
まずis_okを定義
ng = 最小の値-1 ok = 最大の値+1 で最小
最大最小が逆の場合はng ok をひっくり返す
'''
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
return ok
print(bisect_ok(-1,m[0]+1)) | 1 | 164,910,108,257,650 | null | 290 | 290 |
def to_fizzbuzz(num: int) -> str:
if num % 15 == 0:
return 'FizzBuzz'
if num % 3 == 0:
return 'Fizz'
if num % 5 == 0:
return 'Buzz'
return str(num)
N = int(input())
answer = 0
for i in range(1, N + 1):
fb_str = to_fizzbuzz(i)
if fb_str.isdecimal():
answer += int(fb_str)
print(answer) | N = int(input())
A = 0
for i in range(1, N+1):
if i%3 > 0 and i%5 > 0:
A += i
print(A) | 1 | 34,973,997,371,208 | null | 173 | 173 |
k= int(input())
s= input()
if len(s)>k:
r=s[:k]+"..."
print(r)
else:
print(s) | k = int(input())
s = input()
if len(s)>k:
print(s[0:k]+'...')
else:
print(s) | 1 | 19,749,528,829,660 | null | 143 | 143 |
n=int(input())
a=list(map(int,input().split()))
m=max(a)
b=[0]
b*=m
for i in range(n):
b[a[i]-1]+=1
c=[]
for i in range(m):
if b[i]>=2:
c.append(int(b[i]*(b[i]-1)/2))
else:
c.append(0)
d=sum(c)
for i in range(n):
if c[a[i]-1]>=1:
e=c[a[i]-1]-int((b[a[i]-1]-1)*(b[a[i]-1]-2)/2)
print(d-e)
else:
print(d)
| n=int(input())
arr=list(map(int,input().split()))
tt=[0]*(n+7)
total=0
for a in arr:
tt[a]+=1
for t in tt:
total += (t*(t-1)//2)
for i in range(n):
n = tt[arr[i]]
d = (n*(n-1)//2) - ((n-1)*(n-2)//2)
print(total-d)
# x * x-1 // 2
| 1 | 47,962,670,380,950 | null | 192 | 192 |
k=int(input())
v='ACL'
print(k*v) | k=int(input())
print("ACL"*k)
| 1 | 2,168,957,804,420 | null | 69 | 69 |
# -*- coding: utf-8
s = list(map(str,input().split()))
sum = 0
for i in range(len(s)):
sum += (int) (s[i])
if sum %9 == 0:
print("Yes")
else:
print("No") | import sys
input = lambda: sys.stdin.readline().rstrip()
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 solve():
N = int(input())
S = list(input())
Q = int(input())
seg = [[0 for _ in range(N)] for _ in range(26)]
for i in range(N):
al = ord(S[i]) - ord('a')
seg[al][i] = 1
segtree = []
segfunc = lambda a, b: a | b
for i in range(26):
segtree.append(SegTree(seg[i], segfunc, 0))
ans = []
for i in range(Q):
a, b, c = input().split()
a = int(a)
if a == 1:
b = int(b) - 1
ps = S[b]
S[b] = c
segtree[ord(ps) - ord('a')].update(b, 0)
segtree[ord(c) - ord('a')].update(b, 1)
elif a == 2:
b, c = int(b) - 1, int(c)
count = 0
for i in range(26):
count += segtree[i].query(b, c)
ans.append(count)
print('\n'.join(map(str, ans)))
if __name__ == '__main__':
solve()
| 0 | null | 33,299,511,595,740 | 87 | 210 |
k = int(input())
hp = [i for i in range(k+4)]
r, w = 1, 10
while w <= k:
n = hp[r]
r += 1
nm = n % 10
val = n * 10 + nm
if nm != 0:
hp[w] = val - 1
w += 1
hp[w] = val
w += 1
if nm != 9:
hp[w] = val + 1
w += 1
print(hp[k]) | def main():
N, M = map(int, input().split())
digits = [-1] * N
for _ in range(M):
s, c = map(int, input().split())
s -= 1
if ~digits[s] and digits[s] != c:
print(-1)
return
digits[s] = c
if N == 1:
print(max(0, digits[0]))
return
if digits[0] == 0:
print(-1)
return
if digits[0] == -1:
digits[0] = 1
ans = ''.join(map(str, (d if ~d else 0 for d in digits)))
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 50,107,602,939,114 | 181 | 208 |
nk=list(map(int, input().split()))
a=list(map(int, input().split()))
n=nk[0]
k=nk[1]
for i in range(n-k):
if(a[i]<a[i+k]):
print("Yes")
else:
print("No") | # cook your dish here
n,k=input().split()
n=int(n)
k=int(k)
l=list(map(int,input().split()))
for j in range(n):
if k+j==n:
break
if l[k+j]>l[j]:
print("Yes")
else:
print("No")
| 1 | 7,191,985,719,802 | null | 102 | 102 |
import math
import sys
x=input()
x0=x.split()
a=int(x0[0])
b=int(x0[1])
n=int(x0[2])
b0=n%b
b1=0
q1=0
if b==1:
print(0)
sys.exit()
for i in range(1,math.floor(n/b)+1):
b1=b*i-1
q1=max(q1,math.floor(a*b1/b)-a*math.floor(b1/b))
q2=math.floor(a*b0/b)-a*math.floor(b0/b)
print(max(q1,q2)) | n,k = map(int,input().split())
w = []
for _ in range(n):
w.append(int(input()))
def enough(p,k,w):
count = 0
in_truck = 0
for x in w:
if x > p:
return False
else:
if in_truck + x > p:
count += 1
in_truck = x
else:
in_truck += x
if in_truck > 0:
count += 1
return k >= count
maximum = sum(w)
minimum = 1
while True:
if minimum == maximum:
break
else:
tmpp = (maximum + minimum) // 2
if enough(tmpp,k,w):
maximum = tmpp
else:
minimum = tmpp + 1
print(minimum)
| 0 | null | 14,155,183,940,260 | 161 | 24 |
n = int(input())
c = list(input())
r = c.count('R')
w = c.count('W')
ans = 0
for i in range(r):
if c[i] == 'R':
pass
elif c[i] == 'W':
ans += 1
print(ans) | n = int(input())
stones = input()
r = stones.count("R")
w = stones.count("W")
ans = stones[0:r].count("W")
print(ans) | 1 | 6,326,570,616,410 | null | 98 | 98 |
import math
r = input()
S = math.pi * r ** 2
L = math.pi * r * 2
print "%f %f" %(S, L) | class UFTree:
def __init__(self, N):
self.nodes = [Node(i) for i in range(N)]
self.N = N
def find_max_child_num(self):
result = 0
for i in range(self.N):
result = max(result, self.nodes[i].child_num)
return result
class Node:
def __init__(self, ID):
self.ID = ID
self.parent = None
self.child_num = 0
self.rank = 1
def get_root(self):
if self.parent is None:
return self
return self.parent.get_root()
def concat(self, another):
sr = self.get_root()
ar = another.get_root()
# is in a same tree.
if sr.ID == ar.ID:
return
if sr.rank > ar.rank:
parent, child = sr, ar
else:
parent, child = ar, sr
parent.child_num += child.child_num + 1
parent.rank = max(parent.rank, child.rank + 1)
child.parent = parent
N, M = map(int, input().split())
tree = UFTree(N)
AB = []
for i in range(M):
l = list(map(int, input().split()))
AB.append(l)
for i in range(M):
a, b = AB[i][0], AB[i][1]
a -= 1;
b -= 1;
tree.nodes[a].concat(tree.nodes[b])
print(tree.find_max_child_num() + 1) | 0 | null | 2,334,986,400,064 | 46 | 84 |
line = ""
while line != "0":
line = input()
x = 0
for i in range(len(line)):
x += int(line[i])
if x != 0:
print(x)
| N = list(input().split())
A = int(N[0])
b1,b2 = N[1].split('.')
B = int(b1+b2)
prd = list(str(A*B))
ans = 0
if len(prd) < 3:
ans = 0
else:
prd.pop()
prd.pop()
ans = int(''.join(prd))
print(ans)
| 0 | null | 9,035,340,307,728 | 62 | 135 |
import math
r = input()
print ("%.5f " "%.5f")% (r*r*math.pi, 2*r*math.pi) | s =input()
t =input()
for i in range(len(s)):
if s[i] != t[i]:
print('No')
exit()
if len(t) == len(s)+1:
print('Yes')
else:
print('No') | 0 | null | 11,102,012,651,744 | 46 | 147 |
from collections import deque
n = int(input())
rg = [[] for _ in range(n)]
ret_dict = dict()
ls = []
for _ in range(n-1):
a, b = map(int, input().split())
rg[a-1].append(b-1)
rg[b-1].append(a-1)
ls.append((a-1, b-1))
deq = deque()
deq.append((0, 0))
visited = set()
visited.add(0)
ret = 0
while deq:
head, color = deq.pop()
n_color = 1
for item in rg[head]:
if item not in visited:
visited.add(item)
if n_color == color:
n_color += 1
ret = max(ret, n_color)
deq.append((item, n_color))
ret_dict[(min(head, item), max(head, item))] = n_color
n_color += 1
print(ret)
for item in ls:
print(ret_dict[item])
| from collections import deque
N = int(input())
X = [list(map(int, input().split())) for _ in range(N - 1)]
tree = [[] for _ in range(N + 1)]
for i, (a, b) in enumerate(X):
tree[a].append((b, i))
tree[b].append((a, i))
visited = [False] * (N + 1)
visited[1] = True
color = [0] * (N - 1)
stack = deque()
stack.append((1, 0))
while stack:
u, c = stack.popleft()
tmp = 0
for v, i in tree[u]:
if visited[v]:
continue
tmp += 1
if tmp == c:
tmp += 1
visited[v] = True
color[i] = tmp
stack.append((v, tmp))
print(max(color))
print(*color, sep="\n")
| 1 | 136,484,976,639,770 | null | 272 | 272 |
N = int(input())
As = list(map(int, input().split()))
P = 10**9 + 7
rlt = 0
pw = 1
for i in range(61):
c0 = 0
c1 = 0
for j in range(N):
a = As[j]
if a % 2 == 0:
c0 += 1
else:
c1 += 1
As[j] = a//2
rlt += c0*c1*pw % P
rlt %= P
pw *= 2
print(rlt) | class UnionFindTree():
def __init__(self, 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
# 常にxの要素数>yの要素数とする
if self.parents[x] > self.parents[y]:
x, y = y, x
# self.parents[x] に yの要素数を追加してから併合
self.parents[x] += self.parents[y]
self.parents[y] = x
def main():
N, M = map(int, input().split())
uft = UnionFindTree(N)
for m in range(M):
a, b = map(lambda x: int(x)-1, input().split())
uft.union(a, b)
print(-min(uft.parents))
if __name__ == "__main__":
main() | 0 | null | 63,395,468,784,362 | 263 | 84 |
a = int(input())
s = 100000
for i in range(a):
s = s * 1.05
if s % 1000:
s = s - (s % 1000) + 1000
print(int(s))
| import sys
def compoundInterest(x, i, n):
if n == 0:
return x
ans = int(x * (1 + i))
hasu = ans % 1000
if hasu != 0:
ans -= hasu
ans += 1000
return compoundInterest(ans, i, n-1)
if __name__ == "__main__":
n = int(input())
ans = compoundInterest(100000, 0.05, n)
print (ans) | 1 | 1,141,417,090 | null | 6 | 6 |
#!/usr/bin/env python3
import sys
import collections as cl
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
N = II()
print((N/3)**3)
main()
| import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9
def main():
l = int(input())
print((l/3)**3)
if __name__ == '__main__':
main()
| 1 | 47,122,213,810,272 | null | 191 | 191 |
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
K = min(K, 41)
# imos
for _ in range(K):
B = [0 for _ in range(N)]
for i in range(N):
l = max(0, i-A[i])
r = min(N-1, i+A[i])
B[l] += 1
if r+1 < N:
B[r+1] -= 1
for i in range(1, N):
B[i] += B[i-1]
A = B
for i in range(N):
A[i] = str(A[i])
print(' '.join(A)) | n,k=map(int,input().split())
a=list(map(int,input().split()))
for _ in range(min(k,41)):
b=[0]*(n+1)
for i in range(n):
l=max(0,i-a[i])
r=min(n,i+a[i]+1)
b[l]+=1
b[r]-=1
for i in range(n-1):
b[i+1]+=b[i]
a=b[:n]
print(*a) | 1 | 15,575,495,652,710 | null | 132 | 132 |
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.readline()[:-1]
mod = 10**9 + 7
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
if row <= 0:
return [[] for _ in range(col)]
elif col == 1:
return [I() for _ in range(row)]
else:
read_all = [LI() for _ in range(row)]
return map(list, zip(*read_all))
#################
def floor(a,b):
return a//b
N,X,M = LI()
# 繰り返しの1回目が終わるまで
used = [-1]*M
end_index = -1
A = [X]
sum_ = 0
for i in range(N):
if i == 0:
sum_ += A[0]
else:
val = pow(A[i-1],2,M)
A.append(val)
if used[val] == -1:
used[val] = i
sum_ += val
else:
end_index = i
start_val = val
start_index = used[val]
break
if end_index == -1:
print(sum_)
exit()
else:
ans = sum_
# 繰り返し全体が終わるまで
n = floor(N-start_index,end_index-start_index)
sum_ = 0
A2 = [start_val]
for j in range(end_index-start_index):
if j == 0:
val2 = start_val
sum_ += val2
else:
val2 = pow(A2[j-1],2,M)
A2.append(val2)
sum_ += val2
ans += (n-1)*sum_
# 残りの部分
sum_ = 0
A2 = [start_val]
for j in range(N-n*end_index+(n-1)*start_index):
if j == 0:
val2 = start_val
sum_ += val2
else:
val2 = pow(A2[j-1],2,M)
A2.append(val2)
sum_ += val2
ans += sum_
print(ans) | N, X, M = map(int, input().split())
tmp = X
seq = []
ans = 0
for i in range(N):
if X in seq:
break
seq.append(X)
X = (X ** 2) % M
ans = sum(seq[:min(N, len(seq))])
N -= len(seq)
if N < 1:
print(ans)
exit()
i = seq.index(X)
l = len(seq) - i
ans += sum(seq[i:]) * (N//l)
N %= l
ans += sum(seq[i:i+N])
print(ans)
| 1 | 2,792,582,503,370 | null | 75 | 75 |
n, k = [int(i) for i in input().split()]
cnt = 0
if n == 0:
print(1)
exit()
while n != 0:
n = n // k
cnt += 1
print(cnt) | N,K=map(int,input().split())
ans=list()
for i in range(K):
D=int(input())
L=list(map(int,input().split()))
ans+=L
ans=list(set(ans))
print(N-len(ans)) | 0 | null | 44,245,980,159,492 | 212 | 154 |
N = int(input())
import math
o = math.ceil(N / 2)
print(o / N)
| def main():
N,P = map(int,input().split())
S = input()[::-1]
ans = 0
if P == 2 or P == 5:
for i,s in enumerate(S):
if int(s) % P == 0:
ans += N - i
else:
mods = [0] * P
mods[0] = 1
current = 0
x = 1
for s in S:
current = (current + x * int(s)) % P
ans += mods[current % P]
mods[current % P] += 1
x = x * 10 % P
print(ans)
if __name__ == '__main__':
main() | 0 | null | 117,687,609,844,518 | 297 | 205 |
n=int(input())
from math import gcd
m=gcd(360,n)
print(360//m) | def main():
import sys
from collections import Counter
input = sys.stdin.readline
input()
a = list(map(int, input().split()))
ans = sum(a)
a = Counter(a)
for _ in range(int(input())):
b, c = map(int, input().split())
if b in a:
ans += (c - b) * a[b]
print(ans)
if c in a:
a[c] += a[b]
else:
a[c] = a[b]
del a[b]
else:
print(ans)
if __name__ == "__main__":
main() | 0 | null | 12,705,102,321,248 | 125 | 122 |
nk=list(map(int, input().split()))
a=list(map(int, input().split()))
n=nk[0]
k=nk[1]
for i in range(n-k):
if(a[i]<a[i+k]):
print("Yes")
else:
print("No") | n=int(input())
if n%10==7:
print("Yes")
exit()
n//=10
if n%10==7:
print("Yes")
exit()
n//=10
if n%10==7:
print("Yes")
exit()
print("No") | 0 | null | 20,879,217,710,550 | 102 | 172 |
import math
H = int(input())
W = int(input())
N = int(input())
Max = max(H,W)
print(math.ceil(N/Max)) | import math
A = int(input())
B = int(input())
N = int(input())
if A> B:
print(math.ceil(N/A))
else:
print(math.ceil(N/B)) | 1 | 88,644,808,828,758 | null | 236 | 236 |
H,W = map(int,input().split())
if H == 1 or W == 1:
print(1)
a = H * W
b = a // 2
if b != a / 2:
b += 1
if H != 1 and W != 1:
print(b)
| from itertools import accumulate
N, K = list(map(int, input().split()))
P = list(map(lambda x: int(x) + 1, input().split()))
P_cumsum = [0] + list(accumulate(P))
print(max([P_cumsum[i+K]-P_cumsum[i] for i in range(N-K+1)])/2) | 0 | null | 62,582,181,863,872 | 196 | 223 |
d=int(input())
c=list(map(int,input().split()))
s=[]
for _ in range(d):
s_i=list(map(int,input().split()))
s.append(s_i)
t=[]
for _ in range(d):
t_i=int(input())
t.append(t_i)
dp=[0]*26
ans=0
for i in range(d):
s_i = s[i][t[i]-1]
ans+=s_i
dp[t[i]-1]=i+1
tmp=0
for j in range(26):
tmp+=c[j]*((i+1)-dp[j])
ans -= tmp
print(ans) | D = int(input())
c = list(map(int, input().split()))
s = []
for i in range(D):
s.append(list(map(int, input().split())))
t = []
for i in range(D):
t.append(int(input())-1)
v = 0
last = [-1 for _ in range(26)]
for d in range(D):
v += s[d][t[d]]
last[t[d]]=d
for i in range(26):
v -= c[i] * (d - last[i])
print(v)
| 1 | 10,050,523,585,374 | null | 114 | 114 |
cnt = 0
def merge(A, left, mid, right):
global cnt
L = A[left:mid]
R = A[mid:right]
L.append(10000000000)
R.append(10000000000)
i = 0
j = 0
for k in range(left, right):
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
cnt += 1
def mergesort(A, left, right):
if left + 1 < right: #if block size >= 2
mid = int((left + right)/2)
mergesort(A, left, mid)
mergesort(A, mid, right)
merge(A, left, mid, right)
n = int(input())
S = list(map(int,input().split()))
mergesort(S, 0, n)
print(*S)
print(str(cnt))
| def merge(A, left, mid, right):
global cnt
L = A[left:mid] + [1000000001]
R = A[mid:right] + [1000000001]
i = j = 0
for k in range(left, right):
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
cnt += right - left
def mergeSort(A, left, right):
if left + 1 < right:
mid = (left + right) // 2
mergeSort(A, left, mid)
mergeSort(A, mid, right)
merge(A, left, mid, right)
if __name__ == '__main__':
n = int(input())
A = list(map(int, input().split()))
cnt = 0
mergeSort(A, 0, n)
print(*A)
print(cnt) | 1 | 112,631,915,402 | null | 26 | 26 |
def resolve():
n,k = map(int,input().split())
ans = 0
while n!=0:
n = n//k
ans += 1
print(ans)
resolve() | N = int(input())
A = []
B = []
for _ in range(N):
a, b = map(int, input().split())
A.append(a)
B.append(b)
def median(arr):
arr.sort()
n = len(arr)
if n % 2 == 1:
return arr[(n + 1) // 2 - 1]
else:
return (arr[n//2 - 1] + arr[n//2]) / 2
med_a = median(A)
med_b = median(B)
if N % 2 == 1:
ans = int(med_b) - int(med_a) + 1
else:
ans = med_b * 2 - med_a * 2 + 1
ans = int(ans)
print(ans) | 0 | null | 40,849,645,127,470 | 212 | 137 |
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('') | import math
a,b,x = map(int,input().split())
if x <= a*a*b//2:
theta = (math.pi/2) - math.atan((2*x)/(a*b*b))
else:
theta = math.atan(2*(a*a*b-x)/(a*a*a))
degree = math.degrees(theta)
print(degree) | 0 | null | 82,236,993,902,392 | 51 | 289 |
#!/usr/bin python3
# -*- coding: utf-8 -*-
def main():
N = int(input())
A = list(map(int, input().split()))
cnt = 0
for i, a in enumerate(A):
if (i+1)%2==1 and a%2==1:
cnt += 1
print(cnt)
if __name__ == '__main__':
main() | D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]
import copy
MAX_SCORE = -float('inf')
MAX_ANS = -1
for K in range(26):
v = 0
ans = [0]*D
L = [0]*26
for i in range(1, D+1):
max_score = -float('inf')
max_idx = 0
for j in range(26):
temp = v
temp += S[i-1][j]
L_ = copy.copy(L)
L_[j] = i
for k in range(26):
for l in range(i, min(i+K+1, D+1)):
temp -= C[k]*(l-L_[k])
if temp >= max_score:
max_score = temp
max_idx = j
v += S[i-1][max_idx]
L[max_idx] = i
for k in range(26):
v -= C[k]*(i-L[k])
ans[i-1] = max_idx+1
if v >= MAX_SCORE:
MAX_SCORE = v
MAX_ANS = ans
print(*MAX_ANS, sep='\n')
| 0 | null | 8,733,886,785,638 | 105 | 113 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal, ROUND_CEILING
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
R, C, K = MAP()
dp1 = [[0]*4 for _ in range(C+1)]
dp2 = [[0]*4 for _ in range(C+1)]
field = [[0]*(C+1)] + [[0]*(C+1) for _ in range(R)]
for _ in range(K):
r, c, v = MAP()
field[r][c] = v
for i in range(1, R+1):
for j in range(1, C+1):
if i%2 == 0:
up_max = max(dp1[j])
p = field[i][j]
dp2[j][0] = max(up_max, dp1[j-1][0])
dp2[j][1] = max(up_max+p, dp2[j-1][1], dp2[j-1][0]+p)
dp2[j][2] = max(dp2[j-1][2], dp2[j-1][1]+p)
dp2[j][3] = max(dp2[j-1][3], dp2[j-1][2]+p)
else:
up_max = max(dp2[j])
p = field[i][j]
dp1[j][0] = max(up_max, dp2[j-1][0])
dp1[j][1] = max(up_max+p, dp1[j-1][1], dp1[j-1][0]+p)
dp1[j][2] = max(dp1[j-1][2], dp1[j-1][1]+p)
dp1[j][3] = max(dp1[j-1][3], dp1[j-1][2]+p)
a = max(dp1[-1])
b = max(dp2[-1])
print(max(a, b))
| N = int(input())
s = "a"
ans = []
def dfs(s,n):
if len(s) == n:
ans.append(s)
return
last = 0
for i in range(len(s)):
last = max(last,ord(s[i]))
limit = chr(last+1)
for i in range(26):
temp = chr(97+i)
if temp <= limit:
dfs(s+temp,n)
dfs(s,N)
print(*ans,sep="\n") | 0 | null | 28,890,969,733,202 | 94 | 198 |