code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
x = int(input())
for a in range(x):
y = map(int,raw_input().split())
y.sort()
if y[2]**2-y[1]**2 == y[0]**2:
print "YES"
else:
print "NO" | s = list(map(int,input()))
s.reverse()
t = len(s)
mod = 2019
arr = [0] * (t+1)
arr[-2] = s[0]
for i in range(1,t):
arr[t-i-1] = (arr[t-i] + s[i]*pow(10,i,mod)) % mod
from collections import Counter
arr = Counter(arr)
ans = 0
for i in arr:
ans += (arr[i] - 1) * arr[i] // 2
print(ans) | 0 | null | 15,431,021,809,364 | 4 | 166 |
mountain = [int(input()) for _ in range(10)]
mountain.sort()
for _ in -1, -2, -3 : print(mountain[_]) | import math
import collections
K = int(input())
S = input()
L = list(S)
if len(L) <= K:
print(S)
else:
M = L[:K]
print(''.join(M)+'...')
| 0 | null | 9,820,984,449,632 | 2 | 143 |
n = int(input())
s = input()
slime_end = "0"
num = 0
for i in range(n):
if s[i] != slime_end:
num += 1
slime_end = s[i]
print(num) | import math
from math import gcd
INF = float("inf")
import sys
input=sys.stdin.readline
import itertools
from collections import Counter
def main():
n = int(input())
s = input().rstrip()
ans = [s[0]]
now = s[0]
for i in s[1:]:
if i != now:
ans.append(i)
now = i
print(len(ans))
if __name__=="__main__":
main()
| 1 | 170,362,192,219,998 | null | 293 | 293 |
l,r,d=[int(x) for x in input().split()]
x=(r-l)//d
if l%d==0 or r%d==0:
x+=1
print(x) | from itertools import *
N = int(input())
H = []
A = []
for i in range(N):
for j in range(int(input())):
x,y = map(int, input().split())
H+=[[i,x-1,y]]
for P in product([0,1],repeat=N):
for h in H:
if P[h[0]]==1 and P[h[1]]!=h[2]:
break
else:
A+=[sum(P)]
print(max(A)) | 0 | null | 64,891,862,810,748 | 104 | 262 |
n = int(input())
a = [0]+list(map(int,input().split()))
dp = [[0]*2 for _ in range(n+1)]
dp[1][1] = a[1]
dp[2][1] = max(a[1],a[2])
for i in range(3,n+1):
if i % 2 == 1:
dp[i][0] = max(dp[i-1][1],dp[i-2][0]+a[i])
dp[i][1] = dp[i-2][1]+a[i]
else:
dp[i][0] = max(dp[i-1][0],dp[i-2][0]+a[i])
dp[i][1] = max(dp[i-1][1],dp[i-2][1]+a[i])
if n % 2 == 1:
print(dp[-1][0])
else:
print(dp[-1][1])
#print(dp) | import math
K = int(input())
ans = 0
A = {}
for a in range(1, K+1):
A[a] = 0
for a in range(1, K+1):
for b in range(1, K+1):
num = math.gcd(a, b)
A[num] += 1
for c in range(1, K+1):
for k in A.keys():
num = math.gcd(c, k) * A[k]
ans += num
print(ans) | 0 | null | 36,632,638,960,610 | 177 | 174 |
# coding: utf-8
cnt = int()
m = int()
g = []
def insersion_sort(a, n, g):
global cnt
for i in xrange(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
return list(a)
def shell_sort(a, n):
global cnt
global m
global g
cnt = 0
m = 0
g = []
nn = n
while True:
nn /= 2
if nn <= 0:
break
g.append(nn)
m += 1
if n == 1:
m = 1
g = [1]
for i in g:
a = insersion_sort(a, n, i)
return a
def main():
global cnt
global m
global g
n = input()
a = []
for i in xrange(n):
a.append(input())
a = shell_sort(a, n)
print m
print " ".join(map(str, g))
print cnt
for i in xrange(n):
print a[i]
main() | def insertionSort(A, n, g):
cnt=0
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
return cnt,A
def shellSort(A, n):
cnt = 0
G = [1]
flag=True
while flag:
g = G[0]*3+1
if g < n:
G = [g] + G
else:
flag=False
m = len(G)
for i in range(m):
tmp_cnt,tmp_A = insertionSort(A, n, G[i])
cnt += tmp_cnt
print(m)
G_str = (list(map(lambda x:str(x),list(G))))
print(" ".join(G_str))
print(cnt)
for a in A:
print(a)
#print(A)
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
shellSort(A, n)
| 1 | 31,333,711,932 | null | 17 | 17 |
s=input()
for i in range(len(s)):
print('x',end='') | #queue
n,q=(int(i) for i in input().split())
nl=[]
t=[]
et=0
for i in range(n):
na,ti=(j for j in input().split())
# print(t)
nl.append(na)
t.append(int(ti))
i=0
while len(nl)>0:
t[i]-=q
et+=q
# print(t)
if t[i]<=0:
et+=t[i]
print(nl[i]+" "+str(et))
nl.pop(i)
t.pop(i)
i-=1
i+=1
if i>=len(nl):
i=0 | 0 | null | 36,249,028,784,050 | 221 | 19 |
H = int(input())
cnt = 0
while True:
H //= 2
cnt += 1
if H == 0:
break
print(2**cnt-1)
| def exhaustiveSearch(A:list, m:int) -> str:
if m == 0:
return True
if len(A) == 0 or sum(A) < m:
return False
return exhaustiveSearch(A[1:], m) or exhaustiveSearch(A[1:], m - A[0])
if __name__ == '__main__':
n = int(input())
A = list(map(int, input().rstrip().split()))
q = int(input())
M = list(map(int, input().rstrip().split()))
for m in M:
if exhaustiveSearch(A, m):
print('yes')
else:
print('no')
| 0 | null | 39,992,391,194,250 | 228 | 25 |
N, K = map(int, input().split())
SC = list(map(int, input().split()))
T = input()
Q = []
for i in range(len(T)):
if T[i] == "r":
Q.append(0)
elif T[i] == "s":
Q.append(1)
else:
Q.append(2)
my = [0 for i in range(N)]
ans = 0
for i in range(N):
if i < K:
my[i] = (Q[i] - 1) % 3
ans += SC[my[i]]
else:
n = (Q[i] - 1) % 3
if my[i - K] != n:
my[i] = n
ans += SC[my[i]]
else:
if i + K < N:
my[i] = Q[i+K]
print(ans) | n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
ans = []
a,b,c = 0,0,0
for i in range(n):
if i>=k:
if t[i]==ans[i-k]:
ans.append('X')
continue
if t[i] =='r':
ans.append('r')
c += 1
elif t[i]=='s':
ans.append('s')
a += 1
else:
ans.append('p')
b += 1
print(a*r+b*s+c*p) | 1 | 106,969,248,595,068 | null | 251 | 251 |
def f1(s,a,b):
print(s[a:b+1])
return s
def f2(s,a,b):
temp = s[a:b+1]
return s[:a] + temp[::-1] + s[b+1:]
def f3(s,a,b,p):
return s[:a] + p + s[b+1:]
data = input()
q = int(input())
functions = {'print':f1, 'reverse':f2, 'replace':f3}
for i in range(q):
temp = [s if s.isalpha() else int(s) for s in input().split(' ')]
f = temp.pop(0)
data = functions[f](data,*temp) | n=int(input())
a=list(map(int,input().split()))
a.sort()
am=max(a)
dp=[[True,0] for _ in range(am+1)]
count=0
for i in a:
if dp[i][0]==False:
continue
else:
if dp[i][1]==1:
dp[i][0]=False
count-=1
else:
dp[i][1]=1
count+=1
for j in range(2*i,am+1,i):
dp[j][0]=False
print(count) | 0 | null | 8,209,041,123,140 | 68 | 129 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import Counter
N, P = map(int, readline().split())
S = list(map(int, read().rstrip().decode()))
def solve_2(S):
ind = (i for i, x in enumerate(S, 1) if x % 2 == 0)
return sum(ind)
def solve_5(S):
ind = (i for i, x in enumerate(S, 1) if x % 5 == 0)
return sum(ind)
def solve(S,P):
if P == 2:
return solve_2(S)
if P == 5:
return solve_5(S)
S = S[::-1]
T = [0] * len(S)
T[0] = S[0] % P
power = 1
for i in range(1, len(S)):
power *= 10
power %= P
T[i] = T[i-1] + power * S[i]
T[i] %= P
counter = Counter(T)
return sum(x * (x - 1) // 2 for x in counter.values()) + counter[0]
print(solve(S,P))
| import sys
input = sys.stdin.readline
n, m, l = map(int, input().split())
INF = float("INF")
d = [[INF] * n for _ in range(n)]
for i in range(n):
d[i][i] = 0
for i in range(m):
a, b, c = map(int, input().split())
a -= 1
b -= 1
d[a][b] = c
d[b][a] = c
for k in range(n):
for i in range(n):
for j in range(n):
if d[i][j] > d[i][k] + d[k][j]:
d[i][j] = d[i][k] + d[k][j]
# print()
# print(*d, sep='\n')
for i in range(n):
for j in range(n):
if i == j:
continue
if d[i][j] <= l:
d[i][j] = 1
else:
d[i][j] = INF
for k in range(n):
for i in range(n):
for j in range(n):
if d[i][j] > d[i][k] + d[k][j]:
d[i][j] = d[i][k] + d[k][j]
# print()
# print(*d, sep='\n')
q = int(input())
for i in range(q):
s, t = map(int, input().split())
s -= 1
t -= 1
if d[s][t] == INF:
print(-1)
else:
print(d[s][t]-1) | 0 | null | 115,887,954,855,620 | 205 | 295 |
N, K = map(int, input().split())
A = list(map(int, input().split()))
def is_ok(x):
cnt = 0
for a in A:
cnt += a // x
if a % x == 0:
cnt -= 1
return cnt <= K
ng = 0
ok = 10**9
while ok - ng > 1:
mid = (ok + ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
print(ok) | import sys
n = sys.stdin.readline().rstrip()
l = len(n)
def main():
dp0 = [None] * (l + 1)
dp1 = [None] * (l + 1)
dp0[0] = 0
dp1[0] = 1
for i in range(l):
d = int(n[i])
dp0[i+1] = min(dp0[i]+d, dp1[i]+10-d)
dp1[i+1] = min(dp0[i]+d+1, dp1[i]+10-d-1)
return dp0[l]
if __name__ == '__main__':
ans = main()
print(ans) | 0 | null | 38,846,632,606,418 | 99 | 219 |
import sys
MOD = 10**9+7
def main():
input = sys.stdin.readline
N,K=map(int, input().split())
ans=Mint()
cnt=[Mint() for _ in range(K+1)]
for g in range(K,0,-1):
cnt[g]+=pow(K//g,N,MOD)
for h in range(g+g,K+1,g):
cnt[g]-=cnt[h]
ans+=g*cnt[g]
print(ans)
class Mint:
def __init__(self, value=0):
self.value = value % MOD
if self.value < 0: self.value += MOD
@staticmethod
def get_value(x): return x.value if isinstance(x, Mint) else x
def inverse(self):
a, b = self.value, MOD
u, v = 1, 0
while b:
t = a // b
b, a = a - t * b, b
v, u = u - t * v, v
if u < 0: u += MOD
return u
def __repr__(self): return str(self.value)
def __eq__(self, other): return self.value == other.value
def __neg__(self): return Mint(-self.value)
def __hash__(self): return hash(self.value)
def __bool__(self): return self.value != 0
def __iadd__(self, other):
self.value = (self.value + Mint.get_value(other)) % MOD
return self
def __add__(self, other):
new_obj = Mint(self.value)
new_obj += other
return new_obj
__radd__ = __add__
def __isub__(self, other):
self.value = (self.value - Mint.get_value(other)) % MOD
if self.value < 0: self.value += MOD
return self
def __sub__(self, other):
new_obj = Mint(self.value)
new_obj -= other
return new_obj
def __rsub__(self, other):
new_obj = Mint(Mint.get_value(other))
new_obj -= self
return new_obj
def __imul__(self, other):
self.value = self.value * Mint.get_value(other) % MOD
return self
def __mul__(self, other):
new_obj = Mint(self.value)
new_obj *= other
return new_obj
__rmul__ = __mul__
def __ifloordiv__(self, other):
other = other if isinstance(other, Mint) else Mint(other)
self *= other.inverse()
return self
def __floordiv__(self, other):
new_obj = Mint(self.value)
new_obj //= other
return new_obj
def __rfloordiv__(self, other):
new_obj = Mint(Mint.get_value(other))
new_obj //= self
return new_obj
if __name__ == '__main__':
main() | n,k=map(int,input().split())
cnt=[0]*(k+1)
mod=10**9+7
for i in range(1,k+1):
cnt[i]=pow(k//i,n,mod)
#print(cnt)
for i in range(k):
baisu=k//(k-i)
for j in range(2,baisu+1):
cnt[k-i]=(cnt[k-i]-cnt[(k-i)*j]+mod)%mod
ans=0
for i in range(1,k+1):
ans+=i*cnt[i]
ans%=mod
print(ans) | 1 | 36,740,976,986,740 | null | 176 | 176 |
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+c*c == a*a or a*a+c*c == b*b:
print("YES")
else:
print("NO") | import sys
data_list = sys.stdin.readlines()
data_length = int(data_list.pop(0))
for x in xrange(data_length):
lines = map(int, data_list[x].strip().split())
lines.sort(reverse = True)
if lines[0]**2 == (lines[1]**2 + lines[2]**2):
print "YES"
else:
print "NO" | 1 | 347,253,370 | null | 4 | 4 |
if __name__ == "__main__":
a, b, c = map( int, input().split() )
if a < b < c:
print("Yes")
else:
print("No") | s = input()
q = int(input())
head = []
tail = []
flip = 0
for i in range(q):
query = input().split()
if query[0] == "1":
flip ^=1
else:
f = int(query[1]) - 1
c = query[2]
if (f ^ flip) == 0:
head.append(c)
else:
tail.append(c)
if flip:
head, tail = tail, head
s = s[::-1]
head = "".join(head)
tail = "".join(tail)
print(head[::-1] + s + tail) | 0 | null | 28,644,836,288,260 | 39 | 204 |
import itertools
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
w = 0
x = 0
S = []
T = []
for i in range(N):
S.append(i+1)
for j in itertools.permutations(S):
T.append(list(j))
a = T.index(P)
b = T.index(Q)
print(abs(a-b))
| N = int(input())
ACcount = 0
WAcount = 0
TLEcount = 0
REcount = 0
for i in range(N):
S=input()
if S == "AC":
ACcount = ACcount + 1
elif S == "WA":
WAcount = WAcount + 1
elif S == "TLE":
TLEcount = TLEcount + 1
elif S == "RE":
REcount = REcount + 1
print("AC x", ACcount)
print("WA x", WAcount)
print("TLE x", TLEcount)
print("RE x", REcount)
| 0 | null | 54,764,842,365,408 | 246 | 109 |
D = list(input())
ans = 0
cnt = 0
for i in D:
if i == 'R':
cnt += 1
else:
cnt = 0
if ans < cnt:
ans = cnt
print(ans) | s = str(input())
array = list(s)
if array.count("R")==3:print(3)
elif s[1]==("R") and array.count("R")==2:print(2)
elif array.count("R")==0:print(0)
else:print(1) | 1 | 4,904,365,826,130 | null | 90 | 90 |
#!/usr/bin/env python
label = list(map(int, input().split()))
command = list(input())
faces = [1, 2, 3, 4, 5, 6]
def dice(command):
if command == "N":
faces[0], faces[1], faces[4], faces[5] = faces[1], faces[5], faces[0], faces[4]
elif command == "S":
faces[0], faces[1], faces[4], faces[5] = faces[4], faces[0], faces[5], faces[1]
elif command == "E":
faces[0], faces[2], faces[3], faces[5] = faces[3], faces[0], faces[5], faces[2]
else: # command W
faces[0], faces[2], faces[3], faces[5] = faces[2], faces[5], faces[0], faces[3]
for c in command:
dice(c)
print(label[faces[0] - 1])
| class Dice:
def __init__(self,s1,s2,s3,s4,s5,s6):
self.s1 = s1
self.s2= s2
self.s3= s3
self.s4= s4
self.s5 = s5
self.s6= s6
def east(self):
prev_s1 = self.s1 #prev_s1を固定していないと以前の値が後述でs1に値を代入するとき変わってしまう。
prev_s3 = self.s3
prev_s4 = self.s4
prev_s6 = self.s6
self.s1 = prev_s4
self.s3 = prev_s1
self.s4 = prev_s6
self.s6 = prev_s3
def west(self):
prev_s1 = self.s1
prev_s3 = self.s3
prev_s4 = self.s4
prev_s6 = self.s6
self.s1 = prev_s3
self.s3 = prev_s6
self.s4 = prev_s1
self.s6 = prev_s4
def south(self):
prev_s1 = self.s1
prev_s2 = self.s2
prev_s5 = self.s5
prev_s6 = self.s6
self.s1 = prev_s5
self.s2 = prev_s1
self.s5 = prev_s6
self.s6 = prev_s2
def north(self):
prev_s1 = self.s1
prev_s2 = self.s2
prev_s5 = self.s5
prev_s6 = self.s6
self.s1 = prev_s2
self.s2 = prev_s6
self.s5 = prev_s1
self.s6 = prev_s5
def top(self):
return self.s1
s1,s2,s3,s4,s5,s6 = map(int,input().split())
dice = Dice(s1,s2,s3,s4,s5,s6)
order = input()
for c in order:
if c =='N':
dice.north()
elif c =='S':
dice.south()
elif c =='E':
dice.east()
elif c == 'W':
dice.west()
print(dice.top())
| 1 | 224,450,671,390 | null | 33 | 33 |
#coding:utf-8
data = [int(i) for i in input().split()]
a = data[0]
b = data[1]
if a == b:
print("a == b")
elif a > b:
print("a > b")
else:
print("a < b") | [a,b] = input().split()
a = int(a)
b= int(b)
if(a == b):
print('a == b')
elif(a > b):
print("a > b")
else:
print("a < b") | 1 | 355,006,854,950 | null | 38 | 38 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, T, *AB = map(int, read().split())
A = AB[::2]
B = AB[1::2]
dp1 = [[0] * T for _ in range(N + 1)]
for i in range(N):
for t in range(T):
if 0 <= t - A[i]:
dp1[i + 1][t] = dp1[i][t - A[i]] + B[i]
if dp1[i + 1][t] < dp1[i][t]:
dp1[i + 1][t] = dp1[i][t]
dp2 = [[0] * T for _ in range(N + 1)]
for i in range(N - 1, -1, -1):
for t in range(T):
if 0 <= t - A[i]:
dp2[i][t] = dp2[i + 1][t - A[i]] + B[i]
if dp2[i][t] < dp2[i + 1][t]:
dp2[i][t] = dp2[i + 1][t]
ans = 0
for i in range(N):
tmp = max(dp1[i][t] + dp2[i + 1][T - t - 1] for t in range(T)) + B[i]
if ans < tmp:
ans = tmp
print(ans)
return
if __name__ == '__main__':
main()
| N = int(input())
S, T = input().split()
L = [S[i]+T[i] for i in range(N)]
print(*L, sep="") | 0 | null | 131,818,155,924,950 | 282 | 255 |
n = int(input())
s = input()
ans = ''
for c in s:
nc_ord = ord(c) + n
while nc_ord > ord('Z'):
nc_ord -= 26
ans += chr(nc_ord)
print(ans)
| N = int(input())
S = list(str(input()))
l = [chr(ord('A')+i) for i in range(26)]
p = []
for t in range(len(S)):
for i in range(26):
if S[t] == l[i]:
k = (i+N)%26
p.append(l[k])
print(''.join(map(str,p))) | 1 | 134,407,076,471,006 | null | 271 | 271 |
n = map(int,list(input()))
ans = "No"
if sum(n) % 9 == 0:
ans = "Yes"
print(ans) | a = []
while True:
l = list(map(int,input().split()))
if l == [0,0]:
break
a.append(l)
for i in range(len(a)):
H,W = a[i]
for i in range(H):
print("#"*W)
print("") | 0 | null | 2,574,306,159,402 | 87 | 49 |
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
class SWAG(object):
def __init__(self,dot):
self.__front=[]
self.__back=[]
self.__dot=dot
def __bool__(self):
return True if(self.__front or self.__back) else False
def __len__(self):
return len(self.__front)+len(self.__back)
def append(self,x):
back=self.__back
if(not back): back.append((x,x))
else: back.append((x,self.__dot(back[-1][1],x)))
def popleft(self):
assert(self)
front=self.__front; back=self.__back
if(not front):
front.append((back[-1][0],back[-1][0]))
back.pop()
while(back):
front.append((back[-1][0],self.__dot(back[-1][0],front[-1][1])))
back.pop()
front.pop()
def sum(self):
assert(self)
front=self.__front; back=self.__back
if(not front): return back[-1][1]
elif(not back): return front[-1][1]
else: return self.__dot(front[-1][1],back[-1][1])
def resolve():
n,m=map(int,input().split())
S=list(map(int,input()))
swag=SWAG(min)
dp=[INF]*(n+1)
dp[n]=0
for i in range(n-1,-1,-1):
if(i+1+m<=n): swag.popleft()
swag.append(dp[i+1])
if(S[i]==1): continue
dp[i]=swag.sum()+1
if(dp[0]==INF):
print(-1)
return
ans=[]
now=0
next=0
while(now!=n):
next+=1
if(dp[next]!=INF and dp[now]!=dp[next]):
ans.append(next-now)
now=next
print(*ans)
resolve() | m, d = input().split(' ')
M, D = input().split(' ')
if D == '1':
print(1)
else:
print(0) | 0 | null | 131,587,324,954,540 | 274 | 264 |
n = int(input())
sum = 0
for i in range(n) :
if (i+1)%3 != 0 and (i+1)%5 != 0 :
sum += i+1
print(sum) | def main():
n = int(input())
ans = 0
for i in range(1, n + 1):
if (i % 3 != 0) and (i % 5 != 0):
ans += i
print(ans)
main()
| 1 | 34,961,725,061,418 | null | 173 | 173 |
#!/usr/bin/env python3
from queue import Queue
def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))
def main():
H, W = MII()
S = [input() for _ in range(H)]
dp = [[10**9] * W for _ in range(H)]
dp[0][0] = (S[0][0] == '#') + 0
for i in range(H):
for j in range(W):
a = dp[i-1][j]
b = dp[i][j-1]
if S[i-1][j] == '.' and S[i][j] == '#':
a += 1
if S[i][j-1] == '.' and S[i][j] == '#':
b += 1
dp[i][j] = min(dp[i][j], a, b)
print(dp[H-1][W-1])
if __name__ == '__main__':
main() | 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))
n, k = inm()
H = inl()
H.sort()
def solve():
if k >= n:
return 0
return sum(H[: n - k])
print(solve())
| 0 | null | 64,396,200,078,080 | 194 | 227 |
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
flush = sys.stdin.flush()
def solve():
x,y = LI()
ans = 0
f = [300000,200000,100000,0]
if x == 1 and y == 1:
print(1000000)
else:
ans = f[min(3,x-1)]+f[min(3,y-1)]
print(ans)
return
#Solve
if __name__ == "__main__":
solve()
| n, p = map(int, input().split())
s = input()
if 10%p==0:
ans = 0
for r in range(n):
if int(s[r])%p == 0:
ans += r+1
print(ans)
exit()
d = [0]*(n+1)
ten = 1
for i in range(n-1, -1, -1):
a = int(s[i])*ten%p
d[i] = (d[i+1]+a)%p
ten *= 10
ten %= p
cnt = [0]*p
ans = 0
for i in range(n, -1, -1):
ans += cnt[d[i]]
cnt[d[i]] += 1
print(ans) | 0 | null | 99,838,399,562,640 | 275 | 205 |
def main():
N = int(input())
A = []
B = []
for _ in range(N):
a, b = (int(i) for i in input().split())
A.append(a)
B.append(b)
A.sort()
B.sort()
ans = -1
if N % 2 == 1:
ans = B[N//2] - A[N//2] + 1
else:
a = (A[N//2] + A[N//2 - 1])/2
b = (B[N//2] + B[N//2 - 1])/2
ans = b - a + 1
ans += ans - 1
print(int(ans))
if __name__ == '__main__':
main()
| main=list(map(int,input().split()));count=0
for i in range(main[0],main[1]+1):
if(i%main[2]==0): count=count+1
print(count) | 0 | null | 12,414,940,483,268 | 137 | 104 |
import sys
x=[]
n=input()
for i in range(3,n+1):
if i%3==0:
x.append(i)
else:
j=i
while j!=0:
if j%10==3:
x.append(i)
break
j=j/10
X=iter(x)
for i in X:
sys.stdout.write(' ')
sys.stdout.write('%d'%i)
print('') | from collections import Counter
N = int(input())
A = list(map(int,input().split()))
C_A = Counter(A)
S = 0
for ca in C_A:
S += ca * C_A[ca]
Q = int(input())
for q in range(Q):
b, c = map(int,input().split())
S += (c - b) * C_A[b]
C_A[c] += C_A[b]
C_A[b] = 0
print(S)
| 0 | null | 6,542,421,941,430 | 52 | 122 |
from collections import deque
n = int(input())
d = [-1]*n
d[0] = 0
M = []
for i in range(n):
adj = list(map(int,input().split()))
if adj[1] == 0:
M += [[]]
else:
M += [adj[2:]]
Q = deque([0])
while Q != deque([]):
u = Q.popleft()
for i in range(len(M[u])):
v = M[u][i]-1
if d[v] == -1:
d[v] = d[u] + 1
Q.append(v)
for i in range(n):
print(i+1,d[i])
| n = int(input())
adj = [None]
for i in range(n):
adji = list(map(int, input().split()[2:]))
adj.append(adji)
isSearched = [None] + [False] * n
distance = [None] + [-1] * n
def BFS(u):
d = 0
isSearched[u] = True
distance[u] = d
edge = [u]
while edge:
q = list(edge)
edge = []
d += 1
for ce in q:
for ne in adj[ce]:
if not isSearched[ne]:
isSearched[ne] = True
edge.append(ne)
distance[ne] = d
BFS(1)
for i, x in enumerate(distance[1:], start=1):
print(i, x) | 1 | 4,452,915,780 | null | 9 | 9 |
from __future__ import division, print_function, unicode_literals
from future_builtins import *
N = int(raw_input())
A = list(map(int, raw_input().split()))
print(" ".join(map(str, A)))
for i in xrange(1,N):
j, p = i-1, A[i]
while j >= 0 and A[j] > p:
A[j+1] = A[j]
j -= 1
A[j+1] = p
print(" ".join(map(str, A))) | N=int(input())
arr=list(map(int,input().split()))
print(' '.join(map(str,arr)))
for key in range(1,len(arr)):
temp=arr[key]
i=key-1
while i>=0 and arr[i]>temp:
arr[i+1]=arr[i]
i-=1
arr[i+1]=temp
print(' '.join(map(str,arr))) | 1 | 5,907,578,100 | null | 10 | 10 |
import sys
read = sys.stdin.read
def main():
l = int(input())
print((l/3)**3)
if __name__ == '__main__':
main()
| import sys
def input(): return sys.stdin.readline().rstrip()
def main():
k = int(input())
keta = 1
mod = 7%k
while keta < 10**7:
if mod==0:
print(keta)
break
keta += 1
mod = (mod*10 + 7)%k
else:
print(-1)
if __name__=='__main__':
main() | 0 | null | 26,698,267,014,710 | 191 | 97 |
s=input()[::-1]+'0'
d=[0,1]
for c in s:
x=int(c)
d=[x+min(d[0],1+d[1]),min(1+d[0],d[1])+9-x]
print(min(d))
| print('x'*len(input())) | 0 | null | 72,063,305,387,700 | 219 | 221 |
#!/usr/bin/env python3
def main():
N = int(input())
print(-(-N // 2))
main()
| R =int(input())
print(R*3.14159*2) | 0 | null | 45,008,484,242,592 | 206 | 167 |
n, k = map(int, input().split())
a = list(map(int, input().split()))
def f(m):
res = sum([-(-x//m)-1 for x in a])
return res <= k
l, r = 0, 10**9+10
while r-l > 1:
x = (l+r)//2
if f(x): r = x
else: l = x
print(r)
| def main():
n,k = map(int,input().split())
A = list(map(int,input().split()))
left = 0
right = max(A)
while abs(right-left)>1:
cent = (right+left)//2
ct = 0
for a in A:
ct+=a//cent
if a%cent==0:
ct-=1
if ct <= k:
right=cent
else:
left=cent
print(right)
main()
| 1 | 6,570,731,326,624 | null | 99 | 99 |
import sys
def solve(h):
if h == 1:
return 1
else:
return 1 + 2 * solve(h // 2)
def main():
input = sys.stdin.buffer.readline
h = int(input())
print(solve(h))
if __name__ == "__main__":
main()
| H = int(input())
cnt = 0
res = 0
while H > 1:
H = H //2
cnt += 1
res += 2**cnt
print(res+1) | 1 | 80,091,882,492,650 | null | 228 | 228 |
n = int(input())
a = list(map(int, input().split()))
i = 1
if 0 in a:
i = 0
else:
for j in range(n):
if i >= 0:
i = i * a[j]
if i > 10 ** 18:
i = -1
print(int(i)) | def main():
n = int(input())
A = [int(x) for x in input().split()]
if 0 in A:
print(0)
return
mul = 1
for a in A:
mul *= a
if mul > 1e18:
print(-1)
return
print(mul)
main() | 1 | 16,103,452,865,148 | null | 134 | 134 |
r, c = map(int, input().split())
element = [list(map(int, input().split())) for i in range(r)]
for i in range(r):
element[i].append(sum(element[i]))
for i in range(r):
for j in range(c):
print(element[i][j],end="")
print(' ',end="")
print(element[i][c])
for i in range(c):
num = 0
for j in range(r):
num += element[j][i]
print(num, end="")
print(' ',end="")
b = 0
for i in range(r):
b += element[i][c]
print(b)
| r, c = map(int, input().split())
l = []
for i in range(r):
l.append(list(map(int, input().split())))
l[i] += [sum(l[i])]
print(*l[i])
l = list(zip(*l))
for i in range(c): print(sum(l[i]), end = " ")
print(sum(l[c]))
| 1 | 1,363,190,726,418 | null | 59 | 59 |
import numpy as np
n,k = map(int,input().split())
m = 10**9 + 7
gcds = np.zeros(k+1, int)
ans = 0
for i in range(k,0,-1):
tmp = pow(k//i,n, m)
for j in range(i*2,k+1,i):
tmp -= gcds[j]
ans = (ans + tmp*i)%m
gcds[i] = tmp
print(ans) | while 1:
x,y=map(int,raw_input().split())
if x==y==0: exit()
else: print min(x,y),max(x,y) | 0 | null | 18,706,323,276,550 | 176 | 43 |
a=int(input())
hours=a//3600
minutes_num=a%3600
minutes=minutes_num//60
seconds=a%60
print(str(hours)+":"+str(minutes)+":"+str(seconds))
| import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
N = I()
S = _S()
print(S.count("ABC"))
main()
| 0 | null | 49,766,961,601,280 | 37 | 245 |
cnt = 0
n = int(input())
lst = list(map(int, input().split()))
for i in range(n):
m = i
for j in range(i, n):
if lst[j] < lst[m]:
m = j
if m != i:
lst[i], lst[m] = lst[m], lst[i]
cnt += 1
print(*lst)
print(cnt) | import numpy as np
N = int(input())
A = list(map(int,input().split()))
A = np.array(A)
A.sort()
d = {}
for a in A:
d.setdefault(a,0)
d[a] += 1
sieve = [True] * (A[-1] + 1)
for a in A:
if d[a] > 1:
sieve[a] = False
for i in range(a + a, A[-1] + 1, a):
sieve[i] = False
print(sum(1 for a in A if sieve[a])) | 0 | null | 7,273,266,734,240 | 15 | 129 |
from collections import deque
H, W = map(int, input().split())
maze = [input() for _ in range(H)]
v = {(1,0), (-1,0), (0,1), (0,-1)}
q = deque()
ans = 0
for i in range(H):
for j in range(W):
if maze[i][j] == '.':
#bfs
dist = [[-1 for _ in range(W)] for _ in range(H)]
dist[i][j] = 0
q.append([j, i])
while len(q) > 0:
now = q.popleft()
x, y = now[0], now[1]
d = dist[y][x]
for dx, dy in v:
nx, ny = x+dx, y+dy
if 0<=nx<W and 0<=ny<H and dist[ny][nx]==-1 and maze[ny][nx]=='.':
dist[ny][nx] = d+1
q.append([nx, ny])
ans = max(ans, d)
print(ans) | r = float(input())
pi = 3.141592653589793
print(pi*r**2, 2*pi*r)
| 0 | null | 47,525,268,443,000 | 241 | 46 |
N, M = map(int, input().split())
A = list(map(int, input().split()))
print(max(-1, N-sum(A)))
| import sys
sys.setrecursionlimit(100000000)
S = int(input())
mod = 10**9+7
def dfs_memo(n):
memo = [0]*(n+1)
memo[3] = 1
def dfs(n):
if n < 3:
return 0
elif memo[n] != 0:
return memo[n]
memo[n] = dfs(n-1)+dfs(n-3)
return memo[n]
return dfs(n)
if S <3:
print(0)
else:
print(dfs_memo(S)%mod) | 0 | null | 17,730,156,824,768 | 168 | 79 |
from sys import stdin
n = int(stdin.readline())
ans = 0
dp = [0]*(n+1)
for i in range(1,n+1):
j = i
while j <= n:
dp[j] += 1
j += i
for i in range(1,n+1):
ans += dp[i]*i
print(ans) | d=int(input())
C=[int(i) for i in input().split()]
s=[[int(i) for i in input().split()] for q in range(d)]
sco=0
L=[0 for i in range(26)]
ans=[]
#calc
for i in range(d):
mayou=0
est=s[i][0]+C[0]*(i+1-L[0])
for p in range(1,26):
if s[i][p]+C[p]*(i+1-L[p]) > est:
mayou=p
est=s[i][p]+C[p]*(i+1-L[p])
ans.append(mayou)
L[mayou]=i+1
print(mayou+1) #output
| 0 | null | 10,333,633,865,438 | 118 | 113 |
s = []
F = {
'+': lambda: s.append(s.pop() + s.pop()),
'-': lambda: s.append(-s.pop() + s.pop()),
'*': lambda: s.append(s.pop() * s.pop())
}
for op in input().split():
if op in F:
F[op]()
else:
s.append(int(op))
print(s.pop()) | def main():
n = [x for x in input().split(' ')]
s = []
for i in n:
if i == '+':
a = s.pop()
b = s.pop()
s.append(a + b)
elif i == '-':
b = s.pop()
a = s.pop()
s.append(a - b)
elif i == '*':
a = s.pop()
b = s.pop()
s.append(a * b)
else:
s.append(int(i))
print(s.pop())
if __name__ == '__main__':
main() | 1 | 35,134,166,130 | null | 18 | 18 |
a,b=input().split()
X=a*int(b)
Y=b*int(a)
print(min(X,Y)) | def main():
a, b = input().split()
if a < b:
ans = a * int(b)
else:
ans = b * int(a)
print(ans)
if __name__ == '__main__':
main()
| 1 | 84,172,448,154,560 | null | 232 | 232 |
def resolve():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
for i in range(K, N):
if A[i-K] < A[i]:
print("Yes")
else:
print("No")
if '__main__' == __name__:
resolve() | x = {"S": list(range(1, 14)), "H": list(range(1, 14)),
"C": list(range(1, 14)), "D": list(range(1, 14))}
n = int(input())
for i in range(n):
tmp = input().split()
key = tmp[0]
num = int(tmp[1])
x[key].remove(num)
keys = ["S", "H", "C", "D"]
for key in keys:
if len(x[key])==0:
pass
else:
for i in x[key]:
print(key, i) | 0 | null | 4,037,255,000,000 | 102 | 54 |
import math
x1, y1, x2, y2 = [float(i) for i in input().split()]
bottom = x2 - x1
height = y2 - y1
print(math.sqrt(bottom**2 + height**2)) | import os,sys
s=input()
n=len(s)
if s[n-1]=='s':
s=s+'es'
else:
s=s+'s'
print(s) | 0 | null | 1,295,309,121,176 | 29 | 71 |
n=int(input())
s=input()
ans='No'
if n%2==0:
if s[:n//2]==s[n//2:]:
ans='Yes'
print(ans)
| n = int(input())
s = input()
if n % 2 != 0:
print("No")
else:
h = n // 2
print("Yes" if s[0:h] == s[h:] else "No") | 1 | 146,536,555,746,572 | null | 279 | 279 |
#! /usr/bin/env python3
import sys
sys.setrecursionlimit(10**9)
INF=10**20
def solve(N: int, K: int):
ans = 0
while N >= K:
N //= K
ans += 1
print(ans+1)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
K = int(next(tokens)) # type: int
solve(N, K)
if __name__ == "__main__":
main()
| N,K = map(int,input().split())
i = 0
while True:
if N >= K ** i:
i += 1
else:
break
print(i) | 1 | 64,220,864,623,498 | null | 212 | 212 |
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 = 2*(10**5)+1
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 )
a,b=map(int,input().split())
c=min(a,b)
s=0
for i in range(0,c+1):
s+=cmb(a,i,10**9+7)*cmb(a-1,i,10**9+7)
print(s%(10**9+7)) | N = int(input())
A = list(map(int, input().split()))
p = list(range(N))
p.sort(key=lambda i: A[i], reverse=True)
dp = [[0]*(N + 1) for _ in range(N + 1)]
for i in range(N):
for j in range(i + 1):
pi = p[i]
dp[i+1][j] = max(dp[i+1][j], dp[i][j] + A[pi]*(N - i + j - 1 - pi))
dp[i+1][j+1] = dp[i][j] + A[pi]*(pi - j)
print(max(dp[N]))
| 0 | null | 50,672,545,809,520 | 215 | 171 |
square = []
while True:
data = [int(e) for e in input().split()]
if data[0]==0 and data[1]==0:
break
square.append(data)
for i in range(len(square)):
for j in range(square[i][0]):
for k in range(square[i][1]):
print("#", end="")
print()
print()
| while(True):
H, W = map(int, input().split())
if(H == W == 0):
break
first = False
for i in range(H):
print("#" * W)
print() | 1 | 765,793,636,422 | null | 49 | 49 |
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys
INF = float('inf')
def solve(A: "List[int]"):
return 'bust' if sum(A) >= 22 else 'win'
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
A = [int(next(tokens)) for _ in range(3)] # type: "List[int]"
print(f'{solve(A)}')
if __name__ == '__main__':
main()
| v = sum(map(int,list(input().split())))
if(v > 21):
print('bust')
else:
print('win')
| 1 | 119,017,145,404,036 | null | 260 | 260 |
N, M, X = map(int,input().split())
C = []
A = []
for _ in range(N):
c, *a = map(int, input().split())
C.append(c)
A.append(a)
ans = -1
for i in range(2**N):
c = 0
R = [0 for _ in range(M)]
for j in range(N):
if (i>>j) % 2:
c += C[j]
for m in range(M):
R[m] += A[j][m]
flag = True
for m in range(M):
if R[m] < X:
flag = False
break
if flag:
if ans == -1:
ans = c
elif ans > c:
ans = c
print(ans) | n = int(input())
a = [int(i) for i in input().split()]
color = [0, 0, 0]
ans = 1
mod = 10 ** 9 + 7
for i in a:
cnt = color.count(i)
ans *= cnt
ans = ans % mod
if ans > 0:
color[color.index(i)] += 1
else:
break
print(ans) | 0 | null | 75,825,994,154,118 | 149 | 268 |
numbers = input()
numbers = numbers.split(" ")
for i in range(3):
numbers[i] = int(numbers[i])
numbers.sort()
print("{0} {1} {2}".format(numbers[0], numbers[1], numbers[2])) | import sys
nums = sorted( [ int( val ) for val in sys.stdin.readline().split( " " ) ] )
print( "{:d} {:d} {:d}".format( nums[0], nums[1], nums[2] ) ) | 1 | 411,704,134,310 | null | 40 | 40 |
x = input().split()
x[0], x[1], x[2] = x[2], x[0], x[1]
print(x[0]+' '+x[1]+' '+x[2]) | N = int(input())
cnt = 0
for _ in range(N):
a, b = map(int, input().split())
if a == b:
cnt += 1
else:
cnt = 0
if cnt == 3:
print('Yes')
exit()
print('No') | 0 | null | 20,318,571,137,380 | 178 | 72 |
A, B = map(int, input().split())
C = A - (B*2)
C = 0 if C < 0 else C
print(C) | from collections import deque
n,p=map(int ,input().split())
que=deque([])
for i in range(n):
name,time=input().split()
time=int(time)
que.append([name,time])
t=0
while len(que)>0:
atop=que.popleft()
spend=min(atop[1],p)
atop[1]-=spend
t+=spend
if(atop[1]==0):
print(atop[0],t)
else:
que.append(atop) | 0 | null | 83,475,287,656,370 | 291 | 19 |
#!/usr/bin python3
# -*- coding: utf-8 -*-
def main():
H, W = map(int,input().split())
sth, stw = 0, 0
glh, glw = H-1, W-1
INF = 10000
Gmap = [list(input()) for _ in range(H)]
Dist = [[INF]*W for _ in range(H)]
direc = {(1,0), (0,1)}
if Gmap[0][0]=='#':
Dist[0][0]=1
else:
Dist[0][0]=0
for h in range(H):
for w in range(W):
nw = Gmap[h][w]
for d in direc:
hs, ws = h + d[0], w + d[1]
if 0<=hs<H and 0<=ws<W:
cr = Gmap[hs][ws]
Dist[hs][ws] = min(Dist[hs][ws], Dist[h][w] + (cr=='#' and nw=='.'))
print(Dist[glh][glw])
if __name__ == '__main__':
main() | H, W = map(int, input().split())
L = [input() for _ in range(H)]
inf = 10**9
dp = [[inf] * W for _ in range(H)]
#[0][0]を埋める
if (L[0][0] == '.'):
dp[0][0] = 0
else:
dp[0][0] = 1
for i in range(H):
for j in range(W):
#[0][0]の時は無視
if (i == 0 and j == 0):
continue
#→の場合。一個前のマス。
a = dp[i][j - 1]
#↓の場合。一個前のマス。
b = dp[i - 1][j]
#.から#に移動するときだけ操作が(1回)必要
if (L[i][j - 1] == "." and L[i][j] == "#"):
a += 1
if (L[i - 1][j] == '.' and L[i][j] == '#'):
b += 1
# min(dp[i][j],a,b)でもいいが結局問題になるのはa,bの比較だけでは?
dp[i][j] = min(a, b)
print(dp[-1][-1]) | 1 | 49,251,519,745,570 | null | 194 | 194 |
num_freebies = int(input())
freebies = []
for _ in range(num_freebies):
freebies.append(input())
print(len(set(freebies)))
| N = int(input())
S = set(input() for _ in range(N))
print(len(S))
| 1 | 30,377,079,761,340 | null | 165 | 165 |
a=int(input())
b,c=input().split()
b=int(b)
c=int(c)
if b%a==0 or c%a==0:
print("OK")
else:
if int(b/a)==int(c/a):
print("NG")
else:
print("OK") | a,b,c,d = map(int,input().split())
cnt = d-a
if cnt > 0:
num = 1*a
cnt -=b
if cnt > 0:
num = a + (d-a-b)*(-1)
else:
num = 1*d
print(num) | 0 | null | 24,196,416,818,462 | 158 | 148 |
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
tmp = []
if n % i == 0:
tmp.append(i)
tmp.append(n//i)
if(len(tmp)>0):
divisors.append(sum(tmp))
return divisors
def main5():
n = int(input())
k = make_divisors(n)
print(min(k)-2)
if __name__ == '__main__':
main5()
| # -*- coding: utf-8 -*-
num = int(raw_input())
a = int(raw_input())
b = int(raw_input())
diff = b - a
pre_min = min(a,b)
counter = 2
while counter < num:
current_num = int(raw_input())
if diff < current_num - pre_min:
diff = current_num - pre_min
if pre_min > current_num:
pre_min = current_num
counter += 1
print diff | 0 | null | 80,577,308,507,680 | 288 | 13 |
# 参考 : https://atcoder.jp/contests/abc165/submissions/16921279
# 参考 : https://atcoder.jp/contests/abc165/submissions/16832189
from collections import deque
n,m,q = map(int,input().split())
l = [list(map(int,input().split())) for i in range(q)]
a,b,c,d = [list(i) for i in zip(*l)]
# 数列 A の基(最初は1を入れておく)
queue = deque([[1]])
ans = 0
# 数列 A の候補がなくなる(キューが空になる)まで探索
while queue:
# 数列 A を前から一つ取り出す
x = queue.popleft()
# 数列 A が長さ N か
if len(x) == n:
s = 0
# 実際に何点取得できるか
for i in range(q):
if x[b[i]-1] - x[a[i]-1] == c[i]:
s += d[i]
ans = max(ans,s)
else:
# 違う場合、後ろに数字を付け足す
# 付け足す数字は取り出した数列 A の一番後ろの値から M まで
# 最終的に長さが 1 , 2 ... N となり、if の条件を満たすようになる
for j in range(x[-1],m+1):
y = x + [j]
queue.append(y)
print(ans)
# 制約
# 2 <= N <= 10
# 1 <= M <= 50
# 1 <= Q <= 50
# なのでこの探索は間に合う
# 入力例 1 は A[1,3,4]
# 入力例 2 は A[1,1,1,4]
# 入力例 3 は A[1,1,1,1,1,1,1,1,1,10]
# が最大得点となる |
X = int(input())
SUM = 0
(X * 1000 / 500)
Z = X // 500
A = X % 500
SUM = SUM + (Z * 1000)
B = A // 5
SUM = SUM + (B * 5)
print(int(SUM)) | 0 | null | 34,884,350,398,170 | 160 | 185 |
class Info:
def __init__(self,arg_start,arg_end,arg_S):
self.start = arg_start
self.end = arg_end
self.S = arg_S
LOC = []
POOL = []
line = input()
loc = 0
sum_S = 0
for ch in line:
if ch == '\\':
LOC.append(loc)
elif ch == '/':
if len(LOC) == 0:
continue
tmp_start = int(LOC.pop())
tmp_end = loc
tmp_S = tmp_end-tmp_start;
sum_S += tmp_S;
#既に突っ込まれている池の断片が、今回の断片の部分区間になるなら統合する
while len(POOL) > 0:
if POOL[-1].start > tmp_start and POOL[-1].end < tmp_end:
tmp_S += POOL[-1].S
POOL.pop()
else:
break
POOL.append(Info(tmp_start,tmp_end,tmp_S))
else:
pass
loc += 1
print("%d"%(sum_S))
print("%d"%(len(POOL)),end = "")
while len(POOL) > 0:
print(" %d"%(POOL[0].S),end = "") #先頭から
POOL.pop(0)
print()
| from sys import stdin
inp = lambda : stdin.readline().strip()
d, t, s = [int(x) for x in inp().split()]
if d / s <= t:
print('Yes')
else:
print('No') | 0 | null | 1,780,830,512,018 | 21 | 81 |
for i in range(1, 10):
a=i
b=1
while True:
print(a,"x",b,"=",a*b,sep="")
if b==9:
break
b+=1
| import numpy as np
#基本入力
D = int(input())
c =list(map(int,input().split()))
s = []
for i in range(D):
s.append(list(map(int,input().split())))
t = []
for i in range(D):
t.append(int(input()))
#基本入力完了
#得点計算
c = np.array(c)
last_day = np.array([0]*26)
day_pulse = np.array([1]*26)
s = np.array(s)
t = np.array(t)
manzoku = 0
for day in range(1,D+1):
contest_number = t[day-1] #開催するコンテスト種類
manzoku += s[day-1,contest_number-1] #開催したコンテストによる満足度上昇
last_day += day_pulse #経過日数の計算
last_day[contest_number -1 ] = 0 #開催したコンテスト種類の経過日数を0に
manzoku -= sum(c*last_day) #開催していないコンテストによる満足度の減少
print(manzoku)
| 0 | null | 4,929,491,630,048 | 1 | 114 |
def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(input()) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
#############
# Main Code #
#############
def segfunc(x, y):
return min(x, y)
ide_ele = float('inf')
class SegTree:
def __init__(self, init_val, segfunc, ide_ele):
n = len(init_val)
self.segfunc = segfunc
self.ide_ele = ide_ele
self.num = 1 << (n - 1).bit_length()
self.tree = [ide_ele] * 2 * self.num
# 配列の値を葉にセット
for i in range(n):
self.tree[self.num + i] = init_val[i]
# 構築していく
for i in range(self.num - 1, 0, -1):
self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])
def update(self, k, x):
k += self.num
self.tree[k] = x
while k > 1:
self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
k >>= 1
def query(self, l, r):
res = self.ide_ele
l += self.num
r += self.num
while l < r:
if l & 1:
res = self.segfunc(res, self.tree[l])
l += 1
if r & 1:
res = self.segfunc(res, self.tree[r - 1])
l >>= 1
r >>= 1
return res
# 最短手数k回でクリアできるとすると、
# 1 ~ M の内1つをk回選んで合計をNにする
N, M = getNM()
S = input()
trap = set()
for i in range(len(S)):
if S[i] == '1':
trap.add(i)
# これABC011 123引き算と同じでは
# 案1 dpを使う
# dp[i]: iマスに止まる時の最短手順
# dp[i]の時 dp[i + 1] ~ dp[i + M]についてmin(dp[i] + 1, dp[i + j])を見ていく
# 決まったらdpを前から見ていき最短手順がdp[i] - 1になるものを探す(辞書順)
# → M <= 10 ** 5より多分無理
# セグ木使えばいける?
# dp[i] = dp[i - M] ~ dp[i - 1]の最小値 + 1
# dp[i - M] ~ dp[i - 1]の最小値はlogNで求められるので全体でNlogN
dp = [float('inf')] * (N + 1)
dp[0] = 0
seg = SegTree([float('inf')] * (N + 1), segfunc, ide_ele)
seg.update(0, 0)
# dp[i]をレコード
for i in range(1, N + 1):
# もしドボンマスなら飛ばす(float('inf')のまま)
if i in trap:
continue
# dp[i - M] ~ dp[i - 1]の最小値をサーチ
min_t = seg.query(max(0, i - M), i)
seg.update(i, min_t + 1)
dp[i] = min_t + 1
# goalに到達できないなら
if dp[-1] == float('inf'):
print(-1)
exit()
# 何回の試行で到達できるかをグルーピング
dis = [[] for i in range(dp[-1] + 1)]
for i in range(len(dp)):
if dp[i] == float('inf'):
continue
dis[dp[i]].append(i)
# ゴールから巻き戻っていく
now = dp[-1]
now_index = N
ans = []
# 辞書順で1 4 4 < 3 3 3なので
# 一番前にできるだけ小さい数が来るようにする
for i in range(now, 0, -1):
# dp[i] - 1回で到達できる
# 現在地点からMマス以内
# で最も現在地点から遠いところが1つ前のマス
index = bisect_left(dis[i - 1], now_index - M)
# サイコロの目を決める
ans.append(now_index - dis[i - 1][index])
# 現在地点更新
now_index = dis[i - 1][index]
for i in ans[::-1]:
print(i) | import sys
input = sys.stdin.readline
N, M = map(int, input().split())
S = input().rstrip()
A = [0]*N
cnt = 0
S = reversed(S)
for i, s in enumerate(S):
if s=="1":
cnt += 1
A[i] = cnt
else:
cnt = 0
dp = 0
res = []
while dp+M <= N-1:
t = M - A[dp+M]
if t>0:
dp += t
else:
print(-1)
exit()
res.append(t)
res.append(N-dp)
res.reverse()
print(*res) | 1 | 139,015,301,468,128 | null | 274 | 274 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
A = LIST()
n = max(A).bit_length()
cnt = [0]*n
for x in A:
for i, y in enumerate("{:b}".format(x).zfill(n)[::-1]):
if y == "1":
cnt[i] += 1
ans = 0
for i, c in enumerate(cnt):
bit_sum = (c*(N-c)%mod) * pow(2, i, mod) % mod
ans = (ans+bit_sum)%mod
print(ans)
| N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
count = 0
max = A[-1]
if max == 0:
print(0)
exit()
import math
V = [0]*(math.floor(math.log(max, 2))+1)
for i in range (0, N):
B = A[i]
vount = 0
while B > 0:
if B%2 == 0:
B = B//2
vount+=1
else:
B = (B-1)//2
V[vount]+=1
vount+=1
for i in range (0, len(V)):
count+=((V[i]*(N-V[i]))*(2**i))
print(count%(10**9+7)) | 1 | 122,797,269,159,170 | null | 263 | 263 |
#WA
#桁DP
N=str(input())
K=int(input())
L=len(N)
#DP[i][smaller][j]=上からi桁(1<=i<=L)で0でない数字がj個(0<=j<=3)
DP=[[[0]*5 for index1 in range(2)] for index2 in range(L+1)]
#適当に初期設定
DP[0][0][0]=1
for i in range(1,L+1):
#smaller=1->smaller=1
DP[i][1][4]+=DP[i-1][1][4]*10+DP[i-1][1][3]*9
DP[i][1][3]+=DP[i-1][1][3]+DP[i-1][1][2]*9
DP[i][1][2]+=DP[i-1][1][2]+DP[i-1][1][1]*9
DP[i][1][1]+=DP[i-1][1][1]+DP[i-1][1][0]*9
DP[i][1][0]+=DP[i-1][1][0]
n=int(N[i-1])
#smaller=0->smaller=1
#n=0だとsmaller=0->smaller=1がない
#n=1だとsmaller=0->smaller=1のとき必ずjは変化しない
if n==1:
DP[i][1][4]+=DP[i-1][0][4]
DP[i][1][3]+=DP[i-1][0][3]
DP[i][1][2]+=DP[i-1][0][2]
DP[i][1][1]+=DP[i-1][0][1]
DP[i][1][0]+=DP[i-1][0][0]
elif n>=2:
DP[i][1][4]+=DP[i-1][0][4]*n+DP[i-1][0][3]*(n-1)
DP[i][1][3]+=DP[i-1][0][3]+DP[i-1][0][2]*(n-1)
DP[i][1][2]+=DP[i-1][0][2]+DP[i-1][0][1]*(n-1)
DP[i][1][1]+=DP[i-1][0][1]+DP[i-1][0][0]*(n-1)
DP[i][1][0]+=DP[i-1][0][0]
#smaller=0->smaller=0
#n=0だと必ずjは変化しない
if n==0:
DP[i][0][4]+=DP[i-1][0][4]
DP[i][0][3]+=DP[i-1][0][3]
DP[i][0][2]+=DP[i-1][0][2]
DP[i][0][1]+=DP[i-1][0][1]
DP[i][0][0]+=DP[i-1][0][0]
else:
DP[i][0][4]+=DP[i-1][0][4]+DP[i-1][0][3]
DP[i][0][3]+=DP[i-1][0][2]
DP[i][0][2]+=DP[i-1][0][1]
DP[i][0][1]+=DP[i-1][0][0]
print(DP[L][0][K]+DP[L][1][K])
| n, d = map(int, input().split())
cnt = 0
for i in range(n):
Z = list(map(int, input().split()))
X = Z[0]
Y = Z[1]
if X**2 + Y**2 <= d**2:
cnt += 1
print(cnt)
| 0 | null | 40,748,681,416,220 | 224 | 96 |
N, K = [int(_) for _ in input().split()]
P = [int(_) - 1 for _ in input().split()]
C = [int(_) for _ in input().split()]
def f(v, K):
if K == 0:
return 0
if max(v) < 0:
return max(v)
n = len(v)
X = [0]
for i in range(n):
X.append(X[-1] + v[i])
ans = -(10 ** 10)
for i in range(n + 1):
for j in range(i):
if i - j > K:
continue
ans = max(ans, X[i] - X[j])
return(ans)
X = [False for _ in range(N)]
ans = -(10 ** 10)
for i in range(N):
if X[i]:
continue
t = i
v = []
while X[t] is False:
X[t] = True
v.append(C[t])
t = P[t]
n = len(v)
if K > n:
s = sum(v)
x = f(v * 2, n)
if s > 0:
a = s * (K // n - 1) + max(s + f(v * 2, K % n), x)
else:
a = x
else:
a = f(v * 2, K)
ans = max(a, ans)
print(ans)
| n = int(input())
minv = int(input())
maxv = -2*10**9
for i in range(n-1):
r = int(input())
maxv = max(maxv,r-minv)
minv = min(minv,r)
print(maxv) | 0 | null | 2,704,489,465,480 | 93 | 13 |
from collections import Counter
n = int(input())
s = list(input() for i in range(n))
c = Counter(s)
m = max(c.values())
s = sorted(list(set(s)))
for i in range(len(s)):
if c[s[i]] == m:
print(s[i]) | import itertools
N = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
lis = list(itertools.permutations(range(1,N+1)))
a = lis.index(P)+1
b = lis.index(Q)+1
ans = abs(a-b)
print(ans) | 0 | null | 85,396,222,872,470 | 218 | 246 |
# ?????????????????±??????????????????????????¢???????????????????????°?????°??????????????°??????
# ?¨??????\??????????????????????????????
import sys
# ???????????????????????????????????????
input_char = []
for line in sys.stdin:
input_char.append(line)
# ???????????????????????????
count_char = "".join(input_char)
# print(count_char[2])
# ????????????????????¨???????????????
countingChar = [0 for i in range(26)]
# ??????????????¢????????????
for i in range(0, len(count_char)):
if ord(count_char[i].lower()) - ord("a") > -1 and ord(count_char[i].lower()) - ord("a") < 27:
countingChar[ord(count_char[i].lower()) - ord("a")] += 1
# ??????
for i in range(0, 26):
print("{0} : {1}".format(chr(ord("a") + i), countingChar[i])) | N = int(input())
S,T = map(str,input().split())
slist = list(S)
tlist = list(T)
new = ''
for i in range(N):
new += slist[i]
new += tlist[i]
print(new) | 0 | null | 56,768,076,593,760 | 63 | 255 |
n=list(map(str,input().split()));print(n[2]+' '+n[0]+' '+n[1]) | import decimal
a,b = map(decimal.Decimal,input().split())
ans = a*b//1
print(ans)
| 0 | null | 27,262,818,483,428 | 178 | 135 |
from sys import exit
N, R = [int(x) for x in input().split()]
if N >= 10:
print(R)
exit()
else:
print(R + (100 * (10 - N)))
exit()
| a, b = map(int, input().split())
if a==b:
ans = 'Yes'
else:
ans = 'No'
print(ans) | 0 | null | 73,715,854,502,972 | 211 | 231 |
import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque
def r():
return int(input())
def rm():
return map(int,input().split())
def rl():
return list(map(int,input().split()))
n = r()
tens=1
nines=1
eights=1
mod = 10**9+7
for i in range(n):
tens=(tens*10)%mod
nines=(nines*9)%mod
eights=(eights*8)%mod
print((tens-2*nines+eights)%mod) | N = int(input())
MOD = 10**9 + 7
print((pow(10, N, MOD) - ( (pow(9, N, MOD)*2)%MOD - pow(8, N, MOD) )%MOD )%MOD) | 1 | 3,171,586,999,620 | null | 78 | 78 |
s = list(input())
q = int(input())
rvs = []
i = 0
j = 0
p = []
order = []
for i in range(q):
order.append(input().split())
if order[i][0] == "replace":
p = []
p = list(order[i][3])
for j in range(int(order[i][1]), int(order[i][2]) + 1):
s[j] = p[j - int(order[i][1])]
elif order[i][0] == "reverse":
ss = "".join(s[int(order[i][1]):int(order[i][2]) + 1])
rvs = list(ss)
rvs.reverse()
for j in range(int(order[i][1]), int(order[i][2]) + 1):
s[j] = rvs[j - int(order[i][1])]
# temp = s[int(order[i][1])]
# s[int(order[i][1])] = s[int(order[i][2])]
# s[int(order[i][2])] = temp
elif order[i][0] == "print":
ss = "".join(s)
print("%s" % ss[int(order[i][1]):int(order[i][2]) + 1])
| str = [w for w in input()]
q = int(input())
for i in range(q):
command = [w for w in input().split()]
command[1] = int(command[1])
command[2] = int(command[2])
if command[0] == "print":
for i in range(command[1], command[2]+1):
print(str[i], end="")
print()
if command[0] == "replace":
j = command[1]
for i in range(len(command[3])):
str[j] = command[3][i]
j += 1
if command[0] == "reverse":
r = []
for i in range(command[2], command[1]-1, -1):
r.append(str[i])
i = command[1]
for w in r:
str[i] = w
i += 1 | 1 | 2,077,007,124,180 | null | 68 | 68 |
a = int(input())
b = a // 100
c = a // 10 - b * 10
d = a - b * 100 - c * 10
if b != 7 and c != 7 and d != 7:
print("No")
else:
print("Yes") | N = input()
ans = 'No'
for i in range(3):
if int(N[i]) == 7:
ans = 'Yes'
print(ans) | 1 | 34,483,024,019,860 | null | 172 | 172 |
a = int(input())
x = list(map(str,input().split()))
y = reversed(x)
print(" ".join(y)) | N = int(input())
while N > 0:
es = sorted(list(map(int, input().split())))
if es[2] ** 2 == es[1] ** 2 + es[0] ** 2:
print('YES')
else:
print('NO')
N -= 1 | 0 | null | 479,274,352,100 | 53 | 4 |
s1 = input().split()
s2 = input().split()
if s1[0] == s2[0]:
print("0")
if s1[0] != s2[0] and int(s2[1])== 1:
print("1")
| N, M = map(int, input().split())
ans = 0
N, M = map(int, input().split())
if M==1:
ans=1
print(ans)
#print(*ans, sep='/n') | 1 | 124,373,318,252,930 | null | 264 | 264 |
r, c = map(int, input().split())
element = [list(map(int, input().split())) for i in range(r)]
for i in range(r):
element[i].append(sum(element[i]))
for i in range(r):
for j in range(c):
print(element[i][j],end="")
print(' ',end="")
print(element[i][c])
for i in range(c):
num = 0
for j in range(r):
num += element[j][i]
print(num, end="")
print(' ',end="")
b = 0
for i in range(r):
b += element[i][c]
print(b)
| # coding: utf-8
n, m = map(int, input().split())
total = [0] * m
for i in range(n+1):
if i < n:
line = [int(j) for j in input().split()]
print(" ".join([str(k) for k in line]),sum(line))
total = [total[i] + line[i] for i in range(m)]
else:
print(" ".join([str(k) for k in total]),sum(total)) | 1 | 1,371,620,918,418 | null | 59 | 59 |
#!/usr/bin/env python3
def main():
N, K = map(int, input().split())
H = sorted([int(x) for x in input().split()])
if K == 0:
print(sum(H))
elif N > K:
print(sum(H[:-K]))
else:
print(0)
if __name__ == '__main__':
main()
| import sys
N, K = map(int, next(sys.stdin.buffer).split())
H = list(map(int, next(sys.stdin.buffer).split()))
if K:
H.sort()
print(sum(H[:-K]))
else:
print(sum(H))
| 1 | 78,868,616,240,050 | null | 227 | 227 |
S=list(input())
n=len(S)
for i in range(n):
S[i]=int(S[i])
k=int(input())
dp0=[[0]*(n+1) for i in range(k+1)]
dp0[0][0]=1
s=0
for i in range(n):
if S[i]!=0:
s=s+1
if s==k+1:
break
dp0[s][i+1]=1
else:
dp0[s][i+1]=1
dp1=[[0]*(n+1) for i in range(k+1)]
for i in range(1,n+1):
if dp0[0][i]==0:
dp1[0][i]=1
for i in range(1,k+1):
for j in range(1,n+1):
if S[j-1]==0:
dp1[i][j]=dp0[i-1][j-1]*0+dp0[i][j-1]*0+dp1[i-1][j-1]*9+dp1[i][j-1]
else:
dp1[i][j]=dp0[i-1][j-1]*(S[j-1]-1)+dp0[i][j-1]+dp1[i-1][j-1]*9+dp1[i][j-1]
print(dp0[-1][-1]+dp1[-1][-1]) | while True:
h,w = map(int,raw_input().split())
if h==0 and w==0:
break
sside=""
for x in xrange(w):
sside += "#"
for x in xrange(h):
print sside
print | 0 | null | 38,438,765,725,100 | 224 | 49 |
# coding: utf-8
n = int(input())
L = list(map(int,input().split()))
l=[]
A=[]
ans=0
for i in range(n-2):
for j in range(i+1, n-1):
for k in range(j+1, n):
a=L[i]
b=L[j]
c=L[k]
if a!=b and b!=c and c!=a and a+b>c and b+c>a and c+a>b:
#print(i+1,j+1,k+1)
#print(a,b,c)
ans += 1
#print(L)
#print()
print(ans) | N,S = map(int,input().split())
A = list(map(int,input().split()))
MOD = 998244353
dp = [0 for _ in range(S+1)]
#i個目までの和がjの数となるのは何通りあるかdp[i][j]
dp[0] = 1
#dp = [0 if i==0 else INF for i in range(S + 1)]
for i in range(N): #i個目まで見て。
p = [0 for _ in range(S+1)]
p,dp = dp,p
for j in range(S+1):
dp[j] = (dp[j]+p[j]*2)%MOD
if j >= A[i]:
#print(j,A[i],p[j-A[i]])
dp[j] += p[j-A[i]]
#print(dp)
ans = dp[S]%MOD
print(ans)
| 0 | null | 11,409,904,175,420 | 91 | 138 |
MOD = 10**9 + 7
S = int(input())
dp = [0] * (S+1)
dp[0] = 1
for i in range(1, S+1):
for j in range(0, (i-3)+1):
dp[i] += dp[j]
dp[i] %= MOD
print(dp[S]) | MOD = 10 ** 9 + 7
def inv(x):
return pow(x, MOD - 2, MOD)
def gen_fact(n):
fact = [1] * (n + 1)
for i in range(2, n + 1):
fact[i] = fact[i - 1] * i % MOD
return fact
def binom(n, k, fact):
assert 0 <= k <= n
return fact[n] * inv(fact[k]) * inv(fact[n - k]) % MOD
def count(n, k, fact):
n -= 3 * k
return binom(n + k - 1, k - 1, fact)
if __name__ == '__main__':
s = int(input())
fact = gen_fact(s)
res = 0
for k in range(1, s // 3 + 1):
res += count(s, k, fact)
print(res % MOD) | 1 | 3,305,882,854,508 | null | 79 | 79 |
n = list(input())
n1 = int(n[-1])
if n1 == 2 or n1 == 4 or n1 == 5 or n1 == 7 or n1 == 9:
print("hon")
elif n1 == 0 or n1 == 1 or n1 == 6 or n1 == 8:
print("pon")
else:
print("bon")
| N = int(input())
n = N % 10
if n in [2,4,5,7,9]:
print('hon')#.format(N))
elif n in [0,1,6,8]:
print('pon')#.format(N))
else:
print('bon')#.format(N)) | 1 | 19,268,926,286,908 | null | 142 | 142 |
dice=input().split()
q=int(input())
do = [(2,3,5,4), (6,3,1,4), (2,6,5,1), (2,1,5,6), (1,3,6,4), (2,4,5,3)]
def check(top, front):
top_index=dice.index(top)
front_index=dice.index(front)+1
tmp=do[top_index]
tmp_index=tmp.index(front_index)
# print(top_index,front_index,tmp,tmp_index)
i = 0
if tmp_index == 3:
i = tmp[0]
else:
i = tmp[tmp_index+1]
print(dice[i-1])
for i in range(q):
top,front=input().split()
check(top,front)
| # 10_*
class Dice:
def __init__(self, label: list):
self.top, self.front, self.right, self.left, self.back, self.bottom = label
def roll(self, direction: str):
if direction == "N":
self.top, self.front, self.right, self.left, self.back, self.bottom = (
self.front,
self.bottom,
self.right,
self.left,
self.top,
self.back,
)
elif direction == "W":
self.top, self.front, self.right, self.left, self.back, self.bottom = (
self.right,
self.front,
self.bottom,
self.top,
self.back,
self.left,
)
elif direction == "S":
self.top, self.front, self.right, self.left, self.back, self.bottom = (
self.back,
self.top,
self.right,
self.left,
self.bottom,
self.front,
)
elif direction == "E":
self.top, self.front, self.right, self.left, self.back, self.bottom = (
self.left,
self.front,
self.top,
self.bottom,
self.back,
self.right,
)
def output_top(self):
print(self.top)
def get_top_front(self):
return f"{self.top} {self.front}"
def print_right(self):
print(self.right)
# 10_A
# (*label,) = map(int, input().split())
# dice = Dice(label)
# for i in input():
# dice.roll(i)
# dice.output_top()
# 10_B
(*label,) = map(int, input().split())
dice = Dice(label)
q = int(input())
for _ in range(q):
t, f = map(int, input().split())
for i in "EEEN" * 2 + "EEES" * 2 + "EEEN" * 2:
if f"{t} {f}" == dice.get_top_front():
dice.print_right()
break
dice.roll(i)
| 1 | 256,838,175,072 | null | 34 | 34 |
xs = ["X"] + input().split(" ")
print(xs.index("0")) | n = list(input().split())
for i in range(len(n)):
if n[i] == "0":
print(int(i)+1)
| 1 | 13,414,065,156,158 | null | 126 | 126 |
(X,N) = map(int,input().split())
if N == 0:
print(X)
else:
p = list(map(int,input().split()))
for i in range(N+1):
if (X - i) not in p:
print(X-i)
break
elif(X+i) not in p:
print(X+i)
break | x, n = list(map(int, input().split()))
if n == 0:
print(x)
exit(0)
else:
arr = list(map(int, input().split()))
arr.sort()
if x in arr:
i = arr.index(x)
else:
print(x)
exit(0)
if not i and i != 0:
print(x)
exit(0)
j = 1
for _ in range(n):
row = i - j
high = i + j
if x - j not in arr:
print(x - j)
exit(0)
elif x + j not in arr:
print(x + j)
exit(0)
j += 1
print(x-1)
| 1 | 14,058,761,723,488 | null | 128 | 128 |
a,b,k = map(int, input().split())
if k > a and k >= a+b:
print( 0 , 0 )
elif k < a :
print(a-k , b)
elif k == a:
print(0 , b)
elif k>a and k < a+b:
print(0 , b-(k-a))
| n=int(input())
x = int(n/2)
if n%2 == 1:
ans = x + 1
else:
ans = x
print(ans) | 0 | null | 81,369,375,464,868 | 249 | 206 |
# -*- coding: utf-8 -*-
def main():
S = input()
week = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
for i, name in enumerate(week):
if name == S:
ans = 7 - i
print(ans)
if __name__ == "__main__":
main() | store = {"SUN":7,"MON":6,"TUE":5,"WED":4,"THU":3,"FRI":2,"SAT":1}
s = input()
print(store[s]) | 1 | 132,815,981,918,790 | null | 270 | 270 |
n = input().split()
array = []
for s in n:
if s == "+" or s == "-" or s == "*":
b = array.pop()
a = array.pop()
if s == "+":
array.append(a + b)
elif s == "-":
array.append(a - b)
else:
array.append(a * b)
else:
array.append(int(s))
print(array[0]) | n = int(raw_input())
d = [0 for i in range(n)]
f = [0 for i in range(n)]
G = [0 for i in range(n)]
M = [[0 for i in range(n)] for j in range(n)]
st = [0 for i in range(n)]
t = [0]
def DFS_visit(s):
st[s] = 1
t[0] += 1
d[s] = t[0]
for e in range(n):
if M[s][e] == 1 and st[e] == 0:
DFS_visit(e)
st[s] == 2
t[0] += 1
f[s] = t[0]
def DFS():
for s in range(n):
if st[s] == 0:
DFS_visit(s)
for s in range(n):
print'{0} {1} {2}'.format(s+1, d[s], f[s])
for i in range(n):
G = map(int, raw_input().split())
for j in range(G[1]):
M[G[0]-1][G[2+j]-1] = 1
DFS() | 0 | null | 19,213,170,020 | 18 | 8 |
n= int(input())
ans=(n+1)//2
print(ans) | n = int(input())
print(int(n/2)+n%2) | 1 | 59,005,050,029,878 | null | 206 | 206 |
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7
H,W = map(int,readline().split())
s = [readline().rstrip() for i in range(H)]
dp = [[INF] * W for i in range(H)]
dp[0][0] = 0 if s[0][0] == '.' else 1
for i in range(H):
ii = max(0,i-1)
for j in range(W):
jj = max(0,j-1)
dp[i][j] = min(dp[ii][j] + (s[i][j] != s[ii][j]), dp[i][jj] + (s[i][j] != s[i][jj]))
print((dp[H-1][W-1]+1)//2)
| i = 1
while True:
x = int(input())
if x == 0:
break
else:
print('Case {}: {}'.format(i, x))
i += 1
| 0 | null | 24,706,380,851,668 | 194 | 42 |
k = int(input())
x = 7 % k
for i in range(1, k+1):
if x == 0:
print(i)
exit()
x = (x*10+7)%k
print(-1)
| def solve(string):
n, k = 7, int(string)
if k % 2 == 0 or k % 5 == 0:
return "-1"
for i in range(k):
if not n % k:
return str(i + 1)
n = (10 * n + 7) % k
if __name__ == '__main__':
import sys
print(solve(sys.stdin.read().strip()))
| 1 | 6,042,547,068,232 | null | 97 | 97 |
from collections import Counter
n, m = map(int, input().split())
group = [None for _ in range(n)]
connected = [[] for i in range(n)]
for i in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
connected[a].append(b)
connected[b].append(a)
# print(connected)
for i in range(n):
if group[i] is not None: continue
newly_visited = [i]
group[i] = i
while len(newly_visited) > 0:
new = newly_visited.pop()
for j in connected[new]:
if group[j] is not None: continue
group[j] = i
newly_visited.append(j)
# print(Counter(group))
print(len(Counter(group)) - 1)
| import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
class UnionFind:
def __init__(self, N: int):
"""
N:要素数
root:各要素の親要素の番号を格納するリスト.
ただし, root[x] < 0 ならその頂点が根で-root[x]が木の要素数.
rank:ランク
"""
self.N = N
self.root = [-1] * N
self.rank = [0] * N
def __repr__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def find(self, x: int):
"""頂点xの根を見つける"""
if self.root[x] < 0:
return x
else:
while self.root[x] >= 0:
x = self.root[x]
return x
def union(self, x: int, y: int):
"""x,yが属する木をunion"""
# 根を比較する
# すでに同じ木に属していた場合は何もしない.
# 違う木に属していた場合はrankを見てくっつける方を決める.
# rankが同じ時はrankを1増やす
x = self.find(x)
y = self.find(y)
if x == y:
return
elif self.rank[x] > self.rank[y]:
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
if self.rank[x] == self.rank[y]:
self.rank[y] += 1
def same(self, x: int, y: int):
"""xとyが同じグループに属するかどうか"""
return self.find(x) == self.find(y)
def count(self, x):
"""頂点xが属する木のサイズを返す"""
return - self.root[self.find(x)]
def members(self, x):
"""xが属する木の要素を列挙"""
_root = self.find(x)
return [i for i in range(self.N) if self.find == _root]
def roots(self):
"""森の根を列挙"""
return [i for i, x in enumerate(self.root) if x < 0]
def group_count(self):
"""連結成分の数"""
return len(self.roots())
def all_group_members(self):
"""{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す"""
return {r: self.members(r) for r in self.roots()}
N,M=MI()
uf=UnionFind(N)
for _ in range(M):
a,b=MI()
a-=1
b-=1
uf.union(a,b)
cnt=uf.group_count()
print(cnt-1)
main()
| 1 | 2,280,080,543,402 | null | 70 | 70 |
def fib(n,memo={}):
if n==0 or n==1:
return 1
elif n in memo:
return memo[n]
else:
memo[n]= fib(n-1,memo)+fib(n-2,memo)
return memo[n]
n=int(input())
print(fib(n))
| k=int(input())
def gcd(a,b):
if b==0:
return a
else:
return gcd(b,a%b)
ans=0
for i in range(1,k+1):
for j in range(1,k+1):
for l in range(1,k+1):
ans+=gcd(gcd(i,j),l)
print(ans) | 0 | null | 17,709,037,355,332 | 7 | 174 |
A,B,C,D = map(int,input().split())
while True:
C -= B
A -= D
if C <= 0:
print("Yes")
exit()
elif A <= 0:
print("No")
exit() | d,t,s = map(int, input().split())
if(d-t*s>0):
print("No")
else:
print("Yes") | 0 | null | 16,560,371,566,024 | 164 | 81 |
t, h = 0, 0
for i in range(int(input())):
tc, hc= input().split()
if tc > hc:
t += 3
elif tc < hc:
h += 3
else:
t += 1
h += 1
print('%d %d' % (t, h)) | n = int(input())
x = 0
y = 0
for _ in range(n):
a,b=input().split()
if a < b:
y+=3
elif a ==b:
x+=1
y+=1
else:
x+=3
print (x,y)
| 1 | 1,985,169,697,350 | null | 67 | 67 |
from collections import deque
N, D, A = map(int, input().split())
XH = [list(map(int, input().split())) for i in range(N)]
XH.sort(key=lambda x:x[0])
q = deque()
s = 0
ans = 0
for i in range(N):
x = XH[i][0]
h = XH[i][1]
while len(q) > 0:
elm = q.popleft()
if x <= elm[0]:
q.appendleft(elm)
break
else:
s -= elm[1]
h -= s
c = max(0, (h + A - 1) // A)
ans += c
s += c * A
q.append((x + 2*D, c*A))
print(ans) | import sys
input = sys.stdin.readline
from collections import deque
import math
n, d, a = map(int, input().split())
XH = []
for _ in range(n):
x, h = map(int, input().split())
XH.append((x, h))
XH.sort()
answer = 0
damage = 0
QUEUE = deque()
for x, h in XH:
if QUEUE:
while x > QUEUE[0][0]:
damage -= QUEUE[0][1]
QUEUE.popleft()
if not QUEUE:
break
h -= damage
if h <= 0:
continue
bomb = math.ceil(h / a)
QUEUE.append((x + 2 * d, a * bomb))
damage += a * bomb
answer += bomb
print(answer)
| 1 | 82,009,480,407,300 | null | 230 | 230 |
import heapq
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
L = []
ans = 0
heapq.heappush(L, -A[0])
for i in range(1, N):
max = heapq.heappop(L)
max *= -1
ans += max
heapq.heappush(L, -A[i])
heapq.heappush(L, -A[i])
print(ans)
| import math
n = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
D1 = 0
d2 = 0
d3 = 0
dm =[]
for i in range(n):
D1 += abs(x[i]-y[i])
d2 += (abs(x[i]-y[i]))**2
d3 += (abs(x[i]-y[i]))**3
m = abs(x[i]-y[i])
dm.append(m)
D2 = math.sqrt(d2)
D3 = d3 ** (1/3)
Dm = max(dm)
print(f'{D1:.06f}')
print(f'{D2:.06f}')
print(f'{D3:.06f}')
print(f'{Dm:.06f}')
| 0 | null | 4,661,318,165,922 | 111 | 32 |
k = int(input())
res = ''
while(k >= 1):
res += 'ACL'
k -= 1
print(res) | n,m=map(int,input().split());a=sorted(map(int,input().split()),reverse=True)
print('NYoe s'[all([1 if i>=sum(a)/(4*m) else 0 for i in a[:m]])::2]) | 0 | null | 20,402,097,964,260 | 69 | 179 |
F = [[[0] * 10 for i in range(3)] for i in range(4)]
n = int(input())
for i in range(n):
b, f, r, v = map(int, input().split())
F[b-1][f-1][r-1] += v
for x in range(0, 4):
for y in range(0, 3):
for z in range(0, 10):
print(" {0}".format(F[x][y][z]), end = '')
print()
if x != 3:
print("#" * 20) | #!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
import math
a, b, c = map(float, sys.stdin.readline().split())
degree = abs(180-abs(c))*math.pi / 180
height = abs(b * math.sin(degree))
pos_x = b * math.cos(degree) + a
edge_x = (height**2 + pos_x**2) ** 0.5
print(round(a * height / 2, 6))
print(round(a + b + edge_x, 6))
print(round(height, 6))
| 0 | null | 637,652,739,320 | 55 | 30 |
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a,b=mi()
print(max(a-b-b,0)) | a, b = map(int, input().split())
ans = a - b*2
print(ans if ans > 0 else 0) | 1 | 166,700,776,221,632 | null | 291 | 291 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.