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
brcktsrm_0
Problem description. Vipul is a hardworking super-hero who maintains the bracket ratio of all the strings in the world. Recently he indulged himself in saving the string population so much that he lost his ability for checking brackets (luckily, not permanently ).Being his super-hero friend help him in his time of hard...
for _ in range(input()): try: eval(raw_input()) print 'YES' except TypeError: print 'YES' except: print 'NO'
1Python2
{ "input": [ "3\n((()))\n(())()\n()(()", "3\n((()))\n(())()\n()())", "3\n((()()\n(())()\n()(()", "3\n((()))\n(())))\n()())", "3\n)))(((\n(())))\n()())", "3\n((()))\n(())()\n))(((", "3\n((()()\n(())()\n()(((", "3\n((()))\n(())()\n()()(", "3\n((()()\n'())()\n()(((", "3\n)))(((\n(...
1CODECHEF
comm3_1
The Chef likes to stay in touch with his staff. So, the Chef, the head server, and the sous-chef all carry two-way transceivers so they can stay in constant contact. Of course, these transceivers have a limited range so if two are too far apart, they cannot communicate directly. The Chef invested in top-of-the-line t...
import math no_of_testcases = int(input()) for each in range(no_of_testcases): dist = int(input()) point_1 = map(int,raw_input().split()) point_2 = map(int,raw_input().split()) point_3 = map(int,raw_input().split()) point_12 =math.sqrt( math.pow((point_1[0] -point_2[0]),2) + math.pow((point_1[1]...
1Python2
{ "input": [ "3\n1\n0 1\n0 0\n1 0\n2\n0 1\n0 0\n1 0\n2\n0 0\n0 2\n2 1", "3\n1\n0 1\n0 -1\n1 0\n2\n0 1\n0 0\n1 0\n2\n0 0\n0 2\n2 1", "3\n2\n0 1\n0 -1\n1 0\n2\n0 1\n0 0\n1 0\n2\n0 0\n0 2\n2 1", "3\n2\n0 -1\n0 -1\n1 0\n2\n0 0\n0 0\n1 0\n2\n1 0\n1 2\n2 1", "3\n2\n0 -1\n-1 -1\n2 0\n2\n1 0\n0 -1\n1 -1\n...
1CODECHEF
gcd2_2
Frank explained its friend Felman the algorithm of Euclides to calculate the GCD of two numbers. Then Felman implements it algorithm int gcd(int a, int b) { if (b==0) return a; else return gcd(b,a%b); } and it proposes to Frank that makes it but with a little integer and another integer that has up to 250 d...
def gcd(a,b): while(b): a,b=b,a%b return a t=input() while(t): a,b=map(int,raw_input().split()) print(gcd(a,b)) t=t-1;
1Python2
{ "input": [ "2\n2 6\n10 11", "2\n3 6\n10 11", "2\n1 3\n10 11", "2\n0 6\n10 11", "2\n0 6\n0 11", "2\n3 6\n8 22", "2\n3 6\n8 4", "2\n5 2\n10 2", "2\n4 10\n8 6", "2\n7 14\n8 6", "2\n7 14\n8 4", "2\n2 6\n5 2", "2\n0 14\n16 2", "2\n0 11\n10 1", "2\n0 14\n16 1", ...
1CODECHEF
luckybal_3
A Little Elephant from the Zoo of Lviv likes lucky strings, i.e., the strings that consist only of the lucky digits 4 and 7. The Little Elephant calls some string T of the length M balanced if there exists at least one integer X (1 ≤ X ≤ M) such that the number of digits 4 in the substring T[1, X - 1] is equal to the n...
n = input() for i in range(n): str = raw_input() l = len(str) megacounter = 0 counter = 0 i = 0 while(1): while(i<l and str[i]=='7'): i=i+1 counter=counter+1 if(i>=l): break megacounter = megacounter + (counter*(counter+1))/2 i=...
1Python2
{ "input": [ "4\n47\n74\n477\n4747477", "4\n47\n47\n477\n4747477", "4\n7\n47\n477\n4747477", "4\n4\n47\n477\n4747477", "4\n7\n7\n477\n4747477", "4\n7\n44\n477\n4747477", "4\n44\n74\n477\n4747477", "4\n7\n44\n7\n4747477", "4\n47\n44\n477\n4747477", "4\n47\n4\n477\n4747477", ...
1CODECHEF
prpaln_4
Given a string s. Can you make it a palindrome by deleting exactly one character? Note that size of the string after deletion would be one less than it was before. Input First line of the input contains a single integer T denoting number of test cases. For each test case, you are given a single line containing string...
import math import sys def checkpal(s): return s==s[::-1] for a in range(input()): s=raw_input() l=len(s) if(l==2): print "YES" else: if checkpal(s): print "YES" else: while s[0] == s[-1] and len(s)>2: s=s[1:-1] if checkpal(s[1:]) or ...
1Python2
{ "input": [ "4\naaa\nabc\nabdbca\nabba", "4\naaa\nabc\nabdbca\nabca", "4\naaa\nabc\nabdbc`\naaca", "4\naab\nacc\n`bd`cb\naaad", "4\nbaa\nabc\n`bd`bb\naabd", "4\nbab\nabb\nbb`db`\naabd", "4\nbaa\n`aa\nbb`c`b\ndba`", "4\nba`\n`aa\nbb`c_c\ndba`", "4\n`a_\naa`\ndda`^c\nca^a", "4\n...
1CODECHEF
tf01_5
An established group of scientists are working on finding solution to NP hard problems. They claim Subset Sum as an NP-hard problem. The problem is to determine whether there exists a subset of a given set S whose sum is a given number K. You are a computer engineer and you claim to solve this problem given that all...
import sys for __ in range(input()) : n , k = map(int,sys.stdin.readline().split()) lists = map(int,sys.stdin.readline().split()) dp = [0]*(k+1) dp[0]=1 for i in lists : for j in range(k-i,-1,-1) : if dp[k] : break if dp[j] : dp[j+i] =...
1Python2
{ "input": [ "2\n5 10\n3 4 6 1 9\n3 2\n1 3 4" ], "output": [ "1\n0" ] }
1CODECHEF
1012_E. Cycle sort_6
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
#include <bits/stdc++.h> using namespace std; const int MAXN = 300000; map<int, int> mapa; map<pair<int, int>, vector<int>> pos; vector<int> g[MAXN]; int ptr[MAXN]; int used[MAXN]; void euler(int v, vector<int> &res) { used[v] = true; for (; ptr[v] < (int)(g[v]).size();) { ++ptr[v]; int u = g[v][ptr[v] - 1]...
2C++
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n", "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n1676166...
2CODEFORCES
1012_E. Cycle sort_7
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≤ i_j ≤ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., t...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Arrays; import java.io.IOException; import java.util.Random; import java.util.ArrayList; import java.io.UncheckedIOException; import java.util.List; import java.io.Closeable; import java.io...
4JAVA
{ "input": [ "5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n", "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n1676166...
2CODEFORCES
1037_E. Trips_8
There are n persons who initially don't know each other. On each morning, two of them, who were not friends before, become friends. We want to plan a trip for every evening of m days. On each trip, you have to select a group of people that will go on the trip. For every person, one of the following should hold: * ...
import sys range = xrange n,m,k = [int(x) for x in sys.stdin.readline().split()] inp = [int(x)-1 for x in sys.stdin.read().split()] ii = 0 coupl = [[] for _ in range(n)] time = [[] for _ in range(n)] nfr = [0]*n for i in range(m): a,b = inp[ii],inp[ii+1] ii += 2 coupl[a].append(b) coupl[b].append(a...
1Python2
{ "input": [ "4 4 2\n2 3\n1 2\n1 3\n1 4\n", "5 8 2\n2 1\n4 2\n5 4\n5 2\n4 3\n5 1\n4 1\n3 2\n", "5 7 2\n1 5\n3 2\n2 5\n3 4\n1 2\n5 3\n1 3\n", "16 20 2\n10 3\n5 3\n10 5\n12 7\n7 6\n9 12\n9 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n4 13\n13 15\n1 8\n7 15\n1 7\n8 15\n", "2 1 1\n2 1\n", "16 20...
2CODEFORCES
1037_E. Trips_9
There are n persons who initially don't know each other. On each morning, two of them, who were not friends before, become friends. We want to plan a trip for every evening of m days. On each trip, you have to select a group of people that will go on the trip. For every person, one of the following should hold: * ...
#include <bits/stdc++.h> using namespace std; const int module = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, k; cin >> n >> m >> k; vector<set<int>> to(n, set<int>()); vector<pair<int, int>> edges(m); vector<int> nbr(n); for (int i = 0; i < m; ++i) { ...
2C++
{ "input": [ "4 4 2\n2 3\n1 2\n1 3\n1 4\n", "5 8 2\n2 1\n4 2\n5 4\n5 2\n4 3\n5 1\n4 1\n3 2\n", "5 7 2\n1 5\n3 2\n2 5\n3 4\n1 2\n5 3\n1 3\n", "16 20 2\n10 3\n5 3\n10 5\n12 7\n7 6\n9 12\n9 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n4 13\n13 15\n1 8\n7 15\n1 7\n8 15\n", "2 1 1\n2 1\n", "16 20...
2CODEFORCES
1037_E. Trips_10
There are n persons who initially don't know each other. On each morning, two of them, who were not friends before, become friends. We want to plan a trip for every evening of m days. On each trip, you have to select a group of people that will go on the trip. For every person, one of the following should hold: * ...
from collections import deque def solve(adj, m, k, uv): n = len(adj) nn = [len(a) for a in adj] q = deque() for i in range(n): if nn[i] < k: q.append(i) while q: v = q.popleft() for u in adj[v]: nn[u] -= 1 if nn[u] == k-1: ...
3Python3
{ "input": [ "4 4 2\n2 3\n1 2\n1 3\n1 4\n", "5 8 2\n2 1\n4 2\n5 4\n5 2\n4 3\n5 1\n4 1\n3 2\n", "5 7 2\n1 5\n3 2\n2 5\n3 4\n1 2\n5 3\n1 3\n", "16 20 2\n10 3\n5 3\n10 5\n12 7\n7 6\n9 12\n9 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n4 13\n13 15\n1 8\n7 15\n1 7\n8 15\n", "2 1 1\n2 1\n", "16 20...
2CODEFORCES
1037_E. Trips_11
There are n persons who initially don't know each other. On each morning, two of them, who were not friends before, become friends. We want to plan a trip for every evening of m days. On each trip, you have to select a group of people that will go on the trip. For every person, one of the following should hold: * ...
import java.io.*; import java.util.*; public class Test { static int readInt() { int ans = 0; boolean neg = false; try { boolean start = false; for (int c = 0; (c = System.in.read()) != -1; ) { if (c == '-') { start = true; ...
4JAVA
{ "input": [ "4 4 2\n2 3\n1 2\n1 3\n1 4\n", "5 8 2\n2 1\n4 2\n5 4\n5 2\n4 3\n5 1\n4 1\n3 2\n", "5 7 2\n1 5\n3 2\n2 5\n3 4\n1 2\n5 3\n1 3\n", "16 20 2\n10 3\n5 3\n10 5\n12 7\n7 6\n9 12\n9 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n4 13\n13 15\n1 8\n7 15\n1 7\n8 15\n", "2 1 1\n2 1\n", "16 20...
2CODEFORCES
1060_A. Phone Numbers_12
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit. For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not. You have n cards with digits, and you want to use them to make as many phone n...
n=int(raw_input()) s=str(raw_input()) cou=s.count('8') if cou==0 or n<11: print 0 else: while n<11*cou: cou-=1 print cou
1Python2
{ "input": [ "22\n0011223344556677889988\n", "11\n00000000008\n", "11\n31415926535\n", "51\n882889888888689888850888388887688788888888888858888\n", "55\n7271714707719515303911625619272900050990324951111943573\n", "72\n888488888888823288848804883838888888887888888888228888218488897809784868\n",...
2CODEFORCES
1060_A. Phone Numbers_13
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit. For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not. You have n cards with digits, and you want to use them to make as many phone n...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long int LINF = 0x3f3f3f3f3f3f3f3fll; int t, n, a, b, cnt1, cnt2; string s; int main() { cin >> n; cin >> s; cnt1 = n / 11; for (int i = 0; i < s.size(); i++) { if (s[i] == '8') cnt2++; } cout << min(cnt1, cnt2) << endl...
2C++
{ "input": [ "22\n0011223344556677889988\n", "11\n00000000008\n", "11\n31415926535\n", "51\n882889888888689888850888388887688788888888888858888\n", "55\n7271714707719515303911625619272900050990324951111943573\n", "72\n888488888888823288848804883838888888887888888888228888218488897809784868\n",...
2CODEFORCES
1060_A. Phone Numbers_14
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit. For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not. You have n cards with digits, and you want to use them to make as many phone n...
n = int(input()) s = input() k = s.count("8") l = n - k if k <= l//10: print(k) else: while k > l//10: k -= 1 l += 1 print(min(k, l//10))
3Python3
{ "input": [ "22\n0011223344556677889988\n", "11\n00000000008\n", "11\n31415926535\n", "51\n882889888888689888850888388887688788888888888858888\n", "55\n7271714707719515303911625619272900050990324951111943573\n", "72\n888488888888823288848804883838888888887888888888228888218488897809784868\n",...
2CODEFORCES
1060_A. Phone Numbers_15
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit. For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not. You have n cards with digits, and you want to use them to make as many phone n...
import java.util.Scanner; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author anhnth37 */ public class A_1060 { public static void main(String[] args) { ...
4JAVA
{ "input": [ "22\n0011223344556677889988\n", "11\n00000000008\n", "11\n31415926535\n", "51\n882889888888689888850888388887688788888888888858888\n", "55\n7271714707719515303911625619272900050990324951111943573\n", "72\n888488888888823288848804883838888888887888888888228888218488897809784868\n",...
2CODEFORCES
1081_G. Mergesort Strikes Back_16
Chouti thought about his very first days in competitive programming. When he had just learned to write merge sort, he thought that the merge sort is too slow, so he restricted the maximum depth of recursion and modified the merge sort to the following: <image> Chouti found his idea dumb since obviously, this "merge s...
#include <bits/stdc++.h> const int MAXN = 1e5 + 20; int n, k, M; int inv[MAXN], pre_inv[MAXN]; void math_pre() { inv[1] = 1; for (int i = 2; i <= ((n < 4) ? 4 : n); ++i) inv[i] = 1ll * (M - M / i) * inv[M % i] % M; for (int i = 1; i <= n; ++i) pre_inv[i] = (pre_inv[i - 1] + inv[i]) % M; } struct map { stati...
2C++
{ "input": [ "3 2 998244353\n", "9 3 998244353\n", "3 1 998244353\n", "9 4 998244353\n", "53812 4 967428361\n", "7 2 400166453\n", "75727 16 485722667\n", "65536 10 802338989\n", "65535 12 196344479\n", "5000 4 961162523\n", "13694 5 579788161\n", "99999 14 746231791\n"...
2CODEFORCES
1101_A. Minimum Integer_17
You are given q queries in the following form: Given three integers l_i, r_i and d_i, find minimum positive integer x_i such that it is divisible by d_i and it does not belong to the segment [l_i, r_i]. Can you answer all the queries? Recall that a number x belongs to segment [l, r] if l ≤ x ≤ r. Input The first l...
q = int(raw_input()) for _ in xrange(q): l,r,d = map(int,raw_input().split()) if l/d > 0 and l> d: print d else: print ((r/d)+1)*d
1Python2
{ "input": [ "5\n2 4 2\n5 10 4\n3 10 1\n1 2 3\n4 6 5\n", "20\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 100000...
2CODEFORCES
1101_A. Minimum Integer_18
You are given q queries in the following form: Given three integers l_i, r_i and d_i, find minimum positive integer x_i such that it is divisible by d_i and it does not belong to the segment [l_i, r_i]. Can you answer all the queries? Recall that a number x belongs to segment [l, r] if l ≤ x ≤ r. Input The first l...
#include <bits/stdc++.h> using namespace std; long long f[1000001]; long long pow(long long a, long long b, long long MOD) { long long x = 1, y = a; while (b > 0) { if (b % 2 == 1) { x = (x * y); if (x > MOD) x %= MOD; } y = (y * y); if (y > MOD) y %= MOD; b /= 2; } return x; } l...
2C++
{ "input": [ "5\n2 4 2\n5 10 4\n3 10 1\n1 2 3\n4 6 5\n", "20\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 100000...
2CODEFORCES
1101_A. Minimum Integer_19
You are given q queries in the following form: Given three integers l_i, r_i and d_i, find minimum positive integer x_i such that it is divisible by d_i and it does not belong to the segment [l_i, r_i]. Can you answer all the queries? Recall that a number x belongs to segment [l, r] if l ≤ x ≤ r. Input The first l...
n = int(input()) A = [] for i in range(n): A = A+[input().split()] for a in A: if int(a[2]) < int(a[0]) or int(a[2]) > int(a[1]): print(a[2]) else: print(int(a[2])*(int(a[1])//int(a[2])+1))
3Python3
{ "input": [ "5\n2 4 2\n5 10 4\n3 10 1\n1 2 3\n4 6 5\n", "20\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 100000...
2CODEFORCES
1101_A. Minimum Integer_20
You are given q queries in the following form: Given three integers l_i, r_i and d_i, find minimum positive integer x_i such that it is divisible by d_i and it does not belong to the segment [l_i, r_i]. Can you answer all the queries? Recall that a number x belongs to segment [l, r] if l ≤ x ≤ r. Input The first l...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.Input...
4JAVA
{ "input": [ "5\n2 4 2\n5 10 4\n3 10 1\n1 2 3\n4 6 5\n", "20\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 100000...
2CODEFORCES
1129_D. Isolation_21
Find the number of ways to divide an array a of n integers into any number of disjoint non-empty segments so that, in each segment, there exist at most k distinct integers that appear exactly once. Since the answer can be large, find it modulo 998 244 353. Input The first line contains two space-separated integers n...
#include <bits/stdc++.h> int bb[1 + 100000], dp[1 + 100000], ss[((100000 + 500 - 1) / 500)], dq[((100000 + 500 - 1) / 500)][500 + 1 + 500]; void update(int h) { int *qq = dq[h]; int i, t, c; t = 0; memset(qq, 0, (500 + 1 + 500) * sizeof *qq); for (i = (h + 1) * 500; i > h * 500; i--) { t += bb[i]; ...
2C++
{ "input": [ "5 5\n1 2 3 4 5\n", "3 1\n1 1 2\n", "5 2\n1 1 2 1 3\n", "50 1\n50 8 46 9 12 38 41 18 49 10 23 15 16 3 13 17 48 8 31 32 6 31 31 49 9 40 9 21 23 41 17 31 45 47 17 1 12 15 50 40 38 4 20 1 9 37 4 47 4 24\n", "100 30\n31 57 26 94 41 92 88 4 46 51 64 45 89 59 91 49 3 28 17 63 9 74 77 60 83 ...
2CODEFORCES
1129_D. Isolation_22
Find the number of ways to divide an array a of n integers into any number of disjoint non-empty segments so that, in each segment, there exist at most k distinct integers that appear exactly once. Since the answer can be large, find it modulo 998 244 353. Input The first line contains two space-separated integers n...
import java.io.*; import java.util.*; public class CF1129D { static final int MD = 998244353, A = 100000, B = 500; static int[] bb, dp, ss; static int[][] dq; static void update(int h) { int[] qq = dq[h]; Arrays.fill(qq, 0); int t = 0; for (int i = (h + 1) * B; i > h * B; i--) { t += bb[i]; qq[B + t...
4JAVA
{ "input": [ "5 5\n1 2 3 4 5\n", "3 1\n1 1 2\n", "5 2\n1 1 2 1 3\n", "50 1\n50 8 46 9 12 38 41 18 49 10 23 15 16 3 13 17 48 8 31 32 6 31 31 49 9 40 9 21 23 41 17 31 45 47 17 1 12 15 50 40 38 4 20 1 9 37 4 47 4 24\n", "100 30\n31 57 26 94 41 92 88 4 46 51 64 45 89 59 91 49 3 28 17 63 9 74 77 60 83 ...
2CODEFORCES
1149_E. Election Promises_23
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, co...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 100; int n, m, h[N], lev[N], Xor[N], cnt[N], deg[N]; vector<int> nxt[N], rnxt[N], vec[N]; set<int> s; queue<int> q; int main() { cin >> n >> m; for (int i = 1; i <= n; ++i) cin >> h[i]; for (int i = 1; i <= m; ++i) { int x, y; cin >> x >> y...
2C++
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n", "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 ...
2CODEFORCES
1149_E. Election Promises_24
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, co...
import java.io.*; import java.util.*; import java.math.*; import java.lang.*; import static java.lang.Math.*; public class Main implements Runnable { static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numCh...
4JAVA
{ "input": [ "6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n", "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 ...
2CODEFORCES
1189_D1. Add on a Tree_25
Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You are given a tree with n nodes. In the beginning, 0 is written on all edges. In one operation, you can choose any 2 distinct leaves u, v and any real number x and add x to values written on al...
v = int(raw_input()) adj = [] for k in xrange(v): adj.append([]) for i in xrange(v-1): a, b = map(int, raw_input().split()) adj[a-1].append(b) adj[b-1].append(a) for k in xrange(v): if len(adj[k]) == 2: print "NO" exit() print "YES"
1Python2
{ "input": [ "2\n1 2\n", "3\n1 2\n2 3\n", "5\n1 2\n1 3\n1 4\n2 5\n", "6\n1 2\n1 3\n1 4\n2 5\n2 6\n", "50\n16 4\n17 9\n31 19\n22 10\n8 1\n40 30\n3 31\n20 29\n47 27\n22 25\n32 34\n12 15\n40 32\n10 33\n47 12\n6 24\n46 41\n14 23\n12 35\n31 42\n46 28\n31 20\n46 37\n1 39\n29 49\n37 47\n40 6\n42 36\n47 2...
2CODEFORCES
1189_D1. Add on a Tree_26
Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You are given a tree with n nodes. In the beginning, 0 is written on all edges. In one operation, you can choose any 2 distinct leaves u, v and any real number x and add x to values written on al...
#include <bits/stdc++.h> using namespace std; void pr_init() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } vector<vector<long long> > tree; vector<long long> deg; void solve() { long long n; cin >> n; tree.assign(n + 1, vector<long long>()); deg.assign(n + 1, 0); for (long long i = 0; i < n...
2C++
{ "input": [ "2\n1 2\n", "3\n1 2\n2 3\n", "5\n1 2\n1 3\n1 4\n2 5\n", "6\n1 2\n1 3\n1 4\n2 5\n2 6\n", "50\n16 4\n17 9\n31 19\n22 10\n8 1\n40 30\n3 31\n20 29\n47 27\n22 25\n32 34\n12 15\n40 32\n10 33\n47 12\n6 24\n46 41\n14 23\n12 35\n31 42\n46 28\n31 20\n46 37\n1 39\n29 49\n37 47\n40 6\n42 36\n47 2...
2CODEFORCES
1189_D1. Add on a Tree_27
Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You are given a tree with n nodes. In the beginning, 0 is written on all edges. In one operation, you can choose any 2 distinct leaves u, v and any real number x and add x to values written on al...
m = int(input()) l = [0 for _ in range(m + 1)] for _ in range(m - 1): a,b = map(int, input().split()) l[a] += 1 l[b] += 1 if 2 in l: print("NO") else: print("YES")
3Python3
{ "input": [ "2\n1 2\n", "3\n1 2\n2 3\n", "5\n1 2\n1 3\n1 4\n2 5\n", "6\n1 2\n1 3\n1 4\n2 5\n2 6\n", "50\n16 4\n17 9\n31 19\n22 10\n8 1\n40 30\n3 31\n20 29\n47 27\n22 25\n32 34\n12 15\n40 32\n10 33\n47 12\n6 24\n46 41\n14 23\n12 35\n31 42\n46 28\n31 20\n46 37\n1 39\n29 49\n37 47\n40 6\n42 36\n47 2...
2CODEFORCES
1189_D1. Add on a Tree_28
Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You are given a tree with n nodes. In the beginning, 0 is written on all edges. In one operation, you can choose any 2 distinct leaves u, v and any real number x and add x to values written on al...
import java.io.*; import java.util.ArrayList; import java.util.StringTokenizer; public class D1_AddOnATree { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader inp = new InputReader(inputStream); PrintWr...
4JAVA
{ "input": [ "2\n1 2\n", "3\n1 2\n2 3\n", "5\n1 2\n1 3\n1 4\n2 5\n", "6\n1 2\n1 3\n1 4\n2 5\n2 6\n", "50\n16 4\n17 9\n31 19\n22 10\n8 1\n40 30\n3 31\n20 29\n47 27\n22 25\n32 34\n12 15\n40 32\n10 33\n47 12\n6 24\n46 41\n14 23\n12 35\n31 42\n46 28\n31 20\n46 37\n1 39\n29 49\n37 47\n40 6\n42 36\n47 2...
2CODEFORCES
1208_D. Restore Permutation_29
An array of integers p_{1},p_{2}, …,p_{n} is called a permutation if it contains each number from 1 to n exactly once. For example, the following arrays are permutations: [3,1,2], [1], [1,2,3,4,5] and [4,3,1,2]. The following arrays are not permutations: [2], [1,1], [2,3,4]. There is a hidden permutation of length n. ...
def bsearch(k,tree,n): low = 1 high = n cnt = 0 while low <= high: mid = (low+high)/2 tmp1 = sum(tree,mid-1) tmp2 = sum(tree,mid) s = mid*(mid-1)/2 if k+tmp2 == s and tmp1 == tmp2: break elif k+tmp1 <s: high = mid-1 else: low = mid +1 return mid def lowbit(x): return x&-x def add(t,i,...
1Python2
{ "input": [ "3\n0 0 0\n", "5\n0 1 1 1 10\n", "2\n0 1\n", "100\n0 0 57 121 57 0 19 251 19 301 19 160 57 578 664 57 19 50 0 621 91 5 263 34 5 96 713 649 22 22 22 5 108 198 1412 1147 84 1326 1777 0 1780 132 2000 479 1314 525 68 690 1689 1431 1288 54 1514 1593 1037 1655 807 465 1674 1747 1982 423 837 139...
2CODEFORCES
1208_D. Restore Permutation_30
An array of integers p_{1},p_{2}, …,p_{n} is called a permutation if it contains each number from 1 to n exactly once. For example, the following arrays are permutations: [3,1,2], [1], [1,2,3,4,5] and [4,3,1,2]. The following arrays are not permutations: [2], [1,1], [2,3,4]. There is a hidden permutation of length n. ...
#include <bits/stdc++.h> using namespace std; const long long maxN = 2 * 100224; struct BIT { long long data[maxN] = {0}; void update(long long idx, long long val) { while (idx < maxN) { data[idx] += val; idx += idx & -idx; } } void update(long long l, long long r, long long val) { updat...
2C++
{ "input": [ "3\n0 0 0\n", "5\n0 1 1 1 10\n", "2\n0 1\n", "100\n0 0 57 121 57 0 19 251 19 301 19 160 57 578 664 57 19 50 0 621 91 5 263 34 5 96 713 649 22 22 22 5 108 198 1412 1147 84 1326 1777 0 1780 132 2000 479 1314 525 68 690 1689 1431 1288 54 1514 1593 1037 1655 807 465 1674 1747 1982 423 837 139...
2CODEFORCES
1208_D. Restore Permutation_31
An array of integers p_{1},p_{2}, …,p_{n} is called a permutation if it contains each number from 1 to n exactly once. For example, the following arrays are permutations: [3,1,2], [1], [1,2,3,4,5] and [4,3,1,2]. The following arrays are not permutations: [2], [1,1], [2,3,4]. There is a hidden permutation of length n. ...
from sys import stdin,stdout class Tree(object): def __init__(self,n): self.tree=[0]*(4*n+10) self.b=[0]*(n+10) self.a=list(map(int,stdin.readline().split())) self.n=n def update(self,L,C,l,r,rt): if l==r: self.tree[rt]+=C return mid=(l+r)...
3Python3
{ "input": [ "3\n0 0 0\n", "5\n0 1 1 1 10\n", "2\n0 1\n", "100\n0 0 57 121 57 0 19 251 19 301 19 160 57 578 664 57 19 50 0 621 91 5 263 34 5 96 713 649 22 22 22 5 108 198 1412 1147 84 1326 1777 0 1780 132 2000 479 1314 525 68 690 1689 1431 1288 54 1514 1593 1037 1655 807 465 1674 1747 1982 423 837 139...
2CODEFORCES
1208_D. Restore Permutation_32
An array of integers p_{1},p_{2}, …,p_{n} is called a permutation if it contains each number from 1 to n exactly once. For example, the following arrays are permutations: [3,1,2], [1], [1,2,3,4,5] and [4,3,1,2]. The following arrays are not permutations: [2], [1,1], [2,3,4]. There is a hidden permutation of length n. ...
import java.util.*; import java.io.*; import java.math.*; public class Solution{ public static long[] bit; public static int n; public static long ver(int c,long sum){ long r =(long) c*(long)(c-1); r/=(long)2; return sum-r; } public static void update(int x,long val){ ...
4JAVA
{ "input": [ "3\n0 0 0\n", "5\n0 1 1 1 10\n", "2\n0 1\n", "100\n0 0 57 121 57 0 19 251 19 301 19 160 57 578 664 57 19 50 0 621 91 5 263 34 5 96 713 649 22 22 22 5 108 198 1412 1147 84 1326 1777 0 1780 132 2000 479 1314 525 68 690 1689 1431 1288 54 1514 1593 1037 1655 807 465 1674 1747 1982 423 837 139...
2CODEFORCES
1227_D1. Optimal Subsequences (Easy Version)_33
This is the easier version of the problem. In this version 1 ≤ n, m ≤ 100. You can hack this problem only if you solve and lock both problems. You are given a sequence of integers a=[a_1,a_2,...,a_n] of length n. Its subsequence is obtained by removing zero or more elements from the sequence a (they do not necessarily...
#include <bits/stdc++.h> using namespace std; int main(int argc, const char* argv[]) { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; ++i) { cin >> v[i]; } vector<int> v2 = v; sort(v.rbegin(), v.rend()); int m; cin >> m; for (int i = 0; i < m; ++i) { int k, ind; cin >> k >> in...
2C++
{ "input": [ "3\n10 20 10\n6\n1 1\n2 1\n2 2\n3 1\n3 2\n3 3\n", "7\n1 2 1 3 1 2 1\n9\n2 1\n2 2\n3 1\n3 2\n3 3\n1 1\n7 1\n7 7\n7 4\n", "2\n1 10\n3\n2 2\n2 1\n1 1\n", "2\n3922 3922\n3\n2 2\n2 1\n1 1\n", "1\n1000000000\n1\n1 1\n", "1\n1\n3\n1 1\n1 1\n1 1\n", "5\n3 1 4 1 2\n15\n5 5\n5 4\n5 3\n5...
2CODEFORCES
1227_D1. Optimal Subsequences (Easy Version)_34
This is the easier version of the problem. In this version 1 ≤ n, m ≤ 100. You can hack this problem only if you solve and lock both problems. You are given a sequence of integers a=[a_1,a_2,...,a_n] of length n. Its subsequence is obtained by removing zero or more elements from the sequence a (they do not necessarily...
# class SegmentTree(): # adapted from https://www.geeksforgeeks.org/segment-tree-efficient-implementation/ # def __init__(self,arr,func,initialRes=0): # self.f=func # self.N=len(arr) # self.tree=[0 for _ in range(2*self.N)] # self.initialRes=initialRes # for i in range(self....
3Python3
{ "input": [ "3\n10 20 10\n6\n1 1\n2 1\n2 2\n3 1\n3 2\n3 3\n", "7\n1 2 1 3 1 2 1\n9\n2 1\n2 2\n3 1\n3 2\n3 3\n1 1\n7 1\n7 7\n7 4\n", "2\n1 10\n3\n2 2\n2 1\n1 1\n", "2\n3922 3922\n3\n2 2\n2 1\n1 1\n", "1\n1000000000\n1\n1 1\n", "1\n1\n3\n1 1\n1 1\n1 1\n", "5\n3 1 4 1 2\n15\n5 5\n5 4\n5 3\n5...
2CODEFORCES
1227_D1. Optimal Subsequences (Easy Version)_35
This is the easier version of the problem. In this version 1 ≤ n, m ≤ 100. You can hack this problem only if you solve and lock both problems. You are given a sequence of integers a=[a_1,a_2,...,a_n] of length n. Its subsequence is obtained by removing zero or more elements from the sequence a (they do not necessarily...
import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.*; import java.io.*; import java.math.*; public class Main { InputStream is; PrintWriter out; String INPUT = ""; //class Declaration static class pair implement...
4JAVA
{ "input": [ "3\n10 20 10\n6\n1 1\n2 1\n2 2\n3 1\n3 2\n3 3\n", "7\n1 2 1 3 1 2 1\n9\n2 1\n2 2\n3 1\n3 2\n3 3\n1 1\n7 1\n7 7\n7 4\n", "2\n1 10\n3\n2 2\n2 1\n1 1\n", "2\n3922 3922\n3\n2 2\n2 1\n1 1\n", "1\n1000000000\n1\n1 1\n", "1\n1\n3\n1 1\n1 1\n1 1\n", "5\n3 1 4 1 2\n15\n5 5\n5 4\n5 3\n5...
2CODEFORCES
1269_E. K Integers_36
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
n = input() arr = map(int,raw_input().split(" ")) trees = [0]*(1+n) dic = [0]*(n+1) ans = [0]*n def update(t,i,v): while i < len(t): t[i] += v i += lowbit(i) def lowbit(x): return x&-x def sum(t,i): ans = 0 while i>0: ans += t[i] ...
1Python2
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n", "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 8...
2CODEFORCES
1269_E. K Integers_37
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const int mod = 1e9 + 7; int head[N]; int dis[N], ecnt; int fa[N]; int cat[2005][2005]; long long gcd(long long a, long long b) { return a % b == 0 ? b : gcd(b, a % b); } long long qpow(long long base, long long n) { long long ans = 1; while (n...
2C++
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n", "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 8...
2CODEFORCES
1269_E. K Integers_38
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
n = int(input()) a = [0] + list(map(int, input().split())) pos, pb, ps = [[0] * (n + 1) for x in range(3)] def add(bit, i, val): while i <= n: bit[i] += val i += i & -i def sum(bit, i): res = 0 while i > 0: res += bit[i] i -= i & -i return res def find(bit, sum): ...
3Python3
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n", "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 8...
2CODEFORCES
1269_E. K Integers_39
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
import java.io.*; import java.util.*; public class Contest1 { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////...
4JAVA
{ "input": [ "3\n1 2 3\n", "5\n5 4 3 2 1\n", "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 8...
2CODEFORCES
1291_E. Prefix Enlightenment_40
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≤ i_1 < i_2 < i_3 ≤ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = ∅. In one operation, you ...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; int n, k; char s[maxn]; int pre[maxn << 1], sz[maxn << 1]; vector<int> op[maxn]; int find(int x) { return x == pre[x] ? x : pre[x] = find(pre[x]); } void merge(int x, int y) { int fx = find(x), fy = find(y); if (fy == 0) swap(fx, fy); if (fx...
2C++
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n", "1 1\n1\n1\n1\n", "5 3\n00011\n3\n1 2 3...
2CODEFORCES
1291_E. Prefix Enlightenment_41
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≤ i_1 < i_2 < i_3 ≤ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = ∅. In one operation, you ...
from sys import stdin input = stdin.readline n , k = [int(i) for i in input().split()] pairs = [i + k for i in range(k)] + [i for i in range(k)] initial_condition = list(map(lambda x: x == '1',input().strip())) data = [i for i in range(2*k)] constrain = [-1] * (2*k) h = [0] * (2*k) L = [1] * k + [0] * k dp1 = [-1 for...
3Python3
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n", "1 1\n1\n1\n1\n", "5 3\n00011\n3\n1 2 3...
2CODEFORCES
1291_E. Prefix Enlightenment_42
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≤ i_1 < i_2 < i_3 ≤ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = ∅. In one operation, you ...
import java.io.*; import java.lang.Math; import java.util.*; public class Main { public BufferedReader in; public PrintStream out; public boolean log_enabled = false; public boolean multiply_tests = false; public static boolean do_gen_test = false; public void gen_test() { ...
4JAVA
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n", "1 1\n1\n1\n1\n", "5 3\n00011\n3\n1 2 3...
2CODEFORCES
1311_F. Moving Points_43
There are n points on a coordinate axis OX. The i-th point is located at the integer point x_i and has a speed v_i. It is guaranteed that no two points occupy the same coordinate. All n points move with the constant speed, the coordinate of the i-th point at the moment t (t can be non-integer) is calculated as x_i + t ...
import sys from collections import defaultdict range = xrange input = raw_input class segtree: def __init__(self, n): m = 1 while m < n: m *= 2 self.m = m self.data1 = [0.0]*(m + m) self.data2 = [0]*(m + m) def add(self, i, val): i += self.m while i: ...
1Python2
{ "input": [ "3\n1 3 2\n-100 2 3\n", "2\n2 1\n-3 0\n", "5\n2 1 4 3 5\n2 2 2 3 4\n", "3\n1 3 2\n-100 2 6\n", "2\n2 1\n-4 0\n", "2\n0 1\n-4 0\n", "2\n0 2\n-4 0\n", "3\n1 5 2\n-167 2 6\n", "3\n1 3 2\n-75 1 0\n", "3\n1 7 2\n-255 0 6\n", "3\n1 3 8\n-75 1 0\n", "3\n1 3 8\n-75...
2CODEFORCES
1311_F. Moving Points_44
There are n points on a coordinate axis OX. The i-th point is located at the integer point x_i and has a speed v_i. It is guaranteed that no two points occupy the same coordinate. All n points move with the constant speed, the coordinate of the i-th point at the moment t (t can be non-integer) is calculated as x_i + t ...
#include <bits/stdc++.h> using namespace std; struct FenwickTree { int n; vector<long long> num; FenwickTree() : n(0) {} FenwickTree(int _n) { n = _n; num.assign(n, 0); } void add(int i, int val) { for (; i < n; i |= i + 1) num[i] += val; } long long sum(int i) { long long ret = 0; f...
2C++
{ "input": [ "3\n1 3 2\n-100 2 3\n", "2\n2 1\n-3 0\n", "5\n2 1 4 3 5\n2 2 2 3 4\n", "3\n1 3 2\n-100 2 6\n", "2\n2 1\n-4 0\n", "2\n0 1\n-4 0\n", "2\n0 2\n-4 0\n", "3\n1 5 2\n-167 2 6\n", "3\n1 3 2\n-75 1 0\n", "3\n1 7 2\n-255 0 6\n", "3\n1 3 8\n-75 1 0\n", "3\n1 3 8\n-75...
2CODEFORCES
1311_F. Moving Points_45
There are n points on a coordinate axis OX. The i-th point is located at the integer point x_i and has a speed v_i. It is guaranteed that no two points occupy the same coordinate. All n points move with the constant speed, the coordinate of the i-th point at the moment t (t can be non-integer) is calculated as x_i + t ...
import bisect def getsum(tree , i): s = 0 i += 1 while i>0: s += tree[i] i -= i & (-i) return s def updatebit(tree , n , i , v): i+= 1 while i <= n: tree[i] += v i += i & (-i) n = int(input()) x = list(map(int , input().split())) v = list(map(int , input().spli...
3Python3
{ "input": [ "3\n1 3 2\n-100 2 3\n", "2\n2 1\n-3 0\n", "5\n2 1 4 3 5\n2 2 2 3 4\n", "3\n1 3 2\n-100 2 6\n", "2\n2 1\n-4 0\n", "2\n0 1\n-4 0\n", "2\n0 2\n-4 0\n", "3\n1 5 2\n-167 2 6\n", "3\n1 3 2\n-75 1 0\n", "3\n1 7 2\n-255 0 6\n", "3\n1 3 8\n-75 1 0\n", "3\n1 3 8\n-75...
2CODEFORCES
1311_F. Moving Points_46
There are n points on a coordinate axis OX. The i-th point is located at the integer point x_i and has a speed v_i. It is guaranteed that no two points occupy the same coordinate. All n points move with the constant speed, the coordinate of the i-th point at the moment t (t can be non-integer) is calculated as x_i + t ...
// Don't place your source in a package import java.util.*; import java.lang.*; import java.io.*; import java.math.*; /* 6666666666666 6666666666666 6 6 6 6 6 6 6 6 ...
4JAVA
{ "input": [ "3\n1 3 2\n-100 2 3\n", "2\n2 1\n-3 0\n", "5\n2 1 4 3 5\n2 2 2 3 4\n", "3\n1 3 2\n-100 2 6\n", "2\n2 1\n-4 0\n", "2\n0 1\n-4 0\n", "2\n0 2\n-4 0\n", "3\n1 5 2\n-167 2 6\n", "3\n1 3 2\n-75 1 0\n", "3\n1 7 2\n-255 0 6\n", "3\n1 3 8\n-75 1 0\n", "3\n1 3 8\n-75...
2CODEFORCES
1334_D. Minimum Euler Cycle_47
You are given a complete directed graph K_n with n vertices: each pair of vertices u ≠ v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of...
'''input 3 2 1 3 3 3 6 99995 9998900031 9998900031 ''' import sys import math from collections import Counter debug = 1 readln = sys.stdin.readline #sys.setrecursionlimit(1000000) def write(s): sys.stdout.write(str(s)) def writeln(s): sys.stdout.write(str(s)) sys.stdout.write('\n') def readint(): r...
1Python2
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n", "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",...
2CODEFORCES
1334_D. Minimum Euler Cycle_48
You are given a complete directed graph K_n with n vertices: each pair of vertices u ≠ v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of...
#include <bits/stdc++.h> using namespace std; long long n; int tc = 0; int solve(); int main() { ios_base::sync_with_stdio(0); if (tc < 0) { cout << "TC!\n"; cin.ignore(1e8); } else if (!tc) cin >> tc; while (tc--) solve(); return 0; } int solve() { long long l, r; cin >> n >> l >> r; l--; ...
2C++
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n", "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",...
2CODEFORCES
1334_D. Minimum Euler Cycle_49
You are given a complete directed graph K_n with n vertices: each pair of vertices u ≠ v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of...
# -*- coding:utf-8 -*- """ created by shuangquan.huang at 2020/7/1 """ import collections import time import os import sys import bisect import heapq from typing import List def solve(n, l, r): # 1, 2, 1, 3, ..., 1, n # 2, 3, 2, 4, ..., 2, n # ... # n-1, n # 1 lo, hi = 1, n while...
3Python3
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n", "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",...
2CODEFORCES
1334_D. Minimum Euler Cycle_50
You are given a complete directed graph K_n with n vertices: each pair of vertices u ≠ v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of...
import java.io.*; import java.util.*; public class D { PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tok; HashMap<List<Long>, Long> map = new HashMap<>(); public v...
4JAVA
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n", "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",...
2CODEFORCES
1354_F. Summoning Minions_51
Polycarp plays a computer game. In this game, the players summon armies of magical minions, which then fight each other. Polycarp can summon n different minions. The initial power level of the i-th minion is a_i, and when it is summoned, all previously summoned minions' power levels are increased by b_i. The minions c...
#include <bits/stdc++.h> using namespace std; struct Edge { long long to, dis, next, cost; } edge[24050]; long long num = -1; bool vis[10010]; long long mincost; long long pre[10010], head[10010], cost[10010], last[10010], flow[10010], n, k, a[110], b[110], s, t, maxflow; long long to[110]; void add(long long f, ...
2C++
{ "input": [ "3\n5 2\n5 3\n7 0\n5 0\n4 0\n10 0\n2 1\n10 100\n50 10\n5 5\n1 5\n2 4\n3 3\n4 2\n5 1\n", "3\n5 2\n5 3\n7 0\n5 0\n4 0\n10 0\n2 1\n10 100\n50 10\n5 5\n1 5\n2 4\n3 3\n4 2\n5 1\n", "3\n5 2\n5 3\n7 0\n5 0\n4 0\n10 0\n2 1\n10 100\n8 10\n5 5\n1 5\n2 4\n3 3\n4 2\n5 1\n", "3\n5 2\n5 3\n7 0\n1 0\n4 ...
2CODEFORCES
1354_F. Summoning Minions_52
Polycarp plays a computer game. In this game, the players summon armies of magical minions, which then fight each other. Polycarp can summon n different minions. The initial power level of the i-th minion is a_i, and when it is summoned, all previously summoned minions' power levels are increased by b_i. The minions c...
from sys import stdin, gettrace from heapq import nlargest if not gettrace(): def input(): return next(stdin)[:-1] # def input(): # return stdin.buffer.readline() INF = int(10E10) def main(): def solve(): n, k = map(int, input().split()) mm = [] for i in range(1,n+1): ...
3Python3
{ "input": [ "3\n5 2\n5 3\n7 0\n5 0\n4 0\n10 0\n2 1\n10 100\n50 10\n5 5\n1 5\n2 4\n3 3\n4 2\n5 1\n", "3\n5 2\n5 3\n7 0\n5 0\n4 0\n10 0\n2 1\n10 100\n50 10\n5 5\n1 5\n2 4\n3 3\n4 2\n5 1\n", "3\n5 2\n5 3\n7 0\n5 0\n4 0\n10 0\n2 1\n10 100\n8 10\n5 5\n1 5\n2 4\n3 3\n4 2\n5 1\n", "3\n5 2\n5 3\n7 0\n1 0\n4 ...
2CODEFORCES
1354_F. Summoning Minions_53
Polycarp plays a computer game. In this game, the players summon armies of magical minions, which then fight each other. Polycarp can summon n different minions. The initial power level of the i-th minion is a_i, and when it is summoned, all previously summoned minions' power levels are increased by b_i. The minions c...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.util.stream.IntStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.IOException; import java.util.s...
4JAVA
{ "input": [ "3\n5 2\n5 3\n7 0\n5 0\n4 0\n10 0\n2 1\n10 100\n50 10\n5 5\n1 5\n2 4\n3 3\n4 2\n5 1\n", "3\n5 2\n5 3\n7 0\n5 0\n4 0\n10 0\n2 1\n10 100\n50 10\n5 5\n1 5\n2 4\n3 3\n4 2\n5 1\n", "3\n5 2\n5 3\n7 0\n5 0\n4 0\n10 0\n2 1\n10 100\n8 10\n5 5\n1 5\n2 4\n3 3\n4 2\n5 1\n", "3\n5 2\n5 3\n7 0\n1 0\n4 ...
2CODEFORCES
1374_E1. Reading Books (easy version)_54
Easy and hard versions are actually different problems, so read statements of both problems completely and carefully. Summer vacation has started so Alice and Bob want to play and joy, but... Their mom doesn't think so. She says that they have to read some amount of books before all entertainments. Alice and Bob will ...
input = raw_input range = xrange import sys inp = [int(x) for x in sys.stdin.read().split()]; ii = 0 seg = [0]*200000 def offset(x): return x + 100000 def encode(x, y): return (x<<20) + y def upd(node, L, R, pos, val): if L+1 == R: seg[node] += val seg[offset(node)] = seg[node]*L return M = (L+R)>>1 if po...
1Python2
{ "input": [ "8 4\n7 1 1\n2 1 1\n4 0 1\n8 1 1\n1 0 1\n1 1 1\n1 0 1\n3 0 0\n", "5 2\n6 0 0\n9 0 0\n1 0 1\n2 1 1\n5 1 0\n", "5 3\n3 0 0\n2 1 0\n3 1 0\n5 0 1\n3 0 1\n", "2 1\n7 1 1\n2 1 1\n", "5 1\n2 1 0\n2 0 1\n1 0 1\n1 1 0\n1 0 1\n", "6 2\n6 0 0\n11 1 0\n9 0 1\n21 1 1\n10 1 0\n8 0 1\n", "3 ...
2CODEFORCES
1374_E1. Reading Books (easy version)_55
Easy and hard versions are actually different problems, so read statements of both problems completely and carefully. Summer vacation has started so Alice and Bob want to play and joy, but... Their mom doesn't think so. She says that they have to read some amount of books before all entertainments. Alice and Bob will ...
#include <bits/stdc++.h> using namespace std; template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>; int n, k, a, b; long long t; vector<long long> ve[2][2]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> k; for (int i = (0); i < (n); i++) { cin >> t >> a >> b; ...
2C++
{ "input": [ "8 4\n7 1 1\n2 1 1\n4 0 1\n8 1 1\n1 0 1\n1 1 1\n1 0 1\n3 0 0\n", "5 2\n6 0 0\n9 0 0\n1 0 1\n2 1 1\n5 1 0\n", "5 3\n3 0 0\n2 1 0\n3 1 0\n5 0 1\n3 0 1\n", "2 1\n7 1 1\n2 1 1\n", "5 1\n2 1 0\n2 0 1\n1 0 1\n1 1 0\n1 0 1\n", "6 2\n6 0 0\n11 1 0\n9 0 1\n21 1 1\n10 1 0\n8 0 1\n", "3 ...
2CODEFORCES
1374_E1. Reading Books (easy version)_56
Easy and hard versions are actually different problems, so read statements of both problems completely and carefully. Summer vacation has started so Alice and Bob want to play and joy, but... Their mom doesn't think so. She says that they have to read some amount of books before all entertainments. Alice and Bob will ...
import sys input=sys.stdin.readline f=lambda :list(map(int, input().strip('\n').split())) n, k=f() _11=[] _01=[] _10=[] for _ in range(n): t, a, b=f() if a and b: _11.append(t) elif a: _10.append(t) elif b: _01.append(t) _01.sort(); _10.sort(); _11.sort() for i in range(1, len(_01)): _01[i]+=_01[i-1] for i ...
3Python3
{ "input": [ "8 4\n7 1 1\n2 1 1\n4 0 1\n8 1 1\n1 0 1\n1 1 1\n1 0 1\n3 0 0\n", "5 2\n6 0 0\n9 0 0\n1 0 1\n2 1 1\n5 1 0\n", "5 3\n3 0 0\n2 1 0\n3 1 0\n5 0 1\n3 0 1\n", "2 1\n7 1 1\n2 1 1\n", "5 1\n2 1 0\n2 0 1\n1 0 1\n1 1 0\n1 0 1\n", "6 2\n6 0 0\n11 1 0\n9 0 1\n21 1 1\n10 1 0\n8 0 1\n", "3 ...
2CODEFORCES
1374_E1. Reading Books (easy version)_57
Easy and hard versions are actually different problems, so read statements of both problems completely and carefully. Summer vacation has started so Alice and Bob want to play and joy, but... Their mom doesn't think so. She says that they have to read some amount of books before all entertainments. Alice and Bob will ...
import java.io.*; import java.util.*; public class Codeforces { public static void main(String args[])throws Exception { BufferedReader bu=new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb=new StringBuilder(); String s[]=bu.readLine().split(" "); int n=Integ...
4JAVA
{ "input": [ "8 4\n7 1 1\n2 1 1\n4 0 1\n8 1 1\n1 0 1\n1 1 1\n1 0 1\n3 0 0\n", "5 2\n6 0 0\n9 0 0\n1 0 1\n2 1 1\n5 1 0\n", "5 3\n3 0 0\n2 1 0\n3 1 0\n5 0 1\n3 0 1\n", "2 1\n7 1 1\n2 1 1\n", "5 1\n2 1 0\n2 0 1\n1 0 1\n1 1 0\n1 0 1\n", "6 2\n6 0 0\n11 1 0\n9 0 1\n21 1 1\n10 1 0\n8 0 1\n", "3 ...
2CODEFORCES
1398_A. Bad Triangle_58
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≤ a_{i + 1}). Find three indices i, j, k such that 1 ≤ i < j < k ≤ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to...
# Author: yumtam # Created at: 2020-08-27 18:53 from __future__ import division, print_function _interactive = False def main(): for _ in range(int(input())): n = int(input()) ar = input_as_list() a, b, c = ar[0], ar[1], ar[-1] if a + b <= c: print(1, 2, n) ...
1Python2
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n"...
2CODEFORCES
1398_A. Bad Triangle_59
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≤ a_{i + 1}). Find three indices i, j, k such that 1 ≤ i < j < k ≤ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int tt; cin >> tt; while (tt--) { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } if (a[0] + a[1] <= a.back()) { cout << "1 2 " << n << '\n'; ...
2C++
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n"...
2CODEFORCES
1398_A. Bad Triangle_60
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≤ a_{i + 1}). Find three indices i, j, k such that 1 ≤ i < j < k ≤ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to...
t=int(input()) for z in range(t): n=int(input()) arr=list(map(int,input().split())) min= arr[0] + arr[1] pos=True for i in range(2,n): if(arr[i]>=min): pos=False posf=i break if(pos): print("-1") else: print("1 2", posf+1)
3Python3
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n"...
2CODEFORCES
1398_A. Bad Triangle_61
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≤ a_{i + 1}). Find three indices i, j, k such that 1 ≤ i < j < k ≤ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to...
import java.util.*; public class BadTriangle { public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); while (t-- > 0) { int n = s.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; ++i) { a[i] = s.nextInt(); } if (a[n -...
4JAVA
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n"...
2CODEFORCES
1421_B. Putting Bricks in the Wall_62
Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like [walls](https://www.youtube.com/watch?v=YR5ApYxkU-U), he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid. Roger Waters has a square grid of size n× n and he wants to traverse his grid f...
for _ in range(input()): n=input() l=[] for i in range(n): k=raw_input() l.append(k) sq1=l[0][1] sq2=l[1][0] sq3=l[n-1][n-2] sq4=l[n-2][n-1] switch=[] if sq1==sq2: if sq3==sq1: switch.append([n,n-1]) if sq4==sq1: switch.append([...
1Python2
{ "input": [ "3\n4\nS010\n0001\n1000\n111F\n3\nS10\n101\n01F\n5\nS0101\n00000\n01111\n11111\n0001F\n", "1\n3\nS01\n111\n00F\n", "1\n5\nS0000\n00000\n00000\n00000\n0000F\n", "1\n3\nS10\n010\n11F\n", "1\n3\nS11\n011\n01F\n", "1\n3\nS10\n010\n01F\n", "1\n10\nS000000000\n0000000000\n0000000000...
2CODEFORCES
1421_B. Putting Bricks in the Wall_63
Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like [walls](https://www.youtube.com/watch?v=YR5ApYxkU-U), he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid. Roger Waters has a square grid of size n× n and he wants to traverse his grid f...
#include <bits/stdc++.h> using namespace std; const int inf = INT_MAX; const long long int inf64 = LLONG_MAX; vector<string> vect; long long int n; vector<pair<int, int> > d4{{-1, 0}, {1, 0}, {0, 1}, {0, -1}}; bool good(long long int xx, long long int yy) { return (xx < n and xx >= 0 and yy < n and yy >= 0); } int ma...
2C++
{ "input": [ "3\n4\nS010\n0001\n1000\n111F\n3\nS10\n101\n01F\n5\nS0101\n00000\n01111\n11111\n0001F\n", "1\n3\nS01\n111\n00F\n", "1\n5\nS0000\n00000\n00000\n00000\n0000F\n", "1\n3\nS10\n010\n11F\n", "1\n3\nS11\n011\n01F\n", "1\n3\nS10\n010\n01F\n", "1\n10\nS000000000\n0000000000\n0000000000...
2CODEFORCES
1421_B. Putting Bricks in the Wall_64
Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like [walls](https://www.youtube.com/watch?v=YR5ApYxkU-U), he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid. Roger Waters has a square grid of size n× n and he wants to traverse his grid f...
l=[] for _ in range(int(input())): n=int(input()) a=[] for i in range(n): a.append(list(input())) if a[0][1]==a[1][0]: if a[n-1][n-2]==a[n-2][n-1]: if a[n-1][n-2]==a[0][1]: l.append("2") l.append("1 2") l.append("2 1") ...
3Python3
{ "input": [ "3\n4\nS010\n0001\n1000\n111F\n3\nS10\n101\n01F\n5\nS0101\n00000\n01111\n11111\n0001F\n", "1\n3\nS01\n111\n00F\n", "1\n5\nS0000\n00000\n00000\n00000\n0000F\n", "1\n3\nS10\n010\n11F\n", "1\n3\nS11\n011\n01F\n", "1\n3\nS10\n010\n01F\n", "1\n10\nS000000000\n0000000000\n0000000000...
2CODEFORCES
1421_B. Putting Bricks in the Wall_65
Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like [walls](https://www.youtube.com/watch?v=YR5ApYxkU-U), he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid. Roger Waters has a square grid of size n× n and he wants to traverse his grid f...
import javax.swing.tree.TreeNode; import java.io.IOException; import java.io.InputStream; import java.util.*; public class TestClass { static final class InputReader { private final InputStream stream; private final byte[] buf = new byte[1024]; private int curChar; private int n...
4JAVA
{ "input": [ "3\n4\nS010\n0001\n1000\n111F\n3\nS10\n101\n01F\n5\nS0101\n00000\n01111\n11111\n0001F\n", "1\n3\nS01\n111\n00F\n", "1\n5\nS0000\n00000\n00000\n00000\n0000F\n", "1\n3\nS10\n010\n11F\n", "1\n3\nS11\n011\n01F\n", "1\n3\nS10\n010\n01F\n", "1\n10\nS000000000\n0000000000\n0000000000...
2CODEFORCES
143_A. Help Vasilisa the Wise 2_66
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with tha...
r, t, c, v, d, f = (int(x) for i in '123' for x in raw_input().split()) w, x, y, z = r+c-f, r+v-d, t+c-d, t+v-f print -1 if len(set([w,x,y,z])) < 4 or any(n%2 or n<2 or n>18 for n in [w,x,y,z]) \ else "%d %d\n%d %d" % (w/2, x/2, y/2, z/2)
1Python2
{ "input": [ "1 2\n3 4\n5 6\n", "11 10\n13 8\n5 16\n", "3 7\n4 6\n5 5\n", "10 10\n10 10\n10 10\n", "3 14\n8 9\n10 7\n", "12 11\n11 12\n16 7\n", "12 17\n10 19\n13 16\n", "9 12\n3 17\n10 10\n", "10 7\n4 13\n11 6\n", "7 9\n4 12\n5 11\n", "2 4\n1 5\n3 3\n", "13 8\n15 6\n11 ...
2CODEFORCES
143_A. Help Vasilisa the Wise 2_67
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with tha...
#include <bits/stdc++.h> using namespace std; int main() { short l = 0; bool b = 0; vector<vector<short>> v(3); for (int i = 0; i < 3; i++) for (int j = 0; j < 2; j++) { cin >> l; v[i].push_back(l); } short x = (v[2][1] - v[0][1] + v[1][1]) / 2; short a[4]; a[0] = v[0][0] - x; a[1] =...
2C++
{ "input": [ "1 2\n3 4\n5 6\n", "11 10\n13 8\n5 16\n", "3 7\n4 6\n5 5\n", "10 10\n10 10\n10 10\n", "3 14\n8 9\n10 7\n", "12 11\n11 12\n16 7\n", "12 17\n10 19\n13 16\n", "9 12\n3 17\n10 10\n", "10 7\n4 13\n11 6\n", "7 9\n4 12\n5 11\n", "2 4\n1 5\n3 3\n", "13 8\n15 6\n11 ...
2CODEFORCES
143_A. Help Vasilisa the Wise 2_68
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with tha...
inn = list(map(int, input().split(" "))) r1 = inn[0] r2 = inn[1] inn = list(map(int, input().split(" "))) c1 = inn[0] c2 = inn[1] inn = list(map(int, input().split(" "))) d1 = inn[0] d2 = inn[1] x = int((d1+c1-r2)/2) y = int(((2*r1)-d1-c1+r2)/2) a = int(((2*c1)-d1-c1+r2)/2) b = int((r2-(2*c1)+d1+c1)/2) if x == y or x ...
3Python3
{ "input": [ "1 2\n3 4\n5 6\n", "11 10\n13 8\n5 16\n", "3 7\n4 6\n5 5\n", "10 10\n10 10\n10 10\n", "3 14\n8 9\n10 7\n", "12 11\n11 12\n16 7\n", "12 17\n10 19\n13 16\n", "9 12\n3 17\n10 10\n", "10 7\n4 13\n11 6\n", "7 9\n4 12\n5 11\n", "2 4\n1 5\n3 3\n", "13 8\n15 6\n11 ...
2CODEFORCES
143_A. Help Vasilisa the Wise 2_69
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with tha...
import java.util.Scanner; public class HelpVasilisaTheWise { public static void main (String [] args) { Scanner in = new Scanner(System.in); int r1 = in.nextInt(); int r2 = in.nextInt(); int c1 = in.nextInt(); int c2 = in.nextInt(); int d1 = in.nextInt(); int ...
4JAVA
{ "input": [ "1 2\n3 4\n5 6\n", "11 10\n13 8\n5 16\n", "3 7\n4 6\n5 5\n", "10 10\n10 10\n10 10\n", "3 14\n8 9\n10 7\n", "12 11\n11 12\n16 7\n", "12 17\n10 19\n13 16\n", "9 12\n3 17\n10 10\n", "10 7\n4 13\n11 6\n", "7 9\n4 12\n5 11\n", "2 4\n1 5\n3 3\n", "13 8\n15 6\n11 ...
2CODEFORCES
1466_F. Euclid's nightmare_70
You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare. In his bad dream Euclid has a set S of n m-dimensional vectors over the Z_2 field and can perform vector addition on them. In other words h...
# Author: yumtam # Created at: 2020-12-31 01:27 from __future__ import division, print_function _interactive = False def main(): n, m = input_as_list() A = [input_with_offset(-1)[1:] for _ in range(n)] uf = DisjointSetUnion(m) dims = 0 for e in A: if len(e) == 1: x = e[0] ...
1Python2
{ "input": [ "3 2\n1 1\n1 2\n2 2 1\n", "3 5\n2 1 2\n1 3\n1 4\n", "2 3\n2 1 3\n2 1 2\n", "50 5000\n2 35 46\n2 43 92\n2 16 88\n2 67 99\n2 36 93\n2 12 20\n2 33 96\n2 55 82\n2 18 32\n2 48 87\n2 29 83\n2 19 37\n2 68 100\n2 13 76\n2 73 90\n2 25 86\n2 17 61\n2 10 27\n2 70 94\n2 28 41\n2 14 53\n2 15 72\n2 8 9...
2CODEFORCES
1466_F. Euclid's nightmare_71
You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare. In his bad dream Euclid has a set S of n m-dimensional vectors over the Z_2 field and can perform vector addition on them. In other words h...
#include <bits/stdc++.h> #define fst first #define snd second #define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i) #define pb push_back #define ALL(s) s.begin(),s.end() #define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define SZ(s) int(s.size()) using namespace std; typedef long long ll; typedef pair<i...
2C++
{ "input": [ "3 2\n1 1\n1 2\n2 2 1\n", "3 5\n2 1 2\n1 3\n1 4\n", "2 3\n2 1 3\n2 1 2\n", "50 5000\n2 35 46\n2 43 92\n2 16 88\n2 67 99\n2 36 93\n2 12 20\n2 33 96\n2 55 82\n2 18 32\n2 48 87\n2 29 83\n2 19 37\n2 68 100\n2 13 76\n2 73 90\n2 25 86\n2 17 61\n2 10 27\n2 70 94\n2 28 41\n2 14 53\n2 15 72\n2 8 9...
2CODEFORCES
1466_F. Euclid's nightmare_72
You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare. In his bad dream Euclid has a set S of n m-dimensional vectors over the Z_2 field and can perform vector addition on them. In other words h...
import sys input = sys.stdin.buffer.readline def _find(s, u): p = [] while s[u] != u: p.append(u) u = s[u] for v in p: s[v] = u return u def _union(s, u, v): su, sv = _find(s, u), _find(s, v) if su != sv: s[su] = sv return su != sv n, m = map(int, input().split()) s, solo ...
3Python3
{ "input": [ "3 2\n1 1\n1 2\n2 2 1\n", "3 5\n2 1 2\n1 3\n1 4\n", "2 3\n2 1 3\n2 1 2\n", "50 5000\n2 35 46\n2 43 92\n2 16 88\n2 67 99\n2 36 93\n2 12 20\n2 33 96\n2 55 82\n2 18 32\n2 48 87\n2 29 83\n2 19 37\n2 68 100\n2 13 76\n2 73 90\n2 25 86\n2 17 61\n2 10 27\n2 70 94\n2 28 41\n2 14 53\n2 15 72\n2 8 9...
2CODEFORCES
1466_F. Euclid's nightmare_73
You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare. In his bad dream Euclid has a set S of n m-dimensional vectors over the Z_2 field and can perform vector addition on them. In other words h...
import java.util.ArrayList; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.Arrays; import java.util.Random; import java.io.FileWriter; import java.io.PrintWriter; /* Solution Created: 12:06:17...
4JAVA
{ "input": [ "3 2\n1 1\n1 2\n2 2 1\n", "3 5\n2 1 2\n1 3\n1 4\n", "2 3\n2 1 3\n2 1 2\n", "50 5000\n2 35 46\n2 43 92\n2 16 88\n2 67 99\n2 36 93\n2 12 20\n2 33 96\n2 55 82\n2 18 32\n2 48 87\n2 29 83\n2 19 37\n2 68 100\n2 13 76\n2 73 90\n2 25 86\n2 17 61\n2 10 27\n2 70 94\n2 28 41\n2 14 53\n2 15 72\n2 8 9...
2CODEFORCES
1490_G. Old Floppy Drive _74
Polycarp was dismantling his attic and found an old floppy drive on it. A round disc was inserted into the drive with n integers written on it. Polycarp wrote the numbers from the disk into the a array. It turned out that the drive works according to the following algorithm: * the drive takes one positive number x...
from __future__ import division from sys import stdin, stdout from bisect import * from collections import * rstr = lambda: stdin.readline().strip() rstrs = lambda: [str(x) for x in stdin.readline().split()] rstr_2d = lambda n: [rstr() for _ in range(n)] rint = lambda: int(stdin.readline()) rints = lambda: [int(x) for...
1Python2
{ "input": [ "3\n3 3\n1 -3 4\n1 5 2\n2 2\n-2 0\n1 2\n2 2\n0 1\n1 2\n", "3\n3 3\n1 -3 4\n1 5 2\n2 2\n-4 0\n1 2\n2 2\n0 1\n1 2\n", "3\n3 3\n1 -3 4\n1 5 2\n2 2\n-2 0\n1 2\n2 2\n0 2\n1 2\n", "3\n3 3\n2 -3 4\n1 5 2\n2 2\n-4 0\n1 2\n2 2\n0 1\n1 2\n", "3\n3 3\n0 -3 4\n1 5 2\n2 2\n-4 0\n1 1\n2 2\n0 1\n1 2...
2CODEFORCES
1490_G. Old Floppy Drive _75
Polycarp was dismantling his attic and found an old floppy drive on it. A round disc was inserted into the drive with n integers written on it. Polycarp wrote the numbers from the disk into the a array. It turned out that the drive works according to the following algorithm: * the drive takes one positive number x...
#include<iostream> #include<bits/stdc++.h> using namespace std; #define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); typedef int _loop_int; #define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i) #define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i) #define FORR(i,a,b) for(_loop_int i=...
2C++
{ "input": [ "3\n3 3\n1 -3 4\n1 5 2\n2 2\n-2 0\n1 2\n2 2\n0 1\n1 2\n", "3\n3 3\n1 -3 4\n1 5 2\n2 2\n-4 0\n1 2\n2 2\n0 1\n1 2\n", "3\n3 3\n1 -3 4\n1 5 2\n2 2\n-2 0\n1 2\n2 2\n0 2\n1 2\n", "3\n3 3\n2 -3 4\n1 5 2\n2 2\n-4 0\n1 2\n2 2\n0 1\n1 2\n", "3\n3 3\n0 -3 4\n1 5 2\n2 2\n-4 0\n1 1\n2 2\n0 1\n1 2...
2CODEFORCES
1490_G. Old Floppy Drive _76
Polycarp was dismantling his attic and found an old floppy drive on it. A round disc was inserted into the drive with n integers written on it. Polycarp wrote the numbers from the disk into the a array. It turned out that the drive works according to the following algorithm: * the drive takes one positive number x...
def findIndexGE(prefixSumsMax,startSum,query): n=len(prefixSumsMax) b=n i=-1 while b>0: while i+b<n and startSum+prefixSumsMax[i+b]<query: i+=b b//=2 i+=1 return i def main(): t=int(input()) allans=[] for _ in range(t): n,m=readIntArr() ...
3Python3
{ "input": [ "3\n3 3\n1 -3 4\n1 5 2\n2 2\n-2 0\n1 2\n2 2\n0 1\n1 2\n", "3\n3 3\n1 -3 4\n1 5 2\n2 2\n-4 0\n1 2\n2 2\n0 1\n1 2\n", "3\n3 3\n1 -3 4\n1 5 2\n2 2\n-2 0\n1 2\n2 2\n0 2\n1 2\n", "3\n3 3\n2 -3 4\n1 5 2\n2 2\n-4 0\n1 2\n2 2\n0 1\n1 2\n", "3\n3 3\n0 -3 4\n1 5 2\n2 2\n-4 0\n1 1\n2 2\n0 1\n1 2...
2CODEFORCES
1490_G. Old Floppy Drive _77
Polycarp was dismantling his attic and found an old floppy drive on it. A round disc was inserted into the drive with n integers written on it. Polycarp wrote the numbers from the disk into the a array. It turned out that the drive works according to the following algorithm: * the drive takes one positive number x...
/** * Created by Aminul on 2/16/2021. */ import java.io.*; import java.util.*; import static java.lang.Math.*; public class G { public static void main(String[] args) throws Exception { FastReader in = new FastReader(System.in); PrintWriter pw = new PrintWriter(System.out); int test = i...
4JAVA
{ "input": [ "3\n3 3\n1 -3 4\n1 5 2\n2 2\n-2 0\n1 2\n2 2\n0 1\n1 2\n", "3\n3 3\n1 -3 4\n1 5 2\n2 2\n-4 0\n1 2\n2 2\n0 1\n1 2\n", "3\n3 3\n1 -3 4\n1 5 2\n2 2\n-2 0\n1 2\n2 2\n0 2\n1 2\n", "3\n3 3\n2 -3 4\n1 5 2\n2 2\n-4 0\n1 2\n2 2\n0 1\n1 2\n", "3\n3 3\n0 -3 4\n1 5 2\n2 2\n-4 0\n1 1\n2 2\n0 1\n1 2...
2CODEFORCES
1513_C. Add One_78
You are given an integer n. You have to apply m operations to it. In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once. You have to find the length of n after applying m operations. Since...
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": [ "5\n1912 1\n5 6\n999 1\n88 2\n12 100\n", "5\n90 94\n26 25\n64 84\n14 6\n20 96\n", "5\n90 94\n26 25\n64 84\n18 6\n20 96\n", "5\n1912 1\n5 6\n999 1\n88 2\n11 100\n", "5\n90 94\n26 25\n64 84\n22 6\n20 96\n", "5\n1912 1\n5 6\n999 1\n88 2\n6 100\n", "5\n90 113\n26 25\n64 84\n22 6\n...
2CODEFORCES
1513_C. Add One_79
You are given an integer n. You have to apply m operations to it. In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once. You have to find the length of n after applying m operations. Since...
#include <bits/stdc++.h> using namespace std; #define rep(i, a) for (int i = 0; i < (int)(a); i++) #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll typedef long long ll; template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,sz(v))i>>v[j];return i;} template<typename T>string join(const vec...
2C++
{ "input": [ "5\n1912 1\n5 6\n999 1\n88 2\n12 100\n", "5\n90 94\n26 25\n64 84\n14 6\n20 96\n", "5\n90 94\n26 25\n64 84\n18 6\n20 96\n", "5\n1912 1\n5 6\n999 1\n88 2\n11 100\n", "5\n90 94\n26 25\n64 84\n22 6\n20 96\n", "5\n1912 1\n5 6\n999 1\n88 2\n6 100\n", "5\n90 113\n26 25\n64 84\n22 6\n...
2CODEFORCES
1513_C. Add One_80
You are given an integer n. You have to apply m operations to it. In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once. You have to find the length of n after applying m operations. Since...
from os import path import sys,time from math import ceil, floor,gcd,log,log2 ,factorial from collections import defaultdict ,Counter , OrderedDict , deque from heapq import heapify , heappush , heappop from bisect import * # from functools import reduce from operator import mul from itertools import permutations maxx,...
3Python3
{ "input": [ "5\n1912 1\n5 6\n999 1\n88 2\n12 100\n", "5\n90 94\n26 25\n64 84\n14 6\n20 96\n", "5\n90 94\n26 25\n64 84\n18 6\n20 96\n", "5\n1912 1\n5 6\n999 1\n88 2\n11 100\n", "5\n90 94\n26 25\n64 84\n22 6\n20 96\n", "5\n1912 1\n5 6\n999 1\n88 2\n6 100\n", "5\n90 113\n26 25\n64 84\n22 6\n...
2CODEFORCES
1513_C. Add One_81
You are given an integer n. You have to apply m operations to it. In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once. You have to find the length of n after applying m operations. Since...
import java.io.*; import java.util.*; // fast i/o & modInverse is taken from gfg(https://www.geeksforgeeks.org/multiplicative-inverse-under-modulo-m/) public class D { static class pair implements Comparable<pair> { int f = 0; int s = 0; public pair() { } public pair(int a, int b) { f = a; s = b...
4JAVA
{ "input": [ "5\n1912 1\n5 6\n999 1\n88 2\n12 100\n", "5\n90 94\n26 25\n64 84\n14 6\n20 96\n", "5\n90 94\n26 25\n64 84\n18 6\n20 96\n", "5\n1912 1\n5 6\n999 1\n88 2\n11 100\n", "5\n90 94\n26 25\n64 84\n22 6\n20 96\n", "5\n1912 1\n5 6\n999 1\n88 2\n6 100\n", "5\n90 113\n26 25\n64 84\n22 6\n...
2CODEFORCES
1540_C1. Converging Array (Easy Version)_82
This is the easy version of the problem. The only difference is that in this version q = 1. You can make hacks only if both versions of the problem are solved. There is a process that takes place on arrays a and b of length n and length n-1 respectively. The process is an infinite sequence of operations. Each operat...
from __future__ import division,print_function from heapq import* import sys le = sys.__stdin__.read().split("\n")[::-1] mo=10**9+7 if 1: n=int(le.pop()) c = list(map(int,le.pop().split())) b = list(map(int,le.pop().split())) le.pop() x=int(le.pop()) prefb=[b[0]] for k in b[1:]: pref...
1Python2
{ "input": [ "3\n2 3 4\n2 1\n1\n-1\n", "100\n95 54 23 27 51 58 94 34 29 95 53 53 8 5 64 32 17 62 14 37 26 95 27 85 94 37 85 72 88 69 43 9 60 3 48 26 81 48 89 56 34 28 2 63 26 6 13 19 99 41 70 24 92 41 9 73 52 42 34 98 16 82 7 81 28 80 18 33 90 69 19 13 51 96 8 21 86 32 96 7 5 42 52 87 24 82 14 88 4 69 7 69 4 ...
2CODEFORCES
1540_C1. Converging Array (Easy Version)_83
This is the easy version of the problem. The only difference is that in this version q = 1. You can make hacks only if both versions of the problem are solved. There is a process that takes place on arrays a and b of length n and length n-1 respectively. The process is an infinite sequence of operations. Each operat...
#include<bits/stdc++.h> #define pii pair<int,int> #define fi first #define sc second #define pb push_back #define ll long long #define trav(v,x) for(auto v:x) #define all(x) (x).begin(), (x).end() #define VI vector<int> #define VLL vector<ll> using namespace std; const int N = 1e6 + 100; const ll mod = 1e9 + 7; signed...
2C++
{ "input": [ "3\n2 3 4\n2 1\n1\n-1\n", "100\n95 54 23 27 51 58 94 34 29 95 53 53 8 5 64 32 17 62 14 37 26 95 27 85 94 37 85 72 88 69 43 9 60 3 48 26 81 48 89 56 34 28 2 63 26 6 13 19 99 41 70 24 92 41 9 73 52 42 34 98 16 82 7 81 28 80 18 33 90 69 19 13 51 96 8 21 86 32 96 7 5 42 52 87 24 82 14 88 4 69 7 69 4 ...
2CODEFORCES
1540_C1. Converging Array (Easy Version)_84
This is the easy version of the problem. The only difference is that in this version q = 1. You can make hacks only if both versions of the problem are solved. There is a process that takes place on arrays a and b of length n and length n-1 respectively. The process is an infinite sequence of operations. Each operat...
def putin(): return map(int, input().split()) def sol(): n = int(input()) C = list(putin()) B = list(putin()) q = int(input()) x = int(input()) min_arr = [x] min_part_sums = [x] part_sums = [C[0]] for i in range(1, n): part_sums.append(part_sums[-1] + C[i]) for elem...
3Python3
{ "input": [ "3\n2 3 4\n2 1\n1\n-1\n", "100\n95 54 23 27 51 58 94 34 29 95 53 53 8 5 64 32 17 62 14 37 26 95 27 85 94 37 85 72 88 69 43 9 60 3 48 26 81 48 89 56 34 28 2 63 26 6 13 19 99 41 70 24 92 41 9 73 52 42 34 98 16 82 7 81 28 80 18 33 90 69 19 13 51 96 8 21 86 32 96 7 5 42 52 87 24 82 14 88 4 69 7 69 4 ...
2CODEFORCES
1540_C1. Converging Array (Easy Version)_85
This is the easy version of the problem. The only difference is that in this version q = 1. You can make hacks only if both versions of the problem are solved. There is a process that takes place on arrays a and b of length n and length n-1 respectively. The process is an infinite sequence of operations. Each operat...
/* stream Butter! eggyHide eggyVengeance I need U xiao rerun when */ import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import static java.lang.System.out; import java.util.*; import java.io.*; import java.math.*; public class PurpleCrayonE1 { static final int MA...
4JAVA
{ "input": [ "3\n2 3 4\n2 1\n1\n-1\n", "100\n95 54 23 27 51 58 94 34 29 95 53 53 8 5 64 32 17 62 14 37 26 95 27 85 94 37 85 72 88 69 43 9 60 3 48 26 81 48 89 56 34 28 2 63 26 6 13 19 99 41 70 24 92 41 9 73 52 42 34 98 16 82 7 81 28 80 18 33 90 69 19 13 51 96 8 21 86 32 96 7 5 42 52 87 24 82 14 88 4 69 7 69 4 ...
2CODEFORCES
168_A. Wizards and Demonstration_86
Some country is populated by wizards. They want to organize a demonstration. There are n people living in the city, x of them are the wizards who will surely go to the demonstration. Other city people (n - x people) do not support the wizards and aren't going to go to the demonstration. We know that the city administr...
import sys def readints() : l = sys.stdin.readline() return map(int, l.split(' ')) def readstring() : l = sys.stdin.readline()[:-1] return l def readint() : l = sys.stdin.readline() return int(l) def clearchars(s, chars) : for c in chars : s = s.replace(c, '') return s def g...
1Python2
{ "input": [ "1000 352 146\n", "10 1 14\n", "20 10 50\n", "7879 2590 2818\n", "78 28 27\n", "9178 2255 7996\n", "6571 6449 8965\n", "6151 6148 3746\n", "6487 5670 8\n", "4890 1112 5\n", "4909 2111 8860\n", "10000 10000 10000\n", "78 55 96\n", "3271 5 50\n", ...
2CODEFORCES
168_A. Wizards and Demonstration_87
Some country is populated by wizards. They want to organize a demonstration. There are n people living in the city, x of them are the wizards who will surely go to the demonstration. Other city people (n - x people) do not support the wizards and aren't going to go to the demonstration. We know that the city administr...
#include <bits/stdc++.h> using namespace std; int main() { double n, x, y, p, q, r; int a; cin >> n >> x >> y; p = y / 100; q = n * p; r = q - x; a = r; if (r > a) { cout << a + 1; } else if (a < 0) { cout << "0"; } else { cout << a; } }
2C++
{ "input": [ "1000 352 146\n", "10 1 14\n", "20 10 50\n", "7879 2590 2818\n", "78 28 27\n", "9178 2255 7996\n", "6571 6449 8965\n", "6151 6148 3746\n", "6487 5670 8\n", "4890 1112 5\n", "4909 2111 8860\n", "10000 10000 10000\n", "78 55 96\n", "3271 5 50\n", ...
2CODEFORCES
168_A. Wizards and Demonstration_88
Some country is populated by wizards. They want to organize a demonstration. There are n people living in the city, x of them are the wizards who will surely go to the demonstration. Other city people (n - x people) do not support the wizards and aren't going to go to the demonstration. We know that the city administr...
num,wiz,per = map(int,input().split()) k = 0 while (k+wiz)/num*100 < per: k += 1 print(k)
3Python3
{ "input": [ "1000 352 146\n", "10 1 14\n", "20 10 50\n", "7879 2590 2818\n", "78 28 27\n", "9178 2255 7996\n", "6571 6449 8965\n", "6151 6148 3746\n", "6487 5670 8\n", "4890 1112 5\n", "4909 2111 8860\n", "10000 10000 10000\n", "78 55 96\n", "3271 5 50\n", ...
2CODEFORCES
168_A. Wizards and Demonstration_89
Some country is populated by wizards. They want to organize a demonstration. There are n people living in the city, x of them are the wizards who will surely go to the demonstration. Other city people (n - x people) do not support the wizards and aren't going to go to the demonstration. We know that the city administr...
import java.util.Scanner; public class WizardMeeting { public static void main(String[] args) { Scanner read = new Scanner(System.in); int n = read.nextInt(); int x = read.nextInt(); int y = read.nextInt(); int minCount = (int) Math.ceil( (double)(n)*(double)(y)/...
4JAVA
{ "input": [ "1000 352 146\n", "10 1 14\n", "20 10 50\n", "7879 2590 2818\n", "78 28 27\n", "9178 2255 7996\n", "6571 6449 8965\n", "6151 6148 3746\n", "6487 5670 8\n", "4890 1112 5\n", "4909 2111 8860\n", "10000 10000 10000\n", "78 55 96\n", "3271 5 50\n", ...
2CODEFORCES
20_B. Equation_90
You are given an equation: Ax2 + Bx + C = 0. Your task is to find the number of distinct roots of the equation and print all of them in ascending order. Input The first line contains three integer numbers A, B and C ( - 105 ≤ A, B, C ≤ 105). Any coefficient may be equal to 0. Output In case of infinite root cou...
from math import sqrt a, b, c = map(float, raw_input().split()) delta = b**2-4*a*c if (a == 0): print -1 if ((b == 0) and (c == 0)) else 0 if ((b == 0) and (c != 0)) else 1 if (b != 0): print "%.5f" %(-c/b) elif (delta > 0): print 2 for i in range(2): print "%.5f" %sorted([(-b+sqrt(delta))/(2*a)...
1Python2
{ "input": [ "1 -5 6\n", "0 -2 0\n", "1223 -23532 1232\n", "0 1 0\n", "-1 10 20\n", "0 3431 43123\n", "-50000 100000 -50000\n", "1 1 0\n", "50000 100000 50000\n", "0 -2 1\n", "0 -4 -4\n", "1 1 1\n", "1 -100000 0\n", "-2 -5 0\n", "0 1 -1\n", "1 0 0\n", ...
2CODEFORCES
20_B. Equation_91
You are given an equation: Ax2 + Bx + C = 0. Your task is to find the number of distinct roots of the equation and print all of them in ascending order. Input The first line contains three integer numbers A, B and C ( - 105 ≤ A, B, C ≤ 105). Any coefficient may be equal to 0. Output In case of infinite root cou...
#include <bits/stdc++.h> using namespace std; int main() { double A, B, C; double D; cin >> A >> B >> C; double x1, x2; if (!A) { if (!B) { if (!C) { printf("-1"); return 0; } else { printf("0"); return 0; } } else { printf("1\n"); printf("...
2C++
{ "input": [ "1 -5 6\n", "0 -2 0\n", "1223 -23532 1232\n", "0 1 0\n", "-1 10 20\n", "0 3431 43123\n", "-50000 100000 -50000\n", "1 1 0\n", "50000 100000 50000\n", "0 -2 1\n", "0 -4 -4\n", "1 1 1\n", "1 -100000 0\n", "-2 -5 0\n", "0 1 -1\n", "1 0 0\n", ...
2CODEFORCES
20_B. Equation_92
You are given an equation: Ax2 + Bx + C = 0. Your task is to find the number of distinct roots of the equation and print all of them in ascending order. Input The first line contains three integer numbers A, B and C ( - 105 ≤ A, B, C ≤ 105). Any coefficient may be equal to 0. Output In case of infinite root cou...
a, b, c = map(float, input().split()) D = b ** 2 - (4 * a * c) if D < 0: print(0) elif a == 0 and b == 0 and c != 0: print(0) elif a == 0 and b == 0 and c == 0: print(-1) elif a == 0: x0 = c / -(b) print(1) print(x0) elif b == 0: print(1) print(0) elif D == 0 and (a > 0 or a < 0): x ...
3Python3
{ "input": [ "1 -5 6\n", "0 -2 0\n", "1223 -23532 1232\n", "0 1 0\n", "-1 10 20\n", "0 3431 43123\n", "-50000 100000 -50000\n", "1 1 0\n", "50000 100000 50000\n", "0 -2 1\n", "0 -4 -4\n", "1 1 1\n", "1 -100000 0\n", "-2 -5 0\n", "0 1 -1\n", "1 0 0\n", ...
2CODEFORCES
20_B. Equation_93
You are given an equation: Ax2 + Bx + C = 0. Your task is to find the number of distinct roots of the equation and print all of them in ascending order. Input The first line contains three integer numbers A, B and C ( - 105 ≤ A, B, C ≤ 105). Any coefficient may be equal to 0. Output In case of infinite root cou...
import java.util.Scanner; public class b { public static void main(String[] args) { Scanner sc = new Scanner(System.in); double a = sc.nextDouble(), b = sc.nextDouble(), c = sc.nextDouble(); sc.close(); if (a == 0 && b == 0 && c == 0) { System.out.println("-1"); ...
4JAVA
{ "input": [ "1 -5 6\n", "0 -2 0\n", "1223 -23532 1232\n", "0 1 0\n", "-1 10 20\n", "0 3431 43123\n", "-50000 100000 -50000\n", "1 1 0\n", "50000 100000 50000\n", "0 -2 1\n", "0 -4 -4\n", "1 1 1\n", "1 -100000 0\n", "-2 -5 0\n", "0 1 -1\n", "1 0 0\n", ...
2CODEFORCES
235_D. Graph Game_94
In computer science, there is a method called "Divide And Conquer By Node" to solve some hard problems about paths on a tree. Let's desribe how this method works by function: solve(t) (t is a tree): 1. Chose a node x (it's common to chose weight-center) in tree t. Let's call this step "Line A". 2. Deal with all...
#include <bits/stdc++.h> struct edge { int to; edge* next; } E[6010], *ne = E, *first[3010]; void link(int a, int b) { *ne = (edge){b, first[a]}; first[a] = ne++; } int C[3010], cnt; bool tag[3010]; int dfs1(int i, int f) { int t; tag[i] = 1; for (edge* e = first[i]; e; e = e->next) if (e->to != f) { ...
2C++
{ "input": [ "5\n0 1\n1 2\n2 0\n3 0\n4 1\n", "5\n3 4\n2 3\n2 4\n0 4\n1 2\n", "3\n0 1\n1 2\n0 2\n", "15\n0 1\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 0\n", "15\n0 1\n1 2\n2 3\n3 4\n4 5\n5 0\n0 6\n5 7\n3 8\n3 9\n3 10\n7 11\n4 12\n6 13\n5 14\n", "15\n0 1\n1 2\...
2CODEFORCES
235_D. Graph Game_95
In computer science, there is a method called "Divide And Conquer By Node" to solve some hard problems about paths on a tree. Let's desribe how this method works by function: solve(t) (t is a tree): 1. Chose a node x (it's common to chose weight-center) in tree t. Let's call this step "Line A". 2. Deal with all...
//package round146; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; public class D3 { InputStream is; PrintWriter out; String INPUT = ""; void solve() { int n = ni(); int[] from = new int[n]; int[] to = new i...
4JAVA
{ "input": [ "5\n0 1\n1 2\n2 0\n3 0\n4 1\n", "5\n3 4\n2 3\n2 4\n0 4\n1 2\n", "3\n0 1\n1 2\n0 2\n", "15\n0 1\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 0\n", "15\n0 1\n1 2\n2 3\n3 4\n4 5\n5 0\n0 6\n5 7\n3 8\n3 9\n3 10\n7 11\n4 12\n6 13\n5 14\n", "15\n0 1\n1 2\...
2CODEFORCES
260_B. Ancient Prophesy_96
A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-". We'll say that some date is mentioned in the Prophesy if there is a substring in the Prophesy that is the date's record in the format "dd-mm-yyyy". We'll say tha...
def main(): s = raw_input() mon = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] ans, cnt = "", 0 for i in xrange(2013, 2016): for j in xrange(1, 13): for k in xrange(1, mon[j - 1] + 1): t = (str(k) if k >= 10 else ("0" + str(k))) + "-" + (str(j) if j >= 10 else ("0" + str(j))) + "-" + str(i) cntNew ...
1Python2
{ "input": [ "777-444---21-12-2013-12-2013-12-2013---444-777\n", "12-12-201312-12-201312-12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-2013\n", "01--01--2013-12-2013-01--01--2013\n", "01-04-201425-08-201386-04-201525-10-2014878-04-20102-06-201501-04-2014-08...
2CODEFORCES
260_B. Ancient Prophesy_97
A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-". We'll say that some date is mentioned in the Prophesy if there is a substring in the Prophesy that is the date's record in the format "dd-mm-yyyy". We'll say tha...
#include <bits/stdc++.h> using namespace std; char s[100005]; int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; map<string, int> my; void check(char* s) { if (((s[0]) >= '0' && (s[0]) <= '9') && ((s[1]) >= '0' && (s[1]) <= '9') && ((s[3]) >= '0' && (s[3]) <= '9') && ((s[4]) >= '0' && (s[4]) <= '9') ...
2C++
{ "input": [ "777-444---21-12-2013-12-2013-12-2013---444-777\n", "12-12-201312-12-201312-12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-2013\n", "01--01--2013-12-2013-01--01--2013\n", "01-04-201425-08-201386-04-201525-10-2014878-04-20102-06-201501-04-2014-08...
2CODEFORCES
260_B. Ancient Prophesy_98
A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-". We'll say that some date is mentioned in the Prophesy if there is a substring in the Prophesy that is the date's record in the format "dd-mm-yyyy". We'll say tha...
s=input() n=len(s) l=list("0987654321") cnt={} for i in range(n-9): t=s[i:i+10] if t[0] in l and t[1] in l and t[2]=="-" and t[3] in l and t[4] in l and t[5]=="-" and t[6] in l and t[7] in l and t[8] in l and t[9] in l: if 2013<=int(t[6:11])<=2015 and 1<=int(t[3:5])<=12: if int(t[3:5]) in [1,3,5,7,8,10,1...
3Python3
{ "input": [ "777-444---21-12-2013-12-2013-12-2013---444-777\n", "12-12-201312-12-201312-12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-2013\n", "01--01--2013-12-2013-01--01--2013\n", "01-04-201425-08-201386-04-201525-10-2014878-04-20102-06-201501-04-2014-08...
2CODEFORCES
260_B. Ancient Prophesy_99
A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-". We'll say that some date is mentioned in the Prophesy if there is a substring in the Prophesy that is the date's record in the format "dd-mm-yyyy". We'll say tha...
import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.io.*; import java.math.*; import java.text.*; import java.util.*; public class B { static BufferedReader br; static StringTokenizer st; static PrintWriter pw; static int[] max = new int[]{0,31,28,31,30,31,30,31,31,30,31,30,31}; pu...
4JAVA
{ "input": [ "777-444---21-12-2013-12-2013-12-2013---444-777\n", "12-12-201312-12-201312-12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-2013\n", "01--01--2013-12-2013-01--01--2013\n", "01-04-201425-08-201386-04-201525-10-2014878-04-20102-06-201501-04-2014-08...
2CODEFORCES