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
p03254 AtCoder Grand Contest 027 - Candy Distribution Again_1100
There are N children, numbered 1, 2, ..., N. Snuke has decided to distribute x sweets among them. He needs to give out all the x sweets, but some of the children may get zero sweets. For each i (1 \leq i \leq N), Child i will be happy if he/she gets exactly a_i sweets. Snuke is trying to maximize the number of happy ...
n, x = map(int, input().split()) a = list(map(int, input().split())) a.sort() ans = 0 for i in a: if x < i: break ans += 1 x -= i else: if x > 0: ans -= 1 print(ans)
3Python3
{ "input": [ "4 1111\n1 10 100 1000", "3 70\n20 30 10", "3 10\n20 30 10", "2 10\n20 20", "3 70\n20 30 5", "3 10\n20 18 10", "2 10\n29 20", "4 1111\n1 5 100 1000", "4 1111\n-1 2 110 1000", "3 70\n20 49 5", "3 10\n20 9 10", "2 10\n30 20", "3 70\n4 49 5", "3 10\n20...
5ATCODER
p03254 AtCoder Grand Contest 027 - Candy Distribution Again_1101
There are N children, numbered 1, 2, ..., N. Snuke has decided to distribute x sweets among them. He needs to give out all the x sweets, but some of the children may get zero sweets. For each i (1 \leq i \leq N), Child i will be happy if he/she gets exactly a_i sweets. Snuke is trying to maximize the number of happy ...
import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); int x = scanner.nextInt(); List<Integer> lis...
4JAVA
{ "input": [ "4 1111\n1 10 100 1000", "3 70\n20 30 10", "3 10\n20 30 10", "2 10\n20 20", "3 70\n20 30 5", "3 10\n20 18 10", "2 10\n29 20", "4 1111\n1 5 100 1000", "4 1111\n-1 2 110 1000", "3 70\n20 49 5", "3 10\n20 9 10", "2 10\n30 20", "3 70\n4 49 5", "3 10\n20...
5ATCODER
p03407 AtCoder Beginner Contest 091 - Two Coins_1102
An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan. Constraints * All input values a...
x = raw_input().split() if (int(x[2]) <= int(x[0])+int(x[1])): print("Yes") else: print("No")
1Python2
{ "input": [ "500 100 1000", "19 123 143", "19 123 142", "50 100 120", "500 000 1000", "31 123 143", "19 123 141", "50 100 127", "500 101 1000", "55 123 143", "1 123 141", "50 000 127", "500 001 1000", "64 123 143", "1 123 281", "50 001 127", "726 10...
5ATCODER
p03407 AtCoder Beginner Contest 091 - Two Coins_1103
An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan. Constraints * All input values a...
#import<iostream> int main(){int A,B,C;std::cin>>A>>B>>C;puts(A+B<C?"No":"Yes");}
2C++
{ "input": [ "500 100 1000", "19 123 143", "19 123 142", "50 100 120", "500 000 1000", "31 123 143", "19 123 141", "50 100 127", "500 101 1000", "55 123 143", "1 123 141", "50 000 127", "500 001 1000", "64 123 143", "1 123 281", "50 001 127", "726 10...
5ATCODER
p03407 AtCoder Beginner Contest 091 - Two Coins_1104
An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan. Constraints * All input values a...
a,b,c = map(int,input().split()) if c > a + b: print('No') else: print('Yes')
3Python3
{ "input": [ "500 100 1000", "19 123 143", "19 123 142", "50 100 120", "500 000 1000", "31 123 143", "19 123 141", "50 100 127", "500 101 1000", "55 123 143", "1 123 141", "50 000 127", "500 001 1000", "64 123 143", "1 123 281", "50 001 127", "726 10...
5ATCODER
p03407 AtCoder Beginner Contest 091 - Two Coins_1105
An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan. Constraints * All input values a...
import java.util.Scanner; public class Main { public static void main(String[] args) { final Scanner sc = new Scanner(System.in); int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt(); if(a+b < c) { System.out.println("No"); } else { System.out.println("Yes"); } } }
4JAVA
{ "input": [ "500 100 1000", "19 123 143", "19 123 142", "50 100 120", "500 000 1000", "31 123 143", "19 123 141", "50 100 127", "500 101 1000", "55 123 143", "1 123 141", "50 000 127", "500 001 1000", "64 123 143", "1 123 281", "50 001 127", "726 10...
5ATCODER
p03570 CODE FESTIVAL 2017 qual C - Yet Another Palindrome Partitioning_1106
We have a string s consisting of lowercase English letters. Snuke is partitioning s into some number of non-empty substrings. Let the subtrings obtained be s_1, s_2, ..., s_N from left to right. (Here, s = s_1 + s_2 + ... + s_N holds.) Snuke wants to satisfy the following condition: * For each i (1 \leq i \leq N), it ...
#include <bits/stdc++.h> using namespace std; char ax[200005]; int dp[200005]; int len; map<int,int> m; int main() { scanf("%s",ax); int i,j,a,b,now=0; len = strlen(ax); m[0]=len; for(i=len-1;i>=0;i--){ now ^= (1<<(ax[i]-'a')); dp[i]=len-i; if(m.count(now))dp[i]=min(dp[i],dp...
2C++
{ "input": [ "byebye", "abcdefghijklmnopqrstuvwxyz", "aabxyyzz", "abcabcxabcx", "byeybe", "zyxwvutsrqponmlkjihgfedcba", "aabwyyzz", "axcabcbabcx", "zyxwvutsrqponmlkjihgfedbba", "aabwyzzz", "eybcxb", "abzwxayz", "ayxwvutsrqponmlkiihgfedbbz", "yccabbcacxa", "a...
5ATCODER
p03570 CODE FESTIVAL 2017 qual C - Yet Another Palindrome Partitioning_1107
We have a string s consisting of lowercase English letters. Snuke is partitioning s into some number of non-empty substrings. Let the subtrings obtained be s_1, s_2, ..., s_N from left to right. (Here, s = s_1 + s_2 + ... + s_N holds.) Snuke wants to satisfy the following condition: * For each i (1 \leq i \leq N), it ...
import sys readline = sys.stdin.readline from collections import defaultdict S = list(map(lambda x: ord(x)-97, readline().strip())) N = len(S) table = [0] + [1<<S[i] for i in range(N)] for i in range(1, N+1): table[i] ^= table[i-1] inf = 10**9+7 dp = defaultdict(lambda: inf) dp[0] = 0 for i in range(1, N+1): ...
3Python3
{ "input": [ "byebye", "abcdefghijklmnopqrstuvwxyz", "aabxyyzz", "abcabcxabcx", "byeybe", "zyxwvutsrqponmlkjihgfedcba", "aabwyyzz", "axcabcbabcx", "zyxwvutsrqponmlkjihgfedbba", "aabwyzzz", "eybcxb", "abzwxayz", "ayxwvutsrqponmlkiihgfedbbz", "yccabbcacxa", "a...
5ATCODER
p03570 CODE FESTIVAL 2017 qual C - Yet Another Palindrome Partitioning_1108
We have a string s consisting of lowercase English letters. Snuke is partitioning s into some number of non-empty substrings. Let the subtrings obtained be s_1, s_2, ..., s_N from left to right. (Here, s = s_1 + s_2 + ... + s_N holds.) Snuke wants to satisfy the following condition: * For each i (1 \leq i \leq N), it ...
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 void solve() { char[] ...
4JAVA
{ "input": [ "byebye", "abcdefghijklmnopqrstuvwxyz", "aabxyyzz", "abcabcxabcx", "byeybe", "zyxwvutsrqponmlkjihgfedcba", "aabwyyzz", "axcabcbabcx", "zyxwvutsrqponmlkjihgfedbba", "aabwyzzz", "eybcxb", "abzwxayz", "ayxwvutsrqponmlkiihgfedbbz", "yccabbcacxa", "a...
5ATCODER
p03725 AtCoder Grand Contest 014 - Closed Rooms_1109
Takahashi is locked within a building. This building consists of H×W rooms, arranged in H rows and W columns. We will denote the room at the i-th row and j-th column as (i,j). The state of this room is represented by a character A_{i,j}. If A_{i,j}= `#`, the room is locked and cannot be entered; if A_{i,j}= `.`, the r...
from collections import deque H, W, K = map(int, raw_input().split()) MAP = [raw_input() for _ in xrange(H)] visited = [[False for _ in xrange(W)] for _ in xrange(H)] for y in range(H): x = MAP[y].find('S') if x != -1: sx = x sy = y Q = deque() Q.append((0, (sx, sy))) visited[sy][sx] = True ...
1Python2
{ "input": [ "3 3 3\n#.#\n#S.\n###", "3 3 3\n.#\nS.", "3 3 3\n\nS#", "7 7 2\n\n\n...##\nS###\n.#.##\n.###", "2 3 3\n.#\nS.", "7 8 2\n\n\n...##\n###S\n.#.##\n.###", "7 7 2\n\n\n##...\nS###\n.#.##\n.###", "2 3 3\n#.\nS.", "7 7 2\n\n\n##...\nS###\n##.#.\n.###", "2 3 3\n#.\n.S", ...
5ATCODER
p03725 AtCoder Grand Contest 014 - Closed Rooms_1110
Takahashi is locked within a building. This building consists of H×W rooms, arranged in H rows and W columns. We will denote the room at the i-th row and j-th column as (i,j). The state of this room is represented by a character A_{i,j}. If A_{i,j}= `#`, the room is locked and cannot be entered; if A_{i,j}= `.`, the r...
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair using namespace std; typedef pair <int, int> pii; typedef pair <pii, int> piii; char a[810][810]; int ans; queue <piii> q; int dir[4][2] = {0, 1, 1, 0, -1, 0, 0, -1}; int n, m, k; bool IN(int x, int y){return x >= 0 && x < n && y >= 0 &...
2C++
{ "input": [ "3 3 3\n#.#\n#S.\n###", "3 3 3\n.#\nS.", "3 3 3\n\nS#", "7 7 2\n\n\n...##\nS###\n.#.##\n.###", "2 3 3\n.#\nS.", "7 8 2\n\n\n...##\n###S\n.#.##\n.###", "7 7 2\n\n\n##...\nS###\n.#.##\n.###", "2 3 3\n#.\nS.", "7 7 2\n\n\n##...\nS###\n##.#.\n.###", "2 3 3\n#.\n.S", ...
5ATCODER
p03725 AtCoder Grand Contest 014 - Closed Rooms_1111
Takahashi is locked within a building. This building consists of H×W rooms, arranged in H rows and W columns. We will denote the room at the i-th row and j-th column as (i,j). The state of this room is represented by a character A_{i,j}. If A_{i,j}= `#`, the room is locked and cannot be entered; if A_{i,j}= `.`, the r...
from collections import deque h,w,k = map(int,input().split()) a = [] for i in range(h): b = input() tmp = [] for j in range(w): tmp.append(b[j]) if b[j] == "S": sx = i sy = j a.append(tmp) ma = [[0]*w for i in range(h)] def dfs(x,y,z): if ma[x][y] == 1: return if z>k: return m...
3Python3
{ "input": [ "3 3 3\n#.#\n#S.\n###", "3 3 3\n.#\nS.", "3 3 3\n\nS#", "7 7 2\n\n\n...##\nS###\n.#.##\n.###", "2 3 3\n.#\nS.", "7 8 2\n\n\n...##\n###S\n.#.##\n.###", "7 7 2\n\n\n##...\nS###\n.#.##\n.###", "2 3 3\n#.\nS.", "7 7 2\n\n\n##...\nS###\n##.#.\n.###", "2 3 3\n#.\n.S", ...
5ATCODER
p03725 AtCoder Grand Contest 014 - Closed Rooms_1112
Takahashi is locked within a building. This building consists of H×W rooms, arranged in H rows and W columns. We will denote the room at the i-th row and j-th column as (i,j). The state of this room is represented by a character A_{i,j}. If A_{i,j}= `#`, the room is locked and cannot be entered; if A_{i,j}= `.`, the r...
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.NoSuchElementException; public class Main { int H,W,K; int[] dx = {0,0,-1,1},dy = {-1,1,0,0}; char[][] ch; boolean[][] canGo; public boolean isRange(int x,...
4JAVA
{ "input": [ "3 3 3\n#.#\n#S.\n###", "3 3 3\n.#\nS.", "3 3 3\n\nS#", "7 7 2\n\n\n...##\nS###\n.#.##\n.###", "2 3 3\n.#\nS.", "7 8 2\n\n\n...##\n###S\n.#.##\n.###", "7 7 2\n\n\n##...\nS###\n.#.##\n.###", "2 3 3\n#.\nS.", "7 7 2\n\n\n##...\nS###\n##.#.\n.###", "2 3 3\n#.\n.S", ...
5ATCODER
p03889 CODE FESTIVAL 2016 Relay (Parallel) - Mirror String_1113
You are given a string S consisting of letters `b`, `d`, `p` and `q`. Determine whether S is a mirror string. Here, a mirror string is a string S such that the following sequence of operations on S results in the same string S: 1. Reverse the order of the characters in S. 2. Replace each occurrence of `b` by `d`, `d...
S = raw_input() flag = True if len(S) % 2 == 1: flag = False else: for i in range(len(S)/2): if S[i] == "b": if S[-i-1] != "d": flag = False break elif S[i] == "d": if S[-i-1] != "b": flag = False break ...
1Python2
{ "input": [ "ppqb", "pdbq", "qbdp", "dbqp", "bdqp", "bqpp", "pdqb", "dqbp", "pqbd", "pqdb", "bqqp", "pdpb", "pbqd", "dqpb", "bqpq", "pbpd", "dppb", "qpqb", "dpbp", "bpdp", "bqdp", "pqqb", "dpbq", "dpqb", "dbpp", "...
5ATCODER
p03889 CODE FESTIVAL 2016 Relay (Parallel) - Mirror String_1114
You are given a string S consisting of letters `b`, `d`, `p` and `q`. Determine whether S is a mirror string. Here, a mirror string is a string S such that the following sequence of operations on S results in the same string S: 1. Reverse the order of the characters in S. 2. Replace each occurrence of `b` by `d`, `d...
#include<iostream> #include<string> using namespace std; char ch[256]; int main() { ch['b']='d'; ch['d']='b'; ch['q']='p'; ch['p']='q'; string s; cin>>s; int i; for(i=0;i<s.size();i++) { if(ch[s[i]]!=s[s.size()-1-i]) goto br; } printf("Yes\n"); return 0; br:; printf("No\n"); return 0; }
2C++
{ "input": [ "ppqb", "pdbq", "qbdp", "dbqp", "bdqp", "bqpp", "pdqb", "dqbp", "pqbd", "pqdb", "bqqp", "pdpb", "pbqd", "dqpb", "bqpq", "pbpd", "dppb", "qpqb", "dpbp", "bpdp", "bqdp", "pqqb", "dpbq", "dpqb", "dbpp", "...
5ATCODER
p03889 CODE FESTIVAL 2016 Relay (Parallel) - Mirror String_1115
You are given a string S consisting of letters `b`, `d`, `p` and `q`. Determine whether S is a mirror string. Here, a mirror string is a string S such that the following sequence of operations on S results in the same string S: 1. Reverse the order of the characters in S. 2. Replace each occurrence of `b` by `d`, `d...
r=str.replace s=input() print(['No','Yes'][s==''.join(reversed(r(r(r(r(r(r(r(r(s,'b','0'),'d','1'),'p','2'),'q','3'),'0','d'),'1','b'),'2','q'),'3','p')))])
3Python3
{ "input": [ "ppqb", "pdbq", "qbdp", "dbqp", "bdqp", "bqpp", "pdqb", "dqbp", "pqbd", "pqdb", "bqqp", "pdpb", "pbqd", "dqpb", "bqpq", "pbpd", "dppb", "qpqb", "dpbp", "bpdp", "bqdp", "pqqb", "dpbq", "dpqb", "dbpp", "...
5ATCODER
p03889 CODE FESTIVAL 2016 Relay (Parallel) - Mirror String_1116
You are given a string S consisting of letters `b`, `d`, `p` and `q`. Determine whether S is a mirror string. Here, a mirror string is a string S such that the following sequence of operations on S results in the same string S: 1. Reverse the order of the characters in S. 2. Replace each occurrence of `b` by `d`, `d...
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.*; class Main{ static void solve(){ String s = ns(); char[] mr = new char[256]; mr['b']='d'; mr['d']='b'; mr['p']='q'; mr['q']='p'; for(int i=0;i<s.length();++i){ ...
4JAVA
{ "input": [ "ppqb", "pdbq", "qbdp", "dbqp", "bdqp", "bqpp", "pdqb", "dqbp", "pqbd", "pqdb", "bqqp", "pdpb", "pbqd", "dqpb", "bqpq", "pbpd", "dppb", "qpqb", "dpbp", "bpdp", "bqdp", "pqqb", "dpbq", "dpqb", "dbpp", "...
5ATCODER
p04048 AtCoder Grand Contest 001 - Mysterious Light_1117
Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of Mysterious Light. Three mirrors of length N are set so that they form an equilateral triangle. Let the vertices of the triangle be a, b and c. Inside the triangle, the rifle is placed at the point p on segment ab such that ap ...
n, x = map(int, raw_input().split()) ans = x while 0 < x < n: k = x / (n-x) rest = x % (n-x) ans += 2*k*(n-x) if rest: ans += n-x + rest n, x = n-x, n-x-rest print ans
1Python2
{ "input": [ "5 2", "5 4", "7 4", "6 1", "9 4", "6 3", "14 4", "8 1", "28 4", "15 2", "28 3", "19 2", "32 2", "29 5", "26 3", "46 1", "46 2", "81 3", "85 3", "10 3", "14 1", "2 1", "11 4", "4 2", "18 4", "28 6", ...
5ATCODER
p04048 AtCoder Grand Contest 001 - Mysterious Light_1118
Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of Mysterious Light. Three mirrors of length N are set so that they form an equilateral triangle. Let the vertices of the triangle be a, b and c. Inside the triangle, the rifle is placed at the point p on segment ab such that ap ...
#include<bits/stdc++.h> using namespace std; int main(){ long long N , X , ans; cin >> N >> X; ans = N; long long P = X , Q = N - X; while(Q){ans += (P / Q * 2 - !(P % Q)) * Q; P %= Q; swap(P , Q);} cout << ans; return 0; }
2C++
{ "input": [ "5 2", "5 4", "7 4", "6 1", "9 4", "6 3", "14 4", "8 1", "28 4", "15 2", "28 3", "19 2", "32 2", "29 5", "26 3", "46 1", "46 2", "81 3", "85 3", "10 3", "14 1", "2 1", "11 4", "4 2", "18 4", "28 6", ...
5ATCODER
p04048 AtCoder Grand Contest 001 - Mysterious Light_1119
Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of Mysterious Light. Three mirrors of length N are set so that they form an equilateral triangle. Let the vertices of the triangle be a, b and c. Inside the triangle, the rifle is placed at the point p on segment ab such that ap ...
"""B - Mysterious Light""" N,X=(int(i) for i in input().split()) def MysteriousLight(tmp,rem): while rem: tmp, rem= rem,tmp%rem return tmp print(3*(N-MysteriousLight(N,X)))
3Python3
{ "input": [ "5 2", "5 4", "7 4", "6 1", "9 4", "6 3", "14 4", "8 1", "28 4", "15 2", "28 3", "19 2", "32 2", "29 5", "26 3", "46 1", "46 2", "81 3", "85 3", "10 3", "14 1", "2 1", "11 4", "4 2", "18 4", "28 6", ...
5ATCODER
p04048 AtCoder Grand Contest 001 - Mysterious Light_1120
Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of Mysterious Light. Three mirrors of length N are set so that they form an equilateral triangle. Let the vertices of the triangle be a, b and c. Inside the triangle, the rifle is placed at the point p on segment ab such that ap ...
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long N = sc.nextLong(); long X = sc.nextLong(); long sum = N + func(Math.min(N-X, X), Math.max(N-X, X)); System.out.println(sum); sc.close(); } private static long func(long a, l...
4JAVA
{ "input": [ "5 2", "5 4", "7 4", "6 1", "9 4", "6 3", "14 4", "8 1", "28 4", "15 2", "28 3", "19 2", "32 2", "29 5", "26 3", "46 1", "46 2", "81 3", "85 3", "10 3", "14 1", "2 1", "11 4", "4 2", "18 4", "28 6", ...
5ATCODER
p00127 Pocket Pager Input_1121
One day, Taro received a strange email with only the number "519345213244" in the text. The email was from my cousin, who was 10 years older than me, so when I called and asked, "Oh, I sent it with a pocket bell because I was in a hurry. It's convenient. Nice to meet you!" I got it. You know this cousin, who is always ...
import sys s = 'abcdefghijklmnopqrstuvwxyz.?! ' d = {} for y in range(1, 7): for t in range(1, 6): d[(str(y),str(t))] = s[0] s = s[1:] for line in sys.stdin: line = line.rstrip() if len(line) == 0 or len(line) % 2 != 0: print 'NA' continue ans = '' for i in range(0,...
1Python2
{ "input": [ "341143514535\n314\n143565553551655311343411652235654535651124615163\n551544654451431564\n4\n3411\n6363636363\n153414", "341143514535\n158\n143565553551655311343411652235654535651124615163\n551544654451431564\n4\n3411\n6363636363\n153414", "341143514535\n314\n101412831831152091951865990005832...
6AIZU
p00127 Pocket Pager Input_1122
One day, Taro received a strange email with only the number "519345213244" in the text. The email was from my cousin, who was 10 years older than me, so when I called and asked, "Oh, I sent it with a pocket bell because I was in a hurry. It's convenient. Nice to meet you!" I got it. You know this cousin, who is always ...
#include <iostream> #include <string> using namespace std; int main(){ string str; char code[6][5] = {{'a', 'b', 'c', 'd', 'e'}, {'f', 'g', 'h', 'i', 'j'}, {'k', 'l', 'm', 'n', 'o'}, {'p', 'q', 'r', 's', 't'}, {'u', 'v', 'w', 'x',...
2C++
{ "input": [ "341143514535\n314\n143565553551655311343411652235654535651124615163\n551544654451431564\n4\n3411\n6363636363\n153414", "341143514535\n158\n143565553551655311343411652235654535651124615163\n551544654451431564\n4\n3411\n6363636363\n153414", "341143514535\n314\n101412831831152091951865990005832...
6AIZU
p00127 Pocket Pager Input_1123
One day, Taro received a strange email with only the number "519345213244" in the text. The email was from my cousin, who was 10 years older than me, so when I called and asked, "Oh, I sent it with a pocket bell because I was in a hurry. It's convenient. Nice to meet you!" I got it. You know this cousin, who is always ...
mes = {11:"a",12:"b",13:"c",14:"d",15:"e" ,21:"f",22:"g",23:"h",24:"i",25:"j" ,31:"k",32:"l",33:"m",34:"n",35:"o" ,41:"p",42:"q",43:"r",44:"s",45:"t" ,51:"u",52:"v",53:"w",54:"x",55:"y" ,61:"z",62:".",63:"?",64:"!",65:" "} while True: try: s = input() except: break ss = ...
3Python3
{ "input": [ "341143514535\n314\n143565553551655311343411652235654535651124615163\n551544654451431564\n4\n3411\n6363636363\n153414", "341143514535\n158\n143565553551655311343411652235654535651124615163\n551544654451431564\n4\n3411\n6363636363\n153414", "341143514535\n314\n101412831831152091951865990005832...
6AIZU
p00127 Pocket Pager Input_1124
One day, Taro received a strange email with only the number "519345213244" in the text. The email was from my cousin, who was 10 years older than me, so when I called and asked, "Oh, I sent it with a pocket bell because I was in a hurry. It's convenient. Nice to meet you!" I got it. You know this cousin, who is always ...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { private static BufferedReader br = null; private static char[][] wt = { { 'a', 'b', 'c', 'd', 'e' }, { 'f', 'g', 'h', 'i', 'j' }, { 'k', 'l', 'm', 'n', 'o' }, { 'p', 'q', 'r', 's', 't' }, { 'u', 'v', 'w...
4JAVA
{ "input": [ "341143514535\n314\n143565553551655311343411652235654535651124615163\n551544654451431564\n4\n3411\n6363636363\n153414", "341143514535\n158\n143565553551655311343411652235654535651124615163\n551544654451431564\n4\n3411\n6363636363\n153414", "341143514535\n314\n101412831831152091951865990005832...
6AIZU
p00260 Cats Going Straight_1125
There was a large mansion surrounded by high walls. The owner of the mansion loved cats so much that he always prepared delicious food for the occasional cats. The hungry cats jumped over the high walls and rushed straight to the rice that was everywhere in the mansion. One day the husband found some cats lying down i...
#include<bits/stdc++.h> #define EQ(a,b) (abs((a)-(b)) < EPS) #define rep(i,n) for(int i=0;i<(int)(n);i++) #define fs first #define sc second #define pb push_back #define sz size() #define all(a) (a).begin(),(a).end() using namespace std; typedef long double D; typedef complex<D> P; typedef pair<P,P> L; typedef vector<...
2C++
{ "input": [ "8\n0 0\n3 2\n6 2\n8 6\n6 5\n7 7\n0 4\n3 4\n8\n0 0\n5 3\n5 2\n4 1\n6 1\n8 6\n6 4\n2 4\n0", "8\n0 -1\n3 2\n6 2\n8 6\n6 5\n7 7\n0 4\n3 4\n8\n0 0\n5 3\n5 2\n4 1\n6 1\n8 6\n6 4\n2 4\n0", "8\n0 -1\n3 2\n6 2\n8 6\n6 5\n7 7\n0 4\n3 4\n8\n0 0\n5 3\n4 2\n4 1\n6 1\n8 6\n6 4\n2 4\n0", "8\n0 -1\n3 3\...
6AIZU
p00447 Searching Constellation_1126
problem You are looking for a constellation in a picture of the starry sky. The photo always contains exactly one figure with the same shape, orientation, and size as the constellation you are looking for. However, there is a possibility that extra stars are shown in the photograph other than the stars that make up th...
while 1: f = []; s = []; m = input() if m==0: break for i in xrange(m): f.append(map(int, raw_input().split())) n = input() for i in xrange(n): s.append(map(int, raw_input().split())) for i in range(n): x0 = s[i][0] - f[0][0] y0 = s[i][1] - f[0][1] flg...
1Python2
{ "input": [ "5\n8 5\n6 4\n4 3\n7 10\n0 10\n10\n10 5\n2 7\n9 7\n8 10\n10 2\n1 2\n8 1\n6 7\n6 0\n0 9\n5\n904207 809784\n845370 244806\n499091 59863\n638406 182509\n435076 362268\n10\n757559 866424\n114810 239537\n519926 989458\n461089 424480\n674361 448440\n81851 150384\n459107 795405\n299682 6700\n254125 362183\n...
6AIZU
p00447 Searching Constellation_1127
problem You are looking for a constellation in a picture of the starry sky. The photo always contains exactly one figure with the same shape, orientation, and size as the constellation you are looking for. However, there is a possibility that extra stars are shown in the photograph other than the stars that make up th...
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; P f(P a, P b) { return make_pair(b.first - a.first, b.second - a.second); } int main() { int m, n; while (true) { cin >> m; if (m == 0) break; vector<P> seiza(m); for (int i = 0; i < m; ++i) cin >> seiza[i].first >> seiza[i].secon...
2C++
{ "input": [ "5\n8 5\n6 4\n4 3\n7 10\n0 10\n10\n10 5\n2 7\n9 7\n8 10\n10 2\n1 2\n8 1\n6 7\n6 0\n0 9\n5\n904207 809784\n845370 244806\n499091 59863\n638406 182509\n435076 362268\n10\n757559 866424\n114810 239537\n519926 989458\n461089 424480\n674361 448440\n81851 150384\n459107 795405\n299682 6700\n254125 362183\n...
6AIZU
p00447 Searching Constellation_1128
problem You are looking for a constellation in a picture of the starry sky. The photo always contains exactly one figure with the same shape, orientation, and size as the constellation you are looking for. However, there is a possibility that extra stars are shown in the photograph other than the stars that make up th...
import operator for e in iter(input,'0'): target = [[*map(int,input().split())]for _ in[0]*int(e)] s,t = min(target) b = {tuple(map(int,input().split()))for _ in[0]*int(input())} m=max(b)[0] - max(target)[0] + s for x,y in b: if x>m:continue for u,v in target: if (x + u -...
3Python3
{ "input": [ "5\n8 5\n6 4\n4 3\n7 10\n0 10\n10\n10 5\n2 7\n9 7\n8 10\n10 2\n1 2\n8 1\n6 7\n6 0\n0 9\n5\n904207 809784\n845370 244806\n499091 59863\n638406 182509\n435076 362268\n10\n757559 866424\n114810 239537\n519926 989458\n461089 424480\n674361 448440\n81851 150384\n459107 795405\n299682 6700\n254125 362183\n...
6AIZU
p00447 Searching Constellation_1129
problem You are looking for a constellation in a picture of the starry sky. The photo always contains exactly one figure with the same shape, orientation, and size as the constellation you are looking for. However, there is a possibility that extra stars are shown in the photograph other than the stars that make up th...
import java.util.HashSet; import java.util.Scanner; import java.util.Set; //Searching Constellation public class Main{ void run(){ Scanner sc = new Scanner(System.in); long W = 1000001; while(true){ int m = sc.nextInt(); if(m==0)break; long[][] star = new long[m][2]; for(int i=0;i<m;i++){ for(i...
4JAVA
{ "input": [ "5\n8 5\n6 4\n4 3\n7 10\n0 10\n10\n10 5\n2 7\n9 7\n8 10\n10 2\n1 2\n8 1\n6 7\n6 0\n0 9\n5\n904207 809784\n845370 244806\n499091 59863\n638406 182509\n435076 362268\n10\n757559 866424\n114810 239537\n519926 989458\n461089 424480\n674361 448440\n81851 150384\n459107 795405\n299682 6700\n254125 362183\n...
6AIZU
p00638 Old Bridges_1130
Long long ago, there was a thief. Looking for treasures, he was running about all over the world. One day, he heard a rumor that there were islands that had large amount of treasures, so he decided to head for there. Finally he found n islands that had treasures and one island that had nothing. Most of islands had sea...
while 1: n = int(raw_input()) if n == 0: break land = [map(int,raw_input().split(" ")) for i in range(n)] land.sort(key = lambda x:(x[1],x[0])) gold = 0 for i in range(n): gold += land[i][0] if gold > land[i][1]: print "No" break else: print "Yes"
1Python2
{ "input": [ "3\n2 3\n3 6\n1 2\n3\n2 3\n3 5\n1 2\n0", "3\n2 3\n3 6\n1 2\n3\n2 3\n3 5\n2 2\n0", "3\n2 3\n3 6\n2 2\n3\n3 3\n3 6\n2 2\n0", "3\n2 1\n3 6\n1 2\n3\n2 3\n3 5\n0 2\n0", "3\n2 5\n0 9\n4 1\n0\n2 0\n3 10\n2 3\n0", "3\n4 5\n3 8\n1 2\n0\n7 3\n3 5\n2 1\n0", "3\n2 3\n3 6\n1 2\n3\n0 3\n3 5...
6AIZU
p00638 Old Bridges_1131
Long long ago, there was a thief. Looking for treasures, he was running about all over the world. One day, he heard a rumor that there were islands that had large amount of treasures, so he decided to head for there. Finally he found n islands that had treasures and one island that had nothing. Most of islands had sea...
#include <iostream> //“üo—Í #include <string> //•¶Žš—ñ #include <vector> //“®“I”z—ñ #include <sstream> //•¶Žš—ñƒtƒH[ƒ}ƒbƒg using namespace std; int main(){ int n, num; cin >> n; while(1){ if(n == 0){ break; } vector<int> vec1, vec2; for(int i=0;i<n;i++){ cin >> num; vec1.push_back(num); cin >...
2C++
{ "input": [ "3\n2 3\n3 6\n1 2\n3\n2 3\n3 5\n1 2\n0", "3\n2 3\n3 6\n1 2\n3\n2 3\n3 5\n2 2\n0", "3\n2 3\n3 6\n2 2\n3\n3 3\n3 6\n2 2\n0", "3\n2 1\n3 6\n1 2\n3\n2 3\n3 5\n0 2\n0", "3\n2 5\n0 9\n4 1\n0\n2 0\n3 10\n2 3\n0", "3\n4 5\n3 8\n1 2\n0\n7 3\n3 5\n2 1\n0", "3\n2 3\n3 6\n1 2\n3\n0 3\n3 5...
6AIZU
p00638 Old Bridges_1132
Long long ago, there was a thief. Looking for treasures, he was running about all over the world. One day, he heard a rumor that there were islands that had large amount of treasures, so he decided to head for there. Finally he found n islands that had treasures and one island that had nothing. Most of islands had sea...
while True: n = int(input()) if n == 0: break z = sorted([tuple(map(int, input().split())) for _ in range(n)], key=lambda x: x[1]) total = 0 for a, b in z: total += a if total > b: print("No") break else: print("Yes")
3Python3
{ "input": [ "3\n2 3\n3 6\n1 2\n3\n2 3\n3 5\n1 2\n0", "3\n2 3\n3 6\n1 2\n3\n2 3\n3 5\n2 2\n0", "3\n2 3\n3 6\n2 2\n3\n3 3\n3 6\n2 2\n0", "3\n2 1\n3 6\n1 2\n3\n2 3\n3 5\n0 2\n0", "3\n2 5\n0 9\n4 1\n0\n2 0\n3 10\n2 3\n0", "3\n4 5\n3 8\n1 2\n0\n7 3\n3 5\n2 1\n0", "3\n2 3\n3 6\n1 2\n3\n0 3\n3 5...
6AIZU
p00638 Old Bridges_1133
Long long ago, there was a thief. Looking for treasures, he was running about all over the world. One day, he heard a rumor that there were islands that had large amount of treasures, so he decided to head for there. Finally he found n islands that had treasures and one island that had nothing. Most of islands had sea...
import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { int n = sc.nextInt(); if (n == 0) return; List<Bridge> bridges = new ArrayLi...
4JAVA
{ "input": [ "3\n2 3\n3 6\n1 2\n3\n2 3\n3 5\n1 2\n0", "3\n2 3\n3 6\n1 2\n3\n2 3\n3 5\n2 2\n0", "3\n2 3\n3 6\n2 2\n3\n3 3\n3 6\n2 2\n0", "3\n2 1\n3 6\n1 2\n3\n2 3\n3 5\n0 2\n0", "3\n2 5\n0 9\n4 1\n0\n2 0\n3 10\n2 3\n0", "3\n4 5\n3 8\n1 2\n0\n7 3\n3 5\n2 1\n0", "3\n2 3\n3 6\n1 2\n3\n0 3\n3 5...
6AIZU
p00781 Lattice Practices_1134
Once upon a time, there was a king who loved beautiful costumes very much. The king had a special cocoon bed to make excellent cloth of silk. The cocoon bed had 16 small square rooms, forming a 4 × 4 lattice, for 16 silkworms. The cocoon bed can be depicted as follows: <image> The cocoon bed can be divided into 10 re...
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <cstring> using namespace std; int lat[5][5]; vector<vector<int>> bx = { {0, 1, 2, 3, 4}, {0, 1, 2, 3, 4}, {0, 1, 2, 3, 4}, {0, 1, 2, 3, 4}, {0, 1, 2, 3, 4}, {0, 0, 0, 0, 0}, {1, 1, 1, 1, 1}, {2, 2, 2...
2C++
{ "input": [ "10000 01000 00100 11000 01100 11111 01110 11100 10110 11110\n10101 01000 00000 11001 01100 11101 01110 11100 10110 11010\nEND", "10000 01000 00100 11000 01100 11111 01110 11100 10110 11110\n10101 01000 00000 11001 01100 11001 01110 11100 10110 11010\nEND", "10000 01000 00100 11000 00100 1111...
6AIZU
p00781 Lattice Practices_1135
Once upon a time, there was a king who loved beautiful costumes very much. The king had a special cocoon bed to make excellent cloth of silk. The cocoon bed had 16 small square rooms, forming a 4 × 4 lattice, for 16 silkworms. The cocoon bed can be depicted as follows: <image> The cocoon bed can be divided into 10 re...
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; int[] a, b, c, rev; int n, m, ans; void run(){ // 10ŒÂ‚©‚ç5ŒÂ‘I‚ԏ‡—ñP(10,5)...
4JAVA
{ "input": [ "10000 01000 00100 11000 01100 11111 01110 11100 10110 11110\n10101 01000 00000 11001 01100 11101 01110 11100 10110 11010\nEND", "10000 01000 00100 11000 01100 11111 01110 11100 10110 11110\n10101 01000 00000 11001 01100 11001 01110 11100 10110 11010\nEND", "10000 01000 00100 11000 00100 1111...
6AIZU
p00914 Equal Sum Sets_1136
Let us consider sets of positive integers less than or equal to n. Note that all elements of a set are different. Also note that the order of elements doesn't matter, that is, both {3, 5, 9} and {5, 9, 3} mean the same set. Specifying the number of set elements and their sum to be k and s, respectively, sets satisfyin...
import itertools while 1: n,k,s = map(int,raw_input().split()) if n == 0: break print sum(sum(ele) == s for ele in itertools.combinations(range(1,n+1),k))
1Python2
{ "input": [ "9 3 23\n9 3 22\n10 3 28\n16 10 107\n20 8 102\n20 10 105\n20 10 155\n3 4 3\n4 2 11\n0 0 0", "9 3 23\n9 3 22\n10 3 28\n16 10 107\n20 8 102\n20 10 105\n20 10 155\n3 5 3\n4 2 11\n0 0 0", "9 3 23\n9 3 22\n10 3 28\n16 10 107\n20 8 102\n20 10 105\n20 20 155\n3 5 3\n4 2 11\n0 0 0", "9 3 23\n9 3 ...
6AIZU
p00914 Equal Sum Sets_1137
Let us consider sets of positive integers less than or equal to n. Note that all elements of a set are different. Also note that the order of elements doesn't matter, that is, both {3, 5, 9} and {5, 9, 3} mean the same set. Specifying the number of set elements and their sum to be k and s, respectively, sets satisfyin...
#include<bits/stdc++.h> #define rep(i,n)for(int i=0;i<n;i++) using namespace std; int dp[30][20][200]; int main() { int N, K, S; while (scanf("%d%d%d", &N, &K, &S), N) { memset(dp, 0, sizeof(dp)); for (int i = 0; i <= N; i++)dp[i][0][0] = 1; for (int i = 1; i <= N; i++) { for (int j = 1; j <= K; j++) { ...
2C++
{ "input": [ "9 3 23\n9 3 22\n10 3 28\n16 10 107\n20 8 102\n20 10 105\n20 10 155\n3 4 3\n4 2 11\n0 0 0", "9 3 23\n9 3 22\n10 3 28\n16 10 107\n20 8 102\n20 10 105\n20 10 155\n3 5 3\n4 2 11\n0 0 0", "9 3 23\n9 3 22\n10 3 28\n16 10 107\n20 8 102\n20 10 105\n20 20 155\n3 5 3\n4 2 11\n0 0 0", "9 3 23\n9 3 ...
6AIZU
p00914 Equal Sum Sets_1138
Let us consider sets of positive integers less than or equal to n. Note that all elements of a set are different. Also note that the order of elements doesn't matter, that is, both {3, 5, 9} and {5, 9, 3} mean the same set. Specifying the number of set elements and their sum to be k and s, respectively, sets satisfyin...
import itertools while True: N,K,S = map(int,input().split()) if N == 0: break cnt = 0 for comb in itertools.combinations(range(1,N+1),K): if sum(comb) == S: cnt += 1 print(cnt)
3Python3
{ "input": [ "9 3 23\n9 3 22\n10 3 28\n16 10 107\n20 8 102\n20 10 105\n20 10 155\n3 4 3\n4 2 11\n0 0 0", "9 3 23\n9 3 22\n10 3 28\n16 10 107\n20 8 102\n20 10 105\n20 10 155\n3 5 3\n4 2 11\n0 0 0", "9 3 23\n9 3 22\n10 3 28\n16 10 107\n20 8 102\n20 10 105\n20 20 155\n3 5 3\n4 2 11\n0 0 0", "9 3 23\n9 3 ...
6AIZU
p00914 Equal Sum Sets_1139
Let us consider sets of positive integers less than or equal to n. Note that all elements of a set are different. Also note that the order of elements doesn't matter, that is, both {3, 5, 9} and {5, 9, 3} mean the same set. Specifying the number of set elements and their sum to be k and s, respectively, sets satisfyin...
import java.util.*; class Main{ static Scanner s=new Scanner(System.in); static int a,b,c; static int[]v=new int[11]; static int f(int d,int m) { //System.out.println(d+" "+m); if(m<0) return 0; if(d==b+1) return m==0?1:0; int sum=0; for(v[d]=v[d-1]+1;v[d]<=a;++v[d]) { sum+=f(d+1,m-v[d]); ...
4JAVA
{ "input": [ "9 3 23\n9 3 22\n10 3 28\n16 10 107\n20 8 102\n20 10 105\n20 10 155\n3 4 3\n4 2 11\n0 0 0", "9 3 23\n9 3 22\n10 3 28\n16 10 107\n20 8 102\n20 10 105\n20 10 155\n3 5 3\n4 2 11\n0 0 0", "9 3 23\n9 3 22\n10 3 28\n16 10 107\n20 8 102\n20 10 105\n20 20 155\n3 5 3\n4 2 11\n0 0 0", "9 3 23\n9 3 ...
6AIZU
p01046 Yu-kun Likes a lot of Money_1140
Background The kindergarten attached to the University of Aizu is a kindergarten where children who love programming gather. Yu, one of the kindergarten children, loves money as much as programming. Yu-kun visited the island where treasures sleep to make money today. Yu-kun has obtained a map of the treasure in advanc...
#include <bits/stdc++.h> #define INF 1000000007 using namespace std; typedef long long ll; typedef pair<int,int> P; struct uftree{ int par[25]; int rank[25]; uftree(){ } void init(int n){ for(int i=0;i<n;i++){ par[i]=i; rank[i]=0; } } int find(int x){ if(par[x]==x)return x; return par[x]=find(par[...
2C++
{ "input": [ "3 3 1 10\n@#b\n.#.\n.#.\nb 100", "3 3 1 20\n@*C\n..*\n...\nC 10", "3 3 1 10\n@0.\n...\n...\n0 100" ], "output": [ "0", "0", "100" ] }
6AIZU
p01179 Cousin's Aunt_1141
Sarah is a girl who likes reading books. One day, she wondered about the relationship of a family in a mystery novel. The story said, * B is A’s father’s brother’s son, and * C is B’s aunt. Then she asked herself, “So how many degrees of kinship are there between A and C?” There are two possible relationships bet...
#include <algorithm> #include <cassert> #include <climits> #include <iostream> #include <string> #include <vector> using namespace std; using namespace std::placeholders; enum Relation { FATHER, MOTHER, SON, DAUGHTER, HUSBAND, WIFE, BROTHER, SISTER, GRANDFATHER, GRANDMOTHER, GRANDSON, GRANDDAUGHTER, UNCLE, AUNT, N...
2C++
{ "input": [ "7\nC is A’s father’s brother’s son’s aunt\nC is A’s mother’s brother’s son’s aunt\nC is A’s son’s mother’s mother’s son\nC is A’s aunt’s niece’s aunt’s niece\nC is A’s father’s son’s brother\nC is A’s son’s son’s mother\nC is A" ], "output": [ "5 3\n5 1\n2 2\n6 0\n2 0\n1 1\n0 0" ] }
6AIZU
p01316 Differential Pulse Code Modulation_1142
Differential pulse code modulation is one of the compression methods mainly used when compressing audio signals. The audio signal is treated as an integer sequence (impulse sequence) on the computer. The integer sequence is a sample of the input signal at regular time intervals and the amplitude recorded. In general, ...
#include <iostream> #include <vector> #include <algorithm> #define IF 1300500010 #define lengthof(x) (sizeof(x) / sizeof(*(x))) using namespace std; int main(int argc, char const *argv[]) { int n,m; long long dp[1<<8][2]; long long min_; while(1){ cin>>n>>m; if(n+m==0) break; vector<long long> cb(m); v...
2C++
{ "input": [ "2 7\n4\n2\n1\n0\n-1\n-2\n-4\n131\n137\n2 7\n4\n2\n1\n0\n-1\n-2\n-4\n131\n123\n10 7\n-4\n-2\n-1\n0\n1\n2\n4\n132\n134\n135\n134\n132\n128\n124\n122\n121\n122\n5 1\n255\n0\n0\n0\n0\n0\n4 1\n0\n255\n0\n255\n0\n0 0", "2 7\n4\n2\n1\n0\n-1\n-2\n-4\n131\n137\n2 7\n4\n2\n1\n0\n-1\n-2\n-4\n124\n123\n10 7...
6AIZU
p01316 Differential Pulse Code Modulation_1143
Differential pulse code modulation is one of the compression methods mainly used when compressing audio signals. The audio signal is treated as an integer sequence (impulse sequence) on the computer. The integer sequence is a sample of the input signal at regular time intervals and the amplitude recorded. In general, ...
def solve(): from sys import stdin INF = float('inf') f_i = stdin while True: N, M = map(int, f_i.readline().split()) if N == 0: break C = tuple(int(f_i.readline()) for i in range(M)) # decode table tbl_1 = tuple(tuple(255 if i +...
3Python3
{ "input": [ "2 7\n4\n2\n1\n0\n-1\n-2\n-4\n131\n137\n2 7\n4\n2\n1\n0\n-1\n-2\n-4\n131\n123\n10 7\n-4\n-2\n-1\n0\n1\n2\n4\n132\n134\n135\n134\n132\n128\n124\n122\n121\n122\n5 1\n255\n0\n0\n0\n0\n0\n4 1\n0\n255\n0\n255\n0\n0 0", "2 7\n4\n2\n1\n0\n-1\n-2\n-4\n131\n137\n2 7\n4\n2\n1\n0\n-1\n-2\n-4\n124\n123\n10 7...
6AIZU
p01316 Differential Pulse Code Modulation_1144
Differential pulse code modulation is one of the compression methods mainly used when compressing audio signals. The audio signal is treated as an integer sequence (impulse sequence) on the computer. The integer sequence is a sample of the input signal at regular time intervals and the amplitude recorded. In general, ...
import java.util.BitSet; import java.util.HashMap; import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner in = new Scanner(System.in); while(true){ int n = in.nextInt(); int m = in.nextInt(); if(n == 0) break; int[] c = new int[m]; int[] x = new int[n]; for(...
4JAVA
{ "input": [ "2 7\n4\n2\n1\n0\n-1\n-2\n-4\n131\n137\n2 7\n4\n2\n1\n0\n-1\n-2\n-4\n131\n123\n10 7\n-4\n-2\n-1\n0\n1\n2\n4\n132\n134\n135\n134\n132\n128\n124\n122\n121\n122\n5 1\n255\n0\n0\n0\n0\n0\n4 1\n0\n255\n0\n255\n0\n0 0", "2 7\n4\n2\n1\n0\n-1\n-2\n-4\n131\n137\n2 7\n4\n2\n1\n0\n-1\n-2\n-4\n124\n123\n10 7...
6AIZU
p01484 Icy Composer_1145
Time Limit: 8 sec / Memory Limit: 64 MB Example Input 5 3 2 aaaaa aaa aab Output 1 6
#include <stdio.h> #include <string.h> #include <algorithm> #include <iostream> #include <math.h> #include <assert.h> #include <vector> #include <queue> #include <string> #include <map> #include <set> using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; static const dou...
2C++
{ "input": [ "5 3 2\naaaaa\naaa\naab", "5 3 2\naaaaa\nbaa\naab", "5 3 2\naaaaa\nabb\naac", "6 3 2\naaaaa\naaa\naab", "6 3 2\naabaa\naaa\naab", "10 3 1\naaaaa\nabb\naab", "5 3 2\nbaaaa\naab\naab", "8 3 2\naaaac\n`ab\naba", "5 1 2\naaaaa\nbaa\naca", "10 0 2\naaaaa\nabb\naab", ...
6AIZU
p01646 Dictionary_1146
Problem Statement We found a dictionary of the Ancient Civilization Mayo (ACM) during excavation of the ruins. After analysis of the dictionary, we revealed they used a language that had not more than 26 letters. So one of us mapped each letter to a different English alphabet and typed all the words in the dictionary ...
graph = [] def init(): global graph graph = [[False] * 26 + [True] for _ in xrange(27)] graph[26][26] = False def atoi(c):#index if c == "#": return 26 return ord(c) - ord("a") def make_graph(L): global graph cur = 0 L = [L[0]] + [L[i] for i in xrange(1, len(L)) if L[i] != L[i...
1Python2
{ "input": [ "4\ncba\ncab\nb\na\n3\nbca\nab\na\n5\nabc\nacb\nb\nc\nc\n5\nabc\nacb\nc\nb\nb\n0", "4\ncba\ncab\nb\na\n3\nbca\nab\na\n5\nabc\nacb\nb\nc\nc\n5\nabc\nacc\nc\nb\nb\n0", "4\ncba\ncab\nb\na\n3\nbca\nab\na\n5\nabc\nacb\nb\nc\nc\n5\nabc\nacc\nd\nb\nb\n0", "4\ncba\ncab\nb\na\n3\nbca\nab\na\n5\ncb...
6AIZU
p01646 Dictionary_1147
Problem Statement We found a dictionary of the Ancient Civilization Mayo (ACM) during excavation of the ruins. After analysis of the dictionary, we revealed they used a language that had not more than 26 letters. So one of us mapped each letter to a different English alphabet and typed all the words in the dictionary ...
#include<bits/stdc++.h> #define REP(i,s,n) for(int i=s;i<n;i++) #define rep(i,n) REP(i,0,n) using namespace std; typedef pair<int,int> ii; vector<int> G[510]; vector<string> arr; vector<ii> edges; bool found[510]; bool used[510]; bool cycle; bool inValid(string a,string b) { if( a == b ) return false; int dif...
2C++
{ "input": [ "4\ncba\ncab\nb\na\n3\nbca\nab\na\n5\nabc\nacb\nb\nc\nc\n5\nabc\nacb\nc\nb\nb\n0", "4\ncba\ncab\nb\na\n3\nbca\nab\na\n5\nabc\nacb\nb\nc\nc\n5\nabc\nacc\nc\nb\nb\n0", "4\ncba\ncab\nb\na\n3\nbca\nab\na\n5\nabc\nacb\nb\nc\nc\n5\nabc\nacc\nd\nb\nb\n0", "4\ncba\ncab\nb\na\n3\nbca\nab\na\n5\ncb...
6AIZU
p01646 Dictionary_1148
Problem Statement We found a dictionary of the Ancient Civilization Mayo (ACM) during excavation of the ruins. After analysis of the dictionary, we revealed they used a language that had not more than 26 letters. So one of us mapped each letter to a different English alphabet and typed all the words in the dictionary ...
def add_edge(node, adj_lst, s1, s2): ind = 0 max_len = min(len(s1), len(s2)) while ind < max_len and s1[ind] == s2[ind]: ind += 1 if ind == max_len: return max_len < len(s1) c1 = ord(s1[ind]) - ord("a") c2 = ord(s2[ind]) - ord("a") adj_lst[c1].add(c2) node.add(c1) node.add(c2) return False ...
3Python3
{ "input": [ "4\ncba\ncab\nb\na\n3\nbca\nab\na\n5\nabc\nacb\nb\nc\nc\n5\nabc\nacb\nc\nb\nb\n0", "4\ncba\ncab\nb\na\n3\nbca\nab\na\n5\nabc\nacb\nb\nc\nc\n5\nabc\nacc\nc\nb\nb\n0", "4\ncba\ncab\nb\na\n3\nbca\nab\na\n5\nabc\nacb\nb\nc\nc\n5\nabc\nacc\nd\nb\nb\n0", "4\ncba\ncab\nb\na\n3\nbca\nab\na\n5\ncb...
6AIZU
p01646 Dictionary_1149
Problem Statement We found a dictionary of the Ancient Civilization Mayo (ACM) during excavation of the ruins. After analysis of the dictionary, we revealed they used a language that had not more than 26 letters. So one of us mapped each letter to a different English alphabet and typed all the words in the dictionary ...
import java.io.*; import java.util.*; public class Main { static int N; static String[] S; public static void main(String[] args) { FastScanner sc = new FastScanner(System.in); while(true) { N = sc.nextInt(); if( N == 0 ) break; S = new String[N]; ...
4JAVA
{ "input": [ "4\ncba\ncab\nb\na\n3\nbca\nab\na\n5\nabc\nacb\nb\nc\nc\n5\nabc\nacb\nc\nb\nb\n0", "4\ncba\ncab\nb\na\n3\nbca\nab\na\n5\nabc\nacb\nb\nc\nc\n5\nabc\nacc\nc\nb\nb\n0", "4\ncba\ncab\nb\na\n3\nbca\nab\na\n5\nabc\nacb\nb\nc\nc\n5\nabc\nacc\nd\nb\nb\n0", "4\ncba\ncab\nb\na\n3\nbca\nab\na\n5\ncb...
6AIZU
p01797 Kimagure Cleaner_1150
Example Input 2 -3 4 L 2 5 ? 3 5 Output 2 L 4 L 3
// // Problem: Kimagagure Cleaner // Solution by: MORI Shingo // O(n*2^(n3/8)) // // implement1 & debug1 214min // implement2 86min // debug2 122min // #include <stdio.h> #include <string.h> #include <algorithm> #include <iostream> #include <math.h> #include <assert.h> #include <vector> #include <queue> #include <stri...
2C++
{ "input": [ "2 -3 4\nL 2 5\n? 3 5" ], "output": [ "2\nL 4\nL 3" ] }
6AIZU
p01931 Check answers_1151
problem AOR Ika is studying to pass the test. AOR Ika-chan solved the $ N $ question. After that, round the solved problem according to the following procedure. 1. Check the correctness of the answer. 2. If the answer is correct, write a circle mark, and if it is incorrect, write a cross mark on the answer sheet. ...
p=int(input()) if p>0: dato=raw_input() i=dato.find("xx") if i<0: print p else: print i+1
1Python2
{ "input": [ "3\noxx", "3\nnxx", "3\nnwx", "3\nxxo", "3\nxwn", "3\nowx", "3\npxx", "3\npyx", "3\npzx", "3\npzw", "3\npwz", "3\nzwp", "3\nzxp", "3\npxz", "3\nzyp", "3\nyzp", "3\nyzq", "3\nyzr", "3\nxzr", "3\nrzx", "3\nxrz", "3\nwrz...
6AIZU
p01931 Check answers_1152
problem AOR Ika is studying to pass the test. AOR Ika-chan solved the $ N $ question. After that, round the solved problem according to the following procedure. 1. Check the correctness of the answer. 2. If the answer is correct, write a circle mark, and if it is incorrect, write a cross mark on the answer sheet. ...
#include<iostream> #include<string> using namespace std; int main(){ int N,i=0; string s; cin>>N>>s; for(i=1;i<N;i++){ if(s[i]=='x'&&s[i-1]=='x') break; } cout << i << endl; return 0; }
2C++
{ "input": [ "3\noxx", "3\nnxx", "3\nnwx", "3\nxxo", "3\nxwn", "3\nowx", "3\npxx", "3\npyx", "3\npzx", "3\npzw", "3\npwz", "3\nzwp", "3\nzxp", "3\npxz", "3\nzyp", "3\nyzp", "3\nyzq", "3\nyzr", "3\nxzr", "3\nrzx", "3\nxrz", "3\nwrz...
6AIZU
p01931 Check answers_1153
problem AOR Ika is studying to pass the test. AOR Ika-chan solved the $ N $ question. After that, round the solved problem according to the following procedure. 1. Check the correctness of the answer. 2. If the answer is correct, write a circle mark, and if it is incorrect, write a cross mark on the answer sheet. ...
def main(): N = int(input()) S = input() try: ans = S.index('xx') + 1 print(ans) except: print(N) main()
3Python3
{ "input": [ "3\noxx", "3\nnxx", "3\nnwx", "3\nxxo", "3\nxwn", "3\nowx", "3\npxx", "3\npyx", "3\npzx", "3\npzw", "3\npwz", "3\nzwp", "3\nzxp", "3\npxz", "3\nzyp", "3\nyzp", "3\nyzq", "3\nyzr", "3\nxzr", "3\nrzx", "3\nxrz", "3\nwrz...
6AIZU
p01931 Check answers_1154
problem AOR Ika is studying to pass the test. AOR Ika-chan solved the $ N $ question. After that, round the solved problem according to the following procedure. 1. Check the correctness of the answer. 2. If the answer is correct, write a circle mark, and if it is incorrect, write a cross mark on the answer sheet. ...
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); char[] s = sc.next().toCharArray(); boolean lastWrong = false; int ans = n; for(int i=0;i<n;i++) { if (s[i] == 'o') { lastWrong = false; }else{ i...
4JAVA
{ "input": [ "3\noxx", "3\nnxx", "3\nnwx", "3\nxxo", "3\nxwn", "3\nowx", "3\npxx", "3\npyx", "3\npzx", "3\npzw", "3\npwz", "3\nzwp", "3\nzxp", "3\npxz", "3\nzyp", "3\nyzp", "3\nyzq", "3\nyzr", "3\nxzr", "3\nrzx", "3\nxrz", "3\nwrz...
6AIZU
p02069 Universal and Existential Quantifiers_1155
Problem Statement You are given a list of $N$ intervals. The $i$-th interval is $[l_i, r_i)$, which denotes a range of numbers greater than or equal to $l_i$ and strictly less than $r_i$. In this task, you consider the following two numbers: * The minimum integer $x$ such that you can select $x$ intervals from the gi...
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <cmath> #include <map> #include <queue> #include <iomanip> #include <set> #include <tuple> #define mkp make_pair #define mkt make_tuple #define rep(i,n) for(int i = 0; i < (n); ++i) using namespace std; typedef long long ll; const ll ...
2C++
{ "input": [ "" ], "output": [ "" ] }
6AIZU
p02069 Universal and Existential Quantifiers_1156
Problem Statement You are given a list of $N$ intervals. The $i$-th interval is $[l_i, r_i)$, which denotes a range of numbers greater than or equal to $l_i$ and strictly less than $r_i$. In this task, you consider the following two numbers: * The minimum integer $x$ such that you can select $x$ intervals from the gi...
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { Scanner ir = new Scanner(System.in); int n = ir.nextInt(); long l = ir.nextLong(); long[][] x = new long[n][]; for (int i = 0; i < n; i++) { x[i] = new long[] { ir....
4JAVA
{ "input": [ "" ], "output": [ "" ] }
6AIZU
p02211 Apple Adventure_1157
Apple adventure square1001 and E869120 got lost in the grid world of $ H $ rows and $ W $ rows! Said the god of this world. "When you collect $ K $ apples and they meet, you'll be back in the original world." Upon hearing this word, square1001 decided to collect more than $ K $ of apples and head to the square wher...
#include <bits/stdc++.h> int ri() { int n; scanf("%d", &n); return n; } std::pair<int, int> d[] = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}}; int main() { int h = ri(), w = ri(), k = ri(); std::string a[h]; for (auto &i : a) std::cin >> i; int gx, gy, sx, sy; std::vector<std::pair<int, int> > apples; for (int i = 0;...
2C++
{ "input": [ "5 5 2\ns..#a\n.#...\na#e.#\n...#a\n.#...", "5 5 2\ns..#a\n.#...\ne#a.#\n...#a\n.#...", "5 5 2\ns..#a\n.#../\n#.a#e\n...#a\n.#...", "5 5 2\nb#..s\n.#/./\ne#a.#\n...#a\n.#...", "5 5 1\ns..#a\n.#...\na#e.#\n...#b\n.#...", "5 5 2\ns.#.a\n.#../\ne#a.#\n...#a\n.#...", "5 5 1\nc#..s...
6AIZU
p02365 Minimum-Cost Arborescence_1158
Find the sum of the weights of edges of the Minimum-Cost Arborescence with the root r for a given weighted directed graph G = (V, E). Constraints * 1 ≤ |V| ≤ 100 * 0 ≤ |E| ≤ 1,000 * 0 ≤ wi ≤ 10,000 * G has arborescence(s) with the root r Input |V| |E| r s0 t0 w0 s1 t1 w1 : s|E|-1 t|E|-1 w|E|-1 , where |V| is the...
V, E, r = map(int, raw_input().split()) es = [map(int, raw_input().split()) for i in xrange(E)] def solve(V, es, r): mins = [(10**18, -1)]*V for s, t, w in es: mins[t] = min(mins[t], (w, s)) mins[r] = (-1, -1) group = [0]*V comp = [0]*V cnt = 0 used = [0]*V for v in xrange(V):...
1Python2
{ "input": [ "4 6 0\n0 1 3\n0 2 2\n2 0 1\n2 3 1\n3 0 1\n3 1 5", "6 10 0\n0 2 7\n0 1 1\n0 3 5\n1 4 9\n2 1 6\n1 3 2\n3 4 3\n4 2 2\n2 5 8\n3 5 3", "4 6 0\n0 1 3\n0 2 2\n2 0 1\n2 3 2\n3 0 1\n3 1 5", "6 10 0\n0 2 7\n0 1 1\n0 3 5\n1 4 9\n2 1 6\n1 3 2\n3 4 3\n4 2 2\n1 5 8\n3 5 3", "4 6 0\n0 1 1\n0 2 2\n2...
6AIZU
p02365 Minimum-Cost Arborescence_1159
Find the sum of the weights of edges of the Minimum-Cost Arborescence with the root r for a given weighted directed graph G = (V, E). Constraints * 1 ≤ |V| ≤ 100 * 0 ≤ |E| ≤ 1,000 * 0 ≤ wi ≤ 10,000 * G has arborescence(s) with the root r Input |V| |E| r s0 t0 w0 s1 t1 w1 : s|E|-1 t|E|-1 w|E|-1 , where |V| is the...
#include <bits/stdc++.h> using namespace std; struct StronglyConnectedComponents { vector< vector< int > > gg, rg; vector< pair< int, int > > edges; vector< int > comp, order, used; StronglyConnectedComponents(size_t v) : gg(v), rg(v), comp(v, -1), used(v, 0) {} void add_edge(int x, int y) { gg[x].p...
2C++
{ "input": [ "4 6 0\n0 1 3\n0 2 2\n2 0 1\n2 3 1\n3 0 1\n3 1 5", "6 10 0\n0 2 7\n0 1 1\n0 3 5\n1 4 9\n2 1 6\n1 3 2\n3 4 3\n4 2 2\n2 5 8\n3 5 3", "4 6 0\n0 1 3\n0 2 2\n2 0 1\n2 3 2\n3 0 1\n3 1 5", "6 10 0\n0 2 7\n0 1 1\n0 3 5\n1 4 9\n2 1 6\n1 3 2\n3 4 3\n4 2 2\n1 5 8\n3 5 3", "4 6 0\n0 1 1\n0 2 2\n2...
6AIZU
p02365 Minimum-Cost Arborescence_1160
Find the sum of the weights of edges of the Minimum-Cost Arborescence with the root r for a given weighted directed graph G = (V, E). Constraints * 1 ≤ |V| ≤ 100 * 0 ≤ |E| ≤ 1,000 * 0 ≤ wi ≤ 10,000 * G has arborescence(s) with the root r Input |V| |E| r s0 t0 w0 s1 t1 w1 : s|E|-1 t|E|-1 w|E|-1 , where |V| is the...
from collections import defaultdict from itertools import chain nv, ne, r = map(int, input().split()) in_edges = defaultdict(set) out_edges = defaultdict(set) while ne: s, t, w = map(int, input().split()) in_edges[t].add((w, s)) out_edges[s].add((w, t)) ne -= 1 def chu_liu_edmond(vertices, cycle_cos...
3Python3
{ "input": [ "4 6 0\n0 1 3\n0 2 2\n2 0 1\n2 3 1\n3 0 1\n3 1 5", "6 10 0\n0 2 7\n0 1 1\n0 3 5\n1 4 9\n2 1 6\n1 3 2\n3 4 3\n4 2 2\n2 5 8\n3 5 3", "4 6 0\n0 1 3\n0 2 2\n2 0 1\n2 3 2\n3 0 1\n3 1 5", "6 10 0\n0 2 7\n0 1 1\n0 3 5\n1 4 9\n2 1 6\n1 3 2\n3 4 3\n4 2 2\n1 5 8\n3 5 3", "4 6 0\n0 1 1\n0 2 2\n2...
6AIZU
p02365 Minimum-Cost Arborescence_1161
Find the sum of the weights of edges of the Minimum-Cost Arborescence with the root r for a given weighted directed graph G = (V, E). Constraints * 1 ≤ |V| ≤ 100 * 0 ≤ |E| ≤ 1,000 * 0 ≤ wi ≤ 10,000 * G has arborescence(s) with the root r Input |V| |E| r s0 t0 w0 s1 t1 w1 : s|E|-1 t|E|-1 w|E|-1 , where |V| is the...
import java.util.ArrayList; import java.util.HashMap; import java.util.Map.Entry; import java.util.Map; import java.util.Scanner; public class Main { // root ????????????????°???¨?????¨????????????????±??????? public static long Chu_Liu_Edmonds(final int V, int root, ArrayList<Map<Integer, Long>> rev_adj) { // ...
4JAVA
{ "input": [ "4 6 0\n0 1 3\n0 2 2\n2 0 1\n2 3 1\n3 0 1\n3 1 5", "6 10 0\n0 2 7\n0 1 1\n0 3 5\n1 4 9\n2 1 6\n1 3 2\n3 4 3\n4 2 2\n2 5 8\n3 5 3", "4 6 0\n0 1 3\n0 2 2\n2 0 1\n2 3 2\n3 0 1\n3 1 5", "6 10 0\n0 2 7\n0 1 1\n0 3 5\n1 4 9\n2 1 6\n1 3 2\n3 4 3\n4 2 2\n1 5 8\n3 5 3", "4 6 0\n0 1 1\n0 2 2\n2...
6AIZU
acdemy_1162
Sherlock Holmes has decided to start a new academy to some of the young lads. He has conducted several tests and finally selected N equally brilliant students.Now he don't know whether to train all the N students or not. Now since Holmes was in a confusion, Watson came up with an idea. He wanted to test the obedience o...
# your code goes here from sys import stdin, stdout t = int(stdin.readline()) while t: t -= 1 n = int(stdin.readline()) a = map(int, stdin.readline().strip().split(' ')) if n <= 2: stdout.write(str(n)+"\n") else: m = 2 c = 2 i = 2 while i < n: if a[i] != a[i-1] + a[i-2]: m = max(c, m) c = 2 ...
1Python2
{ "input": [ "2\n5\n2 3 5 1 2\n3\n1 2 3" ], "output": [ "3\n3" ] }
1CODECHEF
chefrp_1163
Rupsa recently started to intern under Chef. He gave her N type of ingredients of varying quantity A1, A2, ..., AN respectively to store it. But as she is lazy to arrange them she puts them all in a storage box. Chef comes up with a new recipe and decides to prepare it. He asks Rupsa to get two units of each type ingr...
_ = int(raw_input()) for __ in range(_): N = int(raw_input()) arr = map(int,raw_input().split()) ans = 0 mx = 10**4 + 10 for num in arr : if num < 2: ans = -1 break ans = ans + num if num < mx: mx = num if ans != -1: ans = ans -...
1Python2
{ "input": [ "2\n2\n2 2\n1\n6", "2\n2\n2 1\n1\n6", "2\n2\n2 2\n1\n8", "2\n2\n4 2\n1\n6", "2\n1\n2 1\n1\n1", "2\n3\n3 2\n1\n8", "2\n3\n4 2\n0\n1", "2\n3\n4 7\n0\n6", "2\n3\n5 2\n0\n2", "2\n4\n4 9\n0\n6", "2\n6\n4 11\n0\n6", "2\n0\n2 2\n1\n1", "2\n6\n4 22\n0\n6", ...
1CODECHEF
donuts_1164
There is new delicious item in Chef's menu - a doughnut chain. Doughnuts connected successively in line forming a chain. Chain of 3 doughnuts Chef has received an urgent order for making a chain of N doughnuts. He noticed that there are exactly N cooked doughnuts in the kitchen, some of which are already connected i...
for t in xrange(input()): n, m = map(int, raw_input().strip().split()) arr = map(int, raw_input().strip().split()) arr.sort() cuts = 0 for i in xrange(m): k = m - i - cuts - 1 if k <= arr[i]: ans = cuts + k break cuts += arr[i] print ans
1Python2
{ "input": [ "2\n11 3\n4 3 4\n6 3\n3 2 1", "2\n11 3\n2 3 4\n6 3\n3 2 1", "2\n22 3\n2 0 3\n4 3\n3 2 1", "2\n22 3\n0 0 3\n4 3\n3 2 1", "2\n11 3\n2 3 4\n6 5\n3 2 1", "2\n22 6\n2 3 4\n6 3\n2 2 1", "2\n12 3\n0 0 3\n4 4\n3 1 1", "2\n11 5\n2 3 4\n9 5\n3 2 2", "2\n22 6\n0 3 7\n6 3\n4 2 0",...
1CODECHEF
ism1_1165
Hackers! Hackers! Everywhere! Some days back your email ID was hacked. Some one read the personal messages and Love Letters you sent to your girl friend. That's a terrible thing, well, you know how are the boys at ISM. So, you have decided that from now onwards you will write Love Letters to your girlfriend in a differ...
t=input() while t>0: b=[] a=raw_input().split() for i in range(len(a)): str=a[i] rev=str[::-1] b.append(rev) for i in range(len(b)): print b[i], print "\n" t=t-1
1Python2
{ "input": [ "3\ncan you meet me outside ccd today\na\nthis year hard kaur is coming to entertain us", "3\ncan you meet me ouuside ccd today\na\nthis year hard kaur is coming to entertain us", "3\ncan you meet me ouuside ccd today\na\nthis xear hard kaur is coming to entertain us", "3\ncan you meet me...
1CODECHEF
nopc10_1166
Computation of the date either previous or forthcoming dates is quiet easy. But it is quiet difficult to calculate the day from a particular given date. You are required to find a day from a particular date given to you. Input It consists of a single line entry consisting of date in format dd mm yyyy. i.e. the input...
import datetime dt='21/03/2012' day, month, year = (int(x) for x in dt.split('/')) ans=datetime.date(year,month,day) print (ans.strftime("%A"))
1Python2
{ "input": [ "14 3 2012", "14 2 2012", "14 4 2012", "14 4 1177", "20 4 1177", "20 4 1433", "20 3 1433", "14 3 1433", "14 3 1186", "14 1 1186", "7 1 1186", "7 2 1186", "7 2 1946", "7 1 1946", "10 1 1946", "10 1 3808", "2 1 3808", "2 1 6973", "...
1CODECHEF
seg003_1167
Problem description. The problem statement is simple , you are given an array and you have to perform two types of operation on it. Type 1 : update the value of array at the given index. Type 2 : find the maximum sum you can obtained in the given range ( L , R ) by taking any two index i and j , such that ( L <=...
# your code goes here from math import ceil, log from sys import stdin, stdout st = [] def getMid(s, e): return s + (e-s) / 2 def construct(st, arr, ss, se, si, type): if se == ss: if se%2 == type: st[si] = arr[ss] else: st[si] = 0 return st[si] m = getMid(ss, se) st[si] = max(construct(st, arr, ss, m,...
1Python2
{ "input": [ "5 3 \n1 2 3 4 5\n2 1 5\n1 2 5\n2 1 5" ], "output": [ "9 \n10" ] }
1CODECHEF
1003_D. Coins and Queries_1168
Polycarp has n coins, the value of the i-th coin is a_i. It is guaranteed that all the values are integer powers of 2 (i.e. a_i = 2^d for some non-negative integer number d). Polycarp wants to know answers on q queries. The j-th query is described as integer number b_j. The answer to the query is the minimum number of...
from sys import stdin,stdout a = map(int,stdin.readline().split()) n = a[0] q = a[1] a = map(int,stdin.readline().split()) d = {} for i in a: try: po = d[i] d[i] += 1 except: d[i] = 1 l = d.keys() l.sort(reverse = True) out = [] for t in range(q): b = int(stdin.readline()) c = 0...
1Python2
{ "input": [ "5 4\n2 4 8 2 4\n8\n5\n14\n10\n", "1 10\n8\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16\n", "1 10\n4\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16\n", "1 10\n2\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16\n", "1 10\n1\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16\n", "3 3\n1 1 1\n1\n2\n3\n", "4 1\n2 4 16 32\n14\n", "1 10\n8\n1\n2...
2CODEFORCES
1003_D. Coins and Queries_1169
Polycarp has n coins, the value of the i-th coin is a_i. It is guaranteed that all the values are integer powers of 2 (i.e. a_i = 2^d for some non-negative integer number d). Polycarp wants to know answers on q queries. The j-th query is described as integer number b_j. The answer to the query is the minimum number of...
#include <bits/stdc++.h> using namespace std; int main() { int n, q; map<int, int> coins; cin >> n >> q; int queries[q]; for (int i = 0; i < n; i++) { int val; cin >> val; coins[val]++; } for (int i = 0; i < q; i++) { cin >> queries[i]; } for (int i = 0; i < q; i++) { int counter =...
2C++
{ "input": [ "5 4\n2 4 8 2 4\n8\n5\n14\n10\n", "1 10\n8\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16\n", "1 10\n4\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16\n", "1 10\n2\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16\n", "1 10\n1\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16\n", "3 3\n1 1 1\n1\n2\n3\n", "4 1\n2 4 16 32\n14\n", "1 10\n8\n1\n2...
2CODEFORCES
1003_D. Coins and Queries_1170
Polycarp has n coins, the value of the i-th coin is a_i. It is guaranteed that all the values are integer powers of 2 (i.e. a_i = 2^d for some non-negative integer number d). Polycarp wants to know answers on q queries. The j-th query is described as integer number b_j. The answer to the query is the minimum number of...
# @oj: codeforces # @id: hitwanyang # @email: 296866643@qq.com # @date: 2020-10-14 16:44 # @url:https://codeforc.es/contest/1003/problem/D import sys,os from io import BytesIO, IOBase import collections,itertools,bisect,heapq,math,string from decimal import * # region fastio BUFSIZE = 8192 BUFSIZE = 8192 class FastI...
3Python3
{ "input": [ "5 4\n2 4 8 2 4\n8\n5\n14\n10\n", "1 10\n8\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16\n", "1 10\n4\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16\n", "1 10\n2\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16\n", "1 10\n1\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16\n", "3 3\n1 1 1\n1\n2\n3\n", "4 1\n2 4 16 32\n14\n", "1 10\n8\n1\n2...
2CODEFORCES
1003_D. Coins and Queries_1171
Polycarp has n coins, the value of the i-th coin is a_i. It is guaranteed that all the values are integer powers of 2 (i.e. a_i = 2^d for some non-negative integer number d). Polycarp wants to know answers on q queries. The j-th query is described as integer number b_j. The answer to the query is the minimum number of...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.StringTokenizer; import java.util.TreeMap; public class Main { public static boolean isPowOf2(int...
4JAVA
{ "input": [ "5 4\n2 4 8 2 4\n8\n5\n14\n10\n", "1 10\n8\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16\n", "1 10\n4\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16\n", "1 10\n2\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16\n", "1 10\n1\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16\n", "3 3\n1 1 1\n1\n2\n3\n", "4 1\n2 4 16 32\n14\n", "1 10\n8\n1\n2...
2CODEFORCES
1027_E. Inverse Coloring_1172
You are given a square board, consisting of n rows and n columns. Each tile in it should be colored either white or black. Let's call some coloring beautiful if each pair of adjacent rows are either the same or different in every position. The same condition should be held for the columns as well. Let's call some col...
import sys range = xrange input = raw_input MOD = 998244353 class sumseg: def __init__(self,n): m = 1 while m<n:m*=2 self.n = n self.m = m self.data = [0]*(n+m) def summa(self,l,r): l+=self.m r+=self.m s = 0 while l<r: if l%2=...
1Python2
{ "input": [ "2 3\n", "1 1\n", "49 1808\n", "4 15\n", "4 2\n", "467 4\n", "4 11\n", "4 7\n", "3 1\n", "4 14\n", "500 125000\n", "3 7\n", "499 248999\n", "3 2\n", "4 9\n", "3 4\n", "2 2\n", "4 12\n", "499 249001\n", "4 5\n", "499 24900...
2CODEFORCES
1027_E. Inverse Coloring_1173
You are given a square board, consisting of n rows and n columns. Each tile in it should be colored either white or black. Let's call some coloring beautiful if each pair of adjacent rows are either the same or different in every position. The same condition should be held for the columns as well. Let's call some col...
#include <bits/stdc++.h> using namespace std; long long mod = 998244353, dpp[510][510][4], dpc[510][510][4], f[510], g[510]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long tp2, i, j, n, k, cnt = 0, tp; cin >> n >> tp2; tp2--; dpp[1][1][1] = 1; dpp[1][1][2] = 1; for (...
2C++
{ "input": [ "2 3\n", "1 1\n", "49 1808\n", "4 15\n", "4 2\n", "467 4\n", "4 11\n", "4 7\n", "3 1\n", "4 14\n", "500 125000\n", "3 7\n", "499 248999\n", "3 2\n", "4 9\n", "3 4\n", "2 2\n", "4 12\n", "499 249001\n", "4 5\n", "499 24900...
2CODEFORCES
1027_E. Inverse Coloring_1174
You are given a square board, consisting of n rows and n columns. Each tile in it should be colored either white or black. Let's call some coloring beautiful if each pair of adjacent rows are either the same or different in every position. The same condition should be held for the columns as well. Let's call some col...
import sys from array import array # noqa: F401 def readline(): return sys.stdin.buffer.readline().decode('utf-8') n, k = map(int, readline().split()) mod = 998244353 if k == 1: print(0) exit() dp1 = [array('i', [0])*n for _ in range(n)] dp2 = [array('i', [0])*n for _ in range(n)] dp1[0][0] = 1 for i i...
3Python3
{ "input": [ "2 3\n", "1 1\n", "49 1808\n", "4 15\n", "4 2\n", "467 4\n", "4 11\n", "4 7\n", "3 1\n", "4 14\n", "500 125000\n", "3 7\n", "499 248999\n", "3 2\n", "4 9\n", "3 4\n", "2 2\n", "4 12\n", "499 249001\n", "4 5\n", "499 24900...
2CODEFORCES
1027_E. Inverse Coloring_1175
You are given a square board, consisting of n rows and n columns. Each tile in it should be colored either white or black. Let's call some coloring beautiful if each pair of adjacent rows are either the same or different in every position. The same condition should be held for the columns as well. Let's call some col...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual soluti...
4JAVA
{ "input": [ "2 3\n", "1 1\n", "49 1808\n", "4 15\n", "4 2\n", "467 4\n", "4 11\n", "4 7\n", "3 1\n", "4 14\n", "500 125000\n", "3 7\n", "499 248999\n", "3 2\n", "4 9\n", "3 4\n", "2 2\n", "4 12\n", "499 249001\n", "4 5\n", "499 24900...
2CODEFORCES
1046_D. Interstellar battle_1176
In the intergalactic empire Bubbledom there are N planets, of which some pairs are directly connected by two-way wormholes. There are N-1 wormholes. The wormholes are of extreme religious importance in Bubbledom, a set of planets in Bubbledom consider themselves one intergalactic kingdom if and only if any two planets ...
#include <bits/stdc++.h> using namespace std; int n, m; int x, y; double a[100005]; struct Edge { int v; Edge *next; } * h[100005], pool[100005 << 1]; int tot; void addEdge(int u, int v) { Edge *p = &pool[tot++]; p->v = v; p->next = h[u]; h[u] = p; } double ans; int um; double r; int fa[100005]; double son[...
2C++
{ "input": [ "5\n0.50 0.29 0.49 0.95 0.83\n2 3\n0 3\n3 4\n2 1\n3\n4 0.66\n1 0.69\n0 0.36\n", "26\n0.98 0.64 0.06 0.90 0.01 0.73 0.21 0.98 0.65 1.00 0.87 0.85 0.01 0.06 0.65 0.00 0.65 0.40 0.71 0.80 0.66 0.16 0.54 0.39 0.21 0.29\n20 21\n9 23\n9 0\n17 13\n16 20\n1 8\n9 4\n22 15\n14 17\n14 6\n2 16\n5 19\n11 23\n...
2CODEFORCES
1046_D. Interstellar battle_1177
In the intergalactic empire Bubbledom there are N planets, of which some pairs are directly connected by two-way wormholes. There are N-1 wormholes. The wormholes are of extreme religious importance in Bubbledom, a set of planets in Bubbledom consider themselves one intergalactic kingdom if and only if any two planets ...
//package bubble11; 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 D { InputStream is; PrintWriter out; String INPUT = ""; void solve() { int n = ni(); dou...
4JAVA
{ "input": [ "5\n0.50 0.29 0.49 0.95 0.83\n2 3\n0 3\n3 4\n2 1\n3\n4 0.66\n1 0.69\n0 0.36\n", "26\n0.98 0.64 0.06 0.90 0.01 0.73 0.21 0.98 0.65 1.00 0.87 0.85 0.01 0.06 0.65 0.00 0.65 0.40 0.71 0.80 0.66 0.16 0.54 0.39 0.21 0.29\n20 21\n9 23\n9 0\n17 13\n16 20\n1 8\n9 4\n22 15\n14 17\n14 6\n2 16\n5 19\n11 23\n...
2CODEFORCES
1070_C. Cloud Computing_1178
Buber is a Berland technology company that specializes in waste of investor's money. Recently Buber decided to transfer its infrastructure to a cloud. The company decided to rent CPU cores in the cloud for n consecutive days, which are numbered from 1 to n. Buber requires k CPU cores each day. The cloud provider offer...
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") using namespace std; const int N = 200005; long long int tree[2 * N]; long long int tree1[2 * N]; vector<long long int> e(N, 0); vector<long long int> cos1(N, 0); int m; vector<pair<pair<in...
2C++
{ "input": [ "7 13 5\n2 3 10 7\n3 5 10 10\n1 2 10 6\n4 5 10 9\n3 4 10 8\n", "4 100 3\n3 3 2 5\n1 1 3 2\n2 4 4 4\n", "5 7 3\n1 4 5 3\n1 3 5 2\n2 5 10 1\n", "5 2 5\n3 5 2 1\n2 3 1 4\n1 4 3 1\n2 3 1 2\n2 3 1 5\n", "2 1 1\n1 2 1 1\n", "1 2 1\n1 1 3 1\n", "2 1 5\n1 1 1 4\n2 2 1 1\n1 2 1 1\n1 2 ...
2CODEFORCES
1070_C. Cloud Computing_1179
Buber is a Berland technology company that specializes in waste of investor's money. Recently Buber decided to transfer its infrastructure to a cloud. The company decided to rent CPU cores in the cloud for n consecutive days, which are numbered from 1 to n. Buber requires k CPU cores each day. The cloud provider offer...
import java.io.*; import java.math.*; import java.util.*; public class Main { public static void solve(FastIO io) { int N = io.nextInt(); int K = io.nextInt(); int M = io.nextInt(); Plan[] plans = new Plan[M]; for (int i = 0; i < M; ++i) { plans[i] = new Plan(); plans[i].L = io.nextInt(); plans[i...
4JAVA
{ "input": [ "7 13 5\n2 3 10 7\n3 5 10 10\n1 2 10 6\n4 5 10 9\n3 4 10 8\n", "4 100 3\n3 3 2 5\n1 1 3 2\n2 4 4 4\n", "5 7 3\n1 4 5 3\n1 3 5 2\n2 5 10 1\n", "5 2 5\n3 5 2 1\n2 3 1 4\n1 4 3 1\n2 3 1 2\n2 3 1 5\n", "2 1 1\n1 2 1 1\n", "1 2 1\n1 1 3 1\n", "2 1 5\n1 1 1 4\n2 2 1 1\n1 2 1 1\n1 2 ...
2CODEFORCES
1091_G. New Year and the Factorisation Collaboration_1180
Integer factorisation is hard. The RSA Factoring Challenge offered $100 000 for factoring RSA-1024, a 1024-bit long product of two prime numbers. To this date, nobody was able to claim the prize. We want you to factorise a 1024-bit number. Since your programming language of choice might not offer facilities for handli...
import sys,random range = xrange input = raw_input def gcd(a,b): while b: a,b = b, a%b return a n = N = int(input()) def is_prime(n): """returns True if n is prime else False""" if n < 5 or n & 1 == 0 or n % 3 == 0: return 2 <= n <= 3 s = ((n - 2) ^ (n - 1)).bit_length() - 1 d...
1Python2
{ "input": [ "21\n\n7\n\n17\n\n15\n\n17\n\n11\n\n-1\n\n15\n\n", "3\n230967221047542071272908186525868331398921682471308664253988778356539397562182960087 182611080502122916090565666030857827681271950069759605734177210648361435031281924911 205581245187208120217130726679204642305706761599409643715552516156991358...
2CODEFORCES
1091_G. New Year and the Factorisation Collaboration_1181
Integer factorisation is hard. The RSA Factoring Challenge offered $100 000 for factoring RSA-1024, a 1024-bit long product of two prime numbers. To this date, nobody was able to claim the prize. We want you to factorise a 1024-bit number. Since your programming language of choice might not offer facilities for handli...
#include <bits/stdc++.h> using namespace std; unsigned long long gcd(unsigned long long a, unsigned long long b) { return b == 0 ? a : gcd(b, a % b); } const int BIGINTBITS = 32; const unsigned int BIGINTMASK = (1LL << BIGINTBITS) - 1; struct BigInt { vector<unsigned int> d; BigInt() {} BigInt(unsigned long lon...
2C++
{ "input": [ "21\n\n7\n\n17\n\n15\n\n17\n\n11\n\n-1\n\n15\n\n", "3\n230967221047542071272908186525868331398921682471308664253988778356539397562182960087 182611080502122916090565666030857827681271950069759605734177210648361435031281924911 205581245187208120217130726679204642305706761599409643715552516156991358...
2CODEFORCES
1091_G. New Year and the Factorisation Collaboration_1182
Integer factorisation is hard. The RSA Factoring Challenge offered $100 000 for factoring RSA-1024, a 1024-bit long product of two prime numbers. To this date, nobody was able to claim the prize. We want you to factorise a 1024-bit number. Since your programming language of choice might not offer facilities for handli...
import sys import random def gcd(x, y): return x if y == 0 else gcd(y, x % y) def isPrime(n): """ Miller-Rabin primality test. A return value of False means n is certainly not prime. A return value of True means n is very likely a prime. """ if n!=int(n): return False n=int(n)...
3Python3
{ "input": [ "21\n\n7\n\n17\n\n15\n\n17\n\n11\n\n-1\n\n15\n\n", "3\n230967221047542071272908186525868331398921682471308664253988778356539397562182960087 182611080502122916090565666030857827681271950069759605734177210648361435031281924911 205581245187208120217130726679204642305706761599409643715552516156991358...
2CODEFORCES
1091_G. New Year and the Factorisation Collaboration_1183
Integer factorisation is hard. The RSA Factoring Challenge offered $100 000 for factoring RSA-1024, a 1024-bit long product of two prime numbers. To this date, nobody was able to claim the prize. We want you to factorise a 1024-bit number. Since your programming language of choice might not offer facilities for handli...
import java.math.BigInteger; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class Main { static ArrayList<BigInteger> v; static Random rnd; static Scanner scanner; static BigInteger n; public static void factor() { for (int i = 0; i < 60; i++) { ...
4JAVA
{ "input": [ "21\n\n7\n\n17\n\n15\n\n17\n\n11\n\n-1\n\n15\n\n", "3\n230967221047542071272908186525868331398921682471308664253988778356539397562182960087 182611080502122916090565666030857827681271950069759605734177210648361435031281924911 205581245187208120217130726679204642305706761599409643715552516156991358...
2CODEFORCES
1110_E. Magic Stones_1184
Grigory has n magic stones, conveniently numbered from 1 to n. The charge of the i-th stone is equal to c_i. Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index i, where 2 ≤ i ≤ n - 1), and after that synchronizes it with neighboring stones. After that, the chosen stone loses its ...
n = input() a, b = [map(int, raw_input().split()) for _ in 0,0] x = [a[i] - a[i-1] for i in range(1, n)] y = [b[i] - b[i-1] for i in range(1, n)] print ['No', 'Yes'][sorted(x) == sorted(y) and a[0] == b[0]]
1Python2
{ "input": [ "4\n7 2 4 12\n7 15 10 12\n", "3\n4 4 4\n1 2 3\n", "10\n62159435 282618243 791521863 214307200 976959598 590907019 166397456 708291256 85377387 569889619\n296371399 546807332 272720717 689420404 273026579 74510326 749070707 104458586 450770185 466655231\n", "7\n12 9 8 6 9 12 84\n12 9 8 5 9...
2CODEFORCES
1110_E. Magic Stones_1185
Grigory has n magic stones, conveniently numbered from 1 to n. The charge of the i-th stone is equal to c_i. Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index i, where 2 ≤ i ≤ n - 1), and after that synchronizes it with neighboring stones. After that, the chosen stone loses its ...
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int t, c; vector<int> T(N - 1); vector<int> C(N - 1); cin >> t; int a = t; for (int i = 0; i < N - 1; i++) { int b; cin >> b; T[i] = abs(b - a); a = b; } cin >> c; int w = c; for (int i = 0; i < N - 1; i+...
2C++
{ "input": [ "4\n7 2 4 12\n7 15 10 12\n", "3\n4 4 4\n1 2 3\n", "10\n62159435 282618243 791521863 214307200 976959598 590907019 166397456 708291256 85377387 569889619\n296371399 546807332 272720717 689420404 273026579 74510326 749070707 104458586 450770185 466655231\n", "7\n12 9 8 6 9 12 84\n12 9 8 5 9...
2CODEFORCES
1110_E. Magic Stones_1186
Grigory has n magic stones, conveniently numbered from 1 to n. The charge of the i-th stone is equal to c_i. Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index i, where 2 ≤ i ≤ n - 1), and after that synchronizes it with neighboring stones. After that, the chosen stone loses its ...
n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) f=a[0]==b[0] a=sorted([a[i+1]-a[i] for i in range(n-1)]) b=sorted([b[i+1]-b[i] for i in range(n-1)]) print('YES' if f and a==b else 'NO')
3Python3
{ "input": [ "4\n7 2 4 12\n7 15 10 12\n", "3\n4 4 4\n1 2 3\n", "10\n62159435 282618243 791521863 214307200 976959598 590907019 166397456 708291256 85377387 569889619\n296371399 546807332 272720717 689420404 273026579 74510326 749070707 104458586 450770185 466655231\n", "7\n12 9 8 6 9 12 84\n12 9 8 5 9...
2CODEFORCES
1110_E. Magic Stones_1187
Grigory has n magic stones, conveniently numbered from 1 to n. The charge of the i-th stone is equal to c_i. Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index i, where 2 ≤ i ≤ n - 1), and after that synchronizes it with neighboring stones. After that, the chosen stone loses its ...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Random; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.io.BufferedReader; import java.io.InputStream; /...
4JAVA
{ "input": [ "4\n7 2 4 12\n7 15 10 12\n", "3\n4 4 4\n1 2 3\n", "10\n62159435 282618243 791521863 214307200 976959598 590907019 166397456 708291256 85377387 569889619\n296371399 546807332 272720717 689420404 273026579 74510326 749070707 104458586 450770185 466655231\n", "7\n12 9 8 6 9 12 84\n12 9 8 5 9...
2CODEFORCES
1140_B. Good String_1188
You have a string s of length n consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the l...
n = int(raw_input()) for k in xrange(n): ns = int(raw_input()) s = raw_input() cont = 0 while cont < ns and s[cont] == "<": cont += 1 cont2 = -1 while -cont2 <= ns and s[cont2] == ">": cont2 -= 1 print min((-cont2)-1, cont)
1Python2
{ "input": [ "3\n2\n&lt;&gt;\n3\n&gt;&lt;&lt;\n1\n&gt;\n", "1\n9\n>>>>>>>><\n", "13\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n", "14\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n<\n", "3\n2\n<>\n3\n><<\n1\n>\n", "13\n1\n...
2CODEFORCES
1140_B. Good String_1189
You have a string s of length n consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the l...
#include <bits/stdc++.h> using namespace std; void pikachu() {} short t, n; char a[111]; int main() { pikachu(); scanf("%hd", &t); short u, v; while (t--) { scanf("%hd", &n); scanf("%s", a + 1); u = 0; v = n + 1; for (short i = 1; i <= n; ++i) { if (a[i] == '<') u = i; el...
2C++
{ "input": [ "3\n2\n&lt;&gt;\n3\n&gt;&lt;&lt;\n1\n&gt;\n", "1\n9\n>>>>>>>><\n", "13\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n", "14\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n<\n", "3\n2\n<>\n3\n><<\n1\n>\n", "13\n1\n...
2CODEFORCES
1140_B. Good String_1190
You have a string s of length n consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the l...
t = int(input()) tests = [] for i in range(t): length = int(input()) tests.append(input()) def solve(s): streak1 = 0 streak2 = 0 for i in range(len(s)): if s[i] == "<": streak1 +=1 else: break for i in range(len(s)): if s[-i-1] == ">": ...
3Python3
{ "input": [ "3\n2\n&lt;&gt;\n3\n&gt;&lt;&lt;\n1\n&gt;\n", "1\n9\n>>>>>>>><\n", "13\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n", "14\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n<\n", "3\n2\n<>\n3\n><<\n1\n>\n", "13\n1\n...
2CODEFORCES
1140_B. Good String_1191
You have a string s of length n consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the l...
import java.util.Scanner; public class good_string { public static void main(String[] args) { // TODO Auto-generated method stub Scanner s = new Scanner(System.in); int t=s.nextInt()...
4JAVA
{ "input": [ "3\n2\n&lt;&gt;\n3\n&gt;&lt;&lt;\n1\n&gt;\n", "1\n9\n>>>>>>>><\n", "13\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n", "14\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n<\n", "3\n2\n<>\n3\n><<\n1\n>\n", "13\n1\n...
2CODEFORCES
1158_F. Density of subarrays_1192
Let c be some positive integer. Let's call an array a_1, a_2, …, a_n of positive integers c-array, if for all i condition 1 ≤ a_i ≤ c is satisfied. Let's call c-array b_1, b_2, …, b_k a subarray of c-array a_1, a_2, …, a_n, if there exists such set of k indices 1 ≤ i_1 < i_2 < … < i_k ≤ n that b_j = a_{i_j} for all 1 ≤...
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; int n, c, m, a[3010]; int ksm(int x, int y = mod - 2) { int z = 1; for (; y; y >>= 1, x = 1ll * x * x % mod) if (y & 1) z = 1ll * z * x % mod; return z; } void ADD(int &x, int y) { x += y; if (x >= mod) x -= mod; } int SUM(int x, int...
2C++
{ "input": [ "5 2\n1 2 1 2 1\n", "3 3\n1 2 3\n", "4 1\n1 1 1 1\n", "2 1\n1 1\n", "2 3\n3 1\n", "100 5\n5 5 2 4 5 4 4 4 4 2 5 3 4 2 4 4 1 1 5 3 2 2 1 3 3 2 5 3 4 5 1 3 5 4 4 4 3 1 4 4 3 4 5 2 5 4 2 1 2 2 3 5 5 5 1 4 5 3 1 4 2 2 5 1 5 3 4 1 5 1 2 2 3 5 1 3 2 4 2 4 2 2 4 1 3 5 2 2 2 3 3 4 3 2 2 5...
2CODEFORCES
1158_F. Density of subarrays_1193
Let c be some positive integer. Let's call an array a_1, a_2, …, a_n of positive integers c-array, if for all i condition 1 ≤ a_i ≤ c is satisfied. Let's call c-array b_1, b_2, …, b_k a subarray of c-array a_1, a_2, …, a_n, if there exists such set of k indices 1 ≤ i_1 < i_2 < … < i_k ≤ n that b_j = a_{i_j} for all 1 ≤...
// https://codeforces.com/contest/1158/submission/54045740 (ecnerwala) // upsolve with rainboy import java.io.*; import java.util.*; public class CF1158F { static final int MD = 998244353; static long power(int a, int k) { if (k == 0) return 1; long p = power(a, k / 2); p = p * p % MD; if (k % 2 == 1) ...
4JAVA
{ "input": [ "5 2\n1 2 1 2 1\n", "3 3\n1 2 3\n", "4 1\n1 1 1 1\n", "2 1\n1 1\n", "2 3\n3 1\n", "100 5\n5 5 2 4 5 4 4 4 4 2 5 3 4 2 4 4 1 1 5 3 2 2 1 3 3 2 5 3 4 5 1 3 5 4 4 4 3 1 4 4 3 4 5 2 5 4 2 1 2 2 3 5 5 5 1 4 5 3 1 4 2 2 5 1 5 3 4 1 5 1 2 2 3 5 1 3 2 4 2 4 2 2 4 1 3 5 2 2 2 3 3 4 3 2 2 5...
2CODEFORCES
1180_E. Serge and Dining Room_1194
Serge came to the school dining room and discovered that there is a big queue here. There are m pupils in the queue. He's not sure now if he wants to wait until the queue will clear, so he wants to know which dish he will receive if he does. As Serge is very tired, he asks you to compute it instead of him. Initially t...
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e6, big = 1e18; long long val[maxn], t[4 * maxn + 5], sum[4 * maxn + 5]; void build(long long v, long long l, long long r) { if (l == r - 1) { sum[v] = 0; t[v] = val[l]; return; } long long m = (l + r) / 2; build(2 * v, l, m); b...
2C++
{ "input": [ "1 1\n1\n1\n1\n2 1 100\n", "4 6\n1 8 2 4\n3 3 6 1 5 2\n3\n1 1 1\n2 5 10\n1 1 6\n", "1 1\n1\n1\n1\n1 1 100\n", "4 1\n7 6 1 1\n3\n3\n2 1 9\n2 1 10\n2 1 6\n", "5 1\n8 4 8 7 3\n9\n5\n2 1 3\n1 5 1\n2 1 8\n2 1 7\n2 1 3\n", "3 5\n3 2 8\n1 2 8 1 1\n4\n1 3 3\n1 2 2\n2 2 10\n1 1 5\n", "...
2CODEFORCES
1180_E. Serge and Dining Room_1195
Serge came to the school dining room and discovered that there is a big queue here. There are m pupils in the queue. He's not sure now if he wants to wait until the queue will clear, so he wants to know which dish he will receive if he does. As Serge is very tired, he asks you to compute it instead of him. Initially t...
import java.io.BufferedWriter; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.Scanner; public class Serg6 { static int MILLION = 1000000; public static void main(String[] args) { LazySegmentTree segTree = new LazySegmentTree(1, MILLION); Scanner in = new Scanne...
4JAVA
{ "input": [ "1 1\n1\n1\n1\n2 1 100\n", "4 6\n1 8 2 4\n3 3 6 1 5 2\n3\n1 1 1\n2 5 10\n1 1 6\n", "1 1\n1\n1\n1\n1 1 100\n", "4 1\n7 6 1 1\n3\n3\n2 1 9\n2 1 10\n2 1 6\n", "5 1\n8 4 8 7 3\n9\n5\n2 1 3\n1 5 1\n2 1 8\n2 1 7\n2 1 3\n", "3 5\n3 2 8\n1 2 8 1 1\n4\n1 3 3\n1 2 2\n2 2 10\n1 1 5\n", "...
2CODEFORCES
1199_E. Matching vs Independent Set_1196
You are given a graph with 3 ⋅ n vertices and m edges. You are to find a matching of n edges, or an independent set of n vertices. A set of edges is called a matching if no two edges share an endpoint. A set of vertices is called an independent set if no two vertices are connected with an edge. Input The first line...
#include <bits/stdc++.h> using namespace std; const long long N = 3e5 + 5, inf = 1e18 + 100; vector<long long> g[N]; long long used[N]; void solve() { long long n, m; cin >> n >> m; for (long long i = 1; i <= 3 * n; ++i) g[i].clear(), used[i] = 0; vector<long long> seq; for (long long i = 1; i <= m; ++i) { ...
2C++
{ "input": [ "4\n1 2\n1 3\n1 2\n1 2\n1 3\n1 2\n2 5\n1 2\n3 1\n1 4\n5 1\n1 6\n2 15\n1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n4 5\n4 6\n5 6\n", "1\n5 39\n1 2\n3 4\n5 6\n7 8\n1 9\n3 10\n3 11\n5 12\n5 13\n7 14\n7 15\n9 2\n10 2\n11 2\n12 2\n13 2\n14 2\n15 2\n9 4\n10 4\n11 4\n12 4\n13 4\n14 4\n15...
2CODEFORCES
1199_E. Matching vs Independent Set_1197
You are given a graph with 3 ⋅ n vertices and m edges. You are to find a matching of n edges, or an independent set of n vertices. A set of edges is called a matching if no two edges share an endpoint. A set of vertices is called an independent set if no two vertices are connected with an edge. Input The first line...
import sys input = sys.stdin.readline T = int(input()) for _ in range(T): n, m = map(int, input().split()) v = [True] * (3 * n + 1) e = [0] * n ptr = 0 for i in range(1, m + 1): a, b = map(int, input().split()) if ptr < n and v[a] and v[b]: e[ptr] = i ptr += 1...
3Python3
{ "input": [ "4\n1 2\n1 3\n1 2\n1 2\n1 3\n1 2\n2 5\n1 2\n3 1\n1 4\n5 1\n1 6\n2 15\n1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n4 5\n4 6\n5 6\n", "1\n5 39\n1 2\n3 4\n5 6\n7 8\n1 9\n3 10\n3 11\n5 12\n5 13\n7 14\n7 15\n9 2\n10 2\n11 2\n12 2\n13 2\n14 2\n15 2\n9 4\n10 4\n11 4\n12 4\n13 4\n14 4\n15...
2CODEFORCES
1199_E. Matching vs Independent Set_1198
You are given a graph with 3 ⋅ n vertices and m edges. You are to find a matching of n edges, or an independent set of n vertices. A set of edges is called a matching if no two edges share an endpoint. A set of vertices is called an independent set if no two vertices are connected with an edge. Input The first line...
import java.io.*; import java.util.*; public class TaskE { void run() { FastReader in = new FastReader(System.in); // FastReader in = new FastReader(new FileInputStream("input.txt")); PrintWriter out = new PrintWriter(System.out); // PrintWriter out = new PrintWriter(new FileOutputSt...
4JAVA
{ "input": [ "4\n1 2\n1 3\n1 2\n1 2\n1 3\n1 2\n2 5\n1 2\n3 1\n1 4\n5 1\n1 6\n2 15\n1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n4 5\n4 6\n5 6\n", "1\n5 39\n1 2\n3 4\n5 6\n7 8\n1 9\n3 10\n3 11\n5 12\n5 13\n7 14\n7 15\n9 2\n10 2\n11 2\n12 2\n13 2\n14 2\n15 2\n9 4\n10 4\n11 4\n12 4\n13 4\n14 4\n15...
2CODEFORCES
1216_D. Swords_1199
There were n types of swords in the theater basement which had been used during the plays. Moreover there were exactly x swords of each type. y people have broken into the theater basement and each of them has taken exactly z swords of some single type. Note that different people might have taken different types of swo...
# Enter your code here. Read input from STDIN. Print output to STDOUT# =============================================================================================== # importing some useful libraries. from __future__ import division, print_function from fractions import Fraction import sys import os from io import Byt...
1Python2
{ "input": [ "2\n2 9\n", "3\n3 12 6\n", "7\n2 1000000000 4 6 8 4 2\n", "6\n13 52 0 13 26 52\n", "10\n100000000 200000000 300000000 20 500000000 600000000 700000000 800000000 900000000 1000000000\n", "10\n1 1000000000 1 1 1 1 1 1 1 1\n", "5\n0 0 1 0 0\n", "10\n1000000000 1 2 3 4 5 6 7 8...
2CODEFORCES