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
|
---|---|---|---|---|---|---|
from collections import Counter
def main():
n = int(input())
s = (input() for i in range(n))
d = Counter(s)
num = d.most_common(1)[0][1]
ans = sorted(j[0] for j in d.items() if j[1] == num)
for i in ans:
print(i)
main() | from collections import Counter
n = int(input())
s = Counter([str(input()) for _ in range(n)])
l = []
c = 1
for stri, count in s.items():
if count == c:
c = count
l.append(stri)
elif count > c:
c = count
l.clear()
l.append(stri)
sort_l = sorted(l)
for i in sort_l:
print(i)
| 1 | 70,317,261,443,520 | null | 218 | 218 |
x = int(input())
if x >= 30:
print("Yes")
else:
print("No") | N, X, M = map(int, input().split())
ls = [False]*M
ls_mod = []
x = X
for m in range(M+1):
if ls[x] == False:
ls_mod.append(x)
ls[x] = m
x = (x**2)%M
else:
last = m
fast = ls[x]
diff = last - fast
break
if M == 1:
print(0)
else:
if last > N:
print(sum(ls_mod[:N]))
else:
shou = (N-fast) // diff
amari = (N-fast) % diff
print(sum(ls_mod[:fast])+sum(ls_mod[fast:])*shou+sum(ls_mod[fast:fast+amari]))
| 0 | null | 4,291,605,720,610 | 95 | 75 |
def solve():
from sys import stdin
f_i = stdin
N, T = map(int, f_i.readline().split())
AB = [tuple(map(int, f_i.readline().split())) for i in range(N)]
AB.sort()
dp = [[0] * T for i in range(N + 1)]
for i, AB_i in enumerate(AB, start=1):
A_i, B_i = AB_i
dp_i = dp[i]
dp_pre = dp[i-1]
dp_i[:A_i] = dp_pre[:A_i]
for j, t in enumerate(zip(dp_pre[A_i:], dp_pre), start=A_i):
x, y = t
if x < y + B_i:
dp_i[j] = y + B_i
else:
dp_i[j] = x
ans = max(dp[k][-1] + AB[k][1] for k in range(N))
print(ans)
solve() | import sys
read = sys.stdin.buffer.read
def main():
N, T, *AB = map(int, read().split())
D = [(a, b) for a, b in zip(*[iter(AB)] * 2)]
D.sort()
dp = [[0] * T for _ in range(N + 1)]
for i, (a, b) in enumerate(D):
for t in range(T):
if 0 <= t - a:
dp[i + 1][t] = dp[i][t - a] + b
if dp[i + 1][t] < dp[i][t]:
dp[i + 1][t] = dp[i][t]
ans = 0
for i in range(N - 1):
if ans < dp[i + 1][T - 1] + D[i + 1][1]:
ans = dp[i + 1][T - 1] + D[i + 1][1]
print(ans)
return
if __name__ == '__main__':
main()
| 1 | 151,379,355,380,132 | null | 282 | 282 |
x, y = map(int, input().split())
if x > y:
x, y = y, x
while x:
x, y = y % x, x
print(y) | def gcd( x, y ):
if 1 < y < x:
return gcd( y, x%y )
else:
if y == 1:
return 1
return x
a, b = [ int( val ) for val in raw_input( ).split( " " ) ]
if a < b:
a, b = b, a
print( gcd( a, b ) ) | 1 | 7,386,005,370 | null | 11 | 11 |
n=int(input())
a=list(map(int,input().split()))
l=[]
for i,x in enumerate(a):
l.append([x,i])
l.sort(reverse=True)
cnt=1
dp=[[0]*(n+1) for _ in range(n+1)]
for i,j in l:
for x in range(cnt+1):
if x==0:
dp[x][cnt-x]=dp[x][cnt-x-1]+i*(n-1-(cnt-x-1)-j)
elif x==cnt:
dp[x][cnt-x]=dp[x-1][cnt-x]+i*(j-x+1)
else:
dp[x][cnt-x]=max(dp[x-1][cnt-x]+i*(j-x+1),dp[x][cnt-x-1]+i*(n-1-(cnt-x-1)-j))
cnt+=1
ans=0
for i in range(n+1):
ans=max(ans,dp[i][n-i])
print(ans) | import heapq
import math
import random
import sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, namedtuple, UserDict
from functools import cmp_to_key, lru_cache, reduce
from itertools import (chain, combinations, combinations_with_replacement,
permutations, product)
import numpy as np
sys.setrecursionlimit(10**6+1)
write = sys.stdout.write
input = sys.stdin.buffer.readline
MOD = 10**9 + 7
if __name__ == "__main__":
n = int(input())
arr = sorted(enumerate(map(int, input().split()), 1),
key=lambda x: x[1], reverse=True)
dp = np.zeros(n+1, dtype=np.int)
for k, (i, a) in enumerate(arr, 1):
ndp = dp.copy()
add_left = np.abs(np.arange(1, k+1) - i) * a
ndp[1:k+1] = np.maximum(ndp[1:k+1], dp[:k] + add_left)
add_right = np.abs(np.arange(n-k+1, n+1) - i) * a
ndp[:k] = np.maximum(ndp[:k], dp[:k] + add_right)
dp = ndp
print(dp.max())
| 1 | 33,625,342,020,832 | null | 171 | 171 |
MOD = 10 ** 9 + 7
from operator import mul
from functools import reduce
def nCr(n, r):
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 // under
S = int(input())
ans = 0
for i in range(1, S):
if S - i * 3 < 0:
break
ans += nCr(S - i * 3 + i - 1, i - 1)
print(ans % MOD) | import sys
import re
import queue
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []
def main():
S = i_input()
ans = []
ans.append(0)
ans.append(0)
ans.append(1)
for i in range(3,S):
ans.append((ans[i-1]+ans[i-3])%MOD)
print(ans[S-1])
return
if __name__ == '__main__':
main() | 1 | 3,279,813,260,710 | null | 79 | 79 |
import itertools
def main():
N, M, Q = list(map(int, input().split()))
a = []
b = []
c = []
d = []
for i in range(Q):
ai, bi, ci, di = list(map(int, input().split()))
a.append(ai)
b.append(bi)
c.append(ci)
d.append(di)
ans = 0
for A in list(itertools.combinations_with_replacement(range(1, M+1), N)):
# print(A)
score = 0
for i in range(Q):
if A[b[i]-1] - A[a[i]-1] == c[i]:
score += d[i]
if ans < score:
ans = score
print(ans)
if __name__ == "__main__":
main()
| #import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions import gcd
#input=sys.stdin.readline
import bisect
n,m,q=map(int,input().split())
l=[i for i in range(1,m+1)]
ab=[list(map(int,input().split())) for _ in range(q)]
ans=0
for res in itertools.combinations_with_replacement(l, n):
ans_r=0
for i in range(q):
a,b,c,d=ab[i]
if c==res[b-1]-res[a-1]:
ans_r+=d
ans=max(ans,ans_r)
print(ans) | 1 | 27,501,384,342,670 | null | 160 | 160 |
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq
def ri():
return int(input())
def rl():
return list(map(int, input().split()))
def solve():
n, m, q = rl()
Q = []
for i in range(q):
Q.append(rl())
ways = [[i] for i in range(1, m + 1)]
for i in range(n - 1):
new_ways = []
for way in ways:
new_way = list(way)
for j in range(way[-1], m + 1):
new_ways.append(new_way + [j])
ways = new_ways
best = 0
for way in ways:
tot = 0
for a, b, c, d in Q:
if way[b - 1] - way[a - 1] == c:
tot += d
best = max(best, tot)
print (best)
mode = 's'
if mode == 'T':
t = ri()
for i in range(t):
solve()
else:
solve()
| N, M, Q = map(int, input().split())
a, b, c, d = [0] * Q, [0] * Q, [0] * Q, [0] * Q
for i in range(Q):
a[i], b[i], c[i], d[i] = map(int, input().split())
mx = 0
def dfs(Aary):
global mx
if len(Aary) == N + 1:
scr = score(Q, Aary, a, b, c, d)
if mx < scr:
mx = scr
return
Aary.append(Aary[-1])
while Aary[-1] <= M:
dfs(Aary.copy())
Aary[-1] += 1
def score(Q, A, a, b, c, d):
ans = 0
for i in range(Q):
if A[b[i]] - A[a[i]] == c[i]:
ans += d[i]
return ans
dfs( [1] )
print(mx)
| 1 | 27,446,371,074,012 | null | 160 | 160 |
T = input()
lt = list(T)
for i in range(len(lt)):
if lt[i] == '?':
lt[i] = 'D'
T = ''.join(lt)
print(T) | case = 1
x = input()
while(x!=0):
print "Case %d: %d" % (case, x)
x = input()
case += 1 | 0 | null | 9,460,805,472,260 | 140 | 42 |
#!/usr/bin/env python3
import sys
from itertools import chain
import numpy as np
import math
# from itertools import combinations as comb
# form bisect import bisect_left, bisect_right, insort_left, insort_right
# from collections import Counter
# import numpy as np
def factorize(n: int):
"""nを素因数分解する"""
# 2
count = 0
while n % 2 == 0:
count += 1
n = n // 2
if count > 0:
arr = [(2, count)]
else:
arr = []
# 3 以降
for facter in range(3, n + 1, 2):
if facter * facter > n:
if n > 1:
arr.append((n, 1))
break
count = 0
while n % facter == 0:
count += 1
n = n // facter
if count > 0:
arr.append((facter, count))
return arr
def case(n):
t = 0
i = 1
while True:
t += i
if t > n:
return i - 1
i += 1
def solve(N: int):
factors = factorize(N)
answer = 0
for f, count in factors:
answer += case(count)
return answer
def main():
tokens = chain(*(line.split() for line in sys.stdin))
# N = map(int, line.split())
N = int(next(tokens)) # type: int
answer = solve(N)
print(answer)
if __name__ == "__main__":
main()
| from math import sqrt
from collections import defaultdict
N = int(input())
def prime_factorize(n):
a = defaultdict(int)
while n % 2 == 0:
a[2] += 1
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a[f] += 1
n //= f
else:
f += 2
if n != 1:
a[n] += 1
return a
ps = prime_factorize(N)
def func2(k):
n = 1
count = 1
while count * (count+1) // 2 <= k:
count += 1
return count-1
res = 0
for value in ps.values():
if value > 0:
res += func2(value)
print(res) | 1 | 16,907,020,190,398 | null | 136 | 136 |
s,w = map(int,input().split())
if w >= s:
print("unsafe")
elif w < s:
print("safe") | def resolve():
s, w = map(int, input().split())
if s <= w:
print("unsafe")
else:
print("safe")
resolve()
| 1 | 29,234,771,487,662 | null | 163 | 163 |
import math
import fractions
#import sys
#input = sys.stdin.readline
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
def ValueToBits(x,digit):
res = [0 for i in range(digit)]
now = x
for i in range(digit):
res[i]=now%2
now = now >> 1
return res
def BitsToValue(arr):
n = len(arr)
ans = 0
for i in range(n):
ans+= arr[i] * 2**i
return ans
def ZipArray(a):
aa = [[a[i],i]for i in range(n)]
aa.sort(key = lambda x : x[0])
for i in range(n):
aa[i][0]=i+1
aa.sort(key = lambda x : x[1])
b=[aa[i][0] for i in range(len(a))]
return b
def ValueToArray10(x, digit):
ans = [0 for i in range(digit)]
now = x
for i in range(digit):
ans[digit-i-1] = now%10
now = now //10
return ans
def Zeros(a,b):
if(b<=-1):
return [0 for i in range(a)]
else:
return [[0 for i in range(b)] for i in range(a)]
class Bit:
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.tree[i] += x
i += i & -i
'''
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % p
p = 2
N = 10 ** 6 + 2
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
for i in range(2, N + 1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
'''
#a = list(map(int, input().split()))
#################################################
#################################################
#################################################
#################################################
n = int(input())
lr = []
for i in range(n):
s = input()
m = len(s)
#exam left
count = 0
left = 0
for j in range(m):
if(s[j]=='('):
count += 1
else:
if(count == 0):
left+=1
else:
count -=1
#exam right
count = 0
right = 0
for j in range(m):
if(s[m-j-1]==')'):
count += 1
else:
if(count == 0):
right+=1
else:
count -=1
#print(left,right)
lr.append([left,right])
existL = 0
existR = 0
sumL = 0
sumR = 0
for i in range(n):
sumL += lr[i][0]
sumR += lr[i][1]
if(lr[i][0]==0 and lr[i][1]!=0):
existL=1
#print(lr[i])
if(lr[i][1]==0 and lr[i][0]!=0):
existR=1
#print(lr[i])
lr2 = []
for i in range(n):
if(lr[i][0]==0): lr2.append(lr[i])
lr3 = []
for i in range(n):
if(lr[i][0]*lr[i][1]!=0): lr3.append(lr[i])
lr3.sort(key = lambda x : x[0]-x[1])
for i in lr3:
lr2.append(i)
for i in range(n):
if(lr[i][1]==0): lr2.append(lr[i])
#print(lr2)
ok = 1
now = 0
for i in range(n):
now -= lr2[i][0]
if(now<0):
ok = 0
#print('a',lr2[i])
now += lr2[i][1]
if(existL*existR == 1 and sumL == sumR and ok==1):
print("Yes")
else:
if(sumL==0 and sumR==0):
print("Yes")
else:
print("No")
| n = int(input())
li = []
for _ in range(n):
s = input()
count = 0
while True:
if count + 1 >= len(s):
break
if s[count] == '(' and s[count+1] == ')':
s = s[:count] + s[count+2:]
count = max(0, count-1)
else:
count += 1
li.append(s)
li2 = []
for i in li:
count = 0
for j in range(len(i)):
if i[j] == ')':
count += 1
else:
break
li2.append((count, len(i) - count))
li3 = []
li4 = []
for i in li2:
if i[0] <= i[1]:
li3.append(i)
else:
li4.append(i)
li3.sort()
li4.sort(key = lambda x: x[1], reverse = True)
now = [0,0]
for l,r in li3:
if l == 0 and r == 0:
pass
elif l == 0:
now[1] += r
else:
now[1] -= l
if now[1] < 0:
print('No')
exit()
now[1] += r
for l,r in li4:
if l == 0 and r == 0:
pass
elif r == 0:
now[1] -= l
if now[1] < 0:
print('No')
exit()
else:
now[1] -= l
if now[1] < 0:
print('No')
exit()
now[1] += r
if now[0] == 0 and now[1] == 0:
print('Yes')
else:
print('No')
| 1 | 23,673,527,870,540 | null | 152 | 152 |
l = input().split()
print(l.index('0')+1)
| s = input()
len_ = len(s)
half = len(s) // 2
ans = 0
if len_ % 2 == 0:
front = s[:half]
back = s[half:][-1::-1]
for i in range(len(front)):
if front[i] != back[i]:
ans += 1
else:
front = s[:half]
back = s[half+1:][-1::-1]
for i in range(len(front)):
if front[i] != back[i]:
ans += 1
print(ans)
| 0 | null | 66,863,554,074,230 | 126 | 261 |
n,k = map(int,input().split())
a = list(map(int,input().split()))
f = list(map(int,input().split()))
a.sort()
f.sort(reverse = True)
def ok(p):
result = 0
for i in range(n):
result += max(a[i]-p//f[i],0)
if result <= k:
return True
return False
L = 0
U = a[-1]*f[0]
while U-L >= 1:
M = (U+L)//2
if ok(M):
U = M
else:
L = M+1
print(U)
| def main():
n, m, l = tuple(map(int, input().split()))
matA = [[0 for j in range(m)] for i in range(n)]
matB = [[0 for k in range(l)] for j in range(m)]
matC = [[0 for k in range(l)] for i in range(n)]
for i in range(n):
tmp = list(map(int, input().split()))
for j in range(m):
matA[i][j] = tmp[j]
for j in range(m):
tmp = list(map(int, input().split()))
for k in range(l):
matB[j][k] = tmp[k]
for i in range(n):
for k in range(l):
for j in range(m):
matC[i][k] += matA[i][j] * matB[j][k]
for i in range(n):
for k in range(l):
if k == l-1:
print(matC[i][k])
else:
print(matC[i][k], end=' ')
if __name__ == '__main__':
main()
| 0 | null | 83,055,752,037,820 | 290 | 60 |
def zeroTrim(s):
while s[0] == '0':
if len(s) == 1:
break
s = s[1:]
return s
N = input()
K = int(input())
def calc(N, K):
digit = len(N)
res = 0
if K == 1:
if digit > 1:
res += (digit - 1) * 9
res += int(N[0])
elif K == 2:
if digit <= 1:
return 0
if digit > 2:
res += 9 * 9 * (digit - 1) * (digit - 2) // 2
for i in range(int(N[0])-1):
res += calc('9'*(digit-1), 1)
res += calc(zeroTrim(N[1:]), 1)
else:
if digit <= 2:
return 0
if digit > 3:
res += 9 * 9 * 9 * (digit - 1) * (digit - 2) * (digit - 3) // 6
for i in range(int(N[0])-1):
res += calc('9'*(digit-1), 2)
res += calc(zeroTrim(N[1:]), 2)
return res
print(calc(N, K)) | N=int(input())
A=list(map(int,input().split()))
ans=0
f=[1]*(N+1)
las=A[N]
g=[las]*(N+1)
flag=1
for i in range(0,N):
f[i+1]=2*(f[i]-A[i])
for i in range(N,0,-1):
g[i-1]=g[i]+A[i-1]
#print(f,g)
for i in range(N+1):
if min(f[i],g[i])<=0:
flag=0
break
ans=ans+min(f[i],g[i])
if g[N]>f[N]:
flag=0
if flag==0:
print(-1)
else:
print(ans) | 0 | null | 47,368,802,763,312 | 224 | 141 |
T=input()
print(T.replace("?","D"))
| T=input()
N=len(T)
l=[]
for i in range(N):
if T[i]=="?":
l.append("D")
else:
l.append(T[i])
ans=""
for i in range(N):
ans+=l[i]
print(ans) | 1 | 18,346,617,282,364 | null | 140 | 140 |
# coding:utf-8
import math
N=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
manh_dist=0.0
for i in range(0,N):
manh_dist=manh_dist+math.fabs(x[i]-y[i])
print('%.6f'%manh_dist)
eucl_dist=0.0
for i in range(0,N):
eucl_dist=eucl_dist+(x[i]-y[i])**2
eucl_dist=math.sqrt(eucl_dist)
print('%.6f'%eucl_dist)
mink_dist=0.0
for i in range(0,N):
mink_dist=mink_dist+math.fabs(x[i]-y[i])**3
mink_dist=math.pow(mink_dist,1.0/3)
print('%.6f'%mink_dist)
cheb_dist=0.0
for i in range(0,N):
if cheb_dist<math.fabs(x[i]-y[i]):
cheb_dist=math.fabs(x[i]-y[i])
print('%.6f'%cheb_dist) | from sys import stdin
n = int(stdin.readline().rstrip())
x = [float(x) for x in stdin.readline().rstrip().split()]
y = [float(x) for x in stdin.readline().rstrip().split()]
def minkowski_dist(x, y, p="INF"):
if p == "INF":
return max([abs(x[i]-y[i]) for i in range(n)])
elif isinstance(p, int):
return (sum([(abs(x[i]-y[i]))**p for i in range(n)]))**(1/p)
print(minkowski_dist(x, y, 1))
print(minkowski_dist(x, y, 2))
print(minkowski_dist(x, y, 3))
print(minkowski_dist(x, y))
| 1 | 212,788,858,132 | null | 32 | 32 |
s, w = map(int, input().split(" "))
print(["safe", "unsafe"][s <= w]) | n = int(input())
p2 = (n + 1) / 1.08
p1 = n / 1.08
if p2 > int(p2) >= p1:
print(int(p2))
else:
print(":(") | 0 | null | 77,516,876,722,318 | 163 | 265 |
N = int(input())
l = []
for _ in range(N):
A, B = map(int, input().split())
l.append((A, B))
t = N//2
tl = sorted(l)
tr = sorted(l, key=lambda x:-x[1])
if N%2:
print(tr[t][1]-tl[t][0]+1)
else:
a1, a2 = tl[t-1][0], tr[t][1]
a3, a4 = tl[t][0], tr[t-1][1]
print(a4-a3+a2-a1+1)
| n=int(input())
m=[];M=[]
for i in range(n):
a,s=map(int,input().split())
m.append(a);M.append(s)
m.sort();M.sort()
if n%2:
print(M[n//2]-m[n//2]+1)
else:
print(M[n//2]+M[n//2-1]-m[n//2]-m[n//2-1]+1) | 1 | 17,224,076,962,620 | null | 137 | 137 |
while True:
x,y = map(int,input().split())
if (x,y) ==(0,0): break
if x < y:
print(x,y)
else:
print(y,x)
| list = []
while True:
line = raw_input().split(" ")
if line[0] == "0" and line[1] == "0":
break
line = map(int, line)
#print line
if line[0] > line[1]:
temp = line[0]
line[0] = line[1]
line[1] = temp
print " ".join(map(str, line)) | 1 | 524,672,880,592 | null | 43 | 43 |
N=int(input())
c=input()
right_r=0
right_w=0
left_r=0
left_w=0
for i in range(N):
if c[i]=='R':
right_r+=1
else:
right_w+=1
ans=right_r
for j in range(N):
cnt=0
if c[j]=='W':
left_w+=1
right_w-=1
else:
left_r+=1
right_r-=1
if right_r<=left_w:
cnt+=right_r
cnt+=left_w-right_r
else:
cnt+=left_w
cnt+=right_r-left_w
if cnt<ans:
ans=cnt
print(ans) | C = {}
S = input().strip()
N = len(S)
K = int(input())
for i in range(N):
s = S[i]
if s not in C:
C[s]=0
C[s] += 1
if len(C)>1:
a = 0
cnt = 1
for i in range(1,N):
if S[i]==S[i-1]:
cnt += 1
else:
a += cnt//2
cnt = 1
a += cnt//2
X = S+S
b = 0
cnt = 1
for i in range(1,2*N):
if X[i]==X[i-1]:
cnt += 1
else:
b += cnt//2
cnt = 1
b += cnt//2
d = b-a
print(a+d*(K-1))
else:
A = list(C.items())
k = A[0][1]
if k%2==0:
print((k//2)*K)
else:
if K%2==0:
a = k
b = 2*k
d = k
print(a+d*((K//2)-1))
else:
a = k//2
b = (k*3)//2
d = b-a
print(a+d*(K//2)) | 0 | null | 91,027,417,137,920 | 98 | 296 |
N, M = [int(_) for _ in input().split()]
if N == M:
print('Yes')
else:
print('No') | n, k =map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
roop = []
seen = [0 for _ in range(n)]
count = 0
for i in range(n):
if seen[i]>0:
continue
else:
count+=1
seen[i] = count
roop.append([c[i]])
t = i
while i!=p[t]-1:
seen[p[t]-1]=count
roop[-1].append(c[p[t]-1])
t = p[t]-1
#print(seen)
#print(roop)
ans = max(c)
for i in roop:
#print(ans)
s = sum(i)
ii = i+i
#print(ii)
if len(i)>=k:
for j in range(1, k+1):
temp = sum(ii[:j])
for l in range(len(i)):
if l!=0:
temp+=ii[l+j-1]
temp-=ii[l-1]
#temp = sum(ii[l:l+j])
#print(i, j, l, temp)
ans = max(ans, temp)
else:
for j in range(1, len(i)+1):
temp= sum(ii[:j])
for l in range(len(i)):
if l != 0:
temp+=ii[l+j-1]
temp-=ii[l-1]
#print(temp)
if s>0:
temp1 = temp+s*((k-j)//len(i))
else:
temp1 = temp
#print(i, j, l, temp)
ans = max(ans, temp)
ans = max(ans, temp1)
print(ans)
| 0 | null | 44,453,299,007,040 | 231 | 93 |
import sys
import math
for n in [int(math.log10(float(int(line.split()[0])+int(line.split()[1]))))+1 for line in sys.stdin]:
print n | while 1:
try:
line = raw_input()
except EOFError:
break
arr = map((lambda x: int(x)), line.split())
print len(str(arr[0]+arr[1])) | 1 | 136,473,314 | null | 3 | 3 |
A, B, C, D = map(int, input().split())
while(True):
C = C - B
if C <= 0:
ans = 'Yes'
break
A = A - D
if A <= 0:
ans = 'No'
break
print(ans) | n=int(input())
gou=n//2
gou+=n%2
print(gou) | 0 | null | 44,486,479,956,600 | 164 | 206 |
n = int(input())
graph = [[] for _ in range(n)]
for i in range(n - 1):
a, b = map(int, input().split())
graph[a - 1].append((b - 1, i))
graph[b - 1].append((a - 1, i))
ans = [0] * (n - 1)
from collections import deque
d = deque()
d.append([0, -1])
while d:
point, prev = d.popleft()
color = 1 if prev != 1 else 2
for a, index in graph[point]:
if ans[index] == 0:
ans[index] = color
d.append([a, color])
color += 1 if prev != color + 1 else 2
print(max(ans))
print(*ans, sep='\n') | import sys
sys.setrecursionlimit(2147483647)
INF=float('inf')
MOD=10**9+7
input=sys.stdin.readline
n=int(input())
#初期値が0の辞書
from collections import defaultdict
tree = defaultdict(lambda: set([]))
color={}
key=[]
for _ in range(n-1):
a,b=map(int,input().split())
tree[a-1].add(b-1)
tree[b-1].add(a-1)
color[(a-1,b-1)]=0
key.append((a-1,b-1))
checked=[0]*n
cnt=0
def DEF(parent_color,node_no):
global color,checked,tree,cnt
checked[node_no]=1
cnt=max(cnt,parent_color)
i=1
#print("node_no",node_no)
for item in tree[node_no]:
if checked[item]==0:
if i==parent_color:
i+=1
color[(min(item,node_no),max(item,node_no))]=i
DEF(i,item)
i+=1
DEF(0,1)
print(cnt)
for item in key:
print(color[item])
| 1 | 136,525,059,330,930 | null | 272 | 272 |
import sys
input = sys.stdin.readline
N,K = map(int,input().split())
MOD = 998244353
dp = [0 for _ in range(N+1)]
dp[1] = 1
R = [tuple(map(int,input().split())) for _ in range(K)]
S = [0 for _ in range(K)]
for i in range(2, N+1):
s = 0
for k in range(K):
S[k] += dp[max(0, i - R[k][0])] - dp[max(0, i - R[k][1] - 1)]
S[k] %= MOD
s = (s + S[k]) % MOD
dp[i] = s
print(dp[N]) | n,k=[int(i) for i in input().strip().split(" ")]
arr=[int(i) for i in input().strip().split(" ")]
ans=0
arr=sorted(arr)
for i in range(k):
ans+=arr[i]
print(ans) | 0 | null | 7,154,148,810,500 | 74 | 120 |
import math
a, b, C = map(int,input().split());
c = math.radians(C)
print((1/2)*a*b*math.sin(c));
print(a+b+math.sqrt(a**2+b**2-2*a*b*math.cos(c)));
print(b*math.sin(c));
| import math
a,b,C = (int(x) for x in input().split())
S = a * b * math.sin(math.radians(C)) / 2
L = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(C))) + a + b
h = b * math.sin(math.radians(C))
print(round(S,8),round(L,8),round(h,8))
| 1 | 175,293,473,312 | null | 30 | 30 |
N = int(input())
height = [int(i) for i in input().split()]
box = [0]
for x in range(1 ,N):
if(height[x] >= height[x-1] + box[x-1]):
box.append(0)
if(height[x] < height[x-1] + box[x-1]):
box.append(- height[x] + height[x-1] + box[x-1])
sum = 0
for t in box:
sum += t
print(sum) | a=int(input())
b=(a)//2+1
ans=0
for i in range(1,b,1):
x=a//i
ans+=((x**2+x)//2)*i
ans+=(a**2+a+b-b**2)//2
print(ans) | 0 | null | 7,852,420,655,222 | 88 | 118 |
import sys
input = sys.stdin.readline
def main():
T = list(input().rstrip())
ans = ["D" if c == "?" else c for c in T]
print("".join(ans))
if __name__ == "__main__":
main() | from functools import reduce
N = int(input())
S = input()
ans = [chr(ord("A") + (ord(s) + N - ord("A"))%26) for s in S]
ans = reduce(lambda x, y: x + y, ans)
print(ans) | 0 | null | 76,396,974,829,982 | 140 | 271 |
wd = ['SUN','MON','TUE','WED','THU','FRI','SAT']
s = input()
print(str(7 - wd.index(s) % 7)) | s = input()
days_of_the_week = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
n = days_of_the_week.index(s)
print(7 - days_of_the_week.index(s)) | 1 | 133,067,091,002,820 | null | 270 | 270 |
n,m=map(int,raw_input().split())
if m ==n:
print "Yes"
else:
print "No" | import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
def LI(): return list(map(int, stdin.readline().split()))
def LS(): return list(stdin.readline())
n,m = LI()
print('Yes' if n==m else 'No') | 1 | 83,452,021,066,140 | null | 231 | 231 |
a,b=map(int,input().split())
a1=f"{a}"*b
b1=f"{b}"*a
print(a1 if a1<b1 else b1) | import sys
import math
def main():
n = int(input().rstrip())
r = 1.05
digit = 3
a = 100000
for i in range(n):
a = math.ceil(a*r/10**digit)*10**digit
print(a)
if __name__ == '__main__':
main() | 0 | null | 42,213,830,797,908 | 232 | 6 |
# アライグマはモンスターと戦っています。モンスターの体力はHです。
# アライグマはN種類の必殺技を使うことができ、i番目の必殺技を使うとモンスターの体力を Ai
# 減らすことができます。 必殺技を使う以外の方法でモンスターの体力を減らすことはできません。
# モンスターの体力を0以下にすればアライグマの勝ちです。
# アライグマが同じ必殺技を2度以上使うことなくモンスターに勝つことができるなら Yes を、
# できないなら No を出力してください。
H, N = map(int, input().split())
damege = map(int, input().split())
total_damege = sum(damege)
if H - total_damege <= 0:
print('Yes')
else:
print('No') | h, n = map(int, input().split())
a = list(map(int, input().split()))
x = sum(a)
if (h - x) <= 0:
print('Yes')
else:
print('No') | 1 | 77,596,250,566,500 | null | 226 | 226 |
def merge(a, l, m, r):
global cnt
ll = a[l:m] + [1e9 + 1]
rl = a[m:r] + [1e9 + 1]
i, j = 0, 0
for k in range(l, r):
if ll[i] < rl[j]:
a[k] = ll[i]
i += 1
else:
a[k] = rl[j]
j += 1
cnt += 1
def merge_sort(a, l, r):
if l + 1 < r:
m = (l + r) // 2
merge_sort(a, l, m)
merge_sort(a, m, r)
merge(a, l, m, r)
n, a, cnt = int(input()), list(map(int, input().split())), 0
merge_sort(a, 0, n)
print(*a)
print(cnt) | n = int(input())
s = list(map(int, input().split()))
cnt = 0
def merge(A, left, mid, right):
L = A[left:mid]
R = A[mid:right]
L.append(float('inf'))
R.append(float('inf'))
i = 0
j = 0
global cnt
for k in range(left, right):
cnt += 1
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 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(cnt)
| 1 | 115,967,828,108 | null | 26 | 26 |
import math
n=int(input())
S=100
for i in range(n):
S=S+0.05*S
S=math.ceil(S)
print(S*1000)
| import math
n = input()
p = 0
money = 100
while p != n:
money = math.ceil(money * 1.05)
p += 1
print int(money * 1000) | 1 | 983,139,762 | null | 6 | 6 |
# coding: utf-8
# Your code here!
a,b=map(int,input().split())
if (1<=a<=9) and (1<=b<=9):
print(a*b)
else:
print(-1) | a = [int(i) for i in input().split()]
if(max(a) > 9):
print("-1")
else:
print(a[0] * a[1]) | 1 | 157,874,574,220,890 | null | 286 | 286 |
n = int(input())
max_div_num = 1
for i in range(2, int(n**(1/2) + 1)):
if n % i == 0:
max_div_num = max(i, max_div_num)
x = max_div_num
y = n // max_div_num
print(x + y - 2) | from math import sqrt
from math import floor
n = int(input())
ans = 10 ** 12
m = floor(sqrt(n))
for i in range(1,m+1):
if n % i == 0:
j = n // i
ans = min(ans,i+j-2)
print(ans) | 1 | 161,680,666,716,870 | null | 288 | 288 |
mod=10**9+7
n,k=map(int,input().split())
l=[0]*(k+1)
for i in range(k):
num=(k-i)
if k//num==1:
l[num]=1
else:
ret=pow(k//num,n,mod)
for j in range(2,k//num+1):
ret-=l[num*j]
ret%=mod
l[num]=(ret)%mod
ans=0
for i in range(k+1):
ans+=(l[i]*i)%mod
print(ans%mod)
| #!/usr/bin/env python3
# -*- coding: utf-8 -*-
# E - Sum of gcd of Tuples (Hard)
n, k = map(int, input().split())
modulus = 10 ** 9 + 7
def expt(x, k):
"""(x ** k) % modulus"""
p = 1
for b in (bin(k))[2:]:
p = p * p % modulus
if b == '1':
p = p * x % modulus
return p
# iの倍数をn個並べた列の個数
nseq = [expt((k // i), n) if i > 0 else None for i in range(k + 1)]
for i in range(k, 0, -1):
# iの2倍以上の倍数からなる列の個数を引く
s = sum(nseq[m] for m in range(2 * i, k + 1, i))
nseq[i] = (nseq[i] - s % modulus + modulus) % modulus
# nseq[i]はgcd==iになる列の個数
ans = sum(i * nseq[i] % modulus for i in range(1, k + 1))
print(ans % modulus)
| 1 | 37,048,870,677,292 | null | 176 | 176 |
n = int(input())
dict = {1:"a", 2:"b", 3:"c", 4:"d", 5:"e", 6:"f", 7:"g", 8:"h", 9:"i", 10:"j"}
dict2 = {"a":1, "b":2, "c":3, "d":4, "e":5, "f":6, "g":7, "h":8, "i":9, "j":10}
#ans = [["a", 1]]
#for i in range(n-1):
# newans = []
# for lis in ans:
# now = lis[0]
# count = lis[1]
# for j in range(1, count + 2):
# newans.append([now + dict[j], max(j, count)])
# ans = newans
#for lis in ans:
# print(lis[0])
def dfs(s):
if len(s) == n:
print(s)
return
m = max(s)
count = dict2[m]
for i in range(1, count+2):
dfs(s+dict[i])
dfs("a") | print('Yes') if int(input())>=30 else print('No') | 0 | null | 29,089,673,391,460 | 198 | 95 |
value = int(input())
h, value = value // 3600, value - (value//3600) * 3600
m, value = value //60, value - (value // 60) * 60
s = value
print("%d:%d:%d" %(h,m,s))
| s = input()
s = 'x'*len(s)
print(s)
| 0 | null | 36,653,131,473,518 | 37 | 221 |
lst = list(input())
v_lakes = []
idx_stack = []
for i, c in enumerate(lst):
if (c == '\\'):
idx_stack.append(i)
elif (idx_stack and c == '/'):
# 対応する'\\'の位置
j = idx_stack.pop()
v = i - j
while (v_lakes and v_lakes[-1][0] > j):
v += v_lakes.pop()[1]
v_lakes.append((j, v))
ans = [len(v_lakes)]
v = [v[1] for v in v_lakes]
ans.extend(v)
print(sum(v))
print(*ans)
| A,B = sorted(map(int,open(0).read().split()))
if A==1 and B==2:
print(3)
elif A==1 and B==3:
print(2)
else:
print(1)
| 0 | null | 55,148,941,694,720 | 21 | 254 |
# -*= coding: utf-8 -*-
from collections import deque
S = input()
Q = int(input())
query = list()
for i in range(Q):
query.append(list(map(str, input().split())))
d = deque()
for s in S:
d.append(s) # 右からsを追加
is_reverse = False
for q in query:
if len(q) == 1:
# Tiが1の場合
is_reverse = not is_reverse
else:
# Tiが2の場合
if q[1] == '1':
# Fiが1の場合
if is_reverse == False:
d.appendleft(q[2])
else:
d.append(q[2])
else:
# Fiが2の場合
if is_reverse == False:
d.append(q[2])
else:
d.appendleft(q[2])
ans = ''
if is_reverse == True:
d.reverse()
ans = ''.join(d)
print(ans) | from collections import deque
import sys
flg1 = 1
s = input()
ll = deque()
lr = deque()
for _ in range(int(input())):
q = sys.stdin.readline().rstrip()
if q == "1":
flg1 *= -1
else:
q = list(q.split())
flg2 = 1 if q[1] == "1" else -1
if flg1 * flg2 == 1:
ll.appendleft(q[2])
else:
lr.append(q[2])
ans = "".join(ll) + s + "".join(lr)
print((ans[::-1], ans)[flg1 == 1]) | 1 | 57,249,392,583,740 | null | 204 | 204 |
A = list(map(int, input().split()))
if sum(A) < 22:
print("win")
else:
print("bust") | import sys
def input(): return sys.stdin.readline().rstrip()
class Sieve: #区間[2,n]の値の素因数分解
def __init__(self,n=1):
self.primes=[]
self.f=[0]*(n+1) #ふるい(素数ならその値)
self.f[0]=self.f[1]=-1
for i in range(2,n+1): #素数リスト作成
if self.f[i]: continue
self.primes.append(i)
self.f[i]=i
for j in range(i*i,n+1,i):
if not self.f[j]:
self.f[j]=i # 最小の素因数を代入
def is_prime(self, x):
return self.f[x]==x
def prime_fact(self,x): # 素因数分解の昇順リスト, {2:p,3:q,5:r,...}
fact_dict=dict()
while x!=1:
p=self.f[x]
fact_dict[p]=fact_dict.get(p,0)+1
x//=self.f[x]
return fact_dict
def main():
n=int(input())
A=list(map(int,input().split()))
mod=10**9+7
p_lis={}
Prime=Sieve(10**6+5)
for a in A:
f=Prime.prime_fact(a)
#print(f)
for key in f:
p_lis[key]=max(p_lis.get(key,0),f[key])
lcm=1
#print(p_lis)
for key in p_lis:
lcm=(lcm*pow(key,p_lis[key],mod))%mod
ans=0
#print(lcm)
for a in A:
b=lcm*pow(a,mod-2,mod)%mod
ans=(ans+b)%mod
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 103,124,816,403,232 | 260 | 235 |
# coding:utf-8
import sys
a = []
for line in sys.stdin:
a.append(list(line.strip().replace(" ","").lower()))
a = reduce(lambda x,y: x+y,a)
dict = {}
for i in range(26):
dict[chr(ord('a')+i)] = 0
for i in a:
for key,value in dict.items():
if key == i:
dict[key] += 1
for key,value in sorted(dict.items()):
print "%s : %d" % (key,value)
| all_text = []
while True:
try:
text = input().split()
all_text.extend(text)
except EOFError:
break
text = ''.join(all_text)
count = [0]*32
for letter in text:
i = ord(letter)
if i < 64:
continue
else:
i %= 32
if i:
count[i] += 1
for i in range(26):
print(chr(i+ord('a')), ':', count[i+1])
| 1 | 1,652,441,931,868 | null | 63 | 63 |
n = int(input())
x = []
for i in range(n):
a, b = map(int, input().split())
x.append([a, b])
ans = 0
for i in range(len(x) - 1):
for j in range(i+1, len(x)):
ans += ((x[i][0]-x[j][0])**2 + (x[i][1]-x[j][1])**2)**0.5
print((2*ans)/n) | a, b, c, k = map(int, input().split())
ans = 0
ans += min(a, k)
k -= min(a, k)
k -= min(b, k)
ans -= min(c, k)
print(ans)
| 0 | null | 84,952,218,917,034 | 280 | 148 |
class Fibonacci(object):
memo = [1, 1]
def get_nth(self, n):
if n < len(Fibonacci.memo):
return Fibonacci.memo[n]
# print('fib({0}) not found'.format(n))
for i in range(len(Fibonacci.memo), n+1):
result = Fibonacci.memo[i-1] + Fibonacci.memo[i-2]
Fibonacci.memo.append(result)
# print('fib({0})={1} append'.format(i, result))
return Fibonacci.memo[n]
if __name__ == '__main__':
# ??????????????\???
num = int(input())
# ?????£??????????????°????¨????
f = Fibonacci()
result = f.get_nth(num)
# ???????????????
print('{0}'.format(result)) | import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
def main():
N = int(readline())
dp = [0] * 47
dp[0] = 1
dp[1] = 1
for i in range(2,N+1):
dp[i] = dp[i-1] + dp[i-2]
print(dp[N])
if __name__ == '__main__':
main()
| 1 | 2,269,311,422 | null | 7 | 7 |
######################
# _ ____ #
# U /"\ u U /"___| #
# \/ _ \/ \| | u #
# / ___ \ | |/__ #
# /_/ \_\ \____| #
# \\ >> _// \\ #
# (__) (__)(__)(__) #
# Compro by NULL_CT© #
######################
from sys import stdin
import numpy as np
import math
input = stdin.readline
def divisor(_n):
result = []
for i in range(1, int(math.sqrt(_n)) + 1):
if _n % i == 0:
result.append(i)
if _n % (_n / i) == 0:
result.append(int(_n / i))
return result
k,x = map(int,input().split())
if 500 * k >= x:
print("Yes")
else:
print("No") | import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
N = int(readline())
if N % 2 == 1:
print(0)
else:
count2 = 0
count5 = 0
compare = 1
while N >= compare * 2:
compare *= 2
count2 += N // compare
compare = 1
N //= 2
while N >= compare * 5:
compare *= 5
count5 += N // compare
ans = min(count2, count5)
print(ans)
if __name__ == '__main__':
solve() | 0 | null | 106,733,624,212,078 | 244 | 258 |
n = int(input())
a = list(map(int, input().split()))
ans = 1
for i in a:
if i == 0:
ans = 0
if ans != 0:
for i in a:
ans *= i
if ans > 10**18:
ans = -1
break
print(ans) | h, w, n = map(int, [input() for _ in range(3)])
print((n-1)//max(h, w)+1) | 0 | null | 52,630,198,419,040 | 134 | 236 |
H,N = map(int,input().split())
Magic = [list(map(int, input().split())) for i in range(N)]
inf = float("inf")
dp = [inf]*(H+1)
dp[0]=0
for i in range(N):
a,b = Magic[i]
for h in range(H):
next_h = min(h+a,H)
dp[next_h]=min(dp[next_h],dp[h]+b)
print(dp[-1]) | H, N = map(int, input().split())
AB = []
INF = 10**8 + 1
dp = [INF]*(H+1)
dp[0] = 0
for _ in range(N):
a, b = map(int, input().split())
AB.append((a, b))
for i in range(1, H+1):
for j in range(N):
dp[i] = min(dp[i], dp[max(0, i - AB[j][0])] + AB[j][1])
print(dp[-1]) | 1 | 81,064,537,209,932 | null | 229 | 229 |
X,K,D=(int(x) for x in input().split())
x=abs(X)
a=x//D
b=x-a*D
B=abs(x-(a+1)*D)
if b>B:
a=a+1
if a>=K:
print(abs(x-K*D))
else:
c=K-a
if c%2 == 0:
print(abs(x-a*D))
else:
d=abs(x-(a-1)*D)
e=abs(x-(a+1)*D)
print(min(d,e)) | N, R = (int(x) for x in input().split())
if N >= 10:
result = R
else:
result = R + 100*(10-N)
print(result) | 0 | null | 34,513,667,763,410 | 92 | 211 |
N=input()
N=list(N)
N=map(lambda x: int(x),N)
if sum(N)%9==0:
print("Yes")
else:
print("No")
| n = int(input())
s = input()
print(sum(int(s[i:i+3] == "ABC") for i in range(n - 2))) | 0 | null | 51,750,733,789,822 | 87 | 245 |
def luckey7():
# 入力
N = input()
# 判別処理
if '7' in N:
return 'Yes'
else:
return 'No'
result = luckey7()
print(result) | n = input()
for s in n:
if s == '7':exit(print('Yes'))
print('No') | 1 | 34,094,067,034,540 | null | 172 | 172 |
L = float(input())
returnVal = (L/3)**3
print(returnVal) | num = int(input())
number = num / 3
print(number * number * number) | 1 | 47,062,729,121,760 | null | 191 | 191 |
# encoding: utf-8
from collections import deque
def round_robin_scheduling(N, Q, A):
t = 0
while A:
process = A.popleft()
if process[1] <= Q:
t += process[1]
print(process[0],t)
else:
t += Q
A.append([process[0],process[1]-Q])
if __name__ == '__main__':
N,Q = map(int,input().split())
A = deque()
for i in range(N):
a = input()
A.append([a.split()[0],int(a.split()[1])])
round_robin_scheduling(N,Q,A) | process_num, qms = map(int, input().split())
raw_procs = [input() for i in range(process_num)]
if __name__ == '__main__':
procs = []
for row in raw_procs:
name, time = row.split()
procs.append({
"name": name,
"time": int(time),
})
total_time = 0
current_proc = 0
while len(procs) > 0:
if procs[current_proc]["time"] > qms:
procs[current_proc]["time"] = procs[current_proc]["time"] - qms
total_time += qms
if current_proc == len(procs)-1:
current_proc = 0
else:
current_proc += 1
else:
total_time += procs[current_proc]["time"]
print("{} {}".format(procs[current_proc]["name"], total_time))
del procs[current_proc]
if current_proc == len(procs):
current_proc = 0
| 1 | 44,183,400,690 | null | 19 | 19 |
m1, _ = list(map(int, input().split()))
m2, _ = list(map(int, input().split()))
if m1 == m2:
print(0)
else:
print(1) | a,b=input().split()
c,d=input().split()
if a==c:
print("0")
else:
print("1") | 1 | 124,108,951,693,078 | null | 264 | 264 |
import numpy as np
def main():
n = int(input())
x = np.arange(n + 1)
x[x % 3 == 0] = 0
x[x % 5 == 0] = 0
print(x.sum())
if __name__ == '__main__':
main() | a,b,c = sorted(map(int,raw_input().split()))
print a,b,c | 0 | null | 17,575,032,980,330 | 173 | 40 |
def main():
n = int(input())
operation = [input().split() for _ in range(n)]
dictionary = {}
for command, char in operation:
if command == "insert":
dictionary[char] = True
elif command == "find":
try:
if dictionary[char]:
print("yes")
except KeyError:
print("no")
return
if __name__ == "__main__":
main()
| haveTrumps = [[0 for i in range(13)] for j in range(4)]
allCards = int(input())
for i in range(0, allCards):
cardType, cardNum = input().split()
if cardType == "S":
haveTrumps[0][int(cardNum) - 1] = 1
elif cardType == "H":
haveTrumps[1][int(cardNum) - 1] = 1
elif cardType == "C":
haveTrumps[2][int(cardNum) - 1] = 1
elif cardType == "D":
haveTrumps[3][int(cardNum) - 1] = 1
for i in range(0, 4):
for j in range(0, 13):
if haveTrumps[i][j] == 0:
if i == 0:
print("S ", end="")
elif i == 1:
print("H ", end="")
elif i == 2:
print("C ", end="")
elif i == 3:
print("D ", end="")
print("{0}".format(j + 1)) | 0 | null | 548,450,154,340 | 23 | 54 |
N,K = map(int,input().split())
S = []
d = {}
A = list(map(int,input().split()))
ans = 0
sum =0
for i in range(1,N+1):
sum += A[i-1] % K
s = (sum - i) % K
if i > K:
x = S.pop(0)
d[x] -= 1
elif i < K:
if s == 0:
ans += 1
if s not in d:
d[s] = 0
ans += d[s]
d[s] += 1
S.append(s)
print(ans)
| #coding:utf-8
def seki(a, b):
c = []
gou = 0
d = []
for i in range(len(a)):
for j in range(len(b[0])):
for k in range(len(b)):
gou += a[i][k] * b[k][j]
d.append(gou)
gou = 0
c.append(d)
d=[]
return c
n, m, l = [int(i) for i in input().rstrip().split()]
a = [list(map(int , input().rstrip().split())) for i in range(n)]
b = [list(map(int , input().rstrip().split())) for i in range(m)]
c = seki(a,b)
for i in c:
print(" ".join(list(map(str,i)))) | 0 | null | 69,153,963,994,490 | 273 | 60 |
# AGC 043 A
H,W = map(int, input().split())
table = [input() for _ in range(H)]
inf = 10**9
dp = [[inf] * (W+1) for _ in range(H+1)]
dp[0][0] = 0 if table[0][0] == "." else 1
for h in range(H):
for w in range(W):
flg = table[h][w] == "." and (table[h][w+1] == "#" if w < W-1 else True)
dp[h][w+1] = min(dp[h][w+1], dp[h][w] + 1 if flg else dp[h][w])
flg = table[h][w] == "." and (table[h+1][w] == "#" if h < H-1 else True)
dp[h+1][w] = dp[h][w] + 1 if flg else dp[h][w]
print(dp[H-1][W-1])
| from collections import deque
H, W = map(int, input().split())
grid = [input() for _ in range(H)]
INF = 1000
path = [[INF] * W for _ in range(H)]
q = deque()
q.append((0, 0, 0))
path[0][0] = 0
while q:
s, i, j = q.popleft()
c = grid[i][j]
for di, dj in [(1, 0), (0, 1)]:
ni, nj = i + di, j + dj
if 0 <= ni < H and 0 <= nj < W:
nc = grid[ni][nj]
ns = s + (c != nc)
if path[ni][nj] > ns:
path[ni][nj] = ns
if c == nc:
q.appendleft((ns, ni, nj))
else:
q.append((ns, ni, nj))
ans = path[-1][-1]
ans += (grid[0][0] == '#') + (grid[-1][-1] == '#')
print(ans // 2)
| 1 | 49,279,275,514,910 | null | 194 | 194 |
n = int(input())
a = [int(i) for i in input().split(" ")]
t = a[0]
for i in a[1:]:
t = t ^ i
ans = [t^i for i in a]
print(" ".join(map(str, ans))) | from collections import deque
l=deque()
for _ in range(input()):
a=raw_input().split()
c=a[0][-4]
if c=="i": l.popleft()
elif c=="L": l.pop()
elif c=="s": l.appendleft(a[1])
else:
try: l.remove(a[1])
except: pass
print " ".join(l) | 0 | null | 6,291,133,754,620 | 123 | 20 |
from collections import defaultdict
n = int(input())
m = n//2
INF = 10**18
dp = [defaultdict(lambda: -INF)for _ in range(n+2)]
for i, a in enumerate(map(int, input().split()), 2):
for j in range(max(1, i//2-1), -(-i//2)+1):
if j-1 == 0:
dp[i-2][j-1] = 0
dp[i][j] = max(dp[i-1][j], dp[i-2][j-1]+a)
print(dp[n+1][m])
| import math
import sys
from collections import Counter
import bisect
readline = sys.stdin.readline
def main():
cnt = 0
arg = 0
x = int(readline().rstrip())
for i in range(1000):
cnt += 1
arg += x
arg %= 360
if arg == 0:
break
print(cnt)
if __name__ == '__main__':
main()
| 0 | null | 25,416,337,577,594 | 177 | 125 |
import os
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353
t1, t2 = list(map(int, sys.stdin.buffer.readline().split()))
a1, a2 = list(map(int, sys.stdin.buffer.readline().split()))
b1, b2 = list(map(int, sys.stdin.buffer.readline().split()))
da1 = t1 * a1
da2 = t2 * a2
db1 = t1 * b1
db2 = t2 * b2
if da1 + da2 > db1 + db2:
a1, b1 = b1, a1
a2, b2 = b2, a2
da1, db1 = db1, da1
da2, db2 = db2, da2
# b のほうがはやい
# 無限
if da1 + da2 == db1 + db2:
print('infinity')
exit()
# 1回も会わない
if da1 < db1:
print(0)
exit()
# t1 で出会う回数
cnt = abs(da1 - db1) / abs(da1 + da2 - db1 - db2)
ans = int(cnt) * 2 + 1
if cnt == int(cnt):
ans -= 1
print(ans)
| T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
X1 = T1 * (A1 - B1)
X2 = T2 * (A2 - B2)
D = X1 + X2
if D == 0:
print("infinity")
else:
if X1 < 0:
X1, X2 = [-X1, -X2]
else:
D = -D
if D < 0:
print("0")
else:
if X1 % D == 0:
print((X1 // D) * 2)
else:
print((X1 // D) * 2 + 1)
| 1 | 131,365,131,413,930 | null | 269 | 269 |
def main():
N = int(input())
A = list(map(int, input().split()))
SUM = 1
if 0 in A:
print(0)
return
for a in A:
SUM = SUM * a
if SUM > 1000000000000000000:
print(-1)
return
print(SUM)
main() | n = int(input())
A = list(map(int, input().split(' ')))
res = 1
for a in A:
res = min(res*a, 10**18 + 1)
if res == 10**18 + 1: print(-1)
else: print(res) | 1 | 16,266,780,215,442 | null | 134 | 134 |
x, n = map(int, input().split())
p = sorted(list(map(int, input().split())))
a = 100
b = 0
for i in range(0, 102):
if i not in p and abs(x - i) < a:
a = abs(x - i)
b = i
print(b)
| num=int(input())
print(3.14159265359*num*2) | 0 | null | 22,716,556,739,620 | 128 | 167 |
import sys
from io import StringIO
import unittest
import os
from operator import ixor
# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)
# 実装を行う関数
def resolve(test_def_name=""):
# 数値取得サンプル
# 1行1項目 n = int(input())
# 1行2項目 x, y = map(int, input().split())
# 1行N項目 x = [list(map(int, input().split()))]
# N行1項目 x = [int(input()) for i in range(n)]
# N行N項目 x = [list(map(int, input().split())) for i in range(n)]
# 文字取得サンプル
# 1行1項目 x = input()
# 1行1項目(1文字ずつリストに入れる場合) x = list(input())
n = int(input())
a_s = list(map(int, input().split()))
one_counts = [0 for i in range(61)]
zero_counts = [0 for i in range(61)]
# 以下、XORで便利と思われる処理。
# -------------------------------------------
# ループ回数の取得(最大の数値の桁数分、ループ処理を行うようにする)
max_num = max(a_s)
max_loop = 0
for i in range(0, 61):
if max_num < 1 << i:
break
max_loop += 1
# ループ処理にて、各桁の0と1の個数を数え上げる。
# 例:入力[1(01),2(10),3(11)] -> one_count=[2,2,0・・]とzero_counts[1,1,0・・]を得る。
for a in a_s:
for i in range(0, max_loop):
if a & 1 << i:
one_counts[i] += 1
else:
zero_counts[i] += 1
# -------------------------------------------
# 以上、XORで便利と思われる処理。
# 結果を計算する処理
ans = 0
for i in range(0, max_loop):
# 各桁の「0の個数」*「1の個数」*2^(0~桁数-1乗まで) を加算していく
ans += (one_counts[i] * zero_counts[i] * pow(2, i)) % (pow(10, 9) + 7)
ans = ans % (pow(10, 9) + 7)
# 結果を出力
print(ans)
# テストクラス
class TestClass(unittest.TestCase):
def assertIO(self, assert_input, output):
stdout, sat_in = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
resolve(sys._getframe().f_back.f_code.co_name)
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, sat_in
self.assertEqual(out, output)
def test_input_1(self):
test_input = """3
1 2 3"""
output = """6"""
self.assertIO(test_input, output)
def test_input_2(self):
test_input = """10
3 1 4 1 5 9 2 6 5 3"""
output = """237"""
self.assertIO(test_input, output)
def test_input_3(self):
test_input = """10
3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820"""
output = """103715602"""
self.assertIO(test_input, output)
# 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
def tes_t_1original_1(self):
test_input = """データ"""
output = """データ"""
self.assertIO(test_input, output)
# 実装orテストの呼び出し
if __name__ == "__main__":
if os.environ.get("USERNAME") is None:
# AtCoder提出時の場合
resolve()
else:
# 自PCの場合
unittest.main()
| n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
# 解説AC
ans, num = 0,1
for i in range(60):
cnt = sum((ai & num) == num for ai in a)
ans += (cnt * (n - cnt) * num) % mod
num <<= 1
print(ans % mod)
| 1 | 123,386,379,846,938 | null | 263 | 263 |
x = int(input())
k = []
for i in range(1, x + 1):
y = i
if i % 3 == 0:
k.append(i)
else:
while True:
if y % 10 == 3:
k.append(i)
break
else:
if y <= 10:
break
else:
y //= 10
print(' '+ ' '.join([str(x) for x in k]))
| for x in range(1,10):
for y in range(1,10):
print str(x)+"x"+str(y)+"="+str(x*y) | 0 | null | 474,736,112,214 | 52 | 1 |
n, x, m = list(map(int, input().split()))
count = 0
# table2jou = []
# for mi in range(m + 1):
# table2jou.append(pow(mi, 2))
# tablef = []
# for mi in range(m + 1):
# # tablef.append(table2jou[mi] % m)
# tablef.append(pow(mi, 2, m))
is_used = [0] * (m + 1)
count = x
pre_an = x
his = [x]
for ni in range(2, n + 1):
# an = tablef[pre_an]
an = pow(pre_an, 2, m)
if is_used[an] == 1:
leftnum = n - ni + 1
start = his.index(an)
end = leftnum % (len(his) - start) + start
loopnum = leftnum // (len(his) - start)
count = count + sum(his[start: end])
count = count + sum(his[start:]) * loopnum
break
his.append(an)
is_used[an] = 1
count = count + an
pre_an = an
print(count)
| s = input()
n = len(s)
kotae = "x"*n
print(kotae) | 0 | null | 37,684,866,248,100 | 75 | 221 |
import sys
def main():
sys.stdin.readline()
list1 = [int(i) for i in sys.stdin.readline().split()]
print(min(list1), max(list1), sum(list1))
if __name__ == '__main__':
main()
| x,y = list(map(int,input().split()))
if x<y: x,y = y,x
while y!=0: x,y = y,x%y
print(x) | 0 | null | 363,144,667,222 | 48 | 11 |
s=int(input())
a=s//3600
b=(s%3600)//60
c=(s%3600)%60
print(str(a)+":"+str(b)+":"+str(c))
| x = input().split(" ")
a = int(x[0])
b = int(x[1])
if a < b:
print("a < b")
elif a > b:
print("a > b")
elif a == b:
print("a == b") | 0 | null | 342,306,900,562 | 37 | 38 |
N = input()
sum = 0
for i in range(10):
sum += N.count(str(i)) * i
print('Yes' if sum%9 == 0 else 'No') | import sys
sys.setrecursionlimit(10**7)
readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))
from itertools import accumulate
def sum_max(line,n_min,n_max):
n = len(line)
ac = list(accumulate([0]+line))
l = 0
r = n_min
ans = ac[r]-ac[l]
i = 0
if n_min==n_max:
for i in range(n-n_min+1):
ans = max(ans,ac[i+n_min]-ac[i])
else:
while r!=n or i%2==1:
if i%2==0:
r = ac[r+1:l+n_max+1].index(max(ac[r+1:l+n_max+1])) + r+1
else:
l = ac[l+1:r-n_min+1].index(min(ac[l+1:r-n_min+1])) + l+1
i+=1
ans = max(ans,ac[r]-ac[l])
return ans
def sum_min(line,n_min,n_max):
n = len(line)
ac = list(accumulate([0]+line))
l = 0
r = n_min
ans = ac[r]-ac[l]
i = 0
if n_min==n_max:
for i in range(n-n_min+1):
ans = min(ans,ac[i+n_min]-ac[i])
else:
while r!=n or i%2==1:
if i%2==0:
r = ac[r+1:l+n_max+1].index(min(ac[r+1:l+n_max+1])) + r+1
else:
l = ac[l+1:r-n_min+1].index(max(ac[l+1:r-n_min+1])) + l+1
i+=1
ans = min(ans,ac[r]-ac[l])
return ans
def circle_sum_max(circle,num):
n = len(circle)
s = sum(circle)
if num == 0:
ans = 0
else:
ans = max(sum_max(circle,1,num), s-sum_min(circle,n-num,n-1))
return ans
n,k = readints()
p = [x-1 for x in readints()]
c = readints()
circles = []
used = [0]*n
for i in range(n):
if not used[i]:
circles.append([c[i]])
used[i] = 1
j = p[i]
while not used[j]:
circles[-1].append(c[j])
used[j] = 1
j = p[j]
score = -10**20
for cir in circles:
m = len(cir)
a = sum(cir)
if k>m:
if a>0:
score = max(score, (k//m)*a + circle_sum_max(cir,k%m), (k//m-1)*a + circle_sum_max(cir,m))
else:
score = max(score,circle_sum_max(cir,m))
else:
score = max(score,circle_sum_max(cir,k))
print(score)
| 0 | null | 4,900,114,054,628 | 87 | 93 |
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions import gcd
#input=sys.stdin.readline
import bisect
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ar=[0]*(n+1)
br=[0]*(m+1)
ans=0
for i in range(n):
ar[i+1]=ar[i]+a[i]
for i in range(m):
br[i+1]=br[i]+b[i]
for i in range(m+1):
sup=k-br[i]
if sup<0:
break
res=bisect.bisect_right(ar,sup)+i-1
ans=max(res,ans)
print(ans) | import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(input())
A = list(map(int, input().split()))
A_and_i = [[a, i] for i, a in enumerate(A)]
A_and_i.sort(reverse=True)
DP = [[0] * (N + 1) for _ in range(N + 1)]
for i in range(N):
a, idx = A_and_i[i]
for j in range(N):
# 右に持っていく
if j <= i:
DP[i + 1][j] = max(DP[i + 1][j], DP[i][j] +
a * abs(N - 1 - (i - j) - idx))
DP[i + 1][j + 1] = max(DP[i + 1][j + 1], DP[i]
[j] + a * abs(idx - j))
ans = max(DP[N])
print(ans)
| 0 | null | 22,238,522,774,558 | 117 | 171 |
'''
@sksshivam007 - Template 1.0
'''
import sys, re, math
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx): return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))[::-1]
toret = {}
for tup in temp:
toret[tup[0]] = tup[1]
return toret
def sortDictWithKey(passedDic):
return dict(OrderedDict(sorted(passedDic.items())))
INF = float('inf')
mod = 10 ** 9 + 7
n, k = MAP()
a = [0]*(k+1)
for i in range(k, 0, -1):
temp = pow((k//i), n, mod)
ans = temp%mod
for j in range(2, k//i + 1):
ans -= a[j*i]%mod
a[i] = ans%mod
final = 0
for i in range(len(a)):
final+=(a[i]*i)%mod
print(final%mod) | 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
a,b = input().split()
b = b[:-3] + b[-2:]
ans = int(a) * int(b)
ans = ans // 100
print(ans)
| 0 | null | 26,822,227,714,220 | 176 | 135 |
N, M = map(int, input().split())
if N%2:
for i in range(1, M+1):
print(i, N-i)
else:
for i in range(1, M+1):
if i <= (N//2)//2:
print(i, N-i+1)
else:
print(i+1, N-i+1)
| import bisect
n = int(input())
L = list(map(int,input().split()))
L.sort()
ans = 0
for a in range(0,n):
for b in range(a+1,n):
p = bisect.bisect_left(L, L[a]+L[b])
ans += max(p-(b+1),0)
print(ans) | 0 | null | 100,500,677,034,762 | 162 | 294 |
print('Yes' if input() in ['hi'*i for i in range(1,6)] else 'No') | S = input()
ans = 'Yes'
while len(S) > 0:
if S[:2] == 'hi':
S = S[2:]
else:
ans = 'No'
break
print(ans) | 1 | 53,138,222,301,078 | null | 199 | 199 |
S = str(input())
L = len(S)
ans = "x" * L
print(ans) | s = input()
ans = ''
for i in range(len(s)):
ans = ans + 'x'
print(ans) | 1 | 72,519,522,072,688 | null | 221 | 221 |
s = input()
count = 0
max = 0
for i in range(len(s)):
if s[i] == 'S':
count =0
else:
count += 1
if count > max:
max = count
print(max) | import sys
readline = sys.stdin.readline
X = int(readline())
limit = 600
rank = 8
for i in range(8):
if X < limit:
print(rank)
break
limit += 200
rank -= 1 | 0 | null | 5,856,497,978,548 | 90 | 100 |
# 参考 : https://atcoder.jp/contests/abc165/submissions/16921279
# 参考 : https://atcoder.jp/contests/abc165/submissions/16832189
from collections import deque
n,m,q = map(int,input().split())
l = [list(map(int,input().split())) for i in range(q)]
a,b,c,d = [list(i) for i in zip(*l)]
# 数列 A の基(最初は1を入れておく)
queue = deque([[1]])
ans = 0
# 数列 A の候補がなくなる(キューが空になる)まで探索
while queue:
# 数列 A を前から一つ取り出す
x = queue.popleft()
# 数列 A が長さ N か
if len(x) == n:
s = 0
# 実際に何点取得できるか
for i in range(q):
if x[b[i]-1] - x[a[i]-1] == c[i]:
s += d[i]
ans = max(ans,s)
else:
# 違う場合、後ろに数字を付け足す
# 付け足す数字は取り出した数列 A の一番後ろの値から M まで
# 最終的に長さが 1 , 2 ... N となり、if の条件を満たすようになる
for j in range(x[-1],m+1):
y = x + [j]
queue.append(y)
print(ans)
# 制約
# 2 <= N <= 10
# 1 <= M <= 50
# 1 <= Q <= 50
# なのでこの探索は間に合う
# 入力例 1 は A[1,3,4]
# 入力例 2 は A[1,1,1,4]
# 入力例 3 は A[1,1,1,1,1,1,1,1,1,10]
# が最大得点となる | from itertools import combinations_with_replacement
N, M, Q = map(int, input().split())
num = []
for i in range(Q):
num.append(list(map(int, input().split())))
lst = list(combinations_with_replacement([i for i in range(1, M+1)], N))
ans = 0
for q in lst:
ans_tmp = 0
for i in range(Q):
if(q[num[i][1]-1]-q[num[i][0]-1] == num[i][2]):
ans_tmp += num[i][3]
if(ans < ans_tmp):
ans = ans_tmp
print(ans) | 1 | 27,393,043,924,960 | null | 160 | 160 |
N,M=map(int,input().split())
A=[]
A=list(map(int,input().split()))
if(N-sum(A)<0):
print('-1')
exit()
print(N-sum(A))
| #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
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()))
"""
"""
def warshall_floyd(d):
for k in range(n):
for i in range(n):
for j in range(n):
d[i][j] = min(d[i][j],d[i][k] + d[k][j])
return d
n,m,l = LI()
dist = [[inf]*n for _ in range(n)]
dist2 = [[inf]*n for _ in range(n)]
for i in range(n):
dist[i][i] = 0
dist2[i][i] = 0
for _ in range(m):
a,b,c = LI()
dist[a-1][b-1] = c
dist[b-1][a-1] = c
dist = warshall_floyd(dist)
for i in range(n):
for j in range(n):
if dist[i][j] > l:
dist2[i][j] = inf
else:
dist2[i][j] = 1
dist2 = warshall_floyd(dist2)
q = I()
ans = []
for _ in range(q):
s,t = LI()
if dist2[s-1][t-1] == inf:
print(-1)
else:
print(dist2[s-1][t-1]-1)
| 0 | null | 102,323,403,259,282 | 168 | 295 |
import math
N = int(input())
X = N / 1.08
floor = math.ceil(N/1.08)
ceil = math.ceil((N+1)/1.08)
for i in range(floor,ceil):
print(i)
break
else:
print(":(") | while 1:
x, y = map(int, input().split())
if x == 0 and y == 0:
break
elif x < y:
print("%d %d" % (x, y))
else:
print("%d %d" % (y, x)) | 0 | null | 63,046,060,552,060 | 265 | 43 |
S=input()
n=int(S)
h=int(n/(60*60))
m=int((n-60*60*h)/60)
s=int(n-(60*60*h+60*m))
print(h,":",m,":",s, sep='')
| N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
G = [-1 for i in range(N+1)]
for i, v in enumerate(P):
G[i+1] = (v, C[v-1])
ans = -float("inf")
for i in range(1, N+1):
loop = []
S = i
visited = [False for i in range(N+1)]
while visited[S] == False:
loop.append(G[S][-1])
visited[S] = True
S = G[S][0]
circle_sum = sum(loop)
this_case_ans = -float("inf")
if circle_sum < 0:
pass_sum = 0
for i in range(len(loop)):
pass_sum += loop[i]
this_case_ans = max(this_case_ans, pass_sum)
ans = max(ans, this_case_ans)
continue
else:
L = len(loop)
for i in range(1, L):
loop[i] += loop[i-1]
loop.insert(0, -float("inf"))
for i in range(1, L+1):
loop[i] = max(loop[i], loop[i-1])
loop[0] = 0
if K//L > 0:
this_case_ans = max(K//L * circle_sum +
loop[K % L], (K//L-1)*circle_sum + loop[-1])
else:
for i in range(1, K+1):
this_case_ans = max(this_case_ans, loop[i])
ans = max(ans, this_case_ans)
print(ans) | 0 | null | 2,879,253,280,810 | 37 | 93 |
n,k=map(int,(input().split()))
ans=0
max=sum(range(n-k+1,n+1))*(n-k+2)
min=sum(range(k))*(n-k+2)
for i in range(1,n-k+2):
min+=(k-1+i)*(n-k+2-i)
for i in range(1,n-k+2):
max+=(n-k+1-i)*(n-k+2-i)
ans=(max-min+n-k+2)%(10**9+7)
print(ans) | N, K = map(int, input().split())
def sub_sum(l, r):
return (l + r) * (r - l + 1) / 2
ans = 0
for i in range(K, N+2):
l = sub_sum(0, i-1)
r = sub_sum(N-i+1, N)
ans += r - l + 1
ans = ans % (10**9+7)
print(int(ans))
| 1 | 33,088,933,771,610 | null | 170 | 170 |
line = input()
words = line.split()
nums = list(map(int, words))
a = nums[0]
b = nums[1]
d = a // b
r = a % b
f = a / b
f = round(f,5)
print ("{0} {1} {2}".format(d,r,f)) | A,B = list(input().split())
A = int(A)
B = int((float(B)+0.005)*100)
print(A*B//100) | 0 | null | 8,658,799,796,732 | 45 | 135 |
H, W = map(int, input().split())
if (H*W) % 2 == 0:
if H == 1 or W == 1:
res = 1
else:
res = int(H * W / 2)
else:
if H == 1 or W == 1:
res = 1
else:
res = int(H * (W//2) + int(H/2) + 1)
print('{0:d}'.format(res)) | a = int(input())
print(2*(22/7)*a) | 0 | null | 41,070,624,875,478 | 196 | 167 |
N,K = map(int, input().split())
P = list(map(int, input().split()))
P.sort()
plist = P[0:K]
a = 0
for p in plist:
a+=p
print(a) | n,k=map(int,input().split())
l =[]
cnt =0
for i in range(k):
d = int(input())
a = list(map(int,input().split()))
for j in a:
l.append(j)
for i in range(1,n+1):
if i not in l:
cnt+=1
print(cnt) | 0 | null | 18,196,511,335,240 | 120 | 154 |
#coding:utf-8
apartment = [[[0 for z in range(10)] for y in range(3)] for x in range(4)]
N = int(input())
data = [[int(x) - 1 for x in input().split()] for y in range(N)]
for x in data:
apartment[x[0]][x[1]][x[2]] += x[3] + 1
if apartment[x[0]][x[1]][x[2]] > 9:
apartment[x[0]][x[1]][x[2]] = 9
elif apartment[x[0]][x[1]][x[2]] < 0:
apartment[x[0]][x[1]][x[2]] = 0
for x in range(4):
for y in range(3):
for z in range(10):
print(" " + str(apartment[x][y][z]), end="")
print()
if x != 3:
print(("#"*20)) | n = input()
arr = [map(int,raw_input().split()) for _ in range(n)]
tou = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for line in arr:
b,f,r,v = line
tou[b-1][f-1][r-1] = tou[b-1][f-1][r-1] + v
for i in range(4):
for j in range(3):
print ' '+' '.join(map(str,tou[i][j]))
if i < 3 :
print '#'*20 | 1 | 1,105,033,240,832 | null | 55 | 55 |
def selectionSort(a, n):
count = 0
for i in range(0, n):
minj = i
for j in range(i, n):
if a[j] < a[minj]:
minj = j
a[i], a[minj] = a[minj], a[i]
if i != minj:
count += 1
return count
def main():
n = int(input())
a = [int(x) for x in input().split(' ')]
count = selectionSort(a, n)
print(' '.join([str(x) for x in a]))
print(count)
if __name__ == '__main__':
main() | n,k,*a=map(int, open(0).read().split())
b=[0]*-~n
for i in range(n):b[i+1]=(a[i]+b[i]-1)%k
d={k:0}
a=0
for l,r in zip([k]*min(k,n+1)+b,b):d[l]-=1;t=d.get(r,0);a+=t;d[r]=t+1
print(a) | 0 | null | 68,829,609,904,020 | 15 | 273 |
rad = int(input())
print (2*3.1415926*rad) | R=int(input())
print(2*3.14159265*R)
| 1 | 31,355,508,280,928 | null | 167 | 167 |
X,N = map(int,input().split())
p = list(map(int,input().split()))
count = -1
while True:
count +=1
if X-count not in p:
print(X-count)
break
elif X+count not in p:
print(X+count)
break | import bisect
X, N = map(int, input().split())
P = set(map(int, input().split()))
A = {i for i in range(102)}
S = list(A - P)
T = bisect.bisect_left(S, X)
if T == 0:
print(S[0])
elif X - S[T-1] > S[T] - X:
print(S[T])
else:
print(S[T-1])
| 1 | 14,101,658,558,092 | null | 128 | 128 |
N,K=map(int,input().split())
H=sorted(list(map(int,input().split())))
if K==0:
print(sum(H))
exit()
H=H[-N:-K]
print(sum(H)) | n,k=map(int,input().split())
h=[int(x) for x in input().rstrip().split()]
h.sort(reverse=True)
for i in range(min(k,n)):
h[i]=0
print(sum(h))
| 1 | 78,980,064,880,028 | null | 227 | 227 |
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations, product
from math import *
sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7
def lcm(x,y):
return x*y//gcd(x,y)
def mint():
return map(int,input().split())
def lint():
return list(map(int,input().split()))
def ilint():
return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
print(l[0] if x else l[1])
def lprint(l, sep='\n'):
for x in l:
print(x, end=sep)
def ston(c, c0='a'):
return ord(c)-ord(c0)
def ntos(x, c0='a'):
return chr(x+ord(c0))
class counter(dict):
def __init__(self, *args):
super().__init__(args)
def add(self,x):
self.setdefault(x,0)
self[x] += 1
S = input()
L = deque()
for i in range(len(S)):
L.append(S[i])
Q = int(input())
rev = False
for _ in range(Q):
q = input()
if q[0]=='1':
rev = not rev
else:
_,f,c = q.split()
if rev==(f=='1'):
L.append(c)
else:
L.appendleft(c)
L = list(L)
if rev:
L = L[::-1]
print(''.join(L)) | def main():
s = input()
q = int(input())
is_fwd = True
before = ''
after = ''
for i in range(q):
fields = [i for i in input().split()]
t = int(fields[0])
if t == 1:
is_fwd = not is_fwd
elif t == 2:
f = int(fields[1])
c = fields[2]
if (f == 1) == is_fwd:
before += c
else:
after += c
res = before[::-1] + s + after
if is_fwd:
print(res)
else:
print(res[::-1])
main()
| 1 | 57,468,489,764,450 | null | 204 | 204 |
import sys
stdin = sys.stdin
def main():
N = int(stdin.readline().rstrip())
A = list(map(int,stdin.readline().split()))
mod = 10**9+7
ans = 0
for i in range(61):
bits = 0
for x in A:
if (x>>i)&1:
bits += 1
ans += ((bits*(N-bits))* 2**i) %mod
ans %= mod
print(ans)
main() | string = list(map(str, input()))
ans =[]
for char in string:
if char.islower():
ans.append(char.upper())
elif char.isupper():
ans.append(char.lower())
else:
ans.append(char)
print(ans[-1], end="")
print()
| 0 | null | 61,879,205,185,380 | 263 | 61 |
n = input()
x = len(n)
inf = 10 ** 9
#dp[i][flg]...i桁目まで、未満フラグ=1
dp = [[inf] * 2 for _ in range(x+1)]
dp[0][0] = 0
dp[0][1] = 1
for i in range(x):
s = int(n[i])
dp[i+1][0] = min(dp[i][0] + s, dp[i][1] + 10 - s)
dp[i+1][1] = min(dp[i][0] + s + 1, dp[i][1] + 9 - s)
print(dp[x][0])
| n = input()
n = n[::-1]
n += '0'
cnt = 0
dp = [[float('inf')] * 2 for _ in range(len(n) + 1)]
dp[0][0] = 0
dp[0][1] = 1
for i in range(len(n)):
a = int(n[i])
dp[i + 1][0] = min(dp[i][0] + a, dp[i][1] + a + 1)
dp[i + 1][1] = min(dp[i][0] + 10 - a, dp[i][1] + 10 - (a + 1))
print(min(dp[len(n)][0], dp[len(n)][1])) | 1 | 70,853,139,071,582 | null | 219 | 219 |
s = input()
if s.count('A') == 0 or s.count('B') == 0:
print('No')
else:
print('Yes') | N = int(input())
As = []
Bs = []
for _ in range(N):
c = 0
m = 0
for s in input():
if s == '(':
c += 1
elif s == ')':
c -= 1
m = min(m, c)
if c >= 0:
As.append((-m, c - m))
else:
Bs.append((-m, c - m))
As.sort(key=lambda x: x[0])
Bs.sort(key=lambda x: x[1], reverse=True)
f = True
c = 0
for (l, r) in As:
if c < l:
f = False
break
c += r - l
if f:
for (l, r) in Bs:
if c < l:
f = False
break
c += r - l
f = f and (c == 0)
if f:
print('Yes')
else:
print('No') | 0 | null | 38,988,091,873,910 | 201 | 152 |
A, B, C = map(int, input().split())
Z = A + B + C
if Z >= 22:
print("bust")
else:
print("win")
| a1, a2, a3 = map(int, input().split())
if a1 + a2 + a3 >= 22: print("bust")
else: print("win") | 1 | 118,766,064,864,992 | null | 260 | 260 |
# 貪欲+山登り(2点交換+1点更新)
import time
import random
d = int(input())
dd = d * (d + 1) // 2
*C, = map(int, input().split())
S = [list(map(int, input().split())) for i in range(d)]
# 貪欲法による初期解の構築
T = []
L = [-1 for j in range(26)]
for i in range(d):
max_diff = -10**7
arg_max = 0
for j in range(26):
memo = L[j]
L[j] = i
diff = S[i][j] - sum([C[k] * (i - L[k]) for k in range(26)])
if diff > max_diff:
max_diff = diff
arg_max = j
L[j] = memo
T.append(arg_max)
L[arg_max] = i
def calc_score(T):
L = [-1 for j in range(26)]
X = [0 for j in range(26)]
score = 0
for i in range(d):
score += S[i][T[i]]
X[T[i]] += (d - i) * (i - L[T[i]])
L[T[i]] = i
for j in range(26):
score -= C[j] * (dd - X[j])
return score
score = calc_score(T)
start = time.time()
while True:
now = time.time()
if now - start > 1.8:
break
# 1点更新
i = random.choice(range(d))
j = random.choice(range(26))
memo = T[i]
T[i] = j
new_score = calc_score(T)
T[i] = memo
if new_score > score:
T[i] = j
score = new_score
# 2点交換
i0 = random.choice(range(d))
z = random.choice(range(5))
i1 = i0 - z if i0 > z else i0 + z
T[i0], T[i1] = T[i1], T[i0]
new_score = calc_score(T)
T[i0], T[i1] = T[i1], T[i0]
if new_score > score:
T[i0], T[i1] = T[i1], T[i0]
score = new_score
for t in T:
print(t + 1)
| N = int(input())
R = []
for _ in range(N):
x, L = map(int, input().split())
R.append([x - L, x + L])
R.sort(key=lambda x: x[1])
ans = 1
for i in range(N):
if (i == 0):
first = R[0][1]
continue
if first <= R[i][0]:
first = R[i][1]
ans += 1
print(ans)
| 0 | null | 49,708,933,472,968 | 113 | 237 |
import sys
input = lambda: sys.stdin.readline().rstrip()
def solve():
A, B = map(int, input().split())
ans = max(0, A - 2 * B)
print(ans)
if __name__ == '__main__':
solve()
| #!/usr/bin/env python3
import sys
from itertools import chain
def solve(A: int, B: int):
answer = 6 - A - B
return answer
def main():
tokens = chain(*(line.split() for line in sys.stdin))
A = int(next(tokens)) # type: int
B = int(next(tokens)) # type: int
answer = solve(A, B)
print(answer)
if __name__ == "__main__":
main()
| 0 | null | 138,630,588,426,928 | 291 | 254 |
s = input()
t = input()
T = list(t)
sl = len(s)
tl = len(t)
ans = 10**18
for i in range((sl-tl)+1):
cnt = 0
S = list(s[i:i+tl])
for a,b in zip(S,T):
if a != b:
cnt += 1
if ans > cnt:
ans = cnt
print(ans) | s = input()
t = input()
numlist = []
for i in range(len(s)-len(t)+1):
a = s[i:i+len(t)]
count = 0
for j in range(len(t)):
if a[j] != t[j]:
count += 1
numlist.append(count)
print(min(numlist)) | 1 | 3,686,108,094,382 | null | 82 | 82 |
import itertools
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
R = [i+1 for i in range(N)]
RPS = sorted(list(itertools.permutations(R)))
print(abs(RPS.index(P)-RPS.index(Q))) | N, K = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(K)]
# dpの高速化 => 累積和によって、O(N)で解く
dp = [0] * N
acc = [0]* (N+1)
dp[0], acc[1] = 1, 1
# acc[0] = 0
# acc[1] = dp[0]
# acc[2] = dp[0] + dp[1]
# acc[n] = dp[0] + dp[1] + dp[n-1]
# dp[0] = acc[1] - acc[0]
# dp[1] = acc[2] - acc[1]
# dp[n-1] = acc[n] - acc[n-1]
mod = 998244353
for i in range(1, N):
# acc[i] = dp[0] + ... + dp[i-1] が既知
# 貰うdp
for j in range(K):
r = i - X[j][0]
l = i - X[j][1]
if r < 0: continue
l = max(l, 0)
dp[i] += acc[r+1] - acc[l] # s = dp[L] + ... + dp[R]
dp[i] %= mod
acc[i+1] = acc[i] + dp[i] # acc[i+1] = dp[0] + ... + dp[i]
print(dp[N-1]) | 0 | null | 51,692,782,160,580 | 246 | 74 |
N = int(input())
A = list(map(int, input().split()))
R = A[:]
for i in range(N - 1, -1, -1):
R[i] = R[i + 1] + A[i]
B = 1
ans = B
for i in range(1, N + 1):
M = 2 * B - A[i]
if M < 0:
ans = -1
break
B = min(M, max(0, R[i] - A[i]))
ans += A[i] + B
print(ans if A[0] == 0 or A[0] == 1 and len(A) == 1 else -1)
| L = float(input())
returnVal = (L/3)**3
print(returnVal) | 0 | null | 32,947,452,613,922 | 141 | 191 |
n = int(input())
a = [int(i) for i in input().split()]
k = 1 + n%2
dp = [[-float('inf')] * (k + 2) for i in range(n + 1)]
dp[0][0] = 0
for i in range(n):
for j in range(k + 1):
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j])
now = dp[i][j]
if (i + j) % 2 == 0:
now += a[i]
dp[i + 1][j] = max(dp[i + 1][j], now)
print(dp[n][k]) | import numpy as np
n = int(input())
a = list(map(int,input().split()))
dp = np.zeros((n+1,2), int)
dp[1],dp[2] = [0,a[0]], [0,max(a[0], a[1])]
for i in range(3,n+1):
if(i%2 == 0):
dp[i][0] = max(dp[i-1][0],dp[i-2][0]+a[i-1],dp[i-2][1])
dp[i][1] = max(dp[i-1][1],dp[i-2][1]+a[i-1])
else:
dp[i][0] = max(dp[i-1][1],dp[i-2][1],dp[i-2][0]+a[i-1])
dp[i][1] = dp[i-2][1]+a[i-1]
print(dp[n][(n+1)%2]) | 1 | 37,561,695,627,580 | null | 177 | 177 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.