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
|
---|---|---|---|---|---|---|
def main():
N = int(input())
X = []
Y = []
for _ in range(N):
x, y = (int(i) for i in input().split())
X.append(x + y)
Y.append(x - y)
ans = max(max(X) - min(X), max(Y) - min(Y))
print(ans)
if __name__ == '__main__':
main()
| N = int(input())
xy = [tuple(map(int, input().split())) for _ in range(N)]
z = []; w = []
for x, y in xy:
z.append(x + y)
w.append(x - y)
print(max(max(z)-min(z), max(w)-min(w))) | 1 | 3,445,212,726,550 | null | 80 | 80 |
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC_List = x = [list(map(int, input().split())) for i in range(Q)]
int_list = [0 for _ in range(10**5+1)]
sum = 0
for i in A:
int_list[i] += 1
sum += i
for B, C in BC_List:
sum = sum + (C-B) * int_list[B]
int_list[C] += int_list[B]
int_list[B] = 0
print(sum)
| n=int(input())
a=list(map(int,input().split()))
q=int(input())
b=[0]*q
c=[0]*q
for i in range(q):
b[i],c[i]=map(int,input().split())
N=[0]*(10**5)
s=0
for i in range(n):
N[a[i]-1]+=1
s+=a[i]
for i in range(q):
s+=(c[i]-b[i])*N[b[i]-1]
N[c[i]-1]+=N[b[i]-1]
N[b[i]-1]=0
print(s) | 1 | 12,175,781,895,690 | null | 122 | 122 |
import sys
N,M = map(int,input().split())
if N%2 == 1:
for i in range(1,M+1):
print(i,N-i+1)
elif N%4 == 0:
total = 0
count = 1
for i in range(N//4,0,-1):
print(i,i+count)
count += 2
total += 1
if total >= M:
sys.exit()
count = 2
for i in range(3*(N//4)-1,N//2,-1):
print(i,i+count)
count += 2
total += 1
if total >= M:
sys.exit()
else:
total = 0
count = 1
for i in range(N//4,0,-1):
print(i,i+count)
count += 2
total += 1
if total >= M:
sys.exit()
count = 2
for i in range(3*(N//4),N//2-1,-1):
print(i,i+count)
count += 2
total += 1
if total >= M:
sys.exit() | from sys import setrecursionlimit
setrecursionlimit(1 << 30)
nv, ne, nBad = map(int, input().split())
g = [[] for _ in range(nv)]
for _ in range(ne):
u, v = map(lambda x: int(x) - 1, input().split())
g[u].append(v)
g[v].append(u)
a = [tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(nBad)]
def dfs(v):
id[v] = cur
comps[-1].append(v)
for to in g[v]:
if id[to] == None:
dfs(to)
id = [None] * nv
cur = 0
comps = []
for v in range(nv):
if id[v] == None:
comps.append([])
dfs(v)
cur += 1
bad = [0] * nv
for u, v in a:
if id[u] == id[v]:
bad[u] += 1
bad[v] += 1
ret = [None] * nv
for v in range(nv):
ret[v] = len(comps[id[v]]) - 1 - len(g[v]) - bad[v]
print(' '.join(map(str, ret))) | 0 | null | 45,135,040,968,738 | 162 | 209 |
import math
n = int(input())
answer = (n - math.floor(n / 2)) / n
print(answer)
# nums = list(range(1, n + 1))
#
# odds = [x for x in nums if x % 2 == 1]
#
# if len(nums) % 2 == 0:
# print(0.5)
# else:
# print(len(odds) / len(nums))
| ondo = int(input())
if 30 <= ondo:
print("Yes")
else:
print("No") | 0 | null | 91,505,114,600,898 | 297 | 95 |
n = int(input())
ans = 0
if n >= 2 and n % 2 == 0:
j = 10
while n >= j:
ans += (n // j)
j *= 5
print(ans) | A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[]
d=[]
for i in range(M):
c.append(list(map(int,input().split())))
C=min(a)+min(b)
for i in range(0,M):
d.append(a[(c[i][0]-1)]+b[(c[i][1]-1)]-c[i][2])
D=min(d)
print(min(C,D)) | 0 | null | 85,054,203,819,940 | 258 | 200 |
cnt = 0
def insertion_sort(seq, n, g):
global cnt
for i in range(g, n):
v = seq[i]
j = i - g
while j >= 0 and seq[j] > v:
seq[j + g] = seq[j]
j = j - g
cnt = cnt + 1
seq[j + g] = v
def shell_sort(seq, n):
g = 1
G = []
while g <= n:
G.append(g)
g = 3 * g + 1
print(len(G))
print(' '.join(map(str, reversed(G))))
for g in reversed(G):
insertion_sort(seq, n, g)
return seq
n = int(input())
a = [int(input()) for _ in range(n)]
ans = shell_sort(a, n)
print(cnt)
print('\n'.join(map(str, ans))) | import sys
count = 0
def insertionSort(A, n, g):
global count
for i in range(n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
count += 1
A[j+g] = v
return A
def shellSort(A, n):
for i in range(m):
insertionSort(A, n, G[i])
return A
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
G = [1]
m = 1
while True:
x = 3 * G[m-1] + 1
if x >= n: break
G.append(x)
m += 1
G = G[::-1]
shellSort(A, n)
print(m)
print(' '.join([str(i) for i in G]))
print(count)
for i in A:
print(i) | 1 | 32,021,503,920 | null | 17 | 17 |
import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp
INF = inf
MOD = 1000000007
x = int(input())
tmp = [i ** 5 for i in range(ceil(x ** 0.25) + 1)]
res = 0
for a in range(len(tmp) - 1):
for b in range(a + 1, len(tmp)):
if tmp[a] - tmp[b] == x:
res = f"{a} {b}"
break
elif tmp[a] + tmp[b] == x:
res = f"{a} {-b}"
break
elif -tmp[a] + tmp[b] == x:
res = f"{-a} {-b}"
break
elif -tmp[a] - tmp[b] == x:
res = f"{-a} {b}"
break
print(res)
| X = int(input())
found = False
for a in range(-200, 200):
if found: break;
for b in range(-200, 200):
if a ** 5 - b ** 5 == X:
print(a, b)
found = True
break
| 1 | 25,611,224,169,240 | null | 156 | 156 |
from sys import stdin, setrecursionlimit
input = stdin.buffer.readline
N = int(input())
A = list(map(int, input().split()))
max_A = max(A)
if max_A == 1:
print("pairwise coprime")
exit()
class Prime:
def __init__(self, n):
self.prime_factor = [i for i in range(n + 1)]
self.prime = []
for i in range(2, n + 1):
if self.prime_factor[i] == i:
for j in range(2, n // i + 1):
self.prime_factor[i * j] = i
self.prime.append(i)
#print(self.prime_factor)
#print(self.prime)
def factorize(self, m):
ret = []
while m != 1:
if not ret:
ret = [[self.prime_factor[m], 1]]
elif self.prime_factor[m] == ret[-1][0]:
ret[-1][1] += 1
else:
ret.append([self.prime_factor[m], 1])
m //= self.prime_factor[m]
return ret
def divisors(self, m):
ret = []
for i in range(1, int(m ** 0.5) + 1):
if m % i == 0:
ret.append(i)
if i != m // i:
ret.append(m // i)
#self.divisors.sort()
return ret
pm = Prime(max_A)
def is_pairwise_coprime(arr):
cnt = [0] * (max_A + 1)
for a in arr:
for b, c in pm.factorize(a):
cnt[b] += 1
if max(cnt[2:]) <= 1:
return 1
else:
return 0
def gcd(a, b):
while b:
a, b = b, a % b
return a
def is_setwise_coprime(A):
gcd_a = 0
for a in A:
gcd_a = gcd(gcd_a, a)
if gcd_a == 1:
return 1
else:
return 0
if is_pairwise_coprime(A):
print("pairwise coprime")
elif is_setwise_coprime(A):
print("setwise coprime")
else:
print("not coprime") | import sys
input = sys.stdin.readline
def gcd(a,b):
while b:
a,b=b,a%b
return a
def prime_factor(n):
a=[]
while n%2==0:
a.append(2)
n//=2
f=3
while f*f<=n:
if n%f==0:
a.append(f)
n//=f
else:
f+=2
if n!=1:
a.append(n)
return set(a)
n=int(input())
L=list(map(int,input().split()))
val = L[0]
for i in range(1,n):
val = gcd(L[i],val)
if val!=1:
print('not coprime')
sys.exit()
d={}
for i in range(n):
factor=prime_factor(L[i])
for j in factor:
if j not in d:
d[j]=1
else:
print('setwise coprime')
sys.exit()
print('pairwise coprime')
| 1 | 4,123,689,025,080 | null | 85 | 85 |
x1,y1,x2,y2 = map(float,input().split())
an = (x1 - x2)**2 + (y1 - y2)**2
dis = an/2
v = an/4
while abs(dis**2 - an) > 0.0001:
if dis**2 > an:
dis -= v
else:
dis += v
v = v/2
print(dis)
| n,m=map(int,raw_input().split())
c=map(int,raw_input().split())
dp=[[0]+[float('inf')]*n]+[[0]+[float('inf')]*n for i in xrange(m)]
for i in xrange(m):
for j in xrange(n+1):
if c[i]>j:
dp[i+1][j]=dp[i][j]
else:
dp[i+1][j]=min(dp[i][j],dp[i+1][j-c[i]]+1)
print(dp[m][n]) | 0 | null | 148,689,043,452 | 29 | 28 |
n = int(input())
s = []
for _ in range(n):
s.append(str(input()))
print('AC x ' + str(s.count('AC')))
print('WA x ' + str(s.count('WA')))
print('TLE x ' + str(s.count('TLE')))
print('RE x ' + str(s.count('RE'))) | listSi = [0,0,0,0]
ic = int(input())
icz = 0
while True:
icz += 1
i = input()
if i == "AC":
listSi[0] += 1
elif i == "WA":
listSi[1] += 1
elif i == "TLE":
listSi[2] += 1
elif i == "RE":
listSi[3] += 1
if icz == ic:
break
print(f"AC x {listSi[0]}")
print(f"WA x {listSi[1]}")
print(f"TLE x {listSi[2]}")
print(f"RE x {listSi[3]}")
| 1 | 8,634,453,561,092 | null | 109 | 109 |
h, w = map(int, input().split())
M = [list(input()) for _ in range(h)]
count = [[int(1e18) for _ in range(w)] for _ in range(h)]
count[0][0] = 1 if M[0][0] == '#' else 0
# 同じ色かどうかを見る
for i in range(h):
for j in range(w):
if i + 1 < h:
v = 1 if M[i][j] != M[i + 1][j] else 0
count[i + 1][j] = min(count[i + 1][j], count[i][j] + v)
if j + 1 < w:
v = 1 if M[i][j] != M[i][j + 1] else 0
count[i][j + 1] = min(count[i][j + 1], count[i][j] + v)
print((count[h - 1][w - 1] + 1) // 2) | n = int(input())
adjacency_list = []
for i in range(n):
input_list = list(map(int, input().split()))
adjacency_list.append(input_list[2:])
checked_set = set()
dfs_stack = []
v =[0 for i in range(n)]
f =[0 for i in range(n)]
time = 1
for i in range(n):
if i not in checked_set:
dfs_stack = []
dfs_stack.append(i)
while dfs_stack:
current = dfs_stack.pop()
if current not in checked_set:
checked_set.add(current)
v[current] = time
dfs_stack.append(current)
for ad in reversed(adjacency_list[current]):
if ad-1 not in checked_set:
dfs_stack.append(ad-1)
time +=1
elif f[current] == 0:
f[current] = time
time +=1
for i in range(n):
print(f'{i+1} {v[i]} {f[i]}')
| 0 | null | 24,740,245,954,180 | 194 | 8 |
import math
s=list(input())
N=len(s)
x=0
for i in range(0,N):
if s[i]!=s[N-1-i]:
x+=1
x=math.ceil(x/2)
print(x) | S=list(input())
N=len(S)
ans=0
for i in range(N):
if S[i]!=S[-i-1]:
ans+=1
print(int(ans/2)) | 1 | 120,495,845,957,190 | null | 261 | 261 |
S = str(input())
l = len(S)
if l % 2 == 0:
A = S[:(l//2)]
B = S[(l//2):]
else:
A = S[:(l//2)]
B = S[(l//2+1):]
B = B[::-1]
ans = 0
for i in range(l//2):
if A[i] != B[i]:
ans += 1
print(ans) | # 147 B
s = input()
k = s[::-1]
n = 0
for i in range(len(s)):
if s[i] != k[i]:
n += 1
# print(s[i])
print(n // 2)
| 1 | 120,237,775,903,298 | null | 261 | 261 |
from sys import stdin
r = int(stdin.readline().rstrip())
print(r**2) | #!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import itertools
import math
import sys
INF = float('inf')
def solve(N: int, A: "List[int]"):
c = collections.Counter(A)
return "\n".join([f'{c[i+1]}' for i in range(N)])
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N - 2 + 1)] # type: "List[int]"
print(solve(N, A))
if __name__ == '__main__':
main()
| 0 | null | 89,156,434,189,020 | 278 | 169 |
x = int(input())
count_500 = 0
count_5 = 0
count_500 = x // 500
x -= 500 * count_500
count_5 = x // 5
x -= 5 * count_5
print(1000 * count_500 + 5 * count_5) | X = int(input())
syou = int(X/500)
syou_second = int((X - syou*500)/5)
ans = syou*1000 + syou_second*5
print(ans) | 1 | 42,859,048,623,104 | null | 185 | 185 |
N = int(input())
X = list(map(int, input().split()))
ans = [0] * (N + 1)
for v in X:
ans[v] += 1
print(*ans[1:], sep="\n")
| import collections
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
c = collections.Counter(a)
l = [0]*n
for i,x in c.items():
l[i-1] = x
for i in l:
print(i) | 1 | 32,596,420,402,336 | null | 169 | 169 |
N = int(input())
A = [int(a) for a in input().split()]
xor = 0
for x in A:
xor ^= x
for v in A:
print(xor^v, end=' ') | import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
N = I()
a = LI()
b = 0
for i in range(N):
b ^= a[i]
print(*[b^a[i] for i in range(N)])
| 1 | 12,441,761,617,932 | null | 123 | 123 |
import sys
for n in sys.stdin:
l=map(int,n.split())
b=l[0]*l[1]
u=[max(l),min(l)]
while u[1]!=0:
u=[u[1],u[0]%u[1]]
print "%d %d"%(u[0],b/u[0]) | # -*- coding: utf-8 -*-
import math
errerN=1
while errerN:
try:
a=list(map(int, input().split()))
gcdN=math.gcd(a[0],a[1])
print(gcdN, int(a[0]*a[1]/gcdN))
except :
errerN=0
| 1 | 569,273,418 | null | 5 | 5 |
import sys
from itertools import accumulate
from collections import defaultdict
input = sys.stdin.readline
N,K=map(int,input().split());A=list(map(int,input().split()))
S_=list(map(lambda t: (t[1]-t[0])%K,enumerate(accumulate([0]+A))))
count=0
C=defaultdict(int)
for t in range(1,N+1):
C[S_[t-1]]+=1
if t-K>=0:
C[S_[t-K]]-=1
count+=C[S_[t]]
print(count)
| import sys
from collections import defaultdict
#+++++
def main():
n, k = map(int, input().split())
aal = list(map(int, input().split()))
sss = [0]*(n+1)
si=0
for i, a in enumerate(aal):
si+=a-1
sss[i+1]=si%k
count=0
mkl_dict=defaultdict(lambda :0)
for j in range(n+1):
sj=sss[j]
if j-k >= 0:
mkl_dict[sss[j-k]]-=1
count += mkl_dict[sj]
mkl_dict[sj] += 1
print(count)
#+++++
isTest=False
def pa(v):
if isTest:
print(v)
if __name__ == "__main__":
if sys.platform =='ios':
sys.stdin=open('inputFile.txt')
isTest=True
else:
pass
#input = sys.stdin.readline
ret = main()
if ret is not None:
print(ret) | 1 | 137,615,554,030,070 | null | 273 | 273 |
n = int(input())
a = list(map(int,input().split()))
mod = 10**9 + 7
c = [n]*61
for i in range(n):
b = str(bin(a[i]))[2:]
b = b[::-1]
for j, x in enumerate(b):
if x == "1":
c[j] -= 1
ans = 0
for i in range(60):
ans += c[i]*(n-c[i])*pow(2,i,mod)
ans %= mod
print(ans)
| n,k = map(int, input().split())
alist=list(map(int, input().split()))
def is_ok(arg):
cnt=0
for i in alist:
cnt+=(i-1)//arg
return cnt<=k
def nibun(ng, ok):
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
return ok
print(nibun(0 , 10**9 + 1)) | 0 | null | 64,591,317,432,612 | 263 | 99 |
while 1:
m,f,r=map(int,input().split());s=m+f
if m==f==r<0:break
if(m*f<0)|(s<30):print('F')
elif(s<50)*(r<50):print('D')
elif s<65:print('C')
elif s<80:print('B')
else:print('A')
| x = int(input())
print((1999-x)//200+1) | 0 | null | 3,944,770,385,188 | 57 | 100 |
while True:
m, f, v = [int(n) for n in input().split()]
if m == f == v == -1:
break
sum = m + f
if m == -1 or f == -1:
print("F")
elif 80 <= sum:
print("A")
elif 65 <= sum < 80:
print("B")
elif 50 <= sum < 65:
print("C")
elif 30 <= sum < 50:
if 50 <= v:
print("C")
else:
print("D")
else:
print("F") | while True:
m, f, r = map(int, input().split())
score = m + f
if m == f == r == -1:
break
elif m == -1 or f == -1:
print('F')
elif score >= 80:
print('A')
elif score >= 65:
print('B')
elif score >= 50 or (score >= 30 and r >= 50):
print('C')
elif score >= 30:
print('D')
else:
print('F')
| 1 | 1,248,300,973,700 | null | 57 | 57 |
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T =input()
com = [0]*N
for i in range(N):
if i>=K and T[i]==T[i-K] and com[i-K]!=0:
continue
elif T[i] =="r":
com[i] =P
elif T[i] =="s":
com[i] =R
else:
com[i] =S
print(sum(com))
| N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
dp = [[0]*3 for _ in range(N+1)]
for i in range(1, N+1):
if i <= K:
dp[i][0] = int(T[i-1]=='s') * R
dp[i][1] = int(T[i-1]=='p') * S
dp[i][2] = int(T[i-1]=='r') * P
else:
dp[i][0] = max(dp[i-K][1], dp[i-K][2]) + int(T[i-1]=='s') * R
dp[i][1] = max(dp[i-K][0], dp[i-K][2]) + int(T[i-1]=='p') * S
dp[i][2] = max(dp[i-K][0], dp[i-K][1]) + int(T[i-1]=='r') * P
ans = 0
for d in dp[-K:]:
ans += max(d)
print(ans) | 1 | 106,948,290,816,902 | null | 251 | 251 |
x = int(input())
for i in range(1,121):
for j in range(-121,121):
if x == i**5 - j**5:
print(i,j)
exit()
| n = int(input())
lst = list(map(int, input().split()))
for i in range(n):
li = lst[i]
j = i-1
while j >= 0 and lst[j] > li:
lst[j:j+2] = lst[j+1], lst[j]
j -= 1
print(*lst) | 0 | null | 12,837,238,091,300 | 156 | 10 |
N = int(input())
S = input()
abc = S.count('R')*S.count('G')*S.count('B')
L = (N-1)//2
for i in range(1,L+1):
for j in range(N-2*i):
if S[j]!=S[j+i] and S[j+i]!=S[j+2*i] and S[j]!=S[j+2*i]:
abc -= 1
print(abc) | import sys
l = []
for i in sys.stdin:
l.append(i.split())
taro = 0
hanako = 0
for i in range(1,len(l)):
if l[i][1] > l[i][0]:
hanako += 3
elif l[i][0] > l[i][1]:
taro += 3
else:
hanako += 1
taro += 1
print(taro,hanako)
| 0 | null | 18,929,762,908,390 | 175 | 67 |
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = [_ for _ in input()]
cnt = 0
for i in range(N):
if i < K or T[i] != T[i-K]:
if T[i] == "r":
cnt += P
elif T[i] == "s":
cnt += R
else:
cnt += S
else:
T[i] = "z"
print(cnt) | import sys
from io import StringIO
import unittest
import os
from collections import deque
# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)
# 実装を行う関数
def resolve(test_def_name=""):
# 数値取得サンプル
# 1行1項目 n = int(input())
# 1行2項目 h, w = 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())
h, w = map(int, input().split())
maze = [list(input()) for i in range(h)]
start_list = []
for i_len, i in enumerate(range(h)):
for j_len, j in enumerate(range(w)):
route = 4
# 自分が壁なら対象外
if maze[i][j] == "#":
continue
# 上下端なら-1
route -= 1 if i_len == 0 else 0
route -= 1 if i_len + 1 == h else 0
# 上下が壁なら-1
route -= 1 if not i_len == 0 and maze[i - 1][j] == "#" else 0
route -= 1 if not i_len + 1 == h and maze[i + 1][j] == "#" else 0
# 左右端なら-1
route -= 1 if j_len == 0 else 0
route -= 1 if j_len + 1 == w else 0
# 左右が壁なら-1
route -= 1 if not j_len == 0 and maze[i][j - 1] == "#" else 0
route -= 1 if not j_len + 1 == w and maze[i][j + 1] == "#" else 0
if route <= 2:
start_list.append((i, j))
ans = 0
que = deque()
for start in start_list:
que.appendleft(start)
ed_list = [[-1 for i in range(w)] for j in range(h)]
ed_list[start[0]][start[1]] = 0
# BFS開始
while len(que) is not 0:
now = que.pop()
# 各方向に移動
for i, j in [(1, 0), (0, 1), (0, -1), (-1, 0)]:
# 処理対象の座標
target = [now[0] + i, now[1] + j]
# 処理対象のチェック
# 外なら何もしない
if not 0 <= target[0] < h or not 0 <= target[1] < w:
continue
# 距離が設定されているなら何もしない
if ed_list[target[0]][target[1]] != -1:
continue
# 壁なら何もしない
if maze[target[0]][target[1]] == "#":
continue
# 処理対象に対する処理
# キューに追加(先頭に追加するのでappendleft())
que.appendleft(target)
# 距離を設定(現在の距離+1)
ed_list[target[0]][target[1]] = ed_list[now[0]][now[1]] + 1
ans = max(ans, ed_list[target[0]][target[1]])
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 3
...
...
..."""
output = """4"""
self.assertIO(test_input, output)
def test_input_2(self):
test_input = """3 5
...#.
.#.#.
.#..."""
output = """10"""
self.assertIO(test_input, output)
# 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
def test_1original_1(self):
test_input = """1 2
.."""
output = """1"""
self.assertIO(test_input, output)
# 実装orテストの呼び出し
if __name__ == "__main__":
if os.environ.get("USERNAME") is None:
# AtCoder提出時の場合
resolve()
else:
# 自PCの場合
unittest.main()
| 0 | null | 100,900,992,224,396 | 251 | 241 |
n = int(input())
h_list = list(map(int,input().split()))
a_dict = dict()
b_dict = dict()
for i in range(n):
a = h_list[i]+i
b = i-h_list[i]
if not a in a_dict:
a_dict[a] = 1
else:
a_dict[a] += 1
if not b in b_dict:
b_dict[b] = 1
else:
b_dict[b] += 1
count = 0
for a in a_dict:
if a in b_dict:
count += a_dict[a]*b_dict[a]
print(count)
| n = int(input())
x = input()
x_popcnt = x.count('1')
one_popcnt = x_popcnt - 1
zero_popcnt = x_popcnt + 1
one_mod = 0
zero_mod = 0
for b in x:
if one_popcnt != 0:
one_mod = (one_mod*2 + int(b)) % one_popcnt
zero_mod = (zero_mod*2 + int(b)) % zero_popcnt
f = [0]*220000
popcnt = [0]*220000
for i in range(1, 220000):
popcnt[i] = popcnt[i//2] + i % 2
f[i] = f[i % popcnt[i]] + 1
for i in range(n-1, -1, -1):
if x[n-1-i] == '1':
if one_popcnt != 0:
nxt = one_mod
nxt -= pow(2, i, one_popcnt)
nxt %= one_popcnt
print(f[nxt]+1)
else:
print(0)
if x[n-1-i] == '0':
nxt = zero_mod
nxt += pow(2, i, zero_popcnt)
nxt %= zero_popcnt
print(f[nxt]+1)
| 0 | null | 17,261,283,907,024 | 157 | 107 |
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
totalA = sum(A)
while totalA > K:
totalA -= A.pop()
ans = len(A)
totalB = 0
for i in range(M):
totalB += B[i]
while totalA + totalB > K:
if not A:
break
totalA -= A.pop()
if totalA + totalB <= K:
ans = max(ans, len(A) + i + 1)
print(ans)
| import sys
input = sys.stdin.readline
def main():
N, M = map(int, input().split())
P = [0] * M
S = [""] * M
for i in range(M):
PS = input().split()
P[i], S[i] = int(PS[0]), PS[1]
AC = [False] * (N + 1)
WA = [0] * (N + 1)
n_AC = 0
n_WA = 0
for p, s in zip(P, S):
if AC[p]:
continue
if s == "AC":
n_AC += 1
AC[p] = True
n_WA += WA[p]
else:
WA[p] += 1
print(n_AC, n_WA)
if __name__ == "__main__":
main()
| 0 | null | 51,914,898,401,810 | 117 | 240 |
from math import ceil
def point(x,y,r,s,p):
if y == 'r':
y = p
if y == 's':
y = r
if y == 'p':
y = s
return ceil(x/2) * y
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = list(input())
ans = 0
for _ in range(k):
l = t[_::k]
x = 1
y = l[0]
for i in l[1:]:
if i != y:
ans += point(x,y,r,s,p)
x = 1
y = i
else:
x += 1
ans += point(x,y,r,s,p)
print(ans) | n, x, m = map(int, input().split())
a = x
s = 0
h = []
h.append(a)
i = 0
fl = 0
while i < n:
s += a
a = (a*a) % m
if a == 0:
break
i += 1
if fl == 0 and a in h:
fl = 1
po = h.index(a)
ss = 0
for j in range(po):
ss += h[j]
s2 = s - ss
f = (n - po) // (i - po)
s2 *= f
s = s2 + ss
i2 = i - po
i2 *= f
i = i2 + po
else:
h.append(a)
print(s) | 0 | null | 54,685,452,363,610 | 251 | 75 |
K,X=input().split()
K=int(K)
X=int(X)
if 500*K>=X:
print('Yes')
else:
print('No') | #!/usr/bin/env python3
print("YNeos"[eval(input().replace(" ","*500<"))::2])
| 1 | 98,281,010,583,328 | null | 244 | 244 |
# encoding:utf-8
while True:
input = map(int, raw_input().split())
x, y = input
if x == y == 0:
break
input.sort()
print(" ".join(map(str, input))) | # coding: utf-8
import sys
i = sys.stdin
for line in i:
a,b = map(int,line.split())
if a == 0 and b == 0: break
if a < b:
print(a,b)
else:
print(b,a) | 1 | 523,051,453,638 | null | 43 | 43 |
x = {"S": list(range(1, 14)), "H": list(range(1, 14)),
"C": list(range(1, 14)), "D": list(range(1, 14))}
n = int(input())
for i in range(n):
tmp = input().split()
key = tmp[0]
num = int(tmp[1])
x[key].remove(num)
keys = ["S", "H", "C", "D"]
for key in keys:
if len(x[key])==0:
pass
else:
for i in x[key]:
print(key, i) | n = int(input())
S = []
H = []
C = []
D = []
for x in range(0,n):
L = raw_input().split()
if L[0] == "S": S.append(int(L[1]))
elif L[0] == "H": H.append(int(L[1]))
elif L[0] == "C": C.append(int(L[1]))
else: D.append(int(L[1]))
for x in range(1,14):
if not x in S: print "S {}".format(x)
for x in range(1,14):
if not x in H: print "H {}".format(x)
for x in range(1,14):
if not x in C: print "C {}".format(x)
for x in range(1,14):
if not x in D: print "D {}".format(x) | 1 | 1,051,222,861,920 | null | 54 | 54 |
"""dfs"""
import sys
sys.setrecursionlimit(10**6)
n = int(input())
to = [[] for _ in range(n)]
eid = [[] for _ in range(n)]
ans = [0]*(n-1)
def dfs(v, c=-1, p=-1): # v:これから見るnode、c:pとvを繋ぐedgeの色、p:親node
k = 1
for i in range(len(to[v])):
u = to[v][i]
ei = eid[v][i]
if u == p: continue # 親nodeは確認済みなので見ない
if k == c: k += 1 # 親nodeとの間のedgeの色と同じではいけないのでインクリメントする
ans[ei] = k
k += 1
dfs(u,ans[ei],v)
for i in range(n-1):
a,b = map(int, input().split())
a -= 1; b -= 1
to[a].append(b); eid[a].append(i) # to:nodeの繋がり、eid:edgeの色
to[b].append(a); eid[b].append(i)
dfs(0)
mx = 0
for i in range(n):
mx = max(mx, len(to[i]))
print(mx)
for i in range(n-1):
print(ans[i]) | from sys import stdin
n = int(input())
r=[int(input()) for i in range(n)]
rv = r[::-1][:-1]
m = None
p_r_j = None
for j,r_j in enumerate(rv):
if p_r_j == None or p_r_j < r_j:
p_r_j = r_j
if p_r_j > r_j:
continue
r_i = min(r[:-(j+1)])
t = r_j - r_i
if m == None or t > m:
m = t
print(m) | 0 | null | 67,699,878,173,760 | 272 | 13 |
import sys
def check(x_list, f, r, v):
x_list[f][r] += v
def peo(x_list):
for i in range(3):
for j in range(10):
sys.stdout.write(" %d" %(x_list[i][j]))
print ("")
A_bill = [[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]
B_bill = [[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]
C_bill = [[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]
D_bill = [[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]
n = input()
for i in range(n):
x = raw_input()
b, f, r, v = x.split()
b = int(b)
f = int(f)
r = int(r)
v = int(v)
if b == 1:
check(A_bill, f-1,r-1,v)
elif b == 2:
check(B_bill, f-1,r-1,v)
elif b == 3:
check(C_bill, f-1,r-1,v)
elif b == 4:
check(D_bill, f-1,r-1,v)
peo(A_bill)
print("####################")
peo(B_bill)
print("####################")
peo(C_bill)
print("####################")
peo(D_bill) | n,m = map(int,input().split())
p=[0]*m
s=[0]*m
for i in range(m):
p[i],s[i]=map(str,input().split())
cor=[0]*n
fal=[0]*n
for i in range(m):
x=int(p[i])
if cor[x-1]==0:
if s[i]=='AC':
cor[x-1]=1
else:
fal[x-1]+=1
ans_cor=0
ans_fal=0
for i in range(n):
if cor[i]==1:
ans_cor+=1
ans_fal+=fal[i]
print(ans_cor,ans_fal) | 0 | null | 47,493,781,308,710 | 55 | 240 |
N = int(raw_input())
count = 0
A_str = raw_input().split()
A = map(int, A_str)
def merge(left, right):
global count
sorted_list = []
l_index = 0
r_index = 0
while l_index < len(left) and r_index < len(right):
count += 1
if left[l_index] <= right[r_index]:
sorted_list.append(left[l_index])
l_index += 1
else:
sorted_list.append(right[r_index])
r_index += 1
if len(left) != l_index:
sorted_list.extend(left[l_index:])
count += len(left[l_index:])
if len(right) != r_index:
sorted_list.extend(right[r_index:])
count += len(right[r_index:])
return sorted_list
def mergeSort(A):
if len(A) <= 1:
return A
mid = len(A) // 2
left = A[:mid]
right = A[mid:]
left = mergeSort(left)
right = mergeSort(right)
return list(merge(left, right))
print ' '.join(map(str, mergeSort(A)))
print count | def merge(a, left, mid, right):
INF = int(1e+11)
l = a[left:mid]
r = a[mid:right]
l.append(INF)
r.append(INF)
i = 0
j = 0
ans = 0
for k in range(left, right):
ans += 1
if l[i] <= r[j]:
a[k] = l[i]
i += 1
else:
a[k] = r[j]
j += 1
return ans
def merge_sort(a, left, right):
ans = 0
if left + 1 < right:
mid = (left + right) // 2
ans += merge_sort(a, left, mid)
ans += merge_sort(a, mid, right)
ans += merge(a, left, mid, right)
return ans
def print_list_split_whitespace(s):
for x in s[:-1]:
print(x, end=" ")
print(s[-1])
n = int(input())
s = [int(x) for x in input().split()]
ans = merge_sort(s, 0, len(s))
print_list_split_whitespace(s)
print(ans)
| 1 | 114,088,801,748 | null | 26 | 26 |
kazu=int(input())
A=[int(i) for i in input().split()]
# kazu=6
# A=[5,2,4,6,1,3]
j=0
for i in range(kazu - 1):
print(A[i], end=" ")
print(A[kazu-1])
for i in range(1,kazu):
v=A[i]
j=i-1
while j>=0 and A[j] >v:
A[j+1]=A[j]
j =j -1
A[j+1]=v
for i in range(kazu-1):
print(A[i],end=" ")
print(A[kazu-1]) | import sys
a = ""
l = []
for input in sys.stdin:
a += input
l = a.split()
b = int(l[0])
l = l[1:]
for i in range(0,b):
key = int(l[i])
j = i - 1
while(j >= 0 and int(l[j]) > key):
l[j+1] = l[j]
j = j - 1
l[j+1] = key
if(b > 0):
for data in l:
print int(data),
print
b = b-1
| 1 | 5,747,664,670 | null | 10 | 10 |
import sys
rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
flag = False
s = rr()
q = ri()
front = ''
end = ''
for _ in range(q):
query = list(rs())
if query[0] == '1':
flag = not flag
continue
else:
f = int(query[1])
c = query[-1]
if flag == True:
if f == 1:
end += c
else:
front = c+front
else:
if f == 1:
front = c+front
else:
end += c
if flag:
print((front+s+end)[::-1])
else:
print(front+s+end) | N, K, C = map(int, input().split())
S = input()
L = [0]*K
R = [0]*K
lpiv = 0
rpiv = N-1
for i in range(K):
while S[lpiv] == 'x':
lpiv += 1
while S[rpiv] == 'x':
rpiv -= 1
L[i] = lpiv
R[i] = rpiv
lpiv += C+1
rpiv -= C+1
ans = 0
for i in range(K):
if L[i]==R[K-i-1]:
print(L[i]+1)
| 0 | null | 49,015,105,511,512 | 204 | 182 |
a, b = [int(i) for i in input().split(" ")]
num1 = a // b
num2 = a % b
num3 = "{:.8f}".format(a / b)
print(num1, num2, num3) | n=int(input())
l=list(map(int,input().split()))
m=n//2
t=n%2+2
dp=[0]*t
for i in range(m):
for j in range(t):
dp[j]+=l[2*i+j]
for j in range(1,t):
dp[j]=max(dp[j],dp[j-1])
print(dp[-1]) | 0 | null | 19,139,348,100,258 | 45 | 177 |
s = input()
a = list(s)
for i in range(len(s)):
a[i] = 'x'
ans = "".join(a)
print(ans) | S = input()
l = len(S)
ans = "x" * l
print(ans)
| 1 | 72,674,137,681,412 | null | 221 | 221 |
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
import random
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7
def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def main():
K = int(input())
print("ACL" * K)
if __name__ == "__main__":
main()
| k=int(input())
line="ACL"*k
print(line) | 1 | 2,179,731,708,574 | null | 69 | 69 |
#coding:utf-8
#????????¢?????????
def draw_square(h, w):
for i in range(h):
a = ""
for j in range(w):
a += "#"
print a
while 1:
HW = raw_input().split()
H = int(HW[0])
W = int(HW[1])
if H == 0 and W == 0:
break
draw_square(H, W)
print "" | def solve(n):
ans = 0
for i in range(1, n+1):
if (i % 3 == 0 and i % 5 == 0) or (i % 3 == 0) or (i % 5 == 0):
continue
else:
ans += i
print(ans)
if __name__ == "__main__":
n = int(input())
solve(n) | 0 | null | 17,750,674,205,254 | 49 | 173 |
x = int(input())
ans = 0
ans += 1000*(x//500)
x %= 500
ans += 5*(x//5)
print(ans) | W, H, x, y, r = [int(i) for i in input().split()]
if r <= y <= H - r and r <= x <= W - r:
print('Yes')
else:
print('No') | 0 | null | 21,750,139,967,750 | 185 | 41 |
n = int(input())
aa = []
bb = []
for _ in range(n):
a, b = map(int, input().split())
aa.append(a)
bb.append(b)
aa.sort()
bb.sort()
if n % 2 == 1:
ac = aa[n // 2]
bc = bb[n // 2]
print(abs(ac - bc) + 1)
else:
ac1 = aa[n // 2 - 1]
bc1 = bb[n // 2 - 1]
ac2 = aa[n // 2]
bc2 = bb[n // 2]
print((bc2 + bc1) - (ac2 + ac1) + 1)
| def counter(s):
cnt = 0
flag = 0
for i in range(1, len(s)):
if flag == 1:
flag = 0
else:
if s[i] == s[i-1]:
cnt += 1
flag = 1
return cnt * k
s = str(input())
k = int(input())
if len(set(s)) == 1:
ans = len(s) * k // 2
else:
if k == 1 or s[0] != s[-1]:
ans = counter(s)
else:
l = 0
r = 0
for i in range(len(s)):
if s[i] == s[0]:
l += 1
else:
break
for j in range(len(s)-1, 0, -1):
if s[j] == s[0]:
r += 1
else:
break
ans = counter(s[l:-r])
ans += l // 2 + r // 2 + (l + r) // 2 * (k - 1)
print(ans)
| 0 | null | 96,517,115,615,928 | 137 | 296 |
import numpy as np
import sys
read = sys.stdin.read
def solve(stdin):
h, w, m = stdin[:3]
row = np.zeros(h, np.int)
col = np.zeros(w, np.int)
for i in range(3, m * 2 + 3, 2):
y, x = stdin[i: i + 2] - 1
row[y] += 1
col[x] += 1
max_cnt_y = max(row)
max_cnt_x = max(col)
max_pair = np.sum(row == max_cnt_y) * np.sum(col == max_cnt_x)
for i in range(3, m * 2 + 3, 2):
y, x = stdin[i: i + 2] - 1
if row[y] == max_cnt_y and col[x] == max_cnt_x:
max_pair -= 1
return max_cnt_y + max_cnt_x - (max_pair == 0)
print(solve(np.fromstring(read(), dtype=np.int, sep=' '))) | import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()
def main():
H, W, M = map(int, input().split())
bombs = []
hs = [0] * H
ws = [0] * W
for _ in range(M):
h, w = map(int, input().split())
bombs.append(tuple([h-1, w-1]))
hs[h-1] += 1
ws[w-1] += 1
maxh = max(hs)
maxw = max(ws)
ans = maxh + maxw
maxhindex = [i for i, x in enumerate(hs) if x == maxh]
maxwindex = [i for i, x in enumerate(ws) if x == maxw]
bombs = set(bombs)
for i in maxhindex:
for j in maxwindex:
if (i, j) not in bombs:
print(ans)
exit()
print(ans-1)
if __name__ == '__main__':
main() | 1 | 4,682,519,351,630 | null | 89 | 89 |
r=input().split()
N=int(r[0])
D=int(r[1])
ans=0
d=[input().split() for i in range(N)]
for i in range(N):
if int(d[i][1])**2+int(d[i][0])**2<=D**2:
ans+=1
print(ans) | a,b,c,d = list(map(int,input().split()))
t_win_turn = c // b
if c % b > 0:
t_win_turn += 1
a_win_turn = a // d
if a % d > 0:
a_win_turn += 1
if t_win_turn <= a_win_turn:
print('Yes')
else:
print('No')
| 0 | null | 17,933,877,040,288 | 96 | 164 |
S = int(input())
s = S%60
m = (S-s)/60%60
h = S/3600%24
answer = str(int(h))+":"+str(int(m))+":"+str(s)
print(answer)
| s = int(input());
print str(s/3600) + ':' + str((s%3600)/60) + ':' + str((s%3600)%60) | 1 | 325,006,499,868 | null | 37 | 37 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
# import decimal
# from decimal import Decimal
# decimal.getcontext().prec = 10
# from heapq import heappush, heappop, heapify
# import math
# from math import gcd
# import itertools as it
# import collections
# from collections import deque
def inp():
return int(input())
def inps():
return input().rstrip()
def inpl():
return list(map(int, input().split()))
def _debug(obj):
print(obj, file=sys.stderr)
# ---------------------------------------
X = inp()
for i in range(-120, 120):
for j in range(-120, 120):
if i**5 - j**5 == X:
print(i, j)
sys.exit() | x = int(input())
min_x = -int(pow(x,0.2))-1
for a in range(x):
for b in range(min_x,x):
test = pow(a,5) - pow(b,5)
if b > 0 and test < x:
break
if test == x:
print(a,b)
exit() | 1 | 25,611,060,494,322 | null | 156 | 156 |
import math
N = int(input())
s = 0
# def devisor(x):
# count = 0
# for i in range(1,math.floor(math.sqrt(x))+1):
# if (x % i) == 0:
# count += 2
# if i**2 == x:
# count -= 1
# return count
# for i in range(1, N+1):
# s += i * devisor(i)
for i in range(1,N+1):
y = math.floor(N/i)
s += y*(y+1)*i//2
print(s) | n = int(input())
answer = 0
for i in range(1, n+1):
md = n // i
answer += i * (md *(md+1) // 2)
print(answer) | 1 | 11,026,678,517,888 | null | 118 | 118 |
a = int(input())
b = int(input())
t = set([1, 2, 3])
s = set([a,b])
ans = t - s
print(list(ans)[0]) | N = int(input())
print(N**2) | 0 | null | 128,067,006,401,650 | 254 | 278 |
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() | x,k,d = map(int, input().split())
x = abs(x)
if x - d*k >= 0:
print(abs(x-d*k))
else:
a = x // d
if k % 2 == 0:
if a % 2 == 0:
print(abs(x - d*a))
else:
print(abs(x - d * (a+1)))
else:
if a % 2 == 0:
print(abs(x - d * (a + 1)))
else:
print(abs(x - d * a))
| 0 | null | 11,415,201,117,430 | 138 | 92 |
N = int(input())
A = list(map(int, input().split()))
if N == 0:
if A[0] == 1:
print (1)
exit()
else:
print (-1)
exit()
MAX = 10 ** 18
lst = [1] * (10 ** 5 + 10)
#純粋な2分木としたときの最大値
for i in range(N + 1):
lst[i + 1] = min(MAX, lst[i] * 2)
# print (lst[:10])
for i in range(N + 1):
tmp = lst[i] - A[i]
if tmp < 0:
print (-1)
exit()
lst[i + 1] = min(lst[i + 1], tmp * 2)
# print (lst[:10])
if lst[N] >= A[N]:
lst[N] = A[N]
else:
print (-1)
exit()
# print (lst[:10])
ans = 1
tmp = 0
for i in range(N, 0, -1):
ans += lst[i]
lst[i - 1] = min(lst[i] + A[i - 1], lst[i - 1])
# print (lst[:10])
print (ans)
| import sys
import itertools
sys.setrecursionlimit(10 ** 8)
ni = lambda: int(sys.stdin.readline())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
ns = lambda: sys.stdin.readline().rstrip()
dbg = lambda *args, **kwargs: print(*args, **kwargs, file=sys.stderr)
N = ni()
A = nl()
assert len(A) == (N + 1)
def solve():
ar = list(itertools.accumulate(A[::-1]))
ar.reverse()
ar.append(0)
assert len(ar) == (N + 2)
if N == 0:
return 1 if A[0] == 1 else -1
if A[0] != 0:
return -1
inn = ans = 1
for i in range(1, N + 1):
b = 2 * inn - A[i]
if b < 0:
return -1
inn = min(b, ar[i + 1])
ans += inn + A[i]
return ans
print(solve())
| 1 | 18,782,633,957,780 | null | 141 | 141 |
import math
H = int(input())
W = int(input())
N = int(input())
for i in range(1, max(H, W)+1):
if(max(H, W)*i >= N):
print(i)
break | from sys import stdin
H = int(stdin.readline().rstrip())
W = int(stdin.readline().rstrip())
N = int(stdin.readline().rstrip())
if N%(max(H,W))==0:
print(N//(max(H,W)))
else:
print(N//(max(H,W))+1) | 1 | 88,716,312,121,892 | null | 236 | 236 |
N = int(input())
s = [input() for i in range(N)]
S = [[0]*len(s[i]) for i in range(N)]
for i, x in enumerate(s):
res = []
q = 0
for j in range(len(x)):
if x[j] == ')':
S[i][j] = -1
else:
S[i][j] = 1
s = [0]*N
m = [len(S[i]) for i in range(N)]
for i, x in enumerate(S):
tmp = 0
for j in range(len(x)):
tmp += S[i][j]
m[i] = min(tmp, m[i])
s[i] = tmp
if sum(s) == 0:
sp = [(m[i], s[i]) for i in range(N) if s[i] > 0]
mp = [(-(s[i]-m[i]), -s[i]) for i in range(N) if s[i] <= 0]#右から見た場合
sp.sort(key=lambda x: x[0], reverse=True)
tmp = 0
for x, y in sp:
if tmp + x < 0:
print("No")
exit(0)
tmp += y
mp.sort(key=lambda x: x[0], reverse=True)
tmp2 = 0
for x, y in mp:
if tmp2 + x < 0:
print("No")
exit(0)
tmp2 += y
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,597,355,832,038 | null | 152 | 152 |
N = input()
K = int(input())
dp = [[[0 for _ in range(5)] for _ in range(2)] for _ in range(len(N)+1)]
dp[0][0][0] = 1
for i in range(len(N)):
dgt = int(N[i])
for k in range(K+1):
dp[i+1][1][k+1] += dp[i][1][k] * 9
dp[i+1][1][k] += dp[i][1][k]
if dgt > 0:
dp[i+1][1][k+1] += dp[i][0][k] * (dgt-1)
dp[i+1][1][k] += dp[i][0][k]
dp[i+1][0][k+1] = dp[i][0][k]
else:
dp[i+1][0][k] = dp[i][0][k]
print(dp[len(N)][0][K] + dp[len(N)][1][K])
| n=list(input())
N=len(n)
k=int(input())
dp1=[[0 for i in range(k+1)] for j in range(N+1)]
dp2=[[0 for i in range(k+1)] for j in range(N+1)]
dp1[0][0]=1
for i in range(1,N+1):
x=int(n[i-1])
if i!=N and x!=0:
for j in range(k+1):
if j==0:
dp2[i][j]=dp1[i-1][j]+dp2[i-1][j]
else:
dp1[i][j]=dp1[i-1][j-1]
dp2[i][j]=dp1[i-1][j]+dp1[i-1][j-1]*(x-1)+dp2[i-1][j]+dp2[i-1][j-1]*9
elif i!=N and x==0:
for j in range(k+1):
if j==0:
dp1[i][j]=dp1[i-1][j]
dp2[i][j]=dp2[i-1][j]
else:
dp1[i][j]=dp1[i-1][j]
dp2[i][j]=dp2[i-1][j]+dp2[i-1][j-1]*9
elif i==N and x!=0:
for j in range(k+1):
if j==0:
dp2[i][j]=dp1[i-1][j]+dp2[i-1][j]
else:
dp2[i][j]=dp1[i-1][j]+dp1[i-1][j-1]*x+dp2[i-1][j]+dp2[i-1][j-1]*9
else:
for j in range(k+1):
if j==0:
dp2[i][j]=dp2[i-1][j]
else:
dp2[i][j]=dp1[i-1][j]+dp2[i-1][j]+dp2[i-1][j-1]*9
print(dp2[N][k]) | 1 | 75,636,102,450,428 | null | 224 | 224 |
import sys
s = ''
for line in sys.stdin:
s += line
s = s.lower()
count = {letter: s.count(letter) for letter in set(s)}
for c in range(97,97+26):
if chr(c) in count:
print("%c : %d" % (chr(c), count[chr(c)]))
else:
print("%c : 0" % chr(c)) | s = []
while 1:
try :
x = raw_input()
except :
break
s.append(x.lower())
s = ''.join(s)
for i in range(26):
c = chr(i + 97)
print '%s : %d' % (c , s.count(c)) | 1 | 1,655,495,407,652 | null | 63 | 63 |
h,n = map(int, input().split())
a = [int(i) for i in input().split()]
print("No" if sum(a)<h else "Yes") | H, N = map(int, input().split())
special_move = input().split()
def answer(H: int, N: int, special_move: list) -> str:
damage = 0
for i in range(0, N):
damage += int(special_move[i])
if damage >= H:
return 'Yes'
else:
return 'No'
print(answer(H, N, special_move)) | 1 | 77,927,385,591,042 | null | 226 | 226 |
n,k=map(int,input().split())
DIV = 10**9+7
count = 0
for i in range(k,n+2):
min_k = i*(i-1)/2
max_k = i*(2*n-i+1)/2
count += max_k - min_k + 1
print(int(count % DIV)) | #!/usr/bin/env python3
import sys
input = sys.stdin.readline
mod = 1000000007
def ST():
return input().rstrip()
def I():
return int(input())
def MI():
return map(int, input().split())
def LI():
return list(MI())
N, K = MI()
MAX = sum(range(N - K + 2, N + 1))
MIN = sum(range(0, K - 1))
ans = 0
for k in range(K, N + 2):
MAX += N - k + 1
MIN += k - 1
ans += (MAX - MIN + 1) % mod
print(ans % mod)
| 1 | 33,201,782,801,980 | null | 170 | 170 |
from math import *
a,b,C=map(int,raw_input().split())
C = radians(C)
print (0.5)*a*b*sin(C)
print sqrt(a**2+b**2-2*a*b*cos(C)) + a + b
h = b*sin(C)
print h | N = int(input())
print('ACL' * N) | 0 | null | 1,181,068,678,468 | 30 | 69 |
# -*- coding: utf-8 -*-
# F
import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
from itertools import accumulate, combinations
input = sys.stdin.readline
mod = 998244353
N, S = map(int, input().split())
A = list(map(int, input().split()))
dp = [[0] * (S+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(1, N+1):
for j in range(S+1):
dp[i][j] += dp[i-1][j] * 2
if j + A[i-1] <= S:
dp[i][j+A[i-1]] += dp[i-1][j]
dp[i][j] %= mod
# print(dp)
print(dp[-1][S] % mod)
| import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 998244353
DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def main():
N, S = LI()
a = LI()
dp = [[0 for _ in range(S+1)] for _ in range(N+1)]
for i in range(1, N+1):
dp[i][0] = dp[i-1][0] * 2 + 1
dp[i][0] %= mod
for i in range(N):
for j in range(1, S+1):
if j - a[i] >= 0:
dp[i+1][j] = (dp[i][j-a[i]] % mod) + (dp[i][j] * 2 % mod)
else:
dp[i+1][j] = dp[i][j] * 2 % mod
if j == a[i]:
dp[i+1][j] += 1
dp[i+1][j] %= mod
print(dp[N][S])
main()
| 1 | 17,628,239,748,540 | null | 138 | 138 |
A=int(input())
#pr#print(A)
int(A)
B=int(input())
if A + B == 3:
print(3)
elif A+B==4:
print(2)
else:
print(1)
| n=int(input())
a,b=map(str,input().split())
s=''
for i in range(n):
s+=a[i]
s+=b[i]
print(s) | 0 | null | 111,347,162,276,880 | 254 | 255 |
N=int(input())
D=list(map(int,input().split()))
print((sum(D)**2-sum(d*d for d in D))//2) | S=input()
i=len(S)-1
if S[i]=="s":
out=S+"es"
else:
out=S+"s"
print(out) | 0 | null | 85,648,006,853,322 | 292 | 71 |
n, m = map(int, input().split())
ac = [0] * n
wa = [0] * n
for _ in range(m):
p, s = input().split()
if s == 'AC':
ac[int(p) - 1] = 1
elif ac[int(p) - 1] == 0:
wa[int(p) - 1] += 1
for i in range(n):
if ac[i] == 0:
wa[i] = 0
print(sum(ac), sum(wa)) | import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
solved = [False] * (n + 1)
wa = [0] * (n + 1)
for i in range(m):
p_str, s = input().split()
p = int(p_str)
if s == "AC":
solved[p] = True
else:
if not solved[p]:
wa[p] += 1
ac = 0
pe = 0
for i in range(1, n+1):
if solved[i]:
ac += 1
pe += wa[i]
print(ac, pe) | 1 | 93,658,479,500,428 | null | 240 | 240 |
def main():
n = int(input())
a_list = []
b_list = []
for _ in range(n):
a, b = map(int, input().split())
a_list.append(a)
b_list.append(b)
a_sorted = list(sorted(a_list))
b_sorted = list(sorted(b_list))
if n%2:
print(b_sorted[n//2]-a_sorted[n//2]+1)
else:
print((b_sorted[n//2-1]+b_sorted[n//2]-a_sorted[n//2-1]-a_sorted[n//2])+1)
if __name__ == "__main__":
main() | from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque
from operator import mul
from functools import reduce
n = int(input())
m = 0
for i in range(1,n+1):
a = n // i
m += a*(a+1)*i//2
print(m) | 0 | null | 14,289,426,594,290 | 137 | 118 |
# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np
# import heapq
# from collections import deque
N = int(input())
# S = input()
# n, *a = map(int, open(0))
# N, M = map(int, input().split())
A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()
# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)
# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)
# def dfs(tree, s):
# for l in tree[s]:
# if depth[l[0]] == -1:
# depth[l[0]] = depth[s] + l[1]
# dfs(tree, l[0])
# dfs(tree, 1)
# def factorization(n):
# arr = []
# temp = n
# for i in range(2, int(-(-n**0.5//1))+1):
# if temp%i==0:
# cnt=0
# while temp%i==0:
# cnt+=1
# temp //= i
# arr.append([i, cnt])
# if temp!=1:
# arr.append([temp, 1])
# if arr==[]:
# arr.append([n, 1])
# return arr
A.insert(0, 0)
cnt = [0] * (N + 1)
ans = 0
for i in range(1, N + 1):
if i - A[i] >= 0:
ans += cnt[i - A[i]]
if i + A[i] <= N:
cnt[i + A[i]] += 1
print(ans) | current_l = 0
stack_s = []
stack_each_area = []
areas = []
for s in input():
# print(stack_each_area)
if(s == '\\'):
stack_s.append(current_l)
elif(s == '/'):
if(len(stack_s)==0):
continue
left_edge = stack_s.pop(-1)
area = current_l - left_edge
areas.append(area)
merged_area = area
merged_j = []
for j in range(len(stack_each_area)):
if( left_edge < stack_each_area[j][0] and stack_each_area[j][0] < current_l):
merged_area += stack_each_area[j][1]
merged_j.append(j)
for del_j in merged_j[::-1]:
del stack_each_area[del_j]
stack_each_area.append((current_l, merged_area))
current_l += 1
print(sum(areas))
if(len(stack_each_area) != 0):
print(len(stack_each_area), " ".join([ str(lm[1]) for lm in stack_each_area]))
else:
print(0)
| 0 | null | 13,085,253,141,312 | 157 | 21 |
n = int(input())
# R[0]
minv = int(input())
maxv = - 10 ** 10
# R[1..N-1]
for j in range(1, n):
r = int(input())
maxv = max(maxv, r - minv)
minv = min(minv, r)
print(maxv) | num = raw_input()
num_list = []
for i in range(int(num)):
a = raw_input()
num_list.append(int(a))
min_ans = num_list[0]
max_ans = float("-inf")
for i in num_list[1:]:
if i - min_ans > max_ans:
max_ans = i - min_ans
if i < min_ans:
min_ans = i
print max_ans | 1 | 12,654,439,118 | null | 13 | 13 |
n, k = map(int, input().split())
a = list(map(int, input().split()))
def cut(x):
cut_count = 0
for i in range(n):
cut_count += (a[i]-1)//x
return cut_count
l = 0
r = 10**9
while r-l > 1:
mid = (l+r)//2
if k >= cut(mid):
r = mid
else:
l = mid
print(r)
| while True:
try:
s=input().split(" ")
num=int(s[0])+int(s[1])
print(len(str(num)))
except:
break
| 0 | null | 3,209,738,580,060 | 99 | 3 |
(A,B)=input().split()
(A,B)=(int(A),int(B))
if 1<=A<=9 and 1<=B<=9:
print(A*B)
else:
print(-1) | A, B = map(int, input().split())
print(A * B if A < 10 and B < 10 else '-1') | 1 | 158,493,585,024,218 | null | 286 | 286 |
from decimal import *
import math
getcontext().prec=1000
a,b,c=map(int,input().split())
if a+b+2*Decimal(a*b).sqrt()<c:
print("Yes")
else:
print("No")
| import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict
def main():
n, *a = map(int, read().split())
maxa = max(a) + 1 # aはint配列
d = [i for i in range(maxa)]
for p0 in range(2, maxa):
if p0 == d[p0]:
for p1 in range(p0 ** 2, maxa, p0):
if d[p1] % p0 == 0:
d[p1] = p0
def factorization(f): # f > maxaだとエラー
l = []
t = f
while True:
if t == d[t]:
l.append(d[t])
break
else:
l.append(d[t])
t = t // d[t]
return l
if all([i == 1 for i in a]):
print('pairwise coprime')
sys.exit()
if len(set(a)) == 1:
print('not coprime')
sys.exit()
d1 = defaultdict(int)
for ae in a:
t1 = set(factorization(ae))
for t1e in t1:
d1[t1e] += 1
if 1 in a:
d1[1] = 1
d1v = tuple(d1.values())
if all([i == 1 for i in d1v]):
print('pairwise coprime')
elif max(d1v) == n:
print('not coprime')
else:
print('setwise coprime')
if __name__ == '__main__':
main() | 0 | null | 27,831,959,115,620 | 197 | 85 |
import sys
input = sys.stdin.readline
n = int(input())
ans = 0
for i in range(1, n):
ans += (n-1) // i
print(ans) | A,B,K = list(map(int,input().split()))
if A>= K:
print(str(A-K) + ' ' + str(B))
elif A < K :
print(str(0) + ' ' + str(max(B+A-K,0)))
| 0 | null | 53,156,327,584,640 | 73 | 249 |
list = input().split()
print(list[2],list[0],list[1]) | def main():
N = int(input())
total = 0
for i in range(N):
i = i + 1
if i % 3 == 0 and i % 5 == 0:
continue
elif i % 3 == 0:
continue
elif i % 5 == 0:
continue
total = total + i
print(total)
main() | 0 | null | 36,601,848,671,130 | 178 | 173 |
N = int(input())
A = list(map(int,input().split()))
ans = "APPROVED"
for n in range(N):
if A[n] %2 == 0:
if A[n] % 3 != 0 and A[n] % 5 != 0:
ans = "DENIED"
break
print(ans) | N = int(input())
S = list(map(int,input().split()))
B= list()
X = list()
for i in S:
if i % 2== 0:
B.append(i)
for n in B:
if n % 3 == 0 or n % 5 == 0:
X.append(n)
if len(B) == len(X):
print('APPROVED')
else:
print('DENIED')
| 1 | 68,783,303,639,760 | null | 217 | 217 |
def give_grade(m, f, r):
if m == -1 or f == -1:
return "F"
elif m + f < 30:
return "F"
elif m + f < 50:
return "D" if r < 50 else "C"
elif m + f < 65:
return "C"
elif m + f < 80:
return "B"
else:
return "A"
while True:
m, f, r = map(int, input().split())
if m == f == r == -1:
break
else:
print(give_grade(m, f, r)) | while True:
m, f, r = (int(x) for x in input().split())
if (m, f, r) == (-1, -1, -1):
break
sum_score = m + f
if m == -1 or f == -1:
print("F")
elif sum_score >= 80:
print("A")
elif 65 <= sum_score < 80:
print("B")
elif 50 <= sum_score < 65:
print("C")
elif 30 <= sum_score < 50:
print("C") if r >= 50 else print("D")
else:
print("F") | 1 | 1,217,452,954,350 | null | 57 | 57 |
m1, d1 = map(int, input().split())
m2, d2 = map(int, input().split())
if m1 + 1 == m2 and d2 == 1:
print(1)
else:
print(0) | M1, D1 = list(map(int, input().split()))
M2, D2 = list(map(int, input().split()))
ans = 1 if M1 + 1 == M2 else 0
print(ans) | 1 | 124,617,462,950,428 | null | 264 | 264 |
if __name__ == '__main__':
n = int(input())
R = [int(input()) for i in range(n)]
minv = R[0]
maxv = R[1] - R[0]
for j in range(1, n):
if (maxv < R[j] - minv):
maxv = R[j] - minv
if (R[j] < minv):
minv = R[j]
print(maxv) | #akash mandal: jalpaiguri government engineering college
import sys,math
def ii(): return int(input())
def mii(): return map(int,input().split())
def lmii(): return list(mii())
def main():
A,B,C=mii()
print("Yes" if B*C>=A else "No")
if __name__=="__main__":
main() | 0 | null | 1,748,601,469,058 | 13 | 81 |
from sys import stdin, stdout
import math,sys,heapq
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict
from os import path
import bisect as bi
def yes():print('YES')
def no():print('NO')
if (path.exists('input.txt')):
#------------------Sublime--------------------------------------#
sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');
def I():return (int(input()))
def In():return(map(int,input().split()))
else:
#------------------PYPY FAst I/o--------------------------------#
def I():return (int(stdin.readline()))
def In():return(map(int,stdin.readline().split()))
def dict(a):
d={}
for x in a:
if d.get(x,-1)!=-1:
d[x]+=1
else:
d[x]=1
return d
def find_gt(a, x):
'Find leftmost value greater than x'
i = bi.bisect_right(a, x)
if i != len(a):
return i
else:
return -1
def main():
try:
a,b,c=In()
k=I()
t1,t2=0,0
if a>=b:
t1=0
while b<=a:
b*=2
t1+=1
if b>=c:
t2=0
while c<=b:
c*=2
t2+=1
#print(a,b,c)
if a<b and b<c:
if t1+t2<=k:
print('Yes')
else:
print('No')
else:
print('No')
except:
pass
M = 998244353
P = 1000000007
if __name__ == '__main__':
#for _ in range(I()):main()
for _ in range(1):main()
| a, b, c = map(int, input().split())
k = int(input())
flg = False
c = (2**k) * c
for i in range(k):
if a < b < c:
flg = True
break
b *= 2
c //= 2
if flg:
print('Yes')
else:
print('No')
| 1 | 6,943,721,208,928 | null | 101 | 101 |
import sys
# input = sys.stdin.readline
def main():
S, T =input().split()
print(T,S,sep="")
if __name__ == "__main__":
main() | n = input()
if (sum(map(int, n))) % 9 == 0:
print("Yes")
else:
print("No") | 0 | null | 53,516,102,793,570 | 248 | 87 |
s = input()
if s[0] != '7' and s[1] != '7' and s[2] != '7':
print('No')
else:
print('Yes') | from sys import exit
for i in input():
if i == '7':
print('Yes')
exit()
print('No')
| 1 | 34,289,639,794,748 | null | 172 | 172 |
# coding: utf-8
# Your code here!
import math
num = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
result = 0
for i in range(num):
result += abs(y[i]-x[i])
print(result)
result = 0
for i in range(num):
result += abs(y[i] - x[i]) ** 2
result = math.sqrt(result)
print(result)
result = 0
for i in range(num):
result += abs(y[i] - x[i]) ** 3
result = math.pow(result,1.0/3.0)
print(result)
result = 0
for i in range(num):
if i == 0:
result = abs(y[i] - x[i])
else:
if abs(y[i] - x[i]) > result:
result = abs(y[i] - x[i])
print(result)
| input();print(input().count('ABC')) | 0 | null | 49,564,912,213,920 | 32 | 245 |
import collections
calc_time = 0
hoge = collections.deque()
num, q = [int(x) for x in input().split()]
for _ in range(num):
name, t = input().split()
hoge.append([name, int(t)])
while hoge:
name, t = hoge.popleft()
if t - q > 0:
hoge.append([name, t-q])
calc_time += q
elif t == q:
calc_time += q
print ('{} {}'.format(name, calc_time))
elif t - q < 0:
calc_time += t
print ('{} {}'.format(name, calc_time))
| n = int(input())
dic = {}
for i in range(1,50000):
dic[int(i * 1.08)] = i
if n in dic:
print(dic[n])
else:
print(':(') | 0 | null | 62,872,178,400,668 | 19 | 265 |
import sys
def input():
return sys.stdin.readline()[:-1]
n = int(input())
plus, minus = [], []
for _ in range(n):
s = input()
mi, cur = 0, 0
for i in range(len(s)):
if s[i] == "(":
cur += 1
else:
cur -= 1
mi = min(mi, cur)
if cur >= 0:
plus.append((mi, cur))
else:
minus.append((mi, cur))
plus.sort(key=lambda x: -x[0])
minus.sort(key=lambda x: x[0] - x[1])
res = plus + minus
cur = 0
for m, t in res:
if cur + m < 0:
print("No")
exit()
cur += t
if cur != 0:
print("No")
exit()
print("Yes") | def selection_sort(A):
count = 0
for i in range(len(A)):
min_value = A[i]
min_value_index = i
# print('- i:', i, 'A[i]', A[i], '-')
for j in range(i, len(A)):
# print('j:', j, 'A[j]:', A[j])
if A[j] < min_value:
min_value = A[j]
min_value_index = j
# print('min_value', min_value, 'min_value_index', min_value_index)
if i != min_value_index:
count += 1
A[i], A[min_value_index] = A[min_value_index], A[i]
# print('swap!', A)
return count
n = int(input())
A = list(map(int, input().split()))
count = selection_sort(A)
print(*A)
print(count)
| 0 | null | 11,841,631,439,872 | 152 | 15 |
w,h,x,y,r=map(int,input().split())
print(['No','Yes'][r<=x<=w-r and r<=y<=h-r]) | w,h,x,y,r = map(int, input().split())
if x>= r and y >= r and x+r <= w and y+r <= h:
print('Yes')
else:
print('No')
| 1 | 449,847,508,982 | null | 41 | 41 |
n, m = map(int, input().split())
a = [int(x) for x in input().split()]
s = sum(a)
print('Yes' if len(list(filter(lambda x : x >= s * (1/(4*m)), a))) >= m else 'No') | import sys
for line in sys.stdin:
a, b = map(int, line.split())
digitNumber = len(str(a + b))
print(digitNumber) | 0 | null | 19,315,746,704,992 | 179 | 3 |
n = int(input())
g = n // 2
print((n-g) / n) | n,m,k = list(map(int,input().split(" ")))
a = list(map(int,input().split(" ")))
b = list(map(int,input().split(" ")))
cnt = 0
ans = 0
j = m
t = sum(b)
for i in range(n+1):
while j>0:
if t>k: #aのみの場合の処理が足りない(常にjでスキップされてしまう)
j -= 1
t -= b[j]
else:break
if t<=k:ans = max(ans,i+j)
if i==n:break
t += a[i]
print(ans) | 0 | null | 94,251,378,426,518 | 297 | 117 |
n = int(input())
l = sorted([int(i) for i in input().split(' ')])
if len(l) < 3:
print(0)
exit()
count = 0
for i in range(0, (n - 2)):
for j in range((i + 1), (n - 1)):
if l[i] == l[j]:
continue
for k in range((j + 1), n):
if l[j] == l[k]:
continue
if l[i] + l[j] > l[k]:
count += 1
print(count) | from itertools import combinations
N = int(input())
L = list(map(int, input().split()))
ans = 0
for a, b, c in combinations(L, 3):
if a == b or b ==c or a == c:
continue
if a + b + c - max(a, b, c) > max(a, b, c):
ans += 1
print(ans) | 1 | 5,007,114,837,374 | null | 91 | 91 |
S = input()
import re
print('Yes' if re.match(r'^(hi)+$', S) else 'No')
| h, n = map(int, input().split())
aa = [int(a) for a in input().split()]
all = sum(aa)
if h <= all :
print("Yes")
else :
print("No") | 0 | null | 65,679,036,598,730 | 199 | 226 |
N = list(input())
M = [ int(i) for i in N[::-1] ]
M.append(0)
c = 0
for i in range(len(M)-1):
if M[i] >= 6 or ( M[i] >=5 and M[i+1] >= 5):
M[i+1] += 1
c += min(M[i],10-M[i])
c += M[len(M)-1]
print(c) | #import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')
N, K = map(int, input().split())
d = [0]*(K+1)
for i in range(1, K+1):
val = K//i
d[i] = pow(val, N, MOD)
# print(d)
for i in range(K, 0, -1):
# print('i', i)
for j in range(K//i, 1, -1):
# print(' j', j)
# print(i, i*j)
d[i] -= d[i*j]
# print(d)
res = 0
for i, v in enu(d):
res += i*v
res %= MOD
print(res)
| 0 | null | 53,906,773,945,730 | 219 | 176 |
N = int(input())
P = list(map(int, input().split()))
dp = [0] * N
dp[0] = P[0]
for i in range(1, N):
dp[i] = min(dp[i - 1], P[i])
res = 0
for i in range(N):
if dp[i] >= P[i]:
res += 1
print(res) | import sys
input = sys.stdin.readline
from collections import deque
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = [0]
for a in A:
b = (B[-1] + (a-1)) % K
B.append(b)
ans = 0
dic = {}
for i, b in enumerate(B):
if b in dic:
dic[b].append(i)
else:
dic[b] = deque()
dic[b].append(i)
while len(dic[b]) > 0 and dic[b][0] <= i - K:
dic[b].popleft()
ans += len(dic[b])-1
print(ans) | 0 | null | 111,883,134,836,148 | 233 | 273 |
while True:
try:
a, b = map(int, input().split())
if a < b:
b, a = a, b
x, y = a, b
while b: a, b = b, a%b
gcd = a
lcm = (x*y)//gcd
print(gcd, lcm)
except:
break | 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, M = map(int, readline().split())
C = list(map(int, readline().split()))
# dp[i] := i円払うのに必要な枚数
dp = [INF] * (N+1)
dp[0] = 0
for c in C:
if c<=N:
for i in range(N-c+1):
dp[i+c] = min(dp[i]+1, dp[i+c])
print(dp[N])
if __name__ == '__main__':
main()
| 0 | null | 72,027,436,992 | 5 | 28 |
def composite(d,n,s):
for a in (2,3,5,7):
probably_prime = False
if pow(a,d,n) == 1:
continue
for i in range(s):
if pow(a, 2**i * d, n) == n-1:
probably_prime = True
break
return not probably_prime
return False
def is_prime(n):
if n == 2:
return True
elif n % 2 == 0:
return False
else:
d,s = n-1, 0
while not d%2:
d, s = d>>1, s+1
return not composite(d,n,s)
r = []
n = int(input())
for i in range(n):
n = int(input())
if is_prime(n):
if n not in r:
r.append(n)
print(len(r)) | dif = -1E9
n = int(input())
mn = int(input())
for i in range(n - 1):
r = int(input())
if r - mn > dif:
dif = r - mn
if r < mn:
mn = r
print(dif) | 0 | null | 13,099,536,800 | 12 | 13 |
n = int(input())
s = input()
if n % 2 == 1:
print('No')
else:
sa = s[:n//2]
sb = s[n//2:]
if sa == sb:
print('Yes')
else:
print('No') | N, K = map(int, input().split())
ans = 1
while N >= K:
N = N // K
ans += 1
print(ans) | 0 | null | 105,553,293,270,932 | 279 | 212 |
n,m=map(int,input().split())
c=list(map(int,input().split()))
c.sort(reverse=True)
#print(c)
dp=[0]
for i in range(1,n+1):
mini=float("inf")
for num in c:
if i-num>=0:
mini=min(mini,dp[i-num]+1)
dp.append(mini)
#print(dp)
print(dp[-1])
| a,b = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
ans = [10**9 for _ in range(a+1)]
ans[0] = 0
for i in range(a+1):
for j in l:
if i + j < a+1:
ans[i+j] = min(ans[i] + 1,ans[i+j])
print(ans[-1])
| 1 | 144,764,163,710 | null | 28 | 28 |
n = int(input())
num_AC = 0
num_WA = 0
num_TLE = 0
num_RE = 0
for i in range(n):
i = input()
if i == "AC":
num_AC += 1
elif i == "WA":
num_WA += 1
elif i == "TLE":
num_TLE += 1
elif i == "RE":
num_RE += 1
print("AC x " + str(num_AC))
print("WA x " + str(num_WA))
print("TLE x " + str(num_TLE))
print("RE x " + str(num_RE)) | 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") | 0 | null | 11,938,802,646,160 | 109 | 131 |
import bisect
def main():
N, D, A = list(map(int, input().split()))
monsters = [list(map(int, input().split())) for _ in range(N)]
monsters.sort()
X = [m[0] for m in monsters]
# 端から貪欲に攻撃していく
ans = 0
damages = [0] * (N + 1)
for n, monster in enumerate(monsters):
x, h = monster
h = max(0, h - damages[n])
to_n = bisect.bisect_right(X, x + 2 * D)
cnt = (h + A - 1) // A # ceil(h / A)
ans += cnt
damages[n] += A * cnt
damages[to_n] -= A * cnt
damages[n + 1] += damages[n]
print(ans)
if __name__ == '__main__':
main() | import sys
sys.setrecursionlimit(2147483647)
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()
class LazySegmentTree(object):
def __init__(self, A, dot, unit, compose, identity, act):
# A : array of monoid (M, dot, unit)
# (S, compose, identity) : sub monoid of End(M)
# compose : (f, g) -> fg (f, g in S)
# act : (f, x) -> f(x) (f in S, x in M)
logn = (len(A) - 1).bit_length()
n = 1 << logn
tree = [unit] * (2 * n)
for i, v in enumerate(A):
tree[i + n] = v
for i in range(n - 1, 0, -1):
tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
self._n, self._logn, self._tree, self._lazy = n, logn, tree, [identity] * (2 * n)
self._dot, self._unit, self._compose, self._identity, self._act = dot, unit, compose, identity, act
def _ascend(self, i):
tree, lazy, dot, act = self._tree, self._lazy, self._dot, self._act
while i > 1:
i >>= 1
tree[i] = act(lazy[i], dot(tree[i << 1], tree[i << 1 | 1]))
def _descend(self, i):
tree, lazy, identity, compose, act = self._tree, self._lazy, self._identity, self._compose, self._act
for k in range(self._logn, 0, -1):
p = i >> k
f = lazy[p]
tree[p << 1], lazy[p << 1] = act(f, tree[p << 1]), compose(f, lazy[p << 1])
tree[p << 1 | 1], lazy[p << 1 | 1] = act(f, tree[p << 1 | 1]), compose(f, lazy[p << 1 | 1])
lazy[p] = identity
# A[i] <- f(A[i]) for all i in [l, r)
def range_act(self, l, r, f):
l += self._n
r += self._n
# propagation isn't necessary if S is commutative
# self._descend(l)
# self._descend(r - 1)
l0, r0 = l, r
tree, lazy, act, compose = self._tree, self._lazy, self._act, self._compose
while l < r:
if l & 1:
tree[l], lazy[l] = act(f, tree[l]), compose(f, lazy[l])
l += 1
if r & 1:
r -= 1
tree[r], lazy[r] = act(f, tree[r]), compose(f, lazy[r])
l >>= 1
r >>= 1
self._ascend(l0)
self._ascend(r0 - 1)
# calculate product of A[l:r]
def sum(self, l, r):
l += self._n
r += self._n
self._descend(l)
self._descend(r - 1)
l_val = r_val = self._unit
tree, dot = self._tree, self._dot
while l < r:
if l & 1:
l_val = dot(l_val, tree[l])
l += 1
if r & 1:
r -= 1
r_val = dot(tree[r], r_val)
l >>= 1
r >>= 1
return dot(l_val, r_val)
from operator import add
def resolve():
n, d, a = map(int, input().split())
XH = [None] * n
coordinates = set() # for coordinates compression
for i in range(n):
x, h = map(int, input().split())
XH[i] = [x, (h - 1) // a + 1] # 初めから何回減らすかだけ持てばよい
coordinates.add(x)
coordinates.add(x + 2 * d + 1) # [x, x + 2d + 1) に減らす
XH.sort()
compress = {v : i for i, v in enumerate(sorted(coordinates))}
n = len(compress)
A = [0] * n
for i in range(len(XH)):
A[compress[XH[i][0]]] = XH[i][1]
res = 0
tree = LazySegmentTree(A, max, 0, add, 0, add) # 区間 add, 1点取得ができればよいので、区間拡張しなくてよい max にしておく
for x, h in XH:
# もし x が生き残っていたら、[x, x + 2d + 1) から hp を引く
hp = tree.sum(compress[x], compress[x] + 1)
if hp <= 0:
continue
res += hp
tree.range_act(compress[x], compress[x + 2 * d + 1], -hp)
print(res)
resolve() | 1 | 82,610,272,507,290 | null | 230 | 230 |
r = int(input())
print(r * 2 * 3.1415926535897932384626433) | a = int(input())
print(2*(22/7)*a) | 1 | 31,225,647,920,138 | null | 167 | 167 |
N = int(input())
S = input()
S = list(S)
ans = ""
for i in range(N-1):
if S[i]==S[i+1]:
ans+=S[i]
print(N-len(ans)) | n=int(input())
s=list(input())
for x in range(n-1):
if s[x]==s[x+1]:
s[x]='1'
print(len(s)-s.count('1')) | 1 | 170,054,883,706,130 | null | 293 | 293 |
import sys
sys.setrecursionlimit(10**5)
n = int(input())
ab = [list(map(int,input().split()))for _ in range(n-1)]
graph = [[] for _ in range(n+1)]
ans = [0]*(n-1)
for i in range(n-1):
graph[ab[i][0]].append((ab[i][1],i))
graph[ab[i][1]].append((ab[i][0],i))
visit = [False]*(n+1)
def dfs(p,c):
color = 1
visit[p] = True
for n,i in graph[p]:
if visit[n] == False:
if color == c:
color += 1
ans[i] = color
dfs(n,color)
color += 1
dfs(1,0)
print(max(ans))
for t in ans:
print(t)
| from collections import deque, defaultdict
N = int(input())
ab = [list(map(int, input().split())) for _ in range(N - 1)]
d = [0] * (N + 1)
G = [[] for _ in range(N + 1)]
for a, b in ab:
d[a] += 1
d[b] += 1
G[a].append(b)
G[b].append(a)
print(max(d))
color = defaultdict(int)
q = deque([[1, 0]])
seen = [0] * (N + 1)
while q:
v, c = q.popleft()
seen[v] = 1
tem = 1
for u in G[v]:
if seen[u]:
continue
if tem == c:
tem += 1
q.append([u, tem])
i, j = min(v, u), max(v, u)
color[(i, j)] = tem
tem += 1
for a, b in ab:
i, j = min(a, b), max(a, b)
print(color[(i, j)])
| 1 | 136,004,680,121,828 | null | 272 | 272 |
op = "$"
while op != "?":
a, op, c = map(str, raw_input().split())
a = int(a)
c = int(c)
if op == "+":
print u"%d" % (a+c)
elif op == "-":
print u"%d" % (a-c)
elif op == "*":
print u"%d" % (a*c)
elif op == "/":
print u"%d" % (a/c)
else:
break | while True:
ins = input().split()
a = int(ins[0])
b = int(ins[2])
op = ins[1]
if op == "?":
break
elif op == "+":
print(a+b)
elif op == "-":
print(a-b)
elif op == "/":
print(a//b)
else:
print(a*b) | 1 | 692,790,324,252 | null | 47 | 47 |
H,N=map(int,input().split())
L=[0]*N
for i in range(N):
a,b=map(int,input().split())
L[i]=(a,b)
DP=[float("inf")]*(H+1)
DP[0]=0
for (A,B) in L:
for k in range(1,H+1):
if k>=A:
DP[k]=min(DP[k],DP[k-A]+B)
else:
DP[k]=min(DP[k],B)
print(DP[-1]) | d,t,s = [float(x) for x in input().split()]
if d/s > t:
print("No")
else:
print("Yes") | 0 | null | 42,381,837,296,202 | 229 | 81 |
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
def ceil(a, b):
return (a + b - 1) // b
def sum_of_arithmetic_progression(s, d, n):
return n * (2 * s + (n - 1) * d) // 2
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def lcm(a, b):
g = gcd(a, b)
return a / g * b
def solve(N, M):
ans = []
now = 0
for d in range(M, 0, -2):
ans.append((now, now + d))
now += 1
now = M + 1
for d in range(M - 1, 0, -2):
ans.append((now, (now + d) % N))
now += 1
return ans
def main():
N, M = map(int, input().split())
ans = solve(N, M)
for x in ans:
print(f"{x[0] + 1} {x[1] + 1}")
if __name__ == '__main__':
main()
| n, m = map(int, input().split())
for i in range(m):
if n % 2 == 0 and n // 2 <= (m - i) * 2 - 1:
x = 1
else:
x = 0
print(i + 1, (m - i) * 2 + i + x) | 1 | 28,535,305,602,272 | null | 162 | 162 |
H = int(input())
W = int(input())
N = int(input())
cnt=wcnt=hcnt=0
while N>0:
a = max(H-hcnt, W-wcnt)
N -= a
cnt+=1
if a==W:
H-=1
hcnt+=1
elif a==H:
W-=1
wcnt+=1
print(cnt) | import sys, math
h, w, n = [int(i) for i in sys.stdin.readlines()]
bigger = h if h >= w else w
print(math.ceil(n / bigger)) | 1 | 88,852,278,190,532 | null | 236 | 236 |