code1
stringlengths 16
24.5k
| code2
stringlengths 16
24.5k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,628B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
import sys
def main():
input = sys.stdin.buffer.readline
n = int(input())
a = list(map(int, input().split()))
b = [0] * (10 ** 6)
ans = 0
for i in range(n):
if i - a[i] > 0:
ans += b[i - a[i]]
if i + a[i] < 10 ** 6:
b[i + a[i]] += 1
print(ans)
if __name__ == "__main__":
main()
|
N=int(input())
A=list(map(int,input().split()))
L={}
R={}
ans=0
for i in range(N):
if i+A[i] in L:
L[i+A[i]]+=1
else:
L[i+A[i]]=1
if A[i]<=i:
if i-A[i] in R:
R[i-A[i]]+=1
else:
R[i-A[i]]=1
for r in R:
if r in L:
ans+=L[r]*R[r]
print(ans)
| 1 | 26,171,917,384,290 | null | 157 | 157 |
h,a=map(int,input().split())
if h%a!=0:
n=int(h/a)+1
print(n)
else:
n=int(h/a)
print(n)
|
from collections import deque
while True:
str = input()
if str == "-":
break
dq = deque(char for char in list(str))
shuffle_count = int(input())
for i in range(shuffle_count):
h = int(input())
dq.rotate(h * -1)
print(''.join(dq))
| 0 | null | 39,336,472,532,930 | 225 | 66 |
n,m=map(int,input().split())
h =list(map(int,input().split()))
cnt = 0
l = [[] for i in range(n)]
for i in range(m):
a,b=map(int,input().split())
l[a-1].append(h[b-1])
l[b-1].append(h[a-1])
for i in range(n):
if l[i] == []:
cnt+=1
elif h[i] > max(l[i]):
cnt +=1
print(cnt)
|
N,M=map(int, input().split())
peaks=list(map(int, input().split()))
flag=[1]*N
a=0
b=0
for i in range(M):
a,b=map(int,input().split())
a-=1
b-=1
if peaks[a]<=peaks[b]:
flag[a]=0
if peaks[a]>=peaks[b]:
flag[b]=0
ans=0
for i in flag:
ans+=i
print(ans)
| 1 | 25,225,454,961,770 | null | 155 | 155 |
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
def readInts():
return list(map(int,input().split()))
def I():
return int(input())
m1,d1 = readInts()
m2,d2 = readInts()
print('1' if m1 != m2 else '0')
|
import sys
input = sys.stdin.readline
from bisect import *
def judge(x):
cnt = 0
for i in range(N):
idx = bisect_left(A, x-A[i])
cnt += N-idx
return cnt>=M
def binary_search():
l, r = 0, 10**11
while l<=r:
mid = (l+r)//2
if judge(mid):
l = mid+1
else:
r = mid-1
return r
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
border = binary_search()
acc = [0]
for Ai in A:
acc.append(acc[-1]+Ai)
ans = 0
cnt = 0
for i in range(N):
idx = bisect_left(A, border-A[i]+1)
ans += A[i]*(N-idx)+acc[N]-acc[idx]
cnt += N-idx
ans += (M-cnt)*border
print(ans)
| 0 | null | 116,283,516,525,290 | 264 | 252 |
x = int(input())
k = 1
while(True):
if k * x % 360 == 0:
print(k)
break
else:
k += 1
|
# A - Takahashikun, The Strider
x = int(input())
i = 1
while True:
if 360 * i % x == 0:
print(360 * i // x)
break
else:
i += 1
| 1 | 13,008,244,216,592 | null | 125 | 125 |
S, W = tuple(int(c) for c in input().split(' '))
if S > W:
print('safe')
else:
print('unsafe')
|
s,w = map(int,input().split())
print("unsafe" if w>=s else "safe")
| 1 | 28,991,130,831,570 | null | 163 | 163 |
N = int(input())
a = list(map(int, input().split(" ")))
t = 1
for x in a:
if x == t:
t += 1
t -= 1
if t == 0:
print(-1)
else:
print(N-t)
|
import typing
def binary_serch(x:int, b_sum:list):
l = 0
r = len(b_sum) - 1
mid = (l + r + 1) // 2
res = mid
while True:
if x == b_sum[mid]:
return mid
elif x < b_sum[mid]:
res = mid - 1
r = mid
mid = (l + r + 1) // 2
elif b_sum[mid] < x:
res = mid
l = mid
mid = (l + r + 1) // 2
if l + 1 == r:
return res
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b_sum = [0] * (m + 2)
for i in range(m):
b_sum[i + 1] = b[i] + b_sum[i]
b_sum[-1] = 10 ** 9 + 1
a = [0] + a
pass_k = 0
ans = 0
for i in range(n + 1):
if pass_k + a[i] <= k:
pass_k += a[i]
book = i
book += binary_serch(k - pass_k, b_sum)
ans = max(ans, book)
else:
break
print(ans)
| 0 | null | 62,442,712,456,188 | 257 | 117 |
n=int(input())
ans=set()
ans.add(n)
i=2
x = 1
while x * x <= n-1 :
if (n-1) % x == 0:
ans.add(x)
ans.add((n-1)//x)
x += 1
while i*i<=n:
t=n
while t%i==0:
t/=i
if t%i==1:
ans.add(i)
i+=1
print(len(ans)-1)
|
import sys
input = lambda: sys.stdin.readline().rstrip()
def main():
s, t = input().split()
print(t+s)
if __name__ == '__main__':
main()
| 0 | null | 72,041,212,817,910 | 183 | 248 |
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
def ceiler(a,b):
return -((-a)//b)
n,k=MI()
costs=LI()
difs=LI()
costs.sort()
difs.sort(reverse=True)
lis=[0 for i in range(n)]
#print(costs)
#print(difs)
for i in range(n):
lis[i]=costs[i]*difs[i]
#print(lis)
def judge(x):
times=0
for i in range(n):
u=ceiler(lis[i]-x,difs[i])
times+=max(0,u)
#print(u)
#print(x,times<=k)
return times<=k
l,r=-1,10**13
while l+1<r:
mid=(l+r)//2
if judge(mid):
r=mid
else:
l=mid
print(r)
|
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def IS(): return sys.stdin.readline()[:-1]
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 LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def main():
N,K = MI()
A = LI();A.sort();
F = LI();F.sort(reverse=True);
upper_X = -1
for i in range(N):
upper_X = max(A[i]*F[i], upper_X)
def BinarySearch(upper_X, lower_X):
X = upper_X//2
candidate = upper_X
while upper_X > lower_X:
deduct = 0
for i in range(N):
n = A[i]-X//F[i]
deduct += n if n>=1 else 0
if(K < deduct):
lower_X = X
if(upper_X - lower_X) <= 1: break
else:
candidate = X
upper_X = X
X = (lower_X+upper_X)//2
return candidate
print(BinarySearch(upper_X,0))
main()
| 1 | 165,552,829,629,020 | null | 290 | 290 |
INF=10**30
N=list(map(int,list(input())))[::-1]
l=len(N)
dp=[[INF,INF] for i in range(l+1)]
dp[0][0]=0
for i in range(l):
dp[i+1][0]=min(dp[i][0]+N[i],dp[i][1]+N[i]+1)
dp[i+1][1]=min(dp[i][0]+(10-N[i]),dp[i][1]+(9-N[i]))
print(min(dp[l][0],dp[l][1]+1))
|
l=[0]+[int(i) for i in input()]
l.reverse()
su=0
for i in range(len(l)):
if l[i]>5:
l[i]=10-l[i]
l[i+1]+=1
elif l[i]==5 and l[i+1]>4:
l[i+1]+=1
su+=l[i]
print(su)
| 1 | 71,271,339,133,220 | null | 219 | 219 |
import sys
input = sys.stdin.readline
#n = int(input())
#l = list(map(int, input().split()))
'''
a=[]
b=[]
for i in range():
A, B = map(int, input().split())
a.append(A)
b.append(B)'''
def cal(n,li):
lis=[True]*(n+1)
for item in li:
if lis[item]:
for i in range(item*2,n+1,item):
lis[i]=False
return lis
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
a.sort()
l=cal(a[-1],a)
ll=Counter(a)
#print(l,ll)
ans=0
for i in range(n):
if ll[a[i]]==1:
if l[a[i]]:
ans+=1
print(ans)
|
n = int(input())
x = input()
a = x.count('1')
b = int(x,2)
# print (b)
ary = [None for i in range(200010)]
ary[0] = 0
def f(n):
if ary[n] is not None:
return ary[n]
b = bin(n).count('1')
r = 1 + f(n%b)
ary[n] = r
return ary[n]
a1 = a + 1
a0 = a - 1
for i in range(200010):
f(i)
one = [1] * 200010
zero = [1] * 200010
for i in range(1, 200010):
if a0 != 0:
one[i] = one[i-1] * 2 % a0
zero[i] = zero[i-1] * 2 % a1
ans = [0 for i in range(n)]
c1 = b%a1
if a0 != 0:
c0 = b%a0
for i in range(n-1, -1, -1):
if x[n-1-i] == '0':
y = c1 + zero[i]
# y = x %a1
y %= a1
print (ary[y]+1)
else:
if a0 != 0:
y = c0 - one[i]
y %= a0
print (ary[y]+1)
else:
print (0)
# ans.reverse()
# for i in ans:
# print (i)
| 0 | null | 11,326,497,967,712 | 129 | 107 |
import sys
import numpy as np
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
#======================================================#
def main():
h, w, m = MII()
bombs = [MIIZ() for _ in range(m)]
a = [0]*h
b = [0]*w
for y,x in bombs:
a[y] += 1
b[x] += 1
maxa = max(a)
maxb = max(b)
sumv = maxa + maxb
c = a.count(maxa)*b.count(maxb) - sum(a[y]+b[x] == sumv for y,x in bombs)
print(sumv - (c<=0))
if __name__ == '__main__':
main()
|
h,w,m=map(int,input().split())
hl=[0]*(h)
wl=[0]*(w)
bom=[]
for i in range(m):
h1,w1=map(int,input().split())
bom.append([h1-1,w1-1])
hl[h1-1]+=1
wl[w1-1]+=1
mh=max(hl)
mw=max(wl)
ans=mh+mw
mhl=set()
mwl=set()
for i in range(h):
if mh==hl[i]:
mhl.add(i)
for i in range(w):
if mw==wl[i]:
mwl.add(i)
count=len(mhl)*len(mwl)
for i in range(len(bom)):
if bom[i][0] in mhl and bom[i][1] in mwl:
count-=1
if count>0:
print(ans)
else:
print(ans-1)
| 1 | 4,744,270,763,430 | null | 89 | 89 |
b,a = input().split()
print(a + b)
|
import math
H = int(input())
count = 0
atk = 0
for i in range(10 ** 12):
if H == 1:
for j in range(0,atk+1):
count += 2 ** j
break
else:
H = math.floor(H / 2)
atk += 1
print(count)
| 0 | null | 91,412,895,192,708 | 248 | 228 |
#coding:utf-8
#1_2_A
def bubble_sort(ary, n):
count = 0
flag = 1
i = 0
while flag:
flag = 0
for j in reversed(range(i+1, n)):
if ary[j] < ary[j-1]:
ary[j], ary[j-1] = ary[j-1], ary[j]
count += 1
flag = 1
i += 1
print(' '.join(map(str, ary)))
print(count)
n = int(input())
numbers = list(map(int, input().split()))
bubble_sort(numbers, n)
|
n = int(input())
nums = list(map(int, input().split()))
count = 0
while True:
flag = 0
for j in range(n - 1):
if (nums[j + 1] < nums[j]):
temp = nums[j]
nums[j] = nums[j + 1]
nums[j + 1] = temp
count += 1
flag = 1
if flag != 1:
break
print(' '.join([str(i) for i in nums]))
print(count)
| 1 | 16,819,769,890 | null | 14 | 14 |
n = int(input())
abc="abcdefghijklmnopqrstuvwxyz"
ans = ""
while True:
n -= 1
m = n % 26
ans += abc[m]
n = n // 26
if n == 0:
break
print(ans[::-1])
|
s = input()
t = input()
change = len(t)
for x in range(len(s) - len(t) + 1):
temp_change = 0
for y in range(len(t)):
if s[x+y] != t[y]:
temp_change += 1
if change > temp_change:
change = temp_change
print(change)
| 0 | null | 7,732,113,464,740 | 121 | 82 |
n = input()
x = input()
if n == x[:-1]:
if len(x) - len(n) == 1:
print('Yes')
else:
print('No')
|
S = input()
T = input()
N = len(S)
if len(T) == N+1:
Ts = T[:N]
if Ts == S:
print('Yes')
else:
print('No')
else:
print('No')
| 1 | 21,427,058,765,410 | null | 147 | 147 |
N = int(input())
ans = [0] * (N + 1)
for x in range(1, 10 ** 2 + 1):
for y in range(1, 10 ** 2 + 1):
for z in range(1, 10 ** 2 + 1):
n = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
if N < n:
continue
ans[n] += 1
print(*ans[1:], sep='\n')
|
N, K = map(int, input().split())
A = list(map(int, input().split()))
visited = [0 for _ in range(N)]
first_visit = [0 for _ in range(N)]
now = 0
flag = True
for i in range(10 ** 5 * 5):
if first_visit[now] == 0:
first_visit[now] = i
visited[A[now] - 1] += 1
now = A[now] - 1
if i == K - 1:
print(now + 1)
flag = False
break
if flag:
num = 0
for i in range(N):
if visited[i] > 2:
num += 1
for i in range(N):
if visited[i] >= 2:
if K % num == first_visit[i] % num:
print(i + 1)
break
| 0 | null | 15,290,805,392,230 | 106 | 150 |
A, B, C = map(int, input().split())
if (A == B and B == C) or (A != B and B != C and A != C):
print("No")
else:
print("Yes")
|
l = input().split(' ')
print('Yes' if len(set(l)) == 2 else 'No')
| 1 | 68,078,735,333,740 | null | 216 | 216 |
f = lambda x: x if p[x]<0 else f(p[x])
N,M = map(int,input().split())
p = [-1]*N
for _ in range(M):
A,B = map(lambda x:f(int(x)-1),input().split())
if A==B: continue
elif A<B: A,B=B,A
p[A] += p[B]
p[B] = A
print(sum(i<0 for i in p)-1)
|
n = int(input())
a = ["a","b","c","d","e","f","g","h","i","j"]
def dfs(s, max_x, LEN):
if LEN == n:
print(s)
else:
for c in a[:a.index(max_x)+2]:
dfs(s+c, max(max_x,c), LEN+1)
dfs("a", "a", 1)
| 0 | null | 27,422,247,568,420 | 70 | 198 |
import math
def koch(n, p1, p2):
if n == 0:
return
s = [(2 * p1[0] + p2[0]) / 3, (2 * p1[1] + p2[1]) / 3]
t = [(p1[0] + 2 * p2[0]) / 3, (p1[1] + 2 * p2[1]) / 3]
u = [(t[0] - s[0]) * math.cos(math.radians(60))
- (t[1] - s[1]) * math.sin(math.radians(60)) + s[0],
(t[0] - s[0]) * math.sin(math.radians(60))
+ (t[1] - s[1]) * math.cos(math.radians(60)) + s[1]]
koch(n - 1, p1, s)
print(s[0], s[1])
koch(n - 1, s, u)
print(u[0], u[1])
koch(n - 1, u, t)
print(t[0], t[1])
koch(n - 1, t, p2)
n = int(input())
p1 = (0, 0)
p2 = (100, 0)
print(p1[0], p1[1])
koch(n, p1, p2)
print(p2[0], p2[1])
|
s=raw_input()
p=raw_input()
if p in s*2:
print "Yes"
else:
print "No"
| 0 | null | 950,052,680,930 | 27 | 64 |
# E - All-you-can-eat
n,t=map(int,input().split())
a,b=[],[]
for i in range(n):
aa,bb=map(int,input().split())
a.append(aa)
b.append(bb)
dp1=[[0]*t for _ in range(n+1)] # 前から
dp2=[[0]*t for _ in range(n+1)] # 後ろから
arev=a[::-1]
brev=b[::-1]
for i in range(1,n+1):
for j in range(t):
if j-a[i-1]>=0:
dp1[i][j]=max(dp1[i-1][j-a[i-1]]+b[i-1],dp1[i-1][j])
else:
dp1[i][j]=dp1[i-1][j]
for i in range(1,n+1):
for j in range(t):
if j-arev[i-1]>=0:
dp2[i][j]=max(dp2[i-1][j-arev[i-1]]+brev[i-1],dp2[i-1][j])
else:
dp2[i][j]=dp2[i-1][j]
ans=-1
for i in range(1,n+1):
for j in range(t):
ans=max(ans,dp1[i-1][j]+dp2[n-i][t-1-j]+b[i-1])
print(ans)
|
number = int(input())
Total = []
for i in range(1, number + 1):
if number % 3 == 0 and i % 5 ==0:
"FizzBuzz"
elif i % 3 ==0:
"Fizz"
elif i % 5 == 0:
"Buzz"
else:
Total.append(i)
print(sum(Total))
| 0 | null | 93,288,727,345,550 | 282 | 173 |
a = input()
iff3 = a[2]
iff4 = a[3]
iff5 = a[4]
iff6 = a[5]
if iff3 == iff4 :
if iff5 == iff6 :
print("Yes")
else :
print("No")
else :
print("No")
|
S = input()
ans = 'No'
if (S[2] == S[3]) and (S[4] == S[5]):
ans = 'Yes'
print(ans)
| 1 | 41,923,819,491,520 | null | 184 | 184 |
n, m = map(int, input().split())
h_list = list(map(int, input().split()))
min_list = [1] * n
for _ in range(m):
a, b = map(lambda x : int(x) - 1, input().split())
if h_list[a] <= h_list[b]:
min_list[a] = 0
if h_list[b] <= h_list[a]:
min_list[b] = 0
print(sum(min_list))
|
n, m = map(int,input().split())
h = list(map(int, input().split()))
e = [[] for _ in range(n)]
for i in range(m):
u, v = map(int,input().split())
u -= 1
v -= 1
e[u].append(h[u]- h[v])
e[v].append(h[v]- h[u])
cnt = 0
for i in range(n):
if not e[i]:
cnt += 1
elif min(e[i]) > 0:
cnt += 1
print(cnt)
| 1 | 25,022,836,274,020 | null | 155 | 155 |
n = int(input())
s = input()
x = [int(i) for i in s]
pc = s.count('1')
def popcnt(x):
x = x - ((x >> 1) & 0x5555555555555555)
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
x = x + (x >> 8)
x = x + (x >> 16)
x = x + (x >> 32)
return x & 0x0000007f
def f(x):
if x == 0:
return 0
return f(x % popcnt(x)) + 1
ans = [0]*n
for a in range(2):
npc = pc
if a == 0:
npc += 1
else:
npc -= 1
if npc <= 0:
continue
r0 = 0
for i in range(n):
r0 = (r0*2) % npc
r0 += x[i]
k = 1
for i in range(n-1, -1, -1):
if x[i] == a:
r = r0
if a == 0:
r = (r+k) % npc
else:
r = (r-k+npc) % npc
ans[i] = f(r) + 1
k = (k*2) % npc
for i in ans:
print(i)
|
import sys
import collections
S = int(next(sys.stdin))
_A = (s.strip() for s in sys.stdin)
A = collections.Counter(_A)
# print(A)
# print(max(A.values()))
m = max(A.values())
keys = [k for k, v in A.items() if v == m]
keys.sort()
for s in keys:
print(s)
| 0 | null | 39,345,347,911,352 | 107 | 218 |
s = input()
p = input()
s = s + s[:len(p)]
if p in s:
print('Yes')
else:
print('No')
|
def main():
s = input()
t = input()
if s == t[0:len(t) - 1]:
print('Yes')
else:
print('No')
main()
| 0 | null | 11,661,939,813,240 | 64 | 147 |
while True:
H, W = map(int, raw_input().split())
if H == W == 0:
break
for i in range(H):
if i == 0 or i == H -1:
print "#" * W
else:
print "#" + "."*(W-2) + "#"
print
|
while True:
h,w = [int(s) for s in input().split(' ')]
if h==0 and w==0:
break
else:
top_bottom = '#'*w + '\n'
low = '#' + '.'*(w-2) + '#\n'
rectangle = top_bottom + low*(h-2) + top_bottom
print(rectangle)
| 1 | 819,360,275,972 | null | 50 | 50 |
N = int(input())
A = list(map(int, input().split()))
for i, a in enumerate(A.copy(), 1):
A[a - 1] = i
for a in A:
print(str(a) + ' ', end='')
print()
|
N = int(input())
list = input().split()
answer = [0] * N
for i in range(N):
answer[int(list[i]) - 1] = str(i + 1)
print(' '.join(answer))
| 1 | 181,570,453,200,256 | null | 299 | 299 |
count = 0
def marge(A,left,mid,right):
global count
n1 = mid -left
n2 = right -mid
L = []
R = []
for i in range(left,n1+left):
L.append(A[i])
for i in range(mid,n2+mid):
R.append(A[i])
L.append(float("inf"))
R.append(float("inf"))
r_id,l_id = 0,0
for k in range(left,right):
count += 1
if(L[l_id] <= R[r_id]):
A[k] = L[l_id]
l_id += 1
else:
A[k] = R[r_id]
r_id += 1
def margeSort(A,left,right):
if left+1 < right:
mid = int((left+right)/2)
margeSort(A,left,mid)
margeSort(A,mid,right)
marge(A,left,mid,right)
n = int(raw_input())
s = raw_input()
A = []
A = map(int,s.split())
margeSort(A,0,n)
A_str = map(str,A)
print(" ".join(list(A_str)))
print count
|
import math
f = True
N = int(input())
for i in range(N+1):
if math.floor(i*1.08) == N:
print(i)
f = False
break
if f:
print(":(")
| 0 | null | 62,980,331,404,592 | 26 | 265 |
a = list(map(int,input().split()))
print(15-sum(a))
|
H, W = map(int, input().split())
ans = 0
if H%2==0:
a = H // 2
b = H // 2
else:
a = H // 2 + 1
b = H // 2
if H==1 or W==1:
ans = 1
elif W%2==0:
ans = a * (W // 2) + b * (W // 2)
else:
ans = a * (W // 2 + 1) + b * (W // 2)
print(ans)
| 0 | null | 32,338,973,432,348 | 126 | 196 |
import math
def koch_kurve(n, p1=[0, 0], p2=[100, 0]):
if n == 0: return
s, t, u = make_edge_list(p1, p2)
koch_kurve(n-1, p1, s)
# print(s)
# print(s)
print(" ".join([ str(i) for i in s ]))
koch_kurve(n-1, s, u)
print(" ".join([ str(i) for i in u ]))
koch_kurve(n-1, u, t)
print(" ".join([ str(i) for i in t ]))
koch_kurve(n-1, t, p2)
def make_edge_list(p1, p2):
sx = 2 / 3 * p1[0] + 1 / 3 * p2[0]
sy = 2 / 3 * p1[1] + 1 / 3 * p2[1]
# s = (sx, sy)
s = [sx, sy]
tx = 1 / 3 * p1[0] + 2 / 3 * p2[0]
ty = 1 / 3 * p1[1] + 2 / 3 * p2[1]
t = [tx, ty]
theta = math.radians(60)
ux = math.cos(theta) * (tx - sx) - math.sin(theta) * (ty - sy) + sx
uy = math.sin(theta) * (tx - sx) + math.cos(theta) * (ty - sy) + sy
u = [ux, uy]
return s, t, u
n = int(input())
print("0 0")
koch_kurve(n)
print("100 0")
|
n = input()
S = list(map(int,input().split()))
n = input()
T = list(map(int,input().split()))
count = 0
for i in T:
if i in S:
count+= 1
print(count)
| 0 | null | 100,335,938,974 | 27 | 22 |
x = input()
print(int(x)*int(x)*int(x))
|
while True:
x, y = list(map(int, input().split()))
if (x == 0 and y == 0) :
break
if (x < y) :
print(str(x) + " " + str(y))
else :
print(str(y) + " " + str(x))
| 0 | null | 392,892,864,432 | 35 | 43 |
import sys
sys.setrecursionlimit(10**7)
n = int(input())
def dfs(s):
if len(s) == n:
print(s)
return 0
for x in map(chr, range(97, ord(max(s))+2)):
dfs(s+x)
dfs('a')
|
from collections import deque
N = int(input())
def dfs(str):
if len(str) == N:
print(*str, sep="")
return
M = max(str)
for i in range(ord(M) - ord("a") + 2):
char = alpha[i]
str.append(char)
dfs(str)
str.pop()
alpha = 'abcdefghijklmnopqrstuvwxyz'
s = deque(["a"])
dfs(s)
| 1 | 52,468,047,192,780 | null | 198 | 198 |
#create date: 2020-07-03 10:09
import sys
stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))
def main():
s = ns()
t = ns()
print("Yes" if s==t[:-1] else "No")
if __name__ == "__main__":
main()
|
class Dice:
def __init__(self, men):
self.men = men
def throw(self, direction):
if direction == "E":
pmen = men[:]
men[0] = pmen[3]
men[1] = pmen[1]
men[2] = pmen[0]
men[3] = pmen[5]
men[4] = pmen[4]
men[5] = pmen[2]
elif direction == "W":
pmen = men[:]
men[0] = pmen[2]
men[1] = pmen[1]
men[2] = pmen[5]
men[3] = pmen[0]
men[4] = pmen[4]
men[5] = pmen[3]
elif direction == "S":
pmen = men[:]
men[0] = pmen[4]
men[1] = pmen[0]
men[2] = pmen[2]
men[3] = pmen[3]
men[4] = pmen[5]
men[5] = pmen[1]
elif direction == "N":
pmen = men[:]
men[0] = pmen[1]
men[1] = pmen[5]
men[2] = pmen[2]
men[3] = pmen[3]
men[4] = pmen[0]
men[5] = pmen[4]
def printUe(self):
print (self.men)[0]
def printMen(self):
print self.men
men = map(int, (raw_input()).split(" "))
d = Dice(men)
S = raw_input()
for s in S:
d.throw(s)
d.printUe()
| 0 | null | 10,813,807,804,854 | 147 | 33 |
n=int(input())
a=1000
i=1
while n>a:
i=i+1
a=a+1000
print(a-n)
|
n = int(input())
rounded = round(n, -3)
if rounded < n:
rounded += 1000
print(rounded - n)
| 1 | 8,436,476,209,810 | null | 108 | 108 |
def cube(x):
return x**3
n = int(input())
print(cube(n))
|
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))
l=set([1,2,3])
for i in range(2):
l=l-set([int(input())])
print(int(list(l)[0]))
| 0 | null | 55,663,188,596,092 | 35 | 254 |
import math
N = int(input())
x = math.ceil(N/1000)
print(x*1000-N)
|
N=int(input())
if N%1000==0:
Q=N//1000
else:
Q=N//1000+1
W=Q*1000-N
print(W)
| 1 | 8,498,368,069,842 | null | 108 | 108 |
n = int(input())
X_MAX = 50001
for x in range(X_MAX):
if int(x * 1.08) == n:
print(x)
exit()
print(":(")
|
x = int(input())
b = int(x/1.08)
x1 = int(b*1.08)
x2 = int((b+1)*1.08)
if x1 == x:
print(b)
elif x2 == x:
print(b+1)
else:
print(":(")
| 1 | 125,610,310,327,222 | null | 265 | 265 |
n, a, b = map(int, input().split())
ans = 0
if (b - a) % 2 == 0:
ans = (b - a) // 2
else:
# ans += (b - a) // 2
# a += ans
# b -= ans
# ans += min(n - a, b - 1)
if a - 1 <= n - b:
ans += a
b -= a
a = 1
else:
ans += n - b + 1
a += n - b + 1
b = n
ans += (b - a) // 2
print(ans)
|
N, A, B=map(int, input().split())
if (B-A)%2==0:
print((B-A)//2)
else:
if A==1 or B==N:
ans=(B-A-1)//2+1
else:
ans=min(A-1, N-B)+(B-A-1)//2+1
print(ans)
| 1 | 109,497,281,784,212 | null | 253 | 253 |
# -*-coding:utf-8
def main():
while True:
inputNumber = input()
if(inputNumber == '0'):
break
else:
print(sum(list(map(int, inputNumber))))
if __name__ == '__main__':
main()
|
# -*- coding: utf-8 -*-
while True:
n = int(input())
if n == 0:
break
l = [int(x) for x in list(str(n))]
print(sum(l))
| 1 | 1,567,555,412,320 | null | 62 | 62 |
import sys
#input = sys.stdin.buffer.readline
# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np
def main():
n=int(input())
s=[]
t=[]
for i in range(n):
a,b=input().split()
s.append(a)
t.append(int(b))
x=input()
for i in range(n):
if x==s[i]:
print(sum(t[i+1:]))
if __name__ == "__main__":
main()
|
n=int(input())
s=[]
t=[]
for i in range(n):
st,tt=input().split()
s.append(st)
t.append(int(tt))
x=str(input())
temp=0
ans=sum(t)
for i in range(n):
temp=temp+t[i]
if s[i]==x:
break
print(ans-temp)
| 1 | 97,038,648,428,762 | null | 243 | 243 |
# Date [ 2020-08-23 14:02:31 ]
# Problem [ e.py ]
# Author Koki_tkg
# After Contest
import sys; from decimal import Decimal
import math; from numba import njit, i8, u1, b1
import bisect; from itertools import combinations, product
import numpy as np; from collections import Counter, deque, defaultdict
# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846
def read_str(): return sys.stdin.readline().strip()
def read_int(): return int(sys.stdin.readline().strip())
def read_ints(x=0): return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def lcm(a: int, b: int) -> int: return (a * b) // math.gcd(a, b)
def solve(h,w,bomb):
row = np.zeros(h, dtype=np.int64)
column = np.zeros(w, dtype=np.int64)
for y, x in bomb:
row[y] += 1
column[x] += 1
max_row = np.max(row)
max_col = np.max(column)
val = max_row + max_col
max_row_lis = np.ravel(np.where(row == row.max()))
max_col_lis = np.ravel(np.where(column == column.max()))
for r in max_row_lis:
for c in max_col_lis:
if (r, c) not in bomb:
return val
return val - 1
def Main():
h, w, m = read_ints()
bomb = set([tuple(read_ints(x=1)) for _ in range(m)])
print(solve(h, w, bomb))
if __name__ == '__main__':
Main()
|
H,V,M=map(int,input().split())
h=[0 for i in range(M)]
w=[0 for i in range(M)]
for i in range(M):
h[i],w[i]=map(int,input().split())
Dh=dict()
Dw=dict()
for i in range(M):
if h[i] in Dh:
Dh[h[i]]+=1
else:
Dh[h[i]]=1
if w[i] in Dw:
Dw[w[i]]+=1
else:
Dw[w[i]]=1
Hmax=0
Wmax=0
for i in Dh:
if Dh[i]>Hmax:
Hmax=Dh[i]
for i in Dw:
if Dw[i]>Wmax:
Wmax=Dw[i]
A=0
B=0
for i in Dh:
if Dh[i]==Hmax:
A+=1
for i in Dw:
if Dw[i]==Wmax:
B+=1
tmp=0
for i in range(M):
if Dh[h[i]]==Hmax and Dw[w[i]]==Wmax:
tmp+=1
if A*B>tmp:
print(Hmax+Wmax)
else:
print(Hmax+Wmax-1)
| 1 | 4,703,155,575,392 | null | 89 | 89 |
n, k = map(int, input().split())
truck = [0] * k
w = []
for _ in range(n):
w.append(int(input()))
def is_ok(p):
truck_index = 0
w_index = 0
while w_index < n and truck_index < k:
load_sum = 0
while w_index < n and load_sum + w[w_index] <= p:
load_sum += w[w_index]
w_index += 1
truck_index += 1
return w_index == n
ng = 0
ok = 100000 * 100000
while ok - ng > 1:
mid = (ng + ok) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
print("%d" % ok)
|
import sys
l = []
for line in sys.stdin:
l.append(line)
for i in range(len(l)):
numl = l[i].split(' ')
a = int(numl[0])
b = int(numl[1])
sum = a + b
digitstr = "{0}".format(sum)
print(len(digitstr))
| 0 | null | 45,509,301,486 | 24 | 3 |
N = int(input())
a = list(map(int, input().split()))
count = 0
for i in range(N):
minj = i
for j in range(i, N):
if a[j] < a[minj]:
minj = j
if a[i] != a[minj]:
a[minj], a[i] = a[i], a[minj]
count += 1
print(*a)
print(count)
|
INF = float("inf")
n, k, c = map(int, input().split())
s = input()
l, r = [(0, -INF)] + [None] * n, [(0, INF)] + [None] * n
for i, x in enumerate(s):
wn, wd = l[i]
l[i+1] = (wn+1, i) if x == "o" and i-wd > c else l[i]
for i, x in enumerate(s[::-1]):
wn, wd = r[i]
j = n-i-1
r[i+1] = (wn+1, j) if x == "o" and wd-j > c else r[i]
for i in range(n):
ln, ld = l[i]
rn, rd = r[n-i-1]
w = ln + rn
if rd - ld <= c: w -= 1
if w < k: print(i+1)
| 0 | null | 20,486,761,968,820 | 15 | 182 |
def qsort(l):
if l == []: return []
else:
pv = l[0]
left = []
right = []
for i in range(1, len(l)):
if l[i] > pv:
left.append(l[i])
else:
right.append(l[i])
left = qsort(left)
right = qsort(right)
left.append(pv)
return left + right
def main():
lst = []
for i in range(0, 10):
lst.append(int(raw_input()))
lst = qsort(lst)
for i in range(0, 3):
print(lst[i])
main()
|
a=[]
for i in range(10):
a.append(int(input()))
a=sorted(a)[::-1]
for i in range(3):
print(a[i])
| 1 | 27,310,052 | null | 2 | 2 |
import bisect
import math
import sys
from collections import Counter, defaultdict, deque
from copy import copy, deepcopy
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations
from queue import Queue
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def SI():
return int(readline())
def MI():
return map(int, readline().split())
def MLI():
return map(int, open(0).read().split())
inf = float("inf")
def check(k, P, W):
count = 1
tmp_sum = 0
for w in W:
if tmp_sum + w <= P:
tmp_sum += w
else:
tmp_sum = w
count += 1
if count <= k:
return True
else:
return False
def main():
n, k, *W = MLI()
lb = max(W)
ub = sum(W)
while ub - lb > 1:
P = (lb + ub) // 2
if check(k, P, W):
ub = P
else:
lb = P
if check(k, lb, W):
print(lb)
else:
print(ub)
if __name__ == "__main__":
main()
|
from typing import List
def is_able_to_load(tmp_P: int, weights: List[int], track_num_max: int) -> bool:
track_num = 1
tmp_sum = 0
for w in weights:
if tmp_sum + w <= tmp_P:
tmp_sum += w
else:
track_num += 1
tmp_sum = w
if track_num > track_num_max:
return False
return True
if __name__ == "__main__":
n, k = map(lambda x: int(x), input().split())
weights = list(map(lambda x: int(input()), range(n)))
left_weight = max(weights)
right_weight = 10000 * 100000
mid_weight = (left_weight + right_weight) // 2
optimal_P = right_weight
while left_weight <= right_weight:
if is_able_to_load(mid_weight, weights, k):
optimal_P = mid_weight
right_weight = mid_weight - 1
else:
left_weight = mid_weight + 1
mid_weight = (left_weight + right_weight) // 2
print(f"{optimal_P}")
| 1 | 91,152,389,192 | null | 24 | 24 |
#!/usr/bin/env python
# coding: utf-8
# In[1]:
N = int(input())
# In[15]:
def func(i,j,N):
ans = []
for x in range(1,N+1):
x_ = str(x)
if x_[0] == str(i) and x_[-1] == str(j):
ans += [x]
return ans
# In[23]:
ans = 0
for i in range(10):
for j in range(10):
ans += len(func(i,j,N))*len(func(j,i,N))
print(ans)
# In[ ]:
|
n, k = map(int, input().split())
a = set()
for i in range(k):
d = input()
a |= set(map(int, input().split()))
print(n - len(a))
| 0 | null | 55,286,972,816,000 | 234 | 154 |
from collections import deque
h,w = map(int, input().split())
hw = [input() for _ in range(h)]
def bfs(s):
que = deque([s])
m = [[-1]*w for _ in range(h)]
sh, sw = s
m[sh][sw] = 0
ret = 0
while que:
now_h, now_w = que.popleft()
for dh, dw in [(1,0), (-1,0), (0,-1), (0,1)]:
nh = now_h + dh
nw = now_w + dw
if not (0<=nh<h and 0<=nw<w) or m[nh][nw] != -1 or hw[nh][nw] == '#':
continue
m[nh][nw] = m[now_h][now_w] + 1
que.append((nh,nw))
ret = max(ret, m[now_h][now_w] + 1)
return ret
ans = 0
for y in range(h):
for x in range(w):
if hw[y][x] == '#':
continue
s = (y, x)
ans = max(bfs(s), ans)
print(ans)
|
import math
import itertools
from collections import deque
import bisect
import heapq
def IN(): return int(input())
def sIN(): return input()
def lIN(): return list(input())
def MAP(): return map(int,input().split())
def LMAP(): return list(map(int,input().split()))
def TATE(n): return [input() for i in range(n)]
ans = 0
def bfs(sx,sy):
d = [[-1] * w for i in range(h)]
MAX = 0
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
que = deque([])
que.append((sx, sy))#スタート座標の記録
d[sx][sy] = 0#スタートからスタートへの最短距離は0
while que:#中身がなくなるまで
p = que.popleft()
for m in range(4):#現在地から4方向の移動を考える
nx = p[0] + dx[m]
ny = p[1] + dy[m]
if 0 <= nx < h and 0 <= ny < w:
if maze[nx][ny] != "#" and d[nx][ny] == -1:
que.append((nx, ny))#↑格子点からでない&壁でない&まだ通ってない
d[nx][ny] = d[p[0]][p[1]] + 1
for k in range(h):
MAX = max(max(d[k]),MAX)
return MAX
h, w = map(int, input().split())
maze = [lIN() for i in range(h)]
for i in range(h):#sx座標指定0~h-1
for j in range(w):#sy座標指定0~w-1
if maze[i][j] == '.':
ans = max(bfs(i,j),ans)
print(ans)
| 1 | 94,416,877,903,370 | null | 241 | 241 |
n,m=map(int,input().split())
for i in range(m):
if n%2==0 and 2*m-i-i-1>=n//2:
print(i+1,2*m-i+1)
else:
print(i+1,2*m-i)
|
n,m = map(int,input().split())
if(n % 2 == 0):
d = n // 2 - 1
c = 0
i = 1
while(d > 0):
print(i,i+d)
d -= 2
i += 1
c += 1
if(c == m):exit()
d = n // 2 - 2
i = n // 2 + 1
while(d > 0):
print(i,i+d)
d -= 2
i += 1
c += 1
if(c == m):exit()
else:
for i in range(m):
print(i+1,n-i)
| 1 | 28,616,534,628,220 | null | 162 | 162 |
while True:
H, W = [int(x) for x in input().split() if x.isdigit()]
if H ==0 and W == 0:
break
else:
for i in range(H):
print("#", end='')
if i == 0 or i == H-1:
for j in range(W-2):
print("#", end='')
else:
for j in range(W-2):
print(".", end='')
print("#")
print("")
|
while True:
(H, W) = [int(i) for i in input().split()]
if H == W == 0:
break
print ("\n".join(["".join(["#" if i == 0 or i == W - 1 or j == 0 or j == H - 1 else "." for i in range(W)]) for j in range(H)]))
print()
| 1 | 806,839,623,522 | null | 50 | 50 |
s,t = input().split()
a,b = map(int,input().split())
u = input()
print(a if u == t else a-1, end = " ")
print(b-1 if u == t else b)
|
import sys
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))
ss, st = ins().split()
a, b = inm()
su = ins()
def solve():
if su == ss:
return (a - 1), b
else:
return a, (b - 1)
print(*solve())
| 1 | 71,963,121,120,150 | null | 220 | 220 |
def main():
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
if A[i] % 2 == 0 and (A[i] % 3 != 0 and A[i] % 5 != 0):
return "DENIED"
return "APPROVED"
if __name__ == '__main__':
print(main())
|
n = int(input())
a = list(map(int, input().split()))
ch = 0
for i in range(n):
if a[i] % 2 == 0:
if a[i] % 3 != 0 and a[i] % 5 != 0:
ch = 1
if ch == 0:
ans = 'APPROVED'
else:
ans = 'DENIED'
print(ans)
| 1 | 68,973,645,820,800 | null | 217 | 217 |
import collections
#https://note.nkmk.me/python-prime-factorization/
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
def f(n):
for i in range(1,20):
if n<(i*(i+1))//2:
return i-1
n = int(input())
c = collections.Counter(prime_factorize(n))
ans = 0
for i in c.keys():
ans += f(c[i])
print(ans)
|
n = 0
while True:
x = input()
if x==0:
break
n+=1
print 'Case %d: %d' %(n, x)
| 0 | null | 8,610,286,838,020 | 136 | 42 |
import numpy as np
def min_steps_v2(n, a, b):
n = np.int64(n)
a = np.int64(a)
b = np.int64(b)
if (b - a) % 2 == 0:
return np.int64(int(b - a) // 2)
# odd case
a_diff = a - 1
b_diff = n - b
if a_diff > b_diff:
steps_to_even = n - b + 1
remain_steps = min_steps_v2(n, a + (n - b) + 1, n)
else:
steps_to_even = a
remain_steps = min_steps_v2(n, 1, b - a)
return steps_to_even + remain_steps
numbers = input().split(' ')
n = int(numbers[0])
a = int(numbers[1])
b = int(numbers[2])
print(min_steps_v2(n, a, b))
|
N = int(input())
X = list(map(int, input().split()))
al = []
for i in range(100):
d = 0
p = i+1
for j in range(N):
d += (X[j]-p)**2
al.append(d)
print(min(al))
| 0 | null | 87,151,262,679,998 | 253 | 213 |
import math
N = int(input())
ans = math.inf
for i in range(1, math.ceil(math.sqrt(N)) + 1):
if N%i == 0:
ans = i+N//i-2
print(ans)
|
n = int(input())
x = int(n**(1/2))+1
for i in range(1, x+1):
if n%i == 0:
p = i
q = n//i
print(p+q-2)
| 1 | 161,052,938,453,092 | null | 288 | 288 |
import math
import string
def readints():
return list(map(int, input().split()))
def nCr(n, r):
return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))
def has_duplicates2(seq):
seen = []
for item in seq:
if not(item in seen):
seen.append(item)
return len(seq) != len(seen)
def divisor(n):
divisor = []
for i in range(1, n+1):
if n % i == 0:
divisor.append(i)
return divisor
l = [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 = int(input())
print(l[k-1])
|
li = '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'
li = list(map(int, li.split(',')))
k = int(input())
print(li[k - 1])
| 1 | 50,199,689,027,990 | null | 195 | 195 |
#!/usr/bin/env python3
import sys
input = iter(sys.stdin.read().splitlines()).__next__
D, T, S = map(int, input().split())
print('Yes' if D <= T*S else 'No')
|
import numpy as np
N = int(input())
A = list(map(int, input().split()))
A = np.argsort(A)
for a in A:
print(a+1, end=" ")
| 0 | null | 92,162,714,113,820 | 81 | 299 |
import sys
for line in sys.stdin:
if len(line)>1:
x1, y1, x2, y2 = line.strip('\n').split()
x1, y1, x2, y2 = float(x1), float(y1), float(x2), float(y2)
print ((x1-x2)**2+(y1-y2)**2)**0.5
|
N=int(input())
result=N/2
if N%2 != 0:
result+=0.5
print(int(result))
| 0 | null | 29,644,332,600,632 | 29 | 206 |
str1 = input()
str2 = input()
idx = 0
cnt = 0
for _ in range(len(str1)):
if str1[idx] != str2[idx]:
cnt += 1
idx += 1
print(cnt)
|
S, T = input(), input()
print(sum(x != y for x, y in zip(S, T)))
| 1 | 10,419,430,436,688 | null | 116 | 116 |
mod = 10**9+7
def cmb(x, y):
ret = 1
for i in range(1, y+1):
ret = (ret * (x+1-i)) % mod
ret = (ret * pow(i, mod-2, mod)) % mod
return ret
n,a,b = map(int,input().split())
ans = (pow(2,n,mod) - 1 - cmb(n,a) - cmb(n,b)) % mod
print(ans)
|
n, a, b = map(int, input().split())
mod = 10**9+7
ans = pow(2, n, mod)-1
nCa = 1
nCb = 1
for i in range(b):
nCb *= (n-i)
nCb %= mod
nCb *= pow(i+1, mod-2, mod)
if i == a-1:
nCa = nCb
ans -= nCa
ans %= mod
ans -= nCb
ans %= mod
print(ans)
| 1 | 66,192,758,965,412 | null | 214 | 214 |
n = int(input())
a_list = list(map(int, input().split()))
ans_list =[0]*n
for i in range(n):
ans_list[a_list[i]-1] = i+1
print(*ans_list)
|
N = int(input())
A = list(map(int,input().split()))
B = [[A[i],i+1]for i in range(N)]
B.sort()
ans = [B[i][1]for i in range(N)]
print(" ".join(map(str,ans)))
| 1 | 180,428,090,937,538 | null | 299 | 299 |
#!/usr/bin/env python
#-*- coding: utf-8 -*-
class Queue:
def __init__(self):
self.l = []
def enqueue(self, x):
self.l.append(x)
def dequeue(self):
x = self.l[0]
del self.l[0]
return x
def is_empty(self):
return len(self.l) == 0
class Process:
def __init__(self, name, time):
self.name = name
self.time = time
if __name__ == '__main__':
n, q = map(int, raw_input().split())
Q = Queue()
i = 0
while i != n:
tmp = raw_input().split()
Q.enqueue(Process(tmp[0], int(tmp[1])))
i += 1
cnt = 0
while not Q.is_empty():
p = Q.dequeue()
if p.time > q:
p.time -= q
cnt += q
Q.enqueue(p)
else:
cnt += p.time
print p.name, cnt
|
#!python3
import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
def _cmb(N, mod):
N1 = N + 1
fact = [1] * N1
inv = [1] * N1
for i in range(2, N1):
fact[i] = fact[i-1] * i % mod
inv[N] = pow(fact[N], mod-2, mod)
for i in range(N-1, 1, -1):
inv[i] = inv[i+1]*(i+1) % mod
def cmb(a, b):
return fact[a] * inv[b] * inv[a-b] % mod
return cmb
def resolve():
K = int(input())
s = input()
ls = len(s) - 1
mod = 10**9+7
cmb = _cmb(ls+K, mod)
ans = 0
for i in range(K+1):
ans += cmb(ls+i, ls) * pow(25, i, mod) * pow(26, K - i, mod)
ans %= mod
print(ans)
if __name__ == "__main__":
resolve()
| 0 | null | 6,426,992,118,900 | 19 | 124 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
H,W,K = map(int, readline().split())
S = [list(map(int, readline().strip())) for j in range(H)]
white = 0
for line in S:
white += sum(line)
if white <= K:
print(0)
exit()
# 横線の決め方を全探索
ans = 10**5
#yに横線Patternごとの列合計を作成
#入力例1のPattern[bin(2)]場合、y=[[1,1,1,0,0], [1,0,1,1,2]]
for pattern in range(2**(H-1)):
# 初期化
impossible = False
x = 0
ly = bin(pattern).count("1")
y = [S[0]]
line = 0
for i in range(1,H):
if (pattern >> i-1) & 1:
line += 1
y.append(S[i])
else:
y[line] = [y[line][j] + S[i][j] for j in range(W)]
# 各列の値を加算していく
count = [0]*(ly + 1)
for j in range(W):
for i in range(line+1):
if y[i][j] > K :
impossible = True
break
count[i] += y[i][j]
#print("横Pattern{} 縦列まで {} カウント数{} 縦線の数{}".format(i, j, count[i], x))
#横Patten毎にj列までのホワイトチョコ合計数をカウント、
#カウント>Kとなったら、縦線数を+1、その列値でカウント数を初期化
if count[i] > K:
x += 1
for i in range(line+1):
count[i] = y[i][j]
break
#x縦線の数 + ly横線の数がAnsより大きくなったらBreak
if x + ly > ans or impossible:
impossible = True
break
if impossible:
x = 10**6
#x縦線の数 + ly横線の数がAnsより小さくなったらAnsを更新
ans = min(ans, x + ly)
print(ans)
main()
|
# 各行の所属するグループを配列として持たせる実装。列ごと見ていってダメなら垂直線追加していく
H, W, K = map(int, input().split())
S = [input() for _ in range(H)]
ans = 10**9
for bit in range((1 << (H-1))):
vidx = []
gok = True
g = 0
gid = [0] * H
for i in range(H-1):
if (bit >> i) & 1:
g += 1
gid[i+1] = g
g += 1
gnum = [0]*g
vertical = 0
for w in range(W):
ok = True
one = [0]*g
for h in range(H):
one[gid[h]] += int(S[h][w])
gnum[gid[h]] += int(S[h][w])
if one[gid[h]] > K:
gok = False
if gnum[gid[h]] > K:
ok = False
if not ok:
vertical += 1
vidx.append(w)
gnum = one
# if bit == 2:
# print('aaaaa')
# print(gid)
# print(vidx)
# print(bin(bit), g-1, vertical)
# print('aaaaa')
if gok:
if ans > g-1 + vertical:
ans = g-1 + vertical
# print(bin(bit), g-1, vertical)
# print(vidx)
# print(ans)
# ans = min(ans, g-1 + vertical)
if ans == 10**9:
print(-1)
else:
print(ans)
| 1 | 48,838,585,647,008 | null | 193 | 193 |
import math
R=int(input())
cir=2*math.pi*R
print(cir)
|
r = int(input())
print(r * 3.14159265 * 2);
| 1 | 31,399,023,596,412 | null | 167 | 167 |
w = input().lower()
cnt = 0
while True:
l = input()
if l == 'END_OF_TEXT':
break
for e in l.split():
cnt += e.lower() == w
print(cnt)
|
N = int(raw_input())
num_list = map(int, raw_input().split())
c = 0
for i in range(0,N,1):
flag =0
minj =i
for j in range(i,N,1):
if num_list[j] < num_list[minj]:
minj = j
flag = 1
c += flag
num_list[i], num_list[minj] = num_list[minj], num_list[i]
print " ".join(map(str,num_list))
print c
| 0 | null | 935,652,773,718 | 65 | 15 |
import sys
a=[]
for i in sys.stdin:
a.append(map(int,i.split()))
for i in a:
print(str(len(str(i[0]+i[1]))))
|
import sys
def solve():
a = []
for line in sys.stdin:
digit_list = line.split(' ')
new_list = []
for s in digit_list:
new_list.append(int(s))
a.append((new_list))
for j in a:
print str(len(str(sum(j))))
if __name__ == '__main__':
solve()
| 1 | 88,870,890 | null | 3 | 3 |
s,w = map(int, input().split())
ans = ['unsafe' if w >= s else 'safe']
print(ans[0])
|
import math
a, b, h, m = map(int, input().split())
omg_s = math.pi / 360
omg_l = math.pi / 30
tht = (60*h + m)*omg_s - m*omg_l
c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(tht))
print(c)
| 0 | null | 24,682,719,378,990 | 163 | 144 |
import sys
import fractions
import re
def lcm(a, b):
return a / fractions.gcd(a, b) * b
#input_file = open(sys.argv[1], "r")
#for line in input_file:
for line in sys.stdin:
ab = map(int, re.split(" +", line))
a, b = tuple(ab)
gcd_ab = fractions.gcd(a, b)
lcm_ab = lcm(a, b)
print gcd_ab, lcm_ab
|
import sys
for l in sys.stdin:
x,y=map(int, l.split())
m=x*y
while x%y:x,y=y,x%y
print "%d %d"%(y,m/y)
| 1 | 668,849,740 | null | 5 | 5 |
import sys
input = sys.stdin.readline
mod = 1000000007
N = int(input())
AA = list(map(int, input().split()))
num = [0,0,0]
ans = 1
for i in AA:
f = False
cnt = 0
for j in range(3):
if(num[j] == i):
if f==False :
num[j] += 1
f=True
cnt += 1
ans = (ans * cnt) % mod
print(ans)
|
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
color = [0]*3
ans = 1
for i in range(N):
if A[i] not in color:
ans = 0
break
ind = color.index(A[i])
ans *= len([c for c in color if c == A[i]])
ans %= mod
color[ind] += 1
#ans = rec(color,0)
print(ans)
| 1 | 130,371,332,263,340 | null | 268 | 268 |
def solve():
N = int(input())
dfs("", 0, N)
def dfs(cur, n_type, N):
if len(cur) == N:
print(cur)
return
for offset in range(n_type+1):
next_chr = chr(ord('a') + offset)
next_n_type = n_type + 1 if offset==n_type else n_type
dfs(cur+next_chr, next_n_type, N)
return
if __name__ == '__main__':
solve()
|
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')
x = int(input())
print(int(x!=1))
| 0 | null | 27,842,682,383,172 | 198 | 76 |
x = range(1,10)
for i in x:
for j in x:
print u"%dx%d=%d"%(i, j, i*j)
|
N = int(input())
S = str(input())
count = 1
for i in range(N-1):
if S[i]!=S[i+1]:
count += 1
print(count)
| 0 | null | 84,957,691,560,004 | 1 | 293 |
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
n,m = inpm()
way = [[] for _ in range(n+1)]
for i in range(m):
a,b = inpm()
way[a].append(b)
way[b].append(a)
ans = [0 for i in range(n+1)]
q = queue.Queue()
q.put((1,0))
while not q.empty():
room,sign = q.get()
if ans[room] != 0:
continue
ans[room] = sign
for i in way[room]:
q.put((i,room))
print('Yes')
for i in range(2,n+1):
print(ans[i])
|
H, W = map(int, input().split(' '))
s = []
for _ in range(H):
s.append(input())
dp = [[10 ** 9 for i in range(W)] for j in range(H)]
dp[0][0] = 0 if s[0][0] == '.' else 1
for i in range(H):
for j in range(W):
if i + 1 < H:
cost = int(s[i][j] == '.' and s[i + 1][j] == '#')
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + cost)
if j + 1 < W:
cost = int(s[i][j] == '.' and s[i][j + 1] == '#')
dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + cost)
print(dp[H - 1][W - 1])
| 0 | null | 34,818,742,381,120 | 145 | 194 |
K = int(input())
A, B = map(int, input().split())
for i in range(1000):
C = K * i
if A <= C and C <= B:
print('OK')
exit()
print('NG')
|
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')
| 1 | 26,598,897,735,930 | null | 158 | 158 |
x, n = map(int, input().split())
li_p = list(map(int, input().split()))
li_p.sort()
i = 0
while True:
a = x - i
b = x + i
if not a in li_p:
print(a)
break
elif a in li_p and not b in li_p:
print(b)
break
elif a in li_p and b in li_p:
i += 1
|
import sys
sys.setrecursionlimit(2147483647)
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()
class modfact(object):
def __init__(self, n):
fact, invfact = [1] * (n + 1), [1] * (n + 1)
for i in range(1, n + 1): fact[i] = i * fact[i - 1] % MOD
invfact[n] = pow(fact[n], MOD - 2, MOD)
for i in range(n - 1, -1, -1): invfact[i] = invfact[i + 1] * (i + 1) % MOD
self._fact, self._invfact = fact, invfact
def inv(self, n):
return self._fact[n - 1] * self._invfact[n] % MOD
def fact(self, n):
return self._fact[n]
def invfact(self, n):
return self._invfact[n]
def comb(self, n, k):
if k < 0 or n < k: return 0
return self._fact[n] * self._invfact[k] % MOD * self._invfact[n - k] % MOD
def perm(self, n, k):
if k < 0 or n < k: return 0
return self._fact[n] * self._invfact[n - k] % MOD
def resolve():
n, k = map(int, input().split())
mf = modfact(n)
res = 0
for i in range(min(k + 1, n)):
res += mf.comb(n, i) * mf.comb(n - 1, i) % MOD
res %= MOD
print(res)
resolve()
| 0 | null | 40,733,286,761,306 | 128 | 215 |
s=list(input())
t=[]
for i in range(3):
t.append(s[i])
r=''.join(t)
print(r)
|
s = input()
print(s[:3].lower())
| 1 | 14,745,517,499,108 | null | 130 | 130 |
from math import ceil
def main():
N, K = map(int, input().split())
A = list(map(int, input().split()))
def check(Min):
kill = 0
for a in A:
kill += (ceil(a/Min)-1)
return kill <= K
l = 0
r = 1000000000
while r-l > 1:
mid = (l+r)//2
if check(mid):
r = mid
else:
l = mid
print(r)
if __name__ == '__main__':
main()
|
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
NG=0
OK=max(A)+1
while OK-NG>1:
mid = (OK+NG)//2
cur=0
for x in A:
cur += (x-1)//mid
if cur > K:
NG=mid
else:
OK=mid
print(OK)
| 1 | 6,495,794,792,026 | null | 99 | 99 |
n, m, l = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [list(map(int, input().split())) for _ in range(m)]
for i in a:
c = []
for j in zip(*b):
c.append(sum([k * l for k, l in zip(i, j)]))
print(*c)
|
n,m,l=map(int, input().split())
a=[]
b=[]
for i in range(n):
a.append(list(map(int, input().split())))
for j in range(m):
b.append(list(map(int, input().split())))
for i in range(n):
ci=[0]*l
for k in range(l):
for j in range(m):
ci[k]+=a[i][j]*b[j][k]
print(*ci)
| 1 | 1,435,540,154,568 | null | 60 | 60 |
#A
x = input()
if x.isupper() ==True:
print('A')
else:
print('a')
|
X = input()
if X.isupper():
print("A")
else:
print("a")
| 1 | 11,264,307,780,608 | null | 119 | 119 |
n = int(input())
if n == 1:
print(0)
exit()
def is_prime(n):
if n <= 1: return False
for i in range(2, int(n**0.5) + 1):
if n%i == 0: return False
return True
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n%i == 0:
divisors.append(i)
if i!=n//i:
divisors.append(n//i)
divisors.sort()
return divisors
ans = []
cnt = 0
X = make_divisors(n)[1:]
for x in X:
if is_prime(x):
ans.append(x)
n //= x
cnt += 1
e = 2
while x**e < n:
ans.append(x**e)
e += 1
elif x in ans:
if n%x == 0:
n //= x
cnt += 1
print(cnt)
|
n=int(input())
factors=[]
i=2
def checker(power):
l=1
r=20
ans=1
while l<=r:
mid=l+(r-l)//2
if mid*(mid+1)/2<=power:
ans=mid
l=mid+1
else:
r=mid-1
return ans
while i**2<=n:
if n%i==0:
cnt=0
while n%i==0:
n/=i
cnt+=1
factors.append([i,cnt])
i+=1
if n>1:
factors.append([n,1])
res=0
rem=0
for i in range(len(factors)):
a=checker(factors[i][1])
res+=a
factors[i][1]-=a
rem+=factors[i][1]
'''if rem>1:
res+=rem*(rem-1)/2'''
#print(factors)
print(int(res))
| 1 | 16,893,559,744,908 | null | 136 | 136 |
N = int(input())
a = list(map(int,input().split()))
aset = set(a)
if 1 not in aset:
print(-1)
else:
nex = 1
counter = 0
for i in range(N):
if a[i] == nex:
nex += 1
else:
counter += 1
print(counter)
|
import sys
from io import StringIO
import unittest
import os
# 実装を行う関数
def resolve():
# 数値取得サンプル
# 1行N項目 x, y = map(int, input().split())
# N行N項目 x = [list(map(int, input().split())) for i in range(n)]
n = int(input())
bricks = list(map(int, input().split()))
# 1が無ければ-1
if 1 not in bricks:
print(-1)
return
num = 1
ban = 0
for brick in bricks:
if brick == num:
num += 1
continue
ban += 1
# dev
1 == 1
print(ban)
# 文字取得サンプル
# 1行1項目 x = input()
pass
# テストクラス
class TestClass(unittest.TestCase):
def assertIO(self, assert_input, output):
stdout, sat_in = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, sat_in
self.assertEqual(out, output)
def test_input_1(self):
test_input = """3
2 1 2"""
output = """1"""
self.assertIO(test_input, output)
def test_input_2(self):
test_input = """3
2 2 2"""
output = """-1"""
self.assertIO(test_input, output)
def test_input_3(self):
test_input = """10
3 1 4 1 5 9 2 6 5 3"""
output = """7"""
self.assertIO(test_input, output)
def test_input_4(self):
test_input = """1
1"""
output = """0"""
self.assertIO(test_input, output)
# 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
def tes_t_1original_1(self):
test_input = """データ"""
output = """データ"""
self.assertIO(test_input, output)
# 実装orテストの呼び出し
if __name__ == "__main__":
if os.environ.get("USERNAME") is None:
# AtCoder提出時の場合
resolve()
else:
# 自PCの場合
unittest.main()
| 1 | 114,235,626,644,696 | null | 257 | 257 |
n,m=map(int,input().split())
#Union-Find木
#par[i]:iの親 deep[i]:iの深さ size[i]:iの大きさ
par=[i for i in range(n)]
deep=[1]*n
size=[1]*n
#親を見つける
def find(x):
if par[x]==x:
return x
else:
return find(par[x])
#二つのグループを統合する
def unite(x,y):
x=find(x)
y=find(y)
if x==y:
return
if deep[x]<deep[y]:
par[x]=y
size[y]+=size[x]
else:
par[y]=x
size[x]+=size[y]
if deep[x]==deep[y]:
deep[x]+=1
#xとyが同じグループに属するかどうか
def same(x,y):
return find(x)==find(y)
#xが属するグループの要素数を返す
def group_count(x):
return size[find(x)]
#連結成分の個数を返す
def count():
check=set()
for i in range(n):
parent=find(i)
if parent not in check:
check.add(parent)
return len(check)
for i in range(m):
a,b=map(int,input().split())
unite(a-1,b-1)
s=count()
print(s-1)
|
a = [int(s) for s in input().split()]
b = int(a[0] // (a[1] + a[2]))
c = int(a[0] % (a[1] + a[2]))
d = b * a[1]
if c >= a[1]:
d = d + a[1]
else:
d = d + c
print(d)
| 0 | null | 28,846,502,045,030 | 70 | 202 |
n,*a=map(int,open(0).read().split())
dp=[0]*(n+1)
dp[0]=1
for i,x in enumerate(a):
if dp[i]<x:
print(-1)
exit()
if i<n:
dp[i+1]=(dp[i]-x)*2
dp[-1]=a[-1]
for i in range(n,0,-1):
if dp[i-1]>a[i-1]+dp[i]:
dp[i-1]=a[i-1]+dp[i]
print(sum(dp))
|
# -*- coding:utf-8
def main():
N = int(input())
A = list(map(int, input().split()))
insertionSort(A, N)
print(' '.join(map(str, A)))
def insertionSort(A, N):
for i in range(1, N):
print(' '.join(map(str, A)))
v = A[i]
j = i-1
while(j>=0 and A[j]>v):
A[j+1] = A[j]
j -= 1
A[j+1] = v
if __name__ == '__main__':
main()
| 0 | null | 9,527,991,744,990 | 141 | 10 |
s=input()
print('Yes' if len(set(s))>1 else 'No')
|
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0]+list(accumulate(lst))
def celi(a,b):
return -(-a//b)
sys.setrecursionlimit(5000000)
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())
a=list(map(int,input().split()))
lst=[0]*n
for i in range(n-1):
lst[a[i]-1]+=1
print(*lst)
| 0 | null | 43,663,672,625,668 | 201 | 169 |
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import sin, cos, tan, asin, acos, atan, degrees, radians
sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7
def lcm(x,y):
return x*y//gcd(x,y)
def lgcd(l):
return reduce(gcd,l)
def llcm(l):
return reduce(lcm,l)
def powmod(n,i,mod):
return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
return x.bit_length()
def div10(x):
return len(str(x))-(x==0)
def perm(n,mod=None):
ans = 1
for i in range(1,n+1):
ans *= i
if mod!=None:
ans %= mod
return ans
def intput():
return int(input())
def mint():
return map(int,input().split())
def lint():
return list(map(int,input().split()))
def ilint():
return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
print(l[0] if x else l[1])
def lprint(l, sep='\n'):
for x in l:
print(x, end=sep)
def ston(c, c0='a'):
return ord(c)-ord(c0)
def ntos(x, c0='a'):
return chr(x+ord(c0))
class counter(dict):
def __init__(self, *args):
super().__init__(args)
def add(self,x,d=1):
self.setdefault(x,0)
self[x] += d
class comb():
def __init__(self, n, mod=None):
self.l = [1]
self.n = n
self.mod = mod
def get(self,k):
l,n,mod = self.l, self.n, self.mod
k = n-k if k>n//2 else k
while len(l)<=k:
i = len(l)
l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
return l[k]
H,W=mint()
s=[input() for _ in range(H)]
dp=[[0]*W for _ in range(H)]
dp[0][0]=int(s[0][0]=='#')
for i in range(H):
for j in range(W):
if i==j==0:
continue
tmp = INF
if i>0:
tmp = min(tmp,dp[i-1][j]+int(s[i-1][j]=='.' and s[i][j]=='#'))
if j>0:
tmp = min(tmp,dp[i][j-1]+int(s[i][j-1]=='.' and s[i][j]=='#'))
dp[i][j] = tmp
print(dp[H-1][W-1])
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def main():
for lhs in range(1,9+1):
for rhs in range(1,9+1):
print("{}x{}={}".format(lhs, rhs, lhs*rhs))
if __name__ == "__main__": main()
| 0 | null | 24,454,657,587,692 | 194 | 1 |
def main():
N = int(input())
S = input()
fusion = [S[0]]
prev = S[0]
for s in S[1:]:
if s == prev:
continue
fusion.append(s)
prev = s
print(len(fusion))
main()
|
# -*- coding: utf-8 -*-
n = int(input())
s = input()
ans = 1
tmp = s[0]
for c in s:
if tmp != c:
ans += 1
tmp = c
print(ans)
| 1 | 170,101,178,587,428 | null | 293 | 293 |
import math
a, b, x = list(map(int, input().split()))
if x/a < a*b/2:
print(math.atan(a*b*b/(2*x))*180/math.pi)
else:
print(math.atan(2/a * (b-x/a**2))*180/math.pi)
|
n, m = map(int, input().split())
if 2*m>=n:
print(0)
else:
print(n-2*m)
| 0 | null | 165,535,165,548,678 | 289 | 291 |
n = int(input())
l = list(map(int,input().split()))+[0]
l.sort(reverse=True)
ans = 0
for i in range(n-2):
for j in range(i+1,n-1):
left = j
right = n
while right - left > 1:
middle = (left + right)//2
if l[i]-l[j] < l[middle]:
left = middle
else:
right = middle
ans += (left-j)
print(ans)
|
import bisect
import sys
sys.setrecursionlimit(10**9)
def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))
INF=10**20
def main():
N=ii()
L=list(mi())
ans = 0
L.sort()
for ai in range(N):
for bi in range(ai+1,N):
a,b = L[ai],L[bi]
left = bisect.bisect_left(L,abs(a-b)+1)
right = bisect.bisect_right(L,a+b-1)
count = right - left
if left <= ai <= right:
count -= 1
if left <= bi <= right:
count -= 1
ans += count
# if count > 0:
# print(a,b,count)
print(ans//3)
if __name__ == "__main__":
main()
| 1 | 171,141,632,745,190 | null | 294 | 294 |
N,M = map(int,input().split())
H = list(map(int,input().split()))
H.insert(0,0)
S = set()
for m in range(M):
A,B = map(int,input().split())
if H[A]<=H[B]:
S.add(A)
if H[A]>=H[B]:
S.add(B)
print(N-len(S))
|
N = int(input())
xy = [[] for i in range(N)]
for i in range(N):
A = int(input())
for j in range(A):
x, y = map(int, input().split())
xy[i].append([x, y])
ans = 0
for i in range(2**N):
b = format(i, "0" + str(N) + "b")
t = 0
f = 0
for j in range(N):
if b[j] == "1":
t += 1
for k in xy[j]:
if str(k[1]) != b[k[0]-1]:
f = 1
break
if f == 0:
ans = max(ans, t)
#print(b)
print(ans)
| 0 | null | 73,379,883,832,420 | 155 | 262 |
n=int(input())
a=list(map(int,input().split()))
c=a[0]
for i in range(1,n):
c=c^a[i]
for i in range(n):
print(c^a[i])
|
# -*- coding: utf-8 -*-
def main():
Num = input().split()
area = int(Num[0]) * int(Num[1])
sur = 2 * (int(Num[0])+int(Num[1]))
print(area, sur)
if __name__ == '__main__':
main()
| 0 | null | 6,393,050,642,034 | 123 | 36 |
import math, cmath
def koch(p1, p2, n):
if n == 0:
return [p1, p2]
rad60 = math.pi/3
v1 = (p2 - p1)/3
v2 = cmath.rect(abs(v1), cmath.phase(v1)+rad60)
q1 = p1 + v1
q2 = q1 + v2
q3 = q1 + v1
if n == 1:
return [p1,q1,q2,q3,p2]
else:
x1 = koch(p1,q1,n-1)[1:-1]
x2 = koch(q1,q2,n-1)[1:-1]
x3 = koch(q2,q3,n-1)[1:-1]
x4 = koch(q3,p2,n-1)[1:-1]
x = [p1]+x1+[q1]+x2+[q2]+x3+[q3]+x4+[p2]
return x
n = int(raw_input())
p1 = complex(0,0)
p2 = complex(100,0)
for e in koch(p1,p2,n):
print e.real,e.imag
|
import sys
input = sys.stdin.readline
from itertools import accumulate
N, K = map(int, input().split())
A = map(int, input().split())
B = accumulate(A)
C = [0]+[(b-i)%K for i, b in enumerate(B,start=1)]
cnt = dict()
cnt[C[0]] = 1
res = 0
for i in range(1, N+1):
if i >= K:
cnt[C[i-K]] = cnt.get(C[i-K],0) - 1
res += cnt.get(C[i], 0)
cnt[C[i]] = cnt.get(C[i],0) + 1
print(res)
| 0 | null | 68,690,877,730,280 | 27 | 273 |
s = input()
if s[1] == 'B':
print("ARC")
else:
print("ABC")
|
N = int(input())
R = []
for _ in range(N):
X, L = map(int, input().split())
R.append([X-L, X+L])
R = sorted(R, key=lambda x: x[1])
ans = 1
p = R[0][1]
for i in range(1, N):
if p <= R[i][0]:
ans += 1
p = R[i][1]
print(ans)
| 0 | null | 56,932,626,820,580 | 153 | 237 |
def ans():
if t==0:
return "N0"
if d/s <= t:
return "Yes"
else:
return "No"
d, t, s = map(int, input().split())
print(ans())
|
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)]
print(*S,sep="")
"""
import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()
inf = float("inf") # 無限
a,b = map(int,input().split())
if 0<a<10 and 0<b<10:
print(a*b)
else:
print(-1)
| 0 | null | 81,158,786,538,060 | 81 | 286 |
import math
def cmb(n, r, mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 10**5+5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
N,K = list(map(int,input().split()))
A = sorted(tuple(map(int,input().split())))
B = tuple(A[i+1]-A[i] for i in range(len(A)-1))
lim = math.ceil(len(B)/2)
L = 10**9+7
ans = 0
multi = cmb(N,K,mod)
for j in range(lim):
front = j + 1
back = N - front
tmp_b = 0
tmp_f = 0
if front >= K:
tmp_f = cmb(front,K,mod)
if back >= K:
tmp_b = cmb(back,K,mod)
if j == (len(B)-1)/2:
ans += (multi - tmp_b - tmp_f)*(B[j]) % L
else:
ans += (multi - tmp_b - tmp_f)*(B[j]+B[len(B)-1-j]) % L
print(ans%L)
|
def main():
n, k = map(int, input().split())
a = sorted(int(i) for i in input().split())
mod = 10**9 + 7
comb = [1] * (n - k + 1)
for i in range(n - k):
comb[i + 1] = (comb[i] * (k + i) * pow(i + 1, mod - 2, mod)) % mod
f = 0
for i in range(n - k + 1):
f = (f + a[k + i - 1] * comb[i] % mod) % mod
f = (f - a[i] * comb[-1 - i] % mod) % mod
print(f)
if __name__ == '__main__':
main()
| 1 | 95,759,983,458,480 | null | 242 | 242 |
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools as fts
import itertools as its
import math
import sys
INF = float('inf')
def solve(S: str, T: str):
return len(T) - max(sum(s == t for s, t in zip(S[i:], T)) for i in range(len(S) - len(T) + 1))
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
S = next(tokens) # type: str
T = next(tokens) # type: str
print(f'{solve(S, T)}')
if __name__ == '__main__':
main()
|
def main():
A, B = map(int, input().split())
print(A * B)
if __name__ == '__main__':
main()
| 0 | null | 9,827,635,027,200 | 82 | 133 |
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT() : return int(input())
def MAP() : return map(int,input().split())
def MAP1() : return map(lambda x:int(x)-1,input().split())
def LIST() : return list(MAP())
def LIST1() : return list(MAP1())
def solve():
N = INT()
a = []
b = []
for i in range(N):
A, B = MAP()
a.append(A)
b.append(B)
a.sort()
b.sort()
if N % 2 == 1:
am = a[(N+1)//2-1]
bm = b[(N+1)//2-1]
ans = bm - am + 1
else:
am = ( a[N//2-1]+a[N//2] ) / 2
bm = ( b[N//2-1]+b[N//2] ) / 2
ans = int( ( bm - am ) * 2 + 1 )
print(ans)
if __name__ == '__main__':
solve()
|
k = int(input())
s = input()
mod = 10**9 + 7
ans = 0
class Combination:
"""
O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる
n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
使用例:
comb = Combination(1000000)
print(comb(5, 3)) # 10
"""
def __init__(self, n_max, mod=10**9+7):
self.mod = mod
self.modinv = self.make_modinv_list(n_max)
self.fac, self.facinv = self.make_factorial_list(n_max)
def __call__(self, n, r):
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
def make_factorial_list(self, n):
# 階乗のリストと階乗のmod逆元のリストを返す O(n)
# self.make_modinv_list()が先に実行されている必要がある
fac = [1]
facinv = [1]
for i in range(1, n+1):
fac.append(fac[i-1] * i % self.mod)
facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
return fac, facinv
def make_modinv_list(self, n):
# 0からnまでのmod逆元のリストを返す O(n)
modinv = [0] * (n+1)
modinv[1] = 1
for i in range(2, n+1):
modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
return modinv
comb = Combination(2*10**6+10)
for i in range(k+1):
ans += pow(25, k-i, mod) * pow(26, i, mod) * comb(len(s)+k-i-1, len(s)-1)
ans %= mod
print(ans)
| 0 | null | 15,050,796,333,808 | 137 | 124 |
import math
while True:
try:
n=input()
x=100000
for i in xrange(n):
x=math.ceil(x*1.05/1000)*1000
print(int(x))
except EOFError: break
|
n=int(input())
syakkin=100000
for i in range(n):
syakkin+=syakkin*0.05
if syakkin%1000!=0:
syakkin=(syakkin//1000)*1000+1000
print(int (syakkin))
| 1 | 916,703,580 | null | 6 | 6 |
n, k = map(int, input().split())
a = [int(s) for s in input().split()]
for i in range(k, n):
if a[i] > a[i - k]:
print('Yes')
else:
print('No')
|
n = int(input())
a = list(map(int, input().split()))
L = sum(a)
l = 0
i = 0
while l < L / 2:
l += a[i]
i += 1
print(min(abs(sum(a[:i - 1]) - sum(a[i - 1:])), abs(sum(a[:i]) - sum(a[i:]))))
| 0 | null | 74,482,523,899,744 | 102 | 276 |
A, B, C = input().split()
A = int(A)
B = int(B)
C = int(C)
A, B, C = B, A, C
B, A, C = C, A, B
C, A, B = A, B, C
print(A, B, C)
|
a = int(input().rstrip())
print(a*(1+a*(1+a)))
| 0 | null | 24,262,201,188,850 | 178 | 115 |
import networkx as nx
H, W = map(int, input().split())
maze = [input() for _ in range(H)]
G = nx.grid_2d_graph(H, W)
for h in range(H):
for w in range(W):
# 壁に入る辺を削除
if maze[h][w] == '#':
for dh, dw in ((1, 0), (0, 1), (-1, 0), (0, -1)):
if ((h - dh, w - dw), (h, w)) in G.edges():
G.remove_edge((h - dh, w - dw), (h, w))
def bfs(sy, sx):
d = dict()
d[(sy, sx)] = 0
for coordinate_from, coordinate_to in nx.bfs_edges(G, (sy, sx)):
d[coordinate_to] = d[coordinate_from] + 1
return max(d.values())
ans = 0
for y in range(H):
for x in range(W):
if maze[y][x] == '.':
ans = max(ans, bfs(y, x))
print(ans)
|
from collections import deque
def main():
H, W = map(int, input().split())
field = "#"*(W+2)
field += "#" + "##".join([input() for _ in range(H)]) + "#"
field += "#"*(W+2)
INF = 10**9
cost = [INF]*len(field)
move = [-1, 1, -(W+2), W+2]
def bfs(s, g):
q = deque()
dequeue = q.popleft
enqueue = q.append
cost[s] = 0
enqueue(s)
while q:
now = dequeue()
now_cost = cost[now]
for dx in move:
nv = now + dx
if nv == g:
cost[g] = now_cost + 1
return
if field[nv] == "#" or cost[nv] < INF:
continue
else:
cost[nv] = now_cost + 1
q.append(nv)
ans = 0
for si in range(H):
for sj in range(W):
for gi in range(H):
for gj in range(W):
start = (si+1)*(W+2)+sj+1
goal = (gi+1)*(W+2)+gj+1
if field[start] == "#" or field[goal] == "#" or start == goal:
continue
cost = [INF] * len(field)
bfs(start, goal)
ans = max(ans, cost[goal])
print(ans)
if __name__ == "__main__":
main()
| 1 | 94,373,567,460,688 | null | 241 | 241 |
while True:
ab = [int(x) for x in input().split()]
a, b = ab[0], ab[1]
if a == 0 and b == 0:
break
if a > b:
a, b = b, a
print("{0} {1}".format(a, b))
|
in_string = raw_input()
in_arr = in_string.split()
N = int(in_arr[0])
A = int(in_arr[1])
B = int(in_arr[2])
if ((B-A) % 2) == 0:
print(int((B-A)/2))
else:
if (N-B) > A-1:
print(int(A+(B-A-1)/2))
else:
print(int(N-B+1+((N-(A+N-B+1))/2)))
| 0 | null | 55,147,780,162,168 | 43 | 253 |
N = int(input())
kuku = []
for i in range(1, 10):
kuku += [i * j for j in range(1, 10)]
if N in kuku:
print("Yes")
else:
print("No")
|
N=int(input())
S=[]
T=[]
for i in range(N):
x,y=map(str,input().split())
S.append(x)
T.append(int(y))
X=str(input())
p=S.index(X)
print(sum(T[p+1:]))
| 0 | null | 128,887,448,977,580 | 287 | 243 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.