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=int(input())
s=input()
R=[]
G={}
B=[]
for i in range(n):
if s[i]=='R':
R.append(i+1)
elif s[i]=='G':
G[i+1]=G.get(i+1,0)+1
else:
B.append(i+1)
res=len(R)*len(G)*len(B)
for i in R:
for j in B:
if ((i+j)%2==0 and G.get((i+j)//2,0)==1):
res-=1
if G.get(2*max(i,j)-min(i,j),0)==1:
res-=1
if G.get(2*min(i,j)-max(i,j),0)==1:
res-=1
print(res) |
S, T = input().split()
print(T, S, sep='')
| 0 | null | 69,855,193,460,822 | 175 | 248 |
N,M=map(int,input().split())
if(N==M):
print("Yes")
else:
print("No")
| import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
n, m = list(map(int, readline().split()))
print("Yes" if n == m else "No")
if __name__ == '__main__':
solve()
| 1 | 83,171,487,588,732 | null | 231 | 231 |
A,B = map(int,input().split())
if A<=9 and B<=9:print(A*B)
else : print(-1) | #!/usr/bin/env python
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**6)
INF = float("inf")
def main():
A,B = map(int,input().split())
if A < 10 and B < 10:
print(A*B)
else:
print(-1)
if __name__ == "__main__":
main() | 1 | 157,752,684,524,620 | null | 286 | 286 |
A, B = [int(v) for v in input().rstrip().split()]
print(A * B)
| N = list(map(int,input().split()))
print(N[0]*N[1]) | 1 | 15,801,936,400,962 | null | 133 | 133 |
#!/usr/bin/env python3
S = input()
print(len(S) * 'x')
| MOD = 10**9 + 7
class modint():
def __init__(self, value):
self.value = value % MOD
def __int__(self):
return int(self.value)
def __float__(self):
return float(self.value)
def __str__(self):
return str(self.value)
def __repr__(self):
return str(self.value)
def __add__(self, other):
return (modint(self.value + other.value) if isinstance(other, modint)
else modint(self.value + other))
def __sub__(self, other):
return (modint(self.value - other.value) if isinstance(other, modint)
else modint(self.value - other))
def __mul__(self, other):
return (modint(self.value * other.value) if isinstance(other, modint)
else modint(self.value * other))
def __truediv__(self, other):
return (modint(self.value * pow(other.value, MOD - 2, MOD))
if isinstance(other, modint)
else modint(self.value * pow(other, MOD - 2, MOD)))
def __pow__(self, other):
return (modint(pow(self.value, other.value, MOD))
if isinstance(other, modint)
else modint(pow(self.value, other, MOD)))
def __eq__(self, other):
return (self.value == other.value if isinstance(other, modint)
else self.value == (other % MOD))
def __ne__(self, other):
return (self.value == other.value if isinstance(other, modint)
else self.value == (other % MOD))
def __radd__(self, other):
return (modint(other.value + self.value) if isinstance(other, modint)
else modint(other + self.value))
def __rsub__(self, other):
return (modint(other.value - self.value) if isinstance(other, modint)
else modint(other - self.value))
def __rmul__(self, other):
return (modint(other.value * self.value) if isinstance(other, modint)
else modint(other * self.value))
def __rtruediv__(self, other):
return (modint(other.value * pow(self.value, MOD - 2, MOD))
if isinstance(other, modint)
else modint(other * pow(self.value, MOD - 2, MOD)))
def __rpow__(self, other):
return (modint(pow(other.value, self.value, MOD))
if isinstance(other, modint)
else modint(pow(other, self.value, MOD)))
def modinv(self):
return modint(pow(self.value, MOD - 2, MOD))
def main():
import sys
input = sys.stdin.buffer.readline
N = int(input())
A = [int(i) for i in input().split()]
def gcd(x, y):
if y == 0:
return x
while y != 0:
x, y = y, x % y
return x
def lcm(x, y):
return x*y//gcd(x, y)
num = 1
for a in A:
num = lcm(num, a)
n = modint(num)
ans = 0
for i, a in enumerate(A):
ans += n/a
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 80,461,993,671,488 | 221 | 235 |
N = int(input())
edge = [[] for _ in range(N)]
for _ in range(N):
l = list(map(int, input().split()))
for j in range(l[1]):
edge[l[0]-1].append(l[2+j]-1)
now_list = [0]
next_list = []
dist = 0
dists = [-1] * N
while len(now_list) > 0:
for _ in range(len(now_list)):
v = now_list.pop()
if dists[v] == -1:
dists[v] = dist
else:
continue
for nv in edge[v]:
next_list.append(nv)
now_list = next_list
next_list = []
dist += 1
for i in range(N):
print(1+i, dists[i])
| from __future__ import print_function
import time
from sys import stdin
from Queue import Queue
start = time.clock()
i = 0
num=int(stdin.readline())
L=[]
for _ in range(num):
L.append([int(s) for s in stdin.readline().split()[2:]])
d=[-1]*num
d[0]=0
q=Queue(100)
q.put(0)
while not q.empty():
u=q.get()
for v in L[u]:
if d[v-1]<0:
d[v-1]=d[u]+1
q.put(v-1)
for i,v in enumerate(d):
print (i+1,v) | 1 | 3,915,085,408 | null | 9 | 9 |
n, k, s = map(int, input().split())
ai = s
ls1 = [ai] * k
for aj in reversed(range(10 ** 9 + 1)):
if aj != ai:
ls2 = [aj] * (n - k)
break
print(" ".join(map(str, (ls1 + ls2)))) | N, K, S = map(int ,input().split())
if N == K:
A = [S] * N
elif S == 10**9:
A = [S]*K + [1]*(N-K)
elif K == 0:
A = [S+1] * N
elif S == 1:
A = [1]*K + [2]*(N-K)
else:
A = [S+1] * N
x = S // 2
y = S - x
for i in range(K+1):
if i%2 == 0:
A[i] = x
else:
A[i] = y
print(' '.join(map(str, A))) | 1 | 91,036,888,039,130 | null | 238 | 238 |
n = int(input())
answer = 0
for i in range(n):
x, y = input().split()
if x == y:
answer = answer + 1
else:
answer = 0
if answer == 3:
print('Yes')
exit(0)
else:
print('No')
| from collections import Counter
n = int(input())
A = list(map(int, input().split()))
ANS = sum(A)
A = Counter(A)
Q = int(input())
for i in range(Q):
B, C = map(int, input().split())
print(ANS + (C - B) * A[B])
ANS += (C - B) * A[B]
A[C] = A[C] + A[B]
A[B] = 0
| 0 | null | 7,286,443,709,550 | 72 | 122 |
def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(input()) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
#############
# Main Code #
#############
N, M = getNM()
W = []
V = []
for i in range(M):
a, b = getNM()
W.append(b)
V.append(a)
# magicを重複ありで適当に組み合わせて合計Nを目指す
def knapsack_4(N, limit, weight, value):
dp = [float('inf')] * (limit + 1)
dp[0] = 0
for i in range(1, limit + 1):
for j in range(N):
if i < value[j]:
dp[i] = min(dp[i], weight[j])
else:
dp[i] = min(dp[i], dp[i - value[j]] + weight[j])
return dp[-1]
print(knapsack_4(M, N, W, V))
| i=1
while i<=9:
j=1
while j<=9:
print '%d%s%d%s%d'%(i,"x",j,"=",i*j)
j=j+1
i=i+1 | 0 | null | 40,463,119,521,542 | 229 | 1 |
import itertools as it
n = int(input())
lst = []
for i in range(n):
x, y = list(map(int, input().split()))
lst.append([x, y])
perm = list(it.permutations(lst))
cost = []
for i in perm:
temp = 0
for j in range(len(i)-1):
temp += (((i[j][0] - i[j+1][0])**2) + ((i[j][1] - i[j+1][1])**2))**0.5
cost.append(temp)
print(sum(cost) / len(cost)) | n = int(input())
XY = [[] for _ in range(n)]
ans = 0
for i in range(n):
a = int(input())
for _ in range(a):
x, y = map(int, input().split())
XY[i].append((x-1, y))
for i in range(2**n):
correct = [False]*n
tmp_cnt = 0
flag = True
for j in range(n):
if i&(1<<j):
correct[j] = True
tmp_cnt += 1
for j in range(n):
if correct[j]:
for x, y in XY[j]:
if (y==0 and correct[x]) or (y==1 and not correct[x]):
flag = False
if flag:
ans = max(tmp_cnt, ans)
print(ans) | 0 | null | 134,841,439,580,032 | 280 | 262 |
X = int(input())
a = 100
year = 0
import math
while True:
a = a*101//100
year += 1
if a >= X:
break
print(year) | import sys
def insertionSort(A, n, g):
for i in range(g, n):
global cnt
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
def shellSort(A, n):
global m
global G
for i in range(0, m):
insertionSort(A, n, G[i])
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
if n == 1:
print(1)
print(1)
print(0)
print(A[0])
sys.exit()
t = n - 1
G = []
G.append(t)
while t != 1:
t = t//2
G.append(t)
m = len(G)
cnt = 0
shellSort(A, n)
print(m)
print(' '.join(map(str, G)))
print(cnt)
for i in range(n):
print(A[i])
| 0 | null | 13,520,723,207,740 | 159 | 17 |
def main():
## IMPORT MODULE
#import sys
#sys.setrecursionlimit(100000)
#input=lambda :sys.stdin.readline().rstrip()
#f_inf=float("inf")
#MOD=10**9+7
if 'get_ipython' in globals():
## SAMPLE INPUT
n = 4
S = ['((()))', '((((((', '))))))', '()()()']
else:
## INPUT
n = int(input())
#a, b = map(int, input().split())
S = [input() for _ in range(n)]
## SUBMITION CODES HERE
def CNT(A):
tmp, Min = 0, 0
for a in A:
if a == '(': tmp += 1
else: tmp -= 1
Min = min(Min, tmp)
return (-Min, tmp-Min)
T = [CNT(s) for s in S]
pls = []
mis = []
for l, r in T:
if l <= r: pls.append((l, r))
else: mis.append((l, r))
pls.sort(key=lambda a: a[0])
mis.sort(key=lambda a: a[1], reverse=True)
total = pls + mis
levl = 0
for l, r in total:
levl -= l
if levl < 0:
print('No')
exit()
levl += r
print('Yes' if levl == 0 else 'No')
main() | N = int(input())
S_list = []
for _ in range(N):
S_list.append(input().strip())
data = []
for s in S_list:
bottom = 0
height = 0
for c in s:
if c == ")":
height -= 1
if bottom > height:
bottom = height
else:
height += 1
if height == 0:
k1 = 1
k2 = 0
elif height > 0:
k1 = 0
k2 = -bottom
else:
k1 = 2
k2 = bottom - height
data.append((k1, k2, bottom, height, s))
data.sort()
def check():
height = 0
for k1, k2, b, h, s in data:
# print(height, b, h, s)
if height + b < 0:
return False
height += h
return height == 0
if check():
print("Yes")
else:
print("No")
| 1 | 23,626,868,174,300 | null | 152 | 152 |
t = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [t[0]*a[0],t[1]*a[1]]
d = [t[0]*b[0],t[1]*b[1]]
if sum(c)==sum(d):
print('infinity')
exit()
elif c[0]==d[0]:
print('infinity')
exit()
if sum(d)>sum(c) and d[0]>c[0]:
print(0)
exit()
elif sum(c)>sum(d) and c[0]>d[0]:
print(0)
exit()
else:
n = (c[0]-d[0])/(sum(d)-sum(c))
if n==int(n):
print(2*int(n))
else:
print(2*int(n)+1)
| T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
P = (A1 - B1) * T1
Q = (A2 - B2) * T2
if P > 0:
P *= -1
Q *= -1
if P + Q < 0:
print(0)
elif P + Q == 0:
print("infinity")
else:
S = (-P) // (P + Q)
T = (-P) % (P + Q)
if T != 0:
print(S * 2 + 1)
else:
print(S * 2)
| 1 | 131,687,840,745,050 | null | 269 | 269 |
num = int(input())
number = num / 3
print(number * number * number) | import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9
def main():
l = int(input())
print((l/3)**3)
if __name__ == '__main__':
main()
| 1 | 47,247,769,003,710 | null | 191 | 191 |
import sys
import math
#from queue import *
#import random
#sys.setrecursionlimit(int(1e6))
input = sys.stdin.readline
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
return(int(input()))
def inara():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
################################################################
############ ---- THE ACTUAL CODE STARTS BELOW ---- ############
l,r,d=invr()
ans=0
for i in range(l,r+1):
if i%d==0:
ans+=1
print(ans) | n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
d=[-1,-1,-1]
ans=1
for aa in a:
ans*=d.count(aa-1)
ans%=mod
if aa-1 in d:
d[d.index(aa-1)]+=1
print(ans)
| 0 | null | 68,721,439,932,958 | 104 | 268 |
Sum = input().split()
cou = 1
while len(Sum) != 1 :
cou += 1
if Sum[cou] == '+' :
del Sum[cou]
Sum.insert((cou - 2) ,int(Sum.pop(cou - 2)) + int(Sum.pop(cou - 2)))
cou -= 2
elif Sum[cou] == '-' :
del Sum[cou]
Sum.insert((cou - 2) ,int(Sum.pop(cou - 2)) - int(Sum.pop(cou - 2)))
cou -= 2
elif Sum[cou] == '*' :
del Sum[cou]
Sum.insert((cou - 2) ,int(Sum.pop(cou - 2)) * int(Sum.pop(cou - 2)))
cou -= 2
print(Sum[0]) | D, T, S = map(int, input().split())
print("Yes" if(((T*S) - D) >= 0) else "No") | 0 | null | 1,821,257,958,598 | 18 | 81 |
import collections
def prime_factorize(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 a
N=int(input())
D = collections.Counter(prime_factorize(N))
A=0
for d in D:
e=D[d]
for i in range(40):
if (i+1)*(i+2)>2*e:
A=A+i
break
print(A) | import math , sys
def fac(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(cnt)
if temp!=1:
arr.append(1)
if arr==[]:
arr.append(1)
return arr
def sta ( x ):
return int( 0.5* (-1 + math.sqrt(1+8*x)))
N = int( input() )
if N == 1:
print(0)
sys.exit()
if N == 2 or N ==3:
print(1)
sys.exit()
Is = fac( N )
ans = sum( [ sta(j) for j in Is])
print(max(ans,1)) | 1 | 17,056,900,521,244 | null | 136 | 136 |
def selectionSort(nums,n):
k=0
for i in range(n):
minj=i
for j in range(i,n):
if nums[j]<nums[minj]:
minj=j
if nums[i]!=nums[minj]:
nums[i],nums[minj]=nums[minj],nums[i]
#print(nums)
k+=1
return nums,k
n=int(input())
nums=list(map(int,input().split()))
nums,k=selectionSort(nums,n)
print(*nums)
print(k) | n = int(input())
st = [input().split() for _ in range(n)]
x = input()
s,t = zip(*st)
print(sum(int(t[i]) for i in range(s.index(x)+1,n)))
| 0 | null | 48,454,506,438,766 | 15 | 243 |
if __name__ == "__main__":
a = []
for i in range(0,10):
val = input()
a.append(int(val))
a.sort()
a.reverse()
for i in range(0,3):
print(a[i]) | numbers = []
while True:
x=int(input())
if x==0:
break
numbers.append(x)
for i in range(len(numbers)):
print("Case ",i+1,": ",numbers[i],sep="")
| 0 | null | 235,462,255,480 | 2 | 42 |
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
N = i()
A = l()
L = []
L2 = [0]*(10**6)
for i in range(N):
if i+A[i]+1 < 10**6:
L.append(i+A[i]+1)
if i-A[i]+1 >= 0 and i-A[i]+1 < 10**6:
L2[i-A[i]+1] += 1
ans = 0
for l in L:
ans += L2[l]
print(ans) | import sys
import itertools
N, K = map(int, input().split())
a = 0
h = 0
l = 0
for j in range(0,K-1):
h += j
for j in range(N+2-K,N+1):
l += j
for i in range(K,N+2):
h += i-1
l += N+1-i
a += l - h + 1
a %= 10 ** 9 + 7
print(a)
| 0 | null | 29,349,592,490,232 | 157 | 170 |
r, c = map(int, input().split())
matrix = [[0 for i in range(c+1)] for j in range(r+1)]
for i in range(r):
a = list(map(int, input().split()))
for j in range(c):
matrix[i][j] = a[j]
matrix[i][c] = sum(a)
for l in range(c+1):
for m in range(r):
matrix[r][l] += matrix[m][l]
for cv in range(r+1):
for fv in range(c+1):
print(matrix[cv][fv], end='')
if fv != c:
print(" ", end='')
print()
| def main():
r, c = map(int, input().split())
table = []
for _ in range(r):
table.append(list(map(int, input().split())))
table.append([0] * (c+1))
for index, line in enumerate(table[:-1]):
table[index].append(sum(line))
for index1, value in enumerate(table[index]):
table[-1][index1] += value
for line in [map(str, line) for line in table]:
print(' '.join(line))
return
if __name__ == '__main__':
main()
| 1 | 1,375,093,483,104 | null | 59 | 59 |
S = str(input())
L = len(S)
ans = "x" * L
print(ans) | def Warshall_Floyd(dist,n,restoration=False):
next_point = [[j for j in range(n)] for _ in range(n)]
for i in range(n):
for j in range(n):
for k in range(n):
if dist[j][k] > dist[j][i] + dist[i][k]:
next_point[j][k] = next_point[j][i]
dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k])
if restoration:
return dist,next_point
else:
return dist
n,m,l = map(int,input().split())
inf = 10**18
dist = [[inf for i in range(n)] for j in range(n)]
for i in range(n):
dist[i][i] = 0
for i in range(m):
a,b,c = map(int,input().split())
a -= 1
b -= 1
if c <= l:
dist[a][b] = c
dist[b][a] = c
dist = Warshall_Floyd(dist,n)
route = [[inf for i in range(n)] for j in range(n)]
for i in range(n):
for j in range(n):
if i == j:
route[i][j] = 0
elif dist[i][j] <= l:
route[i][j] = 1
route = Warshall_Floyd(route,n)
q = int(input())
for i in range(q):
s,t = map(int,input().split())
s -= 1
t -= 1
print(route[s][t]-1 if route[s][t] < inf else -1) | 0 | null | 123,337,800,658,838 | 221 | 295 |
import sys
def gcd(a,b):
if(b):
return gcd(b,(a%b))
else:
return a
def lcm(a,b):
return a*b/gcd(a,b)
a = ""
for input in sys.stdin:
a += input
l = a.split()
for i in range(0,len(l),2):
if(int(l[i]) > int(l[i+1])):
print gcd(int(l[i]),int(l[i+1])),lcm(int(l[i]),int(l[i+1]))
else:
print gcd(int(l[i+1]),int(l[i])),lcm(int(l[i+1]),int(l[i]))
| import sys
dataset = sys.stdin.readlines()
def gcd(a, b):
if b > a: return gcd(b, a)
if a % b == 0: return b
return gcd(b, a % b)
def lcd(a, b):
return a * b // gcd(a, b)
for item in dataset:
a, b = list(map(int, item.split()))
print(gcd(a, b), lcd(a,b)) | 1 | 645,770,990 | null | 5 | 5 |
import math
from math import gcd
INF = float("inf")
import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque
def main():
a,b,c,d = map(int, input().split())
while True:
c -= b
if c<= 0:
print("Yes")
exit()
a -= d
if a <= 0:
print("No")
exit()
if __name__=="__main__":
main()
| N = int(input())
P = list(map(int,input().split()))
num = float("inf")
ans = 0
for i in range(N):
if num >= P[i]:
ans += 1
num = P[i]
print(ans) | 0 | null | 57,433,902,722,210 | 164 | 233 |
H=int(input())
ans=0
i=0
while 2**i<=H:
ans+=2**i
i+=1
print(ans) | N = int(input())
P = [int(x) for x in input().split()]
ans = 1
min_p = P[0]
for i in range(1,N):
if(min_p >= P[i]):
ans += 1
min_p = P[i]
print(ans) | 0 | null | 82,478,702,585,698 | 228 | 233 |
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
point = 0
flg=[0]*n
for i in range(n):
if t[i] == 'r' and flg[i] == 0:
point += p
elif t[i] == 's' and flg[i] == 0:
point += r
elif t[i] == 'p' and flg[i] == 0:
point += s
if i+k < n and t[i+k] == t[i]:
if t[i] == 'r' and flg[i] == 0:
flg[i+k] = 'r'
elif t[i] == 's' and flg[i] == 0:
flg[i+k] = 's'
elif t[i] =='p' and flg[i] == 0:
flg[i+k] = 'p'
print(point) | n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
point = {"r":(p,"p"), "s":(r,"r"), "p":(s,"s")}
ans = 0
hand = ""
for i in range(n):
if i < k:
ans += point[t[i]][0]
hand += point[t[i]][1]
else:
if (t[i-k] != t[i]):
ans += point[t[i]][0]
hand += point[t[i]][1]
else:
if hand[i-k] != point[t[i]][1]:
ans += point[t[i]][0]
hand += point[t[i]][1]
else:
if (i+k) < n:
hand += "rsp".replace(point[t[i+k]][1],"").replace(hand[i-k],"")[0]
else:
hand += "rsp".replace(hand[i-k],"")[0]
print(ans) | 1 | 107,301,818,747,424 | null | 251 | 251 |
import math
N = int(input())
A = list(map(int, input().split()))
Sum = 0
mod = (10 ** 9) + 7
for i in range(len(bin(max(A)))-2):
Sum_1 = 0
for j in range(N):
#print(i, j)
if ((A[j] >> i) & 1):
Sum_1 += 1
Sum_0 = N - Sum_1
Sum = (Sum + ((Sum_0 * Sum_1) % mod * (2 ** i)) % mod) % mod
# print(Sum_0,Sum_1)
print(Sum)
| import sys
input = sys.stdin.readline
#n = int(input())
#l = list(map(int, input().split()))
'''
a=[]
b=[]
for i in range():
A, B = map(int, input().split())
a.append(A)
b.append(B)'''
import numpy as np
n=int(input())
a = np.array([int(i) for i in input().split()])
ans=0
for i in range(60):
cnt=np.count_nonzero(a&1)
ans+=(n-cnt)*cnt*(2**i)
if ans>=10**9+7:
ans%=(10**9+7)
a>>=1
print(ans) | 1 | 122,937,097,334,960 | null | 263 | 263 |
N = int(input())
for i in range(int(N**(1/2)),0,-1):
if N%i == 0:
break
print(i+N//i-2)
| N,K = map(int,input().split())
A = list(map(int,input().split()))
if K==0:
high = max(A)
else:
low = 0
high = 10**9
while high-low>1:
mid = (high+low)//2
cnt = 0
for i in range(N):
if A[i]%mid==0:
cnt += A[i]//mid-1
else:
cnt += A[i]//mid
if K>=cnt:
high = mid
else:
low = mid
print(high) | 0 | null | 84,016,906,240,542 | 288 | 99 |
b = input()
a = input().split()
for i in range(len(a)):
a[i] = int(a[i])
max_a = max(a)
min_a = min(a)
Sum = sum(a)
print(min_a,max_a,Sum)
| a,b = map(int,input().split())
ans = b if a >= 10 else b + 100 * (10-a)
print(ans) | 0 | null | 32,214,030,831,274 | 48 | 211 |
n=input()
b=0
e=len(n)-1
c=0
while(b<=e):
if(n[b]==n[e]):
b+=1
e-=1
elif(n[b]!=n[e]):
c+=1
b+=1
e-=1
print(c) | t = input()
leng = len(t)
print('x' * leng) | 0 | null | 96,771,787,246,560 | 261 | 221 |
a=int(input())
print(sum(divmod(a,2)))
| n=input()
a=(int(n)+1)//2
print(a)
| 1 | 59,027,545,019,858 | null | 206 | 206 |
N = int(input())
A = list(map(int,input().split()))
R, B, G = 0, 0, 0
ans = 1
for a in A:
if R == a:
if B == a and G == a:
ans *= 3
elif B == a or G == a:
ans *= 2
else:
ans *= 1
R += 1
elif B == a:
if G == a:
ans *= 2
else:
ans *= 1
B += 1
elif G == a:
ans *= 1
G += 1
else:
print(0)
exit()
ans %= 10**9+7
print(ans) | a, b, c, d = map(int, input().split())
t_death = a // d + 1 if a % d else a // d
a_death = c // b + 1 if c % b else c // b
if t_death >= a_death:
print('Yes')
else:
print('No') | 0 | null | 79,910,893,747,648 | 268 | 164 |
M=10**9+7
x,y=map(int,input().split())
ans=0
if (x+y)%3==0:
a=(2*y-x)//3
b=(2*x-y)//3
if a>=0 and b>=0:
f1,f2=1,1
for i in range(a+1,a+b+1):
f1*=i
f1%=M
for i in range(1,b+1):
f2*=i
f2%=M
ans=f1*pow(f2,M-2,M)
print(ans%M)
| mod=10**9+7
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
from itertools import combinations
import bisect
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a,b=mi()
if (a+b)%3!=0:
print(0)
sys.exit()
s=(a+b)//3
a-=s
b-=s
if a<0 or b<0:
print(0)
sys.exit()
fac=[1]*700000
for i in range(1,700000):
fac[i]=(fac[i-1]*i)%mod
m=a+b
n=min(a,b)
c=1
for j in range(m,m-n,-1):
c*=j
c=c%mod
print((c*pow(fac[n],mod-2,mod))%mod) | 1 | 149,716,276,799,260 | null | 281 | 281 |
from decimal import Decimal
a,b,c=map(Decimal,input().split())
root=Decimal("0.5")
print("Yes" if a**root+b**root<c**root else "No") | from decimal import Decimal
a,b,c = map(int,input().split())
d = Decimal(0.5)
ans = "Yes" if a**d + b**d < c**d else "No"
print(ans) | 1 | 51,467,858,164,340 | null | 197 | 197 |
n = int(input())
a = list(map(int,input().split()))
ans = 1
if 0 in a:
print(0)
exit()
else:
for i in a:
ans *= i
if ans > 10**18:
print(-1)
exit()
print(ans)
| n, *a = map(int, open(0).read().split())
a.sort()
if a[0] == 0:
print(0)
exit()
b = 1
for c in a:
b *= c
if b > 10 ** 18:
print(-1)
exit()
print(b)
| 1 | 16,155,301,281,542 | null | 134 | 134 |
s = input()
for c in s:
if c.islower():
print(c.upper(), end="")
else:
print(c.lower(), end="")
print()
| from collections import Counter
N = int(input())
A = list([int(x) for x in input().split()])
result = dict(Counter(A))
for i in range(1, N+1):
if i in result:
print(result[i])
else:
print(0)
| 0 | null | 17,054,815,224,450 | 61 | 169 |
def f(x, m):
return x * x % m
def main():
N, X, M = map(int, input().split())
pre = set()
pre.add(X)
cnt = 1
while cnt < N:
X = f(X, M)
if X in pre: break
cnt += 1
pre.add(X)
if cnt == N:
return sum(pre)
ans = sum(pre)
N -= cnt
loop = set()
loop.add(X)
while cnt < N:
X = f(X, M)
if X in loop: break
loop.add(X)
left = N % len(loop)
ans += sum(loop) * (N // len(loop))
for i in range(left):
ans += X
X = f(X, M)
return ans
print(main())
| class Combination:
def __init__(self, mod, max_n):
self.MOD = mod
self.MAX_N = max_n
self.f = self.factorial(self.MAX_N)
self.f_inv = [self.inv(x) for x in self.f]
def inv(self,x):
return pow(x, self.MOD-2, self.MOD)
def factorial(self, n):
res = [1]
for i in range(1,n+1):
res.append(res[-1] * i % self.MOD)
return res
def comb(self, n, r):
return (self.f[n] * self.f_inv[r] % self.MOD) * self.f_inv[n-r] % self.MOD
X, Y = map(int,input().split())
k, l = (2*Y-X)//3, (2*X-Y)//3
if (X + Y) % 3 != 0 or k < 0 or l < 0:
print(0)
exit()
CB = Combination(10**9+7, k+l)
print(CB.comb(k+l,k)) | 0 | null | 76,618,024,441,370 | 75 | 281 |
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
sys.setrecursionlimit(100000000)
def input(): return sys.stdin.readline().rstrip()
N = int(input())
def f(x):
ans = set()
i = 1
while i * i <= x:
if x % i == 0:
ans.add(i)
i += 1
for i in ans.copy():
ans.add(x // i)
return ans
ans = set()
for K in f(N) | f(N - 1):
if K == 1:
continue
n = N
while n % K == 0:
n //= K
if n % K == 1:
ans.add(K)
print(len(ans))
| def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
return divisors
N = int(input())
d1 = make_divisors(N)
d2 = make_divisors(N - 1)
ans = len(d2) - 1
for n in d1:
if n == 1:
continue
n2 = N
while n2 % n == 0:
n2 //= n
if n2 % n == 1:
if n not in d2:
ans += 1
print(ans)
| 1 | 41,374,103,828,052 | null | 183 | 183 |
a,b,m = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = []
ans.append(min(A)+min(B))
for i in range(m):
M = list(map(int,input().split()))
tmp = A[M[0]-1] + B[M[1]-1] -M[2]
ans.append(tmp)
print(min(ans))
| # n, m, l = map(int, input().split())
# list_n = list(map(int, input().split()))
# n = input()
# list = [input() for i in range(N)
# list = [[i for i in range(N)] for _ in range(M)]
import sys
input = sys.stdin.readline
A, B, M = map(int, input().split())
List_A = list(map(int, input().split()))
List_B = list(map(int, input().split()))
List_discount = [list(map(int, input().split())) for i in range(M)]
# print(List_discount)
ans = 2 * 10**5
for d in List_discount:
# print(d)
p = List_A[d[0]-1] + List_B[d[1]-1] - d[2]
ans = min(ans, p)
no_discount = min(List_A) + min(List_B)
ans = min(ans, no_discount)
print(ans)
| 1 | 54,113,630,944,530 | null | 200 | 200 |
def insertionSort(A,n,g,cnt):
for i in range(g,n):
v = A[i]
j = i-g
while (j>=0)*(A[j]>v):
A[j+g]=A[j]
j = j-g
cnt[0] += 1
A[j+g] = v
A =[]
N = int(input())
for i in range(N):
A.append(int(input()))
cnt = [0]
import math
m = math.floor(math.log(N,2))+1
G = [math.ceil(N/2)]
for i in range(1,m-1):
G.append(math.ceil(G[i-1]/2))
G.append(N-sum(G))
if G[len(G)-1] != 1:
G[len(G)-1] = 1
for k in range(m):
insertionSort(A,N,G[k],cnt)
print(m)
for i in range(m):
print(f"{G[i]}",end=" ")
print(f"\n{cnt[0]}")
for i in range(N):
print(f"{A[i]}")
| import math
def insertionSort(A,n,g):
global cnt
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
def shellSort(A,n):
global cnt
cnt = 0
m = int(math.log(n))
if m < 1:
m = 1
G = []
for i in range(0,m):
if i == 0:
G.append(1)
else:
G.append(G[i-1]*3+1)
G.sort(reverse=True)
for i in range(0,m):
insertionSort(A,n,G[i])
print(m)
for i in range(m):
if i == m-1:
print(G[i])
else:
print(G[i],end=" ")
print(cnt)
for i in range(n):
print(A[i])
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
shellSort(A,n) | 1 | 31,475,654,432 | null | 17 | 17 |
h, m = map(int, input().split())
if h == 1 or m == 1:
count = 1
else:
count = ((h //2) * m) + ((h %2) *((m //2) + (m %2)))
print(count)
| def resolve():
h, w = map(int, input().split())
import math
if w == 1 or h == 1:
print(1)
else:
print(math.ceil(h * w / 2))
if __name__ == '__main__':
resolve() | 1 | 50,915,455,283,980 | null | 196 | 196 |
import sys
[a, b] = [int(x) for x in sys.stdin.readline().split()]
d = a / b
r = a - a / b * b
f = round(1.0 * a / b, 7)
print d, r, f | a,b,c,d = map(int,input().split())
while True:
c = c - b
if c <= 0:
print("Yes")
break
a = a - d
if a <= 0:
print("No")
break
| 0 | null | 15,079,826,037,430 | 45 | 164 |
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる
mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000
d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))
N, M = LI()
if N == M:
print("Yes")
else:
print("No")
| import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
a, b, c = mapint()
if c-(a+b)>=0:
if 4*a*b<(c-a-b)**2:
print('Yes')
else:
print('No')
else:
print('No') | 0 | null | 67,800,048,890,912 | 231 | 197 |
#template
def inputlist(): return [int(j) for j in input().split()]
#template
from collections import Counter
N = int(input())
A = inputlist()
Q = int(input())
B = [0]*Q
C = [0]*Q
for i in range(Q):
B[i],C[i] = inputlist()
A_sum = sum(A)
dic = Counter(A)
for i in range(Q):
A_sum += (C[i]-B[i])*dic[B[i]]
print(A_sum)
dic[C[i]] += dic[B[i]]
dic[B[i]] = 0 | import math , sys
N = int( input() )
A = list( map( int, input().split() ) )
Q = int( input() )
count = [0 for _ in range( 10**5 + 1)]
for each in A:
count[each]+=1
ans = sum(A)
for _ in range(Q):
B , C = list( map( int , input().split() ) )
D = count[B]
ans += (C-B) * D
count[B] = 0
count[C] += D
print(ans)
| 1 | 12,203,813,491,478 | null | 122 | 122 |
n=int(input())
ans=0
if n%2==0:
for i in range(1,26):
ans+=(n//(2*5**i))
print(ans) | n = int(input())
if n%2==1:
print(0)
else:
ans = 0
div = 10
pt = 1
while div<=n:
ans += n//div
div *=5
print(ans) | 1 | 116,191,168,716,480 | null | 258 | 258 |
print(8 - (int(input()) - 400) // 200)
|
import decimal
#decimal.getcontext().prec = 30
a,b,c = list(map(int, input().split()))
a = decimal.Decimal(a)
b = decimal.Decimal(b)
c = decimal.Decimal(c)
d = decimal.Decimal(0.5)
e = decimal.Decimal(1/10000000)
#print(a**decimal.Decimal(0.5))
if(a**d + b**d < (c)**d ):
print("Yes")
else:
print("No")
#print(a**d + b**d , (c)**d)
| 0 | null | 29,307,418,490,282 | 100 | 197 |
MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
def main():
n,k,c = map(int,input().split())
s = input()
R = [-1] * k
L = [-1] * k
day = INF
cnt = 0
for i in range(n):
if s[i] == 'o':
if day > c:
L[cnt] = i
cnt += 1
if cnt == k:
break
day = 1
else:
day += 1
else:
day += 1
day = INF
cnt = k - 1
for i in range(n - 1,-1,-1):
if s[i] == 'o':
if day > c:
R[cnt] = i
cnt -= 1
if cnt < 0:
break
day = 1
else:
day += 1
else:
day += 1
ans = []
for j in range(k):
if R[j] == L[j]:
ans.append(R[j] + 1)
print(*ans,sep = '\n')
if __name__ =='__main__':
main() | L = int(input())
l3 = L/3
print(pow(l3,3)) | 0 | null | 43,863,193,325,672 | 182 | 191 |
N = int(input())
Count = 0
for T in range(1,N+1):
if not (T%3==0 or T%5==0):
Count = Count+T
print(Count) | n = int(input())
sum = 0
for i in range(1, n + 1):
if i % 3 != 0 and i % 5 != 0:
sum = sum + i
print(sum) | 1 | 34,877,349,824,928 | null | 173 | 173 |
# -*- coding: utf-8 -*-
while True:
line = map(str, raw_input().split())
H = int(line[0])
W = int(line[1])
if H+W:
for i in range(H):
print "#"*W
print ""
else:
break | H=1
W=1
while H!=0 or W!=0:
H,W = [int(i) for i in input().split()]
if H!=0 or W!=0:
for i in range(H):
for j in range(W):
print('#',end='')
print()
print() | 1 | 769,924,030,522 | null | 49 | 49 |
x,y,z=map(int,input().split())
x,y=y,x
x,z=z,x
print(x,y,z,sep=" ")
| n = list(map(int,input().split()))
m = []
for i in range(2):
m.append(n[0])
n.pop(0)
n.append(m[0])
n.append(m[1])
print(*n) | 1 | 38,250,441,067,580 | null | 178 | 178 |
def hash1(m, key):
return key % m
def hash2(m, key):
return 1 + key % (m - 1)
def hash(m, key, i):
return (hash1(m, key) + i * hash2(m, key) ) % m
def insert(T, key):
i = 0
l = len(T)
while True:
h = hash(1046527,key,i)
if (T[h] == None ):
T[h] = key
return h
elif (T[h] == key):
return h
else:
i += 1
def search(T,key):
l = len(T)
i = 0
while True:
h = hash(1046527,key,i)
if(T[h] == key):
return h
elif(T[h] is None or h >= l):
return -1
else:
i += 1
def find(T, key):
a = search(T,key)
if(a == -1):
print('no')
else:
print('yes')
dict = {'A' : '1', 'C' : '2', 'G' : '3', 'T' : '4'}
data = []
T = [None]*1046527
n = int(input())
while n > 0:
st = input()
d = list(st.split())
### convert key to num(1~4)
tmp_key = ''
for x in list(d[1]):
tmp_key += dict[x]
data.append([d[0],int(tmp_key)])
n -= 1
for com in data:
if(com[0] == 'insert'):
insert(T,com[1])
else:
find(T,com[1]) | x, y = map(int,input().split())
ans = 0
for i in range(x+1):
for j in range(x+1):
if 2*i + 4 * j == y and i + j == x:
ans += 1
if ans > 0:
print('Yes')
else:
print('No') | 0 | null | 6,929,413,202,808 | 23 | 127 |
def solve():
N = int(input())
A = [(a, i+1) for i, a in enumerate(map(int, input().split()))]
A.sort(reverse=True)
INF = float('inf')
dp = [[-INF] * (N+1) for _ in range(N+1)]
dp[0][0] = 0
for s in range(1, N+1):
for l in range(s+1):
r = s - l
dp[l][r] = max(dp[l-1][r] + A[s-1][0] * abs(A[s-1][1]-l), dp[l][r-1] + A[s-1][0] * abs(N-r+1-A[s-1][1]))
ans = 0
for m in range(N):
if dp[m][N-m] > ans:
ans = dp[m][N-m]
print(ans)
solve() | # 解説AC
import sys
input = sys.stdin.buffer.readline
n = int(input())
A = list(map(int, input().split()))
B = []
for i, e in enumerate(A):
B.append((e, i + 1))
B.sort(reverse=True)
# dp[i][j]: Aiまで入れた時、左にj個決めた時の最大値
dp = [[-1] * (n + 1) for _ in range(n + 1)]
dp[0][0] = 0
for i in range(n):
for j in range(i + 1): # 左の個数
k = i - j # 右の個数
ni = i + 1
val, idx = B[i]
dp[ni][j] = max(dp[ni][j], dp[i][j] + abs(n - k - idx) * val)
dp[ni][j + 1] = max(dp[ni][j + 1], dp[i][j] + abs(idx - (j + 1)) * val)
ans = 0
for i in range(n + 1):
ans = max(ans, dp[n][i])
print(ans)
| 1 | 33,595,821,528,328 | null | 171 | 171 |
input = input()
W,H,x,y,r = map(int ,input.split())
if x - r < 0 or x + r > W or y - r < 0 or y + r > H:
print("No")
if x - r >= 0 and x + r <= W and y - r >= 0 and y + r <= H:
print("Yes")
| W,H,x,y,r=map(int,input().split())
a = x-r
b = x+r
c = y-r
d = y+r
if a>=0 and b<=W and c>=0 and d<=H:
print("Yes")
else:
print("No")
| 1 | 457,504,004,142 | null | 41 | 41 |
import math
import itertools
import sys
class Dice:
numbers = []
faces = {
'top': None,
'back': None,
'right': None,
'left': None,
'front': None,
'bottom': None,
}
def __init__(self, int_array):
self.numbers = int_array
self.faces['top'] = self.numbers[0]
self.faces['back'] = self.numbers[1]
self.faces['right'] = self.numbers[2]
self.faces['left'] = self.numbers[3]
self.faces['front'] = self.numbers[4]
self.faces['bottom'] = self.numbers[5]
def getNum(self, n):
return self.numbers[n-1]
def getFace(self, f):
return self.faces[f]
def getRightFace(self, t, b):
top = self.faces['top']
back = self.faces['back']
right = self.faces['right']
left = self.faces['left']
front = self.faces['front']
bottom = self.faces['bottom']
if t == self.getNum(2):
self.rotate('N')
elif t == self.getNum(4):
self.rotate('E')
elif t == self.getNum(5):
self.rotate('S')
elif t == self.getNum(3):
self.rotate('W')
elif t == self.getNum(6):
for _ in range(2):
self.rotate('N')
while self.getFace('back') != b:
self.rotate('R')
result = self.getFace('right')
self.faces['top'] = top
self.faces['back'] = back
self.faces['right'] = right
self.faces['left'] = left
self.faces['front'] = front
self.faces['bottom'] = bottom
return result
def rotate(self, direction):
if direction == 'N': # 前回り
top = self.getFace('top') #一時保存
self.faces['top'] = self.faces['back']
self.faces['back'] = self.faces['bottom']
self.faces['bottom'] = self.faces['front']
self.faces['front'] = top
elif direction == 'E': # 右回り
top = self.faces['top'] #一時保存
self.faces['top'] = self.faces['left']
self.faces['left'] = self.faces['bottom']
self.faces['bottom'] = self.faces['right']
self.faces['right'] = top
elif direction == 'S': # 後ろ回り
top = self.faces['top'] #一時保存
self.faces['top'] = self.faces['front']
self.faces['front'] = self.faces['bottom']
self.faces['bottom'] = self.faces['back']
self.faces['back'] = top
elif direction == 'W': # 左回り
top = self.faces['top'] #一時保存
self.faces['top'] = self.faces['right']
self.faces['right'] = self.faces['bottom']
self.faces['bottom'] = self.faces['left']
self.faces['left'] = top
elif direction == 'R': # その場右回り
back = self.faces['back'] #一時保存
self.faces['back'] = self.faces['left']
self.faces['left'] = self.faces['front']
self.faces['front'] = self.faces['right']
self.faces['right'] = back
else: # その場左回り
back = self.faces['back'] #一時保存
self.faces['back'] = self.faces['right']
self.faces['right'] = self.faces['front']
self.faces['front'] = self.faces['left']
self.faces['left'] = back
def main():
number = list(map(int, input().split()))
q = int(input())
dice = Dice(number)
for _ in range(q):
t, b = map(int, input().split())
print(dice.getRightFace(t,b))
if __name__ == '__main__':
main()
| from math import gcd
def main():
N = int(input())
A = list([int(x) for x in input().split()])
max_a = max(A)
before = 0
result = [0 for _ in range(max_a + 1)]
for i in A:
before = gcd(before, i)
result[i] += 1
is_pairwise = True
for i in range(2, max_a + 1):
cnt = 0
for j in range(i, max_a + 1, i):
cnt += result[j]
if cnt > 1:
is_pairwise = False
break
if is_pairwise:
print('pairwise coprime')
exit()
if before == 1:
print('setwise coprime')
else:
print('not coprime')
if __name__ == '__main__':
main()
| 0 | null | 2,172,756,386,638 | 34 | 85 |
X = int(input())
quint = [0] * 1001
for i in range(1, 1001):
quint[i] = i ** 5
for i in range(0, 1001):
a = X - quint[i]
b = X + quint[i]
try:
c = quint.index(a)
print("{} {}".format(c, -i))
break
except:
try:
c = quint.index(b)
print("{} {}".format(c, i))
break
except:
continue | N,R=input().split()
n,r=int(N),int(R)
if n>=10:
print(r)
else:
print(r+100*(10-n)) | 0 | null | 44,330,883,137,122 | 156 | 211 |
n , d = map(int, input().split())
x = []
y = []
for i in range(n):
a = list(map(int, (input().split())))
x.append(a[0])
y.append(a[1])
ans = 0
for i in range(n):
if (x[i] ** 2 + y[i] ** 2) ** (0.5) <= d:
ans += 1
print(ans) | n = int(input())
s = input()
rs = [0]*n
gs = [0]*n
bs = [0]*n
for i in reversed(range(n)):
if s[i] == 'R':
rs[i] += 1
elif s[i] == 'G':
gs[i] += 1
else:
bs[i] += 1
for i in reversed(range(n-1)):
rs[i] += rs[i+1]
gs[i] += gs[i+1]
bs[i] += bs[i+1]
res = 0
for i in range(n):
for j in range(i+1,n-1):
if s[i] == s[j]:
continue
if s[i]!='B' and s[j]!='B':
res += bs[j+1]
if j-i+j < n:
if s[j-i+j] == 'B':
res -=1
elif s[i]!='G' and s[j]!='G':
res += gs[j+1]
if j - i + j < n:
if s[j-i+j] == 'G':
res -=1
else:
res += rs[j+1]
if j - i + j < n:
if s[j-i+j] == 'R':
res -= 1
print(res) | 0 | null | 21,127,063,869,028 | 96 | 175 |
import sys
def input(): return sys.stdin.readline().rstrip()
N, X, M = map(int, input().split())
numlist = [-1] * M
num = X
ans = num
roop_start = -1
for i in range(N-1):
new_num = (num * num) % M
if numlist[num] == -1:
numlist[num] = new_num
ans += new_num
num = new_num
else:
roop_start = num
break
num = roop_start
if roop_start == -1:
print(ans)
else:
roop_sum = [num]
for i in range(N-1):
new_num = numlist[num]
numlist[num] = -1
if numlist[new_num] == -1:
break
else:
roop_sum.append(roop_sum[-1] + new_num)
num = new_num
if numlist[X] != -1:
count = 0
ans = 0
for i in range(M):
if numlist[i] != -1:
ans += i
count += 1
N -= count
else:
ans = 0
size = len(roop_sum)
div = N // size
rest = N % size
ans += div * roop_sum[-1]
if rest != 0:
ans += roop_sum[rest-1]
print(ans) | list = []
n = int(raw_input())
list = map(int, raw_input().split(' '))
list.reverse()
for i in range(len(list)):
print list[i], | 0 | null | 1,918,549,889,440 | 75 | 53 |
S = list(input())
NS = [s for s in S]
K = int(input())
L = len(S)
if "".join(S) == S[0] * L:
print(L * K // 2)
exit()
ans = 0
for i in range(L-1):
f_s = S[i]
s_s = S[i+1]
if f_s == s_s:
S[i+1] = '-'
ans += 1
# 先頭と末尾が異なる
if S[0] != S[-1]:
ans *= K
# 一緒
else:
a = 0
for i in range(L):
if NS[i] == NS[0]:
a += 1
else:
break
b = 0
for i in range(L)[::-1]:
if NS[i] == NS[-1]:
b += 1
else:
break
ans *= K
#t = (- (-a // 2)) + (- (-b // 2)) - (- (-a-b) // 2)
#t = -(-a // 2) - (-b // 2) + (-(a+b) // 2)
t = a // 2 + b // 2 - (a+b) // 2
ans -= t * (K-1)
print(ans)
| S = list(input())
K = int(input())
S.extend(S)
prev = ''
cnt = 0
for s in S:
if s == prev:
cnt += 1
prev = ''
else:
prev = s
b = 0
if K % 2 == 0:
b += 1
if K > 2 and S[0] == S[-1]:
mae = 1
while mae < len(S) and S[mae] == S[0]:
mae += 1
if mae % 2 == 1 and mae != len(S):
usiro = 1
i = len(S) - 2
while S[i] == S[-1]:
usiro += 1
i -= 1
if usiro % 2 == 1:
b = K // 2
if K % 2 == 0:
res = cnt * (K // 2) + (b - 1)
else:
res = cnt * (K // 2) + cnt // 2 + b
print(res)
| 1 | 175,903,873,581,292 | null | 296 | 296 |
a,b,k = map(int,input().split())
t1 = min(a,k)
k -= t1
a -= t1
t2 = min(b,k)
k -= t2
b -= t2
print(a,b) | A, B, K = map(int, input().split())
if A-K <= 0:
K2 = K-A
A_ans = 0
if B-K2 <= 0:
B_ans = 0
else:
B_ans = B-K2
else:
A_ans = A-K
B_ans = B
print(A_ans, B_ans) | 1 | 104,108,309,362,848 | null | 249 | 249 |
import sys
from collections import deque
input = sys.stdin.readline
h, w = list(map(int, input().split()))
t = h * w
s = ""
for i in range(h):
s += input().replace( '\n' , '' )
#print(s)
adj = [[] for _ in range(t)]
for i in range(t):
#よこ
if i % w != 0 and s[i-1] == ".":
adj[i].append(i-1)
if i % w != w-1 and s[i+1] == ".":
adj[i].append(i+1)
#たて
if i - w >= 0 and s[i-w] == ".":
adj[i].append(i-w)
if i + w < t and s[i+w] == ".":
adj[i].append(i+w)
#print(adj)
m = 0
for i in range(t):
if s[i] == "#":
pass
else:
#BFS
depth = [0] * t
visited = [False] * t
q = deque([i])
visited[i] = True
while len(q) > 0:
v = q.popleft()
for w in adj[v]:
if not visited[w]:
q.append(w)
visited[w] = True
depth[w] = depth[v] + 1
#print(depth)
m = max(m, max(depth))
print(m)
| n = int(input())
i = 1
#end_check_num
while i <= n:
#check_num
x = i
if x % 3 == 0:
print(" %d" % i, end = "")
else:
#INCLUDE3
while x != 0:
if x % 10 == 3:
print(" %d" % i, end = "")
break
x //= 10
i += 1
print() | 0 | null | 47,607,883,118,584 | 241 | 52 |
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
n = int(input())
ans = 0
for i in range(1, n+1):
ans += i*(1 + n//i)*(n//i)//2
print(ans)
if __name__=='__main__':
main() | r=input().split()
H=int(r[0])
N=int(r[1])
data_pre=input().split()
data=[int(s) for s in data_pre]
if sum(data)>=H:
print("Yes")
else:
print("No") | 0 | null | 44,604,297,817,566 | 118 | 226 |
from itertools import permutations
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
r = 0
for i, x in enumerate(permutations([j for j in range(1,N+1)])):
if x == P:
r = abs(r-i)
if x == Q:
r = abs(r-i)
print(r)
| import math
import itertools
N=int(input())
P=list(map(int,input().split()))
Q=list(map(int,input().split()))
ls=[]
for i in range(1,N+1):
ls.append(i)
ls2 = list(itertools.permutations(ls,N))
#print(ls2)
cnt1 = 0
cnt2 = 0
for j in range(math.factorial(N)):
for i in range(N):
#print(j,i,P[i],ls2[j][i])
if P[i] == ls2[j][i]:
cnt1 += 1
if Q[i] == ls2[j][i]:
cnt2 += 1
#print("cnt1",cnt1,"cnt2",cnt2)
if cnt1 == N:
a = j
if cnt2 == N:
b = j
cnt1 = 0
cnt2 = 0
#print(a,b)
print(abs(a-b))
| 1 | 100,863,428,280,160 | null | 246 | 246 |
import sys
N = int(input())
S,T = input().split()
if not ( 1 <= N <= 100 ): sys.exit()
if not ( len(S) == len(T) and len(S) == N ): sys.exit()
if not ( S.islower() and T.islower() ): sys.exit()
for I in range(N):
print(S[I],end='')
print(T[I],end='') | n = int(input())
s = input().split(" ")
nums = list(map(int,s))
koukan = 0
for i in range(n):
minj = i
for j in range(i+1,n):
if nums[j] < nums[minj]:
minj = j
w = nums[i]
nums[i] = nums[minj]
nums[minj] = w
if i != minj:
koukan += 1
for i in range(n):
if i == n-1:
print(nums[i])
else:
print(nums[i],end=" ")
print(koukan) | 0 | null | 55,955,031,762,224 | 255 | 15 |
n = input()
list = raw_input().split(" ")
list.reverse()
print " ".join(list) | n=int(input());l=list(map(int,input().split()));p=[0]*n;d=[0]*n
for i in range(n):p[i]=l[i]+p[i-2];d[i]=max(p[i-1]if i&1else d[i-1],l[i]+d[i-2])
print(d[-1]) | 0 | null | 19,266,491,335,392 | 53 | 177 |
l=int(input())
m=l/3
s=m**3
print(s) | n,d,a = map(int,input().split())
xh = [list(map(int,input().split())) for _ in range(n)]
xh.sort()
ans = 0
att = [0]*n
cnt = 0
f = []
f1 = [0]*n
for x,h in xh:
f.append(h)
for i in range(n):
tmp = xh[i][0] + 2 * d
while cnt < n:
if xh[cnt][0] <= tmp:
cnt += 1
else:
break
att[i] = min(cnt-1, n-1)
for i in range(n):
if f[i] > 0:
da = -(-f[i]//a)
ans += da
f1[i] -= da * a
if att[i]+1 < n:
f1[att[i]+1] += da * a
if i < n-1:
f1[i+1] += f1[i]
f[i+1] += f1[i+1]
print(ans)
| 0 | null | 64,932,836,414,648 | 191 | 230 |
from itertools import combinations
n = int(input())
def dfs(s):
if len(s) == n:
print(s)
return 0
for i in range(ord('a'), ord(max(s))+2):
t = s
t += chr(i)
dfs(t)
dfs('a') | # https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_d
def main():
n = int(input())
data = [chr(ord("a") + i) for i in range(10)]
generate("a", 0, n, data)
def generate(cur, max_i, n, data):
if len(cur) == n:
print(cur)
return
for i in range(max_i + 2):
generate(cur + chr(ord("a") + i), max(max_i, i), n, data)
if __name__ == '__main__':
main()
| 1 | 52,388,471,773,950 | null | 198 | 198 |
n = int(input())
sum = 0
for _ in range(n):
a = int(input())
if a == 2:
continue
for i in range(a):
x = i + 2
if a%x == 0:
sum += 1
break
if x > a ** 0.5:
break
print(n - sum)
| from math import sqrt
def isPrime(x):
if x == 2:
return True
if x < 2 or x % 2 == 0:
return False
i, xx = 3, int(sqrt(x))
while i <= xx:
if x % i == 0:
return False
i = i + 2
return True
N = int(input())
print(sum([1 for _ in range(N) if isPrime(int(input()))])) | 1 | 10,454,379,602 | null | 12 | 12 |
N = input()
if N.endswith('2') == True or N.endswith('4') == True or N.endswith('5') == True or N.endswith('7') == True or N.endswith('9') == True:
print('hon')
elif N.endswith('0') == True or N.endswith('1') == True or N.endswith('6') == True or N.endswith('8') == True:
print('pon')
else:
print('bon') |
x=input()
l=(x/60)
h=(l/60)
m=(l-h*60)
s=x-m*60-h*60*60
print str(h)+":"+str(m)+":"+str(s) | 0 | null | 9,860,582,563,920 | 142 | 37 |
def main():
global s,ide_ele,num,seg
n = int(input())
s = list(input())
for i in range(n):
s[i] = ord(s[i])-97
ide_ele = 0
num = 2**(n-1).bit_length()
seg = [[ide_ele for _ in range(2*num)] for _ in range(26)]
for i in range(n):
seg[s[i]][i+num-1] = 1
for a in range(26):
for i in range(num-2,-1,-1) :
seg[a][i] = max(seg[a][2*i+1],seg[a][2*i+2])
q = int(input())
for _ in range(q):
QUERY = list(input().split())
QUERY[0], QUERY[1] = int(QUERY[0]), int(QUERY[1])
if QUERY[0] == 1:
x = ord(QUERY[2])-97
k = QUERY[1]-1
pre = s[k]
s[k] = x
k += num-1
seg[pre][k] = 0
seg[x][k] = 1
while k:
k = (k-1)//2
seg[pre][k] = max(seg[pre][k*2+1],seg[pre][k*2+2])
seg[x][k] = max(seg[x][k*2+1],seg[x][k*2+2])
if QUERY[0] == 2:
P, Q = QUERY[1]-1, int(QUERY[2])
if Q <= P:
print(ide_ele)
break
P += num-1
Q += num-2
ans = ide_ele
for i in range(26):
res = ide_ele
p,q = P,Q
while q-p > 1:
if p&1 == 0:
res = max(res,seg[i][p])
if q&1 == 1:
res = max(res,seg[i][q])
q -= 1
p = p//2
q = (q-1)//2
if p == q:
res = max(res,seg[i][p])
else:
res = max(max(res,seg[i][p]),seg[i][q])
ans += res
print(ans)
if __name__ == "__main__":
main() | 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 | 31,143,411,579,140 | 210 | 28 |
a,b,c=map(int,input().split())
print('Yes' if c>a+b and 4*a*b<(c-a-b)**2 else 'No') | import math
r = float(input())
print("%.6f %.6f" % (math.pi * r**2, 2 * math.pi * r))
| 0 | null | 26,240,340,930,522 | 197 | 46 |
import sys
import re
stri = sys.stdin.readline()
ret = re.match( '^(hi)+$', stri)
if ret:
print("Yes")
else:
print("No")
sys.stdout.flush() | S = input()
ans = 'Yes'
if len(S)%2 != 0:
print('No')
exit()
for i in range(0,len(S),2):
if S[i] != 'h':
print('No')
exit()
if S[i+1] != 'i':
print('No')
exit()
print('Yes')
| 1 | 53,007,165,785,380 | null | 199 | 199 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N,T = map(int,readline().split())
m = map(int,read().split())
AB = sorted(zip(m,m))
can_add = [0] * N
for n in range(N-1,0,-1):
x = can_add[n]
y = AB[n][1]
can_add[n-1] = x if x > y else y
dp = np.zeros(T,np.int64)
answer = 0
for i,(a,b) in enumerate(AB):
np.maximum(dp[a:], dp[:-a] + b, out = dp[a:])
x = dp.max() + can_add[i]
if answer < x:
answer = x
print(answer)
| import sys
readline = sys.stdin.buffer.readline
n,t = map(int,readline().split())
dp = [0]*(t+1)
AB = [list(map(int,readline().split())) for i in range(n)]
AB.sort(reverse=True)
for i in range(n):
a,b = AB[i]
for j in range(t):
if j+a > t:
dp[j] = max(dp[j],b)
else:
dp[j] = max(dp[j],dp[j+a]+b)
print(dp[0]) | 1 | 152,024,422,090,268 | null | 282 | 282 |
A, B=input().split()
a=int(A)
R,E=B.split('.')
while len(E)<2:
E=E+0
c=int(R+E)
p=str(a*c)
if len(p)<=2:
print(0)
else:
print(p[0:len(p)-2])
| N = int(input())
i = 1
sum = 0
while True:
if i%3!=0 and i%5!=0:
sum +=i
i+=1
if i==N+1:
break
print (sum) | 0 | null | 25,885,787,060,592 | 135 | 173 |
a, b, c, k = map(int, input().split())
ans = 0
for i, j in zip([1, 0, -1], [a, b, c]):
x = min(k, j)
ans += i*x
k -= x
print(ans)
| import sys
def input(): return sys.stdin.readline().rstrip()
A,B,C,K = map(int,input().split())
point = 0
if A <= K:
point += A
K -= A
else:
point += K
K = 0
if B <= K:
K -= B
else:
K = 0
point -= K
print(point) | 1 | 21,756,913,848,460 | null | 148 | 148 |
r = int(input())
if 1 <= r <= 100:
print(int(r*r)) | class Dice:
def __init__(self,u,s,e,w,n,d):
self.n = n
self.e = e
self.s = s
self.w = w
self.u = u
self.d = d
def roll(self,dir):
if (dir == "N"):
tmp = self.n
self.n = self.u
self.u = self.s
self.s = self.d
self.d = tmp
elif (dir == "E"):
tmp = self.e
self.e = self.u
self.u = self.w
self.w = self.d
self.d = tmp
elif (dir == "S"):
tmp = self.s
self.s = self.u
self.u = self.n
self.n = self.d
self.d = tmp
elif (dir == "W"):
tmp = self.w
self.w = self.u
self.u = self.e
self.e = self.d
self.d = tmp
spots = raw_input().split()
operations = raw_input()
dice = Dice(*spots)
for i in operations:
dice.roll(i)
print dice.u | 0 | null | 72,936,135,387,630 | 278 | 33 |
import math
a, b, C=map(int, input().split())
print("{0:.5f}".format((1/2)*a*b*math.sin(C*math.pi/180.0)))
print("{0:.5f}".format(a+b+math.sqrt(a**2+b**2-2*a*b*math.cos(C*math.pi/180))))
print("{0:.5f}".format(b*math.sin(C*math.pi/180.0))) | # coding:utf-8
import math
a,b,C=list(map(float,input().split()))
h=b*math.sin(math.radians(C))
S=a*h/2
c=math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(C)))
L=a+b+c
print('%.6f'%S)
print('%.6f'%L)
print('%.6f'%h) | 1 | 173,876,729,180 | null | 30 | 30 |
H,W = map(int,input().split())
if H==1 or W==1:
print(1)
elif H%2==0 and W%2==0 or H%2==0 and W%2==1 or H%2==1 and W%2==0:
print((H*W)//2)
else:
print(((H*W)+1)//2) | from math import ceil
h,w=map(int,input().split())
ans=0
if h==1 or w==1:
ans=1
elif (h*w)%2==0:
ans=int(h*w//2)
else:
ans=ceil(h*w/2)
print(ans) | 1 | 50,459,621,985,672 | null | 196 | 196 |
x = int(input())
ans, r = divmod(x, 500)
ans *= 1000
ans += (r//5)*5
print(ans)
| X = int(input())
c1 = X//500
X = X - c1*500
c2 = X//5
print(c1*1000 + c2*5) | 1 | 42,664,633,512,032 | null | 185 | 185 |
x, y = map(int, input().split())
prise_dict = {3: 100000, 2: 200000, 1: 300000}
ans = 0
if x in prise_dict.keys():
ans += prise_dict[x]
if y in prise_dict.keys():
ans += prise_dict[y]
if x == y == 1:
ans += 400000
print(ans)
| if __name__ == '__main__':
for i in range(1,10):
for j in range(1,10):
print(str(i)+"x"+str(j)+"="+str(i*j)) | 0 | null | 69,954,900,052,530 | 275 | 1 |
def selection_Sort(A,N):
count = 0
for i in range(N):
minj = i
for j in range(i,N):
if A[j] < A[minj]:
minj = j
if i != minj:
A[i],A[minj] = A[minj],A[i]
count += 1
return (count)
if __name__ == '__main__':
n = int(input())
data = [int(i) for i in input().split()]
result = selection_Sort(data,n)
print(" ".join(map(str,data)))
print(result) | def selection(A, N):
count = 0
for i in range(0, N):
minj = i
for j in range(i, N):
if A[j] < A[minj]:
minj = j
if i != minj:
A[i], A[minj] = A[minj], A[i]
count += 1
return A, count
if __name__ == "__main__":
N = int(input())
A = [int(i) for i in input().split()]
A, count = selection(A, N)
print (*A)
print (count) | 1 | 20,997,033,502 | null | 15 | 15 |
# coding: utf-8
n = int(input())
A = list(map(int, input().split()))
mini = 1
c = 0
for i in range(n):
mini = i
for j in range(i, n):
if A[j] < A[mini]:
mini = j
A[i], A[mini] = A[mini], A[i]
if mini != i:
c += 1
print(" ".join(map(str, A)))
print(c) | a, b, k = map(int, input().split())
print(min(a, max(a-k, 0)), min(b, max(b-k+a, 0))) | 0 | null | 52,030,016,039,078 | 15 | 249 |
import math
from functools import reduce
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
N = int(input())
A = list(map(int,input().split()))
ans = 0
lcm = lcm_list(A)
for i in range(N):
ans += lcm//A[i]
print(ans%1000000007) | from fractions import gcd
def main():
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7
lcm = 1
for a in A:
lcm = lcm * a // gcd(lcm, a)
ans = 0
for a in A:
ans += lcm // a
print(ans % MOD)
if __name__ == "__main__":
main() | 1 | 87,787,214,397,700 | null | 235 | 235 |
import math
x1,y1,x2,y2=map(float,input().split())
print(round(math.sqrt((x1-x2)**2+(y1-y2)**2),7))
| #coding:utf-8
#1_10_A 2015.4.10
import math
x1,y1,x2,y2 = list(map(float,input().split()))
distance = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
print('{:.5f}'.format(distance)) | 1 | 149,875,933,120 | null | 29 | 29 |
N = int(input())
K = N % 2 + 1
A = tuple(map(int, input().split()))
table = [[-float("inf")] * (K + 2) for _ in range(N + 1)]
table[0][0] = 0
for i in range(N):
for j in range(K + 1):
table[i + 1][j] = max(table[i][j] + (A[i] if not (i + j) % 2 else 0), table[i + 1][j])
table[i + 1][j + 1] = max(table[i][j], table[i + 1][j + 1])
print(table[N][K])
| def answer(n: int, s: str, t: str) -> str:
new_str = ''
for i in range(n):
new_str += f'{s[i]}{t[i]}'
return new_str
def main():
n = int(input())
s, t = input().split()
print(answer(n, s, t))
if __name__ == '__main__':
main()
| 0 | null | 74,778,311,572,230 | 177 | 255 |
rooms = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
n = int(input())
for i in range(n):
b, f, r, v= map(int, input().split())
rooms[b-1][f-1][r-1] += v
for i in range(4):
for j in range(3):
for k in range(10):
print('', rooms[i][j][k], end='')
print()
if i < 3:
print('####################') | s = input()
lc = s.lower()
uc = s.upper()
ans = ""
for i in range(len(s)):
if s[i] == lc[i]:
ans += uc[i]
else:
ans += lc[i]
print(ans)
| 0 | null | 1,319,335,021,090 | 55 | 61 |
import sys
import bisect
from functools import lru_cache
from collections import defaultdict
from collections import deque
inf = float('inf')
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline().rstrip()
def read():
return int(readline())
def reads():
return map(int, readline().split())
s=input()
n=len(s)
ten=[1]
mod=2019
for i in range(n-1):
ten.append((ten[i]*10)%mod)
modls=[0]*n
modls[n-1]=int(s[n-1])
dic=defaultdict(int)
dic[modls[n-1]]+=1
dic[0]=1
for i in range(n-2,-1,-1):
modls[i]=int(s[i])*ten[n-1-i]+modls[i+1]
modls[i]%=mod
dic[modls[i]]+=1
ans=0
#print(dic)
for num in dic.values():
ans+=num*(num-1)//2
#ans+=dic[0]
print(ans) | h, w = map(int, input().split())
print(1) if h == 1 or w == 1 else print((h * w + 1) // 2) | 0 | null | 41,090,188,299,030 | 166 | 196 |
n=int(input())-1
print(n//2) | from sys import stdin
from collections import deque
sect = stdin.readline().lstrip("/_").rstrip("\n\\_")
stack = deque()
res = deque()
for i in range(len(sect)):
if sect[i] == "\\":
stack.append(i)
elif sect[i] == "/":
if len(stack) != 0:
b = stack.pop()
if len(res) == 0:
res.append( (b, i-b) )
elif b > res[-1][0]:
res.append( (b, i-b) )
else: # 水たまりを結合
sum_L = i-b
while len(res) != 0:
if res[-1][0] > b:
sum_L += res[-1][1]
res.pop()
else:
break
res.append((b, sum_L))
res = [x[1] for x in res]
print(sum(res))
print(len(res), *res)
| 0 | null | 76,547,917,890,220 | 283 | 21 |
n,*l=map(int,open(0).read().split())
a=t=0
for i in l:
if i>t: t=i
a+=t-i
print(a) | N, S = map(int, input().split())
A = list(map(int, input().split()))
# dp[n][i][s] := i 番目まで見て n 個使って合計が s になる場合の数 これは無理
# dp[i][s] := i 番目まで見て合計 s
dp = [[0]*(S+1) for _ in range(N+1)]
dp[0][0] = 1
mod = 998244353
for i, a in enumerate(A, 1):
for s in range(S+1):
if s-a >= 0:
dp[i][s] = (dp[i-1][s] * 2 + dp[i-1][s-a]) % mod
else:
dp[i][s] = dp[i-1][s] * 2 % mod
print(dp[N][S]) | 0 | null | 11,147,176,960,918 | 88 | 138 |
r, c, k = map(int, input().split())
rcv = [list(map(int, input().split())) for i in range(k)]
area = [[0] * (c+1) for i in range(r+1)]
for a, b, v in rcv:
area[a-1][b-1] = v
# dp[i][j][k]: その行でiまで拾っており、
# j行k列目に到達時点の最大スコア
dp = [[[-1] * (c+1) for i in range(r+1)] for j in range(4)]
dp[0][0][0] = 0
for rr in range(r+1):
for cc in range(c+1):
for i in range(4):
# 取って右
if i+1<4 and cc<c and area[rr][cc]>0:
dp[i+1][rr][cc+1] = max(dp[i+1][rr][cc+1],
dp[i][rr][cc]+area[rr][cc])
# 取って下
if i+1<4 and rr<r and area[rr][cc]>0:
dp[0][rr+1][cc] = max(dp[0][rr+1][cc],
dp[i][rr][cc]+area[rr][cc])
# 取らずに右
if cc<c:
dp[i][rr][cc+1] = max(dp[i][rr][cc+1],
dp[i][rr][cc])
# 取らずに下
if rr<r:
dp[0][rr+1][cc] = max(dp[0][rr+1][cc],
dp[i][rr][cc])
# ans: r行c列目の最大値(iは問わず)
ans = max([dp[i][r][c] for i in range(4)])
print(ans)
| R, C, K = map(int, input().split())
# = int(input())
p = []
for k in range(K):
p.append(list(map(int, input().split())))
maps = [[0 for _ in range(C)] for _ in range(R)]
for k in range(K):
maps[p[k][0]-1][p[k][1]-1] += p[k][2]
point1 = [[0 for _ in range(C)] for _ in range(R)]
point2 = [[0 for _ in range(C)] for _ in range(R)]
point3 = [[0 for _ in range(C)] for _ in range(R)]
point1[0][0] = maps[0][0]
for r in range(R):
for c in range(C):
a, b, d = point1[r][c], point2[r][c], point3[r][c]
if c < C - 1:
x = maps[r][c+1]
point1[r][c+1] = max(point1[r][c+1], x, a)
point2[r][c+1] = max(point2[r][c+1], a + x, b)
point3[r][c+1] = max(point3[r][c+1], b + x, d)
if r < R - 1:
point1[r+1][c] = maps[r+1][c] + max(a, b, d)
print(max(point1[-1][-1], point2[-1][-1], point3[-1][-1])) | 1 | 5,610,618,095,798 | null | 94 | 94 |
n,k=map(int,input().split())
count = 0
while n/k >0:
n//=k
count+=1
print(count) | # B - Digits
N,K = map(int,input().split())
i = 1
while K**i-1<N:
i += 1
print(i) | 1 | 64,024,158,533,328 | null | 212 | 212 |
# 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()
T = 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
ma = 0
s = len(S)
t = len(T)
for i in range(s - t + 1):
cnt = 0
for j in range(t):
if S[i + j] == T[j]:
cnt += 1
if cnt > ma:
ma = cnt
print(t - ma) | from math import gcd
N = int(input())
num_lis = list(map(int, input().split()))
def osa_k(max_num):
lis = [i for i in range(max_num+1)]
p = 2
while p**2 <= max_num:
if lis[p] == p:
for q in range(2*p, max_num+1, p):
if lis[q] == q:
lis[q] = p
p += 1
return lis
hoge = 0
for i in num_lis:
hoge = gcd(hoge, i)
if hoge > 1:
print("not coprime")
exit()
d_lis = osa_k(max(num_lis))
tmp = set()
for i in num_lis:
num = i
new_tmp = set()
while num > 1:
d = d_lis[num]
new_tmp.add(d)
num //= d
for j in new_tmp:
if j in tmp:
print("setwise coprime")
exit()
else:
tmp.add(j)
print("pairwise coprime") | 0 | null | 3,904,758,360,100 | 82 | 85 |
x=input()
lst=x.split(" ")
print(int(lst[0])*int(lst[1])) | S = list(input())
count = 0
ans = 0
for i in range(len(S)):
if S[i] == 'R':
count += 1
if ans < count:
ans = count
else:
count = 0
print(ans) | 0 | null | 10,292,203,136,322 | 133 | 90 |
X=int(input())
for i in range(1,10000):
if (i*X)%360==0:
print(i)
break | def gcd(a, b):
a, b = max(a, b), min(a, b)
if b == 0:
return a
return gcd(b, a % b)
def main():
X = int(input())
ans = 360 // gcd(X, 360)
print(ans)
if __name__ == "__main__":
main()
| 1 | 13,033,426,573,790 | null | 125 | 125 |
while 1:
H, W = map(int, raw_input().split())
if H == W == 0:
break
print ('#'*W + '\n')*H | while 1:
H, W = map(int, input().split())
if (H == 0 and W == 0) : break
for i in range(H):
x = ""
for j in range(W):
x += "#"
print(x)
print("") | 1 | 773,577,741,330 | null | 49 | 49 |
n = int(input())
all_result = 10 ** n
nothing = 8 ** n
only_1 = 9 ** n
result = all_result + nothing - 2 * only_1
print(result % (10**9+7)) | n = int(input())
nAll = 10**n
nOne = 2*(9**n)
nBoth = 8**n
print((nAll - nOne + nBoth)%(10**9+7)) | 1 | 3,206,140,352,990 | null | 78 | 78 |
n = int(input())
a = list(map(int, input().split()))
b = sorted(enumerate(a), key=lambda x:x[1])
c = [b[i][0]+1 for i in range(n)]
d = [str(x) for x in c]
e = " ".join(d)
print(e) | import sys
input = sys.stdin.readline
from collections import defaultdict, deque
n, s = int(input()), list(map(int, input().split()))
res = [0 for i in range(n)]
for i in range(n): res[s[i]-1] = i + 1
print(' '.join(str(i) for i in res)) | 1 | 180,499,971,861,550 | null | 299 | 299 |
# -*- coding: utf-8 -*-
# 1つの文字列
s = str(input())
ans = ''
for i in range(3):
ans = ans + s[i]
print(ans)
| def main():
print(input()[:3])
main()
| 1 | 14,751,202,021,782 | null | 130 | 130 |
K, X = map(int, input().split())
K *= 500
if K >= X:
print("Yes")
else:
print("No")
| n=int(input())
l=[['a1']]+[[] for _ in range(9)]
for i in range(9):
for b in l[i]:
t=b[-1]
for p in range(int(t)):
l[i+1].append(b[:-1]+chr(97+p)+t)
l[i+1].append(b[:-1]+chr(97+int(t))+str(int(t)+1))
for i in l[n-1]:
if len(i)==12:
print(i[:-2])
else:
print(i[:-1]) | 0 | null | 75,168,255,314,282 | 244 | 198 |
a = input()
hi_cnt = a.count('hi')
if hi_cnt > 0:
if hi_cnt * 2 == len(a):
print('Yes')
else:
print('No')
else:
print('No') |
cnt = 0
SENTINEL = 2000000000
def merge(arr, length, left, mid, right):
# n1 = mid - left
# n2 = right - mid
L = arr[left : mid]
R = arr[mid : right]
L.append(SENTINEL)
R.append(SENTINEL)
i, j = 0, 0
for k in range(left, right):
global cnt
cnt += 1
if (L[i] <= R[j]):
arr[k] = L[i]
i += 1
else:
arr[k] = R[j]
j += 1
def merge_sort(arr, length, left, right):
if (left + 1 < right):
mid = (left + right)//2
merge_sort(arr, length, left, mid)
merge_sort(arr, length, mid, right)
merge(arr, n, left, mid, right)
if __name__ == '__main__':
n = int(input())
S = list(map(int, input().split()))
merge_sort(S, n, 0, n)
print(' '.join(map(str, S)))
print(cnt)
| 0 | null | 26,773,583,205,838 | 199 | 26 |
from operator import itemgetter
n = int(input())
s = []
for i in range(n):
l = list(map(int, input().split()))
rang = [l[0] - l[1], l[0] + l[1]]
s.append(rang)
s_sort = sorted(s, key=itemgetter(1))
ans = 0
last = -float("inf")
for i in range(n):
if last <= s_sort[i][0]:
ans += 1
last = s_sort[i][1]
print(ans)
| 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()
P=[-1]*N#親から来た辺の色だけ持っておく
C=[0]*(N-1)
adj=[[]for _ in range(N)]
from collections import defaultdict
dd = defaultdict(lambda : -1)
dd2 = defaultdict(lambda : -1)
for i in range(N-1):
a,b=MI()
a-=1
b-=1
adj[a].append(b)
adj[b].append(a)
dd[(a,b)] = i
dd2[i]=(a,b)
import queue
q=queue.Queue()
q.put((0,-1))
while not q.empty():
v,p=q.get()
col=0
for i in range(len(adj[v])):
nv=adj[v][i]
if nv==p:
continue
if col==P[v]:
col+=1
a=min(v,nv)
b=max(v,nv)
ii=dd[(a,b)]
C[ii]=col
P[nv]=col
col+=1
q.put((nv,v))
K=0
for i in range(N):
K=max(K,len(adj[i]))
print(K)
for i in range(N-1):
print(C[i]+1)
main()
| 0 | null | 112,801,570,039,840 | 237 | 272 |