code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
room = [0 for i in range(120)]
c = int(input())
for i in range(c):
b, f, r, v = [int(s) for s in input().split()]
index = (30 * (b - 1)) + (10 * (f - 1)) + (r - 1)
room[index] += v
for i in range(12):
if (i != 0) and (i % 3 == 0):
print('#' * 20)
print(' ' + ' '.join([str(v) for v in room[i*10:i*10+10]])) | import sys
printf = sys.stdout.write
bilt1 = [0] * 30
bilt2 = [0] * 30
bilt3 = [0] * 30
bilt4 = [0] * 30
sha = "#" * 20
count = 0;
x = input()
for i in range(x):
b,f,r,v =map(int, raw_input().split())
if b == 1:
bilt1[((f - 1) * 10) + (r - 1)] = bilt1[((f - 1) * 10) + (r - 1)] + v
elif b == 2:
bilt2[((f - 1) * 10) + (r - 1)] = bilt2[((f - 1) * 10) + (r - 1)] + v
elif b == 3:
bilt3[((f - 1) * 10) + (r - 1)] = bilt3[((f - 1) * 10) + (r - 1)] + v
else:
bilt4[((f - 1) * 10) + (r - 1)] = bilt4[((f - 1) * 10) + (r - 1)] + v
for i in range(3):
for j in range(10):
print " ",
printf(str(bilt1[(i * 10) + j]))
print ""
print sha
for i in range(3):
for j in range(10):
print " ",
printf(str(bilt2[(i * 10) + j]))
print ""
print sha
for i in range(3):
for j in range(10):
print " ",
printf(str(bilt3[(i * 10) + j]))
print ""
print sha
for i in range(3):
for j in range(10):
print " ",
printf(str(bilt4[(i * 10) + j]))
print "" | 1 | 1,097,917,735,192 | null | 55 | 55 |
N=int(input())
A=list(map(int,input().split()))
c=0
flug = 1
while flug:
flug = 0
for j in range(1,N)[::-1]:
if A[j]<A[j-1]:
A[j],A[j-1]=A[j-1],A[j]
flug=1
c+=1
print(*A)
print(c) | import sys
import math
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
s = sum(a)
a.sort(reverse=True)
border = s / (4 * m)
ans = True
for i in range(m):
if (a[i] >= border):
pass
else:
ans = False
break
if (ans):
print("Yes")
else:
print("No")
| 0 | null | 19,295,607,098,220 | 14 | 179 |
# coding:utf-8
class Dice:
def __init__(self):
self.f = [0 for i in range(6)]
def roll_z(self): self.roll(1,2,4,3)
def roll_y(self): self.roll(0,2,5,3)
def roll_x(self): self.roll(0,1,5,4)
def roll(self,i,j,k,l):
t = self.f[i]; self.f[i] = self.f[j]; self.f[j] = self.f[k]; self.f[k] = self.f[l]; self.f[l] = t
def move(self,ch):
if ch == 'E':
for i in range(3):
self.roll_y()
if ch == 'W':
self.roll_y()
if ch == 'N':
self.roll_x()
if ch == 'S':
for i in range(3):
self.roll_x()
dice = Dice()
dice.f = map(int, raw_input().split())
com = raw_input()
for i in range(len(com)):
dice.move(com[i])
print dice.f[0]
| x,y = list(map(int, input().split()))
ans=0
prize=[0, 300000, 200000, 100000, 0]
if x ==1 and y == 1:
print(1000000)
else:
print(prize[min(x,4)] + prize[min(y,4)]) | 0 | null | 70,403,716,049,340 | 33 | 275 |
from collections import defaultdict as dd
from itertools import accumulate
N, K = map(int, input().split())
As = [0] + list(map(int, input().split()))
S = list(accumulate(As))
ans = 0
counts = dd(int)
counts[0] = 1
for j in range(1, N+1):
if j >= K:
counts[(S[j-K] - (j-K)) % K] -= 1
t = (S[j] - j) % K
ans += counts[t]
counts[t] += 1
print(ans) | #!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify
import itertools
import math, fractions
import sys, copy
def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))
def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007
INF = float("inf")
def main():
N, K = LI()
A = LI()
S = list(itertools.accumulate(A))
keep = defaultdict(int)
keep[0] += 1
ans = 0
for i in range(1, N+1):
v = (S[i-1] - i) % K
if i == K:
keep[0] -= 1
if i - K > 0:
w = (S[i-K-1] - (i - K)) % K
keep[w] -= 1
ans += keep[v]
keep[v] += 1
print(ans)
if __name__ == '__main__':
main() | 1 | 137,807,029,800,930 | null | 273 | 273 |
from fractions import gcd
def lcm(a, b):
return (a * b) // gcd(a, b)
def f(x):
res = 0
while x % 2 == 0:
x //= 2
res += 1
return res
n, m = map(int, input().split())
a = [int(i) // 2 for i in input().split()]
t = f(a[0])
flag = True
for i in range(n):
if f(a[i]) != t:
flag = False
else:
a[i] >>= t
m >>= t
l = 1
for i in range(n):
l = lcm(l, a[i])
if l > m:
flag = False
m //= l
print(-(-m // 2) if flag else 0) | from math import gcd
def lcm(a, b):
return a // gcd(a, b) * b
N, M = map(int, input().split())
As = list(map(int, input().split()))
rightmostbit = As[0] & -As[0]
for A in As[1:]:
if rightmostbit != A & -A:
print(0)
exit()
lcm_of_half_As = 1
for A in As:
lcm_of_half_As = lcm(lcm_of_half_As, A // 2)
if lcm_of_half_As > M:
break
print((M // lcm_of_half_As + 1) // 2) | 1 | 101,631,239,657,658 | null | 247 | 247 |
a = int(input())
s = input()
ans = ''
for i in range(a-1):
if s[i] == s[i+1]:
continue
else:
ans += s[i]
ans += s[-1]
#print(ans)
print(len(ans)) | x = input()
youbi = {
'SUN': 7
, 'MON': 6
, 'TUE': 5
, 'WED': 4
, 'THU': 3
, 'FRI': 2
, 'SAT': 1
}
print(youbi[x]) | 0 | null | 151,869,688,149,540 | 293 | 270 |
# ALDS1_5_A.
def intinput():
a = input().split()
for i in range(len(a)):
a[i] = int(a[i])
return a
def binary_search(S, k):
a = 0; b = len(S) - 1
if b == 0: return S[0] == k
while b - a > 1:
c = (a + b) // 2
if k <= S[c]: b = c
else: a = c
return S[a] == k or S[b] == k
def show(a):
# 配列aの中身を出力する。
_str = ""
for i in range(len(a) - 1): _str += str(a[i]) + " "
_str += str(a[len(a) - 1])
print(_str)
def main():
n = int(input())
A = intinput()
q = int(input())
m = intinput()
# 配列Aの作る数を調べる。
nCanMake = [0]
for i in range(n):
for k in range(len(nCanMake)):
x = nCanMake[k] + A[i]
if not x in nCanMake: nCanMake.append(x)
# show(nCanMake)
for i in range(q):
if m[i] in nCanMake: print("yes")
else: print("no")
if __name__ == "__main__":
main()
| #coding:utf-8
#1_5_A
from itertools import combinations
n = int(input())
A = list(map(int, input().split()))
q = int(input())
ms = list(map(int, input().split()))
numbers = []
for i in range(1, n+1):
for com in combinations(A, i):
numbers.append(sum(com))
for m in ms:
if m in numbers:
print("yes")
else:
print("no") | 1 | 99,982,879,790 | null | 25 | 25 |
# coding: utf-8
while True:
try:
data = map(int, raw_input().split())
if data[0] > data[1]:
a = data[0]
b = data[1]
else:
a = data[1]
b = data[0]
r = 1
while r > 0:
q = a / b
r = a - b * q
a = b
b = r
gcd = a
lcm = data[0] * data[1] / gcd
print("{:} {:}".format(gcd, lcm))
except EOFError:
break | while True:
x = input().split()
a = int(x[0])
b = int(x[1])
if a == 0 and b == 0:
break
elif a > b:
print('{0} {1}'.format(b, a))
else:
print('{0} {1}'.format(a, b)) | 0 | null | 263,722,767,262 | 5 | 43 |
x = 1
y = 1
for x in range(9):
for y in range(9):
print((x+1),"x",(y+1),"=",(x+1)*(y+1),sep="")
y = y + 1
x = x + 1
| for i in range(1,10):
for j in range(1,10):
print(i,"x",j,"=",i*j,sep="")
j+=1
i+=1
| 1 | 277,728 | null | 1 | 1 |
import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, T = lr()
AB = [lr() for _ in range(N)]
AB.sort()
# 時間のかかる物は後ろへ
dp = np.zeros(T, np.int64)
answer = 0
for a, b in AB:
answer = max(answer, dp.max() + b)
prev = dp
dp[a:] = np.maximum(prev[a:], prev[:-a] + b)
print(answer)
| ans=0
n,t=map(int,input().split())
food=[]
for i in range(n):
f=list(map(int,input().split()))
food.append(f)
food=sorted(food)
dp=[0,0]+[-1]*(t-1)
for a,b in food:
tmp=[dp[i] for i in range(t)]
for i in range(t):
if dp[i]==-1: continue
j=i+a
if j<t: tmp[j]=max(tmp[j],dp[i]+b)
else: ans=max(ans,dp[i]+b)
dp=[tmp[i] for i in range(t)]
print(max(ans,max(dp))) | 1 | 151,551,499,946,136 | null | 282 | 282 |
def INT():
return int(input())
def MI():
return map(int, input().split())
def LI():
return list(map(int, input().split()))
N = INT()
cnt = 0
for _ in range(N):
D1, D2 = MI()
if D1 == D2:
cnt += 1
else:
cnt = 0
if cnt == 3:
print("Yes")
exit()
print("No") | for _ in[0]*int(input()):
a,b,c=sorted(map(int,input().split()))
print(['NO','YES'][a*a+b*b==c*c])
| 0 | null | 1,229,332,942,710 | 72 | 4 |
from collections import Counter, defaultdict
# 拡張ユークリッド互除法
# ax + by = gcd(a,b)の最小整数解を返す
def egcd(a, b):
if a == 0:
return (b, 0, 1)
else:
g, y, x = egcd(b % a, a)
return (g, x - (b // a) * y, y)
# mを法とするaの乗法的逆元
def modinv(a, m):
g, x, y = egcd(a, m)
if g != 1:
raise Exception('modular inverse does not exist')
else:
return x % m
# 素因数分解
def prime_factors(n):
i = 2
while i * i <= n:
if n % i:
i += 1
else:
n //= i
yield i
if n > 1:
yield n
# mを法とするときのa^n
def modpow(a,n,m):
res = 1
t = a
while n:
if n%2:
res = (res*t)%m
t = (t*t)%m
n //= 2
return res
def lcm_mod(nums, mod):
p = defaultdict(int)
for n in nums:
c = Counter(prime_factors(n))
for v,cnt in c.items():
p[v] = max(p[v],cnt)
res = 1
for v,cnt in p.items():
res *= modpow(v,cnt,mod)
res %= mod
return res
MOD = 10**9+7
N = int(input())
A = list(map(int,input().split()))
s = sum(modinv(a,MOD) for a in A)%MOD
s *= lcm_mod(A, MOD)
print(s%MOD)
| def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
def main():
n=int(input())
a=list(map(int,input().split()))
mod=pow(10,9)+7
lcma={}
for ai in a:
f=factorization(ai)
for fi in f:
if fi[0] in lcma:
lcma[fi[0]]=max(lcma[fi[0]],fi[1])
else:
lcma[fi[0]]=fi[1]
l=1
for k,v in lcma.items():
l*=pow(k,v,mod)
l%=mod
ans=0
for ai in a:
ans+=l*pow(ai,mod-2,mod)
ans%=mod
print(ans)
main()
| 1 | 87,388,422,204,870 | null | 235 | 235 |
aN = int(input())
A = list(map(int, input().split()))
mN = int(input())
M = list(map(int, input().split()))
def memorize(f) :
cache = {}
def helper(*args) :
if args not in cache :
cache[args] = f(*args)
return cache[args]
return helper
@memorize
def solve(i, m):
if m == 0:
return True
if i >= aN:
return False
res = solve(i + 1, m) or solve(i + 1, m - A[i])
return res
for m in M:
print("yes" if solve(0, m) else "no")
| # -*- coding: utf-8 -*-
"""
全探索
・再帰で作る
・2^20でTLEするからメモ化した
"""
N = int(input())
aN = list(map(int, input().split()))
Q = int(input())
mQ = list(map(int, input().split()))
def dfs(cur, depth, ans):
# 終了条件
if cur == ans:
return True
# memo[現在位置]に数値curがあれば、そこから先はやっても同じだからやらない
if cur in memo[depth]:
return False
memo[depth].add(cur)
# 全探索
for i in range(depth, N):
if dfs(cur+aN[i], i+1, ans):
return True
# 見つからなかった
return False
for i in range(Q):
memo = [set() for j in range(N+1)]
if dfs(0, 0, mQ[i]):
print('yes')
else:
print('no')
| 1 | 102,859,763,718 | null | 25 | 25 |
n = int(input())
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
#divisors.sort()
return divisors
d1 = make_divisors(n)
d2 = make_divisors(n-1)
ans = 0
for k in d1:
if k == 1:
continue
temp = n
while temp%k == 0:
temp //= k
if temp%k == 1:
ans += 1
ans += len(d2)-1
print(ans)
| N, M = map(int, input().split())
if M%2 != 0:
center = M + 1
else:
center = M
c = center//2
d = (center + 1 + 2*M + 1) // 2
i = 0
while i < c:
print(c-i, c+1+i)
i += 1
j = 0
while i < M:
print(d-(j+1), d+(j+1))
i += 1
j += 1 | 0 | null | 34,838,188,777,700 | 183 | 162 |
val = map(int,raw_input().split())
count = 0
for x in xrange(val[0], val[1] + 1):
pass
if val[2] % x == 0:
count+=1
print count | a,b,c = map(int,input().split())
cnt = 0
for d in range(a,b+1):
if c%d==0: cnt+=1
print(cnt)
| 1 | 566,410,816,092 | null | 44 | 44 |
# -*- coding: utf-8 -*-
def check(r,g,b):
if g > r and b > g:
return True
else:
return False
A,B,C = map(int, input().split())
K = int(input())
for i in range(K+1):
for j in range(K+1-i):
for k in range(K+1-i-j):
if i+j+k==0:
continue
r = A*(2**i)
g = B*(2**j)
b = C*(2**k)
if check(r, g, b):
print("Yes")
exit()
print("No")
| A, B, C = map(int, input().split())
K = int(input())
flg = 0
for i in range(K):
if B > A:
if C > B or 2*C > B:
flg = 1
else:
C = 2*C
else:
B = 2*B
continue
if flg:
print('Yes')
else:
print('No') | 1 | 6,935,957,586,996 | null | 101 | 101 |
def f():return map(int,raw_input().split())
n,m,l=f()
A = [f() for _ in [0]*n]
B = [f() for _ in [0]*m]
C = [[0 for _ in [0]*l] for _ in [0]*n]
for i in range(n):
for j in range(l):
print sum([A[i][k]*B[k][j] for k in range(m)]),
print | n, m, L = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [list(map(int, input().split())) for _ in range(m)]
c = [[sum(ak * bk for ak, bk in zip(ai,bj)) for bj in zip(*b)] for ai in a]
for ci in c:
print(*ci) | 1 | 1,428,287,966,752 | null | 60 | 60 |
s=input()
count=0
for i in range(0,len(list(s))-1):
if(s[i]!=s[i+1]):
count+=1
elif(s[i]==s[i+1]):
count+=0
if(count>1 or count==1):
print("Yes")
else:
print("No")
| S = input()
if S == 'AAA' or S== 'BBB':
print("No")
else:
print("Yes") | 1 | 54,877,130,165,146 | null | 201 | 201 |
x = input().split()
print(x.index('0') + 1) | print(input().find('0')//2+1) | 1 | 13,375,416,495,518 | null | 126 | 126 |
n = int(input())
S = 100000
for i in range(n):
S = int(S*1.05)
slist = list(str(S))
if slist[-3:] == ['0','0','0'] :
S = S
else:
S = S - int(slist[-3])*100 - int(slist[-2])*10 - int(slist[-1])*1 + 1000
print(S)
| MOD = 10**9 + 7
def xgcd(a, b):
x0, y0, x1, y1 = 1, 0, 0, 1
while b != 0:
q, a, b = a // b, b, a % b
x0, x1 = x1, x0 - q * x1
y0, y1 = y1, y0 - q * y1
return a, x0, y0
def modinv(a, mod):
g, x, y = xgcd(a, mod)
assert g == 1, 'modular inverse does not exist'
return x % mod
factorials = [1]
def factorial(n, mod):
# n! % mod
assert n >= 0, 'Argument Error! n is "0 <= n".'
if len(factorials) < n+1:
for i in range(len(factorials), n+1):
factorials.append(factorials[-1]*i % mod)
return factorials[n]
def comb(n, r, mod):
# nCr % mod
assert n >= 0, 'Argument Error! n is "0 <= n".'
assert n >= r >= 0, 'Argument Error! r is "0 <= r <= n".'
return perm(n, r, mod) * modinv(factorial(r, mod), mod) % mod
def perm(n, r, mod):
# nPr % mod
assert n >= 0, 'Argument Error! n is "0 <= n".'
assert n >= r >= 0, 'Argument Error! r is "0 <= r <= n".'
return factorial(n, mod) * modinv(factorial(n-r, mod), mod) % mod
x, y = sorted(map(int, input().split()))
MOD = 10 ** 9 + 7
q, r = divmod(x+y, 3)
if r != 0:
print(0)
else:
try:
print(comb(q, y - q, MOD))
except AssertionError:
print(0) | 0 | null | 74,619,043,225,810 | 6 | 281 |
n = int(input())
lst = []
for i in range(n):
x, l = map(int, input().split())
left = x - l
right = x + l
lst.append([left, right])
lst = sorted(lst, key=lambda x: x[1])
ans = 1
limit = lst[0][1]
for i in range(n):
if lst[i][0] >= limit:
ans += 1
limit = lst[i][1]
print(ans) | # でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(H, N, AB):
INF = 10**9
dp = [INF] * (H + 1)
dp[H] = 0
for h in reversed(range(H + 1)):
for i, (a, b) in enumerate(AB):
nh = max(0, h - a)
dp[nh] = min(dp[nh], dp[h] + b)
print(dp[0])
if __name__ == '__main__':
input = sys.stdin.readline
H, N = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
main(H, N, AB)
| 0 | null | 85,312,916,849,412 | 237 | 229 |
#変b数のまとめの入力についてsplitとインデックスで価を特定させる
youbi = "SUN,MON,TUE,WED,THU,FRI,SAT".split(",")
a = input()
print(7 - youbi.index(a)) | s = input()
S = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
print(7-S.index(s)) | 1 | 132,914,487,816,712 | null | 270 | 270 |
one = [int(i) for i in input().split()]
data = []
while one != [-1, -1, -1]:
data.append(one)
one = [int(i) for i in input().split()]
answer = ['F' if i[0] == -1 or i[1] == -1 else 'A' if i[0] + i[1] >= 80 else 'B' if 65 <= i[0] + i[1] < 80 else 'C' if 50 <= i[0] + i[1] < 65 else 'C' if 30 <= i[0] + i[1] < 50 and 50 <= i[2] else 'D' if 30 <= i[0] + i[1] < 50 else 'F' for i in data]
print(*answer, sep="\n")
| while True:
i = input().split()
m, f, r = map(int, i)
if m == -1 and f == -1 and r == -1:
break
if m == -1 or f == -1:
print('F')
elif m+f >= 80:
print('A')
elif m+f < 80 and m+f >= 65:
print('B')
elif m+f < 65 and m+f >= 50:
print('C')
elif m+f < 50 and m+f >=30:
if r >= 50:
print('C')
else:
print('D')
else:
print('F') | 1 | 1,228,538,502,720 | null | 57 | 57 |
n = int(input())
A = list(map(int, input().split()))
print(' '.join(list(map(str, A))))
for i in range(1,n):
key = A[i]
j = i - 1
while j >= 0 and A[j] > key:
A[j+1] = A[j]
j -= 1
A[j+1] = key
print(' '.join(list(map(str, A)))) | import sys
sys.setrecursionlimit(10**7)
def dfs(f):
if vis[f] == 1: return
vis[f] = 1
for t in V[f]:
dfs(t)
n, m = map(int, input().split())
E = [[*map(lambda x: int(x)-1, input().split())] for _ in range(m)]
V = [[] for _ in range(n)]
for a, b in E: V[a].append(b); V[b].append(a)
ans = 0
vis = [0]*n
for a in range(n):
if vis[a]==1:
continue
ans+=1
dfs(a)
print(ans-1)
| 0 | null | 1,130,717,205,760 | 10 | 70 |
n, m = map(int, input().split())
S = input()
ans = []
x = len(S) - 1
while x:
for step in range(m, 0, -1):
if x - step < 0:
continue
to = S[x-step]
if to == '1':
continue
else:
x -= step
ans.append(str(step))
break
else:
print(-1)
exit()
print(' '.join(ans[::-1])) | import sys
input = sys.stdin.readline
N,M=map(int,input().split());S=input()[:-1]
if S.find("1"*M)>0:
print(-1)
exit()
k=[N+1]*(N+1)
k[0]=N
c=1
for i in range(N-1,-1,-1):
if int(S[i])==0:
if k[c-1]-i <= M:
k[c]=i
else:
c+=1
k[c]=i
print(*[j-i for i,j in zip(k[c::-1],k[c-1::-1])]) | 1 | 138,863,260,719,940 | null | 274 | 274 |
for j in range(1,10):
for k in range(1,10):
print str(j)+"x"+str(k)+"="+str(j*k) | for i in range(1,10):
for j in range(1,10):
print('%sx%s=%s'%(i,j,i*j)) | 1 | 477,190 | null | 1 | 1 |
n=int(input())
s=input()
ans=''
for i in range(n-1):
if s[i]==s[i+1]:
pass
else:
ans+=s[i]
ans+=s[-1]
print(len(ans)) | def abc143c_slimes():
n = int(input())
s = input()
cnt = 1
for i in range(n-1):
if s[i] != s[i+1]:
cnt += 1
print(cnt)
abc143c_slimes() | 1 | 170,310,250,050,990 | null | 293 | 293 |
N, K, S = map(int, input().split())
INF = int(1e9)
if S == INF:
ans = [INF]*K + [INF-1]*(N-K)
else:
ans = [S]*K + [INF]*(N-K)
for e in ans:
print(e, end=" ") | #%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):
return map(type,input().split())
#%%code
def resolve():
bigint=10**9
N,K,S=pin()
if S!=bigint:
print(*([bigint]*(N-K)+[S]*(K)))
return
print(*([1]*(N-K)+[bigint]*K))
#%%submit!
resolve() | 1 | 91,235,850,547,420 | null | 238 | 238 |
import sys
for i in range(1,10):
for j in range(1,10):
print("{0}x{1}={2}".format(i,j,i*j)) | # Aizu Problem 0000: QQ
#
import sys, math, os
# read input:
#PYDEV = os.environ.get('PYDEV')
#if PYDEV=="True":
# sys.stdin = open("sample-input2.txt", "rt")
for i in range(1, 10):
for j in range(1, 10):
print("%dx%d=%d" % (i, j, i*j)) | 1 | 2,852,100 | null | 1 | 1 |
time = int(input())
hour=int(time/3600)
minutes=int((time-hour*3600)/60)
seconds=int(time-(hour*3600)-(minutes*60))
print(str(hour)+':'+str(minutes)+':'+str(seconds))
| import tempfile, os, subprocess, sys, base64, time, zlib
(_, file) = tempfile.mkstemp()
f = open(file, "wb")
f.write(zlib.decompress(base64.b64decode(b"""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""")))
f.close()
os.chmod(file, 0o755)
os.system("cp %s ./run" % file)
if os.system("./run") != 0:
print(1/0) | 1 | 332,770,636,000 | null | 37 | 37 |
import sys
n = input()
a = [[[0]*10 for i in range(3)] for i in range(4)]
for i in xrange(n):
b = map(int, raw_input().split())
a[b[0]-1][b[1]-1][b[2]-1] += b[3]
for i in range(4):
for j in range(3):
for k in range(10):
sys.stdout.write(' %s' % a[i][j][k])
print ""
if i != 3:
print '#'*20 | from __future__ import print_function
import sys
officalhouse = [0]*4*3*10
n = int( sys.stdin.readline() )
for i in range( n ):
b, f, r, v = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
bfr = (b-1)*30+(f-1)*10+(r-1)
officalhouse[bfr] = officalhouse[bfr] + v;
output = []
for b in range( 4 ):
for f in range( 3 ):
for r in range( 10 ):
output.append( " {:d}".format( officalhouse[ b*30 + f*10 + r ] ) )
output.append( "\n" )
if b < 3:
output.append( "####################\n" )
print( "".join( output ), end="" ) | 1 | 1,096,498,941,128 | null | 55 | 55 |
n = input()
A = map(int, raw_input().split())
print "%d %d %d" %(min(A), max(A), sum(A)) | #!/usr/bin/env python3
from functools import reduce
x, y = map(int, input().split())
mod = 10**9 + 7
def cmb(n, r, m):
def mul(a, b):
return a * b % m
r = min(n - r, r)
if r == 0:
return 1
over = reduce(mul, range(n, n - r, -1))
under = reduce(mul, range(1, r + 1))
return (over * pow(under, m - 2, m))%m
r = abs(x - y)
l = (min(x, y) - r) // 3
r += l
if (x+y)%3 < 1 and l >= 0:
print(cmb(r + l, l, mod))
else:
print(0)
| 0 | null | 75,088,850,521,260 | 48 | 281 |
while True:
a=input()
b=a.split()
c=list()
for d in b:
c.append(int(d))
if c[0]==0 and c[1]==0:
break
else:
d=sorted(c)
print(d[0],d[1])
| def solve():
N, X, M = map(int,input().split())
past_a = {X}
A = [X]
ans = prev = X
for i in range(1, min(M,N)):
next_a = prev ** 2 % M
if next_a in past_a:
loop_start = A.index(next_a)
loop_end = i
loop_size = loop_end - loop_start
loop_elem = A[loop_start:loop_end]
rest_n = N-i
ans += rest_n // loop_size * sum(loop_elem)
ans += sum(loop_elem[:rest_n%loop_size])
break
ans += next_a
past_a.add(next_a)
A.append(next_a)
prev = next_a
print(ans)
if __name__ == '__main__':
solve() | 0 | null | 1,686,841,299,990 | 43 | 75 |
n = int(input())
taro = 0
hanako = 0
for i in range(n):
animals = input().split()
taro_animal = animals[0]
hanako_animal = animals[1]
if taro_animal > hanako_animal:
taro += 3
elif taro_animal < hanako_animal:
hanako +=3
else:
taro += 1
hanako += 1
print(taro, hanako) | round=int(input())
T_pt=0
H_pt=0
for i in range(round):
pair=raw_input().split(" ")
T_card=pair[0].lower()
H_card=pair[1].lower()
if T_card<H_card:
H_pt+=3
elif T_card>H_card:
T_pt+=3
else:
T_pt+=1
H_pt+=1
print T_pt,H_pt | 1 | 2,015,751,843,648 | null | 67 | 67 |
import sys
s=sys.stdin.read().lower()
[print(chr(i),':',s.count(chr(i)))for i in range(97,123)] | count = {}
for i in range(26):
count[(i)] = 0
while True:
try:
x = raw_input()
except:
break
for i in range(len(x)):
if(ord('a') <= ord(x[i]) and ord(x[i]) <= ord('z')):
count[(ord(x[i])-ord('a'))] += 1
elif(ord('A') <= ord(x[i]) and ord(x[i]) <= ord('Z')):
count[(ord(x[i])-ord('A'))] += 1
for i in range(26):
print '%s : %d' %(chr(i+ord('a')), count[(i)])
exit(0) | 1 | 1,661,720,797,604 | null | 63 | 63 |
# 数字を取得
N = int(input())
# 数値分ループ
calc = []
for cnt in range(1, N + 1):
# 3もしくは5の倍数であれば、加算しない
if cnt % 3 != 0 and cnt % 5 != 0:
calc.append(cnt)
# 合計を出力
print(sum(calc)) | def calculator(op, x, y):
if op == '+':
return x + y
elif op == '-':
return y - x
else:
return x * y
raw = [r for r in input().split()]
for i in range(len(raw)):
try:
raw[i] = int(raw[i])
except:
continue
arr = []
buff = 0
for i in range(len(raw)):
if isinstance(raw[i], int):
arr.append(raw[i])
else:
buff = calculator(raw[i], arr.pop(), arr.pop())
arr.append(buff)
print(*arr)
| 0 | null | 17,471,515,830,770 | 173 | 18 |
#!/usr/bin/env python3
n = list(input())
if '3' == n[-1]:
print('bon')
elif n[-1] in ['0', '1', '6', '8']:
print('pon')
else:
print('hon')
| N = str(input())
N = N[::-1]
if N[0] == '2' or N[0] =='4' or N[0] =='5' or N[0] =='7' or N[0] =='9' :
print('hon')
elif N[0] == '0' or N[0] =='1' or N[0] =='6' or N[0] =='8' :
print('pon')
else:
print('bon') | 1 | 19,262,411,275,680 | null | 142 | 142 |
S = input()[::-1]
## 余りを0~2018で総数保持
counts = [0]*2019
## 0桁の余りは0
counts[0] = 1
num, d = 0, 1
for c in S:
## 右から~桁の数字
num += int(c) * d
num %= 2019
## 次の桁
d *= 10
d %= 2019
counts[num] += 1
ans = 0
for cnt in counts:
## nC2の計算
ans += cnt * (cnt-1) //2
print(ans) | s = input()
res = 0
m = 1
p =[0]*2019
for i in map(int,s[::-1]):
res +=i*m
res %=2019
p[res] +=1
m *=10
m %=2019
print(p[0]+sum([i*(i-1)//2 for i in p])) | 1 | 30,819,401,589,778 | null | 166 | 166 |
h,w = map(int,input().split())
B = [input() for _ in range(h)]
dp=[]
def ch(x1,y1,x2,y2):
if B[x1][y1]=='.' and B[x2][y2]=='#':
return 1
else:
return 0
dp = [[0 for j in range(w)] for i in range(h)]
for i in range(h):
for j in range(w):
if i==0 and j==0 and B[i][j]=='#':
dp[i][j]+=1
elif i==0:
dp[i][j] = dp[i][j-1]+ch(i,j-1,i,j)
elif j==0:
dp[i][j] = dp[i-1][j]+ch(i-1,j,i,j)
else:
dp[i][j] = min(dp[i][j-1]+ch(i,j-1,i,j),dp[i-1][j]+ch(i-1,j,i,j))
print(dp[h-1][w-1]) | from itertools import chain
def main():
inputs = []
r, _ = map(int, input().split())
for i in range(r):
inputs.append(tuple(map(int, input().split())))
row_sums = map(lambda row: sum(row), inputs)
column_sums = map(lambda column: sum(column), map(lambda *x: x, *inputs))
all_sum = sum(chain.from_iterable(inputs))
for i, s in zip(inputs, row_sums):
print(" ".join(map(lambda n: str(n), i)) + " {}".format(s))
else:
print(" ".join(map(lambda n: str(n), column_sums)) + " {}".format(all_sum))
if __name__ == "__main__":
main() | 0 | null | 25,481,616,100,768 | 194 | 59 |
def main():
data_count = int(input())
data = [list(map(int, input().split())) for i in range(data_count)]
for item in data:
item.sort()
print('YES') if item[0]**2 + item[1]**2 == item[2]**2 else print('NO')
main() | for i in range(int(input())):
temp = [int(x) for x in input().split()]
stemp = sorted(temp)
if stemp[2]**2 == stemp[1]**2 + stemp[0]**2:
print('YES')
else:
print('NO')
| 1 | 305,529,458 | null | 4 | 4 |
a,b,c=map(int,input().split())
if a<=b*c:print("Yes")
else:print("No")
#連続acしなきゃ……
| from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools
import queue
from collections import deque
from fractions import Fraction
def main():
a, b , c = map(int, input().split())
if a / c <= b:
print("Yes")
else:
print("No")
if __name__ == '__main__':
main()
| 1 | 3,563,525,712,222 | null | 81 | 81 |
ini = lambda : int(input())
inm = lambda : map(int,input().split())
inl = lambda : list(map(int,input().split()))
gcd = lambda x,y : gcd(y,x%y) if x%y else y
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
divisors.sort()
return divisors
#maincode-------------------------------------------------
k = ini()
a,b = inm()
ans = 'NG'
for i in range(1000):
if a <= i * k <= b:
ans = 'OK'
print(ans) | k=int(input())
a,b=map(int,input().split())
count=a
while count <= b:
if count%k == 0:
print("OK")
break
else:
count += 1
else:
print("NG") | 1 | 26,469,416,640,380 | null | 158 | 158 |
n, x, m = [int(x) for x in input().split()]
A = [x]
while len(A) < n:
a = (A[-1] * A[-1]) % m
if a not in A:
A.append(a)
else:
i = A.index(a)
loop_len = len(A) - i
print(sum(A[:i]) + sum(A[i:]) * ((n - i) // loop_len) + sum(A[i:i + ((n - i) % loop_len)]))
break
else:
print(sum(A))
| N, X, M = map(int, input().split())
pt = [[0] * (M+100) for i in range(70)]
to = [[0] * (M+100) for i in range(70)]
for i in range(M+1):
to[0][i] = (i*i) % M
pt[0][i] = i
for i in range(65):
for j in range(M+1):
to[i+1][j] = to[i][to[i][j]]
pt[i+1][j] = pt[i][j] + pt[i][to[i][j]]
ans = 0
for i in range(60):
if (N>>i)&1:
ans += pt[i][X]
X = to[i][X]
print(ans)
| 1 | 2,800,650,647,000 | null | 75 | 75 |
import sys
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def MAP(): return map(int, input().split())
inf = sys.maxsize
h, w, k = MAP()
s = [[int(i) for i in STR()] for _ in range(h)]
ans = inf
for i in range(2 ** (h - 1)): #縦方向の割り方を全探索 O(500)
hdiv = [1 for _ in range(h)]
for j in range(h - 1):
tmp = 2 ** j
hdiv[j] = 1 if i & tmp else 0
sh = sum(hdiv)
tmpans = sh - 1
wdiv = [0 for _ in range(w - 1)]
partsum = [0 for _ in range(sh + 1)]
j = 0
cnt = 0
while j < w: #O(2 * 10 ** 4)
tmp = 0
idx = 0
for kk in range(h): #O(10)
tmp += s[kk][j]
if hdiv[kk]:
partsum[idx] += tmp
tmp = 0
idx += 1
flag = True
for kk in range(sh + 1):
if partsum[kk] > k:
tmpans += 1
partsum = [0 for _ in range(sh + 1)]
flag = False
if flag:
j += 1
cnt = 0
else:
cnt += 1
if cnt > 2:
tmpans = inf
break
ans = min(ans, tmpans)
print(ans)
| import sys
input=sys.stdin.readline
n,u,v = map(int, input().split())
link = [[] for _ in range(n)]
for i in range(n-1):
tmp = list(map(int,input().split()))
link[tmp[0]-1].append(tmp[1]-1)
link[tmp[1]-1].append(tmp[0]-1)
from collections import deque
Q = deque()
Q.append([v-1,0])
visited=[-1]*n
visited[v-1]=0
while Q:
now,cnt = Q.popleft()
for nxt in link[now]:
if visited[nxt]!=-1:
continue
visited[nxt]=cnt+1
Q.append([nxt,cnt+1])
Q = deque()
Q.append([u-1,0])
v_taka=[-1]*n
v_taka[u-1]=0
while Q:
now,cnt = Q.popleft()
for nxt in link[now]:
if v_taka[nxt]!=-1:
continue
if visited[nxt] <= cnt+1:
continue
v_taka[nxt]=cnt+1
Q.append([nxt,cnt+1])
ans=-1
for i in range(n):
if v_taka[i] == -1:
continue
if ans < visited[i]:
ans=visited[i]
print(ans-1) | 0 | null | 83,146,727,309,552 | 193 | 259 |
for val in range(input()):
x = map(int,raw_input().split(' '))
x.sort()
if x[0]**2+x[1]**2==x[2]**2: print 'YES'
else: print 'NO' | # -*- coding: utf-8 -*-
import math
num = int(raw_input())
for i in range(num):
list = [int(x) for x in raw_input().split(" ")]
list.sort(lambda n1, n2:n2 - n1)
if list[0]**2 == list[1]**2 + list[2]**2:
print("YES")
else:
print("NO") | 1 | 237,266,404 | null | 4 | 4 |
N,K=map(int,input().split())
H=list(map(int, input().split()))
#Nモンスターの数、K必殺回数(モンスターは体力ゼロになる)、Hモンスターの数と各々の体力
H=sorted(H)
if K>=len(H):
print(0)
else:
for i in range(0,K):
del H[-1]
result=sum(H)
print(result) | import sys
n,k=map(int,input().split())
h=list(map(int,input().split()))
if n<=k:
print(0)
sys.exit()
hi=sorted(h)
if k:
print(sum(hi[:-k]))
else:
print(sum(hi))
| 1 | 79,049,911,594,470 | null | 227 | 227 |
import sys
i=1
while True:
x = sys.stdin.readline().rstrip()
if "0" != x:
print( "Case {}: {}".format( i, x) )
else:
break
i += 1 | n = int(input())
st = [input().split() for _ in range(n)]
x = input()
s,t = zip(*st)
print(sum(int(t[i]) for i in range(s.index(x)+1,n)))
| 0 | null | 48,695,343,453,308 | 42 | 243 |
#!/usr/bin/env python
contents = []
counter = 0
word = input()
while True:
text = input()
if text == "END_OF_TEXT":
break
textWords = text.split()
contents.append(textWords)
for x in contents:
for y in x:
if y.lower() == word:
counter += 1
print(counter) | from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
import math
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())
INF, NINF = float('inf'), float('-inf')
def main():
L, R, d = rli()
ans = 0
for x in range(L, R+1):
if x % d == 0:
ans += 1
print(ans)
stdout.close()
if __name__ == "__main__":
main() | 0 | null | 4,669,724,818,132 | 65 | 104 |
import sys
r = int(input())
if not ( 1 <= r <= 100 ): sys.exit()
print(r**2) | # 問題:https://atcoder.jp/contests/abc145/tasks/abc145_a
print(int(input()) ** 2)
| 1 | 145,687,090,937,930 | null | 278 | 278 |
# E - Colorful Hats 2
MOD = 10**9+7
N = int(input())
A = list(map(int,input().split()))
count = [0]*N+[3]
used = [0]*(N+1)
ans = 1
for x in A:
ans = (ans*(count[x-1]-used[x-1]))%MOD
count[x] += 1
used[x-1] += 1
print(ans) | N=int(input())
A=list(map(int,input().split()))
a,b,c=0,0,0
ans=1
mod=10**9+7
for i in A:
ans=ans*[a,b,c].count(i)%mod
if i==a: a+=1
elif i==b: b+=1
elif i==c: c+=1
print(ans) | 1 | 130,274,827,646,608 | null | 268 | 268 |
while True:
m,f,r = map(int, input().split())
if m == -1 and f == -1 and r == -1:
break
if m == -1 or f == -1:
print("F")
continue
s = m + f
if s >= 80:
print("A")
elif s >= 65:
print("B")
elif s >= 50:
print("C")
elif s >=30:
if r >= 50:
print("C")
else:
print("D")
else:
print("F") | #coding: utf-8
while True:
m, f, r = (int(i) for i in input().split())
if m == f == r == -1:
break
if m == -1 or f == -1:
print("F")
elif m + f >= 80:
print("A")
elif m + f >= 65 and m + f < 80:
print("B")
elif (m + f >= 50 and m + f < 65) or r >= 50:
print("C")
elif m + f >= 30 and m + f < 50:
print("D")
elif m + f < 30:
print("F")
| 1 | 1,245,690,242,720 | null | 57 | 57 |
def func(N):
result = 0
for A in range(1,N):
result += (N-1)//A
return result
if __name__ == "__main__":
N = int(input())
print(func(N)) | n = int(input())
ans = 0
t = 0
J = 0
for i in range(1,n):
for j in range(i,n):
if i*j >= n:break
if i == j : t+=1
ans +=1
J = j
if i*J >= n:break
print(2*ans -t)
| 1 | 2,599,435,850,858 | null | 73 | 73 |
x,k,d=map(int,input().split());xx=abs(x)
tmp=xx;tmp=(xx//d);cc=min(tmp,k)
xx-=d*cc;k-=cc;k&=1;xx-=d*k
print(abs(xx)) | n=int(input())
r=[int(input()) for i in range(n)]
maxv=r[1]-r[0]
minv=r[0]
for i in range(1,n):
maxv=max(maxv,r[i]-minv)
minv=min(minv,r[i])
print(maxv)
| 0 | null | 2,621,875,184,790 | 92 | 13 |
N, S = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353
def main():
dp = [0]*(S+1)
dp[0] = 1
for i in range(1, N+1):
p = [0]*(S+1)
dp, p = p, dp
for j in range(0, S+1):
dp[j] += 2*p[j]
dp[j] %= MOD
if j-A[i-1] >= 0:
dp[j] += p[j-A[i-1]]
dp[j] %= MOD
print(dp[S])
if __name__ == "__main__":
main() | n = input()
S = set([int(s) for s in raw_input().split()])
m = input()
T = set([int(s) for s in raw_input().split()])
print len(T & S) | 0 | null | 8,827,293,198,958 | 138 | 22 |
#!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
n,k = LI()
a = LI()
for i in range(k, n):
if a[i] > a[i-k]:
print('Yes')
else:
print('No')
| S, T = input().split()
A, B = map(int, input().split())
U = input()
if S == U :
print(str(A - 1) + ' ' + str(B))
elif T == U :
print(str(A) + ' ' + str(B - 1)) | 0 | null | 39,379,605,519,408 | 102 | 220 |
n = int(input())
def dfs(s):
if len(s) == n:
print(s)
else:
max_list = []
for _ in s:
max_list.append(ord(_))
for i in range(ord("a"),max(max_list) + 2):
s = s + chr(i)
dfs(s)
s = s[:len(s) - 1]
dfs("a") | S = list(str(input()))
count = 0
max = 0
for i in range(3):
if S[i] == "R":
count += 1
else:
if max < count:
max = count
count = 0
if max < count:
max = count
print(max) | 0 | null | 28,585,383,918,990 | 198 | 90 |
cnt = 0
s = input().lower()
while 1:
line = input()
if line == "END_OF_TEXT":
break
for w in line.lower().split():
if w == s:
cnt+=1
print(cnt) | N, M = map(int, input().split())
WA = [0] * (N+1)
AC = [0] * (N+1)
Q = [list(input().split()) for _ in range(M)]
for p, s in Q:
p = int(p)
if AC[p] == 1:
continue
if s == "WA":
WA[p] += 1
else:
AC[p] = 1
ans = 0
for w, a in zip(WA, AC):
if a:
ans += w
print(sum(AC), ans) | 0 | null | 47,517,440,217,062 | 65 | 240 |
import numpy as np
def solve():
for i in range(K,N):
if A[i-K] < A[i]:
print("Yes")
else:
print("No")
if __name__ == "__main__":
N,K = list(map(int, input().split()))
A = list(map(int, input().split()))
solve()
| n,k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
for i in range(n-k):
if a[i]<a[i+k]:
print("Yes")
else:
print("No") | 1 | 7,169,476,526,352 | null | 102 | 102 |
n = int(input())
a = list(map(int, input().split()))
ans = 0
tallest = 0
for i in range(n):
tallest = max(tallest, a[i])
ans += tallest - a[i]
print(int(ans))
| # coding: utf-8
# Your code here!
n,k=map(int,input().split())
a=list(map(int,input().split()))
cnt=a[k-1]
for i in range(n-k):
if a[i]<a[i+k]:
print('Yes')
else:
print('No')
| 0 | null | 5,814,404,767,108 | 88 | 102 |
def main():
a = int(input())
b = int(input())
print(6 - a - b)
if __name__ == "__main__":
main()
| f = list(map(str, [1, 2, 3]))
f.remove(input())
f.remove(input())
print(f[0]) | 1 | 110,983,577,515,910 | null | 254 | 254 |
def popcount(x):
xb = bin(x)
return xb.count("1")
def solve(x, count_1):
temp = x %count_1
if(temp == 0):
return 1
else:
return 1 + solve(temp, popcount(temp))
n = int(input())
x = input()
x_b = int(x, 2)
mod = x.count("1")
xm1 = x_b %(mod+1)
if(mod != 1):
xm2 = x_b %(mod-1)
for i in range(n):
if(x[i] == "0"):
mi = (((pow(2, n-1-i, mod+1) + xm1) % (mod+1)))
if(mi == 0):
print(1)
else:
print(1 + solve(mi, popcount(mi)))
else:
if(mod == 1):
print(0)
else:
mi = ((xm2-pow(2, n-1-i, mod-1)) % (mod-1))
if((x_b - xm2 == 0)):
print(0)
elif(mi == 0):
print(1)
else:
print(1 + solve(mi, popcount(mi))) | while True:
num = int(input())
if num == 0:
break
data = list(map(int, input().split()))
datasqr = [i ** 2 for i in data]
print("%lf" % (sum(datasqr) / num - (sum(data) / num) ** 2) ** 0.5)
| 0 | null | 4,241,518,148,012 | 107 | 31 |
A,B,C=map(int,input().split())
A,B=B,A
A,C=C,A
print(str(A)+" "+str(B)+" "+str(C)) | input_lists = list(input().split(' '))
result = [input_lists[-1]]
result += input_lists[0:-1]
result = ' '.join(result)
print(result) | 1 | 37,959,372,464,478 | null | 178 | 178 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
???????????????
"""
inputstr = input().strip()
cmdnum = int(input().strip())
for i in range(cmdnum) :
cmd = input().strip().split()
if cmd[0] == "print":
start = int(cmd[1])
end = int(cmd[2]) + 1
print(inputstr[start:end])
if cmd[0] == "reverse":
start = int(cmd[1])
end = int(cmd[2]) + 1
prev = inputstr[:start]
revr = inputstr[start:end]
next = inputstr[end:]
inputstr = prev + revr[::-1] + next
if cmd[0] == "replace":
start = int(cmd[1])
end = int(cmd[2]) + 1
inputstr = inputstr[:start] + cmd[3] + inputstr[end:] | string = input()
n = int(input())
print_s=[]
for i in range(n):
order = [i for i in input().split()]
if order[0] == "replace":
string = list(string)
for i in range(len(order[3])):
string[int(order[1])+i]=order[3][i]
string= "".join(string)
elif order[0] == "reverse":
string = string.replace(string[int(order[1]):int(order[2])+1],
string[int(order[2])-len(string):
int(order[1])-len(string)-1:-1])
else:
print_s.append(string[int(order[1]):int(order[2])+1])
for i in range(len(print_s)):
print(print_s[i])
| 1 | 2,064,584,199,052 | null | 68 | 68 |
n, m = map(int, input().split())
submit = []
for i in range(m):
temp = [x for x in input().split()]
submit.append(temp)
ac = [0] * (n + 1)
wa = [0] * (n + 1)
for i in range(m):
result = submit[i][1]
question = int(submit[i][0])
if result == 'AC' and ac[question] == 0:
ac[question] = 1
elif result == 'WA' and ac[question] == 0:
wa[question] += 1
for i in range(n + 1):
if ac[i] != 1:
wa[i] = 0
print(sum(ac), sum(wa))
| import sys
from collections import defaultdict
N, M = map(int, input().split())
is_ac = [False] * N
wa = [0] * N
for i in range(M):
p, S = input().split()
n = int(p) - 1
if not is_ac[n] and S == "AC":
is_ac[n] = True
if not is_ac[n] and S == "WA":
wa[n] += 1
cnt_ac = is_ac.count(True)
cnt_wa = 0
for i in range(N):
if is_ac[i]:
cnt_wa += wa[i]
print(cnt_ac, cnt_wa)
| 1 | 93,740,448,243,430 | null | 240 | 240 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def print_array(a):
print(" ".join(map(str, a)))
def bubblesort(a, n):
swap = 0
flag = True
while flag:
flag = False
for j in range(n - 1, 0, -1):
if a[j] < a[j - 1]:
(a[j], a[j - 1]) = (a[j - 1], a[j])
swap += 1
flag = True
return (a, swap)
def main():
n = int(input())
a = list(map(int, input().split()))
(b, swap) = bubblesort(a, n)
print_array(b)
print(swap)
if __name__ == "__main__":
main() | n = int(input())
a = [int(i) for i in input().split()]
num = 0
is_swapped = True
i = 0
while is_swapped:
is_swapped = False
for j in range(n-1, i, -1):
if a[j] < a[j-1]:
tmp = a[j]
a[j] = a[j-1]
a[j-1] = tmp
is_swapped = True
num += 1
i += 1
print(' '.join([str(i) for i in a]))
print(num)
| 1 | 17,896,996,704 | null | 14 | 14 |
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
for i in range(N - 2):
if all(x == y for (x, y) in A[i:i+3]):
print('Yes')
break
else:
print('No') | n = int(input())
if n % 2 == 0:
print(1 / 2)
elif n == 1:
print(1)
else:
print(((n + 1) / 2) / n) | 0 | null | 89,593,481,323,520 | 72 | 297 |
# Problem B - Postdocs
# input
T = list(input())
T_len = len(T)
# swap
for i in range(T_len):
if T[i]=='?':
T[i] = 'D'
# output
print("".join(T))
| #!/usr/bin/env python3
import collections as cl
import sys
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def main():
N = II()
S = LI()
if len(set(S)) == N:
print("YES")
else:
print("NO")
main()
| 0 | null | 46,174,240,173,440 | 140 | 222 |
import numpy as np
N = int(input())
X_low = N // 1.08
X_high = int(X_low + 1)
if np.floor(X_low * 1.08) == N:
print(X_low)
elif np.floor(X_high * 1.08) == N:
print(X_high)
else:
print(':(')
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
def main():
N, K = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N - K):
print("Yes" if A[i] < A[i + K] else "No")
if __name__ == "__main__":
main()
| 0 | null | 66,425,618,002,720 | 265 | 102 |
def popcount(x):
x = (x & 0x5555555555555555) + (x >> 1 & 0x5555555555555555)
x = (x & 0x3333333333333333) + (x >> 2 & 0x3333333333333333)
x = (x & 0x0f0f0f0f0f0f0f0f) + (x >> 4 & 0x0f0f0f0f0f0f0f0f)
x = (x & 0x00ff00ff00ff00ff) + (x >> 8 & 0x00ff00ff00ff00ff)
x = (x & 0x0000ffff0000ffff) + (x >> 16 & 0x0000ffff0000ffff)
x = (x & 0x00000000ffffffff) + (x >> 32 & 0x00000000ffffffff)
return x
n = int(input())
testimonies = [[] * n for _ in range(n)]
for i in range(n):
a = int(input())
for _ in range(a):
x, y = map(int, input().split())
testimonies[i].append((x-1, y))
ans = 0
for bits in range(1, 1<<n):
possible = True
for i in range(n):
if not bits >> i & 1:
continue
for x, y in testimonies[i]:
if bits >> x & 1 != y:
possible = False
break
if not possible:
break
if possible:
ans = max(ans, popcount(bits))
print(ans) | import sys
from io import StringIO
import unittest
import itertools
def yn(b):
print("Yes" if b==1 else "No")
return
def resolve():
readline=sys.stdin.readline
n=int(readline())
dat = [[-1 for i in range(n)] for j in range(n)]
for i in range(n):
m=int(readline())
for j in range(m):
x,y=map(int, readline().rstrip().split())
x-=1
dat[i][x] = y
ans=0
for ptn in itertools.product([False,True], repeat=n):
ok=True
for i in range(n):
if ptn[i]==False:
continue
for j in range(n):
if dat[i][j] == -1:
continue
if dat[i][j] == 1 and ptn[j]==False:
ok=False
break
if dat[i][j] == 0 and ptn[j]==True:
ok=False
break
if ok==False:
break
if ok==True:
ans=max(ans,ptn.count(True))
print(ans)
return
if 'doTest' not in globals():
resolve()
sys.exit() | 1 | 121,628,829,364,900 | null | 262 | 262 |
n,m,x = map(int,input().split())
ca = [list(map(int,input().split())) for i in range(n)]
c = [0]*n
a = [0]*n
for i in range(n):
c[i],a[i] = ca[i][0],ca[i][1:]
INF = 10**9
ans = INF
for i in range(1<<n):
understanding = [0]*m
cost = 0
for j in range(n):
if ((i>>j)&1):
cost += c[j]
for k in range(m):
understanding[k] += a[j][k]
ok = True
for s in range(m):
if understanding[s] < x:
ok = False
if ok:
ans = min(ans, cost)
if ans == INF:
ans = -1
print(ans)
| import numpy as np
n,m,x = map(int,input().split())
value = []
books = []
for i in range(n):
a = list(map(int,input().split()))
value.append(a[0])
books.append(np.array(a[1:]))
if min(sum(books))<x:
print(-1)
else:
ans = 10**8
for i in range(2**n):
M = np.array([0]*m)
v = 0
for j in range(n):
if i >> j & 1:
M += books[j]
v += value[j]
if min(M)>= x:
ans = min(ans,v)
print(ans) | 1 | 22,234,837,317,270 | null | 149 | 149 |
import sys
def gcd(a, b):
if b == 0: return a
return gcd(b, a%b)
for line in sys.stdin:
a, b= map(int, line.split())
if a < b:
a, b = b, a
g = gcd(a,b)
print g, a*b/g | #atcoder template
def main():
import sys
imput = sys.stdin.readline
#文字列入力の時は上記はerrorとなる。
#ここにコード
#input
N, S = map(int, input().split())
A = list(map(int, input().split()))
#output
mod = 998244353
dp = [[0] * ( S+1) for _ in range(N+1)]
#dp[i, j]を、A[0]...A[i]までを使って、Tの空でない部分集合
#{x_1, x_2, ..., x_k}であって、Ax_1 + A_x_2 + ... + A_x_k = jを満たすものの個数とする。
dp[0][0] = 1
#iまででjが作られている時、i+1ではA[i]がどのような値であっても、部分集合としてjは作れる。
#iまででjが作られない時、j-A[i]が作られていれば、A[i]を足せばjは作れる。
for i in range(N):
for j in range(S+1):
dp[i+1][j] += dp[i][j] * 2
dp[i+1][j] %= mod
if j >= A[i]:
dp[i+1][j] += dp[i][j-A[i]]
dp[i+1][j] %= mod
print(dp[N][S] % mod)
#N = 1のときなどcorner caseを確認!
if __name__ == "__main__":
main() | 0 | null | 8,758,709,320,260 | 5 | 138 |
import collections
List=collections.deque()
n=int(input())
for i in range(n):
command=input().split()
if command[0] == 'insert':
List.appendleft(command[1])
elif command[0] == 'delete':
try:List.remove(command[1])
except:pass
elif command[0] == 'deleteFirst':
List.popleft()
elif command[0] == 'deleteLast':
List.pop()
print(*List)
| import collections
a = collections.deque()
for i in range(int(input())):
b = input()
# 命令がinsertだった場合、
if b[0] == 'i':
# キーxを先頭に追加(数字は文字列bの7文字目以降にある)
a.appendleft(b[7:])
# 命令がdeleteだった場合
elif b[6] == ' ':
# 命令のキーが含まれる場合そのキーのデータを消すが、なければ何もしない
try:
a.remove(b[7:])
except:
pass
# 命令がdeleteFirstだった場合
elif len(b) > 10:
a.popleft()
# 命令がdeleteLastだった場合
elif len(b) > 6:
a.pop()
print(*a)
| 1 | 51,068,713,098 | null | 20 | 20 |
s = input()
mid = len(s)//2
q = s[:mid]
if len(s)%2 == 0:
t = list(s[mid:])
else:
t = list(s[mid+1:])
t.reverse()
cnt = 0
for i in range(mid):
cnt += s[i] != t[i]
print(cnt) | import sys
SUITS = ('S', 'H', 'C', 'D')
cards = {suit:{i for i in range(1, 14)} for suit in SUITS}
n = input() # 読み捨て
for line in sys.stdin:
suit, number = line.split()
cards[suit].discard(int(number))
for suit in SUITS:
for i in cards[suit]:
print(suit, i) | 0 | null | 60,539,669,293,168 | 261 | 54 |
from collections import deque
N,K = map(int,input().split())
R,S,P = map(int,input().split())
Tlist = input()
Answer = 0
def po(x):
if x == 's':
return R
elif x == 'r':
return P
else:
return S
for i in range(K):
TK = list(Tlist[i::K]).copy()
TK.append('')
T2 = TK[0]
sig = 2
for i in range(1,len(TK)):
T1 = T2
T2 = TK[i]
if T1 == T2 and i != len(TK)-1:
sig += 1
else:
Answer += po(T1)*(sig//2)
sig = 2
print(Answer) | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n, k = map(int, readline().split())
r, s, p = map(int, readline().split())
t = readline().decode().rstrip()
t = list(t)
for i in range(k, n):
if t[i] == t[i - k]:
t[i] = 0
ans = t.count('r') * p + t.count('p') * s + t.count('s') * r
print(ans) | 1 | 107,429,849,112,894 | null | 251 | 251 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N = int(readline())
print((N+1) // 2)
return
if __name__ == '__main__':
main()
| # -*- coding: utf-8 -*-
import math
def main():
N = int(input())
ans = math.ceil(N / 2)
print(ans)
if __name__ == "__main__":
main() | 1 | 59,013,143,033,650 | null | 206 | 206 |
N = int(input())
target_list = []
if N % 2 == 1:
N += 1
for i in range(1, int(N/2)):
target = N - i
if target == i:
continue
else:
target_list.append(target)
print(len(target_list)) | N = int(input())
if N % 2 == 0:
ans = int(N / 2) - 1
else:
ans = int(N / 2)
print('{}'.format(ans))
| 1 | 153,017,504,043,280 | null | 283 | 283 |
# from collections import Counter
# n = int(input())
# li = list(map(int, input().split()))
# a, b = map(int, input().split())
n = int(input())
print(n//2 if n&1 else n//2-1)
| n = int(input())
cnt = 0
for i in range(1, n//2+1):
if i != n - i and n - i > 0:
cnt += 1
print(cnt)
| 1 | 152,606,521,013,420 | null | 283 | 283 |
import math
K=int(input())
ans=0
for a in range(1,K+1):
for b in range(1,K+1):
g=math.gcd(a,b)
for c in range(1,K+1):
ans+=math.gcd(g,c)
print(ans) | #!/usr/bin/env python3
from functools import reduce
from itertools import combinations
from math import gcd
K = int(input())
sum = K * (K + 1) // 2
for i in combinations(range(1, K + 1), 2):
sum += 6 * reduce(gcd, i)
for i in combinations(range(1, K + 1), 3):
sum += 6 * reduce(gcd, i)
print(sum)
| 1 | 35,532,871,115,170 | null | 174 | 174 |
import sys
input = sys.stdin.readline
S=tuple(input().strip())
N=len(S)+1
sets = []
count = 0
for c in S:
d = 1 if c == '<' else -1
if count * d < 0:
sets.append(count)
count = d
else:
count += d
sets.append(count)
sum = 0
for i in range(len(sets)):
k=sets[i]
if k > 0:
sum += (k*(k+1))//2
else:
sum += (k*(k-1))//2
if i > 0:
sum -= min(sets[i-1], -k)
print(sum)
| n, m, x = map(int, input().split())
a = []
b = []
for i in range(n):
ca = list(map(int,input().split()))
a.append(ca[0])
b.append(ca[1:])
ans = 10**9
for i in range(1 << n):
money = 0
ex = [0]*m
for j in range(n):
if (i >> j) & 1 == 0: continue
money += a[j]
for k in range(m):
ex[k] += b[j][k]
if all(x <= l for l in ex):
ans = min(ans,money)
if ans == 10**9:
print(-1)
else:
print(ans) | 0 | null | 89,126,828,136,890 | 285 | 149 |
a,b,c=[int(x) for x in input().split()]
if a+b+c>=22:
print('bust')
else:
print('win')
| N = int(input())
S = list(input())
r = S.count('R')
g = S.count('G')
b = S.count('B')
cnt = 0
for i in range(N-3):
if S[i] == 'R':
r -= 1
cnt += g * b
l = 1
while (i + 2 * l < N):
if (S[i+l] == 'G' and S[i+2*l] == 'B') or (S[i+l] == 'B' and S[i+2*l] == 'G'):
cnt -= 1
l += 1
if S[i] == 'G':
g -= 1
cnt += r * b
l = 1
while (i + 2 * l < N):
if (S[i+l] == 'R' and S[i+2*l] == 'B') or (S[i+l] == 'B' and S[i+2*l] == 'R'):
cnt -= 1
l += 1
if S[i] == 'B':
b -= 1
cnt += g * r
l = 1
while (i + 2 * l < N):
if (S[i+l] == 'G' and S[i+2*l] == 'R') or (S[i+l] == 'R' and S[i+2*l] == 'G'):
cnt -= 1
l += 1
print(cnt)
| 0 | null | 77,038,705,434,820 | 260 | 175 |
scores = []
while True:
a_score = [int(x) for x in input().split( )]
if a_score[0] == a_score[1] == a_score[2] == -1:
break
else:
scores.append(a_score)
for s in scores:
m,f,r = [int(x) for x in s]
if m == -1 or f == -1:
print('F')
elif m + f >= 80:
print('A')
elif m + f >= 65:
print('B')
elif m + f >= 50 or r >= 50:
print('C')
elif m + f >= 30:
print('D')
else:
print('F')
| S,T = (x for x in input().split())
A,B = map(int,input().split())
U = input()
if S == U:
A -= 1
else:
B -= 1
print(A,B) | 0 | null | 36,605,176,656,580 | 57 | 220 |
N,M = map(int,input().split())
L = map(int,input().split())
work = 0
for i in L :
work += i
if N >= work :
print ( N - work )
else :
print ("-1") | N, M = map(int, input().split())
A = list(map(int, input().split()))
for i in A:
N -= i
if N >= 0:
print(N)
else:
print(-1)
| 1 | 31,808,307,222,680 | null | 168 | 168 |
a, b ,c = [int(i) for i in input().split()]
total = 0
for d in range(a, b + 1):
if c % d == 0:
total += 1
print(total) | 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)) | 0 | null | 2,864,495,730,720 | 44 | 92 |
n,k,s=map(int,input().split())
L=[s]*k+[min(s+1,10**9-1)]*(n-k)
print(' '.join(map(str,L))) | x1, v1 = map(int, input().split(' '))
x2, v2 = map(int, input().split(' '))
t = int(input())
p = abs(x2 - x1)
q = (v1 - v2) * t
if p <= q:
print("YES")
else:
print("NO") | 0 | null | 53,112,558,919,680 | 238 | 131 |
i = 1
while True:
factor = input()
if factor == '0':
break
print('Case ', i, ': ', factor, sep='')
i += 1
| import sys
i = 1
for line in sys.stdin.readlines():
x = line.strip()
if x != "0":
print("Case {}: {}".format(i, x))
i += 1 | 1 | 497,615,151,642 | null | 42 | 42 |
# from math import factorial
def main():
x, y = map(int, input().split())
# m = (i+2, j+1)
# n = (i+1, j+2)
# x = 2m + n
# y = m + 2n
# 2x - y = 3m
# 2y - x = 3n
m = (2*x-y) // 3
n = (2*y-x) // 3
def cmb(n, r, mod):
if (r<0 or r>n):
return 0
r = min(r, n-r)
return fac[n] * finv[r] * finv[n-r] % mod
mod = 10**9+7 #素数制限
N = m+n
fac = [1, 1] # 元テーブル
finv = [1, 1] # 逆元テーブル
finv_cal = [0, 1] #逆元計算用
for i in range(2, N + 1):
fac.append((fac[-1] * i) % mod)
finv_cal.append((-finv_cal[mod % i] * (mod//i)) % mod)
finv.append((finv[-1] * finv_cal[-1]) % mod)
# 行き先のx+yが3の倍数でないとたどり着けない。
if (x+y) % 3 != 0:
print(0)
else:
# m, n どちらかが負かもしくはどちらも0の時
if m < 0 or n < 0 or (m+n) == 0:
print(0)
else:
ans = cmb(m+n, n, mod)
print(ans)
if __name__ == '__main__':
main() | class Com:
def __init__(self, MAX = 1000000, MOD = 1000000007):
self.MAX = MAX
self.MOD = MOD
self._fac = [0]*MAX
self._finv = [0]*MAX
self._inv = [0]*MAX
self._fac[0], self._fac[1] = 1, 1
self._finv[0], self._finv[1] = 1, 1
self._inv[1] = 1
for i in range(2,self.MAX):
self._fac[i] = self._fac[i - 1] * i % self.MOD
self._inv[i] = self.MOD - self._inv[self.MOD%i] * (self.MOD // i) % self.MOD
self._finv[i] = self._finv[i - 1] * self._inv[i] % self.MOD
def com(self, n, k):
if (n < k):
return 0
if (n < 0 or k < 0):
return 0
return self._fac[n] * (self._finv[k] * self._finv[n - k] % self.MOD) % self.MOD
a,b = list(map(int,input().split()))
if 2*a-b >= 0 and (2*a-b)%3 == 0 and a-2*((2*a-b)//3) >= 0:
x = (2*a-b)//3
y = a-2*x
com = Com()
print(com.com(x+y, x))
exit()
a,b = b,a
if 2*a-b >= 0 and (2*a-b)%3 == 0 and a-2*((2*a-b)//3) >= 0:
x = (2*a-b)//3
y = a-2*x
com = Com()
print(com.com(x+y, x))
exit()
print(0) | 1 | 149,924,593,465,570 | null | 281 | 281 |
N=int(input())
D=list(map(int,input().split()))
print(sum([D[i]*D[j] for i in range(N) for j in range(i+1,N)])) | n,*d=map(int,open(0).read().split())
ans=0
for i in range(n):
for j in range(i+1,n):
ans+=d[i]*d[j]
print(ans) | 1 | 168,776,030,957,050 | null | 292 | 292 |
import sys
def main():
n, x, y = map(int, sys.stdin.buffer.readline().split())
L = [0] * n
for i in range(1, n):
for j in range(i + 1, n + 1):
d = j - i
if i <= x and y <= j:
d -= y - x - 1
elif i <= x and x < j < y:
d = min(d, x - i + y - j + 1)
elif x < i < y and y <= j:
d = min(d, i - x + j - y + 1)
elif x < i and j < y:
d = min(d, i - x + y - j + 1)
L[d] += 1
for a in L[1:]:
print(a)
main() | x, y = list(map(int, input().split()))
a = 4 * x - y
b = y - 2 * x
if (a % 2 == 0 and a >= 0) and (b % 2 == 0 and b >= 0):
print('Yes')
else:
print('No') | 0 | null | 28,743,960,677,070 | 187 | 127 |
def calc(n, k):
length = len(n)
dp = [[[0]*(k + 1) for _ in range(2)] for _ in range(length+1)]
dp[0][0][0] = 1
for i in range(length):
max_digit = int(n[i])
for flag_less in range(2):
for non_zero in range(4):
range_digit = 9 if flag_less else max_digit
for d in range(range_digit+1):
flag_less_next = 0
non_zero_next = non_zero
if flag_less == 1 or d < max_digit:
flag_less_next = 1
if d != 0:
non_zero_next = non_zero + 1
if non_zero_next < k + 1:
dp[i+1][flag_less_next][non_zero_next] += dp[i][flag_less][non_zero]
return dp[length][0][k]+dp[length][1][k]
n = input()
k = int(input())
print(calc(n, k)) | n = int(input())
maximum_profit = -10**9
r0 = int(input())
r_min = r0
for i in range(1, n):
r1 = int(input())
if r0 < r_min:
r_min = r0
profit = r1 - r_min
if profit > maximum_profit:
maximum_profit = profit
r0 = r1
print(maximum_profit) | 0 | null | 37,807,320,056,132 | 224 | 13 |
N,M = map(int, input().split())
S = list(input())
cnt,cnt1 = 0,0
for s in S:
if s == "1":
cnt1 += 1
else:
cnt = max(cnt, cnt1)
cnt1 = 0
if cnt >= M:
print(-1)
exit()
ans = []
pos = N
while pos > 0:
for m in range(M, 0, -1):
if pos - m < 0: continue
if S[pos - m] == "1": continue
ans.append(m)
pos -= m
break
print(*ans[::-1]) | class SegmentTree():
"""一点更新、区間取得クエリをそれぞれO(logN)で答えるデータ構造を構築する。
built(array) := arrayを初期値とするセグメント木を構築する O(N)。
update(i, val) := i番目の要素をvalに変更する。
get_val(l, r) := 区間[l, r)に対する二項演算の畳み込みの結果を返す。
"""
def __init__(self, n, op, e):
"""要素数、二項演算、単位元を引数として渡す
例) 区間最小値 SegmentTree(n, min, 10 ** 18)
区間和 SegmentTree(n, lambda a, b : a + b, 0)
"""
self.n = n
self.op = op
self.e = e
self.size = 2 ** ((n - 1).bit_length())
self.node = [self.e] * (2 * self.size)
def built(self, array):
"""arrayを初期値とするセグメント木を構築する"""
for i in range(self.n):
self.node[self.size + i] = array[i]
for i in range(self.size - 1, 0, -1):
self.node[i] = self.op(self.node[i << 1], self.node[(i << 1) + 1])
def update(self, i, val):
"""i番目の要素をvalに変更する"""
i += self.size
self.node[i] = val
while i > 1:
i >>= 1
self.node[i] = self.op(self.node[i << 1], self.node[(i << 1) + 1])
def get_val(self, l, r):
"""[l, r)の畳み込みの結果を返す"""
l, r = l + self.size, r + self.size
res_l, res_r = self.e, self.e
while l < r:
if l & 1:
res_l = self.op(res_l, self.node[l])
l += 1
if r & 1:
r -= 1
res_r = self.op(self.node[r], res_r)
l, r = l >> 1, r >> 1
return self.op(res_l, res_r)
n, m = map(int, input().split())
s = input()
INF = 10 ** 18
st = SegmentTree(n + 1, min, INF)
st.update(n, 0)
for i in range(n)[::-1]:
if s[i] == "1":
continue
tmp = st.get_val(i + 1, min(i + 1 + m, n + 1)) + 1
st.update(i, tmp)
if st.get_val(0, 1) >= INF:
print(-1)
exit()
ans = []
ind = 0
for i in range(n + 1):
if st.get_val(ind, ind + 1) - 1 == st.get_val(i, i + 1):
ans.append(i - ind)
ind = i
print(*ans) | 1 | 138,508,803,672,224 | null | 274 | 274 |
def main():
l = int(input())
print((l / 3) ** 3)
if __name__ == "__main__":
main() | import sys
l = int(input())
print((l / 3)**3)
| 1 | 47,213,300,346,596 | null | 191 | 191 |
import sys
for i in sys.stdin.readlines():
x = i.split(" ")
print len(str(int(x[0]) + int(x[1]))) | from sys import stdin
for line in stdin:
a,b = line.split(" ")
c = int(a)+int(b)
print(len(str(c)))
| 1 | 77,804,160 | null | 3 | 3 |
def main():
N,K=map(int,input().split())
M={}
mod=pow(10,9)+7
res=0
for i in range(K,0,-1):
syou=K//i
mc=pow(syou,N,mod)
if syou>=2:
for sub_m in range(2,syou+1):
mc-=M[sub_m*i]
res+=(i*mc)%mod
M[i]=mc
print(res%mod)
if __name__=="__main__":
main() | a= list(map(int,input().split()))
N = a[0]
K = a[1]
a = [0]*K
mod = 10**9+7
for x in range(K,0,-1):
a[x-1] = pow(K//x, N,mod)
for t in range(2,K//x+1):
a[x-1] -= a[t*x-1]
s = 0
for i in range(K):
s += (i+1)*a[i]
ans = s%mod
print(ans) | 1 | 36,804,184,632,298 | null | 176 | 176 |
h,w,k=map(int,input().split())
s=[[int(j) for j in input()] for i in range(h)]
def popcount(x):
global h
ret=0
for i in range(h-1):
ret+=(x>>i&1)
return ret
#できない場合は除く
ans=1000000000000000
for i in range(2**(h-1)):
p=popcount(i)
div=[0]*(p+1)
ans_sub=p
f=False
for j in range(w):
now=0
div[now]+=s[0][j]
for l in range(h-1):
if i>>l&1:
now+=1
div[now]+=s[l+1][j]
if all(i<=k for i in div):
continue
else:
div=[0]*(p+1)
now=0
div[now]=s[0][j]
for l in range(h-1):
if i>>l&1:
now+=1
div[now]+=s[l+1][j]
ans_sub+=1
f=any(i>k for i in div)
if not f:ans=min(ans,ans_sub)
print(ans) | N = int(input())
A = list(map(int, input().split()))
sa = sum(A)
last = A[-1]
count = last
root = 1
for i in range(N):
sa -= A[i]
if root <= A[i]:
print(-1)
break
elif root-A[i] > sa:
root = sa + A[i]
count+=root
root = (root-A[i])*2
else:
if count == 0 or root < last:
count = -1
print(count)
| 0 | null | 33,908,103,232,630 | 193 | 141 |
_, lis = input(), list(input().split())[::-1]
print(*lis)
| def main():
line = input()
deepen_x = []
cur_x = 0
ponds = [] # [(水たまりの最初の位置, 水量)]
while len(line) > 0:
#print(cur_x, ponds, deepen_x)
tmp_char = line[0]
if tmp_char == '\\':
deepen_x.append(cur_x)
elif tmp_char == '/' and len(deepen_x) != 0:
pre_x = deepen_x.pop()
volume = cur_x - pre_x
if len(ponds) == 0:
ponds.append([pre_x, volume])
else:
if pre_x < ponds[-1][0]:
# 前の水たまりと結合する
a = list(filter(lambda x: x[0] > pre_x, ponds))
pond = 0
for item in a:
pond += item[1]
[ponds.pop() for x in range(len(a))]
ponds.append([pre_x, pond + volume])
else:
# 新しい水たまりを作成
ponds.append([pre_x, volume])
cur_x += 1
line = line[1:]
print(sum([x[1] for x in ponds]))
if len(ponds) == 0:
print('0')
else:
print("{} ".format(len(ponds)) + " ".join([str(x[1]) for x in ponds]))
return
main()
| 0 | null | 522,337,885,340 | 53 | 21 |
import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
from numba import njit
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())
N,K = LI()
p = LI()
p.sort()
p1 = np.array(p)
print(p1[:K].sum())
| h, w = map(int, input().split())
hw = [input() for _ in range(h)]
dp = [[1000]*w for _ in range(h)]
if hw[0][0] == "#":
dp[0][0] = 1
else:
dp[0][0] = 0
for i in range(h):
for j in range(w):
if i > 0:
if hw[i][j] == "#" and hw[i-1][j] == ".":
dp[i][j] = min(dp[i][j], dp[i-1][j] + 1)
else:
dp[i][j] = min(dp[i][j], dp[i-1][j])
if j > 0:
if hw[i][j] == "#" and hw[i][j-1] == ".":
dp[i][j] = min(dp[i][j], dp[i][j-1] + 1)
else:
dp[i][j] = min(dp[i][j], dp[i][j-1])
print(dp[h-1][w-1]) | 0 | null | 30,280,750,393,280 | 120 | 194 |
n = int(input())
S = list(map(int, input().split()))
c = 0
def merge(A, left, mid, right):
inf = float('inf')
L = A[left:mid] + [inf]
R = A[mid:right] + [inf]
i = 0
j = 0
global c
for k in range(left, right):
if L[i] <= R[j]:
A[k] = L[i]
i += 1
c += 1
else:
A[k] = R[j]
j += 1
c += 1
def mergesort(A, left, right):
if left+1 < right:
mid = (left + right)//2
mergesort(A, left, mid)
mergesort(A, mid, right)
merge(A, left, mid, right)
mergesort(S, 0, n)
print(" ".join(map(str, S)))
print(c)
| from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache # @lru_cache(None)
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**6)
# ----------------------------------------------------------- #
a, v = (int(x) for x in input().split())
b, w = (int(x) for x in input().split())
t = int(input())
if a == b:
print("YES")
elif a < b:
if a + t*v >= b + t*w:
print("YES")
else:
print("NO")
else:
if a - t*v <= b - t*w:
print("YES")
else:
print("NO") | 0 | null | 7,537,113,472,330 | 26 | 131 |
n = int(input())
s, t = [], []
for i in range(n):
ss = input().split()
s.append(ss[0])
t.append(int(ss[1]))
x = input()
start = n
for i in range(n):
if s[i] == x:
start = i + 1
res = 0
for i in range(start, n):
res += t[i]
print(res) | n = int(input())
dic = {}
time = []
for i in range(n):
s, t = map(str, input().split())
dic[s] = i + 1
time.append(int(t))
ans = 0
song = input()
ans = sum(time[dic[song]:])
print(ans) | 1 | 97,342,341,990,934 | null | 243 | 243 |
input()
a = list(map(int, input().split()))
c = 1000000007
print(((sum(a)**2-sum(map(lambda x: x**2, a)))//2)%c) | input()
A = list(map(int, input().split()))
sum_list = sum(A)
sum_of_product = 0
for i in A:
sum_list -= i
sum_of_product = ((sum_list * i) % (10 ** 9 + 7) + sum_of_product) % (10 ** 9 + 7)
print(sum_of_product) | 1 | 3,830,356,526,838 | null | 83 | 83 |
N = int(input())
res = 0
if N % 2 == 0:
div = N // 2
for i in range(1,30):
res += div // 5**i
print(res)
| import sys
input = sys.stdin.readline
def main():
N = int(input())
if N % 2 == 1:
print(0)
exit()
count = []
i = 0
while True:
q = N // (10 * 5 ** i)
if q == 0:
break
else:
count.append((q, i + 1))
i += 1
ans = 0
prev_c = 0
for c, n_zero in count[::-1]:
ans += n_zero * (c - prev_c)
prev_c = c
print(ans)
if __name__ == "__main__":
main()
| 1 | 116,371,347,020,000 | null | 258 | 258 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.