code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.71M
180,629B
code1_group
int64
1
299
code2_group
int64
1
299
n=int(input()) p=list(map(int,input().split())) minnumber=1e9 count=0 for i in p: if i<=minnumber: count+=1 minnumber=i print(count)
from math import floor,ceil,sqrt,factorial,log from collections import Counter, deque from functools import reduce import itertools def S(): return input() def I(): return int(input()) def MS(): return map(str,input().split()) def MI(): return map(int,input().split()) def FLI(): return [int(i) for i in input().split()] def LS(): return list(MS()) def LI(): return list(MI()) def LLS(): return [list(map(str, l.split() )) for l in input()] def LLI(): return [list(map(int, l.split() )) for l in input()] def LLSN(n: int): return [LS() for _ in range(n)] def LLIN(n: int): return [LI() for _ in range(n)] N = I() A = LI() ans = True for a in A: if a % 2 != 0: continue if a % 3 != 0 and a % 5 != 0: ans = False if ans: print("APPROVED") else: print("DENIED")
0
null
77,285,534,908,612
233
217
h = int(input()) for i in range(100): if 2**i > h: print(2**i - 1) exit()
input_data = input().split(" ") items = [int(cont) for cont in input_data] keys = ['T', 'S', 'E', 'W', 'N', 'B'] dice = dict(zip(keys, items)) def q1(): def rot_func_list(rot, dice): if rot == "N": keys = ['T', 'S', 'B', 'N'] items = dice['S'], dice['B'], dice['N'], dice['T'] new_dice = dict(zip(keys, items)) dice.update(new_dice) if rot == "S": keys = ['T', 'S', 'B', 'N'] items = dice['N'], dice['T'], dice['S'], dice['B'] new_dice = dict(zip(keys, items)) dice.update(new_dice) if rot == "E": keys = ['T', 'E', 'B', 'W'] items = dice['W'], dice['T'], dice['E'], dice['B'] new_dice = dict(zip(keys, items)) dice.update(new_dice) if rot == "W": keys = ['T', 'E', 'B', 'W'] items = dice['E'], dice['B'], dice['W'], dice['T'] new_dice = dict(zip(keys, items)) dice.update(new_dice) controls = list(input()) for i in controls: rot_func_list(i, dice) print(dice["T"]) def q2(): def search_surf(conds, dice): a,b=conds a_key = [k for k, v in dice.items() if v == a ] b_key = [k for k, v in dice.items() if v == b ] key_list = a_key + b_key part_st = ''.join(key_list) def search(part_st): if part_st in "TNBST": return "W" if part_st in "TSBNT": return "E" if part_st in "TEBWT": return "N" if part_st in "TWBET": return "S" if part_st in "NESWN": return "B" if part_st in "NWSEN": return "T" target_key = search(part_st) print(dice[target_key]) a = input() repeater = int(a) for neee in range(repeater): control_input = input().split(" ") conds = [int(i) for i in control_input] search_surf(conds, dice) q2()
0
null
40,234,740,001,280
228
34
import sys def isEmpty(S): if len(S) == 0: return True def isFull(S): if len(S) >= 101: return True def push(x): if isFull(S): print 'Error' S.append(x) def pop(top): if isEmpty(S): print 'error' k = S[top] S.pop() return k S = [] top = -1 x = sys.stdin.readline().strip() x_list = x.split(" ") for i in range(0, len(x_list)): if x_list[i] == '*': a = int(pop(top)) top -= 1 b = int(pop(top)) top -= 1 push(a * b) top += 1 elif x_list[i] == '+': a = int(pop(top)) top -= 1 b = int(pop(top)) top -= 1 push(a + b) top += 1 elif x_list[i] == '-': a = int(pop(top)) top -= 1 b = int(pop(top)) top -= 1 push(b - a) top += 1 else: push(x_list[i]) top += 1 a = int(pop(top)) print a
import sys Stack = [] MAX = 1000 def push(x): #if isFull(): # print "ERROR!" # sys.exit() Stack.append(x) def pop(): #if isEmpty(): # print "ERROR!" # sys.exit() Stack.pop(-1) def cul(exp): for v in exp: if v == "+": x = reduce(lambda a,b:int(a)+int(b), Stack[-2:]) for i in range(2): pop() push(x) elif v == "-": x = reduce(lambda a,b:int(a)-int(b), Stack[-2:]) for i in range(2): pop() push(x) elif v == "*": x = reduce(lambda a,b:int(a)*int(b), Stack[-2:]) for i in range(2): pop() push(x) else: push(v) return Stack[0] if __name__ == "__main__": exp = sys.stdin.read().strip().split(" ") ans = cul(exp) print ans
1
37,240,648,812
null
18
18
R=int(input()) print(2*R*3.1419)
import math n = int(input()) a = math.pi print(2*n*a)
1
31,475,757,601,960
null
167
167
h1, m1, h2, m2, k = list(map(int, input().split())) if m2 < m1: while m2 < m1: h2 -= 1 m2 += 60 tm = m2 - m1 th = h2 - h1 if k > (th*60 + tm): print (0) else: print(th*60 + tm - k)
import math h1, m1, h2, m2, k = map(int, input().split(" ")) t1 = h1 * 60 + m1 t2 = h2 * 60 + m2 print(t2 - t1 - k)
1
18,099,371,898,790
null
139
139
r, c = map(int, [int(_) for _ in input().split()]) ll = [] for _ in range(r): l = [int(n) for n in input().split()] l.append(sum(l)) ll.append(l) l = [sum(_) for _ in zip(*ll)] ll.append(l) for l in ll: print(" ".join([str(_) for _ in l]))
r, c = map(int, input().split(' ')) matrix = [] total_cols = [0 for i in range(c+1)] for i in range(r): rows = list(map(int, input().split(' '))); total = sum(rows) rows.append(total) total_cols = [ total_cols[i] + x for i, x in enumerate(rows) ] matrix.append(rows) matrix.append(total_cols) for row in matrix: print(' '.join([str(i) for i in row]))
1
1,347,035,723,098
null
59
59
i=1 while True: a=int(input()) if a == 0: break print("Case {0}: {1}".format(i,a)) i=i+1
N=int(input()) A=list(map(int,input().split())) count=0 for i in range(len(A)): if A[i]%2==0: if A[i]%3==0 or A[i]%5==0: count+=1 else: count+=1 if count==len(A): print("APPROVED") else: print("DENIED")
0
null
34,732,722,092,212
42
217
x = input().split() a = int(x[0]) b = int(x[1]) if a == b : print('a == b') elif a > b : print('a > b') else : print('a < b')
n =raw_input() m =n.split(" ") a = int(m[0]) b = int(m[1]) if a < b :print "a < b" if a > b :print "a > b" if a == b :print "a == b"
1
354,521,369,962
null
38
38
def sel_sort(A, N): ''' 選択ソート ''' count = 0 for n in range(N): minm = n for m in range(n, N): if A[m] < A[minm]: minm = m if minm != n: A[n], A[minm] = A[minm], A[n] count += 1 return (A, count) if __name__ == '__main__': N = int(input()) A = list(map(int, input().split(' '))) ans = sel_sort(A, N) print(' '.join([str(x) for x in ans[0]])) print(ans[1])
A=input() if str.isupper(A): print('A') else: print('a')
0
null
5,693,949,263,762
15
119
X, Y = map(int, input().split()) if Y % 2 == 1: print("No") exit(0) if 0 <= 2 * X - Y / 2 <= X: print("Yes") else: print("No")
x,y=map(int,input().split()) t=2*y-4*x c=y-t if t<0 or c<0 or t%4!=0 or c%2!=0: print("No") else: print("Yes")
1
13,771,256,063,730
null
127
127
a = [[[0] * 10 for i in range(3)] for j in range(4)] n = int(input()) for _ in range(n): [b, f, r, v] = [int(j) - 1 for j in input().split()] a[b][f][r] += v + 1 for i, d in enumerate(a): for c in d: print("", *c) if i != len(a) - 1: print("#" * 20)
a = list(map(int, input().rstrip().split())) resto=a[0]%a[-1] if resto >0: o = a[0]+a[-1]- resto else: o= a[0] print((a[1]-o)//a[-1]+1)
0
null
4,325,700,155,360
55
104
import sys from math import log10, floor print('\n'.join(map(str, [floor(log10(sum(map(int, ab.split())))) + 1 for ab in sys.stdin])))
import sys [print(len(str(sum(map(int, line.split()))))) for line in sys.stdin]
1
118,299,708
null
3
3
def main(): n, m = map(int, input().split()) # nは偶数、mは奇数 # n+mから2つ選ぶ選び方は # n:m = 0:2 和は 偶数、選び方はmC2 # n:m = 1:1 和は 奇数 (今回はこれは含めない) # n:m = 2:0 和は 偶数、選び方はnC2 cnt = 0 if m >= 2: cnt += m * (m -1) // 2 if n >=2: cnt += n * (n -1) // 2 print(cnt) if __name__ == '__main__': main()
N, M = (int(x) for x in input().split()) print(int(N*(N-1)/2 + M*(M-1)/2))
1
45,251,150,875,168
null
189
189
# 問題:https://atcoder.jp/contests/abc143/tasks/abc143_b n = int(input()) d = list(map(int, input().strip().split())) res = 0 for i in range(1, n): for j in range(i): res += d[i] * d[j] print(res)
from itertools import combinations n = int(input()) d = list(map(int,input().split())) ans = 0 for x,y in combinations(range(n),2): ans += d[x] * d[y] print(ans)
1
168,395,294,572,648
null
292
292
A = [] b = [] n,m = [int(i) for i in input().split()] for i in range(n): A.append([int(j) for j in input().split()]) for i in range(m): b.append(int(input())) for i in range(n): print(sum([x*y for x,y in zip(A[i],b)]))
n = int(input()) a , b = input().split() ans = "" for i in range(n): ans += a[i] ans += b[i] print(ans)
0
null
56,459,609,062,402
56
255
import sys n = int(raw_input()) R = [int(raw_input()) for i in xrange(n)] minimum = sys.maxint maximum = -sys.maxint - 1 for x in R: p = x - minimum if maximum < p: maximum = p if minimum > x: minimum = x print maximum
# coding: utf-8 def getint(): return int(input().rstrip()) def main(): n = getint() values = [] for i in range(n): values.append(getint()) maxv = values[1] - values[0] minv = values[0] for j in range(1,n): maxv = max(maxv, values[j]-minv) minv = min(minv, values[j]) print(maxv) if __name__ == '__main__': main()
1
13,665,521,338
null
13
13
while(True): a = input() if '?' in a: break print(int(eval(a)))
len_s = int(input()) s = [int(i) for i in input().split()] len_t = int(input()) t = [int(i) for i in input().split()] cnt = 0 for f in t: i = 0 while i < len(s) and s[i] != f: i += 1 if i < len(s): cnt +=1 print(cnt)
0
null
366,815,788,132
47
22
import sys, bisect, math, itertools, string, queue, copy import numpy as np import scipy from collections import Counter,defaultdict,deque from itertools import permutations, combinations from heapq import heappop, heappush from fractions import gcd input = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9+7 def inp(): return int(input()) def inpm(): return map(int,input().split()) def inpl(): return list(map(int, input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(input()) for _ in range(n)) def inplL(n): return [list(input()) for _ in range(n)] def inplT(n): return [tuple(input()) for _ in range(n)] def inpll(n): return [list(map(int, input().split())) for _ in range(n)] def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) k = inp() runrun = [["1","2","3","4","5","6","7","8","9"]] runrun_int = [] for j in range(2,11): tmp = [] for i in range(len(runrun[j - 2])): if runrun[j-2][i][j-2] == "0": tmp.append(runrun[j-2][i] + str(int(runrun[j-2][i][j-2]))) tmp.append(runrun[j-2][i] + str(int(runrun[j-2][i][j-2]) + 1)) elif runrun[j-2][i][j-2] in ["1","2","3","4","5","6","7","8"]: tmp.append(runrun[j-2][i] + str(int(runrun[j-2][i][j-2]) - 1)) tmp.append(runrun[j-2][i] + str(int(runrun[j-2][i][j-2]))) tmp.append(runrun[j-2][i] + str(int(runrun[j-2][i][j-2]) + 1)) elif runrun[j-2][i][j-2] == "9": tmp.append(runrun[j-2][i] + str(int(runrun[j-2][i][j-2]) - 1)) tmp.append(runrun[j-2][i] + str(int(runrun[j-2][i][j-2]))) runrun.append(tmp) ans = [] for i in range(len(runrun)): for j in range(len(runrun[i])): ans.append(int(runrun[i][j])) ans.sort() print(ans[k - 1])
from sys import stdin from collections import deque def main(): #入力 readline=stdin.readline k=int(readline()) lunlun_number=[] d=deque(map(str,range(1,10))) cnt=0 while cnt<k: now=d.popleft() lunlun_number.append(now) cnt+=1 if now[-1]=="0": nex=("0","1") elif now[-1]=="9": nex=("8","9") else: last=int(now[-1]) nex=(str(last-1),str(last),str(last+1)) for x in nex: d.append(now+x) print(lunlun_number[k-1]) if __name__=="__main__": main()
1
40,098,913,140,222
null
181
181
import math R=float(input()) print(2.0*R*math.pi)
r = int(input()) print(r*2*3.141)
1
31,562,429,172,318
null
167
167
while True: a, op, b = input().split() # 3変数ともに文字列として読み込む a = int(a) # a を整数に変換 b = int(b) # b を整数に変換 if op == '?': break elif op == '+': print("%d"%(a+b)) elif op == '-': print("%d"%(a-b)) elif op == '/': print("%d"%(a/b)) else: print("%d"%(a*b))
while True: a, op, b = input().split() if op == "?": break elif op == "+": print(int(a) + int(b)) elif op == "-": print(int(a) - int(b)) elif op == "*": print(int(a) * int(b)) elif op == "/": print(int(a) // int(b))
1
681,840,404,580
null
47
47
import math R = int(input()) pi = math.pi ans = 2*R * pi print(ans)
r = int(input()) print(6.3*r)
1
31,413,905,852,644
null
167
167
N,D=map(int,input().split()) X=[] for i in range(N): X.append(list(map(int,input().split()))) count=0 for i in range(N): if pow(X[i][0]*X[i][0]+X[i][1]*X[i][1],1/2)<=D:count+=1 print(count)
import math nd = list(map(int,input().split(" "))) n = nd[0] d = nd[1] cnt = 0 xy=[] for i in range(n): xy.append(list(map(int,input().split(" ")))) result = math.sqrt((xy[i][0]**2)+(xy[i][1]**2)) if result <= d: cnt += 1 print(cnt)
1
5,945,323,749,724
null
96
96
a = list(set([i*j for i in range(1,10) for j in range(1, 10)])) n = int(input()) print('Yes' if n in a else 'No')
n = int(input()) print('Yes' if any(i*j == n for i in range(1, 10) for j in range(1, 10)) else 'No')
1
160,032,147,478,120
null
287
287
from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations # (string,3) 3回 from collections import deque from collections import defaultdict import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 def readInts(): return list(map(int,input().split())) def main(): n = int(input()) A = readInts() # 全体の合計 その差が答え 全部で最小値を取る total = sum(A) mi_ = float("inf") left = 0 for i in range(n): left += A[i] total -= A[i] mi_ = min(mi_,abs(left - total)) print(mi_) if __name__ == '__main__': main()
n, x, t = map(int, input().split()) time = 0 cnt = 0 while cnt < n: time += t cnt += x print(time)
0
null
73,067,865,541,340
276
86
# -*- coding: utf-8 -*- S = [0] * 13 H = [0] * 13 C = [0] * 13 D = [0] * 13 n = int(raw_input()) for i in xrange(n): symbol, num = map(str, raw_input().split()) if symbol == 'S': S[int(num)-1] = 1 elif symbol == 'H': H[int(num)-1] = 1 elif symbol == 'C': C[int(num)-1] = 1 else: D[int(num)-1] = 1 cards = [S, H, C, D] marks = ['S', 'H', 'C', 'D'] for card, mark in zip(cards, marks): for index, num in enumerate(card): if num < 1: print mark, index+1
haveTrumps = [[0 for i in range(13)] for j in range(4)] allCards = int(input()) for i in range(0, allCards): cardType, cardNum = input().split() if cardType == "S": haveTrumps[0][int(cardNum) - 1] = 1 elif cardType == "H": haveTrumps[1][int(cardNum) - 1] = 1 elif cardType == "C": haveTrumps[2][int(cardNum) - 1] = 1 elif cardType == "D": haveTrumps[3][int(cardNum) - 1] = 1 for i in range(0, 4): for j in range(0, 13): if haveTrumps[i][j] == 0: if i == 0: print("S ", end="") elif i == 1: print("H ", end="") elif i == 2: print("C ", end="") elif i == 3: print("D ", end="") print("{0}".format(j + 1))
1
1,018,448,438,368
null
54
54
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): def root(x): if par[x] == x: return x par[x] = root(par[x]) return par[x] def unite(x,y): x = root(x) y = root(y) if rank[x] < rank[y]: par[x] = y else: par[y] = x if rank[x] == rank[y]: rank[x] += 1 n,m = LI() rank = [0]*n par = [i for i in range(n)] for _ in range(m): a,b = LI() a -= 1 b -= 1 if root(a) != root(b): unite(a,b) cnt = [0]*n for i in range(n): cnt[root(i)] += 1 print(max(cnt)) return #Solve if __name__ == "__main__": solve()
k, x = map(int, input().split()) if 500 * k >= x: print('Yes') elif 500 * k < x: print('No')
0
null
51,147,306,642,278
84
244
a=int(input("")) if a>=30: print("Yes") elif a<30: print("No")
import sys while 1: H,W = map(int, raw_input().split()) if H == 0 and W == 0: break for i in range(H): for j in range(W): if i%2 == 0: if j%2 == 0: sys.stdout.write("#") else: sys.stdout.write(".") if i%2 != 0: if j%2 != 0: sys.stdout.write("#") else: sys.stdout.write(".") if j == W-1: print "" print ""
0
null
3,320,742,487,650
95
51
import sys a,b,c = map(int,sys.stdin.readline().split()) if a < b and b < c: print('Yes') else: print('No')
import sys, math import bisect sys.setrecursionlimit(500000) MOD = 10**9+7 def input(): return sys.stdin.readline()[:-1] def mi(): return map(int, input().split()) def ii(): return int(input()) def i2(n): tmp = [list(mi()) for i in range(n)] return [list(i) for i in zip(*tmp)] def isPrime(n): if n < 2: return False i = 2 while i*i <= n: if n%i==0: return False i += 1 return True def main(): 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] K = ii() print(l[K-1]) if __name__ == '__main__': main()
0
null
25,336,837,479,512
39
195
N = int(input()) moji = str(input()) if len(moji) <= N: print(moji) else: print(moji[:N] + "...")
K=int(input()) S=input() if len(S)<=K: print(S) else: for i in range(K): print(S[i],end="") print("...")
1
19,704,131,235,250
null
143
143
if __name__ == '__main__': n,k = map(int,input().split()) A = list(map(int,input().split())) A.sort() print(sum(A[:k]))
L, R = input().split() huga = list(map(int, input().split())) i=0 gou=0 huga.sort() for a in range(int(R)): gou=gou+huga[i] i+=1 print(gou)
1
11,641,658,558,780
null
120
120
a, b, c = map(int, input().split()) if c - (a+b) < 0: print("No") exit() if 4*a*b < c**2 - 2*c*(a+b) + (a+b)**2: print("Yes") else: print("No")
while(True): H, W = map(int, input().split()) if(H == W == 0): break first = False for i in range(H): print("#" * W) print()
0
null
26,258,485,747,530
197
49
c = 0 while 1: c += 1 t = int(input()) if t==0: break print("Case "+str(c)+":",t)
l = [] while True: i = str(input()) if i == '0': break else: l.append(i) t = 0 for i in l: t += 1 print('Case '+str(t)+': '+i)
1
472,746,021,732
null
42
42
d = int(input()) c = list(map(int,input().split())) s = [0]*d for i in range(d): s[i] = list(map(int,input().split())) lis = [0]*26 sum_score = 0 for i in range(d): #d日全てに対して ans = -float("Inf") num = 0 for j in range(26): #i日目にj番目を選んだ時の得点を計算 score = 0 score += s[i][j] for k in range(26): if k != j: score -= (lis[k]+1)*c[k] if score > ans: ans = score num = j sum_score += ans #print(sum_score) print(num+1) for j in range(26): if j != num: lis[j] += 1 else: lis[j] = 0 #print(lis)
n = int(input()) print(0 if n == 1 else 1)
0
null
6,332,552,195,808
113
76
a, b, k = map(int, input().split()) if k <= a: a -= k elif a < k <= a + b: temp = a a = 0 b -= k - temp else: a = 0 b = 0 print('{} {}'.format(a, b))
a, b, k = map(int, input().split()) if a==0 and b==0: print(0, 0) elif k>a: if b-(k-a)>0: print(0, b-(k-a)) else: print(0, 0) elif k<a: print(a-k, b) elif a==k: print(0, b)
1
104,287,721,873,138
null
249
249
#from collections import deque,defaultdict printn = lambda x: print(x,end='') inn = lambda : int(input()) inl = lambda: list(map(int, input().split())) inm = lambda: map(int, input().split()) ins = lambda : input().strip() DBG = True # and False BIG = 10**18 R = 10**9 + 7 #R = 998244353 def ddprint(x): if DBG: print(x) s = ins() t = ins() ls = len(s) lt = len(t) mn = BIG for i in range(ls-lt+1): x = 0 for j in range(lt): if s[i+j]!=t[j]: x += 1 mn = min(mn,x) print(mn)
n=int(input()) c=0 for _ in range(n): x=int(input()) if x==2:c+=1 elif pow(2,x-1,x)==1:c+=1 print(c)
0
null
1,818,494,730,302
82
12
while(True): a = input() if '?' in a: break print(int(eval(a)))
T1, T2 = map(int, input().split()) A1, A2 = map(int, input().split()) B1, B2 = map(int, input().split()) D1 = T1 * A1 - T1 * B1 D2 = T1 * A1 + T2 * A2 - T1 * B1 - T2 * B2 if D1 * D2 > 0: print(0) elif D2 == 0: print("infinity") else: D1 = abs(D2 - D1) D2 = abs(D2) c = (D1 // D2) * 2 - 1 if D1 % D2 == 0: c -= 1 print(c)
0
null
66,419,945,308,222
47
269
rooms = [0] * (4*3*10) count = int(input()) for i in range(count): b, f, r, v = [int(x) for x in input().split()] rooms[30*(b-1) + 10*(f-1) + (r-1)] += v for i, room in enumerate(rooms, start=1): print('', room, end='') if i%10 == 0: print() if i%30 == 0 and i%120 != 0: print('#'*20)
x,y=map(int,input().split()) if (x*2) <= y <= (x*4) and y%2 ==0: print('Yes') else: print('No')
0
null
7,469,375,614,492
55
127
H, A = map(int, input().split()) if H % A == 0: count_e = H//A print(count_e) elif H < A: count_u = 1 print(count_u) elif H % A != 0: count_o = H // A + 1 print(count_o)
S = list(str(input())) T = list(str(input())) if S == T[:len(T)-1]: print('Yes') else: print('No')
0
null
49,356,488,689,948
225
147
import sys sys.setrecursionlimit(10 ** 9) N,u,v = map(int,input().split()) u -= 1 v -= 1 E = [set() for _ in range(N)] for _ in range(N-1): a,b = map(int,input().split()) a -= 1 b -= 1 E[a].add(b) E[b].add(a) DU = [-1 for _ in range(N)] DV = [-1 for _ in range(N)] def dfs(p,c,D): D[p] = c for q in E[p]: if D[q] == -1: dfs(q,c+1,D) dfs(u,0,DU) dfs(v,0,DV) #print(DU) #print(DV) mx = 0 for du,dv in zip(DU,DV): if du < dv: mx = max(dv,mx) print(mx-1)
def check(seq): return len(seq) != len(set(seq)) def main(): N = int(input()) A = list(map(int, input().split())) ans = check(A) if ans: print("NO") else: print("YES") main()
0
null
95,949,168,610,692
259
222
def bubbleSort(A, N): flag = 1 count = 0 while flag: flag = 0 for j in xrange(N-1,0,-1): if A[j] < A[j-1]: tmp = A[j] A[j] = A[j-1] A[j-1] = tmp flag += 1 count += 1 return A, count def main(): N = int(raw_input()) A = map(int, raw_input().split()) new_A, count = bubbleSort(A, N) print ' '.join(map(str,new_A)) print count if __name__ == "__main__": main()
from sys import stdin import sys import math from functools import reduce import functools import itertools from collections import deque,Counter,defaultdict from operator import mul import copy # ! /usr/bin/env python # -*- coding: utf-8 -*- import heapq sys.setrecursionlimit(10**6) # INF = float("inf") INF = 10**18 import bisect import statistics mod = 10**9+7 # mod = 998244353 import numpy N = int(input()) A = list(map(int, input().split())) a = numpy.argsort(A) b = [] for i in range(N): b.append(str(a[i]+1)) print(" ".join(b))
0
null
90,027,050,933,430
14
299
from itertools import accumulate N, K = map(int, input().split()) P = tuple(accumulate(map(int, input().split()))) ans = P[K - 1] for i in range(N - K): ans = max(P[i + K] - P[i], ans) print((ans + K) / 2)
def main(): a = int(input()) ans = a + a ** 2 + a ** 3 print(ans) if __name__ == '__main__': main()
0
null
42,377,424,728,340
223
115
N = int(input()) As = list(map(int, input().split())) height = 1 step = 0 for i in range(N): if As[i] < height: step += height - As[i] else: height = As[i] print(step)
a, b = map(int, input().split()) mat = [map(int, input().split()) for i in range(a)] vec = [int(input()) for i in range(b)] for row in mat: print(sum([x*y for x, y in zip(row, vec)]))
0
null
2,892,685,770,120
88
56
import math H,A=map(int,input().split()) if H<=A: print(1) else: print(math.ceil(H/A))
H,A = map(int, input().split()) ans=0 for i in range(H//A+1): if H >0: H=H-A ans+=1 else: break print(ans)
1
76,879,918,866,482
null
225
225
S = input() N = len(S) def is_palindrome(s): return s == ''.join(list(reversed(s))) ans = 'Yes' if is_palindrome(S) and is_palindrome(S[:(N-1)//2]) and is_palindrome(S[(N+1)//2:]) else 'No' print(ans)
mount=[] for i in range(10): tmp=int(input()) mount.append(tmp) mount.sort() mount.reverse() for i in range(3): print(mount[i])
0
null
23,305,433,234,226
190
2
H,A=map(int,input().split()) count=0 while H >= 1: H -= A count += 1 print(count)
import math N, M = map(int, input().split()) A_list = list(map(int, input().split())) cnt = 0 A_sum = sum(A_list) for i in range(N): if A_list[i] >= math.ceil(A_sum/4/M): cnt += 1 if cnt >= M: print("Yes") else: print("No")
0
null
57,950,577,092,030
225
179
from collections import Counter counter = Counter() while True: try: s = input() for c in s: counter[c.lower()] += 1 except: break for c in range(ord('a'), ord('z')+1): print('{} : {}'.format(chr(c), counter[chr(c)]))
import sys sen=[] for line in sys.stdin: sen.append(line) Sen=''.join(sen) a=[] b=[] c=[] d=[] e=[] f=[] g=[] h=[] i=[] j=[] k=[] l=[] m=[] n=[] o=[] p=[] q=[] r=[] s=[] t=[] u=[] v=[] x=[] y=[] z=[] w=[] count={'a':a,'b':b,'c':c,'d':d,'e':e,'f':f,'g':g,'h':h,'i':i,'j':j,'k':k,'l':l,'m':m,'n':n,'o':o,'p':p,'q':q,'r':r,'s':s,'t':t,'u':u,'v':v,'w':w,'x':x,'y':y,'z':z} for i in range(len(Sen)): if Sen[i].isalpha(): count[Sen[i].lower()].append('#') for char in sorted(count.keys()): print('%s : %d'%(char,len(count[char])))
1
1,647,168,598,350
null
63
63
#coding:UTF-8 a,b = map(int,raw_input().split()) d = a/b r = a%b f = float(a)/b f = '%.8f' % (f) print d,r,f
s=input() t=input() ans=10**8 n=len(s) m=len(t) for i in range(n-m+1): cnt=0 for j in range(m): if s[i+j]!=t[j]: cnt+=1 ans=min(ans,cnt) print(ans)
0
null
2,122,733,501,988
45
82
N = int(input()) XYList = [] for i in range(N): A = int(input()) XY = [] for j in range(A): XY.append(list(map(int, input().split()))) XYList.append(XY) maxSum = 0 for i in range(2**N): sum = 0 for j in range(N): if i >> j & 1: honest = True for XY in XYList[j]: if ((i >> (XY[0]-1)) & 1) != XY[1]: honest = False break if honest: sum += 1 else: sum = 0 break if maxSum < sum: maxSum = sum print(maxSum)
def main(): N, K = map(int, input().split()) *A, = map(int, input().split()) ans = [] for i in range(K, N): cond = A[i] > A[i - K] ans.append('Yes' if cond else 'No') print(*ans, sep='\n') if __name__ == '__main__': main()
0
null
64,574,223,856,256
262
102
n = int(input()) a = list(map(int,input().split())) mod = 10**9 + 7 temp = sum(a)**2 for x in a: temp -= x**2 print((temp//2)%mod)
n = int(input()) a = list(map(int, input().split())) ruiseki = 0 count = 0 for i in range(n-1): ruiseki += a[i] count += ruiseki * a[i+1] mod = 10**9 + 7 if count >= mod: print(count%mod) else: print(count)
1
3,849,472,800,292
null
83
83
import sys input = sys.stdin.readline h,w,m = map(int,input().split()) h_array = [ 0 for i in range(h) ] w_array = [ 0 for i in range(w) ] ps = set() for i in range(m): hi,wi = map( lambda x : int(x) - 1 , input().split() ) h_array[hi] += 1 w_array[wi] += 1 ps.add( (hi,wi) ) h_great = max(h_array) w_great = max(w_array) h_greats = list() w_greats = list() for i , hi in enumerate(h_array): if hi == h_great: h_greats.append(i) for i , wi in enumerate(w_array): if wi == w_great: w_greats.append(i) ans = h_great + w_great for _h in h_greats: for _w in w_greats: if (_h,_w) in ps: continue print(ans) exit() print(ans-1)
n = int(raw_input()) i = 1 print "", for i in range(1,n+1): x = i if x%3 == 0: print "%d" %i , elif x%10 == 3: print "%d" %i , else: while x != 0: x = x/10 if x % 10 == 3: print "%d" %i , break
0
null
2,784,971,301,920
89
52
# ABC159 # String Palindrome S = input() n = len(S) n m = int(((n - 1)/2)-1) l = int(((n + 3)/2)-1) if S[::1] == S[::-1]: if S[:m+1:] == S[m::-1]: if S[l::] == S[:l-1:-1]: print('Yes') exit() print('No')
# --*-coding:utf-8-*-- def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) B = [0]*(N+1) b = 0 for i, a in enumerate(A): b += a - 1 b %= K B[i+1] = b Q = {} X = 0 for i, b in enumerate(B): if i>=K: Q[B[i-K]] -= 1 if b in Q: X += Q[b] Q[b] += 1 else: Q[b] = 1 print(X) if __name__ == '__main__': main()
0
null
92,109,966,722,852
190
273
W, H, x, y, r = map(int, input().split()) flg = False for X in [x - r, x + r]: for Y in [y - r, y + r]: if not 0 <= X <= W or not 0 <= Y <= H: flg = True print(["Yes", "No"][flg])
a = int(input()) S ="" l =['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] num = a % 26 while a >0: if a%26 !=0: S =l[(a%26)-1] + S a = (a-a%26)//26 else: S = l[(a%26)-1] + S a = (a-26)//26 print(S)
0
null
6,122,828,249,340
41
121
import math n = int(input()) mod = 10**9+7 d = {} zero = 0 for i in range(n): a,b = map(int,input().split()) if a == 0 and b == 0: zero += 1 else: g = math.gcd(a,b) a //= g b //= g if b < 0: a = -a b = -b if b == 0 and a == -1: a = 1 if a > 0: if (a,b) in d: d[(a,b)][0] += 1 else: d[(a,b)] = [1,0] else: if (b,-a) in d: d[(b,-a)][1] += 1 else: d[(b,-a)] = [0,1] ans = 1 for (a,b),(c,d) in d.items(): count = (pow(2,c,mod)+pow(2,d,mod)-1)%mod ans *= count ans %= mod print((ans+zero-1)%mod)
n = int(input()) ab=[list(map(int,input().split())) for i in range(n)] import math from collections import defaultdict d = defaultdict(int) zerozero=0 azero=0 bzero=0 for tmp in ab: a,b=tmp if a==0 and b==0: zerozero+=1 continue if a==0: azero+=1 continue if b==0: bzero+=1 continue absa=abs(a) absb=abs(b) gcd = math.gcd(absa,absb) absa//=gcd absb//=gcd if a*b >0: d[(absa,absb)]+=1 else: d[(absa,-absb)]+=1 found = defaultdict(int) d[(0,1)]=azero d[(1,0)]=bzero ans=1 mod=1000000007 for k in list(d.keys()): num = d[k] a,b=k if b>0: bad_ab = (b,-a) else: bad_ab = (-b,a) if found[k]!=0: continue found[bad_ab] = 1 bm=d[bad_ab] if bm == 0: mul = pow(2,num,mod) if k==bad_ab: mul = num+1 else: mul = pow(2,num,mod) + pow(2,bm,mod) -1 ans*=mul ans+=zerozero ans-=1 print(ans%mod)
1
20,856,301,908,570
null
146
146
#!/usr/bin/env python3 # -*- coding: utf-8 -*- R = int(input()) print(R * R)
from sys import stdin r = int(stdin.readline()) if r < 1: print(0) else: circle = r * r print(circle)
1
145,326,212,423,900
null
278
278
n,m = map(int,input().split()) ans="No" if n==m : ans="Yes" print(ans)
A = raw_input().split() S = [] for x in A: if x in ['+', '-', '*']: b = int(S.pop()) a = int(S.pop()) if x == '+': S.append(a + b) elif x == '-': S.append(a - b) else: S.append(a * b) else: S.append(x) print S.pop()
0
null
41,886,765,383,398
231
18
while True: s = input() if s == "-": exit() m = int(input()) for i in range(m): h = int(input()) s = s[h:] + s[:h] print(s)
import copy h, w = map(int,input().split()) maze = [[9]*(w+2)] for i in range(h): s = input() tmp = [9] for j in s: if j == "#": tmp.append(9) else: tmp.append(0) tmp.append(9) maze.append(tmp) maze.append([9]*(w+2)) #print(maze) def bfs(start): maze2 = copy.deepcopy(maze) #print(maze2) pos = [start] max_depth = 0 maze2[start[0]][start[1]] = 2 while len(pos): x, y, depth = pos.pop(0) max_depth = max(depth, max_depth) if maze2[x-1][y] < 2: pos.append([x-1,y,depth + 1]) maze2[x-1][y] = 2 if maze2[x+1][y] < 2: pos.append([x+1,y,depth + 1]) maze2[x+1][y] = 2 if maze2[x][y-1] < 2: pos.append([x,y-1,depth +1]) maze2[x][y-1] = 2 if maze2[x][y+1] < 2: pos.append([x,y+1,depth +1]) maze2[x][y+1] = 2 return max_depth ans = 0 for i in range(h): for j in range(w): start = [i+1,j+1,0] maze2 = maze if maze[i+1][j+1] != 9: #print(bfs(start)) ans = max(ans,bfs(start)) print(ans)
0
null
48,219,114,109,600
66
241
import sys for l in sys.stdin: H, W = map(int,l.split()) if H == 0 and W == 0: break for i,h in enumerate(range(H)): if i % 2 == 0: print (('#.' * (int(W/2)+1))[:W]) else: print(('.#' * (int(W/2)+1))[:W]) print ('')
import sys while(1): H, W = map(int, raw_input().split()) if(H == 0 and W == 0): break else: for i in range(H): for j in range(W): if(i%2==0 and j%2==0): sys.stdout.write("#") elif(i%2==0 and j%2==1): sys.stdout.write(".") elif(i%2==1 and j%2==0): sys.stdout.write(".") else: sys.stdout.write("#") print print
1
875,041,535,340
null
51
51
import math , sys N , M = list(map( int, input().split() )) cor = 0 pen = 0 F = [False]*N C = [0]*N for i in range(M): A , B = list( input().split() ) A = int(A)-1 if B == "WA" and not F[A]: C[A]+=1 #print(C) if B == "AC" and not F[A]: F[A] = True cor += 1 pen +=C[A] print(cor,pen)
N,K = map(int,input().split()) li = [] count = 0 for i in range(K): d = int(input()) a = list(map(int,input().split())) for j in range(d): li.append(a[j]) for i in range(N): if i+1 not in li: count += 1 print(count)
0
null
58,835,975,613,858
240
154
n, *AB = map(int, open(0).read().split()) a = sorted(AB[::2]) b = sorted(AB[1::2]) if n % 2 == 0: print(b[n // 2 - 1] + b[n // 2] - a[n // 2 - 1] - a[n // 2] + 1) else: print(b[(n + 1) // 2 - 1] - a[(n + 1) // 2 - 1] + 1)
import math n,d = map(int,input().split()) x = [list(map(int,input().split()))for _ in range(n)] ans = 0 for i in range(n): r = math.sqrt(x[i][0]**2+x[i][1]**2) if r <= d: ans += 1 print(ans)
0
null
11,611,954,384,380
137
96
N,K=map(int, input().split()) a_ls=list(map(int, input().split())) j=1 step=0 s=set([]) l=[] loop_s=-1 loop_g=-1 while True: s.add(j) l+=[j] j=a_ls[j-1] #update if j in s: loop_s=l.index(j) loop_g=len(l) break #print(l) #print(loop_s) #print(loop_g) if K<loop_s: print(l[K]) elif (K+1-loop_s)%(loop_g-loop_s)!=0: print(l[loop_s+(K+1-loop_s)%(loop_g-loop_s)-1]) else: print(l[-1])
from bisect import * N, D, A = map(int, input().split()) data = [] for _ in range(N): x, h = map(int, input().split()) data.append((x,h)) data.sort() X = [] H = [] for x, h in data: X.append(x) H.append(h) Imos = [0]*(N+1) cnt = 0 damage = 0 res = 0 for i in range(N): damage -= Imos[i]*A h = H[i] - damage x = X[i] if h > 0: cnt = h//A + (h%A!=0) p = min(bisect_right(X, x+2*D)-1, N-1) Imos[p+1] += cnt damage = damage + cnt * A res += cnt print(res)
0
null
52,449,879,035,792
150
230
n = int(input()) s = [input() for i in range(n)] c0 = 0 c1 = 0 c2 = 0 c3 = 0 for i in range(len(s)): if s[i] == "AC": c0 += 1 elif s[i] == "WA": c1 += 1 elif s[i] == "TLE": c2 += 1 else: c3 += 1 print("AC x ", str(c0)) print("WA x ", str(c1)) print("TLE x ", str(c2)) print("RE x ", str(c3))
def main(): def trial_division(n): divs = set() for i in range(1, int(n**0.5)+1): if n % i == 0: divs.add(i) if i != n//i: divs.add(n//i) return divs def gcd(x, y): if y == 0: return x while y != 0: x, y = y, x % y return x N = int(input()) ans = 0 divs = trial_division(N) | trial_division(N-1) for d in divs: if d == 1: continue num = N while num % d == 0 and d <= num: num //= d if num % d == 1: ans += 1 print(ans) if __name__ == '__main__': main()
0
null
25,038,991,944,992
109
183
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, T, *AB = map(int, read().split()) A = AB[::2] B = AB[1::2] dp1 = [[0] * T for _ in range(N + 1)] for i in range(N): for t in range(T): if 0 <= t - A[i]: dp1[i + 1][t] = dp1[i][t - A[i]] + B[i] if dp1[i + 1][t] < dp1[i][t]: dp1[i + 1][t] = dp1[i][t] dp2 = [[0] * T for _ in range(N + 1)] for i in range(N - 1, -1, -1): for t in range(T): if 0 <= t - A[i]: dp2[i][t] = dp2[i + 1][t - A[i]] + B[i] if dp2[i][t] < dp2[i + 1][t]: dp2[i][t] = dp2[i + 1][t] ans = 0 for i in range(N): tmp = max(dp1[i][t] + dp2[i + 1][T - t - 1] for t in range(T)) + B[i] if ans < tmp: ans = tmp print(ans) return if __name__ == '__main__': main()
class UnionFind: def __init__(self, sz: int): self._par: list[int] = [-1] * sz def root(self, a: int): if self._par[a] < 0: return a self._par[a] = self.root(self._par[a]) return self._par[a] def size(self, a: int): return -self._par[self.root(a)] def unite(self, a, b): a = self.root(a) b = self.root(b) if a != b: if self.size(a) < self.size(b): a, b = b, a self._par[a] += self._par[b] self._par[b] = a if __name__ == '__main__': N, M = map(int, input().split()) uf = UnionFind(N + 1) for i in range(M): a, b = map(int, input().split()) uf.unite(a, b) ans = 1 for i in range(1, N + 1): ans = max(ans, uf.size(i)) print(ans)
0
null
78,002,736,612,570
282
84
while 1: m,f,r=map(int,input().split());s=m+f if m==f==r==-1:break if m==-1 or f==-1 or s<30:print('F') elif s>79:print('A') elif s>64:print('B') elif s>49 or r>49:print('C') else:print('D')
while 1: m,f,r=map(int, raw_input().split()) if m==f==r==-1: break s=m+f if m==-1 or f==-1 or s<30: R="F" elif s>=80: R="A" elif s>=65: R="B" elif s>=50: R="C" elif r>=50: R="C" else: R="D" print R
1
1,252,247,330,180
null
57
57
a=1 b=1 c=[] n=int(input()) c.append(a) c.append(b) for i in range(n): c.append(a+b) d=b b+=a a=d print(c[n])
n = int(input()) a = [0] * (n + 1) for i in range(1, n + 1): if i*i > n: break for j in range(1, n + 1): z = i*i + j*j + i*j if z > n: break for k in range(1, n + 1): if (z + k * k + k*i + k * j) > n: break a[z + k * k + k*i + k * j] += 1 for i in a[1:]: print(i)
0
null
4,049,311,967,932
7
106
n, x, t = map(int, input().split()) ans = t *(n // x) if n%x == 0: print(ans) else: print(ans + t)
line = input() N, X, T = (int(x) for x in line.split(" ")) print((N + X - 1) // X * T)
1
4,275,639,809,268
null
86
86
for i in sorted([input() for _ in xrange(10)])[:-4:-1]: print i
A = [int(input()) for i in range(10)] for i in sorted(A)[:-4:-1]: print(i)
1
21,772,960
null
2
2
from functools import lru_cache import math def main(): n=int(input()) a=list(map(int,input().split())) x=set() y=a[0] pair=True for i in a: if pair: p=set(prime_factorize(i)) if len(x&p)>0: pair=False x|=p y=math.gcd(y, i) if pair: print("pairwise coprime") elif y==1: print("setwise coprime") else: print("not coprime") # 素数リスト(エラトステネスの篩) @lru_cache(maxsize=None) def primes(n:int) -> list: '''n以下の全素数をlistで返す''' is_prime = [True] * (n + 1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, n + 1, i): is_prime[j] = False return [i for i in range(n + 1) if is_prime[i]] # 素数判定(単純な素数判定なら十分早い。大量にやる場合はX in primesがよさそう) @lru_cache(maxsize=None) def is_prime(n: int) -> bool: '''引数nが素数であればTrue、そうでなければFalseを返す''' if n == 1: return False elif n == 2: return True elif n % 2 == 0: return False for i in range(3, int(n**0.5)+1, 2): if n % i == 0: return False return True # 素因数分解 def prime_factorize(n: int) -> list: '''引数nの素因数分解結果のlistを返す。''' arr = [] # 2で割り続け奇数まで還元する while n % 2 == 0: arr.append(2) n //= 2 # sqrt(n)までの素数で試し割 for f in primes(int(n**0.5)): while n % f == 0: arr.append(f) n //= f if n != 1: arr.append(n) return arr if __name__ == "__main__": main()
n = list(map(int, input())) dp = (0, 1) for i in n: dp = (min(dp[0] + i, dp[1] + 10 - i), min(dp[0] + i + 1, dp[1] + 9 - i)) print(dp[0])
0
null
37,310,186,495,050
85
219
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') elif x-r>=0 and x+r<=W and y-r>=0 and y+r<=H: print('Yes')
# -*- coding: UTF-8 -*- lst = [int(raw_input()) for i in range(10)] lst.sort() lst.reverse() print lst[0] print lst[1] print lst[2]
0
null
222,996,790,290
41
2
floor = [[[0] * 10 for x in range(3)] for y in range(4)] for c in range(int(input())): (b,f,r,v) = [int(x) for x in input().split()] floor[b-1][f-1][r-1] += v for x in range(3 * 4): if x % 3 == 0 and not x == 0: print('#' * 20) print('',' '.join(str(y) for y in floor[int(x / 3)][x % 3]))
build = range(1, 5) floor = range(1, 4) dic = {b: {f: [0]*10 for f in floor} for b in build} n = input() for i in range(n): info = map(int, raw_input().split()) dic[info[0]][info[1]][info[2]-1] += info[3] if dic[info[0]][info[1]][info[2]-1] > 9: print 'error' for b in build: for f in floor: print '', print ' '.join(map(str, dic[b][f])) if b != 4: print "#"*20
1
1,073,153,185,388
null
55
55
import sys n, truck_num = map(int, input().split()) weights = [int(x) for x in map(int, sys.stdin)] def main(): # 最小値と最大値をもとに二分探索する print(binary_search(max(weights), sum(weights))) def binary_search(left, right): """二分探索 :param left: 最小値 :param right: 最大値 :return: """ while left < right: # 真ん中の値を割り当てる middle = (left + right) // 2 # 真ん中の値で一旦シミュレート if simulate(middle, weights, truck_num): # OKならば、最大値をシミュレートした値に right = middle else: # NGならば、最小値をシミュレートした+1に left = middle + 1 return left def simulate(mid, wei, t_num): """ :param mid: 中央値 :param wei: 荷物が格納されたリスト :param t_num: トラックの台数 :return: シミュレートOKかNGか """ count = 1 tmp = 0 for w in wei: tmp += w # 積載量(tmp)が求める答え(mid)より大きくなったら if mid < tmp: # tmpを次の積載物に初期化 tmp = w count += 1 if t_num < count: return False return True if __name__ == '__main__': main()
import statistics while True: n = int(input()) if n == 0: break str = input().split() list = [] for i in range(n): list.append(int(str[i])) print(statistics.pstdev(list))
0
null
140,847,189,110
24
31
h = int(input()) p = 1 i = 1 while h > 1: h = h // 2 p += 2 ** i i += 1 print(p)
n = int(input()) a = list(map(int, input().split())) cnt = 0 ave = sum(a)/2 for i in range(n): cnt += a[i] if cnt >= ave: ans = min(cnt*2-ave*2, ave*2-(cnt-a[i])*2) break print(int(ans))
0
null
111,288,200,733,730
228
276
H,W,M=map(int,input().split()) #二次元リストではなく列行を一個のボムで消してくれるためそれぞれのリストを用意。 sumh = [0] * H sumw = [0] * W bomb=[] for i in range(M): h,w=map(int,input().split()) sumh[h-1]+=1 sumw[w-1]+=1 bomb.append((h,w)) #爆弾の個数の最大値とその最大値がいくつずつあるか(ch,cw)に保存。最大の列と最大の行のいずれかの組み合わせに置くことで爆破数を最大化できる。 maxh=max(sumh) maxw=max(sumw) ch=sumh.count(maxh) cw=sumw.count(maxw) #print(maxh,maxw,ch,cw) #爆弾のある場所がH,Wの座標で両方共で最大個数の場所であった場合その数を加算 count=0 for h,w in bomb: if sumh[h-1]==maxh and sumw[w-1]==maxw: count+=1 #print(count) #破壊できる数は、そのマスに爆破対象があるとき一つ減ってしまう。 if count==ch*cw: print(maxh+maxw-1) else: print(maxh+maxw)
def solve(h, w, m, hw_list): h_count = [0] * (h + 1) w_count = [0] * (w + 1) for h_, w_ in hw_list: h_count[h_] += 1 w_count[w_] += 1 h_max = max(h_count) w_max = max(w_count) res = h_max + w_max h_max_count = 0 w_max_count = 0 for i in range(h + 1): if h_count[i] == h_max: h_max_count += 1 for j in range(w + 1): if w_count[j] == w_max: w_max_count += 1 max_count = h_max_count * w_max_count max_count_cross = 0 for h_, w_ in hw_list: if h_count[h_] == h_max and w_count[w_] == w_max: max_count_cross += 1 if max_count_cross == max_count: return res - 1 else: return res def main(): h, w, m = map(int, input().split()) hw_list = [] for _ in range(m): hw_list.append(list(map(int, input().split()))) res = solve(h, w, m, hw_list) print(res) def test(): assert solve(2, 3, 3, [[2, 2], [1, 1], [1, 3]]) == 3 assert solve(3, 3, 4, [[3, 3], [3, 1], [1, 1], [1, 2]]) == 3 assert solve(5, 5, 10, [[2, 5], [4, 3], [2, 3], [5, 5], [2, 2], [5, 4], [5, 3], [5, 1], [3, 5], [1, 4]]) == 6 if __name__ == "__main__": test() main()
1
4,666,648,515,008
null
89
89
H,W,K=map(int, input().split()) S=[input()for _ in range(H)] A=[[0]*W for _ in range(H)] c=0 for i in range(H): d=0 for j in range(W): if S[i][j]=="#": c+=1 d=c A[i][j]=d p=0 for j in range(W-1,-1,-1): if A[i][j]==0: A[i][j]=p p=A[i][j] if S[i].find("#")<0 and i!=0: A[i][:]=A[i-1] for i in range(H-2,-1,-1): if all(a==0 for a in A[i]): A[i][:]=A[i+1] for i in range(H): print(*A[i])
N, K = [int(v) for v in input().split()] S = [0] * N for _ in range(K): snack = int(input()) snukes = [int(v) for v in input().split()] for snuke in snukes: S[snuke-1] = 1 print(sum(x == 0 for x in S))
0
null
84,068,379,749,858
277
154
n,a,b = map(int, input().split()) m1 = n // (a + b) m2 = n % (a + b) if a ==0: print(0) elif a >= n: print(n) elif a + b >n: print(a) else: if m2 >= a: print((m1 + 1) * a ) else: print(m1 * a + m2)
N=int(input()) S=list(map(str,input())) ans=1 for i in range(N-1): if S[i]!=S[i+1]: ans+=1 print(ans)
0
null
112,964,009,046,240
202
293
K = int(input()) A, B = map(int, input().split()) cnt = 0 while 1: cnt+=K if A <= cnt <= B: print("OK") break if B < cnt: print("NG") break
n=int(input()) p=list(map(int,input().split())) min_t=10**6 cnt=0 for i in range(n): if min_t>=p[i]: cnt+=1 min_t=min(min_t,p[i]) print(cnt)
0
null
55,822,090,048,352
158
233
n = int(input()) E = [[]]*n for i in range(n): inputs = list(map(int, input().split())) if inputs[1]==0: continue else: for j in inputs[2:]: E[i] = E[i] + [j-1] beg = [-1]*n fin = [-1]*n t = 0 def f(i): global t #print(i,t) t += 1 beg[i] = t for c in E[i]: if beg[c]>0: continue else: f(c) t+=1 fin[i] = t for i in range(n): if beg[i]<0: f(i) for i in range(n): print(i+1, beg[i], fin[i])
from collections import Counter,defaultdict,deque from heapq import heappop,heappush from bisect import bisect_left,bisect_right import sys,math,itertools,fractions sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) s = input() n = len(s) K = inp() dp = [[[0 for i in range(5)] for j in range(2)] for k in range(n+1)] # dp[i][j][k] j:0 kaku j:1 mikaku , k:kosuu dp[0][1][0] = 1 for i,x in enumerate(s): x = int(x) for k in range(4): dp[i+1][0][k] += dp[i][0][k] dp[i+1][0][k+1] += dp[i][0][k]*9 + dp[i][1][k]*max(0,(x-1)) if x != 0: dp[i+1][0][k] += dp[i][1][k] dp[i+1][1][k+1] = dp[i][1][k] if k == 0: dp[i+1][1][k] = 0 else: dp[i+1][1][k] = dp[i][1][k] for j in range(2): dp[i+1][j][k] %= mod # print(dp[i+1][0]) # print(dp[i+1][1]) # print() print(dp[-1][0][K] + dp[-1][1][K])
0
null
38,056,838,081,890
8
224
import sys input = sys.stdin.readline def log(*args): print(*args, file=sys.stderr) def main(): n = int(input().rstrip()) ans = [0 for _ in range(n)] for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): tmp = pow(x, 2) + pow(y, 2) + pow(z, 2) + x * y + y * z + z * x if tmp > n: break # if x == y == z: # ans[tmp - 1] = 1 # elif x == y or y == z or z == x: # ans[tmp - 1] = 3 # else: # ans[tmp - 1] = 6 ans[tmp - 1] += 1 for v in ans: print(v) if __name__ == '__main__': main()
import copy N = int(input()) A = input().split() B = copy.copy(A) boo = 1 while boo: boo = 0 for i in range(N-1): if A[i][1] > A[i+1][1]: A[i], A[i+1] = A[i+1], A[i] boo = 1 print(*A) print("Stable") for i in range(N): mi = i for j in range(i,N): if B[mi][1] > B[j][1]: mi = j B[i], B[mi] = B[mi], B[i] if A==B: print(*B) print("Stable") else: print(*B) print("Not stable")
0
null
3,953,762,767,640
106
16
n=int(input()) import heapq q=[] for i in range(n): x,l=map(int,input().split()) heapq.heappush(q,(x+l,l)) largest=-float('inf') c=0 while q: a,l=heapq.heappop(q) if largest<=a-2*l: largest=a c+=1 print(c)
n = int(input()) x = list(map(int, input().split())) y = list(map(int, input().split())) d = [abs(x[i] - y[i]) for i in range(n)] for i in range(1,4): print('{0:f}'.format(sum(j ** i for j in d) ** (1 / i))) print('{0:f}'.format(max(d)))
0
null
45,287,970,045,500
237
32
N,K = map(int,input().split()) sunuke = [0]*(N+1) for i in range(K): okashi_category = input() #print (okashi_category) if okashi_category ==1: sunuke[input()]=1 else: sunukelist = list(map(int,input().split())) for j in range(len(sunukelist)): #print(sunukelist[j]) sunuke[sunukelist[j]]=1 print (N-sum(sunuke))
N, K = (int(x) for x in input().split()) check=[False]*N ans=N for i in range(K): d=int(input()) A=list(map(int, input().split())) for j in range(d): if check[A[j]-1]==False: ans-=1 check[A[j]-1]=True print(ans)
1
24,651,355,917,718
null
154
154
x = int(input()) if x >= 30: a = "Yes" else: a = "No" print(a)
X = int(input()) print('Yes' if X >= 30 else 'No')
1
5,715,699,817,468
null
95
95
import math import sys sys.setrecursionlimit(10**9) def comb(n, r): # 普通のcombination計算 if r < 0 or r > n: return 0 else: n1 = math.factorial(n) n21 = math.factorial(n - r) n22 = math.factorial(r) ans = n1 // (n21 * n22) return ans """ solve(i, k, smaller) := i桁目以降について、0以外の値を残りk個使用可能という状況を考える。 このときi桁目までの部分が「等しい」か「strictに小さくなっている」かを smallerフラグによって分岐する。 """ def solve(i, k, smaller): # 再帰 # print(i, k, smaller) if i == N: if k == 0: return 1 else: return 0 if k == 0: return 1 if smaller == True: return comb(N - i, k) * pow(9, k) else: if S[i] == "0": return solve(i + 1, k, False) else: """ ex. S = 314159 の場合 000000〜099999 := a 100000〜299999 := b 300000〜314159 := c のように場合分け """ a = solve(i + 1, k, True) b = solve(i + 1, k - 1, True) * (int(S[i]) - 1) c = solve(i + 1, k - 1, False) return a + b + c # 問題文ではNだが、文字列として扱うのでSと名付ける S = input() # Sの桁数、問題文のNとは違う N = len(S) K = int(input()) ans = solve(0, K, False) print(ans)
cnt = 0 n = int(raw_input()) A = [int(raw_input()) for _ in range(n)] G = [1] if n < 5 else [1, 4] while G[-1]*3+1 <= n/5: G.append(G[-1]*3+1) G.reverse() def insersionSort(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(): for g in G: insersionSort(g) shellSort() print len(G) print " ".join(map(str, G)) print cnt print "\n".join(map(str, A))
0
null
37,745,662,756,802
224
17
h, n = map(int,input().split()) a = list(map(int,input().split())) atack = sum(a) can = h <= atack print("Yes" if can else "No")
def atc_153b(a: str, b: str) -> str: HN = a.split(" ") H = int(HN[0]) N = int(HN[1]) A = b.split(" ") A_int = [int(ai) for ai in A] damage = sum(A_int) if (H - damage) <= 0: return "Yes" else: return "No" a = input() b = input() print(atc_153b(a, b))
1
77,754,581,324,840
null
226
226
s = input() if len(s)%2!=0: print("No") else: if s.count("hi") == len(s)//2: print("Yes") else: print("No")
import copy class Dice: def __init__(self, eyes: [int]): self.__eyes = eyes def top(self): return self.__eyes[0] def roll_s(self): tmp = copy.copy(self.__eyes) tmp[0] = self.__eyes[4] tmp[1] = self.__eyes[0] tmp[2] = self.__eyes[2] tmp[3] = self.__eyes[3] tmp[4] = self.__eyes[5] tmp[5] = self.__eyes[1] self.__eyes = tmp def roll_e(self): tmp = copy.copy(self.__eyes) tmp[0] = self.__eyes[3] tmp[1] = self.__eyes[1] tmp[2] = self.__eyes[0] tmp[3] = self.__eyes[5] tmp[4] = self.__eyes[4] tmp[5] = self.__eyes[2] self.__eyes = tmp def roll_n(self): tmp = copy.copy(self.__eyes) tmp[0] = self.__eyes[1] tmp[1] = self.__eyes[5] tmp[2] = self.__eyes[2] tmp[3] = self.__eyes[3] tmp[4] = self.__eyes[0] tmp[5] = self.__eyes[4] self.__eyes = tmp def roll_w(self): tmp = copy.copy(self.__eyes) tmp[0] = self.__eyes[2] tmp[1] = self.__eyes[1] tmp[2] = self.__eyes[5] tmp[3] = self.__eyes[0] tmp[4] = self.__eyes[4] tmp[5] = self.__eyes[3] self.__eyes = tmp def roll(self, direction: str): if direction == 'N': self.roll_n() if direction == 'E': self.roll_e() if direction == 'S': self.roll_s() if direction == 'W': self.roll_w() def resolve(): eyes = list(map(int, input().split())) directions = list(input()) dice = Dice(eyes) for direction in directions: dice.roll(direction) print(dice.top()) resolve()
0
null
26,776,866,080,202
199
33
#!/usr/bin/env python3 def main(): N, K = map(int, input().split()) H = sorted([int(x) for x in input().split()]) if K == 0: print(sum(H)) elif N > K: print(sum(H[:-K])) else: print(0) if __name__ == '__main__': main()
N,K = map(int,input().split()) H = list(map(int,input().split())) H.sort() reversed(H) for i in range(K): if len(H)==0: break else: H.pop() if len(H)==0: print(0) else: print(sum(H))
1
79,074,439,697,198
null
227
227
N = list(input()) l = len(N) if N[l-1] == '2' or N[l-1] == '4' or N[l-1] == '5' or N[l-1] == '7' or N[l-1] == '9': print('hon') elif N[l-1] == '0' or N[l-1] == '1' or N[l-1] == '6' or N[l-1] == '8': print('pon') elif N[l-1] == '3': print('bon')
N = int(input()) Assertions = [] ansnum = 0 for i in range(N): b = [] n = int(input()) for j in range(n): xi,yi = map(int,input().split()) b.append([xi-1,yi]) Assertions.append(b) for i in range(2**N): select = [] ans = [0 for _ in range(N)] index = [] flag = True for j in range(N): if ((i >> j) & 1): select.append(Assertions[j]) index.append(j) ans[j] = 1 for idx in index: for Assert in Assertions[idx]: if ans[Assert[0]] != Assert[1]: flag = False break if flag: ansnum = max(ansnum,len(index)) print(ansnum)
0
null
70,631,990,395,418
142
262
h,w,k=map(int,input().split()) s=[input() for _ in range(h)] ans=[] c=1 for si in s: ans.append([c]*w) c+=si.count('#') ans.append([c]*w) p=0 q=1 while q<=h: if ans[q][0]-ans[p][0]>=1: c=ans[p][0] for j in range(w): for i in range(p,q): ans[i][j]=c if s[i][j]=='#': c=min(c+1,ans[q][0]-1) p=q if ans[q-1][-1]==k: while q<h: ans[q]=ans[q-1] q+=1 q+=1 for a in ans[:-1]: print(*a)
N = int(input()) memo = [-1]*500 def fibo(x): if memo[x] != -1: return memo[x] if x == 0 or x == 1: ans=1 memo[x] = ans return ans ans = fibo(x-1) + fibo(x-2) memo[x] = ans return ans print(fibo(N))
0
null
71,872,917,839,870
277
7
def resolve(): N, K = map(int, input().split()) H = list(map(int, input().split())) h = sorted(H)[::-1] ans = h[K:] print(sum(ans)) resolve()
O = ['Yes','No'] S = str(input()) f = 0 if S == 'AAA' or S == 'BBB': f = 1 print(O[f])
0
null
67,282,082,406,770
227
201
from collections import defaultdict N = int(input()) A = [int(i) for i in input().split()] ans = 0 d = defaultdict(int) cur = N for a in A[::-1]: ans += d[cur + a] if cur - a > 0: d[cur - a] += 1 cur -= 1 print(ans)
A,B,M = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) X = [] Y = [] C = [] for _ in range(M): x,y,c = map(int,input().split()) X.append(x) Y.append(y) C.append(c) ans = min(a) + min(b) for i in range(M): ans = min(ans,a[X[i]-1] + b[Y[i] - 1] - C[i]) print(ans)
0
null
40,078,483,238,752
157
200
import sys, bisect, math, itertools, string, queue, copy import numpy as np import scipy from collections import Counter,defaultdict,deque from itertools import permutations, combinations from heapq import heappop, heappush from fractions import gcd input = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9+7 def inp(): return int(input()) def inpm(): return map(int,input().split()) def inpl(): return list(map(int, input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(input()) for _ in range(n)) def inplL(n): return [list(input()) for _ in range(n)] def inplT(n): return [tuple(input()) for _ in range(n)] def inpll(n): return [list(map(int, input().split())) for _ in range(n)] def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) n,m,q = inpm() ans = 0 abcd = [] for _ in range(q): a,b,c,d = inpm() abcd.append((a,b,c,d)) for e in itertools.combinations_with_replacement(range(m),n): cnt = 0 for i in range(q): [a,b,c,d] = abcd[i] if e[b-1] - e[a-1] == c: cnt += d ans = max(ans,cnt) print(ans)
from math import log2 N = int(input()) log = int(log2(N)+1) ans = (2**log-1) print(ans)
0
null
53,734,254,017,540
160
228
#!/usr/bin/env python3 import sys import collections as cl def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def main(): x, y, a, b, c = MI() p = LI() q = LI() r = LI() p.sort(reverse=True) q.sort(reverse=True) r.sort(reverse=True) p_selected = p[:x] q_selected = q[:y] ans = [*p_selected, *q_selected] ans.sort() i = 0 while i < x + y and i < c and ans[i] < r[i]: ans[i] = r[i] i += 1 print(sum(ans)) main()
N, M = map(int, input().split()) H = list(map(int, input().split())) H.insert(0, 0) t = [True] * (N+1) for i in range(M): a, b = map(int, input().split()) if H[a] <= H[b]: t[a] = False if H[b] <= H[a]: t[b] = False c = 0 for i in range(1, N+1, 1): if t[i]: c += 1 print(c)
0
null
34,985,068,160,068
188
155
s = input() n = len(s) kotae = "x"*n print(kotae)
s = input() l = len(s) ss = "" for x in range(l): ss = ss+'x' print(ss)
1
72,545,817,507,140
null
221
221
import math N = int(input()) x = [] y = [] for i in range(N): tmp = input().split(" ") x.append(int(tmp[0])) y.append(int(tmp[1])) d = 0 for i in range(N): for j in range(N): d += math.sqrt((x[j]-x[i]) ** 2 + (y[j]-y[i]) ** 2) print(d/N)
# A Lucky 7 N = input() for n in N: if n == "7": print("Yes") exit() else: print("No")
0
null
91,348,685,209,628
280
172
while True: l = input().split() h = int(l[0]) w = int(l[1]) if h == 0 and w == 0: break element = h*(w+1) for i in range(element): if (i+1)%(w+1) == 0: print("") if i == element-1: print("") elif i+1 < w or i+1 > element-w-1: print("#", end="") else: if (i+1)%(w+1) == 1 or (i+1)%(w+1) == w: print("#", end="") else: print(".", end="")
while True: H,W = map(int,input().split()) if H == 0 and W == 0: break for i in range(H): for k in range(W): if i == 0 or i == H-1 or k == 0 or k == W-1: print("#",end = "") else: print(".",end = "") print() print()
1
823,499,561,728
null
50
50
def main(): a = int(input()) print(a + a*a + a*a*a) if __name__ == "__main__": main()
user_input = int(input()) print(user_input + user_input**2 + user_input**3)
1
10,179,648,644,242
null
115
115
N = int(input()) arr = list(map(int, input().split())) s = 0 for i in range(N): s ^= arr[i] for i in range(N): arr[i] ^= s print(' '.join(map(str, arr)))
import math x1, y1, x2, y2 = map(float, input().split()) line = (x2 - x1) ** 2 + (y2 - y1) ** 2 line = math.sqrt(line) print(line)
0
null
6,390,149,176,300
123
29
import math N = int(input()) A = list(map(int,input().split())) B = [0] * (N) lcmall = A[0] for i in range(1,N): gcdall = math.gcd(lcmall,A[i]) lcmall = lcmall*A[i] // gcdall sum = 0 for i in range(N): B[i] =int(lcmall // A[i]) sum += B[i] print(sum % (10 ** 9 + 7))
# import sys from fractions import gcd input=sys.stdin.readline def main(): MOD=10**9+7 N=int(input()) A=list(map(int,input().split())) if N==1: print(1) exit() l=(A[0]*A[1])//gcd(A[0],A[1]) for i in range(2,N): l=(l*A[i])//gcd(A[i],l-A[i]) l%=MOD ans=0 for i in range(N): ans+=l*pow(A[i],MOD-2,MOD) ans%=MOD print(ans) if __name__=="__main__": main()
1
87,701,742,797,970
null
235
235
n=int(input()) t = [[0 for _ in range(10)] for _ in range(10)] for i in range(1,n+1):t[int(str(i)[0])][int(str(i)[-1])]+=1 g=0 for i in range(1,10): for j in range(1,10): g+=t[i][j]*t[j][i] print(g)
N = int(input()) li = [[0]*9 for i in range(9)] counter = 0 for i in range(1,N+1): I = str(i) fast = int(I[0]) last = int(I[-1]) if not last==0: li[fast-1][last-1] += 1 for i in range(9): for k in range(9): counter += li[i][k]*li[k][i] print(counter)
1
86,620,733,306,208
null
234
234
N = input() print("Yes" if "7" in N else "No")
n = input() for s in n: if s == '7':exit(print('Yes')) print('No')
1
34,084,143,872,700
null
172
172
x1, y1, x2, y2 = map(float, input().split()) print(abs(complex(x1-x2, y1-y2)))
import math as mt x = list(map(float,input().split())) a = ((x[0]-x[2])**2)+((x[1]-x[3])**2) print(mt.sqrt(a))
1
158,607,881,808
null
29
29
k = int(input()) s = input() if len(s)>k: print('{}...'.format(s[:k])) else: print(s)
n = int(input()) s = input() print(s if len(s) <= n else s[:n] + '...')
1
19,678,374,143,648
null
143
143