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
1025_D. Recovering BST_2400
Dima the hamster enjoys nibbling different things: cages, sticks, bad problemsetters and even trees! Recently he found a binary search tree and instinctively nibbled all of its edges, hence messing up the vertices. Dima knows that if Andrew, who has been thoroughly assembling the tree for a long time, comes home and s...
import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.regex.*; import javafx.util.*; public class Solution { static class com implements Comparator<Pair<Integer,Integer>>{ public int compare(Pair<Integer,Integer...
4JAVA
{ "input": [ "9\n4 8 10 12 15 18 33 44 81\n", "6\n3 6 9 18 36 108\n", "2\n7 17\n", "4\n3 5 7 105\n", "13\n2 12 60 300 900 6300 44100 176400 352800 705600 3528000 21168000 148176000\n", "11\n2 6 15 35 77 143 221 323 437 667 899\n", "4\n2 3 5 30\n", "27\n5 10 29 58 116 174 2297 4594 9188...
2CODEFORCES
1045_F. Shady Lady_2401
Ani and Borna are playing a short game on a two-variable polynomial. It's a special kind of a polynomial: the monomials are fixed, but all of its coefficients are fill-in-the-blanks dashes, e.g. $$$ \\_ xy + \\_ x^4 y^7 + \\_ x^8 y^3 + … $$$ Borna will fill in the blanks with positive integers. He wants the polynomial...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; struct Node { int x, y, id; Node operator+(Node A) { return (Node){x + A.x, y + A.y, id}; } Node operator-(Node A) { return (Node){x - A.x, y - A.y, id}; } long long operator*(Node A) const { return 1ll * x * A.y - 1ll * y * A.x; } long lon...
2C++
{ "input": [ "3\n1 1\n2 0\n0 2\n", "4\n0 0\n0 1\n0 2\n0 8\n", "2\n2 0\n0 0\n", "10\n2 0\n5 0\n6 0\n8 0\n4 6\n5 5\n6 6\n2 4\n8 4\n3 3\n", "2\n1 0\n0 0\n", "2\n1 0\n2 0\n", "2\n2 0\n3 0\n", "5\n0 0\n500000000 2\n999999998 6\n499999999 2\n0 1000000000\n", "8\n8 8\n7 6\n10 2\n10 6\n9 6...
2CODEFORCES
1045_F. Shady Lady_2402
Ani and Borna are playing a short game on a two-variable polynomial. It's a special kind of a polynomial: the monomials are fixed, but all of its coefficients are fill-in-the-blanks dashes, e.g. $$$ \\_ xy + \\_ x^4 y^7 + \\_ x^8 y^3 + … $$$ Borna will fill in the blanks with positive integers. He wants the polynomial...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.AbstractSet; import java.util.InputMismatchException; import java.util.Random; import java.util.ArrayList; import java.util.AbstractCollection; import java.util.Map; import java.io.OutputStream...
4JAVA
{ "input": [ "3\n1 1\n2 0\n0 2\n", "4\n0 0\n0 1\n0 2\n0 8\n", "2\n2 0\n0 0\n", "10\n2 0\n5 0\n6 0\n8 0\n4 6\n5 5\n6 6\n2 4\n8 4\n3 3\n", "2\n1 0\n0 0\n", "2\n1 0\n2 0\n", "2\n2 0\n3 0\n", "5\n0 0\n500000000 2\n999999998 6\n499999999 2\n0 1000000000\n", "8\n8 8\n7 6\n10 2\n10 6\n9 6...
2CODEFORCES
1068_F. Knights_2403
Ivan places knights on infinite chessboard. Initially there are n knights. If there is free cell which is under attack of at least 4 knights then he places new knight in this cell. Ivan repeats this until there are no such free cells. One can prove that this process is finite. One can also prove that position in the en...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int y = 0, k = 0; while (y != n) { if (k % 2 == 0) { cout << k << " 0" << endl; y++; } else { if (n - y == 1) { cout << k << " 0" << endl; y++; } else if (k % 2 == 1) { cout << k...
2C++
{ "input": [ "7\n", "4\n", "523\n", "4\n", "40\n", "14\n", "23\n", "11\n", "27\n", "7\n", "1\n", "1000\n", "41\n", "38\n", "346\n", "26\n", "21\n", "25\n", "19\n", "13\n", "30\n", "42\n", "79\n", "33\n", "12\n", "1...
2CODEFORCES
1068_F. Knights_2404
Ivan places knights on infinite chessboard. Initially there are n knights. If there is free cell which is under attack of at least 4 knights then he places new knight in this cell. Ivan repeats this until there are no such free cells. One can prove that this process is finite. One can also prove that position in the en...
n = int(input()) anss = [(0, 0)] for i in range(1, n): anss.append((0, i)) anss.append((i, 0)) anss.append((0, -i)) anss.append((-i, 0)) for i in range(n): print(str(anss[i][0]) + ' ' + str(anss[i][1]))
3Python3
{ "input": [ "7\n", "4\n", "523\n", "4\n", "40\n", "14\n", "23\n", "11\n", "27\n", "7\n", "1\n", "1000\n", "41\n", "38\n", "346\n", "26\n", "21\n", "25\n", "19\n", "13\n", "30\n", "42\n", "79\n", "33\n", "12\n", "1...
2CODEFORCES
1068_F. Knights_2405
Ivan places knights on infinite chessboard. Initially there are n knights. If there is free cell which is under attack of at least 4 knights then he places new knight in this cell. Ivan repeats this until there are no such free cells. One can prove that this process is finite. One can also prove that position in the en...
import java.io.*; import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; public class F { public static void main(String[] args) throws IOException { try (Input input = new StandardInput(); PrintWriter writ...
4JAVA
{ "input": [ "7\n", "4\n", "523\n", "4\n", "40\n", "14\n", "23\n", "11\n", "27\n", "7\n", "1\n", "1000\n", "41\n", "38\n", "346\n", "26\n", "21\n", "25\n", "19\n", "13\n", "30\n", "42\n", "79\n", "33\n", "12\n", "1...
2CODEFORCES
1090_J. Two Prefixes_2406
Misha didn't do his math homework for today's lesson once again. As a punishment, his teacher Dr. Andrew decided to give him a hard, but very useless task. Dr. Andrew has written two strings s and t of lowercase English letters at the blackboard. He reminded Misha that prefix of a string is a string formed by removing...
#include <bits/stdc++.h> const int N = 200005; std::string s, t; int lcp, next[N], occur[N]; void kmp(const std::string &s) { for (int i = 1, j = next[0] = -1; i <= s.size(); next[i++] = ++j) for (; j >= 0 && s[j] != s[i - 1];) j = next[j]; } int size[N], idx = 1, lst = 1; int nxt[N][26], fail[N], max[N]; void ap...
2C++
{ "input": [ "aaaaa\naaaa\n", "aba\naa\n", "nnqnnnqqnqnn\nqnnqqqqqqnqnqqqnqnnqqqqnnnqqnqnqnnq\n", "k\nk\n", "jj\njj\n", "e\nee\n", "nnqnnnqqnqnn\nqnnqnqnqqnnnqqqqnnqnqqqnqnqqqqqqnnq\n", "k\nl\n", "jj\nij\n", "e\nef\n", "abaaa\naaaa\n", "aab\naa\n", "baa\nab\n", ...
2CODEFORCES
1090_J. Two Prefixes_2407
Misha didn't do his math homework for today's lesson once again. As a punishment, his teacher Dr. Andrew decided to give him a hard, but very useless task. Dr. Andrew has written two strings s and t of lowercase English letters at the blackboard. He reminded Misha that prefix of a string is a string formed by removing...
import java.io.*; import java.util.*; import java.math.*; import java.lang.*; import static java.lang.Math.*; public class Main implements Runnable { static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numCha...
4JAVA
{ "input": [ "aaaaa\naaaa\n", "aba\naa\n", "nnqnnnqqnqnn\nqnnqqqqqqnqnqqqnqnnqqqqnnnqqnqnqnnq\n", "k\nk\n", "jj\njj\n", "e\nee\n", "nnqnnnqqnqnn\nqnnqnqnqqnnnqqqqnnqnqqqnqnqqqqqqnnq\n", "k\nl\n", "jj\nij\n", "e\nef\n", "abaaa\naaaa\n", "aab\naa\n", "baa\nab\n", ...
2CODEFORCES
110_B. Lucky String_2408
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya recently learned to determine whether a string of lowercase Latin letters is lucky. For each i...
n=int(raw_input()) s="abcd" * n print s[:n]
1Python2
{ "input": [ "3\n", "5\n", "1\n", "77777\n", "16\n", "9999\n", "10\n", "64\n", "74\n", "99\n", "1024\n", "47589\n", "9475\n", "100\n", "1000\n", "99994\n", "747\n", "2\n", "7\n", "8\n", "128\n", "6\n", "2075\n", "9\n", ...
2CODEFORCES
110_B. Lucky String_2409
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya recently learned to determine whether a string of lowercase Latin letters is lucky. For each i...
#include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n) { for (int i = 0; i < n; i++) cout << (char)('a' + i % 4); cout << endl; } }
2C++
{ "input": [ "3\n", "5\n", "1\n", "77777\n", "16\n", "9999\n", "10\n", "64\n", "74\n", "99\n", "1024\n", "47589\n", "9475\n", "100\n", "1000\n", "99994\n", "747\n", "2\n", "7\n", "8\n", "128\n", "6\n", "2075\n", "9\n", ...
2CODEFORCES
110_B. Lucky String_2410
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya recently learned to determine whether a string of lowercase Latin letters is lucky. For each i...
n=int(input()) x='a'+'bcda'*25002 print(x[:n])
3Python3
{ "input": [ "3\n", "5\n", "1\n", "77777\n", "16\n", "9999\n", "10\n", "64\n", "74\n", "99\n", "1024\n", "47589\n", "9475\n", "100\n", "1000\n", "99994\n", "747\n", "2\n", "7\n", "8\n", "128\n", "6\n", "2075\n", "9\n", ...
2CODEFORCES
110_B. Lucky String_2411
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya recently learned to determine whether a string of lowercase Latin letters is lucky. For each i...
import java.util.Scanner; public class LuckyString { public static void main(String asd[])throws Exception { Scanner in=new Scanner(System.in); int n=in.nextInt(); char ch[]=new char[n]; for(int i=0;i<n;i+=4) ch[i]='a'; char c='b'; in...
4JAVA
{ "input": [ "3\n", "5\n", "1\n", "77777\n", "16\n", "9999\n", "10\n", "64\n", "74\n", "99\n", "1024\n", "47589\n", "9475\n", "100\n", "1000\n", "99994\n", "747\n", "2\n", "7\n", "8\n", "128\n", "6\n", "2075\n", "9\n", ...
2CODEFORCES
1139_E. Maximize Mex_2412
There are n students and m clubs in a college. The clubs are numbered from 1 to m. Each student has a potential p_i and is a member of the club with index c_i. Initially, each student is a member of exactly one club. A technical fest starts in the college, and it will run for the next d days. There is a coding competit...
#include <bits/stdc++.h> #pragma GCC optimize("O3") std::pair<int, int> DR[] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}, {-1, 1}, {-1, -1}, {1, 1}, {1, -1}}; using namespace std; int gcd(int a, int b) { if (b) return gcd(b, a % b); return a; } mt19937 rng(chrono::steady_clock::now().time_sinc...
2C++
{ "input": [ "5 5\n0 1 2 4 5\n1 2 3 4 5\n4\n2\n3\n5\n4\n", "5 3\n0 1 2 2 0\n1 2 2 3 2\n5\n3\n2\n4\n5\n1\n", "5 3\n0 1 2 2 1\n1 3 2 3 2\n5\n4\n2\n3\n5\n1\n", "5 5\n0 0 1 1 2\n1 2 2 3 2\n2\n2\n3\n", "5 3\n0 0 1 1 2\n1 2 2 3 2\n2\n2\n3\n", "10 5\n0 1 1 0 3 1 3 0 2 0\n5 4 3 4 3 4 1 2 3 3\n10\n1\n2...
2CODEFORCES
1139_E. Maximize Mex_2413
There are n students and m clubs in a college. The clubs are numbered from 1 to m. Each student has a potential p_i and is a member of the club with index c_i. Initially, each student is a member of exactly one club. A technical fest starts in the college, and it will run for the next d days. There is a coding competit...
import sys input = sys.stdin.readline n, m = map(int, input().split()) p = list(map(int, input().split())) c = list(map(int, input().split())) d = int(input()) disable = [False] * n base = 5001 ds = [int(input())-1 for _ in range(d)] for ele in ds: disable[ele] = True # Create Graph childs = [[] for i in range(...
3Python3
{ "input": [ "5 5\n0 1 2 4 5\n1 2 3 4 5\n4\n2\n3\n5\n4\n", "5 3\n0 1 2 2 0\n1 2 2 3 2\n5\n3\n2\n4\n5\n1\n", "5 3\n0 1 2 2 1\n1 3 2 3 2\n5\n4\n2\n3\n5\n1\n", "5 5\n0 0 1 1 2\n1 2 2 3 2\n2\n2\n3\n", "5 3\n0 0 1 1 2\n1 2 2 3 2\n2\n2\n3\n", "10 5\n0 1 1 0 3 1 3 0 2 0\n5 4 3 4 3 4 1 2 3 3\n10\n1\n2...
2CODEFORCES
1139_E. Maximize Mex_2414
There are n students and m clubs in a college. The clubs are numbered from 1 to m. Each student has a potential p_i and is a member of the club with index c_i. Initially, each student is a member of exactly one club. A technical fest starts in the college, and it will run for the next d days. There is a coding competit...
//package round548; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.BitSet; import java.util.InputMismatchException; import java.util.List; public class E { InputStream is; P...
4JAVA
{ "input": [ "5 5\n0 1 2 4 5\n1 2 3 4 5\n4\n2\n3\n5\n4\n", "5 3\n0 1 2 2 0\n1 2 2 3 2\n5\n3\n2\n4\n5\n1\n", "5 3\n0 1 2 2 1\n1 3 2 3 2\n5\n4\n2\n3\n5\n1\n", "5 5\n0 0 1 1 2\n1 2 2 3 2\n2\n2\n3\n", "5 3\n0 0 1 1 2\n1 2 2 3 2\n2\n2\n3\n", "10 5\n0 1 1 0 3 1 3 0 2 0\n5 4 3 4 3 4 1 2 3 3\n10\n1\n2...
2CODEFORCES
1157_E. Minimum Array_2415
You are given two arrays a and b, both of length n. All elements of both arrays are from 0 to n-1. You can reorder elements of the array b (if you want, you may leave the order of elements as it is). After that, let array c be the array of length n, the i-th element of this array is c_i = (a_i + b_i) \% n, where x \% ...
#!/usr/bin/env python from __future__ import division, print_function import operator as op import os import sys from bisect import bisect_left, bisect_right, insort from io import BytesIO, IOBase from itertools import chain, repeat, starmap if sys.version_info[0] < 3: from __builtin__ import xrange as range ...
1Python2
{ "input": [ "4\n0 1 2 1\n3 2 1 1\n", "7\n2 5 1 5 3 4 3\n2 4 3 5 6 5 1\n", "1\n0\n0\n", "10\n6 3 0 5 4 5 5 5 8 5\n3 8 2 9 5 4 1 0 3 6\n", "5\n1 4 2 1 3\n3 3 1 0 1\n", "5\n2 1 3 0 4\n1 0 3 2 3\n", "4\n1 2 1 1\n1 3 0 2\n", "3\n2 0 0\n1 0 2\n", "4\n1 1 0 3\n2 0 2 2\n", "3\n0 1 1\n...
2CODEFORCES
1157_E. Minimum Array_2416
You are given two arrays a and b, both of length n. All elements of both arrays are from 0 to n-1. You can reorder elements of the array b (if you want, you may leave the order of elements as it is). After that, let array c be the array of length n, the i-th element of this array is c_i = (a_i + b_i) \% n, where x \% ...
#include <bits/stdc++.h> using namespace std; int n; int a[200005], b[200005], c[200005], ans[200005]; int t[200005 << 3]; void pushup(int x) { t[x] = t[x << 1] + t[x << 1 | 1]; } void build(int x, int l, int r) { if (l == r) { t[x] = c[l]; return; } int mid = (l + r) >> 1; build(x << 1, l, mid); buil...
2C++
{ "input": [ "4\n0 1 2 1\n3 2 1 1\n", "7\n2 5 1 5 3 4 3\n2 4 3 5 6 5 1\n", "1\n0\n0\n", "10\n6 3 0 5 4 5 5 5 8 5\n3 8 2 9 5 4 1 0 3 6\n", "5\n1 4 2 1 3\n3 3 1 0 1\n", "5\n2 1 3 0 4\n1 0 3 2 3\n", "4\n1 2 1 1\n1 3 0 2\n", "3\n2 0 0\n1 0 2\n", "4\n1 1 0 3\n2 0 2 2\n", "3\n0 1 1\n...
2CODEFORCES
1157_E. Minimum Array_2417
You are given two arrays a and b, both of length n. All elements of both arrays are from 0 to n-1. You can reorder elements of the array b (if you want, you may leave the order of elements as it is). After that, let array c be the array of length n, the i-th element of this array is c_i = (a_i + b_i) \% n, where x \% ...
class SegmentTree: @classmethod def all_identity(cls, operator, equality, identity, size): return cls(operator, equality, identity, [identity]*(2 << (size-1).bit_length())) @classmethod def from_initial_data(cls, operator, equality, identity, data): size = 1 << (len(data)-1).bit_lengt...
3Python3
{ "input": [ "4\n0 1 2 1\n3 2 1 1\n", "7\n2 5 1 5 3 4 3\n2 4 3 5 6 5 1\n", "1\n0\n0\n", "10\n6 3 0 5 4 5 5 5 8 5\n3 8 2 9 5 4 1 0 3 6\n", "5\n1 4 2 1 3\n3 3 1 0 1\n", "5\n2 1 3 0 4\n1 0 3 2 3\n", "4\n1 2 1 1\n1 3 0 2\n", "3\n2 0 0\n1 0 2\n", "4\n1 1 0 3\n2 0 2 2\n", "3\n0 1 1\n...
2CODEFORCES
1157_E. Minimum Array_2418
You are given two arrays a and b, both of length n. All elements of both arrays are from 0 to n-1. You can reorder elements of the array b (if you want, you may leave the order of elements as it is). After that, let array c be the array of length n, the i-th element of this array is c_i = (a_i + b_i) \% n, where x \% ...
/* Author: Anthony Ngene Created: 25/09/2020 - 06:38 */ import java.io.*; import java.util.*; public class E { // checks: 1. edge cases 2. overflow 3. possible errors (e.g 1/0, arr[out]) 4. time/space complexity void solver() throws IOException { int n = in.intNext(); int[] a = new i...
4JAVA
{ "input": [ "4\n0 1 2 1\n3 2 1 1\n", "7\n2 5 1 5 3 4 3\n2 4 3 5 6 5 1\n", "1\n0\n0\n", "10\n6 3 0 5 4 5 5 5 8 5\n3 8 2 9 5 4 1 0 3 6\n", "5\n1 4 2 1 3\n3 3 1 0 1\n", "5\n2 1 3 0 4\n1 0 3 2 3\n", "4\n1 2 1 1\n1 3 0 2\n", "3\n2 0 0\n1 0 2\n", "4\n1 1 0 3\n2 0 2 2\n", "3\n0 1 1\n...
2CODEFORCES
117_B. Very Interesting Game_2419
In a very ancient country the following game was popular. Two people play the game. Initially first player writes a string s1, consisting of exactly nine digits and representing a number that does not exceed a. After that second player looks at s1 and writes a string s2, consisting of exactly nine digits and representi...
#!/usr/bin/env python """(c) gorlum0 [at] gmail.com""" import itertools as it from sys import stdin def solve(a, b, mod): if b >= mod: return 2 m = 10**9 % mod s = 0 for i in xrange(1, a+1): s += m if s >= mod: s -= mod if s == 0: break if s + b < mod: retur...
1Python2
{ "input": [ "4 0 9\n", "1 10 7\n", "1 2 11\n", "576695 1234562 1234567\n", "138 11711 11829\n", "1000000000 100050 1000001\n", "116482865 344094604 3271060\n", "0 3 3\n", "0 0 1\n", "7004769 3114686 4659684\n", "0 1 1\n", "100 2 3\n", "4 3 12\n", "0 1000000000 ...
2CODEFORCES
117_B. Very Interesting Game_2420
In a very ancient country the following game was popular. Two people play the game. Initially first player writes a string s1, consisting of exactly nine digits and representing a number that does not exceed a. After that second player looks at s1 and writes a string s2, consisting of exactly nine digits and representi...
#include <bits/stdc++.h> using namespace std; int const MAX = 1000 * 1000 * 1000; int main() { long long a, b, m, i; cin >> a >> b >> m; if (m <= b + 1 || MAX % m == 0) { cout << 2; return 0; } for (i = 1; i <= min(m - 1, a); ++i) { int k = MAX * i % m; if (0 < k && k < m - b) { printf("...
2C++
{ "input": [ "4 0 9\n", "1 10 7\n", "1 2 11\n", "576695 1234562 1234567\n", "138 11711 11829\n", "1000000000 100050 1000001\n", "116482865 344094604 3271060\n", "0 3 3\n", "0 0 1\n", "7004769 3114686 4659684\n", "0 1 1\n", "100 2 3\n", "4 3 12\n", "0 1000000000 ...
2CODEFORCES
117_B. Very Interesting Game_2421
In a very ancient country the following game was popular. Two people play the game. Initially first player writes a string s1, consisting of exactly nine digits and representing a number that does not exceed a. After that second player looks at s1 and writes a string s2, consisting of exactly nine digits and representi...
a, b, m = map(int, input().split()) k = s = 10 ** 9 % m i = 0 while k and i < a: i += 1 if k < m - b: exit(print(1, str(i).zfill(9))) k += s if k >= m: k -= m print(2)
3Python3
{ "input": [ "4 0 9\n", "1 10 7\n", "1 2 11\n", "576695 1234562 1234567\n", "138 11711 11829\n", "1000000000 100050 1000001\n", "116482865 344094604 3271060\n", "0 3 3\n", "0 0 1\n", "7004769 3114686 4659684\n", "0 1 1\n", "100 2 3\n", "4 3 12\n", "0 1000000000 ...
2CODEFORCES
117_B. Very Interesting Game_2422
In a very ancient country the following game was popular. Two people play the game. Initially first player writes a string s1, consisting of exactly nine digits and representing a number that does not exceed a. After that second player looks at s1 and writes a string s2, consisting of exactly nine digits and representi...
import java.io.PrintWriter; import java.util.Scanner; public class TaskB { /** * @param args */ public static void main(String[] args) { TaskB task = new TaskB(); task.read(); task.write(); } long a,b; long mod; public void read() { Scanner in = new S...
4JAVA
{ "input": [ "4 0 9\n", "1 10 7\n", "1 2 11\n", "576695 1234562 1234567\n", "138 11711 11829\n", "1000000000 100050 1000001\n", "116482865 344094604 3271060\n", "0 3 3\n", "0 0 1\n", "7004769 3114686 4659684\n", "0 1 1\n", "100 2 3\n", "4 3 12\n", "0 1000000000 ...
2CODEFORCES
1198_C. Matching vs Independent Set_2423
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...
#!/usr/bin/env python from __future__ import division, print_function import os import sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip import random import collections import math import itert...
1Python2
{ "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", "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", ...
2CODEFORCES
1198_C. Matching vs Independent Set_2424
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 double pi = acos(-1.0); int n, m; bool vis[300010]; vector<int> ans; int main() { int t; cin >> t; while (t--) { scanf("%d %d", &n, &m); for (int i = 1; i < 3 * n + 1; i++) { vis[i] = false; } ans.clear(); bool findans = false; for ...
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", "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", ...
2CODEFORCES
1198_C. Matching vs Independent Set_2425
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()) X = [[] for i in range(3*N)] for i in range(M): x, y = map(int, input().split()) x, y = min(x,y), max(x,y) X[x-1].append((y-1, i+1)) MAT = [] IND = [] DONE = [...
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", "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", ...
2CODEFORCES
1198_C. Matching vs Independent Set_2426
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...
/** * BaZ :D */ import java.util.*; import java.io.*; import static java.lang.Math.*; public class ACMIND { static FastReader scan; static PrintWriter pw; static long MOD = 1_000_000_007; static long INF = 1_000_000_000_000_000_000L; static long inf = 2_000_000_000; public static void main(S...
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", "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", ...
2CODEFORCES
1215_B. The Number of Products_2427
You are given a sequence a_1, a_2, ..., a_n consisting of n non-zero integers (i.e. a_i ≠ 0). You have to calculate two following values: 1. the number of pairs of indices (l, r) (l ≤ r) such that a_l ⋅ a_{l + 1} ... a_{r - 1} ⋅ a_r is negative; 2. the number of pairs of indices (l, r) (l ≤ r) such that a_l ⋅ a...
import sys,os,math from collections import Counter, defaultdict import bisect from sys import stdin, stdout from itertools import repeat # sys.stdin = open('input') # n, k = map(int, raw_input().split()) # da = map(int, raw_input().split()) # db = map(int, raw_input().split()) def solve(): pass def main(): ...
1Python2
{ "input": [ "10\n4 2 -4 3 1 2 -4 3 2 3\n", "5\n-1 -2 -3 -4 -5\n", "5\n5 -3 3 -1 1\n", "2\n-703630698 870277542\n", "3\n-1 -1 1\n", "2\n1000000000 -1000000000\n", "2\n1 1\n", "1\n1761402\n", "5\n1 1 1 1 1\n", "1\n1\n", "2\n665876657 284761489\n", "1\n-648613522\n", ...
2CODEFORCES
1215_B. The Number of Products_2428
You are given a sequence a_1, a_2, ..., a_n consisting of n non-zero integers (i.e. a_i ≠ 0). You have to calculate two following values: 1. the number of pairs of indices (l, r) (l ≤ r) such that a_l ⋅ a_{l + 1} ... a_{r - 1} ⋅ a_r is negative; 2. the number of pairs of indices (l, r) (l ≤ r) such that a_l ⋅ a...
#include <bits/stdc++.h> using namespace std; using ll = long long; using namespace std::chrono; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll inf = 1100000000; ll n; cin >> n; int pro = 1; ll pos = 1; ll neg = 0; for (int i = 0; i < n; i++) { ll temp; cin >> temp; if...
2C++
{ "input": [ "10\n4 2 -4 3 1 2 -4 3 2 3\n", "5\n-1 -2 -3 -4 -5\n", "5\n5 -3 3 -1 1\n", "2\n-703630698 870277542\n", "3\n-1 -1 1\n", "2\n1000000000 -1000000000\n", "2\n1 1\n", "1\n1761402\n", "5\n1 1 1 1 1\n", "1\n1\n", "2\n665876657 284761489\n", "1\n-648613522\n", ...
2CODEFORCES
1215_B. The Number of Products_2429
You are given a sequence a_1, a_2, ..., a_n consisting of n non-zero integers (i.e. a_i ≠ 0). You have to calculate two following values: 1. the number of pairs of indices (l, r) (l ≤ r) such that a_l ⋅ a_{l + 1} ... a_{r - 1} ⋅ a_r is negative; 2. the number of pairs of indices (l, r) (l ≤ r) such that a_l ⋅ a...
input() a=list(map(int,input().split())) q,w,e,t,y=0,0,1,0,0 for i in a: if e>0: q+=1 if i>0: e=1 else: e=-1 else: w+=1 if i>0: e=-1 else: e=1 if e>0: t+=q y+=w else: t+=w y+=q...
3Python3
{ "input": [ "10\n4 2 -4 3 1 2 -4 3 2 3\n", "5\n-1 -2 -3 -4 -5\n", "5\n5 -3 3 -1 1\n", "2\n-703630698 870277542\n", "3\n-1 -1 1\n", "2\n1000000000 -1000000000\n", "2\n1 1\n", "1\n1761402\n", "5\n1 1 1 1 1\n", "1\n1\n", "2\n665876657 284761489\n", "1\n-648613522\n", ...
2CODEFORCES
1215_B. The Number of Products_2430
You are given a sequence a_1, a_2, ..., a_n consisting of n non-zero integers (i.e. a_i ≠ 0). You have to calculate two following values: 1. the number of pairs of indices (l, r) (l ≤ r) such that a_l ⋅ a_{l + 1} ... a_{r - 1} ⋅ a_r is negative; 2. the number of pairs of indices (l, r) (l ≤ r) such that a_l ⋅ a...
/* -> Written by <- ----------- |J_O_B_E_E_L| |___________| | ___ | | (^_^) | | /( | )\ | |____|_|____| */ import java.util.*; import java.io.*; import java.lang.*; import java.math.*; import java.util.Map.*; public class Test { static PrintWriter pw = new PrintWriter(System.out); ...
4JAVA
{ "input": [ "10\n4 2 -4 3 1 2 -4 3 2 3\n", "5\n-1 -2 -3 -4 -5\n", "5\n5 -3 3 -1 1\n", "2\n-703630698 870277542\n", "3\n-1 -1 1\n", "2\n1000000000 -1000000000\n", "2\n1 1\n", "1\n1761402\n", "5\n1 1 1 1 1\n", "1\n1\n", "2\n665876657 284761489\n", "1\n-648613522\n", ...
2CODEFORCES
1238_D. AB-string_2431
The string t_1t_2 ... t_k is good if each letter of this string belongs to at least one palindrome of length greater than 1. A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not. Here are some examp...
from __future__ import division,print_function n=int(input()) s=raw_input() A_plus_proche_avant=[-1]*n B_plus_proche_avant=[-1]*n A_plus_proche_apres=[n]*n B_plus_proche_apres=[n]*n for k in range(1,n): if s[k-1]=='A': A_plus_proche_avant[k]=k-1 B_plus_proche_avant[k]=B_plus_proche_avant[k-1] el...
1Python2
{ "input": [ "5\nAABBB\n", "3\nAAA\n", "7\nAAABABB\n", "3\nABA\n", "7\nBBABAAA\n", "7\nBAAAABB\n", "5\nBBBBA\n", "7\nABABAAB\n", "7\nBBAAABA\n", "3\nBBB\n", "5\nABBAA\n", "5\nABBBA\n", "7\nBAAAAAB\n", "7\nAAAAAAA\n", "3\nBAA\n", "3\nAAB\n", "7\nBBAAA...
2CODEFORCES
1238_D. AB-string_2432
The string t_1t_2 ... t_k is good if each letter of this string belongs to at least one palindrome of length greater than 1. A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not. Here are some examp...
#include <bits/stdc++.h> using namespace std; int n; string s; bool f = false; bool l = false; long long res = 0; int main() { scanf("%d", &n); cin >> s; res = (long long)n * (n - 1) / 2; for (int i = 0; i < n; i++) { char c = s[i]; int j = i + 1; int br = 0; while (j < n && s[j] != c) { b...
2C++
{ "input": [ "5\nAABBB\n", "3\nAAA\n", "7\nAAABABB\n", "3\nABA\n", "7\nBBABAAA\n", "7\nBAAAABB\n", "5\nBBBBA\n", "7\nABABAAB\n", "7\nBBAAABA\n", "3\nBBB\n", "5\nABBAA\n", "5\nABBBA\n", "7\nBAAAAAB\n", "7\nAAAAAAA\n", "3\nBAA\n", "3\nAAB\n", "7\nBBAAA...
2CODEFORCES
1238_D. AB-string_2433
The string t_1t_2 ... t_k is good if each letter of this string belongs to at least one palindrome of length greater than 1. A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not. Here are some examp...
from sys import stdin n = int(input()) s = stdin.read(n) ans = n*(n-1)//2 k = 0 m = 0 for i in range(1, n): p = s[i-1] t = s[i] if p == t: k+=1 else: ans -= k*(1<<m)+1 m |= 1 k = 0 else: ans -= k*m print(ans)
3Python3
{ "input": [ "5\nAABBB\n", "3\nAAA\n", "7\nAAABABB\n", "3\nABA\n", "7\nBBABAAA\n", "7\nBAAAABB\n", "5\nBBBBA\n", "7\nABABAAB\n", "7\nBBAAABA\n", "3\nBBB\n", "5\nABBAA\n", "5\nABBBA\n", "7\nBAAAAAB\n", "7\nAAAAAAA\n", "3\nBAA\n", "3\nAAB\n", "7\nBBAAA...
2CODEFORCES
1238_D. AB-string_2434
The string t_1t_2 ... t_k is good if each letter of this string belongs to at least one palindrome of length greater than 1. A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not. Here are some examp...
import java.util.*; import java.io.*; public class Solution{ static int mod=1_000_000_007, oo=Integer.MAX_VALUE, _oo=Integer.MAX_VALUE; public static void main(String args[]) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); Scanner in=new Scanner(System.in); String...
4JAVA
{ "input": [ "5\nAABBB\n", "3\nAAA\n", "7\nAAABABB\n", "3\nABA\n", "7\nBBABAAA\n", "7\nBAAAABB\n", "5\nBBBBA\n", "7\nABABAAB\n", "7\nBBAAABA\n", "3\nBBB\n", "5\nABBAA\n", "5\nABBBA\n", "7\nBAAAAAB\n", "7\nAAAAAAA\n", "3\nBAA\n", "3\nAAB\n", "7\nBBAAA...
2CODEFORCES
1256_E. Yet Another Division Into Teams_2435
There are n students at your university. The programming skill of the i-th student is a_i. As a coach, you want to divide them into teams to prepare them for the upcoming ICPC finals. Just imagine how good this university is if it has 2 ⋅ 10^5 students ready for the finals! Each team should consist of at least three s...
n = input() arr2 = map(int,raw_input().split(" ")) tmp = zip(arr2,range(n)) tmp.sort() arr,idx = zip(*tmp) dp = [[1e18]*3 for i in range(n)] dp[0][2] = 0 dp[1][1] = arr[1]-arr[0] labels = [1]*n for i in range(2,n): dp[i][1] = dp[i-2][0]+arr[i]-arr[i-1] dp[i][2] = dp[i-1][0] dp[i][0] = min(dp[i-2]) + arr[i...
1Python2
{ "input": [ "5\n1 1 3 4 2\n", "6\n1 5 12 13 2 15\n", "10\n1 2 5 129 185 581 1041 1909 1580 8150\n", "10\n716243820 716243820 716243820 716243820 716243820 716243820 716243820 716243820 716243820 716243820\n", "6\n1 1 2 2 3 3\n", "10\n716243820 716243820 716243820 716243820 1034310574 71624382...
2CODEFORCES
1256_E. Yet Another Division Into Teams_2436
There are n students at your university. The programming skill of the i-th student is a_i. As a coach, you want to divide them into teams to prepare them for the upcoming ICPC finals. Just imagine how good this university is if it has 2 ⋅ 10^5 students ready for the finals! Each team should consist of at least three s...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<pair<int, int>> v(n); for (int i = 0; i < n; ++i) { cin >> v[i].first; v[i].second = i; } vector<long long> dp(n + 1); vector<int> p(n + 1, -1); sort(v.begin(), v.end()); fill(dp.begin(), dp.end(), 2e15); dp...
2C++
{ "input": [ "5\n1 1 3 4 2\n", "6\n1 5 12 13 2 15\n", "10\n1 2 5 129 185 581 1041 1909 1580 8150\n", "10\n716243820 716243820 716243820 716243820 716243820 716243820 716243820 716243820 716243820 716243820\n", "6\n1 1 2 2 3 3\n", "10\n716243820 716243820 716243820 716243820 1034310574 71624382...
2CODEFORCES
1256_E. Yet Another Division Into Teams_2437
There are n students at your university. The programming skill of the i-th student is a_i. As a coach, you want to divide them into teams to prepare them for the upcoming ICPC finals. Just imagine how good this university is if it has 2 ⋅ 10^5 students ready for the finals! Each team should consist of at least three s...
def main(): n=int(input()) a=readIntArr() a2=[[x,i+1] for i,x in enumerate(a)] # [value, index] a2.sort(key=lambda x:x[0]) # sort by value asc dp=[inf for _ in range(n)] # dp[i] is the min diversity achievable at i #dp[i]=min(ai-aj+dp[j-1])=min(a[i]+(dp[j-1]-a[j]))=a[i]+dp2[i-2] ...
3Python3
{ "input": [ "5\n1 1 3 4 2\n", "6\n1 5 12 13 2 15\n", "10\n1 2 5 129 185 581 1041 1909 1580 8150\n", "10\n716243820 716243820 716243820 716243820 716243820 716243820 716243820 716243820 716243820 716243820\n", "6\n1 1 2 2 3 3\n", "10\n716243820 716243820 716243820 716243820 1034310574 71624382...
2CODEFORCES
1256_E. Yet Another Division Into Teams_2438
There are n students at your university. The programming skill of the i-th student is a_i. As a coach, you want to divide them into teams to prepare them for the upcoming ICPC finals. Just imagine how good this university is if it has 2 ⋅ 10^5 students ready for the finals! Each team should consist of at least three s...
import java.util.*; import java.io.*; public class E1256 { public static void main(String [] args) { MyScanner sc = new MyScanner(); PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); int n = sc.nextInt(); Student [] skills = new Student [n]; for (int i = 0; i < n; i++) ...
4JAVA
{ "input": [ "5\n1 1 3 4 2\n", "6\n1 5 12 13 2 15\n", "10\n1 2 5 129 185 581 1041 1909 1580 8150\n", "10\n716243820 716243820 716243820 716243820 716243820 716243820 716243820 716243820 716243820 716243820\n", "6\n1 1 2 2 3 3\n", "10\n716243820 716243820 716243820 716243820 1034310574 71624382...
2CODEFORCES
127_E. E-reader Display_2439
After years of hard work scientists invented an absolutely new e-reader display. The new display has a larger resolution, consumes less energy and its production is cheaper. And besides, one can bend it. The only inconvenience is highly unusual management. For that very reason the developers decided to leave the e-read...
#include <bits/stdc++.h> using namespace std; const int nmax = 2009; int a[2009][2009]; int ui[nmax], uj[nmax]; int n; void inc(int &a) { ++a; a = a & 1; } int main() { int ans = 0; scanf("%d\n", &n); char s[nmax]; for (int i = 1; i <= n; i++) { scanf("%s", s); for (int j = 1; j <= n; j++) a[i][j] =...
2C++
{ "input": [ "5\n01110\n10010\n10001\n10011\n11110\n", "3\n000\n000\n000\n", "10\n1111100000\n0010100000\n0110111000\n0000001000\n1011001010\n0010100001\n0010111000\n0011001010\n0000110010\n0000001100\n", "10\n1101010101\n1110101010\n0111010101\n1011101010\n0101110101\n1010111010\n0101011101\n10101011...
2CODEFORCES
127_E. E-reader Display_2440
After years of hard work scientists invented an absolutely new e-reader display. The new display has a larger resolution, consumes less energy and its production is cheaper. And besides, one can bend it. The only inconvenience is highly unusual management. For that very reason the developers decided to leave the e-read...
n=int(input()) T=[] for i in range(n): T.append(input()[::-1]) Val=['0','1'] S=0 L1=[0]*n C1=[0]*n for diag in range(n-1): for i in range(diag+1): l,c=L1[i],C1[diag-i] if T[i][diag-i]!=Val[(l+c)%2]: S+=1 L1[i]=1-l C1[diag-i]=1-c L2=[0]*n C2=[0]...
3Python3
{ "input": [ "5\n01110\n10010\n10001\n10011\n11110\n", "3\n000\n000\n000\n", "10\n1111100000\n0010100000\n0110111000\n0000001000\n1011001010\n0010100001\n0010111000\n0011001010\n0000110010\n0000001100\n", "10\n1101010101\n1110101010\n0111010101\n1011101010\n0101110101\n1010111010\n0101011101\n10101011...
2CODEFORCES
127_E. E-reader Display_2441
After years of hard work scientists invented an absolutely new e-reader display. The new display has a larger resolution, consumes less energy and its production is cheaper. And besides, one can bend it. The only inconvenience is highly unusual management. For that very reason the developers decided to leave the e-read...
import java.io.* ; import java.util.*; import static java.lang.Math.* ; import static java.util.Arrays.* ; public class C { public static void main(String[] args) throws IOException { new C().solveProblem(); out.close(); } //static Scanner in = new Scanner(new InputStreamReader(System.in)); static Bu...
4JAVA
{ "input": [ "5\n01110\n10010\n10001\n10011\n11110\n", "3\n000\n000\n000\n", "10\n1111100000\n0010100000\n0110111000\n0000001000\n1011001010\n0010100001\n0010111000\n0011001010\n0000110010\n0000001100\n", "10\n1101010101\n1110101010\n0111010101\n1011101010\n0101110101\n1010111010\n0101011101\n10101011...
2CODEFORCES
12_D. Ball_2442
N ladies attend the ball in the King's palace. Every lady can be described with three values: beauty, intellect and richness. King's Master of Ceremonies knows that ladies are very special creatures. If some lady understands that there is other lady at the ball which is more beautiful, smarter and more rich, she can ju...
#include <bits/stdc++.h> using namespace std; const int MAXN = 500000 + 5; struct Titem { int a, b, c; } p[MAXN]; int n, cmax[MAXN], tmp[MAXN], ans = 0; bool cmpb(Titem p, Titem q) { return p.b > q.b; } void modify(int i, int v) { for (; i <= n; cmax[i] = max(cmax[i], v), i += i & -i) ; } int getmax(int i) { ...
2C++
{ "input": [ "3\n1 4 2\n4 3 2\n2 5 3\n", "5\n5 4 0 2 5\n8 3 1 0 10\n4 5 0 0 5\n", "10\n10 19 4 1 11 6 1 20 11 13\n2 7 17 8 10 3 20 16 10 8\n15 9 9 2 20 9 0 15 0 4\n", "10\n12 16 11 13 6 18 6 14 4 2\n11 6 4 13 10 1 6 3 8 19\n1 3 1 9 4 17 18 1 14 13\n", "5\n9 7 0 2 10\n8 6 5 5 9\n1 9 3 0 1\n", "...
2CODEFORCES
12_D. Ball_2443
N ladies attend the ball in the King's palace. Every lady can be described with three values: beauty, intellect and richness. King's Master of Ceremonies knows that ladies are very special creatures. If some lady understands that there is other lady at the ball which is more beautiful, smarter and more rich, she can ju...
/* Keep solving problems. */ import java.util.*; import java.io.*; public class CF12D { BufferedReader br; PrintWriter out; StringTokenizer st; boolean eof; final long MOD = 1000L * 1000L * 1000L + 7; class Lady { int b; int i; int r; int idx; public La...
4JAVA
{ "input": [ "3\n1 4 2\n4 3 2\n2 5 3\n", "5\n5 4 0 2 5\n8 3 1 0 10\n4 5 0 0 5\n", "10\n10 19 4 1 11 6 1 20 11 13\n2 7 17 8 10 3 20 16 10 8\n15 9 9 2 20 9 0 15 0 4\n", "10\n12 16 11 13 6 18 6 14 4 2\n11 6 4 13 10 1 6 3 8 19\n1 3 1 9 4 17 18 1 14 13\n", "5\n9 7 0 2 10\n8 6 5 5 9\n1 9 3 0 1\n", "...
2CODEFORCES
1323_F. Reality Show_2444
A popular reality show is recruiting a new cast for the third season! n candidates numbered from 1 to n have been interviewed. The candidate i has aggressiveness level l_i, and recruiting this candidate will cost the show s_i roubles. The show host reviewes applications of all candidates from i=1 to i=n by increasing ...
#include <bits/stdc++.h> void rd(int &x) { x = 0; int f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar(); x *= f; } void lrd(long long &x) { x = 0; int f = 1; char ch = getch...
2C++
{ "input": [ "2 2\n1 2\n0 0\n2 1 -100 -100\n", "5 4\n4 3 2 1 1\n0 2 6 7 4\n12 12 12 6 -3 -5 3 10 -4\n", "5 4\n4 3 1 2 1\n1 2 1 2 1\n1 2 3 4 5 6 7 8 9\n", "15 5\n1 1 1 2 2 2 4 4 4 3 3 3 5 5 5\n822 1311 4281 176 3421 3834 3809 2033 4566 4194 4472 2680 4369 3408 1360\n-4335 1912 20 697 -2978 -3139 1901 -...
2CODEFORCES
1323_F. Reality Show_2445
A popular reality show is recruiting a new cast for the third season! n candidates numbered from 1 to n have been interviewed. The candidate i has aggressiveness level l_i, and recruiting this candidate will cost the show s_i roubles. The show host reviewes applications of all candidates from i=1 to i=n by increasing ...
import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Locale; import...
4JAVA
{ "input": [ "2 2\n1 2\n0 0\n2 1 -100 -100\n", "5 4\n4 3 2 1 1\n0 2 6 7 4\n12 12 12 6 -3 -5 3 10 -4\n", "5 4\n4 3 1 2 1\n1 2 1 2 1\n1 2 3 4 5 6 7 8 9\n", "15 5\n1 1 1 2 2 2 4 4 4 3 3 3 5 5 5\n822 1311 4281 176 3421 3834 3809 2033 4566 4194 4472 2680 4369 3408 1360\n-4335 1912 20 697 -2978 -3139 1901 -...
2CODEFORCES
1342_E. Placing Rooks_2446
Calculate the number of ways to place n rooks on n × n chessboard so that both following conditions are met: * each empty cell is under attack; * exactly k pairs of rooks attack each other. An empty cell is under attack if there is at least one rook in the same row or at least one rook in the same column. Two...
f=[1 for j in range(200055)] gf=[1 for j in range(200055)] mod=998244353 for i in range(1,200050): f[i]=((f[i-1]*i)%mod) gf[i]=(pow(f[i],mod-2,mod)) def bc(n,p): j=f[n]*gf[p] j%=mod;j*=gf[n-p];j%=mod return j n,k=map(int,raw_input().split()) if n<=k: print 0 elif k==0: print f[n] else: ...
1Python2
{ "input": [ "4 0\n", "3 2\n", "1337 42\n", "3 3\n", "4 5\n", "4 3\n", "3000 3000\n", "200000 200000\n", "200000 1000\n", "3000 0\n", "2 1\n", "3 0\n", "4 4\n", "3000 42\n", "4 1\n", "200000 199999\n", "4 6\n", "200000 199998\n", "200000 3393...
2CODEFORCES
1342_E. Placing Rooks_2447
Calculate the number of ways to place n rooks on n × n chessboard so that both following conditions are met: * each empty cell is under attack; * exactly k pairs of rooks attack each other. An empty cell is under attack if there is at least one rook in the same row or at least one rook in the same column. Two...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int MOD = 998244353; const int INF = 0x3f3f3f3f; const long long INF_LL = 0x3f3f3f3f3f3f3f3f; long long QPow(long long bas, int t) { long long ret = 1; bas %= MOD; while (t) { if (t & 1) ret = ret * bas % MOD; bas = bas * bas % MOD...
2C++
{ "input": [ "4 0\n", "3 2\n", "1337 42\n", "3 3\n", "4 5\n", "4 3\n", "3000 3000\n", "200000 200000\n", "200000 1000\n", "3000 0\n", "2 1\n", "3 0\n", "4 4\n", "3000 42\n", "4 1\n", "200000 199999\n", "4 6\n", "200000 199998\n", "200000 3393...
2CODEFORCES
1342_E. Placing Rooks_2448
Calculate the number of ways to place n rooks on n × n chessboard so that both following conditions are met: * each empty cell is under attack; * exactly k pairs of rooks attack each other. An empty cell is under attack if there is at least one rook in the same row or at least one rook in the same column. Two...
import io,os input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline import sys def solve(n,k): mod=998244353 if k==0: ans=1 for i in range(1,n+1): ans*=i ans%=mod return ans if k>=n: return 0 inv=lambda x: pow(x,mod-2,mod) Fact=[1] #階乗 ...
3Python3
{ "input": [ "4 0\n", "3 2\n", "1337 42\n", "3 3\n", "4 5\n", "4 3\n", "3000 3000\n", "200000 200000\n", "200000 1000\n", "3000 0\n", "2 1\n", "3 0\n", "4 4\n", "3000 42\n", "4 1\n", "200000 199999\n", "4 6\n", "200000 199998\n", "200000 3393...
2CODEFORCES
1342_E. Placing Rooks_2449
Calculate the number of ways to place n rooks on n × n chessboard so that both following conditions are met: * each empty cell is under attack; * exactly k pairs of rooks attack each other. An empty cell is under attack if there is at least one rook in the same row or at least one rook in the same column. Two...
import java.io.*; import java.util.*; public class E { static long mod = 998244353; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long k = sc.nextLong(); if(k == 0) { long res = 1; for(long i = 1; i <= n; i++) { res *= i; res %= mod; } Sys...
4JAVA
{ "input": [ "4 0\n", "3 2\n", "1337 42\n", "3 3\n", "4 5\n", "4 3\n", "3000 3000\n", "200000 200000\n", "200000 1000\n", "3000 0\n", "2 1\n", "3 0\n", "4 4\n", "3000 42\n", "4 1\n", "200000 199999\n", "4 6\n", "200000 199998\n", "200000 3393...
2CODEFORCES
1364_E. X-OR_2450
This is an interactive problem! Ehab has a hidden permutation p of length n consisting of the elements from 0 to n-1. You, for some reason, want to figure out the permutation. To do that, you can give Ehab 2 different indices i and j, and he'll reply with (p_i|p_j) where | is the [bitwise-or](https://en.wikipedia.org/...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); map<pair<int, int>, int> mp; int ask(int l, int r) { if (mp.find({l, r}) != mp.end()) return mp[{l, r}]; cout << "? " << l << " " << r << endl; int x; cin >> x; mp[{l, r}] = x; mp[{r, l}] = x; ...
2C++
{ "input": [ "3\n1\n3\n2", "128\n49 64 93 66 79 101 57 76 30 25 31 104 39 15 24 51 83 117 73 41 46 77 50 16 61 32 112 95 100 68 52 116 91 40 54 125 113 89 10 84 106 23 12 3 75 36 4 45 58 9 13 53 11 67 121 107 99 108 102 110 21 28 29 22 109 35 90 55 1 71 74 103 59 92 97 86 81 118 127 34 0 48 85 119 44 80 94 69...
2CODEFORCES
1364_E. X-OR_2451
This is an interactive problem! Ehab has a hidden permutation p of length n consisting of the elements from 0 to n-1. You, for some reason, want to figure out the permutation. To do that, you can give Ehab 2 different indices i and j, and he'll reply with (p_i|p_j) where | is the [bitwise-or](https://en.wikipedia.org/...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Random; import java.util.StringTokenizer; public class EBrute { static FastScanner fs; //TODO: don't fix seed before submitting! static Random random=new Random(); // static Random random=new Random(5); ...
4JAVA
{ "input": [ "3\n1\n3\n2", "128\n49 64 93 66 79 101 57 76 30 25 31 104 39 15 24 51 83 117 73 41 46 77 50 16 61 32 112 95 100 68 52 116 91 40 54 125 113 89 10 84 106 23 12 3 75 36 4 45 58 9 13 53 11 67 121 107 99 108 102 110 21 28 29 22 109 35 90 55 1 71 74 103 59 92 97 86 81 118 127 34 0 48 85 119 44 80 94 69...
2CODEFORCES
1384_F. Rearrange_2452
Koa the Koala has a matrix A of n rows and m columns. Elements of this matrix are distinct integers from 1 to n ⋅ m (each number from 1 to n ⋅ m appears exactly once in the matrix). For any matrix M of n rows and m columns let's define the following: * The i-th row of M is defined as R_i(M) = [ M_{i1}, M_{i2}, …, M...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<vector<int>> mat(n, vector<int>(m)); for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> mat[i][j]; vector<int> h(n * m + 1); vector<int> v(n * m + 1); fo...
2C++
{ "input": [ "3 4\n12 10 8 6\n3 4 5 7\n2 11 9 1\n", "3 3\n3 5 6\n1 7 9\n4 8 2\n", "2 2\n4 1\n3 2\n", "1 1\n1\n", "5 8\n14 20 36 25 31 29 11 24\n16 2 27 1 33 13 35 38\n12 8 37 30 10 7 32 19\n40 18 26 3 17 23 22 9\n6 15 34 21 39 5 4 28\n", "9 14\n103 120 6 12 5 68 122 22 33 3 121 105 53 54\n63 3...
2CODEFORCES
1384_F. Rearrange_2453
Koa the Koala has a matrix A of n rows and m columns. Elements of this matrix are distinct integers from 1 to n ⋅ m (each number from 1 to n ⋅ m appears exactly once in the matrix). For any matrix M of n rows and m columns let's define the following: * The i-th row of M is defined as R_i(M) = [ M_{i1}, M_{i2}, …, M...
import java.io.*; import java.util.*; public class CF1384F extends PrintWriter { CF1384F() { super(System.out); } Scanner sc = new Scanner(System.in); public static void main(String[] $) { CF1384F o = new CF1384F(); o.main(); o.flush(); } void main() { int n = sc.nextInt(); int m = sc.nextInt(); int[] ii...
4JAVA
{ "input": [ "3 4\n12 10 8 6\n3 4 5 7\n2 11 9 1\n", "3 3\n3 5 6\n1 7 9\n4 8 2\n", "2 2\n4 1\n3 2\n", "1 1\n1\n", "5 8\n14 20 36 25 31 29 11 24\n16 2 27 1 33 13 35 38\n12 8 37 30 10 7 32 19\n40 18 26 3 17 23 22 9\n6 15 34 21 39 5 4 28\n", "9 14\n103 120 6 12 5 68 122 22 33 3 121 105 53 54\n63 3...
2CODEFORCES
1406_C. Link Cut Centroids_2454
Fishing Prince loves trees, and he especially loves trees with only one centroid. The tree is a connected graph without cycles. A vertex is a centroid of a tree only when you cut this vertex (remove it and remove all edges from this vertex), the size of the largest connected component of the remaining graph is the sma...
import math def calc(n, graph): visited = [False] * (n+1) subtree = [0] * (n+1) # dfs over tree finding subtree sizes stack = [1] while stack: node = stack[-1] if visited[node]: stack.pop() subtree[node] = 1 for c in graph[node]: ...
1Python2
{ "input": [ "2\n5\n1 2\n1 3\n2 4\n2 5\n6\n1 2\n1 3\n1 4\n2 5\n2 6\n", "15\n4\n1 2\n2 3\n3 4\n4\n1 2\n2 4\n3 4\n4\n1 2\n1 3\n1 4\n4\n1 3\n2 3\n4 3\n4\n1 4\n3 4\n2 3\n4\n4 1\n3 2\n2 1\n5\n1 2\n2 3\n3 4\n4 5\n5\n1 2\n2 3\n4 1\n5 1\n5\n1 2\n3 1\n4 1\n1 5\n6\n1 2\n2 3\n3 4\n4 5\n5 6\n6\n1 3\n2 3\n3 4\n4 5\n4 6\n3...
2CODEFORCES
1406_C. Link Cut Centroids_2455
Fishing Prince loves trees, and he especially loves trees with only one centroid. The tree is a connected graph without cycles. A vertex is a centroid of a tree only when you cut this vertex (remove it and remove all edges from this vertex), the size of the largest connected component of the remaining graph is the sma...
#include <bits/stdc++.h> using namespace std; int n, to[200050], nxt[200050], fir[100050], ans, t1, t2, tot, siz[100050], son[100050], mx[100050], rt, rt2, dep[100040]; void ade(int x, int y) { to[++tot] = y; nxt[tot] = fir[x]; fir[x] = tot; } void find(int x, int fa) { siz[x] = 1; mx[x] = 0; dep[x] = d...
2C++
{ "input": [ "2\n5\n1 2\n1 3\n2 4\n2 5\n6\n1 2\n1 3\n1 4\n2 5\n2 6\n", "15\n4\n1 2\n2 3\n3 4\n4\n1 2\n2 4\n3 4\n4\n1 2\n1 3\n1 4\n4\n1 3\n2 3\n4 3\n4\n1 4\n3 4\n2 3\n4\n4 1\n3 2\n2 1\n5\n1 2\n2 3\n3 4\n4 5\n5\n1 2\n2 3\n4 1\n5 1\n5\n1 2\n3 1\n4 1\n1 5\n6\n1 2\n2 3\n3 4\n4 5\n5 6\n6\n1 3\n2 3\n3 4\n4 5\n4 6\n3...
2CODEFORCES
1406_C. Link Cut Centroids_2456
Fishing Prince loves trees, and he especially loves trees with only one centroid. The tree is a connected graph without cycles. A vertex is a centroid of a tree only when you cut this vertex (remove it and remove all edges from this vertex), the size of the largest connected component of the remaining graph is the sma...
from random import choice as _choice import sys as _sys def main(): t = int(input()) for i in range(t): n, = _read_ints() graph = [set() for v in range(n)] for i_edge in range(n-1): v1, v2 = _read_ints() v1 -= 1 v2 -= 1 graph[v1].add(v2) ...
3Python3
{ "input": [ "2\n5\n1 2\n1 3\n2 4\n2 5\n6\n1 2\n1 3\n1 4\n2 5\n2 6\n", "15\n4\n1 2\n2 3\n3 4\n4\n1 2\n2 4\n3 4\n4\n1 2\n1 3\n1 4\n4\n1 3\n2 3\n4 3\n4\n1 4\n3 4\n2 3\n4\n4 1\n3 2\n2 1\n5\n1 2\n2 3\n3 4\n4 5\n5\n1 2\n2 3\n4 1\n5 1\n5\n1 2\n3 1\n4 1\n1 5\n6\n1 2\n2 3\n3 4\n4 5\n5 6\n6\n1 3\n2 3\n3 4\n4 5\n4 6\n3...
2CODEFORCES
1406_C. Link Cut Centroids_2457
Fishing Prince loves trees, and he especially loves trees with only one centroid. The tree is a connected graph without cycles. A vertex is a centroid of a tree only when you cut this vertex (remove it and remove all edges from this vertex), the size of the largest connected component of the remaining graph is the sma...
// package CodeForces; import java.io.BufferedOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.InputMismatchException; import java.util.LinkedList; public class Round670C { public static LinkedList<Integer>[] adj; public...
4JAVA
{ "input": [ "2\n5\n1 2\n1 3\n2 4\n2 5\n6\n1 2\n1 3\n1 4\n2 5\n2 6\n", "15\n4\n1 2\n2 3\n3 4\n4\n1 2\n2 4\n3 4\n4\n1 2\n1 3\n1 4\n4\n1 3\n2 3\n4 3\n4\n1 4\n3 4\n2 3\n4\n4 1\n3 2\n2 1\n5\n1 2\n2 3\n3 4\n4 5\n5\n1 2\n2 3\n4 1\n5 1\n5\n1 2\n3 1\n4 1\n1 5\n6\n1 2\n2 3\n3 4\n4 5\n5 6\n6\n1 3\n2 3\n3 4\n4 5\n4 6\n3...
2CODEFORCES
1427_D. Unshuffling a Deck_2458
You are given a deck of n cards numbered from 1 to n (not necessarily in this order in the deck). You have to sort the deck by repeating the following operation. * Choose 2 ≤ k ≤ n and split the deck in k nonempty contiguous parts D_1, D_2,..., D_k (D_1 contains the first |D_1| cards of the deck, D_2 contains the f...
n = int(raw_input()) a = map(int, raw_input().split()) ans = [] def go(): global a for i in xrange(n): for j in xrange(i + 1, n): if a[i] == a[j] + 1: b = [] k = j while a[k-1] + 1 == a[k]: k -= 1 if i: ...
1Python2
{ "input": [ "1\n1\n", "6\n6 5 4 3 2 1\n", "4\n3 1 2 4\n", "44\n1 32 3 18 5 41 27 26 9 10 11 31 13 14 19 35 17 4 22 40 21 15 24 23 44 8 7 43 29 30 37 2 33 34 28 36 12 38 39 20 6 42 16 25\n", "51\n51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 ...
2CODEFORCES
1427_D. Unshuffling a Deck_2459
You are given a deck of n cards numbered from 1 to n (not necessarily in this order in the deck). You have to sort the deck by repeating the following operation. * Choose 2 ≤ k ≤ n and split the deck in k nonempty contiguous parts D_1, D_2,..., D_k (D_1 contains the first |D_1| cards of the deck, D_2 contains the f...
#include <bits/stdc++.h> using namespace std; template <class T> ostream& operator<<(ostream& out, vector<T>& v) { out << "["; for (auto k : v) out << k << " "; out << "]" << "\n"; return out; } template <class T> ostream& operator<<(ostream& out, set<T> s) { out << "{"; for (auto k : s) out << k << "...
2C++
{ "input": [ "1\n1\n", "6\n6 5 4 3 2 1\n", "4\n3 1 2 4\n", "44\n1 32 3 18 5 41 27 26 9 10 11 31 13 14 19 35 17 4 22 40 21 15 24 23 44 8 7 43 29 30 37 2 33 34 28 36 12 38 39 20 6 42 16 25\n", "51\n51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 ...
2CODEFORCES
1427_D. Unshuffling a Deck_2460
You are given a deck of n cards numbered from 1 to n (not necessarily in this order in the deck). You have to sort the deck by repeating the following operation. * Choose 2 ≤ k ≤ n and split the deck in k nonempty contiguous parts D_1, D_2,..., D_k (D_1 contains the first |D_1| cards of the deck, D_2 contains the f...
from sys import stdin, stdout n = int(stdin.readline()) c = [int(x) for x in stdin.readline().split()] ops = [] turn = True for x in range(n-1): newC = [] newC2 = [] op = [] ind = c.index(x+1) if turn: if ind != 0: op.append(ind) op.append(n-x-ind) op += [1]*x...
3Python3
{ "input": [ "1\n1\n", "6\n6 5 4 3 2 1\n", "4\n3 1 2 4\n", "44\n1 32 3 18 5 41 27 26 9 10 11 31 13 14 19 35 17 4 22 40 21 15 24 23 44 8 7 43 29 30 37 2 33 34 28 36 12 38 39 20 6 42 16 25\n", "51\n51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 ...
2CODEFORCES
1427_D. Unshuffling a Deck_2461
You are given a deck of n cards numbered from 1 to n (not necessarily in this order in the deck). You have to sort the deck by repeating the following operation. * Choose 2 ≤ k ≤ n and split the deck in k nonempty contiguous parts D_1, D_2,..., D_k (D_1 contains the first |D_1| cards of the deck, D_2 contains the f...
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.StringToken...
4JAVA
{ "input": [ "1\n1\n", "6\n6 5 4 3 2 1\n", "4\n3 1 2 4\n", "44\n1 32 3 18 5 41 27 26 9 10 11 31 13 14 19 35 17 4 22 40 21 15 24 23 44 8 7 43 29 30 37 2 33 34 28 36 12 38 39 20 6 42 16 25\n", "51\n51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 ...
2CODEFORCES
1450_D. Rating Compression_2462
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers a of length n. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter k, the program takes the minimum of ...
import sys if sys.subversion[0] == "PyPy": import io, atexit sys.stdout = io.BytesIO() atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue())) sys.stdin = io.BytesIO(sys.stdin.read()) input = lambda: sys.stdin.readline().rstrip() RS = raw_input RI = lambda x=int: map(x,RS().split(...
1Python2
{ "input": [ "5\n5\n1 5 3 4 2\n4\n1 3 2 1\n5\n1 3 3 3 2\n10\n1 2 3 4 5 6 7 8 9 10\n3\n3 3 2\n", "5\n5\n1 5 3 4 2\n4\n1 3 2 1\n5\n1 3 3 3 2\n10\n1 2 1 4 5 6 7 8 9 10\n3\n3 3 2\n", "5\n5\n1 5 3 3 2\n4\n1 3 2 1\n5\n1 3 3 3 2\n10\n1 2 1 4 5 6 7 8 9 10\n3\n3 3 2\n", "5\n5\n1 5 3 4 2\n4\n1 3 2 1\n5\n1 3 3 3...
2CODEFORCES
1450_D. Rating Compression_2463
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers a of length n. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter k, the program takes the minimum of ...
#include <bits/stdc++.h> #include <random> #include <chrono> using namespace std; //#pragma GCC optimize("Ofast") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef ...
2C++
{ "input": [ "5\n5\n1 5 3 4 2\n4\n1 3 2 1\n5\n1 3 3 3 2\n10\n1 2 3 4 5 6 7 8 9 10\n3\n3 3 2\n", "5\n5\n1 5 3 4 2\n4\n1 3 2 1\n5\n1 3 3 3 2\n10\n1 2 1 4 5 6 7 8 9 10\n3\n3 3 2\n", "5\n5\n1 5 3 3 2\n4\n1 3 2 1\n5\n1 3 3 3 2\n10\n1 2 1 4 5 6 7 8 9 10\n3\n3 3 2\n", "5\n5\n1 5 3 4 2\n4\n1 3 2 1\n5\n1 3 3 3...
2CODEFORCES
1450_D. Rating Compression_2464
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers a of length n. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter k, the program takes the minimum of ...
from collections import deque for iii in range(int(input())): d = deque() f = 1 n = int(input()) m = {i+1 : 0 for i in range(n)} s = map(int, input().split()) for i in s: m[i]+=1 if m[i]!=1: f = 0 d.append(i) res = [0 for i in range(n)] if f: r...
3Python3
{ "input": [ "5\n5\n1 5 3 4 2\n4\n1 3 2 1\n5\n1 3 3 3 2\n10\n1 2 3 4 5 6 7 8 9 10\n3\n3 3 2\n", "5\n5\n1 5 3 4 2\n4\n1 3 2 1\n5\n1 3 3 3 2\n10\n1 2 1 4 5 6 7 8 9 10\n3\n3 3 2\n", "5\n5\n1 5 3 3 2\n4\n1 3 2 1\n5\n1 3 3 3 2\n10\n1 2 1 4 5 6 7 8 9 10\n3\n3 3 2\n", "5\n5\n1 5 3 4 2\n4\n1 3 2 1\n5\n1 3 3 3...
2CODEFORCES
1450_D. Rating Compression_2465
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers a of length n. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter k, the program takes the minimum of ...
import java.io.*;import java.util.*;import java.math.*; public class Main { static long mod=1000000007l; static int max=Integer.MAX_VALUE,min=Integer.MIN_VALUE; static long maxl=Long.MAX_VALUE,minl=Long.MIN_VALUE; static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); static Str...
4JAVA
{ "input": [ "5\n5\n1 5 3 4 2\n4\n1 3 2 1\n5\n1 3 3 3 2\n10\n1 2 3 4 5 6 7 8 9 10\n3\n3 3 2\n", "5\n5\n1 5 3 4 2\n4\n1 3 2 1\n5\n1 3 3 3 2\n10\n1 2 1 4 5 6 7 8 9 10\n3\n3 3 2\n", "5\n5\n1 5 3 3 2\n4\n1 3 2 1\n5\n1 3 3 3 2\n10\n1 2 1 4 5 6 7 8 9 10\n3\n3 3 2\n", "5\n5\n1 5 3 4 2\n4\n1 3 2 1\n5\n1 3 3 3...
2CODEFORCES
1474_B. Different Divisors_2466
Positive integer x is called divisor of positive integer y, if y is divisible by x without remainder. For example, 1 is a divisor of 7 and 3 is not divisor of 8. We gave you an integer d and asked you to find the smallest positive integer a, such that * a has at least 4 divisors; * difference between any two di...
##################################### import atexit, io, sys, collections, math, heapq buffer = io.BytesIO() sys.stdout = buffer @atexit.register def write(): sys.__stdout__.write(buffer.getvalue()) ##################################### pr = [True for _ in range(50000)] pr[0] = 0 for ii in range(2, int(len(p...
1Python2
{ "input": [ "2\n1\n2\n", "2\n2\n2\n", "2\n2\n3\n", "2\n3\n3\n", "2\n5\n3\n", "2\n5\n6\n", "2\n5\n12\n", "2\n1\n12\n", "2\n1\n4\n", "2\n2\n1\n", "2\n4\n6\n", "2\n5\n15\n", "2\n4\n2\n", "2\n6\n2\n", "2\n8\n6\n", "2\n2\n15\n", "2\n8\n7\n", "2\n2\n1...
2CODEFORCES
1474_B. Different Divisors_2467
Positive integer x is called divisor of positive integer y, if y is divisible by x without remainder. For example, 1 is a divisor of 7 and 3 is not divisor of 8. We gave you an integer d and asked you to find the smallest positive integer a, such that * a has at least 4 divisors; * difference between any two di...
#include<bits/stdc++.h> using namespace std; #define ll long long int #define mod 1000000007 vector<int> v2; bool prime[1000000]; void fun(int n) { for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } for (int p = 2; p <= n; p++) { ...
2C++
{ "input": [ "2\n1\n2\n", "2\n2\n2\n", "2\n2\n3\n", "2\n3\n3\n", "2\n5\n3\n", "2\n5\n6\n", "2\n5\n12\n", "2\n1\n12\n", "2\n1\n4\n", "2\n2\n1\n", "2\n4\n6\n", "2\n5\n15\n", "2\n4\n2\n", "2\n6\n2\n", "2\n8\n6\n", "2\n2\n15\n", "2\n8\n7\n", "2\n2\n1...
2CODEFORCES
1474_B. Different Divisors_2468
Positive integer x is called divisor of positive integer y, if y is divisible by x without remainder. For example, 1 is a divisor of 7 and 3 is not divisor of 8. We gave you an integer d and asked you to find the smallest positive integer a, such that * a has at least 4 divisors; * difference between any two di...
# ------------------- fast io -------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mod...
3Python3
{ "input": [ "2\n1\n2\n", "2\n2\n2\n", "2\n2\n3\n", "2\n3\n3\n", "2\n5\n3\n", "2\n5\n6\n", "2\n5\n12\n", "2\n1\n12\n", "2\n1\n4\n", "2\n2\n1\n", "2\n4\n6\n", "2\n5\n15\n", "2\n4\n2\n", "2\n6\n2\n", "2\n8\n6\n", "2\n2\n15\n", "2\n8\n7\n", "2\n2\n1...
2CODEFORCES
1474_B. Different Divisors_2469
Positive integer x is called divisor of positive integer y, if y is divisible by x without remainder. For example, 1 is a divisor of 7 and 3 is not divisor of 8. We gave you an integer d and asked you to find the smallest positive integer a, such that * a has at least 4 divisors; * difference between any two di...
import java.util.*; public class B{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- != 0) { int d = sc.nextInt(); int x = 1+d; int ans1 = 0; int ans2 = 0; while(true) { if(isPrime(x)) { ans1 = x; break; } x++; ...
4JAVA
{ "input": [ "2\n1\n2\n", "2\n2\n2\n", "2\n2\n3\n", "2\n3\n3\n", "2\n5\n3\n", "2\n5\n6\n", "2\n5\n12\n", "2\n1\n12\n", "2\n1\n4\n", "2\n2\n1\n", "2\n4\n6\n", "2\n5\n15\n", "2\n4\n2\n", "2\n6\n2\n", "2\n8\n6\n", "2\n2\n15\n", "2\n8\n7\n", "2\n2\n1...
2CODEFORCES
149_D. Coloring Brackets_2470
Once Petya read a problem about a bracket sequence. He gave it much thought but didn't find a solution. Today you will face it. You are given string s. It represents a correct bracket sequence. A correct bracket sequence is the sequence of opening ("(") and closing (")") brackets, such that it is possible to obtain a ...
bs = raw_input() n = len(bs) t = (0, 1, 2) M = 10**9+7 def empty_state(_cache={}): if _cache == {}: s = _cache for c1 in t: for c2 in t: if c1 * c2 == 0 and c1 + c2 != 0: s[c1, c2] = 1 else: s[c1, c2] = 0 return...
1Python2
{ "input": [ "(())\n", "()\n", "(()())\n", "()()(())()(())\n", "((()((()))()((()(()))())))()((()())())()(()())((()))(()())(())()(())()(())(())((()()))((()))()()()()(())()\n", "()()()\n", "((()(((((()(()(())))()((((((((())))()(((((())()((((())())(()(()(())())((()))()((()))))))))))))))))))))...
2CODEFORCES
149_D. Coloring Brackets_2471
Once Petya read a problem about a bracket sequence. He gave it much thought but didn't find a solution. Today you will face it. You are given string s. It represents a correct bracket sequence. A correct bracket sequence is the sequence of opening ("(") and closing (")") brackets, such that it is possible to obtain a ...
#include <bits/stdc++.h> char s[800]; long long dp[800][800][3][3]; int match[800]; void find_match(int n) { int stac[800], top = 0, i; for (i = 0; i <= n; i++) { if (s[i] == '(') stac[++top] = i; else { match[i] = stac[top]; match[stac[top]] = i; top--; } } return; } void df...
2C++
{ "input": [ "(())\n", "()\n", "(()())\n", "()()(())()(())\n", "((()((()))()((()(()))())))()((()())())()(()())((()))(()())(())()(())()(())(())((()()))((()))()()()()(())()\n", "()()()\n", "((()(((((()(()(())))()((((((((())))()(((((())()((((())())(()(()(())())((()))()((()))))))))))))))))))))...
2CODEFORCES
149_D. Coloring Brackets_2472
Once Petya read a problem about a bracket sequence. He gave it much thought but didn't find a solution. Today you will face it. You are given string s. It represents a correct bracket sequence. A correct bracket sequence is the sequence of opening ("(") and closing (")") brackets, such that it is possible to obtain a ...
// practice with rainboy import java.io.*; import java.util.*; public class CF149D extends PrintWriter { CF149D() { super(System.out, true); } Scanner sc = new Scanner(System.in); public static void main(String[] $) { CF149D o = new CF149D(); o.main(); o.flush(); } static final int MD = 1000000007; void merge...
4JAVA
{ "input": [ "(())\n", "()\n", "(()())\n", "()()(())()(())\n", "((()((()))()((()(()))())))()((()())())()(()())((()))(()())(())()(())()(())(())((()()))((()))()()()()(())()\n", "()()()\n", "((()(((((()(()(())))()((((((((())))()(((((())()((((())())(()(()(())())((()))()((()))))))))))))))))))))...
2CODEFORCES
1523_D. Love-Hate_2473
<image> William is hosting a party for n of his trader friends. They started a discussion on various currencies they trade, but there's an issue: not all of his trader friends like every currency. They like some currencies, but not others. For each William's friend i it is known whether he likes currency j. There are...
#include <stdio.h> #include <algorithm> #include <vector> #include <memory.h> #include <stack> #include <queue> #include <map> #include <set> #include <string.h> #include <string> #include <math.h> #include <time.h> #include <stdlib.h> using namespace std; typedef long long ll; const int INF = 1e9; const int MOD = 1e9 ...
2C++
{ "input": [ "3 4 3\n1000\n0110\n1001\n", "5 5 4\n11001\n10101\n10010\n01110\n11011\n", "2 30 15\n111010000000110001001001111111\n000101111111001110110110000000\n", "6 30 15\n111111111111111000000000000000\n111111111111111000000000000000\n111111111111111000000000000000\n000000000000000111111111111111\...
2CODEFORCES
1523_D. Love-Hate_2474
<image> William is hosting a party for n of his trader friends. They started a discussion on various currencies they trade, but there's an issue: not all of his trader friends like every currency. They like some currencies, but not others. For each William's friend i it is known whether he likes currency j. There are...
#!/usr/bin/env python import os import sys from io import BytesIO, IOBase def main(): def popCount(a): cnt = 0 for i in range(60): if a & (1 << i): cnt += 1 return cnt n,m,p = map(int,input().split()) person = [] for _ in range(n): person.a...
3Python3
{ "input": [ "3 4 3\n1000\n0110\n1001\n", "5 5 4\n11001\n10101\n10010\n01110\n11011\n", "2 30 15\n111010000000110001001001111111\n000101111111001110110110000000\n", "6 30 15\n111111111111111000000000000000\n111111111111111000000000000000\n111111111111111000000000000000\n000000000000000111111111111111\...
2CODEFORCES
1523_D. Love-Hate_2475
<image> William is hosting a party for n of his trader friends. They started a discussion on various currencies they trade, but there's an issue: not all of his trader friends like every currency. They like some currencies, but not others. For each William's friend i it is known whether he likes currency j. There are...
import java.io.*; import java.util.*; import java.math.*; import java.awt.Point; public class Main { static final long MOD = 1000000007L; //static final long MOD2 = 1000000009L; //static final long MOD = 998244353L; //static final long INF = 500000000000L; static final int INF = 1000000005; ...
4JAVA
{ "input": [ "3 4 3\n1000\n0110\n1001\n", "5 5 4\n11001\n10101\n10010\n01110\n11011\n", "2 30 15\n111010000000110001001001111111\n000101111111001110110110000000\n", "6 30 15\n111111111111111000000000000000\n111111111111111000000000000000\n111111111111111000000000000000\n000000000000000111111111111111\...
2CODEFORCES
155_C. Hometask_2476
Sergey attends lessons of the N-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the N-ish language. Sentences of the N-ish language can be represented as strings consisting of lowercase Latin letters without spaces or punctuation marks. Sergey totally forgot about ...
source = raw_input() source_length, i, result = len(source), 0, 0 pairs = [raw_input() for j in xrange(input())] while i < source_length: temp = i for pair in pairs: first, second = 0, 0 while i < source_length and source[i] in pair: if source[i] == pair[0]: first += 1 el...
1Python2
{ "input": [ "ababa\n1\nab\n", "codeforces\n2\ndo\ncs\n", "pninnihzipirpbdggrdglzdpbldtzihgbzdnrgznbpdanhnlag\n4\nli\nqh\nad\nbp\n", "mbmxuuuuxuuuuhhooooxxxuxxxuxuuxuuuxxjvjvjjjjvvvjjjjjvvjvjjjvvvjjvjjvvvjjjvjvvjvjjjjjmmbmbbbbbmbbbbmm\n5\nmb\nho\nxu\njv\nyp\n", "nllnrlrnll\n1\nrl\n", "aludfbjt...
2CODEFORCES
155_C. Hometask_2477
Sergey attends lessons of the N-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the N-ish language. Sentences of the N-ish language can be represented as strings consisting of lowercase Latin letters without spaces or punctuation marks. Sergey totally forgot about ...
#include <bits/stdc++.h> using namespace std; vector<string> seqs(string s, string v) { auto_ptr<stringstream> sst; vector<string> ret; for (int i = 0; i < s.size(); i++) { if (sst.get() == NULL) { if (s[i] == v[0] || s[i] == v[1]) { sst.reset(new stringstream()); *sst.get() << s[i]; ...
2C++
{ "input": [ "ababa\n1\nab\n", "codeforces\n2\ndo\ncs\n", "pninnihzipirpbdggrdglzdpbldtzihgbzdnrgznbpdanhnlag\n4\nli\nqh\nad\nbp\n", "mbmxuuuuxuuuuhhooooxxxuxxxuxuuxuuuxxjvjvjjjjvvvjjjjjvvjvjjjvvvjjvjjvvvjjjvjvvjvjjjjjmmbmbbbbbmbbbbmm\n5\nmb\nho\nxu\njv\nyp\n", "nllnrlrnll\n1\nrl\n", "aludfbjt...
2CODEFORCES
155_C. Hometask_2478
Sergey attends lessons of the N-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the N-ish language. Sentences of the N-ish language can be represented as strings consisting of lowercase Latin letters without spaces or punctuation marks. Sergey totally forgot about ...
s = input() + "#" k = int(input()) arr = [input() for _ in range(k)] res = 0 for t in arr: a, b = 0, 0 for i in range(len(s)): if s[i] == t[0]: a += 1 elif s[i] == t[1]: b += 1 else: if a and b: res += min(a, b) a, b = 0, 0 ...
3Python3
{ "input": [ "ababa\n1\nab\n", "codeforces\n2\ndo\ncs\n", "pninnihzipirpbdggrdglzdpbldtzihgbzdnrgznbpdanhnlag\n4\nli\nqh\nad\nbp\n", "mbmxuuuuxuuuuhhooooxxxuxxxuxuuxuuuxxjvjvjjjjvvvjjjjjvvjvjjjvvvjjvjjvvvjjjvjvvjvjjjjjmmbmbbbbbmbbbbmm\n5\nmb\nho\nxu\njv\nyp\n", "nllnrlrnll\n1\nrl\n", "aludfbjt...
2CODEFORCES
155_C. Hometask_2479
Sergey attends lessons of the N-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the N-ish language. Sentences of the N-ish language can be represented as strings consisting of lowercase Latin letters without spaces or punctuation marks. Sergey totally forgot about ...
import java.util.*; public class c { static boolean[][] graph; static int[] w; public static void main(String[] args) { Scanner in = new Scanner(System.in); char[] word = in.next().toCharArray(); w = new int[word.length]; for(int i = 0; i < w.length; i++) w[i] = (int)(word[i]-'a'); graph = new boolean[...
4JAVA
{ "input": [ "ababa\n1\nab\n", "codeforces\n2\ndo\ncs\n", "pninnihzipirpbdggrdglzdpbldtzihgbzdnrgznbpdanhnlag\n4\nli\nqh\nad\nbp\n", "mbmxuuuuxuuuuhhooooxxxuxxxuxuuxuuuxxjvjvjjjjvvvjjjjjvvjvjjjvvvjjvjjvvvjjjvjvvjvjjjjjmmbmbbbbbmbbbbmm\n5\nmb\nho\nxu\njv\nyp\n", "nllnrlrnll\n1\nrl\n", "aludfbjt...
2CODEFORCES
177_D1. Encrypting Messages_2480
The Smart Beaver from ABBYY invented a new message encryption method and now wants to check its performance. Checking it manually is long and tiresome, so he decided to ask the ABBYY Cup contestants for help. A message is a sequence of n integers a1, a2, ..., an. Encryption uses a key which is a sequence of m integers...
try: input = raw_input except: pass def slow(): for i in range(n-m+1): for k in range(m): result[i+k] = (result[i+k] + key[k]) % c n, m, c = list(map(int, input().split())) msg = list(map(int, input().split())) key = list(map(int, input().split())) result = [start for start in msg] slow() ...
1Python2
{ "input": [ "3 1 5\n1 2 3\n4\n", "4 3 2\n1 1 1 1\n1 1 1\n", "80 6 99\n48 97 9 77 73 21 86 78 48 5 71 16 42 67 90 27 30 52 41 86 53 4 60 17 66 38 94 46 51 51 70 11 1 16 74 53 17 12 82 95 51 33 83 70 45 27 90 57 67 2 68 15 20 61 47 90 11 5 95 33 69 35 79 51 95 45 10 17 12 88 93 43 31 31 85 68 85 81 70 43\n...
2CODEFORCES
177_D1. Encrypting Messages_2481
The Smart Beaver from ABBYY invented a new message encryption method and now wants to check its performance. Checking it manually is long and tiresome, so he decided to ask the ABBYY Cup contestants for help. A message is a sequence of n integers a1, a2, ..., an. Encryption uses a key which is a sequence of m integers...
#include <bits/stdc++.h> using namespace std; int a[100005], b[100005], ans[100005]; int main() { int mod, n, m, i, j, sum = 0; scanf("%d %d %d", &n, &m, &mod); for (i = 0; i < n; i++) scanf("%d", &a[i]); for (i = 0; i < m; i++) scanf("%d", &b[i]); for (i = 0; i < n; i++) { if (i < m) sum += b[i]; if ...
2C++
{ "input": [ "3 1 5\n1 2 3\n4\n", "4 3 2\n1 1 1 1\n1 1 1\n", "80 6 99\n48 97 9 77 73 21 86 78 48 5 71 16 42 67 90 27 30 52 41 86 53 4 60 17 66 38 94 46 51 51 70 11 1 16 74 53 17 12 82 95 51 33 83 70 45 27 90 57 67 2 68 15 20 61 47 90 11 5 95 33 69 35 79 51 95 45 10 17 12 88 93 43 31 31 85 68 85 81 70 43\n...
2CODEFORCES
177_D1. Encrypting Messages_2482
The Smart Beaver from ABBYY invented a new message encryption method and now wants to check its performance. Checking it manually is long and tiresome, so he decided to ask the ABBYY Cup contestants for help. A message is a sequence of n integers a1, a2, ..., an. Encryption uses a key which is a sequence of m integers...
n,m,c = map(int,input().split()) a = list(input().split()) b = list(input().split()) sum = 0 for i in range(n): if i<m: sum = sum + int(b[i]) sum = sum%c if i >= n - m + 1: sum = c - int(b[i-n+m-1]) + sum sum = sum%c print((int(a[i])+sum)%c,end = ' ')
3Python3
{ "input": [ "3 1 5\n1 2 3\n4\n", "4 3 2\n1 1 1 1\n1 1 1\n", "80 6 99\n48 97 9 77 73 21 86 78 48 5 71 16 42 67 90 27 30 52 41 86 53 4 60 17 66 38 94 46 51 51 70 11 1 16 74 53 17 12 82 95 51 33 83 70 45 27 90 57 67 2 68 15 20 61 47 90 11 5 95 33 69 35 79 51 95 45 10 17 12 88 93 43 31 31 85 68 85 81 70 43\n...
2CODEFORCES
177_D1. Encrypting Messages_2483
The Smart Beaver from ABBYY invented a new message encryption method and now wants to check its performance. Checking it manually is long and tiresome, so he decided to ask the ABBYY Cup contestants for help. A message is a sequence of n integers a1, a2, ..., an. Encryption uses a key which is a sequence of m integers...
import java.io.BufferedReader; import java.io.InputStreamReader; public class CF177D { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s[] = br.readLine().split(" "); int n = Integer....
4JAVA
{ "input": [ "3 1 5\n1 2 3\n4\n", "4 3 2\n1 1 1 1\n1 1 1\n", "80 6 99\n48 97 9 77 73 21 86 78 48 5 71 16 42 67 90 27 30 52 41 86 53 4 60 17 66 38 94 46 51 51 70 11 1 16 74 53 17 12 82 95 51 33 83 70 45 27 90 57 67 2 68 15 20 61 47 90 11 5 95 33 69 35 79 51 95 45 10 17 12 88 93 43 31 31 85 68 85 81 70 43\n...
2CODEFORCES
198_D. Cube Snake_2484
You've got an n × n × n cube, split into unit cubes. Your task is to number all unit cubes in this cube with positive integers from 1 to n3 so that: * each number was used as a cube's number exactly once; * for each 1 ≤ i < n3, unit cubes with numbers i and i + 1 were neighbouring (that is, shared a side); * ...
#include <bits/stdc++.h> using namespace std; const int maxn = 105; inline int gi() { char c = getchar(); while (c < '0' || c > '9') c = getchar(); int sum = 0; while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar(); return sum; } int n, A[maxn][maxn][maxn]; int main() { n = gi(); if (n == 1)...
2C++
{ "input": [ "3\n", "24\n", "27\n", "18\n", "26\n", "11\n", "16\n", "19\n", "2\n", "23\n", "28\n", "28\n", "27\n", "24\n", "6\n", "9\n", "31\n", "23\n", "14\n", "30\n", "13\n", "20\n", "25\n", "26\n", "21\n", "7\n"...
2CODEFORCES
198_D. Cube Snake_2485
You've got an n × n × n cube, split into unit cubes. Your task is to number all unit cubes in this cube with positive integers from 1 to n3 so that: * each number was used as a cube's number exactly once; * for each 1 ≤ i < n3, unit cubes with numbers i and i + 1 were neighbouring (that is, shared a side); * ...
import java.io.InputStreamReader; import java.io.IOException; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static ...
4JAVA
{ "input": [ "3\n", "24\n", "27\n", "18\n", "26\n", "11\n", "16\n", "19\n", "2\n", "23\n", "28\n", "28\n", "27\n", "24\n", "6\n", "9\n", "31\n", "23\n", "14\n", "30\n", "13\n", "20\n", "25\n", "26\n", "21\n", "7\n"...
2CODEFORCES
221_E. Little Elephant and Shifts_2486
The Little Elephant has two permutations a and b of length n, consisting of numbers from 1 to n, inclusive. Let's denote the i-th (1 ≤ i ≤ n) element of the permutation a as ai, the j-th (1 ≤ j ≤ n) element of the permutation b — as bj. The distance between permutations a and b is the minimum absolute value of the dif...
#include <bits/stdc++.h> using namespace std; const int Maxn = 100 * 1000 + 10; int n, inda[Maxn], indb[Maxn]; set<pair<int, int> > a, b, b1; int main() { scanf("%d", &n); int aa; for (int i = 0; i < n; i++) { scanf("%d", &aa); aa--; inda[aa] = i; } for (int i = 0; i < n; i++) { scanf("%d", &a...
2C++
{ "input": [ "4\n2 1 3 4\n3 4 2 1\n", "2\n1 2\n2 1\n", "74\n52 59 25 35 69 1 54 20 26 12 53 44 24 51 66 16 57 15 7 10 60 31 70 42 61 55 41 33 67 46 28 17 32 13 9 39 43 36 6 38 48 3 29 45 56 64 65 34 21 4 73 74 27 50 5 2 22 68 49 8 71 19 14 40 62 37 72 11 30 58 18 47 63 23\n56 3 68 1 9 70 36 58 52 15 27 57...
2CODEFORCES
221_E. Little Elephant and Shifts_2487
The Little Elephant has two permutations a and b of length n, consisting of numbers from 1 to n, inclusive. Let's denote the i-th (1 ≤ i ≤ n) element of the permutation a as ai, the j-th (1 ≤ j ≤ n) element of the permutation b — as bj. The distance between permutations a and b is the minimum absolute value of the dif...
import java.util.Scanner; import java.io.OutputStream; import java.io.IOException; import java.io.PrintWriter; import java.util.TreeSet; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author George Marcus */ public class Main { public static void main(String[] arg...
4JAVA
{ "input": [ "4\n2 1 3 4\n3 4 2 1\n", "2\n1 2\n2 1\n", "74\n52 59 25 35 69 1 54 20 26 12 53 44 24 51 66 16 57 15 7 10 60 31 70 42 61 55 41 33 67 46 28 17 32 13 9 39 43 36 6 38 48 3 29 45 56 64 65 34 21 4 73 74 27 50 5 2 22 68 49 8 71 19 14 40 62 37 72 11 30 58 18 47 63 23\n56 3 68 1 9 70 36 58 52 15 27 57...
2CODEFORCES
245_F. Log Stream Analysis_2488
You've got a list of program warning logs. Each record of a log stream is a string in this format: "2012-MM-DD HH:MM:SS:MESSAGE" (without the quotes). String "MESSAGE" consists of spaces, uppercase and lowercase English letters and characters "!", ".", ",", "?". String "2012-MM-DD" determines a correct date in the ...
from datetime import datetime n,m = [int(x) for x in raw_input().split()] t = [] found = False while not found: try: line = raw_input().split() day = line[0].split("-") hour = line[1].split(":") t.append(datetime(year = int(day[0]),month = int(day[1]),day = int(day[2]), ...
1Python2
{ "input": [ "60 3\n2012-03-16 16:15:25: Disk size is\n2012-03-16 16:15:25: Network failute\n2012-03-16 16:16:29: Cant write varlog\n2012-03-16 16:16:42: Unable to start process\n2012-03-16 16:16:43: Disk size is too small\n2012-03-16 16:16:53: Timeout detected\n", "2 2\n2012-03-16 23:59:59:Disk size is too s...
2CODEFORCES
245_F. Log Stream Analysis_2489
You've got a list of program warning logs. Each record of a log stream is a string in this format: "2012-MM-DD HH:MM:SS:MESSAGE" (without the quotes). String "MESSAGE" consists of spaces, uppercase and lowercase English letters and characters "!", ".", ",", "?". String "2012-MM-DD" determines a correct date in the ...
#include <bits/stdc++.h> using namespace std; int que[10000000]; char ss[10000000]; int day[13] = {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366}; int main() { int n, m; int head = 0, tail = 0; int now; int ye, mo, da, h, mi, s; cin >> n >> m; while (scanf("%d-%d-%d %d:%d:%d:", &ye, &mo, &da, &...
2C++
{ "input": [ "60 3\n2012-03-16 16:15:25: Disk size is\n2012-03-16 16:15:25: Network failute\n2012-03-16 16:16:29: Cant write varlog\n2012-03-16 16:16:42: Unable to start process\n2012-03-16 16:16:43: Disk size is too small\n2012-03-16 16:16:53: Timeout detected\n", "2 2\n2012-03-16 23:59:59:Disk size is too s...
2CODEFORCES
245_F. Log Stream Analysis_2490
You've got a list of program warning logs. Each record of a log stream is a string in this format: "2012-MM-DD HH:MM:SS:MESSAGE" (without the quotes). String "MESSAGE" consists of spaces, uppercase and lowercase English letters and characters "!", ".", ",", "?". String "2012-MM-DD" determines a correct date in the ...
import atexit import io import sys _INPUT_LINES = sys.stdin.read().splitlines() input = iter(_INPUT_LINES).__next__ _OUTPUT_BUFFER = io.StringIO() sys.stdout = _OUTPUT_BUFFER @atexit.register def write(): sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) import bisect from datetime import datetime def main(): ...
3Python3
{ "input": [ "60 3\n2012-03-16 16:15:25: Disk size is\n2012-03-16 16:15:25: Network failute\n2012-03-16 16:16:29: Cant write varlog\n2012-03-16 16:16:42: Unable to start process\n2012-03-16 16:16:43: Disk size is too small\n2012-03-16 16:16:53: Timeout detected\n", "2 2\n2012-03-16 23:59:59:Disk size is too s...
2CODEFORCES
245_F. Log Stream Analysis_2491
You've got a list of program warning logs. Each record of a log stream is a string in this format: "2012-MM-DD HH:MM:SS:MESSAGE" (without the quotes). String "MESSAGE" consists of spaces, uppercase and lowercase English letters and characters "!", ".", ",", "?". String "2012-MM-DD" determines a correct date in the ...
import static java.lang.Math.*; import static java.lang.System.currentTimeMillis; import static java.lang.System.exit; import static java.lang.System.arraycopy; import static java.util.Arrays.sort; import static java.util.Arrays.binarySearch; import static java.util.Arrays.fill; import java.util.*; import java.io.*; p...
4JAVA
{ "input": [ "60 3\n2012-03-16 16:15:25: Disk size is\n2012-03-16 16:15:25: Network failute\n2012-03-16 16:16:29: Cant write varlog\n2012-03-16 16:16:42: Unable to start process\n2012-03-16 16:16:43: Disk size is too small\n2012-03-16 16:16:53: Timeout detected\n", "2 2\n2012-03-16 23:59:59:Disk size is too s...
2CODEFORCES
270_D. Greenhouse Effect_2492
Emuskald is an avid horticulturist and owns the world's longest greenhouse — it is effectively infinite in length. Over the years Emuskald has cultivated n plants in his greenhouse, of m different plant species numbered from 1 to m. His greenhouse is very narrow and can be viewed as an infinite line, with each plant o...
import sys def upper_bound(nums, x): l, r = 0, len(nums)-1 while l <= r: mid = (l + r + 1) >> 1 if nums[mid] > x: r = mid - 1 else: l = mid + 1 return l if __name__ == "__main__": n, t = map(int,raw_input().split()) dp = [] for i in xrange(n): ...
1Python2
{ "input": [ "3 3\n1 5.0\n2 5.5\n3 6.0\n", "6 3\n1 14.284235\n2 17.921382\n1 20.328172\n3 20.842331\n1 25.790145\n1 27.204125\n", "3 2\n2 1\n1 2.0\n1 3.100\n", "20 10\n1 0.000000\n2 0.000001\n3 0.000002\n4 0.000003\n5 0.000004\n6 0.000005\n7 0.000006\n8 0.000007\n9 0.000008\n10 0.000009\n1 999999999.9...
2CODEFORCES
270_D. Greenhouse Effect_2493
Emuskald is an avid horticulturist and owns the world's longest greenhouse — it is effectively infinite in length. Over the years Emuskald has cultivated n plants in his greenhouse, of m different plant species numbered from 1 to m. His greenhouse is very narrow and can be viewed as an infinite line, with each plant o...
#include <bits/stdc++.h> using namespace std; int xx[5002][5002]; int lon_com_sub(int *ar, int *br, int n) { int i, j; for (i = 0; i <= n; i++) { for (j = 0; j <= n; j++) { if (i == 0 || j == 0) xx[i][j] = 0; else if (ar[i - 1] == br[j - 1]) xx[i][j] = xx[i - 1][j - 1] + 1; els...
2C++
{ "input": [ "3 3\n1 5.0\n2 5.5\n3 6.0\n", "6 3\n1 14.284235\n2 17.921382\n1 20.328172\n3 20.842331\n1 25.790145\n1 27.204125\n", "3 2\n2 1\n1 2.0\n1 3.100\n", "20 10\n1 0.000000\n2 0.000001\n3 0.000002\n4 0.000003\n5 0.000004\n6 0.000005\n7 0.000006\n8 0.000007\n9 0.000008\n10 0.000009\n1 999999999.9...
2CODEFORCES
270_D. Greenhouse Effect_2494
Emuskald is an avid horticulturist and owns the world's longest greenhouse — it is effectively infinite in length. Over the years Emuskald has cultivated n plants in his greenhouse, of m different plant species numbered from 1 to m. His greenhouse is very narrow and can be viewed as an infinite line, with each plant o...
n, m = [int(x) for x in input().split()] d = [0 for i in range(m)] for i in range(n): c, x = [x for x in input().split()] c = int(c) d[c-1] = max(d[:c])+1 print(n-max(d))
3Python3
{ "input": [ "3 3\n1 5.0\n2 5.5\n3 6.0\n", "6 3\n1 14.284235\n2 17.921382\n1 20.328172\n3 20.842331\n1 25.790145\n1 27.204125\n", "3 2\n2 1\n1 2.0\n1 3.100\n", "20 10\n1 0.000000\n2 0.000001\n3 0.000002\n4 0.000003\n5 0.000004\n6 0.000005\n7 0.000006\n8 0.000007\n9 0.000008\n10 0.000009\n1 999999999.9...
2CODEFORCES
270_D. Greenhouse Effect_2495
Emuskald is an avid horticulturist and owns the world's longest greenhouse — it is effectively infinite in length. Over the years Emuskald has cultivated n plants in his greenhouse, of m different plant species numbered from 1 to m. His greenhouse is very narrow and can be viewed as an infinite line, with each plant o...
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": [ "3 3\n1 5.0\n2 5.5\n3 6.0\n", "6 3\n1 14.284235\n2 17.921382\n1 20.328172\n3 20.842331\n1 25.790145\n1 27.204125\n", "3 2\n2 1\n1 2.0\n1 3.100\n", "20 10\n1 0.000000\n2 0.000001\n3 0.000002\n4 0.000003\n5 0.000004\n6 0.000005\n7 0.000006\n8 0.000007\n9 0.000008\n10 0.000009\n1 999999999.9...
2CODEFORCES
294_A. Shaass and Oskols_2496
Shaass has decided to hunt some birds. There are n horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to n from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are ai oskols ...
n=input() a=[100] +map(int, raw_input().split())+[100] m=input() c=[map(int, raw_input().split()) for i in ['']*m] for x,y in c: a[x-1] += y - 1 a[x+1] += a[x] - y a[x] = 0 print '\n'.join(map(str, a[1:-1]))
1Python2
{ "input": [ "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n", "3\n2 4 1\n1\n2 2\n", "1\n100\n1\n1 100\n", "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43\n", "2\n72 45\n6\n1 69\n2 41\n1 19\n2 7\n1 5\n2 1\n", "10\n48 53 10 28 91 56 81 2 67 52\n2\n2 40\n6 51\n", "1\n10\n0\n", "1\n1...
2CODEFORCES
294_A. Shaass and Oskols_2497
Shaass has decided to hunt some birds. There are n horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to n from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are ai oskols ...
#include <bits/stdc++.h> using namespace std; int main() { int i, m, n, y, x, a[106]; cin >> n; for (i = 1; i <= n; ++i) cin >> a[i]; cin >> m; for (i = 1; i <= m; ++i) { cin >> x >> y; a[x - 1] += y - 1; a[x + 1] += a[x] - y; a[x] = 0; } for (i = 1; i <= n; ++i) cout << a[i] << endl; re...
2C++
{ "input": [ "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n", "3\n2 4 1\n1\n2 2\n", "1\n100\n1\n1 100\n", "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43\n", "2\n72 45\n6\n1 69\n2 41\n1 19\n2 7\n1 5\n2 1\n", "10\n48 53 10 28 91 56 81 2 67 52\n2\n2 40\n6 51\n", "1\n10\n0\n", "1\n1...
2CODEFORCES
294_A. Shaass and Oskols_2498
Shaass has decided to hunt some birds. There are n horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to n from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are ai oskols ...
n = int(input()) l = list(map(int,input().split())) n1 = int(input()) for i in range(n1): x,y = map(int,input().split()) if len(l)==1: l[0]=0 elif x==1: l[x]+=l[x-1]-y l[x-1]=0 elif x==len(l): l[x-2]+=y-1 l[x-1]=0 else: l[x-2]+=y-1 l[x]+=l[x-1]-y l[x-1]=0 for i in l: print(i)
3Python3
{ "input": [ "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n", "3\n2 4 1\n1\n2 2\n", "1\n100\n1\n1 100\n", "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43\n", "2\n72 45\n6\n1 69\n2 41\n1 19\n2 7\n1 5\n2 1\n", "10\n48 53 10 28 91 56 81 2 67 52\n2\n2 40\n6 51\n", "1\n10\n0\n", "1\n1...
2CODEFORCES
294_A. Shaass and Oskols_2499
Shaass has decided to hunt some birds. There are n horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to n from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are ai oskols ...
import java.util.*; public class Main{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int a[]=new int[n]; for(int i=0;i<n;i++){ a[i]=sc.nextInt(); } in...
4JAVA
{ "input": [ "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n", "3\n2 4 1\n1\n2 2\n", "1\n100\n1\n1 100\n", "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43\n", "2\n72 45\n6\n1 69\n2 41\n1 19\n2 7\n1 5\n2 1\n", "10\n48 53 10 28 91 56 81 2 67 52\n2\n2 40\n6 51\n", "1\n10\n0\n", "1\n1...
2CODEFORCES