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
|
---|---|---|---|---|---|---|
def Qb():
a, b, c, k = map(int, input().split())
ra = min(k, a)
k -= ra
k -= b
rc = 0 if k <= 0 else -(min(k, c))
print(ra + rc)
if __name__ == '__main__':
Qb()
|
from collections import defaultdict
n, m = map(int, input().split())
ac_dict = defaultdict(int)
wa_dict = defaultdict(int)
ac_p, wa_p = set(), set()
for _ in range(m):
p, s = input().split()
p = int(p)
if s == 'AC':
ac_p.add(p)
ac_dict[p] = 1
elif ac_dict[p] != 1:
wa_p.add(p)
wa_dict[p] += 1
wa = 0
for pi in ac_p:
wa += wa_dict[pi]
print(sum(ac_dict.values()), wa)
| 0 | null | 57,341,262,054,526 | 148 | 240 |
while True:
num = input()
if int(num) == 0:
break
sum = 0
for i in num:
a = int(i)
sum += a
print(sum)
|
#3 Range Flip Find Route
h,w = map(int,input().split())
s= [None for i in range(h)]
for i in range(h):
s[i] = input()
dp = [[0]*w for i in range(h)]
dp[0][0] = int(s[0][0]=="#")
for i in range(1,w):
dp[0][i]=dp[0][i-1] + (s[0][i-1]=="." and s[0][i]=="#")
for i in range(1,h):
dp[i][0]=dp[i-1][0] + (s[i-1][0]=="." and s[i][0]=="#")
for i in range(1,h):
for j in range(1,w):
cand1 = dp[i-1][j] + (s[i-1][j]=="." and s[i][j]=="#")
cand2 = dp[i][j-1] + (s[i][j-1]=="." and s[i][j]=="#")
dp[i][j]=min(cand1,cand2)
print(dp[-1][-1])
| 0 | null | 25,294,095,558,820 | 62 | 194 |
n, k = map(int, input().split())
a = list(map(int, input().split()))
for _ in range(min(50, k)):
l = [0]*(n+1)
for i in range(n):
l[max(i-a[i], 0)] += 1 #光の届く距離(後ろ)
l[min(i+a[i]+1, n)] -= 1 #光が届かなくなる距離(前)
add = 0
for i in range(n):
add += l[i] #光の届いている電球の数を累積
a[i] = add
print(*a)
|
N = int(input())
stocks = list(map(int, input().split()))
curr = 1000
for i in range(N - 1):
cnt = 0
if stocks[i] < stocks[i + 1]:
cnt = curr // stocks[i]
curr += cnt * (stocks[i + 1] - stocks[i])
print(curr)
| 0 | null | 11,400,862,549,248 | 132 | 103 |
n = int(input())
cnt = 0
for i in range(1,n+1):
cnt += n//i
if n%i == 0:
cnt -= 1
print(cnt)
|
N = int(input())
count = 0
for A in range(1, N):
N_ = (N - 1) // A
count += N_
print(count)
| 1 | 2,635,950,056,672 | null | 73 | 73 |
N = int(input())
A = list(map(int, input().split()))
S = sum(A)
ans = float("INF")
LS = [0]*(N+1)
LS[0] = 0
for i in range(N-1):
LS[i+1] = A[i] + LS[i]
ans = min(ans, abs(LS[i+1] - (S - LS[i+1])))
print(ans)
|
n = int(input())
A = list(map(int, input().split()))
for i in range(n - 1):
A[i + 1] += A[i]
minv = float('inf')
for a in A[:-1]:
minv = min(minv, abs(A[-1]/2 - a))
print(int(minv * 2))
| 1 | 142,261,358,091,464 | null | 276 | 276 |
a=input()
if '7' in a:
print('Yes')
else:
print('No')
|
def merge(a, left, mid, right):
global count
l = a[left:mid] + [sentinel]
r = a[mid:right] + [sentinel]
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 merge_sort(a, left, right):
if left + 1 < right:
mid = (left + right) // 2
merge_sort(a, left, mid)
merge_sort(a, mid, right)
merge(a, left, mid, right)
sentinel = 10 ** 9 + 1
n = int(input())
a = list(map(int, input().split()))
count = 0
merge_sort(a, 0, len(a))
print(*a)
print(count)
| 0 | null | 17,308,977,463,196 | 172 | 26 |
n=int(input())
a=list(map(int,input().split()))
res=1000
for i in range(1,n):
if a[i]>a[i-1]:
t=(res//a[i-1])*a[i]+res%a[i-1]
res=t
print(res)
|
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()
n = k()
a = l()
sum = 1000
for i in range(n-1):
if a[i] > a[i+1]:
xx = a[cnt:i+1]
b = sum//min(xx)
sum += (max(xx)-min(xx))*b
cnt = i+1
xx = a[cnt:]
b = sum//min(xx)
sum += (max(xx)-min(xx))*b
print(sum)
| 1 | 7,361,677,774,880 | null | 103 | 103 |
n = int(input())
if n>=3:
if n%2==0:
print(n//2-1)
else:
print(n//2)
else:
print(0)
|
a,b=(map(int,input().split()))
c=0
if a<=b:
print(0)
elif a>b:
c=a-b*2
if c>0:
print(c)
elif c<=0:
print(0)
| 0 | null | 159,727,482,045,860 | 283 | 291 |
import sys
sys.setrecursionlimit(10**7)
readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))
n = readint()
ans = [[[0],[0]]]
i = 0
while len(ans[i][0])<n:
a = ans[i]
for x in a[1]:
ans.append([a[0]+[x],a[1]])
x = a[1][-1]+1
ans.append([a[0]+[x],a[1] + [x]])
i+=1
a_ = ord('a')
for i in range(len(ans)):
a = ans[i][0]
if len(a)<n:
continue
for x in a[:-1]:
print(chr(x+a_),end='')
print(chr(a[-1]+a_))
|
def main():
X, Y, Z = map(int, input().split())
return " ".join(map(str, [Z, X, Y]))
if __name__ == '__main__':
print(main())
| 0 | null | 45,252,919,930,570 | 198 | 178 |
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
def shellsort(A,n):
cnt = 0
h = 1
G = []
while h <= n:
G.append(h)
h = 3*h + 1
G.reverse()
m = len(G)
print(m)
print(" ".join(map(str,G)))
for i in range(m):
cnt += insertionSort(A,n,G[i])
print(cnt)
for i in A:
print(i)
n = int(input())
A = []
for _ in range(n):
A.append(int(input()))
shellsort(A,n)
|
def insertionSort(a,n,g):
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
global cnt
cnt+=1
a[j+g]=v
def shellsort(a,n):
global cnt
cnt=0
g=[i for i in [262913, 65921, 16577, 4193, 1073, 281, 77, 23, 8, 1] if i <= n]
m=len(g)
#print(g,m)
for i in range(m):
insertionSort(a,n,g[i])
return a,m,g
n=int(input())
a=[int(input()) for i in range(n)]
a,m,g=shellsort(a,n)
print(m)
print(*g)
print(cnt)
for i in a:
print(i)
| 1 | 31,504,950,450 | null | 17 | 17 |
N, A = map(int,input().split())
print("Yes" if 500*N >= A else "No")
|
from collections import defaultdict
dd = defaultdict(int)
n,p=map(int, input().split())
S = list(input().rstrip())
tmp = 0
r=1
su=0
dd[0]=1
if p==2 or p==5:
c=n
for s in S[::-1]:
if int(s)%p==0:
su+=c
c-=1
print(su)
else:
for s in S[::-1]:
tmp+=int(s)*r
tmp%=p
dd[tmp]+=1
r*=10
r%=p
for i in dd.values():
su += (i*(i-1))//2
print(su)
| 0 | null | 78,016,828,871,420 | 244 | 205 |
#!/usr/bin/env python3
import sys
import heapq
MOD = 1000000007 # type: int
def containPositive(arr):
for a in arr:
if a >= 0:
return True
return False
def solve(N: int, K: int, A: "List[int]"):
if N == K:
m = 1
for a in A:
m = m*a%MOD
print(m)
elif not containPositive(A) and K%2 == 1:
A = list(reversed(sorted(A)))
m = 1
for i in range(K):
m = m*A[i]%MOD
print(m)
else:
m = 1
B = [(abs(a),a) for a in A]
B = list(reversed(sorted(B)))
lastNegative = 0
lastPositive = 1
hadPositive = False
for i in range(K):
a = B[i][1]
if a < 0:
if lastNegative == 0:
lastNegative = a
else:
m = m*lastNegative*a%MOD
lastNegative = 0
else:
if a > 0 and lastPositive != 1:
m = m*lastPositive%MOD
if a > 0:
lastPositive = a
hadPositive = True
else:
m=m*a%MOD
if lastNegative == 0:
print(m*lastPositive%MOD)
else:
nextNegative = 0
for i in range(K,N):
b = B[i][1]
if b < 0:
nextNegative = b
break
if nextNegative == 0:
m = m*B[K][1]
print(m*lastPositive%MOD)
else:
c1 = lastNegative*nextNegative
nextPositive = 0
k = K
while k < N:
a = B[k][1]
if a >=0:
nextPositive = a
break
k+=1
c2 = nextPositive*lastPositive
if not hadPositive: # This array contain some non-negative value. This means the result value could be positive. But if there were no positive values in the first K values sorted by the absolute value, use just next positive value instead of the last negative values.
m = m*nextPositive%MOD
print(m)
exit()
if c1 > c2:
m = m*lastNegative*nextNegative%MOD
print(m)
else:
m =m*nextPositive*lastPositive%MOD
print(m)
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
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
A = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, K, A)
if __name__ == '__main__':
main()
|
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
mod=10**9+7
ans=1
if K%2==1 and A[-1]<0:
for i in range(K):
ans=ans*A[N-(i+1)]%mod
print(ans)
exit()
l=0
r=N-1
if K%2==1:
ans=ans*A[r]
r-=1
for _ in range(K//2):
ml=A[l]*A[l+1]
mr=A[r]*A[r-1]
if ml>mr:
ans=ans*ml%mod
l+=2
else:
ans=ans*mr%mod
r-=2
print(ans)
| 1 | 9,434,301,888,814 | null | 112 | 112 |
from math import floor
A= input().split()
p = int(A[0])
q = round(float(A[1])*100)
t = p*q
t //= 100
print(t)
|
x,n = map(int, input().split())
p = list(map(int, input().split()))
l = [i for i in range(102)]
for j in p:
l.remove(j)
m = []
for k in l:
m.append(abs(k-x))
print(l[m.index(min(m))])
| 0 | null | 15,254,324,507,420 | 135 | 128 |
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
T=LI()
A=LI()
B=LI()
d1=(A[0]-B[0])*T[0]
d2=(A[1]-B[1])*T[1]
if d1>=0:
#最初は必ず正の方向へいかないように調整
d1*=-1
d2*=-1
if d1+d2==0:
print("infinity")
elif d1==0:#d1=0のパターンを排除した
print(0)
elif d1+d2<=0:
print(0)
else:
cnt=(-1*d1)//(d1+d2)
ans=cnt*2+1
if cnt*(d1+d2)==-1*d1:
ans-=1
print(ans)
main()
|
# -*- coding: utf-8 -*-
## Library
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy
## input
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split())
# P = [list(map(int,input().split())) for i in range(M)]
# S = []
# for _ in range(N):
# S.append(list(input()))
N=int(input())
print(N+N**2+N**3)
| 0 | null | 71,014,464,846,408 | 269 | 115 |
a=int(input())
b=list(map(int,input().split()))
b.sort()
c=0
for i in range(a-1):
if b[i]==b[i+1]:
c=c+1
if c==0:
print("YES")
else:
print("NO")
|
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
input = lambda: given().rstrip()
LMIIS = lambda: list(map(int,input().split()))
II = lambda: int(input())
XLMIIS = lambda x: [LMIIS() for _ in range(x)]
YN = lambda c : print('Yes') if c else print('No')
MOD = 10**9+7
N = II()
A = LMIIS()
print('YES' if len(A) == len(set(A)) else 'NO')
if __name__ == '__main__':
main()
| 1 | 73,899,527,749,252 | null | 222 | 222 |
x, y, z = map(int, raw_input().split())
cnt = 0
for i in range(x, y+1):
if z%i == 0:
cnt += 1
print cnt
|
import sys
from collections import defaultdict
sys.setrecursionlimit(500000)
class Fraction:
def gcd(self, a ,b):
a,b = max(a,b),min(a,b)
while a%b!=0:
a,b = b,a%b
return b
def frac(self,a,b):
if a==0 and b==0:
return (0,0)
elif a==0:
return (0,1)
elif b==0:
return (1,0)
else:
d = self.gcd(abs(a),abs(b))
if a<0:
a = -a
b = -b
return (a//d,b//d)
def __init__(self, a, b):
self.value = self.frac(a,b)
def v(self):
return self.value
def __lt__(self, other):
assert self.value!=(0,0) and other.value!=(0,0), 'value (0,0) cannot be compared.'
a,b = self.value
c,d = other.value
return a*d < b*c
def __le__(self, other):
assert self.value!=(0,0) and other.value!=(0,0), 'value (0,0) cannot be compared.'
a,b = self.value
c,d = other.value
return a*d <= b*c
def __eq__(self, other):
a,b = self.value
c,d = other.value
return a==c and b==d
def __ne__(self, other):
a,b = self.value
c,d = other.value
return not (a==c and b==d)
def __gt__(self, other):
assert self.value!=(0,0) and other.value!=(0,0), 'value (0,0) cannot be compared.'
a,b = self.value
c,d = other.value
return a*d > b*c
def __ge__(self, other):
assert self.value!=(0,0) and other.value!=(0,0), 'value (0,0) cannot be compared.'
a,b = self.value
c,d = other.value
return a*d >= b*c
def __add__(self, other):
a,b = self.value
c,d = other.value
return Fraction(a*d + b*c, b*d)
def __sub__(self, other):
a,b = self.value
c,d = other.value
return Fraction(a*d - b*c, b*d)
def __mul__(self, other):
a,b = self.value
c,d = other.value
return Fraction(a*c, b*d)
def __truediv__(self, other):
a,b = self.value
c,d = other.value
return Fraction(a*d, b*c)
def __neg__(self):
a,b = self.value
return Fraction(-a,b)
def inv(self):
return Fraction(1,1) / self
def input():
return sys.stdin.readline()[:-1]
def main():
N = int(input())
vec = [list(map(int,input().split())) for i in range(N)]
arg = defaultdict(int)
zero = 0
for v in vec:
if v[0] == 0 and v[1] == 0:
zero += 1
else:
f = Fraction(v[0],v[1])
arg[f.v()] += 1
arg[(-f.inv()).v()] += 0
pair = []
fd = lambda : False
checked_list = defaultdict(fd)
for key in arg:
if not checked_list[key]:
inv = (-Fraction(*key).inv()).v()
pair.append([arg[key],arg[inv]])
checked_list[inv] = True
mod = 1000000007
ans = 1
for p1,p2 in pair:
ans *= pow(2,p1,mod) + pow(2,p2,mod) - 1
ans %= mod
ans += zero
ans %= mod
print((ans+mod-1)%mod)
if __name__ == '__main__':
main()
| 0 | null | 10,655,453,798,912 | 44 | 146 |
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue
# import numpy as np
sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353
ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
# ===CODE===
def main():
n, u, v = ns()
edge = [[] for _ in range(n)]
for _ in range(n - 1):
a, b = ns()
a -= 1
b -= 1
edge[a].append(b)
edge[b].append(a)
dist_takahashi = [-1] * n
dist_aoki = [-1] * n
def bfs(pos, dist):
que = queue.Queue()
que.put(pos)
dist[pos] = 0
while not que.empty():
current = que.get()
for e in edge[current]:
if dist[e] == -1:
dist[e] = dist[current] + 1
que.put(e)
return dist
dist_takahashi = bfs(u - 1, dist_takahashi)
dist_aoki = bfs(v - 1, dist_aoki)
ans = 0
for dt, da in zip(dist_takahashi, dist_aoki):
if dt < da:
ans = max(ans, da - 1)
print(ans)
if __name__ == '__main__':
main()
|
from _collections import deque
from _ast import Num
def parser():
while 1:
data = list(input().split(' '))
for number in data:
if len(number) > 0:
yield (number)
input_parser = parser()
def gw():
global input_parser
return next(input_parser)
def gi():
data = gw()
return int(data)
MOD = int(1e9 + 7)
import numpy
from collections import deque
from math import sqrt
from math import floor
import heapq
#https://atcoder.jp/contests/abc148/tasks/abc148_f
#F - Playing Tag on Tree
"""
"""
N = gi()
U = gi()
V = gi()
t = [[] for i in range(N + 1)]
d = [[-1 for i in range(2)] for j in range(N + 1)]
for _ in range(1, N):
a = gi()
b = gi()
t[a].append(b)
t[b].append(a)
def bfs(s, di):
d[s][di] = 0
q = deque()
q.append(s)
while len(q):
v = q.pop()
for u in t[v]:
if d[u][di] >= 0:
continue
d[u][di] = d[v][di] + 1
q.append(u)
bfs(U, 0)
bfs(V, 1)
ans = 0
for l in range(1, N + 1):
if len(t[l]) > 1:
continue
du = d[l][0]
dv = d[l][1]
#print(l, du, dv)
if dv >= du:
ans = max(ans, dv - 1)
print(ans)
| 1 | 117,841,272,363,100 | null | 259 | 259 |
n=int(input())
A=list(map(int,input().split()))
N=[3]+[0]*n
mod=10**9+7
ans=1
for a in A:
ans*=N[a]
ans%=mod
N[a]-=1
N[a+1]+=1
print(ans)
|
from collections import *
from heapq import *
import sys
input=lambda :sys.stdin.readline().rstrip()
N=int(input())
A=list(map(int,input().split()))
mod=10**9+7
count=1
lst=[0,0,0]
for a in A:
data=[i for i in range(3) if lst[i] == a]
if not data:
count=0
break
count*=len(data)
count%=mod
i=data[0]
lst[i]+=1
print(count)
| 1 | 130,182,721,567,040 | null | 268 | 268 |
import math
a, b = map(str, input().split())
a2 = int(a)
b2 = int(b.replace('.', ''))
print(int((a2 * b2)//100))
|
def main():
S = input()
K = int(input())
if len(set(S)) == 1:
print((len(S) * K)//2)
return
result = 0
piyo = 0
hoge = S[0]
huga = 1
first = 0
for s in S[1:]:
if s == hoge:
huga += 1
if huga % 2 == 0:
piyo += 1
else:
if first == 0:
first = huga
hoge = s
huga = 1
if first == 0:
first = huga
if first % 2 == 1 and huga % 2 == 1 and S[0] == S[-1]:
result += K - 1
print(piyo * K + result)
main()
| 0 | null | 96,351,729,236,670 | 135 | 296 |
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq
def ri():
return int(input())
def rl():
return list(map(int, input().split()))
def solve():
n = ri()
L = [0] * (n + 1)
for i in rl():
L[i] += 1
for i in range(1, n + 1):
print (L[i])
mode = 's'
if mode == 'T':
t = ri()
for i in range(t):
solve()
else:
solve()
|
#coding:utf-8
#1_4_C 2015.3.29
while True:
data = input().split()
if data[1] == '?':
break
elif data[1] == '+':
print(int(data[0]) + int(data[2]))
elif data[1] == '-':
print(int(data[0]) - int(data[2]))
elif data[1] == '*':
print(int(data[0]) * int(data[2]))
elif data[1] == '/':
print(int(data[0]) // int(data[2]))
| 0 | null | 16,501,743,971,618 | 169 | 47 |
import sys
from collections import Counter
N = int(input())
S = [str(s) for s in sys.stdin.read().split()]
items = list(dict.fromkeys(S))
print(len(items))
|
a,b = map(int,input().split())
q = list()
for i in range(1009):
if int(i*0.08) == a and int(i*0.1) == b:
q.append(i)
if len(q) == 0:
print(-1)
exit()
print(min(q))
| 0 | null | 43,575,973,544,998 | 165 | 203 |
heights = list()
for i in range(10):
heights.append(int(input()))
for height in list(reversed(sorted(heights)))[:3]:
print(height)
|
hp, count_skills = map(int, input().split())
a = map(int, input().split())
skills_list = list(a)
for skill in skills_list:
hp -= skill
if hp <= 0:
print('Yes')
break
if hp >= 1:
print('No')
| 0 | null | 38,923,774,855,170 | 2 | 226 |
def stdinput():
from sys import stdin
return stdin.readline().strip()
def main():
from itertools import combinations
n = int(stdinput())
*A, = map(int, stdinput().split(' '))
q = int(stdinput())
*M, = map(int, stdinput().split(' '))
all_canditee = set([sum(c) for i in range(1, n+1) for c in combinations(A, i)])
# print(A)
# print(all_canditee)
for m in M:
if m in all_canditee:
print('yes')
else:
print('no')
# can not pass 9/10
def check(m, a, A):
for i, next_a in enumerate(A):
this_a = a + next_a
if this_a == m:
return True
elif this_a < m:
if check(m, this_a, A[i+1:]):
return True
return False
if __name__ == '__main__':
main()
# import cProfile
# cProfile.run('main()')
|
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
K = inp()
X = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(X[K-1])
| 0 | null | 25,035,110,299,738 | 25 | 195 |
a = [i for i in input().split()]
b = []
for i in range(len(a)):
b.append(a.pop(a.index(min(a))))
print(" ".join([str(i) for i in b]))
|
table = list(map(int,input().split()))
for i in range(2,0,-1):
k = 0
while k < i:
if table[k] > table[k+1]:
table[k],table[k+1] = table[k+1],table[k]
k += 1;
print(table[0],table[1],table[2])
| 1 | 421,078,274,946 | null | 40 | 40 |
N,K = map(int, input().split())
P = list(map(int, input().split()))
P.sort()
plist = P[0:K]
a = 0
for p in plist:
a+=p
print(a)
|
n = int(input())
a = [0] * 10**5
for x in range(1, 101):
for y in range(1, 101):
for z in range(1, 101):
a[x**2 + y**2 + z**2 + x*y + y*z + z*x] += 1
for i in range(1, n + 1):
print(a[i])
| 0 | null | 9,859,602,903,400 | 120 | 106 |
x,y,a,b,c = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
from collections import deque
p = sorted(p)[a-x:]
q = sorted(q)[b-y:]
t = deque(sorted(p+q))
r = deque(reversed(sorted(r)))
# print(t,r)
while r:
if t[0] < r[0]:
t.popleft()
w = r.popleft()
t.append(w)
else:
break
ans = sum(t)
print(ans)
|
while True:
c = 0
n, x= map(int, input().split())
if n == 0 and x == 0:
break
for i in range(1, n + 1):
for j in range(1, n + 1 ):
if j <= i:
continue
for k in range(1, n + 1):
if k <= j:
continue
if i != j and i != k and j != k and i + j + k == x:
c += 1
print(c)
| 0 | null | 22,944,624,202,550 | 188 | 58 |
# -*- coding:utf-8 -*-
def chess(H,W,m):
c = ''
count = 0
if m % 2 == 0:
for i in range(H):
if count % 2 == 0:
c += '#'
else:
c += '.'
count += 1
print(c)
if m % 2 == 1:
for i in range(H):
if count % 2 == 0:
c += '.'
else:
c += '#'
count += 1
print(c)
data = []
while True:
try:
di = input()
if di == '0 0':
break
data.append(di)
except:
break
for i in range(len(data)):
x = data[i]
W,H = map(int,x.split())
for l in range(W):
chess(H,W,l)
print('')
|
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
K = min(K, 41)
# imos
for _ in range(K):
B = [0 for _ in range(N)]
for i in range(N):
l = max(0, i-A[i])
r = min(N-1, i+A[i])
B[l] += 1
if r+1 < N:
B[r+1] -= 1
for i in range(1, N):
B[i] += B[i-1]
A = B
print(*A)
| 0 | null | 8,229,145,289,728 | 51 | 132 |
import sys
read = sys.stdin.read
#readlines = sys.stdin.readlines
from math import ceil
def main():
n, x, t = map(int, input().split())
print(ceil(n / x) * t)
if __name__ == '__main__':
main()
|
N,X,T = map(int,input().split())
num = N//X
mode = N%X
if mode == 0:
print(num * T)
else:
print((num + 1)*T)
| 1 | 4,215,968,790,528 | null | 86 | 86 |
H,A = map(int,input().split())
cnt = 0
while True:
if H <= 0:
print(cnt)
break
else:
H -= A
cnt += 1
|
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
| 0 | null | 39,350,077,258,560 | 225 | 65 |
#coding:utf-8
import math
r=float(input())
print("%.6f"%(math.pi*r**2)+" %.6f"%(2*math.pi*r))
|
import math
r=input()
p=math.pi
print "{0:.6f} {1:.6f}".format(r*r*p,2*r*p)
| 1 | 654,744,686,560 | null | 46 | 46 |
# 23-Structure_and_Class-Dice_I.py
# ???????????? I
# ?¬?????±??????????????????????????????????????????¢??????????????\??¬????????§????????????????????°????????????????????????????????????
# ????????????????????¢??????????????¨????????? 1 ?????? 6 ????????????????????????????????????????????????
# ??\?????¨??????????????????????????¢?????????????????????????????°?????¨?????¢?????????????????????????????????????????§???
# ????????????????????¢?????°?????????????????????????????????
# ????????\??¬????????§??????????????¶?????????????????¨?????????????????????????????§?????????????????????????????????????????¨????????????
# Input
# ?????????????????¢?????°???????????????????????????????????????????????????????????§?????????????????????
# ???????????????????????¨????????????????????????????????????????????????????????????????????????????????????????????¨????????? E???N???S???W ????????????????????§??????
# Output
# ???????????????????????????????????????????????????????????¢?????°???????????????????????????????????????
# Constraints
# 0???0??? ??\?????????????????????????????¢?????°??? ???100???100
# 0???0??? ???????????¨????????????????????? ???100???100
# Note
# ?¶???????????????? Dice III, Dice IV ??§???????????°????????????????????±????????§???????????????????????????????§?????????§?????????????????????????????????
# Sample Input 1
# 1 2 4 8 16 32
# SE
# Sample Output 1
# 8
# ?????¢??? 1, 2, 4, 8, 16, 32 ??¨??????????????????????????? S ??????????????¢???????????????E ??????????????¢????????¨????????¢?????°?????? 8 ??????????????????
# Sample Input 2
# 1 2 4 8 16 32
# EESWN
# Sample Output 2
# 32
class Dice:
def __init__(self, dice_num):
self.side_top=1
self.side_bot=6
self.side_Nor=5
self.side_Eas=3
self.side_Sau=2
self.side_Wes=4
self.dice_num = dice_num
def op_N(self):
self.side_top, self.side_bot, self.side_Nor, self.side_Sau =\
self.side_Sau, self.side_Nor, self.side_top, self.side_bot
def op_E(self):
self.side_top, self.side_bot, self.side_Eas, self.side_Wes =\
self.side_Wes, self.side_Eas, self.side_top, self.side_bot
def op_S(self):
self.side_top, self.side_bot, self.side_Nor, self.side_Sau =\
self.side_Nor, self.side_Sau, self.side_bot, self.side_top
def op_W(self):
self.side_top, self.side_bot, self.side_Eas, self.side_Wes =\
self.side_Eas, self.side_Wes, self.side_bot, self.side_top
def print_side_top(self):
print( dice_num[self.side_top-1] )
def print_side_all(self):
print( "top:{}, bot:{}, Nor:{}, Eas{}, Sau:{}, Wes,{}.".format(self.side_top, self.side_bot, self.side_Nor, self.side_Eas, self.side_Sau, self.side_Wes ) )
dice_num = list( map(int, input().split()))
op = input()
dice_roll = Dice(dice_num)
for i in op:
if i == "N":
dice_roll.op_N()
elif i =="E":
dice_roll.op_E()
elif i =="S":
dice_roll.op_S()
elif i =="W":
dice_roll.op_W()
else:
print("?????°??°")
dice_roll.print_side_top()
|
from typing import List
class Dice:
def __init__(self, s: List[int]):
self.s = s
def get_s(self) -> int:
return self.s[0]
def invoke_method(self, mkey: str) -> None:
if mkey == 'S':
self.S()
return None
if mkey == 'N':
self.N()
return None
if mkey == 'E':
self.E()
return None
if mkey == 'W':
self.W()
return None
raise ValueError(f'This method does not exist. : {mkey}')
def set_s(self, s0, s1, s2, s3, s4, s5) -> None:
self.s[0] = s0
self.s[1] = s1
self.s[2] = s2
self.s[3] = s3
self.s[4] = s4
self.s[5] = s5
def S(self) -> None:
self.set_s(self.s[4], self.s[0], self.s[2], self.s[3], self.s[5],
self.s[1])
def N(self) -> None:
self.set_s(self.s[1], self.s[5], self.s[2], self.s[3], self.s[0],
self.s[4])
def E(self) -> None:
self.set_s(self.s[3], self.s[1], self.s[0], self.s[5], self.s[4],
self.s[2])
def W(self) -> None:
self.set_s(self.s[2], self.s[1], self.s[5], self.s[0], self.s[4],
self.s[3])
# 提出用
data = [int(i) for i in input().split()]
order = list(input())
# # 動作確認用
# data = [int(i) for i in '1 2 4 8 16 32'.split()]
# order = list('SE')
dice = Dice(data)
for o in order:
dice.invoke_method(o)
print(dice.get_s())
| 1 | 231,294,818,832 | null | 33 | 33 |
L = int(input())
print(L **3 / 27)
|
# coding: utf-8
from collections import deque
n, quantum = [int(i) for i in input().split()]
dq = deque()
for i in range(n):
p, time = [str(i) for i in input().split()]
dq.append([p, int(time)])
time = 0
while(len(dq) != 0):
#引き算処理
#処理が終了しない場合
if dq[0][1] > quantum:
dq[0][1] -= quantum
dq.rotate(-1)
time += quantum
#処理が終了する場合
else:
time += dq[0][1]
print("{} {}".format(dq[0][0], time))
dq.popleft()
| 0 | null | 23,442,376,733,532 | 191 | 19 |
def resolve():
n, k = map(int, input().split())
S = []
L, R = [], []
for _ in range(k):
l1, r1 = map(int, input().split())
L.append(l1)
R.append(r1)
dp = [0 for i in range(n + 1)]
dpsum = [0 for i in range(n + 1)]
dp[1] = 1
dpsum[1] = 1
for i in range(2, n + 1):
for j in range(k):
Li = i - R[j]
Ri = i - L[j]
if Ri < 0:
continue
Li = max(1, Li)
dp[i] += dpsum[Ri] - dpsum[Li - 1] # dp[Li] ~ dp[Ri]
dp[i] %= 998244353
dpsum[i] = (dpsum[i - 1] + dp[i]) % 998244353
print(dp[n])
resolve()
|
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 998244353
n, k = map(int, input().split())
s = list()
for i in range(k):
s.append(tuple(map(int, input().split())))
dp = [0] + [0] * n
diff = [0] + [0] * n
dp[1] = 1
diff[2] = -1
for i in range(1, n):
for j, k in s:
if i + j > n:
continue
diff[i + j] += dp[i]
if i + k + 1 > n:
continue
diff[i + k + 1] -= dp[i]
#dp[i] = (dp[i - 1] + diff[i]) % MOD
dp[i + 1] = (dp[i] + diff[i + 1]) % MOD
print(dp[n])
| 1 | 2,713,947,464,188 | null | 74 | 74 |
s = input()
n = len(s)+1
ls = [0]*n
rs = [0]*n
for i in range(n-1):
if s[i] == "<":
ls[i+1] = ls[i]+1
for i in range(n-1):
if s[-1-i] == ">":
rs[-2-i] = rs[-1-i]+1
ans = 0
for i,j in zip(ls,rs):
ans += max(i,j)
print(ans)
|
# coding: utf-8
'''
S 1
H 3
H 7
C 12
D 8
'''
cards = ['S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9', 'S10', 'S11', 'S12', 'S13',
'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'H7', 'H8', 'H9', 'H10', 'H11', 'H12', 'H13',
'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'C10', 'C11', 'C12', 'C13',
'D1', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7', 'D8', 'D9', 'D10', 'D11', 'D12', 'D13']
for _ in range(int(input())):
# suit, number = input().split()
suit, number = map(str, input().split())
cards.remove(suit + number)
for trump in cards:
print(trump[0], trump[1:])
| 0 | null | 78,410,826,425,650 | 285 | 54 |
n = int(input())
s = str(input())
ok = "Yes"
if n == 1:
ok = "No"
if n % 2 == 1:
ok = "No"
for i in range (0, n//2):
if s[i] != s[i + n // 2] :
ok = "No"
print(ok)
|
S=int(input())
T=list(input())
t=S//2
p=0
for i in range(t):
if S%2==1:
p=-1
break
elif T[i]!=T[i+t]:
p=-1
break
if p==-1 or t==0:
print("No")
elif p==0:
print("Yes")
| 1 | 147,183,378,376,100 | null | 279 | 279 |
import collections, heapq, itertools, math, functools
groupby = itertools.groupby
rs = lambda: input()
ri = lambda: int(input())
rm = lambda: map(int, input().split())
rai = lambda: [int(x) for x in input().split()]
def solve():
N = ri()
ans = 0
for i in range(1, N + 1):
n = N // i
ans += i * n * (n + 1) // 2
return ans
print(solve())
|
N = int(input())
def calc(start, end):
n = end // start
return (n * (n+1) // 2) * start
ans = 0
for i in range(1, N+1):
ans += calc(i, N//i * i)
print(ans)
| 1 | 11,075,437,564,960 | null | 118 | 118 |
D = int(input())
c_list = list(map(int, input().split()))
s_list = [list(map(int, input().split())) for _ in range(D)]
last_open = [0] * 26
res = 0
res_list = []
for i in range(D):
t = int(input())
res += s_list[i][t-1]
bad = 0
last_open[t-1] = i+1
for ci in range(26):
bad += c_list[ci]*(i+1 - last_open[ci])
res -= bad
print(res)
res_list.append(res)
|
import numpy as np
D = int(input())
c = np.array(list(map(int, input().split())))
s = np.array([list(map(int, input().split())) for x in range(D)])
t = np.array([int(input()) for x in range(D)])
last = np.zeros(26, dtype=np.int16)
score = 0
for d in range(1, D + 1):
score += s[d - 1, t[d - 1] - 1]
last[t[d - 1] - 1] = d
score -= (c * (d - last)).sum()
print(score)
| 1 | 9,907,768,666,102 | null | 114 | 114 |
N,K = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]
ans = 0
for i in range(N):
if K <= H[i]:
ans += 1
print(ans)
|
n,k=map(int,input().split())
h=list(map(int,input().split()))
sum=0
for l in h:
if l>=k:
sum+=1
print(sum)
| 1 | 178,281,830,739,364 | null | 298 | 298 |
X=int(input())
maisu_max=X//100
if X<100:
print(0)
exit()
else:
X=str(X)
X=int(X[-2:])
if X==0:
print(1)
exit()
ans=100
for i in range(2):
for j in range(2):
for k in range(2):
for l in range(2):
for m in range(20):
tmp=i+j*2+k*3+l*4+m*5
if tmp==X:
if i+j+k+l+m<ans:
ans=i+j+k+l+m
if maisu_max>=ans:
print(1)
else:
print(0)
|
n = int(input())
cards = {
'S': [],
'H': [],
'C': [],
'D': []
}
for _ in range(n):
color, rank = input().split()
cards[color].append(rank)
for color in ['S', 'H', 'C', 'D']:
for rank in [x for x in range(1, 14) if str(x) not in cards[color]]:
print(color, rank)
| 0 | null | 64,066,058,425,150 | 266 | 54 |
N=int(input())
r=[0]*10000
for i in range(1,101):
for j in range(1,101):
for k in range(1,101):
v = i*i + j*j + k*k + i*j + i*k + k*j
if v <= 10000:
r[v-1] += 1
for i in range(N):
print(r[i])
|
import math
N = int(input())
ans = [0]*(N+1)
owari = math.sqrt(N)
owari = math.ceil(owari)
for x in range(1, owari):
a = x*x
for y in range(1, owari):
b = y*y
c = x*y
for z in range(1, owari):
hantei = z*(z+x+y)+a+b+c
if hantei > N:
break
ans[hantei] += 1
for i in range(1, N+1):
print(ans[i])
| 1 | 7,994,041,732,320 | null | 106 | 106 |
def get_input():
while True:
try:
yield ''.join(raw_input().strip())
except EOFError:
break
inlist = list(get_input())
instr = "".join(inlist)
instr = instr.lower()
ascstart = 97
ascfin = 122
strlist = [0 for i in xrange(97,122+1)]
# print len(strlist)
for x in xrange(len(instr)):
if ord(instr[x]) < ascstart or ord(instr[x]) > ascfin:
continue
strlist[ord(instr[x])-ascstart] +=1
for x in xrange(ascstart,ascfin+1):
print "%s : %d" % (chr(x),strlist[x-ascstart])
|
import sys
data = sys.stdin.read()
for i in range(0x61,0x7b):
print("%c : %d" %(i,data.lower().count(chr(i))))
| 1 | 1,651,953,206,160 | null | 63 | 63 |
N = int(input())
res = int(N / 2)
if N % 2 != 0:
res += 1
print(res)
|
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()
print(int(N/2) if N%2==0 else int(N/2)+1)
main()
| 1 | 58,990,448,548,890 | null | 206 | 206 |
class BIT:
def __init__(self, n):
self.n = n
self.data = [0]*(n+1)
def to_sum(self, i):
s = 0
while i > 0:
s += self.data[i]
i -= (i & -i)
return s
def add(self, i, x):
while i <= self.n:
self.data[i] += x
i += (i & -i)
def get(self, i, j):
return self.to_sum(j)-self.to_sum(i-1)
N = int(input())
A = list(map(int,input().split()))
A.sort()
M = pow(10,6)+ 100
Tree = BIT(M)
for x in A:
Tree.add(x,1)
ans = 0
for i in range(N):
for j in range(i+1,N):
x = A[i]; y = A[j]
Tree.add(x,-1);Tree.add(y,-1)
MIN = abs(x-y)+1; MAX = (x+y)-1
#print(x,y,MIN,MAX)
ans += Tree.get(MIN,MAX)
Tree.add(x,1);Tree.add(y,1)
#print(ans)
print(ans//3)
|
import sys
def input(): return sys.stdin.readline().strip()
def resolve():
n,r=map(int, input().split())
if n>=10:
print(r)
else:
print(r+100*(10-n))
resolve()
| 0 | null | 117,851,741,824,232 | 294 | 211 |
X,N=map(int,input().split())
p=list(map(int,input().split()))
ans=0
for i in range(1,102):
if i not in p:
if abs(X-i)<abs(X-ans):
ans=i
print(ans)
|
X,N = map(int,input().split())
p = list(map(int,input().split()))
if not X in p:
print(X)
else:
for i in range(100):
if not (X-i) in p:
print(X-i)
break
elif not (X+i) in p:
print(X+i)
break
| 1 | 13,969,712,076,478 | null | 128 | 128 |
n = int(input())
v = 'abcdefghij'
def dfs(s):
if len(s) == n:
print (s)
return
for i in range(len(set(s))+1):
dfs(s+v[i])
dfs('a')
|
n = int(input())
def aa(str, chrMax):
if len(str) == n:
print(str)
return
for i in range(ord("a"), ord(chrMax)+2):
if i > ord(chrMax):
aa(str+chr(i), chr(i))
else:
aa(str+chr(i), chrMax)
aa("a", "a")
| 1 | 52,536,668,419,720 | null | 198 | 198 |
def skip_num(num_digits:list, compare_digit):
compare_upper_digit = num_digits[compare_digit]
compare_lower_digit = num_digits[compare_digit + 1]
if compare_upper_digit > compare_lower_digit:
num_digits[compare_digit + 1] = compare_lower_digit + 1
if compare_digit + 2 > len(num_digits):
num_digits[compare_digit + 2:] = [0] * (len(num_digits) - compare_digit - 2)
else: # compare_upper_digit < compare_lower_digit
num_digits[compare_digit] = compare_upper_digit + 1
num_digits[compare_digit + 1:] = [0] * (len(num_digits) - compare_digit - 1)
return int("".join([str(i) for i in num_digits]))
K = int(input())
lunlun_count = 0
num = 0
while True:
num += 1
if num < 10:
lunlun_count += 1
else:
num_digits = list(map(int, str(num)))
is_lunlun = True
for i in range(len(num_digits) - 1):
if abs(num_digits[i] - num_digits[i + 1]) > 1:
is_lunlun = False
num = skip_num(num_digits, i) - 1
break
if is_lunlun:
lunlun_count += 1
if lunlun_count >= K:
break
print(num)
|
from collections import deque
k=int(input())
d=deque()
for i in range(1,10):
d.append(i)
for i in range(k-1):
x=d.popleft()
if x%10!=0:
d.append(10*x+(x%10)-1)
d.append(10*x+(x%10))
if x%10!=9:
d.append(10*x+(x%10)+1)
print(d.popleft())
| 1 | 40,112,059,091,352 | null | 181 | 181 |
# -*-coding:utf-8
def main():
n, m, l = map(int, input().split())
A = []
B = []
for i in range(n):
A.append(list(map(int, input().split())))
for i in range(m):
B.append(list(map(int, input().split())))
Ans = []
for i in range(n):
row = []
for j in range(l):
rowSum = 0
for k in range(m):
rowSum += A[i][k] * B[k][j]
row.append(rowSum)
Ans.append(row)
for i in range(n):
print(' '.join([str(a) for a in Ans[i]]))
if __name__ == '__main__':
main()
|
#!/usr/bin/env python3
N = int(input().split()[0])
a_list = list(map(int, input().split()))
before_a = 0
total = 0
for i, a in enumerate(a_list):
if i == 0:
before_a = a
continue
total += max(before_a - a, 0)
before_a = a + max(before_a - a, 0)
ans = total
print(ans)
| 0 | null | 2,981,962,509,926 | 60 | 88 |
import collections
N = int(input())
S = [input() for _ in range(N)]
c = collections.Counter(S)
max_num = max(c.values())
l = []
for item in c.items():
k = item[0]
v = item[1]
if v == max_num:
l.append(k)
l.sort()
for li in l:
print(li)
|
n = input()
data = []
space = []
for i in ['S ', 'H ', 'C ', 'D ']:
for j in map( str , xrange(1, 14)):
data.append(i + j)
for i in xrange(n):
data.remove(raw_input())
for i in xrange(len(data)):
print data[i]
| 0 | null | 35,463,439,167,380 | 218 | 54 |
def solve(n,x):
count = 0
for i in range(1,n+1):
for j in range(1,n+1):
if i == j :
continue
for k in range(1,n+1):
if j == k or i == k:
continue
if i+j+k == x:
count += 1
return count//6
while True:
n,x = map(int,input().split())
if n == x == 0:
break;
print(solve(n,x))
|
number = int(input())
word = input()
answer = word.count('ABC')
print(answer)
| 0 | null | 50,410,857,371,868 | 58 | 245 |
n,a,b=map(int,input().split())
c=max(a,b)
b=min(a,b)
a=c
MOD = pow(10,9) + 7
X=1
Y=1
for i in range(1,a+1):
X=X*(n+1-i)%MOD
Y=Y*i%MOD
if i==b:
b_X=X
b_Y=Y
a_X=X
a_Y=Y
def calc(X,Y,MOD):
return X*pow(Y,MOD-2,MOD)
ans=pow(2,n,MOD)%MOD-1-calc(a_X,a_Y,MOD)-calc(b_X,b_Y,MOD)
print(ans%MOD)
|
k,n = map(int,input().split())
Ai = list(map(int,input().split()))
kyori = []
for x in range(n-1):
kyori.append(Ai[x+1]-Ai[x])
kyori.append(Ai[0]+k-Ai[n-1])
kyori.remove(max(kyori))
print(sum(kyori))
| 0 | null | 55,077,978,323,368 | 214 | 186 |
X = int(input())
ans=0
if X < 500:
print((X // 5) * 5)
else:
ans += (X // 500)*1000
X -= (X//500)*500
ans += (X//5)*5
print(ans)
|
X = int(input())
num1000 = X // 500
r500 = X % 500
num5 = r500 // 5
print(num1000 * 1000 + num5 * 5)
| 1 | 42,535,537,035,460 | null | 185 | 185 |
import sys
sys.setrecursionlimit(300000)
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')
K = I()
num = 7
for i in range(10 ** 6):
if num % K == 0:
print(i + 1)
exit()
num = (num * 10 + 7) % K
print(-1)
|
N=int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(0, N, 2):
ans += A[i] % 2 != 0
print(ans)
| 0 | null | 6,934,460,266,170 | 97 | 105 |
i = 1
while True:
n = input()
if n != 0:
print 'Case %s: %s' % (str(i), str(n))
i = i + 1
else:
break
|
for i in range(1,10001):
x = int(input())
if(x == 0):
break
print('Case ', i, ': ', x, sep='')
| 1 | 474,945,478,940 | null | 42 | 42 |
# import math
# import statistics
a=int(input())
#b,c=int(input()),int(input())
# c=[]
# for i in a:
# c.append(i)
# e1,e2 = map(int,input().split())
f = list(map(int,input().split()))
#g = [input() for _ in range(a)]
f.sort()
count=1
ans=[0 for i in range(a)]
for i in range(len(f)-1):
if f[i]==f[i+1]:
count+=1
else:
ans[f[i]-1]=count
count=1
if count>=1:
ans[f[-1]-1]=count
for i in ans:
print(i)
|
N = int(input())
A = list(map(int,input().split()))
buka = [0]*N
for p in range(N-1):
buka[A[p] -1] += 1
for q in range(N):
print(buka[q])
| 1 | 32,536,667,668,010 | null | 169 | 169 |
n = int(input())
P = list(map(int, input().split( )))
mas = P[0]
ans = 1
for i in range(n-1):
if mas >= P[i+1]:
ans += 1
mas = min(mas,P[i+1])
print(ans)
|
N=int(input())
P=list(map(int,input().split()))
m=N
ans=0
for i in range(N):
if m>=P[i]:
ans+=1
m=min(m,P[i])
print(ans)
| 1 | 85,423,349,607,388 | null | 233 | 233 |
s = sorted([int(input()), int(input())])
print(3 if s == [1, 2] else (2 if s == [1, 3] else 1))
|
a, b = int(input()), int(input())
if 1 not in [a, b]:
print(1)
elif 2 not in [a, b]:
print(2)
else:
print(3)
| 1 | 110,739,971,610,568 | null | 254 | 254 |
from math import *
from collections import defaultdict
GLOBAL = {}
def roots(n):
res = set()
for i in range(1,int(sqrt(n))+1):
if n%i == 0:
res.add(i)
res.add(n//i)
return len(res)
n = int(input())
cnt = 0
for i in range(1,n+1):
y = n//i
cnt+=((y)*(y+1)*(i))//2
print(cnt)
|
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(map(str, input().split()))
def pl(a): print(" ".join(list(map(str, a))))
N = ri()
a = rls()
bubble = a[:]
flag = True
while(flag):
flag = False
for i in range(1, N):
if(bubble[-i][1] < bubble[-i-1][1]):
hold = bubble[-i]
bubble[-i] = bubble[-i-1]
bubble[-i-1] = hold
flag = True
pl(bubble)
print("Stable") # ?????????Stable
selection = a[:]
for i in range(N):
minj = i
for j in range(i, N):
if(selection[j][1] < selection[minj][1]):
minj = j
hold = selection[i]
selection[i] = selection[minj]
selection[minj] = hold
pl(selection)
print("Stable" if bubble == selection else "Not stable")
| 0 | null | 5,532,544,826,480 | 118 | 16 |
N, X, M = map(int, input().split())
A = X
ans = A
visited = [0]*M
tmp = []
i = 2
while i <= N:
A = (A*A) % M
if visited[A] == 0:
visited[A] = i
tmp.append(A)
ans += A
else:
ans += A
loop_length = i-visited[A]
loop_val = tmp[-1*loop_length:]
loop_count = (N-i) // loop_length
ans += sum(loop_val) * loop_count
visited = [0]*M
i += loop_length * loop_count
i += 1
print(ans)
|
import sys
import heapq
import math
def input(): return sys.stdin.readline().rstrip()
def main():
n, k = map(int,input().split())
A = list(map(int,input().split()))
def is_good(mid, key):
kk = 0
for a in A:
kk += -(-a//mid)-1
if kk <= key:
return True
else:
return False
def bi_search(bad, good, key):
while good - bad > 1:
mid = (bad + good)//2
if is_good(mid, key):
good = mid
else:
bad = mid
return good
print(bi_search(0, 1000000000, k))
if __name__=='__main__':
main()
| 0 | null | 4,700,670,364,250 | 75 | 99 |
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
import numpy as np
#======================================================#
MOD=10**9+7
def main():
n = II()
aa = np.array(MII(), dtype='uint64')
ans = 0
for i in range(60):
cnt1 = (aa&1).sum()
ans += (cnt1*(n-cnt1))%MOD*(2**i)%MOD
aa >>= 1
print(int(ans%MOD))
if __name__ == '__main__':
main()
|
#!/usr/bin/env python3
k, n = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
maxku = 0
for i in range(n-1):
ku = a[i + 1] - a[i]
maxku = max(ku, maxku)
cnt += ku
ku = a[0] + (k - a[-1])
maxku = max(ku, maxku)
cnt += ku
print(cnt - maxku)
| 0 | null | 82,901,562,715,328 | 263 | 186 |
N = int(input())
s = input()
a = [chr(i) for i in range(65, 65+26)]
ls = []
for x in a:
ls.append(x)
for x in a:
ls.append(x)
ans = []
for x in s:
ans.append(ls[ls.index(x)+N])
print(''.join(ans))
|
import sys
s = input().lower()
t = sys.stdin.read().lower().split()
print(t.count(s))
| 0 | null | 68,181,802,266,562 | 271 | 65 |
N,K,S = map(int,input().split())
ans = []
for i in range(K):
ans.append(S)
for j in range(N-K):
if not S == 1000000000:
ans.append(S+1)
else:
ans.append(S-1)
for l in ans:
print(l,end=" ")
print()
|
S = input()
ans = 'No'
if (S[2] == S[3]) and (S[4] == S[5]):
ans = 'Yes'
print(ans)
| 0 | null | 66,699,840,368,350 | 238 | 184 |
n = int(input())
s = list(str(n))
r = list(reversed(s))
if r[0] in ["2","4","5","7","9"]:
print("hon")
elif r[0] in ["0","1","6","8"]:
print("pon")
else:
print("bon")
|
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
last = [0]*26
ans = 0
for d in range(D):
max_s = int(input()) - 1
last[max_s] = d+1
ans += s[d][max_s]
for i in range(26):
ans -= (c[i]*(d+1 - last[i]))
print(ans)
| 0 | null | 14,564,185,324,138 | 142 | 114 |
import sys
N,M=map(int,input().split())
S=input()
lst=[]
koma=N
rs=0
ME=0
pn=0
while koma>0 and pn==0:
rs+=1
if int(S[koma-rs])==0:
ME=rs
if koma-rs==0 or rs==M:
lst.append(ME)
if ME==0:
pn+=1
koma-=ME
rs=rs-ME
ME=0
if pn>0:
print(-1)
else:
lst.reverse()
print(*lst)
|
n = int(input())
ans = 0
for i in range(9):
if n % (i+1) == 0:
if n//(i+1) >= 1 and n//(i+1) <= 9:
print('Yes')
ans = 1
break
if ans == 0:
print('No')
| 0 | null | 149,919,229,267,290 | 274 | 287 |
import bisect
n = int(input().strip())
S = list(input().strip())
L=[[] for _ in range(26)]
for i,s in enumerate(S):
L[ord(s)-ord("a")].append(i)
q = int(input().strip())
for _ in range(q):
query=input().strip().split()
if query[0]=="1":
i=int(query[1])
i-=1
c=query[2]
if S[i]!=c:
delInd=bisect.bisect_left(L[ord(S[i])-ord("a")],i)
del L[ord(S[i])-ord("a")][delInd]
bisect.insort(L[ord(c)-ord("a")], i)
S[i]=c
else:
l,r=map(int,[query[1],query[2]])
l-=1; r-=1
ans=0
for j in range(26):
ind=bisect.bisect_left(L[j],l)
if ind<len(L[j]) and L[j][ind]<=r:
ans+=1
print(ans)
|
import sys,queue,math,copy,itertools,bisect,collections,heapq
def main():
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
N = NI()
R = 2**(N.bit_length())
st = [0] * (R*2)
def update(i,s):
x = 2 ** (ord(s) - ord('a'))
i += R-1
st[i] = x
while i > 0:
i = (i-1) // 2
st[i] = st[i*2+1] | st[i*2+2]
def query(l,r):
l += R-1
r += R-2
ret = 0
while l+1 < r:
if l % 2 == 0:
ret |= st[l]
if r % 2 == 1:
ret |= st[r]
r -= 1
l = l // 2
r = (r-1) // 2
if l == r:
ret |= st[l]
else:
ret |= st[l] | st[r]
return ret
for i,s in enumerate(sys.stdin.readline().rstrip()):
update(i+1,s)
Q = NI()
for _ in range(Q):
c,a,b = sys.stdin.readline().split()
if c == '1':
update(int(a),b)
else:
ret = query(int(a),int(b)+1)
cnt = 0
b = 1
for i in range(26):
cnt += (b & ret) > 0
b <<= 1
print(cnt)
if __name__ == '__main__':
main()
| 1 | 62,932,419,894,318 | null | 210 | 210 |
n = int(input())
a = list( map(int, input().split()))
p =10**9+7
cnt= [0]*n
cnt[0]=1
ans = 3
if a[0]!=0:
print(0)
exit()
for i in range(1,n):
if a[i]==0:
ans *= (3-cnt[a[i]])
else:
ans *= (cnt[a[i]-1] - cnt[a[i]])
if cnt[a[i]-1]==0:
print(0)
exit()
ans%=p
cnt[a[i]] += 1
if cnt[a[i]]>3:
print(0)
exit()
print(ans%p)
|
def resolve():
MOD = 1000000007
N = int(input())
A = list(map(int, input().split()))
C = [0]*(N+1)
C[0] = 3
ans = 1
for i in range(N):
a = A[i]
ans *= C[a]
ans %= MOD
C[a] -= 1
C[a+1] += 1
print(ans)
if __name__ == "__main__":
resolve()
| 1 | 130,658,269,968,900 | null | 268 | 268 |
from collections import *
n, p = map(int, input().split())
s = list(map(int, input()))
if 10%p==0:
r = 0
for i in range(n):
if s[i]%p==0:
r += i+1
print(r)
exit()
c = Counter()
c[0] += 1
v = r = 0
k = 1
for i in s[::-1]:
v += int(i)*k
v %= p
r += c[v]
c[v] += 1
k *= 10
k %= p
print(r)
|
n, p = map(int, input().split())
s = input()
ruisekiwa = [0 for _ in range(0, n + 1)]
if 10 % p == 0:
ans = 0
for i in range(0, n):
if (ord(s[i]) - ord('0')) % p == 0:
ans += i + 1
print(ans)
exit()
ten = 1
for _i in range(0, n):
i = n - _i - 1
ruisekiwa[n - i] = ((ord(s[i]) - ord('0')) * ten + ruisekiwa[n - i - 1]) % p
ten *= 10
ten %= p
ans = 0
cnt = [0 for _ in range(0, p)]
for i in range(0, n+1):
ans += cnt[ruisekiwa[i]]
cnt[ruisekiwa[i]] += 1
print(ans)
| 1 | 58,058,740,289,130 | null | 205 | 205 |
import math
a,b,c,d = map(int,input().split())
def death_time(hp,atack):
if hp%atack == 0:
return hp/atack
else:
return hp//atack + 1
takahashi_death = death_time(a,d)
aoki_death = death_time(c,b)
if aoki_death<=takahashi_death:
print("Yes")
else:
print("No")
|
n, m, x = map(int, input().split())
c = []
algo = []
for _ in range(n):
l = list(map(int, input().split()))
c.append(l[0])
algo.append(l[1:])
cost = []
for i in range(2**n):
c_sum = 0
u_sum = [0]*m
for j in range(n):
if (i>>j) & 1:
c_sum += c[j]
for k in range(m):
u_sum[k] += algo[j][k]
if all(s >= x for s in u_sum):
cost.append(c_sum)
if cost:
print(min(cost))
else:
print(-1)
| 0 | null | 26,090,513,321,070 | 164 | 149 |
def main():
import sys
from collections import defaultdict
input = sys.stdin.readline
K = int(input())
S = len(input().strip())
mod = 10 ** 9 + 7
fact = [1] * (K + S + 1)
invfact = [1] * (K + S + 1)
for i in range(K + S):
fact[i+1] = (fact[i] * (i+1)) % mod
invfact[-1] = pow(fact[-1], mod-2, mod)
for i in range(K + S):
invfact[-2-i] = (invfact[-1-i] * (K + S - i)) % mod
def nCr(n, r):
if r == n or r == 0:
return 1
r = min(r, n - r)
return (fact[n] * invfact[n-r] * invfact[r]) % mod
ans = 0
for i in range(K+1):
ans += pow(25, i, mod) * nCr(i+S-1, S-1) * pow(26, K-i, mod)
ans %= mod
print(ans)
if __name__ == '__main__':
main()
|
while True:
H, W = map(int, input().split())
if H == W == 0:
break
for i in range(W):
print('#', end='')
print('')
for i in range(H - 2):
print('#', end='')
for j in range(W - 2):
print('.', end='')
print('#')
for i in range(W):
print('#', end='')
print('\n')
| 0 | null | 6,868,883,301,762 | 124 | 50 |
import sys
read = lambda: sys.stdin.readline().rstrip()
def counting_tree(N, D):
import collections
tot = 1
cnt = collections.Counter(D)
"""
cnt = [0]*N
for i in D:
cnt[i]+=1
"""
for i in D[1:]:
tot = tot * cnt[i-1]%998244353
return tot if D[0]==0 else 0
def main():
N0 = int(read())
D0 = tuple(map(int, read().split()))
res = counting_tree(N0, D0)
print(res)
if __name__ == "__main__":
main()
|
from collections import defaultdict
N = int(input())
D = list(map(int, input().split()))
MOD = 998244353
p = defaultdict(int)
for d in D:
p[d] += 1
if p[0] == 1 and D[0] == 0:
ans = 1
for i in range(max(D)):
ans *= pow(p[i], p[i + 1], MOD)
ans %= MOD
if ans == 0:
break
print(ans)
else:
print(0)
| 1 | 154,536,224,325,030 | null | 284 | 284 |
i=input;i();l=i().split();x=1-('0'in l)
for j in l:
x*=int(j)
if x>1e18:
print(-1);quit()
print(x)
|
N=int(input())
A_list=sorted(list(map(int, input().split())), reverse=True)
ans=1
for a in A_list:
ans*=a
if ans>1e+18:
ans=-1
break
if 0 in A_list:
ans=0
print(ans)
| 1 | 16,207,666,770,460 | null | 134 | 134 |
n = input()
num = map(int, raw_input().split())
for i in range(n):
if i == n-1:
print num[n-i-1]
break
print num[n-i-1],
|
input()
xs=reversed(input().split())
print(" ".join(xs))
| 1 | 994,773,928,830 | null | 53 | 53 |
s=input();print(('No','Yes')[s==input()[:len(s)]])
|
S=input()
T=input()
if T.find(S)==0:
print("Yes")
else:
print("No")
| 1 | 21,296,111,056,000 | null | 147 | 147 |
s,t = map(str,input().split())
print(t ,end='')
print(s)
|
import sys
import math
from collections import defaultdict
from collections import deque
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def make_grid_int(h, w, num): return [[int(num)] * w for _ in range(h)]
def main():
R, C, K = NMI()
grid = make_grid_int(R, C, 0)
for i in range(K):
r_, c_, v_, = NMI()
grid[r_ - 1][c_ - 1] = v_
dp = [[[0 for _ in range(C + 2)] for _ in range(R + 2)] for _ in range(4)]
for i in range(R + 1):
for j in range(C + 1):
for k in range(4):
a = dp[k][i][j]
try:
v = grid[i][j]
except:
v = 0
if k == 3:
dp[0][i + 1][j] = max(a, dp[0][i + 1][j])
continue
dp[0][i + 1][j] = max(a, a + v, dp[0][i + 1][j])
dp[k][i][j + 1] = max(a, dp[k][i][j + 1])
dp[k + 1][i][j + 1] = max(a + v, dp[k + 1][i][j + 1])
print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C]))
if __name__ == "__main__":
main()
| 0 | null | 54,136,200,085,440 | 248 | 94 |
S = input().replace("><", "> <").split()
ans = 0
for s in S:
up = s.count("<")
down = len(s) - up
if up < down:
up -= 1
ans += up * (up+1) // 2 + down * (down+1) // 2
else:
down -= 1
ans += up * (up+1) // 2 + down * (down+1) // 2
print(ans)
|
n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=[]
for i in range(n):
ct=0
score=0
s=[]
pos=i
while ct<k:
ct+=1
pos=p[pos]-1
score+=c[pos]
s.append(score)
if pos==i:
break
if s[-1]<0:
ans.append(max(s))
elif pos!=i:
ans.append(max(s))
elif k%len(s)==0:
ans.append(s[-1]*(k//len(s)-1)+max(s))
else:
ans.append(max(s[-1]*(k//len(s)-1)+max(s),s[-1]*(k//len(s))+max(s[0:k%len(s)])))
print(max(ans))
| 0 | null | 81,254,230,122,560 | 285 | 93 |
N = int(input())
A = [int(i) for i in input().split(" ")]
Min = float("inf")
index = 0
L = 0
R = sum(A)
for i in range(0,len(A)):
L+=A[i]
R-=A[i]
diff = abs(L - R)
if diff < Min:
Min = diff
print(Min)
|
n=int(input())
a=list(map(int,input().split()))
l=0
r=sum(a)
ans=20202020200
for i in range(n):
l+=a[i]
r-=a[i]
ans=min(ans,abs(l-r))
print(ans)
| 1 | 141,484,408,440,288 | null | 276 | 276 |
x , y = map(int , input().split());
ans = 0;
if(x == 1):
ans += 300000;
if(x == 2):
ans += 200000;
if(x == 3):
ans += 100000;
if(y == 1):
ans += 300000;
if(y == 2):
ans += 200000;
if(y == 3):
ans += 100000;
if(x + y == 2):
ans += 400000;
print(ans)
|
a, b = input().split(" ")
x = int(a)
y = int(b)
amt = 0
if x == 1:
amt += 300000
elif x == 2:
amt += 200000
elif x == 3:
amt += 100000
if y == 1:
amt += 300000
elif y == 2:
amt += 200000
elif y == 3:
amt += 100000
if x == 1 and y == 1:
amt += 400000
print (amt)
| 1 | 140,920,879,392,182 | null | 275 | 275 |
n = int(input())
a = list(map(int,input().split()))
ans = 1
for i in a :
ans *= i
if ans > 10**18 :
ans = -1
break
if 0 in a :
ans = 0
print(ans)
|
from collections import Counter
import math
def combinations_count(n):
return (n * (n - 1)) // 2
N = int(input())
A = list(map(int, input().split()))
combs = {}
dic = Counter(A)
for k, v in dic.items():
combs[k] = combinations_count(v)
ans = sum(combs.values())
for i in range(N):
a = A[i]
ans_i = ans
if combs[a] < 2:
ans_i -= combs[a]
print(ans_i)
else:
ans_i -= dic[a] - 1
print(ans_i)
| 0 | null | 31,877,574,858,400 | 134 | 192 |
N=int(input())
A=list(map(int,input().split()))
flg=True
for i in A:
if i%2==0:
if i%3==0 or i%5==0:
pass
else:
flg=False
break
else:
pass
if flg:
print("APPROVED")
else:
print("DENIED")
|
n=int(input())
a=list(map(int,input().split()))
ans='APPROVED'
for i in range(n):
if a[i]%2==0:
if a[i]%3!=0 and a[i]%5!=0:
ans='DENIED'
print(ans)
| 1 | 68,929,420,266,518 | null | 217 | 217 |
N, K = map(int, input().split())
a = input().split()
a = list(map(int,a))
a.sort()
b = sum(a[:K])
print(b)
|
n = int(input())
s0=list(str(n))
ans=0
if len(s0)==1:
print(n)
exit()
if len(s0)==2:
for i in range(1,n+1):
s1=list(str(i))
if s1[-1]=='0':
continue
if s1[0]==s1[-1]:
ans+=1
if int(s1[-1])*10+int(s1[0])<=n:
ans+=1
print(ans)
exit()
for i in range(1,n+1):
s1=list(str(i))
if s1[-1]=='0':
continue
if s1[0]==s1[-1]:
ans+=1
for j in range(2,len(s0)):#nより小さい桁数のものを足す
ans+=10**(j-2)
if int(s0[0])>int(s1[-1]):#nより入れ替えた数の最高位数が小さいとき、全て足す
ans+=10**(len(s0)-2)
elif s0[0]==s1[-1]:#nと入れ替えた数の最高位数が同じ時
ans+=int(''.join(s0[1:len(s0)-1]))+1
if int(s0[-1])<int(s1[0]):
ans-=1
print(ans)
| 0 | null | 48,924,561,413,770 | 120 | 234 |
#!/usr/bin/env python3
def main():
h,w,k = map(int, input().split())
s = [input() for i in range(h)]
l = [[0]*w for i in range(h)]
from collections import deque
d = deque()
c = 1
for i in range(h):
for j in range(w):
if s[i][j] == '#':
d.append([i, j])
l[i][j] = c
c += 1
while len(d) > 0:
x,y = d.pop()
c = l[x][y]
l[x][y] = c
f1 = True
f2 = True
for i in range(1,w):
if y+i < w and l[x][y+i] == 0 and s[x][y+i] != '#' and f1:
l[x][y+i] = c
else:
f1 = False
if 0 <= y-i and l[x][y-i] == 0 and s[x][y-i] != '#' and f2:
l[x][y-i] = c
else:
f2 = False
for i in range(h):
if all(l[i]) == 0:
k1 = 1
while 0 < i+k1 < h and all(l[i+k1]) == 0:
k1 += 1
# print("test: ", i, k1)
if i+k1 < h:
for j in range(i, i+k1):
for r in range(w):
l[j][r] = l[i+k1][r]
for i in range(h-1, -1, -1):
if all(l[i]) == 0:
k1 = 1
while 0 < i-k1 < h and all(l[i-k1]) == 0:
k1 += 1
# print("test: ", i, k1)
if 0 <= i-k1 < h:
for j in range(i, i-k1, -1):
for r in range(w):
l[j][r] = l[i-k1][r]
for i in range(h):
print(' '.join(map(str, l[i])))
if __name__ == '__main__':
main()
|
H, W, K = map(int, input().split())
grid = [input() for _ in range(H)]
ans = [[0] * W for _ in range(H)]
cnt = 1
for h in range(H):
for w in range(W):
if grid[h][w] == "#":
ans[h][w] = cnt
cnt += 1
# left -> right
for h in range(H):
for w in range(1, W):
if ans[h][w] == 0 and ans[h][w - 1] != 0:
ans[h][w] = ans[h][w - 1]
# right -> left
for h in range(H):
for w in range(W - 2, -1, -1):
if ans[h][w] == 0 and ans[h][w + 1] != 0:
ans[h][w] = ans[h][w + 1]
# top -> bottom
for h in range(1, H):
for w in range(W):
if ans[h][w] == 0 and ans[h - 1][w] != 0:
ans[h][w] = ans[h - 1][w]
# bottom -> top
for h in range(H - 2, -1, -1):
for w in range(W):
if ans[h][w] == 0 and ans[h + 1][w] != 0:
ans[h][w] = ans[h + 1][w]
for a in ans:
print(*a)
| 1 | 144,216,358,113,620 | null | 277 | 277 |
word = input()
if (word.endswith('s')):
print(word + 'es')
else:
print(word + 's')
|
s=input()
if s[len(s)-1]=='s':print(s+'es')
else:print(s+'s')
| 1 | 2,415,220,397,546 | null | 71 | 71 |
import sys
input = sys.stdin.readline
r,c,k = map(int,input().split())
l = [[0]*c for i in range(r)]
for i in range(k):
x,y,v = map(int,input().split())
l[x-1][y-1] = v
dp = [[0]*4 for i in range(c+1)]
for i in range(r):
ndp = [[0]*4 for i in range(c+1)]
for j in range(c):
M = max(dp[j+1])
if l[i][j]>0:
v = l[i][j]
ndp[j+1][0] = max(M,dp[j][0],ndp[j][0])
ndp[j+1][1] = max(M+v,dp[j][0]+v,ndp[j][0]+v,dp[j][1],ndp[j][1])
ndp[j+1][2] = max(dp[j][1]+v,ndp[j][1]+v,dp[j][2],ndp[j][2])
ndp[j+1][3] = max(dp[j][2]+v,ndp[j][2]+v,dp[j][3],ndp[j][3])
else:
ndp[j+1][0] = max(M,dp[j][0],ndp[j][0])
ndp[j+1][1] = max(dp[j][1],ndp[j][1])
ndp[j+1][2] = max(dp[j][2],ndp[j][2])
ndp[j+1][3] = max(dp[j][3],ndp[j][3])
dp = ndp
print(max(dp[-1]))
|
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7
def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def main():
R, C, K = read_values()
V = [0] * (R * C)
for _ in range(K):
r, c, v = read_values()
r -= 1
c -= 1
V[r * C + c] = v
dp = [0 for _ in range(R * C * 4)]
for i in range(R * C):
r = i // C
c = i % C
if c + 1 < C:
# not take
for k in range(4):
dp[4 * (i + 1) + k] = max(dp[4 * (i + 1) + k], dp[4 * i + k])
# take
for k in range(3):
dp[4 * (i + 1) + k + 1] = max(dp[4 * (i + 1) + k + 1], dp[4 * i + k] + V[i])
# next r
if r + 1 < R:
for k in range(4):
dp[4 * (i + C)] = max(dp[4 * (i + C)], dp[4 * i + k] + (V[i] if k < 3 else 0))
res = 0
for k in range(4):
res = max(res, dp[4 * (R * C - 1) + k] + (V[-1] if k < 3 else 0))
print(res)
if __name__ == "__main__":
main()
| 1 | 5,533,003,495,132 | null | 94 | 94 |
n = int(input())
answer = 0
for i in range(1, n+1):
md = n // i
answer += i * (md *(md+1) // 2)
print(answer)
|
N = int(input())
root = int(N**0.5)
for i in range(root,-1,-1):
if N % i ==0:
break
print(int(N/i + i -2))
| 0 | null | 86,070,550,110,838 | 118 | 288 |
a=int(input())
result=a+a**2+a**3
print(int(result))
|
""" Atcorder practice 20200719 """
# test programm for practice
def __main__():
""" def for calc """
num_input = int(input())
if num_input < 1 or num_input > 10:
raise ValueError
#elif num_input % 1 != 0:
#raise ValueError
else:
print(num_input + num_input**2 + num_input**3)
if __name__ == "__main__":
__main__()
| 1 | 10,264,166,653,850 | null | 115 | 115 |
import numpy as np
a= input()
K = [1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51]
print(K[int(a)-1])
|
import sys
lst=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
pos = input()
print(lst[int(pos)-1])
| 1 | 49,922,244,891,050 | null | 195 | 195 |
s=input()
res=''
for i in s:
if i.islower():
i=i.upper()
elif i.isupper():
i=i.lower()
res+=i
print(res)
|
import sys
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
buf = str(input())
print(buf.swapcase())
| 1 | 1,493,318,477,952 | null | 61 | 61 |
a1,a2,a3 = map(int,input().split())
if a1+a2+a3 >21:
print('bust')
else:
print('win')
|
N = int(input())
S =list(map(int,input()))
ans = 0
for x in [0,1,2,3,4,5,6,7,8,9]:
if x in S:
x_index = S.index(x)
for y in [0,1,2,3,4,5,6,7,8,9]:
if y in S[x_index+1:]:
y_index = S[x_index+1:].index(y)
for z in [0,1,2,3,4,5,6,7,8,9]:
if z in S[x_index + 1 + y_index+1:]:
ans += 1
print(ans)
| 0 | null | 123,757,235,727,940 | 260 | 267 |
n = list(map(int, input().split()))
print('Yes' if sum(n) % 9 == 0 else 'No')
|
class SegTree:
""" segment tree with point modification and range product. """
# # https://yukicoder.me/submissions/452850
def __init__(self, N, data_f = min, data_unit=1<<30):
self.N = N
self.data_f = data_f
self.data_unit = data_unit
self.data = [self.data_unit] * (N + N)
def build(self, raw_data):
data = self.data
f = self.data_f
N = self.N
data[N:] = raw_data[:]
for i in range(N - 1, 0, -1):
data[i] = f(data[i << 1], data[i << 1 | 1])
def set_val(self, i, x):
data = self.data
f = self.data_f
i += self.N
data[i] = x
while i > 1:
data[i >> 1] = f(data[i], data[i ^ 1])
i >>= 1
def fold(self, L, R):
""" compute for [L, R) """
vL = vR = self.data_unit
data = self.data
f = self.data_f
L += self.N
R += self.N
while L < R:
if L & 1:
vL = f(vL, data[L])
L += 1
if R & 1:
R -= 1
vR = f(data[R], vR)
L >>= 1
R >>= 1
return f(vL, vR)
N=int(input())
S=input()
data = [[0]*N for _ in range(26)]
di = {}
for i in range(N):
data[ord(S[i])-97][i] = 1
di[i] = S[i]
seg = [SegTree(N,max,0) for _ in range(26)]
for i in range(26):
seg[i].build(data[i])
Q=int(input())
for i in range(Q):
*q, = input().split()
if q[0] == '1':
i, c = q[1:]
i = int(i)-1
c_old = di[i]
di[i] = c
seg[ord(c_old)-97].set_val(i,0)
seg[ord(c)-97].set_val(i,1)
else:
l,r = map(int,q[1:])
ans=0
for i in range(26):
ans += seg[i].fold(l-1,r)
print(ans)
| 0 | null | 33,589,145,785,320 | 87 | 210 |
import sys
# A - Don't be late
D, T, S = map(int, input().split())
if S * T >= D:
print('Yes')
else:
print('No')
|
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 3 23:43:13 2020
@author: liang
"""
N ,M ,Q = map(int, input().split())
A = list()
lis = list()
ans = 0
def make_list(n,m):
if n == N:
A.append(lis.copy())
return
for i in range(m,M+1):
lis.append(i)
make_list(n+1,i)
lis.pop()
make_list(0,1)
#print(A)
calc = [list(map(int,input().split())) for _ in range(Q)]
for a in A:
tmp = 0
for c in calc:
if a[c[1]-1] - a[c[0]-1] == c[2]:
tmp += c[3]
if tmp > ans:
ans = tmp
print(ans)
| 0 | null | 15,554,149,606,702 | 81 | 160 |
while True:
n, x = map(int, input().split())
if not n and not x:
break
li = []
for i in range(1,x//3):
y = x - i
li.append((y-1)//2 - max(i, y-n-1))
print(sum([comb for comb in li if comb > 0]))
|
# coding: utf-8
import itertools
data_set = []
answer = []
while (1):
n,x = map(int, input().split())
if (n == 0 and x == 0):
break
data_set.append([n,x])
for d in data_set:
num = list(range(d[0] + 1))[1:]
counter = 0
for i in itertools.combinations(num, 3):
if (sum(i) == d[1]):
counter += 1
answer.append(counter)
for ans in answer:
print(ans)
| 1 | 1,277,690,970,400 | null | 58 | 58 |
n = int(input())
a = 0
b = 0
for i in range(n):
t1,t2 = input().split()
if t1>t2:
a+=3
elif t1==t2:
a+=1
b+=1
else:
b+=3
print(a,b)
|
n, x, y = list(map(int, input().split()))
x = x-1
y = y-1
ans = [0] * (n-1)
for i in range(n):
for j in range(i+1, n):
shortest = min(abs(j-i), abs(x-i)+abs(y-j)+1, abs(y-i)+abs(x-j)+1)
ans[shortest-1] += 1
for a in ans:
print(a)
| 0 | null | 23,224,693,318,660 | 67 | 187 |
def gcd(a, b):
c = max([a, b])
d = min([a, b])
if c % d == 0:
return d
else:
return gcd(d, c % d)
nums = input().split()
print(gcd(int(nums[0]), int(nums[1])))
|
a,b,c,k=map(int,input().split())
if a>=k:
print(k)
elif (k>a) and (a+b>=k):
print(a)
elif (a+b<k):
print(a-(k-(a+b)))
| 0 | null | 10,979,146,947,260 | 11 | 148 |
A, B, N = map(int, input().split())
if N >= B - 1:
print(int(A * (B - 1) / B))
else:
print(int(A * N / B))
|
#!/usr/bin/env python3
def main():
import sys
input = sys.stdin.readline
A, B, N = map(int, input().split())
x = min(B - 1, N)
print((A * x) // B - A * (x // B))
if __name__ == '__main__':
main()
| 1 | 28,173,276,693,604 | null | 161 | 161 |
H, W, K = map(int, input().split())
grid = 'x' * (W + 2)
for _ in range(H):
grid += 'x' + input() + 'x'
grid += 'x' * (W + 2)
N = len(grid)
strb = [i for i in range(N) if grid[i] == '#']
G = [0] * N
for i, s in enumerate(strb, 1):
q = [s]
while q:
x = q.pop()
if G[x] != 0:
continue
G[x] = i
for dx in [1, -1]:
y = x + dx
if grid[y] == '.' and G[y] == 0:
q.append(y)
for i in range(N - 1, -1, -1):
if G[i] == 0 and i + W + 2 < N:
G[i] = G[i + W + 2]
for i in range(N):
if G[i] == 0 and i - W - 2 < N:
G[i] = G[i - W - 2]
j = 0
for i in range(H):
print(' '.join(str(x) for x in G[j + W + 3:j + 2 * W + 3]))
j += W + 2
|
N = int(input())
items = set(input() for i in range(N))
print(len(items))
| 0 | null | 86,973,888,742,090 | 277 | 165 |
a = list(input().split())
print("Yes" if len(set(a)) == 2 else "No")
|
num_l = set(map(int, input().split()))
print('Yes' if len(num_l) == 2 else 'No')
| 1 | 68,204,213,474,124 | null | 216 | 216 |
import sys
input = sys.stdin.readline
def main():
N, M = map(int, input().split())
P = [0] * M
S = [""] * M
for i in range(M):
PS = input().split()
P[i], S[i] = int(PS[0]), PS[1]
AC = [False] * (N + 1)
WA = [0] * (N + 1)
n_AC = 0
n_WA = 0
for p, s in zip(P, S):
if AC[p]:
continue
if s == "AC":
n_AC += 1
AC[p] = True
n_WA += WA[p]
else:
WA[p] += 1
print(n_AC, n_WA)
if __name__ == "__main__":
main()
|
N,M = map(int, input().split())
AC = [0] * (N+1)
pl = [0] * (N+1)
cole = 0
pena = 0
for target_list in range(M):
ans = input().split()
problem = int(ans[0])
result = ans[1]
if AC[problem] == 0 and result == 'WA':
pl[problem] += 1
elif AC[problem] == 0 and result == 'AC':
pena += pl[problem]
cole += 1
AC[problem] = 1
print(cole, pena)
| 1 | 93,113,961,765,330 | null | 240 | 240 |
n = int(input())
a = list(map(int, input().split()))
b = a[0]
for v in a[1:]:
b ^= v
print(*map(lambda x: x ^ b, a))
|
n=int(input())
arr=list(map(int,input().split()))
x=0
for i in arr:
x^=i
ans=[]
for i in arr:
ans.append(x^i)
print(*ans)
| 1 | 12,519,219,725,042 | null | 123 | 123 |
a,c,b = list(map(int, input().split()))
a = abs(a)
b = abs(b)
c = abs(c)
if b*c <= a:
print(a - (b*c))
else:
c -= a//b
a = a%b
#print(a,b,c)
if c%2==0:
print(a)
else:
print(abs(a-b))
|
x,k,d=map(int,input().split())
x=abs(x)
if x%d==0:
minNear = x%d + d
minFar = x%d
minTransitionToNear = (x-minNear)/d
#print(minNear)
#print(minFar)
#print(minTransitionToNear)
else:
minNear = x%d
minFar = x%d - d
minTransitionToNear = (x-minNear)/d
#print(minNear)
#print(minFar)
#print(minTransitionToNear)
if k<minTransitionToNear:
print(x-k*d)
else:
if (k-minTransitionToNear)%2==0:
print(abs(minNear))
else:
print(abs(minFar))
| 1 | 5,187,919,631,520 | null | 92 | 92 |
a1,a2,a3=(int(x) for x in input().split())
if a1+a2+a3>=22:
print("bust")
else:
print("win")
|
from decimal import Decimal as D
a,b=map(str,input().split())
print(int(D(a)*D(b)))
| 0 | null | 67,959,876,650,308 | 260 | 135 |
X = int(input())
n = X % 100
m = X // 100
cnt = 0
for a in reversed(range(1, 6)):
while n - a >= 0:
n -= a
cnt += 1
if cnt <= m:
print(1)
else:
print(0)
|
x = int(input())
cnt = x//100
if x < 100 :
print("0")
else :
for i in range(cnt) :
if 100*cnt <= x <= 105*cnt :
print("1")
break
else :
print("0")
| 1 | 127,095,679,165,492 | null | 266 | 266 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.