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
1076_B. Divisor Subtraction_2100
You are given an integer number n. The following algorithm is applied to it: 1. if n = 0, then end algorithm; 2. find the smallest prime divisor d of n; 3. subtract d from n and go to step 1. Determine the number of subtrations the algorithm will make. Input The only line contains a single integer n (2 ≤...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long ans = 0; if (n % 2 == 0) { cout << n / 2 << endl; return 0; } for (long long i = 2; i * i <= n; ++i) if (n % i == 0) { cout << (n - i) / 2 + 1 << endl; return 0; } cout << 1 << endl; }
2C++
{ "input": [ "4\n", "5\n", "9999999999\n", "10000000000\n", "9999999967\n", "2\n", "6969696\n", "473\n", "9998200081\n", "3000000021\n", "186627465\n", "10000000010\n", "4868692902\n", "6\n", "7434214\n", "261\n", "2351148436\n", "4156825468\n", ...
2CODEFORCES
1076_B. Divisor Subtraction_2101
You are given an integer number n. The following algorithm is applied to it: 1. if n = 0, then end algorithm; 2. find the smallest prime divisor d of n; 3. subtract d from n and go to step 1. Determine the number of subtrations the algorithm will make. Input The only line contains a single integer n (2 ≤...
from collections import deque as de import math class My_stack(): def __init__(self): self.data = [] def my_push(self, x): return (self.data.append(x)) def my_pop(self): return (self.data.pop()) def my_peak(self): return (self.data[-1]) def my_contains(self, x): ...
3Python3
{ "input": [ "4\n", "5\n", "9999999999\n", "10000000000\n", "9999999967\n", "2\n", "6969696\n", "473\n", "9998200081\n", "3000000021\n", "186627465\n", "10000000010\n", "4868692902\n", "6\n", "7434214\n", "261\n", "2351148436\n", "4156825468\n", ...
2CODEFORCES
1076_B. Divisor Subtraction_2102
You are given an integer number n. The following algorithm is applied to it: 1. if n = 0, then end algorithm; 2. find the smallest prime divisor d of n; 3. subtract d from n and go to step 1. Determine the number of subtrations the algorithm will make. Input The only line contains a single integer n (2 ≤...
import java.io.*; import java.util.*; public class Towers { public static void main(String args[]) { Scanner input = new Scanner(System.in); long n = input.nextLong(); long count = 0; boolean is_prime = true; int temp = 0; for ( int i = 2; i <= Math.sqrt(n); i++){ ...
4JAVA
{ "input": [ "4\n", "5\n", "9999999999\n", "10000000000\n", "9999999967\n", "2\n", "6969696\n", "473\n", "9998200081\n", "3000000021\n", "186627465\n", "10000000010\n", "4868692902\n", "6\n", "7434214\n", "261\n", "2351148436\n", "4156825468\n", ...
2CODEFORCES
1097_B. Petr and a Combination Lock_2103
Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360 degrees and a pointer which initially points at zero: <image> Petr called his car dealer, who in...
rotations = int(raw_input().strip()) valuesPos = [] valuesNeg = [] for r in xrange(rotations): v = int(raw_input().strip()) valuesPos.append(v) valuesNeg.append(360-v) valueSums = [valuesPos[0], valuesNeg[0]] for i in xrange(1, rotations): newSums = [] for v in valueSums: newSums.append(v +...
1Python2
{ "input": [ "3\n10\n10\n10\n", "3\n120\n120\n120\n", "3\n10\n20\n30\n", "5\n179\n179\n179\n179\n4\n", "5\n179\n170\n160\n111\n100\n", "4\n1\n178\n180\n1\n", "6\n180\n178\n157\n143\n63\n1\n", "5\n100\n100\n100\n100\n40\n", "9\n80\n80\n80\n80\n80\n80\n80\n80\n80\n", "5\n179\n179...
2CODEFORCES
1097_B. Petr and a Combination Lock_2104
Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360 degrees and a pointer which initially points at zero: <image> Petr called his car dealer, who in...
#include <bits/stdc++.h> using namespace std; const int N = 20; int a[N]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d", &a[i]); for (int i = 0; i < 1 << n; ++i) { int res = 0; for (int j = 0; j < n; ++j) { if ((i >> j) & 1) res = (res + a[j]) % 360; els...
2C++
{ "input": [ "3\n10\n10\n10\n", "3\n120\n120\n120\n", "3\n10\n20\n30\n", "5\n179\n179\n179\n179\n4\n", "5\n179\n170\n160\n111\n100\n", "4\n1\n178\n180\n1\n", "6\n180\n178\n157\n143\n63\n1\n", "5\n100\n100\n100\n100\n40\n", "9\n80\n80\n80\n80\n80\n80\n80\n80\n80\n", "5\n179\n179...
2CODEFORCES
1097_B. Petr and a Combination Lock_2105
Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360 degrees and a pointer which initially points at zero: <image> Petr called his car dealer, who in...
n = int(input()) a = [0] for _ in range(n): curr = int(input()) mods = [] for o in a: mods.extend([o + curr, o - curr]) a = mods[:] #print(a) print("YES" if any(x%360 == 0 for x in a) else "NO")
3Python3
{ "input": [ "3\n10\n10\n10\n", "3\n120\n120\n120\n", "3\n10\n20\n30\n", "5\n179\n179\n179\n179\n4\n", "5\n179\n170\n160\n111\n100\n", "4\n1\n178\n180\n1\n", "6\n180\n178\n157\n143\n63\n1\n", "5\n100\n100\n100\n100\n40\n", "9\n80\n80\n80\n80\n80\n80\n80\n80\n80\n", "5\n179\n179...
2CODEFORCES
1097_B. Petr and a Combination Lock_2106
Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360 degrees and a pointer which initially points at zero: <image> Petr called his car dealer, who in...
import java.io.*; public class b1109 {static int a[],n; public static int fun(int a[],int i,int s) { if(i==n) { if(s%360==0) return 1; else return 0;} int x =fun(a,i+1,s+a[i]); if(x==1) return 1; int y= fun(a,i+1,s-a[i]); if(y==1) return 1; else return 0; } public static void main(String args[])thro...
4JAVA
{ "input": [ "3\n10\n10\n10\n", "3\n120\n120\n120\n", "3\n10\n20\n30\n", "5\n179\n179\n179\n179\n4\n", "5\n179\n170\n160\n111\n100\n", "4\n1\n178\n180\n1\n", "6\n180\n178\n157\n143\n63\n1\n", "5\n100\n100\n100\n100\n40\n", "9\n80\n80\n80\n80\n80\n80\n80\n80\n80\n", "5\n179\n179...
2CODEFORCES
1118_C. Palindromic Matrix_2107
Let's call some square matrix with integer values in its cells palindromic if it doesn't change after the order of rows is reversed and it doesn't change after the order of columns is reversed. For example, the following matrices are palindromic: <image> The following matrices are not palindromic because they change...
import math import string x=input() arr=[] i=0 l = map(int,raw_input().split()) for item in l: arr.append(item) arr.sort() matrix=0 if (x==1): print("YES") print(arr[0]) else: if (x %2 ==0): k=1 for i in range(1,x*x): if (arr[i]==arr[i-1]): k+=1 if (k==4): k=0 else: if (k==0): k=1 ...
1Python2
{ "input": [ "4\n1 8 8 1 2 2 2 2 2 2 2 2 1 8 8 1\n", "4\n1 2 1 9 8 4 3 8 8 3 4 8 9 2 1 1\n", "1\n10\n", "3\n1 1 1 1 1 3 3 3 3\n", "3\n13 13 42 42 69 69 420 420 666\n", "11\n1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 6...
2CODEFORCES
1118_C. Palindromic Matrix_2108
Let's call some square matrix with integer values in its cells palindromic if it doesn't change after the order of rows is reversed and it doesn't change after the order of columns is reversed. For example, the following matrices are palindromic: <image> The following matrices are not palindromic because they change...
#include <bits/stdc++.h> using namespace std; int a[1001], mat[21][21]; queue<int> n2; queue<int> n4; int n1; int main() { int n, t; cin >> n; for (int i = 1; i <= n * n; i++) { cin >> t; a[t]++; } int odd = 0, oddi; int r = 1, c = 1; if (n % 2 == 0) { for (int i = 1; i <= 1000; i++) { w...
2C++
{ "input": [ "4\n1 8 8 1 2 2 2 2 2 2 2 2 1 8 8 1\n", "4\n1 2 1 9 8 4 3 8 8 3 4 8 9 2 1 1\n", "1\n10\n", "3\n1 1 1 1 1 3 3 3 3\n", "3\n13 13 42 42 69 69 420 420 666\n", "11\n1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 6...
2CODEFORCES
1118_C. Palindromic Matrix_2109
Let's call some square matrix with integer values in its cells palindromic if it doesn't change after the order of rows is reversed and it doesn't change after the order of columns is reversed. For example, the following matrices are palindromic: <image> The following matrices are not palindromic because they change...
import os from io import BytesIO, StringIO #input = BytesIO(os.read(0, os.fstat(0).st_size)).readline from collections import defaultdict def input_as_list(): return list(map(int, input().split())) def array_of(f, *dim): return [array_of(f, *dim[1:]) for _ in range(dim[0])] if dim else f() def main(): n ...
3Python3
{ "input": [ "4\n1 8 8 1 2 2 2 2 2 2 2 2 1 8 8 1\n", "4\n1 2 1 9 8 4 3 8 8 3 4 8 9 2 1 1\n", "1\n10\n", "3\n1 1 1 1 1 3 3 3 3\n", "3\n13 13 42 42 69 69 420 420 666\n", "11\n1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 6...
2CODEFORCES
1118_C. Palindromic Matrix_2110
Let's call some square matrix with integer values in its cells palindromic if it doesn't change after the order of rows is reversed and it doesn't change after the order of columns is reversed. For example, the following matrices are palindromic: <image> The following matrices are not palindromic because they change...
import java.io.PrintWriter; import java.lang.reflect.Array; import java.util.Arrays; import java.util.Scanner; public class PalindromicMatrix { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(); int n2 = n*n...
4JAVA
{ "input": [ "4\n1 8 8 1 2 2 2 2 2 2 2 2 1 8 8 1\n", "4\n1 2 1 9 8 4 3 8 8 3 4 8 9 2 1 1\n", "1\n10\n", "3\n1 1 1 1 1 3 3 3 3\n", "3\n13 13 42 42 69 69 420 420 666\n", "11\n1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 6...
2CODEFORCES
1144_F. Graph Without Long Directed Paths_2111
You are given a connected undirected graph consisting of n vertices and m edges. There are no self-loops or multiple edges in the given graph. You have to direct its edges in such a way that the obtained directed graph does not contain any paths of length two or greater (where the length of path is denoted as the numb...
# Author : raj1307 - Raj Singh # Date : 23.05.2020 from __future__ import division, print_function import os,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 def ii(): return int(input()) ...
1Python2
{ "input": [ "6 5\n1 5\n2 1\n1 4\n3 1\n6 1\n", "8 9\n8 1\n1 2\n1 5\n2 6\n6 5\n6 4\n4 7\n7 3\n3 5\n", "10 10\n2 1\n3 4\n7 1\n4 10\n6 1\n8 4\n9 1\n5 8\n1 8\n3 6\n", "10 10\n1 3\n9 6\n4 5\n1 9\n8 5\n9 7\n3 2\n5 7\n5 3\n10 5\n", "7 7\n4 1\n7 3\n4 7\n4 2\n1 3\n6 4\n5 3\n", "4 5\n1 2\n2 3\n3 4\n4 1\...
2CODEFORCES
1144_F. Graph Without Long Directed Paths_2112
You are given a connected undirected graph consisting of n vertices and m edges. There are no self-loops or multiple edges in the given graph. You have to direct its edges in such a way that the obtained directed graph does not contain any paths of length two or greater (where the length of path is denoted as the numb...
#include <bits/stdc++.h> using namespace std; bool answer = true; void dfs(vector<int>& visited, vector<vector<int>>& g, int vertex, int oddity) { visited[vertex] = oddity; for (int i = 0; i < g[vertex].size(); ++i) { if (visited[g[vertex][i]] == 0) { dfs(visited, g, g[vertex][i], oddity == 1 ? -1 : 1); ...
2C++
{ "input": [ "6 5\n1 5\n2 1\n1 4\n3 1\n6 1\n", "8 9\n8 1\n1 2\n1 5\n2 6\n6 5\n6 4\n4 7\n7 3\n3 5\n", "10 10\n2 1\n3 4\n7 1\n4 10\n6 1\n8 4\n9 1\n5 8\n1 8\n3 6\n", "10 10\n1 3\n9 6\n4 5\n1 9\n8 5\n9 7\n3 2\n5 7\n5 3\n10 5\n", "7 7\n4 1\n7 3\n4 7\n4 2\n1 3\n6 4\n5 3\n", "4 5\n1 2\n2 3\n3 4\n4 1\...
2CODEFORCES
1144_F. Graph Without Long Directed Paths_2113
You are given a connected undirected graph consisting of n vertices and m edges. There are no self-loops or multiple edges in the given graph. You have to direct its edges in such a way that the obtained directed graph does not contain any paths of length two or greater (where the length of path is denoted as the numb...
# lista doble enlazada o(1) en operaciones en los bordes from collections import deque def solve(): global n, m n, m = map(lambda x: int(x), input().split()) global maxValue maxValue = n**2 graph = [[] for _ in range(0, n)] edges = [] for _ in range(0, m): u, v = map(lambda x: int(...
3Python3
{ "input": [ "6 5\n1 5\n2 1\n1 4\n3 1\n6 1\n", "8 9\n8 1\n1 2\n1 5\n2 6\n6 5\n6 4\n4 7\n7 3\n3 5\n", "10 10\n2 1\n3 4\n7 1\n4 10\n6 1\n8 4\n9 1\n5 8\n1 8\n3 6\n", "10 10\n1 3\n9 6\n4 5\n1 9\n8 5\n9 7\n3 2\n5 7\n5 3\n10 5\n", "7 7\n4 1\n7 3\n4 7\n4 2\n1 3\n6 4\n5 3\n", "4 5\n1 2\n2 3\n3 4\n4 1\...
2CODEFORCES
1144_F. Graph Without Long Directed Paths_2114
You are given a connected undirected graph consisting of n vertices and m edges. There are no self-loops or multiple edges in the given graph. You have to direct its edges in such a way that the obtained directed graph does not contain any paths of length two or greater (where the length of path is denoted as the numb...
import java.io.*; import java.util.*; public class GraphWithout{ static List<Integer>[]adj; static int[] clr; static int[]visit; public static void main(String[]args){ MyScanner sc=new MyScanner(); PrintWriter pw=new PrintWriter(System.out); int n=sc.nextInt(),m=sc.nextInt(); adj=new Array...
4JAVA
{ "input": [ "6 5\n1 5\n2 1\n1 4\n3 1\n6 1\n", "8 9\n8 1\n1 2\n1 5\n2 6\n6 5\n6 4\n4 7\n7 3\n3 5\n", "10 10\n2 1\n3 4\n7 1\n4 10\n6 1\n8 4\n9 1\n5 8\n1 8\n3 6\n", "10 10\n1 3\n9 6\n4 5\n1 9\n8 5\n9 7\n3 2\n5 7\n5 3\n10 5\n", "7 7\n4 1\n7 3\n4 7\n4 2\n1 3\n6 4\n5 3\n", "4 5\n1 2\n2 3\n3 4\n4 1\...
2CODEFORCES
1165_E. Two Arrays and Sum of Functions_2115
You are given two arrays a and b, both of length n. Let's define a function f(l, r) = ∑_{l ≤ i ≤ r} a_i ⋅ b_i. Your task is to reorder the elements (choose an arbitrary order of elements) of the array b to minimize the value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r). Since the answer can be very large, you have to print it modulo...
from sys import stdin add = lambda a, b: (a % mod + b % mod) % mod mult = lambda a, b: ((a % mod) * (b % mod)) % mod rints = lambda: [int(x) for x in stdin.readline().split()] arr_enu = lambda: [[i, int(x)] for i, x in enumerate(stdin.readline().split())] mod = 998244353 def sum_segments(a): tem = [] for i i...
1Python2
{ "input": [ "1\n1000000\n1000000\n", "5\n1 8 7 2 4\n9 7 2 9 3\n", "2\n1 3\n4 2\n", "1\n1000010\n1000000\n", "5\n1 8 7 2 4\n9 11 2 9 3\n", "2\n1 3\n4 1\n", "1\n1000011\n1000000\n", "5\n1 8 7 2 5\n9 11 2 9 3\n", "2\n1 5\n4 1\n", "1\n1001011\n1000000\n", "5\n1 11 7 2 5\n9 11 ...
2CODEFORCES
1165_E. Two Arrays and Sum of Functions_2116
You are given two arrays a and b, both of length n. Let's define a function f(l, r) = ∑_{l ≤ i ≤ r} a_i ⋅ b_i. Your task is to reorder the elements (choose an arbitrary order of elements) of the array b to minimize the value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r). Since the answer can be very large, you have to print it modulo...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 7; const int mod = 998244353; long long a[maxn]; long long b[maxn]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); a[i] = a[i] * (n - i + 1) * i; } for (int i = 1; i <= n; i++) scanf("%d", &...
2C++
{ "input": [ "1\n1000000\n1000000\n", "5\n1 8 7 2 4\n9 7 2 9 3\n", "2\n1 3\n4 2\n", "1\n1000010\n1000000\n", "5\n1 8 7 2 4\n9 11 2 9 3\n", "2\n1 3\n4 1\n", "1\n1000011\n1000000\n", "5\n1 8 7 2 5\n9 11 2 9 3\n", "2\n1 5\n4 1\n", "1\n1001011\n1000000\n", "5\n1 11 7 2 5\n9 11 ...
2CODEFORCES
1165_E. Two Arrays and Sum of Functions_2117
You are given two arrays a and b, both of length n. Let's define a function f(l, r) = ∑_{l ≤ i ≤ r} a_i ⋅ b_i. Your task is to reorder the elements (choose an arbitrary order of elements) of the array b to minimize the value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r). Since the answer can be very large, you have to print it modulo...
m=998244353 n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) a=sorted([a[i]*(i+1)*(n-i) for i in range(n)]) b.sort(reverse=True) ans=0 for i in range(n): ans=(ans+(a[i]*b[i])%m)%m print(ans)
3Python3
{ "input": [ "1\n1000000\n1000000\n", "5\n1 8 7 2 4\n9 7 2 9 3\n", "2\n1 3\n4 2\n", "1\n1000010\n1000000\n", "5\n1 8 7 2 4\n9 11 2 9 3\n", "2\n1 3\n4 1\n", "1\n1000011\n1000000\n", "5\n1 8 7 2 5\n9 11 2 9 3\n", "2\n1 5\n4 1\n", "1\n1001011\n1000000\n", "5\n1 11 7 2 5\n9 11 ...
2CODEFORCES
1165_E. Two Arrays and Sum of Functions_2118
You are given two arrays a and b, both of length n. Let's define a function f(l, r) = ∑_{l ≤ i ≤ r} a_i ⋅ b_i. Your task is to reorder the elements (choose an arbitrary order of elements) of the array b to minimize the value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r). Since the answer can be very large, you have to print it modulo...
import java.io.*; import java.lang.reflect.Array; import java.math.BigInteger; import java.util.*; import static java.lang.Math.*; public class Main { static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bu...
4JAVA
{ "input": [ "1\n1000000\n1000000\n", "5\n1 8 7 2 4\n9 7 2 9 3\n", "2\n1 3\n4 2\n", "1\n1000010\n1000000\n", "5\n1 8 7 2 4\n9 11 2 9 3\n", "2\n1 3\n4 1\n", "1\n1000011\n1000000\n", "5\n1 8 7 2 5\n9 11 2 9 3\n", "2\n1 5\n4 1\n", "1\n1001011\n1000000\n", "5\n1 11 7 2 5\n9 11 ...
2CODEFORCES
1184_D1. Parallel Universes (Easy)_2119
The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be more than 250. Heidi recently got her hands on a multiverse observation to...
n,k,m,t = map(int,raw_input().split()) a = [i for i in range(n)] k-=1 p=k x = n for _ in range(t): q,i = map(int,raw_input().split()) if q == 1: a.insert(i-1,x) x+=1 else: b = a[0:i] c = a[i:len(a)] if p<len(b): a = b else: a = c ...
1Python2
{ "input": [ "5 2 10 4\n0 1\n1 1\n0 4\n1 2\n", "10 5 20 4\n1 1\n0 4\n1 7\n1 7\n", "18 5 20 4\n1 1\n0 4\n1 7\n1 7\n", "5 2 10 4\n0 1\n1 1\n1 4\n1 2\n", "5 2 10 4\n0 1\n1 1\n1 4\n0 2\n", "18 5 20 4\n1 2\n0 2\n1 7\n1 7\n", "18 5 20 4\n1 1\n0 1\n1 7\n1 7\n", "5 2 10 4\n1 1\n1 1\n1 4\n0 2\n...
2CODEFORCES
1184_D1. Parallel Universes (Easy)_2120
The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be more than 250. Heidi recently got her hands on a multiverse observation to...
#include <bits/stdc++.h> int main() { int n, k, m, t, i; scanf("%d%d%d%d", &n, &k, &m, &t); int a, b; for (i = 0; i < t; i++) { scanf("%d %d", &a, &b); if (a == 0) { if (b < k) { n -= b; k -= b; } else { n = b; } } if (a == 1) { if (b <= k) { ...
2C++
{ "input": [ "5 2 10 4\n0 1\n1 1\n0 4\n1 2\n", "10 5 20 4\n1 1\n0 4\n1 7\n1 7\n", "18 5 20 4\n1 1\n0 4\n1 7\n1 7\n", "5 2 10 4\n0 1\n1 1\n1 4\n1 2\n", "5 2 10 4\n0 1\n1 1\n1 4\n0 2\n", "18 5 20 4\n1 2\n0 2\n1 7\n1 7\n", "18 5 20 4\n1 1\n0 1\n1 7\n1 7\n", "5 2 10 4\n1 1\n1 1\n1 4\n0 2\n...
2CODEFORCES
1184_D1. Parallel Universes (Easy)_2121
The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be more than 250. Heidi recently got her hands on a multiverse observation to...
n,k,m,t=map(int,input().split()) for i in range(t): a,b=map(int,input().split()) if a==1: if b<=k: k+=1 n+=1 print(n,k) else : if k>b: n=n-b k=k-b else : n=b print(n,k)
3Python3
{ "input": [ "5 2 10 4\n0 1\n1 1\n0 4\n1 2\n", "10 5 20 4\n1 1\n0 4\n1 7\n1 7\n", "18 5 20 4\n1 1\n0 4\n1 7\n1 7\n", "5 2 10 4\n0 1\n1 1\n1 4\n1 2\n", "5 2 10 4\n0 1\n1 1\n1 4\n0 2\n", "18 5 20 4\n1 2\n0 2\n1 7\n1 7\n", "18 5 20 4\n1 1\n0 1\n1 7\n1 7\n", "5 2 10 4\n1 1\n1 1\n1 4\n0 2\n...
2CODEFORCES
1184_D1. Parallel Universes (Easy)_2122
The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be more than 250. Heidi recently got her hands on a multiverse observation to...
import java.util.*; import java.io.*; import java.text.*; public class D1_1184 { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int n = sc.nextInt(); int k = sc.nextInt(); int m = sc.nextInt(); int t = sc.nextI...
4JAVA
{ "input": [ "5 2 10 4\n0 1\n1 1\n0 4\n1 2\n", "10 5 20 4\n1 1\n0 4\n1 7\n1 7\n", "18 5 20 4\n1 1\n0 4\n1 7\n1 7\n", "5 2 10 4\n0 1\n1 1\n1 4\n1 2\n", "5 2 10 4\n0 1\n1 1\n1 4\n0 2\n", "18 5 20 4\n1 2\n0 2\n1 7\n1 7\n", "18 5 20 4\n1 1\n0 1\n1 7\n1 7\n", "5 2 10 4\n1 1\n1 1\n1 4\n0 2\n...
2CODEFORCES
1203_A. Circle of Students_2123
There are n students standing in a circle in some order. The index of the i-th student is p_i. It is guaranteed that all indices of students are distinct integers from 1 to n (i. e. they form a permutation). Students want to start a round dance. A clockwise round dance can be started if the student 2 comes right after...
# # Bad python template TM # # Zeyu, 2019 # from sys import stdin, stdout, setrecursionlimit input = stdin.readline flush = stdout.flush # setrecursionlimit(1000000) ############################################################ OUT = [] def write(item, sep=" "): if type(item) is int: OUT.appen...
1Python2
{ "input": [ "5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4\n", "1\n11\n11 2 3 4 5 6 7 8 9 10 1\n", "1\n12\n12 3 4 5 6 7 8 9 10 11 1 2\n", "1\n12\n12 3 8 5 6 7 8 9 10 11 1 2\n", "1\n12\n12 3 8 5 11 7 8 9 10 11 1 2\n", "1\n11\n11 2 3 4 5 6 7 13 9 10 1\n", "1\n12\n12 3 4 5 6 7 8 ...
2CODEFORCES
1203_A. Circle of Students_2124
There are n students standing in a circle in some order. The index of the i-th student is p_i. It is guaranteed that all indices of students are distinct integers from 1 to n (i. e. they form a permutation). Students want to start a round dance. A clockwise round dance can be started if the student 2 comes right after...
#include <bits/stdc++.h> using namespace std; long long int cnt = 0; long long int n, m; long long int h1[100005], h2[100007]; int main() { long long int i, j, k, l, n, m; long long int q; cin >> q; while (q--) { cin >> n; long long int a[n], t = 0; for (int i = 0; i < n; i++) { cin >> a[i]; ...
2C++
{ "input": [ "5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4\n", "1\n11\n11 2 3 4 5 6 7 8 9 10 1\n", "1\n12\n12 3 4 5 6 7 8 9 10 11 1 2\n", "1\n12\n12 3 8 5 6 7 8 9 10 11 1 2\n", "1\n12\n12 3 8 5 11 7 8 9 10 11 1 2\n", "1\n11\n11 2 3 4 5 6 7 13 9 10 1\n", "1\n12\n12 3 4 5 6 7 8 ...
2CODEFORCES
1203_A. Circle of Students_2125
There are n students standing in a circle in some order. The index of the i-th student is p_i. It is guaranteed that all indices of students are distinct integers from 1 to n (i. e. they form a permutation). Students want to start a round dance. A clockwise round dance can be started if the student 2 comes right after...
t=int(input()) while t: n=int(input()) a=list(map(int,input().split())) b=[0]*n for i in range(n): b[a[i]-1]=i+1 k=0 flag=0 # print(b) if n==1: print("YES") elif abs(b[0]-b[1])==1 or abs(b[0]-b[1])==n-1: if abs(b[0]-b[1])==1: k=b[0]-b[1] else: k=b[1]-b[2] for j in range(1,n): if j==n-1: ...
3Python3
{ "input": [ "5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4\n", "1\n11\n11 2 3 4 5 6 7 8 9 10 1\n", "1\n12\n12 3 4 5 6 7 8 9 10 11 1 2\n", "1\n12\n12 3 8 5 6 7 8 9 10 11 1 2\n", "1\n12\n12 3 8 5 11 7 8 9 10 11 1 2\n", "1\n11\n11 2 3 4 5 6 7 13 9 10 1\n", "1\n12\n12 3 4 5 6 7 8 ...
2CODEFORCES
1203_A. Circle of Students_2126
There are n students standing in a circle in some order. The index of the i-th student is p_i. It is guaranteed that all indices of students are distinct integers from 1 to n (i. e. they form a permutation). Students want to start a round dance. A clockwise round dance can be started if the student 2 comes right after...
import java.io.*; import java.lang.reflect.Array; import java.util.*; public class Main { private static PrintWriter out; private static <T> void mprintln(T... ar) { for (T i : ar) { out.print(i + " "); } out.println(); } public static void main(String[] args) thr...
4JAVA
{ "input": [ "5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4\n", "1\n11\n11 2 3 4 5 6 7 8 9 10 1\n", "1\n12\n12 3 4 5 6 7 8 9 10 11 1 2\n", "1\n12\n12 3 8 5 6 7 8 9 10 11 1 2\n", "1\n12\n12 3 8 5 11 7 8 9 10 11 1 2\n", "1\n11\n11 2 3 4 5 6 7 13 9 10 1\n", "1\n12\n12 3 4 5 6 7 8 ...
2CODEFORCES
121_C. Lucky Permutation_2127
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
from math import factorial import sys def lucky(x): return str(x).count('4')+str(x).count('7')==len(str(x)) def fun(x): xs, result = str(x), 0 for i in range(len(xs)): rest = 1<<(len(xs)-i-1) if int(xs[i]) == 4: continue elif int(xs[i]) == 7: result += rest continue elif int(xs[i]) < 4: return ...
1Python2
{ "input": [ "4 7\n", "7 4\n", "7 1000\n", "7 5032\n", "7 980\n", "777477774 1\n", "77 47\n", "777777 2\n", "7 985\n", "7 127\n", "7479 58884598\n", "49 1000000000\n", "10 1\n", "47 8547744\n", "7 5040\n", "64 87\n", "4 25\n", "7 2048\n", "27...
2CODEFORCES
121_C. Lucky Permutation_2128
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; int res; int a[100], ins[100]; int IsLucky(int x) { for (; x; x /= 10) if (x % 10 != 4 && x % 10 != 7) return 0; return 1; } void Dfs(int now, int lim) { res++; if ((long long)now * 10 + 4 <= lim) Dfs(now * 10 + 4, lim); if ((long long)now * 10 + 7 <= lim) Dfs...
2C++
{ "input": [ "4 7\n", "7 4\n", "7 1000\n", "7 5032\n", "7 980\n", "777477774 1\n", "77 47\n", "777777 2\n", "7 985\n", "7 127\n", "7479 58884598\n", "49 1000000000\n", "10 1\n", "47 8547744\n", "7 5040\n", "64 87\n", "4 25\n", "7 2048\n", "27...
2CODEFORCES
121_C. Lucky Permutation_2129
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
def lucky(x): s=str(x) return s.count('4')+s.count('7')==len(s) def Gen_lucky(n): if(len(n)==1): if(n<"4"): return 0 if(n<"7"): return 1 return 2 s=str(n) if(s[0]<'4'): return 0 if(s[0]=='4'): return Gen_lucky(s[1:]) if(s[0]<'7...
3Python3
{ "input": [ "4 7\n", "7 4\n", "7 1000\n", "7 5032\n", "7 980\n", "777477774 1\n", "77 47\n", "777777 2\n", "7 985\n", "7 127\n", "7479 58884598\n", "49 1000000000\n", "10 1\n", "47 8547744\n", "7 5040\n", "64 87\n", "4 25\n", "7 2048\n", "27...
2CODEFORCES
121_C. Lucky Permutation_2130
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.List; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.util.Collections; import java.io.InputStreamReader; import java.util.ArrayList;...
4JAVA
{ "input": [ "4 7\n", "7 4\n", "7 1000\n", "7 5032\n", "7 980\n", "777477774 1\n", "77 47\n", "777777 2\n", "7 985\n", "7 127\n", "7479 58884598\n", "49 1000000000\n", "10 1\n", "47 8547744\n", "7 5040\n", "64 87\n", "4 25\n", "7 2048\n", "27...
2CODEFORCES
1244_G. Running in Pairs_2131
Demonstrative competitions will be held in the run-up to the 20NN Berlatov Olympic Games. Today is the day for the running competition! Berlatov team consists of 2n runners which are placed on two running tracks; n runners are placed on each track. The runners are numbered from 1 to n on each track. The runner with nu...
rr = raw_input rri = lambda: int(rr()) rrm = lambda: map(int, rr().split()) def solve(N, K): A = range(1, N+1) cur = N * (N+1) / 2 if K < cur: return [[-1]] for fixed in range(N / 2): if K - cur >= N - 1 - 2 * fixed: A[~fixed], A[fixed] = A[fixed], A[~fixed] cur += N - ...
1Python2
{ "input": [ "10 54\n", "3 9\n", "5 20\n", "10 81\n", "3 1\n", "500 125251\n", "50 1274\n", "10000 75005000\n", "2 1\n", "50 1901\n", "500000 125000249999\n", "1 1\n", "3 6\n", "3 7\n", "50 1275\n", "100000 5000049999\n", "10000 74621728\n", "100...
2CODEFORCES
1244_G. Running in Pairs_2132
Demonstrative competitions will be held in the run-up to the 20NN Berlatov Olympic Games. Today is the day for the running competition! Berlatov team consists of 2n runners which are placed on two running tracks; n runners are placed on each track. The runners are numbered from 1 to n on each track. The runner with nu...
#include <bits/stdc++.h> using namespace std; long long n, a[1000005], add[1000005]; long long k; bool used[1000005]; int main() { scanf("%lld%lld", &n, &k); long long sum = n * (n + 1) / 2; if (sum > k) { cout << -1 << endl; return 0; } for (int i = 1; i <= n; i++) a[i] = i; for (int i = 1; i <= n ...
2C++
{ "input": [ "10 54\n", "3 9\n", "5 20\n", "10 81\n", "3 1\n", "500 125251\n", "50 1274\n", "10000 75005000\n", "2 1\n", "50 1901\n", "500000 125000249999\n", "1 1\n", "3 6\n", "3 7\n", "50 1275\n", "100000 5000049999\n", "10000 74621728\n", "100...
2CODEFORCES
1244_G. Running in Pairs_2133
Demonstrative competitions will be held in the run-up to the 20NN Berlatov Olympic Games. Today is the day for the running competition! Berlatov team consists of 2n runners which are placed on two running tracks; n runners are placed on each track. The runners are numbered from 1 to n on each track. The runner with nu...
n, t = [int(i) for i in input().split()] import os def tr(qq): return (qq*(qq+1))//2 if t < tr(n): print(-1) exit() upp = 2 * (tr(n) - tr(n//2)) if n % 2 == 1: upp -= (n+1)//2 if t >= upp: # print(upp) # exit() os.write(1, (str(upp) + '\n').encode()) ans = list(range(1, n+1)) # p...
3Python3
{ "input": [ "10 54\n", "3 9\n", "5 20\n", "10 81\n", "3 1\n", "500 125251\n", "50 1274\n", "10000 75005000\n", "2 1\n", "50 1901\n", "500000 125000249999\n", "1 1\n", "3 6\n", "3 7\n", "50 1275\n", "100000 5000049999\n", "10000 74621728\n", "100...
2CODEFORCES
1244_G. Running in Pairs_2134
Demonstrative competitions will be held in the run-up to the 20NN Berlatov Olympic Games. Today is the day for the running competition! Berlatov team consists of 2n runners which are placed on two running tracks; n runners are placed on each track. The runners are numbered from 1 to n on each track. The runner with nu...
/** * ******* Created on 14/10/19 3:04 PM******* */ import java.io.*; import java.util.*; public class G1244 implements Runnable { public static final int MAX = (int) (1e6+5); int[] a = new int[MAX]; int[] b = new int[MAX]; private void solve() throws IOException { long n = reader.nextLong...
4JAVA
{ "input": [ "10 54\n", "3 9\n", "5 20\n", "10 81\n", "3 1\n", "500 125251\n", "50 1274\n", "10000 75005000\n", "2 1\n", "50 1901\n", "500000 125000249999\n", "1 1\n", "3 6\n", "3 7\n", "50 1275\n", "100000 5000049999\n", "10000 74621728\n", "100...
2CODEFORCES
1264_D2. Beautiful Bracket Sequence (hard version)_2135
This is the hard version of this problem. The only difference is the limit of n - the length of the input string. In this version, 1 ≤ n ≤ 10^6. Let's define a correct bracket sequence and its depth as follow: * An empty string is a correct bracket sequence with depth 0. * If "s" is a correct bracket sequence wi...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10, mod = 998244353; const long long inf = 1e18; int fac[maxn], ifac[maxn], sm1[maxn], sm2[maxn]; int Pow(int a, int b) { int ans = 1; for (; b; b >>= 1, a = 1ll * a * a % mod) if (b & 1) ans = 1ll * ans * a % mod; return ans; } int C(int n,...
2C++
{ "input": [ "(?(?))\n", "??\n", ")))\n", "(?(??)))(()?(???)(?((?(?()))(())?))?(?)))?)?)))?)?()())??)?()?)??))?(()??)?()))()(???)())?(??)))((?())()(?\n", "???)\n", "(((\n", ")?)??)?)))??)???))?))?)?))))))?)????)??)?????)????))))???)?)??)??)??)))????)?)))))????)???)??)??))?)?))?)?\n", "...
2CODEFORCES
1264_D2. Beautiful Bracket Sequence (hard version)_2136
This is the hard version of this problem. The only difference is the limit of n - the length of the input string. In this version, 1 ≤ n ≤ 10^6. Let's define a correct bracket sequence and its depth as follow: * An empty string is a correct bracket sequence with depth 0. * If "s" is a correct bracket sequence wi...
import java.io.*; import java.util.*; public class CF1264D2 { static long MOD=998244353; public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String str=br.readLine(); int len=str.length(); if(len==1){ ...
4JAVA
{ "input": [ "(?(?))\n", "??\n", ")))\n", "(?(??)))(()?(???)(?((?(?()))(())?))?(?)))?)?)))?)?()())??)?()?)??))?(()??)?()))()(???)())?(??)))((?())()(?\n", "???)\n", "(((\n", ")?)??)?)))??)???))?))?)?))))))?)????)??)?????)????))))???)?)??)??)??)))????)?)))))????)???)??)??))?)?))?)?\n", "...
2CODEFORCES
1286_A. Garland_2137
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland....
n = int(raw_input()) a = map(int, raw_input().split()) e = n / 2 o = n - n / 2 dp = [[200] * (o + 1), [200] * (o + 1)] dp[0][0] = dp[1][0] = 0 for i, x in enumerate(a): ndp = [[200] * (o + 1), [200] * (o + 1)] for j in xrange(2): if x and x % 2 != j: continue for k in xrange(2): ...
1Python2
{ "input": [ "7\n1 0 0 5 0 0 2\n", "5\n0 5 0 2 3\n", "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 48 69 63 77 67 28 7 23 97 99 20 42 50 43 27 81 18 76 87 79 52 37 29 24 65 85 83 68 25 10 45 75 33 15 66 71 6 21 64 47 22 8 39 57 4 1 19 35 12 34 13 9 53 40 62 94 44 ...
2CODEFORCES
1286_A. Garland_2138
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland....
#include <bits/stdc++.h> using namespace std; const int maxN = 101; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } int dp[maxN][maxN][2]; memset(dp, 0x3f, sizeof(dp)); dp[0][0][0] = 0; dp[0][0][1] = 0; fo...
2C++
{ "input": [ "7\n1 0 0 5 0 0 2\n", "5\n0 5 0 2 3\n", "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 48 69 63 77 67 28 7 23 97 99 20 42 50 43 27 81 18 76 87 79 52 37 29 24 65 85 83 68 25 10 45 75 33 15 66 71 6 21 64 47 22 8 39 57 4 1 19 35 12 34 13 9 53 40 62 94 44 ...
2CODEFORCES
1286_A. Garland_2139
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland....
def ip(): n=int(input()) a=list(map(int,input().split())) rem=set([i for i in range(1,n+1)])-set(a) if n==1: return 0 o=e=0 for i in rem: if i%2==0: e+=1 else: o+=1 ct=0 i=0 while i<len(a) and a[i]==0: i+=1 if i==len(a): ...
3Python3
{ "input": [ "7\n1 0 0 5 0 0 2\n", "5\n0 5 0 2 3\n", "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 48 69 63 77 67 28 7 23 97 99 20 42 50 43 27 81 18 76 87 79 52 37 29 24 65 85 83 68 25 10 45 75 33 15 66 71 6 21 64 47 22 8 39 57 4 1 19 35 12 34 13 9 53 40 62 94 44 ...
2CODEFORCES
1286_A. Garland_2140
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland....
import java.io.*; import java.util.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class cf1286a { public static void main(String[] args) throws IOException { int n = ri(), p[] = ria(n), last[] = new int[n], cnt[] = new int[2]; last[0] = -1; for(int i = 1; i < ...
4JAVA
{ "input": [ "7\n1 0 0 5 0 0 2\n", "5\n0 5 0 2 3\n", "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 48 69 63 77 67 28 7 23 97 99 20 42 50 43 27 81 18 76 87 79 52 37 29 24 65 85 83 68 25 10 45 75 33 15 66 71 6 21 64 47 22 8 39 57 4 1 19 35 12 34 13 9 53 40 62 94 44 ...
2CODEFORCES
1305_B. Kuroni and Simple Strings_2141
Now that Kuroni has reached 10 years old, he is a big boy and doesn't like arrays of integers as presents anymore. This year he wants a Bracket sequence as a Birthday present. More specifically, he wants a bracket sequence so complex that no matter how hard he tries, he will not be able to remove a simple subsequence! ...
a = raw_input() re = [] l = len(a) b = '(' b = b+a+')' count1,count2 = 1,l while count1 < count2: while True: if b[count1] == '(': re.append(count1) count1+=1 break if count1>=count2: break if count1 == l+1: break count1+=1 ...
1Python2
{ "input": [ "(()((\n", "(()())\n", ")(\n", "()()()()()()()(\n", "()\n", "())((\n", "))()((\n", "(())(\n", ")))(((\n", "(()()(\n", "()))((\n", "()(()(\n", "((()()))()()()(\n", "()(((\n", "(())))\n", "()()()()))()(((\n", "()()()())(()(((\n", ")())...
2CODEFORCES
1305_B. Kuroni and Simple Strings_2142
Now that Kuroni has reached 10 years old, he is a big boy and doesn't like arrays of integers as presents anymore. This year he wants a Bracket sequence as a Birthday present. More specifically, he wants a bracket sequence so complex that no matter how hard he tries, he will not be able to remove a simple subsequence! ...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; vector<int> a, b; int i = 0, j = s.size() - 1; while (i < j) { while (i < s.size() && s[i] == ')') i++; while (j >= 0 && s[j] == '(') j--; if (i < s.size() && j >= 0 && i < j) { a.push_back(i + 1); b.push_ba...
2C++
{ "input": [ "(()((\n", "(()())\n", ")(\n", "()()()()()()()(\n", "()\n", "())((\n", "))()((\n", "(())(\n", ")))(((\n", "(()()(\n", "()))((\n", "()(()(\n", "((()()))()()()(\n", "()(((\n", "(())))\n", "()()()()))()(((\n", "()()()())(()(((\n", ")())...
2CODEFORCES
1305_B. Kuroni and Simple Strings_2143
Now that Kuroni has reached 10 years old, he is a big boy and doesn't like arrays of integers as presents anymore. This year he wants a Bracket sequence as a Birthday present. More specifically, he wants a bracket sequence so complex that no matter how hard he tries, he will not be able to remove a simple subsequence! ...
s = input() to_ans = [False for _ in range(len(s))] def solve(s, left, right): #right inclusive if left >= right: return while left <= right and s[left] == ")": left += 1 while right >= left and s[right] == "(": right -= 1 if left >= right: return else: to_ans[left] = True to_ans[right] = True solve...
3Python3
{ "input": [ "(()((\n", "(()())\n", ")(\n", "()()()()()()()(\n", "()\n", "())((\n", "))()((\n", "(())(\n", ")))(((\n", "(()()(\n", "()))((\n", "()(()(\n", "((()()))()()()(\n", "()(((\n", "(())))\n", "()()()()))()(((\n", "()()()())(()(((\n", ")())...
2CODEFORCES
1305_B. Kuroni and Simple Strings_2144
Now that Kuroni has reached 10 years old, he is a big boy and doesn't like arrays of integers as presents anymore. This year he wants a Bracket sequence as a Birthday present. More specifically, he wants a bracket sequence so complex that no matter how hard he tries, he will not be able to remove a simple subsequence! ...
/* Aman Agarwal algo.java */ import java.util.*; import java.io.*; public class B1305 { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); ...
4JAVA
{ "input": [ "(()((\n", "(()())\n", ")(\n", "()()()()()()()(\n", "()\n", "())((\n", "))()((\n", "(())(\n", ")))(((\n", "(()()(\n", "()))((\n", "()(()(\n", "((()()))()()()(\n", "()(((\n", "(())))\n", "()()()()))()(((\n", "()()()())(()(((\n", ")())...
2CODEFORCES
1329_D. Dreamoon Likes Strings_2145
Dreamoon likes strings. Today he created a game about strings: String s_1, s_2, …, s_n is beautiful if and only if for each 1 ≤ i < n, s_i ≠ s_{i+1}. Initially, Dreamoon has a string a. In each step Dreamoon can choose a beautiful substring of a and remove it. Then he should concatenate the remaining characters (in t...
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e6 + 100; const long long inf = 0x3f3f3f3f; const long long iinf = 1 << 30; const long long linf = 2e18; const long long mod = 998244353; const double eps = 1e-7; template <class T = long long> T chmin(T &a, T b) { return a = min(a, b); } template ...
2C++
{ "input": [ "4\naabbcc\naaabbb\naaa\nabacad\n", "4\naabbcc\naaabbb\naaa\nabacad\n", "4\naabbcc\naa`bbb\naaa\nabacad\n", "4\naabbcc\naaabbb\naaa\nabaacd\n", "4\nababcc\nbbbaaa\naaa\nabaacd\n", "4\naabbbc\naaabbb\naaa\nabacad\n", "4\naacbcc\naaabbb\naaa\nabacad\n", "4\naabbbc\naa`bbb\na...
2CODEFORCES
1329_D. Dreamoon Likes Strings_2146
Dreamoon likes strings. Today he created a game about strings: String s_1, s_2, …, s_n is beautiful if and only if for each 1 ≤ i < n, s_i ≠ s_{i+1}. Initially, Dreamoon has a string a. In each step Dreamoon can choose a beautiful substring of a and remove it. Then he should concatenate the remaining characters (in t...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintStream; import java.io.IOException; import java.util.TreeSet; import java.util.ArrayList; import java.io.UncheckedIOException; import java.util.List; import java.io.Closeable; import jav...
4JAVA
{ "input": [ "4\naabbcc\naaabbb\naaa\nabacad\n", "4\naabbcc\naaabbb\naaa\nabacad\n", "4\naabbcc\naa`bbb\naaa\nabacad\n", "4\naabbcc\naaabbb\naaa\nabaacd\n", "4\nababcc\nbbbaaa\naaa\nabaacd\n", "4\naabbbc\naaabbb\naaa\nabacad\n", "4\naacbcc\naaabbb\naaa\nabacad\n", "4\naabbbc\naa`bbb\na...
2CODEFORCES
1349_D. Slime and Biscuits_2147
Slime and his n friends are at a party. Slime has designed a game for his friends to play. At the beginning of the game, the i-th player has a_i biscuits. At each second, Slime will choose a biscuit randomly uniformly among all a_1 + a_2 + … + a_n biscuits, and the owner of this biscuit will give it to a random unifor...
#include <bits/stdc++.h> using namespace std; namespace FGF { int n, m, ans; const int N = 3e5 + 5, mo = 998244353; int a[N], f[N], inv[N]; void work() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]), m += a[i]; inv[1] = 1; for (int i = 2; i <= m; i++) inv[i] = 1ll * inv[mo % i] * (mo - mo / ...
2C++
{ "input": [ "2\n1 2\n", "5\n8 4 2 0 1\n", "2\n1 1\n", "5\n0 0 0 0 35\n", "36\n110 7 51 3 36 69 30 7 122 22 11 96 98 17 133 44 38 75 7 10 4 3 68 50 43 25 4 29 42 36 11 7 36 12 75 1\n", "10\n7758 19921 15137 1138 90104 17467 82544 55151 3999 6781\n", "100\n4364 698 1003 1128 1513 39 4339 96...
2CODEFORCES
1349_D. Slime and Biscuits_2148
Slime and his n friends are at a party. Slime has designed a game for his friends to play. At the beginning of the game, the i-th player has a_i biscuits. At each second, Slime will choose a biscuit randomly uniformly among all a_1 + a_2 + … + a_n biscuits, and the owner of this biscuit will give it to a random unifor...
import os import sys input = sys.stdin.buffer.readline #sys.setrecursionlimit(int(2e5)) from collections import deque import math # list(map(int, input().split())) ##################################################################################### class CF(object): def __init__(self): self.mod = 998244...
3Python3
{ "input": [ "2\n1 2\n", "5\n8 4 2 0 1\n", "2\n1 1\n", "5\n0 0 0 0 35\n", "36\n110 7 51 3 36 69 30 7 122 22 11 96 98 17 133 44 38 75 7 10 4 3 68 50 43 25 4 29 42 36 11 7 36 12 75 1\n", "10\n7758 19921 15137 1138 90104 17467 82544 55151 3999 6781\n", "100\n4364 698 1003 1128 1513 39 4339 96...
2CODEFORCES
1349_D. Slime and Biscuits_2149
Slime and his n friends are at a party. Slime has designed a game for his friends to play. At the beginning of the game, the i-th player has a_i biscuits. At each second, Slime will choose a biscuit randomly uniformly among all a_1 + a_2 + … + a_n biscuits, and the owner of this biscuit will give it to a random unifor...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigDecimal; import java.math.BigInteger; import java.math.MathContext; import java.math.RoundingMode; import java.text.DecimalFormat; import java.util.Ar...
4JAVA
{ "input": [ "2\n1 2\n", "5\n8 4 2 0 1\n", "2\n1 1\n", "5\n0 0 0 0 35\n", "36\n110 7 51 3 36 69 30 7 122 22 11 96 98 17 133 44 38 75 7 10 4 3 68 50 43 25 4 29 42 36 11 7 36 12 75 1\n", "10\n7758 19921 15137 1138 90104 17467 82544 55151 3999 6781\n", "100\n4364 698 1003 1128 1513 39 4339 96...
2CODEFORCES
136_B. Ternary Logic_2150
Little Petya very much likes computers. Recently he has received a new "Ternatron IV" as a gift from his mother. Unlike other modern computers, "Ternatron IV" operates with ternary and not binary logic. Petya immediately wondered how the xor operation is performed on this computer (and whether there is anything like it...
import sys #sys.stdin = open("input.txt", "r") def calc(a): digit = [0] * 40 i = 0 while a > 0: digit[i] = a % 3 a /= 3 i += 1 return digit, i def fprint(a): l = len(a) for i in range(l): print a[i], print a, c = raw_input().split() a = int(a) c = i...
1Python2
{ "input": [ "387420489 225159023\n", "14 34\n", "50 34\n", "5 5\n", "976954722 548418041\n", "4232 755480607\n", "640735701 335933492\n", "5341 813849430\n", "23476 23875625\n", "47229813 6200\n", "657244587 28654748\n", "278014879 3453211\n", "5849 7211\n", "4...
2CODEFORCES
136_B. Ternary Logic_2151
Little Petya very much likes computers. Recently he has received a new "Ternatron IV" as a gift from his mother. Unlike other modern computers, "Ternatron IV" operates with ternary and not binary logic. Petya immediately wondered how the xor operation is performed on this computer (and whether there is anything like it...
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; int ans = 0; int t = 1; while (a || b) { int x = a % 3; int y = b % 3; int z = (y - x + 3) % 3; ans += z * t; t *= 3; a /= 3, b /= 3; } cout << ans << endl; }
2C++
{ "input": [ "387420489 225159023\n", "14 34\n", "50 34\n", "5 5\n", "976954722 548418041\n", "4232 755480607\n", "640735701 335933492\n", "5341 813849430\n", "23476 23875625\n", "47229813 6200\n", "657244587 28654748\n", "278014879 3453211\n", "5849 7211\n", "4...
2CODEFORCES
136_B. Ternary Logic_2152
Little Petya very much likes computers. Recently he has received a new "Ternatron IV" as a gift from his mother. Unlike other modern computers, "Ternatron IV" operates with ternary and not binary logic. Petya immediately wondered how the xor operation is performed on this computer (and whether there is anything like it...
def untor(a, c): res = '' while a or c: a, ma = divmod(a, 3) c, mc = divmod(c, 3) x = 0 while (ma + x)%3 != mc: x += 1 res = str(x) + res try: return int(res, 3) except Exception as e: return 0 a, c = map(int, input().split()) print(un...
3Python3
{ "input": [ "387420489 225159023\n", "14 34\n", "50 34\n", "5 5\n", "976954722 548418041\n", "4232 755480607\n", "640735701 335933492\n", "5341 813849430\n", "23476 23875625\n", "47229813 6200\n", "657244587 28654748\n", "278014879 3453211\n", "5849 7211\n", "4...
2CODEFORCES
136_B. Ternary Logic_2153
Little Petya very much likes computers. Recently he has received a new "Ternatron IV" as a gift from his mother. Unlike other modern computers, "Ternatron IV" operates with ternary and not binary logic. Petya immediately wondered how the xor operation is performed on this computer (and whether there is anything like it...
import java.util.Scanner; public class B136 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int A = in.nextInt(); int C = in.nextInt(); int B = 0; int power = 1; while (A != 0 || C != 0) { int b = (3 + C%3 - A%3)%3; ...
4JAVA
{ "input": [ "387420489 225159023\n", "14 34\n", "50 34\n", "5 5\n", "976954722 548418041\n", "4232 755480607\n", "640735701 335933492\n", "5341 813849430\n", "23476 23875625\n", "47229813 6200\n", "657244587 28654748\n", "278014879 3453211\n", "5849 7211\n", "4...
2CODEFORCES
1392_B. Omkar and Infinity Clock_2154
Being stuck at home, Ray became extremely bored. To pass time, he asks Lord Omkar to use his time bending power: Infinity Clock! However, Lord Omkar will only listen to mortals who can solve the following problem: You are given an array a of n integers. You are also given an integer k. Lord Omkar wants you to do k ope...
#!/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 def main(): for _ in range(int(input())): n,...
1Python2
{ "input": [ "3\n2 1\n-199 192\n5 19\n5 -1 4 2 0\n1 2\n69\n", "1\n2 1\n-2 -3\n", "3\n1 1\n1\n5 4\n5 -1 4 2 0\n1 2\n69\n", "1\n5 1\n-5 -4 -3 -2 -1\n", "1\n2 1\n-6 -9\n", "1\n1 398708496844866113\n959414461\n", "1\n2 1\n-5 -4\n", "2\n3 1\n-1 -2 0\n3 2\n-1 -2 0\n", "1\n5 1\n-1 -2 -3 -...
2CODEFORCES
1392_B. Omkar and Infinity Clock_2155
Being stuck at home, Ray became extremely bored. To pass time, he asks Lord Omkar to use his time bending power: Infinity Clock! However, Lord Omkar will only listen to mortals who can solve the following problem: You are given an array a of n integers. You are also given an integer k. Lord Omkar wants you to do k ope...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t, i, n, k; cin >> t; while (t--) { cin >> n >> k; long long a[n], maxa; for (i = 0; i < n; i++) { cin >> a[i]; } if (k % 2 != 0) { maxa = a[0...
2C++
{ "input": [ "3\n2 1\n-199 192\n5 19\n5 -1 4 2 0\n1 2\n69\n", "1\n2 1\n-2 -3\n", "3\n1 1\n1\n5 4\n5 -1 4 2 0\n1 2\n69\n", "1\n5 1\n-5 -4 -3 -2 -1\n", "1\n2 1\n-6 -9\n", "1\n1 398708496844866113\n959414461\n", "1\n2 1\n-5 -4\n", "2\n3 1\n-1 -2 0\n3 2\n-1 -2 0\n", "1\n5 1\n-1 -2 -3 -...
2CODEFORCES
1392_B. Omkar and Infinity Clock_2156
Being stuck at home, Ray became extremely bored. To pass time, he asks Lord Omkar to use his time bending power: Infinity Clock! However, Lord Omkar will only listen to mortals who can solve the following problem: You are given an array a of n integers. You are also given an integer k. Lord Omkar wants you to do k ope...
t=int(input()) for i in range(t): n,k=map(int,input().split()) ar=list(map(int,input().split())) m=max(ar) new=[] for i in range(n): new.append(m-ar[i]) if k%2==0: mx=max(new) for j in range(n): new[j]=mx-new[j] print(*new)
3Python3
{ "input": [ "3\n2 1\n-199 192\n5 19\n5 -1 4 2 0\n1 2\n69\n", "1\n2 1\n-2 -3\n", "3\n1 1\n1\n5 4\n5 -1 4 2 0\n1 2\n69\n", "1\n5 1\n-5 -4 -3 -2 -1\n", "1\n2 1\n-6 -9\n", "1\n1 398708496844866113\n959414461\n", "1\n2 1\n-5 -4\n", "2\n3 1\n-1 -2 0\n3 2\n-1 -2 0\n", "1\n5 1\n-1 -2 -3 -...
2CODEFORCES
1392_B. Omkar and Infinity Clock_2157
Being stuck at home, Ray became extremely bored. To pass time, he asks Lord Omkar to use his time bending power: Infinity Clock! However, Lord Omkar will only listen to mortals who can solve the following problem: You are given an array a of n integers. You are also given an integer k. Lord Omkar wants you to do k ope...
import java.util.*; public class Main { static void find(long a[]){ long max=a[0]; for (long i:a)max=Math.max(i,max); for (long i=0;i<a.length;i++)a[(int)i]=max-a[(int)i]; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); long T = sc.next...
4JAVA
{ "input": [ "3\n2 1\n-199 192\n5 19\n5 -1 4 2 0\n1 2\n69\n", "1\n2 1\n-2 -3\n", "3\n1 1\n1\n5 4\n5 -1 4 2 0\n1 2\n69\n", "1\n5 1\n-5 -4 -3 -2 -1\n", "1\n2 1\n-6 -9\n", "1\n1 398708496844866113\n959414461\n", "1\n2 1\n-5 -4\n", "2\n3 1\n-1 -2 0\n3 2\n-1 -2 0\n", "1\n5 1\n-1 -2 -3 -...
2CODEFORCES
1416_D. Graph and Queries_2158
You are given an undirected graph consisting of n vertices and m edges. Initially there is a single integer written on every vertex: the vertex i has p_i written on it. All p_i are distinct integers from 1 to n. You have to process q queries of two types: * 1 v — among all vertices reachable from the vertex v using...
#include <bits/stdc++.h> using namespace std; int val[200005]; pair<int, int> e[300005]; bool del[300005]; int qT[500005], qV[500005]; int color[200005]; inline int repr(int x) { return color[x] == x ? x : (color[x] = repr(color[x])); } vector<int> f[200005]; pair<int, int> op[500005]; inline void join(int x, int y, ...
2C++
{ "input": [ "5 4 6\n1 2 5 4 3\n1 2\n2 3\n1 3\n4 5\n1 1\n2 1\n2 3\n1 1\n1 2\n1 2\n", "9 5 14\n7 1 4 8 5 2 6 9 3\n2 8\n1 6\n5 7\n1 3\n3 9\n1 5\n1 8\n1 5\n1 4\n1 8\n1 3\n1 5\n1 5\n1 7\n1 7\n2 3\n1 2\n1 1\n1 2\n", "6 5 8\n1 2 6 3 4 5\n2 4\n1 3\n1 6\n3 5\n2 5\n1 1\n1 4\n1 1\n2 1\n2 5\n2 2\n2 3\n1 4\n", "2...
2CODEFORCES
1416_D. Graph and Queries_2159
You are given an undirected graph consisting of n vertices and m edges. Initially there is a single integer written on every vertex: the vertex i has p_i written on it. All p_i are distinct integers from 1 to n. You have to process q queries of two types: * 1 v — among all vertices reachable from the vertex v using...
//package round673; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class D { InputStream is; PrintWriter out; String INPUT = ""; void solve() { int n = ni(), m = n...
4JAVA
{ "input": [ "5 4 6\n1 2 5 4 3\n1 2\n2 3\n1 3\n4 5\n1 1\n2 1\n2 3\n1 1\n1 2\n1 2\n", "9 5 14\n7 1 4 8 5 2 6 9 3\n2 8\n1 6\n5 7\n1 3\n3 9\n1 5\n1 8\n1 5\n1 4\n1 8\n1 3\n1 5\n1 5\n1 7\n1 7\n2 3\n1 2\n1 1\n1 2\n", "6 5 8\n1 2 6 3 4 5\n2 4\n1 3\n1 6\n3 5\n2 5\n1 1\n1 4\n1 1\n2 1\n2 5\n2 2\n2 3\n1 4\n", "2...
2CODEFORCES
1433_C. Dominant Piranha_2160
There are n piranhas with sizes a_1, a_2, …, a_n in the aquarium. Piranhas are numbered from left to right in order they live in the aquarium. Scientists of the Berland State University want to find if there is dominant piranha in the aquarium. The piranha is called dominant if it can eat all the other piranhas in the...
from __future__ import division, print_function # import threading # threading.stack_size(2**27) import sys sys.setrecursionlimit(10**4) # sys.stdin = open('inpy.txt', 'r') # sys.stdout = open('outpy.txt', 'w') from sys import stdin, stdout import bisect #c++ upperbound import math import heapq i_m=922337203...
1Python2
{ "input": [ "6\n5\n5 3 4 4 5\n3\n1 1 1\n5\n4 4 3 4 4\n5\n5 5 4 3 2\n3\n1 1 2\n5\n5 4 3 5 5\n", "1\n3\n5 3 4\n", "6\n5\n5 3 4 4 5\n3\n1 1 1\n5\n4 4 3 4 4\n5\n5 5 4 3 2\n3\n1 1 2\n5\n5 4 3 5 5\n", "1\n3\n10 1 5\n", "6\n5\n5 3 4 4 5\n3\n1 1 1\n5\n4 4 3 4 4\n5\n5 7 4 3 2\n3\n1 1 2\n5\n5 4 3 5 5\n", ...
2CODEFORCES
1433_C. Dominant Piranha_2161
There are n piranhas with sizes a_1, a_2, …, a_n in the aquarium. Piranhas are numbered from left to right in order they live in the aquarium. Scientists of the Berland State University want to find if there is dominant piranha in the aquarium. The piranha is called dominant if it can eat all the other piranhas in the...
#include <bits/stdc++.h> using namespace std; const int mod = 1e8 + 7; const int N = 3e5 + 10; int vis[N]; int main() { int num; scanf("%d", &num); int n, m; while (num--) { scanf("%d", &n); int maxx = 0; for (int i = 0; i < n; i++) { scanf("%d", &vis[i]); maxx = max(vis[i], maxx); }...
2C++
{ "input": [ "6\n5\n5 3 4 4 5\n3\n1 1 1\n5\n4 4 3 4 4\n5\n5 5 4 3 2\n3\n1 1 2\n5\n5 4 3 5 5\n", "1\n3\n5 3 4\n", "6\n5\n5 3 4 4 5\n3\n1 1 1\n5\n4 4 3 4 4\n5\n5 5 4 3 2\n3\n1 1 2\n5\n5 4 3 5 5\n", "1\n3\n10 1 5\n", "6\n5\n5 3 4 4 5\n3\n1 1 1\n5\n4 4 3 4 4\n5\n5 7 4 3 2\n3\n1 1 2\n5\n5 4 3 5 5\n", ...
2CODEFORCES
1433_C. Dominant Piranha_2162
There are n piranhas with sizes a_1, a_2, …, a_n in the aquarium. Piranhas are numbered from left to right in order they live in the aquarium. Scientists of the Berland State University want to find if there is dominant piranha in the aquarium. The piranha is called dominant if it can eat all the other piranhas in the...
for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) if len(set(l))==1: print(-1) else: m=max(l) for i in range(n): if i>0: if i<n-1: if l[i]==m and (l[i-1]<m or l[i+1]<m): print(i+1) break else: if l[i]==m and l[i-1]<m: print(i+1) break ...
3Python3
{ "input": [ "6\n5\n5 3 4 4 5\n3\n1 1 1\n5\n4 4 3 4 4\n5\n5 5 4 3 2\n3\n1 1 2\n5\n5 4 3 5 5\n", "1\n3\n5 3 4\n", "6\n5\n5 3 4 4 5\n3\n1 1 1\n5\n4 4 3 4 4\n5\n5 5 4 3 2\n3\n1 1 2\n5\n5 4 3 5 5\n", "1\n3\n10 1 5\n", "6\n5\n5 3 4 4 5\n3\n1 1 1\n5\n4 4 3 4 4\n5\n5 7 4 3 2\n3\n1 1 2\n5\n5 4 3 5 5\n", ...
2CODEFORCES
1433_C. Dominant Piranha_2163
There are n piranhas with sizes a_1, a_2, …, a_n in the aquarium. Piranhas are numbered from left to right in order they live in the aquarium. Scientists of the Berland State University want to find if there is dominant piranha in the aquarium. The piranha is called dominant if it can eat all the other piranhas in the...
import java.io.*; import java.util.*; public class Main{ static int mod=(int)1e9+7; public static void main(String[] args) throws IOException { Writer out=new Writer(System.out); Reader in=new Reader(System.in); int ts=in.nextInt(); outer: while(ts-->0) { int n=in.nextInt(); int a[]=in.readArra...
4JAVA
{ "input": [ "6\n5\n5 3 4 4 5\n3\n1 1 1\n5\n4 4 3 4 4\n5\n5 5 4 3 2\n3\n1 1 2\n5\n5 4 3 5 5\n", "1\n3\n5 3 4\n", "6\n5\n5 3 4 4 5\n3\n1 1 1\n5\n4 4 3 4 4\n5\n5 5 4 3 2\n3\n1 1 2\n5\n5 4 3 5 5\n", "1\n3\n10 1 5\n", "6\n5\n5 3 4 4 5\n3\n1 1 1\n5\n4 4 3 4 4\n5\n5 7 4 3 2\n3\n1 1 2\n5\n5 4 3 5 5\n", ...
2CODEFORCES
1458_B. Glass Half Spilled_2164
There are n glasses on the table numbered 1, …, n. The glass i can hold up to a_i units of water, and currently contains b_i units of water. You would like to choose k glasses and collect as much water in them as possible. To that effect you can pour water from one glass to another as many times as you like. However, ...
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const int N=102; int a[N],b[N]; int dp[N][N*N][N]; // step, volume, k, max water int n; int watersum,volumesum; int main(){ cin.tie(0);cin.sync_with_stdio(0); cin>>n; for(int i=0;i<n;++i)cin>>a[i...
2C++
{ "input": [ "3\n6 5\n6 5\n10 2\n", "100\n1 0\n1 0\n1 0\n1 0\n1 0\n1 1\n1 0\n1 0\n1 0\n1 1\n1 0\n1 0\n1 0\n1 0\n1 0\n1 0\n1 0\n1 0\n1 1\n1 0\n1 0\n1 0\n1 0\n1 1\n1 0\n1 1\n1 0\n1 1\n1 1\n1 0\n1 0\n1 0\n1 1\n1 0\n1 0\n1 0\n1 1\n1 1\n1 0\n1 1\n1 0\n1 1\n1 1\n1 0\n1 0\n1 0\n1 0\n1 1\n1 0\n1 0\n1 0\n1 0\n1 1\n1 0...
2CODEFORCES
1458_B. Glass Half Spilled_2165
There are n glasses on the table numbered 1, …, n. The glass i can hold up to a_i units of water, and currently contains b_i units of water. You would like to choose k glasses and collect as much water in them as possible. To that effect you can pour water from one glass to another as many times as you like. However, ...
n=int(input()) dp=[[-10**8]*(10002) for _ in range(n+1)] dp[0][0]=0 total=0 for i in range(n): a,b=map(int,input().split()) total+=b for k in range(n-1,-1,-1): for c in range(10001-a,-1,-1): dp[k+1][c+a]=max(dp[k+1][c+a],dp[k][c]+b) ans = [0 for i in range(n+1)] for j in range(1,n+1): ...
3Python3
{ "input": [ "3\n6 5\n6 5\n10 2\n", "100\n1 0\n1 0\n1 0\n1 0\n1 0\n1 1\n1 0\n1 0\n1 0\n1 1\n1 0\n1 0\n1 0\n1 0\n1 0\n1 0\n1 0\n1 0\n1 1\n1 0\n1 0\n1 0\n1 0\n1 1\n1 0\n1 1\n1 0\n1 1\n1 1\n1 0\n1 0\n1 0\n1 1\n1 0\n1 0\n1 0\n1 1\n1 1\n1 0\n1 1\n1 0\n1 1\n1 1\n1 0\n1 0\n1 0\n1 0\n1 1\n1 0\n1 0\n1 0\n1 0\n1 1\n1 0...
2CODEFORCES
1458_B. Glass Half Spilled_2166
There are n glasses on the table numbered 1, …, n. The glass i can hold up to a_i units of water, and currently contains b_i units of water. You would like to choose k glasses and collect as much water in them as possible. To that effect you can pour water from one glass to another as many times as you like. However, ...
import java.util.*; import java.io.*; //https://codeforces.com/contest/1459/problem/D public class D1459Fix{ static int[][][] dp; public static void print(int[][] a){ for(int i = 0; i < a.length; i++){ for(int j = 0; j < a[0].length; j++) System.out.printf("%9d ", a[i][j]); System.out.println(""); ...
4JAVA
{ "input": [ "3\n6 5\n6 5\n10 2\n", "100\n1 0\n1 0\n1 0\n1 0\n1 0\n1 1\n1 0\n1 0\n1 0\n1 1\n1 0\n1 0\n1 0\n1 0\n1 0\n1 0\n1 0\n1 0\n1 1\n1 0\n1 0\n1 0\n1 0\n1 1\n1 0\n1 1\n1 0\n1 1\n1 1\n1 0\n1 0\n1 0\n1 1\n1 0\n1 0\n1 0\n1 1\n1 1\n1 0\n1 1\n1 0\n1 1\n1 1\n1 0\n1 0\n1 0\n1 0\n1 1\n1 0\n1 0\n1 0\n1 0\n1 1\n1 0...
2CODEFORCES
1481_B. New Colony_2167
After reaching your destination, you want to build a new colony on the new planet. Since this planet has many mountains and the colony must be built on a flat surface you decided to flatten the mountains using boulders (you are still dreaming so this makes sense to you). <image> You are given an array h_1, h_2, ..., ...
import sys testing = len(sys.argv) == 4 and sys.argv[3] == "myTest" if testing: cmd = sys.stdout from time import time start_time = int(round(time() * 1000)) readAll = open(sys.argv[1], 'r').read sys.stdout = open(sys.argv[2], 'w') else: readAll = sys.stdin.read # ############ ---- I/O Functio...
1Python2
{ "input": [ "4\n4 3\n4 1 2 3\n2 7\n1 8\n4 5\n4 1 2 3\n3 1\n5 3 1\n", "14\n7 150\n11 21 25 35 45 52 62\n7 145\n11 21 31 41 51 61 71\n7 50\n2 12 22 32 42 52 62\n7 204\n11 21 21 31 41 51 61\n7 101\n11 21 31 41 51 61 71\n7 107\n11 21 31 41 51 59 69\n7 218\n11 19 29 39 49 54 64\n7 199\n58 7 24 70 5 43 69\n7 335\n...
2CODEFORCES
1481_B. New Colony_2168
After reaching your destination, you want to build a new colony on the new planet. Since this planet has many mountains and the colony must be built on a flat surface you decided to flatten the mountains using boulders (you are still dreaming so this makes sense to you). <image> You are given an array h_1, h_2, ..., ...
#include<bits/stdc++.h> #define ll long long #define ull unsigned long long ll mod=1000000007; using namespace std; void solve() { int n,k; cin>>n>>k; int a[n]; for(int i=0;i<n;i++)cin>>a[i]; int ans=-1; while(k--){ int f=0; for(int i=0;i<n-1;i++){ if(a[i]<a[i+1]){ a[i]++; f=1; ans=i+1; ...
2C++
{ "input": [ "4\n4 3\n4 1 2 3\n2 7\n1 8\n4 5\n4 1 2 3\n3 1\n5 3 1\n", "14\n7 150\n11 21 25 35 45 52 62\n7 145\n11 21 31 41 51 61 71\n7 50\n2 12 22 32 42 52 62\n7 204\n11 21 21 31 41 51 61\n7 101\n11 21 31 41 51 61 71\n7 107\n11 21 31 41 51 59 69\n7 218\n11 19 29 39 49 54 64\n7 199\n58 7 24 70 5 43 69\n7 335\n...
2CODEFORCES
1481_B. New Colony_2169
After reaching your destination, you want to build a new colony on the new planet. Since this planet has many mountains and the colony must be built on a flat surface you decided to flatten the mountains using boulders (you are still dreaming so this makes sense to you). <image> You are given an array h_1, h_2, ..., ...
import collections import string import math import copy 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 fil...
3Python3
{ "input": [ "4\n4 3\n4 1 2 3\n2 7\n1 8\n4 5\n4 1 2 3\n3 1\n5 3 1\n", "14\n7 150\n11 21 25 35 45 52 62\n7 145\n11 21 31 41 51 61 71\n7 50\n2 12 22 32 42 52 62\n7 204\n11 21 21 31 41 51 61\n7 101\n11 21 31 41 51 61 71\n7 107\n11 21 31 41 51 59 69\n7 218\n11 19 29 39 49 54 64\n7 199\n58 7 24 70 5 43 69\n7 335\n...
2CODEFORCES
1481_B. New Colony_2170
After reaching your destination, you want to build a new colony on the new planet. Since this planet has many mountains and the colony must be built on a flat surface you decided to flatten the mountains using boulders (you are still dreaming so this makes sense to you). <image> You are given an array h_1, h_2, ..., ...
import java.util.*; import java.io.*; public class Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { ...
4JAVA
{ "input": [ "4\n4 3\n4 1 2 3\n2 7\n1 8\n4 5\n4 1 2 3\n3 1\n5 3 1\n", "14\n7 150\n11 21 25 35 45 52 62\n7 145\n11 21 31 41 51 61 71\n7 50\n2 12 22 32 42 52 62\n7 204\n11 21 21 31 41 51 61\n7 101\n11 21 31 41 51 61 71\n7 107\n11 21 31 41 51 59 69\n7 218\n11 19 29 39 49 54 64\n7 199\n58 7 24 70 5 43 69\n7 335\n...
2CODEFORCES
1508_C. Complete the MST_2171
As a teacher, Riko Hakozaki often needs to help her students with problems from various subjects. Today, she is asked a programming task which goes as follows. You are given an undirected complete graph with n nodes, where some edges are pre-assigned with a positive weight while the rest aren't. You need to assign all...
#include <bits/stdc++.h> using namespace std; typedef long long ll; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 2e5 + 20; vector<int> g[N]; vector<pair<ll, pair<int, int>>> edges; ll bal, ans; bool vis[N]; set<int> unvis; int p[N], p2[N], cnt[N], sz[N]; int root(int v){ if(p...
2C++
{ "input": [ "4 4\n2 1 14\n1 4 14\n3 2 15\n4 3 8\n", "5 6\n2 3 11\n5 3 7\n1 4 10\n2 4 14\n4 3 8\n2 5 6\n", "6 6\n3 6 4\n2 4 1\n4 5 7\n3 4 10\n3 5 1\n5 2 15\n", "2 0\n", "6 8\n1 4 1\n1 5 1\n1 6 1\n2 4 1\n2 5 1\n2 6 1\n3 5 1\n3 6 1\n", "6 12\n1 3 8763000\n1 4 8763000\n1 5 8763000\n1 6 8763000\n2...
2CODEFORCES
1508_C. Complete the MST_2172
As a teacher, Riko Hakozaki often needs to help her students with problems from various subjects. Today, she is asked a programming task which goes as follows. You are given an undirected complete graph with n nodes, where some edges are pre-assigned with a positive weight while the rest aren't. You need to assign all...
def divisors(M): d=[] i=1 while M>=i**2: if M%i==0: d.append(i) if i**2!=M: d.append(M//i) i=i+1 return d def popcount(x): x = x - ((x >> 1) & 0x55555555) x = (x & 0x33333333) + ((x >> 2) & 0x33333333) x = (x + (x >> 4)) & 0x0f0f0f0f ...
3Python3
{ "input": [ "4 4\n2 1 14\n1 4 14\n3 2 15\n4 3 8\n", "5 6\n2 3 11\n5 3 7\n1 4 10\n2 4 14\n4 3 8\n2 5 6\n", "6 6\n3 6 4\n2 4 1\n4 5 7\n3 4 10\n3 5 1\n5 2 15\n", "2 0\n", "6 8\n1 4 1\n1 5 1\n1 6 1\n2 4 1\n2 5 1\n2 6 1\n3 5 1\n3 6 1\n", "6 12\n1 3 8763000\n1 4 8763000\n1 5 8763000\n1 6 8763000\n2...
2CODEFORCES
1508_C. Complete the MST_2173
As a teacher, Riko Hakozaki often needs to help her students with problems from various subjects. Today, she is asked a programming task which goes as follows. You are given an undirected complete graph with n nodes, where some edges are pre-assigned with a positive weight while the rest aren't. You need to assign all...
import java.io.*; import java.util.*; public class CF1509F extends PrintWriter { CF1509F() { super(System.out, true); } Scanner sc = new Scanner(System.in); public static void main(String[] $) { CF1509F o = new CF1509F(); o.main(); o.flush(); } int n, m, x; int[] ii, jj, ww; Integer[] hh; int[] ds; int fin...
4JAVA
{ "input": [ "4 4\n2 1 14\n1 4 14\n3 2 15\n4 3 8\n", "5 6\n2 3 11\n5 3 7\n1 4 10\n2 4 14\n4 3 8\n2 5 6\n", "6 6\n3 6 4\n2 4 1\n4 5 7\n3 4 10\n3 5 1\n5 2 15\n", "2 0\n", "6 8\n1 4 1\n1 5 1\n1 6 1\n2 4 1\n2 5 1\n2 6 1\n3 5 1\n3 6 1\n", "6 12\n1 3 8763000\n1 4 8763000\n1 5 8763000\n1 6 8763000\n2...
2CODEFORCES
1534_D. Lost Tree_2174
This is an interactive problem. Little Dormi was faced with an awkward problem at the carnival: he has to guess the edges of an unweighted tree of n nodes! The nodes of the tree are numbered from 1 to n. The game master only allows him to ask one type of question: * Little Dormi picks a node r (1 ≤ r ≤ n), and the...
import sys import random import collections test = False edges = [(1, 2) ,(1, 3) ,(1, 4) ,(2, 5) ,(2, 6) ,(3, 7) ,(3, 8) ,(4, 9) ,(4, 10) ,(5, 11) ,(5, 12)] adj = collections.defaultdict(list) for u,v in edges: adj[u].append(v) adj[v].append(u) def ask(l, n): if test: q = collections.deque([(l,0)]) vis = set(...
1Python2
{ "input": [ "4\n\n0 1 2 2\n\n1 0 1 1", "5\n\n2 2 1 1 0\n", "5\n5 3\n2 4\n3 1\n4 5\n", "4\n2 4\n3 2\n2 1\n", "5\n5 3\n2 4\n3 1\n4 5\n", "2\n1 2\n", "4\n3 4\n2 3\n3 1\n", "10\n8 10\n2 9\n7 8\n4 1\n7 3\n4 7\n2 5\n2 4\n4 6\n", "5\n3 4\n3 2\n3 1\n1 5\n", "3\n1 2\n2 3\n", "5\n1 ...
2CODEFORCES
1534_D. Lost Tree_2175
This is an interactive problem. Little Dormi was faced with an awkward problem at the carnival: he has to guess the edges of an unweighted tree of n nodes! The nodes of the tree are numbered from 1 to n. The game master only allows him to ask one type of question: * Little Dormi picks a node r (1 ≤ r ≤ n), and the...
#include<bits/stdc++.h> using namespace std; #define ll long long #define mex 400005 #define pi pair<int,int> #define minmax(a,b) {min(a,b),max(a,b)} int main() { // your code goes here int n; cin>>n; cout<<"? 1\n"; cout.flush(); int a[n]; map<int,vector<int> > h; for(int i=0;i<n;i++) cin>>a[i],h[a[i]].push_bac...
2C++
{ "input": [ "4\n\n0 1 2 2\n\n1 0 1 1", "5\n\n2 2 1 1 0\n", "5\n5 3\n2 4\n3 1\n4 5\n", "4\n2 4\n3 2\n2 1\n", "5\n5 3\n2 4\n3 1\n4 5\n", "2\n1 2\n", "4\n3 4\n2 3\n3 1\n", "10\n8 10\n2 9\n7 8\n4 1\n7 3\n4 7\n2 5\n2 4\n4 6\n", "5\n3 4\n3 2\n3 1\n1 5\n", "3\n1 2\n2 3\n", "5\n1 ...
2CODEFORCES
1534_D. Lost Tree_2176
This is an interactive problem. Little Dormi was faced with an awkward problem at the carnival: he has to guess the edges of an unweighted tree of n nodes! The nodes of the tree are numbered from 1 to n. The game master only allows him to ask one type of question: * Little Dormi picks a node r (1 ≤ r ≤ n), and the...
res = [] n = int(input()) print('?', 1, flush=True) arr = list(map(int, input().split())) for v,d in enumerate(arr): if d==1: res.append([0,v]) one = [v for v,d in enumerate(arr) if d&1] two = [v for v,d in enumerate(arr) if v and not (d&1)] if len(one)>len(two): one, two = two, one for u in one: pr...
3Python3
{ "input": [ "4\n\n0 1 2 2\n\n1 0 1 1", "5\n\n2 2 1 1 0\n", "5\n5 3\n2 4\n3 1\n4 5\n", "4\n2 4\n3 2\n2 1\n", "5\n5 3\n2 4\n3 1\n4 5\n", "2\n1 2\n", "4\n3 4\n2 3\n3 1\n", "10\n8 10\n2 9\n7 8\n4 1\n7 3\n4 7\n2 5\n2 4\n4 6\n", "5\n3 4\n3 2\n3 1\n1 5\n", "3\n1 2\n2 3\n", "5\n1 ...
2CODEFORCES
1534_D. Lost Tree_2177
This is an interactive problem. Little Dormi was faced with an awkward problem at the carnival: he has to guess the edges of an unweighted tree of n nodes! The nodes of the tree are numbered from 1 to n. The game master only allows him to ask one type of question: * Little Dormi picks a node r (1 ≤ r ≤ n), and the...
import java.io.*; import java.util.ArrayList; import java.util.LinkedList; import java.util.Random; import java.util.TreeSet; public class DLATOKEN1 { public static void main(String[] args) throws IOException { init_io(); int N = nint(); boolean[] visited = new boolean[N+1]; boolean...
4JAVA
{ "input": [ "4\n\n0 1 2 2\n\n1 0 1 1", "5\n\n2 2 1 1 0\n", "5\n5 3\n2 4\n3 1\n4 5\n", "4\n2 4\n3 2\n2 1\n", "5\n5 3\n2 4\n3 1\n4 5\n", "2\n1 2\n", "4\n3 4\n2 3\n3 1\n", "10\n8 10\n2 9\n7 8\n4 1\n7 3\n4 7\n2 5\n2 4\n4 6\n", "5\n3 4\n3 2\n3 1\n1 5\n", "3\n1 2\n2 3\n", "5\n1 ...
2CODEFORCES
181_B. Number of Triplets_2178
You are given n points on a plane. All points are different. Find the number of different groups of three points (A, B, C) such that point B is the middle of segment AC. The groups of three points are considered unordered, that is, if point B is the middle of segment AC, then groups (A, B, C) and (C, B, A) are consi...
s, n = 0, int(raw_input()) a = [0] * n for i in range(n): x, y = map(int, raw_input().split()) a[i] = 4000 * x + y a.sort() b = set(2 * k for k in a) for i, u in enumerate(a, 2): for v in a[i: ]: if v + u in b: s += 1 print s
1Python2
{ "input": [ "3\n0 0\n-1 0\n0 1\n", "3\n1 1\n2 2\n3 3\n", "10\n-2 1\n2 -2\n-1 -2\n0 0\n2 -1\n0 -2\n2 2\n0 2\n-1 -1\n1 -2\n", "40\n-8 24\n2 -1\n1 -18\n72 -70\n5 -4\n-308 436\n-19 40\n36 -35\n-178 265\n-1 2\n-7 30\n-1 0\n3 -2\n200 -285\n17 -16\n-35 74\n0 -4\n-86 106\n-1 4\n-7 6\n0 1\n-5 4\n-2 3\n6 -5\n-...
2CODEFORCES
181_B. Number of Triplets_2179
You are given n points on a plane. All points are different. Find the number of different groups of three points (A, B, C) such that point B is the middle of segment AC. The groups of three points are considered unordered, that is, if point B is the middle of segment AC, then groups (A, B, C) and (C, B, A) are consi...
#include <bits/stdc++.h> using namespace std; struct diem { int x, y; }; int n, ans = 0; diem a[3005]; bool cmp(diem a, diem b) { if (a.x == b.x) return a.y <= b.y; return a.x <= b.x; } int binary_search(int l, int r, diem value) { if (l > r) return 0; if (l == r) return l; int mid = (l + r) / 2; if (cmp(...
2C++
{ "input": [ "3\n0 0\n-1 0\n0 1\n", "3\n1 1\n2 2\n3 3\n", "10\n-2 1\n2 -2\n-1 -2\n0 0\n2 -1\n0 -2\n2 2\n0 2\n-1 -1\n1 -2\n", "40\n-8 24\n2 -1\n1 -18\n72 -70\n5 -4\n-308 436\n-19 40\n36 -35\n-178 265\n-1 2\n-7 30\n-1 0\n3 -2\n200 -285\n17 -16\n-35 74\n0 -4\n-86 106\n-1 4\n-7 6\n0 1\n-5 4\n-2 3\n6 -5\n-...
2CODEFORCES
181_B. Number of Triplets_2180
You are given n points on a plane. All points are different. Find the number of different groups of three points (A, B, C) such that point B is the middle of segment AC. The groups of three points are considered unordered, that is, if point B is the middle of segment AC, then groups (A, B, C) and (C, B, A) are consi...
n = int(input()) points_array = [] cords = [] for i in range(2001): cords.append([False] * 2001) for i in range(n): x, y = [a for a in input().split()] points_array.append([int(x), int(y)]) cords[int(x)+1000][int(y)+1000] = True count = 0 for i in range(n): for j in range(i+1, n): x1, y1...
3Python3
{ "input": [ "3\n0 0\n-1 0\n0 1\n", "3\n1 1\n2 2\n3 3\n", "10\n-2 1\n2 -2\n-1 -2\n0 0\n2 -1\n0 -2\n2 2\n0 2\n-1 -1\n1 -2\n", "40\n-8 24\n2 -1\n1 -18\n72 -70\n5 -4\n-308 436\n-19 40\n36 -35\n-178 265\n-1 2\n-7 30\n-1 0\n3 -2\n200 -285\n17 -16\n-35 74\n0 -4\n-86 106\n-1 4\n-7 6\n0 1\n-5 4\n-2 3\n6 -5\n-...
2CODEFORCES
181_B. Number of Triplets_2181
You are given n points on a plane. All points are different. Find the number of different groups of three points (A, B, C) such that point B is the middle of segment AC. The groups of three points are considered unordered, that is, if point B is the middle of segment AC, then groups (A, B, C) and (C, B, A) are consi...
import java.io.BufferedReader; import java.io.InputStreamReader; public class Number_of_Triplets { static boolean [][]mapa = new boolean[2001][2001]; static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); static int coordenadas[]; public static void main(String[] args) { ...
4JAVA
{ "input": [ "3\n0 0\n-1 0\n0 1\n", "3\n1 1\n2 2\n3 3\n", "10\n-2 1\n2 -2\n-1 -2\n0 0\n2 -1\n0 -2\n2 2\n0 2\n-1 -1\n1 -2\n", "40\n-8 24\n2 -1\n1 -18\n72 -70\n5 -4\n-308 436\n-19 40\n36 -35\n-178 265\n-1 2\n-7 30\n-1 0\n3 -2\n200 -285\n17 -16\n-35 74\n0 -4\n-86 106\n-1 4\n-7 6\n0 1\n-5 4\n-2 3\n6 -5\n-...
2CODEFORCES
204_D. Little Elephant and Retro Strings_2182
The Little Elephant has found a ragged old black-and-white string s on the attic. The characters of string s are numbered from the left to the right from 1 to |s|, where |s| is the length of the string. Let's denote the i-th character of string s as si. As the string is black-and-white, each character of the string is...
#include <bits/stdc++.h> using namespace std; template <class T> void dbs(string str, T t) { cerr << str << " : " << t << "\n"; } template <class T, class... S> void dbs(string str, T t, S... s) { int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...); } templat...
2C++
{ "input": [ "10 2\nXXBXXWXXXX\n", "3 2\nXXX\n", "4 2\nXXXX\n", "4 2\nXXBW\n", "2 1\nWB\n", "128 100\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n", "25 7\nXWBXWBXWXWBWXBWWXBWXXXXBB\n", "1 1\nX\n", ...
2CODEFORCES
204_D. Little Elephant and Retro Strings_2183
The Little Elephant has found a ragged old black-and-white string s on the attic. The characters of string s are numbered from the left to the right from 1 to |s|, where |s| is the length of the string. Let's denote the i-th character of string s as si. As the string is black-and-white, each character of the string is...
Mod=1000000007 n,k=map(int,input().split(' ')) s=' '+input() f,fs,g,gs,w=[0]*1000005,[0]*1000005,[0]*1000005,[0]*1000005,[0]*1000005 qx,qw,qb=[0]*1000005,[0]*1000005,[0]*1000005 q=0 f[0]=fs[0]=1 for i in range(1,n+1): lg=(i-k if i-k>=q else q) if s[i]!='B': f[i]=fs[i-1]-fs[lg-1]+Mod f[i]-=(Mod if f[i]>=Mod else 0...
3Python3
{ "input": [ "10 2\nXXBXXWXXXX\n", "3 2\nXXX\n", "4 2\nXXXX\n", "4 2\nXXBW\n", "2 1\nWB\n", "128 100\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n", "25 7\nXWBXWBXWXWBWXBWWXBWXXXXBB\n", "1 1\nX\n", ...
2CODEFORCES
204_D. Little Elephant and Retro Strings_2184
The Little Elephant has found a ragged old black-and-white string s on the attic. The characters of string s are numbered from the left to the right from 1 to |s|, where |s| is the length of the string. Let's denote the i-th character of string s as si. As the string is black-and-white, each character of the string is...
import java.io.OutputStream; import java.io.IOException; import java.io.PrintWriter; import java.util.InputMismatchException; 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[] args) { Inpu...
4JAVA
{ "input": [ "10 2\nXXBXXWXXXX\n", "3 2\nXXX\n", "4 2\nXXXX\n", "4 2\nXXBW\n", "2 1\nWB\n", "128 100\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n", "25 7\nXWBXWBXWXWBWXBWWXBWXXXXBB\n", "1 1\nX\n", ...
2CODEFORCES
229_C. Triangles_2185
Alice and Bob don't play games anymore. Now they study properties of all sorts of graphs together. Alice invented the following task: she takes a complete undirected graph with n vertices, chooses some m edges and keeps them. Bob gets the <image> remaining edges. Alice and Bob are fond of "triangles" in graphs, that i...
#include <bits/stdc++.h> const int maxn = 1000100; long long result, n, m; long long deg[maxn + 1]; int main() { long long i, j, k, x, y; scanf("%I64d%I64d", &n, &m); for (i = 1; i <= n; ++i) deg[i] = 0; for (i = 1; i <= m; ++i) { scanf("%I64d%I64d", &x, &y); ++deg[x]; ++deg[y]; } result = 0; ...
2C++
{ "input": [ "5 5\n1 2\n1 3\n2 3\n2 4\n3 4\n", "5 3\n1 2\n2 3\n1 3\n", "3 3\n1 2\n3 1\n2 3\n", "2 0\n", "10 17\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n", "2 1\n1 2\n", "8 13\n1 2\n2 3\n3 4\n4 1\n2 4\n1 3\n5 6\n6 7\n7 8\n8 5\n6 8\n5 7\n1 8\n",...
2CODEFORCES
229_C. Triangles_2186
Alice and Bob don't play games anymore. Now they study properties of all sorts of graphs together. Alice invented the following task: she takes a complete undirected graph with n vertices, chooses some m edges and keeps them. Bob gets the <image> remaining edges. Alice and Bob are fond of "triangles" in graphs, that i...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.Random; import java.util.StringTokenizer; public class Solution{ public static void main(String[] args) throws IOException { FastScanne...
4JAVA
{ "input": [ "5 5\n1 2\n1 3\n2 3\n2 4\n3 4\n", "5 3\n1 2\n2 3\n1 3\n", "3 3\n1 2\n3 1\n2 3\n", "2 0\n", "10 17\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n", "2 1\n1 2\n", "8 13\n1 2\n2 3\n3 4\n4 1\n2 4\n1 3\n5 6\n6 7\n7 8\n8 5\n6 8\n5 7\n1 8\n",...
2CODEFORCES
253_A. Boys and Girls_2187
There are n boys and m girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to n + m. Then the number of integers i (1 ≤ i < n + m) such that positions with indexes i...
#include <bits/stdc++.h> using namespace std; void solve() { ifstream in("input.txt"); ofstream out("output.txt"); int n, m; in >> n >> m; if (n >= m) { for (int(i) = int(0); (i) < int(m); (i)++) out << "BG"; for (int(i) = int(0); (i) < int(n - m); (i)++) out << "B"; } else { for (int(i) = int(0...
2C++
{ "input": [ "4 2\n", "3 3\n", "100 100\n", "1 2\n", "10 100\n", "1 34\n", "1 100\n", "90 100\n", "1 4\n", "89 89\n", "6 4\n", "1 98\n", "99 3\n", "1 1\n", "46 2\n", "84 27\n", "5 5\n", "76 48\n", "2 1\n", "56 98\n", "100 90\n", "...
2CODEFORCES
253_A. Boys and Girls_2188
There are n boys and m girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to n + m. Then the number of integers i (1 ≤ i < n + m) such that positions with indexes i...
import os.path import sys if os.path.exists('input.txt'): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') n,m=[int(x) for x in input().split(' ')] x=min(n,m) #print(x) if n<m: ans=x*"GB" else: ans=x*'BG' n=n-x m=m-x #print(n,m) if n!=0: ans+=n*'B' if m!=0: ans+=m*'G' prin...
3Python3
{ "input": [ "4 2\n", "3 3\n", "100 100\n", "1 2\n", "10 100\n", "1 34\n", "1 100\n", "90 100\n", "1 4\n", "89 89\n", "6 4\n", "1 98\n", "99 3\n", "1 1\n", "46 2\n", "84 27\n", "5 5\n", "76 48\n", "2 1\n", "56 98\n", "100 90\n", "...
2CODEFORCES
253_A. Boys and Girls_2189
There are n boys and m girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to n + m. Then the number of integers i (1 ≤ i < n + m) such that positions with indexes i...
import java.math.BigInteger; import java.util.*; import java.io.*; public class A_Boys_and_Girls { public static void main (String[] args) throws IOException{ BufferedReader br = new BufferedReader(new FileReader("input.txt")); PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("out...
4JAVA
{ "input": [ "4 2\n", "3 3\n", "100 100\n", "1 2\n", "10 100\n", "1 34\n", "1 100\n", "90 100\n", "1 4\n", "89 89\n", "6 4\n", "1 98\n", "99 3\n", "1 1\n", "46 2\n", "84 27\n", "5 5\n", "76 48\n", "2 1\n", "56 98\n", "100 90\n", "...
2CODEFORCES
278_B. New Problem_2190
Coming up with a new problem isn't as easy as many people think. Sometimes it is hard enough to name it. We'll consider a title original if it doesn't occur as a substring in any titles of recent Codeforces problems. You've got the titles of n last problems — the strings, consisting of lowercase English letters. Your...
n = input() s = '' a = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] for i in xrange(n): s = s +' '+ raw_input() key2 = 1 key = 1 metka = 0 for m in xrange(len(a)+1): if key2: b = '' else: b = a[i-1] for i in xrange(len(a)+1): ...
1Python2
{ "input": [ "4\naa\nbdefghijklmn\nopqrstuvwxyz\nc\n", "5\nthreehorses\ngoodsubstrings\nsecret\nprimematrix\nbeautifulyear\n", "3\nrjnflsbpxqivrcdjptj\nvpojopbwbwbswdu\nrydkiwnugwddcgcrng\n", "1\nz\n", "30\nb\nu\np\nn\nf\nm\nt\ni\nj\nk\np\nh\na\nc\nw\nz\nz\np\nt\nd\no\nw\nu\nq\nl\ny\ni\no\na\nu\n"...
2CODEFORCES
278_B. New Problem_2191
Coming up with a new problem isn't as easy as many people think. Sometimes it is hard enough to name it. We'll consider a title original if it doesn't occur as a substring in any titles of recent Codeforces problems. You've got the titles of n last problems — the strings, consisting of lowercase English letters. Your...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); std::ios::sync_with_stdio(false); long long n; string s; map<string, bool> maap; cin >> n; for (int i = 0; i < n; i++) { cin >> s; for (int k = 0; k < s.size(); k++) { for (int h = k; h < s.size(); h++) { maap[s.s...
2C++
{ "input": [ "4\naa\nbdefghijklmn\nopqrstuvwxyz\nc\n", "5\nthreehorses\ngoodsubstrings\nsecret\nprimematrix\nbeautifulyear\n", "3\nrjnflsbpxqivrcdjptj\nvpojopbwbwbswdu\nrydkiwnugwddcgcrng\n", "1\nz\n", "30\nb\nu\np\nn\nf\nm\nt\ni\nj\nk\np\nh\na\nc\nw\nz\nz\np\nt\nd\no\nw\nu\nq\nl\ny\ni\no\na\nu\n"...
2CODEFORCES
278_B. New Problem_2192
Coming up with a new problem isn't as easy as many people think. Sometimes it is hard enough to name it. We'll consider a title original if it doesn't occur as a substring in any titles of recent Codeforces problems. You've got the titles of n last problems — the strings, consisting of lowercase English letters. Your...
from itertools import * alphabet="abcdefghijklmnopqrstuvwxyz"; def isValid(s, names): for name in names: if name.find(s)!=-1: return False return True def newProblem(names): for i in range(1,3): for s in product(alphabet, repeat=i): st="" for c in s: ...
3Python3
{ "input": [ "4\naa\nbdefghijklmn\nopqrstuvwxyz\nc\n", "5\nthreehorses\ngoodsubstrings\nsecret\nprimematrix\nbeautifulyear\n", "3\nrjnflsbpxqivrcdjptj\nvpojopbwbwbswdu\nrydkiwnugwddcgcrng\n", "1\nz\n", "30\nb\nu\np\nn\nf\nm\nt\ni\nj\nk\np\nh\na\nc\nw\nz\nz\np\nt\nd\no\nw\nu\nq\nl\ny\ni\no\na\nu\n"...
2CODEFORCES
278_B. New Problem_2193
Coming up with a new problem isn't as easy as many people think. Sometimes it is hard enough to name it. We'll consider a title original if it doesn't occur as a substring in any titles of recent Codeforces problems. You've got the titles of n last problems — the strings, consisting of lowercase English letters. Your...
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class Solver { public static void main(String[] Args) t...
4JAVA
{ "input": [ "4\naa\nbdefghijklmn\nopqrstuvwxyz\nc\n", "5\nthreehorses\ngoodsubstrings\nsecret\nprimematrix\nbeautifulyear\n", "3\nrjnflsbpxqivrcdjptj\nvpojopbwbwbswdu\nrydkiwnugwddcgcrng\n", "1\nz\n", "30\nb\nu\np\nn\nf\nm\nt\ni\nj\nk\np\nh\na\nc\nw\nz\nz\np\nt\nd\no\nw\nu\nq\nl\ny\ni\no\na\nu\n"...
2CODEFORCES
300_A. Array_2194
Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero ( < 0). 2. The product of all numbers in the second set is greater than zero ( > 0). 3. The product of a...
from __future__ import division, print_function def main(): n = int(input()) con = [int(_) for _ in input().split()] a, b, c, = [], [], [] for x in con: if x == 0: c.append(x) if x > 0: b.append(x) if x < 0: a.append(x) if len(b) == 0: ...
1Python2
{ "input": [ "4\n-1 -2 -3 0\n", "3\n-1 2 0\n", "100\n-34 81 85 -96 50 20 54 86 22 10 -19 52 65 44 30 53 63 71 17 98 -92 4 5 -99 89 -23 48 9 7 33 75 2 47 -56 42 70 -68 57 51 83 82 94 91 45 46 25 95 11 -12 62 -31 -87 58 38 67 97 -60 66 73 -28 13 93 29 59 -49 77 37 -43 -27 0 -16 72 15 79 61 78 35 21 3 8 84 1...
2CODEFORCES
300_A. Array_2195
Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero ( < 0). 2. The product of all numbers in the second set is greater than zero ( > 0). 3. The product of a...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); cout << "1 " << a[0] << endl; if (a[n - 1] > 0) { cout << "1 " << a[n - 1] << endl; cout << n - 2 << endl; for (int i = 1; i < n - 1; i++) { ...
2C++
{ "input": [ "4\n-1 -2 -3 0\n", "3\n-1 2 0\n", "100\n-34 81 85 -96 50 20 54 86 22 10 -19 52 65 44 30 53 63 71 17 98 -92 4 5 -99 89 -23 48 9 7 33 75 2 47 -56 42 70 -68 57 51 83 82 94 91 45 46 25 95 11 -12 62 -31 -87 58 38 67 97 -60 66 73 -28 13 93 29 59 -49 77 37 -43 -27 0 -16 72 15 79 61 78 35 21 3 8 84 1...
2CODEFORCES
300_A. Array_2196
Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero ( < 0). 2. The product of all numbers in the second set is greater than zero ( > 0). 3. The product of a...
n=int(input()) a=list(map(int,input().split())) b=[] k=0 k1=0 for i in range(0,n): if(a[i]==0): b.append(a[i]) elif(a[i]>0): if(k==0): k=a[i] else: b.append(a[i]) elif(a[i]<0): if(k1==0): k1=a[i] else: b.append(a[i]) pri...
3Python3
{ "input": [ "4\n-1 -2 -3 0\n", "3\n-1 2 0\n", "100\n-34 81 85 -96 50 20 54 86 22 10 -19 52 65 44 30 53 63 71 17 98 -92 4 5 -99 89 -23 48 9 7 33 75 2 47 -56 42 70 -68 57 51 83 82 94 91 45 46 25 95 11 -12 62 -31 -87 58 38 67 97 -60 66 73 -28 13 93 29 59 -49 77 37 -43 -27 0 -16 72 15 79 61 78 35 21 3 8 84 1...
2CODEFORCES
300_A. Array_2197
Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero ( < 0). 2. The product of all numbers in the second set is greater than zero ( > 0). 3. The product of a...
import java.util.Scanner; import java.util.ArrayList; public class Problem023_300A_Array { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int n=sc.nextInt(); int zeros=0; ArrayList<Integer> positive = new ArrayList<Integer>(); ArrayList<Inte...
4JAVA
{ "input": [ "4\n-1 -2 -3 0\n", "3\n-1 2 0\n", "100\n-34 81 85 -96 50 20 54 86 22 10 -19 52 65 44 30 53 63 71 17 98 -92 4 5 -99 89 -23 48 9 7 33 75 2 47 -56 42 70 -68 57 51 83 82 94 91 45 46 25 95 11 -12 62 -31 -87 58 38 67 97 -60 66 73 -28 13 93 29 59 -49 77 37 -43 -27 0 -16 72 15 79 61 78 35 21 3 8 84 1...
2CODEFORCES
325_D. Reclamation_2198
In a far away land, there exists a planet shaped like a cylinder. There are three regions in this planet: top, bottom, and side as shown in the following picture. <image> Both the top and the bottom areas consist of big cities. The side area consists entirely of the sea. One day, a city decides that it has too littl...
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const int Maxn = 3005, Maxm = 300005, Mo = 1000000007, sp[8][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {-1, -1}, {1, -1}, {-1, 1}}; const long long oo = INT_MAX >> 2; struct Tree...
2C++
{ "input": [ "3 4 9\n2 2\n3 2\n2 3\n3 4\n3 1\n1 3\n2 1\n1 1\n1 4\n", "2 5 10\n2 2\n1 1\n1 4\n2 1\n1 2\n1 5\n2 4\n2 5\n1 3\n2 3\n", "2 2 2\n1 1\n2 2\n", "3 3 9\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3\n", "7 5 35\n5 3\n3 5\n1 1\n2 5\n6 4\n7 2\n5 1\n3 4\n6 5\n7 3\n4 1\n2 2\n4 2\n2 4\n4 3\n3 3\n6...
2CODEFORCES
325_D. Reclamation_2199
In a far away land, there exists a planet shaped like a cylinder. There are three regions in this planet: top, bottom, and side as shown in the following picture. <image> Both the top and the bottom areas consist of big cities. The side area consists entirely of the sea. One day, a city decides that it has too littl...
import java.io.InputStreamReader; import java.io.IOException; import java.util.Arrays; 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 cla...
4JAVA
{ "input": [ "3 4 9\n2 2\n3 2\n2 3\n3 4\n3 1\n1 3\n2 1\n1 1\n1 4\n", "2 5 10\n2 2\n1 1\n1 4\n2 1\n1 2\n1 5\n2 4\n2 5\n1 3\n2 3\n", "2 2 2\n1 1\n2 2\n", "3 3 9\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3\n", "7 5 35\n5 3\n3 5\n1 1\n2 5\n6 4\n7 2\n5 1\n3 4\n6 5\n7 3\n4 1\n2 2\n4 2\n2 4\n4 3\n3 3\n6...
2CODEFORCES