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
|
---|---|---|---|---|---|---|
n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):a[i]*=-1
a.sort()
from bisect import bisect_left,bisect_right
def check(mid):
mm=0
for i in range(n):
if -(a[i]+a[0])<mid:break
mm+=bisect_right(a,-(mid+a[i]))
return mm
ok=0
ng=10**10+7
while ng!=ok+1:
mid=(ok+ng)//2
if check(mid)>=m:ok=mid
else:ng=mid
b=[0]
for i in a:b.append(b[-1]+i)
ans=0
for i in range(n):
if -(a[i]+a[0])<ok:break
ind=bisect_right(a,-(ok+a[i]))
ans+=a[i]*ind
ans+=b[ind]
print(-(ans+(check(ok)-m)*ok)) | n = int(input())
a = list(map(int, input().split()))
l = []
for i in range(n):
l.append([a[i], i+1])
l = sorted(l)
ans = []
for j in range(n):
ans.append(str(l[j][1]))
print(" ".join(ans)) | 0 | null | 144,409,641,252,330 | 252 | 299 |
X = int(input())
a = 100
for i in range(1, 100000):
a = a * 101 // 100
if a >= X:
print(i)
exit()
| 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():
x = ri()
steps = 0
bal = 100
while bal < x:
steps += 1
bal += bal // 100
print (steps)
mode = 's'
if mode == 'T':
t = ri()
for i in range(t):
solve()
else:
solve()
| 1 | 27,044,210,984,320 | null | 159 | 159 |
N, K = map(int, input().split())
count = 1
while N >= K:
N //= K
count +=1
print(count) | 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)
| 0 | null | 67,409,884,817,340 | 212 | 218 |
#!/usr/bin python3
# -*- coding: utf-8 -*-
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
#DP[i] = i までの魔法でモンスターの体力を減らすため消耗する魔力の最小値
dp = [0] * 20001
for i in range(h):
dp[i] = min(dp[i-a] + b for a, b in ab)
print(dp[h-1])
| from collections import defaultdict
(h,n),*ab = [list(map(int, s.split())) for s in open(0)]
mxa = max(a for a,b in ab)
dp = defaultdict(lambda: float('inf'))
dp[0] = 0
for i in range(1, h+mxa):
dp[i] = min(dp[i-a] + b for a,b in ab)
print(min(v for k,v in dp.items() if k>=h)) | 1 | 80,703,685,113,092 | null | 229 | 229 |
S = int(input())
h = S // 3600
m = S % 3600 // 60
s = S % 60
print(h, m, s, sep=':') | N = int(input())
X = input()
val = int(X,2)
C = X.count("1")
if C==1:
for i in range(N):
if X[i]=='1':
print(0)
elif i==N-1:
print(2)
else:
print(1)
exit()
# xをpopcountで割ったあまりに置き換える
def f(x):
if x==0: return 0
return 1 + f(x % bin(x).count("1"))
# 初回のpopcountでの割り方は、(C+1) or (C-1)
Y = val%(C+1)
if C-1 != 0:
Z = val%(C-1)
else:
Z = 0
for i in range(N):
if X[i] == "1":
if Z - 1 == 0:
print(0)
continue
k = (Z - pow(2,N-i-1,C-1)) % (C-1)
else:
k = (Y + pow(2,N-i-1,C+1)) % (C+1)
print(f(k)+1) | 0 | null | 4,325,033,826,340 | 37 | 107 |
def check(pt, brackets):
brackets.sort(reverse=True)
for m, t in brackets:
if pt + m < 0:
return -1
pt += t
return pt
n = int(input())
brackets_p = [] # (始めを0として、( = +1, ) = -1 として、最後はいくつか, 途中の最小値はいくつか)
brackets_m = []
pt = 0
mt = 0
for _ in range(n):
s = input()
total = 0
mini = 0
for c in s:
if c == '(':
total += 1
else:
total -= 1
mini = min(mini, total)
if total >= 0:
if mini == 0:
pt += total
else:
brackets_p.append((mini, total))
else:
total, mini = -total, mini - total
if mini == 0:
mt += total
else:
brackets_m.append((mini, total))
pt = check(pt, brackets_p)
mt = check(mt, brackets_m)
if (pt == -1) or (mt == -1) or (pt != mt):
print('No')
else:
print('Yes')
| from heapq import *
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
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 LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
def main():
n=II()
ss=[SI() for _ in range(n)]
ms1=[]
ms2=[]
for s in ss:
mn=0
now=0
for c in s:
if c=="(":now+=1
else:now-=1
if now<mn:mn=now
if now>0:ms1.append((mn,now))
else:ms2.append((mn-now,-now))
#print(ms1)
#print(ms2)
cnt=0
for mn,s in sorted(ms1,reverse=True):
if cnt+mn<0:
print("No")
exit()
cnt+=s
cnt2=0
for mn,s in sorted(ms2,reverse=True):
if cnt2+mn<0:
print("No")
exit()
cnt2+=s
if cnt==cnt2:print("Yes")
else:print("No")
main() | 1 | 23,556,858,393,320 | null | 152 | 152 |
import os, sys, re, math
A = [int(n) for n in input().split()]
print('win' if sum(A) <= 21 else 'bust')
| if sum(list(map(int, input().split()))) >= 22:
print("bust")
else:
print("win") | 1 | 118,487,515,708,890 | null | 260 | 260 |
n=int(input())
a=list(map(int,input().split()))
for i in a:
if i%2==0 and i%3!=0 and i%5!=0:
print("DENIED")
exit()
print("APPROVED") | N = int(input())
A = list(map(int, input().split()))
ans = 'DENIED'
for a in A:
if a%2 == 0:
if a%3 == 0 or a%5 == 0:
continue
else:
break
else:
ans = 'APPROVED'
print(ans) | 1 | 69,057,190,448,092 | null | 217 | 217 |
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
def readInts():
return list(map(int,input().split()))
def I():
return int(input())
h = I()
w = I()
n = I()
if h < w:
for i in range(1,h+1):
if i * w >= n:
print(i)
exit()
else:
for i in range(1,w+1):
if i*h >= n:
print(i)
exit()
| input()
a=1
d=1000000000000000000
for i in input().split():
a*=[int(i),1][(a>d)*(i!='0')]
print([a,-1][a>d]) | 0 | null | 52,254,966,569,632 | 236 | 134 |
a=int(input())
print(a//500*1000+a%500//5*5) | n,k=map(int,input().split())
h=list(map(int,input().split()))
if n<=k:
print(0)
exit()
h.sort()
if k==0:
print(sum(h))
else:
print(sum(h[:-k])) | 0 | null | 60,651,386,164,490 | 185 | 227 |
import sys
input = sys.stdin.readline
mod = 998244353
N, S = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
dp = [0] * (S+1)
dp[0] = pow(2, N, mod)
two_inv = pow(2, mod-2, mod)
for i, a in enumerate(A):
for j in range(a, S+1)[::-1]:
dp[j] = (dp[j] + dp[j-a] * two_inv) % mod
print(dp[S])
| 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() | 1 | 17,584,398,362,398 | null | 138 | 138 |
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"
input = sys.stdin.readline
########################################
ans = 0
n = int(input())
for i in range(1,n+1):
for j in range(1,n+1):
if i*j >= n:
break
ans+=1
print(ans)
'''
# Wrap solution for more recursion depth
#submit as python3
import collections,sys,threading
sys.setrecursionlimit(10**9)
threading.stack_size(10**8)
threading.Thread(target=solve).start()
'''
| n=int(input())
ans=0
for a in range(1,n):
x=(n-1)//a
ans+=x
print(ans)
| 1 | 2,619,804,137,036 | null | 73 | 73 |
from collections import defaultdict
N, K, *A = map(int, open(0).read().split())
x = [0] * (N + 1)
for i in range(N):
x[i + 1] = x[i] + A[i]
y = [(x[i] - i) % K for i in range(N + 1)]
ctr = defaultdict(int)
ans = 0
for j in range(N + 1):
ans += ctr[y[j]]
ctr[y[j]] += 1
if j - K + 1 >= 0:
ctr[y[j - K + 1]] -= 1
print(ans)
| #!/usr/bin/env python3
import sys
from collections import Counter
input = sys.stdin.readline
INF = 10**9
n, k = [int(item) for item in input().split()]
a = [int(item) - 1 for item in input().split()]
cumsum = [0] * (n + 1)
for i in range(n):
cumsum[i+1] = cumsum[i] + a[i]
cumsum[i+1] %= k
ls = list(set(cumsum))
dic = dict()
for i, item in enumerate(ls):
dic[item] = i
cnt = [0] * (n + 10)
num = 0
ans = 0
for i, item in enumerate(cumsum):
index = dic[item]
ans += cnt[index]
cnt[index] += 1
num += 1
if num >= k:
left = cumsum[i - k + 1]
index = dic[left]
if cnt[index] > 0:
cnt[index] -= 1
num -= 1
print(ans) | 1 | 137,267,897,948,132 | null | 273 | 273 |
n, m, l = map(int, raw_input().split())
matrix_a = []
matrix_b = []
for i in range(n):
line = map(int, raw_input().split())
matrix_a.append(line)
for i in range(m):
line = map(int, raw_input().split())
matrix_b.append(line)
for i in range(n):
result = []
for j in range(l):
tmp = 0
for k in range(m):
tmp += matrix_a[i][k] * matrix_b[k][j]
result.append(tmp)
print " ".join(map(str, result)) | f = open(0)
N, M, L = map(int, f.readline().split())
A = [list(map(int, f.readline().split())) for i in range(N)]
B = [list(map(int, f.readline().split())) for i in range(M)]
C = [[0]*L for i in range(N)]
for i in range(N):
for j in range(L):
C[i][j] = str(sum(A[i][k]*B[k][j] for k in range(M)))
for line in C:
print(*line)
| 1 | 1,412,556,569,100 | null | 60 | 60 |
A,B,M=map(int,input().split())
*a,=map(int,input().split())
*b,=map(int,input().split())
xyc = [tuple(map(int,input().split())) for _ in range(M)]
ans = min(a)+min(b)
for i in range(M):
x,y,c=xyc[i]
ans = min(ans,a[x-1]+b[y-1]-c)
print(ans) | N = int(input())
S = list(map(int,input().split()))
t = 10**18
ans = 1
if 0 in S:
print(0)
exit(0)
for n in S:
ans *= n
if ans > t:
print(-1)
exit(0)
print(ans) | 0 | null | 34,975,339,719,402 | 200 | 134 |
import sys
input = sys.stdin.readline
from collections import defaultdict
def main():
N, M = map(int, input().split())
passed = set([])
penalty = defaultdict(int)
for _ in range(M):
p, S = input().split()
if S == "WA" and p not in passed:
penalty[p] += 1
elif S == "AC":
passed.add(p)
ans = sum([penalty[p] for p in passed])
print(len(passed), ans)
if __name__ == '__main__':
main()
| n,m = map(int,input().split())
memo2 = [False for i in range(n)]
memo = [0 for i in range(n)]
count1,count2 = 0,0
for i in range(m):
p,l = input().split()
p = int(p)-1
if memo2[p]:
continue
else:
if l == 'WA':
memo[p]+=1
else:
memo2[p] = True
count2 += 1
count1+=memo[p]
print(count2,count1) | 1 | 93,896,433,448,350 | null | 240 | 240 |
while True:
a, b, c = map(int, input().split())
if a == -1 and b == -1 and c == -1:
break
if a == -1 or b == -1 or a + b < 30:
print("F")
elif a + b >= 80:
print("A")
elif a + b >= 65:
print("B")
elif a + b >= 50 or c >= 50:
print("C")
else:
print("D")
| import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
global current_time
global visited,go_time,back_time
global G
def dfs(node_id):
global current_time #書かないとローカル変数扱いされる
go_time[node_id] = current_time
current_time += 1
for next_node in G[node_id]:
if visited[next_node] == True:
continue
visited[next_node] = True
dfs(next_node)
back_time[node_id] = current_time
current_time += 1
V = int(input())
G = [[] for i in range(V)]
visited = [False]*V
go_time = [0]*V
back_time = [0]*V
for loop in range(V):
node_id,num,*tmp_adj = list(map(int,input().split()))
node_id -= 1
for i in range(num):
G[node_id].append(tmp_adj[i]-1)
current_time = 1;
for i in range(V):
if visited[i] == True:
continue
visited[i] = True
dfs(i)
for i in range(V):
print("%d %d %d"%(i+1,go_time[i],back_time[i]))
| 0 | null | 601,424,546,452 | 57 | 8 |
n = int(input())
lst = []
while n % 2 == 0:
lst.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
lst.append(f)
n //= f
else:
f += 2
if n != 1:
lst.append(n)
#print(lst)
count = 0
while lst:
s = 0
i = 1
num = lst[0]
for ele in lst:
if ele == num:
s += 1
for j in range(s):
lst.remove(num)
while s > 0:
s -= i
i += 1
if s >= 0:
count += 1
#print(lst)
print(count) | from math import gcd as g
a, b = map(int, input().split())
print((a*b)//g(a,b)) | 0 | null | 64,965,517,781,990 | 136 | 256 |
def sep():
return map(int,input().strip().split(" "))
def lis():
return list(sep())
n,m,k=sep()
a=lis()
b=lis()
from bisect import bisect_right
a_c=[a[0]]
b_c=[b[0]]
for i in range(1,n):
a_c.append(a_c[-1]+ a[i])
for i in range(1,m):
b_c.append(b_c[-1] + b[i])
m=-1
m=max(m,bisect_right(b_c,k))
for i in range(n):
if a_c[i]<=k:
t=k-a_c[i]
t2=bisect_right(b_c,t)
m=max(i+1+t2,m)
else:
break
print(max(0,m))
| import sys
N, M, K = [int(s) for s in sys.stdin.readline().split()]
n = 0
A = [0]
for s in sys.stdin.readline().split():
n = n + int(s)
A.append(n)
n = 0
B = [0]
for s in sys.stdin.readline().split():
n = n + int(s)
B.append(n)
ans = 0
for i in range(N + 1):
if A[i] > K:
break
for j in range(M, -1, -1):
if A[i] + B[j] <= K:
ans = max(ans, i + j)
M = j
break
print(ans) | 1 | 10,747,266,003,372 | null | 117 | 117 |
import sys
def dfs(u):
global time
color[u] = "GRAY"
time += 1
d[u] = time
for v in range(n):
if M[u][v] and color[v] == "WHITE":
dfs(v)
color[u] = "BLACK"
time += 1
f[u] = time
if __name__ == "__main__":
n = int(sys.stdin.readline())
color = ["WHITE"] * n
time = 0
d = [-1] * n
f = [-1] * n
M = [[0] * n for i in range(n)]
for inp in sys.stdin.readlines():
inp = list(map(int, inp.split()))
for i in inp[2:]:
M[inp[0]-1][i-1] = 1
for i in range(n):
if d[i] == -1:
dfs(i)
for i in range(n):
print(i+1, d[i], f[i]) | T = [0]
def curserch(N,k,T,P,n):
T[0] = T[0]+1
P[k]["d"] = T[0]
for i in range(1,n+1):
if N[k][i]==1 and P[i]["d"]==0:
curserch(N,i,T,P,n)
T[0] = T[0]+1
P[i]["f"]=T[0]
n = int(input())
A = [[0 for j in range(n+1)] for i in range(n+1)]
for i in range(n):
vec = input().split()
u = int(vec[0])
k = int(vec[1])
nodes = vec[2:]
for i in range(int(k)):
v = int(nodes[i])
A[u][v] = 1
P=[{"d":0} for i in range(n+1)]
for i in range(1,n+1):
if P[i]["d"]==0:
curserch(A,i,T,P,n)
T[0] = T[0]+1
P[i]["f"]=T[0]
for i in range(1,n+1):
print(i,P[i]["d"],P[i]["f"]) | 1 | 2,811,737,280 | null | 8 | 8 |
N, K = map(int, input().split())
A = list(map(int, input().split()))
result = []
for i in range(K, N):
if A[i] > A[i - K]:
result.append('Yes')
else:
result.append('No')
print(*result, sep='\n') | n,k=map(int,input().split())
a=list(map(int,input().split()))
cnt=0
for i in range(n-k):
if a[cnt]<a[cnt+k]:
print("Yes")
else:
print("No")
cnt+=1
| 1 | 7,177,923,972,768 | null | 102 | 102 |
import sys
a = []
b = []
for i in sys.stdin:
ta, tb = i.split()
a.append(int(ta))
b.append(int(tb))
for i in range(len(a)):
print len(str(a[i]+b[i])) | N,K=map(int,input().split())
ans=0
mod=10**9+7
A=[0 for i in range(K)]
for i in range(K,0,-1):
l=pow(K//i,N,mod)
a=2
while a*i<=K:
l-=A[a*i-1]
a+=1
ans+=l*i%mod
ans%=mod
A[i-1]=l
print(ans) | 0 | null | 18,383,101,562,110 | 3 | 176 |
def gcd_e(x, y):
if y == 0:
return x
else:
return gcd_e(y,x%y)
def lcm(x, y):
return (x * y) // gcd_e(x, y)
n,m=list(map(int,input().split()))
A=list(map(int,input().split()))
a,b=A[0],0
for i in range(1,n):
b = A[i]
a = lcm(a,b)
for i in set(A):
if (a // i) % 2 == 0:
print('0')
exit()
if a // 2 > m:
print('0')
else:
print((m-a//2)//a+1) | import sys
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
inf = 10**17
mod = 10**9+7
# グリッドBFS
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
dy_dx = [[1,0],[0,1],[-1,0],[0,-1]]
ans = 0
for i in range(h):
for j in range(w):
if s[i][j] == '#': continue
dis = [[-1 for k in range(w)] for k in range(h)]
dis[i][j] = 0
d = deque()
d.append([i, j])
while len(d):
now = d.popleft()
y = now[0]
x = now[1]
for k in range(4):
ny = y + dy_dx[k][0]
nx = x + dy_dx[k][1]
if 0 <= ny < h and 0 <= nx < w:
if s[ny][nx] != '#' and dis[ny][nx] == -1:
dis[ny][nx] = dis[y][x] + 1
ans = max([ans, dis[ny][nx]])
d.append([ny, nx])
print(ans)
| 0 | null | 98,457,017,950,944 | 247 | 241 |
import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
N=I()
A=LI()
A.sort()
flag=1
for i in range(N-1):
if A[i]==A[i+1]:
flag=0
break
if flag:
print("YES")
else:
print("NO")
main()
| n = int(input())
a = set(map(int, input().split()))
print('YES' if len(a) == n else 'NO') | 1 | 73,945,979,575,316 | null | 222 | 222 |
n = int(input())
a = list(map(int, input().split()))
min_a = min(a)
max_a = max(a)
sum_a = sum(a)
print(min_a, max_a, sum_a) | n = input()
lis = map(int, raw_input().split())
mn = lis[0]
mx = lis[0]
for t in lis:
if mn > t:
mn = t
if mx < t:
mx = t
print mn, mx, sum(lis) | 1 | 721,659,494,052 | null | 48 | 48 |
def bubbleSort(a,n):
flag = 1
count = 0
while flag:
flag = 0
for j in range(n-1,0,-1):
if a[j] < a[j-1]:
count += 1
w = a[j]
a[j] = a[j-1]
a[j-1] = w
flag = 1
print(' '.join(map(str, a)))
print(count)
n = int(input())
a = list(map(int, input().split()))
bubbleSort(a,n)
| N,S = map(int,input().split())
*A, = map(int,input().split())
A.sort()
MOD = 998244353
dp = [[0]*(S+1) for _ in [0]*(N+1)]
dp[0][0] = 1
for i,a in enumerate(A):
for s in range(S+1):
dp[i+1][s] = dp[i][s]*2
if s-a>=0:
dp[i+1][s] += dp[i][s-a]
dp[i+1][s] %= MOD
print(dp[-1][S]) | 0 | null | 8,868,807,925,380 | 14 | 138 |
n = int(input())
dp = [1, 1]
for i in range(2, n + 1):
dp = [dp[-1], dp[-2] + dp[-1]]
print(dp[-1])
| n = int(input())
dp = [0 for _ in range(46)]
dp[0] = 1
dp[1] = 1
for i in range(2, 46):
dp[i] = dp[i-1] + dp[i-2]
print(dp[n])
| 1 | 1,840,762,878 | null | 7 | 7 |
import sys
input = sys.stdin.readline
from collections import *
N, P = map(int, input().split())
S = input()[:-1]
if P in [2, 5]:
ans = 0
for i in range(N):
if int(S[i])%P==0:
ans += i+1
print(ans)
exit()
cnt = defaultdict(int)
cnt[0] = 1
now = 0
ans = 0
for i in range(N-1, -1, -1):
now = (int(S[i])*pow(10, N-1-i, P)+now)%P
ans += cnt[now]
cnt[now] += 1
print(ans) | def main():
N,P = map(int,input().split())
S = [int(s) for s in list(input().strip())][::-1]
num = 0
ans = 0
if P == 2 or P == 5:
for i in range(N):
if S[i]%P == 0:
ans += N-i
print(ans)
return
L = [0]*P
L[0]=1
t = 0
s = 1
for z in S:
t = (z*s+t)%P
L[t]+=1
s=s*10%P
for l in L:
ans += l * (l - 1) // 2
print(ans)
if __name__ == '__main__':
main()
| 1 | 58,050,074,316,000 | null | 205 | 205 |
# coding: utf-8
def main():
n = int(input())
a_list = list(map(int, input().split()))
a_sum = sum(a_list)
ans = 0
for i in range(n-1):
a_head = a_list[i]
a_sum -= a_head
ans += a_head * a_sum
print(ans % (10**9 + 7))
main() | n = int( input().rstrip())
numbers = list( map(int, input().rstrip().split(" ")) )
total = sum(numbers)
m = 10 ** 9 + 7
result = 0
for number in numbers[:-1]:
total -= number
result += (total * number)
result %= m
print(result) | 1 | 3,829,097,292,132 | null | 83 | 83 |
#coding:utf-8
n = int(input())
numbers = list(map(int, input().split()))
count = 0
for i in range(n-1):
for j in range(n-1, i, -1):
if numbers[j] < numbers[j-1]:
numbers[j], numbers[j-1] = numbers[j-1], numbers[j]
count += 1
print(*numbers)
print(count) | a=str(input())
b=''
for i in range(len(a)):
if a[i].isupper():
b+=a[i].lower()
elif a[i].islower:
b+=a[i].upper()
print(b)
| 0 | null | 773,765,765,380 | 14 | 61 |
# -*- coding: utf-8 -*-
n = input()
a = map(int, raw_input().split())
max = a[0]
min = a[0]
sum = 0
for i in range(n):
if a[i] > max:
max = a[i]
elif a[i] < min:
min = a[i]
else:
pass
sum += a[i]
print "%d %d %d" %(min, max, sum) | import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()
def main():
h,w=LI()
l=[]
l.append('.'*(w+1))
for _ in range(h):
x='.'
x+=S()
l.append(x)
dp=[[inf]*(w+10) for _ in range(h+10)]
if l[1][1]=='#':
dp[1][1]=1
else:
dp[1][1]=0
for i in range(1,h+1):
for j in range(1,w+1):
if i==1 and j==1:
continue
if l[i][j]=='#':
if l[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 l[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])
else:
dp[i][j]=min(dp[i-1][j],dp[i][j-1])
# print(dp)
return dp[h][w]
# main()
print(main())
| 0 | null | 24,950,541,504,080 | 48 | 194 |
s,w = map(int,input().split())
print("unsafe" if w>=s else "safe") | input_line = input().split(" ")
S = int(input_line[0])
W = int(input_line[1])
if S > W:
print("safe")
else:
print("unsafe") | 1 | 29,085,750,438,052 | null | 163 | 163 |
n=list(map(int,input().strip().split()))
m=list(map(int,input().strip().split()))
for i in range(n[0]-n[1]):
if(m[i+n[1]]>m[i]):
print("Yes")
else:
print("No") | def main():
N,K=map(int,input().split())
A=[0]+list(map(int,input().split()))
for i in range(K+1,N+1):
if A[i]>A[i-K]:
print("Yes")
else:
print("No")
if __name__=='__main__':
main() | 1 | 7,095,464,800,930 | null | 102 | 102 |
s = input()
n = len(s) // 2
j = -1
t = 0
for i in range(n):
if s[i] != s[j]:
t += 1
j -= 1
print(t) | n = input()
num = len(n) // 2
ans = 0
for i in range(num):
if n[i] != n[len(n)-1-i]:
ans += 1
print(ans)
| 1 | 120,049,282,537,792 | null | 261 | 261 |
def main():
a, v = map(int, input().split())
b, w =map(int, input().split())
t = int(input())
distance = abs(b-a)
speed = v-w
if distance > speed*t:
print('NO')
else:
print('YES')
main() | a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if v <= w:
print('NO')
elif (abs(a-b) / (v-w)) <= t:
print('YES')
else:
print('NO') | 1 | 15,170,087,390,080 | null | 131 | 131 |
N=int(input())
s,t=[],[]
for i in range(N):
S,T=input().split()
s.append(S)
t.append(int(T))
X=input()
xs=s.index(X)
print(sum(t[xs:])-t[xs]) | from collections import deque
N = int(input())
K = 0
Ans = [0] * (N-1)
Edge = [[] for _ in range(N)]
for _ in range(N-1):
a, b = map(int, input().split())
a -= 1
b -= 1
Edge[a].append((b, _))
Edge[b].append((a, _))
Q = deque()
Q.append((0, 0))
P = [-1] * N
while Q:
now, color = Q.popleft()
cnt = 1
for nex, num in Edge[now]:
if cnt == color:
cnt += 1
if nex == P[now]:
continue
if Ans[num] != 0:
continue
Q.append((nex, cnt))
Ans[num] = cnt
K = max(cnt, K)
cnt += 1
print(K)
for a in Ans:
print(a) | 0 | null | 115,863,729,277,990 | 243 | 272 |
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_C
# Stable Sort
# Result:
# Modifications
# - modify inner loop start value of bubble_sort
# This was the cause of the previous wrong answer.
# - improve performance of is_stable function
import sys
ary_len = int(sys.stdin.readline())
ary_str = sys.stdin.readline().rstrip().split(' ')
ary = map(lambda s: (int(s[1]), s), ary_str)
# a is an array of tupples whose format is like (4, 'C4').
def bubble_sort(a):
a_len = len(a)
for i in range(0, a_len):
for j in reversed(range(i + 1, a_len)):
if a[j][0] < a[j - 1][0]:
v = a[j]
a[j] = a[j - 1]
a[j - 1] = v
# a is an array of tupples whose format is like (4, 'C4').
def selection_sort(a):
a_len = len(a)
for i in range(0, a_len):
minj = i;
for j in range(i, a_len):
if a[j][0] < a[minj][0]:
minj = j
if minj != i:
v = a[i]
a[i] = a[minj]
a[minj] = v
def print_ary(a):
vals = map(lambda s: s[1], a)
print ' '.join(vals)
def is_stable(before, after):
length = len(before)
for i in range(0, length):
for j in range(i + 1, length):
if before[i][0] == before[j][0]:
v1 = before[i][1]
v2 = before[j][1]
for k in range(0, length):
if after[k][1] == v1:
v1_idx_after = k
break
for k in range(0, length):
if after[k][1] == v2:
v2_idx_after = k
break
if v1_idx_after > v2_idx_after:
return False
return True
def run_sort(ary, sort_fn):
ary1 = list(ary)
sort_fn(ary1)
print_ary(ary1)
if is_stable(ary, ary1):
print 'Stable'
else:
print 'Not stable'
### main
run_sort(ary, bubble_sort)
run_sort(ary, selection_sort) | N, K = list(map(int, input().split()))
pt = list(map(int, input().split()))
T = input()
pc_hand = [0]*N
my_hand = [0]*N
for i in range(N):
if T[i] == 'r':
pc_hand[i] = 0
elif T[i] == 's':
pc_hand[i] = 1
else:
pc_hand[i] = 2
point = 0
for i in range(N):
if i >= K and T[i] == T[i - K] and (my_hand[i - K] + 1) % 3 == pc_hand[i - K]:
my_hand[i] = pc_hand[i]
else:
my_hand[i] = (pc_hand[i] - 1) % 3
point += pt[my_hand[i]]
print(point) | 0 | null | 53,590,663,685,218 | 16 | 251 |
r=float(input())
a=r*r*(3.141592653589)
b=(r+r)*(3.141592653589)
print(f"{a:.6f} {b:.6f}")
| # encoding:utf-8
import math
r = float(input())
area = r**2*math.pi
circumference = r * 2 * math.pi
area = ('%03.6f' % area)
circumference = ('%03.6f' % circumference)
print(area),
print(circumference) | 1 | 636,570,483,220 | null | 46 | 46 |
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if a == b:
print('YES')
elif a < b:
if b + w * t <= a + v * t:
print('YES')
else:
print('NO')
else:
if a - v * t <= b - w * t:
print('YES')
else:
print('NO')
| n = int(input())
A = [0] * (n + 1)
for i in range(1, n + 1):
for j in range(i, n + 1, i):
A[j] += 1
print(sum(i * A[i] for i in range(1, n + 1))) | 0 | null | 13,133,576,854,528 | 131 | 118 |
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split())
B1,B2 = map(int,input().split())
if T1*A1+T2*A2==T1*B1+T2*B2:
cnt="infinity"
elif T1*A1+T2*A2>T1*B1+T2*B2:
L = T1*(B1-A1)
d = T1*A1+T2*A2-(T1*B1+T2*B2)
if L<0:
cnt = 0
elif L==0:
cnt = 1
else:
cnt = 1
n = L//d
r = L%d
if r>0:
cnt += 2*n
else:
cnt += 2*(n-1)+1
elif T1*A1+T2*A2<T1*B1+T2*B2:
L = T1*(A1-B1)
d = (T1*B1+T2*B2)-(T1*A1+T2*A2)
if L<0:
cnt = 0
elif L==0:
cnt = 1
else:
cnt = 1
n = L//d
r = L%d
if r>0:
cnt += 2*n
else:
cnt += 2*(n-1)+1
print(cnt) | T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
Ax = A1 * T1 + A2 * T2
Bx = B1 * T1 + B2 * T2
diff = abs(Ax - Bx)
if diff == 0:
print('infinity')
exit()
if not ((A1 * T1 > B1 * T1 and Ax < Bx) or (A1 * T1 < B1 * T1 and Ax > Bx)):
print(0)
exit()
ans = 2 * ((abs(B1 - A1) * T1) // diff)
if (abs(B1 - A1) * T1) % diff != 0:
ans += 1
print(ans)
| 1 | 130,999,178,081,120 | null | 269 | 269 |
A, B, C, D = list(map(int, input().split()))
a = A // D
b = C // B
N = max(a, b) + 1
for i in range(N):
if C > 0:
C -= B
if C <= 0:
break
if A > 0:
A -= D
if A <= 0:
break
ans = "No"
if A > C:
ans = "Yes"
print(ans) | MON = list(map(int,input().split()))
while 1:
MON[2] = MON[2] - MON[1]
if(MON[2] <= 0):
print("Yes")
break
MON[0] = MON[0] - MON[3]
if (MON[0] <= 0 ):
print("No")
break | 1 | 29,551,126,135,230 | null | 164 | 164 |
n = int(input())
ans = 100000
# ans += (n*(100000*0.05))
for i in range(n):
ans *= 1.05
if ans % 1000 > 0:
ans = ans // 1000 * 1000 + 1000
print(int(ans))
| import sys, math
for line in sys.stdin.readlines():
line = line.strip()
n = int(line)
value = 100000.0
for week in xrange(n):
value = value * 1.05
value = math.ceil(value / 1000) * 1000
print int(value) | 1 | 1,076,421,292 | null | 6 | 6 |
n, k = map(int, input().split())
k = min(k, n - 1)
MOD = 1000000007
fact = [1] * (n + 1)
ifact = [0] * (n + 1)
for i in range(1, n + 1):
fact[i] = fact[i - 1] * i % MOD
ifact[n] = pow(fact[n], MOD - 2, MOD)
for i in range(n, 0, -1):
ifact[i - 1] = ifact[i] * i % MOD
def comb(n, k):
if k < 0 or k > n:
return 0
return fact[n] * ifact[k] * ifact[n - k] % MOD
ans = 0
for i in range(k + 1):
ans += comb(n, i) * comb(n - 1, i)
ans %= MOD
print(ans)
| n, k, s = map(int, input().split())
ans = []
for i in range(k):
ans.append(s)
if s == pow(10, 9):
s = 0
for j in range(k, n):
ans.append(s+1)
print(' '.join(list(map(str, ans)))) | 0 | null | 78,986,367,655,260 | 215 | 238 |
n = int(input())
num = list(map(int,input().split()))
ans = 0
m = num[0]
for i in range(1,n):
if m >= num[i]:
ans += m - num[i]
else:
m = num[i]
print(ans) | from math import gcd
n = int(input())
s = list(map(int, input().split()))
s.sort()
dp = [0] * ((10 ** 6) + 100)
res = s[0]
for ss in s:
dp[ss] += 1
res = gcd(res, ss)
A = max(s)
pairwise = True
setwise = (res == 1)
primes = set(range(2, A+1))
for i in range(2, int(A**0.5+1)):
if i not in primes:
i += 1
else:
ran = range(i*2, A+1,i)
primes.difference_update(ran)
primes = list(primes)
for i in primes:
cnt = 0
for j in range(i, A + 1, i):
cnt += dp[j]
if cnt > 1:
pairwise = False
break
if pairwise:
print("pairwise coprime")
elif setwise:
print("setwise coprime")
else:
print("not coprime")
| 0 | null | 4,349,820,266,052 | 88 | 85 |
import sys
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
n, r = ISI()
if n<10:
r+=100*(10-n)
print(r)
| N, R = map(int, input().split())
print(R if N > 9 else R + 100*(10 - N))
| 1 | 63,472,340,482,692 | null | 211 | 211 |
def main():
import sys
K=int(sys.stdin.readline())
print('ACL'*K)
main() | k = int(input())
str = ''
for _ in range(k):
str += 'ACL'
print(str) | 1 | 2,153,157,106,396 | null | 69 | 69 |
import numpy as np
H, W, M = map(int, input().split())
col = np.zeros(H)
row = np.zeros(W)
memo = []
for i in range(M):
h, w = map(int, input().split())
h -= 1
w -= 1
col[h] += 1
row[w] += 1
memo.append((h,w))
col_max = col.max()
row_max = row.max()
col_max_indexes = np.where(col == col_max)[0]
row_max_indexes = np.where(row == row_max)[0]
ans = col_max + row_max - 1
memo = set(memo)
for c in col_max_indexes:
for r in row_max_indexes:
if (c,r) not in memo:
ans = col_max + row_max
print(int(ans))
exit()
print(int(ans)) | ########### E
H, W, M = map(int, input().split())
bombs = []
for _ in range(M):
bomb = tuple(map(lambda x:int(x)-1, input().split()))
bombs.append(bomb)
H_list = [0]*H
W_list = [0]*W
for h,w in bombs:
H_list[h] += 1
W_list[w] += 1
maxX = max(H_list)
maxY = max(W_list)
max_H = [i for i,k in enumerate(H_list) if k == maxX]
max_W = [i for i,k in enumerate(W_list) if k == maxY]
bombs = set(bombs)
for i in max_H:
for k in max_W:
if (i,k) not in bombs:
print(maxX + maxY)
exit()
print(maxX + maxY -1) | 1 | 4,751,706,068,644 | null | 89 | 89 |
n=int(input())
a=list(map(int,input().split()))
c=0;b=1;i=0
while b:
b=0
for j in range(0,n-i-1):
if a[j]>a[j+1]:a[j],a[j+1]=a[j+1],a[j];b=1;c+=1
i+=1
print(*a)
print(c)
| def bubblesort(N, A):
"""Do BubbleSort"""
m = 0
flag = True
while(flag):
flag = False
for i in range(N-1, 0, -1):
if (A[i-1] > A[i]):
tmp = A[i-1]
A[i-1] = A[i]
m += 1
A[i] = tmp
flag = True
b = list(map(str, A))
print(" ".join(b))
print(m)
A = []
N = int(input())
s = input()
A = list(map(int, s.split()))
bubblesort(N, A) | 1 | 17,468,842,700 | null | 14 | 14 |
p1 , s1=map(int , input().split())
p2 , s2=map(int , input().split())
t=int(input())
if abs(p1-p2) > t*(s1-s2):
print("NO")
else:
print("YES") | def solve(a, v, b, w, t):
return "YES" if 0 < (v-w) and abs(b-a) / (v-w) <= t else "NO"
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
print(solve(a, v, b, w, t)) | 1 | 15,116,987,290,250 | null | 131 | 131 |
import itertools
n = int(input())
S = list(input())
L = [k for k, v in itertools.groupby(S)]
print(len(L)) | class Dice:
def __init__(self, men):
self.men = men
def throw(self, direction):
if direction == "E":
pmen = men[:]
men[0] = pmen[3]
men[1] = pmen[1]
men[2] = pmen[0]
men[3] = pmen[5]
men[4] = pmen[4]
men[5] = pmen[2]
elif direction == "W":
pmen = men[:]
men[0] = pmen[2]
men[1] = pmen[1]
men[2] = pmen[5]
men[3] = pmen[0]
men[4] = pmen[4]
men[5] = pmen[3]
elif direction == "S":
pmen = men[:]
men[0] = pmen[4]
men[1] = pmen[0]
men[2] = pmen[2]
men[3] = pmen[3]
men[4] = pmen[5]
men[5] = pmen[1]
elif direction == "N":
pmen = men[:]
men[0] = pmen[1]
men[1] = pmen[5]
men[2] = pmen[2]
men[3] = pmen[3]
men[4] = pmen[0]
men[5] = pmen[4]
def printUe(self):
print (self.men)[0]
def printMen(self):
print self.men
men = map(int, (raw_input()).split(" "))
d = Dice(men)
S = raw_input()
for s in S:
d.throw(s)
d.printUe() | 0 | null | 85,007,380,119,112 | 293 | 33 |
K = int(input())
ans = -1
keep = 0
check = 7
for i in range(K):
keep = (keep + check) % K
if keep == 0:
ans = i + 1
break
check = (check * 10) % K
print(ans) | k = int(input())
a = 7%k
flag = False
for i in range(k):
if a == 0:
flag = True
ans = i+1
break
a = (10*a+7)%k
if flag:
print(ans)
else:
print(-1) | 1 | 6,085,423,366,598 | null | 97 | 97 |
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
a,b = MI()
c,d = MI()
print(1 if d == 1 else 0)
| D1 = list(int(i) for i in input().split())
D2 = list(int(i) for i in input().split())
if D1[1] < D2[1]:
print(0)
else:
print(1) | 1 | 124,321,176,328,132 | null | 264 | 264 |
S = list(input())
# ><は0でいいのか
# 同様に S[0]==<とS[-1]==>も0でいい
# 制約的にNlogNくらいまでは十分許容範囲だし><は0で埋めてindex保持、そこから単調増加で組むのが良さそう?
# 3回ループさせる形で実装してみる
tmp = [-1] * (len(S) + 1)
for i in range(len(S) - 1):
if S[i] == ">" and S[i + 1] == "<":
tmp[i + 1] = 0
if S[0] == "<":
tmp[0] = 0
if S[-1] == ">":
tmp[-1] = 0
for i in range(len(S)):
if S[i] == "<":
tmp[i + 1] = tmp[i] + 1
for i in range(len(S) - 1, -1, -1):
if S[i] == ">":
tmp[i] = max(tmp[i], tmp[i + 1] + 1)
print(sum(tmp))
| #import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline
def main():
n=int(input())
ans=0
for i in range(1,n):
if (i!=n-i and i<n-i):
ans+=1
elif i>n-1:
break
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 155,303,378,775,850 | 285 | 283 |
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
N,K,S = MI()
if S == 10**9:
ANS = [10**9]*K + [1]*(N-K)
else:
ANS = [S]*K + [10**9]*(N-K)
print(*ANS)
| N, K, S = map(int, input().split())
L = []
if (S < 10**9):
for i in range(K):
L.append(str(S))
for i in range(N - K):
L.append(str(S + 1))
elif (S == 10 ** 9):
for i in range(K):
L.append(str(S))
for i in range(N - K):
L.append(str(1))
print(' '.join(L))
| 1 | 91,056,518,402,310 | null | 238 | 238 |
words = input()
if words[-1] != "s":
words += "s"
else:
words += "es"
print(words)
| S = input()
if(S[len(S)-1] == 's'):print(S + 'es')
else :print(S + 's') | 1 | 2,361,550,952,762 | null | 71 | 71 |
import math
n = int(input())
ten_counter = 0
exp_index = math.log(10 ** 18, 5)
if n % 2 == 0:
n //= 2
# rangeの範囲をlogとったら if: break 不要
for i in range(1, int(exp_index) + 1):
if n // (5 ** i) == 0:
break
else:
ten_counter += n // (5 ** i)
# else:
# print("finish")
else:
pass
print(ten_counter) | def max_exponent(a, n):
# calculate k s.t. a**k <= n < a**(k+1)
ret, v = 0, 1
while a * v <= n:
ret += 1
v *= a
return ret
def main():
N = int(input())
if N % 2 == 1:
print(0)
return
# N is even
count_5_in_even, pow_5 = 0, 5
for k in range(1, max_exponent(5, N) + 1):
count_5_in_even += (N // pow_5) // 2
pow_5 *= 5
count_2_in_even, pow_2 = 0, 2
for k in range(1, max_exponent(2, N) + 1):
count_2_in_even += N // k
pow_2 *= 2
print(min(count_5_in_even, count_2_in_even))
if __name__ == '__main__':
main() | 1 | 116,537,883,196,294 | null | 258 | 258 |
cnt = 0
for i in range(int(input())):
c_num = int(input())
if cnt == 0:
r_min = c_num
elif cnt == 1:
p_max = c_num - r_min
if c_num < r_min:
r_min = c_num
else:
if p_max < c_num - r_min:
p_max = c_num - r_min
if c_num < r_min:
r_min = c_num
cnt += 1
print(p_max)
| N = int(input())
R = [int(input()) for _ in range(N)]
maxv = -2000000000
minv = R[0]
for i in range(1,N):
maxv = max([maxv, R[i] - minv ])
minv = min([minv, R[i]])
print(maxv)
| 1 | 13,334,619,482 | null | 13 | 13 |
#!/usr/bin/env python3
import sys
from itertools import chain
def solve(N: int, K: int, H: "List[int]"):
H = sorted(H, reverse=True)
return sum(H[K:])
def main():
tokens = chain(*(line.split() for line in sys.stdin))
N = int(next(tokens)) # type: int
K = int(next(tokens)) # type: int
H = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
answer = solve(N, K, H)
print(answer)
if __name__ == "__main__":
main()
| n,k=map(int,input().split())
a=list(map(int,input().split()))
if n<=k:
print(0)
else:
a=sorted(a)
b=n-k
ans=0
for x in range(n-k):
ans+=a[x]
print(ans)
| 1 | 78,739,939,371,356 | null | 227 | 227 |
dic = {}
for s in range(int(input())):
i = input().split()
if i[0] == "insert":
dic[i[1]] = None
else:
print("yes" if i[1] in dic else "no") | # -*- coding: utf-8 -*-
def main():
N = int(input())
S = input()
ans = 1
for i in range(N - 1):
if S[i] != S[i + 1]:
ans += 1
print(ans)
if __name__ == "__main__":
main() | 0 | null | 85,356,923,217,788 | 23 | 293 |
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(input())
n,m = readInts()
A = readInts()
sumA = sum(A)
div = sumA * (1/(4*m))
A = sorted(A,reverse=True)
for i in range(m):
if A[i] < div:
print('No')
exit()
print('Yes')
| x, y = map(int, input().split())
l = list(map(int, input().split()))
count = 0
for i in range(x):
if l[i] >= sum(l)*(1/(4*y)):
count += 1
if count >= y:
print("Yes")
else:
print("No") | 1 | 38,705,699,922,688 | null | 179 | 179 |
S = list(input())
q = int(input())
for i in range(q):
cmd, a, b, *c = input().split()
a = int(a)
b = int(b)
if cmd == "replace":
S[a:b+1] = c[0]
elif cmd == "reverse":
S[a:b+1] = reversed(S[a:b+1])
else:
print(*S[a:b+1], sep='')
| sen = input()
n = int(input())
for i in range(n):
cmd = input().split()
sta = int(cmd[1])
end = int(cmd[2])
if cmd[0] == 'replace':
sen = sen[0:sta] + cmd[3] + sen[end+1:]
elif cmd[0] == 'reverse':
rev = sen[sta:end+1]
rev = rev[::-1]
# print(rev)
sen = sen[0:sta] + rev +sen[end+1:]
elif cmd[0] == 'print':
print(sen[sta:end+1])
# print('sen : '+sen) | 1 | 2,121,219,244,288 | null | 68 | 68 |
while True:
h,w = map(int,raw_input().split())
if h==0 and w==0:
break
sside=""
for x in xrange(w):
sside += "#"
for x in xrange(h):
print sside
print | X = int(input())
i = 1
while (360 * i) % X != 0: i += 1
print((360 * i) // X) | 0 | null | 6,885,941,224,360 | 49 | 125 |
N=int(input())
Ins=[[] for _ in range(N)]
ans=0
#0-indexedにしておく
for i in range(N):
A=int(input())
for _ in range(A):
x,y=map(int,input().split())
Ins[i].append((x-1,y))
for i in range(2**N):
flag=1
honest=[]
unkind=[]
for j in range(N):
if (i>>j)&1:
honest.append(j)
else:
unkind.append(j)
#ここまでは想定の組み合わせを作る作業
for k in honest:
#honestな人の証言を見ていく
for l in Ins[k]:
if l[1]==1 and l[0] in unkind:
flag=0
break
#honestな人がある人物をhonestと答えたのにも関わらず
#その人がunkindに入るような組み合わせは駄目...ケース1
elif l[1]==0 and l[0] in honest:
flag=0
break
#honestな人がある人物をunkindと答えたのにも関わらず
#その人がhonestに入るような組み合わせは駄目...ケース2
if flag==1:
ans=max(ans,len(honest))
#ケース1にもケース2にも該当しない場合
#現在のhonestの人数をansと比較して大きい方を採用
print(ans) | n,m = map(int,input().split())
v1 = [ list(map(int,input().split())) for i in range(n) ]
v2 = [ int(input()) for i in range(m) ]
for v in v1:
print( sum([ v[i] * v2[i] for i in range(m) ])) | 0 | null | 61,599,815,458,204 | 262 | 56 |
# 問題:https://atcoder.jp/contests/abc142/tasks/abc142_c
n = int(input())
a = list(map(int, input().strip().split()))
appear_attendance_number = {}
for i in range(n):
appear_attendance_number[a[i]-1] = i+1
res = []
for i in range(n):
res.append(appear_attendance_number[i])
print(' '.join(map(str, res)))
| def cube(x):
return x**3
def main():
x = int(input())
ans = cube(x)
print(ans)
if __name__=='__main__':
main() | 0 | null | 90,369,624,150,670 | 299 | 35 |
from collections import defaultdict
roots = defaultdict(list)
for k in range(2, 10 ** 6 + 1):
ki = k * k
while ki <= 10 ** 12:
roots[ki].append(k)
ki *= k
def factors(n):
fhead = []
ftail = []
for x in range(1, int(n ** 0.5) + 1):
if n % x == 0:
fhead.append(x)
if x * x != n:
ftail.append(n // x)
return fhead + ftail[::-1]
def solve(N):
works = set()
# Answer seems to be anything of the form: N = (K ** i) * (j * K + 1)
# Try every divisor of N as K ** i
for d in factors(N):
# If i == 1, then K == d
k = d
if (N // d) % k == 1:
assert k <= N
works.add(k)
if d == 1:
# If i == 0, then K ** 0 == 1, so K = (N - 1) // j, so anything that is a factor of N - 1 works
works.update(factors(N - 1))
elif d in roots:
# For i >= 2, see if it's in the list of precomputed roots
for k in roots[d]:
if k > N:
break
if (N // d) % k == 1:
works.add(k)
works.discard(1)
return len(works)
(N,) = [int(x) for x in input().split()]
print(solve(N))
if False:
def brute(N, K):
while N >= K:
if N % K == 0:
N = N // K
else:
N = N - K
return N
for N in range(2, 10000):
count = 0
for K in range(2, N + 1):
temp = brute(N, K)
if temp == 1:
print(N, K, temp)
count += 1
print("##########", N, count, solve(N))
assert count == solve(N)
| def divisor(n):
res = []
i = 1
while i*i <= n:
if not n % i:
res.append(i)
if (i*i != n): res.append(n//i)
i += 1
return res
N = int(input())
ans = 0
for d in divisor(N):
if d == 1: continue
n = N
while not n % d:
n //= d
if n%d == 1: ans += 1
print(ans + len(divisor(N-1))-1) | 1 | 41,437,659,732,332 | null | 183 | 183 |
n=int(input())
for i in range(1,50001):
if i*108//100 == n:
print(i)
break
else:
print(":(") | N=int(input())
P,Q=108,100
A=(N*Q+P-1)//P
B=((N+1)*Q+P-1)//P-1
if A>B:
print(":(")
else:
print(A)
| 1 | 126,160,922,842,460 | null | 265 | 265 |
n = int(input())
mod = 10**18
li = list(map(int, input().split()))
li.sort()
ans = 1
for i in range(n):
ans *= li[i]
if ans > mod:
ans = -1
break
print(ans)
| from itertools import permutations
N = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
Z_list = [n for n in range(1, N + 1)]
for i,j in enumerate(permutations(Z_list, r = N)):
if j == P:
a = i
if j == Q:
b = i
print(abs(b - a)) | 0 | null | 58,151,563,926,300 | 134 | 246 |
n,k,*a=map(int, open(0).read().split())
b=[0]
for t in a:b+=(t-1+b[-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) | n,k=map(int,input().split())
a=list(map(int,input().split()))
current=[0]
dic={}
dic[0]=1
ans=0
for i in range(n):
current.append((current[-1]+a[i]-1)%k)
if i>=k-1:
dic[current[-k-1]]-=1
if current[-1] in dic:
ans+=dic[current[-1]]
dic[current[-1]]+=1
else:
dic[current[-1]]=1
print(ans) | 1 | 137,862,188,810,788 | null | 273 | 273 |
N,M,K=map(int,input().split())
A=[];B=[]
for i in range(M):
a,b=map(int,input().split())
A.append(a);B.append(b)
C=[];D=[]
for i in range(K):
c,d=map(int,input().split())
C.append(c);D.append(d)
f=[set() for i in range(N)]
b=[set() for i in range(N)]
for i in range(M):
f[A[i]-1].add(B[i]-1)
f[B[i]-1].add(A[i]-1)
for i in range(K):
b[C[i]-1].add(D[i]-1)
b[D[i]-1].add(C[i]-1)
checked=[False for i in range(N)]
class UnionFind:
def __init__(self,n):
self.n=n
self.parents=[-1]*n
def root(self,x):
if self.parents[x]<0:
return x
else:
self.parents[x]=self.root(self.parents[x])
return self.parents[x]
def union(self,x,y):
x=self.root(x)
y=self.root(y)
if x==y:
return
if self.parents[x]>self.parents[y]:
x,y=y,x
self.parents[x]+=self.parents[y]
self.parents[y]=x
def same(self,x,y):
return self.root(x)==self.root(y)
def size(self,x):
return -self.parents[self.root(x)]
def roots(self):
return [i for i,x in enumerate(self.parents) if x<0]
def group_count(self):
return len(self.roots())
uf=UnionFind(N)
for i in range(N):
for people in f[i]:
uf.union(i,people)
ans=[]
for i in range(N):
c=uf.size(i)
bl=0
for x in b[i]:
if uf.same(i,x):
bl+=1
ans.append(c-bl-1-len(f[i]))
print(*ans) | def func(l):
i = 0
for num in range(l[0], l[1]+1):
#print(num)
if l[2] % num == 0:
#print(num)
i = i + 1
return i
if __name__ == '__main__':
N = input().split(" ")
l = []
for i in N:
l.append(int(i))
result = func(l)
print(result) | 0 | null | 30,889,794,549,230 | 209 | 44 |
from collections import deque
H,W=map(int,input().split())
S=[input() for _ in range(H)]
ans=0
d=deque([])
for i in range(H):
for j in range(W):
if S[i][j]=='#':
continue
d.append((i,j,0))
visited=[[-1]*W for _ in range(H)]
visited[i][j]=0
while d:
x,y,c=d.popleft()
for dx,dy in [(0,1),(1,0),(0,-1),(-1,0)]:
nx,ny=x+dx,y+dy
if 0<=nx<H and 0<=ny<W and visited[nx][ny]==-1 and S[nx][ny]=='.':
visited[nx][ny]=c+1
d.append((nx,ny,c+1))
ans=max(ans,c)
print(ans) | from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from copy import deepcopy
from collections import deque
h,w=nii()
s=[list(input()) for i in range(h)]
def dfs(cs,i,j):
que=deque()
que.append([i,j])
cs[i][j]='#'
dist=[[-1 for a in range(w)] for b in range(h)]
dist[i][j]=0
while que:
y,x=que.popleft()
for dy,dx in [[1,0],[-1,0],[0,1],[0,-1]]:
ny=y+dy
nx=x+dx
if 0<=ny<h and 0<=nx<w and cs[ny][nx]=='.':
que.append([ny,nx])
cs[ny][nx]='#'
dist[ny][nx]=dist[y][x]+1
t_ans=0
for a in dist:
t_ans=max(t_ans,max(a))
return t_ans
ans=0
for i in range(h):
for j in range(w):
if s[i][j]=='.':
cs=deepcopy(s)
dist=dfs(cs,i,j)
ans=max(ans,dist)
print(ans) | 1 | 94,710,867,657,692 | null | 241 | 241 |
n = int(input())
s = input()
cnt = 0
for i in range(len(s)):
if s[i] == "A" and i+2 <= len(s)-1:
if s[i+1] == "B":
if s[i+2] == "C":
cnt += 1
print(cnt) | # Debt Hell
n = int(input())
value = 100000
for i in xrange(n):
value *= 1.05
if value % 1000 != 0:
value = int(value / 1000 + 1) * 1000
print value | 0 | null | 49,601,273,637,620 | 245 | 6 |
N,K=map(int,input().split())
A=list(map(int,input().split()))
a=0
b=10**9+1
while a+1<b:
mid=(a+b)//2
ans=0
for i in A:
ans+=(i-1)//mid
if K<ans:
a=mid
else:
b=mid
print(b) | x, y = map(int, input().split())
mod = 10 ** 9 + 7
if (x + y) % 3 != 0:
ans = 0
else:
n, m = (2 * x - y) / 3, (2 * y - x) / 3
ans = 0
if n >= 0 and m >= 0:
n, m = int(n), int(m)
ans = 1
for i in range(min(m, n)):
ans = ans * (n + m - i) % mod
ans *= pow(i + 1, mod - 2, mod)
print(ans % mod) | 0 | null | 78,036,516,387,972 | 99 | 281 |
n = int(input())
d = {}
for i in range(n):
line = input().split()
if line[0] == "insert":
d[line[1]] = 1
elif line[0] == "find":
if line[1] in d:
print("yes")
else:
print("no") | if __name__ == "__main__":
n = int(input())
ops = []
words = []
for _ in range(n):
op, word = input().split()
ops.append(op)
words.append(word)
db = set()
for op, word in zip(ops, words):
if op=='insert':
db.add(word)
else:
if word in db:
print("yes")
else:
print("no")
| 1 | 79,759,152,368 | null | 23 | 23 |
A, B, M = list(map(int, input().split()))
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
ans = min(a_list) + min(b_list)
for i in range(M):
x, y, c = list(map(int, input().split()))
cost = a_list[x - 1] + b_list[y - 1] - c
if cost < ans:
ans = cost
print(ans) | A,B,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
li2=[input() for i in range(m)]
c = []
for i in range(m):
c.append( [int(x.strip()) for x in li2[i].split()])
ans = min(a) + min (b)
for i in range(m):
keep = a[c[i][0]-1] + b[c[i][1]-1] - c[i][2]
if keep < ans:
ans = keep
print(ans) | 1 | 53,784,288,650,960 | null | 200 | 200 |
import sys
from bisect import bisect_left
input = sys.stdin.readline
def main():
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for a in range(N - 2):
for b in range(a + 1, N - 1):
x = bisect_left(L, L[a] + L[b])
ans += (x - 1 - b)
print(ans)
if __name__ == "__main__":
main()
| import sys
from itertools import accumulate
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, *L = map(int, read().split())
L.sort()
max_L = max(L)
C = [0] * (max_L + 1)
for l in L:
C[l] += 1
C = list(accumulate(C))
ans = 0
for i, a in enumerate(L):
for j, b in enumerate(L[i + 1 :], i + 1):
if a + b > max_L:
ans += N - j - 1
else:
ans += C[a + b - 1] - j - 1
print(ans)
return
if __name__ == '__main__':
main()
| 1 | 171,602,688,191,844 | null | 294 | 294 |
from bisect import bisect_left
import string
dic={c:[] for c in string.ascii_lowercase}
N=int(input())
S=list(input())
Q=int(input())
for i in range(len(S)):
dic[S[i]].append(i+1)
for i in range(Q):
a,b,c=map(str,input().split())
if a=='1':
if S[int(b)-1]==c:
continue
b=int(b)
f=S[b-1]
d=bisect_left(dic[f],b)
e=bisect_left(dic[c],b)
dic[f].pop(d)
dic[c].insert(e,b)
S[b-1]=c
else:
ans=0
b,c=int(b),int(c)
for j in string.ascii_lowercase:
d=bisect_left(dic[j],b)
if d<len(dic[j]):
if dic[j][d]<=c:
ans+=1
print(ans)
| #http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_C&lang=jp
#??????????????????
#??????????????????????°???????????????£?????´???????????´?????¨??\?????????????????????????????????????????´????????????
#??????????????????????????????????°????????????????????????´???????????????????????????????????????????????¨??????
def bubble_sort(origin_list):
list_length = len(origin_list)
target_list = [i for i in origin_list]#??°????????????????????????
flag = True
change_count = 0
top_index = 1
while flag:
flag = False
for i in range(top_index, list_length)[::-1]:
if target_list[i][1] < target_list[i - 1][1]:
tmp = target_list[i]
target_list[i] = target_list[i - 1]
target_list[i - 1] = tmp
change_count += 1
flag = True
top_index += 1
return target_list
def selection_sort(origin_list):
list_length = len(origin_list)
target_list = [i for i in origin_list]#??°????????????????????????
change_count = 0
for i in range(list_length):
min_index = i
for j in range(i, list_length):
if target_list[j][1] < target_list[min_index][1]:
min_index = j
else:
if not i == min_index:
tmp = target_list[i]
target_list[i] = target_list[min_index]
target_list[min_index] = tmp
change_count += 1
return target_list
def check_stable(origin_list, target_list):
for i, origin_v in enumerate(origin_list):
for origin_v2 in origin_list[i+1:]:
if origin_v[1] == origin_v2[1]:
for j, target_v in enumerate(target_list):
for target_v2 in target_list[j+1:]:
if origin_v == target_v2 and origin_v2 == target_v:
return "Not stable"
return "Stable"
def stable_sort(target_list):
print(*bubble_sort(target_list))
print(check_stable(target_list, bubble_sort(target_list)))
print(*selection_sort(target_list))
print(check_stable(target_list, selection_sort(target_list)))
def main():
n_list = int(input())
target_list = [a for a in input().split()]
stable_sort(target_list)
if __name__ == "__main__":
main() | 0 | null | 31,116,825,935,868 | 210 | 16 |
N = int(input())
memberlist = []
testinomylist = []
for _ in range(N):
A = int(input())
tmpmemberlist = []
tmptestinomylist = []
for i in range(A):
x, y = map(int, input().split())
tmpmemberlist.append(x)
tmptestinomylist.append(y)
memberlist.append(tmpmemberlist) # [[2,3],[1,3],[1]] こんな感じで人が収容
testinomylist.append(tmptestinomylist) # [[0,1],[1],[0]]
ans = 0
for i in range(2 ** N):
honestlist = []
liarlist = []
for j in range(N):
if ((i >> j) & 1):
#if true 条件を満たした人を正直物として考える.
honestlist.append(j+1)
else:
# if false の人は嘘つきものだと考える。
liarlist.append(j+1)
#正直な人だけを見ればいい。
Flag = 0
for honestnumber in honestlist: #bit全探索で得た正直な人の番号
for X,Y in zip(memberlist[honestnumber-1] , testinomylist[honestnumber-1]): # 正直な人だけの証言
if (Y == 0):
if X in liarlist: #正直者の証言が食い違ってないか
pass
else:
Flag = 1
elif (Y == 1):
if X in honestlist:
pass
else:
Flag = 1
if Flag == 1:
pass
else:
ans = max(ans,len(honestlist))
print(ans)
| def main():
A, B, C = list(map(int, input().split()))
K = int(input())
for _ in range(K):
if A >= B:
B *= 2
elif B >= C:
C *= 2
if A < B < C:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main() | 0 | null | 64,486,006,451,328 | 262 | 101 |
k, a, b = map(int, open(0).read().split())
print("OK" if b // k * k >= a else "NG") | def main():
k = int(input())
a, b = (int(i) for i in input().split())
for i in range(a, b+1):
if i % k == 0:
print('OK')
return
print('NG')
main()
| 1 | 26,674,917,813,180 | null | 158 | 158 |
def main():
x = int(input())
a_lst = []
b_lst = []
for i in range(400):
a_lst.append(-200 + i)
for i in range(400):
b_lst.append(-200 + i)
flag = False
for i in range(len(a_lst)):
for j in range(len(b_lst)):
a = a_lst[i]
b = b_lst[j]
if a ** 5 - b ** 5 == x:
print(a, b)
flag = True
break
if flag:
break
if __name__ == '__main__':
main() | N = int(input())
S = list(input())
Q = int(input())
alphabet = "abcdefghijklmnopqrstuvwxyz"
num = dict()
for i, var in enumerate(alphabet):
num[var] = i
class Bit():
def __init__(self, N):
self.__N = N
self.__arr = [[0] * 26 for _ in range(1 + N)]
def add_(self, x, a, i):
while(x < self.__N + 1):
self.__arr[x][i] += a
x += x & -x
def sum_(self, x, i):
res = 0
while(x > 0):
res += self.__arr[x][i]
x -= x & -x
return res
def sub_sum_(self, x, y, i):
return self.sum_(y, i) - self.sum_(x, i)
Bit = Bit(N)
for i, var in enumerate(S):
Bit.add_(i+1, 1, num[var])
for i in range(Q):
q, l, r = input().split()
l = int(l)
if q == "1" and r != S[l-1]:
temp = S[l-1]
S[l-1] = r
Bit.add_(l, -1, num[temp])
Bit.add_(l, 1, num[r])
elif q == "2":
r = int(r)
res = 0
for j in range(26):
res += min(1, Bit.sub_sum_(l-1, r, j))
print(res)
| 0 | null | 44,301,703,238,464 | 156 | 210 |
N, X, M = map(int, input().split())
existence = [False] * M
a = []
A = X
for i in range(N):
if existence[A]:
break
existence[A] = True
a.append(A)
A = A * A % M
for i in range(len(a)):
if a[i] == A:
loop_start = i
break
else:
loop_start = len(a)
result = sum(a[:loop_start])
N -= loop_start
if N != 0:
a = a[loop_start:]
loops = N // len(a)
remainder = N % len(a)
result += sum(a) * loops + sum(a[:remainder])
print(result)
| n=int(input())
s=input()
q=int(input())
query=[]
for i in range(q):
query.append(input())
ide_ele = set()
def segfunc(x, y):
return x | y
class SegTree:
def __init__(self, init_val, segfunc, ide_ele):
n = len(init_val)
self.segfunc = segfunc
self.ide_ele = ide_ele
self.num = 1 << (n - 1).bit_length()
self.tree = [ide_ele] * 2 * self.num
for i in range(n):
self.tree[self.num + i] = init_val[i]
for i in range(self.num - 1, 0, -1):
self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])
def update(self, k, x):
# param k: index(0-index)
# param x: update value
k += self.num
self.tree[k] = x
while k > 1:
self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
k >>= 1
def query(self, l, r):
#[l, r)segfunc, 0-index
res = self.ide_ele
l += self.num
r += self.num
while l < r:
if l & 1:
res = self.segfunc(res, self.tree[l])
l += 1
if r & 1:
res = self.segfunc(res, self.tree[r - 1])
l >>= 1
r >>= 1
return res
al = [{s[i]} for i in range(n)]
seg = SegTree(al, segfunc, ide_ele)
for q in query:
que,a,b=q.split()
if que == "1":
seg.update(int(a)-1,set(b))
else:
ret=seg.query(int(a)-1,int(b))
print(len(ret)) | 0 | null | 32,678,963,850,148 | 75 | 210 |
import math
n = int(input())
folia = list(map(int, input().split()))
#print(n, folia)
#_1 木の一番下から順に各深さの頂点数[min, max]を取得
seq = [[folia[-1], folia[-1]]]
for i in range(n): # 深さ'n'分
tmp = folia[-(i+2)]
sml = math.ceil(seq[i][0] / 2) + tmp
big = seq[i][1] + tmp
seq += [[sml, big]]
#print(seq)
#_2 一番根本の頂点数[min, max]に'1'を含まない場合は '存在しない木'
if not (seq[-1][0] <= 1 <= seq[-1][1]):
print(-1)
exit()
#_3 木の一番上から順に各深さで理論最大頂点数と'#_1のmax'との'min'をとる
ans =[1]
for j in range(n): # 深さ'n'分
tmp = min((ans[j] - folia[j]) * 2, seq[-(j+2)][1])
ans.append(tmp)
print(sum(ans)) # その合計が'ans'
| import networkx as nx
H, W = map(int, input().split())
maze = [input() for _ in range(H)]
G = nx.Graph()
# 辺を加えていく
for h in range(H):
for w in range(W - 1):
if maze[h][w] == maze[h][w + 1] == '.':
G.add_edge((h, w), (h, w + 1))
for h in range(H - 1):
for w in range(W):
if maze[h][w] == maze[h + 1][w] == '.':
G.add_edge((h, w), (h + 1, w))
def bfs(sy, sx):
d = dict()
d[(sy, sx)] = 0
for coordinate_from, coordinate_to in nx.bfs_edges(G, (sy, sx)):
d[coordinate_to] = d[coordinate_from] + 1
return max(d.values())
ans = 0
for y in range(H):
for x in range(W):
if maze[y][x] == '.':
ans = max(ans, bfs(y, x))
print(ans)
| 0 | null | 57,020,684,326,310 | 141 | 241 |
from collections import deque
section = raw_input( )
depth = 0
area = 0
depthArr = deque( )
areaArr = deque( )
for i, ground in enumerate( section ):
if "\\" == ground:
depth += 1
depthArr.append( i )
elif 0 < depth and "/" == ground:
if len( depthArr ):
j = depthArr.pop( )
pool = i - j
area += pool
while len( areaArr ):
preJ, prePool = areaArr.pop( )
if j <= preJ:
pool += prePool
else:
areaArr.append( ( preJ, prePool ) )
break
areaArr.append( ( j, pool ) )
print( area )
output = []
output.append( len( areaArr ) )
for arr in areaArr:
output.append( arr[1] )
print( " ".join( map( str, output ) ) ) | cross_section = input()
stack = []
areas_stack = []
area = 0
for i in range(len(cross_section)):
c = cross_section[i]
if c == '\\':
stack.append(i)
elif c == '/' and len(stack) != 0:
j = stack.pop()
a = i - j
area += a
while len(areas_stack) != 0 and areas_stack[-1][0] > j:
a += areas_stack.pop()[1]
areas_stack.append([j, a])
print(area)
if area == 0:
print(0)
else:
print(len(areas_stack), ' '.join([str(x[1]) for x in areas_stack]))
| 1 | 57,251,107,248 | null | 21 | 21 |
K = int(input())
S = input()
if len(S) <= K:
print(S)
else:
print('{}...'.format(S[:K])) | import sys
sys.setrecursionlimit(10000000)
n,x,y=map(int,input().split())
x-=1
y-=1
res=[0]*n
for i in range(n):
for j in range(i+1,n):
m = min(j-i, abs(i-x)+abs(j-y)+1, abs(i-y)+abs(j-x)+1)
res[m]+=1
for i in range(1,n):
print(res[i]) | 0 | null | 31,946,003,768,480 | 143 | 187 |
if __name__ == '__main__':
n = int(input())
a = list(map(int, input().split()))
ans = 0
x, y, z = [0], [0], [0]
for i in range(n):
if a[i] == 0:
if x[-1] == 0:
x.append(1)
y.append(y[-1])
z.append(z[-1])
elif y[-1] == 0:
x.append(x[-1])
y.append(1)
z.append(z[-1])
else:
x.append(x[-1])
y.append(y[-1])
z.append(1)
else:
if x[-1] == a[i]:
x.append(x[-1] + 1)
y.append(y[-1])
z.append(z[-1])
elif y[-1] == a[i]:
x.append(x[-1])
y.append(y[-1] + 1)
z.append(z[-1])
else:
x.append(x[-1])
y.append(y[-1])
z.append(z[-1] + 1)
ans = 1
for i in range(n):
ans *= [x[i], y[i], z[i]].count(a[i])
ans %= (10 ** 9 + 7)
print(ans)
| n = int(input())
a = list(map(int, input().split()))
que = [-1, -1, -1]
ans = 1
for i in range(n):
if que[0]+1 == a[i]:
if que[0] == que[1] and que[0] == que[2]:
ans *= 3
ans %= (10**9 + 7)
elif que[0] == que[1]:
ans *= 2
ans %= (10**9 + 7)
que[0] = a[i]
elif que[1]+1 == a[i]:
if que[1] == que[2]:
ans *= 2
ans %= (10**9 + 7)
que[1] = a[i]
elif que[2]+1 == a[i]:
que[2] = a[i]
else:
ans = 0
break
print(ans)
| 1 | 129,527,663,948,918 | null | 268 | 268 |
n = int(input())
xpy = []
xmy = []
for i in range(n):
x,y = map(int,input().split())
xpy.append(x+y)
xmy.append(x-y)
xpy.sort()
xmy.sort()
print(max(abs(xpy[0]-xpy[-1]),abs(xmy[0]-xmy[-1]))) | # -*- coding: utf-8 -*-
# E
import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline
# 再起回数上限変更
# sys.setrecursionlimit(1000000)
n = int(input())
d1 = [] * n
d2 = [] * n
for i in range(n):
x, y = map(int, input().split())
d1.append(x+y)
d2.append(x-y)
print(max(max(d1) - min(d1), max(d2)-min(d2)))
| 1 | 3,374,152,386,062 | null | 80 | 80 |
import sys
n = int(input())
d = [list(map(int, input().split())) for _ in range(n)]
cnt = 0
for z in d:
x, y = z
if x == y:
cnt += 1
if cnt >= 3:
print("Yes")
sys.exit()
else:
cnt = 0
print("No") | N=int(input())
cnt=0
ans="No"
for i in range(N):
x,y=input().split()
if x==y:
cnt=cnt+1
else:
cnt=0
if cnt>=3:
ans="Yes"
print(ans) | 1 | 2,504,090,182,772 | null | 72 | 72 |
import itertools
n=int(input())
A=[0 for i in range(n)]
A=input().split()
for i in range(n):
A[i]=int(A[i])
q=int(input())
B=[0 for i in range(q)]
B=input().split()
C=[]
for i in range(q):
B[i]=int(B[i])
l=[0,1]
p=[]
k=0
D=[]
for v in itertools.product(l,repeat=n):
sum=0
for i in range(n):
if v[i]==1:
sum=sum+A[i]
D.append(sum)
k+=1
for i in range(q):
if B[i] in D:
C.append("yes")
else:
C.append("no")
for i in range(q):
print(C[i])
| n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
if n==1:
print(a[0]*2)
exit()
from bisect import bisect_left,bisect_right
#幸福度がx以上がm以上か?
def f(x):
global n,a
ret=0
for i in range(n):
ret+=(n-bisect_left(a,x-a[i]))
return ret
l,r=-1,10**6
while l+1<r:
k=l+(r-l)//2
if f(k)>=m:
l=k
else:
r=k
#print(l,r)
#print(f(l),f(r))
if f(r)>=m:
co,ans=0,0
for i in range(n):
co+=(n-bisect_right(a,r-a[i]))
ans+=(n-bisect_right(a,r-a[i]))*a[i]
print(2*ans+(m-co)*r)
else:
co,ans=0,0
for i in range(n):
co+=(n-bisect_right(a,l-a[i]))
ans+=(n-bisect_right(a,l-a[i]))*a[i]
print(2*ans+(m-co)*l) | 0 | null | 54,288,886,449,388 | 25 | 252 |
def insertion_sort(a, g, n):
cnt = 0
for i in range(g, n):
v = a[i]
j = i - g
while j >= 0 and a[j] > v:
a[j + g] = a[j]
j = j - g
cnt += 1
a[j + g] = v
return cnt
def shell_sort(a, n):
cnt = 0
g = []
h = 1
while h <= n:
g.append(h)
h = 3 * h + 1
g.reverse()
m = len(g)
print(m)
print(*g)
for i in range(m):
cnt += insertion_sort(a, g[i], n)
print(cnt)
n = int(input())
a = [int(input()) for _ in range(n)]
shell_sort(a, n)
print('\n'.join(map(str, a)))
| n,k = map(int,input().split())
t = [0] * n
for _ in range(k):
d = int(input())
a = list(map(int,input().split()))
for e in a:
t[e-1] += 1
ans = 0
l = [i for i in t if i == 0]
# print(l)
print(len(l)) | 0 | null | 12,361,141,468,832 | 17 | 154 |
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) | import math
def solve():
N = int(input())
ans = 0
for i in range(2, int(math.sqrt(N)) + 2):
n = 1
cnt = 0
while N % i == 0:
N //= i
cnt += 1
if cnt == n:
cnt = 0
n += 1
ans += 1
if N != 1:
ans += 1
return ans
print(solve())
| 1 | 16,941,915,973,530 | null | 136 | 136 |
N = int(input())
S = input()
ans = 1
if N % 2:
ans = 0
else:
for i in range(N//2):
if S[i] != S[N//2 + i]:
ans = 0
if ans:
print("Yes")
else:
print("No") | N = int(input())
judge = N%10
hon = [2,4,5,7,9]
pon = [0,1,6,8]
bon = [3]
if judge in hon:
print("hon")
elif judge in pon:
print("pon")
elif judge in bon:
print("bon") | 0 | null | 83,115,145,930,492 | 279 | 142 |
a = int ( input ( ) )
h = a // 3600
m = ( a // 60 ) % 60
d = a % 60
print ( "%s:%s:%s" % ( h, m, d ) ) | S = int(raw_input())
M, s = S / 60, S % 60
h, m = M / 60, M % 60
print '%d:%d:%d' % (h, m, s) | 1 | 337,720,006,198 | null | 37 | 37 |
n = int(input())
s = input()
if n%2 != 0:
ans = 'No'
else:
ans = 'Yes'
for i in range(n//2):
if s[i] != s[i+n//2]:
ans = 'No'
print(ans) | n, k = list(map(int, input().split()))
enemy = list(map(int, input().split()))
enemy = sorted(enemy, reverse=True)
enemy = enemy[k:]
print(sum(enemy)) | 0 | null | 112,826,311,116,204 | 279 | 227 |
n = int(input())
state10 = 1
state9 = 1
state8 = 1
mod = 10**9 + 7
for _ in range(n):
state10 *= 10
state10 %= mod
state9 *= 9
state9 %= mod
state8 *= 8
state8 %= mod
ans = state10 - 2*state9 + state8
ans %= mod
print(ans)
| N = int(input())
MOD = 10**9+7
a10 = 10**N
a9 = 9**N
a8 = 8**N
print((a10-a9-a9+a8) % MOD)
| 1 | 3,186,928,482,880 | null | 78 | 78 |
M1,D1 = [ int(i) for i in input().split() ]
M2,D2 = [ int(i) for i in input().split() ]
print("1" if M1 != M2 else "0")
| x=int(input())
n=x//500
m=x%500//5
ans=1000*n+5*m
print(ans)
| 0 | null | 83,856,952,906,540 | 264 | 185 |
def main():
s = input()
arr = [0]*(len(s)+1)
for i in range(len(s)):
c = s[i]
if c == "<":
arr[i+1] = arr[i]+1
for i in reversed(range(len(s))):
c = s[i]
if c == ">":
arr[i] = max(arr[i], arr[i+1]+1)
print(sum(arr))
if __name__ == "__main__":
main()
| s = list(input())
al = [0]*(len(s)+1)
for i in range(len(s)):
if s[i] == '<':
al[i+1] = max(al[i]+1, al[i+1])
for i in range(len(s)-1, -1, -1):
if s[i] == '>':
al[i] = max(al[i+1]+1, al[i])
print(sum(al)) | 1 | 156,833,191,888,620 | null | 285 | 285 |
N = int(input())
ans = []
while N > 0:
N -= 1
a = N%26
ans.append(chr(97+a))
N = N//26
#print(ans)
ret = ""
for i in range(len(ans)):
ret += ans[-1-i]
#print(ret)
print(ret) | from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT() : return int(input())
def MAP() : return map(int,input().split())
def LIST() : return list(MAP())
n = INT()
ans = ''
while n != 0:
x = ( n - 1 ) % 26
n = ( n - x + 1 ) // 26
ans = chr( ord('a') + x ) + ans
print(ans) | 1 | 11,864,631,717,770 | null | 121 | 121 |
N, K = map(int, input().split())
result = 1
for i in range(K, N+1):
tmp_min = (i - 1) * i // 2
tmp_max = (N * (N + 1) - (N - i) * (N - i + 1)) // 2
result += tmp_max - tmp_min + 1
result %= 10 ** 9 + 7
print(result)
| N, K = input().split()
N = int(N)
K = int(K)
scores = [int(s) for s in input().split()]
sums = []
k = K-1
for i in range(k,N-1):
if(scores[i-k] < scores[i+1]):
print("Yes")
else:
print("No") | 0 | null | 20,259,107,553,494 | 170 | 102 |
import math
n = float(input())
m = n / 1.08
if math.floor(math.floor(m) * 1.08) == n:
print(math.floor(m))
elif math.floor(math.ceil(m) * 1.08) == n:
print(math.ceil(m))
else:
print(':(') | n = int(input())
import math
a = n*100/108
b = (n*100+100)/108
ans = math.ceil(a) if math.ceil(a) < b else ":("
print(ans) | 1 | 125,729,208,796,608 | null | 265 | 265 |
MOD = 1000000007
n, k = map(int, input().split())
rsw = [0]*(n+2)
for i in range(1,n+2):
rsw[i] = (rsw[i-1]+i-1)%MOD
rsw_e = [0]*(n+2)
for i in range(1,n+2):
rsw_e[i] = (rsw_e[i-1]+n-(i-1))%MOD
res = 0
for i in range(k,n+2):
start = rsw[i]
end = rsw_e[i]
res += (end-start+1)%MOD
print(res%MOD) | import copy
# 入力
D = int(input())
C = list(map(int, input().split()))
S_2d = []
for i in range(D):
s_1d = list(map(int, input().split()))
S_2d.append(s_1d)
last_days = [0] * 26
tot_score = 0
def scoring(day, tot_score, today_contest, last_days):
today_plus = S_2d[day - 1][today_contest]
today_minus = 0
for j, c in enumerate(C):
today_minus += c * (day - last_days[j])
# print(today_plus, today_minus)
return (today_plus - today_minus)
# A
for i in range(D):
best_score = -10**100
best_contest = 0
for k, _ in enumerate(C):
last_days_tmp = copy.copy(last_days)
last_days_tmp[k] = i + 1
k_score = scoring(i + 1, tot_score, k, last_days_tmp)
if best_score < k_score:
best_score, best_contest = k_score, k
last_days[best_contest] = i + 1
tot_score += best_score
print(best_contest + 1)
# # B
# T = []
# for i in range(D):
# t = int(input())
# T.append(t)
# for i in range(D):
# last_days[T[i] - 1] = i + 1
# tot_score += scoring(i+1, tot_score, T[i] - 1)
# print(tot_score)
| 0 | null | 21,377,758,543,712 | 170 | 113 |
def gcd (x , y):
sur = x % y
while sur != 0:
x = y
y = sur
sur = x % y
return y
a,b = map(int,raw_input().split())
if a < b :
temp = a
a = b
b = temp
print gcd(a,b) | def dfs(seq):
ans = 0
if len(seq) == n:
kou = 0
for u in data:
if seq[u[1]-1] - seq[u[0]-1] == u[2]:
kou+=u[3]
return kou
else:#len(seq)==N-1からの遷都を考えると良い
for i in range(seq[-1], m+1):
seq_next=seq+[i]
ans = max(ans, dfs(seq_next))
return ans
n, m, q = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(q)]
score = dfs([1])
print(score)
| 0 | null | 13,769,614,316,910 | 11 | 160 |