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
1121_A. Technogoblet of Fire_1500
Everybody knows that the m-coder Tournament will happen soon. m schools participate in the tournament, and only one student from each school participates. There are a total of n students in those schools. Before the tournament, all students put their names and the names of their schools into the Technogoblet of Fire. ...
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 5, M = 3e3 + 5; const long long inf = 1e18 + 100, mod = 1e9 + 7; const double eps = 1e-9; long long pos[N]; pair<long long, long long> a[N]; map<long long, long long> b; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n, m...
2C++
{ "input": [ "8 4 4\n1 2 3 4 5 6 7 8\n4 3 2 1 4 3 2 1\n3 4 5 6\n", "7 3 1\n1 5 3 4 6 7 2\n1 3 1 2 1 2 3\n3\n", "2 1 1\n1 2\n1 1\n1\n", "2 1 1\n1 2\n1 1\n2\n", "1 1 1\n1\n1\n1\n", "10 5 4\n4 2 1 7 10 9 6 3 5 8\n3 2 1 4 5 1 4 2 4 2\n9 3 2 6\n", "10 1 10\n9 1 2 3 5 7 4 10 6 8\n1 1 1 1 1 1 1 1...
2CODEFORCES
1121_A. Technogoblet of Fire_1501
Everybody knows that the m-coder Tournament will happen soon. m schools participate in the tournament, and only one student from each school participates. There are a total of n students in those schools. Before the tournament, all students put their names and the names of their schools into the Technogoblet of Fire. ...
n,m,k=map(int,input().split()) p=list(map(int,input().split())) s=list(map(int,input().split())) c=set(map(int,input().split())) d={} for i in range(n): if s[i] not in d: d[s[i]]=[-1] if p[i]>d[s[i]][0]: d[s[i]]=(p[i],i) st=set() for i in d: st.add(d[i][1]+1) #print(c,st) c=c.difference(st) ...
3Python3
{ "input": [ "8 4 4\n1 2 3 4 5 6 7 8\n4 3 2 1 4 3 2 1\n3 4 5 6\n", "7 3 1\n1 5 3 4 6 7 2\n1 3 1 2 1 2 3\n3\n", "2 1 1\n1 2\n1 1\n1\n", "2 1 1\n1 2\n1 1\n2\n", "1 1 1\n1\n1\n1\n", "10 5 4\n4 2 1 7 10 9 6 3 5 8\n3 2 1 4 5 1 4 2 4 2\n9 3 2 6\n", "10 1 10\n9 1 2 3 5 7 4 10 6 8\n1 1 1 1 1 1 1 1...
2CODEFORCES
1121_A. Technogoblet of Fire_1502
Everybody knows that the m-coder Tournament will happen soon. m schools participate in the tournament, and only one student from each school participates. There are a total of n students in those schools. Before the tournament, all students put their names and the names of their schools into the Technogoblet of Fire. ...
import java.io.*; import java.util.Arrays; import java.util.HashSet; import java.util.StringTokenizer; public class Solution { static final int INF = (int) 1e9; static final int mod = (int) (1e9 + 7); public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); ...
4JAVA
{ "input": [ "8 4 4\n1 2 3 4 5 6 7 8\n4 3 2 1 4 3 2 1\n3 4 5 6\n", "7 3 1\n1 5 3 4 6 7 2\n1 3 1 2 1 2 3\n3\n", "2 1 1\n1 2\n1 1\n1\n", "2 1 1\n1 2\n1 1\n2\n", "1 1 1\n1\n1\n1\n", "10 5 4\n4 2 1 7 10 9 6 3 5 8\n3 2 1 4 5 1 4 2 4 2\n9 3 2 6\n", "10 1 10\n9 1 2 3 5 7 4 10 6 8\n1 1 1 1 1 1 1 1...
2CODEFORCES
1148_C. Crazy Diamond_1503
You are given a permutation p of integers from 1 to n, where n is an even number. Your goal is to sort the permutation. To do so, you can perform zero or more operations of the following type: * take two indices i and j such that 2 ⋅ |i - j| ≥ n and swap p_i and p_j. There is no need to minimize the number of...
def main(): inp = readnumbers() ii = 0 n = inp[ii] ii += 1 P = [p-1 for p in inp[ii:ii+n]] ii += n where = [0]*n for i in range(n): where[P[i]] = i Z = [] def swapper(ind1,ind2): if ind1>ind2: ind1,ind2 = ind2,ind1 swaps = [] ...
1Python2
{ "input": [ "2\n2 1\n", "4\n3 4 1 2\n", "6\n2 5 3 1 4 6\n", "10\n6 1 2 9 3 5 4 10 7 8\n", "100\n47 54 37 8 33 97 74 80 35 96 55 39 15 67 85 92 49 50 1 25 70 53 48 19 86 16 14 68 60 41 40 87 29 27 34 94 26 42 17 38 45 4 22 13 31 57 23 99 73 90 44 88 3 63 59 93 52 30 20 21 18 7 12 58 56 81 32 82 84...
2CODEFORCES
1148_C. Crazy Diamond_1504
You are given a permutation p of integers from 1 to n, where n is an even number. Your goal is to sort the permutation. To do so, you can perform zero or more operations of the following type: * take two indices i and j such that 2 ⋅ |i - j| ≥ n and swap p_i and p_j. There is no need to minimize the number of...
#include <bits/stdc++.h> using namespace std; const long long maxn = (long long)3e5 + 7; long long a[maxn]; long long b[maxn]; long long pos[maxn]; struct node { long long x, y; } ans[maxn * 5]; signed main() { ios::sync_with_stdio(false); long long n; cin >> n; for (long long i = 1; i <= n; i++) cin >> a[i];...
2C++
{ "input": [ "2\n2 1\n", "4\n3 4 1 2\n", "6\n2 5 3 1 4 6\n", "10\n6 1 2 9 3 5 4 10 7 8\n", "100\n47 54 37 8 33 97 74 80 35 96 55 39 15 67 85 92 49 50 1 25 70 53 48 19 86 16 14 68 60 41 40 87 29 27 34 94 26 42 17 38 45 4 22 13 31 57 23 99 73 90 44 88 3 63 59 93 52 30 20 21 18 7 12 58 56 81 32 82 84...
2CODEFORCES
1148_C. Crazy Diamond_1505
You are given a permutation p of integers from 1 to n, where n is an even number. Your goal is to sort the permutation. To do so, you can perform zero or more operations of the following type: * take two indices i and j such that 2 ⋅ |i - j| ≥ n and swap p_i and p_j. There is no need to minimize the number of...
n = int(input()) p = [*map(int, input().split())] p = [i - 1 for i in p] #print(p) pos = {} ans = [] for i, j in enumerate(p): pos[j] = i def swap(i, j): ans.append((i + 1, j + 1)) pos[p[i]], pos[p[j]] = pos[p[j]], pos[p[i]] p[i], p[j] = p[j], p[i] def do(i): j=pos[i] if j<n//2: ...
3Python3
{ "input": [ "2\n2 1\n", "4\n3 4 1 2\n", "6\n2 5 3 1 4 6\n", "10\n6 1 2 9 3 5 4 10 7 8\n", "100\n47 54 37 8 33 97 74 80 35 96 55 39 15 67 85 92 49 50 1 25 70 53 48 19 86 16 14 68 60 41 40 87 29 27 34 94 26 42 17 38 45 4 22 13 31 57 23 99 73 90 44 88 3 63 59 93 52 30 20 21 18 7 12 58 56 81 32 82 84...
2CODEFORCES
1148_C. Crazy Diamond_1506
You are given a permutation p of integers from 1 to n, where n is an even number. Your goal is to sort the permutation. To do so, you can perform zero or more operations of the following type: * take two indices i and j such that 2 ⋅ |i - j| ≥ n and swap p_i and p_j. There is no need to minimize the number of...
import java.io.*; import java.util.*; import java.util.concurrent.ThreadLocalRandom; public class Main { public static void main(String[] args) throws FileNotFoundException { ConsoleIO io = new ConsoleIO(new InputStreamReader(System.in), new PrintWriter(System.out)); // String fileName = "C-large-p...
4JAVA
{ "input": [ "2\n2 1\n", "4\n3 4 1 2\n", "6\n2 5 3 1 4 6\n", "10\n6 1 2 9 3 5 4 10 7 8\n", "100\n47 54 37 8 33 97 74 80 35 96 55 39 15 67 85 92 49 50 1 25 70 53 48 19 86 16 14 68 60 41 40 87 29 27 34 94 26 42 17 38 45 4 22 13 31 57 23 99 73 90 44 88 3 63 59 93 52 30 20 21 18 7 12 58 56 81 32 82 84...
2CODEFORCES
1169_E. And Reachability_1507
Toad Pimple has an array of integers a_1, a_2, …, a_n. We say that y is reachable from x if x<y and there exists an integer array p such that x = p_1 < p_2 < … < p_k=y, and a_{p_i} \& a_{p_{i+1}} > 0 for all integers i such that 1 ≤ i < k. Here \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bi...
#include <bits/stdc++.h> struct node { int next[19] = {}; }; int n, q; int a[300005]; node nodes[300005]; bool isReachable(int curr, int end) { for (int i = 0; i < 19; i++) { if ((a[end] & (1 << i)) && nodes[curr].next[i] && nodes[curr].next[i] <= end) { return true; } } return false; } in...
2C++
{ "input": [ "5 3\n1 3 0 2 1\n1 3\n2 4\n1 4\n", "2 1\n300000 300000\n1 2\n", "5 3\n1 3 0 2 1\n1 2\n2 4\n1 4\n", "2 1\n175528 300000\n1 2\n", "5 3\n1 2 0 2 1\n1 2\n2 4\n1 4\n", "5 3\n1 3 0 2 0\n1 3\n2 4\n1 4\n", "5 3\n0 2 0 2 1\n1 2\n3 4\n2 4\n", "5 3\n0 2 0 2 1\n1 2\n3 4\n3 4\n", "...
2CODEFORCES
1169_E. And Reachability_1508
Toad Pimple has an array of integers a_1, a_2, …, a_n. We say that y is reachable from x if x<y and there exists an integer array p such that x = p_1 < p_2 < … < p_k=y, and a_{p_i} \& a_{p_{i+1}} > 0 for all integers i such that 1 ≤ i < k. Here \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bi...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.FilterInputStream; import java.io.BufferedInputStream; import java.io.InputStream; /** * @author khokharnikunj8 */ public class Main { public static void main(...
4JAVA
{ "input": [ "5 3\n1 3 0 2 1\n1 3\n2 4\n1 4\n", "2 1\n300000 300000\n1 2\n", "5 3\n1 3 0 2 1\n1 2\n2 4\n1 4\n", "2 1\n175528 300000\n1 2\n", "5 3\n1 2 0 2 1\n1 2\n2 4\n1 4\n", "5 3\n1 3 0 2 0\n1 3\n2 4\n1 4\n", "5 3\n0 2 0 2 1\n1 2\n3 4\n2 4\n", "5 3\n0 2 0 2 1\n1 2\n3 4\n3 4\n", "...
2CODEFORCES
1187_G. Gang Up_1509
The leader of some very secretive organization has decided to invite all other members to a meeting. All members of the organization live in the same town which can be represented as n crossroads connected by m two-directional streets. The meeting will be held in the leader's house near the crossroad 1. There are k mem...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxm = 5e3 + 10; const int inf = 0x3f3f3f3f; namespace io { const int SIZE = (1 << 21) + 1; char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr; inline void fl...
2C++
{ "input": [ "3 3 4 2 3\n3 2 2 3\n1 2\n2 3\n2 3\n", "3 2 4 2 3\n3 3 3 3\n1 2\n2 3\n", "50 50 50 50 1\n37 4 43 29 18 26 14 20 35 41 24 18 23 3 18 33 13 41 47 19 34 15 46 38 37 49 7 25 13 48 24 36 24 43 5 32 31 15 5 48 16 6 8 43 38 26 15 12 11 4\n1 16\n16 37\n1 10\n1 44\n10 34\n1 26\n10 12\n12 38\n38 21\n1 ...
2CODEFORCES
1187_G. Gang Up_1510
The leader of some very secretive organization has decided to invite all other members to a meeting. All members of the organization live in the same town which can be represented as n crossroads connected by m two-directional streets. The meeting will be held in the leader's house near the crossroad 1. There are k mem...
// upsolve with rainboy import java.io.*; import java.util.*; public class CF1187G extends PrintWriter { CF1187G() { super(System.out); } static class Scanner { Scanner(InputStream in) { this.in = in; } InputStream in; int k, l; byte[] bb = new byte[1 << 15]; byte getc() { if (k >= l) { k = 0; try {...
4JAVA
{ "input": [ "3 3 4 2 3\n3 2 2 3\n1 2\n2 3\n2 3\n", "3 2 4 2 3\n3 3 3 3\n1 2\n2 3\n", "50 50 50 50 1\n37 4 43 29 18 26 14 20 35 41 24 18 23 3 18 33 13 41 47 19 34 15 46 38 37 49 7 25 13 48 24 36 24 43 5 32 31 15 5 48 16 6 8 43 38 26 15 12 11 4\n1 16\n16 37\n1 10\n1 44\n10 34\n1 26\n10 12\n12 38\n38 21\n1 ...
2CODEFORCES
1206_F. Almost All_1511
You are given a tree with n nodes. You have to write non-negative integers on its edges so that the following condition would be satisfied: For every two nodes i, j, look at the path between them and count the sum of numbers on the edges of this path. Write all obtained sums on the blackboard. Then every integer from ...
#include <bits/stdc++.h> using namespace std; const int N = 1010; struct Edge { int to, next; } e[N * 2]; int lst[N], d; void add(int x, int y) { e[d].to = y, e[d].next = lst[x], lst[x] = d++; } int fa[N], n, sz[N]; int read() { int w = 0, f = 0; char c = getchar(); while ((c < '0' || c > '9') && c != '-') c = ...
2C++
{ "input": [ "4\n2 4\n2 3\n2 1\n", "3\n2 3\n2 1\n", "5\n1 2\n1 3\n1 4\n2 5\n", "43\n7 29\n19 18\n32 4\n39 40\n21 11\n34 28\n30 23\n13 19\n33 39\n13 35\n37 21\n29 8\n40 1\n7 9\n8 38\n7 31\n8 12\n7 42\n33 20\n5 36\n17 32\n30 43\n39 34\n40 3\n8 24\n13 37\n35 16\n23 22\n7 41\n35 30\n9 14\n13 2\n7 27\n10 2...
2CODEFORCES
1206_F. Almost All_1512
You are given a tree with n nodes. You have to write non-negative integers on its edges so that the following condition would be satisfied: For every two nodes i, j, look at the path between them and count the sum of numbers on the edges of this path. Write all obtained sums on the blackboard. Then every integer from ...
import math n = int(input()) if n == 1: print() else: edge = [list(map(int, input().split())) for i in range(1, n) ] g = {} for x, y in edge: if x not in g: g[x] = [] if y not in g: g[y] = [] g[x].append(y) g[y].append(x) ...
3Python3
{ "input": [ "4\n2 4\n2 3\n2 1\n", "3\n2 3\n2 1\n", "5\n1 2\n1 3\n1 4\n2 5\n", "43\n7 29\n19 18\n32 4\n39 40\n21 11\n34 28\n30 23\n13 19\n33 39\n13 35\n37 21\n29 8\n40 1\n7 9\n8 38\n7 31\n8 12\n7 42\n33 20\n5 36\n17 32\n30 43\n39 34\n40 3\n8 24\n13 37\n35 16\n23 22\n7 41\n35 30\n9 14\n13 2\n7 27\n10 2...
2CODEFORCES
1225_B1. TV Subscriptions (Easy Version)_1513
The only difference between easy and hard versions is constraints. The BerTV channel every day broadcasts one episode of one of the k TV shows. You know the schedule for the next n days: a sequence of integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ k), where a_i is the show, the episode of which will be shown in i-th day. The...
c = [[0, 0] for i in xrange(1000001)] def ans(t, v, a, k, s) : y, x, a, m = 0, 0, 0, 1000000000 for i in range(len(v)) : if c[v[i]][0] != t : c[v[i]] = [t, 0] c[v[i]][1] += 1 if c[v[i]][1] == 1 : a += 1 if i-y+1 > s : c[v[y]][1] -= 1 if c[v[y]][1] == 0 :...
1Python2
{ "input": [ "4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 2 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3\n", "1\n100 20 1\n10 17 9 8 11 8 8 3 7 20 11 10 7 7 2 13 10 7 7 10 7 8 4 17 20 9 5 18 12 8 3 5 19 1 18 14 9 11 12 11 11 12 12 9 13 8 20 3 8 1 15 20 6 18 8 1 13 11 4 17 12 15 4 4 11 19 18 5 2 ...
2CODEFORCES
1225_B1. TV Subscriptions (Easy Version)_1514
The only difference between easy and hard versions is constraints. The BerTV channel every day broadcasts one episode of one of the k TV shows. You know the schedule for the next n days: a sequence of integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ k), where a_i is the show, the episode of which will be shown in i-th day. The...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int INF = 1e9 + 5; const double PI = acos(-1); const int X[] = {1, -1, 0, 0}; const int Y[] = {0, 0, 1, -1}; const int mod = 1e9 + 7; int t, n, k, d; map<int, int> mp; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> t; whil...
2C++
{ "input": [ "4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 2 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3\n", "1\n100 20 1\n10 17 9 8 11 8 8 3 7 20 11 10 7 7 2 13 10 7 7 10 7 8 4 17 20 9 5 18 12 8 3 5 19 1 18 14 9 11 12 11 11 12 12 9 13 8 20 3 8 1 15 20 6 18 8 1 13 11 4 17 12 15 4 4 11 19 18 5 2 ...
2CODEFORCES
1225_B1. TV Subscriptions (Easy Version)_1515
The only difference between easy and hard versions is constraints. The BerTV channel every day broadcasts one episode of one of the k TV shows. You know the schedule for the next n days: a sequence of integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ k), where a_i is the show, the episode of which will be shown in i-th day. The...
x = int(input()) for i in range(x): n, k, d = map(int, input().split(' ')) l = map(int, input().split(' ')) l = list(l) ar = [] for j in range(n-d+1): ar.append(len(set(l[j:(j+d)]))) print(min(ar))
3Python3
{ "input": [ "4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 2 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3\n", "1\n100 20 1\n10 17 9 8 11 8 8 3 7 20 11 10 7 7 2 13 10 7 7 10 7 8 4 17 20 9 5 18 12 8 3 5 19 1 18 14 9 11 12 11 11 12 12 9 13 8 20 3 8 1 15 20 6 18 8 1 13 11 4 17 12 15 4 4 11 19 18 5 2 ...
2CODEFORCES
1225_B1. TV Subscriptions (Easy Version)_1516
The only difference between easy and hard versions is constraints. The BerTV channel every day broadcasts one episode of one of the k TV shows. You know the schedule for the next n days: a sequence of integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ k), where a_i is the show, the episode of which will be shown in i-th day. The...
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.StringTokenizer; public class TVSubscriptions { public static void main(String[] args) ...
4JAVA
{ "input": [ "4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 2 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3\n", "1\n100 20 1\n10 17 9 8 11 8 8 3 7 20 11 10 7 7 2 13 10 7 7 10 7 8 4 17 20 9 5 18 12 8 3 5 19 1 18 14 9 11 12 11 11 12 12 9 13 8 20 3 8 1 15 20 6 18 8 1 13 11 4 17 12 15 4 4 11 19 18 5 2 ...
2CODEFORCES
1249_D1. Too Many Segments (easy version)_1517
The only difference between easy and hard versions is constraints. You are given n segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The i-th segment is [l_i; r_i] (l_i ≤ r_i) and it covers all integer points j such that l_i ≤ j ≤ r_i. The integer point is called bad...
from sys import stdin import heapq raw_input = lambda: stdin.readline().rstrip() input = lambda: int(raw_input()) I=lambda: map(int, raw_input().split()) n,k = I() lst = [] for i in xrange(n): l,r = I() lst.append((l, 0, i+1, r+1)) lst.append((r+1, 1, i+1)) lst.sort(key=lambda x: x[0]) q = [] lLst = len(lst) c = 0 j...
1Python2
{ "input": [ "5 1\n29 30\n30 30\n29 29\n28 30\n30 30\n", "7 2\n11 11\n9 11\n7 8\n8 9\n7 8\n9 11\n7 9\n", "6 1\n2 3\n3 3\n2 3\n2 2\n2 3\n2 3\n", "15 2\n4 4\n16 18\n16 18\n6 9\n3 14\n8 11\n3 13\n3 6\n14 16\n5 17\n7 14\n11 14\n4 4\n10 11\n13 17\n", "16 3\n181 182\n183 184\n179 181\n178 178\n182 185\n...
2CODEFORCES
1249_D1. Too Many Segments (easy version)_1518
The only difference between easy and hard versions is constraints. You are given n segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The i-th segment is [l_i; r_i] (l_i ≤ r_i) and it covers all integer points j such that l_i ≤ j ≤ r_i. The integer point is called bad...
#include <bits/stdc++.h> using namespace std; int arr[200005], tree[4 * 200005], lazy[4 * 200005]; struct info { int l, r, i; }; vector<info> vec; bool comp(info a, info b) { if (a.r != b.r) return a.r < b.r; return a.l < b.l; } void update(int node, int a, int b, int i, int j, int value) { if (lazy[node] != 0)...
2C++
{ "input": [ "5 1\n29 30\n30 30\n29 29\n28 30\n30 30\n", "7 2\n11 11\n9 11\n7 8\n8 9\n7 8\n9 11\n7 9\n", "6 1\n2 3\n3 3\n2 3\n2 2\n2 3\n2 3\n", "15 2\n4 4\n16 18\n16 18\n6 9\n3 14\n8 11\n3 13\n3 6\n14 16\n5 17\n7 14\n11 14\n4 4\n10 11\n13 17\n", "16 3\n181 182\n183 184\n179 181\n178 178\n182 185\n...
2CODEFORCES
1249_D1. Too Many Segments (easy version)_1519
The only difference between easy and hard versions is constraints. You are given n segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The i-th segment is [l_i; r_i] (l_i ≤ r_i) and it covers all integer points j such that l_i ≤ j ≤ r_i. The integer point is called bad...
import sys from heapq import * #sys.stdin = open('in', 'r') #n = int(input()) n,k = map(int, input().split()) seg = [] for i in range(n): l, r = map(int, input().split()) seg.append((l, r, i+1)) seg.sort() c = 0 res = [] i = 0 hmin = [] hmax = [] rem = set() while i < n: l,r,si = seg[i] while i < n and ...
3Python3
{ "input": [ "5 1\n29 30\n30 30\n29 29\n28 30\n30 30\n", "7 2\n11 11\n9 11\n7 8\n8 9\n7 8\n9 11\n7 9\n", "6 1\n2 3\n3 3\n2 3\n2 2\n2 3\n2 3\n", "15 2\n4 4\n16 18\n16 18\n6 9\n3 14\n8 11\n3 13\n3 6\n14 16\n5 17\n7 14\n11 14\n4 4\n10 11\n13 17\n", "16 3\n181 182\n183 184\n179 181\n178 178\n182 185\n...
2CODEFORCES
1249_D1. Too Many Segments (easy version)_1520
The only difference between easy and hard versions is constraints. You are given n segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The i-th segment is [l_i; r_i] (l_i ≤ r_i) and it covers all integer points j such that l_i ≤ j ≤ r_i. The integer point is called bad...
import java.util.*; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; public class r558p4{ private static InputReader sc; private static PrintWriter pw; static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]...
4JAVA
{ "input": [ "5 1\n29 30\n30 30\n29 29\n28 30\n30 30\n", "7 2\n11 11\n9 11\n7 8\n8 9\n7 8\n9 11\n7 9\n", "6 1\n2 3\n3 3\n2 3\n2 2\n2 3\n2 3\n", "15 2\n4 4\n16 18\n16 18\n6 9\n3 14\n8 11\n3 13\n3 6\n14 16\n5 17\n7 14\n11 14\n4 4\n10 11\n13 17\n", "16 3\n181 182\n183 184\n179 181\n178 178\n182 185\n...
2CODEFORCES
1267_L. Lexicography_1521
Lucy likes letters. She studied the definition of the lexicographical order at school and plays with it. At first, she tried to construct the lexicographically smallest word out of given letters. It was so easy! Then she tried to build multiple words and minimize one of them. This was much harder! Formally, Lucy want...
from sys import stdout n, l, k = map(int, raw_input().strip().split()) s = raw_input().strip() L = list(s) L.sort() grid = [[0 for i in xrange(l)] for j in xrange(n)] ptr1 = 0 # to iterate over L ptr2 = 0 # to mark the earliest word which has same character as kth word (in the current column) flag = 0 # to mark the...
1Python2
{ "input": [ "2 3 1\nabcabc\n", "3 2 2\nabcdef\n", "5 5 5\nuuuuuyyyyybbbbbqqqqqkkkkk\n", "10 9 2\nskpjgpwrqajrdnynybnsmybttmhkboiqlndqtghvqyorholdzwasytnvteawhahjfhjknhfobiifrtfrlbjkqyxgnc\n", "10 1 3\navdtkzddkk\n", "3 2 2\nabcdef\n", "1 10 1\nlduuukmwxx\n", "9 1 9\neeeeeeeee\n", ...
2CODEFORCES
1267_L. Lexicography_1522
Lucy likes letters. She studied the definition of the lexicographical order at school and plays with it. At first, she tried to construct the lexicographically smallest word out of given letters. It was so easy! Then she tried to build multiple words and minimize one of them. This was much harder! Formally, Lucy want...
#include <bits/stdc++.h> char S[1000002]; char D[1000002]; char R[1002][1002]; void mS(char s[], char d[], int o, int t) { int i, j, k; int c = o + t >> 1; if (o < c) { mS(d, s, o, c); } if (c + 1 < t) { mS(d, s, c + 1, t); } i = o; j = c + 1; k = o; while (i <= c && j <= t) { if (s[i] <...
2C++
{ "input": [ "2 3 1\nabcabc\n", "3 2 2\nabcdef\n", "5 5 5\nuuuuuyyyyybbbbbqqqqqkkkkk\n", "10 9 2\nskpjgpwrqajrdnynybnsmybttmhkboiqlndqtghvqyorholdzwasytnvteawhahjfhjknhfobiifrtfrlbjkqyxgnc\n", "10 1 3\navdtkzddkk\n", "3 2 2\nabcdef\n", "1 10 1\nlduuukmwxx\n", "9 1 9\neeeeeeeee\n", ...
2CODEFORCES
1267_L. Lexicography_1523
Lucy likes letters. She studied the definition of the lexicographical order at school and plays with it. At first, she tried to construct the lexicographically smallest word out of given letters. It was so easy! Then she tried to build multiple words and minimize one of them. This was much harder! Formally, Lucy want...
# ------------------- fast io -------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode...
3Python3
{ "input": [ "2 3 1\nabcabc\n", "3 2 2\nabcdef\n", "5 5 5\nuuuuuyyyyybbbbbqqqqqkkkkk\n", "10 9 2\nskpjgpwrqajrdnynybnsmybttmhkboiqlndqtghvqyorholdzwasytnvteawhahjfhjknhfobiifrtfrlbjkqyxgnc\n", "10 1 3\navdtkzddkk\n", "3 2 2\nabcdef\n", "1 10 1\nlduuukmwxx\n", "9 1 9\neeeeeeeee\n", ...
2CODEFORCES
1267_L. Lexicography_1524
Lucy likes letters. She studied the definition of the lexicographical order at school and plays with it. At first, she tried to construct the lexicographically smallest word out of given letters. It was so easy! Then she tried to build multiple words and minimize one of them. This was much harder! Formally, Lucy want...
import java.io.File; import java.io.FileNotFoundException; import java.util.Arrays; import java.util.PriorityQueue; import java.util.Scanner; public class Lexicography { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String[] nlk = scan.nextLine().split(" "); int n = Integer.pa...
4JAVA
{ "input": [ "2 3 1\nabcabc\n", "3 2 2\nabcdef\n", "5 5 5\nuuuuuyyyyybbbbbqqqqqkkkkk\n", "10 9 2\nskpjgpwrqajrdnynybnsmybttmhkboiqlndqtghvqyorholdzwasytnvteawhahjfhjknhfobiifrtfrlbjkqyxgnc\n", "10 1 3\navdtkzddkk\n", "3 2 2\nabcdef\n", "1 10 1\nlduuukmwxx\n", "9 1 9\neeeeeeeee\n", ...
2CODEFORCES
1290_A. Mind Control_1525
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
# import os # import sys # from atexit import register # from io import BytesIO # sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size)) # sys.stdout = BytesIO() # register(lambda: os.write(1, sys.stdout.getvalue())) # input = lambda: sys.stdin.readline().rstrip('\r\n') # raw_input = lambda: sys.stdin.readline().rstrip('...
1Python2
{ "input": [ "4\n6 4 2\n2 9 2 3 8 5\n4 4 1\n2 13 60 4\n4 1 3\n1 2 2 1\n2 2 0\n1 2\n", "4\n6 4 2\n2 9 2 3 8 5\n4 4 1\n2 13 60 4\n4 1 3\n1 2 1 1\n2 2 0\n1 2\n", "4\n6 4 2\n2 9 2 3 8 5\n4 4 1\n2 13 60 4\n4 2 3\n1 2 2 1\n2 2 0\n1 2\n", "4\n6 3 2\n2 9 2 3 8 5\n4 4 1\n2 13 60 4\n4 2 3\n1 2 2 1\n2 2 0\n1 2\n...
2CODEFORCES
1290_A. Mind Control_1526
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
#include <bits/stdc++.h> using namespace std; template <typename so> void read(so &x) { x = 0; char c; long long dem = 0; for (c = getchar(); c < '0' || c > '9'; c = getchar()) { dem++; if (dem == 100) return; } for (; c >= '0' && c <= '9'; c = getchar()) { x = x * 10 + c - '0'; } } const long...
2C++
{ "input": [ "4\n6 4 2\n2 9 2 3 8 5\n4 4 1\n2 13 60 4\n4 1 3\n1 2 2 1\n2 2 0\n1 2\n", "4\n6 4 2\n2 9 2 3 8 5\n4 4 1\n2 13 60 4\n4 1 3\n1 2 1 1\n2 2 0\n1 2\n", "4\n6 4 2\n2 9 2 3 8 5\n4 4 1\n2 13 60 4\n4 2 3\n1 2 2 1\n2 2 0\n1 2\n", "4\n6 3 2\n2 9 2 3 8 5\n4 4 1\n2 13 60 4\n4 2 3\n1 2 2 1\n2 2 0\n1 2\n...
2CODEFORCES
1290_A. Mind Control_1527
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
t = int(input()) for _ in range(t): ans = 0 n, pos, control = map(int, input().split()) control = min(control, pos - 1) not_control = pos - control - 1 num = n - control - not_control a = list(map(int, input().split())) for i in range(control + 1): tmp = 10 ** 10 + 1 for j in...
3Python3
{ "input": [ "4\n6 4 2\n2 9 2 3 8 5\n4 4 1\n2 13 60 4\n4 1 3\n1 2 2 1\n2 2 0\n1 2\n", "4\n6 4 2\n2 9 2 3 8 5\n4 4 1\n2 13 60 4\n4 1 3\n1 2 1 1\n2 2 0\n1 2\n", "4\n6 4 2\n2 9 2 3 8 5\n4 4 1\n2 13 60 4\n4 2 3\n1 2 2 1\n2 2 0\n1 2\n", "4\n6 3 2\n2 9 2 3 8 5\n4 4 1\n2 13 60 4\n4 2 3\n1 2 2 1\n2 2 0\n1 2\n...
2CODEFORCES
1290_A. Mind Control_1528
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
import java.math.BigInteger; import java.util.*; import java.util.stream.Stream; import static java.lang.Math.max; import static java.lang.Math.min; public class Main { private static Scanner in = new Scanner(System.in); public static void main(String[] args) { int t = in.nextInt(); for (int ...
4JAVA
{ "input": [ "4\n6 4 2\n2 9 2 3 8 5\n4 4 1\n2 13 60 4\n4 1 3\n1 2 2 1\n2 2 0\n1 2\n", "4\n6 4 2\n2 9 2 3 8 5\n4 4 1\n2 13 60 4\n4 1 3\n1 2 1 1\n2 2 0\n1 2\n", "4\n6 4 2\n2 9 2 3 8 5\n4 4 1\n2 13 60 4\n4 2 3\n1 2 2 1\n2 2 0\n1 2\n", "4\n6 3 2\n2 9 2 3 8 5\n4 4 1\n2 13 60 4\n4 2 3\n1 2 2 1\n2 2 0\n1 2\n...
2CODEFORCES
1310_B. Double Elimination_1529
The biggest event of the year – Cota 2 world championship "The Innernational" is right around the corner. 2^n teams will compete in a double-elimination format (please, carefully read problem statement even if you know what is it) to identify the champion. Teams are numbered from 1 to 2^n and will play games one-on-o...
#include <bits/stdc++.h> inline long long read() { long long x = 0, f = 1; char c = getchar(); for (; c > '9' || c < '0'; c = getchar()) { if (c == '-') f = -1; } for (; c >= '0' && c <= '9'; c = getchar()) { x = x * 10 + c - '0'; } return x * f; } int dp[18][(1 << 18)][2][2]; bool fan[200005]; in...
2C++
{ "input": [ "3 4\n1 3 5 7\n", "3 3\n1 7 8\n", "3 1\n6\n", "2 1\n1\n", "3 5\n7 2 1 4 8\n", "2 0\n", "2 3\n2 1 3\n", "3 6\n5 4 1 3 6 7\n", "10 10\n334 588 666 787 698 768 934 182 39 834\n", "3 8\n2 5 6 1 8 3 4 7\n", "17 0\n", "3 7\n5 4 8 1 7 3 6\n", "17 1\n95887\n", ...
2CODEFORCES
1310_B. Double Elimination_1530
The biggest event of the year – Cota 2 world championship "The Innernational" is right around the corner. 2^n teams will compete in a double-elimination format (please, carefully read problem statement even if you know what is it) to identify the champion. Teams are numbered from 1 to 2^n and will play games one-on-o...
import java.io.*; import java.math.*; import java.util.*; import java.util.stream.*; public class B { void submit() { int n = nextInt(); int k = nextInt(); int[] a = new int[1 << n]; for (int i = 0; i < k; i++) { a[nextInt() - 1] = 1; } if (k == 0) { out.println(0); return; } int ans = 1; ...
4JAVA
{ "input": [ "3 4\n1 3 5 7\n", "3 3\n1 7 8\n", "3 1\n6\n", "2 1\n1\n", "3 5\n7 2 1 4 8\n", "2 0\n", "2 3\n2 1 3\n", "3 6\n5 4 1 3 6 7\n", "10 10\n334 588 666 787 698 768 934 182 39 834\n", "3 8\n2 5 6 1 8 3 4 7\n", "17 0\n", "3 7\n5 4 8 1 7 3 6\n", "17 1\n95887\n", ...
2CODEFORCES
1332_G. No Monotone Triples_1531
Given a sequence of integers a of length n, a tuple (i,j,k) is called monotone triples if * 1 ≤ i<j<k≤ n; * a_i ≤ a_j ≤ a_k or a_i ≥ a_j ≥ a_k is satisfied. For example, a=[5,3,4,5], then (2,3,4) is monotone triples for sequence a while (1,3,4) is not. Bob is given a sequence of integers a of length n in a ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5; int a[maxn + 11], lmin[maxn + 11], lmax[maxn + 11], rmin[maxn + 11], rmax[maxn + 11]; int ans3[maxn + 11][5], ans4[maxn + 11][5]; set<int>::iterator it; vector<int> v[maxn + 11]; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);...
2C++
{ "input": [ "6 2\n3 1 4 1 5 9\n1 3\n4 6\n", "10 5\n448242954 927941687 223935474 107020324 288030870 635970780 444360884 697847668 783719272 808030300\n3 10\n4 9\n3 8\n2 5\n5 9\n", "3 1\n1000000000 1000000000 1000000000\n1 3\n", "30 27\n698632656 525581861 577504542 296603772 998990943 682881766 9548...
2CODEFORCES
1332_G. No Monotone Triples_1532
Given a sequence of integers a of length n, a tuple (i,j,k) is called monotone triples if * 1 ≤ i<j<k≤ n; * a_i ≤ a_j ≤ a_k or a_i ≥ a_j ≥ a_k is satisfied. For example, a=[5,3,4,5], then (2,3,4) is monotone triples for sequence a while (1,3,4) is not. Bob is given a sequence of integers a of length n in a ...
import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline from operator import itemgetter import bisect n,q=map(int,input().split()) A=[-1]+list(map(int,input().split())) Q=[list(map(int,input().split()))+[i] for i in range(q)] Q.sort(key=itemgetter(1)) Q_ind=0 ANS1=[-1000,-1000,-1000,-100...
3Python3
{ "input": [ "6 2\n3 1 4 1 5 9\n1 3\n4 6\n", "10 5\n448242954 927941687 223935474 107020324 288030870 635970780 444360884 697847668 783719272 808030300\n3 10\n4 9\n3 8\n2 5\n5 9\n", "3 1\n1000000000 1000000000 1000000000\n1 3\n", "30 27\n698632656 525581861 577504542 296603772 998990943 682881766 9548...
2CODEFORCES
1353_C. Board Moves_1533
You are given a board of size n × n, where n is odd (not divisible by 2). Initially, each cell of the board contains one figure. In one move, you can select exactly one figure presented in some cell and move it to one of the cells sharing a side or a corner with the current cell, i.e. from the cell (i, j) you can move...
cases = int(input()) while cases > 0: sum = 0 n = int(input()) while n > 1: sum = sum + ((4 * n - 4) * ((n - 1) / 2)) n = n - 2 print(int(sum)) cases = cases - 1
1Python2
{ "input": [ "3\n1\n5\n499993\n", "3\n5\n3005\n3005\n", "1\n69791\n", "1\n214541\n", "1\n499999\n", "1\n214145\n", "3\n5\n3005\n1983\n", "1\n203317\n", "3\n7\n3005\n3005\n", "1\n288977\n", "1\n254785\n", "1\n54111\n", "3\n7\n3005\n5103\n", "1\n151107\n", "1\...
2CODEFORCES
1353_C. Board Moves_1534
You are given a board of size n × n, where n is odd (not divisible by 2). Initially, each cell of the board contains one figure. In one move, you can select exactly one figure presented in some cell and move it to one of the cells sharing a side or a corner with the current cell, i.e. from the cell (i, j) you can move...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; long long sum = 0; int j = (n - 1) / 2; for (int i = 0; i < j; i++) { sum += pow(i + 1, 2) * 8; } cout << sum << "\n"; } }
2C++
{ "input": [ "3\n1\n5\n499993\n", "3\n5\n3005\n3005\n", "1\n69791\n", "1\n214541\n", "1\n499999\n", "1\n214145\n", "3\n5\n3005\n1983\n", "1\n203317\n", "3\n7\n3005\n3005\n", "1\n288977\n", "1\n254785\n", "1\n54111\n", "3\n7\n3005\n5103\n", "1\n151107\n", "1\...
2CODEFORCES
1353_C. Board Moves_1535
You are given a board of size n × n, where n is odd (not divisible by 2). Initially, each cell of the board contains one figure. In one move, you can select exactly one figure presented in some cell and move it to one of the cells sharing a side or a corner with the current cell, i.e. from the cell (i, j) you can move...
I = input for _ in range(int(I())): n = int(I())+1 s = 0 for i in range(1,n//2): s += 8*i*i print(s)
3Python3
{ "input": [ "3\n1\n5\n499993\n", "3\n5\n3005\n3005\n", "1\n69791\n", "1\n214541\n", "1\n499999\n", "1\n214145\n", "3\n5\n3005\n1983\n", "1\n203317\n", "3\n7\n3005\n3005\n", "1\n288977\n", "1\n254785\n", "1\n54111\n", "3\n7\n3005\n5103\n", "1\n151107\n", "1\...
2CODEFORCES
1353_C. Board Moves_1536
You are given a board of size n × n, where n is odd (not divisible by 2). Initially, each cell of the board contains one figure. In one move, you can select exactly one figure presented in some cell and move it to one of the cells sharing a side or a corner with the current cell, i.e. from the cell (i, j) you can move...
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.*; public class C { public static void main(String[] args) { Scanner I = new Scanner(new BufferedReader(new InputStreamReader(System.in))); int t = I.nextInt(); while (t > 0) { t--; ...
4JAVA
{ "input": [ "3\n1\n5\n499993\n", "3\n5\n3005\n3005\n", "1\n69791\n", "1\n214541\n", "1\n499999\n", "1\n214145\n", "3\n5\n3005\n1983\n", "1\n203317\n", "3\n7\n3005\n3005\n", "1\n288977\n", "1\n254785\n", "1\n54111\n", "3\n7\n3005\n5103\n", "1\n151107\n", "1\...
2CODEFORCES
1373_B. 01 Game_1537
Alica and Bob are playing a game. Initially they have a binary string s consisting of only characters 0 and 1. Alice and Bob make alternating moves: Alice makes the first move, Bob makes the second move, Alice makes the third one, and so on. During each move, the current player must choose two different adjacent char...
# template by 3xC and starkizard. # contributors: ##################################################################################### from __future__ import division, print_function import sys import os from collections import Counter, deque, defaultdict import itertools import math import io """Uncomment modul...
1Python2
{ "input": [ "3\n01\n1111\n0011\n", "1\n00000000000\n", "1\n111111111111111110000000000000000\n", "1\n11111111111\n", "1\n1\n", "1\n0\n", "1\n1111111111\n", "2\n11111111111\n11111111111\n", "1\n00000000010\n", "1\n111111111111101110000000000000000\n", "2\n11111111101\n11111...
2CODEFORCES
1373_B. 01 Game_1538
Alica and Bob are playing a game. Initially they have a binary string s consisting of only characters 0 and 1. Alice and Bob make alternating moves: Alice makes the first move, Bob makes the second move, Alice makes the third one, and so on. During each move, the current player must choose two different adjacent char...
#include <bits/stdc++.h> using namespace std; int main() { int t, zer, jed, x; cin >> t; string s; for (int i = 0; i < t; i++) { cin >> s; zer = 0; jed = 0; for (int j = 0; j < s.size(); j++) { switch (s[j]) { case '0': zer++; break; case '1': ...
2C++
{ "input": [ "3\n01\n1111\n0011\n", "1\n00000000000\n", "1\n111111111111111110000000000000000\n", "1\n11111111111\n", "1\n1\n", "1\n0\n", "1\n1111111111\n", "2\n11111111111\n11111111111\n", "1\n00000000010\n", "1\n111111111111101110000000000000000\n", "2\n11111111101\n11111...
2CODEFORCES
1373_B. 01 Game_1539
Alica and Bob are playing a game. Initially they have a binary string s consisting of only characters 0 and 1. Alice and Bob make alternating moves: Alice makes the first move, Bob makes the second move, Alice makes the third one, and so on. During each move, the current player must choose two different adjacent char...
from sys import stdin,stdout t=int(stdin.readline().strip()) for _ in range(t): s=stdin.readline().strip() stdout.write(("NET","DA")[min(s.count('0'),s.count('1')) % 2]+"\n")
3Python3
{ "input": [ "3\n01\n1111\n0011\n", "1\n00000000000\n", "1\n111111111111111110000000000000000\n", "1\n11111111111\n", "1\n1\n", "1\n0\n", "1\n1111111111\n", "2\n11111111111\n11111111111\n", "1\n00000000010\n", "1\n111111111111101110000000000000000\n", "2\n11111111101\n11111...
2CODEFORCES
1373_B. 01 Game_1540
Alica and Bob are playing a game. Initially they have a binary string s consisting of only characters 0 and 1. Alice and Bob make alternating moves: Alice makes the first move, Bob makes the second move, Alice makes the third one, and so on. During each move, the current player must choose two different adjacent char...
import java.io.*; import java.util.*; public class game{ public static void main(String[] args){ Scanner scan = new Scanner(System.in); int t = scan.nextInt(); for(int i = 0; i<t; i++){ String s =scan.next(); int count1 = 0; int count0 = 0; in...
4JAVA
{ "input": [ "3\n01\n1111\n0011\n", "1\n00000000000\n", "1\n111111111111111110000000000000000\n", "1\n11111111111\n", "1\n1\n", "1\n0\n", "1\n1111111111\n", "2\n11111111111\n11111111111\n", "1\n00000000010\n", "1\n111111111111101110000000000000000\n", "2\n11111111101\n11111...
2CODEFORCES
1396_A. Multiples of Length_1541
You are given an array a of n integers. You want to make all elements of a equal to zero by doing the following operation exactly three times: * Select a segment, for each number in this segment we can add a multiple of len to it, where len is the length of this segment (added integers can be different). It can...
FAST_IO = 0 if FAST_IO: import io, sys, atexit rr = iter(sys.stdin.read().splitlines()).next sys.stdout = _OUTPUT_BUFFER = io.BytesIO() @atexit.register def write(): sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) else: rr = raw_input rri = lambda: int(rr()) rrm = lambda: map(int, rr()....
1Python2
{ "input": [ "4\n1 3 2 4\n", "1\n-2\n", "1\n-1\n", "16\n-15108237 489260742 681810357 -78861365 -416467743 -896443270 904192296 -932642644 173249302 402207268 -329323498 537696045 -899233426 902347982 -595589754 -480337024\n", "2\n-492673762 -496405053\n", "1\n34688642\n", "32\n474784688 6...
2CODEFORCES
1396_A. Multiples of Length_1542
You are given an array a of n integers. You want to make all elements of a equal to zero by doing the following operation exactly three times: * Select a segment, for each number in this segment we can add a multiple of len to it, where len is the length of this segment (added integers can be different). It can...
#include <bits/stdc++.h> using namespace std; long long ara[100005]; long long aa[100005], bb[100005]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%lld", ara + i); if (n == 1) { printf("1 1\n%lld\n", -ara[1]); printf("1 1\n0\n"); printf("1 1\n0\n"); return 0; } f...
2C++
{ "input": [ "4\n1 3 2 4\n", "1\n-2\n", "1\n-1\n", "16\n-15108237 489260742 681810357 -78861365 -416467743 -896443270 904192296 -932642644 173249302 402207268 -329323498 537696045 -899233426 902347982 -595589754 -480337024\n", "2\n-492673762 -496405053\n", "1\n34688642\n", "32\n474784688 6...
2CODEFORCES
1396_A. Multiples of Length_1543
You are given an array a of n integers. You want to make all elements of a equal to zero by doing the following operation exactly three times: * Select a segment, for each number in this segment we can add a multiple of len to it, where len is the length of this segment (added integers can be different). It can...
n=int(input());vals=list(map(int,input().split())) if n>=2: print(1,n) ans=[-i*n for i in vals] print(*ans) print(2,n) a1=[i*(n-1) for i in vals[1:n]] print(*a1) print(1,1) print(vals[0]*(n-1)) else: print(1,1) print(-vals[0]) print(1,1) print(0) print(1,1) print(...
3Python3
{ "input": [ "4\n1 3 2 4\n", "1\n-2\n", "1\n-1\n", "16\n-15108237 489260742 681810357 -78861365 -416467743 -896443270 904192296 -932642644 173249302 402207268 -329323498 537696045 -899233426 902347982 -595589754 -480337024\n", "2\n-492673762 -496405053\n", "1\n34688642\n", "32\n474784688 6...
2CODEFORCES
1396_A. Multiples of Length_1544
You are given an array a of n integers. You want to make all elements of a equal to zero by doing the following operation exactly three times: * Select a segment, for each number in this segment we can add a multiple of len to it, where len is the length of this segment (added integers can be different). It can...
//package codeforces.D666; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; import java.util.StringTokenizer; /** * @author muhossain * @since 2020-08-1...
4JAVA
{ "input": [ "4\n1 3 2 4\n", "1\n-2\n", "1\n-1\n", "16\n-15108237 489260742 681810357 -78861365 -416467743 -896443270 904192296 -932642644 173249302 402207268 -329323498 537696045 -899233426 902347982 -595589754 -480337024\n", "2\n-492673762 -496405053\n", "1\n34688642\n", "32\n474784688 6...
2CODEFORCES
141_C. Queue_1545
In the Main Berland Bank n people stand in a queue at the cashier, everyone knows his/her height hi, and the heights of the other people in the queue. Each of them keeps in mind number ai — how many people who are taller than him/her and stand in queue in front of him. After a while the cashier has a lunch break and t...
info = [] ans = [] n = input() for i in range(n): b = raw_input().split() info.append([b[0], int(b[1])]) info.sort(key = lambda x : x[1]) for j, i in enumerate(info): if(i[1] > j): print -1 break ans.insert(i[1], (i[0], n - j)) else: for i in ans: print i[0], i[1]
1Python2
{ "input": [ "4\nvasya 0\npetya 1\nmanya 3\ndunay 3\n", "4\na 0\nb 2\nc 0\nd 0\n", "23\nfgtxkw 4\nqgbokh 0\nfrb 0\nnninr 10\nbczzdfvjkh 1\nuxpelsmxxq 2\nntvvx 2\nardaae 0\nctetnl 0\nhgk 0\nvmwo 18\nojaubfibf 1\nnu 7\ngbixtuotft 4\nekmjrgxylj 1\navcygg 1\nmxgdulijf 1\notjmjmvpz 3\nxzubpxqnj 14\nlowoz 3\nmn...
2CODEFORCES
141_C. Queue_1546
In the Main Berland Bank n people stand in a queue at the cashier, everyone knows his/her height hi, and the heights of the other people in the queue. Each of them keeps in mind number ai — how many people who are taller than him/her and stand in queue in front of him. After a while the cashier has a lunch break and t...
#include <bits/stdc++.h> using namespace std; int main() { int n, nop, i, j, k, l, a, temp; char b[100]; string stt[3010]; vector<pair<int, string> > vct; vector<int> v2, v3; cin >> n; nop = n; for (i = 0; i < n; i++) { cin >> stt[i] >> a; vct.push_back(make_pair(a, stt[i])); v2.push_back(i)...
2C++
{ "input": [ "4\nvasya 0\npetya 1\nmanya 3\ndunay 3\n", "4\na 0\nb 2\nc 0\nd 0\n", "23\nfgtxkw 4\nqgbokh 0\nfrb 0\nnninr 10\nbczzdfvjkh 1\nuxpelsmxxq 2\nntvvx 2\nardaae 0\nctetnl 0\nhgk 0\nvmwo 18\nojaubfibf 1\nnu 7\ngbixtuotft 4\nekmjrgxylj 1\navcygg 1\nmxgdulijf 1\notjmjmvpz 3\nxzubpxqnj 14\nlowoz 3\nmn...
2CODEFORCES
141_C. Queue_1547
In the Main Berland Bank n people stand in a queue at the cashier, everyone knows his/her height hi, and the heights of the other people in the queue. Each of them keeps in mind number ai — how many people who are taller than him/her and stand in queue in front of him. After a while the cashier has a lunch break and t...
def solve(arr,n): arr.sort() names = [x[1] for x in arr] counts = [x[0] for x in arr] segments = [] curr_count = counts[0] curr_len = 0 L = 0 for i in range(n): if counts[i]==curr_count: curr_len += 1 else: segments.append((L,i-1)) ...
3Python3
{ "input": [ "4\nvasya 0\npetya 1\nmanya 3\ndunay 3\n", "4\na 0\nb 2\nc 0\nd 0\n", "23\nfgtxkw 4\nqgbokh 0\nfrb 0\nnninr 10\nbczzdfvjkh 1\nuxpelsmxxq 2\nntvvx 2\nardaae 0\nctetnl 0\nhgk 0\nvmwo 18\nojaubfibf 1\nnu 7\ngbixtuotft 4\nekmjrgxylj 1\navcygg 1\nmxgdulijf 1\notjmjmvpz 3\nxzubpxqnj 14\nlowoz 3\nmn...
2CODEFORCES
141_C. Queue_1548
In the Main Berland Bank n people stand in a queue at the cashier, everyone knows his/her height hi, and the heights of the other people in the queue. Each of them keeps in mind number ai — how many people who are taller than him/her and stand in queue in front of him. After a while the cashier has a lunch break and t...
import java.io.*; import java.util.*; public class Ochered implements Runnable { public static void main(String[] args) { new Thread(new Ochered()).run(); } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer in; PrintWriter...
4JAVA
{ "input": [ "4\nvasya 0\npetya 1\nmanya 3\ndunay 3\n", "4\na 0\nb 2\nc 0\nd 0\n", "23\nfgtxkw 4\nqgbokh 0\nfrb 0\nnninr 10\nbczzdfvjkh 1\nuxpelsmxxq 2\nntvvx 2\nardaae 0\nctetnl 0\nhgk 0\nvmwo 18\nojaubfibf 1\nnu 7\ngbixtuotft 4\nekmjrgxylj 1\navcygg 1\nmxgdulijf 1\notjmjmvpz 3\nxzubpxqnj 14\nlowoz 3\nmn...
2CODEFORCES
1438_C. Engineer Artem_1549
Artem is building a new robot. He has a matrix a consisting of n rows and m columns. The cell located on the i-th row from the top and the j-th column from the left has a value a_{i,j} written in it. If two adjacent cells contain the same value, the robot will break. A matrix is called good if no two adjacent cells c...
from sys import stdin t = int(stdin.readline()) for _ in xrange(t): n,m = map(int,stdin.readline().split()) for i in xrange(n): a = map(int,stdin.readline().split()) for j in xrange(m): x = a[j] if (i+j)%2 != x%2: x+=1 print x, print ""
1Python2
{ "input": [ "3\n3 2\n1 2\n4 5\n7 8\n2 2\n1 1\n3 3\n2 2\n1 3\n2 2\n", "1\n10 10\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n", "3\n3 2\n1 2...
2CODEFORCES
1438_C. Engineer Artem_1550
Artem is building a new robot. He has a matrix a consisting of n rows and m columns. The cell located on the i-th row from the top and the j-th column from the left has a value a_{i,j} written in it. If two adjacent cells contain the same value, the robot will break. A matrix is called good if no two adjacent cells c...
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { int f = 1; x = 0; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } x *= f; } signed main() { register in...
2C++
{ "input": [ "3\n3 2\n1 2\n4 5\n7 8\n2 2\n1 1\n3 3\n2 2\n1 3\n2 2\n", "1\n10 10\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n", "3\n3 2\n1 2...
2CODEFORCES
1438_C. Engineer Artem_1551
Artem is building a new robot. He has a matrix a consisting of n rows and m columns. The cell located on the i-th row from the top and the j-th column from the left has a value a_{i,j} written in it. If two adjacent cells contain the same value, the robot will break. A matrix is called good if no two adjacent cells c...
def solve(): input_str = input().split() m, n = int(input_str[0]), int(input_str[1]) nums = [] for i in range(m): nums.append(list(map(int, input().split()))) for i in range(m): for j in range(n): if (i + j) & 1 == 0: if nums[i][j] & 1 == 0: ...
3Python3
{ "input": [ "3\n3 2\n1 2\n4 5\n7 8\n2 2\n1 1\n3 3\n2 2\n1 3\n2 2\n", "1\n10 10\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n", "3\n3 2\n1 2...
2CODEFORCES
1438_C. Engineer Artem_1552
Artem is building a new robot. He has a matrix a consisting of n rows and m columns. The cell located on the i-th row from the top and the j-th column from the left has a value a_{i,j} written in it. If two adjacent cells contain the same value, the robot will break. A matrix is called good if no two adjacent cells c...
// package T800; import java.io.PrintWriter; import java.util.HashSet; import java.util.Scanner; public class GERGOVIA { public static PrintWriter out = new PrintWriter(System.out); public static Scanner in = new Scanner(System.in); public static void main(String[] args) { int n = ni(); while (n-- > 0...
4JAVA
{ "input": [ "3\n3 2\n1 2\n4 5\n7 8\n2 2\n1 1\n3 3\n2 2\n1 3\n2 2\n", "1\n10 10\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n", "3\n3 2\n1 2...
2CODEFORCES
1463_B. Find The Array_1553
You are given an array [a_1, a_2, ..., a_n] such that 1 ≤ a_i ≤ 10^9. Let S be the sum of all elements of the array a. Let's call an array b of n integers beautiful if: * 1 ≤ b_i ≤ 10^9 for each i from 1 to n; * for every pair of adjacent integers from the array (b_i, b_{i + 1}), either b_i divides b_{i + 1}, or...
for _ in range(input()): n=input() a=map(int,raw_input().split()) b=[] c=[] f,g=0,0 for i in range(n): if i%2: b.append(1);c.append(a[i]) f+=(a[i]-1) else: c.append(1);b.append(a[i]) g+=(a[i]-1) s="" if 2*f<=sum...
1Python2
{ "input": [ "4\n5\n1 2 3 4 5\n2\n4 6\n2\n1 1000000000\n6\n3 4 8 1 2 3\n", "1\n10\n1000000000 500000001 500000001 500000001 500000001 500000001 500000001 500000001 500000001 500000001\n", "2\n7\n818 14 386 159 110 186 49\n7\n694 42 511 953 30 284 57\n", "1\n3\n1 1 1\n", "1\n4\n37 19 19 19\n", ...
2CODEFORCES
1463_B. Find The Array_1554
You are given an array [a_1, a_2, ..., a_n] such that 1 ≤ a_i ≤ 10^9. Let S be the sum of all elements of the array a. Let's call an array b of n integers beautiful if: * 1 ≤ b_i ≤ 10^9 for each i from 1 to n; * for every pair of adjacent integers from the array (b_i, b_{i + 1}), either b_i divides b_{i + 1}, or...
// // Created by Ильдар Ялалов on 14.01.2020. // //#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf_int =...
2C++
{ "input": [ "4\n5\n1 2 3 4 5\n2\n4 6\n2\n1 1000000000\n6\n3 4 8 1 2 3\n", "1\n10\n1000000000 500000001 500000001 500000001 500000001 500000001 500000001 500000001 500000001 500000001\n", "2\n7\n818 14 386 159 110 186 49\n7\n694 42 511 953 30 284 57\n", "1\n3\n1 1 1\n", "1\n4\n37 19 19 19\n", ...
2CODEFORCES
1463_B. Find The Array_1555
You are given an array [a_1, a_2, ..., a_n] such that 1 ≤ a_i ≤ 10^9. Let S be the sum of all elements of the array a. Let's call an array b of n integers beautiful if: * 1 ≤ b_i ≤ 10^9 for each i from 1 to n; * for every pair of adjacent integers from the array (b_i, b_{i + 1}), either b_i divides b_{i + 1}, or...
for _ in range(int(input())): n = map(int, input().split()) a = list(map(int, input().split())) c = 1 i = 0 while c <= 1000000000: d = 2 * c if c <= a[i] <= d: print(c, end=" ") i += 1 d = 1 if i == len(a): break c = d ...
3Python3
{ "input": [ "4\n5\n1 2 3 4 5\n2\n4 6\n2\n1 1000000000\n6\n3 4 8 1 2 3\n", "1\n10\n1000000000 500000001 500000001 500000001 500000001 500000001 500000001 500000001 500000001 500000001\n", "2\n7\n818 14 386 159 110 186 49\n7\n694 42 511 953 30 284 57\n", "1\n3\n1 1 1\n", "1\n4\n37 19 19 19\n", ...
2CODEFORCES
1463_B. Find The Array_1556
You are given an array [a_1, a_2, ..., a_n] such that 1 ≤ a_i ≤ 10^9. Let S be the sum of all elements of the array a. Let's call an array b of n integers beautiful if: * 1 ≤ b_i ≤ 10^9 for each i from 1 to n; * for every pair of adjacent integers from the array (b_i, b_{i + 1}), either b_i divides b_{i + 1}, or...
import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { Scanner in=new Scanner(System.in); int t=in.nextInt(); while(t-->0) { ...
4JAVA
{ "input": [ "4\n5\n1 2 3 4 5\n2\n4 6\n2\n1 1000000000\n6\n3 4 8 1 2 3\n", "1\n10\n1000000000 500000001 500000001 500000001 500000001 500000001 500000001 500000001 500000001 500000001\n", "2\n7\n818 14 386 159 110 186 49\n7\n694 42 511 953 30 284 57\n", "1\n3\n1 1 1\n", "1\n4\n37 19 19 19\n", ...
2CODEFORCES
148_B. Escape_1557
The princess is going to escape the dragon's cave, and she needs to plan it carefully. The princess runs at vp miles per hour, and the dragon flies at vd miles per hour. The dragon will discover the escape after t hours and will chase the princess immediately. Looks like there's no chance to success, but the princess ...
i=input p,d,t,f,c=i(),i(),i(),i(),i() r=0 T=t x=t*p*1./(d-p) if d > p else c / p c -= t*p while True: c -= x*p T+=x if c > 0: r += 1 else: break x=(2*T*p + f*d)*1./(d - p) print r
1Python2
{ "input": [ "1\n2\n1\n1\n10\n", "1\n2\n1\n1\n8\n", "71\n19\n2\n10\n645\n", "6\n24\n9\n8\n628\n", "26\n36\n4\n7\n318\n", "2\n100\n10\n10\n739\n", "47\n43\n10\n9\n43\n", "71\n45\n2\n6\n547\n", "2\n1\n1\n1\n1000\n", "13\n14\n3\n3\n79\n", "77\n1\n6\n8\n831\n", "2\n27\n4\n9...
2CODEFORCES
148_B. Escape_1558
The princess is going to escape the dragon's cave, and she needs to plan it carefully. The princess runs at vp miles per hour, and the dragon flies at vd miles per hour. The dragon will discover the escape after t hours and will chase the princess immediately. Looks like there's no chance to success, but the princess ...
#include <bits/stdc++.h> using namespace std; int main() { int vp, vd, t, f, c; scanf("%d %d %d %d %d", &vp, &vd, &t, &f, &c); int kol = 0; if (vp < vd) { double t0 = c; t0 /= vp; double T = vp * t; T /= vd - vp; double x = t; while (x + T < t0) { kol++; x = x + 2 * T + f; ...
2C++
{ "input": [ "1\n2\n1\n1\n10\n", "1\n2\n1\n1\n8\n", "71\n19\n2\n10\n645\n", "6\n24\n9\n8\n628\n", "26\n36\n4\n7\n318\n", "2\n100\n10\n10\n739\n", "47\n43\n10\n9\n43\n", "71\n45\n2\n6\n547\n", "2\n1\n1\n1\n1000\n", "13\n14\n3\n3\n79\n", "77\n1\n6\n8\n831\n", "2\n27\n4\n9...
2CODEFORCES
148_B. Escape_1559
The princess is going to escape the dragon's cave, and she needs to plan it carefully. The princess runs at vp miles per hour, and the dragon flies at vd miles per hour. The dragon will discover the escape after t hours and will chase the princess immediately. Looks like there's no chance to success, but the princess ...
vp = int(input()) vd = int(input()) t = int(input()) f = int(input()) c = int(input()) distance = t * vp time = t treasure = 0 if vp == vd: if t == 0: print(1) else: print(0) elif vp > vd: print(0) else: while distance < c: timeadd = distance/(vd - vp) distance += vp * ti...
3Python3
{ "input": [ "1\n2\n1\n1\n10\n", "1\n2\n1\n1\n8\n", "71\n19\n2\n10\n645\n", "6\n24\n9\n8\n628\n", "26\n36\n4\n7\n318\n", "2\n100\n10\n10\n739\n", "47\n43\n10\n9\n43\n", "71\n45\n2\n6\n547\n", "2\n1\n1\n1\n1000\n", "13\n14\n3\n3\n79\n", "77\n1\n6\n8\n831\n", "2\n27\n4\n9...
2CODEFORCES
148_B. Escape_1560
The princess is going to escape the dragon's cave, and she needs to plan it carefully. The princess runs at vp miles per hour, and the dragon flies at vd miles per hour. The dragon will discover the escape after t hours and will chase the princess immediately. Looks like there's no chance to success, but the princess ...
import java.io.*; public class Main { public static void main(String[] args) throws IOException { int vp,vd,t,f,c,count=0; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out)); vp=Integer.pars...
4JAVA
{ "input": [ "1\n2\n1\n1\n10\n", "1\n2\n1\n1\n8\n", "71\n19\n2\n10\n645\n", "6\n24\n9\n8\n628\n", "26\n36\n4\n7\n318\n", "2\n100\n10\n10\n739\n", "47\n43\n10\n9\n43\n", "71\n45\n2\n6\n547\n", "2\n1\n1\n1\n1000\n", "13\n14\n3\n3\n79\n", "77\n1\n6\n8\n831\n", "2\n27\n4\n9...
2CODEFORCES
1511_F. Chainword_1561
A chainword is a special type of crossword. As most of the crosswords do, it has cells that you put the letters in and some sort of hints to what these letters should be. The letter cells in a chainword are put in a single row. We will consider chainwords of length m in this task. A hint to a chainword is a sequence ...
#include <cstdlib> #include <iostream> #include <cstdio> #include <math.h> #include <cstring> #include <time.h> #include <complex> #include <algorithm> #include <queue> #include <stack> #include <unordered_map> #include <set> #include <bitset> #pragma warning(disable:4996) #define PII std::pair<long long, long long> #...
2C++
{ "input": [ "3 5\nababa\nab\na\n", "2 4\nab\ncd\n", "5 100\na\naa\naaa\naaaa\naaaaa\n", "8 1000000000\nbabba\nb\nbb\nbbaaa\naaaba\nabaab\naabaa\nbaaba\n", "8 1000000\nks\nmbha\nbyn\ncz\ng\nmv\nnct\nbty\n", "8 3\nba\nbbb\nbb\naba\naab\nbaa\nb\na\n", "8 5\nabb\nbaa\na\naba\naa\nb\nba\nbb\n"...
2CODEFORCES
1511_F. Chainword_1562
A chainword is a special type of crossword. As most of the crosswords do, it has cells that you put the letters in and some sort of hints to what these letters should be. The letter cells in a chainword are put in a single row. We will consider chainwords of length m in this task. A hint to a chainword is a sequence ...
import java.util.*; import java.io.*; public class F2 { static long mod = 998244353; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); String[] s = new String[n]; for(int i = 0; i < n; i++) { s[i] = sc.next(); } HashSet<...
4JAVA
{ "input": [ "3 5\nababa\nab\na\n", "2 4\nab\ncd\n", "5 100\na\naa\naaa\naaaa\naaaaa\n", "8 1000000000\nbabba\nb\nbb\nbbaaa\naaaba\nabaab\naabaa\nbaaba\n", "8 1000000\nks\nmbha\nbyn\ncz\ng\nmv\nnct\nbty\n", "8 3\nba\nbbb\nbb\naba\naab\nbaa\nb\na\n", "8 5\nabb\nbaa\na\naba\naa\nb\nba\nbb\n"...
2CODEFORCES
1539_D. PriceFixed_1563
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store — "PriceFixed". Here are some rules of that store: * The store has an infinite number of items of every product. * All products have the same price: 2 rubles per item. * ...
from __future__ import division,print_function from heapq import* import sys A,B=[],[] le = sys.__stdin__.read().split("\n")[::-1] for zorg in range(int(le.pop())): a,b= list(map(int,le.pop().split())) A.append(a) B.append(b) n=len(A) s=sum(A) pr=sorted((b,a) for a,b in zip(A,B)) r=0#to return nbb=0#number ...
1Python2
{ "input": [ "5\n2 7\n2 8\n1 2\n2 4\n1 8\n", "3\n3 4\n1 3\n1 5\n", "8\n1 8\n1 6\n1 5\n1 3\n1 3\n1 8\n1 7\n1 3\n", "4\n4 1\n2 2\n1 6\n1 2\n", "7\n2 11\n3 12\n2 1\n2 6\n1 6\n2 2\n3 14\n", "8\n1 7\n3 16\n1 15\n2 1\n1 15\n4 11\n1 4\n2 15\n", "4\n2 1\n3 2\n4 3\n5 100\n", "15\n1 7\n1 14\n1 6...
2CODEFORCES
1539_D. PriceFixed_1564
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store — "PriceFixed". Here are some rules of that store: * The store has an infinite number of items of every product. * All products have the same price: 2 rubles per item. * ...
#include<bits/stdc++.h> using namespace std; #define int long long //delete if causing problems #define F first #define S second #define setbit(n) __builtin_popcountll(n) #define all(x) x.begin() , x.end() #define clr(x) memset(x,0,sizeof(x)) #define fast ios_base::sync_with_stdio(0); cin.tie(0); #define endl "\n" //d...
2C++
{ "input": [ "5\n2 7\n2 8\n1 2\n2 4\n1 8\n", "3\n3 4\n1 3\n1 5\n", "8\n1 8\n1 6\n1 5\n1 3\n1 3\n1 8\n1 7\n1 3\n", "4\n4 1\n2 2\n1 6\n1 2\n", "7\n2 11\n3 12\n2 1\n2 6\n1 6\n2 2\n3 14\n", "8\n1 7\n3 16\n1 15\n2 1\n1 15\n4 11\n1 4\n2 15\n", "4\n2 1\n3 2\n4 3\n5 100\n", "15\n1 7\n1 14\n1 6...
2CODEFORCES
1539_D. PriceFixed_1565
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store — "PriceFixed". Here are some rules of that store: * The store has an infinite number of items of every product. * All products have the same price: 2 rubles per item. * ...
n = int(input()) arr = [] for _ in range(n): arr.append(list(map(int, input().split()))) arr.sort(key=lambda x:x[1]) # print(arr) lo, hi = 0, n-1 ans, counter = 0, 0 while lo<=hi: # print(lo, hi, counter) to_buy, req = arr[lo] if counter>=req or to_buy==0: counter += to_buy ans += to_bu...
3Python3
{ "input": [ "5\n2 7\n2 8\n1 2\n2 4\n1 8\n", "3\n3 4\n1 3\n1 5\n", "8\n1 8\n1 6\n1 5\n1 3\n1 3\n1 8\n1 7\n1 3\n", "4\n4 1\n2 2\n1 6\n1 2\n", "7\n2 11\n3 12\n2 1\n2 6\n1 6\n2 2\n3 14\n", "8\n1 7\n3 16\n1 15\n2 1\n1 15\n4 11\n1 4\n2 15\n", "4\n2 1\n3 2\n4 3\n5 100\n", "15\n1 7\n1 14\n1 6...
2CODEFORCES
1539_D. PriceFixed_1566
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store — "PriceFixed". Here are some rules of that store: * The store has an infinite number of items of every product. * All products have the same price: 2 rubles per item. * ...
import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.math.BigInteger; import java.util.*; /** * @author Mubtasim Shahriar */ public class PriceFixed { public static void main(String[] args) { InputStream inputStream = System.in; ...
4JAVA
{ "input": [ "5\n2 7\n2 8\n1 2\n2 4\n1 8\n", "3\n3 4\n1 3\n1 5\n", "8\n1 8\n1 6\n1 5\n1 3\n1 3\n1 8\n1 7\n1 3\n", "4\n4 1\n2 2\n1 6\n1 2\n", "7\n2 11\n3 12\n2 1\n2 6\n1 6\n2 2\n3 14\n", "8\n1 7\n3 16\n1 15\n2 1\n1 15\n4 11\n1 4\n2 15\n", "4\n2 1\n3 2\n4 3\n5 100\n", "15\n1 7\n1 14\n1 6...
2CODEFORCES
166_A. Rank List_1567
Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place. You know the rules of comparing the results of two give...
import sys s="" s=[x.replace("\n",'') for x in sys.stdin.readlines()] n=int(s[0].split()[0]) k=int(s[0].split()[1]) a=[[int(x.split()[0]),int(x.split()[1])] for x in s[1:]] a=sorted(a,key=lambda x:(x[0],50-x[1]),reverse=True) para=a[k-1] kol=0 for i in xrange(len(a)): if para==a[i]: kol=kol+1 print kol
1Python2
{ "input": [ "5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n", "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n", "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\...
2CODEFORCES
166_A. Rank List_1568
Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place. You know the rules of comparing the results of two give...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, A[50], i, con = 0, a, b; cin >> n >> k; for (i = 0; i < n; i++) { cin >> a >> b; A[i] = a * 50 - b; } sort(A, A + n); for (i = 0; i < n; i++) if (A[i] == A[n - k]) con++; cout << con; return 0; }
2C++
{ "input": [ "5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n", "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n", "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\...
2CODEFORCES
166_A. Rank List_1569
Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place. You know the rules of comparing the results of two give...
n, k = map(int, input().split()) table =[] table_dic = dict() for i in range(n): p, t = map(int, input().split()) table_dic[i + 1] = [p,t] table.append([p, 50 - t]) ranking = sorted(table, key=lambda table: (table[0], table[1]), reverse=True) for i in range(n): ranking[i][1] = 50 - ranking[i][1] coun...
3Python3
{ "input": [ "5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n", "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n", "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\...
2CODEFORCES
166_A. Rank List_1570
Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place. You know the rules of comparing the results of two give...
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; import java.util.StringTokenizer; public class Main { public static void main(String args[]) throws Exception{ Sca...
4JAVA
{ "input": [ "5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n", "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n", "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\...
2CODEFORCES
187_B. AlgoRace_1571
PMP is getting a warrior. He is practicing a lot, but the results are not acceptable yet. This time instead of programming contests, he decided to compete in a car racing to increase the spirit of victory. He decides to choose a competition that also exhibits algorithmic features. AlgoRace is a special league of car r...
#include <bits/stdc++.h> using namespace std; const int N = 66, INF = 1000000009; int n, m, q; int a[N][N][N]; int dp[N][N][N]; int main() { cin >> n >> m >> q; for (int i = 0; i < m; ++i) { for (int x = 1; x <= n; ++x) { for (int y = 1; y <= n; ++y) { cin >> a[i][x][y]; } } for (int...
2C++
{ "input": [ "4 2 3\n0 1 5 6\n2 0 3 6\n1 3 0 1\n6 6 7 0\n0 3 5 6\n2 0 1 6\n1 3 0 2\n6 6 7 0\n1 4 2\n1 4 1\n1 4 3\n", "4 2 3\n0 7 3 3\n8 0 10 5\n1 1 0 4\n8 9 2 0\n0 3 3 9\n7 0 4 9\n3 8 0 4\n4 8 9 0\n2 3 3\n2 1 3\n1 2 2\n", "2 4 10\n0 1\n3 0\n0 11\n11 0\n0 8\n11 0\n0 15\n6 0\n1 2 0\n1 2 3\n1 2 1\n1 2 0\n2 1...
2CODEFORCES
187_B. AlgoRace_1572
PMP is getting a warrior. He is practicing a lot, but the results are not acceptable yet. This time instead of programming contests, he decided to compete in a car racing to increase the spirit of victory. He decides to choose a competition that also exhibits algorithmic features. AlgoRace is a special league of car r...
import java.io.* ; import java.util.*; import static java.lang.Math.* ; import static java.util.Arrays.* ; public class B { public static void main(String[] args) throws IOException { new B().solveProblem(); out.close(); } static Scanner in = new Scanner(new InputStreamReader(System.in)); //static Bu...
4JAVA
{ "input": [ "4 2 3\n0 1 5 6\n2 0 3 6\n1 3 0 1\n6 6 7 0\n0 3 5 6\n2 0 1 6\n1 3 0 2\n6 6 7 0\n1 4 2\n1 4 1\n1 4 3\n", "4 2 3\n0 7 3 3\n8 0 10 5\n1 1 0 4\n8 9 2 0\n0 3 3 9\n7 0 4 9\n3 8 0 4\n4 8 9 0\n2 3 3\n2 1 3\n1 2 2\n", "2 4 10\n0 1\n3 0\n0 11\n11 0\n0 8\n11 0\n0 15\n6 0\n1 2 0\n1 2 3\n1 2 1\n1 2 0\n2 1...
2CODEFORCES
207_D9. The Beaver's Problem - 3_1573
The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorting documents by their subjects. Let's describe the problem: You've got some training set of documents. For each document you know its su...
#include <bits/stdc++.h> int main() { int n; scanf("%d", &n); n -= 43500; puts(n > 0 ? (n > 2000 ? "3" : "2") : "1"); return 0; }
2C++
{ "input": [ "42000\nLAWSON SEES NO CHANGE IN U.K. MONETARY POLICY\nWASHINGTON, April 9 - British Chancellor of the Exchequer\nNigel Lawson said he saw no immediate implications for British\nmonetary policy arising from the Group of Seven meeting\nyesterday.\n\"Exchange rate stability is in the U.K.'s interest,\"...
2CODEFORCES
207_D9. The Beaver's Problem - 3_1574
The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorting documents by their subjects. Let's describe the problem: You've got some training set of documents. For each document you know its su...
import java.util.*; public class cf207d { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); if(n <= 43000) System.out.println(1); else if(n >= 46000) System.out.println(3); else System.out.println(2); } }
4JAVA
{ "input": [ "42000\nLAWSON SEES NO CHANGE IN U.K. MONETARY POLICY\nWASHINGTON, April 9 - British Chancellor of the Exchequer\nNigel Lawson said he saw no immediate implications for British\nmonetary policy arising from the Group of Seven meeting\nyesterday.\n\"Exchange rate stability is in the U.K.'s interest,\"...
2CODEFORCES
233_C. Cycles_1575
John Doe started thinking about graphs. After some thought he decided that he wants to paint an undirected graph, containing exactly k cycles of length 3. A cycle of length 3 is an unordered group of three distinct graph vertices a, b and c, such that each pair of them is connected by a graph edge. John has been pa...
k, ans, nodes = int(input()), [['0'] * 100 for _ in range(100)], 0 while k > 0: for i in range(nodes): if i > k: break k -= i ans[nodes][i] = ans[i][nodes] = '1' nodes += 1 print(nodes) print('\n'.join([''.join(ans[i][:nodes]) for i in range(nodes)]))
1Python2
{ "input": [ "10\n", "1\n", "99016\n", "99022\n", "5\n", "99007\n", "7\n", "99007\n", "98685\n", "100000\n", "99020\n", "99994\n", "97560\n", "4\n", "99021\n", "97560\n", "99994\n", "99011\n", "99004\n", "9\n", "99999\n", "99009\n...
2CODEFORCES
233_C. Cycles_1576
John Doe started thinking about graphs. After some thought he decided that he wants to paint an undirected graph, containing exactly k cycles of length 3. A cycle of length 3 is an unordered group of three distinct graph vertices a, b and c, such that each pair of them is connected by a graph edge. John has been pa...
#include <bits/stdc++.h> using namespace std; int a[105][105]; int main() { int k; cin >> k; memset(a, 0, sizeof(a)); for (int i = 1; i <= 3; i++) for (int j = 1; j <= 3; j++) if (i != j) a[i][j] = 1; k--; int ans = 3; if (k) { for (ans = ans + 1; ans <= 100; ans++) { for (int i = 1; i...
2C++
{ "input": [ "10\n", "1\n", "99016\n", "99022\n", "5\n", "99007\n", "7\n", "99007\n", "98685\n", "100000\n", "99020\n", "99994\n", "97560\n", "4\n", "99021\n", "97560\n", "99994\n", "99011\n", "99004\n", "9\n", "99999\n", "99009\n...
2CODEFORCES
233_C. Cycles_1577
John Doe started thinking about graphs. After some thought he decided that he wants to paint an undirected graph, containing exactly k cycles of length 3. A cycle of length 3 is an unordered group of three distinct graph vertices a, b and c, such that each pair of them is connected by a graph edge. John has been pa...
n, k = 0, int(input()) p = [['0'] * 100 for i in range(100)] while k: for i in range(n): if i > k: break p[n][i] = p[i][n] = '1' k -= i n += 1 print(n) for i in range(n): print(''.join(p[i][:n]))
3Python3
{ "input": [ "10\n", "1\n", "99016\n", "99022\n", "5\n", "99007\n", "7\n", "99007\n", "98685\n", "100000\n", "99020\n", "99994\n", "97560\n", "4\n", "99021\n", "97560\n", "99994\n", "99011\n", "99004\n", "9\n", "99999\n", "99009\n...
2CODEFORCES
233_C. Cycles_1578
John Doe started thinking about graphs. After some thought he decided that he wants to paint an undirected graph, containing exactly k cycles of length 3. A cycle of length 3 is an unordered group of three distinct graph vertices a, b and c, such that each pair of them is connected by a graph edge. John has been pa...
import java.awt.*; import java.io.*; import java.math.BigDecimal; import java.math.BigInteger; import java.util.*; import java.util.List; import java.util.Queue; import static java.lang.Math.max; import static java.lang.Math.min; public class A implements Runnable{ // SOLUTION AT THE TOP OF CODE!!! // HACK ...
4JAVA
{ "input": [ "10\n", "1\n", "99016\n", "99022\n", "5\n", "99007\n", "7\n", "99007\n", "98685\n", "100000\n", "99020\n", "99994\n", "97560\n", "4\n", "99021\n", "97560\n", "99994\n", "99011\n", "99004\n", "9\n", "99999\n", "99009\n...
2CODEFORCES
259_B. Little Elephant and Magic Square_1579
Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15...
l=lambda:map(int,raw_input().split()) m=[l() for _ in range(3)] a,b,c=0,0,0 # a+c=m[0][2]+m[2][0] # a-c=m[2][0]+m[2][1]-(m[0][1]+m[0][2]) a=m[2][0]+(m[2][1]-m[0][1])/2 c= m[0][2]+(m[0][1]-m[2][1])/2 b=a+m[0][1]+m[0][2]-(m[1][0]+m[1][2]) print a,m[0][1],m[0][2] print m[1][0],b,m[1][2] print m[2][0],m[2][1],c
1Python2
{ "input": [ "0 1 1\n1 0 1\n1 1 0\n", "0 3 6\n5 0 5\n4 7 0\n", "0 100000 100000\n100000 0 100000\n100000 100000 0\n", "0 99626 99582\n99766 0 99258\n99442 99398 0\n", "0 6361 2304\n1433 0 8103\n7232 3175 0\n", "0 28 10\n12 0 24\n26 8 0\n", "0 97 56\n69 0 71\n84 43 0\n", "0 4 4\n4 0 4\n...
2CODEFORCES
259_B. Little Elephant and Magic Square_1580
Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15...
#include <bits/stdc++.h> using namespace std; int cell[4][4]; void go() { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) cout << cell[i][j] << " "; cout << endl; } } int main() { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) cin >> cell[i][j]; } cell[0][0] = (cell[1][2] + ce...
2C++
{ "input": [ "0 1 1\n1 0 1\n1 1 0\n", "0 3 6\n5 0 5\n4 7 0\n", "0 100000 100000\n100000 0 100000\n100000 100000 0\n", "0 99626 99582\n99766 0 99258\n99442 99398 0\n", "0 6361 2304\n1433 0 8103\n7232 3175 0\n", "0 28 10\n12 0 24\n26 8 0\n", "0 97 56\n69 0 71\n84 43 0\n", "0 4 4\n4 0 4\n...
2CODEFORCES
259_B. Little Elephant and Magic Square_1581
Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15...
l=[] for i in range(3): l.append(list(map(int,input().split()))) l[1][1]=(l[1][0]+l[1][2])//2 c=sum(l[1]) l[0][0]=c-(l[0][1]+l[0][2]) l[2][2]=c-(l[2][0]+l[2][1]) for i in range(3): for j in range(3): print(l[i][j],end=" ") print()
3Python3
{ "input": [ "0 1 1\n1 0 1\n1 1 0\n", "0 3 6\n5 0 5\n4 7 0\n", "0 100000 100000\n100000 0 100000\n100000 100000 0\n", "0 99626 99582\n99766 0 99258\n99442 99398 0\n", "0 6361 2304\n1433 0 8103\n7232 3175 0\n", "0 28 10\n12 0 24\n26 8 0\n", "0 97 56\n69 0 71\n84 43 0\n", "0 4 4\n4 0 4\n...
2CODEFORCES
259_B. Little Elephant and Magic Square_1582
Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15...
import java.io.*; import java.util.*; public class CF259B { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int[][] aa = new int[3][3]; for (int i = 0; i < 3; i++) { StringTokenizer st = new StringTokenizer(br.readLine()); ...
4JAVA
{ "input": [ "0 1 1\n1 0 1\n1 1 0\n", "0 3 6\n5 0 5\n4 7 0\n", "0 100000 100000\n100000 0 100000\n100000 100000 0\n", "0 99626 99582\n99766 0 99258\n99442 99398 0\n", "0 6361 2304\n1433 0 8103\n7232 3175 0\n", "0 28 10\n12 0 24\n26 8 0\n", "0 97 56\n69 0 71\n84 43 0\n", "0 4 4\n4 0 4\n...
2CODEFORCES
282_B. Painting Eggs_1583
The Bitlandians are quite weird people. They have very peculiar customs. As is customary, Uncle J. wants to have n eggs painted for Bitruz (an ancient Bitland festival). He has asked G. and A. to do the work. The kids are excited because just as is customary, they're going to be paid for the job! Overall uncle J. h...
a = map(int,raw_input().split()) ans = "" k1,k2 = 0,0 for i in xrange(a[0]): cur = map(int,raw_input().split()) if(k1+cur[0]-k2 <=500): k1=k1+cur[0] ans = ans+"A" else: k2=k2+cur[1] ans = ans+"G" print ans
1Python2
{ "input": [ "2\n1 999\n999 1\n", "3\n400 600\n400 600\n400 600\n", "1\n500 500\n", "2\n500 500\n500 500\n", "1\n1 999\n", "2\n499 501\n501 499\n", "10\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n", "1\n0 1000\n", "1\n1000 0\n", "3\n500 500\n1 999\n40...
2CODEFORCES
282_B. Painting Eggs_1584
The Bitlandians are quite weird people. They have very peculiar customs. As is customary, Uncle J. wants to have n eggs painted for Bitruz (an ancient Bitland festival). He has asked G. and A. to do the work. The kids are excited because just as is customary, they're going to be paid for the job! Overall uncle J. h...
#include <bits/stdc++.h> using namespace std; pair<long long, long long> dp[3][1000005]; int A[1000005], B[1000005]; int ma[3][1000005]; int main() { int n, x; pair<int, int> e1; pair<int, int> e2; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d%d", &A[i], &B[i]); dp[0][0] = make_pair(A[0], 0); dp[...
2C++
{ "input": [ "2\n1 999\n999 1\n", "3\n400 600\n400 600\n400 600\n", "1\n500 500\n", "2\n500 500\n500 500\n", "1\n1 999\n", "2\n499 501\n501 499\n", "10\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n", "1\n0 1000\n", "1\n1000 0\n", "3\n500 500\n1 999\n40...
2CODEFORCES
282_B. Painting Eggs_1585
The Bitlandians are quite weird people. They have very peculiar customs. As is customary, Uncle J. wants to have n eggs painted for Bitruz (an ancient Bitland festival). He has asked G. and A. to do the work. The kids are excited because just as is customary, they're going to be paid for the job! Overall uncle J. h...
import sys input = lambda: sys.stdin.readline() n = int(input()) S = 0 ans = '' for i in range(n): a, g = [int(x) for x in input().split(' ')] if abs(S + a) <= 500: S += a ans += 'A' else: S -= g ans += 'G' print(ans)
3Python3
{ "input": [ "2\n1 999\n999 1\n", "3\n400 600\n400 600\n400 600\n", "1\n500 500\n", "2\n500 500\n500 500\n", "1\n1 999\n", "2\n499 501\n501 499\n", "10\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n", "1\n0 1000\n", "1\n1000 0\n", "3\n500 500\n1 999\n40...
2CODEFORCES
282_B. Painting Eggs_1586
The Bitlandians are quite weird people. They have very peculiar customs. As is customary, Uncle J. wants to have n eggs painted for Bitruz (an ancient Bitland festival). He has asked G. and A. to do the work. The kids are excited because just as is customary, they're going to be paid for the job! Overall uncle J. h...
import java.io.BufferedReader; import java.io.*; import java.util.*; public class Test { public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(in.readLine()); int sa = 0; ...
4JAVA
{ "input": [ "2\n1 999\n999 1\n", "3\n400 600\n400 600\n400 600\n", "1\n500 500\n", "2\n500 500\n500 500\n", "1\n1 999\n", "2\n499 501\n501 499\n", "10\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n", "1\n0 1000\n", "1\n1000 0\n", "3\n500 500\n1 999\n40...
2CODEFORCES
305_A. Strange Addition_1587
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. Vasya has a set of k distinct non-negative integers d1, d2, ..., dk. Vasya wants to choose some integers ...
from sys import stdin k = int(stdin.readline().strip()) numbers = stdin.readline().strip().split(' ') numbers = map(int, numbers) res = [] d1 = d2 = dd = 0 for d in numbers: if d == 0 or d == 100: d0 = 0 elif d % 10 == 0 and not d1: d1 = 1 elif d < 10 and not d2: d2 = 1 else: ...
1Python2
{ "input": [ "4\n100 10 1 0\n", "3\n2 70 3\n", "1\n1\n", "39\n16 72 42 70 17 36 32 40 47 94 27 30 100 55 23 77 67 28 49 50 53 83 38 33 60 65 62 64 6 66 69 86 96 75 85 0 89 73 29\n", "3\n99 10 6\n", "2\n10 12\n", "4\n0 100 10 99\n", "1\n100\n", "1\n99\n", "2\n5 6\n", "3\n0 1...
2CODEFORCES
305_A. Strange Addition_1588
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. Vasya has a set of k distinct non-negative integers d1, d2, ..., dk. Vasya wants to choose some integers ...
#include <bits/stdc++.h> using namespace std; int n, arr[100], i, j; bool a[100][100]; bool Ok(int x, int y) { while (x && y) { int a = x % 10; int b = y % 10; x /= 10; y /= 10; if (a && b) return false; } return true; } int main() { cin >> n; vector<vector<int> > v; for (int i = 0; i < ...
2C++
{ "input": [ "4\n100 10 1 0\n", "3\n2 70 3\n", "1\n1\n", "39\n16 72 42 70 17 36 32 40 47 94 27 30 100 55 23 77 67 28 49 50 53 83 38 33 60 65 62 64 6 66 69 86 96 75 85 0 89 73 29\n", "3\n99 10 6\n", "2\n10 12\n", "4\n0 100 10 99\n", "1\n100\n", "1\n99\n", "2\n5 6\n", "3\n0 1...
2CODEFORCES
305_A. Strange Addition_1589
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. Vasya has a set of k distinct non-negative integers d1, d2, ..., dk. Vasya wants to choose some integers ...
n = int(input()) arr = list(map(int,input().split())) t = [] flag = 0 if(0 in arr): t.append(0) if(100 in arr): t.append(100) for i in range(n): if(arr[i]>0 and arr[i]<10): t.append(arr[i]) flag = 1 break for i in range(n): if(arr[i]%10 == 0 and arr[i]>0 and arr[i]<100): ...
3Python3
{ "input": [ "4\n100 10 1 0\n", "3\n2 70 3\n", "1\n1\n", "39\n16 72 42 70 17 36 32 40 47 94 27 30 100 55 23 77 67 28 49 50 53 83 38 33 60 65 62 64 6 66 69 86 96 75 85 0 89 73 29\n", "3\n99 10 6\n", "2\n10 12\n", "4\n0 100 10 99\n", "1\n100\n", "1\n99\n", "2\n5 6\n", "3\n0 1...
2CODEFORCES
305_A. Strange Addition_1590
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. Vasya has a set of k distinct non-negative integers d1, d2, ..., dk. Vasya wants to choose some integers ...
import java.util.ArrayList; import java.util.List; import java.util.Scanner; /** * Created by Yusuf on 7/27/2016. * A. Strange Addition */ public class A305 { public static int onePos(int num) { int ret = 0; for (int i = 0; i < 3; ++i) { if (num % 10 != 0) ret |= (1 << i); ...
4JAVA
{ "input": [ "4\n100 10 1 0\n", "3\n2 70 3\n", "1\n1\n", "39\n16 72 42 70 17 36 32 40 47 94 27 30 100 55 23 77 67 28 49 50 53 83 38 33 60 65 62 64 6 66 69 86 96 75 85 0 89 73 29\n", "3\n99 10 6\n", "2\n10 12\n", "4\n0 100 10 99\n", "1\n100\n", "1\n99\n", "2\n5 6\n", "3\n0 1...
2CODEFORCES
331_A2. Oh Sweet Beaverette_1591
— Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me? — Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night? At this point the Smart Beaver got rushing. Everything should be perfect by Friday, so he needed to prepare the belt to the upcomin...
n=input() s=map(int,raw_input().split()) S={} z=[0]*(n+1) for i in range(n): z[i+1] = z[i] + max(0,s[i]) r=(-99**9,-1) for i,x in enumerate(s): if x in S: r=max((2*x + z[i] - z[S[x]+1],i),r) else: S[x]=i S=S[s[r[1]]] f=[`i+1` for i in range(n) if i < S or i > r[1] or s[i] < 0 and S< i <...
1Python2
{ "input": [ "5\n1 2 3 1 2\n", "5\n1 -2 3 1 -2\n", "3\n1000000000 1000000000 1000000000\n", "6\n-1 3 3 5 5 -1\n", "10\n-589330597 -126288833 -126288833 -834860352 -834860352 -834860352 -834860352 -21170405 -834860352 -834860352\n", "20\n-808998072 733614990 579897311 -337992089 579897311 12080...
2CODEFORCES
331_A2. Oh Sweet Beaverette_1592
— Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me? — Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night? At this point the Smart Beaver got rushing. Everything should be perfect by Friday, so he needed to prepare the belt to the upcomin...
#include <bits/stdc++.h> using namespace std; map<int, int> mp; vector<int> vc; long long psum[300001]; long long a[300001]; int main() { long long ans = -2000000001; int n, ansi; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] > 0) psum[i] = psum[i - 1] + a[i]; else psum[...
2C++
{ "input": [ "5\n1 2 3 1 2\n", "5\n1 -2 3 1 -2\n", "3\n1000000000 1000000000 1000000000\n", "6\n-1 3 3 5 5 -1\n", "10\n-589330597 -126288833 -126288833 -834860352 -834860352 -834860352 -834860352 -21170405 -834860352 -834860352\n", "20\n-808998072 733614990 579897311 -337992089 579897311 12080...
2CODEFORCES
331_A2. Oh Sweet Beaverette_1593
— Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me? — Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night? At this point the Smart Beaver got rushing. Everything should be perfect by Friday, so he needed to prepare the belt to the upcomin...
n, t = int(input()), list(map(int, input().split())) a, b = {}, {} for i, j in enumerate(t): if not j in a: a[j] = i else: b[j] = i p = [(a[j], b[j] - 1) for j in b] s = [j if j > 0 else 0 for j in t] u = v = 2 * t[p[0][0]] - 1 for i in range(n - 1): s[i + 1] += s[i] for i, j in p: u = 2 * t[i] + s[j] - s[i...
3Python3
{ "input": [ "5\n1 2 3 1 2\n", "5\n1 -2 3 1 -2\n", "3\n1000000000 1000000000 1000000000\n", "6\n-1 3 3 5 5 -1\n", "10\n-589330597 -126288833 -126288833 -834860352 -834860352 -834860352 -834860352 -21170405 -834860352 -834860352\n", "20\n-808998072 733614990 579897311 -337992089 579897311 12080...
2CODEFORCES
331_A2. Oh Sweet Beaverette_1594
— Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me? — Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night? At this point the Smart Beaver got rushing. Everything should be perfect by Friday, so he needed to prepare the belt to the upcomin...
import java.util.*; import java.lang.*; import java.math.*; import java.io.*; import java.text.*; public class Rough{ static PrintWriter w=new PrintWriter(System.out); public static void main(String [] args){ DecimalFormat dm=new DecimalFormat("0.000000"); Scanner sc=new Scanner(System.in);...
4JAVA
{ "input": [ "5\n1 2 3 1 2\n", "5\n1 -2 3 1 -2\n", "3\n1000000000 1000000000 1000000000\n", "6\n-1 3 3 5 5 -1\n", "10\n-589330597 -126288833 -126288833 -834860352 -834860352 -834860352 -834860352 -21170405 -834860352 -834860352\n", "20\n-808998072 733614990 579897311 -337992089 579897311 12080...
2CODEFORCES
352_E. Jeff and Brackets_1595
Jeff loves regular bracket sequences. Today Jeff is going to take a piece of paper and write out the regular bracket sequence, consisting of nm brackets. Let's number all brackets of this sequence from 0 to nm - 1 from left to right. Jeff knows that he is going to spend ai mod n liters of ink on the i-th bracket of th...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int n, m, a[N], b[N]; int dp[22][44]; struct uzi { long long A[44][44]; uzi() { memset(A, 0x3f3f3f, sizeof A); }; } G; uzi operator*(const uzi& a, const uzi& b) { uzi c; for (int i = 0; i <= 40; i++) { for (int j = 0; j <= 40; j++) { ...
2C++
{ "input": [ "1 10000000\n2\n3\n", "2 6\n1 2\n2 1\n", "3 184\n3 2 8\n3 9 2\n", "20 10000000\n7 10 9 2 9 7 6 10 3 7 5 1 1 8 4 9 7 9 6 8\n9 4 3 6 1 7 3 4 1 8 3 5 2 8 10 9 1 2 10 4\n", "20 10000000\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10\n10 10 10 10 10 10 10 10 10 10 10 10 10 10...
2CODEFORCES
352_E. Jeff and Brackets_1596
Jeff loves regular bracket sequences. Today Jeff is going to take a piece of paper and write out the regular bracket sequence, consisting of nm brackets. Let's number all brackets of this sequence from 0 to nm - 1 from left to right. Jeff knows that he is going to spend ai mod n liters of ink on the i-th bracket of th...
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class C { static int[] openCost, closedCost; static int[][][] dp; static int inf = 10000000; public static int solve(int curCost, int endCost, int remMoves) { if (remMoves == open...
4JAVA
{ "input": [ "1 10000000\n2\n3\n", "2 6\n1 2\n2 1\n", "3 184\n3 2 8\n3 9 2\n", "20 10000000\n7 10 9 2 9 7 6 10 3 7 5 1 1 8 4 9 7 9 6 8\n9 4 3 6 1 7 3 4 1 8 3 5 2 8 10 9 1 2 10 4\n", "20 10000000\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10\n10 10 10 10 10 10 10 10 10 10 10 10 10 10...
2CODEFORCES
377_A. Maze_1597
Pavel loves grid mazes. A grid maze is an n × m rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side. Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any oth...
import sys import threading n,m,k=list(map(int,raw_input().split())) li=[list(raw_input()) for _ in range(n)] def issafe(r,c): return 0<=r<n and 0<=c<m def fun(r,c,cnt): if cnt[0]>=k: return li[r][c]="1" if issafe(r-1,c) and li[r-1][c]==".": fun(r-1,c,cnt) if issafe(r+1,c) and ...
1Python2
{ "input": [ "3 4 2\n#..#\n..#.\n#...\n", "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#\n", "2 5 3\n.....\n..#..\n", "3 5 1\n#....\n..#..\n..###\n", "7 7 18\n#.....#\n..#.#..\n.#...#.\n...#...\n.#...#.\n..#.#..\n#.....#\n", "4 4 3\n....\n.#..\n..##\n..##\n", "5 7 4\n.......\n...#...\n...#...\n...#....
2CODEFORCES
377_A. Maze_1598
Pavel loves grid mazes. A grid maze is an n × m rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side. Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any oth...
#include <bits/stdc++.h> using namespace std; const int M = 505; struct Node { int x, y; }; int cnt = 0, sum = 0; int k, n, m; bool book[M][M]; char mapp[M][M]; int mv[4][2] = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}}; void bfs(int x, int y) { queue<Node> q; int xt, yt; Node tmp, next; tmp.x = x; tmp.y = y; book...
2C++
{ "input": [ "3 4 2\n#..#\n..#.\n#...\n", "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#\n", "2 5 3\n.....\n..#..\n", "3 5 1\n#....\n..#..\n..###\n", "7 7 18\n#.....#\n..#.#..\n.#...#.\n...#...\n.#...#.\n..#.#..\n#.....#\n", "4 4 3\n....\n.#..\n..##\n..##\n", "5 7 4\n.......\n...#...\n...#...\n...#....
2CODEFORCES
377_A. Maze_1599
Pavel loves grid mazes. A grid maze is an n × m rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side. Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any oth...
from collections import defaultdict from sys import stdin def put(): return map(int, stdin.readline().split()) def find(): for i in range(n): for j in range(m): if mat[i][j]=='.': return i,j return -1,-1 def dfs(i,j): s = [(i,j)] t = 1 vis[i][j]=1 while s: ...
3Python3
{ "input": [ "3 4 2\n#..#\n..#.\n#...\n", "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#\n", "2 5 3\n.....\n..#..\n", "3 5 1\n#....\n..#..\n..###\n", "7 7 18\n#.....#\n..#.#..\n.#...#.\n...#...\n.#...#.\n..#.#..\n#.....#\n", "4 4 3\n....\n.#..\n..##\n..##\n", "5 7 4\n.......\n...#...\n...#...\n...#....
2CODEFORCES