code1
stringlengths 16
24.5k
| code2
stringlengths 16
24.5k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,628B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
L= list(map(int,input().split()))
a=1
for i in range(5):
if L[i]!=0:
a+=1
else:
print(a)
|
import math
N = int(input())
flag = True
for i in range(N+1):
if math.floor(i * 1.08) == N:
print(i)
flag = False
break
if flag:
print(':(')
| 0 | null | 69,445,251,085,280 | 126 | 265 |
cnt=0
def mer(l,r):
global cnt
ll=len(l)
rr=len(r)
md=[]
i,j=0,0
l.append(float('inf'))
r.append(float('inf'))
for k in range(ll+rr):
cnt+=1
if l[i]<=r[j]:
md.append(l[i])
i+=1
else:
md.append(r[j])
j+=1
return md
def mergesort(a):
m=len(a)
if m<=1:
return a
m=m//2
l=mergesort(a[:m])
r=mergesort(a[m:])
return mer(l,r)
n=int(input())
a=list(map(int, input().split()))
b=mergesort(a)
for i in range(n-1):
print(b[i],end=" ")
print(b[n-1])
print(cnt)
|
INF = 10000000000
def merge(A,left,mid,right):
count = 0
L = A[left:mid] + [INF]
R = A[mid:right] + [INF]
i,j = 0,0
for k in range(left, right):
count += 1
if L[i] <= R[j]:
A[k]=L[i]
i += 1
else:
A[k]=R[j]
j += 1
return count
def merge_sort(A,left,right):
if left+1 < right:
mid = (left+right)//2
count_l = merge_sort(A,left,mid)
count_r = merge_sort(A,mid,right)
return merge(A,left,mid,right) + count_l + count_r
return 0
n = int(input())
A = [int(i) for i in input().split()]
count = merge_sort(A, 0, n)
for i in range(n):
if i:
print(" ", end = "")
print(A[i], end = "")
print()
print(count)
| 1 | 116,214,802,692 | null | 26 | 26 |
n = int(input())
answer = 0
for i in range(1, n + 1):
if i % 3 == 0 or i % 5 == 0:
i = 0
else:
answer = answer + i
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 | 35,060,836,188,290 | null | 173 | 173 |
import sys,math
input = sys.stdin.readline
A,B,C,D=list(map(int,input().split()))
if math.ceil(C/B) <= math.ceil(A/D):
print('Yes')
else:
print('No')
|
a, b, c, d = map(int, input().split())
cnt1 = 0
cnt2 = 0
while c > 0:
c -= b
cnt1 += 1
while a > 0:
a -= d
cnt2 += 1
if cnt1 <= cnt2:
print('Yes')
else:
print('No')
| 1 | 29,634,298,791,932 | null | 164 | 164 |
N, K = map(int, input().split())
A = list(map(int, input().split()))
isMax = False
while K > 0 and not isMax:
isMax = True
B = [0] * N
for i, d in enumerate(A):
l = max(0, i - d)
B[l] += 1
r = i + d + 1
if r < N:
B[r] -= 1
for i in range(N - 1):
isMax &= (B[i] >= N)
B[i + 1] += B[i]
A = B
K -= 1
print(*A[:N])
|
def main():
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
from itertools import accumulate
n, k = map(int, readline().split())
a = [*map(int, readline().split())]
for _ in range(min(k, 41)):
memo = [0] * n
for i, aa in enumerate(a):
if i > aa:
memo[i - aa] += 1
else:
memo[0] += 1
j = i - ~ aa
if j < n:
memo[j] -= 1
a = [*accumulate(memo)]
print(*a)
if __name__ == '__main__':
main()
| 1 | 15,522,439,521,212 | null | 132 | 132 |
import sys
readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')
n_ = 2 * 10**6 + 5
mod = 10**9 + 7
fun = [1] * (n_ + 1)
for i in range(1, n_ + 1):
fun[i] = fun[i - 1] * i % mod
rev = [1] * (n_ + 1)
rev[n_] = pow(fun[n_], mod - 2, mod)
for i in range(n_ - 1, 0, -1):
rev[i] = rev[i + 1] * (i + 1) % mod
def nCr(n, r):
if r > n:
return 0
return fun[n] * rev[r] % mod * rev[n - r] % mod
def modinv(x, mod):
a, b = x, mod
u, v = 1, 0
while b:
t = a // b
a -= t * b; a, b = b, a
u -= t * v; u, v = v, u
return u % mod
inv26 = modinv(26, mod)
def solve():
k = ni()
s = ns()
n = len(s)
ans = 0
v = 1
u = pow(26, k, mod)
for i in range(n, n+k+1):
ans = (ans + nCr(i-1, n-1) * v * u) % mod
u = u * inv26 % mod
v = v * 25 % mod
print(ans)
return
solve()
|
dict = {}
def insert(word):
global dict
dict[word] = 0
def find(word):
global dict
if word in dict:
print('yes')
else:
print('no')
def main():
N = int(input())
order = [list(input().split()) for _ in range(N)]
for i in range(N):
if order[i][0] == 'insert':
insert(order[i][1])
elif order[i][0] == 'find':
find(order[i][1])
main()
| 0 | null | 6,415,942,084,460 | 124 | 23 |
x=int(input())
if x>=400 and x<600:
print(8)
elif x>=600 and x<800:
print(7)
elif x>=800 and x<1000:
print(6)
elif x>=1000 and x<1200:
print(5)
elif x>=1200 and x<1400:
print(4)
elif x>=1400 and x<1600:
print(3)
elif x>=1600 and x<1800:
print(2)
elif x>=1800 and x<2000:
print(1)
|
import sys
input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
ch=[]
for i in range(n):
ch.append((a[i],i))
ch.sort(reverse=True)
#print(ch)
dp=[[0]*(n+1) for _ in range(n+1)]
dp[1][1]=ch[0][0]*ch[0][1]
dp[1][0]=ch[0][0]*(n-1-ch[0][1])
for i in range(2,n+1):
for j in range(i+1):
if j>=1:
dp[i][j]=max(dp[i][j],dp[i-1][j-1]+ch[i-1][0]*abs(ch[i-1][1]-j+1))
if i-1>=j:
dp[i][j]=max(dp[i][j],dp[i-1][j]+ch[i-1][0]*abs(n-i+j-ch[i-1][1]))
print(max(dp[n]))
| 0 | null | 20,324,392,155,880 | 100 | 171 |
# Aizu Problem ITP_1_7_A: Grading
#
import sys, math, os
# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
sys.stdin = open("sample-input.txt", "rt")
while True:
m, f, r = [int(_) for _ in input().split()]
score = m + f
if m == f == r == -1:
break
elif m == -1 or f == -1:
print('F')
elif score >= 80:
print('A')
elif score >= 65:
print('B')
elif score >= 50 or (score >= 30 and r >= 50):
print('C')
elif score >= 30:
print('D')
else:
print('F')
|
nums = [int(e) for e in input().split()]
if (nums[2]+nums[4])<=nums[0] and (nums[3]+nums[4])<=nums[1] and (nums[2]-nums[4])>=0 and (nums[3]-nums[4])>=0:
print("Yes")
else:
print("No")
| 0 | null | 825,137,493,090 | 57 | 41 |
S = input()
cnt = 0
for i,ch in enumerate(S):
if cnt == 0:
if ch == "R":
cnt = 1
elif ch == "R" and S[i-1] == "R":
cnt += 1
print(cnt)
|
a, b, c, k = map(int, input().split())
_sum = 0
if a > k:
_sum += k
else:
k -= a
_sum += a
if b > k:
b = 0
else:
k -= b
if c > k:
_sum -= k
else:
_sum -= c
print (_sum)
| 0 | null | 13,207,627,918,100 | 90 | 148 |
K = ord(input())
print(chr(K+1))
|
x,y=map(int,input().split())
for i in range(0,x+1):
if(2*i+4*(x-i)==y):
print("Yes")
exit()
print("No")
| 0 | null | 52,852,913,174,866 | 239 | 127 |
n = int(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
def factorial(n) :
if n == 1:
return 1
else :
return n*factorial(n-1)
num_p = 0
num_q = 0
for i in range(n-1) :
sort_p = sorted(p[i:],reverse=True)
index_p = sort_p.index(p[i])
mp = n - (index_p + 1)
num_p += mp * factorial(n-(i+1))
sort_q = sorted(q[i:],reverse = True)
index_q = sort_q.index(q[i])
mq = n - (index_q + 1)
num_q += mq * factorial(n-(i+1))
print(abs(num_p - num_q))
|
import math
N = int(input())
town = []
for i in range(N):
x, y = map(int, input().split())
town.append((x, y))
def dfs(current, dist, already):
if len(already) == N:
return dist
d = 0
for i in range(N):
if i in already:
continue
d += dfs(i, dist + math.sqrt((town[current][0] - town[i][0]) ** 2 + (town[current][1] - town[i][1]) ** 2), already | set([i]))
return d
answer = 0
for i in range(N):
answer += dfs(i, 0, set([i]))
print(answer / math.factorial(N))
| 0 | null | 124,535,094,421,780 | 246 | 280 |
# coding: utf-8
from itertools import count
def merge(A, left, mid, right):
global counter
n1, n2 = mid - left, right - mid
L, R = list(A[left:left+n1]+[float("inf")]), list(A[mid:mid+n2]+[float("inf")])
i = j = 0
for k in range(left, right):
if L[i] <= R[j]:
A[k] = L[i]
i = i + 1
else:
A[k] = R[j]
j = j + 1
counter += 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)
N = int(input())
A = [int(i) for i in input().split()]
counter = 0
mergeSort(A, 0, len(A))
print(*A)
print(counter)
|
def maybe_prime(d,s,n):
for a in (2,3,5,7):
p = False
x = pow(a,d,n)
if x==1 or x==n-1:
continue
for i in range(1,s):
x = x*x%n
if x==1: return False
elif x == n-1:
p = True
break
if not p: return False
return True
def is_prime(n):
if n in (2,3,5,7): return True
elif n%2==0: return False
else:
d,s = n-1, 0
while not d%2:
d,s = d>>1,s+1
return maybe_prime(d,s,n)
cnt = 0
n = int(input())
for i in range(n):
n = int(input())
if is_prime(n): cnt+=1
print(cnt)
| 0 | null | 58,982,949,478 | 26 | 12 |
N = int(input())
for i in range(1,10):
if N % i == 0 and 1<=N/i<=9:
print('Yes')
break
elif i == 9:
print('No')
# break:その後の処理を行わない。
|
n=int(input())
flag=0
for i in range(1,10):
if (n%i)==0:
if (n//i)<=9:
flag=1
break
if flag==1:
print ('Yes')
else:
print ('No')
| 1 | 160,521,979,588,728 | null | 287 | 287 |
N, A, B = map(int, input().split())
d = A - B if A > B else B - A
d2 = d // 2
d3 = d % 2
if d3 == 0:
ans = d2
else:
bigger = B
smaller = A
if A > B:
bigger = A
smaller = B
shortest = smaller if N - bigger + 1 > smaller else N - bigger + 1
ans = shortest + d2
print(ans)
|
import sys
def LI():
return list(map(int, input().split()))
N, A, B = LI()
if (B-A) % 2 == 0:
print((B-A)//2)
sys.exit()
a = 1
b = B-A
L = A+(b-a)//2
b = N
R = N-B+1
a = A+R
R += (b-a)//2
print(min(R, L))
| 1 | 109,324,783,081,482 | null | 253 | 253 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(str, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
from decimal import *
K = INT()
if K <= 9:
print(K)
exit()
n = [-1]*11
n[-1] = 9
cnt = 9
def DFS(n):
global cnt
for i in range(1, 11):
if n[-i] == 9:
continue
elif n[-i-1] != -1 and n[-i] == n[-i-1]+1:
continue
else:
if n[-i] == -1:
n[-i] = 1
else:
n[-i] += 1
for j in range(i-1, 0, -1):
n[-j] = max(0, n[-j-1] - 1)
break
cnt += 1
if cnt == K:
print(*n[bisect(n, -1):], sep = "")
exit()
DFS(n)
DFS(n)
|
from collections import deque
k = int(input())
num = deque()
num = deque([i for i in range(1,10)])
for i in range(k):
x = num.popleft()
mod = x % 10
if x % 10 != 0:
num.append(10*x + mod-1)
num.append(10*x + mod)
if x % 10 != 9:
num.append(10*x + mod+1)
print(x)
| 1 | 39,853,669,113,510 | null | 181 | 181 |
from collections import Counter
N = int(input())
d = list(map(int, input().split()))
MOD = 998244353
dn = Counter(d)
ans = 1
if dn[0] != 1 or d[0] != 0: ans = 0
else:
for i in range(1, max(d)+1):
ans *= (dn[i-1]**dn[i])
ans %= MOD
print(ans)
|
import numpy as np
N,K=map(int,input().split())
a = np.array([int(x) for x in input().split()])
val=sum(a[:K])
max_val=val
for i in range(N-K):
val+=a[K+i]
val-=a[i]
max_val=max(val,max_val)
print(max_val/2+K*0.5)
| 0 | null | 114,767,444,193,908 | 284 | 223 |
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
min_price = min(a) + min(b)
for _ in range(M):
x, y, c = map(int, input().split())
discount_price = a[x-1] + b[y-1] - c
if min_price > discount_price:
min_price = discount_price
print(min_price)
|
N =int(input())
c = 0
for i in range(N):
c += (N-1)//(i+1)
print(c)
| 0 | null | 28,290,656,821,482 | 200 | 73 |
n=int(input())
cnt=0
ans=0
while(n>=1):
ans+=2**cnt
n//=2
cnt+=1
print(ans)
|
a=input()
e=a[len(a)-1:len(a)]
if e == "s":
print(a+"es")
else:
print(a+"s")
| 0 | null | 41,499,761,680,080 | 228 | 71 |
"""
全探索
"""
n = int(input())
for i in range(1,10) :
if n % i == 0 and 0 <= n//i <= 9 :
print("Yes")
break
else :
print("No")
|
N = int(input())
multiplication = []
for x in range(1, 10):
for y in range(1, 10):
multiplication.append(x*y)
if N in multiplication:
print( "Yes" )
else:
print( "No" )
| 1 | 160,254,202,307,880 | null | 287 | 287 |
x = 0
while x == 0:
m = map(int,raw_input().split())
if m[0] == 0 and m[1] == 0:
break
for i in xrange(m[0]):
print "#" * m[1]
print ""
|
n = int(input())
a = n // 2
b = n % 2
print(a+b)
| 0 | null | 29,904,099,935,580 | 49 | 206 |
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [list(input())[:-1] for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
H,W,K = map(int,input().split())
P = [list(input())[:-1] for _ in range(H)]
num= 1
cur = 1
flag = [0]*H
ans = [[0]*W for _ in range(H)]
for i in range(H):
count = 0
li = [0]*W
for j in range(W):
if P[i][j] == "#":
count += 1
if count == 0:
flag[i] = 1
else:
judge = 0
d = 0
for j in range(W):
if P[i][j] == "." or d == 1:
ans[i][j] = num
else:
ans[i][j] = num
judge += 1
if judge == count:
d = 1
else:
num += 1
num += 1
for i in range(H):
if flag[i] == 0:
index = i
break
for i in range(index):
flag[i] = 0
for j in range(W):
ans[i][j] = ans[index][j]
for i in range(H):
if flag[i] == 1:
for j in range(W):
ans[i][j] = ans[i-1][j]
for i in range(H):
print(*ans[i])
|
n = int(input())
a = [0]+list(map(int, input().split()))
ans = 0
for i in range(1, n+1):
if i%2 == 1 and a[i]%2==1:
ans += 1
print(ans)
| 0 | null | 75,892,314,870,912 | 277 | 105 |
n = int(input())
li1 = list(map(int,input().split()))
m = int(input())
li2 = list(map(int,input().split()))
cnt = 0
for i in li2:
if i in li1:
cnt +=1
print(cnt)
|
import sys
n = int(sys.stdin.readline().strip())
S = map(int, sys.stdin.readline().strip().split(" "))
n = int(sys.stdin.readline().strip())
T = map(int, sys.stdin.readline().strip().split(" "))
res = []
for t in T:
res.append(int(S.count(t) != 0))
print sum(res)
| 1 | 71,223,551,840 | null | 22 | 22 |
x,y=map(int,input().split())
a=(4*x-y)/2
b=(2*x-y)/(-2)
if a>=0 and b>=0 and a.is_integer() and b.is_integer():
print("Yes")
else:
print("No")
|
X, Y = [int(arg) for arg in input().split()]
def f(X, Y):
for i in range(X + 1):
for j in range(X + 1):
kame = i
tsuru = j
if kame + tsuru == X and kame * 4 + tsuru * 2 == Y:
return 'Yes'
return 'No'
print(f(X, Y))
| 1 | 13,779,828,504,580 | null | 127 | 127 |
import sys
input=sys.stdin.buffer.readline
#sys.setrecursionlimit(10**9)
#from functools import lru_cache
def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')
from collections import defaultdict
def main():
n=II()
A=LI()
X=defaultdict(int)
Y=defaultdict(int)
for i,v in enumerate(A):
X[i+v]+=1
Y[i-v]+=1
ans=0
for k,v in X.items():
ans+=v*Y[k]
print(ans)
if __name__=="__main__":
main()
|
n = int(input())
a = list(map(int, input().split()))
ans = 0
dp = dict()
for i in range(n):
a_p = a[i] + i+1
a_m = i+1 -a[i]
if a_p in dp:
dp[a_p] = dp[a_p] + 1
else:
dp[a_p] = 1
if a_m in dp:
ans = ans + dp[a_m]
print(ans)
| 1 | 26,095,415,087,788 | null | 157 | 157 |
import numpy as np
from numba import njit
from numba.types import i8
ni8 = np.int64
MOD = 998244353
@njit((i8[:,::-1], i8[:], i8, i8), cache=True)
def solve(lr, dp, n, k):
acc_dp = np.ones_like(dp)
for i in range(1, n):
val = 0
for j in range(k):
a = i - lr[j, 0]
if a < 0:
continue
b = i - lr[j, 1] - 1
val += acc_dp[a] - (acc_dp[b] if b >= 0 else 0)
dp[i] = val % MOD
acc_dp[i] = (acc_dp[i - 1] + dp[i]) % MOD
return dp[n - 1]
def main():
f = open(0)
n, k = [int(x) for x in f.readline().split()]
lr = np.fromstring(f.read(), ni8, sep=' ').reshape((-1, 2))
dp = np.zeros(n, ni8)
dp[0] = 1
ans = solve(lr, dp, n, k)
print(ans)
main()
|
# -*- coding: utf-8 -*-
s, t = map(str, input().split())
a, b = map(int, input().split())
u = str(input())
dic = {s:a, t:b}
dic[u] = dic[u] - 1
print(dic[s], dic[t])
| 0 | null | 37,497,925,473,880 | 74 | 220 |
n, k = map(int, input().split())
cnt = 0
while n >= 1:
n = n//k
cnt +=1
print(cnt)
|
N,K = map(int, input().split())
Sum = 0
while True:
Sum += 1
if K ** Sum > N:
break
print(Sum)
| 1 | 64,333,624,526,148 | null | 212 | 212 |
x = 0
y = 0
for i in range(1,10):
x += 1
y = 0
for j in range(1,10):
y += 1
print("{}x{}={}".format(x,y,x*y))
|
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
n,x,y=nii()
x-=1
y-=1
ans=[0 for i in range(n)]
for i in range(n-1):
for j in range(i+1,n):
dist1=j-i
dist2=abs(i-x)+1+abs(j-y)
dist=min(dist1,dist2)
ans[dist]+=1
for i in ans[1:]:
print(i)
| 0 | null | 21,977,883,163,740 | 1 | 187 |
# Rem of sum is Num
# Reviewing problem
from collections import defaultdict
def cnt_func(X):
res = 0
right = 0
L = len(X)
for i in range(L):
while right+1 < L and X[right+1] < K+X[i]:
right += 1
res += right-i
return res
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.insert(0, 0)
for i in range(1, N+1):
A[i] += A[i-1]
B = [0 for i in range(N+1)]
for i in range(N+1):
B[i] = (A[i]-i) % K
ans = 0
Mod = defaultdict(list)
for i in range(N+1):
Mod[B[i]].append(i)
for X in Mod.values():
ans += cnt_func(X)
print(ans)
|
n = int(input())
num = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1, n + 1):
num[int(str(i)[0])][int(str(i)[-1])] += 1
ans = 0
for i in range(1, 10):
for j in range(1, 10):
ans += num[i][j] * num[j][i]
print(ans)
| 0 | null | 112,225,724,408,000 | 273 | 234 |
s = list(input())
t = list(input())
ans = 1000
sub = 0
flag = False
for i in range(len(s)):
if s[i] != t[sub]:
sub = 0
continue
else:
if sub == len(t) - 1:
print(0)
flag = True
break
sub += 1
if not flag:
for i in range(len(s) - len(t) + 1):
sub = 0
an = 0
for j in range(len(t)):
if s[i + j] != t[sub]:
an += 1
sub += 1
ans = min(an, ans)
print(ans)
|
s = input()
t = input()
ans = len(t)
for i in range(len(s)-len(t)+1):
count = 0
for j in range(len(t)):
if s[i+j]!=t[j]:
count += 1
# print(count)
ans = min(ans, count)
print(ans)
| 1 | 3,664,865,321,922 | null | 82 | 82 |
from collections import defaultdict
dic = defaultdict(int)
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
h = []
r, s, p = 0, 0, 0
for i in range(N):
if i>=K:
if T[i]==h[i-K]:
h.append("x")
continue
if T[i]=="r":
h.append("r")
p+=1
elif T[i]=="p":
h.append("p")
s+=1
elif T[i]=="s":
h.append("s")
r+=1
print(p*P + r*R + s*S)
|
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
point = [0]*K
flag = ["a"]*K
k = -1
#K本のリストを用意する 剰余系の中で、同じ手が連続するとき、1、3、5、...は別の手に変える
for i in range(N):
k = (k+1)%K #mod
if T[i] == "r":
if flag[k] == "r":
flag[k] = "a"
else:
flag[k] = "r"
point[k] += P
elif T[i] == "s":
if flag[k] == "s":
flag[k] = "a"
else:
flag[k] = "s"
point[k] += R
if T[i] == "p":
if flag[k] == "p":
flag[k] = "a"
else:
flag[k] = "p"
point[k] += S
print(sum(point))
| 1 | 107,144,172,571,180 | null | 251 | 251 |
# coding: utf-8
import sys
import math
import collections
import itertools
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = I()
print(A[K - 1])
|
import sys
sys.setrecursionlimit(500000)
N = int(input())
E = [[] for i in range(N + 1)]
for i in range(N - 1):
a, b = map(int, input().split(' '))
E[a].append((b, i))
E[b].append((a, i))
K = max(len(e) for e in E)
print(K)
ans = [-1] * (N - 1)
def dfs(v=1, p=0, p_col=-1):
col = 1
for u, idx in E[v]:
if u != p:
if col == p_col:
col += 1
ans[idx] = col
dfs(u, v, col)
col += 1
dfs()
for i in ans:
print(i)
| 0 | null | 92,788,829,628,990 | 195 | 272 |
while True:
h, w = map(int, input().split())
if h == 0 and w == 0:
break
print("#" * w)
for _ in range(h-2):
print("#","." * (w-2), "#", sep="")
print("#" * w)
print()
|
a = map(int, raw_input().split())
while a != [0,0]:
print '#' * a[1]
for i in xrange(a[0]-2):
print '#' + '.' * (a[1] - 2) + '#'
print '#' * a[1]
a = map(int, raw_input().split())
print ""
| 1 | 845,607,637,852 | null | 50 | 50 |
import sys
sys.setrecursionlimit(2147483647)
n,k=map(int,input().split())
#n個の中からk個選んだ時の最大と最小
a=list(map(int,input().split()))
"""
seta=set([])
dic={}
for v in a:
if v in seta:
dic[v]+=1
else:
dic[v]=1
seta.add(v)
a=list(seta)
"""
a.sort()
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % p
p = 10**9+7 #割る数
N = 10 ** 6 # N は必要分だけ用意する
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
for i in range(2, N + 1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
result=0
for i,v in enumerate(a):
if i>=k-1:
result+=v*cmb(i, k-1, p)
if k-1<=n-i-1:
result-=v*cmb(n-i-1, k-1, p)
print(result%p)
|
input()
print(*list(map(int,input().split()))[::-1])
| 0 | null | 48,512,432,244,384 | 242 | 53 |
N = int(input())
x = (N+1) * 100 // 108
if x * 108 // 100 == N:
print(x)
else:
print(":(")
|
n,m = map(int,input().split())
if n%2 ==1:
for i in range(1,m+1):
print(i,n-i)
else:
left_end = 1+m if m%2 == 1 else m
left_start = left_end//2
right_start = left_end+m//2
for i in range(1,m+1):
if i%2 == 1:
print(left_start,left_start+i)
left_start-=1
else:
print(right_start,right_start+i)
right_start-=1
| 0 | null | 77,440,957,024,090 | 265 | 162 |
x, y = [int(x) for x in input().split()]
print(x*y)
|
input()
numbers = input().split()
#print(numbers)
r_numbers = reversed(numbers)
#print(r_numbers)
print(" ".join(r_numbers))
| 0 | null | 8,410,225,573,750 | 133 | 53 |
N = int(input())
ct = []
for i in range(N):
ct.append([int(i) for i in input().split()])
dist = 0
for a in ct:
for b in ct:
dist += (abs(a[0] - b[0])**2 +abs(a[1] - b[1])**2)**0.5
print(dist/N)
|
n, x, m = map(int, input().split())
a = x
s = 0
h = []
h.append(a)
i = 0
fl = 0
while i < n:
s += a
a = (a*a) % m
if a == 0:
break
i += 1
if fl == 0 and a in h:
fl = 1
po = h.index(a)
ss = 0
for j in range(po):
ss += h[j]
s2 = s - ss
f = (n - po) // (i - po)
s2 *= f
s = s2 + ss
i2 = i - po
i2 *= f
i = i2 + po
else:
h.append(a)
print(s)
| 0 | null | 75,393,430,038,342 | 280 | 75 |
import math
r = float(input())
area = math.pi*r**2
circuit = 2*math.pi*r
print"%f %f" % (area, circuit)
|
import math
r = float(input())
c = r * r *math.pi
cf = r *2 *math.pi
a = ("{0:.5f} {1:.5f}".format(c,cf))
print(a)
| 1 | 647,368,225,280 | null | 46 | 46 |
n = int(input())
s_lst = list(str(input()) for _ in range(n))
count_lst = [0, 0, 0, 0]
for i in range(n):
consequence = s_lst[i]
if consequence == 'AC':
count_lst[0] += 1
elif consequence == 'WA':
count_lst[1] += 1
elif consequence == 'TLE':
count_lst[2] += 1
else:
count_lst[3] += 1
consequence_lst = ['AC x {}'.format(count_lst[0]), 'WA x {}'.format(count_lst[1]), 'TLE x {}'.format(count_lst[2]), 'RE x {}'.format(count_lst[3])]
for i in range(4):
con = consequence_lst[i]
print(con)
|
N, K = [int(_) for _ in input().split()]
mod = 10**9 + 7
A = [0] * (K + 1)
for i in range(K, 0, -1):
A[i] = pow(K // i, N, mod)
for j in range(2, K // i + 1):
A[i] -= A[i * j]
A[i] %= mod
print(sum(i * a for i, a in enumerate(A)) % mod)
| 0 | null | 22,901,764,042,200 | 109 | 176 |
a, b = (int(i) for i in input('').split())
print("{0} {1}".format(a*b, 2*(a+b)))
|
import sys
line = sys.stdin.readline()
tate, yoko = line.split(" ")
tate = int(tate)
yoko = int(yoko)
S = tate * yoko
T = 2 * (tate + yoko)
print '%d %d' % (S, T)
| 1 | 299,412,878,002 | null | 36 | 36 |
N = int(input())
ans = 'No'
for i in range(1,10):
if N%i == 0:
tmp = str(int(N/i))
if len(tmp) >= 2:
continue
else:
ans = 'Yes'
break
else:
continue
print(ans)
|
n = int(input())
for i in range(1, 50000):
if i * 108 // 100 == n:
print(i)
exit()
print(':(')
| 0 | null | 143,054,525,300,782 | 287 | 265 |
N = int(input())
def answer(N: int) -> str:
x = 0
for i in range(1, 10):
for j in range(1, 10):
if N == i * j:
x = 1
return 'Yes'
if x == 0:
return 'No'
print(answer(N))
|
N=int(input())
x="No"
for i in range(1,10):
if N%i==0 and N/i<10:
x="Yes"
break
print(x)
| 1 | 159,352,677,437,628 | null | 287 | 287 |
from itertools import cycle
while True:
(H, W) = [int(i) for i in input().split(' ')]
if (H == W == 0):
break
it1 = cycle(['#', '.'])
it2 = cycle(['.', '#'])
str1 = ''
str2 = ''
for i in range(W):
str1 += next(it1)
str2 += next(it2)
for i in range(H):
if ((i % 2) == 0):
print(str1)
else:
print(str2)
print()
|
while True:
H,W = map(int, raw_input().split(" "))
if H == 0 and W == 0:
break
else:
for h in xrange(H):
sw = True if (h % 2) == 0 else False
s = ""
for w in xrange(W):
s += "#" if sw else "."
sw = not sw
print s
print ""
| 1 | 888,236,430,422 | null | 51 | 51 |
# -*- coding: utf-8 -*-
import sys
from collections import deque
N,D,A=map(int, sys.stdin.readline().split())
XH=[ map(int, sys.stdin.readline().split()) for _ in range(N) ]
XH.sort()
q=deque() #(攻撃が無効となる座標、攻撃によるポイント)
ans=0
cnt=0
attack_point=0
for x,h in XH:
while q:
if x<q[0][0]:break #無効となる攻撃がない場合はwhileを終了
end_x,end_point=q.popleft()
attack_point-=end_point #攻撃が無効となる座標<=現在の座標があれば、その攻撃のポイントを引く
if h<=attack_point: #モンスターの体力よりも攻撃で減らせるポイントの方が大きければ新規攻撃は不要
pass
else: #新規攻撃が必要な場合
if h%A==0:
cnt=(h-attack_point)/A #モンスターの大量をゼロ以下にするために何回攻撃が必要か
else:
cnt=(h-attack_point)/A+1
attack_point+=cnt*A
q.append((x+2*D+1,cnt*A)) #(攻撃が無効となる座標、攻撃によるポイント)をキューに入れる
ans+=cnt
print ans
|
n=int(input())
print(n+n*n+n*n*n)
| 0 | null | 46,078,345,124,992 | 230 | 115 |
#ABC158-A
s=input()
if s!='AAA' and s!='BBB':
print('Yes')
else:
print('No')
|
s = input()
if ("A" in s) and ("B" in s):
print("Yes")
else:
print("No")
| 1 | 54,629,034,146,600 | null | 201 | 201 |
while(1):
H, W = map(int, input().split())
if H == 0 and W == 0:
break
for i in range(H):
for j in range(W):
print("#", end='')
print("\n", end='')
print("\n", end='')
|
while True:
x = input().split()
x_int = [int(i) for i in x]
if x_int[0] == 0 and x_int[1] ==0:
break
for i in range(x_int[0]):
z = '#' * x_int[1]
print(z)
print()
| 1 | 756,180,002,788 | null | 49 | 49 |
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
S = list(input().rstrip())
def cost(S):
minCost = [-1]*(N+1)
minCost[0] = 0
ind = 1
for i,s in enumerate(S):
if s == "1":
continue
while i < ind <= min(i+M, N):
if S[ind] == "0":
minCost[ind] = minCost[i] + 1
ind += 1
return minCost
M1 = cost(S)
M2 = cost(S[::-1])[::-1]
if M1[-1] == -1:
print(-1)
else:
C = M1[-1]
Inds = [10**14]*(C+1)
for i, (m1, m2) in enumerate(zip(M1, M2)):
if m1 + m2 == C:
Inds[m1] = min(Inds[m1], i)
ans = []
for i1, i2 in zip(Inds, Inds[1:]):
ans.append(i2-i1)
print(*ans)
|
import numpy as np
n, k = map(int, input().split())
a = np.array(list(map(int, input().split())))
a.sort()
l, r = 0, 10000000000
while r - l > 1:
m = (l + r) // 2
res = n * n - a.searchsorted(m - a).sum()
if res >= k:
l = m
else:
r = m
b = np.array([0] * (n + 1))
for i in range(1, n + 1):
b[i] = b[i - 1] + a[n - i]
cnt = 0
ans = 0
for x in a:
t = n - a.searchsorted(l - x)
ans += b[t] + x * t
cnt += t
print(ans - (cnt - k) * l)
| 0 | null | 123,381,879,035,950 | 274 | 252 |
#!/usr/bin/env python3
import math
x = int(input())
while True:
key=1
for k in range(2, int(math.sqrt(x)) + 1):
if x % k == 0:
key=0
if key==1:
print(x)
exit()
else:
x += 1
print(x)
|
import math
def main():
X = int(input())
if X == 2: return 2
if X == 3: return 3
if X == 4 or X == 5: return 5
if X == 6 or X == 7: return 7
if X == 8: return 11
while True:
if X % 2 != 0:
for i in range(3, int(math.sqrt(X))+1, 2):
if X % i == 0: break
else: return X
X += 1
ans = main()
print(ans)
| 1 | 105,629,166,325,156 | null | 250 | 250 |
[n, k] = [int(i) for i in input().split()]
for i in range(40):
if n < k**i:
print(i)
break
|
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
n, k = map(int, input().split())
cnt = 0
while 0 < n:
n //= k
cnt += 1
print(cnt)
| 1 | 64,594,407,682,060 | null | 212 | 212 |
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]
n=int(input())
s=[input() for i in range(n)]
# lst=[[0]*2 for i in range(n)]
sei=[]
hu=[]
for i in range(n):
l,r=0,0
for j in range(len(s[i])):
if s[i][j]==")":
if r==0:
l+=1
else:
r-=1
if s[i][j]=="(":
r+=1
if r-l>0:
sei.append([l,r-l])
else:
hu.append([r,l-r])
sei.sort(key=lambda x: x[0])
hu.sort(key=lambda x: x[0])
tmp=0
for i in range(len(sei)):
if tmp-sei[i][0]<0:
print("No")
quit()
tmp+=sei[i][1]
tmp2=0
for i in range(len(hu)):
if tmp2-hu[i][0]<0:
print("No")
quit()
tmp2+=hu[i][1]
if tmp==tmp2:
print("Yes")
else:
print("No")
|
# F - Bracket Sequencing
import sys
readline = sys.stdin.readline
N = int(input())
L = []
R = []
for _ in range(N):
S = readline().strip()
sums = 0
mins = 0
for s in S:
if s == '(':
sums += 1
else:
sums -= 1
mins = min(mins, sums)
if sums >= 0:
L.append((sums, mins))
else:
R.append((-sums, mins-sums))
L.sort(key=lambda x: x[1], reverse=True)
R.sort(key=lambda x: x[1], reverse=True)
ans = 'Yes'
l_now = 0
for d, min_d in L:
if l_now + min_d < 0:
ans = 'No'
break
else:
l_now += d
r_now = 0
for d, min_d in R:
if r_now + min_d < 0:
ans = 'No'
break
else:
r_now += d
if l_now != r_now:
ans = 'No'
print(ans)
| 1 | 23,473,122,680,882 | null | 152 | 152 |
S = list(input())
word_num = int(len(S)/2)
temp_num = 0
if len(S) % 2 == 0:
for i in range(word_num):
if S[2*i]+S[2*i+1] == 'hi':
pass
else:
temp_num += 1
else:
pass
if len(S) % 2 == 0 and temp_num == 0:
print('Yes')
else:
print('No')
|
s = input()
L = s.split("hi")
ans = 1
for x in L:
if x != "":
ans = 0
print(["No","Yes"][ans])
| 1 | 53,100,602,046,860 | null | 199 | 199 |
import math
A,B,C,D = map(int, input().split())
Taka=A/D
Aoki=C/B
if math.ceil(Taka)>=math.ceil(Aoki):
print("Yes")
else:
print("No")
|
A,B,C,D = (int(x) for x in input().split())
while True:
C -= B
if C <= 0:
print('Yes')
break
else:
A -= D
if A <= 0:
print('No')
break
| 1 | 29,881,159,126,210 | null | 164 | 164 |
a,b=map(int,input().split())
#a,bの最大公約数
def gcd(a,b):
if(b==0):
return a
else:
return gcd(b, a%b)
#a,bの最小公倍数
def lcm(a,b):
return a*b//gcd(a,b)
print(lcm(a,b))
|
A,B = map(int,(input().split()))
l = 0
if A > B:
l = A
s = B
else:
l = B
s = A
for i in range(1,10**10):
if (l*i)%s == 0:
print(l*i)
exit()
else:
continue
| 1 | 113,507,476,368,010 | null | 256 | 256 |
# Coding is about expressing your feeling, and
# there is always a better way to express your feeling_feelme
import sys
import math
# sys.stdin=open('input.txt','r')
# sys.stdout=open('output2.txt','w')
from sys import stdin,stdout
from collections import deque,defaultdict
from math import ceil,floor,inf,sqrt,factorial,gcd,log2
from copy import deepcopy
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
mod=int(1e9 + 7)
n,h=iia()
arr=iia()
count=0
for i in range(n):
if arr[i]>=h:
count+=1
print(count)
|
a, b = map(int, input().split())
c = list(map(int,input().split()[:a]))
d = 0
for i in c:
if i>=b:
d+=1
print(d)
| 1 | 179,091,213,874,270 | null | 298 | 298 |
def divisor(i):
s = []
for j in range(1, int(i ** (1 / 2)) + 1):
if i % j == 0:
s.append(i // j)
s.append(j)
return sorted(set(s))
n = int(input())
ans = 0
d = divisor(n)
d.pop(0)
for i in d:
x = n
while True:
if not x % i == 0:
break
x //= i
if x % i == 1:
ans += 1
d = divisor(n - 1)
ans += len(d)
ans -= 1
print(ans)
|
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().strip()
from math import sqrt
def factor(n):
"""
nの約数を個数と共にリストにして返す。
ただしあとの都合上1は除外する。
"""
if n == 1:
return 0, []
if n == 2:
return 1, [2]
if n == 3:
return 1, [3]
d = int(sqrt(n))
num = 1
factor_pre = []
factor_post = [n]
for i in range(2, d):
if n % i == 0:
factor_pre.append(i)
factor_post.append(n // i)
num += 2
if d * d == n:
factor_pre.append(d)
num += 1
elif n % d == 0:
factor_pre.append(d)
factor_post.append(n // d)
num += 2
factor_post.reverse()
return num, factor_pre + factor_post
def main():
N = int(input())
"""
題を満たすKは、
N = K^e * n、(n, K) = 1
として
n = K * m + 1 (m ¥in ¥mathbb{N})
とかければ良い。
2つ目の式からnとKが互いに素なのは明らかなので、問題文は
N = K^e * (K * m + 1) (m ¥in ¥mathbb{N})
なるKを求めることに同値。
なのでまずはNの約数を全列挙して、あとはNをそれで割った商がKで割って1余るか確かめれば良い。
"""
_, fact = factor(N)
ans, ans_list = factor(N - 1)
# print(ans_list)
# print("Now we check the list {}".format(fact))
for K in fact:
n = N
while n % K == 0:
n //= K
if n % K == 1:
ans += 1
ans_list.append(K)
# print("{} added".format(K))
# print("ans={}: {}".format(ans, ans_list))
print(ans)
if __name__ == "__main__":
main()
| 1 | 41,134,896,557,518 | null | 183 | 183 |
N = int(input())
Alist = list(map(int, input().split()))
n_dic = {}
for a in Alist:
if a in n_dic.keys():
n_dic[a] += 1
else:
n_dic[a] = 1
base = 0
for k, v in n_dic.items():
base += v * (v-1) // 2
for k in range(N):
n = n_dic[Alist[k]] - 1
print(base - n)
|
N, A, B = map(int, input().split())
q, r = divmod(N, A + B)
print(q * A + min(A, r))
| 0 | null | 51,784,564,679,140 | 192 | 202 |
n, k = map(int, input().split())
LR = [tuple(map(int, input().split())) for _ in range(k)]
mod = 998244353
dp = [1]
acc = [0, 1]
for i in range(1, n):
new = 0
for l, r in LR:
if i < l:
continue
r = min(r, i)
new += acc[i-l+1] - acc[i-r]
new %= mod
dp.append(new)
acc.append((acc[-1]+new) % mod)
print(dp[-1])
|
s = input()
if s[0] == "R":
if s[1] == "R":
if s[2] == "R":
ans = 3
else:
ans = 2
else:
ans = 1
else:
if s[1] == "R":
if s[2] == "R":
ans = 2
else:
ans = 1
elif s[2] == "R":
ans = 1
else:
ans = 0
print(ans)
| 0 | null | 3,819,676,258,630 | 74 | 90 |
MOD = int(1e9+7)
N, K = map(int, input().split())
count = [0] * (K+1)
ans = 0
for now in range(K, 0, -1):
count[now] = pow(K // now, N, MOD)
for j in range(2*now ,K+1, now):
count[now] -= count[j]
if count[now] < 0:
count[now] += MOD
ans += now * count[now]
print(ans % MOD)
|
n, k = map(int, input().split())
mod = 10**9+7
def power(a, n, mod):
bi=str(format(n,"b")) #2進数
res=1
for i in range(len(bi)):
res=(res*res) %mod
if bi[i]=="1":
res=(res*a) %mod
return res
X = [0]*(k+1)
ans = 0
for g in reversed(range(1, k+1)):
temp = power(k//g, n, mod)
j = g
while j <= k:
temp -= X[j]
j += g
ans += temp*g
X[g] = temp
ans %= mod
print(ans)
| 1 | 36,653,360,903,620 | null | 176 | 176 |
#16D8101012J 伊藤惇 dj Python3
def Greatest_Common_Divisor(x,y):
if y>x:
x,y=y,x
if x>=y and y>0:
return Greatest_Common_Divisor(y,x%y)
return x
if __name__ == "__main__":
x=list(map(int,input().split()))
print(Greatest_Common_Divisor(x[0],x[1]))
|
def gcd(a, b):
# ?????§??¬?´???°
while b > 0:
a, b = b, a % b
return a
a, b = map(int, input().split())
print(gcd(a, b))
| 1 | 7,764,290,560 | null | 11 | 11 |
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
sum = 0
sum_1 = 0
for i in range(N):
sum += A[i]%mod
sum = (sum**2)%mod
for j in range(N):
sum_1 += (A[j]**2)%mod
sum2=sum-sum_1
if sum2<0:
sum2+=mod
ans=(sum2*500000004)%mod
print(int(ans))
|
input()
a = list(map(int, input().split()))
c = 1000000007
print(((sum(a)**2-sum(map(lambda x: x**2, a)))//2)%c)
| 1 | 3,800,829,779,446 | null | 83 | 83 |
a1,a2,a3=map(int,input().split())
ans=a1+a2+a3
if ans>=22:
print("bust")
else:
print("win")
|
a = input().split()
sum = 0
for n in a:
sum += int(n)
print('bust') if sum >= 22 else print('win')
| 1 | 119,168,180,243,968 | null | 260 | 260 |
# -*- coding: utf-8 -*-
while True:
score = list(map(int, input().split()))
if score[0] == -1 and score[1] == -1 and score[2] == -1:
break
elif -1 in (score[0], score[1]) or (score[0] + score[1]) < 30:
print('F')
elif (score[0] + score[1]) >= 80:
print('A')
elif 65 <= (score[0] + score[1]) < 80:
print('B')
elif 50 <= (score[0] + score[1]) < 65 or (30 <= (score[0] + score[1]) < 50 <= score[2]):
print('C')
elif 30 <= (score[0] + score[1]) < 50:
print('D')
|
while True:
m, f, r = map(int, input().split())
score = ""
if all([x < 0 for x in [m, f, r]]):
break
if any([x < 0 for x in [m, f]]):
score = "F"
elif 80 <= m+f:
score = "A"
elif 65 <= m+f:
score = "B"
elif 50 <= m+f or (30 <= m+f and 50 <= r):
score = "C"
elif 30 <= m+f:
score = "D"
else:
score = "F"
print(score)
| 1 | 1,252,472,361,232 | null | 57 | 57 |
s = input()
N = len(s)+1
res = []
ans = 0
i = 0
while i < N-1:
seq = 1
while i < N - 2 and s[i] == s[i + 1]:
i += 1
seq += 1
res.append(seq)
i += 1
if s[0] == '>':
ans += res[0] * (res[0] + 1) // 2
res = res[1:]
if s[-1] == '<':
ans += res[-1] * (res[-1]+1)//2
res = res[:-1]
for i in range(len(res) // 2):
tmp = max(res[2 * i], res[2 * i + 1])
tmp2 = min(res[2 * i], res[2 * i + 1])
ans += tmp * (tmp + 1) // 2
ans += tmp2 * (tmp2-1) //2
print(ans)
|
n = int(input())
digit = 1
while n > 26 ** digit:
n -= 26 ** digit
digit += 1
ans = []
n -= 1
char = 'abcdefghijklmnopqrstuvwxyz'
for i in list(range(digit)):
ans.append(char[n % 26])
n -= n%26
n = int(n/26)
print(''.join(reversed(ans)))
| 0 | null | 83,781,276,059,470 | 285 | 121 |
a = raw_input()
while a!='0':
s = 0
for i in range(len(a)):
s += int(a[i])
print s
a = raw_input()
|
l=input("").split(" ")
n=int(l[0])
k=int(l[1])
s=n%k
ss=k-s
if(s<ss):
print(s)
else:
print(ss)
| 0 | null | 20,484,132,425,930 | 62 | 180 |
x, y, z = [int(i) for i in input().split(" ")]
print(z, x, y)
|
nums=[int(i) for i in input().split()]
print(nums[2],nums[0],nums[1])
| 1 | 38,043,052,333,920 | null | 178 | 178 |
n = input()
len_n = len(n)
dp = [[0,2] for i in range(len_n+1)]
for k,v in enumerate(n[::-1]):
v = int(v)
dp[k+1][0] = min(dp[k][0] + v, dp[k][1] + v)
dp[k+1][1] = min(dp[k][0] + 10 - v + 1, dp[k][1] + 10 - v - 1)
print(min(dp[len_n]))
|
N = '0' + input()
INF = float('inf')
dp = [[INF] * 2 for _ in range(len(N) + 1)]
dp[0][0] = 0
for i in range(len(N)):
n = int(N[len(N) - 1 - i])
for j in range(2):
for a in range(10):
ni = i + 1
nj = 0
b = a - n - j
if b < 0:
b += 10
nj = 1
dp[ni][nj] = min(dp[ni][nj], dp[i][j] + a + b)
a == b
print(dp[len(N)][0])
| 1 | 70,772,304,246,918 | null | 219 | 219 |
from collections import defaultdict
from itertools import groupby, accumulate, product, permutations, combinations
from bisect import *
def solve():
ans = 0
N = int(input())
S = input()
d = defaultdict(lambda: [])
for i,s in enumerate(S):
d[int(s)].append(i)
for p in product(range(10),repeat=3):
if not len(d[p[0]]):
continue
ind1 = d[p[0]][0]
ind2 = bisect_right(d[p[1]],ind1)
if ind2==len(d[p[1]]):
continue
ind2 = d[p[1]][ind2]
ind3 = bisect_right(d[p[2]],ind2)
if ind3==len(d[p[2]]):
continue
ans += 1
return ans
print(solve())
|
k = int(input())
a = 7%k
flag = False
for i in range(k):
if a == 0:
flag = True
ans = i+1
break
a = (10*a+7)%k
if flag:
print(ans)
else:
print(-1)
| 0 | null | 67,622,442,152,290 | 267 | 97 |
import sys, heapq
from collections import defaultdict
from itertools import product, permutations, combinations
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.readline()[:-1]
N, u, v = map(int, input().split())
def dijkstra_heap(s,edge):
#始点sから各頂点への最短距離
d = [10**20] * N
used = [True] * N #True:未確定
d[s] = 0
used[s] = False
edgelist = []
for a,b in edge[s]:
heapq.heappush(edgelist,a*(10**6)+b)
while len(edgelist):
minedge = heapq.heappop(edgelist)
#まだ使われてない頂点の中から最小の距離のものを探す
if not used[minedge%(10**6)]:
continue
v = minedge%(10**6)
d[v] = minedge//(10**6)
used[v] = False
for e in edge[v]:
if used[e[1]]:
heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
return d
AB = [list(map(int, input().split())) for _ in range(N-1)]
adjl = [[] for _ in range(N)]
for ab in AB:
a, b = ab[0]-1, ab[1]-1
adjl[a].append([1, b])
adjl[b].append([1, a])
du = dijkstra_heap(u-1, adjl)
dv = dijkstra_heap(v-1, adjl)
dOK = [j for i, j in zip(du, dv) if i < j]
print(int(max(dOK)-1))
|
from collections import defaultdict, deque
N, u, v = map(int, input().split())
G = defaultdict(lambda: [])
for _ in range(N-1):
a,b=map(int,input().split())
G[a].append(b)
G[b].append(a)
if G[u] == [v]:
print(0)
exit()
def bfs(v):
seen = [0]*(N+1)
queue = deque()
dist = [-1]*(N+1)
dist[v] = 0
seen[v] = 1
queue.append(v)
while queue:
q = queue.popleft()
for nx in G[q]:
if seen[nx]:
continue
dist[nx] = dist[q] + 1
seen[nx] = 1
queue.append(nx)
return dist
d_u = bfs(u)
d_v = bfs(v)
ans = 0
for node in range(1, N+1):
if d_u[node] < d_v[node] and len(G[node]) == 1:
ans = max(ans, d_v[node]-1)
print(ans)
| 1 | 117,361,321,518,740 | null | 259 | 259 |
import math
n, k = map(int,input().split())
list = [int(x) for x in input().split()]
list.sort()
l = 0
r = max(list)
while r - l > 1:
count = 0
x = (r + l)//2
for i in range(len(list)):
if x >= list[i]:
continue
count += math.ceil(list[i]/x) - 1
if count <= k:
r = x
else:
l = x
print(r)
|
N, K = map(int, input().split())
A = list(map(int, input().split()))
r = max(A)
l = 0
while l+1 < r:
mid = (l+r)//2
cnt = 0
for a in A:
if(a > mid):
if(a%mid == 0):
cnt += (a//mid)-1
else:
cnt += a//mid
if(cnt > K):
l = mid
else:
r = mid
print(r)
| 1 | 6,500,270,870,250 | null | 99 | 99 |
n = int(input())
count = 0
if n < 2:
print(0)
exit()
for i in range(n//2):
a = i + 1
b = n - a
if a != b and a > 0 and b > 0:
count = count + 1
print(count)
|
print(int((int(input())+1)/2-1))
| 1 | 153,179,361,826,930 | null | 283 | 283 |
from collections import deque
N, D, A = list(map(int, input().split()))
pair_xh = [[-1, -1] for _ in range(N)] # 1回ずつしか使わないけどソートするから必要
for i in range(N):
pair_xh[i][0], pair_xh[i][1] = list(map(int, input().split()))
pair_xh.sort(key = lambda x: x[0]) #座標でソート
q_lim_d = deque() # 累積和に含まれる攻撃範囲とダメージを保存する場所
total = 0 # 喰らいダメージの累積和
count = 0 # 攻撃回数
for i in range(N):
x = pair_xh[i][0]
h = pair_xh[i][1]
while len(q_lim_d) and q_lim_d[-1][0] < x: # 範囲外になったら喰らわないから累積和から外す
total -= q_lim_d[-1][1]
q_lim_d.pop()
h -= total
if h > 0: # 見てる敵の体力が0になる攻撃回数を求めその分を累積和に足す
times = (h + A - 1) // A # 0にするのに必要な回数(切り上げ)
count += times
damage = A * times
total += damage
q_lim_d.appendleft([x + 2 * D, damage])
print(count)
|
import sys,queue,math,copy,itertools,bisect,collections,heapq
def main():
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
SI = lambda : sys.stdin.readline().rstrip()
N,D,A = LI()
X = []; XH = []
for _ in range(N):
x,h = LI()
X.append(x); XH.append((x,h))
XH.sort()
X.sort()
down = [0] * (N+1)
p = 0
ans = 0
for i in range(N):
if p < XH[i][1]:
b = -(-(XH[i][1]-p)//A)
ans += b
p += b * A
down[bisect.bisect(X,X[i]+2*D)-1] += b*A
p -= down[i]
print(ans)
if __name__ == '__main__':
main()
| 1 | 82,088,123,422,982 | null | 230 | 230 |
N,X,Y = map(int,input().split())
from collections import deque
INF = 1000000000
ans = [0]*(N-1)
def rep(sv,dist):
que = deque()
def push(v,d):
if (dist[v] != INF): return
dist[v] = d
que.append(v)
push(sv,0)
while(que):
v = que.popleft()
d = dist[v]
if v-1 >= 0:
push(v-1, d+1)
if v+1 < N:
push(v+1, d+1)
if v == X-1:
push(Y-1, d+1)
#逆に気を付ける
if v == Y-1:
push(X-1, d+1)
for i in range(N):
dist = [INF]*N
rep(i,dist)
# print(dist)
for d in dist:
if d-1 == -1:continue
ans[d-1] += 1
for an in ans:
print(an//2)
# print(ans)
|
n, x, y = list(map(int, input().split()))
x = x-1
y = y-1
ans = [0] * (n-1)
for i in range(n):
for j in range(i+1, n):
shortest = min(abs(j-i), abs(x-i)+abs(y-j)+1, abs(y-i)+abs(x-j)+1)
ans[shortest-1] += 1
for a in ans:
print(a)
| 1 | 44,283,908,403,812 | null | 187 | 187 |
def run(N, M, A):
'''
Aiが10^5なので、searchを以下に変えられる
サイズ10**5のリストで、その満足度を持つ数の件数を事前計算しておけばO(1)で求められる
'''
A = sorted(A, reverse=True)
cnt_A = [len(A)]
pre_a = 0
cnt_dict_A = {}
for a in sorted(A):
cnt_dict_A[a] = cnt_dict_A.get(a, 0) + 1
next_cnt = cnt_A[-1]
for a in sorted(cnt_dict_A.keys()):
cnt_A.extend([next_cnt]*(a-pre_a))
pre_a = a
next_cnt = cnt_A[-1]-cnt_dict_A[a]
right = A[0] * 2
left = 0
while left <= right:
X = (left + right) // 2
# 左手の相手がaで、満足度がX以上となる組合せの数
cnt = 0
for a in A:
# cnt += search(A, X - a)
if X - a <= A[0]:
if X - a >= 0:
cnt += cnt_A[X - a]
else:
cnt += cnt_A[0]
if cnt >= M:
res = X
left = X + 1
else:
right = X - 1
X = res
# Xが決まったので、累積和で組合せの数分の値を求める
sum_A = [0]
for a in sorted(A):
sum_A.append(sum_A[-1] + a)
sum_cnt = 0
ans = 0
for a in A:
cnt = search(A, X - a)
sum_cnt += cnt
if cnt > 0:
ans += cnt * a + sum_A[-1] - sum_A[-cnt-1]
if sum_cnt > M:
ans -= X * (sum_cnt - M)
return ans
def search(A, X):
'''
AのリストからX以上となる数値がいくつか探す
Aはソート済み(降順)
二分探索で実装O(logN)
leftとrightはチェック未
middleはループ終了後チェック済み
'''
left = 0
right = len(A) - 1
res = 0
while left <= right:
middle = (left + right) // 2
if A[middle] >= X:
res = middle + 1
left = middle + 1
else:
right = middle - 1
return res
def main():
N, M = map(int, input().split())
A = list(map(int, input().split()))
print(run(N, M, A))
if __name__ == '__main__':
main()
|
S = input()
T = input()
print('Yes') if T[:len(S)] == S else print('No')
| 0 | null | 64,636,550,517,450 | 252 | 147 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
S = input()
T = input()
#TがSの部分文字列になるようにSを書き換える
N = len(S)
M = len(T)
L = N - M #Sを調べるループの回数
#二重ループが許される
ans = M
for i in range(L+1):
#最大M個一致していない。
cnt = M
for j in range(M):
if S[i+j] == T[j]:
cnt -= 1
#最小を取る
ans = min(ans, cnt)
print(ans)
if __name__ == '__main__':
main()
|
N, K = map(int, input().split())
heights = list(map(int, input().split()))
qualified = 0
for height in heights:
if height >= K:
qualified += 1
print(qualified)
| 0 | null | 91,370,533,494,942 | 82 | 298 |
H ,W = map(int,input().split())
from collections import deque
S = [input() for i in range(H)]
directions = [[0,1],[1,0],[-1,0],[0,-1]]
counter = 0
#インデックス番号 xが行番号 yが列番号
for x in range(H):
for y in range(W):
if S[x][y]=="#":
continue
que = deque([[x,y]])
memory = [[-1]*W for _ in range(H)]
memory[x][y]=0
while True:
if len(que)==0:
break
h,w = que.popleft()
for i,k in directions:
x_new,y_new = h+i,w+k
if not(0<=x_new<=H-1) or not(0<=y_new<=W-1) :
continue
elif not memory[x_new][y_new]==-1 or S[x_new][y_new]=="#":
continue
memory[x_new][y_new] = memory[h][w]+1
que.append([x_new,y_new])
counter = max(counter,max(max(i) for i in memory))
print(counter)
|
N = int(input())
X = [list(map(int,input().split())) for _ in range(N)]
A = sorted([X[i][0] for i in range(N)])
B = sorted([X[i][1] for i in range(N)])
if N%2==1:
a = A[N//2]
b = B[N//2]
print(b-a+1)
else:
a = (A[(N-1)//2]+A[N//2])/2
b = (B[(N-1)//2]+B[N//2])/2
print(int((b-a)/0.5)+1)
| 0 | null | 55,839,433,217,060 | 241 | 137 |
x=input()
y=input()
lst1=[]
lst1=list(x)
lst2=[]
lst2=list(y)
b=0
ans=0
while(b<len(x)):
if(not lst1[b]==lst2[b]):
ans=ans+1
b+=1
print(ans)
|
# C - Go to School
N = int(input())
A = list(map(int,input().split()))
A = [(i+1,A[i]) for i in range(N)]
A.sort(key=lambda x:x[1])
A = [str(a[0]) for a in A]
print(' '.join(A))
| 0 | null | 95,566,933,648,648 | 116 | 299 |
n = int(input())
s, t = input().split()
s_and_t = s[0]
for i in range(len(s)):
if(i >= 1):
s_and_t += s[i]
s_and_t += t[i]
print(s_and_t)
|
rank = [0] * 4
for _ in range(10):
rank[0] = int(input())
rank.sort()
for r in reversed(rank[1:]):
print(r)
| 0 | null | 55,760,488,514,458 | 255 | 2 |
s = input()
if "B" in s:
print("ARC")
else:
print("ABC")
|
s = input()
if s[1] == 'R':
print('ABC')
else:
print('ARC')
| 1 | 23,999,211,925,132 | null | 153 | 153 |
n = int(input())
print("".join(["ACL" for i in range(n)]))
|
kazu = input()
kazu = int(kazu)
for i in range( kazu ):
print("ACL",end = '')
| 1 | 2,228,059,695,462 | null | 69 | 69 |
X,K,D = map(int,input().split())
X = abs(X)
if X <= K * D :
if (K - X // D) % 2 == 1 :
answer = abs(X % D - D)
else :
answer = X % D
else :
answer = X - K * D
print(answer)
|
from itertools import product
n = int(input())
n_num = [[0] * 10 for _ in range(10)]
for i in range(n + 1):
a, b = int(str(i)[0]), i % 10
n_num[a][b] += 1
answer = sum(n_num[a][b] * n_num[b][a] for a, b in product(range(1, 10), repeat=2))
print(answer)
| 0 | null | 45,761,066,841,412 | 92 | 234 |
INF = 1 << 60
n = int(input())
x = [0 for i in range(n)]
l = [0 for i in range(n)]
for i in range(n):
x[i], l[i] = map(int, input().split())
itv = [[x[i] - l[i], x[i] + l[i]] for i in range(n)]
itv.sort(key=lambda x:x[1])
# print("itv =", itv)
ans = 0
t = -INF
for i in range(n):
if t <= itv[i][0]:
ans += 1
t = itv[i][1]
print(ans)
|
n = int(input())
lst = []
for i in range(n):
x, l = map(int, input().split())
lst.append((x + l, x - l))
sorted_lst = sorted(lst)
num = 0
ans = n
while True:
tmp = sorted_lst[num][0]
for i in range(num + 1, n):
if tmp > sorted_lst[i][1]:
ans -= 1
else:
num = i
break
if i == n - 1:
num = i
break
if num == n - 1:
break
print(ans)
| 1 | 89,716,214,021,956 | null | 237 | 237 |
s1 = input()
s2 = input()
while len(s1) <= 100:
s1 = s1 + s1
if s2 in s1:
print("Yes")
else:
print("No")
|
# coding:utf-8
s = raw_input()
p = raw_input()
s += s
if p in s:
print "Yes"
else:
print "No"
| 1 | 1,731,167,365,940 | null | 64 | 64 |
rooms = []
rooms.append([[0 for i in range(10)] for j in range(3)])
rooms.append([[0 for i in range(10)] for j in range(3)])
rooms.append([[0 for i in range(10)] for j in range(3)])
rooms.append([[0 for i in range(10)] for j in range(3)])
num = int(raw_input())
for i in range(num):
b,f,r,v = map(int, raw_input().split())
rooms[b-1][f-1][r-1] += v
for number, room in enumerate(rooms):
for row in room:
print " %d %d %d %d %d %d %d %d %d %d" % (row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9])
if len(rooms) - 1 > number:
print('####################')
|
residents = [[[0] * 11 for i in range(4)] for j in range(5)]
N = int(input())
for _i in range(N):
b, f, r, v = map(int, input().split())
residents[b][f][r] += v
for i in range(1, 5):
for j in range(1, 4):
print(' ' + ' '.join(map(str, residents[i][j][1:])))
if not i == 4:
print(''.join(['#'] * 20))
| 1 | 1,096,973,103,132 | null | 55 | 55 |
import string
n = int(input())
alphabet = list(string.ascii_lowercase)
ans = ''
while n > 0:
ans = alphabet[(n-1) % 26] + ans
n = (n-1) // 26
print(ans)
|
pi = 3.141592653589793
r = float(input())
print('{0:f} {1:f}'.format(r*r*pi, 2 * r * pi))
| 0 | null | 6,271,306,657,928 | 121 | 46 |
k,n = map(int,input().split())
a = list(map(int,input().split()))
ans = 10 ** 8
for i in range(n-1):
a.append(a[i]+k)
for i in range(n):
ans = min(ans,a[i+n-1] - a[i])
print(ans)
|
n=int(input())
s=input()
ans=0
for i in range(n-2):
if s[i]=="R":
a,b="G","B"
elif s[i]=="G":
a,b="B","R"
else:
a,b="R","G"
cnt=[None]*(n-i-1)
acnt=0
bcnt=0
for j in range(i+1,n):
if s[j]==a:
acnt+=1
cnt[j-i-1]=a
elif s[j]==b:
bcnt+=1
cnt[j-i-1]=b
tmp=acnt*bcnt
for j in range((n-i-1)//2):
if cnt[j]==a and cnt[(j+1)*2-1]==b:
tmp-=1
elif cnt[j]==b and cnt[(j+1)*2-1]==a:
tmp-=1
ans+=tmp
print(ans)
| 0 | null | 39,604,887,840,010 | 186 | 175 |
n=input()
a=(int(n)+1)//2
print(a)
|
print((int(input())-1)//2+1)
| 1 | 59,233,837,471,898 | null | 206 | 206 |
n = int(input())
s = str(input())
s_new = s[0]
for i in range(1,len(s)):
if s_new[-1] != s[i]:
s_new = s_new + s[i]
print(len(s_new))
|
n = int(input())
s = str(input())
new_s = s[0]
for i in range(1,len(s)):
if s[i] == s[i-1]:
continue
else:
new_s += s[i]
print(len(new_s))
| 1 | 169,979,305,969,740 | null | 293 | 293 |
i = int(input())
if i >= 30:
print('Yes')
else:
print('No')
|
tem = int(input())
if tem >= 30:
print("Yes")
else:
print("No")
| 1 | 5,738,078,243,832 | null | 95 | 95 |
#!/usr/bin python3
# -*- coding: utf-8 -*-
def main():
H, W = map(int,input().split())
sth, stw = 0, 0
glh, glw = H-1, W-1
INF = 10000
Gmap = [list(input()) for _ in range(H)]
Dist = [[INF]*W for _ in range(H)]
direc = {(1,0), (0,1)}
if Gmap[0][0]=='#':
Dist[0][0]=1
else:
Dist[0][0]=0
for h in range(H):
for w in range(W):
nw = Gmap[h][w]
for d in direc:
hs, ws = h + d[0], w + d[1]
if 0<=hs<H and 0<=ws<W:
cr = Gmap[hs][ws]
Dist[hs][ws] = min(Dist[hs][ws], Dist[h][w] + (cr=='#' and nw=='.'))
print(Dist[glh][glw])
if __name__ == '__main__':
main()
|
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)
def main():
h,w = LI()
aa = [[0 if c == '.' else 1 for c in S()] for _ in range(h)]
dp = [[[inf]*2 for _ in range(w)] for __ in range(h)]
dp[0][0][aa[0][0]] = aa[0][0]
for i in range(h):
for j in range(w):
k = aa[i][j]
if i > 0:
dp[i][j][k] = min(dp[i][j][k], dp[i-1][j][k])
dp[i][j][k] = min(dp[i][j][k], dp[i-1][j][1-k]+1)
if j > 0:
dp[i][j][k] = min(dp[i][j][k], dp[i][j-1][k])
dp[i][j][k] = min(dp[i][j][k], dp[i][j-1][1-k]+1)
return min(dp[-1][-1][0] + 1, dp[-1][-1][1] + 2) // 2
print(main())
| 1 | 49,361,122,687,230 | null | 194 | 194 |
s=input()
if s=="RSR":
print("1")
else:
ans=s.count("R")
print(ans)
|
weather = list(input())
i = 0
j = 0
days = 0
consecutive = []
while i <= 2:
while i + j <= 2:
if weather[i+j] == "R":
days += 1
j += 1
else:
break
i += 1
j = 0
consecutive.append(days)
days = 0
print(max(consecutive))
| 1 | 4,921,345,419,302 | null | 90 | 90 |
n,a,b,=map(int,input().split())
c = n//(a+b)
da = n-c*(a+b)
if da>a:
da=a
print(c*a+da)
|
n, x, y = map(int, input().split())
graph = [[] for _ in range(n)]
for i in range(n):
if i+1 < n:
graph[i].append(i+1)
if i-1 >=0:
graph[i].append(i-1)
graph[x-1].append(y-1)
graph[y-1].append(x-1)
ans = [0] * (n-1)
from collections import deque
for i in range(n):
dist = [-1] * n
dist[i] = 0
d = deque()
d.append(i)
while d:
v = d.popleft()
for j in graph[v]:
if dist[j] != -1:
continue
dist[j] = dist[v] + 1
ans[dist[j] - 1] += 1
d.append(j)
for a in ans:
print(a//2)
| 0 | null | 49,956,487,704,558 | 202 | 187 |
import itertools
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A_=[0]+list(itertools.accumulate(A))
B_=[0]+list(itertools.accumulate(B))
ans=0
j=M
for i in range(N+1):
a=A_[i]
K_a=K-a
while (j>=0 and B_[j]>K_a):
j-=1
if a+B_[j]<=K:
ans=max(ans,i+j)
print(ans)
|
#!/usr/bin/env python3
import sys
MOD = 1000000007 # type: int
def solve(N: int, A: "List[int]"):
from functools import reduce
xyz_list = [[0]*3]
for a in A:
xyz_list.append(xyz_list[-1][:])
for i, v in enumerate(xyz_list[-1]):
if v == a:
xyz_list[-1][i] += 1
break
T = [xyz.count(a) for xyz, a in zip(xyz_list, A)]
return reduce(lambda a,b: a*b%MOD, T)
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
print(solve(N, A))
def test():
import doctest
doctest.testmod()
if __name__ == '__main__':
#test()
main()
| 0 | null | 70,174,893,152,992 | 117 | 268 |
from collections import deque
from sys import stdin
input = stdin.readline
N, M = map(int, input().split())
graph = [[] for _ in range(N)]
seen = [-1] * N
for _ in range(M):
a, b = map(int, input().split())
graph[a - 1].append(b - 1)
graph[b - 1].append(a - 1)
def bfs(x):
q = deque([])
q.append(x)
seen[x] = 1
while q:
x = q.popleft()
for y in graph[x]:
if seen[y] != -1:
continue
seen[y] = 1
q.append(y)
ans = 0
for i in range(N):
if seen[i] != -1:
continue
else:
ans += 1
bfs(i)
print(ans - 1)
|
#!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def root(x):
if par[x] == x:
return x
par[x] = root(par[x])
return par[x]
def union(x,y):
x = root(x)
y = root(y)
if rank[x] < rank[y]:
par[x] = y
else:
par[y] = x
if rank[x] == rank[y]:
rank[x] += 1
n, m = LI()
par = [i for i in range(n)]
rank = [0] * n
for _ in range(m):
a, b = LI()
if root(a-1) != root(b-1):
union(a-1, b-1)
s = set()
for i in range(n):
s.add(root(i))
ans = len(s)-1
print(ans)
| 1 | 2,273,524,606,162 | null | 70 | 70 |
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
a,b,c = map(int, input().split())
if a == b and a != c and b != c:
print("Yes")
elif a == c and a != b and c != b:
print("Yes")
elif b == c and a != b and a != c:
print("Yes")
else:
print("No")
|
print( 'Yes' if len(set(input().split())) == 2 else 'No')
| 1 | 68,179,072,542,122 | null | 216 | 216 |
class Saikoro:
def sai(self,one,two,three,four,five,six):
self.s1=int(one)
self.s2=int(two)
self.s3=int(three)
self.s4=int(four)
self.s5=int(five)
self.s6=int(six)
def turnE(self):
e=[self.s4,self.s2,self.s1,self.s6,self.s5,self.s3]
self.s1=e[0]
self.s2=e[1]
self.s3=e[2]
self.s4=e[3]
self.s5=e[4]
self.s6=e[5]
def turnN(self):
n=[self.s2,self.s6,self.s3,self.s4,self.s1,self.s5]
self.s1=n[0]
self.s2=n[1]
self.s3=n[2]
self.s4=n[3]
self.s5=n[4]
self.s6=n[5]
def turnS(self):
s=[self.s5,self.s1,self.s3,self.s4,self.s6,self.s2]
self.s1=s[0]
self.s2=s[1]
self.s3=s[2]
self.s4=s[3]
self.s5=s[4]
self.s6=s[5]
def turnW(self):
w=[self.s3,self.s2,self.s6,self.s1,self.s5,self.s4]
self.s1=w[0]
self.s2=w[1]
self.s3=w[2]
self.s4=w[3]
self.s5=w[4]
self.s6=w[5]
l=input().split()
m=list(input())
sai1=Saikoro()
sai1.sai(l[0],l[1],l[2],l[3],l[4],l[5])
n=len(m)
i=0
while i<n:
if m[i]=="E":
sai1.turnE()
elif m[i]=="N":
sai1.turnN()
elif m[i]=="S":
sai1.turnS()
else:
sai1.turnW()
i+=1
print(sai1.s1)
|
N = int(input())
L = list("abcdefghijklmnopqrstuvwxyz")
a = 1
while N > 26**a:
N = N - 26**a
a += 1
pre = []
for i in reversed(range(1,a)):
r = (N-1) // 26**i
pre.append(r)
N = int(N%(26**i))
ans = ''
for i in pre:
ans += L[i]
print(ans+L[N-1])
| 0 | null | 6,031,534,638,478 | 33 | 121 |
# -*- coding: utf-8 -*-
def maximum_profit(profits):
max_v = profits[1] - profits[0]
min_v = profits[0]
for j in range(1, len(profits)):
max_v = max(max_v, profits[j]-min_v)
min_v = min(min_v, profits[j])
print(max_v)
def to_int(v):
return int(v)
if __name__ == '__main__':
l = to_int(input())
profits = [to_int(input()) for i in range(l)]
maximum_profit(profits)
|
class Queue:
def __init__(self):
self.queue = []
def enqueue(self, value):
self.queue.append(value)
def dequeue(self):
return self.queue.pop(0)
class Task:
def __init__(self, name, time):
self.name = name
self.time = int(time)
self.endtime = 0
def __repr__(self):
return '{} {}'.format(self.name, self.endtime)
def rr(queue, q):
time = 0
while len(queue.queue) > 0:
task = queue.dequeue()
if task.time > q:
task.time -= q
time += q
queue.enqueue(task)
else:
time += task.time
task.time = 0
task.endtime = time
print(task)
if __name__ == '__main__':
nq = [int(s) for s in input().split()]
N = nq[0]
q = nq[1]
queue = Queue()
task_arr = [Task(*input().split()) for i in range(N)]
for t in task_arr:
queue.enqueue(t)
rr(queue, q)
| 0 | null | 27,660,591,200 | 13 | 19 |
n=int(input())
p=10**9+7
A=list(map(int,input().split()))
binA=[]
for i in range(n):
binA.append(format(A[i],"060b"))
lis=[0 for i in range(60)]
for binAi in binA:
for j in range(60):
lis[j]+=int(binAi[j])
binary=[0 for i in range(60)]
for i in range(n):
for j in range(60):
if binA[i][j]=="0":
binary[j]+=lis[j]
else:
binary[j]+=n-lis[j]
binary[58]+=binary[59]//2
binary[59]=0
explis=[1]
for i in range(60):
explis.append((explis[i]*2)%p)
ans=0
for i in range(59):
ans=(ans+binary[i]*explis[58-i])%p
print(ans)
|
#!/usr/bin/env python
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**6)
INF = float("inf")
def popcount(n):
ret = 0
for i in range(18):
if n>>i & 1:
ret += 1
return ret
def main():
N = int(input())
X = input().decode().rstrip()
# X に含まれる "1" の数
x_cnt = X.count("1")
# i 桁目が 0 : x_cnt += 1
# i 桁目が 1 : x_cnt -= 1
# より, X mod x_cnt +1, X mod x_cnt-1 を事前計算しておく
x_mod_pl,x_mod_mi = 0,0
d_pl,d_mi = 1,1
mod_pl,mod_mi = x_cnt+1,max(1,x_cnt-1)
for i in range(N-1,-1,-1):
if X[i]=="1":
x_mod_pl = (x_mod_pl + d_pl) % mod_pl
x_mod_mi = (x_mod_mi + d_mi) % mod_mi
d_pl = (d_pl*2) % mod_pl
d_mi = (d_mi*2) % mod_mi
for i in range(N):
ans = 1
if X[i] == "1":
# 1 -> 0 に変換した結果, 1が全く存在しない場合
if x_cnt == 1:
print(0)
continue
a = (x_mod_mi - pow(2,(N-1-i), mod_mi)) % mod_mi
else:
a = (x_mod_pl + pow(2,(N-1-i), mod_pl)) % mod_pl
while a > 0:
pop_cnt = popcount(a)
a %= pop_cnt
ans += 1
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 65,500,269,287,768 | 263 | 107 |
while True:
a=map(int,raw_input().split())
if a==[0,0]:
break
if a[0]>a[1]:print(str(a[1])+" "+str(a[0]))
else: print(str(a[0])+" "+str(a[1]))
|
x = int(input())
b = 100
for i in range(1,10**18):
b += b//100
if b >= x:
print(i)
break
| 0 | null | 13,816,499,932,220 | 43 | 159 |
n = int(input())
S = 100000
for i in range(n):
S = int(S*1.05)
slist = list(str(S))
if slist[-3:] == ['0','0','0'] :
S = S
else:
S = S - int(slist[-3])*100 - int(slist[-2])*10 - int(slist[-1])*1 + 1000
print(S)
|
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
c1 = T1*A1-T1*B1
c2 = T2*A2-T2*B2
if c1 > 0:
c1 *= -1
c2 *= -1
power = c1+c2
if power == 0:
print('infinity')
elif power < 0:
print(0)
else:
ans = 2*(-c1//power)+(c1%power > 0)
print(ans)
| 0 | null | 66,077,042,706,890 | 6 | 269 |
A, B, M = map(int,input().split())
A = [a for a in map(int,input().split())]
B = [b for b in map(int,input().split())]
C = []
for m in range(M):
C.append([c for c in map(int,input().split())])
ans = min(A) + min(B)
for c in C:
if (A[c[0]-1]+B[c[1]-1]-c[2])<ans:
ans = A[c[0]-1]+B[c[1]-1]-c[2]
print(ans)
|
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
m=10**6
for i in range(M):
x,y,z=map(int,input().split())
m=min(a[x-1]+b[y-1]-z,m)
print(min(m,min(a)+min(b)))
| 1 | 53,989,447,183,552 | null | 200 | 200 |
def main():
A1, A2, A3 = map(int, input().split())
if A1 + A2 + A3 >= 22:
ans = "bust"
else:
ans = "win"
print(ans)
if __name__ == "__main__":
main()
|
A = map(int,input().split())
if sum(A)>=22:
print("bust")
else:
print("win")
| 1 | 118,775,676,841,020 | null | 260 | 260 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.