id
stringlengths
6
117
description
stringlengths
29
13k
code
stringlengths
9
465k
language
class label
4 classes
test_samples
dict
source
class label
5 classes
class-homework_500
Ramesh and Suresh were in the same class and got home work from their mathematics teacher. The Homework consists of N strings and each string consists of only digits. The task which they need to perform is that they need to divide the string into 4 integers such that their sum is maximum. Note: Each integer should be...
T=input() best=-1 bound=10**12 boundS=str(bound) def findBest(s,off,n,sofar): #print "looking for best fo",s[off:],n remain=len(s)-off if remain<n: return global best if n==1: if remain>13: return if s[off]=="0": if len(s)-off>1: return if remain==13 and s[off:]!=boundS: return val=sofar+int(s[...
1Python2
{ "input": [ "3\n4251\n52310\n00006\n\nSAMPLE", "100\n04\n9\n02163\n003000\n08041479\n80750340926070052\n90056\n11680\n90\n09020809009020989\n00460224000800\n0606\n6402000040\n3918080\n31052060072050\n41\n00070775690\n8000780240500799004\n66\n040934020028\n00241600300023700065\n3\n09964639222895002000\n290300...
3HACKEREARTH
even-from-end-1_501
Problem Description Given a list of integers, find and display all even numbers from the end of the list. Input Format Each line of input begins with an integer N indicating the number of integer n that follow which comprises a list. Output Format All even numbers from the end of the list, each separated by a sin...
while True: try: s = raw_input() except: break if len(s.rstrip().lstrip())==0: break ser = map(int, s.split()) srr = ser[1:][::-1] found = False for x in srr: if x % 2 == 0: found = True print x, if not found: ...
1Python2
{ "input": [ "5 10 25 12 4 1 \n3 16 28 100\n\nSAMPLE", "21 3 -3 3 -3 3 -3 19 3 -3 3 -3 3 -3 19 3 -3 3 -3 3 -3 19", "2 8 -100\n5 -1000 5 1000 500 250\n10 -1000 5 1000 500 250 -1000 5 1000 500 250\n7 3 -3 3 -3 3 -3 19\n5 44 7 11 -999 20", "5 10 25 12 4 1 \n3 16 28 100" ], "output": [ "4 12 10 \n...
3HACKEREARTH
hermione-vs-draco_502
Draco Malfoy and Hermione Granger have gotten into a "battle of brains". Draco was foolish enough to challenge her to a Arithmancy problem. Septima Vector, Arithmancy teacher at Hogwarts, has agreed to give them both a problem which they should solve overnight. The problem is as follows :- Firstly, a function F (fro...
t=int(raw_input()) def z(x): i=5 c=0 while x/i>=1: c+=n/i i*=5 return c for i in range(t): n=int(raw_input()) print z(n)
1Python2
{ "input": [ "6\n3\n60\n100\n1024\n23456\n8735373\n\nSAMPLE", "6\n3\n60\n100\n1024\n23456\n8735373\n\nELPMAS", "6\n5\n60\n100\n1024\n23456\n8735373\n\nELPMAS", "6\n5\n21\n100\n1024\n23456\n8735373\n\nELPMAS", "6\n4\n21\n100\n1024\n23456\n8735373\n\nEMPMAS", "6\n4\n21\n100\n1024\n17256\n8735373...
3HACKEREARTH
magic-gcd_503
Given 2 numbers n1 and n2, following operations can be performed: 1) Decrement n1 by 1(if n1>1) 2) Decrement n2 by 1(if n2>1) 3) Incremenet n1 by 1 4) Incremenet n2 by 1 Find the maximum possible value of gcd(n1,n2) with atmost k operations. Note: Any of the 4 operations counts for one operation. gcd(n1,n2) refers to G...
t=input() from fractions import gcd for x in range(t): n1=input() n2=input() k=input() ans=0 for i in range(-k, k+1): if i+n1<1: continue absi=abs(i) for j in range(-k+absi, k-absi+1): if j+n2<1: continue y=gcd(n1+i, n2+j) if y>ans: ans=y print ans
1Python2
{ "input": [ "1\n9\n10\n1\n\nSAMPLE", "4\n14723\n5512\n100\n28436\n33903\n100\n84816\n75747\n100\n92281\n31380\n100", "1\n45819\n95605\n83", "4\n11833\n5512\n100\n28436\n33903\n100\n84816\n75747\n100\n92281\n31380\n100", "1\n45819\n95605\n90", "1\n9\n10\n1\n\nSANPLE", "1\n45819\n95605\n136...
3HACKEREARTH
new-world-11_504
The time has arrived when the world is going to end. But don't worry, because the new world yuga will start soon. Manu (carrier of mankind) has been assigned the job to carry all the necessary elements of current yuga to the upcoming yuga. There are N stones arranged in a straight line. In order to fulfill the task, M...
def func(s,val): cfc=0 x=0 length=len(s) for i in range(length): if x+s[i]<=val: x+=s[i] else: cfc+=1 x=s[i] return cfc+1 t=input() for i in range(t): l1=map(int,raw_input().strip().split()) n=l1[0] j=l1[1] route=map(int,raw_input().strip().split()) s=[] minimum=0 for k in range(1,n): x=rou...
1Python2
{ "input": [ "2\n4 1\n2 15 36 43 \n3 2\n27 30 35 \n\nSAMPLE", "2\n4 1\n2 15 36 43 \n3 2\n27 29 35 \n\nSAMPLE", "2\n4 1\n4 15 36 43 \n3 2\n27 29 35 \n\nSAMPLE", "2\n4 1\n2 15 36 43 \n3 2\n18 30 35 \n\nSAMPLE", "2\n4 1\n0 15 36 43 \n3 2\n27 29 35 \n\nSAMPLE", "2\n3 1\n2 15 36 43 \n3 2\n18 30 35 ...
3HACKEREARTH
professor-sharma_505
Professor Sharma gives the following problem to his students: given two integers X( ≥ 2) and Y( ≥ 2) and tells them to find the smallest positive integral exponent E such that the decimal expansion of X^E begins with Y. For example, if X = 8 and Y= 51, then X^3 = 512 begins with Y= 51, so E= 3. Professor Sharma has a...
i=1 for _ in xrange(input()): a,b=map(int,raw_input().split()) n=1 x=1 while True: x=x*a if str(b) == str(x)[:len(str(b))]: break n=n+1 print "Case %d:"%i, n i+=1
1Python2
{ "input": [ "2\n5 156\n16 40\n\nSAMPLE", "4\n39 20\n183 11\n551 27\n85 16", "8\n4 65\n5 12\n7 24\n9 38\n12 24\n14 10\n65 75\n31 26", "4\n39 18\n183 11\n551 27\n85 16", "8\n4 65\n5 12\n7 21\n9 38\n12 24\n14 10\n65 75\n31 26", "2\n5 156\n28 40\n\nSAMPLE", "4\n49 18\n183 11\n551 27\n85 16", ...
3HACKEREARTH
sherlock-and-kgb_506
The russian intelligence agency KGB make an encryption technique to send their passwords. Originally the password is of 3 characters. After encryption the password is converted into 3 numbers A-B-C. Now, Sherlock wants to decrypt the password encryption technique of KGB. Sherlock knows that every number has only 2 po...
T = int(raw_input()) for ti in xrange(T): a,b,c = map(int,raw_input().split()) if a%3: s1 = 'X' else: while a%3==0: a /= 3 if a==1: s1 = 'K' else: s1 = 'X' if b%5: s2 = 'Y' else: while b%5==0: b /= 5 if b==1: s2 = 'G' else: s2 = 'Y' if c%2: s3 = 'Z' else: while c%2==0: c ...
1Python2
{ "input": [ "2\n27 25 4\n25 26 16\n\nSAMPLE", "5\n81 125 16\n19683 15625 8192\n59049 15630 32768\n59050 78125 131072\n177147 390625 131073" ], "output": [ "K-G-B\nX-Y-B", "K-G-B \nK-G-B \nK-Y-B \nX-G-B \nK-G-Z" ] }
3HACKEREARTH
the-competitive-class-3_507
Jiro is a fun loving lad. His classmates are very competitive and are striving for getting a good rank, while he loves seeing them fight for it. The results are going to be out soon. He is anxious to know what is the rank of each of his classmates. Rank of i'th student = 1+ (Number of students having strictly grea...
n = int(raw_input()) m = map(int, raw_input().split()) for i in range(0,len(m)): count =1 for j in range(0,len(m)): if(m[i]<m[j]): count+=1 print count,
1Python2
{ "input": [ "4\n62 96 82 55\n\nSAMPLE", "384\n87 78 16 94 36 87 93 50 22 63 28 91 60 64 27 41 27 73 37 12 69 68 30 83 31 63 24 68 36 30 3 23 59 70 68 94 57 12 43 30 74 22 20 85 38 99 25 16 71 14 27 92 81 57 74 63 71 97 82 6 26 85 28 37 6 47 30 14 58 25 96 83 46 15 68 35 65 44 51 88 9 77 79 89 85 4 52 55 100 ...
3HACKEREARTH
xenny-and-range-sums_508
PowerShell had N natural numbers. He wanted to test Xenny's speed in finding the sum and difference of several numbers. He decided to ask Xenny several questions. In each question, he gave him two positive integers L and R. He asked him to find the sum of all integers from index L to index R (inclusive) and the differ...
n,q=map(int,raw_input().split()) b=map(int,raw_input().split()) bb=[0] for i in xrange(n): bb.append(bb[len(bb)-1]+b[i]) for i in xrange(q): l,r=map(int,raw_input().split()) print bb[r]-bb[l-1],2*b[r-1]-bb[r]+bb[l-1]
1Python2
{ "input": [ "4 1\n1 2 3 4\n1 3\n\nSAMPLE", "78 78\n-645462 -187679 693035 927066 431506 16023 -173045 698159 -995400 -687770 -747462 789670 862673 385513 579977 -156856 22209 378002 930156 353000 67263 -758921 572468 562437 125912 -422101 -513624 43409 25348 -214377 808094 -88292 293865 910587 -731480 -50905...
3HACKEREARTH
p02652 AtCoder Grand Contest 045 - 01 Unbalanced_509
Given is a string S, where each character is `0`, `1`, or `?`. Consider making a string S' by replacing each occurrence of `?` with `0` or `1` (we can choose the character for each `?` independently). Let us define the unbalancedness of S' as follows: * (The unbalancedness of S') = \max \\{ The absolute difference be...
#include<bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i=a;i<=b;i++) #define ROF(i,a,b) for(int i=a;i>=b;i--) const int N=1e6+7,INF=0x3f3f3f3f,sgn[]={-1,1}; char a[N]; int n,s[N],nxt[N]; int solve(int x,int cnt=0){ int w=0; FOR(i,1,n){ if(a[i]=='?'&&cnt+2+nxt[i]<=x)cnt+=2; w=min(w,s[i]+cnt); } ...
2C++
{ "input": [ "??00????0??0????0?0??00??1???11?1?1???1?11?111???1", "0??0", "0??", "0?0?", "00??", "??00????0??1????0?0??00??1???11?1?1???1?11?111???1", "1???11??11?1???1?1?11???1??00??0?0?1??1??0>>??00??", "1???111?11?1???111?11???1??00??0?0?@?????0????00??", "????111?11?1?1?111?11...
5ATCODER
p02652 AtCoder Grand Contest 045 - 01 Unbalanced_510
Given is a string S, where each character is `0`, `1`, or `?`. Consider making a string S' by replacing each occurrence of `?` with `0` or `1` (we can choose the character for each `?` independently). Let us define the unbalancedness of S' as follows: * (The unbalancedness of S') = \max \\{ The absolute difference be...
from itertools import accumulate S = input() N = len(S) A = [0] + list(accumulate(1 if s == "1" else -1 for s in S)) ma = max(A) cur = A[-1] C = [ma - cur] for a in reversed(A): cur = max(a, cur) C.append(ma - cur) d, e = 0, 0 D, E = A[:], A[:] for i, (s, c) in enumerate(zip(S, reversed(C[:-1])), 1): if...
3Python3
{ "input": [ "??00????0??0????0?0??00??1???11?1?1???1?11?111???1", "0??0", "0??", "0?0?", "00??", "??00????0??1????0?0??00??1???11?1?1???1?11?111???1", "1???11??11?1???1?1?11???1??00??0?0?1??1??0>>??00??", "1???111?11?1???111?11???1??00??0?0?@?????0????00??", "????111?11?1?1?111?11...
5ATCODER
p02652 AtCoder Grand Contest 045 - 01 Unbalanced_511
Given is a string S, where each character is `0`, `1`, or `?`. Consider making a string S' by replacing each occurrence of `?` with `0` or `1` (we can choose the character for each `?` independently). Let us define the unbalancedness of S' as follows: * (The unbalancedness of S') = \max \\{ The absolute difference be...
import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class Main { static InputStream is; static PrintWriter out; static String INPUT = ""; // static String INPUT = "?0011"; //...
4JAVA
{ "input": [ "??00????0??0????0?0??00??1???11?1?1???1?11?111???1", "0??0", "0??", "0?0?", "00??", "??00????0??1????0?0??00??1???11?1?1???1?11?111???1", "1???11??11?1???1?1?11???1??00??0?0?1??1??0>>??00??", "1???111?11?1???111?11???1??00??0?0?@?????0????00??", "????111?11?1?1?111?11...
5ATCODER
p02781 AtCoder Beginner Contest 154 - Almost Everywhere Zero_512
Find the number of integers between 1 and N (inclusive) that contains exactly K non-zero digits when written in base ten. Constraints * 1 \leq N < 10^{100} * 1 \leq K \leq 3 Input Input is given from Standard Input in the following format: N K Output Print the count. Examples Input 100 1 Output 19 Inpu...
N = input() K = input() def fact(x): r = 1 while x>0: r *= x x -= 1 return r def comb(x, y): if y>x: return 0 return fact(x)/fact(y)/fact(x-y) N = str(N+1) def f(d, k): if k==0: if d>=len(N) or int(N[d:])==0: return 0 else: return 1 while d<len(N) and N[d]=="0": d +=...
1Python2
{ "input": [ "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n3", "314159\n2", "25\n2", "100\n1", "314159\n1", "25\n1", "100\n2", "314159\n3", "999999999999999999999999999999999999999999999999999999999999999999999999999999999999...
5ATCODER
p02781 AtCoder Beginner Contest 154 - Almost Everywhere Zero_513
Find the number of integers between 1 and N (inclusive) that contains exactly K non-zero digits when written in base ten. Constraints * 1 \leq N < 10^{100} * 1 \leq K \leq 3 Input Input is given from Standard Input in the following format: N K Output Print the count. Examples Input 100 1 Output 19 Inpu...
#include <bits/stdc++.h> using namespace std; int dp[20005][100][5]; string s; int n,k; int Rec(int index,int zeros,bool flag){ if(zeros > k) return 0; if(index == n) return zeros == k; if(dp[index][zeros][flag] + 1) return dp[index][zeros][flag]; int Res =0; int Limit = flag?9:s[index...
2C++
{ "input": [ "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n3", "314159\n2", "25\n2", "100\n1", "314159\n1", "25\n1", "100\n2", "314159\n3", "999999999999999999999999999999999999999999999999999999999999999999999999999999999999...
5ATCODER
p02781 AtCoder Beginner Contest 154 - Almost Everywhere Zero_514
Find the number of integers between 1 and N (inclusive) that contains exactly K non-zero digits when written in base ten. Constraints * 1 \leq N < 10^{100} * 1 \leq K \leq 3 Input Input is given from Standard Input in the following format: N K Output Print the count. Examples Input 100 1 Output 19 Inpu...
import functools import sys @functools.lru_cache(None) def doit(n, k): if len(n) == 0 or k < 0: return k == 0 d = int(n[0]) return sum(doit(n[1:] if i == d else '9' * (len(n) - 1), k - 1 if i > 0 else k) for i in range(d + 1)) sys.setrecursionlimit(404) print(doit(input(), int(input())))
3Python3
{ "input": [ "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n3", "314159\n2", "25\n2", "100\n1", "314159\n1", "25\n1", "100\n2", "314159\n3", "999999999999999999999999999999999999999999999999999999999999999999999999999999999999...
5ATCODER
p02781 AtCoder Beginner Contest 154 - Almost Everywhere Zero_515
Find the number of integers between 1 and N (inclusive) that contains exactly K non-zero digits when written in base ten. Constraints * 1 \leq N < 10^{100} * 1 \leq K \leq 3 Input Input is given from Standard Input in the following format: N K Output Print the count. Examples Input 100 1 Output 19 Inpu...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Scanner; /** * Built using CHelper plug-in * Actual solution is at the top * * @author varunvats32 */ public class Main { public static void main(String[] args) { InputStre...
4JAVA
{ "input": [ "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n3", "314159\n2", "25\n2", "100\n1", "314159\n1", "25\n1", "100\n2", "314159\n3", "999999999999999999999999999999999999999999999999999999999999999999999999999999999999...
5ATCODER
p02916 AtCoder Beginner Contest 140 - Buffet_516
Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once. The i-th dish (1 \leq i \leq N) he ate was Dish A_i. When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points. Additionally, when he eats Dish i+1 just after eating Dish i (1 \...
N = int(raw_input()) A = map(int, raw_input().split(' ')) B = map(int, raw_input().split(' ')) C = map(int, raw_input().split(' ')) satisfied = 0 for i in range(0, N): i_food = A[i] satisfied += B[i_food - 1] if i > 0: i_food_prev = A[i - 1] if i_food - i_food_prev == 1: satisfi...
1Python2
{ "input": [ "2\n1 2\n50 50\n50", "4\n2 3 4 1\n13 5 8 24\n45 9 15", "3\n3 1 2\n2 5 4\n3 6", "2\n1 0\n50 50\n50", "4\n2 3 4 1\n13 5 1 24\n45 9 15", "4\n2 3 4 1\n13 5 1 24\n45 9 16", "4\n2 3 4 1\n14 5 1 24\n45 9 16", "4\n2 3 4 1\n7 5 1 24\n45 9 16", "3\n3 1 2\n2 5 3\n3 6", "4\n2 ...
5ATCODER
p02916 AtCoder Beginner Contest 140 - Buffet_517
Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once. The i-th dish (1 \leq i \leq N) he ate was Dish A_i. When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points. Additionally, when he eats Dish i+1 just after eating Dish i (1 \...
#include <bits/stdc++.h> using namespace std; int n,a[201],b[201],c[201]; int main() { scanf("%d",&n); int sum=0; for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) scanf("%d",&b[i]),sum+=b[i]; for(int i=1;i<n;i++) scanf("%d",&c[i]); for(int i=1;i<n;i++) if(a[i]+1==a[i+1]) sum+=c[a[i]]; prin...
2C++
{ "input": [ "2\n1 2\n50 50\n50", "4\n2 3 4 1\n13 5 8 24\n45 9 15", "3\n3 1 2\n2 5 4\n3 6", "2\n1 0\n50 50\n50", "4\n2 3 4 1\n13 5 1 24\n45 9 15", "4\n2 3 4 1\n13 5 1 24\n45 9 16", "4\n2 3 4 1\n14 5 1 24\n45 9 16", "4\n2 3 4 1\n7 5 1 24\n45 9 16", "3\n3 1 2\n2 5 3\n3 6", "4\n2 ...
5ATCODER
p02916 AtCoder Beginner Contest 140 - Buffet_518
Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once. The i-th dish (1 \leq i \leq N) he ate was Dish A_i. When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points. Additionally, when he eats Dish i+1 just after eating Dish i (1 \...
N=int(input()) A=list(map(int,input().split())) B=list(map(int,input().split())) C=list(map(int,input().split())) pnt=sum(B) for i in range(N-1): if A[i+1]==A[i]+1: pnt+=C[A[i]-1] print(pnt)
3Python3
{ "input": [ "2\n1 2\n50 50\n50", "4\n2 3 4 1\n13 5 8 24\n45 9 15", "3\n3 1 2\n2 5 4\n3 6", "2\n1 0\n50 50\n50", "4\n2 3 4 1\n13 5 1 24\n45 9 15", "4\n2 3 4 1\n13 5 1 24\n45 9 16", "4\n2 3 4 1\n14 5 1 24\n45 9 16", "4\n2 3 4 1\n7 5 1 24\n45 9 16", "3\n3 1 2\n2 5 3\n3 6", "4\n2 ...
5ATCODER
p02916 AtCoder Beginner Contest 140 - Buffet_519
Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once. The i-th dish (1 \leq i \leq N) he ate was Dish A_i. When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points. Additionally, when he eats Dish i+1 just after eating Dish i (1 \...
import java.util.*; public class Main { public static void main (String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int nam = 0; int sum = 0; int nam1[] = new int[n]; int nam2[] = new int[n-1]; for(int i = 0;i < n;i++){ nam1[i] = in.next...
4JAVA
{ "input": [ "2\n1 2\n50 50\n50", "4\n2 3 4 1\n13 5 8 24\n45 9 15", "3\n3 1 2\n2 5 4\n3 6", "2\n1 0\n50 50\n50", "4\n2 3 4 1\n13 5 1 24\n45 9 15", "4\n2 3 4 1\n13 5 1 24\n45 9 16", "4\n2 3 4 1\n14 5 1 24\n45 9 16", "4\n2 3 4 1\n7 5 1 24\n45 9 16", "3\n3 1 2\n2 5 3\n3 6", "4\n2 ...
5ATCODER
p03052 diverta 2019 Programming Contest - Edge Ordering_520
You are given a simple connected undirected graph G consisting of N vertices and M edges. The vertices are numbered 1 to N, and the edges are numbered 1 to M. Edge i connects Vertex a_i and b_i bidirectionally. It is guaranteed that the subgraph consisting of Vertex 1,2,\ldots,N and Edge 1,2,\ldots,N-1 is a spanning t...
#include<bits/stdc++.h> using namespace std; typedef long long LL; const int N=20,mod=1000000007; int add(int a,int b,int p=mod){return a+b>=p?a+b-p:a+b;} int sub(int a,int b,int p=mod){return a-b<0?a-b+p:a-b;} int mul(int a,int b,int p=mod){return (LL)a*b%p;} void sadd(int &a,int b,int p=mod){a=add(a,b,p);} void ss...
2C++
{ "input": [ "4 4\n1 2\n3 2\n3 4\n1 3", "15 28\n10 7\n5 9\n2 13\n2 14\n6 1\n5 12\n2 10\n3 9\n10 15\n11 12\n12 6\n2 12\n12 8\n4 10\n15 3\n13 14\n1 15\n15 12\n4 14\n1 7\n5 11\n7 13\n9 10\n2 7\n1 9\n5 6\n12 14\n5 2", "3 3\n1 2\n2 3\n1 3", "15 28\n10 7\n5 9\n2 13\n2 14\n6 1\n9 12\n2 10\n3 9\n10 15\n11 12\...
5ATCODER
p03052 diverta 2019 Programming Contest - Edge Ordering_521
You are given a simple connected undirected graph G consisting of N vertices and M edges. The vertices are numbered 1 to N, and the edges are numbered 1 to M. Edge i connects Vertex a_i and b_i bidirectionally. It is guaranteed that the subgraph consisting of Vertex 1,2,\ldots,N and Edge 1,2,\ldots,N-1 is a spanning t...
import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class Main { static InputStream is; static PrintWriter out; static String INPUT = ""; // static String INPUT = "4 4\r\n" ...
4JAVA
{ "input": [ "4 4\n1 2\n3 2\n3 4\n1 3", "15 28\n10 7\n5 9\n2 13\n2 14\n6 1\n5 12\n2 10\n3 9\n10 15\n11 12\n12 6\n2 12\n12 8\n4 10\n15 3\n13 14\n1 15\n15 12\n4 14\n1 7\n5 11\n7 13\n9 10\n2 7\n1 9\n5 6\n12 14\n5 2", "3 3\n1 2\n2 3\n1 3", "15 28\n10 7\n5 9\n2 13\n2 14\n6 1\n9 12\n2 10\n3 9\n10 15\n11 12\...
5ATCODER
p03194 CADDi 2018 for Beginners - Product and GCD_522
There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1, a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ... \times a_N = P. Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N. Constraints * 1 \leq N \leq 10^{12} * 1 \leq P \leq 10^{12} Input Input is...
import sys from collections import deque import copy import math def get_read_func(fileobject): if fileobject == None : return raw_input else: return fileobject.readline def prime_decomposition(n): i = 2 table = {} while i * i <= n: while n % i == 0: n /= i if i in table: ...
1Python2
{ "input": [ "5 1", "4 972439611840", "3 24", "1 111", "5 2", "1 972439611840", "1 110", "1 2", "1 534720932937", "1 18", "1 010", "1 3", "1 867963093279", "1 15", "1 011", "1 5", "1 100", "1 1431379180228", "1 101", "1 243501193440", ...
5ATCODER
p03194 CADDi 2018 for Beginners - Product and GCD_523
There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1, a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ... \times a_N = P. Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N. Constraints * 1 \leq N \leq 10^{12} * 1 \leq P \leq 10^{12} Input Input is...
#include <iostream> using namespace std; int main(void){ long long N,P,i,j,k,ans=1; cin>>N>>P; if(N==1){ cout<<P<<endl; return 0; } for(i=2;P>1&&i*i<P+1;i++){ k=0; while(P%i==0){ k++; P/=i; } for(j=0;j<k/N;j++){ ans*...
2C++
{ "input": [ "5 1", "4 972439611840", "3 24", "1 111", "5 2", "1 972439611840", "1 110", "1 2", "1 534720932937", "1 18", "1 010", "1 3", "1 867963093279", "1 15", "1 011", "1 5", "1 100", "1 1431379180228", "1 101", "1 243501193440", ...
5ATCODER
p03194 CADDi 2018 for Beginners - Product and GCD_524
There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1, a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ... \times a_N = P. Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N. Constraints * 1 \leq N \leq 10^{12} * 1 \leq P \leq 10^{12} Input Input is...
import math import collections # 試し割法 N, P = map(int, input().split()) def trial_division(n): # 素因数を格納するリスト factor = [] # 2から√n以下の数字で割っていく tmp = int(math.sqrt(n)) + 1 for num in range(2, tmp): while n % num == 0: n //= num factor.append(num) # リストが空ならそれは素数 ...
3Python3
{ "input": [ "5 1", "4 972439611840", "3 24", "1 111", "5 2", "1 972439611840", "1 110", "1 2", "1 534720932937", "1 18", "1 010", "1 3", "1 867963093279", "1 15", "1 011", "1 5", "1 100", "1 1431379180228", "1 101", "1 243501193440", ...
5ATCODER
p03194 CADDi 2018 for Beginners - Product and GCD_525
There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1, a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ... \times a_N = P. Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N. Constraints * 1 \leq N \leq 10^{12} * 1 \leq P \leq 10^{12} Input Input is...
import java.util.*; import java.io.*; import java.math.*; public class Main{ //Don't have to see. start------------------------------------------ static class InputIterator{ ArrayList<String> inputLine = new ArrayList<String>(1024); int index = 0; int max; String read; InputIterator(){ BufferedReader br = ne...
4JAVA
{ "input": [ "5 1", "4 972439611840", "3 24", "1 111", "5 2", "1 972439611840", "1 110", "1 2", "1 534720932937", "1 18", "1 010", "1 3", "1 867963093279", "1 15", "1 011", "1 5", "1 100", "1 1431379180228", "1 101", "1 243501193440", ...
5ATCODER
p03343 AtCoder Regular Contest 098 - Range Minimum Queries_526
You are given an integer sequence A of length N and an integer K. You will perform the following operation on this sequence Q times: * Choose a contiguous subsequence of length K, then remove the smallest element among the K elements contained in the chosen subsequence (if there are multiple such elements, choose one ...
from collections import defaultdict def main(): n, k, q = map(int, raw_input().split()) a = map(int, raw_input().split()) d = defaultdict(list) for i, x in enumerate(a): d[x].append(i) a.append(-1) ans = 1001001001 for x in sorted(d.keys()): p = 0 b = [] s = 0...
1Python2
{ "input": [ "11 7 5\n24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784", "5 3 2\n4 3 1 5 2", "10 1 6\n1 1 2 3 5 8 13 21 34 55", "11 7 5\n24979445 861648772 623690081 433933447 476190629 262703497 147009374 971407775 628894325 731963982 822804...
5ATCODER
p03343 AtCoder Regular Contest 098 - Range Minimum Queries_527
You are given an integer sequence A of length N and an integer K. You will perform the following operation on this sequence Q times: * Choose a contiguous subsequence of length K, then remove the smallest element among the K elements contained in the chosen subsequence (if there are multiple such elements, choose one ...
#include <bits/stdc++.h> using namespace std; int n, m, q; int a[2020]; bool ok(int M) { for (int i = 0; i < n; i++) { int z = 0, c = 0; for (int j = 0, k; j < n; j = k + 1) { for (k = j; k < n; k++) { if (a[k] < a[i]) { break; } if (a[k] <= a[i] + M) { c++; } } if (k - j >= m) {...
2C++
{ "input": [ "11 7 5\n24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784", "5 3 2\n4 3 1 5 2", "10 1 6\n1 1 2 3 5 8 13 21 34 55", "11 7 5\n24979445 861648772 623690081 433933447 476190629 262703497 147009374 971407775 628894325 731963982 822804...
5ATCODER
p03343 AtCoder Regular Contest 098 - Range Minimum Queries_528
You are given an integer sequence A of length N and an integer K. You will perform the following operation on this sequence Q times: * Choose a contiguous subsequence of length K, then remove the smallest element among the K elements contained in the chosen subsequence (if there are multiple such elements, choose one ...
N, K, Q = map(int, input().split()) X = list(map(int, input().split())) r = 10**18 for y in X: tmp = [] tmp2 = [] for x in X: if x < y: tmp.sort() tn = len(tmp) if len(tmp) > K-1: tmp2 += tmp[:tn-K+1] tmp = [] continue ...
3Python3
{ "input": [ "11 7 5\n24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784", "5 3 2\n4 3 1 5 2", "10 1 6\n1 1 2 3 5 8 13 21 34 55", "11 7 5\n24979445 861648772 623690081 433933447 476190629 262703497 147009374 971407775 628894325 731963982 822804...
5ATCODER
p03343 AtCoder Regular Contest 098 - Range Minimum Queries_529
You are given an integer sequence A of length N and an integer K. You will perform the following operation on this sequence Q times: * Choose a contiguous subsequence of length K, then remove the smallest element among the K elements contained in the chosen subsequence (if there are multiple such elements, choose one ...
import java.util.*; import java.io.*; public class Main { static final int mod = (int) 1e9 + 7; static final int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 }; static final int[] DX8 = { -1, -1, -1, 0, 0, 1, 1, 1 }, DY8 = { -1, 0, 1, -1, 1, -1, 0, 1 }; static final int INF = Integer.MAX_VALUE / 2; static final l...
4JAVA
{ "input": [ "11 7 5\n24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784", "5 3 2\n4 3 1 5 2", "10 1 6\n1 1 2 3 5 8 13 21 34 55", "11 7 5\n24979445 861648772 623690081 433933447 476190629 262703497 147009374 971407775 628894325 731963982 822804...
5ATCODER
p03503 AtCoder Beginner Contest 080 - Shopping Street_530
Joisino is planning to open a shop in a shopping street. Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those ...
N = input() F = [] P = [] for _ in xrange(N): F.append(map(int, raw_input().split())) for _ in xrange(N): P.append(map(int, raw_input().split())) calendar = [[]] for _ in xrange(10): newCalendar = [] for y in calendar: newCalendar.append(y + [0]) newCalendar.append(y + [1]) calendar...
1Python2
{ "input": [ "1\n1 1 0 1 0 0 0 1 0 1\n3 4 5 6 7 8 9 -2 -3 4 -2", "3\n1 1 1 1 1 1 0 0 1 1\n0 1 0 1 1 1 1 0 1 0\n1 0 1 1 0 1 0 1 0 1\n-8 6 -2 -8 -8 4 8 7 -6 2 2\n-9 2 0 1 7 -5 0 -2 -6 5 5\n6 -6 7 -9 6 -5 8 0 -9 -7 -7", "2\n1 1 1 1 1 0 0 0 0 0\n0 0 0 0 0 1 1 1 1 1\n0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1\n0 -2 -2 -2...
5ATCODER
p03503 AtCoder Beginner Contest 080 - Shopping Street_531
Joisino is planning to open a shop in a shopping street. Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those ...
// C - Shopping Street #include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vvi = vector<vi>; #define rp(i,s,e) for(int i=(int)(s);i<(int)(e);++i) int main(){ int n; cin>>n; vvi F(n, vi(10)); rp(i, 0, n) rp(j, 0, 10) cin>>F[i][j]; vvi P(n, vi(10+1)); rp(i, 0, n) rp(j, 0, 10+1) cin>>P[i][j];...
2C++
{ "input": [ "1\n1 1 0 1 0 0 0 1 0 1\n3 4 5 6 7 8 9 -2 -3 4 -2", "3\n1 1 1 1 1 1 0 0 1 1\n0 1 0 1 1 1 1 0 1 0\n1 0 1 1 0 1 0 1 0 1\n-8 6 -2 -8 -8 4 8 7 -6 2 2\n-9 2 0 1 7 -5 0 -2 -6 5 5\n6 -6 7 -9 6 -5 8 0 -9 -7 -7", "2\n1 1 1 1 1 0 0 0 0 0\n0 0 0 0 0 1 1 1 1 1\n0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1\n0 -2 -2 -2...
5ATCODER
p03503 AtCoder Beginner Contest 080 - Shopping Street_532
Joisino is planning to open a shop in a shopping street. Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those ...
n = int(input()) f = [[int(x) for x in input().split()] for i in range(n)] p = [[int(x) for x in input().split()] for i in range(n)] t={i:0 for i in range(1,2**10)} for i in range(1,2**10): d, b={j:0 for j in range(n)}, format(i, "010b") for j in range(n): for k in range(10): if (i>>k)%2&f[j][k]==1: d[j]+...
3Python3
{ "input": [ "1\n1 1 0 1 0 0 0 1 0 1\n3 4 5 6 7 8 9 -2 -3 4 -2", "3\n1 1 1 1 1 1 0 0 1 1\n0 1 0 1 1 1 1 0 1 0\n1 0 1 1 0 1 0 1 0 1\n-8 6 -2 -8 -8 4 8 7 -6 2 2\n-9 2 0 1 7 -5 0 -2 -6 5 5\n6 -6 7 -9 6 -5 8 0 -9 -7 -7", "2\n1 1 1 1 1 0 0 0 0 0\n0 0 0 0 0 1 1 1 1 1\n0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1\n0 -2 -2 -2...
5ATCODER
p03503 AtCoder Beginner Contest 080 - Shopping Street_533
Joisino is planning to open a shop in a shopping street. Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those ...
import java.util.*; import java.io.*; import java.math.*; public class Main{ //Don't have to see. start------------------------------------------ static class InputIterator{ ArrayList<String> inputLine = new ArrayList<String>(1024); int index = 0; int max; String read; InputIterator(){ BufferedReader br = ne...
4JAVA
{ "input": [ "1\n1 1 0 1 0 0 0 1 0 1\n3 4 5 6 7 8 9 -2 -3 4 -2", "3\n1 1 1 1 1 1 0 0 1 1\n0 1 0 1 1 1 1 0 1 0\n1 0 1 1 0 1 0 1 0 1\n-8 6 -2 -8 -8 4 8 7 -6 2 2\n-9 2 0 1 7 -5 0 -2 -6 5 5\n6 -6 7 -9 6 -5 8 0 -9 -7 -7", "2\n1 1 1 1 1 0 0 0 0 0\n0 0 0 0 0 1 1 1 1 1\n0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1\n0 -2 -2 -2...
5ATCODER
p03664 AtCoder Regular Contest 078 - Mole and Abandoned Mine_534
Mole decided to live in an abandoned mine. The structure of the mine is represented by a simple connected undirected graph which consists of N vertices numbered 1 through N and M edges. The i-th edge connects Vertices a_i and b_i, and it costs c_i yen (the currency of Japan) to remove it. Mole would like to remove som...
#include<bits/stdc++.h> using namespace std; inline int read() { int res=0,fh=1; char ch=getchar(); while((ch>'9'||ch<'0')&&ch!='-')ch=getchar(); if(ch=='-')fh=-1,ch=getchar(); while(ch>='0'&&ch<='9')res=res*10+ch-'0',ch=getchar(); return fh*res; } const int maxn=16; int n,m,mxs,sum[(1<<16)+12],a[maxn][maxn]; ...
2C++
{ "input": [ "15 22\n8 13 33418\n14 15 55849\n7 10 15207\n4 6 64328\n6 9 86902\n15 7 46978\n8 14 53526\n1 2 8720\n14 12 37748\n8 3 61543\n6 5 32425\n4 11 20932\n3 12 55123\n8 2 45333\n9 12 77796\n3 9 71922\n12 15 70793\n2 4 25485\n11 6 1436\n2 7 81563\n7 11 97843\n3 1 40491", "2 1\n1 2 1", "4 6\n1 2 100\n...
5ATCODER
p03664 AtCoder Regular Contest 078 - Mole and Abandoned Mine_535
Mole decided to live in an abandoned mine. The structure of the mine is represented by a simple connected undirected graph which consists of N vertices numbered 1 through N and M edges. The i-th edge connects Vertices a_i and b_i, and it costs c_i yen (the currency of Japan) to remove it. Mole would like to remove som...
n, m = map(int, input().split()) g = [[0 for j in range(n)] for i in range(n)] for i in range(m): u, v, w = map(int, input().split()) g[u - 1][v - 1] = g[v - 1][u - 1] = w e = [sum(g[i][j] for i in range(n) if S >> i & 1 for j in range(i + 1, n) if S >> j & 1) for S in range(1 << n)] dp = [[-10 ** 9 for j i...
3Python3
{ "input": [ "15 22\n8 13 33418\n14 15 55849\n7 10 15207\n4 6 64328\n6 9 86902\n15 7 46978\n8 14 53526\n1 2 8720\n14 12 37748\n8 3 61543\n6 5 32425\n4 11 20932\n3 12 55123\n8 2 45333\n9 12 77796\n3 9 71922\n12 15 70793\n2 4 25485\n11 6 1436\n2 7 81563\n7 11 97843\n3 1 40491", "2 1\n1 2 1", "4 6\n1 2 100\n...
5ATCODER
p03664 AtCoder Regular Contest 078 - Mole and Abandoned Mine_536
Mole decided to live in an abandoned mine. The structure of the mine is represented by a simple connected undirected graph which consists of N vertices numbered 1 through N and M edges. The i-th edge connects Vertices a_i and b_i, and it costs c_i yen (the currency of Japan) to remove it. Mole would like to remove som...
// package arc.arc078; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.*; public class Main { public static void main(String[] args) { InputReader in = new InputReader(System.in); PrintWriter out = new PrintWriter(System.out); int n = i...
4JAVA
{ "input": [ "15 22\n8 13 33418\n14 15 55849\n7 10 15207\n4 6 64328\n6 9 86902\n15 7 46978\n8 14 53526\n1 2 8720\n14 12 37748\n8 3 61543\n6 5 32425\n4 11 20932\n3 12 55123\n8 2 45333\n9 12 77796\n3 9 71922\n12 15 70793\n2 4 25485\n11 6 1436\n2 7 81563\n7 11 97843\n3 1 40491", "2 1\n1 2 1", "4 6\n1 2 100\n...
5ATCODER
p03819 AtCoder Regular Contest 068 - Snuke Line_537
Snuke has decided to play a game, where the player runs a railway company. There are M+1 stations on Snuke Line, numbered 0 through M. A train on Snuke Line stops at station 0 and every d-th station thereafter, where d is a predetermined constant for each train. For example, if d = 3, the train stops at station 0, 3, 6...
class BIT(): def __init__(self,size): self.size=size self.node=[0]*(size+1) def sum(self,idx): ret=0 while idx>0: ret+=self.node[idx] idx-=idx&(-idx) return ret def add(self,idx,x): while idx<=self.size: self.node[idx]+=x ...
1Python2
{ "input": [ "3 3\n1 2\n2 3\n3 3", "7 9\n1 7\n5 9\n5 7\n5 9\n1 1\n6 8\n3 4", "7 9\n1 9\n5 9\n5 7\n5 9\n1 1\n6 8\n3 4", "7 9\n1 9\n9 9\n5 7\n5 9\n1 1\n6 8\n3 4", "7 11\n1 9\n5 9\n5 7\n5 9\n1 1\n6 8\n3 4", "7 9\n1 9\n9 9\n5 7\n5 9\n1 1\n8 8\n3 4", "7 9\n1 6\n5 13\n5 7\n5 9\n1 1\n6 8\n3 4", ...
5ATCODER
p03819 AtCoder Regular Contest 068 - Snuke Line_538
Snuke has decided to play a game, where the player runs a railway company. There are M+1 stations on Snuke Line, numbered 0 through M. A train on Snuke Line stops at station 0 and every d-th station thereafter, where d is a predetermined constant for each train. For example, if d = 3, the train stops at station 0, 3, 6...
#include <bits/stdc++.h> #define ll long long #define INF 999999999 #define MOD 1000000007 #define rep(i,n) for(int i=0;i<n;i++) using namespace std; typedef pair<int,int>P; const int MAX_N = 100005; vector<P> lens[100005]; int bit[MAX_N+1],n,m; //i番目までの和を計算する int sum(int i) { int s = 0; while(i>0){ s += bit[i...
2C++
{ "input": [ "3 3\n1 2\n2 3\n3 3", "7 9\n1 7\n5 9\n5 7\n5 9\n1 1\n6 8\n3 4", "7 9\n1 9\n5 9\n5 7\n5 9\n1 1\n6 8\n3 4", "7 9\n1 9\n9 9\n5 7\n5 9\n1 1\n6 8\n3 4", "7 11\n1 9\n5 9\n5 7\n5 9\n1 1\n6 8\n3 4", "7 9\n1 9\n9 9\n5 7\n5 9\n1 1\n8 8\n3 4", "7 9\n1 6\n5 13\n5 7\n5 9\n1 1\n6 8\n3 4", ...
5ATCODER
p03819 AtCoder Regular Contest 068 - Snuke Line_539
Snuke has decided to play a game, where the player runs a railway company. There are M+1 stations on Snuke Line, numbered 0 through M. A train on Snuke Line stops at station 0 and every d-th station thereafter, where d is a predetermined constant for each train. For example, if d = 3, the train stops at station 0, 3, 6...
class BIT: def __init__(self, n): self.n = n self.bit = [0] * (n + 1) def add(self, k, x): while k <= self.n: self.bit[k] += x k += k & -k def sum(self, k): s = 0 while k > 0: s += self.bit[k] k -= k & -k retur...
3Python3
{ "input": [ "3 3\n1 2\n2 3\n3 3", "7 9\n1 7\n5 9\n5 7\n5 9\n1 1\n6 8\n3 4", "7 9\n1 9\n5 9\n5 7\n5 9\n1 1\n6 8\n3 4", "7 9\n1 9\n9 9\n5 7\n5 9\n1 1\n6 8\n3 4", "7 11\n1 9\n5 9\n5 7\n5 9\n1 1\n6 8\n3 4", "7 9\n1 9\n9 9\n5 7\n5 9\n1 1\n8 8\n3 4", "7 9\n1 6\n5 13\n5 7\n5 9\n1 1\n6 8\n3 4", ...
5ATCODER
p03819 AtCoder Regular Contest 068 - Snuke Line_540
Snuke has decided to play a game, where the player runs a railway company. There are M+1 stations on Snuke Line, numbered 0 through M. A train on Snuke Line stops at station 0 and every d-th station thereafter, where d is a predetermined constant for each train. For example, if d = 3, the train stops at station 0, 3, 6...
import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.NoSuchElementException; public class Main { public static void main(String[] args) { FastScanner sc = new FastScanner(); int N = sc.nextInt(); int M = sc.nextInt(); int[][] range = sc.nextIntTable(...
4JAVA
{ "input": [ "3 3\n1 2\n2 3\n3 3", "7 9\n1 7\n5 9\n5 7\n5 9\n1 1\n6 8\n3 4", "7 9\n1 9\n5 9\n5 7\n5 9\n1 1\n6 8\n3 4", "7 9\n1 9\n9 9\n5 7\n5 9\n1 1\n6 8\n3 4", "7 11\n1 9\n5 9\n5 7\n5 9\n1 1\n6 8\n3 4", "7 9\n1 9\n9 9\n5 7\n5 9\n1 1\n8 8\n3 4", "7 9\n1 6\n5 13\n5 7\n5 9\n1 1\n6 8\n3 4", ...
5ATCODER
p03986 AtCoder Grand Contest 005 - STring_541
We have a string X, which has an even number of characters. Half the characters are `S`, and the other half are `T`. Takahashi, who hates the string `ST`, will perform the following operation 10^{10000} times: * Among the occurrences of `ST` in X as (contiguous) substrings, remove the leftmost one. If there is no occ...
def finalLength(sample): foo = len(sample) tmp = 0 for c in sample: if c=='S': tmp += 1 elif tmp>0: tmp -= 1 foo -= 2 return foo def main(): sample = raw_input().strip() print finalLength(sample) if __name__ == '__main__': main()
1Python2
{ "input": [ "TSTTSS", "SSTTST", "TSSTTTSS", "SSTTTSST", "STTTSS", "SSSTTT", "TTTSSS", "TTTTSSSS", "TSTSST", "SSTTTS", "TSSTST", "STTSST", "TSSSTT", "TTSSST", "TSSTTS", "STSTST", "TSTSTS", "TSSTTSST", "STSTTS", "TTSTSSST", "STTSTS", ...
5ATCODER
p03986 AtCoder Grand Contest 005 - STring_542
We have a string X, which has an even number of characters. Half the characters are `S`, and the other half are `T`. Takahashi, who hates the string `ST`, will perform the following operation 10^{10000} times: * Among the occurrences of `ST` in X as (contiguous) substrings, remove the leftmost one. If there is no occ...
#import<iostream> using namespace std; string s;int c,f; int main(){ cin>>s; for(int i=0;i<s.size();i++){ if(s[i]=='S')f++; else if(f>0)f--,c+=2; } cout<<s.size()-c<<endl; }
2C++
{ "input": [ "TSTTSS", "SSTTST", "TSSTTTSS", "SSTTTSST", "STTTSS", "SSSTTT", "TTTSSS", "TTTTSSSS", "TSTSST", "SSTTTS", "TSSTST", "STTSST", "TSSSTT", "TTSSST", "TSSTTS", "STSTST", "TSTSTS", "TSSTTSST", "STSTTS", "TTSTSSST", "STTSTS", ...
5ATCODER
p03986 AtCoder Grand Contest 005 - STring_543
We have a string X, which has an even number of characters. Half the characters are `S`, and the other half are `T`. Takahashi, who hates the string `ST`, will perform the following operation 10^{10000} times: * Among the occurrences of `ST` in X as (contiguous) substrings, remove the leftmost one. If there is no occ...
x=input() s=0;t=0 for i in range(len(x)): if x[i]=='S':s+=1 elif s==0:t+=1 else:s-=1 print(s+t)
3Python3
{ "input": [ "TSTTSS", "SSTTST", "TSSTTTSS", "SSTTTSST", "STTTSS", "SSSTTT", "TTTSSS", "TTTTSSSS", "TSTSST", "SSTTTS", "TSSTST", "STTSST", "TSSSTT", "TTSSST", "TSSTTS", "STSTST", "TSTSTS", "TSSTTSST", "STSTTS", "TTSTSSST", "STTSTS", ...
5ATCODER
p03986 AtCoder Grand Contest 005 - STring_544
We have a string X, which has an even number of characters. Half the characters are `S`, and the other half are `T`. Takahashi, who hates the string `ST`, will perform the following operation 10^{10000} times: * Among the occurrences of `ST` in X as (contiguous) substrings, remove the leftmost one. If there is no occ...
import java.util.*; import static java.lang.Integer.*; import static java.lang.Long.*; import static java.lang.Math.*; import static java.lang.System.*; public class Main { public static void main(String[] args) { int i,j; Scanner sc = new Scanner(in); StringBuilder x = new StringBuilder(sc.next()); sc.close(...
4JAVA
{ "input": [ "TSTTSS", "SSTTST", "TSSTTTSS", "SSTTTSST", "STTTSS", "SSSTTT", "TTTSSS", "TTTTSSSS", "TSTSST", "SSTTTS", "TSSTST", "STTSST", "TSSSTT", "TTSSST", "TSSTTS", "STSTST", "TSTSTS", "TSSTTSST", "STSTTS", "TTSTSSST", "STTSTS", ...
5ATCODER
p00074 Videotape_545
There is a 120 minute videotape with standard recording. When I set the VCR counter to 00:00:00 with the tape completely rewound and recorded in standard recording mode, I got a certain counter value. Enter this counter value (hours, minutes, seconds), find the length of the remaining tape (recordable time), and create...
#!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import (division, absolute_import, print_function, unicode_literals) from sys import stdin def print_time_lefts(seconds): h, remain = divmod(seconds, 3600) m, s = divmod(remain, 60) print('{:02d}:{:02d}:{:02d}'.format(h,...
1Python2
{ "input": [ "1 30 0\n-1 -1 -1", "1 36 0\n-1 -1 -1", "0 30 0\n-1 -1 -1", "0 32 0\n-1 -1 -1", "1 16 0\n-1 -1 -1", "0 36 0\n-1 -1 -1", "0 22 0\n-1 -1 -1", "0 55 0\n-1 -1 -1", "0 22 1\n-1 -1 -1", "0 31 1\n-1 -1 -1", "0 26 1\n-1 -1 -1", "0 9 1\n-1 -1 -1", "1 36 1\n-1 -1...
6AIZU
p00074 Videotape_546
There is a 120 minute videotape with standard recording. When I set the VCR counter to 00:00:00 with the tape completely rewound and recorded in standard recording mode, I got a certain counter value. Enter this counter value (hours, minutes, seconds), find the length of the remaining tape (recordable time), and create...
#include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <cmath> #include <stack> #include <vector> #include <map> #include <set> #include <queue> #include <list> #include <iostream> #include <climits> #include <cfloat> using namespace std; void printTime(int sec) { printf("%02d:%02d:%02d...
2C++
{ "input": [ "1 30 0\n-1 -1 -1", "1 36 0\n-1 -1 -1", "0 30 0\n-1 -1 -1", "0 32 0\n-1 -1 -1", "1 16 0\n-1 -1 -1", "0 36 0\n-1 -1 -1", "0 22 0\n-1 -1 -1", "0 55 0\n-1 -1 -1", "0 22 1\n-1 -1 -1", "0 31 1\n-1 -1 -1", "0 26 1\n-1 -1 -1", "0 9 1\n-1 -1 -1", "1 36 1\n-1 -1...
6AIZU
p00074 Videotape_547
There is a 120 minute videotape with standard recording. When I set the VCR counter to 00:00:00 with the tape completely rewound and recorded in standard recording mode, I got a certain counter value. Enter this counter value (hours, minutes, seconds), find the length of the remaining tape (recordable time), and create...
def time(sec): h = sec // 3600 ti = sec % 3600 m = ti // 60 s = ti % 60 return [h,m,s] while True: t,h,s = map(int,input().split()) if t == h == s == -1: break sec = t*3600 + h * 60 + s sec = 7200 - sec ans = time(sec) t_ans = time(3 * sec) if ans[2] < 10: ...
3Python3
{ "input": [ "1 30 0\n-1 -1 -1", "1 36 0\n-1 -1 -1", "0 30 0\n-1 -1 -1", "0 32 0\n-1 -1 -1", "1 16 0\n-1 -1 -1", "0 36 0\n-1 -1 -1", "0 22 0\n-1 -1 -1", "0 55 0\n-1 -1 -1", "0 22 1\n-1 -1 -1", "0 31 1\n-1 -1 -1", "0 26 1\n-1 -1 -1", "0 9 1\n-1 -1 -1", "1 36 1\n-1 -1...
6AIZU
p00074 Videotape_548
There is a 120 minute videotape with standard recording. When I set the VCR counter to 00:00:00 with the tape completely rewound and recorded in standard recording mode, I got a certain counter value. Enter this counter value (hours, minutes, seconds), find the length of the remaining tape (recordable time), and create...
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { int t = sc.nextInt(); int h = sc.nextInt(); int s = sc.nextInt(); if (t == -1 && h == -1 && s == -1) { ...
4JAVA
{ "input": [ "1 30 0\n-1 -1 -1", "1 36 0\n-1 -1 -1", "0 30 0\n-1 -1 -1", "0 32 0\n-1 -1 -1", "1 16 0\n-1 -1 -1", "0 36 0\n-1 -1 -1", "0 22 0\n-1 -1 -1", "0 55 0\n-1 -1 -1", "0 22 1\n-1 -1 -1", "0 31 1\n-1 -1 -1", "0 26 1\n-1 -1 -1", "0 9 1\n-1 -1 -1", "1 36 1\n-1 -1...
6AIZU
p00206 Next Trip_549
You want to go on a trip with a friend. However, friends who have a habit of spending money cannot easily save travel expenses. I don't know when my friends will go on a trip if they continue their current lives. So, if you want to travel early, you decide to create a program to help your friends save in a planned mann...
while 1: L=input() if L<1:break a,t=0,0 for i in range(12): k=map(int,raw_input().split()) t+=k[0]-k[1] if L<=t:a+=1 print 12-a+1 if a else "NA"
1Python2
{ "input": [ "10000\n5000 3150\n5000 5000\n0 0\n5000 1050\n5000 3980\n5000 210\n5000 5000\n5000 5000\n0 0\n5000 2100\n5000 2100\n5000 2100\n29170\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n10...
6AIZU
p00206 Next Trip_550
You want to go on a trip with a friend. However, friends who have a habit of spending money cannot easily save travel expenses. I don't know when my friends will go on a trip if they continue their current lives. So, if you want to travel early, you decide to create a program to help your friends save in a planned mann...
//53 #include<iostream> using namespace std; int main(){ for(int L;cin>>L,L;){ int m=0; for(int i=1;i<=12;i++){ int M,N; cin>>M>>N; L-=M-N; if(m==0&&L<=0){ m=i; } } if(m){ cout<<m<<endl; }else{ cout<<"NA"<<endl; } } return 0; }
2C++
{ "input": [ "10000\n5000 3150\n5000 5000\n0 0\n5000 1050\n5000 3980\n5000 210\n5000 5000\n5000 5000\n0 0\n5000 2100\n5000 2100\n5000 2100\n29170\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n10...
6AIZU
p00206 Next Trip_551
You want to go on a trip with a friend. However, friends who have a habit of spending money cannot easily save travel expenses. I don't know when my friends will go on a trip if they continue their current lives. So, if you want to travel early, you decide to create a program to help your friends save in a planned mann...
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0206 """ import sys from sys import stdin input = stdin.readline def main(args): while True: L = int(input()) if L == 0: break ans = 'NA' for i in range(1, 12+1): if ans ==...
3Python3
{ "input": [ "10000\n5000 3150\n5000 5000\n0 0\n5000 1050\n5000 3980\n5000 210\n5000 5000\n5000 5000\n0 0\n5000 2100\n5000 2100\n5000 2100\n29170\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n10...
6AIZU
p00206 Next Trip_552
You want to go on a trip with a friend. However, friends who have a habit of spending money cannot easily save travel expenses. I don't know when my friends will go on a trip if they continue their current lives. So, if you want to travel early, you decide to create a program to help your friends save in a planned mann...
import java.util.*; import java.lang.*; import java.math.*; import java.io.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class Main{ Scanner sc=new Scanner(System.in); int INF=1<<28; double EPS=1e-9; void run(){ for(;;){ int l=sc.nextInt(); if(l==0){ break; } int...
4JAVA
{ "input": [ "10000\n5000 3150\n5000 5000\n0 0\n5000 1050\n5000 3980\n5000 210\n5000 5000\n5000 5000\n0 0\n5000 2100\n5000 2100\n5000 2100\n29170\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n10...
6AIZU
p00365 Age Difference_553
A trick of fate caused Hatsumi and Taku to come to know each other. To keep the encounter in memory, they decided to calculate the difference between their ages. But the difference in ages varies depending on the day it is calculated. While trying again and again, they came to notice that the difference of their ages w...
#include<bits/stdc++.h> // Shrotening #define fst first #define snd second #define pb push_back // Loop #define FOR(i,a,b) for(auto i=(a);i<(b);++i) #define RFOR(i,a,b) for(auto i=(a);i>=(b);--i) #define REP(i,a) for(long i=0;i<(a);++i) #define RREP(i,a) for(long i=(a);i>=0;--i) #define EACH(i,a) for(auto (i)=(a).b...
2C++
{ "input": [ "2008 2 29\n2015 3 1", "1999 9 9\n2001 11 3", "2008 2 29\n2015 1 1", "1505 9 9\n2001 11 3", "1505 9 9\n2619 11 3", "1505 13 9\n2619 11 3", "573 1 44\n2015 1 1", "595 2 44\n2015 2 1", "597 2 44\n2015 2 1", "246 21 0\n2619 11 5", "246 21 0\n5129 11 5", "431 2...
6AIZU
p00365 Age Difference_554
A trick of fate caused Hatsumi and Taku to come to know each other. To keep the encounter in memory, they decided to calculate the difference between their ages. But the difference in ages varies depending on the day it is calculated. While trying again and again, they came to notice that the difference of their ages w...
y1,m1,d1 = map(int, input().split()) y2,m2,d2 = map(int, input().split()) if y1 > y2 or (y1 == y2 and (m1 > m2 or ( m1 == m2 and d1 > d2 ))): y1, y2 = y2, y1 m1, m2 = m2, m1 d1, d2 = d2, d1 if m1 < m2 or (m1 == m2 and d1 < d2): print(y2 - y1 + 1) else: print(y2 - y1)
3Python3
{ "input": [ "2008 2 29\n2015 3 1", "1999 9 9\n2001 11 3", "2008 2 29\n2015 1 1", "1505 9 9\n2001 11 3", "1505 9 9\n2619 11 3", "1505 13 9\n2619 11 3", "573 1 44\n2015 1 1", "595 2 44\n2015 2 1", "597 2 44\n2015 2 1", "246 21 0\n2619 11 5", "246 21 0\n5129 11 5", "431 2...
6AIZU
p00365 Age Difference_555
A trick of fate caused Hatsumi and Taku to come to know each other. To keep the encounter in memory, they decided to calculate the difference between their ages. But the difference in ages varies depending on the day it is calculated. While trying again and again, they came to notice that the difference of their ages w...
import java.util.*; import java.math.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int y1 = sc.nextInt(), m1 = sc.nextInt(), d1 = sc.nextInt(); int y2 = sc.nextInt(), m2 = sc.nextInt(), d2 = sc.nextInt(); boolean mdsame = m1==m2 && d1==d2; int diff = Ma...
4JAVA
{ "input": [ "2008 2 29\n2015 3 1", "1999 9 9\n2001 11 3", "2008 2 29\n2015 1 1", "1505 9 9\n2001 11 3", "1505 9 9\n2619 11 3", "1505 13 9\n2619 11 3", "573 1 44\n2015 1 1", "595 2 44\n2015 2 1", "597 2 44\n2015 2 1", "246 21 0\n2619 11 5", "246 21 0\n5129 11 5", "431 2...
6AIZU
p00573 Commuter Pass_556
There are N stations in the city where JOI lives, and they are numbered 1, 2, ..., and N, respectively. In addition, there are M railway lines, numbered 1, 2, ..., and M, respectively. The railway line i (1 \ leq i \ leq M) connects station A_i and station B_i in both directions, and the fare is C_i yen. JOI lives nea...
#include<iostream> #include<algorithm> #include<vector> #include<queue> #include<functional> using namespace std; #define ll long long const ll linf = 1e15; struct edge{ int to; ll cost; }; struct node{ int from; ll cost; bool operator<(const node &n1) const { return n1.cost < cost; } }...
2C++
{ "input": [ "6 6\n1 6\n1 4\n1 2 1\n2 3 1\n3 5 1\n2 4 3\n4 5 2\n5 6 1", "6 6\n1 6\n1 4\n1 2 1\n2 3 1\n2 5 1\n2 4 3\n4 5 2\n5 6 1", "11 6\n1 6\n1 4\n1 2 1\n4 3 1\n2 5 1\n2 4 3\n4 5 0\n5 6 1", "11 6\n1 1\n1 2\n1 2 1\n4 3 1\n2 5 1\n2 4 3\n4 5 0\n5 6 1", "11 6\n2 6\n1 4\n1 2 1\n4 3 1\n2 5 1\n2 4 3\n4 ...
6AIZU
p00720 Earth Observation with a Mobile Robot Team_557
A new type of mobile robot has been developed for environmental earth observation. It moves around on the ground, acquiring and recording various sorts of observational data using high precision sensors. Robots of this type have short range wireless communication devices and can exchange observational data with ones ne...
#include<cmath> #include<queue> #include<cstdio> #include<string> #include<cassert> #include<algorithm> #define rep(i,n) for(int i=0;i<(n);i++) #define sq(x) ((x)*(x)) #define sqsum(x,y) (sq(x)+sq(y)) using namespace std; struct path{ int n,t[1001],x[1001],y[1001]; }; struct event{ // ロボットの接触イベント double t; ...
2C++
{ "input": [ "3 5 10\nred\n0 0 0\n5 0 0\ngreen\n0 5 5\n5 6 1\nblue\n0 40 5\n5 0 0\n3 10 5\natom\n0 47 32\n5 -10 -7\n10 1 0\npluto\n0 0 0\n7 0 0\n10 3 3\ngesicht\n0 25 7\n5 -7 -2\n10 -1 10\n4 100 7\nimpulse\n0 -500 0\n100 10 1\nfreedom\n0 -491 0\n100 9 2\ndestiny\n0 -472 0\n100 7 4\nstrike\n0 -482 0\n100 8 3\n0 0 ...
6AIZU
p00720 Earth Observation with a Mobile Robot Team_558
A new type of mobile robot has been developed for environmental earth observation. It moves around on the ground, acquiring and recording various sorts of observational data using high precision sensors. Robots of this type have short range wireless communication devices and can exchange observational data with ones ne...
from heapq import heappush, heappop import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N, T, R = map(int, readline().split()) if N == T == R == 0: return False S = [None]*N TS = [None]*N for i in range(N): s = readline().strip() S[i] = s pr...
3Python3
{ "input": [ "3 5 10\nred\n0 0 0\n5 0 0\ngreen\n0 5 5\n5 6 1\nblue\n0 40 5\n5 0 0\n3 10 5\natom\n0 47 32\n5 -10 -7\n10 1 0\npluto\n0 0 0\n7 0 0\n10 3 3\ngesicht\n0 25 7\n5 -7 -2\n10 -1 10\n4 100 7\nimpulse\n0 -500 0\n100 10 1\nfreedom\n0 -491 0\n100 9 2\ndestiny\n0 -472 0\n100 7 4\nstrike\n0 -482 0\n100 8 3\n0 0 ...
6AIZU
p00860 The Morning after Halloween_559
You are working for an amusement park as an operator of an obakeyashiki, or a haunted house, in which guests walk through narrow and dark corridors. The house is proud of their lively ghosts, which are actually robots remotely controlled by the operator, hiding here and there in the corridors. One morning, you found th...
#include <iostream> #include <sstream> #include <iomanip> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <bitset> #include <numeric> #include <climits> #include <cfloat> using namespace std; int h, w, n;...
2C++
{ "input": [ "5 5 2\n#####\n#A#B#\n# #\n#b#a#\n#####\n16 4 3\n################\n## ########## ##\n# ABCcba #\n################\n16 16 3\n################\n### ## # ##\n## # ## # c#\n# ## ########b#\n# ## # # # #\n# # ## # # ##\n## a# # # # #\n### ## #### ## #\n## # # # #\n# ####...
6AIZU
p00860 The Morning after Halloween_560
You are working for an amusement park as an operator of an obakeyashiki, or a haunted house, in which guests walk through narrow and dark corridors. The house is proud of their lively ghosts, which are actually robots remotely controlled by the operator, hiding here and there in the corridors. One morning, you found th...
import java.io.*; import java.util.*; public class Main { int W, H, N; int[][] field = new int[16][16]; int[] dx = {0, 1, 0, -1, 0}; int[] dy = {1, 0, -1, 0, 0}; short[][][] bfs = new short[16*16][16*16][16*16]; int[][] graph = new int[16*16][6]; Queue<int[]> Q = new ArrayDeque<>(); public void solve() { ...
4JAVA
{ "input": [ "5 5 2\n#####\n#A#B#\n# #\n#b#a#\n#####\n16 4 3\n################\n## ########## ##\n# ABCcba #\n################\n16 16 3\n################\n### ## # ##\n## # ## # c#\n# ## ########b#\n# ## # # # #\n# # ## # # ##\n## a# # # # #\n### ## #### ## #\n## # # # #\n# ####...
6AIZU
p00991 Grid_561
Two coordinates (a1, a2) and (b1, b2) on a two-dimensional grid of r × c are given. The cost of moving from a cell (e, f) to one of the cells (e + 1, f), (e-1, f), (e, f + 1), (e, f-1) is 1. And. You can also move between (e, c-1) and (e, 0), and between (r-1, f) and (0, f) at a cost of 1. At this time, find the number...
#include<iostream> #include<cmath> using namespace std; #define rep(i, n) for (int i = 0; i < int(n); ++i) const int MOD = 100000007; long long nck[1111][1111]; int main() { rep (i, 1111) nck[i][0] = 1; rep (i, 1110) rep (j, 1110) { nck[i + 1][j + 1] = (nck[i][j] + nck[i][j + 1]) % MOD; } int r, c...
2C++
{ "input": [ "500 500 0 0 200 200", "4 4 0 0 1 1", "4 4 0 0 3 3", "2 3 0 0 1 2", "500 500 0 0 107 200", "4 1 0 0 1 1", "4 4 1 0 3 3", "2 3 0 0 1 1", "500 500 0 0 107 239", "2 1 0 0 1 1", "678 500 0 0 107 168", "500 500 0 0 200 277", "500 500 1 0 107 239", "678 3...
6AIZU
p00991 Grid_562
Two coordinates (a1, a2) and (b1, b2) on a two-dimensional grid of r × c are given. The cost of moving from a cell (e, f) to one of the cells (e + 1, f), (e-1, f), (e, f + 1), (e, f-1) is 1. And. You can also move between (e, c-1) and (e, 0), and between (r-1, f) and (0, f) at a cost of 1. At this time, find the number...
# Edit: 2014/09/17 # Lang: Python3 # Time: 00.04s from math import factorial if __name__ == "__main__": r, c, ar, ac, br, bc = map(int, input().strip("\n").split(" ")) maxans = 100000007 # 100,000,007 # tate Row dr = min(abs(br - ar), r - abs(br - ar)) if 2 * dr == r: gainr = 2 else:...
3Python3
{ "input": [ "500 500 0 0 200 200", "4 4 0 0 1 1", "4 4 0 0 3 3", "2 3 0 0 1 2", "500 500 0 0 107 200", "4 1 0 0 1 1", "4 4 1 0 3 3", "2 3 0 0 1 1", "500 500 0 0 107 239", "2 1 0 0 1 1", "678 500 0 0 107 168", "500 500 0 0 200 277", "500 500 1 0 107 239", "678 3...
6AIZU
p00991 Grid_563
Two coordinates (a1, a2) and (b1, b2) on a two-dimensional grid of r × c are given. The cost of moving from a cell (e, f) to one of the cells (e + 1, f), (e-1, f), (e, f + 1), (e, f-1) is 1. And. You can also move between (e, c-1) and (e, 0), and between (r-1, f) and (0, f) at a cost of 1. At this time, find the number...
import java.util.Arrays; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; //Grid public class Main{ int r, c, si, sj, ti, tj; int[][] d = {{-1,0},{0,1},{1,0},{0,-1}}; int[][] dist, mem; int MOD = 100000007, INF = 1<<28; int get(int i, int j){ if(mem[i][j]!=-1)return mem[i][j]; ...
4JAVA
{ "input": [ "500 500 0 0 200 200", "4 4 0 0 1 1", "4 4 0 0 3 3", "2 3 0 0 1 2", "500 500 0 0 107 200", "4 1 0 0 1 1", "4 4 1 0 3 3", "2 3 0 0 1 1", "500 500 0 0 107 239", "2 1 0 0 1 1", "678 500 0 0 107 168", "500 500 0 0 200 277", "500 500 1 0 107 239", "678 3...
6AIZU
p01123 Let's Move Tiles!_564
<!-- Problem G --> Let's Move Tiles! You have a framed square board forming a grid of square cells. Each of the cells is either empty or with a square tile fitting in the cell engraved with a Roman character. You can tilt the board to one of four directions, away from you, toward you, to the left, or to the right, ...
#include <iostream> #include <string> #include <cstdio> #include <vector> #include <numeric> #include <cstdlib> #include <cctype> using namespace std; #define ALL(v) begin(v),end(v) #define REP(i,n) for(int i=0;i<(n);++i) #define RREP(i,n) for(int i=(n)-1;i>=0;--i) typedef long long LL; typedef vector<int> vint; con...
2C++
{ "input": [ "4\n..E.\n.AD.\nB...\n..C.\nD\n4\n..E.\n.AD.\nB...\n..C.\nDR\n3\n...\n.A.\nBC.\n((URD)3L)2R\n5\n...P.\nPPPPP\nPPP..\nPPPPP\n..P..\nLRLR(LR)12RLLR\n20\n....................\n....................\n.III..CC..PPP...CC..\n..I..C..C.P..P.C..C.\n..I..C....P..P.C....\n..I..C....PPP..C....\n..I..C....P....C.....
6AIZU
p01262 Adaptive Time Slicing Quantization_565
Nathan O. Davis is a student at the department of integrated systems. Today he learned digital quanti- zation in a class. It is a process that approximates analog data (e.g. electrical pressure) by a finite set of discrete values or integers. He had an assignment to write a program that quantizes the sequence of real ...
#include <cstdio> #include <iostream> #include <sstream> #include <fstream> #include <iomanip> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <bitset> #include <numeric> #include <climits> #include <cfloa...
2C++
{ "input": [ "5 2 1\n0.1 0.2 0.3 0.4 0.5\n6 2 2\n0.1 0.2 0.3 0.4 0.5 0.6\n0 0 0", "5 2 1\n0.1 0.2 0.3 0.5915213038191143 0.5\n6 2 2\n0.1 0.2 0.3 0.4 0.5 0.6\n0 0 0", "5 2 1\n0.1 0.3034585214713487 0.3 0.5915213038191143 0.5\n6 2 2\n0.1 0.2 0.3 0.4 0.5 0.6\n0 0 0", "5 2 1\n0.1 0.3034585214713487 1.0488...
6AIZU
p01262 Adaptive Time Slicing Quantization_566
Nathan O. Davis is a student at the department of integrated systems. Today he learned digital quanti- zation in a class. It is a process that approximates analog data (e.g. electrical pressure) by a finite set of discrete values or integers. He had an assignment to write a program that quantizes the sequence of real ...
import java.util.Arrays; import java.util.Scanner; //Adaptive Time Slicing Quantization public class Main{ int n, M, L, INF = 1<<29; double res; double[] a; double[][] dp; void dfs(int k, int m, double e){ if(m<0||res<=e)return; if(k==n){ if(m==0)res = e; return; } if(dp[k][m]!=-1){ res = Math...
4JAVA
{ "input": [ "5 2 1\n0.1 0.2 0.3 0.4 0.5\n6 2 2\n0.1 0.2 0.3 0.4 0.5 0.6\n0 0 0", "5 2 1\n0.1 0.2 0.3 0.5915213038191143 0.5\n6 2 2\n0.1 0.2 0.3 0.4 0.5 0.6\n0 0 0", "5 2 1\n0.1 0.3034585214713487 0.3 0.5915213038191143 0.5\n6 2 2\n0.1 0.2 0.3 0.4 0.5 0.6\n0 0 0", "5 2 1\n0.1 0.3034585214713487 1.0488...
6AIZU
p01422 Beautiful Currency_567
KM country has N kinds of coins and each coin has its value a_i. The king of the country, Kita_masa, thought that the current currency system is poor, and he decided to make it beautiful by changing the values of some (possibly no) coins. A currency system is called beautiful if each coin has an integer value and the...
#include <iostream> #include <vector> #include <algorithm> #include <iomanip> #include <cmath> using namespace std; const double INF = 1e18; const int lim = 200000; int main(){ int n; cin >> n; vector<int> a(n); for(int i=0; i<n; i++) cin >> a[i]; vector<double> dp(lim+1, 0); for(int i=0; i<n; i++){ vector<d...
2C++
{ "input": [ "3\n6 11 24", "3\n6 11 30", "3\n6 11 12", "3\n6 13 24", "3\n6 4 30", "3\n12 11 12", "3\n6 20 24", "3\n6 7 30", "3\n11 20 24", "3\n10 7 30", "3\n1 15 12", "3\n8 7 30", "3\n1 1 12", "3\n11 12 15", "3\n8 7 11", "3\n14 14 26", "3\n7 15 28", ...
6AIZU
p01422 Beautiful Currency_568
KM country has N kinds of coins and each coin has its value a_i. The king of the country, Kita_masa, thought that the current currency system is poor, and he decided to make it beautiful by changing the values of some (possibly no) coins. A currency system is called beautiful if each coin has an integer value and the...
# coding:utf-8 import sys input = sys.stdin.readline INF = float('inf') MOD = 10 ** 9 + 7 def inpl(): return list(map(int, input().split())) def solve(N): A = inpl() dp = [INF] * (A[0] * 2) for i in range(A[0]//2, A[0]*2): dp[i] = abs(i - A[0]) / A[0] # A[0]の価格を変えたときのconfusion ratio for...
3Python3
{ "input": [ "3\n6 11 24", "3\n6 11 30", "3\n6 11 12", "3\n6 13 24", "3\n6 4 30", "3\n12 11 12", "3\n6 20 24", "3\n6 7 30", "3\n11 20 24", "3\n10 7 30", "3\n1 15 12", "3\n8 7 30", "3\n1 1 12", "3\n11 12 15", "3\n8 7 11", "3\n14 14 26", "3\n7 15 28", ...
6AIZU
p01422 Beautiful Currency_569
KM country has N kinds of coins and each coin has its value a_i. The king of the country, Kita_masa, thought that the current currency system is poor, and he decided to make it beautiful by changing the values of some (possibly no) coins. A currency system is called beautiful if each coin has an integer value and the...
import java.util.Arrays; import java.util.Scanner; //Beautiful Currency public class Main{ void run(){ Scanner sc = new Scanner(System.in); int N = 200000; int n = sc.nextInt(); int[] a = new int[n]; for(int i=0;i<n;i++)a[i] = sc.nextInt(); double[][] dp = new double[n][N]; for(int i=0;i<n;i++)Arrays.f...
4JAVA
{ "input": [ "3\n6 11 24", "3\n6 11 30", "3\n6 11 12", "3\n6 13 24", "3\n6 4 30", "3\n12 11 12", "3\n6 20 24", "3\n6 7 30", "3\n11 20 24", "3\n10 7 30", "3\n1 15 12", "3\n8 7 30", "3\n1 1 12", "3\n11 12 15", "3\n8 7 11", "3\n14 14 26", "3\n7 15 28", ...
6AIZU
p01576 Exciting Bicycle_570
You happened to get a special bicycle. You can run with it incredibly fast because it has a turbo engine. You can't wait to try it off road to enjoy the power. You planned to go straight. The ground is very rough with ups and downs, and can be seen as a series of slopes (line segments) when seen from a lateral view. T...
#include<cmath> #include<cstdio> #include<vector> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; const long double EPS=1e-8; const long double PI=acos(-1); struct point{ long double x,y; point():x(0),y(0){} point(long double x,long double y):x(x),y(y){} point operator-(const point &a)const{ return...
2C++
{ "input": [ "2 10\n0 0\n10000 0", "4 50\n0 10000\n1 10000\n2 0\n10000 0", "5 10\n0 0\n10 10\n20 0\n30 10\n40 0", "4 10000\n0 0\n1 1\n9999 0\n10000 10000", "4 50\n0 10000\n1 10000\n2 1\n10000 0", "4 10001\n0 0\n1 1\n9999 0\n10000 10000", "4 100\n0 10000\n1 10000\n2 1\n10000 0", "4 1000...
6AIZU
p01738 Gravity Point_571
You are practicing a juggle that involves in a number of square tiles. They all look the same in their size, but actually there are three different kinds of the tiles, A, B and X. The kind of a tile can be distinguishable by its mass. All the tiles of the same kind have exactly the same mass. The mass of type A tiles i...
#include<bits/stdc++.h> using namespace std; double EPS=1e-9; struct L{ double a,b,c; L(double A,double B,double C){ a=A; b=B; c=C; } L(){} }; struct P{ double x,y; P(double X,double Y){ x=X; y=Y; } P(){} }; inline bool operator < (const P &a,const P &b){ if(a.x!=b.x){ return a.x<b.x; }else return...
2C++
{ "input": [ "3 3\n2 4 1 2 1\nXAX\nB.B\nXAX", "3 3\n2 4 1 0 1\nXAX\nB.B\nXAX", "3 6\n2 4 1 1 1\nXXA\nB.B\nXAX", "10 6\n1 9 1 2 3\nYXA\nB.B\nYXA", "10 6\n1 14 1 2 3\nYXA\nB.B\nYXA", "10 6\n1 24 1 2 3\nYXA\nB.B\nYXA", "10 6\n0 24 1 2 3\nYXA\nB.B\nYXA", "10 6\n0 34 1 2 3\nYXA\nB.B\nYXA", ...
6AIZU
p01878 Destiny Draw_572
G: Destiny Draw- problem Mr. D will play a card game. This card game uses a pile of N cards. Also, the pile cards are numbered 1, 2, 3, ..., N in order from the top. He can't afford to be defeated, carrying everything that starts with D, but unfortunately Mr. D isn't good at card games. Therefore, I decided to win b...
#include <bits/stdc++.h> using namespace std; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; typedef pair<LL, LL> PLL; #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define EB emplace_ba...
2C++
{ "input": [ "4 1 1 6\n3 2 3", "4 1 1 12\n3 2 3", "4 1 1 16\n3 2 3", "4 1 1 16\n2 2 3", "4 1 1 6\n3 1 3", "4 0 1 12\n3 2 3", "4 1 1 22\n3 2 3", "4 1 1 31\n2 2 3", "4 1 1 6\n3 1 1", "4 0 1 12\n3 2 2", "4 1 2 22\n3 2 3", "8 1 1 31\n2 2 3", "4 0 1 6\n3 1 1", "4 1 4...
6AIZU
p01878 Destiny Draw_573
G: Destiny Draw- problem Mr. D will play a card game. This card game uses a pile of N cards. Also, the pile cards are numbered 1, 2, 3, ..., N in order from the top. He can't afford to be defeated, carrying everything that starts with D, but unfortunately Mr. D isn't good at card games. Therefore, I decided to win b...
import java.util.*; public class Main { static final long MODULO = 1_000_000_000 + 7; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int K = sc.nextInt(); int C = sc.nextInt() - 1; int T = sc.nextInt(); int[] a = new int[K]; int[] b = new int[K]; ...
4JAVA
{ "input": [ "4 1 1 6\n3 2 3", "4 1 1 12\n3 2 3", "4 1 1 16\n3 2 3", "4 1 1 16\n2 2 3", "4 1 1 6\n3 1 3", "4 0 1 12\n3 2 3", "4 1 1 22\n3 2 3", "4 1 1 31\n2 2 3", "4 1 1 6\n3 1 1", "4 0 1 12\n3 2 2", "4 1 2 22\n3 2 3", "8 1 1 31\n2 2 3", "4 0 1 6\n3 1 1", "4 1 4...
6AIZU
p02014 Rough Sorting_574
For skilled programmers, it is very easy to implement a sorting function. Moreover, they often avoid full sorting to reduce computation time if it is not necessary. Here, we consider "rough sorting" which sorts an array except for some pairs of elements. More formally, we define an array is "$K$-roughly sorted" if an a...
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; #define ll long long #define ull unsigned long long #define rep(i,n,N) for(ll i=n;i<=N;++i) #define rap(i,n,N) for(ll i=n;i>=N;--i) #define mp make_pair #define pb push_back #define pob pop_back #define pf push_front #define pof pop_front #define...
2C++
{ "input": [ "3 100\n3\n2\n1", "3 1\n3\n2\n1", "5 3\n5\n3\n2\n1\n4", "5 3\n1\n2\n3\n4\n5", "3 2\n3\n2\n1", "3 4\n3\n2\n1", "3 0\n3\n2\n1", "3 001\n3\n2\n1", "5 1\n5\n3\n2\n1\n4", "5 6\n1\n2\n3\n4\n5", "5 2\n5\n3\n2\n1\n4", "3 100\n3\n1\n2", "1 2\n1\n2\n3\n4\n5", ...
6AIZU
p02157 Shuffle 2_575
Problem There is a bundle of $ n $ cards, with $ i $ written on the $ i $ th card from the bottom. Shuffle this bundle as defined below $ q $ times. * When looking at the bundle from below, consider a bundle $ x $ made by stacking odd-numbered cards on top, and a bundle $ y $ made by stacking even-numbered cards on ...
#include<bits/stdc++.h> using namespace std; using Int = long long; template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} struct FastIO{ FastIO(){ cin.tie(0); ios::sync_with_stdio(0); } }fastio_beet; //IN...
2C++
{ "input": [ "4 2 3 1", "7834164883628 15 2189823423122 5771212644938", "4 2 1 1", "4 1 1 4", "6 2 3 1", "7834164883628 15 2189823423122 7725883688276", "4 2 1 4", "7 1 3 2", "4 3 3 1", "4 2 2 1", "6 2 1 1", "4 4 1 1", "7834164883628 43 2189823423122 4045849112944",...
6AIZU
p02298 Is-Convex_576
For a given polygon g, print "1" if g is a convex polygon, "0" otherwise. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees. g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon. The line segment con...
#!/usr/bin/env python import sys import math import itertools as it from collections import deque sys.setrecursionlimit(10000000) n = input() lst = [] for loop in range(n): x, y = map(int, raw_input().split()) lst.append((x, y)) lst += lst[:2] ans = 1 for i in range(1, n + 1): x0, y0 = lst[i] x1, y1...
1Python2
{ "input": [ "5\n0 0\n2 0\n1 1\n2 2\n0 2", "4\n0 0\n3 1\n2 3\n0 3", "5\n0 0\n2 1\n1 1\n2 2\n0 2", "4\n0 0\n3 0\n2 1\n0 3", "4\n0 0\n3 1\n2 1\n0 3", "5\n0 0\n3 1\n1 1\n2 2\n0 2", "5\n0 0\n3 1\n1 1\n3 2\n0 2", "4\n0 0\n3 0\n2 0\n0 3", "5\n0 0\n3 1\n1 1\n3 2\n1 2", "4\n0 0\n3 1\n2...
6AIZU
p02298 Is-Convex_577
For a given polygon g, print "1" if g is a convex polygon, "0" otherwise. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees. g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon. The line segment con...
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; double x[10010],y[10010]; double ans; int pd; int n; int main(){ cin>>n; for(int i=1;i<=n;i++){ cin>>x[i]>>y[i]; x[i+n]=x[i],y[i+n]=y[i]; } for(int j=1;j<=n-1;j++){ double xx=x[j],yy=y[j]...
2C++
{ "input": [ "5\n0 0\n2 0\n1 1\n2 2\n0 2", "4\n0 0\n3 1\n2 3\n0 3", "5\n0 0\n2 1\n1 1\n2 2\n0 2", "4\n0 0\n3 0\n2 1\n0 3", "4\n0 0\n3 1\n2 1\n0 3", "5\n0 0\n3 1\n1 1\n2 2\n0 2", "5\n0 0\n3 1\n1 1\n3 2\n0 2", "4\n0 0\n3 0\n2 0\n0 3", "5\n0 0\n3 1\n1 1\n3 2\n1 2", "4\n0 0\n3 1\n2...
6AIZU
p02298 Is-Convex_578
For a given polygon g, print "1" if g is a convex polygon, "0" otherwise. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees. g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon. The line segment con...
from collections import defaultdict,deque import sys,heapq,bisect,math,itertools,string,queue sys.setrecursionlimit(10**8) INF = float('inf') mod = 10**9+7 eps = 10**-7 def inp(): return int(input()) def inpl(): return list(map(int, input().split())) def inpl_str(): return list(input().split()) #######################...
3Python3
{ "input": [ "5\n0 0\n2 0\n1 1\n2 2\n0 2", "4\n0 0\n3 1\n2 3\n0 3", "5\n0 0\n2 1\n1 1\n2 2\n0 2", "4\n0 0\n3 0\n2 1\n0 3", "4\n0 0\n3 1\n2 1\n0 3", "5\n0 0\n3 1\n1 1\n2 2\n0 2", "5\n0 0\n3 1\n1 1\n3 2\n0 2", "4\n0 0\n3 0\n2 0\n0 3", "5\n0 0\n3 1\n1 1\n3 2\n1 2", "4\n0 0\n3 1\n2...
6AIZU
p02298 Is-Convex_579
For a given polygon g, print "1" if g is a convex polygon, "0" otherwise. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees. g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon. The line segment con...
import java.util.*; import java.io.*; import java.lang.*; public class Main { static int INF = 1000000000; static int MAXN = 31; public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); int[][] point = new int[n][2]; for (int i = 0; i < n; ++i) { point...
4JAVA
{ "input": [ "5\n0 0\n2 0\n1 1\n2 2\n0 2", "4\n0 0\n3 1\n2 3\n0 3", "5\n0 0\n2 1\n1 1\n2 2\n0 2", "4\n0 0\n3 0\n2 1\n0 3", "4\n0 0\n3 1\n2 1\n0 3", "5\n0 0\n3 1\n1 1\n2 2\n0 2", "5\n0 0\n3 1\n1 1\n3 2\n0 2", "4\n0 0\n3 0\n2 0\n0 3", "5\n0 0\n3 1\n1 1\n3 2\n1 2", "4\n0 0\n3 1\n2...
6AIZU
p02445 Swap_580
Write a program which reads a sequence of integers $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and swap specified elements by a list of the following operation: * swapRange($b, e, t$): For each integer $k$ ($0 \leq k < (e - b)$, swap element $(b + k)$ and element $(t + k)$. Constraints * $1 \leq n \leq 1,000$ * $-1,000,000,0...
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <map> #include <numeric> #include <string> #include <cmath> #include <iomanip> #include <queue> #include <list> #include <stack> #include <cctype> #include <cmath> using namespace std; /* typedef */ typedef long long ll; /* consta...
2C++
{ "input": [ "11\n1 2 3 4 5 6 7 8 9 10 11\n1\n1 4 7", "11\n1 2 3 4 5 6 7 8 9 10 11\n2\n1 4 7", "11\n1 2 3 4 5 6 2 8 9 10 11\n2\n1 4 1", "11\n1 2 3 3 5 6 2 8 9 10 11\n2\n1 4 1", "11\n1 2 3 3 5 6 2 8 18 10 11\n2\n1 4 1", "11\n1 0 3 3 5 6 2 8 18 10 11\n2\n1 4 1", "11\n1 0 3 3 5 6 2 8 34 10 11...
6AIZU
p02445 Swap_581
Write a program which reads a sequence of integers $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and swap specified elements by a list of the following operation: * swapRange($b, e, t$): For each integer $k$ ($0 \leq k < (e - b)$, swap element $(b + k)$ and element $(t + k)$. Constraints * $1 \leq n \leq 1,000$ * $-1,000,000,0...
n = int(input()) num = list(map(int, input().split())) q = int(input()) for _ in range(q): b, e, t = map(int, input().split()) for i in range(e-b): num[b+i], num[t+i] = num[t+i], num[b+i] print(' '.join(str(n) for n in num))
3Python3
{ "input": [ "11\n1 2 3 4 5 6 7 8 9 10 11\n1\n1 4 7", "11\n1 2 3 4 5 6 7 8 9 10 11\n2\n1 4 7", "11\n1 2 3 4 5 6 2 8 9 10 11\n2\n1 4 1", "11\n1 2 3 3 5 6 2 8 9 10 11\n2\n1 4 1", "11\n1 2 3 3 5 6 2 8 18 10 11\n2\n1 4 1", "11\n1 0 3 3 5 6 2 8 18 10 11\n2\n1 4 1", "11\n1 0 3 3 5 6 2 8 34 10 11...
6AIZU
p02445 Swap_582
Write a program which reads a sequence of integers $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and swap specified elements by a list of the following operation: * swapRange($b, e, t$): For each integer $k$ ($0 \leq k < (e - b)$, swap element $(b + k)$ and element $(t + k)$. Constraints * $1 \leq n \leq 1,000$ * $-1,000,000,0...
import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int progA[] = new int[n]; int progB[] = new int[n]; for(int i = 0; i < n; i++) { progA[i] = sc.nextInt(); } int q = sc.nextInt()...
4JAVA
{ "input": [ "11\n1 2 3 4 5 6 7 8 9 10 11\n1\n1 4 7", "11\n1 2 3 4 5 6 7 8 9 10 11\n2\n1 4 7", "11\n1 2 3 4 5 6 2 8 9 10 11\n2\n1 4 1", "11\n1 2 3 3 5 6 2 8 9 10 11\n2\n1 4 1", "11\n1 2 3 3 5 6 2 8 18 10 11\n2\n1 4 1", "11\n1 0 3 3 5 6 2 8 18 10 11\n2\n1 4 1", "11\n1 0 3 3 5 6 2 8 34 10 11...
6AIZU
bogosort_583
Recently Johnny have learned bogosort sorting algorithm. He thought that it is too ineffective. So he decided to improve it. As you may know this algorithm shuffles the sequence randomly until it is sorted. Johnny decided that we don't need to shuffle the whole sequence every time. If after the last shuffle several fir...
def gcd(a,b): if b==0: return a return gcd(b,a%b) def simplify(a,b): g=gcd(a,b) return (a/g,b/g) E = {0:(0,1), 1:(1,1), 2:(2,1)} for i in xrange(3,151): a,b=E[i-1] c,d=E[i-2] E[i]=simplify(b*d*(i*i-3*i+3)+2*a*d*(i-1)-b*c,b*d*(2*i-3)) t=input() while t: t-=1 n=input() a,b=E[n] if b>1: print "%d/%d" % (...
1Python2
{ "input": [ "3\n2\n6\n10", "3\n2\n4\n10", "3\n2\n6\n12", "3\n4\n6\n12", "3\n4\n6\n19", "3\n2\n4\n19", "3\n2\n3\n12", "3\n4\n11\n12", "3\n4\n5\n19", "3\n2\n2\n19", "3\n2\n3\n21", "3\n4\n7\n19", "3\n2\n2\n23", "3\n2\n3\n7", "3\n4\n7\n11", "3\n4\n2\n23", ...
1CODECHEF
colarr_584
Chef had a hard time arguing with his friend, and after getting a great old kick Chef saw a colored array with N cells, numbered from 1 to N. The kick was so strong that Chef suddenly understood the rules of the game. Each cell is painted with a color. Here the colors are numbered from 1 to M. For any cell i, Chef c...
t = int(raw_input()) for _ in range(t): n, m, k = map(int, raw_input().split()) a = map(int, raw_input().split()) b = [] # gain for _ in range(n): b.append(map(int, raw_input().split())) c = [] # loss for _ in range(n): c.append(map(int, raw_input().split())) init_...
1Python2
{ "input": [ "1\n4 2 1\n1 1 2 2\n1 1\n1 1\n1 1\n3 1\n0 1\n0 1\n1 0\n1 0" ], "output": [ "5" ] }
1CODECHEF
gameaam_585
Two players are playing a game. The game is played on a sequence of positive integer pairs. The players make their moves alternatively. During his move the player chooses a pair and decreases the larger integer in the pair by a positive multiple of the smaller integer in the pair in such a way that both integers in the...
#!/usr/bin/env python #-*- coding:utf-8 -*- def convert_pair(a, b): res = [] if a < b: a, b = b, a while b: res.append(a / b) a, b = b, a % b res[-1] -= 1 while res[-1] == 0: del res[-1] return tuple(res) def grundy(col): res = 0 for N in reversed(col)...
1Python2
{ "input": [ "3\n1\n2 3\n2\n4 5\n5 6\n2\n2 3\n3 5", "3\n1\n2 3\n2\n4 5\n5 6\n2\n2 3\n1 5", "3\n1\n2 3\n2\n4 5\n5 6\n1\n2 3\n3 5", "3\n1\n1 3\n2\n6 5\n5 6\n1\n2 6\n5 5", "3\n1\n2 3\n2\n4 5\n5 3\n1\n2 3\n3 5", "3\n1\n2 3\n2\n6 2\n5 6\n1\n2 6\n3 5", "3\n1\n2 1\n2\n6 5\n5 6\n1\n2 3\n1 5", ...
1CODECHEF
lucky5_586
Chef loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Chef has a positive integer N. He can apply any of the following operations as many times as he want...
t=input() while t: t-=1 n=raw_input().strip() print len(n)-n.count('4')-n.count('7')
1Python2
{ "input": [ "3\n25\n46\n99", "3\n2\n46\n99", "3\n0\n7\n61", "3\n25\n46\n24", "3\n2\n60\n99", "3\n0\n8\n24", "3\n25\n46\n35", "3\n0\n5\n153", "3\n0\n12\n5", "3\n61\n4\n32", "3\n4\n1\n132", "3\n0\n13\n131", "3\n3\n4\n70", "3\n15\n15\n34", "3\n15\n15\n19", ...
1CODECHEF
proposal_587
In PrimeLand, there existed a very handsome young prince named Prima. He greatly desired the Princess of Mathematics – Facie. However, before accepting his hand in marriage, Facie asked Prima to solve the following problem: The figure below shows a simple multiplication problem. However, not all the decimal digits ar...
def isvalid(s, c): if c.difference(s): return False return True def main(): n = input() l = raw_input().split() s = set(l) answer = 0 for _ in xrange(111, 1000): a = [i for i in str(_)] if isvalid(s, set(a)): for __ in xrange(11, 100): b = ...
1Python2
{ "input": [ "5\n2 3 4 6 8", "5\n2 3 0 6 8", "5\n2 3 4 6 5", "5\n2 3 4 6 7", "5\n2 3 0 6 7", "5\n2 -1 8 6 4", "5\n6 0 8 5 2", "5\n6 0 4 5 2", "5\n3 1 9 6 15", "5\n3 1 9 4 15", "5\n3 5 9 1 2", "5\n3 5 4 1 2", "5\n3 9 4 1 2", "5\n5 18 4 1 2", "5\n5 8 4 1 2", ...
1CODECHEF
tech07_588
You are given a square with 'n' points on each side of the square. None of these points co-incide with the corners of this square. You have to compute the total number of triangles that can be formed using these '4n' points (n points on each side of the square) as vertices of the triangle. Input First line contains ...
t = int(input()) for i in range(t): n = int(input()) print(int(10 * n * n * n - 6 * n * n))
1Python2
{ "input": [ "1\n1", "1\n2", "1\n0", "1\n-1", "1\n-2", "1\n-4", "1\n-5", "1\n-8", "1\n-11", "1\n3", "1\n4", "1\n6", "1\n10", "1\n-3", "1\n-7", "1\n11", "1\n17", "1\n30", "1\n7", "1\n9", "1\n16", "1\n31", "1\n58", "1\n60", ...
1CODECHEF
1012_B. Chemical table_589
Innopolis University scientists continue to investigate the periodic table. There are n·m known elements and they form a periodic table: a rectangle with n rows and m columns. Each element can be described by its coordinates (r, c) (1 ≤ r ≤ n, 1 ≤ c ≤ m) in the table. Recently scientists discovered that for every four...
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 10; int fa[N]; int n, m, q; int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); } void solve() { scanf("%d%d%d", &n, &m, &q); for (int i = 1; i <= n + m; i++) { fa[i] = i; } int res = n + m - 1; for (int i = 1; i <= q; i++) { ...
2C++
{ "input": [ "1 5 3\n1 3\n1 1\n1 5\n", "2 2 3\n1 2\n2 2\n2 1\n", "4 3 6\n1 2\n1 3\n2 2\n2 3\n3 1\n3 3\n", "20 20 20\n18 16\n4 20\n2 5\n7 4\n11 13\n6 10\n20 8\n14 6\n3 12\n5 1\n16 7\n10 9\n1 11\n12 18\n19 15\n13 19\n17 3\n9 17\n15 2\n8 14\n", "20 20 1\n17 13\n", "1 1 0\n", "10000 9999 1\n57...
2CODEFORCES
1012_B. Chemical table_590
Innopolis University scientists continue to investigate the periodic table. There are n·m known elements and they form a periodic table: a rectangle with n rows and m columns. Each element can be described by its coordinates (r, c) (1 ≤ r ≤ n, 1 ≤ c ≤ m) in the table. Recently scientists discovered that for every four...
class UnionFind: def __init__(self, n): self.par = [-1]*n self.rank = [0]*n def Find(self, x): if self.par[x] < 0: return x else: self.par[x] = self.Find(self.par[x]) return self.par[x] def Unite(self, x, y): x = self.Find(x) ...
3Python3
{ "input": [ "1 5 3\n1 3\n1 1\n1 5\n", "2 2 3\n1 2\n2 2\n2 1\n", "4 3 6\n1 2\n1 3\n2 2\n2 3\n3 1\n3 3\n", "20 20 20\n18 16\n4 20\n2 5\n7 4\n11 13\n6 10\n20 8\n14 6\n3 12\n5 1\n16 7\n10 9\n1 11\n12 18\n19 15\n13 19\n17 3\n9 17\n15 2\n8 14\n", "20 20 1\n17 13\n", "1 1 0\n", "10000 9999 1\n57...
2CODEFORCES
1012_B. Chemical table_591
Innopolis University scientists continue to investigate the periodic table. There are n·m known elements and they form a periodic table: a rectangle with n rows and m columns. Each element can be described by its coordinates (r, c) (1 ≤ r ≤ n, 1 ≤ c ≤ m) in the table. Recently scientists discovered that for every four...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.HashSet; import java.io.FilterInputStream; import java.io.BufferedInputStream; import java.util.Set; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at ...
4JAVA
{ "input": [ "1 5 3\n1 3\n1 1\n1 5\n", "2 2 3\n1 2\n2 2\n2 1\n", "4 3 6\n1 2\n1 3\n2 2\n2 3\n3 1\n3 3\n", "20 20 20\n18 16\n4 20\n2 5\n7 4\n11 13\n6 10\n20 8\n14 6\n3 12\n5 1\n16 7\n10 9\n1 11\n12 18\n19 15\n13 19\n17 3\n9 17\n15 2\n8 14\n", "20 20 1\n17 13\n", "1 1 0\n", "10000 9999 1\n57...
2CODEFORCES
1037_B. Reach Median_592
You are given an array a of n integers and an integer s. It is guaranteed that n is odd. In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to s. The median of the array with odd length is the ...
n,s = map(int, raw_input().split()) lis = map(int, raw_input().split()) lis = sorted(lis) val = lis[n/2] if val == s: print 0 else: if val < s: ans = 0 for i in range(n/2, n): if lis[i] < s: ans += s-lis[i] else: break print ans ...
1Python2
{ "input": [ "3 8\n6 5 8\n", "7 20\n21 15 12 11 20 19 12\n", "3 1\n1 2 5\n", "1 1\n100000\n", "5 1\n2 2 4 6 1\n", "3 10\n5 5 10\n", "1 1\n1\n", "3 4\n1 2 5\n", "1 100\n88\n", "1 100\n105\n", "3 2\n1 2 5\n", "3 10\n5 3 10\n", "3 4\n0 2 5\n", "1 100\n5\n", "7 ...
2CODEFORCES
1037_B. Reach Median_593
You are given an array a of n integers and an integer s. It is guaranteed that n is odd. In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to s. The median of the array with odd length is the ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int add(int x, int y, int CMOD = MOD) { return (0LL + x + y) % CMOD; } int mult(int x, int y, int CMOD = MOD) { return (1LL * x * y) % CMOD; } long long fast_expo(long long x, long long y, long long CMOD = MOD) { if (x == 0) return 0; if (y == 0...
2C++
{ "input": [ "3 8\n6 5 8\n", "7 20\n21 15 12 11 20 19 12\n", "3 1\n1 2 5\n", "1 1\n100000\n", "5 1\n2 2 4 6 1\n", "3 10\n5 5 10\n", "1 1\n1\n", "3 4\n1 2 5\n", "1 100\n88\n", "1 100\n105\n", "3 2\n1 2 5\n", "3 10\n5 3 10\n", "3 4\n0 2 5\n", "1 100\n5\n", "7 ...
2CODEFORCES
1037_B. Reach Median_594
You are given an array a of n integers and an integer s. It is guaranteed that n is odd. In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to s. The median of the array with odd length is the ...
# -*- coding: utf-8 -*- # @Date : 2018-09-03 08:46:01 # @Author : raj lath (oorja.halt@gmail.com) # @Link : http://codeforces.com/contest/1037/problem/B # @Version : 1.0.0 import os from sys import stdin max_val=int(10e12) min_val=int(-10e12) def read_int() : return int(stdin.readline()) def read_ints() ...
3Python3
{ "input": [ "3 8\n6 5 8\n", "7 20\n21 15 12 11 20 19 12\n", "3 1\n1 2 5\n", "1 1\n100000\n", "5 1\n2 2 4 6 1\n", "3 10\n5 5 10\n", "1 1\n1\n", "3 4\n1 2 5\n", "1 100\n88\n", "1 100\n105\n", "3 2\n1 2 5\n", "3 10\n5 3 10\n", "3 4\n0 2 5\n", "1 100\n5\n", "7 ...
2CODEFORCES
1037_B. Reach Median_595
You are given an array a of n integers and an integer s. It is guaranteed that n is odd. In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to s. The median of the array with odd length is the ...
import java.util.*; import java.io.*; import java.lang.*; import java.math.*; public class cf2 implements Runnable { public void run(){ InputReader in = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); int n=in.nextInt(); long s=in.nextLong(); long[] a=new long[n]; for(...
4JAVA
{ "input": [ "3 8\n6 5 8\n", "7 20\n21 15 12 11 20 19 12\n", "3 1\n1 2 5\n", "1 1\n100000\n", "5 1\n2 2 4 6 1\n", "3 10\n5 5 10\n", "1 1\n1\n", "3 4\n1 2 5\n", "1 100\n88\n", "1 100\n105\n", "3 2\n1 2 5\n", "3 10\n5 3 10\n", "3 4\n0 2 5\n", "1 100\n5\n", "7 ...
2CODEFORCES
105_C. Item World_596
Each item in the game has a level. The higher the level is, the higher basic parameters the item has. We shall consider only the following basic parameters: attack (atk), defense (def) and resistance to different types of impact (res). Each item belongs to one class. In this problem we will only consider three of such...
#!/usr/bin/env python # -*- coding: utf-8 -*- from sys import stdout from collections import defaultdict n = int(raw_input()) things = {} for _ in xrange(n): name, cls, atk, df, res, size = raw_input().split() things[name] = [cls] + map(int, [atk, df, res, size]) tk = sum([x[4] for x in things.values()]) k = i...
1Python2
{ "input": [ "4\nsword weapon 10 2 3 2\npagstarmor armor 0 15 3 1\niceorb orb 3 2 13 2\nlongbow weapon 9 1 2 1\n6\nmike gladiator 5 longbow\nbobby sentry 6 pagstarmor\npetr gladiator 7 iceorb\nteddy physician 6 sword\nblackjack sentry 8 sword\njoe physician 6 iceorb\n", "4\nsword weapon 10 2 3 2\npagstarmor a...
2CODEFORCES
105_C. Item World_597
Each item in the game has a level. The higher the level is, the higher basic parameters the item has. We shall consider only the following basic parameters: attack (atk), defense (def) and resistance to different types of impact (res). Each item belongs to one class. In this problem we will only consider three of such...
#include <bits/stdc++.h> using namespace std; int n, m; struct lut { string name; int cl; int val; int size; }; struct an { string name; string whr; int cl; int val; int num; }; vector<lut> l; vector<an> anim; vector<an> d[3]; vector<bool> used; int all_size; void Inputdata() { cin >> n; l.resize(...
2C++
{ "input": [ "4\nsword weapon 10 2 3 2\npagstarmor armor 0 15 3 1\niceorb orb 3 2 13 2\nlongbow weapon 9 1 2 1\n6\nmike gladiator 5 longbow\nbobby sentry 6 pagstarmor\npetr gladiator 7 iceorb\nteddy physician 6 sword\nblackjack sentry 8 sword\njoe physician 6 iceorb\n", "4\nsword weapon 10 2 3 2\npagstarmor a...
2CODEFORCES
105_C. Item World_598
Each item in the game has a level. The higher the level is, the higher basic parameters the item has. We shall consider only the following basic parameters: attack (atk), defense (def) and resistance to different types of impact (res). Each item belongs to one class. In this problem we will only consider three of such...
# written with help of failed tests def searchBest(iType, number, rType, countResidents): global items, equipped best = 0 ret = None for item, params in items.items(): if params[0] == iType: val = int(params[number]) if countResidents: for resid in equippe...
3Python3
{ "input": [ "4\nsword weapon 10 2 3 2\npagstarmor armor 0 15 3 1\niceorb orb 3 2 13 2\nlongbow weapon 9 1 2 1\n6\nmike gladiator 5 longbow\nbobby sentry 6 pagstarmor\npetr gladiator 7 iceorb\nteddy physician 6 sword\nblackjack sentry 8 sword\njoe physician 6 iceorb\n", "4\nsword weapon 10 2 3 2\npagstarmor a...
2CODEFORCES
105_C. Item World_599
Each item in the game has a level. The higher the level is, the higher basic parameters the item has. We shall consider only the following basic parameters: attack (atk), defense (def) and resistance to different types of impact (res). Each item belongs to one class. In this problem we will only consider three of such...
import static java.lang.Math.min; import java.io.*; import java.util.*; public class C { static String[] types = { "weapon", "armor", "orb" }; static String[] bonusTypes = { "gladiator", "sentry", "physician" }; private void solve() throws IOException { int n = nextInt(); Map<String, Item> hm = new HashMap<S...
4JAVA
{ "input": [ "4\nsword weapon 10 2 3 2\npagstarmor armor 0 15 3 1\niceorb orb 3 2 13 2\nlongbow weapon 9 1 2 1\n6\nmike gladiator 5 longbow\nbobby sentry 6 pagstarmor\npetr gladiator 7 iceorb\nteddy physician 6 sword\nblackjack sentry 8 sword\njoe physician 6 iceorb\n", "4\nsword weapon 10 2 3 2\npagstarmor a...
2CODEFORCES