code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
6.82M
181,637B
question_pair_id
float64
101M
180,471B
code1_group
int64
2
299
code2_group
int64
2
299
n,m=input().split() print(m+n)
def insertion_sort(a, g, n): cnt = 0 for i in range(g, n): v = a[i] j = i - g while j >= 0 and a[j] > v: a[j + g] = a[j] j = j - g cnt += 1 a[j + g] = v return cnt def shell_sort(a, n): cnt = 0 g = [] h = 1 while h <= n: g.append(h) h = 3 * h + 1 g.reverse() m = len(g) print(m) print(*g) for i in range(m): cnt += insertion_sort(a, g[i], n) print(cnt) n = int(input()) a = [int(input()) for _ in range(n)] shell_sort(a, n) print('\n'.join(map(str, a)))
0
null
51,268,919,167,104
248
17
s=input() q=int(input()) cnt=0 front=[] rear=[] for qq in range(q): l=list(input().split()) if l[0]=='1': cnt+=1 else: if (cnt+int(l[1]))%2==1: front.append(l[2]) else: rear.append(l[2]) front=''.join(front[::-1]) rear=''.join(rear) s=front+s+rear print(s if cnt%2==0 else s[::-1])
n, x = map(int, input().split()) while n != 0 or x != 0: count = 0 for i in range(1, n+1): for j in range(i+1, n+1): for k in range(j+1, n+1): if i+j+k == x: count += 1 print(count) n, x = map(int, input().split())
0
null
29,389,697,742,412
204
58
s1 = str(input()) s2 = str(input()) n = len(s1) if s1 == s2[:n]: print('Yes') else: print('No')
S=list(input()) T=list(input()) T.pop(len(T)-1) if S == T: print("Yes") else: print("No")
1
21,389,106,107,808
null
147
147
a, b, c, d = map(int, input().split()) e = a*c f = a*d g = b*c h = b*d print(max(e,f,g,h))
a,b,c,d=map(int,input().split()) ans=[] ans.append(a*c) ans.append(a*d) ans.append(b*c) ans.append(b*d) print(max(ans))
1
3,065,783,278,240
null
77
77
h,w,k=[int(j) for j in input().split()] s=[list(map(int,list(input()))) for i in range(h)] import itertools s=tuple(itertools.chain(*zip(*s))) ans=10**18 for i in range(1<<(h-1)): dp=list(s) for j in range(h-1): if i&(1<<j): for n in range(0,h*w,h): dp[n+j+1]+=dp[n+j] tmp=h-1-bin(i).count("1") b=False for n in range(0,h*w,h): if any(dp[n+j]>k for j in range(h)): tmp=10**18 break if n+h==h*w: ans=min(ans,tmp) tmp=10**18 break if any(dp[n+j]+dp[n+j+h]>k for j in range(h)): tmp+=1 continue for j in range(h): dp[n+j+h]+=dp[n+j] ans=min(ans,tmp) print(ans)
sel='E' #A if sel=='A': N,M=map(int,input().split()) ans=0 ans+=M*(M-1)//2 ans+=N*(N-1)//2 print(ans) #B if sel=='B': def ispal(s): for i in range(len(s)//2+1): if s[i]!=s[-(i+1)]: return False return True S=input() N=len(S) if ispal(S) and ispal(S[:(N-1)//2]) and ispal(S[(N+3)//2-1:]): print('Yes') else: print('No') #C if sel=='C': L=int(input()) print((L**3)/27) #D if sel=='D': N=int(input()) A=[int(i) for i in input().split()] kin=list(set(A)) cnt={} for k in kin: cnt[k]=0 for a in A: cnt[a]+=1 SUM=0 for k in kin: SUM+=cnt[k]*(cnt[k]-1)//2 for a in A: if cnt[a]>=2: print(SUM-cnt[a]+1) else: print(SUM) #E if sel=='E': def add(in1, in2): return [a + b for a, b in zip(in1, in2)] def split(ar, k, w): a = 0 if max(max(ar)) > k: return -1 tm = ar[0] for i in range(1, w): tm = add(tm, ar[i]) if max(tm) > k: a += 1 tm = ar[i] return a h, w, k = map(int, input().split()) s = [[int(i) for i in input()] for j in range(h)] ans = h*w for i in range(2**(h-1)): data = [] temp = s[0] sp = bin(i+2**h)[4:] for j in range(1, h): if sp[j-1] == "0": temp = add(temp, s[j]) else: data.append(temp) temp = s[j] data.append(temp) ans_ = split([list(x) for x in zip(*data)], k, w) if ans_ == -1: continue ans_ += sp.count("1") if ans > ans_: ans = ans_ print(ans) # #F # if sel=='F': # N,S=map(int,input().split()) # A=[int(i) for i in input().split()]
1
48,677,306,133,960
null
193
193
s = list(input()) t = len(s) if t==1 and s[0]=="?": s[0]="D" for i in range(t-1): if i==0 and s[i]=="?": s[i]="D" if s[i+1]=="?": s[i+1]="D" elif s[-1]=="?" and s[-2]=="D" and i==t-2: s[-1]="D" elif s[i]=="D" and s[i+1]=="?" and s[i+2]=="P": s[i+1]="D" elif s[i]=="P" and s[i+1]=="?": s[i+1]='D' elif s[i]=="D" and s[i+1]=="?": s[i+1]='P' print("".join(s))
T=str(input()) T2=list(T) if T2[0]=="?": T2[0]="D" if T2[len(T)-1]=="?": T2[len(T)-1]="D" for i in range(1,len(T2)-1): if T2[i]=="?": if T2[i-1]=="D" and T2[i+1]!="P": T2[i]="P" else: T2[i]="D" ans="".join(T2) print(ans)
1
18,337,397,258,180
null
140
140
n=int(input()) a=list(map(int,input().split())) mod=10**9+7 c=[0]*60 for aa in a: for i in range(60): if aa&(1<<i):c[i]+=1 ans=0 for i,cc in enumerate(c): ans+=cc*(n-cc)*2**i ans%=mod print(ans)
p0 = 10**9+7 def pow(x,m): if m==0: return 1 if m==1: return x if m%2==0: return (pow(x,m//2)**2)%p0 else: return (x*(pow(x,(m-1)//2)**2)%p0)%p0 N = int(input()) A = list(map(int,input().split())) A = [bin(A[i])[2:] for i in range(N)] A = ["0"*(60-len(A[i]))+A[i] for i in range(N)] C = {k:0 for k in range(60)} for i in range(N): for m in range(60): if A[i][m]=="1": C[59-m] += 1 B = [0 for _ in range(60)] for k in range(60): p = C[k] m = N-C[k] B[k] = p*m cnt = 0 for k in range(60): cnt = (cnt+B[k]*pow(2,k))%p0 print(cnt)
1
122,853,092,976,656
null
263
263
a,b = map(int,input().split()) if a <= b or a - (b * 2) <= 0: print("0") else: print(a - (b * 2))
# N=int(input()) A,B=[int(x) for x in input().rstrip().split()] if A<=B*2: print(0) else: print(A-B*2)
1
166,632,146,633,048
null
291
291
x,k,d = map(int,input().split()) def judge(): l = x if x > 0 else -x i = l//d r = l%d if (k - i)%2 == 0: print(r) else: print(d - r) ''' if x > 0: for r in range(d): if (x - r)/d == (x - r)//d: i = (x - r)//d if (k - i)%2 == 0: print(r) else: print(d-r) exit() else: l = -x for r in range(d): if (l - r)/d == (l - r)//d: i = (l - r)//d if (k - i)%2 == 0: print(r) else: print(d-r) exit() ''' if x == 0: if k%2 == 0: print(0) else: print(d) elif x < 0: if k*d + x > 0: judge() else: print(abs(k*d + x)) else: if x - k*d < 0: judge() else: print(abs(x - k*d))
while True: s = input().split(" ") a = int(s[0]) op = s[1] b = int(s[2]) if op == "?": break elif op == "+": print(a + b) elif op == "-": print(a - b) elif op == "*": print(a * b) else: print(a // b)
0
null
2,984,118,657,792
92
47
from sys import stdin global time time = 0 def dfs(graph,start,state,discover,finish): state[start-1] = 1 global time time = time + 1 discover[start-1] = time # print str(time) + " go to " + str(start) neighbours = sorted(graph[start]) for neighbour in neighbours: if state[neighbour-1] == 0: dfs(graph,neighbour,state,discover,finish) state[start-1] = 2 time = time + 1 finish[start - 1] = time # print str(time) + " out of " + str(start) def main(): # g = {1: [2, 3], # 2: [3, 4], # 3: [5], # 4: [6], # 5: [6], # 6: []} # deal with input n = int(stdin.readline()) g = {} d = [0]*n f = [0]*n all_vertex = [] for i in xrange(n): entry = [int(s) for s in stdin.readline().split()[2:]] g[i+1] = entry all_vertex.append(i+1) # exp = [] # state represent vertex visited state: 0 not visited 1 visiting 2 finished state = [0]*n for node in all_vertex: if state[node-1] == 0: dfs(g,node,state,d,f) # print 'state ' + str(state) # print 'd' + str(d) # print 'f' + str(f) # deal with output for i in xrange(n): print str(i+1) + ' ' + str(d[i]) + ' ' + str(f[i]) main()
#!/usr/bin/env python3 def main(): N = int(input()) S = input() seen = set() ans = 0 for i in range(N - 2): if S[i] in seen: continue seen.add(S[i]) for j in range(i + 1, N - 1): if S[i] + S[j] in seen: continue seen.add(S[i] + S[j]) for k in range(j + 1, N): if S[i] + S[j] + S[k] in seen: continue seen.add(S[i] + S[j] + S[k]) ans += 1 print(ans) if __name__ == '__main__': main()
0
null
64,560,131,394,582
8
267
n,m = map(int,input().split()) v1 = [ input().split() for _ in range(n) ] v2 = [ int(input()) for _ in range(m) ] l = [sum(map(lambda x,y:int(x)*y,v,v2)) for v in v1 ] print(*l,sep="\n")
n,m = map(int,input().split()) tbl=[[] for i in range(n)] for i in range(n): tbl[i] = list(map(int,input().split())) tbl2=[[]*1 for i in range(m)] for i in range(m): tbl2[i] = int(input()) for k in range(n): x=0 for l in range(m): x +=tbl[k][l]*tbl2[l] print("%d"%(x))
1
1,150,520,278,286
null
56
56
a, b, c, d = (int(i) for i in input().split()) print(max(a*c, b*d, a*d, b*c))
a,b,c,d = map(int,input().split()) l1 = [a,b] l2 = [c,d] if(a<0 and 0<b): l1.append(0) if(c<0 and 0<d): l2.append(0) l = [] for x in l1: for y in l2: l.append(x*y) print(max(l))
1
3,028,027,523,370
null
77
77
def main(): line1 = input() line2 = input() line3 = input() n, m, k = list(map(int, line1.split())) a = [0] + list(map(int, line2.split())) b = [0] + list(map(int, line3.split())) mark1, mark2 = 0, 0 for i in range(1, len(a)): a[i] += a[i-1] if a[i] > k: mark1 = i break for i in range(1, len(b)): b[i] += b[i-1] if b[i] > k: mark2 = i break if mark1: a = a[:mark1] if mark2: b = b[:mark2] ans = 0 for i in range(len(a)): target = k - a[i] tmp = 0 low, high = 0, len(b) while low < high: mid = (low + high) // 2 if b[mid] <= target: tmp = mid low = mid + 1 else: high = mid - 1 ans = max(ans, i + tmp) print(ans) return if __name__ == "__main__": main()
import sys readline = sys.stdin.readline N = int(readline()) S = [readline().rstrip() for _ in range(N)] def count_cb_ob(s): st = [] for i, si in enumerate(s): if si == '(' or len(st) == 0 or st[-1] != '(': st.append(si) else: st.pop() return st.count(')'), st.count('(') cb_obs = map(count_cb_ob, S) f, b, s = [], [], [] for down, up in cb_obs: (f if down < up else (s if down == up else b)).append((down, up)) f = sorted(f) b = sorted(b, key=lambda x:x[1], reverse=True) count = 0 ans = 'Yes' for down, up in (*f, *s, *b): count -= down if count < 0: ans = 'No' count += up if count != 0: ans = 'No' print(ans)
0
null
17,216,955,158,332
117
152
n, x, m = map(int, input().split()) lis = [x] flag = [-1 for i in range(m)] flag[x] = 0 left = -1 right = -1 for i in range(n-1): x = x**2 % m if flag[x] >= 0: left = flag[x] right = i break else: lis.append(x) flag[x] = i+1 ans = 0 if left == -1: ans = sum(lis) else: ans += sum(lis[0:left]) length = right - left + 1 ans += sum(lis[left:]) * ((n-left)//length) ans += sum(lis[left:left+((n-left)%length)]) print(ans)
n,x,y=map(int,input().split()) a=[0]*n for i in range(1,n+1): for j in range(i,n+1): b=min(abs(i-j),abs(i-x)+1+abs(y-j),abs(x-j)+1+abs(y-i)) a[b]+=1 print(*a[1:],sep="\n")
0
null
23,435,396,259,510
75
187
import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): sys.setrecursionlimit(10**7) INF = 10**7 LI = lambda : [int(x) for x in sys.stdin.readline().split()] NI = lambda : int(sys.stdin.readline()) N = NI() up = 0 down = 0 mp = [] mm = [] for _ in range(N): w = INF e = 0 for s in sys.stdin.readline().rstrip(): if s == '(': e += 1 else: e -= 1 w = min(w,e) if w < 0: if e > 0 :mp.append((w,e)) elif w == e: down += e else: mm.append((w,e)) else: up += e mp.sort(reverse=True) for w,e in mp: if up + w < 0: print('No') exit(0) up += e mm.sort(reverse=True) for w,e in mm: if down - w > 0: print('No') exit(0) down += e if up + down == 0: print('Yes') else: print('No') if __name__ == '__main__': main()
def main(): n = int(input()) ans = 0 for i in range(1, n+1): tmp = n//i ans += i*tmp*(tmp+1)//2 print(ans) return if __name__ == "__main__": main()
0
null
17,396,040,515,840
152
118
S=input() if(S.isupper()): print('A') else: print('a')
dic = {} for b in range(1,5): for f in range(1,4): for r in range(1,11): dic[(b,f,r)] = 0 n = int(raw_input()) for k in range(n): b,f,r,v = map(int,raw_input().split()) dic[(b,f,r)] += v j = 0 for b in range(1,5): for f in range(1,4): ls = [] for r in range(1,11): ls.append(dic[(b,f,r)]) print ' ' + ' '.join(map(str,ls)) else: if j < 3: print '#'*20 j +=1
0
null
6,153,726,213,000
119
55
if len(set(input().split()))==2: print("Yes") else: print("No")
x, k, d = map(int, input().split()) cur = x numTimes = x // d if numTimes == 0: cur -= d k -= 1 else: numTimes = min(abs(numTimes), k) if x < 0: numTimes *= -1 cur -= numTimes * d k -= numTimes if k % 2 == 0: print(abs(cur)) else: result = min(abs(cur - d), abs(cur + d)) print(result)
0
null
36,679,299,565,492
216
92
n = int(raw_input()) a = [int(x) for x in raw_input().split()] q = int(raw_input()) op = [] for _ in xrange(q): v = raw_input().split() op.append([int(x) for x in v]) d = {} total = 0 for v in a: d[v] = d.get(v, 0) + 1 total += v for src, dest in op: c = d.pop(src, 0) d[dest] = d.get(dest, 0) + c total += c * (dest - src) print total
#!/usr/bin/env python3 from collections import Counter def solve(N: int, A: "List[int]", Q: int, BC: "List[(int,int)]"): A = Counter(A) answers = [] ans = ans = sum((i * n for i, n in A.items())) for b, c in BC: if b != c: ans += (c - b) * A[b] A[c] += A[b] del A[b] answers.append(ans) return answers def main(): N = int(input()) # type: int A = list(map(int, input().split())) Q = int(input()) BC = [tuple(map(int, input().split())) for _ in range(Q)] answer = solve(N, A, Q, BC) for ans in answer: print(ans) if __name__ == "__main__": main()
1
12,079,013,823,934
null
122
122
a = input() if a == '0': print('1') elif a == '1': print('0')
print(1-int(input()))
1
2,934,404,686,862
null
76
76
# A - A?C # https://atcoder.jp/contests/abc166/tasks/abc166_a S = input() result = 'ABC' if S == result: result = 'ARC' print(result)
S = input() if S[1] == 'R': print('ABC') elif S[1] == 'B': print('ARC')
1
24,159,882,406,660
null
153
153
from collections import deque n = int(input()) q = deque(range(1, 10)) for _ in range(n - 1): x = q.popleft() r = x % 10 y = 10 * x if r == 0: q.extend([y, y+1]) elif r == 9: q.extend([y+8, y+9]) else: q.extend([y+r-1, y+r, y+r+1]) print(q.popleft())
h,w,k = map(int,input().split()) s = [list(input()) for i in range(h)] a = [[0]*w for i in range(h)] num = 1 for i in range(h): b = s[i] if "#" in b: t = b.count("#") for j in range(w): c = b[j] # print(c) if c=="#" and t!=1: a[i][j] = num num += 1 t -= 1 elif c=="#" and t==1: a[i][j] = num t = -1 else: a[i][j] = num if t==-1: num += 1 else: if i==0: continue else: for j in range(w): a[i][j] = a[i-1][j] index = 0 for i in range(h): if "#" not in s[i]: index += 1 else: break for j in range(index): for k in range(w): a[j][k] = a[index][k] for j in a: print(*j)
0
null
91,674,554,362,820
181
277
from functools import reduce N = int(input()) A = [int(x) for x in input().split()] SUM=reduce(lambda a, b: a^b, A) [print(SUM^A[i]) for i in range(N)]
N = int(input()) a = list(map(int, input().split())) Xsum = 0 for i in a: Xsum = Xsum ^ i ans = list() for i in a: s = Xsum ^ i # print(s) ans.append(str(s)) print(' '.join(ans))
1
12,472,445,178,102
null
123
123
def gcd(a, b): if a < b: tmp = a a = b b = tmp r = a % b while r != 0: a = b b = r r = a % b return b if __name__ == '__main__': l = list(map(int, input().split())) x = l[0] y = l[1] ans = gcd(x, y) print(ans)
#!usr/bin/env python3 import sys def init_card_deck(): # S: spades # H: hearts # C: clubs # D: diamonds card_deck = {'S': [], 'H': [], 'C': [], 'D': []} n = int(sys.stdin.readline()) for i in range(n): lst = [card for card in sys.stdin.readline().split()] card_deck[lst[0]].append(lst[1]) return card_deck def print_missing_cards(card_deck): card_symbols = ['S', 'H', 'C', 'D'] for i in card_symbols: for card in range(1, 14): if not str(card) in card_deck[i]: print(i, card) def main(): print_missing_cards(init_card_deck()) if __name__ == '__main__': main()
0
null
510,933,819,270
11
54
from itertools import accumulate N, *A = map(int, open(0).read().split()) A_acc = list(accumulate(A, initial=0)) min_diff = float("inf") for i in range(1, N): left, right = A_acc[i], A_acc[N] - A_acc[i] min_diff = min(min_diff, abs(right - left)) print(min_diff)
N = int(input()) A = list(map(int, input().split())) left = 0 SUM = sum(A) res = SUM for i in range(N): left += A[i] res = min(res,abs(2*left-SUM)) print(res)
1
142,296,858,884,818
null
276
276
x, n = map(int, input().split()) p = sorted(list(map(int, input().split()))) a = 100 b = 0 for i in range(0, 102): if i not in p and abs(x - i) < a: a = abs(x - i) b = i print(b)
#k = int(input()) #s = input() #a, b = map(int, input().split()) #s, t = map(str, input().split()) #l = list(map(int, input().split())) #l = [list(map(int,input().split())) for i in range(n)] #a = [input() for _ in range(n)] x,n = map(int, input().split()) p = list(map(int, input().split())) ans = x for i in range(x, 102): if i not in p: ans = i break ans2 = x for i in range(x-1, -1, -1): if i not in p: ans2 = i break #print(ans,ans2) tmp1 = abs(ans - x) tmp2 = abs(x - ans2) if (tmp1 < tmp2): print(ans) elif (tmp1 == tmp2): print(min(ans, ans2)) else: print(ans2)
1
14,112,937,786,548
null
128
128
from fractions import gcd n = int(input()) a = list(map(int, input().split())) mod = 1000000007 l = 1 for i in range(n): l = l * a[i] // gcd(l, a[i]) ans = 0 for i in range(n): ans += l // a[i] print(ans % mod)
import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): MOD = 10**9 + 7 LI = lambda : [int(x) for x in sys.stdin.readline().split()] NI = lambda : int(sys.stdin.readline()) N = NI() A = LI() d = {} for x in A: for i in range(2,int(math.sqrt(x))+1): cnt = 0 while x % i == 0: cnt += 1 x //= i if cnt: d[i] = max(d.get(i,0),cnt) if x == 1: break else: d[x] = max(d.get(x,0),1) m = 1 for i,x in d.items(): m = (m * i ** x) % MOD ans = 0 for x in A: ans += (m * pow(x,MOD-2,MOD)) % MOD print(ans % MOD) if __name__ == '__main__': main()
1
87,492,613,119,338
null
235
235
if __name__ == "__main__": K = int(input()) num_ls = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] ret = num_ls[K-1] print(ret)
def Main(K): l = (1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51) return l[K-1] def main(): K = int(input()) print(Main(K)) if __name__ == '__main__': main()
1
49,894,028,966,350
null
195
195
a = [] for i in range(10): a.append(int(raw_input())) a.sort() a.reverse() for i in range(3): print a[i]
list = [] for i in range(0, 10): t = int(raw_input()) list.append(t) list.sort(reverse=True) for i in range(0, 3): print list[i]
1
25,647,422
null
2
2
MOD=10**9+7 K=int(input()) S=list(input()) len_S=len(S) def invmod(a): return pow(a,MOD-2,MOD) fact_dic={0:1} fact_inv_dic={0:1} fact_mod=1 for i in range(1,K+len_S+1): fact_mod=(fact_mod*i)%MOD fact_dic[i]=fact_mod fact_inv_dic[i]=invmod(fact_mod) def comb_mod_table(n,r): if 0<=r<=n: return fact_dic[n]*fact_inv_dic[r]*fact_inv_dic[n-r] else: return 0 pow25=pow(25,K,MOD) inv25=invmod(25) pow26=1 answer=0 for i in range(K+1): answer+=comb_mod_table(K+len_S-i-1,len_S-1)*pow25*pow26 pow25=pow25*inv25%MOD pow26=pow26*26%MOD answer%=MOD print(answer)
K = int(input()) S = input() m = 1000000007 def make_factorial_table(n): result = [0] * (n + 1) result[0] = 1 for i in range(1, n + 1): result[i] = result[i - 1] * i % m return result def mcomb(n, k): if n == 0 and k == 0: return 1 if n < k or k < 0: return 0 return fac[n] * pow(fac[n - k], m - 2, m) * pow(fac[k], m - 2, m) % m fac = make_factorial_table(len(S) - 1 + K) result = 0 for i in range(K + 1): t = pow(26, i, m) * mcomb(len(S) - 1 + K - i, len(S) - 1) t %= m t *= pow(25, K - i, m) t %= m result += t result %= m print(result)
1
12,683,797,138,560
null
124
124
N, M = map(int, input().split()) H = list(map(int, input().split())) OK = [True] * N for _ in range(M): A, B = map(lambda x: int(x)-1, input().split()) if H[A] < H[B]: OK[A] = False elif H[A] > H[B]: OK[B] = False else: OK[A] = False OK[B] = False ans = sum(OK) print(ans)
n,m=map(int,input().split()) H=list(map(int,input().split())) A=[[] for i in range(n)] for i in range(m): a,b=map(int,input().split()) a-=1;b-=1 A[a].append(b) A[b].append(a) ans=0 for i in range(n): for j in A[i]: if H[j]>=H[i]:break else: ans+=1 print(ans)
1
25,251,479,862,280
null
155
155
x = int(input()) num = (x//500)*1000 num += ((x%500)//5)*5 print(num)
x = int(input()) ans = 0 ans += 1000*(x//500) x %= 500 ans += 5*(x//5) print(ans)
1
42,988,487,582,040
null
185
185
n = int(input()) a = list(map(int,input().split())) ans = 0 m = a[0] for i in range(1,n): if a[i] <= m: ans += -a[i]+m else: m = a[i] print(ans)
n = int(input()) a = list(map(int, input().split())) m, s = 0, 0 for i in range(n): m = max(m, a[i]) s += m - a[i] print(s)
1
4,512,190,570,342
null
88
88
from collections import Counter n = int(input()) d = list(map(int, input().split())) mod = 998244353 if d[0] != 0 or 0 in d[1:]: print(0) else: c = Counter(d) ans = 1 for i in range(1, len(c)): ans *= c[i-1] ** c[i] ans %= mod print(ans % mod)
def main(): N = int(input()) num = 0 B = 1 for A in range(1, N): for B in range(1, N): if N - A * B >= 1: num = num + 1 else: break print(num) main()
0
null
78,886,947,135,360
284
73
n=int(input()) s=set([]) for i in range(n): s_=input() s.add(s_) print(len(s))
N=int(input()) print(len(set([input() for _ in range(N)])))
1
30,289,014,965,124
null
165
165
N, K, S = map(int, input().split()) if S == 1000000000: fill = 1000000000 - 1 else: fill = S+1 print(' '.join(map(str, ([S]*K + [fill]*(N-K)))))
n, k, s = map(int, input().split()) a = [s] * n if s == 1: s = 2 else: s -=1 for i in range(k, n): a[i] = s print(a[0], end = "") for i in a[1:]: print("", i, end = "") print()
1
91,075,570,548,460
null
238
238
A,B,C,D=input().split() num = 0 while(int(A)>=0 and int(C)>=0): if int(A)<= 100 and 0 <= int(B)<= 100 and int(C)<= 100 and 0 <= int(D)<= 100: if num %2 == 0: C = int(C)-int(B) if int(C)<=0: print("Yes") break num += 1 elif num %2 !=0: A = int(A)-int(D) if int(A)<=0: print("No") break num += 1 else: break
A, V = map(int, input().split()) B, W = map(int, input().split()) T = int(input()) if W>=V: print('NO') exit() if abs(A-B)/(V-W) > T: print('NO') exit() print('YES')
0
null
22,277,068,582,558
164
131
class Dice: def __init__(self,t,f,r,l,b,u): self.t = t self.f = f self.r = r self.l = l self.b = b self.u = u self.a=[t,f,r,l,b,u] self.direction={'S':(4,0,2,3,5,1),'N':(1,5,2,3,0,4),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3),'Y':(0,3,1,4,2,5)} def roll(self,d): self.a=[self.a[i] for i in self.direction[d]] self.t = self.a[0] self.f = self.a[1] self.r = self.a[2] self.l = self.a[3] self.b = self.a[4] self.u = self.a[5] t,f,r,l,b,u=map(int,input().split()) dice=Dice(t,f,r,l,b,u) n=int(input()) s='SSSEWW' yw='YYY' for j in range(n): t,f=map(int,input().split()) for d in s: if dice.t==t: break dice.roll(d) for t in yw: if dice.f==f: break dice.roll(t) print(dice.r)
class Dice(): def __init__(self, spots): self.spots = [spots[i] for i in range(6)] def roll(self, direction): if direction == 0: self.spots = [self.spots[i] for i in [1, 5, 2, 3, 0, 4]] elif direction == 1: self.spots = [self.spots[i] for i in [3, 1, 0, 5, 4, 2]] elif direction == 2: self.spots = [self.spots[i] for i in [4, 0, 2, 3, 5, 1]] elif direction == 3: self.spots = [self.spots[i] for i in [2, 1, 5, 0, 4, 3]] first_state = list(map(int, input().split())) q = int(input()) for _ in range(q): my_dice = Dice(first_state) a, b = map(int, input().split()) if b == my_dice.spots[0]: my_dice.roll(2) elif b == my_dice.spots[1]: pass elif b == my_dice.spots[2]: my_dice.roll(3) my_dice.roll(2) elif b == my_dice.spots[3]: my_dice.roll(1) my_dice.roll(2) elif b == my_dice.spots[4]: my_dice.roll(2) my_dice.roll(2) elif b == my_dice.spots[5]: my_dice.roll(0) if a == my_dice.spots[0]: pass elif a == my_dice.spots[2]: my_dice.roll(3) elif a == my_dice.spots[3]: my_dice.roll(1) elif a == my_dice.spots[5]: my_dice.roll(1) my_dice.roll(1) print(my_dice.spots[2])
1
254,872,765,856
null
34
34
#!/usr/bin/env python3 from collections import Counter n, *d = map(int, open(0).read().split()) c = Counter(d[1:]) c = [(0, 1)] + sorted(c.items()) ans = d[0] == 0 for i in range(1, len(c)): if i != c[i][0]: ans = 0 break ans *= pow(c[i - 1][1],c[i][1], 998244353) print(ans%998244353)
def my_pow(base, n, mod): if n == 0: return 1 x = base y = 1 while n > 1: if n % 2 == 0: x *= x n //= 2 else: y *= x n -= 1 x %= mod y %= mod return x * y % mod N = int(input()) D = list(map(int, input().split())) dmax = max(D) MOD = 998244353 cnt = [0] * (10 ** 5 + 1) for d in D: cnt[d] += 1 if D[0] or cnt[0] != 1: print(0) exit() ans = cnt[0] for i in range(1, dmax + 1): now = my_pow(cnt[i - 1], cnt[i], MOD) ans *= now ans %= MOD print(ans)
1
155,135,622,764,080
null
284
284
import itertools n = int(input()) town = [list(map(int, input().split())) for _ in range(n)] x = 1 for i in range(1, n+1): x *= i l = [] for j in range(n): l.append(j) ans = 0 for a in itertools.permutations(l, n): newl = a length = 0 for b in range(n-1): length += ((town[newl[b]][0] - town[newl[b+1]][0])**2 + (town[newl[b]][1] - town[newl[b+1]][1])**2)**(1/2) ans += length print(ans/x)
A = int(input()) B = int(input()) ans = 6 - (A+B) print(ans)
0
null
129,353,573,239,550
280
254
import sys import decimal # 10進法に変換,正確な計算 def input(): return sys.stdin.readline().strip() def main(): r = int(input()) print(r**2) main()
K=int(input()) S=set() ans=0 x=7%K i=1 while True: if x==0: ans=1 break if x in S: break else: S.add(x) x=(x*10+7)%K i+=1 print(i if ans else -1)
0
null
75,410,584,935,910
278
97
def sum_dict(d): num = 0 for k, v in d.items(): num += k * v return num def create_dict(A): d = {} for a in A: if d.get(a) is None: d[a] = 1 else: d[a] += 1 return d if __name__ == "__main__": N = int(input()) A = list(map(int, input().split())) Q = int(input()) BC = [] for i in range(Q): BC.append(tuple(map(int, input().split()))) d = create_dict(A) ans = sum_dict(d) for b, c in BC: db = d.get(b) if db is None: db = 0 if d.get(c) is None: d[c] = 0 d[c] += db d[b] = 0 ans += (c - b) * db print(ans)
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,163,796,900,670
null
122
122
n = int(input()) l = [0 for i in range(n)] r = [0 for i in range(n)] dat = [] dat2 = [] st = -1 for i in range(n): s = input() for ch in s: if ch == '(': r[i] += 1 pass else: if r[i] > 0: r[i] -= 1 else: l[i] += 1 pass # print(i, l[i], r[i]) if l[i] == 0: if st == -1 or r[st] < r[i]: st = i if r[i] >= l[i]: dat.append((l[i], i)) else: dat2.append((r[i], i)) dat.sort() dat2.sort(reverse=True) if st == -1: print("No") exit() now = r[st] # print('now={}'.format(now)) for num, i in dat: if i == st: continue if now < l[i]: print("No") exit() now = now - l[i] + r[i] for num, i in dat2: # print('dat2', num, i) if now < l[i]: print("No") exit() now = now - l[i] + r[i] if now == 0: print("Yes") else: print("No")
t=input() ans=str() tmp="" for s in t: if s=="P" or s=="D": ans+=s tmp=s else: ans+="D" tmp="D" print(ans)
0
null
21,192,093,691,338
152
140
d={} for _ in[0]*int(input()): c,g=input().split() if'i'==c[0]:d[g]=0 else:print(['no','yes'][g in d])
def attacks(HP, times=1): if HP==0: return times-1 HP //= 2 times *= 2 return attacks(HP,times) h=int(input()) print(attacks(h))
0
null
40,281,518,571,936
23
228
while True: string = list(input()) #1文字ずつ配列に入ってる if "-" in string: break shuffle = int(input()) for i in range(shuffle): h = int(input()) for j in range(h): string.append(string[0]) del string[0] for i in range(len(string)): if i != len(string)-1: print(string[i],end="") else: print(string[i])
#最大値の最小値を求める問題は二分探索 #求めるものを変数と見て丸太の最大値がxだとすると #丸太の長さは全てx以下である必要があるため切るべき回数がわかる #それがk回以下ならokだしそれがk回を超えていたらだめ n,k=list(map(int,input().split())) a=list(map(int,input().split())) ng=0 ok=max(a) def check(x): num=0 for i in range(n): if a[i]%x==0: num=num+a[i]//x-1 else: num=num+a[i]//x return num<=k while ok-ng>1: mid=(ok+ng)//2 if check(mid): ok=mid else: ng=mid print(ok)
0
null
4,200,970,240,156
66
99
import random import time import copy start = time.time() D = int(input()) s = [[0 for j in range(26)] for i in range(D)] c = list(map(int, input().split(" "))) result = [] total = -10000000 for i in range(D): a = list(map(int, input().split(" "))) for j, k in enumerate(a): s[i][j] = int(k) cnt=0 score = [0 for i in range(26)] while(1): cnt+=1 result_tmp = [] total_tmp = 0 last = [0 for i in range(26)] for i in range(D): for j in range(26): score[j] = s[i][j] for k in range(26): if j != k: score[j] -= (i + 1 - last[k]) * c[k] score_max = max(score) tmp = [] for j in range(26): if score_max >= 0 and score_max*0.8 <= score[j]: tmp.append(j) if score_max < 0 and score_max*1.1 <= score[j]: tmp.append(j) score_max = random.choice(tmp) result_tmp.append(score_max) last[score_max] = i + 1 total_tmp += score[score_max] if total < total_tmp: total = total_tmp result = result_tmp.copy() end = time.time() if end - start > 1.8: break #print("total",total,cnt) for i in range(D): print(result[i]+1)
import time import random d = int(input()) dd = d * (d + 1) // 2 *C, = map(int, input().split()) S = [list(map(int, input().split())) for i in range(d)] T = [] L = [-1 for j in range(26)] for i in range(d): max_diff = -10**7 arg_max = 0 for j in range(26): memo = L[j] L[j] = i diff = S[i][j] - sum([C[k] * (i - L[k]) for k in range(26)]) if diff > max_diff: max_diff = diff arg_max = j L[j] = memo T.append(arg_max) L[arg_max] = i def calc_score(T): L = [-1 for j in range(26)] X = [0 for j in range(26)] score = 0 for i in range(d): score += S[i][T[i]] X[T[i]] += (d - i) * (i - L[T[i]]) L[T[i]] = i for j in range(26): score -= C[j] * (dd - X[j]) return score score = calc_score(T) start = time.time() cnt = 0 while True: now = time.time() if now - start > 1.8: break p = (cnt // 26) % d q = cnt % 26 memo = T[p] T[p] = q new_score = calc_score(T) temp = 20000 * (1 - (now - start) / 2) prob = 2**((new_score - score) / temp) if random.random() < prob: score = new_score else: T[p] = memo cnt = (cnt + 1) % (10**9 + 7) for t in T: print(t + 1)
1
9,637,489,927,010
null
113
113
N, K = list(map(int, input().split())) if abs(N - K) > N: print(N) else: if N % K == 0: N = 0 else: N = abs(N % K - K) print(N)
N,K = map(int,input().split()) A = sorted(list(map(int,input().split()))) mod = 10**9+7 ans = 1 mi = [] pl = [] for a in A: if a < 0: mi.append(a) else: pl.append(a) if N == K: for a in A: ans *= a ans %= mod print(ans) exit() if pl == []: if K%2: for k in range(K): ans *= mi[-1-k] ans %= mod else: for k in range(K): ans *= mi[k] ans %= mod print(ans) exit() pl = pl[::-1] ip = 0 im = 0 if K % 2: ans = pl[0] ip += 1 K -= 1 while K > 0: check = True if ip + 2 <= len(pl): x = pl[ip]*pl[ip+1] else: x = 1 if im + 2 <= len(mi): y = mi[im]*mi[im+1] else: check = False y = 1 if x >= y or check == False: ans *= x ans %= mod ip += 2 else: ans *= y ans %= mod im += 2 K -= 2 print(ans)
0
null
24,507,824,047,740
180
112
import sys import collections input_methods=['clipboard','file','key'] using_method=0 input_method=input_methods[using_method] tin=lambda : map(int, input().split()) lin=lambda : list(tin()) mod=998244353 #+++++ def main(): n = int(input()) #b , c = tin() #s = input() al = lin() if al[0] != 0: return 0 if al.count(0) != 1: return 0 alc = collections.Counter(al) mm = max(alc.keys()) b = alc.keys() b=list(b) b.sort() if list(range(mm+1)) != b: #pa('rrrr') return 0 v = 1 p=1 for k in range(1, mm+1): num = alc[k] add = pow(p, num, mod) v *= add v %= mod p = num return v #+++++ isTest=False def pa(v): if isTest: print(v) def input_clipboard(): import clipboard input_text=clipboard.get() input_l=input_text.splitlines() for l in input_l: yield l if __name__ == "__main__": if sys.platform =='ios': if input_method==input_methods[0]: ic=input_clipboard() input = lambda : ic.__next__() elif input_method==input_methods[1]: sys.stdin=open('inputFile.txt') else: pass isTest=True else: pass #input = sys.stdin.readline ret = main() if ret is not None: print(ret)
K=int(input()) S=input() N=len(S) if N<=K: print(S) else: ans=[] for i in range(K): ans.append(S[i]) print(''.join(ans)+'...')
0
null
87,254,751,967,680
284
143
from math import gcd def setwise_coprime_check_fun(A_list, N): gcd_all = A_list[0] for i in range(N - 1): gcd_all = gcd(gcd_all, A_list[i + 1]) if gcd_all == 1: break return gcd_all def preprocess_fun(A_max): p_flg = [True] * (A_max + 1) D = [0] * (A_max + 1) p_flg[0] = False p_flg[1] = False for i in range(2, A_max + 1, 1): if p_flg[i]: for j in range(i, A_max + 1, i): p_flg[j] = False D[j] = i return D def pairwise_coprime_check(A_list, D, A_max): p_count = [0] * (A_max + 1) for A in A_list: temp = A d = 0 while temp != 1: if p_count[D[temp]] == 1 and d != D[temp]: return 0 p_count[D[temp]] = 1 d = D[temp] temp = temp // D[temp] return 1 ## 標準入力 N = int(input()) A_list = list(map(int, input().split(" "))) # 整数の最大値を取得 A_max = max(A_list) # 本体 if(setwise_coprime_check_fun(A_list, N) != 1): print("not coprime") else: D = preprocess_fun(A_max) if pairwise_coprime_check(A_list, D, A_max) == 1: print("pairwise coprime") else: print("setwise coprime")
N = int(input()) ret = False if N % 2 == 0: S = input() if S[:N//2] == S[N//2:]: ret = True if ret: print("Yes") else: print("No")
0
null
75,685,654,100,360
85
279
n = int(input()) P = list(map(int,input().split())) tmp = float('inf') cnt = 0 for i,p in enumerate(P): if p <=tmp: cnt += 1 tmp = min(tmp,p) print(cnt)
import sys x = int(input()) box = [a**5 for a in range(0,200)] for i in range(200): for j in range(200): if box[i] - box[j] == x: print(i,j) sys.exit() for k in range(200): for l in range(200): if (-1)*box[k] + box[l] == x: print(-(k),-(l)) sys.exit() for s in range(200): for t in range(200): if box[s] + box[t] == x: print(s,-(t)) sys.exit()
0
null
55,611,651,172,948
233
156
s = int(input()) mod = 10**9 + 7 a = [0] * (2001) a[3] = a[4] = a[5] = 1 for i in range(6, s + 1): a[i] = a[i - 1] + a[i - 3] a[i] %= mod print(a[s])
#事前に階乗を計算しておく maximにnの最大値をいれる maxim = 10**6+1 MOD = 10**9+7 kaijou = [1]*(maxim) for i in range(1,maxim): kaijou[i]=(kaijou[i-1]*i)%MOD #nCr def nCr(n,r): if n < r: return 0 return ((kaijou[n]*pow(kaijou[r],MOD-2,MOD))%MOD*pow(kaijou[n-r],MOD-2,MOD))%MOD #nHr def nHr(n,r): if r == 0: if n == 0: return 1 return 0 return ((kaijou[n+r-1]*pow(kaijou[n],MOD-2,MOD))%MOD*pow(kaijou[r-1],MOD-2,MOD))%MOD N = int(input()) ans = 0 for i in range(1,(N//3)+1): tmp = nHr(N-3*i,i) ans = (ans+tmp)%MOD print(ans)
1
3,260,650,338,488
null
79
79
a,b=map(int,input().split()) num=1 while 1: if int(num*0.08)==a and int(num*0.1)==b: print(num) break if int(num*0.08)>a and int(num*0.1)>b: print(-1) break num+=1
nn = int(input()) aa = list(map(int,input().split())) joushi = [0]*nn for i in range(len(aa)): joushi[aa[i]-1] += 1 for j in range(len(joushi)): print(joushi[j])
0
null
44,469,842,866,200
203
169
N = int(input()) A = list(map(int, input().split())) min = A[0] count = 1 for i in range(1, N): if A[i] <= min: count += 1 min = A[i] else: continue print(count)
N,A,B = map(int,input().split()) if A == 0: print(0) exit(0) first = (N // (A+B))*A second = min(A, N % (A+B)) ans = first + second print(ans)
0
null
70,505,138,336,288
233
202
a = [int(i) for i in input().split()] a.sort() print(*a,sep=" ")
n = int(input()) ls = [0]*n param_list = [0]*2**n for i in range(2**n): l = [False]*n for id_r, row in enumerate(ls): if i & (2 ** id_r) >0: l[id_r] = True param_list[i] = l for i in range(n): A = int(input()) for k in range(A): a,b = map(int, input().split()) b = (1==b) new_param =[] for d in param_list: if d[i]: if d[a-1] == b: new_param.append(d) pass else: #print(2) pass else: new_param.append(d) #if d[a-1] is b: #print(3) #pass #else: #print(4) #new_param.append(d) #pass param_list = new_param #print(param_list) ans = 0 for d in param_list: ans = max(ans, d.count(True)) print(ans)
0
null
60,732,663,457,312
40
262
print(6.28318530717958623200*int(input()))
from math import pi print(int(input())*2*pi)
1
31,471,790,803,710
null
167
167
def pc(x): return format(x, 'b').count('1') N = int(input()) X = input() Xo = int(X, 2) count = 0 ans = 0 ori = pc(Xo) X = list(X) Xp = Xo%(ori + 1) if ori == 1: Xm = 0 else: Xm = Xo % (ori - 1) # for i in range(N-1, -1, -1): for i in range(N): if ori == 1 and X[i] == '1': print(0) continue else: if X[i] == '1': # ans = Xm - pow(2, i, ori - 1) ans = Xm - pow(2, N-1-i, ori - 1) ans %= ori - 1 else: # ans = Xp - pow(2, i, ori + 1) ans = Xp + pow(2, N-1-i, ori + 1) ans %= ori + 1 count = 1 while ans > 0: # count += 1 # if ans == 1: # break ans %= pc(ans) count += 1 print(count) count = 1
#!python3 import sys iim = lambda: map(int, sys.stdin.readline().rstrip().split()) from functools import lru_cache @lru_cache(maxsize=2*10**5) def f2(x): if x == 0: return 0 y = bin(x).count("1") return 1 + f2(x % y) def resolve(): N = int(input()) S = input() cnt0 = S.count("1") if cnt0 == 0: print(*[1]*N, sep="\n") return X = int(S, 2) dc = {} for k, v in (("0", 1), ("1", -1)): x = cnt0 + v y = X % x if x else 0 dc[k] = (x, v, y, [1, N-1]) ans = [0] * N for i in reversed(range(N)): si = S[i] cnt, v, n, m1 = dc[si] if cnt == 0: ans[i] = 0 continue ni = N - i - 1 m2 = (m1[0]<<(m1[1]-i)) % cnt n = (n + v*m2) % cnt m1[0] = m2; m1[1] = i ans[i] = 1 + f2(n) print(*ans, sep="\n") if __name__ == "__main__": resolve()
1
8,183,587,780,362
null
107
107
H, W, K = map(int, input().split()) c = [] for _ in range(H): c.append(input()) #こういうinputをすると,c_ij = c[i][j] (C[i]という文字列のj文字目)という構造になってくれて,とても嬉しい。 #print(c) ans = 0 #bit全探索 for rows in range(1 << H): #bit演算子。1 << H は二進数で1000...という風に,1の後ろに0がH個並ぶ。 #例えば rows = 110010 のときには,(2 ** 5ケタ目の1は無視して)(0-indexで)1行目と4行目を赤で塗る状態を指す。 for cols in range(1 << W): black_count = 0 for i in range(H): if (rows >> i) % 2 == 1:continue #i行目が赤で塗られていたならば,何もせずiを一歩進める。 for j in range(W): if (cols >> j) % 2 ==1:continue #j列目が赤で塗られていたならば,何もせずjを一歩進める。 if c[i][j] == "#": black_count += 1 if black_count == K: ans += 1 print(ans)
a, b = map(int,input().split()) c, d = map(int,input().split()) if d == 1: print("1") else: print("0")
0
null
66,913,496,962,860
110
264
a, b = map(int, input().split()) if a % b > 0: print(a//b + 1) else: print(a//b)
N, M, K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) cumsum_a = [0] * (N + 1) cumsum_b = [0] * (M + 1) for i in range(1, N + 1): cumsum_a[i] = cumsum_a[i - 1] + A[i - 1] for i in range(1, M + 1): cumsum_b[i] = cumsum_b[i - 1] + B[i - 1] ans = 0 bi = M for i in range(N+1): for j in range(bi, -1, -1): t = cumsum_a[i] + cumsum_b[j] if t <= K: ans = max(ans, i + j) bi = j break print(ans)
0
null
43,740,997,417,358
225
117
a,b = map(int,input().split()) d,r = divmod(a,b) print("{} {} {:.6f}".format(d,r,a/b))
T1,T2,A1,A2,B1,B2=map(int,open(0).read().split()) D1,D2=(A1-B1)*T1,(A1-B1)*T1+(A2-B2)*T2 if D1*D2>0:print(0) elif D2==0:print("infinity") else:print(-D1//D2*2+1-(-D1%D2==0))
0
null
66,187,586,516,088
45
269
input() list=[int(i) for i in input().split()] print(min(list),max(list),sum(list))
from itertools import accumulate n, k = map(int, input().split()) a = list(map(int, input().split())) for _ in range(k): b = [0] * n for i in range(n): b[max(0, i-a[i])] += 1 tmp = i + a[i] + 1 if tmp < n: b[tmp] -= 1 a = list(accumulate(b)) if a == [n] * n: break print(*a)
0
null
8,048,466,914,488
48
132
x=list(input().split()) print(x[1]+x[0])
a, b = [int(i) for i in input().split()] ans = -1 for i in range(1010): if i * 8 // 100 == a and i // 10 == b: ans = i break print(ans)
0
null
79,902,550,398,180
248
203
N = int(input()) A = list(map(int, input().split())) ans = 0 for i in range(N - 1): if A[i] > A[i + 1]: ans += A[i] - A[i + 1] A[i + 1] = max(A[i], A[i + 1]) print(ans)
N = int(input()) A = list(map(int, input().split())) M = 0 S = 0 for a in A: if M < a: M = a if a < M: S += M - a print(S)
1
4,588,585,359,292
null
88
88
h,n=map(int,input().split()) a=[] b=[] for i in range(n): aa,bb=map(int,input().split()) a.append(aa) b.append(bb) inf=10**10 f=h+max(a)+1 dp=[f*[inf]for _ in range(n+1)] dp[0][0]=0 for i in range(1,n+1): dp[i]=dp[i-1] for j in range(f): if j+a[i-1]<f: dp[i][j+a[i-1]]=min(dp[i][j+a[i-1]],dp[i][j]+b[i-1]) for j in range(f-1,0,-1): dp[i][j-1]=min(dp[i][j-1],dp[i][j]) print(dp[-1][h])
import sys read = sys.stdin.buffer.read INF = 1 << 60 def main(): H, N, *AB = map(int, read().split()) dp = [INF] * (H + 1) dp[0] = 0 for a, b in zip(*[iter(AB)] * 2): for i in range(H + 1): if dp[i] > dp[max(i - a, 0)] + b: dp[i] = dp[max(i - a, 0)] + b print(dp[H]) return if __name__ == '__main__': main()
1
81,319,385,757,596
null
229
229
N = int(input()) G = [[-1] * N for i in range(N)] ans = 0 for i in range(N): A = int(input()) for j in range(A): x, y = map(int, input().split()) G[i][x-1] = y for bit in range(2**N): honests = [] for i in range(N): if bit & (1<<i): honests.append(i) flag = True for j in honests: for k in range(N): if (k in honests) and G[j][k] == 0: flag = False elif(k not in honests) and G[j][k] == 1: flag = False if flag: ans = max(ans, len(honests)) print(ans)
import sys N = int(input()) List = [[-1] * N for i in range(N)] for i in range(N): A = int(input()) for j in range(A): x, y = map(int, input().split()) List[i][x - 1] = y Max = 0 for i in range(2 ** N): flag = True Sum = 0 for j in range(N): # このループが一番のポイント if ((i >> j) & 1): # 順に右にシフトさせ最下位bitのチェックを行う for k in range(N): if (List[j][k] != int((i >> k) & 1)) and List[j][k] != -1: flag = False Sum += 1 if flag: #print(i,Sum) Max = max(Max, Sum) print(Max)
1
121,378,553,031,232
null
262
262
from __future__ import (division, absolute_import, print_function, unicode_literals) import sys from fractions import gcd for line in sys.stdin: small, large = sorted(int(n) for n in line .split()) G = gcd(large, small) print(G, large // G * small)
# -*- coding: utf-8 -*- import sys def gcd(a, b): if a < b: a, b = b, a while b!=0: c = b b = a % b a = c return a def lcm(a, b, g): return a * b / g def main(): for line in sys.stdin: a, b = map(int, line.split()) ng = gcd(a, b) nl = lcm(a, b, ng) print('{0:d} {1:d}'.format(int(ng), int(nl))) if __name__ == '__main__': main()
1
654,332,032
null
5
5
N = int(input()) def solve(x1, y1, x2, y2, n): if n == 0: return print(x1, y1) else: solve(x1, y1, (2 * x1 + x2) / 3, (2 * y1 + y2) / 3, n - 1) solve((2 * x1 + x2) / 3, (2 * y1 + y2) / 3, (x1 + x2) / 2 + (y1 - y2) * (3 ** (1 / 2)) / 6, (y1 + y2) / 2 + (x2 - x1) * (3 ** (1 / 2)) / 6, n - 1) solve((x1 + x2) / 2 + (y1 - y2) * (3 ** (1 / 2)) / 6, (y1 + y2) / 2 + (x2 - x1) * (3 ** (1 / 2)) / 6, (x1 + 2 * x2) / 3, (y1 + 2 * y2) / 3, n - 1) solve((x1 + 2 * x2) / 3, (y1 + 2 * y2) / 3, x2, y2, n - 1) solve(0, 0, 100, 0, N) print(100, 0)
n = int(input()) def koch(n,x1,y1,x2,y2): if n == 0: print(x1,y1) else: a = 3**(1/2)/2 p1 = koch(n-1,x1,y1,(2*x1+x2)/3,(2*y1+y2)/3) if abs(y1 - y2) <= 10**(-4): s = koch(n-1,(2*x1+x2)/3,(2*y1+y2)/3,(x1+x2)/2,y1+(x2-x1)*a/3) u = koch(n-1,(x1+x2)/2,y1+(x2-x1)*a/3,(x1+2*x2)/3,(y1+2*y2)/3) else: if x1 < x2 and y1 < y2: s = koch(n-1,(2*x1+x2)/3,(2*y1+y2)/3,x1,(y1+2*y2)/3) u = koch(n-1,x1,(y1+2*y2)/3,(x1+2*x2)/3,(y1+2*y2)/3) elif x1 < x2 and y1 > y2: s = koch(n-1,(2*x1+x2)/3,(2*y1+y2)/3,x2,(2*y1+y2)/3) u = koch(n-1,x2,(2*y1+y2)/3,(x1+2*x2)/3,(y1+2*y2)/3) elif x1 > x2 and y1 < y2: s = koch(n-1,(2*x1+x2)/3,(2*y1+y2)/3,x2,(2*y1+y2)/3) u = koch(n-1,x2,(2*y1+y2)/3,(x1+2*x2)/3,(y1+2*y2)/3) else: s = koch(n-1,(2*x1+x2)/3,(2*y1+y2)/3,x1,(y1+2*y2)/3) u = koch(n-1,x1,(y1+2*y2)/3,(x1+2*x2)/3,(y1+2*y2)/3) t = koch(n-1,(x1+2*x2)/3,(y1+2*y2)/3,x2,y2) return p1,s,u,t X = koch(n,0,0,100,0) print(100,0)
1
124,036,057,312
null
27
27
N, M = map(int, input().split()) a, w = 0, 0 P = set() W = {} for _ in range(M): p, S = map(str, input().split()) if p in P: continue if S == 'WA': W.setdefault(p, 0) W[p] += 1 if S == 'AC': a += 1 P.add(p) if p in W: w += W[p] print(a, w)
n,m = map(int,input().split()) ac_list = [0 for i in range(n+1)] wa_list = [0 for i in range(n+1)] p_list = [] ac = 0 pena = 0 for i in range(m): p,s = map(str,input().split()) p = int(p) if s == 'AC' and ac_list[p-1] != 1: ac += 1 ac_list[p-1] = 1 pena += wa_list[p-1] elif s == 'WA' and ac_list[p-1] != 1: wa_list[p-1] += 1 print(ac, pena)
1
93,638,975,190,528
null
240
240
n=int(input()) a=list(map(int,input().split())) temp=sum(a) ans=0 t=9999999999999999 tsum=0 ta=0 for i in range(n): tsum=tsum+a[i] if abs(tsum-temp/2)<t: t=abs(tsum-temp/2) ta=tsum print(abs(int(ta)*2-temp))
import sys input = sys.stdin.readline def main(): N = int(input()) A = list(map(int, input().split())) sum_A = sum(A) center = sum_A / 2 total = 0 near_center = 0 for a in A: total += a if abs(total - center) < abs(near_center - center): near_center = total ans = abs((sum_A - near_center) - near_center) print(ans) if __name__ == "__main__": main()
1
142,133,139,838,050
null
276
276
N = int(input()) result = 0 for i in range(1, (N + 1)): if i % 15 == 0: 'Fizz Buzz' elif i % 3 == 0: 'Fizz' elif i % 5 == 0: 'Buzz' else: result = result + i print(result)
n = int(input()) ans = sum(x for x in range(1, n+1) if x % 3 != 0 and x % 5 != 0) print(ans)
1
34,897,125,730,730
null
173
173
x = int(input()) a = x//100 b = x%100 l = list(range(1,6))[::-1] i = 0 cnt = 0 while b > 0: if l[i] > b: i += 1 cnt += b//l[i] b = b % l[i] print(1 if cnt <= a else 0)
M1,D1 = [int(i) for i in input().split()] M2,D2 = [int(i) for i in input().split()] if M1 != M2: print(1) else: print(0)
0
null
125,903,690,771,040
266
264
x = [int(s) for s in input().split()] print('Yes' if x[0] < x[1] and x[1] < x[2] else 'No')
lis = [int(x) for x in input().split()] if lis[0] < lis[1]and lis[1] < lis[2]: print("Yes") else: print("No")
1
380,153,812,272
null
39
39
n = int(input()) A = list(map(int, input().split())) MOD = 10**9+7 ans = 0 for i in range(60): cnt = 0 for a in A: cnt += a>>i&1 ans += cnt*(n-cnt)*2**i ans %= MOD print(ans)
import math x,k,d = map(int,input().split()) abs_x = abs(x) max_len = math.ceil(abs_x/d)*d min_len = max_len-d if abs_x-k*d >= 0: print(abs_x-k*d) exit() if (math.ceil(abs_x/d)-1)%2 == k%2: print(abs(abs_x-min_len)) else: print(abs(abs_x-max_len))
0
null
64,284,842,141,158
263
92
import math N, X, T = map(int, input().split()) t = int(math.ceil(N/X)) print('{}'.format(t*T))
text = '' while(True): try: text += input().lower() except: break count = [0 for i in range(26)] for c in text: if c < 'a' or c > 'z': continue count[ord(c) - ord('a')] += 1 for i, c in enumerate(count): print('{0} : {1}'.format(chr(i + ord('a')), c))
0
null
2,965,896,628,478
86
63
import collections def resolve(): n = int(input()) s = [input() for _ in range(n)] c = collections.Counter(s) max_count = c.most_common()[0][1] ans = [i[0] for i in c.items() if i[1]==max_count] for i in sorted(ans): print(i) resolve()
N = int(input()) dic = {} for _ in range(N): s = input() if s in dic: dic[s] += 1 else: dic[s] = 1 num = 0 for key in dic: num = max(num, dic[key]) ans = [] for key in dic: if dic[key] == num: ans.append(key) ans.sort() for a in ans: print(a)
1
69,893,102,424,000
null
218
218
n, k = map(int, input().split(" ")) p = list(map(int, input().split(" "))) p.sort() ans = sum(p[0:k]) print(ans)
import sys def Ii():return int(sys.stdin.readline()) def Mi():return map(int,sys.stdin.buffer.readline().split()) def Li():return list(map(int,sys.stdin.buffer.readline().split())) n,k = Mi(); p = Li(); p.sort(); print(sum(p[:k]))
1
11,620,736,035,830
null
120
120
import sys import re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N = INT() A = LIST() A_c = Counter(A) A_c_c = 0 for i in A_c.values(): A_c_c += i*(i-1)//2 for k in range(N): ans = A_c_c - (A_c[A[k]] - 1) print(ans)
n = int(input()) a = list(map(int, input().split())) ns = [0] * (n + 1) for i in a: ns[i] += 1 ans = 0 for i in ns: if i > 1: ans += i * (i - 1) // 2 for i in a: print(min(ans - (ns[i] - 1), ans))
1
47,806,059,665,280
null
192
192
import sys n = int(input()) A = list(map(int,sys.stdin)) cnt = 0 G = [int((2.15**i-1)/1.15)for i in range(17,0,-1)] G = [v for v in G if v <= n] 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 for g in G: insertionSort(A, n, g) print(len(G)) print(*G) print(cnt) print('\n'.join(map(str,A)))
A, B, M = [int(x) for x in input().split()] a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] x = [] y = [] c = [] for _ in range(M): xt, yt, ct = [int(x) for x in input().split()] x.append(xt) y.append(yt) c.append(ct) # 割引券を使わない場合の最小値 ret = min(a) + min(b) # 割引券を使った場合 for i in range(len(x)): t = a[x[i] - 1] + b[y[i] - 1] - c[i] if ret > t: ret = t print(ret)
0
null
27,048,549,731,450
17
200
from sys import stdin #n = int(stdin.readline().rstrip()) #l = list(map(int, stdin.readline().rstrip().split())) a,b,c = map(int, stdin.readline().rstrip().split()) #S = [list(map(int, stdin.readline().rstrip().split())) for _ in range(h)]#hの定義を忘れずに import math if c-a-b>0 and 4*a*b<(c-a-b)**2: print('Yes') else: print("No")
# #################################################################### # import io # import sys # _INPUT = """\ # 5 # 86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82 # 19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424 # 6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570 # 6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256 # 8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452 # 19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192 # 1 # 17 # 13 # 14 # 13 # """ # sys.stdin = io.StringIO(_INPUT) # #################################################################### D = int(input()) C = [int(i) for i in input().split()] SS = [[int(i) for i in input().split()] for _ in range(D)] T = [int(input()) for _ in range(D)] L = [0]*26 v = 0 for d, t in enumerate(T): t -= 1 L[t] = d+1 v += SS[d][t] for c, l in zip(C, L): v -= c * (d+1 - l) # v += C[t] print(v)
0
null
30,710,826,929,468
197
114
#a=int(input()) #b,c=int(input()),int(input()) # c=[] # for i in b: # c.append(i) H,N = map(int,input().split()) f = list(map(int,input().split())) #j = [input() for _ in range(a)] # h = [] # for i in range(e1): # h.append(list(map(int,input().split()))) if sum(f)>=H: print("Yes") else: print("No")
H,N = (int(x) for x in input().split()) A = [int(x) for x in input().split()] if sum(A)>=H: print('Yes') else: print('No')
1
78,123,486,310,740
null
226
226
data=str(input("")).split(" ") D=int(data[0]) T=int(data[1]) S=int(data[2]) if D<=T*S: print("Yes") else: print("No")
d,t,s=map(int, input().split()) if d/s<=t: print("Yes") else: print("No")
1
3,518,585,567,808
null
81
81
#!/usr/bin/env python # -*- coding: utf-8 -*- """ ??´????????? """ suits = {"S": 0, "H": 1, "C": 2, "D": 3} nsuits = ["S", "H", "C", "D"] cards = [[0 for i in range(13)] for j in range(4)] n = int(input()) for i in range(n): inp = input().split(" ") s = inp[0] c = int(inp[1]) - 1 cards[suits[s]][c] = 1 for i in range(4): for j in range(13): if cards[i][j] == 0: print("{0} {1}".format(nsuits[i], j+1))
x = int(input()) y=100 c=0 while 1: if y>=x : break y=y*101//100 c+=1 print(c)
0
null
14,189,396,546,998
54
159
N = int(input()) d = {} for _ in range(N): s = input() if s in d: d[s] += 1 else: d[s] = 1 d = {k: v for k, v in sorted(d.items(), key=lambda item: item[1], reverse=True)} max_count = -1 values = [] for k, v in d.items(): if max_count < v: max_count = v if v != max_count: break values.append(k) print("\n".join(sorted(values)))
from collections import deque s = deque(input()) q = int(input()) flag = True for _ in range(q): temp = input().split() if len(temp) == 1: flag = not flag else: if flag: if temp[1] == "1": s.appendleft(temp[2]) else: s.append(temp[2]) else: if temp[1] == "1": s.append(temp[2]) else: s.appendleft(temp[2]) if flag: print("".join(s)) else: print("".join(list(s)[::-1]))
0
null
63,768,163,416,358
218
204
from random import * D=int(input()) C=list(map(int,input().split())) S=[list(map(int,input().split())) for i in range(D)] X=[0]*26 XX=X[:] Y=X[:] YY=X[:] P=[] SC=0 N,M,L,O=0,0,0,0 for i in range(D): for j in range(26): X[j]+=C[j] XX[j]+=X[j] N,M=-1,-10**20 L,O=N,M for j in range(26): if Y==-1: N,M=0,X[0]+S[i][0] if M<X[j]+S[i][j]: L,O=N,M N,M=j,X[j]+S[i][j] elif O<X[j]+S[i][j]: L,O=j,X[j]+S[i][j] XX[N]-=X[N] X[N]=0 P.append([N,L]) SC+=X[N] SC2=0 for i in range(10**5): SC2=SC d,q=randrange(0,D),randrange(0,26) SC2-=S[d][P[d][0]] SC2+=S[d][q] for j in range(26): Y[j]=0 YY[P[d][0]],YY[q]=0,0 for j in range(D): if j==d: Z=q else: Z=P[j][0] Y[P[d][0]]+=C[P[d][0]] Y[q]+=C[q] Y[Z]=0 YY[P[d][0]]+=Y[P[d][0]] YY[q]+=Y[q] if SC2-sum(YY)>=SC-sum(XX): P[d][0]=q XX=YY[:] SC=SC2 elif randrange(0,10000)==0: if randrange(0,2): P[d][0]=q XX=YY[:] SC=SC2 else: P[d][1]=q for d in range(D): for q in range(26): SC2=SC SC2-=S[d][P[d][0]] SC2+=S[d][q] for j in range(26): Y[j]=0 YY[P[d][0]],YY[q]=0,0 for j in range(D): if j==d: Z=q else: Z=P[j][0] Y[P[d][0]]+=C[P[d][0]] Y[q]+=C[q] Y[Z]=0 YY[P[d][0]]+=Y[P[d][0]] YY[q]+=Y[q] if SC2-sum(YY)>=SC-sum(XX): P[d][0]=q XX=YY[:] SC=SC2 for i in range(10**5): SC2=SC d,q=randrange(0,D),randrange(0,26) SC2-=S[d][P[d][0]] SC2+=S[d][q] for j in range(26): Y[j]=0 YY[P[d][0]],YY[q]=0,0 for j in range(D): if j==d: Z=q else: Z=P[j][0] Y[P[d][0]]+=C[P[d][0]] Y[q]+=C[q] Y[Z]=0 YY[P[d][0]]+=Y[P[d][0]] YY[q]+=Y[q] if SC2-sum(YY)>=SC-sum(XX): P[d][0]=q XX=YY[:] SC=SC2 elif randrange(0,10000)==0: if randrange(0,2): P[d][0]=q XX=YY[:] SC=SC2 else: P[d][1]=q for d in range(D): for q in range(26): SC2=SC SC2-=S[d][P[d][0]] SC2+=S[d][q] for j in range(26): Y[j]=0 YY[P[d][0]],YY[q]=0,0 for j in range(D): if j==d: Z=q else: Z=P[j][0] Y[P[d][0]]+=C[P[d][0]] Y[q]+=C[q] Y[Z]=0 YY[P[d][0]]+=Y[P[d][0]] YY[q]+=Y[q] if SC2-sum(YY)>=SC-sum(XX): P[d][0]=q XX=YY[:] SC=SC2 for i in range(D): SC2=SC d,q=i,P[i][1] SC2-=S[d][P[d][0]] SC2+=S[d][q] for j in range(26): Y[j]=0 YY[P[d][0]],YY[q]=0,0 for j in range(D): if j==d: Z=q else: Z=P[j][0] Y[P[d][0]]+=C[P[d][0]] Y[q]+=C[q] Y[Z]=0 YY[P[d][0]]+=Y[P[d][0]] YY[q]+=Y[q] if SC2-sum(YY)>=SC-sum(XX): P[d]=P[d][::-1] XX=YY[:] SC=SC2 for i in range(D): print(P[i][0]+1)
import random import time import copy def down_score(d, c, last_d, score): sum = 0 for i in range(26): sum = sum + c[i]*(d-last_d[i]) return int(score - sum) def main(): D = int(input()) c = list(map(int, input().split())) s = [list(map(int, input().split())) for i in range(D)] start = time.time() last_d = [0 for i in range(26)] ans = [] score1 = 0 for i in range(D): max = 0 idx = 0 for j in range(26): if max < (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] != 0: max = s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2 idx = j elif max == (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] * (i-last_d[j])*(i-last_d[j]+1)/2 > c[idx]* (i-last_d[idx])*(i-last_d[idx]+1)/2 and c[j] != 0: idx = j last_d[idx] = i+1 score1 += s[i][idx] score1 = down_score(i+1,c,last_d,score1) ans.append(idx) while time.time() - start < 1.9: cp = ans.copy() last_d = [0 for i in range(26)] score2 = 0 idx1 = random.randint(0,25) idx2 = random.randint(0,25) idx3 = random.randint(0,25) if random.randint(0,1): d1 = random.randint(0,D-1) d2 = random.randint(0,D-1) d3 = random.randint(0,D-1) if idx1 == idx2 or idx1 == idx3 or idx2 == idx3: continue if random.randint(0,1): ans[d1] = idx1 elif random.randint(0,1): ans[d1] = idx1 ans[d2] = idx2 else: ans[d1] = idx1 ans[d2] = idx2 ans[d3] = idx3 #2値入れ替え elif random.randint(0,1): d1 = random.randint(0,D-8) d2 = random.randint(d1+1,d1+7) tmp1 = ans[d1] tmp2 = ans[d2] if random.randint(0,1): ans[d1] = tmp2 ans[d2] = tmp1 #3値入れ替え else: d1 = random.randint(0,D-11) d2 = random.randint(d1+1,d1+5) d3 = random.randint(d2+1,d2+5) tmp1 = ans[d1] tmp2 = ans[d2] tmp3 = ans[d3] if random.randint(0,1): ans[d1] = tmp2 ans[d2] = tmp3 ans[d3] = tmp1 else: ans[d1] = tmp3 ans[d2] = tmp1 ans[d3] = tmp2 for i in range(D): score2 += s[i][ans[i]] last_d[ans[i]] = i+1 score2 = down_score(i+1, c, last_d, score2) if score1 > score2: ans = cp.copy() else: score1 = score2 for i in range(D): print(ans[i]+1) if __name__ == "__main__": main()
1
9,660,542,858,960
null
113
113
N,M,Q = map(int, input().split()) ab = tuple(tuple(map(int, input().split())) for _ in range(Q)) ans = 0 def dfs(A): global ans if len(A) == N: tmp = 0 for i in range(Q): a,b,c,d = ab[i] if (A[b-1]-A[a-1]) == c: tmp += d if tmp > ans: ans = tmp else: last = A[-1] if len(A) > 0 else 1 for i in range(last, M+1): A.append(i) dfs(A) A.pop() dfs([]) print(ans)
a,b = list(map(int, input().split())) if a > b: sep = '>' elif a < b: sep = '<' else: sep = '==' print('a', sep, 'b')
0
null
13,882,894,076,292
160
38
import math a,b,h,m=map(int,input().split()) hc=360/12*h+30/60*m #時針の角度 mc=360/60*m #分針の角度 hm=abs(hc-mc) #時針と分針の角度の差 if hm > 180: hm=360-hm mcos=math.cos(math.radians(hm)) c=a**2+b**2-(2*a*b*mcos) #余剰定理 print(math.sqrt(c))
n, k = list(map(int, input().split())) MOD = (10 ** 9) + 7 ans = 0 min_val = 0 max_val = n p = 1 for i in range(n + 1): # print(min_val, max_val) if i + 1 >= k: ans += max_val - min_val + 1 ans = ans % MOD min_val += p max_val += n - p p += 1 print(ans)
0
null
26,539,831,056,824
144
170
def main(): n, r = map(int, input().split()) if n >= 10: print(r) else: print(r-100*(n-10)) if __name__ == "__main__": main()
def main(): n, r = map(int, input().split(" ")) print(r+100*(10-min(10,n))) if __name__ == "__main__": main()
1
63,553,407,156,960
null
211
211
x = int(input()) y = 10**4 for i in range(y): for j in range(-y,y): if i ** 5 - j ** 5 == x: print(i, j) exit()
import sys input=sys.stdin.buffer.readline #sys.setrecursionlimit(10**9) #from functools import lru_cache def RD(): return sys.stdin.read() def II(): return int(input()) def MI(): return map(int,input().split()) def MF(): return map(float,input().split()) def LI(): return list(map(int,input().split())) def LF(): return list(map(float,input().split())) def TI(): return tuple(map(int,input().split())) # rstrip().decode('utf-8') import numpy as np def main(): x=II() for i in range(-300,300): for j in range(-300,300): if i**5==x+j**5: print(i,j) exit() if __name__=="__main__": main()
1
25,447,270,992,298
null
156
156
N=int(input()) r=[0]*10000 for i in range(1,101): for j in range(1,101): for k in range(1,101): v = i*i + j*j + k*k + i*j + i*k + k*j if v <= 10000: r[v-1] += 1 for i in range(N): print(r[i])
N = int(input()) ans = [0]*10050 for i in range(1,105): for j in range(1,105): for k in range(1,105): v = (i+j+k)**2-(i*j+i*k+j*k) if v < len(ans): ans[v] += 1 for x in range(1,N+1): print(ans[x])
1
7,959,996,021,660
null
106
106
n,m = map(int,input().split()) h = list(map(int,input().split())) # 隣接リスト graph = [[] for _ in range(n)] for _ in range(m): a, b = map(int, input().split()) graph[a-1].append(b-1) graph[b-1].append(a-1) # 有向グラフなら消す def dfs(x): if len(graph[x]) == 0: return True for i in range(len(graph[x])): if h[graph[x][i]] >= h[x]: return False return True ans = 0 for i in range(n): if dfs(i): ans += 1 print(ans)
n,m = map(int,input().split()) h = list(map(int,input().split())) flg = [1]*n for _ in range(m): a,b = map(int,input().split()) if h[a-1] > h[b-1]: flg[b-1] = 0 elif h[a-1] == h[b-1]: flg[a-1],flg[b-1] = 0,0 else: flg[a-1] = 0 print(flg.count(1))
1
25,006,718,036,960
null
155
155
import sys def input(): return sys.stdin.readline().rstrip() K = int(input()) S = input() size = len(S) if size <= K: print(S) else: print(S[:K]+"...")
def main(): k = int(input()) s = str(input()) output = '' if len(s) > k: for i in range(k): output += s[i] output += '...' else: output = s print(output) if __name__ == '__main__': main()
1
19,618,554,197,250
null
143
143
from copy import deepcopy import numpy as np H, W, K = map(int, input().split()) matrix = [] for i in range(H): matrix.append(input()) matrix_int = np.ones((H, W), dtype=np.uint8) # 1 == 黒、 0 == 白 for row in range(H): for column in range(W): if matrix[row][column] == ".": matrix_int[row, column] = 0 count = 0 for row_options in range(2**H): for col_options in range(2**W): tmp_matrix_int = deepcopy(matrix_int) tmp_row_options = row_options tmp_col_options = col_options for row in range(H): mod = tmp_row_options % 2 if mod == 0: tmp_matrix_int[row,:] = 0 tmp_row_options = tmp_row_options // 2 for col in range(W): mod = tmp_col_options % 2 if mod == 0: tmp_matrix_int[:,col] = 0 tmp_col_options = tmp_col_options // 2 # print(tmp_matrix_int.sum()) if tmp_matrix_int.sum() == K: count += 1 print(count)
h,w,k = map(int, input().split()) s = [list(input()) for _ in range(h)] ans = 0 for row in range(2**h): for col in range(2**w): c = 0 for i in range(h): for j in range(w): if (row >> i)&1 == 0 and (col >> j)&1 == 0: if s[i][j]=='#': c += 1 if c == k: ans += 1 print(ans)
1
8,921,566,197,632
null
110
110
n = int(input()) A = list(map(int, input().split())) money = 1000 kabu = 0 memo = [] buy = True for i in range(n-1): if buy: if A[i] < A[i+1]: kabu = money //A[i] money %= A[i] buy = False else: if A[i] > A[i+1]: money += kabu * A[i] kabu = 0 buy = True if kabu: money += kabu * A[n-1] print(money)
import sys d={} for e in sys.stdin.readlines()[1:]: c,g=e.split() if'i'==c[0]:d[g]=0 else:print(['no','yes'][g in d])
0
null
3,711,606,993,750
103
23
count = int(input()) line = input().split() line.reverse() for i in range(count): print(line[i], end = "") if i != count-1: print(" ", end = "") print()
num = int(input()) numbers = list(map(int,input().split())) for i in reversed(numbers): print(i,end="") if i != numbers[0]: print(" ",end="") print()
1
1,005,111,400,778
null
53
53
# ???????????????. roomDict = {} for b in range(1, 4 + 1): for f in range(1, 3 + 1): for r in range(1, 10 + 1): roomNum = b * 100 + f * 10 + r roomDict[roomNum] = 0 # ??\???????????????????????????. n = int(input()) for i in range(n): input_b, input_f, input_r, input_v = map(int, input().split()) # b?£?f??????r???????????¨?±????v?????\?±?.v???????????????????????????. roomNum = input_b * 100 + input_f * 10 + input_r numOfPeople = roomDict[roomNum] roomDict[roomNum] = numOfPeople + input_v # ???????????¨?????????. isFirst = True for b in range(1, 4 + 1): if isFirst: isFirst = False else: print("####################") for f in range(1, 3 + 1): for r in range(1, 10 + 1): roomNum = b * 100 + f * 10 + r print(" {0}".format(roomDict[roomNum]), end='') print('')
# coding: utf-8 def showBuilding(mansion): for i, building in enumerate(mansion): for line in building: for room in line: print(' ' + str(room), end='') print() if i != 3: print('####################') def calcMoving(mansion, moving_status): b, f, r, v = moving_status live_in_person = mansion[b-1][f-1][r-1] if live_in_person + v >= 9: live_in_person = 9 elif live_in_person + v < 0: live_in_person = 0 else: live_in_person += v mansion[b-1][f-1][r-1] = live_in_person if __name__ == '__main__': mansion = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)] for _ in range(int(input())): calcMoving(mansion, map(int, input().split())) showBuilding(mansion)
1
1,083,686,943,570
null
55
55
import math x = int(input()) def lcm(a, b): return (a * b) // math.gcd(a, b) rad = lcm(360, x) print(rad//x)
a,b,C=map(float,input().split()) import math S=0.5*a*b*math.sin(math.radians(C)) print('{:.8f}'.format(S)) print('{:.8f}'.format(a+b+math.sqrt(pow(a,2)+pow(b,2)-2*a*b*math.cos(math.radians(C))))) print('{:.8f}'.format(S*2/a))
0
null
6,615,303,469,138
125
30
array_str = '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51' array = array_str.split(', ') k = int(input()) print(array[k - 1])
def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): tmp = [] if n % i == 0: tmp.append(i) tmp.append(n//i) if(len(tmp)>0): divisors.append(sum(tmp)) return divisors def main5(): n = int(input()) k = make_divisors(n) print(min(k)-2) if __name__ == '__main__': main5()
0
null
105,516,910,199,740
195
288
s=[] p=s.pop for e in input().split(): s+=[e if e.isdigit() else str(eval(p(-2)+e+p()))] print(*s)
print(1-(input()[:2]in input()))
0
null
62,394,307,599,360
18
264
#!/usr/bin/env python3 from typing import * YES = 'Yes' NO = 'No' # def solve(D: int, T: int, S: int) -> str: def solve(D, T, S): return YES if D <= T*S else NO def main(): D, T, S = map(int, input().split()) a = solve(D, T, S) print(a) if __name__ == '__main__': main()
from sys import stdin inp = lambda : stdin.readline().strip() d, t, s = [int(x) for x in inp().split()] if d / s <= t: print('Yes') else: print('No')
1
3,501,125,596,552
null
81
81
def main(): import sys def input(): return sys.stdin.readline().rstrip() n, k = map(int, input().split()) a = list(map(int, input().split())) mod = 10 ** 9+ 7 ans = 1 def answer(a): ans =1 for x in a: ans *= x ans %= mod return ans if n == k: print(answer(a)) return a.sort(reverse=True, key= lambda x:abs(x)) if sum(x<0 for x in a[:k])%2 == 0: print(answer(a[:k])) else: if all(x < 0 for x in a): print(answer(a[-k:])) else: try: x1, y1= min([x for x in a[:k] if x > 0]), min([x for x in a[k:] if x < 0]) except ValueError: x1, y1 = 1, 0 try: x2, y2= max([x for x in a[:k] if x < 0]),\ max([x for x in a[k:] if x >= 0]) except ValueError: x2, y2 = 1, 0 if abs(x2*y1) > abs(x1*y2): a[a.index(x1)] = y1 else: a[a.index(x2)] = y2 print(answer(a[:k])) if __name__ == '__main__': main()
n = int(input()) a = list(map(int, input().split())) cnt = 0 for i in range(len(a)): if i%2==0 and a[i]%2==1: cnt+=1 print(cnt)
0
null
8,538,339,811,856
112
105
# -*- coding: utf-8 -*- """ Created on Wed Sep 9 14:33:00 2020 @author: liang """ from math import gcd N, M = map(int, input().split()) A = [int(i) for i in input().split()] flag = False res = 1 for a in A: a //= 2 res *= a//gcd(res,a) if res > M: flag = True break #print(res) """ 存在チェック 2で割り切れる個数同じ? """ for a in A: if int(res/a) == res/a: flag = True if flag: ans = 0 print(ans) else: #ans = (M - res(A)//2)//res + 1 #ans = (M-1)//res//2 + 1 ans= (M//res + 1)//2 print(ans)
from fractions import gcd # for python 3.5~, use math.gcd def main(): N, M = list(map(int, input().split(' '))) half_A = list(map(lambda x: int(x) // 2, input().split(' '))) lcm = 1 for half_a in half_A: lcm *= half_a // gcd(lcm, half_a) if lcm > M: print(0) exit(0) for half_a in half_A: if (lcm // half_a) % 2 == 0: print(0) exit(0) num_multiples = M // lcm print((num_multiples + 1) // 2) # count only cases that ratios are odd numbers. if __name__ == '__main__': main()
1
101,759,164,307,030
null
247
247
n, k = map(int, input().split()) a = list(map(int, input().split())) mod = 10**9 + 7 a.sort() fac = [1] * (n + 1) inv = [1] * (n + 1) def COMinit(): for j in range(1, n + 1): fac[j] = fac[j - 1] * j % mod inv[n] = pow(fac[n], mod - 2, mod) for j in range(n - 1, -1, -1): inv[j] = inv[j + 1] * (j + 1) % mod def comb2(n, r): if r > n or n < 0 or r < 0: return 0 return fac[n] * inv[n - r] * inv[r] % mod COMinit() ans = 0 for i in range(n): x = comb2(n-1-i, k-1) ans = (ans - a[i]*x % mod) % mod ans = (ans + a[-1-i]*x % mod) % mod print(ans%mod)
n, k = map(int, input().split()) a = list(map(int, input().split())) mod = 10**9 + 7 a.sort() if n == 1: print(0) exit() fac = [1] * (n + 1) inv = [1] * (n + 1) def COMinit(): for j in range(1, n + 1): fac[j] = fac[j - 1] * j % mod inv[n] = pow(fac[n], mod - 2, mod) for j in range(n - 1, -1, -1): inv[j] = inv[j + 1] * (j + 1) % mod def comb2(n, r): if r > n or n < 0 or r < 0: return 0 return fac[n] * inv[n - r] * inv[r] % mod COMinit() ans = 0 for i in range(n): if k != 1: x = comb2(n-1-i, k-1) ans = (ans - a[i]*x % mod) % mod ans = (ans + a[-1-i]*x % mod) % mod print(ans%mod)
1
96,032,531,623,752
null
242
242