code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 6.82M
181,637B
⌀ | question_pair_id
float64 101M
180,471B
⌀ | code1_group
int64 2
299
| code2_group
int64 2
299
|
---|---|---|---|---|---|---|
X = int(input())
n = 100
year_count = 0
while n < X:
n += n // 100
year_count += 1
print(year_count)
| N = int(input())
X_list = list(map(int, input().split()))
X_list_min = sorted(X_list)
ans = 10**8+1
for i in range(X_list_min[0], X_list_min[-1]+1):
ans_temp = 0
for j in range(N):
ans_temp += (X_list_min[j] - i)**2
ans = min(ans, ans_temp)
print(ans) | 0 | null | 45,872,784,930,870 | 159 | 213 |
import math
from functools import reduce
K = int(input())
def gcd(*numbers):
return reduce(math.gcd, numbers)
out = 0
for a in range(1,K+1):
for b in range(1,K+1):
for c in range(1,K+1):
out += gcd(a,b,c)
print(out)
| h,w,k=map(int,input().split())
ans = 0
def get(sta):
ret = set()
for i in range(6):
if sta & 1:
ret.add(i)
sta //= 2
return ret
grd=[input() for i in range(h)]
for i in range(2**h):
hs=get(i)
for j in range(2**w):
ws=get(j)
chk = 0
for a in range(h):
for b in range(w):
if a in hs or b in ws or grd[a][b]==".":continue
chk += 1
if chk == k:
ans += 1
print(ans) | 0 | null | 22,115,253,419,040 | 174 | 110 |
#
# 179A
#
s = input()
s1 = list(s)
if s1[len(s)-1]=='s':
print(s+'es')
else:
print(s+'s') | inf=float("inf")
h,w=map(int,input().split())
s=[["#"]*(w+2) for i in range(h+2)]
for i in range(h):
s[i+1]=["#"]+list(input())+["#"]
#h,w=3,5
#s=[['#', '#', '#', '#', '#', '#', '#'], ['#', '.', '.', '.', '#', '.', '#'], ['#', '.', '#', '.', '#', '.', '#'], ['#', '.', '#', '.', '.', '.', '#'], ['#', '#', '#', '#', '#', '#', '#']]
nv=h*w
dp=[[inf]*nv for i in range(nv)]
def nhw(hi,wi):
return (hi-1)*w+wi-1
for i in range(1,h+1):
for j in range(1,w+1):
if s[i][j]=="#":
continue
vij=nhw(i,j)
if s[i-1][j]==".":
vij2=nhw(i-1,j)
dp[vij][vij2]=1
dp[vij2][vij]=1
if s[i+1][j]==".":
vij2=nhw(i+1,j)
dp[vij][vij2]=1
dp[vij2][vij]=1
if s[i][j-1]==".":
vij2=nhw(i,j-1)
dp[vij][vij2]=1
dp[vij2][vij]=1
if s[i][j+1]==".":
vij2=nhw(i,j+1)
dp[vij][vij2]=1
dp[vij2][vij]=1
for i in range(nv):
dp[i][i]=0
#print(dp)
for k in range(nv):
for i in range(nv):
for j in range(nv):
dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j])
# print(dp)
#print(dp)
dpmax=0
for i in range(nv):
for j in range(nv):
if dp[i][j]!=inf:
if dpmax<dp[i][j]:
dpmax=dp[i][j]
print(dpmax)
| 0 | null | 48,589,692,035,900 | 71 | 241 |
import sys
input = sys.stdin.readline
H, N = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
dp = [10**10]*(H+1)
dp[0] = 0
for i in range(H):
for ab in AB:
a,b = ab[0], ab[1]
idx = i+a if i+a < H else H
dp[idx] = min(dp[idx], dp[i]+b)
print(dp[H])
| A,B,C,D = map(int,input().split())
if -A//D<=-C//B:
print("Yes")
else:
print("No") | 0 | null | 55,656,515,173,900 | 229 | 164 |
N,K = map(int,input().split())
L = []
for _ in range(K):
l,r = map(int,input().split())
L.append((l,r))
DP = [0] * N
DP[0] = 1
con = [0] * (N + 1)
con[1] = 1
for i in range(1 , N):
s = 0
for l,r in L:
s += con[max(0 , i - l + 1)] - con[max(0 , i - r)]
DP[i] = s
con[i + 1] = (con[i] + DP[i]) % 998244353
print(DP[N - 1] % 998244353)
| N = int(input())
P = list(map(int, input().split()))
mn = N + 1
ans = 0
for p in P:
if p < mn:
ans += 1
mn = min(mn, p)
print(ans) | 0 | null | 44,033,111,529,098 | 74 | 233 |
N = int(input())
ans = 'No'
if N<=82:
for i in range(1,10):
if N%i==0 and len(str(N//i))==1:
ans = 'Yes'
print(ans)
| n=int(input())
for i in range(9):
for u in range(9):
if n==(i+1)*(u+1):
print('Yes')
exit()
print('No') | 1 | 159,892,410,486,692 | null | 287 | 287 |
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
@functools.lru_cache(None)
def aa(k):
if k > 1: return 2*aa(k//2) + 1
return 1
h = int(stdin.readline().rstrip())
print(aa(h)) | n,x,y=map(int,input().split())
#最短距離が1の時2の時、、、という風に実験しても途方に暮れるだけだった
#i,j固定して最短距離がどう表せるかを考える
def min_route_count(i,j):
return min(abs(j-i),abs(j-y)+1+abs(x-i))
ans_list=[0]*(n-1)
for i in range(1,n):
for j in range(i+1,n+1):
ans_list[min_route_count(i,j)-1]+=1
for t in range(n-1):
print(ans_list[t])
| 0 | null | 62,219,400,390,456 | 228 | 187 |
N = 10**7
# M = 10**5
# arr = list(range(M))
# def f(x):
# return x
for i in range(N):
pass
# 答え
a = int(input())
print(a + a**2 + a**3)
| k = int(input())
print(int(k+k**2+k**3)) | 1 | 10,245,427,486,448 | null | 115 | 115 |
S = str(input())
for i in range(int(input())):
L = input().split()
o = L[0]
a = int(L[1])
b = int(L[2]) + 1
if len(L) == 4:
p = L[3]
else:
p = 0
if o == "print":
print(S[a:b])
elif o == "reverse":
S = S[:a]+S[a:b][::-1]+S[b:]
elif o == "replace":
S = S[:a]+p+S[b:]
|
def main():
N, M, X = map(int,input().split())
cost = []
effect = []
for _ in range(N):
t = list(map(int,input().split()))
cost.append(t[0])
effect.append(t[1:])
res = float("inf")
for bits in range(1<<N):
f = True
total = 0
ans = [0] * M
for flag in range(N):
if (1<< flag) & (bits):
total += cost[flag]
for idx, e in enumerate(effect[flag]):
ans[idx] += e
for a in ans:
if a < X: f = False
if f:
res = min(res, total)
print(res if res != float("inf") else -1)
if __name__ == "__main__":
main()
| 0 | null | 12,076,125,019,200 | 68 | 149 |
(X1,X2,Y1,Y2)=list(map(int,input().split()))
ans=max(X2*Y2,X1*Y1,X1*Y2,X2*Y1)
print (ans) | n, m, k = map(int, input().split())
MOD = 998244353
ans = 0
c = 1
for i in range(k + 1):
ans = (ans + m * pow(m - 1, n - i - 1, MOD) * c) % MOD
c = (c * (n - 1 - i) * pow(i + 1, MOD - 2, MOD)) % MOD
# print(f"{ans = }, {c = }")
print(ans) | 0 | null | 13,019,850,797,800 | 77 | 151 |
input()
x=list(map(int,input().split()))
r=10**10
for i in range(min(x),max(x)+1):
s=0
for j in x:
s+=(i-j)**2
r=min(r,s)
print(r) | N = int(input())
# 26進数に変換する問題
ans = ""
alphabet = "Xabcdefghijklmnopqrstuvwxyz"
while N > 0:
mod = N % 26
if mod == 0:
mod = 26
ans = alphabet[mod] + ans
N -= mod
N //= 26
print(ans)
| 0 | null | 38,707,817,622,978 | 213 | 121 |
import sys
# import bisect
# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math
# from numba import jit
# from scipy import
# import numpy as np
# import networkx as nx
# import matplotlib.pyplot as plt
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
n, p = list(map(int, readline().split()))
s = input()
ans = 0
if p == 2 or p == 5:
for i in range(n):
if int(s[i]) % p == 0:
ans += (i + 1)
else:
c = [0] * p
prev = 0
c[0] = 1
for i in range(n):
num = int(s[n - i - 1])
m = (num * pow(10, i, p) + prev) % p
c[m] += 1
prev = m
for i in range(p):
cnt = c[i]
ans += cnt * (cnt - 1) // 2
print(ans)
if __name__ == '__main__':
main()
| n, p = map(int, input().split())
s = input()
a = []
c = 0
if p == 2:
b = [0]*n
for i in range(n):
if int(s[i])%2 == 0:
b[i] += 1
for i in range(n):
if b[i] == 1:
c += i+1
elif p == 5:
b = [0]*n
for i in range(n):
if int(s[i])%5 == 0:
b[i] += 1
for i in range(n):
if b[i] == 1:
c += i+1
else:
b = [0]*p
b[0] = 1
d = [1]
a.append(int(s[-1])%p)
for i in range(n-1):
d.append(d[-1]*10%p)
for i in range(1, n):
a.append((int(s[-i-1])*d[i]+a[i-1])%p)
for i in range(n):
b[a[i]] += 1
for i in range(p):
c += int(b[i]*(b[i]-1)/2)
print(c) | 1 | 58,243,059,774,988 | null | 205 | 205 |
n=int(input())
a=list(map(int,input().split()))
m=len(a)
a=set(a)
n=len(a)
if m==n:
print("YES")
else:
print("NO") | N = int(input())
a = list(input())
count = 1
for i in range(N):
if i>0:
if a[i-1]==a[i]:
pass
elif a[i-1]!=a[i]:
count+=1
print(count) | 0 | null | 122,339,337,955,300 | 222 | 293 |
import math
r = float(input())
print("%.5f %.5f" % (math.pi*r *r, 2*math.pi*r))
| import math
r = float(input())
#r = (float(x) for x in input().split())
d = r * r * math.pi
R = 2 * r * math.pi
print ("{0:.6f} {1:.6f}".format(d,R))
| 1 | 637,828,578,688 | null | 46 | 46 |
S,T = [input() for _ in range(2)]
print("Yes") if S==T[:-1] else print("No") |
def main():
s = input()
t = input()
if s == t[:-1]:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main() | 1 | 21,470,774,046,880 | null | 147 | 147 |
INF = 10 ** 10
def merge(A, left, mid, right):
c = 0
n1 = mid - left
n2 = right - mid
Left = [A[left+i] for i in range(n1)]
Right = [A[mid+i] for i in range(n2)]
Left.append(INF)
Right.append(INF)
i=0
j=0
for k in range(left, right):
c += 1
if Left[i] <= Right[j]:
A[k] = Left[i]
i += 1
else:
A[k] = Right[j]
j += 1
return c
def mergeSort(hoge, left, right):
c = 0
if left+1 < right:
mid = (left + right) // 2
c += mergeSort(hoge, left, mid)
c += mergeSort(hoge, mid, right)
c += merge(hoge, left, mid, right)
return c
if __name__ == '__main__':
_ = input()
hoge = [int(x) for x in input().split()]
c = mergeSort(hoge, 0, len(hoge))
print (' '.join([str(x) for x in hoge]))
print (c)
| n = int(input())
s = list(map(int,input().split()))
count = 0
def merge(a, left, mid, right):
global count
l = a[left:mid] + [float("inf")]
r = a[mid:right] + [float("inf")]
i = j = 0
for k in range(left, right):
if l[i] <= r[j]:
a[k] = l[i]
i += 1
else:
a[k] = r[j]
j += 1
count += right - left
def mergeSort(a, left, right):
if left + 1 < right:
mid = right + (left - right)//2
mergeSort(a, left, mid)
mergeSort(a, mid, right)
merge(a, left, mid, right)
mergeSort(s, 0, n)
print(*s)
print(count) | 1 | 110,195,676,580 | null | 26 | 26 |
import math
a,b=map(int,input().split())
for i in range (11000):
if a <= i*0.08 <a+1:
if b<= i*0.1 <b+1:
print(i)
exit()
print(-1) | a, b = map(int, input().split())
ans = -1
for money in range(pow(10, 4)):
if int(money*0.08) == a and int(money*0.1) == b:
ans = money
break
print(ans) | 1 | 56,517,008,452,476 | null | 203 | 203 |
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
p=10**9+7
def fact(n,p):
a=[[] for _ in range(n+1)]
a[0]=1
for i in range(n):
a[i+1]=(a[i]*(i+1))%p
return a
f=fact(n,p)
g=[]
for i in range(n+1):
g.append(pow(f[i],-1,p))
def com(n,r):
return f[n]*g[r]*g[n-r]
ans=0
for i in range(n-k+1):
ans=ans+(a[-i-1]-a[i])*com(n-i-1,k-1)
print(ans%p) | 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
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=map(int,input().split())
L=list(map(int,input().split()))
L=sorted(L)
s=0
for i in range(N-K+1):
s+=(cmb(N-i-1,K-1,mod)*(L[N-1-i]-L[i]))%mod
print(s%mod) | 1 | 95,557,634,890,296 | null | 242 | 242 |
def az16():
list = []
n = input()
for i in range(0,n):
list.append(raw_input().split())
for mark in ["S","H","C","D"]:
for i in range(1,14):
if [mark,repr(i)] not in list:
print mark,i
az16() | cards = {
"S": [0 for n in range(13)],
"H": [0 for n in range(13)],
"C": [0 for n in range(13)],
"D": [0 for n in range(13)]
}
t = int(input())
for n in range(t):
a,b = input().split()
cards[a][int(b)-1] = 1
for a in ("S", "H","C", "D"):
for b in range(13):
if cards[a][b] == 0:
print(a,b+1) | 1 | 1,044,310,977,290 | null | 54 | 54 |
K=int(input())
if K==32:
print(51)
elif K==24:
print(15)
elif K==16:
print(14)
elif K==8 or K==12 or K==18 or K==20 or K==27:
print(5)
elif K==28 or K==30:
print(4)
elif K==4 or K==6 or K==9 or K==10 or K==14 or K==21 or K==22 or K==25 or K==26:
print(2)
else:
print(1) | x = int(input())
cnt_500 = 0
cnt_5 = 0
while x > 4:
if x >= 500:
x -= 500
cnt_500 += 1
else:
x -= 5
cnt_5 += 1
print(1000*cnt_500+5*cnt_5)
| 0 | null | 46,196,639,502,358 | 195 | 185 |
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]
T = [int(input())-1 for _ in range(D)]
last = [0] * 26
score = 0
for d in range(D):
v = T[d]
score += S[d][v]
for i in range(26):
if i == v:
last[i] = 0
else:
last[i] += 1
score -= C[i] * last[i]
print(score) | S = list(input())
A = [0]*(len(S)+1)
node_value = 0
for i in range(len(S)):
if S[i] == "<":
node_value += 1
A[i+1] = node_value
else:
node_value = 0
node_value = 0
for i in range(len(S)-1,-1,-1):
if S[i] == ">":
node_value += 1
A[i] = max(A[i], node_value)
else:
node_value = 0
print(sum(A)) | 0 | null | 82,996,894,229,480 | 114 | 285 |
n, m, l = map(int, input().split())
A, B = [], []
for _ in range(n):
A.append(list(map(int, input().split())))
for _ in range(m):
B.append(list(map(int, input().split())))
C = []
B_T = list(zip(*B))
for a_row in A:
C.append([sum(a * b for a, b, in zip(a_row, b_column)) for b_column in B_T])
for row in C:
print(' '.join(map(str, row))) | N = input()
a = [input() for i in range(N)]
maxv = a[-1] - a[0]
minv = a[0]
for i in range(1,N):
maxv = max(maxv,a[i]-minv)
minv = min(minv,a[i])
print maxv | 0 | null | 730,715,380,768 | 60 | 13 |
N = input()
tmp = 0
for s in N:
tmp += int(s)
if tmp%9 == 0:
print("Yes")
else:
print("No") | N=str(input())
NN=0
for i in range(len(N)):
NN=NN+int(N[i])
if NN%9==0:print('Yes')
else:print('No') | 1 | 4,432,735,199,388 | null | 87 | 87 |
import sys
n, m = map(int, input().split())
s = input()[::-1]
ans = []
tmp = 0
while tmp < n:
for i in range(min(m, n-tmp), 0, -1):
if s[tmp+i] == "0":
tmp += i
ans.append(str(i))
break
else:
print(-1)
sys.exit()
print(" ".join(ans[::-1])) | N,M=map(int, input().split())
S=list(input())
T=S[::-1]
D=[0]*N
if N<=M:
print(N)
exit()
renzoku,ma=0,0
for i in range(1,N+1):
if S[i]=='1':
renzoku+=1
else:
ma=max(ma,renzoku)
renzoku=0
if ma>=M:
print(-1)
exit()
r=0
for i in range(1,M+1):
if T[i]!='1':
r=i
ans=[r]
while r+M<N:
for i in range(M,0,-1):
if T[r+i]=='0':
ans.append(i)
r+=i
break
ans.append(N-r)
print(*ans[::-1]) | 1 | 139,604,423,502,572 | null | 274 | 274 |
#! python3
# dice_i.py
class dice():
def __init__(self, arr):
self.top = arr[0]
self.south = arr[1]
self.east = arr[2]
self.west = arr[3]
self.north = arr[4]
self.bottom = arr[5]
def rotate(self, ope):
if ope == 'S':
self.top, self.north, self.bottom, self.south = self.north, self.bottom, self.south, self.top
elif ope == 'N':
self.top, self.south, self.bottom, self.north = self.south, self.bottom, self.north, self.top
elif ope == 'E':
self.top, self.west, self.bottom, self.east = self.west, self.bottom, self.east, self.top
elif ope == 'W':
self.top, self.east, self.bottom, self.west = self.east, self.bottom, self.west, self.top
dc = dice([int(x) for x in input().split(' ')])
opes = list(input())
for op in opes:
dc.rotate(op)
print(dc.top)
| d1=[0 for i in range(6)]
d1[:]=(int(x) for x in input().split())
t1=[0 for i in range(6)]
order=input()
for i in range(len(order)):
if order[i]=='N':
t1[0]=d1[1]
t1[1]=d1[5]
t1[2]=d1[2]
t1[3]=d1[3]
t1[4]=d1[0]
t1[5]=d1[4]
if order[i]=='S':
t1[0]=d1[4]
t1[1]=d1[0]
t1[2]=d1[2]
t1[3]=d1[3]
t1[4]=d1[5]
t1[5]=d1[1]
if order[i]=='E':
t1[0]=d1[3]
t1[1]=d1[1]
t1[2]=d1[0]
t1[3]=d1[5]
t1[4]=d1[4]
t1[5]=d1[2]
if order[i]=='W':
t1[0]=d1[2]
t1[1]=d1[1]
t1[2]=d1[5]
t1[3]=d1[0]
t1[4]=d1[4]
t1[5]=d1[3]
d1=list(t1)
print(d1[0])
| 1 | 233,209,651,442 | null | 33 | 33 |
n = int(input())
array = list(map(int, input().split()))
print("{} {} {}".format(min(array), max(array), sum(array)))
| c=[[0]*3001for _ in range(3001)]
dp=[[[0]*3001for _ in range(3001)]for _ in range(4)]
h,w,k=map(int,input().split())
for i in range(k):
y,x,v=map(int,input().split())
c[y][x]=v
for i in range(1,h+1):
for j in range(1,w+1):
x=max(dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j])
for k in range(4):
if k:dp[k][i][j]=max(dp[k][i][j-1],dp[k-1][i][j-1]+c[i][j])
else:dp[k][i][j]=max(dp[k][i][j-1],x)
dp[1][i][j]=max(dp[1][i][j],x+c[i][j])
print(max(dp[0][h][w],dp[1][h][w],dp[2][h][w],dp[3][h][w])) | 0 | null | 3,154,634,176,250 | 48 | 94 |
import sys
a,b,c = map(int,sys.stdin.readline().split())
counter = 0
for n in range(a,b+1):
if c % n == 0:
counter += 1
print(counter) | a,b=map(int,input().split())
if a<b:
ans=str(a)*b
else:
ans=str(b)*a
print(ans) | 0 | null | 42,538,427,782,238 | 44 | 232 |
#!/usr/bin/env python3
def main():
K, X = map(int, open(0).read().split())
if (500 * K >= X):
print('Yes')
else:
print('No')
main() | from fractions import gcd
n, m = map(int, input().split())
a = [int(i) // 2 for i in input().split()]
x = 1
for i in range(n):
x *= a[i] // gcd(x, a[i])
for i in a:
if x // i % 2 == 0:
print(0)
exit()
print((m // x + 1) // 2) | 0 | null | 99,986,231,821,700 | 244 | 247 |
import sys
def main():
k = int(input())
a =7%k
if a == 0:
print(1)
sys.exit()
for i in range(2,10**7):
a = (10*a+7) % k
if a == 0:
print(i)
sys.exit()
print(-1)
main() | K = int(input())
n = 7
for i in range(1, 1000001):
if n % K == 0:
print(i)
exit()
n = (n * 10 + 7) % K
else:
print(-1) | 1 | 6,094,880,823,812 | null | 97 | 97 |
import copy
h, w, k = map(int, input().split())
s = [[0] * w for _ in range(h)]
for i in range(h):
inp = input()
for j in range(w):
s[i][j] = int(inp[j])
# 最終的に出力する操作回数の最小値
ans = h + w - 2
for i in range(2 ** (h-1)):
# bit全探索によるcutの仕方
cutIdx = [0] * (h-1)
for j in range(h-1):
cutIdx[j] = (i >> j) & 1
#print('cI : ', cutIdx)
# cutする場所を示したリスト
div = []
cut_row_begin, cut_row_end = 0, 1
for j in range(h-1):
if cutIdx[j] == 0:
# cutしない
cut_row_end += 1
else:
# cutする
div.append((cut_row_begin, cut_row_end))
cut_row_begin = cut_row_end
cut_row_end += 1
div.append((cut_row_begin, cut_row_end))
#print('div: ', div)
# 既にここまででcutされている回数
cnt = sum(cutIdx)
#print(cnt)
# divごとのホワイトチョコの数をカウント
whiteCnt = [0] * len(div)
# まずは1列目をチェック
for a in range(len(div)):
cal = 0
for b in range(div[a][0], div[a][1]):
cal += s[b][0]
whiteCnt[a] = cal
#print('wC : ', whiteCnt)
# もしこの時点でwhiteCntの要素でkを超えるものがあるとき
# その横の切り方は不可能なのでbreak
if max(whiteCnt) > k:
continue
# Wが1ならそこで終わり
if w == 1:
ans = min(ans, cnt)
# 次行のホワイトチョコ数を保持
search = [0] * len(div)
# 2列目以降を同様にチェックしていく
for a in range(1, w):
# その次行のホワイトチョコの数
for b in range(len(div)):
cal = 0
for c in range(div[b][0], div[b][1]):
cal += s[c][a]
search[b] = cal
# その行単体でmax値とkを比べる
# オーバーしていればcut不可
if max(search) > k:
break
# greedy
for b in range(len(div)):
if whiteCnt[b] + search[b] > k:
# cut対象
cnt += 1
whiteCnt = copy.copy(search)
break
else:
whiteCnt[b] += search[b]
#print('cnt: ', cnt)
ans = min(ans, cnt)
print(ans) | # Problem E - Dividing Chocolate
# input
H, W, K = map(int, input().split())
board = [['']*W for i in range(H)]
for i in range(H):
s = list(input())
for j in range(W):
board[i][j] = s[j]
# initialization
min_divide = 10**10
s = [0]*(H-1) # 横線の入り方 0:無 1:有
is_ok = True
# search
for i in range(2**(H-1)): # bit全探索
# sの初期化
h_count = 0
w_count = 0
for j in range(H-1):
if ((i>>j)&1):
s[j] = 1
h_count += 1
else:
s[j] = 0
# 列の全探索
s_score = [0]*H # 各区域のスコア
s_cur = [0]*H
for j in range(W):
c = 0
s_cur = [0]*H
for k in range(H):
if board[k][j]=='1':
s_cur[c] += 1
# Kを超えていないかのチェック
if s_cur[c]>K:
is_ok = False
break
# 次の遷移先(横線の有無でグループが別れる)
if k+1<H:
if s[k]==1:
c += 1
# Kを超えていたらループ中止
if not is_ok:
break
# 前の列のグループと足してみてKを超えていないかチェック
# 超えていれば縦線分割を施す
group_smaller = True
if j>0:
for c_num in range(c+1):
if s_score[c_num]+s_cur[c_num]>K:
group_smaller = False
else:
group_smaller = True
if group_smaller:
for c_num in range(c+1):
s_score[c_num] += s_cur[c_num]
else:
w_count += 1
for c_num in range(c+1):
s_score[c_num] = s_cur[c_num]
if not is_ok:
is_ok = True
continue
# for c_num in range(h_count+1):
# if s_score[c_num]>K:
# h_count = 10 ** 6
# 縦線と横線の合計でmin_divideを更新
min_divide = min(min_divide, w_count + h_count)
# output
print(min_divide)
| 1 | 48,762,865,189,778 | null | 193 | 193 |
n=int(input())
A=[]
for i in range(n):
a=str(input())
A.append(a)
import collections
c = collections.Counter(A)
ma= c.most_common()[0][1]
C=[i[0] for i in c.items() if i[1] >=ma ]
C.sort(reverse=False)
for j in range(len(C)):
print(C[j]) | import math
import collections
def prime_diviation(n):
factors = []
i = 2
while i <= math.floor(math.sqrt(n)):
if n%i == 0:
factors.append(int(i))
n //= i
else:
i += 1
if n > 1:
factors.append(n)
return factors
N = int(input())
if N == 1:
print(0)
exit()
#pr:素因数分解 prs:集合にしたやつ prcnt:counter
pr = prime_diviation(N)
prs = set(pr)
prcnt = collections.Counter(pr)
#print(pr, prs, prcnt)
ans = 0
for a in prs:
i = 1
cnt = 2*prcnt[a]
#2*prcnt >= n(n+1)となる最大のnを探すのが楽そう
# print(cnt)
while cnt >= i*(i+1):
i += 1
ans += i - 1
print(ans) | 0 | null | 43,458,712,148,220 | 218 | 136 |
# coding: utf-8
import sys
def func(num_list):
count = 0
for i in range(2):
while(True):
# print(num_list[i], num_list[i+1])
if num_list[i] < num_list[i+1]:
break
else:
num_list[i+1] = num_list[i+1] * 2
count = count + 1
return count
if __name__ == "__main__":
lines = []
for l in sys.stdin:
lines.append(l.rstrip('\r\n'))
tmp = lines[0].split(' ')
num_list = []
for n in tmp:
num_list.append(int(n))
count = func(num_list)
if count <= int(lines[1]):
print("Yes")
else:
print("No")
| def main():
mod = 1e9 + 7
n, k = list(map(int, input().split()))
ans = 0
for i in range(k, n + 2):
ans += ((n + (n - i + 1)) * i // 2) - ((0 + (i - 1)) * i // 2) + 1
ans = int(ans % mod)
print(ans)
return
if __name__ == "__main__":
main()
| 0 | null | 20,081,292,905,696 | 101 | 170 |
N=int(input())
A=list(map(int,input().split()))
l=[0]*60
for i in A:
for j in range(60):
if i&(1<<j):l[j]+=1
ans=0
for i in range(60):
ans+=l[i]*(N-l[i])*(1<<i)
ans%=10**9+7
print(ans) | 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)
| 1 | 122,614,962,905,750 | null | 263 | 263 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix
INF = 10**12
N, M, L = map(int, readline().split())
ABCQST = np.array(read().split(), dtype=np.int64)
ABC = ABCQST[:3*M]
A = ABC[::3]; B = ABC[1::3]; C = ABC[2::3]
Q = ABCQST[3*M]
ST = ABCQST[3*M + 1:]
S = ST[::2]; T = ST[1::2]
graph = csr_matrix((C, (A, B)), (N + 1, N + 1))
d = floyd_warshall(graph, directed=False)
d[d <= L] = 1
d[d > L] = INF
d = floyd_warshall(d, directed=False).astype(int)
d[d == INF] = 0
d -= 1
print('\n'.join(d.astype(str)[S, T]))
|
def checkBingo(A,c):
for i in range(3):
for j in range(3):
if A[i][j]==c:
A[i][j]=0
for i in range(3):
if max(A[i])==0 :
return 1
for i in range(3):
if A[0][i]==0 and A[1][i]==0 and A[2][i]==0:
return 1
if A[0][0]==0 and A[1][1]==0 and A[2][2]==0:
return 1
if A[0][2]==0 and A[1][1]==0 and A[2][0]==0:
return 1
return 0
A=[]
for i in range(3):
A.append( list(map(int,input().split()) ))
# print(A, min(A[0]),min(A[1]),min(A[2]))
n = int(input())
res=0
for i in range(n):
b = (int(input()))
# print(A)
res += checkBingo(A,b)
if res :
print("Yes")
else:
print("No") | 0 | null | 116,446,172,672,128 | 295 | 207 |
MOD = 1000000007
n = int(input())
aas = list(map(int, input().split()))
KET = 60
arr_0 = [0]*KET
arr_1 = [0]*KET
for i in aas:
bits = format(i,'060b')
for j in reversed(range(KET)):
if bits[j] == '0':
arr_0[KET-j-1] += 1
else:
arr_1[KET-j-1] += 1
res = 0
for i in range(KET):
res += (arr_0[i]%MOD * arr_1[i]%MOD)%MOD * pow(2,i,MOD)
res %= MOD
print(res) | n=int(input())
ans = [0] * 100000
for x in range(1,101):
for y in range(1,101):
for z in range(1,101):
ans[x*x+y*y+z*z+x*y+y*z+z*x]+=1
for i in range(1,n+1):
print(ans[i])
| 0 | null | 65,739,565,113,540 | 263 | 106 |
# ALDS1_2_D: Shell Sort
#N = 5
#A = [5, 1, 4, 3, 2]
#N = 3
#A = [3, 2, 1]
A = []
N = int(input())
for i in range(N):
A.append(int(input()))
def insertionSort(A, N, g, cnt):
#print(" ".join(map(str, A)))
for i in range(g, N):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
#print(" ".join(map(str, A)))
return cnt
def shellSort(A, N):
cnt = 0
#m = 2
#listG = [4, 1]
h = 1
listG = []
while h <= N:
listG.append(h)
h = 3*h + 1
listG = listG[::-1]
m = len(listG)
for g in listG:
cnt = insertionSort(A, N, g, cnt)
#print(A)
print(m)
print(" ".join(map(str, listG)))
print(cnt)
for v in A:
print(v)
shellSort(A, N)
|
G = [120001,60001,30001,15001,3001,901,601,301,91,58,31,7,4,1]
def insertion_sort(array,g):
for i in range(g,len(array)-1):
v = array[i]
j = i-g
while j>=0 and array[j] > v:
array[j+g] = array[j]
j = j-g
array[-1] += 1
array[j+g] = v
def shell_sort(array,G):
for i in G:
insertion_sort(array,i)
n = int(input())
arr = [int(input()) for i in range(n)] + [0]
Gn = [i for i in G if i <= n]
shell_sort(arr,Gn)
print(len(Gn))
print(' '.join([str(i) for i in Gn]))
print(arr[-1])
[print(i) for i in arr[:-1]] | 1 | 28,787,538,010 | null | 17 | 17 |
import math
a, b, h, m = map(int, input().split())
c = abs((60*h+m)*0.5 - m*6)
if c>180:
c=360-c
c=(a**2 + b**2 - 2*a*b*math.cos(math.radians(c)))**0.5
print(c) | inp=input().split()
n=int(inp[0])
m=int(inp[1])
arr=[]
pares=0
impares=0
count=1
nums=0
def binary(arr, menor, mayor, x):
if mayor >= menor:
med = (mayor + menor) // 2
if arr[med] == x:
return med
elif arr[med] > x:
return binary(arr, menor, med - 1, x)
else:
return binary(arr, med + 1, mayor, x)
else:
return -1
while len(arr)<(m+n):
if count%2==0 and pares<n:
arr.append(count)
pares+=1
elif count%2!=0 and impares<m:
arr.append(count)
impares+=1
count+=1
sums=[]
for x in arr:
for y in arr:
if(x+y)%2==0 and binary(sums, 0, len(sums)-1, [y,x])==-1 and x!=y:
sums.append([x,y])
nums+=1
print(nums)
| 0 | null | 32,697,663,221,090 | 144 | 189 |
n=list(map(int,input()))
if n[-1] in [2,4,5,7,9]:
print('hon')
elif n[-1] in [0,1,6,8]:
print('pon')
else:
print('bon') |
count = 0
n, d = map(int, input().split())
for _ in range(n):
l, m = map(int, input().split())
z = (l ** 2 + m ** 2) ** 0.5
if z <= d:
count += 1
print(count)
| 0 | null | 12,718,041,973,092 | 142 | 96 |
from sys import exit
def main():
N = int(input())
a = list(map(int,input().split()))
index = -1
num = 1
for i in range(index+1, N):
if a[i] != num:
continue
elif a[i] == num:
index = i
num += 1
if index != -1:
print(N-(num-1))
exit()
#indexに更新がなければ-1のまま
print(index)
main() | def gcd(m, n):
x = max(m, n)
y = min(m, n)
if x % y == 0:
return y
else:
while x % y != 0:
z = x % y
x = y
y = z
return z
def lcm(m, n):
return (m * n) // gcd(m, n)
# input
A, B = map(int, input().split())
# lcm
snack = lcm(A, B)
print(snack)
| 0 | null | 113,976,348,792,052 | 257 | 256 |
n=int(input())
li=list(map(int,input().split()))
ans=0
for i in range(n):
ans=ans^li[i]
for i in range(n):
print(ans^li[i],end=" ")
print()
| n,*a = map(int,open(0).read().split())
all = 0
for i in a:
all^=i
print(*[all^i for i in a]) | 1 | 12,564,942,984,608 | null | 123 | 123 |
N,M = map(int,(input().split()))
s = list(input())
s.reverse()
now = 0
me = []
flag = 0
while now != N:
for i in range(1,M+1,)[::-1]:
if now + i <= N and s[now+i] == "0":
now += i
me.append(i)
break
else:
print(-1)
flag = 1
break
if flag == 0:
me.reverse()
print(*me) | n = input()
sum=0
for i in n :
sum += int(i)
if sum%9 == 0 : print("Yes")
else : print("No") | 0 | null | 71,924,992,353,938 | 274 | 87 |
import sys
T1, T2 = map(int,input().split())
A1, A2 = map(int,input().split())
B1, B2 = map(int,input().split())
if A1 < B1:
A1, B1 = B1, A1
A2, B2 = B2, A2
if A1 * T1 + A2 * T2 > B1 * T1 + B2 * T2:
print(0)
sys.exit()
if A1 * T1 + A2 * T2 == B1 * T1 + B2 * T2:
print('infinity')
sys.exit()
N = (T1 * (A1 - B1) - 1) // (T1 * (B1 - A1) + T2 * (B2 - A2)) + 1
ans = N * 2 - 1
if N * (T1 * (B1 - A1) + T2 * (B2 - A2)) == T1 * (A1 - B1):
ans += 1
print(ans) | a,b,c,d,e=map(int,input().split())
x=a*60+b
y=c*60+d
print(y-x-e) | 0 | null | 75,084,519,244,124 | 269 | 139 |
def main():
n,k=map(int,input().split())
a=[int(i)-1 for i in input().split()]
visit=[False]*n
visit[0]=True
loop, loopstart, loopout, cur=0, -1, False, 0
i = 0
while i < k:
#print("{}->{}".format(cur+1, a[cur]+1))
cur=a[cur]
if not loopout and visit[cur]:
#print("OnLoop", k)
if loopstart == cur:
k=(k-sum(visit))%loop
loopout=True
#print("OutLoop", k)
i = 0
continue
elif loopstart == -1:
#print("loop start with", cur+1)
loopstart = cur
loop+=1
else:
visit[cur]=True
i += 1
print(cur+1)
if __name__ == "__main__":
main() | a=int(input())
b=int(input())
ans = set()
ans.add(a)
ans.add(b)
all = {1,2,3}
print((all-ans).pop()) | 0 | null | 66,337,278,890,148 | 150 | 254 |
import math
K = int(input())
g = []
for i in range(1, K+1):
for j in range(1, K+1):
g.append(math.gcd(i, j))
result = 0
for i in range(1, K+1):
for t in g:
result += math.gcd(i, t)
print(result)
| from math import *
a,b,C=map(int,raw_input().split())
C = radians(C)
print (0.5)*a*b*sin(C)
print sqrt(a**2+b**2-2*a*b*cos(C)) + a + b
h = b*sin(C)
print h | 0 | null | 17,893,681,930,188 | 174 | 30 |
N, K = map(int, input().split())
A = list(map(lambda x: int(x)-1, input().split()))
now = 0
route = [now]
visited = set()
visited.add(now)
while A[now] not in visited:
route.append(A[now])
visited.add(A[now])
now = A[now]
L = len(route)
looplen = L-route.index(A[now])
if K < L:
print(route[K]+1)
else:
print(route[L-looplen+(K-L)%looplen]+1) | N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
count = 0
stack = set()
visited = []
visited_set = set()
endf = False
current = 0
while True:
i = A[current]-1
visited_set.add(current)
visited.append(current)
if not i in visited_set:
current = i
count += 1
else:
leng = len(visited_set)
roop_len = leng - visited.index(i)
header_len = leng - roop_len
break
if count >= K:
endf = True
print(i+1)
break
if not endf:
roop_ind = (K - header_len + 1) % roop_len
if roop_ind == 0:
print(visited[-1]+1)
else:
print(visited[header_len + roop_ind-1]+1) | 1 | 22,611,586,520,056 | null | 150 | 150 |
n = int(input())
dp = [0] * 45
dp[0], dp[1] = 1, 1
for i in range(2, 44+1):
dp[i] += dp[i-1] + dp[i-2]
print(dp[n])
| import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
from numba import njit
def getInputs():
D = int(readline())
CS = np.array(read().split(), np.int32)
C = CS[:26]
S = CS[26:].reshape((-1, 26))
return D, C, S
@njit('(i8, i4[:], i4[:, :], i4[:], )', cache=True)
def _compute_score1(D, C, S, out):
score = 0
last = np.zeros(26, np.int32)
for d in range(len(out)):
i = out[d]
score += S[d, i]
last[i] = d + 1
score -= np.sum(C * (d + 1 - last))
return last, score
def step1(D, C, S):
#out = np.zeros(D, np.int32)
out = []
LAST = 0
for d in range(D):
max_score = -10000000
best_i = 0
for i in range(26):
#out[d] = i
out.append(i)
last, score = _compute_score1(D, C, S, np.array(out, np.int32))
if max_score < score:
max_score = score
LAST = last
best_i = i
out.pop()
#out[d] = best_i
out.append(best_i)
return np.array(out), LAST, max_score
def output(out):
out += 1
print('\n'.join(out.astype(str).tolist()))
D, C, S = getInputs()
out, _, score = step1(D, C, S)
output(out) | 0 | null | 4,784,215,668,160 | 7 | 113 |
while 1:
c=list(raw_input())
o=""
if c[0]=="-" and len(c)==1:
break
m=int(raw_input())
for i in range(m):
h=int(raw_input())
c=list(c[h:]+c[:h])
for i in range(len(c)):
o+=c[i]
print o | N,M = map(int,input().split())
a = [0]*N
b = [None]*N
for i in range(M):
s,c = map(int,input().split())
if b[s-1] == c:
continue
else:
a[s-1] +=1
b[s-1] =c
count = 0
for i in range(N):
if a[i]>=2:
count=-1
elif b[0]==0 and N>1:
count =-1
elif i==0:
if b[i] is None:
if N==1:
b[i] =0
else:
b[i]=1
elif i>0:
if b[i] is None:
b[i]=0
b.reverse()
if count == 0:
for i in range(N):
count+=b[i]*10**i
print(count) | 0 | null | 31,476,445,082,332 | 66 | 208 |
import collections
N = int(input())
def make_divisors(n):
lower_divisors , upper_divisors = [], []
i = 1
while i*i <= n:
if n % i == 0:
lower_divisors.append(i)
if i != n // i:
upper_divisors.append(n//i)
i += 1
return lower_divisors + upper_divisors[::-1]
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
use_list = []
cnt = 0
while True:
flag = 0
div_list = make_divisors(N)
if len(div_list) == 1:
break
for i in range(1,len(div_list)):
if (len(collections.Counter(prime_factorize(div_list[i]))) == 1) and (div_list[i] not in use_list):
use_list.append(div_list[i])
N = N //div_list[i]
cnt +=1
flag = 1
break
if flag == 0:
break
print(cnt) | def division(n):
if n < 2:
return []
prime_fac = []
for i in range(2,int(n**0.5)+1):
cnt = 0
while n % i == 0:
n //= i
cnt += 1
if cnt!=0:prime_fac.append((i,cnt))
if n > 1:
prime_fac.append((n,1))
return prime_fac
n = int(input())
div = division(n)
ans = 0
for i,e in div:
b = 1
while b <= e:
e -= b
b += 1
ans += 1
print(ans)
| 1 | 17,043,083,851,842 | null | 136 | 136 |
import sys
def readint():
for line in sys.stdin:
yield map(int,line.split())
def gcd(x,y):
[x,y] = [max(x,y),min(x,y)]
while 1:
z = x % y
if z == 0:
break
[x,y] = [y,z]
return y
for [x,y] in readint():
GCD = gcd(x,y)
mx = x/GCD
print GCD,mx*y | n=int(input())
s=input()
ans=0
for i in range(1000):
i=str(i).zfill(3)
a=0
for c in s:
if c==i[a]:
a+=1
if a==3:
ans+=1
break
print(ans) | 0 | null | 64,048,229,123,412 | 5 | 267 |
n,m,l=map(int,input().split())
#print("n:%d, m:%d, l:%d"%(n, m, l))
nmlist=[]
for i in range(n):
nm=list(map(int,input().split()))
nmlist.append(nm)
#print(nmlist)
mllist=[]
for j in range(m):
ml=list(map(int,input().split()))
mllist.append(ml)
#print(mllist)
result = []
for i in range(n):
for j in range(l):
sum = 0
for k in range(m):
sum = sum + nmlist[i][k]*mllist[k][j]
result.append(sum)
#print(result)
for o in range(1,len(result)+1):
if o%l==0:
print(result[o-1])
else:
print(result[o-1],end=' ')
| n, k = map(int, input().split())
p = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
loop_max = []
loop_len = []
S = []
ans = []
for i in range(len(p)):
now = i
temp_len = 0
temp_s = 0
temp_l = []
while True:
now = p[now] - 1
temp_len += 1
temp_s += c[now]
temp_l.append(temp_s)
# 最初に戻ってきたら
if now == i:
break
loop_len.append(temp_len)
loop_max.append(temp_l)
S.append(temp_s)
for i in range(len(S)):
mod = k % loop_len[i] if k % loop_len[i] != 0 else loop_len[i]
if S[i] > 0:
if max(loop_max[i][:mod]) > 0:
ans.append(((k-1)//loop_len[i])*S[i] + max(loop_max[i][:mod]))
else:
ans.append(((k - 1) // loop_len[i]) * S[i])
else:
ans.append(max(loop_max[i]))
print(max(ans))
| 0 | null | 3,440,421,054,140 | 60 | 93 |
line = input()
num_query = int(input())
for loop in range(num_query):
input_str = list(input().split())
if input_str[0] == 'replace':
left = int(input_str[1])
right = int(input_str[2])
right += 1
line = line[:left] + input_str[3] + line[right:]
elif input_str[0] == 'reverse':
left = int(input_str[1])
right = int(input_str[2])
right += 1
line = line[:left] + line[left:right][::-1] + line[right:]
else: # print
left = int(input_str[1])
right = int(input_str[2])
right += 1
for i in range(left, right):
print(line[i], end="")
print()
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
H1, M1, H2, M2, K = map(int, read().split())
hr = (H2- H1) * 60
if M2 >= M1:
_min = M2 - M1
hr = (H2- H1) * 60
ans = hr + _min
else:
_min = (M2 + 60) - M1
hr = (H2- H1 -1) * 60
ans = hr + _min
print(ans - K) | 0 | null | 10,093,109,941,408 | 68 | 139 |
W = input()
T = ""
while True:
x = input()
if x == "END_OF_TEXT":
break
T += x + " "
num = 0
for t in T.split():
if t.lower() == W.lower():
num += 1
print(num) | key = raw_input().upper()
c = ''
while True:
s = raw_input()
if s == 'END_OF_TEXT':
break
c = c + ' ' + s.upper()
cs = c.split()
total = 0
for w in cs:
if w == key:
total = total + 1
print total | 1 | 1,817,736,508,312 | null | 65 | 65 |
n = int(input())
dic = set()
for i in range(n):
order, Str = input().split()
if order=='insert':
dic.add(Str)
if order=='find':
if Str in dic:
print('yes')
else:
print('no')
| n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(1,len(a)):
height_step = a[i] - a[i-1]
if height_step < 0:
ans -= height_step
a[i] = a[i-1]
print(ans) | 0 | null | 2,301,949,566,880 | 23 | 88 |
# -*- coding: utf-8 -*-
n = int(input())
A = [int(n) for n in input().split()]
q = int(input())
M = [int(n) for n in input().split()]
numbers = [0]
for a in A:
numbers = numbers + [n+a for n in numbers]
for m in M:
if m in numbers:
print("yes")
else:
print("no") | import itertools as it
n, A = int(input()), [*map(int, input().split())]
yes_nums = set()
for bools in it.product([True, False], repeat=n):
yes_nums.add(sum(A[i] for i in range(n) if bools[i]))
_ = input()
for m in map(int, input().split()):
print("yes" if m in yes_nums else "no")
| 1 | 96,740,200,788 | null | 25 | 25 |
H,N = map(int,input().split())
A = list(map(int,input().split()))
All = sum(A)
if H - All > 0:
print("No")
else:
print("Yes") | h,n=list(map(int ,input().split()))
l=list(map(int ,input().split()))
ans=0
count=0
for i in range(0,n):
ans+=l[i]
if(ans==h or ans>h):
count+=1
else:
count+=0
if(count>0):
print("Yes")
else:
print("No") | 1 | 77,885,952,912,498 | null | 226 | 226 |
a = list(map(int, input().split()))
if a[0] == a[1] and a[0] != a[2]:
print("Yes")
elif a[0] != a[1] and a[1] == a[2]:
print("Yes")
elif a[0] == a[2] and a[0] != a[1]:
print("Yes")
else:
print("No")
|
def main():
x, y, z = map(int, input().split(" "))
print(f"{z} {x} {y}")
if __name__ == "__main__":
main() | 0 | null | 53,114,384,263,490 | 216 | 178 |
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
n = int(input())
flag = 0
for _ in range(n):
b = int(input())
for i in range(3):
if b == a1[i]:
a1[i] = 0
elif b == a2[i]:
a2[i] = 0
elif b == a3[i]:
a3[i] = 0
for i in range(3):
if a1[i] == a2[i] == a3[i]:
flag = 1
if sum(a1) == 0:
flag = 1
if sum(a2) == 0:
flag = 1
if sum(a3) == 0:
flag = 1
if a1[0] == a2[1] == a3[2]:
flag = 1
if a1[2] == a2[1] == a3[0]:
flag = 1
if flag == 1:
print("Yes")
break
if flag == 0:
print("No") | s, t = map(str, input().split())
ans = t + s
print(ans) | 0 | null | 81,005,120,219,012 | 207 | 248 |
while True:
a = map(int, raw_input().split(" "))
if len([x for x in a if x <> 0]) <= 0:
break
else:
a.sort()
print " ".join(map(str, a)) | # coding: utf-8
import sys
i = sys.stdin
for line in i:
a,b = map(int,line.split())
if a == 0 and b == 0: break
if a < b:
print(a,b)
else:
print(b,a) | 1 | 534,183,110,720 | null | 43 | 43 |
import sys
H = int(next(sys.stdin.buffer))
ans = 0
i = 1
while H > 0:
H //= 2
ans += i
i *= 2
print(ans) | import math
print(2**(int(math.log2(int(input())))+1)-1) | 1 | 79,842,087,398,788 | null | 228 | 228 |
print raw_input().swapcase() | in_str = input().rstrip()
print(in_str.swapcase()) | 1 | 1,509,278,035,232 | null | 61 | 61 |
def check(a,b,c):
if a==b or a==c or b==c:
return False
if a+b>c and b+c>a and c+a>b:
return True
return False
n=int(input())
c=list(map(int,input().split()))
count=0
for i in range(len(c)-2):
for j in range(i+1,len(c)-1):
for k in range(j+1,len(c)):
if check(c[i],c[j],c[k]):
count+=1
print(count)
| k = int(input())
s = str(input())
if len(s)>k:
print(s[:k]+"...")
else:
print(s[:k]) | 0 | null | 12,409,642,303,078 | 91 | 143 |
n=int(input())
import bisect
L=[]
for i in range(n):
x,l=map(int,input().split())
a=x-l+0.1
b=x+l-0.1
L.append((b,a))
L=sorted(L)
rob=1
bottom=L[0][0]
for i in range(1,n):
if L[i][1]>bottom:
rob += 1
bottom=L[i][0]
print(rob) | cnt = 0
a, b, c = map(int, input().split())
if (a >= 1 and a <= 10000) and (b >= 1 and b <= 10000) and (c >= 1 and c <= 10000):
if a <= b:
for i in range(a, b+1):
if c % i == 0:
cnt += 1
print("{0}".format(str(cnt)))
else:
pass
else:
pass | 0 | null | 45,222,778,869,450 | 237 | 44 |
h,w,k=map(int,input().split())
G=[["."]*w for i in range(h)]
for i in range(h):
G[i]=list(input())
ans=[[0]*w for i in range(h)]
GG=[[0] for i in range(h)]
for i in range(h):
for j in range(w):
if G[i][j]=="#":
GG[i].append(j)
GG[i].append(w)
B=[0]
a=1
for i in range(h):
if len(GG[i])==2:
continue
B.append(i)
ans[i][GG[i][0]:GG[i][2]]=[a]*(GG[i][2]-GG[i][0])
a=a+1
for j in range(len(GG[i])-3):
ans[i][GG[i][j+2]:GG[i][j+3]]=[a]*(GG[i][j+3]-GG[i][j+2])
a=a+1
B.append(h)
for i in range(B[2]-B[0]):
ans[i]=ans[B[1]]
for i in range(B[2],h):
if i not in B:
ans[i]=ans[i-1]
for i in range(h):
for j in range(w):
print(ans[i][j],end=" ")
print() | h,w,k=map(int,input().split())
s=[]
ans=[[0 for k in range(w)] for _ in range(h)]
for _ in range(h): s.append(input())
temp=0
for i in range(h):
flag=0
for j in range(w):
if flag:
if s[i][j]=="#": temp+=1
ans[i][j]=temp
else:
if s[i][j]=="#":
temp+=1
flag=1
ans[i][j]=temp
temp=[ans[i].count(0) for i in range(h)]
for i,val in enumerate(temp):
if 0<val<w:
j=w-1
while ans[i][j]!=0: j-=1
while j>=0:
ans[i][j]=ans[i][j+1]
j-=1
for i in range(h):
if i>0 and ans[i][0]==0: ans[i]=ans[i-1]
for i in range(h-1,-1,-1):
if i<h-1 and ans[i][0]==0: ans[i]=ans[i+1]
for i in range(h):
for j in range(w):
print(ans[i][j],end=" ")
print() | 1 | 143,365,687,882,372 | null | 277 | 277 |
t = int(raw_input())
a = raw_input().split()
small = int(a[0])
large = int(a[0])
total = 0
for i in a:
v = int(i)
if v < small:
small = v
if v > large:
large = v
total = total + v
print small,large,total | n, m = (int(i) for i in input().split())
tot = sum(int(i) for i in input().split())
if tot > n:
print(-1)
else:
print(n - tot)
| 0 | null | 16,279,969,075,722 | 48 | 168 |
def main():
S = list(input())
T = []
reverse = False
n_q = int(input())
for i in range(n_q):
q = input().split(" ")
if q[0] == "1":
reverse = not reverse
elif q[0] == "2":
f = q[1]
c = q[2]
if (f == "1" and not reverse) or (f == "2" and reverse):
T.append(c)
elif (f == "1" and reverse) or (f == "2" and not reverse):
S.append(c)
if reverse:
S.reverse()
ans = S + T
elif not reverse:
T.reverse()
ans = T + S
print("".join(ans))
main() | from collections import deque
s = list(input())
q = int(input())
t = [list(map(str,input().split())) for _ in range(q)]
d = deque(s)
cnt = 0
for i in range(q):
if len(t[i]) == 1:
cnt += 1
else:
if (int(t[i][1])+cnt) % 2 != 0:
d.appendleft(t[i][2])
else:
d.append(t[i][2])
if cnt%2 != 0:
d = list(d)[::-1]
print(''.join(d)) | 1 | 57,400,824,897,098 | null | 204 | 204 |
# -*- coding: utf-8 -*-
def judge(m, f, r):
if m==-1 or f==-1: return "F"
ttl = m + f
if ttl >= 80: return "A"
elif ttl >= 65: return "B"
elif ttl >= 50: return "C"
elif ttl >= 30:
return "C" if r>=50 else "D"
else: return "F"
if __name__ == "__main__":
while True:
m, f, r = map(int, raw_input().split())
if m==-1 and f==-1 and r==-1: break
print judge(m, f, r) | from queue import Queue
k = int(input())
q = Queue()
for i in range(1, 10):
q.put(i)
for i in range(k):
x = q.get()
if x % 10 != 0:
num = 10 * x + (x % 10) - 1
q.put(num)
num = 10 * x + (x % 10)
q.put(num)
if x % 10 != 9:
num = 10 * x + (x % 10) + 1
q.put(num)
print(x) | 0 | null | 20,497,845,044,708 | 57 | 181 |
class Dice:
def __init__(self,t,f,r,l,b,u):
self.t=t
self.f=f
self.r=r
self.l=l
self.b=b
self.u=u
def roll(self,i):
if d=='S':
key=self.t
self.t=self.b
self.b=self.u
self.u=self.f
self.f=key
elif d=='E':
key=self.t
self.t=self.l
self.l=self.u
self.u=self.r
self.r=key
elif d=='N':
key=self.t
self.t=self.f
self.f=self.u
self.u=self.b
self.b=key
else:
key=self.t
self.t=self.r
self.r=self.u
self.u=self.l
self.l=key
t,f,r,l,b,u=map(int,input().split())
a=list(input())
dice=Dice(t,f,r,l,b,u)
for d in a:
dice.roll(d)
print(dice.t)
| diceface = { "TOP":0,"FRONT":1,"RIGHT":2,"LEFT":3,"BACK":4,"BOTTOM":5 }
dice = [ int( i ) for i in raw_input( ).split( " " ) ]
roll = raw_input( )
for i in range( len( roll ) ):
if "E" == roll[i]:
t = dice[ diceface["TOP"] ]
dice[ diceface["TOP"] ] = dice[ diceface["LEFT"] ]
dice[ diceface["LEFT"] ] = dice[ diceface["BOTTOM"] ]
dice[ diceface["BOTTOM"] ] = dice[ diceface["RIGHT"] ]
dice[ diceface["RIGHT"] ] = t
elif "N" == roll[i]:
t = dice[ diceface["TOP"] ]
dice[ diceface["TOP"] ] = dice[ diceface["FRONT"] ]
dice[ diceface["FRONT"] ] = dice[ diceface["BOTTOM"] ]
dice[ diceface["BOTTOM"] ] = dice[ diceface["BACK"] ]
dice[ diceface["BACK"] ] = t
elif "S" == roll[i]:
t = dice[ diceface["TOP"] ]
dice[ diceface["TOP"] ] = dice[ diceface["BACK"] ]
dice[ diceface["BACK"] ] = dice[ diceface["BOTTOM"] ]
dice[ diceface["BOTTOM"] ] = dice[ diceface["FRONT"] ]
dice[ diceface["FRONT"] ] = t
elif "W" == roll[i]:
t = dice[ diceface["TOP"] ]
dice[ diceface["TOP"] ] = dice[ diceface["RIGHT"] ]
dice[ diceface["RIGHT"] ] = dice[ diceface["BOTTOM"] ]
dice[ diceface["BOTTOM"] ] = dice[ diceface["LEFT"] ]
dice[ diceface["LEFT"] ] = t
print( dice[ diceface["TOP"] ] ) | 1 | 233,865,306,240 | null | 33 | 33 |
import math
x = int(input())
y = x
while True:
flg = 0
for i in range(2,math.ceil(y**0.5)):
if y%i == 0:
flg = 1
break
if flg == 0:
print(y)
break
y += 1 | X = int(input())
def is_prime(n):
a = 2
while a*a < n:
if n%a == 0:
return False
a += 1
return True
while True:
if is_prime(X):
break
X += 1
print(X) | 1 | 105,418,609,198,380 | null | 250 | 250 |
n,k = map(int,input().split())
h = list(map(int,input().split()))
print(sum(h[i] >= k for i in range(n)))
| n,k = map(int, input().split())
H = list(map(int, input().split()))
ans = 0
for i in range(n):
if H[i] >= k:
ans += 1
else:
pass
print(ans) | 1 | 179,355,801,363,098 | null | 298 | 298 |
a,b,c = list(map(int,input().split()))
k = int(input())
cnt = 0
while not a < b:
b*=2
cnt+=1
while not b < c:
c*=2
cnt+=1
#print('cnt:',cnt,'k:',k)
print('Yes' if cnt <=k else 'No') | a, b, c = list(map(int, input().split()))
k = int(input())
for i in range(k):
if a >= b:
b *= 2
else:
c *= 2
if a < b and b < c:
print('Yes')
else:
print('No') | 1 | 6,892,081,908,178 | null | 101 | 101 |
n = int(input())
testimonies = [[] for i in range(n)]
for idx1 in range(n):
count = int(input())
for idx2 in range(count):
x,y = map(int, input().split())
testimonies[idx1].append((x-1, y))
output = 0
for combination in range(2 ** n):
consistent = True
for index in range(n):
if (combination >> index) & 1 == 0:
continue
for x,y in testimonies[index]:
if (combination >> x) & 1 != y:
consistent = False
break
if not consistent:
break
if consistent:
output = max(output, bin(combination)[2:].count("1"))
print(output) | from scipy.sparse import*
_,*s=open(0)
*g,=eval('[0]*500,'*500)
i=-1
for t in s:
i+=1;j=0
for u in t:k=i*20+j;g[k][k+1]=u>'#'<t[j+1];g[k][k+20]=u>'#'<(s+['#'*20])[i+1][j];j+=1
a=csgraph.johnson(csr_matrix(g),0)
print(int(max(a[a<999]))) | 0 | null | 107,965,473,110,832 | 262 | 241 |
n=int(input())
table=[[0]*n for i in range(60)]
for i,v in enumerate(map(int,input().split())):
for j in range(60):
table[j][n-1-i]=v%2
v//=2
if v==0:break
#print(*table,sep='\n')
ans=0
mod1,mod2=10**9+7,998244353
mod=mod1
a=1
for t in table:
o,z=0,0
for v in t:
if v:
o+=1
ans=(ans+z*a)%mod
else:
z+=1
ans=(ans+o*a)%mod
a=a*2%mod
print(ans) | # coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit
INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7
def mapline(t = int):
return map(t, sysread().split())
def mapread(t = int):
return map(t, read().split())
def generate_inv(n,mod):
"""
逆元行列
n >= 2
Note: mod must bwe a prime number
"""
ret = [0, 1]
for i in range(2,n+1):
next = -ret[mod%i] * (mod // i)
next %= mod
ret.append(next)
return ret
def run():
N, *A = mapread()
maxA = max(A)
L = maxA.bit_length()
subs = [0] * L
for k in range(L):
sum = 0
for a in A:
if (a >> k) & 1:
sum += 1 << k
sum %= mod
subs[k] = sum
sumA = 0
for a in A:
sumA += a
sumA %= mod
ret = 0
ret += (sumA * N) % mod
ret += (sumA * N) % mod
sub_sum = 0
for a in A:
sums = 0
for k in range(L):
if (a >> k) & 1:
sums += subs[k] * 2
sums %= mod
sub_sum += sums
sub_sum %= mod
ret -= sub_sum
ret %= mod
inv = generate_inv(2, mod)
ret *= inv[2]
ret %= mod
print(ret)
if __name__ == "__main__":
run()
| 1 | 122,405,168,820,314 | null | 263 | 263 |
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect
def solve():
n, k = map(int, input().split())
print(min(n%k, k-(n%k)))
return 0
if __name__ == "__main__":
solve() | n,k=map(int,input().split());print(min(n%k,k-n%k)) | 1 | 39,289,985,524,370 | null | 180 | 180 |
number=list(map(int,input().split()))
n,m=number[0],number[1]
height=list(map(int,input().split()))
load=[[] for i in range(n+1)]
for i in range(m):
tmp=list(map(int,input().split()))
if tmp[1] not in load[tmp[0]]:
load[tmp[0]].append(tmp[1])
if tmp[0] not in load[tmp[1]]:
load[tmp[1]].append(tmp[0])
box=[]
answer=0
for i in range(1,n+1):
box=[]
if len(load[i])==0:
answer+=1
for j in range(len(load[i])):
box.append(height[load[i][j]-1])
if box!=[]:
if max(box)<height[i-1]:
answer+=1
print(answer) | n,m = map(int,input().split())
graph = [[] for _ in range(n)]
h = list(map(int,input().split()))
for _ in range(m):
a,b = map(int,input().split())
graph[a-1].append(b-1)
graph[b-1].append(a-1)
cnt = 0
for i in range(n):
if graph[i] == []:
cnt += 1
continue
if max([h[j] for j in graph[i]]) < h[i] : cnt += 1
print(cnt) | 1 | 24,990,514,015,740 | null | 155 | 155 |
a, b = map(int, input().split())
ab = str(a) * b
ba = str(b) * a
print(sorted([ab, ba])[0])
| # @oj: atcoder
# @id: hitwanyang
# @email: [email protected]
# @date: 2020-09-15 19:45
# @url:
import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
from decimal import *
# region fastio
BUFSIZE = 8192
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
## 注意嵌套括号!!!!!!
## 先有思路,再写代码,别着急!!!
## 先有朴素解法,不要有思维定式,试着换思路解决
def main():
x=int(input())
dp=[0]*(x+1)
mod=10**9+7
for i in range(x+1):
if i<3:
dp[i]=0
continue
dp[i]=1
for j in range(3,i-3+1):
if i-j>5:
dp[i]+=(1+dp[i-j]%mod-1)
else:
dp[i]+=dp[i-j]%mod
print (dp[-1]%mod)
if __name__ == "__main__":
main() | 0 | null | 43,721,994,796,260 | 232 | 79 |
#atcoder template
def main():
import sys
imput = sys.stdin.readline
#文字列入力の時は上記はerrorとなる。
#ここにコード
#input
a = int(input())
#output
print(a + a**2 + a**3)
#N = 1のときなどcorner caseを確認!
if __name__ == "__main__":
main() | n = int(input())
print(n + n**2 + n**3)
| 1 | 10,282,955,004,590 | null | 115 | 115 |
import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()
cnt = 0
for i in range(n):
for j in range(i+1, n):
if j == n-1:
continue
x = l[i] + l[j]
cnt += bisect.bisect_left(l[j+1:], x)
print(cnt) | # coding: utf-8
# Here your code !
import sys
def culc_division(x) :
"""
??\???x????´???°?????°??????????????§??????
"""
culc_list = []
for i in range(1,x+1) :
if x % i == 0 :
culc_list.append(i)
return culc_list
in_std = list(map(int, sys.stdin.readline().split(" ")))
a = in_std[0]
b = in_std[1]
c = culc_division(in_std[2])
counter = 0
for idx in range(a, b+1):
if idx in c:
counter += 1
print(counter) | 0 | null | 86,448,155,950,948 | 294 | 44 |
# -*- coding: utf-8 -*-
# モジュールのインポート
import itertools
def get_input() -> tuple:
"""
標準入力を取得する.
Returns:\n
tuple: 標準入力
"""
# 標準入力を取得
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
return N, P, Q
def main(N: int, P: tuple, Q: tuple) -> None:
"""
メイン処理.
Args:\n
N (int): 数列の大きさ
P (tuple): 順列
Q (tuple): 順列
"""
# 求解処理
p = 0
q = 0
order = 1
for t in itertools.permutations(range(1, N + 1), N):
if t == P:
p = order
if t == Q:
q = order
order += 1
ans = abs(p - q)
# 結果出力
print(ans)
if __name__ == "__main__":
# 標準入力を取得
N, P, Q = get_input()
# メイン処理
main(N, P, Q)
| s = list(input())
al = [0]*(len(s)+1)
for i in range(len(s)):
if s[i] == '<':
al[i+1] = max(al[i]+1, al[i+1])
for i in range(len(s)-1, -1, -1):
if s[i] == '>':
al[i] = max(al[i+1]+1, al[i])
print(sum(al)) | 0 | null | 128,710,514,857,520 | 246 | 285 |
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
n = N // 2
if N % 2 == 1:
ans = sum(A[:n]) + sum(A[1:n+1])
else:
ans = sum(A[:n]) + sum(A[1:n])
print(ans) | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
from collections import deque
def main():
n, *a = map(int, read().split())
a.sort(reverse=True)
a = deque(a)
circle_joined = deque()
next_score = a.popleft()
r = 0
flag = False
while a:
circle_joined.append(a.popleft())
if flag:
next_score = circle_joined.popleft()
r += next_score
flag = False
else:
r += next_score
flag = True
print(r)
if __name__ == '__main__':
main()
| 1 | 9,235,679,260,840 | null | 111 | 111 |
def main():
n = int(input())
cnt = 0
# aが1からn-1まで動くと考える
for a in range(1, n):
# a*bがn-1以下であると考える
cnt += (n-1) // a
print(cnt)
if __name__ == '__main__':
main() | def COMinit():
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2,max):
fac[i] = fac[i-1]*i%mod
inv[i] = mod - inv[mod%i]*(mod//i)%mod
finv[i] = finv[i-1]*inv[i]%mod
def COM(n,k):
if n < k:
return 0
if n < 0 or k < 0:
return 0
return fac[n] * (finv[k]*finv[n-k]%mod)%mod
mod = 998244353
N,M,K = map(int,input().split())
max = max(N,2)
fac = [0] * max
finv = [0] * max
inv = [0] * max
COMinit()
ans = 0
for i in range(K+1):
c = COM(N-1,i)
m = pow(M-1,N-i-1,mod)
ans = (ans + ((c*m%mod)*M%mod))%mod
print(ans)
| 0 | null | 12,997,940,205,966 | 73 | 151 |
while True:
try:
x = map(int, raw_input().split(' '))
if x[0] < x[1]:
m = x[1]
n = x[0]
else:
m = x[0]
n = x[1]
# m is greatrer than n
while n !=0:
m,n = n,m % n
print m,x[0]*x[1]/m
except EOFError:
break | class BIT:
def __init__(self, n):
"""
data : BIT木データ
el : 元配列
"""
self.n = n
self.data = [0]*(n+1)
self.el = [0]*(n+1)
"""A1 ~ Aiまでの累積和"""
def Sum(self, i):
s = 0
while i > 0:
s += self.data[i]
i -= i & (-i) #LSB(Least Significant Bit)の獲得:i&(-i)
return s
"""Ai += x"""
def Add(self, i, x):
self.el[i] += x
while i <= self.n:
self.data[i] += x
i += i & -i
"""Ai ~ Ajまでの累積和"""
def Get(self, i, j=None):
if j is None:
return self.el[i]
return self.Sum(j) - self.Sum(i)
def ctoi(c):
return ord(c) - 97
n = int(input())
s = list(input())
q = int(input())
bits = [BIT(n) for _ in range(26)]
ans = []
for i in range(n):
bits[ctoi(s[i])].Add(i+1, 1)
for _ in range(q):
line = list(input().split())
if line[0] == '1':
idx = int(line[1])
bits[ctoi(s[idx-1])].Add(idx, -1)
s[idx-1] = line[2]
bits[ctoi(line[2])].Add(idx, 1)
else:
l,r = int(line[1]), int(line[2])
cnt = 0
for i in range(26):
if bits[i].Get(l-1,r)!=0:
cnt += 1
ans.append(cnt)
for a in ans:
print(a) | 0 | null | 31,232,324,339,072 | 5 | 210 |
N, K, C = map(int, input().split())
S = input().strip("\n")
L = [-1] * N
R = [10 ** 10] * N
l = 1
r = K
li = 0
ri = N-1
while li < N:
if S[li] == "o":
L[li] = l
l += 1
li += C + 1
else: li += 1
while ri >= 0:
if S[ri] == "o":
R[ri] = r
r -= 1
ri -= C + 1
else: ri -= 1
for i in range(N):
if L[i] == R[i]: print(i + 1)
| n, k, c = map(int, input().split())
s = str(input())
for i in range(n):
if s[i] == 'o':
ant = i+1
antlist = [ant]
break
for i in range(n):
if s[n-i-1] == 'o':
post = n-i
postlist = [post]
break
for i in range(k-1):
ant += c+1
post -= c+1
for i in range(n):
if s[ant+i-1] == 'o':
ant += i
antlist.append(ant)
break
for i in range(n):
if s[post-i-1] == 'o':
post -= i
postlist.append(post)
break
postlist.reverse()
#print(antlist)
#print(postlist)
for i in range(k):
if antlist[i] == postlist[i]:
print(antlist[i]) | 1 | 40,587,907,374,842 | null | 182 | 182 |
import sys
tmp = '#.' * 151
def draw(H, W):
odd = tmp[:W]
even = tmp[1:W + 1]
print((odd + '\n' + even + '\n') * (H // 2) + (odd + '\n' if H % 2 else ''))
for line in sys.stdin:
H, W = map(int, line.split())
if H == W == 0:
break
draw(H, W) | N = int(input())
S = list()
for i in range(N):
S.append(input())
c0 = 0
c1 = 0
c2 = 0
c3 = 0
for i in S:
if i == "AC":
c0 += 1
if i == "WA":
c1 += 1
if i == "TLE":
c2 += 1
if i == "RE":
c3 += 1
print("AC x " + str(c0))
print("WA x " + str(c1))
print("TLE x " + str(c2))
print("RE x " + str(c3))
| 0 | null | 4,819,102,543,450 | 51 | 109 |
# n, k = map(int, input().split())
# from collections import OrderedDict
# d = OrderedDict()
# a = list(input().split())
b = list(map(int, input().split()))
# print(r + max(0, 100*(10-n)))
# print("Yes" if 500*n >= k else "No")
# s = input()
# a = int(input())
# b = int(input())
# c = int(input())
# s = input()
print(b[-1], *b[:2]) | S=input()
ans=0
if 'R' in S:
ans+=1
if S[0]=='R' and S[1]=='R':
ans+=1
if S[1]=='R' and S[2]=='R':
ans+=1
print(ans)
| 0 | null | 21,537,965,040,020 | 178 | 90 |
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
from itertools import accumulate
INF = float("inf")
def bit(n, k):
return (n >> k) & 1
def bit_sum(n):
wa = 0
while n > 0:
wa += n & 1
n >>= 1
return wa
def border(x):
# xを二進数で与えた時、ビットの立っている位置のリストを1-indexで返す
c = 0
ans = []
while x > 0:
c += 1
if x & 1:
ans.append(c)
x >>= 1
return ans
def main():
H, W, K = map(int, input().split())
S = [[0]*W for _ in range(H)]
for h in range(H):
S[h][:] = [int(c) for c in input()]
acc = [[0]+list(accumulate(S[h])) for h in range(H)]
min_kaisu = +INF
for h in range(1 << (H-1)):
# hは分割方法を与える
# hで与えられる分割方法は、どのような分割なのかを得る。
startend = border(h)
flag = False
division = [0]
# x番目でW方向に分割すると仮定する
for x in range(1, W+1):
# xの位置で分割したとき、左の領域のホワイトチョコレートの数
# まずは行ごとに求める
white = [acc[i][x] - acc[i][division[-1]] for i in range(H)]
# 領域ごとに加算するし、最大値を撮る
white_sum = [sum(white[s:e])
for s, e in zip([0]+startend, startend+[H])]
# print(bin(h), division, x, white_sum)
white_max = max(white_sum)
# Kよりも大きくなるなら、事前に分割するべきであった。
if white_max > K:
division.append(x-1)
# 分割してもなおK以下を達成できないケースを除外する
white = [acc[i][x] - acc[i][division[-1]] for i in range(H)]
white_sum = [sum(white[s:e])
for s, e in zip([0]+startend, startend+[H])]
white_max = max(white_sum)
if white_max > K:
flag = True
break
if flag:
continue
# hによる分割も考慮する
division_tot = len(division)-1 + bit_sum(h)
min_kaisu = min(division_tot, min_kaisu)
print(min_kaisu)
return
if __name__ == '__main__':
main()
| import sys
#import numpy as np
input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]
tin=lambda : map(int, input().split())
lin=lambda : list(IN())
mod=1000000007
#+++++
def ii(v, n):
v += 2 ** 15
ret = bin(v)[-n:]
return ret
def v_sum(a,b):
return [av+bv for av,bv in zip(a,b)]
def get_n(rr, mm, k, limit):
ret = sum([int(c) for c in rr])
o = mm[0]
pp = []
for index_i, is_cut in enumerate(rr):
if is_cut == '1':
pp.append(o)
o = mm[index_i+1]
else:
o = v_sum(o, mm[index_i+1])
if max(o) > k:
return mod, None
pp.append(o)
ll = [pp[j][0] for j in range(len(pp))]
for v in ll:
if v > k:
return mod, None
cc = [0]*(len(mm[0]))
for i in range(1, len(mm[0])):
for il, v in enumerate(ll):
if ll[il] + pp[il][i] > k:
ret += 1
if ret >= limit:
return limit+1, None
ll = [pp[j][i] for j in range(len(pp))]
cc[i] = 1
break
else:
ll[il] += pp[il][i]
return ret, cc
def main():
h, w, k = tin()
mm=[]
for _ in range(h):
s = input()
s = [int(c) for c in s]
#s = np.array(s)
mm.append(s)
n = (h-1)*(w-1) + 1
for i in range(2 ** (h-1)):
rr = ii(i, h-1)
tt, cut_info = get_n(rr, mm, k, n)
if tt < n:
n = tt
print(n)
#+++++
isTest=False
def pa(v):
if isTest:
print(v)
def input_clipboard():
import clipboard
input_text=clipboard.get()
input_l=input_text.splitlines()
for l in input_l:
yield l
if __name__ == "__main__":
if sys.platform =='ios':
if input_method==input_methods[0]:
ic=input_clipboard()
input = lambda : ic.__next__()
elif input_method==input_methods[1]:
sys.stdin=open('inputFile.txt')
else:
pass
isTest=True
else:
pass
#input = sys.stdin.readline
ret = main()
if ret is not None:
print(ret) | 1 | 48,420,614,815,386 | null | 193 | 193 |
xyz = list(map(int,input().split()))
print("{} {} {}".format(xyz[2],xyz[0],xyz[1])) | xyz = list(map(int,input().split()))
xyz[0] ,xyz[1] = xyz[1],xyz[0]
xyz[0], xyz[2] = xyz[2], xyz[0]
print(*xyz) | 1 | 38,040,531,112,294 | null | 178 | 178 |
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) | h, a = map(int, input().split())
print(__import__('math').ceil(h / a)) | 0 | null | 48,747,461,179,800 | 144 | 225 |
#グローバル変数
count = int()
interval = int()
interval_list = list()
#アルゴリズム:挿入ソート
def insertionSort(list, number, interval):
for i in range(interval, number):
v = list[i]
j = i - interval
while j >= 0 and list[j] > v:
list[j + interval] = list[j]
j = j - interval
global count
count += 1
list[j + interval] = v
return list
#アルゴリズム:シェルソート
def shellSort(list, number):
global count, interval, interval_list
count = 0
interval = 1
interval_list.append(1)
while number >= 3*interval_list[0]+1:
interval_list.insert(0, 3*interval_list[0]+1)
interval += 1
for i in range(interval):
list = insertionSort(list, number, interval_list[i])
return list
#初期data
input_number = int(input())
input_list = list()
for i in range(input_number):
input_list.append(int(input()))
#処理の実行
result_list = list()
result_list = shellSort(input_list, input_number)
#結果の表示
print(interval)
print(" ".join(map(str, interval_list)))
print(count)
[print(i) for i in result_list]
| n = int(input())
home = [[0 for i in range(20)] for j in range(15)] #横最大20→間の#,縦最大3階*4棟+3行の空行
for i in range(n) :
b, f, r, v = map(int, input().split())
h = (b - 1) * 4 + f - 1
w = r * 2 - 1
s = v
home[h][w] += s
for y in range(15) :
for x in range(20) :
if(y % 4 == 3) :
home[y][x] = "#"
elif(x % 2 == 0) :
home[y][x] = " "
print(home[y][x], end = "")
print()
| 0 | null | 566,071,484,640 | 17 | 55 |
#!/usr/bin/env python3
n = int(input())
ans = [0] * (n + 1)
for x in range(1, 101):
for y in range(1, 101):
for z in range(1, 101):
w = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
if w <= n:
ans[w] += 1
for i in range(1, n + 1):
print(ans[i])
| N = int(input())
ans = [0 for i in range(10**4+1)]
for x in range(1, 101):
for y in range(1, 101):
for z in range(1, 101):
n = x*x + y*y + z*z + x*y + y*z + z*x
if n <= 10**4:
ans[n] += 1
for i in range(1, N+1):
print(ans[i]) | 1 | 8,025,915,769,860 | null | 106 | 106 |
import math
def koch(d, p1, p2):
if d == 0:
return
v = [p2[0] - p1[0], p2[1] - p1[1]]
s = [p1[0] + v[0] / 3, p1[1] + v[1] / 3]
t = [p1[0] + 2 * v[0] / 3, p1[1] + 2 * v[1] / 3]
u = [p1[0] + v[0] / 2 - v[1] * math.sqrt(3) / 6, p1[1] + v[1] / 2 + v[0] * math.sqrt(3) / 6]
koch(d - 1, p1, s)
print(" ".join(map(str, s)))
koch(d - 1, s, u)
print(" ".join(map(str, u)))
koch(d - 1, u, t)
print(" ".join(map(str, t)))
koch(d - 1, t, p2)
n = int(input())
print("0 0")
koch(n, [0, 0], [100, 0])
print("100 0")
| import math
while True:
try:
a, b = list(map(int, input().split()))
print('{0} {1}'.format(math.gcd(a, b), int(a * b / math.gcd(a, b))))
except EOFError:
break
| 0 | null | 66,969,226,038 | 27 | 5 |
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
a = int(input())
print(a + a**2 + a**3) | x = int(input())
b,cnt = 100, 0
while True:
a = b
b = b + a // 100
cnt += 1
if b >= x:
break
print(cnt)
| 0 | null | 18,610,401,390,534 | 115 | 159 |
r,c = map(int,raw_input().split())
matrix = []
for i in range(r):
matrix.append(map(int,raw_input().split()))
a = [0 for j in range(c)]
matrix.append(a)
for i in range(r):
sum = 0
for j in range(c):
sum += matrix[i][j]
matrix[i].append(sum)
for j in range(c):
sum = 0
for i in range(r):
sum += matrix[i][j]
matrix[r][j] = sum
sum = 0
for j in range(c):
sum += matrix[r][j]
matrix[r].append(sum)
for i in range(r):
for j in range(c):
print matrix[i][j],
print matrix[i][c]
for j in range(c + 1):
print matrix[r][j], | while True:
try:
r,c = map(int,raw_input().split())
if r == c == 0:
break
except EOFError:
break
array = []
for i in range(r):
array.append(map(int,raw_input().split()))
# column sum
# add a new sum-row
c_sum_row = [0 for ii in range(c)]
for k in range(c):
for j in range(r):
c_sum_row[k] += array[j][k]
array.append(c_sum_row)
# row sum
# append sum item to end of each row
for k in range(r+1):
array[k].append(sum(array[k]))
for k in range(r+1):
print ' '.join(map(str,array[k])) | 1 | 1,364,722,091,400 | null | 59 | 59 |
#個数が無制限のナップザックの問題(ただし、上限に注意)です(どの魔法を順番に選べば良いなどの制約がないのでナップザックDPを選択しました。)。
#dpの配列にはi番目の要素にモンスターの体力をi減らすために必要な最小の魔力を保存します。
#この配列は個数制限がないことに注意してinfではない要素のみを順に更新していけば良いです。
#また、最終的にモンスターの体力を最小の魔力で0以下にすれば良いので、モンスターの体力をh以上減らせる最小の魔力を求めれば良いです。
h,n=map(int,input().split())
a,b=[],[]
for i in range(n):
a_sub,b_sub=map(int,input().split())
a.append(a_sub)
b.append(b_sub)
inf=10000000000000
ma=max(a)#ダメージの最大値
dp=[inf]*(h+1+ma)#与えるダメージの最大値を考慮したDP
dp[0]=0#初期値
for i in range(h+1+ma):# 与えるダメージ合計:0ーH+1+maまで
if dp[i] == inf:#更新してきて、ダメージiになる組み合わせが存在しない場合は飛ばす
continue
for j in range(n): #N個の魔法を試す
ni = i + a[j] #今の状態から新しく与えた場合のダメージ合計
if ni<h+ma:#オーバーキルの範囲を超えるなら、無視
dp[ni] = min(dp[ni], dp[i] + b[j]) #ダメージniを与えるのにより小さい魔力で実現できる場合は更新
print(min(dp[h:]))
| h,n=map(int,input().split())
INF=10**18
dp=[INF]*(h+1)
dp[0]=0
for _ in range(n):
a,b=map(int,input().split())
for i in range(h+1):
dp[min(i+a,h)]=min(dp[min(i+a,h)],dp[i]+b)
print(dp[h]) | 1 | 80,816,677,141,002 | null | 229 | 229 |
if __name__ == "__main__":
K,N = map(int,input().split())
A = list(map(int,input().split()))
distance_arr = []
for i in range(N-1):
distance_arr.append(A[i+1]-A[i])
distance_arr.append(K - A[N-1] + A[0])
print(K - max(distance_arr)) | k, n = list(map(int, input().split()))
a = list(map(int, input().split()))
d = []
for i in range(n):
if i == n - 1:
d.append(a[0] + (k - a[i]))
else:
d.append(a[i + 1] - a[i])
d.sort()
print(sum(d[:-1])) | 1 | 43,440,745,703,170 | null | 186 | 186 |
s = list(str(input()))
q = int(input())
from collections import deque
s = deque(s)
cnt = 0
for i in range(q):
query = list(map(str, input().split()))
if len(query) == 1:
cnt += 1
else:
t, f, c = query
if f == '1':
if cnt%2 == 0:
s.appendleft(c)
else:
s.append(c)
else:
if cnt%2 == 0:
s.append(c)
else:
s.appendleft(c)
s = list(s)
if cnt%2 == 1:
s.reverse()
print(''.join(s))
| from collections import deque
s = list(input())
moji = deque(s)
is_forward = True
q = int(input())
for i in range(q):
query = input()
if query[0] == "1":
is_forward = is_forward ^ 1
elif query[0] == "2":
_, f, c = query.split()
f = int(f)
f %= 2
is_end = f ^ is_forward
if is_end:
moji.append(c)
else:
moji.appendleft(c)
if is_forward == False:
moji = list(moji)[::-1]
print("".join(moji))
| 1 | 57,184,827,408,688 | null | 204 | 204 |
def decode():
[n, k] = [int(x) for x in input().split(" ")]
ws = []
for _ in range(n):
ws.append(int(input()))
return n, k, ws
def check(k, ws, p):
sum_w = ws[0]
tr = 1
for w in ws[1:]:
if sum_w + w <= p:
sum_w += w
else:
sum_w = w
tr += 1
if tr > k:
return False
return True
if __name__ == '__main__':
n, k, ws = decode()
lo = max(ws)
hi = sum(ws)
while lo <= hi:
p = (lo + hi) // 2
if check(k, ws, p):
hi = p - 1
ans = p
else:
lo = p + 1
print(ans)
| n, k = map(int, raw_input().split())
w = [int(raw_input()) for _ in xrange(n)]
def check(P):
i = 0
for j in range(k):
s = 0
while s + w[i] <= P:
s += w[i]
i += 1
if i == n:
return True
return False
def solver():
left, right = 0, 100000 * 10000
while left < right:
mid = int((left + right) / 2)
if check(mid):
right = mid
else:
left = mid + 1
return right
print solver() | 1 | 88,050,103,548 | null | 24 | 24 |
import sys
input = sys.stdin.readline
def main():
S = input().strip()
assert len(S) == 6
print("Yes") if S[2] == S[3] and S[4] == S[5] else print("No")
if __name__ == '__main__':
main()
| S = str(input())
if(S[2] == S[3] and S[4] == S[5]):
print("Yes")
else:
print("No") | 1 | 41,900,867,437,760 | null | 184 | 184 |
A, B = input().split()
A = int(A)
B = int(B.replace('.',''))
print(f'{A*B//100}') | x, y = input().split()
x = int(x)
z = round(float(y)*100)
print(x*z//100) | 1 | 16,437,150,522,022 | null | 135 | 135 |
# 初期入力
from bisect import bisect_left
import sys
#input = sys.stdin.readline #文字列では使わない
N = int(input())
c =input().strip()
ans =0
w =[i for i, x in enumerate(c) if x == 'W']
r =[i for i, x in enumerate(c) if x == 'R']
w_num =len(w) #全体でWの数
r_num =len(r) #全体でRの数
ans =bisect_left(r,r_num)
print(r_num -ans) | N=int(input())
c=str(input())
num_R = c.count("R")
num_W = 0
ans = []
if num_R >= num_W:
ans.append(num_R)
else:
ans.append(num_W)
#print(ans)
for i in range(len(c)):
if c[i] == "R":
num_R -= 1
else:
num_W += 1
if num_R >= num_W:
ans.append(num_R)
else:
ans.append(num_W)
#print(ans)
print(min(ans))
| 1 | 6,302,068,906,588 | null | 98 | 98 |
#!/usr/bin python3
# -*- coding: utf-8 -*-
from math import gcd #for python3.8
def lcm(a,b):
G = gcd(a, b) #最大公約数
L = (a//G)*b #最小公倍数
return L
def main():
X = int(input())
print(lcm(X,360)//X)
if __name__ == '__main__':
main() | N=int(input())
for i in range(N):
a, b, c = map(int, input().split())
if(a*a==b*b+c*c or b*b==a*a+c*c or c*c==b*b+a*a):
print('YES')
else:
print('NO') | 0 | null | 6,591,895,505,340 | 125 | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.