code1 stringlengths 16 427k | code2 stringlengths 16 427k | similar int64 0 1 | pair_id int64 2 178,025B ⌀ | question_pair_id float64 27.1M 177,113B ⌀ | code1_group int64 1 297 | code2_group int64 1 297 |
|---|---|---|---|---|---|---|
from collections import deque
n,m = map(int,input().split())
to = [[] for _ in range(n)]
for i in range(m):
x, y = map(int,input().split())
to[x-1].append(y-1)
to[y-1].append(x-1)
INF = float('inf')
dist = [INF]*n
dist[0] = 0
pre = [-1]*n
que = deque([])
que.append(0)
while que:
v = que.popleft()
... | def main():
from collections import deque
import sys
input = sys.stdin.readline
N,M = map(int,input().split())
to = [[] for _ in range(N)]
for _ in range(M):
a,b = map(int,input().split())
a -= 1
b -= 1
to[a].append(b)
to[b].append(a)
... | 1 | 20,385,830,829,748 | null | 145 | 145 |
n,k=map(int,input().split())
ans=1
while n//(k**ans):
ans+=1
print(ans) | n,k = map(int,input().split())
ans = 1
while n >= k:
ans += 1
n //= k
print(ans) | 1 | 64,084,599,808,192 | null | 212 | 212 |
MOD = 1000000007
def fast_power(base, power):
"""
Returns the result of a^b i.e. a**b
We assume that a >= 1 and b >= 0
Remember two things!
- Divide power by 2 and multiply base to itself (if the power is even)
- Decrement power by 1 to make it even and then follow the first step
"""
... | # -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal
class Scanner()... | 0 | null | 93,010,028,528,172 | 176 | 281 |
import sys
x,y = map(int,input().split())
for n in range(x+1):
kame = x - n
tsuru_leg = n*2
kame_leg = kame*4
if y == tsuru_leg + kame_leg:
print('Yes')
sys.exit()
print('No') | def main():
n = int(input())
c = input()
r = 0
for i in range(n):
if c[i]=='R':
r += 1
ans = 0
for i in range(r):
if c[i]=='W':
ans += 1
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 9,996,957,363,602 | 127 | 98 |
n = int(input())
added_strings = set()
for i in range(n):
com, s = input().split()
if com == 'insert':
added_strings.add(s)
elif com == 'find':
print('yes' if (s in added_strings) else 'no')
| def triangle(N, Ls):
result = 0
res = []
numbers = {}
edgeLength = list(set(Ls))
for i in edgeLength:
numbers[i] = Ls.count(i)
for i in range(len(edgeLength)):
a = edgeLength[i]
copy1 = edgeLength[i+1:]
for j in range(len(copy1)):
b = copy1[j]
copy2 = copy1[j+1:]
for k i... | 0 | null | 2,580,574,755,748 | 23 | 91 |
str = input()
n = int(input())
for i in range(n):
args = input().split()
command = args[0]
s = int(args[1])
e = int(args[2])
if command == 'print':
print(str[s:e + 1])
if command == 'reverse':
str = str[0:s] + str[s:e + 1][::-1] + str[e + 1:]
if command == 'replace':
... | n = int(input())
a = list(map(int, input().split()))
ans = 0
cnt = 0
for i in range(n) :
if a[i] == cnt + 1 :
cnt += 1
if cnt > 0 :
print(n-cnt)
else :
print("-1")
| 0 | null | 58,708,806,487,300 | 68 | 257 |
import sys
A = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51".split(", ")
N = int(sys.stdin.readline().rstrip())
print(A[N-1])
| #coding: utf-8
#itp1_9d
def rev(s,a,b):
b=b+1
t=s[a:b]
u=t[::-1]
x=s[:a]
y=s[b:]
return x+u+y
def rep(s,a,b,w):
b=b+1
x=s[:a]
y=s[b:]
return x+w+y
s=raw_input()
n=int(raw_input())
for i in xrange(n):
d=raw_input().split()
a=int(d[1])
b=int(d[2])
if d[0]=="print":
print s[a:b+1]
elif d[0]=="reverse":... | 0 | null | 25,958,495,438,120 | 195 | 68 |
a, b, c, k = map(int, input().split())
ans = 0
if a >= k:
ans = k
elif a < k and a+b >= k:
ans = a
else:
ans = a - (k-(a+b))
print(ans) | a, b, c, k = map(int, input().split())
if k - a <= 0:
print(k)
elif k - a > 0 and k - a - b <= 0:
print(a)
else:
s = k - a - b
print(a - s)
| 1 | 21,815,632,748,640 | null | 148 | 148 |
import sys
import time
import math
import itertools as it
def inpl():
return list(map(int, input().split()))
st = time.perf_counter()
# ------------------------------
A, B = map(int, input().split())
print(int(A*B))
# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)
| num1, num2 = map(int, input().split())
print(num1*num2) | 1 | 15,818,386,004,392 | null | 133 | 133 |
K=int(input())
A,B=map(int,input().split())
for x in range(A,B+1):
if x%K==0:
print("OK")
break
else:
print("NG")
| import sys
K = int(input())
A, B = (int(x) for x in input().split())
num=0
while B>=num:
num+=K
if A<=num and num<=B:
print("OK")
sys.exit(0)
print("NG") | 1 | 26,627,692,624,930 | null | 158 | 158 |
from sys import stdin
def ip(): return [int(i) for i in stdin.readline().split()]
def sp(): return [str(i) for i in stdin.readline().split()]
s = str(input())
c = 0
for i in s:
c += int(i)
if (c % 9) == 0: print("Yes")
else: print("No")
| import sys
import math
input = sys.stdin.readline
def main():
k = int(input())
ans = 0
for a in range( 1 , k+1 ):
for b in range( a , k+1 ):
x = math.gcd( a , b )
for c in range( b , k+1 ):
y = math.gcd( x , c )
if a == b == c:
... | 0 | null | 19,945,889,807,966 | 87 | 174 |
n, k = map(int, input().split())
sunukes = [0 for i in range(n)]
for i in range(k):
d = int(input())
aa = list(map(int, input().split()))
for j in range(d):
sunukes[aa[j] - 1] += 1
count = sum(1 for sunuke in sunukes if sunuke == 0)
print(count)
| import math , sys
N = int( input() )
A = list(map(int, input().split() ) )
def Prime(x):
ub=int(math.sqrt(x))+2
if x==2 or x==3 or x==5 or x==7:
return True
for i in range(2,ub):
if x%i==0:
return False
return True
y = N
while not Prime(y):
y+=1
def h1(x):
retur... | 0 | null | 25,167,976,730,240 | 154 | 157 |
n = int(input())
s = list(input())
r = s.count('R')
g = s.count('G')
b = s.count('B')
ans = r * g * b
for i in range(n-2):
for j in range(i+1,n-1):
if (j - i) + j < n:
k = (j - i) + j
if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
ans -= 1
print(ans) ... | N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N-2):
r = S[i]
for j in range(i+1,N-1):
g = S[j]
if r == g:
continue
k = 2*j - i
if k >= N:
continue
b = S[k]
if r != b and g != b:
an... | 1 | 35,905,663,729,490 | null | 175 | 175 |
#atcoder template
def main():
import sys
imput = sys.stdin.readline
#文字列入力の時は上記はerrorとなる。
#ここにコード
#input
N = int(input())
A, B = [0] * N, [0] * N
for i in range(N):
A[i], B[i] = map(int, input().split())
#output
import statistics as st
import math
p = st.median(... | i = int(input())
while (i > 0):
i -= 1000
print(abs(i)) | 0 | null | 12,751,057,368,312 | 137 | 108 |
import math
import sys
def main():
n = int(sys.stdin.readline())
total = 0
for i in range(1,n+1):
for j in range(1,n+1):
for k in range(1,n+1):
total += math.gcd(i, math.gcd(j,k))
print(total)
main() | from functools import lru_cache
MOD = 10**9+7
x,y = map(int, input().split())
summ = x+y
@lru_cache(maxsize=None)
def inv(n):
return pow(n,-1,MOD)
if summ%3 == 0 and summ//3 <= x and summ//3 <= y:
mn = min(x,y)
n = mn - summ//3
a = summ//3
b = 1
ans = 1
for i in range(n):
ans *= a
... | 0 | null | 93,228,400,453,792 | 174 | 281 |
a = []
try:
while True:
a.append(input())
except EOFError:
pass
for i in range(len(a)):
a[i] = a[i].lower()
b=" ".join(a)
for j in "abcdefghijklmnopqrstuvwxyz":
print(j,":",b.count(j))
| from collections import Counter
counter = Counter()
while True:
try:
s = input()
for c in s:
counter[c.lower()] += 1
except:
break
for c in range(ord('a'), ord('z')+1):
print('{} : {}'.format(chr(c), counter[chr(c)])) | 1 | 1,636,639,699,630 | null | 63 | 63 |
N = int(input())
S = input()
abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Sn = ""
for i in range(len(S)):
Sn += abc[(abc.find(S[i])+N) % 26]
print(Sn) | a = [int(s) for s in input().split()]
b = int(a[0] // (a[1] + a[2]))
c = int(a[0] % (a[1] + a[2]))
d = b * a[1]
if c >= a[1]:
d = d + a[1]
else:
d = d + c
print(d) | 0 | null | 95,242,284,795,840 | 271 | 202 |
import sys
import math
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(h, w, num): return [[int(num)] * w for _ in... | X,Y,A,B,C=list(map(int,input().split()))
p=sorted(list(map(int,input().split())),reverse=True)
q=sorted(list(map(int,input().split())),reverse=True)
r=sorted(list(map(int,input().split())),reverse=True)
i=X-1
j=Y-1
k=0
ans=sum(p[:X])+sum(q[:Y])
while k<len(r):
if i>-1 and j>-1:
if p[i]<q[j]:
... | 1 | 44,966,367,573,120 | null | 188 | 188 |
from queue import deque
S = input()
Q = int(input())
Query = list(input().split() for _ in range(Q))
count = 0
L, R = deque(), deque()
for i in range(Q):
if Query[i][0] == "1": count += 1
else:
if Query[i][1] == "1":
if count % 2 == 0: L.appendleft(Query[i][2])
else: R.append(Query[i][2])
else... | while True:
n = int(input())
if n == 0: break
s = list(map(float, input().split()))
m = sum(s) / n
a = (sum((s[i] - m) ** 2 for i in range(n)) / n) ** 0.5
print(a) | 0 | null | 28,838,868,730,180 | 204 | 31 |
l = int(input())
x = l/3
ans = x**3
print(str(ans)) | #!/usr/bin/env python3
n = int(input())
n /= 3
print(n**3) | 1 | 47,060,893,263,400 | null | 191 | 191 |
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
n,m = ma()
s = input()
dp = [-1]*(n+1) #dp[i]:: ... | def coin_change(coins, payment):
T = [0] + [50001] * payment
for c in coins:
for i, t in enumerate(zip(T[c:], T), start=c):
a, b = t
T[i] = min(a, b + 1)
return T[payment]
n, m = map(int, input().split())
c = list(map(int, input().split()))
ans = coin_change(c, n)
print(a... | 0 | null | 69,391,845,425,536 | 274 | 28 |
x = input()
print pow(x, 3) | string = input()
if string == "ARC": print("ABC")
else: print("ARC") | 0 | null | 12,219,393,515,858 | 35 | 153 |
from collections import deque
n,m=map(int,input().split())
ab=[list(map(int, input().split())) for _ in range(m)]
l=[[] for i in range(n)]#各部屋とつながっている部屋
#print(l,ab)
for a,b in ab:
l[a-1].append(b)
l[b-1].append(a)
result=[-1]*n
q=deque([1])
#print(l,result)
while True:
if len(q)==0:
break
x=q.p... | from collections import deque
def bfs(graph, n, s):
visited = [0]*n # 移動回数を保持
visited[s] = 1 # 部屋1の探索は完了としている
q = deque([s]) # 探索用にdequeを設定し、初期位置としてs(0)を設定する
while q:
node = q.popleft() # 先頭から順番に実行
for i in graph[node]: # 各部屋から行ける別の部屋を確認
if not visited[i]: # 値が"0"の場合に処理を実行
visited[i] = no... | 1 | 20,516,371,671,488 | null | 145 | 145 |
# coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, R = lr()
answer = R
if N < 10:
answer += (10-N) * 100
print(answer)
| # coding: utf-8
# Your code here!
N=int(input())
count=-1
for i in range(N//2+1):
count+=1
if N%2==0:
print(count-1)
else:
print(count) | 0 | null | 107,967,426,235,200 | 211 | 283 |
from statistics import median
n=int(input())
A,B=[],[]
for _ in range(n):
a,b=map(int,input().split())
A.append(a*2)
B.append(b*2)
ma,mb = int(median(A)),int(median(B))
#print(ma,mb)
if n%2 == 0:
print(mb-ma+1)
else:
print((mb-ma)//2+1)
|
import glob
# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = 'ABC\\169\\E'
# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'
class Common:
problem = []
index = 0
def __init__(self, rel_path):
self.rel_path = rel_path
def initialize(self, path):
file = open(path)
self.problem = file.readlines(... | 1 | 17,242,870,581,690 | null | 137 | 137 |
n = int(input())
ans = "No"
count = 0
for i in range(n):
D1,D2 = map(int,input().split())
count=count+1 if D1==D2 else 0
ans="Yes" if count>=3 else ans
print(ans) | print(list(map(int,input().split())).index(0) + 1) | 0 | null | 7,970,396,737,952 | 72 | 126 |
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
a=[]
for i in range(k):
a.append([])
for i in range(n):
a[i%k].append(t[i])
for i in range(k):
for j in range(len(a[i])):
if j>=1:
if a[i][j]==a[i][j-1]:
a[i][j]=0
ans=0
for i in range(k):
for j in ... | n,k = map(int, input().split())
r,s,p = map(int, input().split())
t = input()
def add(x):
if x == 'r':
return p
elif x == 's':
return r
else:
return s
nk =[0]*k
for i in range(n):
key = i%k
if nk[key]==0:
nk[key] = [t[i]]
else:
nk[key].append(t[i])
ans =... | 1 | 107,118,395,282,518 | null | 251 | 251 |
t=input()
ans=str()
tmp=""
for s in t:
if s=="P" or s=="D":
ans+=s
tmp=s
else:
ans+="D"
tmp="D"
print(ans) | T = input()
N = len(T)
after_T = ''
for i in range(N):
charr=T[i]
if(charr=='?'):
after_T+='D'
else:
after_T+=charr
print(after_T)
| 1 | 18,533,909,625,198 | null | 140 | 140 |
import math
f = True
N = int(input())
for i in range(N+1):
if math.floor(i*1.08) == N:
print(i)
f = False
break
if f:
print(":(")
| N = int(input())
for i in range(1 , N + 1):
x = int(i * 1.08)
if x == N:
print(i)
exit()
print(':(') | 1 | 126,065,945,856,970 | null | 265 | 265 |
L, R, d = map(int, input().split())
count = 0
if ((L and R and d >=1) and (L and R and d <= 100) ):
for L in range(L, R+1):
if (L%d == 0):
count +=1
print(count)
| L, R, d = map(int,input().split())
ans = 0
while L <= R:
if L % d == 0:
ans += 1
L += 1
print(ans) | 1 | 7,551,541,248,510 | null | 104 | 104 |
import sys
n = int(input())
input_line = [[int(i) for i in str.split()] for str in sys.stdin.read().splitlines()]
for i in range(n):
input_line[i] = [] if len(input_line[i]) == 2 else input_line[i][2:]
is_visit = [False] * n
distance = [0] * n
queue = [1]
while len(queue) != 0:
id = queue.pop(0)
is_visit[i... | import sys
sys.setrecursionlimit(1000000)
s=input()
#print(s)
l=[-1 for _ in range(len(s)+1)]
def aa(ix,v): #ixはlベース
# print(ix,v,l)
if (ix>= len(s) and v==1) or (ix==0 and v==0-1):
return
if v==1 and s[ix]=="<" and l[ix+1]<=l[ix]:
l[ix+1]=l[ix]+1
aa(ix+1,1)
elif v==-1 and s[ix-1]==">" and l[ix-1]<=l[... | 0 | null | 78,410,335,029,432 | 9 | 285 |
import sys
a=[map(int,i.split()) for i in sys.stdin]
[print(len(str(b+c))) for b,c in a] | # -*-coding:utf-8
import fileinput
if __name__ == '__main__':
for line in fileinput.input():
digit = 0
tokens = list(map(int, line.strip().split()))
a, b = tokens[0], tokens[1]
num = a + b
print(len(str(num))) | 1 | 119,574,838 | null | 3 | 3 |
N, M, K = map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
Asum=[0]
Bsum=[0]
for i, a in enumerate(A):
Asum.append(Asum[i]+a)
for i, b in enumerate(B):
Bsum.append(Bsum[i]+b)
ans, b = 0, M
for a, asum in enumerate(Asum):
if asum > K:
break
while Bsum[b]>K - asu... | # ==================================================-
# 二分探索
# functionを満たす,search_listの最大の要素を出力
# 【注意点】searchリストの初めの方はfunctionを満たし、後ろに行くにつれて満たさなくなるべき
import math
import sys
sys.setrecursionlimit(10 ** 9)
def binary_research(start, end,function):
if start == end:
return start
middle = math.ceil((star... | 1 | 10,757,552,060,164 | null | 117 | 117 |
from collections import deque
n,x,y = map(int,input().split())
adj = [[] for i in range(n)]
adj[x-1].append(y-1)
adj[y-1].append(x-1)
for i in range(n-1):
adj[i].append(i+1)
adj[i+1].append(i)
ans = [0]*(n-1)
for i in range(n):
q = deque([])
q.append(i)
dist = [-1]*n
dist[i] = 0
while... | N,M,X=map(int,input().split())
li=[]
ans=100000000000000000000000000000000
for j in range(N):
a=list(map(int,input().split()))
li.append(a)
for k in range(2**N):
temp=0
skill=[0]*M
k=str(bin(k))
k=k[2:]
while len(k)!=N:
k="0"+k
for l in range(N):
if k[l]=="1":
... | 0 | null | 33,280,884,291,428 | 187 | 149 |
n = int(input())
p = []
q = []
r = []
for i in range(2,(int(n**0.5)+1)):
N = n
if N%i == 0:
p.append(i)
for i in range(2,(int(n**0.5)+1)):
N = n - 1
if N%i == 0:
r.append(i)
if i != N//i:
r.append(N//i)
for i in range(len(p)):
N = n
while N % p[i] == 0:
... | def divisors(n):
small = []
large = []
i = 1
while i * i <= n:
if not n % i:
small.append(i)
large.append(n // i)
i += 1
if small[-1] == large[-1]:
large.pop()
return small + large[::-1]
n = int(input())
res = set(divisors(n - 1))
res.remove(1)
for d in divisors(n):
if d == 1:
... | 1 | 41,338,191,252,820 | null | 183 | 183 |
n = int(input())
s = list(input())
alp = list('ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ')
for i in range(len(s)):
for j in range(26):
if s[i] == alp[j]:
s[i] = alp[j+n]
break
print(''.join(s)) | import string
N = int(input())
S = input()
a = string.ascii_uppercase
# a = ABCDEFGHIJKLMNOPQRSTUVWXYZ
ans = ''
for s in S:
ans += a[(a.index(s) + N) % len(a)]
print(ans) | 1 | 134,476,918,954,500 | null | 271 | 271 |
import math
class Circle:
def output(self, r):
print "%.6f %.6f" % (math.pi * r * r, 2.0 * math.pi * r)
if __name__ == "__main__":
cir = Circle()
r = float(raw_input())
cir.output(r) | x, k, d = map(int, input().split())
x = abs(x)
kk = x // d
amari = x % d
if kk >= k:
ans = (kk - k) * d + amari
elif (k - kk) % 2 == 1:
ans = abs(amari - d)
else:
ans = amari
print(ans) | 0 | null | 2,963,780,874,160 | 46 | 92 |
n = int(input())
arrey = [int(i) for i in input().split()]
for i in range(n):
v = arrey[i]
j = i - 1
while j >= 0 and arrey[j] > v:
arrey[j+1] = arrey[j]
j = j - 1
arrey[j+1] = v
for k in range(n):
print(arrey[k]) if k == n-1 else print(str(arrey[k])+' ',end='') | while True:
try:
a,b = map(int,raw_input().split(' '))
print len(str(a+b))
except: break | 0 | null | 2,633,171,452 | 10 | 3 |
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
s = input()
if 'RRR' in s:
print(3)
elif 'RR' in s:
print(2)
elif 'R' in s:
print(1)
else:
print(0)
if __name__ == '__main__':
main() | S = input()
ans = 0
cnt = 0
for w in S:
if w == 'S':
ans = max(ans,cnt)
cnt = 0
else:
cnt += 1
ans = max(cnt,ans)
print(ans) | 1 | 4,869,006,029,120 | null | 90 | 90 |
n = int(input())
buf = list(map(int,input().split()))
a = []
for i in range(n):
a.append([buf[i],i])
a = sorted(a,reverse=True)
dp = [[0]*(n+1) for i in range(n+1)]
for i in range(n):
for j in range(n-i):
cur = i+j
temp1 = dp[i][j]+a[cur][0]*abs(n-1-a[cur][1]-j)
temp2 = dp[i][j]+a[cur][... | import sys
def main():
input = sys.stdin.buffer.readline
h, n = map(int, input().split())
a = [0] * n
b = [0] * n
for i in range(n):
a[i], b[i] = map(int, input().split())
max_a = max(a)
# dp[j]:jダメージ与える魔力の最小値
dp = [1e9] * (h + max_a + 1)
dp[0] = 0
for i in range(n):
... | 0 | null | 57,208,919,785,292 | 171 | 229 |
n,d = map(int,input().split())
count = 0
for i in range(n):
x,y = map(float,input().split())
if(d*d >= x*x + y*y):
count+=1
print(count) | x, k, d = map(int, input().split())
x = abs(x)
if x//d >= k:
print(x-k*d)
else:
k -= x//d
x -= d*(x//d)
if k%2==0:
print(abs(x))
else:
print(abs(x-d)) | 0 | null | 5,582,875,035,584 | 96 | 92 |
H1,M1,H2,M2,K = map(int,input().split())
A1 = H1*60+M1
A2 = H2*60+M2
print(max(0,A2-A1-K)) | h1, m1, h2, m2, k = map(int, input().split())
H = h2 - h1
if m1 <= m2:
M = m2 - m1
else:
M = 60 - m1 + m2
H -= 1
print(H*60 + M - k) | 1 | 17,930,431,613,120 | null | 139 | 139 |
n=int(input())
a=input().split(' ')
b=[int(i) for i in a]
s=0
for k in range(2,n):
for j in range(1,k):
for i in range(j):
if (b[i]!=b[j] and b[j]!=b[k] and b[k]!=b[i]):
m=max(b[i],b[j],b[k])
if 2*m<b[i]+b[j]+b[k]:
s+=1
print(s) | N = int(input())
A = [int(x) for x in input().split()]
B = [0]*(N+1)
if N == 0:
if A[0] != 1:
print(-1)
exit()
else:
print(1)
exit()
if A[0] != 0:
print(-1)
exit()
else:
B[0] = 1
C = [0]*(N+1)
C[0] = 1
for i in range(1,N+1):
C[i] = 2*(C[i-1] - A[i-1])
if C[i... | 0 | null | 12,093,516,452,192 | 91 | 141 |
# coding: utf-8
s = input()
print("x" * len(s))
| N=input()
i=len(N)
print('x'*i)
| 1 | 73,168,907,299,058 | null | 221 | 221 |
n = int(input())
ans = (n - 1) // 2
print(ans) | s = input()
for c in s:
if c.islower():
print(c.upper(), end="")
else:
print(c.lower(), end="")
print()
| 0 | null | 77,367,139,032,702 | 283 | 61 |
from collections import defaultdict
def combination(a, b):
if b > a - b:
return combination(a, a - b)
return fact[a] * ifact[b] * ifact[a-b]
MOD = 10**9+7
n, k = map(int, input().split())
k = min(k, n-1)
# 階乗を前処理
fact = defaultdict(int)
fact[0] = 1
for i in range(1, n+1):
fact[i] = fact[i-1] * i... | # coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import combinations
def run():
n,k = map(int, input().split())
mod = 10 ** 9 + 7
ret = 0... | 1 | 66,937,491,705,020 | null | 215 | 215 |
while True:
h, w = map(int, input().split())
if h == w == 0:
break
print(('#' * w + '\n') * h) | while True:
H,W = map(int, raw_input().split(" "))
if H == 0 and W == 0:
break
else:
for h in xrange(H):
print "#" * W
print "" | 1 | 782,049,557,250 | null | 49 | 49 |
import sys
input = sys.stdin.readline
def inps():
return str(input())
s = inps().rsplit()[0]
t = inps().rsplit()[0]
cnt = 0
for i in range(len(s)):
if s[i]!=t[i]:
cnt+=1
print(cnt)
| S = input()
T = input()
if len(S) != len(T): quit()
sum = 0
for i in range(len(S)):
if T[i] != S[i]:
sum = sum + 1
print(sum) | 1 | 10,485,272,831,288 | null | 116 | 116 |
k = int(input())
a,b = [int(x) for x in input().split()]
ans = "NG"
for i in range(1000):
if a <= i * k and i * k <= b:
ans = "OK"
break
print(ans) | a = [i for i in range(1,10)]
for b in a:
for c in a:
print('{}x{}={}'.format(b,c,b*c))
| 0 | null | 13,291,842,682,568 | 158 | 1 |
d = input()
d = int(d)
if d==0:
print('1')
if d==1:
print('0') | i = int(input())
print(i^1) | 1 | 2,890,011,217,512 | null | 76 | 76 |
"""
i - j = A[i] + A[j]
> i - A[i] = j + A[j]
i > j
"""
from collections import defaultdict
N = int(input())
high = list(map(int, input().split()))
ans = 0
calc = defaultdict(int)
for i in range(1, N+1):
ans += calc[i - high[i-1]]
calc[i + high[i-1]] += 1
print(ans) | import os
import sys
import numpy as np
def solve(N, K, S, P, R, T):
dp = np.zeros((N+1, 3), dtype=np.int64)
for i in range(1, N+1):
c = T[i]
dp[i, 0] = max(dp[i-K, 1], dp[i-K, 2]) + (c == "r") * R
dp[i, 1] = max(dp[i-K, 0], dp[i-K, 2]) + (c == "s") * S
dp[i, 2] = max(dp[i-K, 0]... | 0 | null | 66,425,015,455,360 | 157 | 251 |
import sys
readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prl = lambda x: print(*x ,sep='\n')
s,w = nm()
print('unsafe' if s <= w else 'safe') | import itertools
import math
s, w = map(int, input().split())
if s <= w:
print("unsafe")
else:
print("safe") | 1 | 28,996,458,127,872 | null | 163 | 163 |
input()
d=[abs(s-t)for s,t in zip(*[list(map(int,input().split()))for _ in'12'])]
f=lambda n:sum(s**n for s in d)**(1/n)
print(f(1),f(2),f(3),max(d),sep='\n')
| a = input()
a = a.replace('?', 'D')
print(a) | 0 | null | 9,276,929,113,120 | 32 | 140 |
def F(x, y):
if x % y == 0:
return y
return F(y, x % y)
while True:
try:
x, y = map(int,input().split())
print('{0} {1}'.format(F(x, y), int(x * y / F(x, y))))
except EOFError:
break
| import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
n, r = inm()
print(r if n >= 10 else r + 100 * (10 - n)) | 0 | null | 31,936,885,339,072 | 5 | 211 |
nq = str(input()).split()
n = int(nq[0])
q = int(nq[1])
p = [str(input()).split() for i in range(n)]
p = [(str(i[0]), int(i[1])) for i in p]
ans = []
time = 0
while len(p) != 0:
t = p.pop(0)
if t[1] > q:
#p = [(s[0], s[1], s[2]+q) for s in p]
time += q
p.append((t[0], t[1]-q))
elif t... | h, a = map(int, input().split())
b = 0
while h-a > 0:
h = h - a
b += 1
print(b + 1)
| 0 | null | 38,740,072,145,852 | 19 | 225 |
from copy import deepcopy
from sys import stdin
input = stdin.readline
H,W,K = map(int, input().split())
mat = [list(input()) for _ in range(H)]
ans = 0
for b_i in range(2**H):
mat_1 = deepcopy(mat)
for i in range(H):
if b_i >> i & 1:
for col in range(W):
mat_1[i][col] = '.'
... | h, w, k = map(int, input().split())
c = []
for _ in range(h):
c.append([c for c in input()])
ans = 0
for i in range(1 << h):
for j in range(1 << w):
cnt = 0
for n in range(h):
for m in range(w):
if i >> n & 1:
continue
if j >> m & 1:
continue
if c[n][m] == '#':
cnt += 1
if cnt =... | 1 | 8,990,906,921,536 | null | 110 | 110 |
n = int(input())
a = list(map(int,input().split()))
b = [0]*n
for i in range(n):
b[i] = a[i] + b[i-1]
ans = b[-1]
for j in range(n):
ans = min(ans,abs(b[-1]-b[j]*2))
print(ans) | N = int(input())
A = list(map(int, input().split()))
B = []
R = 0
L = sum(A)
for i in range(N):
B.append(abs(L-R))
R += A[i]
L -= A[i]
print(min(B)) | 1 | 142,198,889,878,820 | null | 276 | 276 |
X = int(input())
num = X//100
amari = X%100
if num*5 >= amari:
print(1)
else:
print(0) | n = input()
x = int(n)
for i in range(3,x+1) :
if i%3 == 0 or '3' in str(i) :
print('',i,end='')
print()
| 0 | null | 63,737,829,368,972 | 266 | 52 |
import math
X = int(input())
ans = 0
while ans == 0:
factor = 0
if X % 2 == 0 and X != 2:
X +=1
continue
for divisor in range(2, X // 2):
if X % divisor == 0:
factor += 1
if factor == 0:
ans =X
X +=1
print(ans) | a = int(input())
import math
def is_prime(x):
if x < 2: return False # 2未満に素数はない
if x == 2 or x == 3 or x == 5: return True # 2,3,5は素数
if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False # 2,3,5の倍数は合成数
# ためし割り: 疑似素数(2でも3でも5でも割り切れない数字)で次々に割っていく
prime = 7
step = 4
while prime <= math.sqr... | 1 | 105,802,666,359,518 | null | 250 | 250 |
class Stack(object):
def __init__(self, _max):
if type(_max) == int:
self._array = [None for i in range(0, _max)]
self._next = 0
def push(self, value):
if self.isFull():
raise IndexError
self._array[self._next] = value
self._next += 1
def... | ops = [op for op in input().split(" ")]
stack = []
for op in ops:
if op == "+":
stack = stack[:-2]+[stack[-2]+stack[-1]]
elif op == "-":
stack = stack[:-2]+[stack[-2]-stack[-1]]
elif op == "*":
stack = stack[:-2]+[stack[-2]*stack[-1]]
else:
stack.append(int(op))
print(sta... | 1 | 36,665,750,688 | null | 18 | 18 |
k, n = map(int, input().split())
a = list(map(int, input().split()))
a.append(a[0] + k)
dist = [a[i + 1] - a[i] for i in range(n)]
print(sum(dist) - max(dist))
| # -*- coding:utf-8 -*-
import sys
class Hash(object):
def __init__(self, size):
self._array = [None] * size
self._size = size
def _hash(self, key):
return key % self._size
def insert(self, key, value):
j = self._hash(key)
if self._array[j] is None:
sel... | 0 | null | 21,612,194,881,148 | 186 | 23 |
a, b, c = map(int,raw_input().split())
count = 0
for x in xrange(a,b+1):
if c%x == 0:
count+=1
print count | from sys import stdin, stdout
import math,sys,heapq
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict
from os import path
import bisect as bi
def yes():print('YES')
def no():print('NO')
if (path.exists('input.txt')):
#------------------Sublime-------------------... | 0 | null | 3,844,530,269,980 | 44 | 102 |
S = ['0'] + list(input()) + ['0']
N = len(S)
flag = False
ans = 0
for i in range(N - 1, 0, -1):
j = int(S[i])
if flag:
j += 1
S[i] = j
if j <= 5:
if j == 5 and int(S[i - 1]) >= 5:
ans += j
flag = True
else:
ans += j
flag = Fa... | import copy
n, k = map(int,input().split())
a = [0] + list(map(int,input().split()))
dist = [-1] * (n+1)
dist[1] = 0
cn = 1
d = 0
cycle = 0
while True:
d += 1
nn = a[cn]
if d == k:
ans = nn
break
if dist[nn] == -1:
dist[nn] = copy.deepcopy(d)
elif cycle == 0:
cycle... | 0 | null | 46,702,725,329,810 | 219 | 150 |
for i in range(0,9):
for j in range(0,9):
print("{0}x{1}={2}".format(i+1,j+1,(i+1)*(j+1))) | for i in range(9):
i=i+1
for j in range(9):
j=j+1
print(str(i)+'x'+str(j)+'='+str(i*j)) | 1 | 2,685,980 | null | 1 | 1 |
#10_B
import math
a,b,C=map(int,input().split())
S=a*b*math.sin((C*2*math.pi)/360)/2
c=math.sqrt(a**2+b**2-2*a*b*math.cos((C*2*math.pi)/360))
L=a+b+c
h=2*float(S)/a
print(str(S)+'\n'+str(L)+'\n'+str(h)+'\n')
| n = int(input())
a = sorted(list(map(int, input().split())))
ans = 1
for i in a:
ans *= i
if ans > 10**18:
print("-1")
break
else:
print(ans) | 0 | null | 8,174,661,945,120 | 30 | 134 |
import bisect
n,m=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
ng=-1
ok=A[-1]*2+1
B=[[0]*n for k in range(2)]
ii=0
while ok-ng>1:
mid=(ok+ng)//2
d=0
for i in range(n):
c=n-bisect.bisect_right(A,mid-A[i],lo=0,hi=len(A))
B[ii][i]=c
d=d+c
if d<m:
ok=mid
ii=(ii+1)%2
else:... | def solve():
S = input()
if S[2] == S[3] and S[4] == S[5]:
print("Yes")
else:
print("No")
if __name__ == "__main__":
solve() | 0 | null | 75,009,036,842,432 | 252 | 184 |
N=int(input())
K=set(input().split())
i=len(K)
if i==N:
print('YES')
else:
print('NO') | def main():
n = int(input())
a = set(map(int, input().split(" ")))
print("YES" if len(a) == n else "NO")
main() | 1 | 73,586,269,796,960 | null | 222 | 222 |
n = int(input())
S = input()
ans = 0
def ok(i):
pin = '{:0=3}'.format(i)
j = 0
for s in S:
if s == pin[j]:
j += 1
if j == 3:
return True
else:
return False
for i in range(1000):
ans += ok(i)
print(ans) | n = int(input())
s = input()
cnt = 0
for i in range(1000):
c = [i // 100, (i // 10) % 10, i % 10]
f = 0
for j in range(n):
if s[j] == str(c[f]): f+=1
if f == 3: break
if f == 3: cnt += 1
print(cnt) | 1 | 128,842,273,368,300 | null | 267 | 267 |
import math
n = input()
for i in range(n):
flag = 0
a = map(int, raw_input().split())
if(pow(a[0],2)+pow(a[1],2) == pow(a[2],2)):
flag = 1
if(pow(a[1],2)+pow(a[2],2) == pow(a[0],2)):
flag = 1
if(pow(a[2],2)+pow(a[0],2) == pow(a[1],2)):
flag = 1
if flag == 1:
pri... | def pascal(xdata):
for x in xrange(3):
for y in xrange(3):
for z in xrange(3):
if xdata[x]**2 + xdata[y]**2 == xdata[z]**2:
return True
return False
N = input()
data = [map(int, raw_input().split()) for x in range(N)]
for x in data:
if pascal(x):
print "YES"
else:
print "NO" | 1 | 272,485,792 | null | 4 | 4 |
a,b = map(int,input().split())
astart, aend = int(a//0.08+1), int((a+1)//0.08) #[astart, aend)
bstart, bend = int(b//0.10+1), int((b+1)//0.10)
alst = set(range(astart,aend))
blst = set(range(bstart,bend))
share = alst & blst
if len(share) == 0:
print(-1)
else:
print(list(share)[0]) | a,b=map(int,input().split())
c=max(int(100*a/8),10*b)
d=min(int(100*a/8+100/8),10*b+10)
f=0
for x in range(c,d+1):
if f==0 and int(x*0.08)==a and int(x*0.1)==b:
f=1
print(x)
if f==0:
print(-1)
| 1 | 56,600,562,094,560 | null | 203 | 203 |
import math
from functools import reduce
n,m = map(int, input().split())
A = list(map(int, input().split()))
def lcm_base(x,y):
return x*y//math.gcd(x,y)
def lcm(target_list):
return reduce(lcm_base, target_list)
A_gcd = reduce(math.gcd, A)
flg = True
for a in A:
if a//A_gcd%2==0:
flg = False
break
... | N=int(input())
print(int((N-1-(N+1)%2)/2)) | 0 | null | 127,330,218,657,852 | 247 | 283 |
L = int(input())
L = L/3
V=1
for i in range (3):
V*=L
print (V)
| N = int(input())
dp = [[0]*10 for _ in range(10)]
for a in range(N+1):
A = str(a)
dp[int(A[0])][int(A[-1])] += 1
ans = 0
for i in range(1,10):
for j in range(1,10):
ans += dp[i][j]*dp[j][i]
print(ans) | 0 | null | 66,811,987,096,102 | 191 | 234 |
N = int(input())
print(N + N**2 + N**3) | # -*- coding:utf-8 -*-
import math
def insertion_sort(num_list, length, interval):
cnt = 0
for i in range(interval, length):
v = num_list[i]
j = i - interval
while j >= 0 and num_list[j] > v:
num_list[j+interval] = num_list[j]
j = j - interval
cnt = ... | 0 | null | 5,143,793,159,558 | 115 | 17 |
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
out = [int(input()) for _ in range(D)]
sat = 0
last = [0] * 26
for d in range(D):
assert(1 <= out[d] and out[d] <= 26)
j = out[d] - 1
last[j] = d + 1
for i in range(26):
sat -= (d + 1 - ... | S = input()
S_len = len(S)
print("x" * S_len) | 0 | null | 41,392,258,537,630 | 114 | 221 |
N = [0] + list(map(int, list(input())))
L = len(N)
ans = 0
for i in range(L-1, -1, -1):
if N[i] == 10:
if i == 0:
ans += 1
else:
N[i-1] += 1
N[i] = 0
if N[i] < 5:
ans += N[i]
elif N[i] > 5:
ans += 10 - N[i]
N[i-1] += 1
else:
... | r_input = input().split()
r = int(r_input[0])
print(r*r) | 0 | null | 108,105,321,719,440 | 219 | 278 |
import math
from numba import jit
k=int(input())
@jit
def f():
ans=0
for a in range(1,k+1):
for b in range(1,k+1):
for c in range(1,k+1):
g=math.gcd(math.gcd(a,b),c)
ans+=g
return ans
print(f())
| def main():
N = int(input())
A = (
1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889,
13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857,
71247, 76884, 84388, 89349, 97881, 10334... | 1 | 35,373,735,569,710 | null | 174 | 174 |
n = int(input())
d = list(map(int,input().split()))
m = max(d)
if(d[0] != 0 or m >= n):
print(0)
else:
s = [0] * (m+1)
for i in d:s[i] += 1
if(0 in s or s[0] != 1):
print(0)
else:
t = 1
for i in range(1,m+1):
t *= s[i-1]**s[i]
t %= 998244353
pr... | s = input()
if 'A' in s and 'B' in s:
print('Yes')
else:
print('No') | 0 | null | 105,002,047,286,212 | 284 | 201 |
A,B,C = input().split()
print(C,A,B)
| A,B,C=map(int,input().split())
R=A
A=B
B=R
R=A
A=C
C=R
print(A,B,C) | 1 | 37,906,214,318,080 | null | 178 | 178 |
def main():
S = input()
print(S.swapcase())
main() | import math
def main():
n = int(input())
A = list(map(int, input().split()))
max_node = [0 for i in range(n+1)]
min_node = [0 for i in range(n+1)]
res = 0
for i in range(n, -1, -1):
if i == n:
max_node[i] = A[i]
min_node[i] = A[i]
elif i == 0:
... | 0 | null | 10,113,678,166,800 | 61 | 141 |
n = int(input())
ans = 0
flag = 0
for i in range(0, n):
x, y = input().split()
if x == y:
ans = ans + 1
else:
ans = 0
if ans >= 3:
flag = 1
if flag == 1:
print("Yes")
else :
print("No")
| N, P = map(int, input().split())
S = input()
ans = 0
if P == 2 or P == 5 :
for i in range(N) :
if int(S[i])%P == 0 :
ans += i+1
print(ans)
exit()
modP = [0 for _ in range(P)]
modP[0] = 1
now = 0
t = 1
for i in range(N) :
now += int(S[-1-i]) * t
now %= P
modP[now] += 1
t... | 0 | null | 30,395,630,146,112 | 72 | 205 |
n=int(input())
a=list(map(int,input().split()))
dp=[0]*(n+1)
for i in range(n-1):
dp[a[i]]+=1
for i in range(n):
print(dp[i+1]) | def resolve():
N = int(input())
array = [0 for i in range(N)]
buka = [int(i) for i in input().split()]
for num in buka:
array[num - 1] += 1
for i in array:
print(i)
resolve() | 1 | 32,279,224,984,282 | null | 169 | 169 |
input()
A = [int(i) for i in input().split()]
c = 0
def bubble_sort(A):
global c
flag = True
while flag:
flag = False
for i in range(len(A)-1, 0, -1):
if A[i] < A[i -1]:
A[i], A[i -1] = A[i -1], A[i]
c += 1
flag = True
bubble_sort(A... | def bubble_sort(alist):
"""Sort alist by bubble sort.
Returns (number of swap operations, sorted list)
>>> bubble_sort([5, 3, 2, 4, 1])
([1, 2, 3, 4, 5], 8)
"""
size = len(alist)
count = 0
for i in range(size-1):
for j in reversed(range(i+1, size)):
if alist[j] < al... | 1 | 16,633,901,668 | null | 14 | 14 |
a, b = map(int, input().split(" "))
print(int(a*b)) | N = int(input())
A = [int(i) for i in input().split()]
print(sum(a % 2 for a in A[::2]))
| 0 | null | 11,812,807,262,880 | 133 | 105 |
import sys
import itertools
class UnionFindTree:
def __init__(self, n: int) -> None:
self.par = list(range(n))
self.rank = [0] * n
def find(self, x: int) -> int:
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return... | def main():
n, k = map(int, input().split())
results = tuple(map(int, input().split()))
for i in range(n-k):
print('Yes' if results[i] < results[i+k] else 'No')
if __name__ == '__main__':
main()
| 0 | null | 4,640,135,850,350 | 70 | 102 |
from collections import deque
h, w = map(int, input().split())
S = [list(input()) for _ in range(h)]
DP = [[10000]*w for _ in range(h)]
DP[0][0] = 0 if S[0][0]=='.' else 1
directs = [[0,1], [1,0]]
for hi in range(h):
for wi in range(w):
for dh,dw in directs:
if not (0<=hi+dh<h and 0<=wi+dw<w): ... | from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator impor... | 0 | null | 27,775,124,141,700 | 194 | 99 |
X = int(input())
cnt = 1
deg = X
while deg%360!=0:
deg += X
cnt += 1
print(cnt)
| def gcd(a,b):
a,b=max(a,b),min(a,b)
return a if b==0 else gcd(b,a%b)
x=int(input())
g=gcd(360,x)
print(360//g) | 1 | 13,089,169,006,890 | null | 125 | 125 |
S = input()
T = input()
S = list(S)
T = list(T)
result = len(T)
x = 0
for i in range(len(S)-len(T)+1):
for j in range(len(T)):
if S[i+j] != T[j]:
x += 1
if result > x:
result = x
x = 0
print(result)
| n = int(input())
a = {}
for i in range(n):
x,m = input().split()
if x[0] =='i':a[m] = 0
else:
if m in a:
print('yes')
else:
print('no')
| 0 | null | 1,893,379,541,782 | 82 | 23 |
A,B,C=map(int,input().split())
if C-A-B>0 and (C-A-B)**2>4*A*B:
print('Yes')
else:
print('No') | a, b, c = map(int, input().split())
print("No" if c-a-b < 0 or 4*a*b >= (c-a-b)**2 else "Yes")
| 1 | 51,561,814,689,212 | null | 197 | 197 |
tes = input()
for mak in range(int(input())) :
ins = input().split()
ins[1], ins[2] = int(ins[1]), int(ins[2])
if ins[0] == 'replace' :
tes = tes[ : (ins[1])] + ins[3] + tes[(ins[2] + 1) :]
elif ins[0] == 'reverse' :
tem = tes[ins[1] : ins[2] + 1]
tem = tem[::-1]
tes = te... | a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
for _ in range(n):
d = int(input())
for i in range(3):
if d in a[i]:
a[i][a[i].index(d)] = -1
for i in range(3):
if sum(a[i])==-3:
print('Yes')
exit()
s = 0
for j in range(3):
s += a[j][i]
if s==-3:
print('Ye... | 0 | null | 30,819,499,253,282 | 68 | 207 |
while True:
h=[]
S=input()
if S=="-":
break
m=int(input())
for i in range(m):
h=int(input())
if len(S)==h:
pass
else:
S=S[h:]+S[:h]
print(S) | while True:
s = input()
if s == "-":
exit()
m = int(input())
for i in range(m):
h = int(input())
s = s[h:] + s[:h]
print(s)
| 1 | 1,912,529,115,552 | null | 66 | 66 |
n = int(input())
a = list(map(int, input().split()))
ans = 10 ** 16
a_1 = 0
a_2 = sum(a)
for i in range(n - 1):
a_1 += a[i]
a_2 -= a[i]
ans = min(ans, abs(a_1 - a_2))
print(ans) | #93 B - Iron Bar Cutting WA (hint)
N = int(input())
A = list(map(int,input().split()))
# 差が最小の切れ目を見つける
length = sum(A)
left = 0
dist = 0
mdist = length
midx = 0
for i,a in enumerate(A):
left += a
right = length - left
dist = abs(left - right)
if dist < mdist:
mdist = dist
midx = i
ans =... | 1 | 142,080,516,691,024 | null | 276 | 276 |
n,d=list(map(int,input().split()))
s=list(map(int,input().split()))
s=sorted(s)
s.reverse()
if d>=n:
print(0)
else:
c=0
s=s[d:n]
for i in s:
c+=int(i)
print(c)
| import sys
import math
def resolve(in_):
a, b, n = map(int, next(in_).split())
x = min(b - 1, n)
return math.floor(a * x / b) - a * math.floor(x / b)
def main():
answer = resolve(sys.stdin.buffer)
print(answer)
if __name__ == '__main__':
main()
| 0 | null | 53,464,328,128,768 | 227 | 161 |
N = int(input())
N_str = str(N)
a = 0
for i in range(len(N_str)):
a += int(N_str[i])
if a % 9 == 0:
print("Yes")
else:
print("No")
| n = list(input())
ans = 0
for i in n:
ans += int(i)
ans = ans%9
print('Yes' if ans == 0 else 'No') | 1 | 4,369,222,520,222 | null | 87 | 87 |
# -*- coding: utf-8 -*-
n = int(raw_input())
num = map(int, raw_input().split())
for e in num[::-1]:
if e == num[0]:
print e
break
print e, | a,b,c,d=map(int,input().split())
an=a*c
an=max(an,a*d)
an=max(an,b*c)
an=max(an,b*d)
print(an) | 0 | null | 2,006,004,696,290 | 53 | 77 |
N = int(input())
jage = "No"
for l in range(1, 10):
for r in range(1,10):
if N == r * l:
jage = "Yes"
print(jage) | ## coding: UTF-8
#N, M, K = 9, 3, 4
N, M, K = map(int,input().split())
p = 998244353
# 返り値: a と b の最大公約数
# 返り値: ax + by = gcd(a, b) を満たす (x, y) が格納される
def aug_gcd(a, b):
lq = []
while b > 0:
q = int(a/b)
r = a % b
a = b
b = r
lq.append(q)
x = 1
y = 0
for i i... | 0 | null | 91,440,676,915,108 | 287 | 151 |
import random
class Dise:
def __init__(self,top,flont,right,left,back,bottom):
self.top,self.flont,self.right,self.left,self.back,self.bottom=top,flont,right,left,back,bottom
def rot(self,d):
if d=='N':
self.top,self.flont,self.bottom,self.back=self.flont,self.bottom,self.... | import numpy as np
N, S = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
dp = np.array([0] * (3001), dtype=int)
dp[0] = 2
dp[A[0]] = 1
mod = 998244353
for a in A[1:]:
dpn = np.zeros(3001, dtype=int)
dpn[a:] = dp[:-a]
dpn += dp * 2
dpn %= mod
dp = dpn
print(dp[S])
| 0 | null | 8,937,108,639,860 | 34 | 138 |
import sys
input = sys.stdin.readline
def main():
N, X, T = map(int, input().split())
ans = (N+X-1)//X * T
print(ans)
if __name__ == '__main__':
main() | word = input()
q = int(input())
for _ in range(q):
s = input().split(" ")
command = s[0]
a = int(s[1])
b = int(s[2])
if command == "print":
print(word[a:b+1])
elif command == "reverse":
word = word[:a] + word[a:b+1][::-1] + word[b+1:]
elif command == "replace":
word ... | 0 | null | 3,166,871,520,438 | 86 | 68 |
import math
def main(n: int, x: int, t: int):
print(math.ceil(n / x) * t)
if __name__ == '__main__':
n, x, t = map(int, input().split())
main(n, x, t)
| N,X,T = map(int,input().split())
a = N % X
if a == 0:
ans = (N//X)*T
else:
ans = ((N//X)+1)*T
print(ans) | 1 | 4,289,394,786,560 | null | 86 | 86 |
import math
def read_int():
return int(input().strip())
def read_ints():
return list(map(int, input().strip().split(' ')))
def solve():
N, K = read_ints()
P = [p-1 for p in read_ints()]
C = read_ints()
max_score = -math.inf
for i in range(N):
cycle_score = C[i]
scores ... | class BinaryIndexTree: # 1-indexed
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self... | 0 | null | 34,115,133,602,470 | 93 | 210 |
n, x, t = map(int, input().split())
ans = t*(n//x)
if n % x != 0:
ans += t
print(ans) | N, X, T = map(int, input().split())
A = N // X
B = N % X
if B == 0:
print(A * T)
else:
print((A+1)*T) | 1 | 4,218,950,295,450 | null | 86 | 86 |
End of preview. Expand in Data Studio
No dataset card yet
- Downloads last month
- 30