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 |
|---|---|---|---|---|---|
walk_300 | Chef and his girlfriend are going to have a promenade. They are walking along the straight road which consists of segments placed one by one. Before walking Chef and his girlfriend stay at the beginning of the first segment, they want to achieve the end of the last segment.
There are few problems:
At the beginning ... | for _ in range(input()):
n= int(raw_input())
att = map(int,raw_input().split())
ans = []
for i in range(n):
ans.append(att[i]+i)
print max(ans) | 1Python2 | {
"input": [
"2\n5\n6 5 4 3 2\n5\n3 4 3 1 1",
"2\n5\n6 5 4 3 2\n5\n3 4 6 1 1",
"2\n5\n6 5 4 3 2\n5\n3 7 9 1 1",
"2\n5\n6 5 4 3 3\n5\n3 7 9 1 1",
"2\n5\n6 5 4 3 2\n5\n3 8 3 1 1",
"2\n5\n6 5 4 5 2\n5\n3 7 6 1 1",
"2\n5\n6 5 4 4 2\n5\n3 8 3 1 1",
"2\n5\n6 5 2 3 0\n5\n3 4 12 1 1",
"2\n... | 1CODECHEF |
101_C. Vectors_301 | At a geometry lesson Gerald was given a task: to get vector B out of vector A. Besides, the teacher permitted him to perform the following operations with vector А:
* Turn the vector by 90 degrees clockwise.
* Add to the vector a certain vector C.
Operations could be performed in any order any number of times.
... | def check(x, y, p, q):
if x == 0 and y == 0:
return True
elif p * p + q * q != 0 and (x * q - y * p) % (p * p + q * q) == 0 and (x * p + y * q) % (p * p + q * q) == 0:
return True
else:
return False
x, y = map(int, raw_input().split())
a, b = map(int, raw_input().split())
p, q = map... | 1Python2 | {
"input": [
"0 0\n1 1\n1 1\n",
"0 0\n1 1\n0 1\n",
"0 0\n1 1\n2 2\n",
"3 1\n-2 3\n-2 -2\n",
"-8916 9282\n2666 2344\n9109 -2730\n",
"0 45\n42 -47\n-51 -82\n",
"45 6\n65 5\n0 5\n",
"3 4\n-4 3\n1 7\n",
"-75629161 -68114618\n23285096 90997125\n84795646 72358903\n",
"2 3\n2 3\n0 0\n... | 2CODEFORCES |
101_C. Vectors_302 | At a geometry lesson Gerald was given a task: to get vector B out of vector A. Besides, the teacher permitted him to perform the following operations with vector А:
* Turn the vector by 90 degrees clockwise.
* Add to the vector a certain vector C.
Operations could be performed in any order any number of times.
... | #include <bits/stdc++.h>
using namespace std;
long long ax, ay, bx, by, cx, cy;
long long AX[4], AY[4], CX[4], CY[4];
bool judge_51nod(long long ax, long long ay, long long cx, long long cy) {
long long zi1 = abs((bx - ax) * cx + (by - ay) * cy);
long long zi2 = abs((by - ay) * cx - (bx - ax) * cy);
long long mu ... | 2C++ | {
"input": [
"0 0\n1 1\n1 1\n",
"0 0\n1 1\n0 1\n",
"0 0\n1 1\n2 2\n",
"3 1\n-2 3\n-2 -2\n",
"-8916 9282\n2666 2344\n9109 -2730\n",
"0 45\n42 -47\n-51 -82\n",
"45 6\n65 5\n0 5\n",
"3 4\n-4 3\n1 7\n",
"-75629161 -68114618\n23285096 90997125\n84795646 72358903\n",
"2 3\n2 3\n0 0\n... | 2CODEFORCES |
101_C. Vectors_303 | At a geometry lesson Gerald was given a task: to get vector B out of vector A. Besides, the teacher permitted him to perform the following operations with vector А:
* Turn the vector by 90 degrees clockwise.
* Add to the vector a certain vector C.
Operations could be performed in any order any number of times.
... | import math
def ok(xa, ya):
x, y = xb - xa, yb - ya
d = math.gcd(abs(xc), abs(yc))
if xc == 0 and yc == 0:
return x == 0 and y == 0
if xc == 0:
return x % yc == 0 and y % yc == 0
if yc == 0:
return x % xc == 0 and y % xc == 0
if (x % d != 0) or (y % d != 0):
retu... | 3Python3 | {
"input": [
"0 0\n1 1\n1 1\n",
"0 0\n1 1\n0 1\n",
"0 0\n1 1\n2 2\n",
"3 1\n-2 3\n-2 -2\n",
"-8916 9282\n2666 2344\n9109 -2730\n",
"0 45\n42 -47\n-51 -82\n",
"45 6\n65 5\n0 5\n",
"3 4\n-4 3\n1 7\n",
"-75629161 -68114618\n23285096 90997125\n84795646 72358903\n",
"2 3\n2 3\n0 0\n... | 2CODEFORCES |
101_C. Vectors_304 | At a geometry lesson Gerald was given a task: to get vector B out of vector A. Besides, the teacher permitted him to perform the following operations with vector А:
* Turn the vector by 90 degrees clockwise.
* Add to the vector a certain vector C.
Operations could be performed in any order any number of times.
... | import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Locale;
import java.util.StringTokenizer;
@SuppressWarnings("unchecked")
public class Main {
private static final String TASKNAME = ... | 4JAVA | {
"input": [
"0 0\n1 1\n1 1\n",
"0 0\n1 1\n0 1\n",
"0 0\n1 1\n2 2\n",
"3 1\n-2 3\n-2 -2\n",
"-8916 9282\n2666 2344\n9109 -2730\n",
"0 45\n42 -47\n-51 -82\n",
"45 6\n65 5\n0 5\n",
"3 4\n-4 3\n1 7\n",
"-75629161 -68114618\n23285096 90997125\n84795646 72358903\n",
"2 3\n2 3\n0 0\n... | 2CODEFORCES |
1043_A. Elections_305 | Awruk is taking part in elections in his school. It is the final round. He has only one opponent — Elodreip. The are n students in the school. Each student has exactly k votes and is obligated to use all of them. So Awruk knows that if a person gives a_i votes for Elodreip, than he will get exactly k - a_i votes from t... | n=int(raw_input())
A=map(int,raw_input().split())
if n==1:
print 2*A[0]+1
exit()
sux=sum(A)
k=max(A)
k2=(2*sux)/n+1
print max(k,k2)
exit()
| 1Python2 | {
"input": [
"5\n2 2 3 2 2\n",
"5\n1 1 1 5 1\n",
"3\n1 2 6\n",
"10\n7 7 7 7 7 7 7 7 7 7\n",
"76\n13 13 5 6 20 20 6 1 18 18 13 15 20 3 9 11 3 11 3 8 12 15 2 4 16 17 8 11 15 6 6 5 3 12 19 15 17 8 5 20 12 6 9 7 20 15 8 7 5 17 9 12 12 17 12 16 2 6 16 16 17 18 6 7 19 13 6 3 8 16 13 7 1 14 11 9\n",
... | 2CODEFORCES |
1043_A. Elections_306 | Awruk is taking part in elections in his school. It is the final round. He has only one opponent — Elodreip. The are n students in the school. Each student has exactly k votes and is obligated to use all of them. So Awruk knows that if a person gives a_i votes for Elodreip, than he will get exactly k - a_i votes from t... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
int ans = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
ans = max(ans, a[i]);
}
for (int i = ans; i < 1000; i++) {
int cur = 0;
for (int j = 0; j < n; j++) {
cur += i - a[j] * 2;
}
i... | 2C++ | {
"input": [
"5\n2 2 3 2 2\n",
"5\n1 1 1 5 1\n",
"3\n1 2 6\n",
"10\n7 7 7 7 7 7 7 7 7 7\n",
"76\n13 13 5 6 20 20 6 1 18 18 13 15 20 3 9 11 3 11 3 8 12 15 2 4 16 17 8 11 15 6 6 5 3 12 19 15 17 8 5 20 12 6 9 7 20 15 8 7 5 17 9 12 12 17 12 16 2 6 16 16 17 18 6 7 19 13 6 3 8 16 13 7 1 14 11 9\n",
... | 2CODEFORCES |
1043_A. Elections_307 | Awruk is taking part in elections in his school. It is the final round. He has only one opponent — Elodreip. The are n students in the school. Each student has exactly k votes and is obligated to use all of them. So Awruk knows that if a person gives a_i votes for Elodreip, than he will get exactly k - a_i votes from t... | import math
n = int(input())
l= list(map(int,input().split()))
s = 2*sum(l)
z= s/n
p = max(l)
an = int(z+1)
print(max(p,an)) | 3Python3 | {
"input": [
"5\n2 2 3 2 2\n",
"5\n1 1 1 5 1\n",
"3\n1 2 6\n",
"10\n7 7 7 7 7 7 7 7 7 7\n",
"76\n13 13 5 6 20 20 6 1 18 18 13 15 20 3 9 11 3 11 3 8 12 15 2 4 16 17 8 11 15 6 6 5 3 12 19 15 17 8 5 20 12 6 9 7 20 15 8 7 5 17 9 12 12 17 12 16 2 6 16 16 17 18 6 7 19 13 6 3 8 16 13 7 1 14 11 9\n",
... | 2CODEFORCES |
1043_A. Elections_308 | Awruk is taking part in elections in his school. It is the final round. He has only one opponent — Elodreip. The are n students in the school. Each student has exactly k votes and is obligated to use all of them. So Awruk knows that if a person gives a_i votes for Elodreip, than he will get exactly k - a_i votes from t... | 'use strict';
const n = Number(readline());
const a = readline().split(' ').map(Number);
let votes = 0;
let max_a = 0;
for (let i = 0; i < n; i++) {
max_a = Math.max(max_a, a[i]);
votes += a[i];
}
print(Math.max(Math.ceil((2 * votes + 1) / n), max_a)); | 4JAVA | {
"input": [
"5\n2 2 3 2 2\n",
"5\n1 1 1 5 1\n",
"3\n1 2 6\n",
"10\n7 7 7 7 7 7 7 7 7 7\n",
"76\n13 13 5 6 20 20 6 1 18 18 13 15 20 3 9 11 3 11 3 8 12 15 2 4 16 17 8 11 15 6 6 5 3 12 19 15 17 8 5 20 12 6 9 7 20 15 8 7 5 17 9 12 12 17 12 16 2 6 16 16 17 18 6 7 19 13 6 3 8 16 13 7 1 14 11 9\n",
... | 2CODEFORCES |
1065_F. Up and Down the Tree_309 | You are given a tree with n vertices; its root is vertex 1. Also there is a token, initially placed in the root. You can move the token to other vertices. Let's assume current vertex of token is v, then you make any of the following two possible moves:
* move down to any leaf in subtree of v;
* if vertex v is a ... | #include <bits/stdc++.h>
using namespace std;
int read() {
char c = getchar();
int x = 0;
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') x = x * 10 + (c - '0'), c = getchar();
return x;
}
void MOD(int &x) {
if (x >= 998244353) x -= 998244353;
}
int m;
int l, nxt[1000010], head[100001... | 2C++ | {
"input": [
"8 2\n1 1 2 3 4 5 5\n",
"7 1\n1 1 3 3 4 4\n",
"30 2\n26 11 22 16 14 29 16 14 8 23 21 22 11 24 15 23 22 1 11 20 23 29 13 19 19 15 13 2 7\n",
"30 1\n19 20 10 21 9 26 20 21 30 12 25 25 2 1 10 3 19 12 18 12 30 18 22 1 18 18 30 30 12\n",
"30 1\n1 22 24 24 2 25 5 2 22 3 1 1 26 22 15 16 17 2... | 2CODEFORCES |
1065_F. Up and Down the Tree_310 | You are given a tree with n vertices; its root is vertex 1. Also there is a token, initially placed in the root. You can move the token to other vertices. Let's assume current vertex of token is v, then you make any of the following two possible moves:
* move down to any leaf in subtree of v;
* if vertex v is a ... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;
/**... | 4JAVA | {
"input": [
"8 2\n1 1 2 3 4 5 5\n",
"7 1\n1 1 3 3 4 4\n",
"30 2\n26 11 22 16 14 29 16 14 8 23 21 22 11 24 15 23 22 1 11 20 23 29 13 19 19 15 13 2 7\n",
"30 1\n19 20 10 21 9 26 20 21 30 12 25 25 2 1 10 3 19 12 18 12 30 18 22 1 18 18 30 30 12\n",
"30 1\n1 22 24 24 2 25 5 2 22 3 1 1 26 22 15 16 17 2... | 2CODEFORCES |
1088_D. Ehab and another another xor problem_311 | This is an interactive problem!
Ehab plays a game with Laggy. Ehab has 2 hidden integers (a,b). Laggy can ask a pair of integers (c,d) and Ehab will reply with:
* 1 if a ⊕ c>b ⊕ d.
* 0 if a ⊕ c=b ⊕ d.
* -1 if a ⊕ c<b ⊕ d.
Operation a ⊕ b is the [bitwise-xor operation](https://en.wikipedia.org/wiki/Bitwise... | #include <bits/stdc++.h>
using namespace std;
inline long long fpow(long long n, long long k, int p = 998244353) {
long long r = 1;
for (; k; k >>= 1) {
if (k & 1) r = r * n % p;
n = n * n % p;
}
return r;
}
inline long long inv(long long a, long long p = 998244353) {
return fpow(a, p - 2, p);
}
inlin... | 2C++ | {
"input": [
"1\n-1\n0",
"0 1073741823\n",
"10 5\n",
"16384 36739846\n",
"727373493 346368330\n",
"62914844 1044381411\n",
"683909153 117987356\n",
"534364885 625821414\n",
"1063413663 0\n",
"56797 6710886\n",
"153391689 613566756\n",
"450278829 900557658\n",
"0 0\n... | 2CODEFORCES |
1088_D. Ehab and another another xor problem_312 | This is an interactive problem!
Ehab plays a game with Laggy. Ehab has 2 hidden integers (a,b). Laggy can ask a pair of integers (c,d) and Ehab will reply with:
* 1 if a ⊕ c>b ⊕ d.
* 0 if a ⊕ c=b ⊕ d.
* -1 if a ⊕ c<b ⊕ d.
Operation a ⊕ b is the [bitwise-xor operation](https://en.wikipedia.org/wiki/Bitwise... |
import java.util.Scanner;
public class D {
public static void main(String[] aaaa) {
Scanner scanner = new Scanner(System.in);
System.out.println("? 0 0");
System.out.flush();
int res = scanner.nextInt();
// System.out.println("res " + res);
int a = 0;
in... | 4JAVA | {
"input": [
"1\n-1\n0",
"0 1073741823\n",
"10 5\n",
"16384 36739846\n",
"727373493 346368330\n",
"62914844 1044381411\n",
"683909153 117987356\n",
"534364885 625821414\n",
"1063413663 0\n",
"56797 6710886\n",
"153391689 613566756\n",
"450278829 900557658\n",
"0 0\n... | 2CODEFORCES |
1107_D. Compression_313 | You are given a binary matrix A of size n × n. Let's denote an x-compression of the given matrix as a matrix B of size n/x × n/x such that for every i ∈ [1, n], j ∈ [1, n] the condition A[i][j] = B[⌈ i/x ⌉][⌈ j/x ⌉] is met.
Obviously, x-compression is possible only if x divides n, but this condition is not enough. For... | from __future__ import print_function,division
import sys
if sys.version_info < (3, 0):
range = xrange
n = int(input())
A = [[0]*(n+1) for _ in range(n+1)]
B = {
'0': (0,0,0,0),
'1': (0,0,0,1),
'2': (0,0,1,0),
'3': (0,0,1,1),
'4': (0,1,0,0),
'5': (0,1,0,1),
'6': (0,1,1,0),
'7': (0... | 1Python2 | {
"input": [
"8\nE7\nE7\nE7\n00\n00\nE7\nE7\nE7\n",
"4\n7\nF\nF\nF\n",
"8\nFF\nFF\n00\n00\nFF\nFF\n00\n00\n",
"4\n0\n0\n0\n1\n",
"8\n33\n33\n33\n33\n33\n33\n11\n11\n",
"16\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\n",
"12\nE38\nE38\nE38... | 2CODEFORCES |
1107_D. Compression_314 | You are given a binary matrix A of size n × n. Let's denote an x-compression of the given matrix as a matrix B of size n/x × n/x such that for every i ∈ [1, n], j ∈ [1, n] the condition A[i][j] = B[⌈ i/x ⌉][⌈ j/x ⌉] is met.
Obviously, x-compression is possible only if x divides n, but this condition is not enough. For... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 5205;
int n;
int sum[maxn][maxn];
char a;
char cs[] = "0123456789ABCDEF";
map<char, int> cidic;
void init() {
for (int i = 0; i < 16; i++) {
cidic[cs[i]] = i;
}
}
void update(int i, int j) {
sum[i][j] += (i > 0 ? sum[i - 1][j] : 0) + (j > 0 ? sum[... | 2C++ | {
"input": [
"8\nE7\nE7\nE7\n00\n00\nE7\nE7\nE7\n",
"4\n7\nF\nF\nF\n",
"8\nFF\nFF\n00\n00\nFF\nFF\n00\n00\n",
"4\n0\n0\n0\n1\n",
"8\n33\n33\n33\n33\n33\n33\n11\n11\n",
"16\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\n",
"12\nE38\nE38\nE38... | 2CODEFORCES |
1107_D. Compression_315 | You are given a binary matrix A of size n × n. Let's denote an x-compression of the given matrix as a matrix B of size n/x × n/x such that for every i ∈ [1, n], j ∈ [1, n] the condition A[i][j] = B[⌈ i/x ⌉][⌈ j/x ⌉] is met.
Obviously, x-compression is possible only if x divides n, but this condition is not enough. For... | # ---------------------------iye ha aam zindegi---------------------------------------------
import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
mod = 10 ** 9 + 7
mod1 = 998244353
# ------------------------------warmup----------------------------
impor... | 3Python3 | {
"input": [
"8\nE7\nE7\nE7\n00\n00\nE7\nE7\nE7\n",
"4\n7\nF\nF\nF\n",
"8\nFF\nFF\n00\n00\nFF\nFF\n00\n00\n",
"4\n0\n0\n0\n1\n",
"8\n33\n33\n33\n33\n33\n33\n11\n11\n",
"16\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\n",
"12\nE38\nE38\nE38... | 2CODEFORCES |
1107_D. Compression_316 | You are given a binary matrix A of size n × n. Let's denote an x-compression of the given matrix as a matrix B of size n/x × n/x such that for every i ∈ [1, n], j ∈ [1, n] the condition A[i][j] = B[⌈ i/x ⌉][⌈ j/x ⌉] is met.
Obviously, x-compression is possible only if x divides n, but this condition is not enough. For... |
import java.io.*;
import java.util.*;
public class Main {
private static int MOD = 1000000007;
public static void main(String[] args) throws Exception {
InputStream inS = System.in;
// InputReader sc = new InputReader(inS);
PrintStream out = System.out;
Scanner sc = new Sc... | 4JAVA | {
"input": [
"8\nE7\nE7\nE7\n00\n00\nE7\nE7\nE7\n",
"4\n7\nF\nF\nF\n",
"8\nFF\nFF\n00\n00\nFF\nFF\n00\n00\n",
"4\n0\n0\n0\n1\n",
"8\n33\n33\n33\n33\n33\n33\n11\n11\n",
"16\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\n",
"12\nE38\nE38\nE38... | 2CODEFORCES |
1136_D. Nastya Is Buying Lunch_317 | At the big break Nastya came to the school dining room. There are n pupils in the school, numbered from 1 to n. Unfortunately, Nastya came pretty late, so that all pupils had already stood in the queue, i.e. Nastya took the last place in the queue. Of course, it's a little bit sad for Nastya, but she is not going to de... | import sys,math
from fractions import gcd
from collections import defaultdict
from io import BytesIO
import hashlib
sys.stdin = BytesIO(sys.stdin.read())
input = lambda: sys.stdin.readline().rstrip('\r\n')
#n = int(input())
n,m = [int(x) for x in input().split(' ')]
arr = [int(x) for x in input().split(' ')]
arr = arr[... | 1Python2 | {
"input": [
"5 2\n3 1 5 4 2\n5 2\n5 4\n",
"3 3\n3 1 2\n1 2\n3 1\n3 2\n",
"2 1\n1 2\n1 2\n",
"10 23\n6 9 8 10 4 3 7 1 5 2\n7 2\n3 2\n2 4\n2 3\n7 5\n6 4\n10 7\n7 1\n6 8\n6 2\n8 10\n3 5\n3 1\n6 1\n10 2\n8 2\n10 1\n7 4\n10 5\n6 9\n6 5\n9 1\n10 4\n",
"2 0\n1 2\n",
"3 2\n1 2 3\n1 2\n2 1\n",
"10... | 2CODEFORCES |
1136_D. Nastya Is Buying Lunch_318 | At the big break Nastya came to the school dining room. There are n pupils in the school, numbered from 1 to n. Unfortunately, Nastya came pretty late, so that all pupils had already stood in the queue, i.e. Nastya took the last place in the queue. Of course, it's a little bit sad for Nastya, but she is not going to de... | #include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int inf = 1e9;
const long long llf = 1e18;
const int mod = 1e9 + 7;
const int maxn = 5e5 + 10;
int n, m;
int p[maxn];
vector<int> f[maxn];
vector<int> q;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++... | 2C++ | {
"input": [
"5 2\n3 1 5 4 2\n5 2\n5 4\n",
"3 3\n3 1 2\n1 2\n3 1\n3 2\n",
"2 1\n1 2\n1 2\n",
"10 23\n6 9 8 10 4 3 7 1 5 2\n7 2\n3 2\n2 4\n2 3\n7 5\n6 4\n10 7\n7 1\n6 8\n6 2\n8 10\n3 5\n3 1\n6 1\n10 2\n8 2\n10 1\n7 4\n10 5\n6 9\n6 5\n9 1\n10 4\n",
"2 0\n1 2\n",
"3 2\n1 2 3\n1 2\n2 1\n",
"10... | 2CODEFORCES |
1136_D. Nastya Is Buying Lunch_319 | At the big break Nastya came to the school dining room. There are n pupils in the school, numbered from 1 to n. Unfortunately, Nastya came pretty late, so that all pupils had already stood in the queue, i.e. Nastya took the last place in the queue. Of course, it's a little bit sad for Nastya, but she is not going to de... | import sys
import math
import bisect
from math import sqrt
def input(): return sys.stdin.readline().strip()
def iinput(): return int(input())
def rinput(): return map(int, sys.stdin.readline().strip().split())
def get_list(): return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1e9)+7
n, m = ... | 3Python3 | {
"input": [
"5 2\n3 1 5 4 2\n5 2\n5 4\n",
"3 3\n3 1 2\n1 2\n3 1\n3 2\n",
"2 1\n1 2\n1 2\n",
"10 23\n6 9 8 10 4 3 7 1 5 2\n7 2\n3 2\n2 4\n2 3\n7 5\n6 4\n10 7\n7 1\n6 8\n6 2\n8 10\n3 5\n3 1\n6 1\n10 2\n8 2\n10 1\n7 4\n10 5\n6 9\n6 5\n9 1\n10 4\n",
"2 0\n1 2\n",
"3 2\n1 2 3\n1 2\n2 1\n",
"10... | 2CODEFORCES |
1136_D. Nastya Is Buying Lunch_320 | At the big break Nastya came to the school dining room. There are n pupils in the school, numbered from 1 to n. Unfortunately, Nastya came pretty late, so that all pupils had already stood in the queue, i.e. Nastya took the last place in the queue. Of course, it's a little bit sad for Nastya, but she is not going to de... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.Set;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
im... | 4JAVA | {
"input": [
"5 2\n3 1 5 4 2\n5 2\n5 4\n",
"3 3\n3 1 2\n1 2\n3 1\n3 2\n",
"2 1\n1 2\n1 2\n",
"10 23\n6 9 8 10 4 3 7 1 5 2\n7 2\n3 2\n2 4\n2 3\n7 5\n6 4\n10 7\n7 1\n6 8\n6 2\n8 10\n3 5\n3 1\n6 1\n10 2\n8 2\n10 1\n7 4\n10 5\n6 9\n6 5\n9 1\n10 4\n",
"2 0\n1 2\n",
"3 2\n1 2 3\n1 2\n2 1\n",
"10... | 2CODEFORCES |
1155_A. Reverse a Substring_321 | You are given a string s consisting of n lowercase Latin letters.
Let's define a substring as a contiguous subsegment of a string. For example, "acab" is a substring of "abacaba" (it starts in position 3 and ends in position 6), but "aa" or "d" aren't substrings of this string. So the substring of the string s from po... | import sys
sys.setrecursionlimit(10 ** 6)
# pow(3,2,5)==4
inp=input()
inp2=raw_input()
last=inp2[0]
flag=0
for x,i in enumerate(inp2[1:],1):
if (ord(i)<ord(last)):
flag=1
print "YES"
print x,x+1
break
last=i
if not flag:
print "NO"
| 1Python2 | {
"input": [
"7\nabacaba\n",
"6\naabcfg\n",
"6\nbabcdc\n",
"5\nbadec\n",
"3\naba\n",
"7\nbaaaccb\n",
"3\naaa\n",
"4\npara\n",
"3\nbac\n",
"7\nbdadccd\n",
"2\nba\n",
"7\nstoopid\n",
"7\nyxyzyyx\n",
"3\nacb\n",
"7\nbcbcbdc\n",
"7\nabacaba\n",
"2\naa\n"... | 2CODEFORCES |
1155_A. Reverse a Substring_322 | You are given a string s consisting of n lowercase Latin letters.
Let's define a substring as a contiguous subsegment of a string. For example, "acab" is a substring of "abacaba" (it starts in position 3 and ends in position 6), but "aa" or "d" aren't substrings of this string. So the substring of the string s from po... | #include <bits/stdc++.h>
using namespace std;
int n, m, a, b, c, d;
struct node {
int a, b;
};
bool cmp(node x, node y) {
if (x.a == y.a) return x.b > y.b;
return x.a > y.a;
}
string s;
int num[30];
char cr, cr1;
int check(char cc) {
for (int i = cc - 'a' + 1; i < 26; ++i) {
if (num[i]) return num[i];
}
... | 2C++ | {
"input": [
"7\nabacaba\n",
"6\naabcfg\n",
"6\nbabcdc\n",
"5\nbadec\n",
"3\naba\n",
"7\nbaaaccb\n",
"3\naaa\n",
"4\npara\n",
"3\nbac\n",
"7\nbdadccd\n",
"2\nba\n",
"7\nstoopid\n",
"7\nyxyzyyx\n",
"3\nacb\n",
"7\nbcbcbdc\n",
"7\nabacaba\n",
"2\naa\n"... | 2CODEFORCES |
1155_A. Reverse a Substring_323 | You are given a string s consisting of n lowercase Latin letters.
Let's define a substring as a contiguous subsegment of a string. For example, "acab" is a substring of "abacaba" (it starts in position 3 and ends in position 6), but "aa" or "d" aren't substrings of this string. So the substring of the string s from po... | '''
Online Python Compiler.
Code, Compile, Run and Debug python program online.
Write your code in this editor and press "Run" button to execute it.
'''
def main():
n = input()
s = input()
for i in range(len(s)-1):
if s[i]>s[i+1]:
print('YES'... | 3Python3 | {
"input": [
"7\nabacaba\n",
"6\naabcfg\n",
"6\nbabcdc\n",
"5\nbadec\n",
"3\naba\n",
"7\nbaaaccb\n",
"3\naaa\n",
"4\npara\n",
"3\nbac\n",
"7\nbdadccd\n",
"2\nba\n",
"7\nstoopid\n",
"7\nyxyzyyx\n",
"3\nacb\n",
"7\nbcbcbdc\n",
"7\nabacaba\n",
"2\naa\n"... | 2CODEFORCES |
1155_A. Reverse a Substring_324 | You are given a string s consisting of n lowercase Latin letters.
Let's define a substring as a contiguous subsegment of a string. For example, "acab" is a substring of "abacaba" (it starts in position 3 and ends in position 6), but "aa" or "d" aren't substrings of this string. So the substring of the string s from po... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author alecs6k
*/
public class Main {
public static void main(String[] args) {
InputStream i... | 4JAVA | {
"input": [
"7\nabacaba\n",
"6\naabcfg\n",
"6\nbabcdc\n",
"5\nbadec\n",
"3\naba\n",
"7\nbaaaccb\n",
"3\naaa\n",
"4\npara\n",
"3\nbac\n",
"7\nbdadccd\n",
"2\nba\n",
"7\nstoopid\n",
"7\nyxyzyyx\n",
"3\nacb\n",
"7\nbcbcbdc\n",
"7\nabacaba\n",
"2\naa\n"... | 2CODEFORCES |
1176_F. Destroy it!_325 | You are playing a computer card game called Splay the Sire. Currently you are struggling to defeat the final boss of the game.
The boss battle consists of n turns. During each turn, you will get several cards. Each card has two parameters: its cost c_i and damage d_i. You may play some of your cards during each turn i... | from sys import stdin, stdout
INF = float('inf')
n = input()
inp = stdin.readlines()
cd = [[[], [], []] for i in xrange(n)]
ptr = 0
idx = 0
while ptr < len(inp):
k = int(inp[ptr]); ptr += 1
for i in xrange(k):
c, d = map(int, inp[ptr].split()); ptr += 1
cd[idx][c - 1].append(d)
idx... | 1Python2 | {
"input": [
"5\n3\n1 6\n1 7\n1 5\n2\n1 4\n1 3\n3\n1 10\n3 5\n2 3\n3\n1 15\n2 4\n1 10\n1\n1 100\n",
"5\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 100\n1 1\n1 1\n",
"1\n4\n1 1\n1 1\n2 2\n3 4\n",
"5\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 2\n1 1\n1 ... | 2CODEFORCES |
1176_F. Destroy it!_326 | You are playing a computer card game called Splay the Sire. Currently you are struggling to defeat the final boss of the game.
The boss battle consists of n turns. During each turn, you will get several cards. Each card has two parameters: its cost c_i and damage d_i. You may play some of your cards during each turn i... | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
int now = 0, nxt = 1;
long long dp[2][10];
memset(dp, -1, sizeof(dp));
dp[0][0] = 0;
while (n--) {
int k;
cin >> k;
vector<long long> v[4];
for (int i = 0; i < k; i++) {... | 2C++ | {
"input": [
"5\n3\n1 6\n1 7\n1 5\n2\n1 4\n1 3\n3\n1 10\n3 5\n2 3\n3\n1 15\n2 4\n1 10\n1\n1 100\n",
"5\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 100\n1 1\n1 1\n",
"1\n4\n1 1\n1 1\n2 2\n3 4\n",
"5\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 2\n1 1\n1 ... | 2CODEFORCES |
1176_F. Destroy it!_327 | You are playing a computer card game called Splay the Sire. Currently you are struggling to defeat the final boss of the game.
The boss battle consists of n turns. During each turn, you will get several cards. Each card has two parameters: its cost c_i and damage d_i. You may play some of your cards during each turn i... | import sys
import math
import cProfile
DEBUG = False
def log(s):
if DEBUG and False:
print(s)
def calc_dmg(num, arr):
maximum = 0
if num - len(arr) < 0:
maximum = max(arr)
return sum(arr) + maximum
if DEBUG:
sys.stdin = open('input.txt')
pr = cProfile.Profile()
pr.... | 3Python3 | {
"input": [
"5\n3\n1 6\n1 7\n1 5\n2\n1 4\n1 3\n3\n1 10\n3 5\n2 3\n3\n1 15\n2 4\n1 10\n1\n1 100\n",
"5\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 100\n1 1\n1 1\n",
"1\n4\n1 1\n1 1\n2 2\n3 4\n",
"5\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 2\n1 1\n1 ... | 2CODEFORCES |
1176_F. Destroy it!_328 | You are playing a computer card game called Splay the Sire. Currently you are struggling to defeat the final boss of the game.
The boss battle consists of n turns. During each turn, you will get several cards. Each card has two parameters: its cost c_i and damage d_i. You may play some of your cards during each turn i... | import java.io.*;
import java.text.*;
import java.util.*;
import java.math.*;
public class F {
public static void main(String[] args) throws Exception {
new F().run();
}
public void run() throws Exception {
FastScanner f = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int n = f.nextInt();... | 4JAVA | {
"input": [
"5\n3\n1 6\n1 7\n1 5\n2\n1 4\n1 3\n3\n1 10\n3 5\n2 3\n3\n1 15\n2 4\n1 10\n1\n1 100\n",
"5\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 100\n1 1\n1 1\n",
"1\n4\n1 1\n1 1\n2 2\n3 4\n",
"5\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 2\n1 1\n1 ... | 2CODEFORCES |
1195_D2. Submarine in the Rybinsk Sea (hard edition)_329 | This problem differs from the previous one only in the absence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n.
A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the st... | from __future__ import division, print_function
def main():
def power(x, y, p) :
res = 1 # Initialize result
# Update x if it is more
# than or equal to p
x = x % p
while (y > 0) :
# If y is odd, multiply
# x with... | 1Python2 | {
"input": [
"3\n12 3 45\n",
"2\n123 456\n",
"20\n76 86 70 7 16 24 10 62 26 29 40 65 55 49 34 55 92 47 43 100\n",
"100\n6591 1074 3466 3728 549 5440 533 3543 1536 2967 1587 304 6326 6410 8670 6736 4482 8431 1697 9264 8338 2995 3725 1805 488 4563 4261 6025 2602 1892 9297 4359 1139 7117 1423 4834 5663 7... | 2CODEFORCES |
1195_D2. Submarine in the Rybinsk Sea (hard edition)_330 | This problem differs from the previous one only in the absence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n.
A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the st... | #include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int Nmax = 100555;
int digit_tally[11];
int n, a[Nmax];
int main(void) {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
int digits = floor(log10(a[i])) + 1;
digit_tally[digits]++;
}
long long result = 0;
for (int ... | 2C++ | {
"input": [
"3\n12 3 45\n",
"2\n123 456\n",
"20\n76 86 70 7 16 24 10 62 26 29 40 65 55 49 34 55 92 47 43 100\n",
"100\n6591 1074 3466 3728 549 5440 533 3543 1536 2967 1587 304 6326 6410 8670 6736 4482 8431 1697 9264 8338 2995 3725 1805 488 4563 4261 6025 2602 1892 9297 4359 1139 7117 1423 4834 5663 7... | 2CODEFORCES |
1195_D2. Submarine in the Rybinsk Sea (hard edition)_331 | This problem differs from the previous one only in the absence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n.
A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the st... | from collections import Counter
n = int(input())
a = list(map(int, input().split()))
l = [len(str(i)) for i in a]
c = Counter(l)
cl = [c[i] for i in range(1,11)]
M = 998244353
pad = lambda a, d: a%d + (a - a%d) * 10
#print(a, l, c, cl)
ans = 0
for i in a:
il = len(str(i)) # let's calculate it again to avoid zi... | 3Python3 | {
"input": [
"3\n12 3 45\n",
"2\n123 456\n",
"20\n76 86 70 7 16 24 10 62 26 29 40 65 55 49 34 55 92 47 43 100\n",
"100\n6591 1074 3466 3728 549 5440 533 3543 1536 2967 1587 304 6326 6410 8670 6736 4482 8431 1697 9264 8338 2995 3725 1805 488 4563 4261 6025 2602 1892 9297 4359 1139 7117 1423 4834 5663 7... | 2CODEFORCES |
1195_D2. Submarine in the Rybinsk Sea (hard edition)_332 | This problem differs from the previous one only in the absence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n.
A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the st... | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class Solve7 {
public static void ma... | 4JAVA | {
"input": [
"3\n12 3 45\n",
"2\n123 456\n",
"20\n76 86 70 7 16 24 10 62 26 29 40 65 55 49 34 55 92 47 43 100\n",
"100\n6591 1074 3466 3728 549 5440 533 3543 1536 2967 1587 304 6326 6410 8670 6736 4482 8431 1697 9264 8338 2995 3725 1805 488 4563 4261 6025 2602 1892 9297 4359 1139 7117 1423 4834 5663 7... | 2CODEFORCES |
1236_A. Stones_333 | Alice is playing with some stones.
Now there are three numbered heaps of stones. The first of them contains a stones, the second of them contains b stones and the third of them contains c stones.
Each time she can do one of two operations:
1. take one stone from the first heap and two stones from the second heap (... | t = input()
for _ in xrange(t):
a, b, c = map(int, raw_input().strip().split())
z = c / 2
ans = 0
for x in xrange(a + 1):
for y in xrange(z + 1):
if 2 * x + y > b: break
ans = max(ans, 3 * (x + y))
print ans | 1Python2 | {
"input": [
"3\n3 4 5\n1 0 5\n5 3 2\n",
"20\n9 4 8\n10 6 7\n4 6 0\n7 7 6\n3 3 10\n4 2 1\n4 4 0\n2 0 0\n8 8 7\n3 1 7\n3 10 7\n1 7 3\n7 9 1\n1 6 9\n0 9 5\n4 0 0\n2 10 0\n4 8 5\n10 0 1\n8 1 1\n",
"64\n0 0 0\n0 0 1\n0 0 2\n0 0 3\n0 1 0\n0 1 1\n0 1 2\n0 1 3\n0 2 0\n0 2 1\n0 2 2\n0 2 3\n0 3 0\n0 3 1\n0 3 2\n0 ... | 2CODEFORCES |
1236_A. Stones_334 | Alice is playing with some stones.
Now there are three numbered heaps of stones. The first of them contains a stones, the second of them contains b stones and the third of them contains c stones.
Each time she can do one of two operations:
1. take one stone from the first heap and two stones from the second heap (... | #include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 1, mod = 1e9 + 7, inf = 1e18;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t, a, b, c;
cin >> t;
for (int i = 1; i <= t; i++) {
cin >> a >> b >> c;
int tmp = min(b, c / 2);
b -= tmp;
tmp += min(a, b / 2);
... | 2C++ | {
"input": [
"3\n3 4 5\n1 0 5\n5 3 2\n",
"20\n9 4 8\n10 6 7\n4 6 0\n7 7 6\n3 3 10\n4 2 1\n4 4 0\n2 0 0\n8 8 7\n3 1 7\n3 10 7\n1 7 3\n7 9 1\n1 6 9\n0 9 5\n4 0 0\n2 10 0\n4 8 5\n10 0 1\n8 1 1\n",
"64\n0 0 0\n0 0 1\n0 0 2\n0 0 3\n0 1 0\n0 1 1\n0 1 2\n0 1 3\n0 2 0\n0 2 1\n0 2 2\n0 2 3\n0 3 0\n0 3 1\n0 3 2\n0 ... | 2CODEFORCES |
1236_A. Stones_335 | Alice is playing with some stones.
Now there are three numbered heaps of stones. The first of them contains a stones, the second of them contains b stones and the third of them contains c stones.
Each time she can do one of two operations:
1. take one stone from the first heap and two stones from the second heap (... | t = int(input())
while t>0:
x, y, z = [int(i) for i in input().split()]
s = 0
f = -1
z = z//2
if y >= z:
y = y - z
s = z*2 + z
else:
s = y*2 + y
f = 1
if f == -1:
y = y//2
if x >= y:
s = s + 2*y + y
else:
... | 3Python3 | {
"input": [
"3\n3 4 5\n1 0 5\n5 3 2\n",
"20\n9 4 8\n10 6 7\n4 6 0\n7 7 6\n3 3 10\n4 2 1\n4 4 0\n2 0 0\n8 8 7\n3 1 7\n3 10 7\n1 7 3\n7 9 1\n1 6 9\n0 9 5\n4 0 0\n2 10 0\n4 8 5\n10 0 1\n8 1 1\n",
"64\n0 0 0\n0 0 1\n0 0 2\n0 0 3\n0 1 0\n0 1 1\n0 1 2\n0 1 3\n0 2 0\n0 2 1\n0 2 2\n0 2 3\n0 3 0\n0 3 1\n0 3 2\n0 ... | 2CODEFORCES |
1236_A. Stones_336 | Alice is playing with some stones.
Now there are three numbered heaps of stones. The first of them contains a stones, the second of them contains b stones and the third of them contains c stones.
Each time she can do one of two operations:
1. take one stone from the first heap and two stones from the second heap (... | import java.util.*;
public class Problem1236a {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int cnt = Math... | 4JAVA | {
"input": [
"3\n3 4 5\n1 0 5\n5 3 2\n",
"20\n9 4 8\n10 6 7\n4 6 0\n7 7 6\n3 3 10\n4 2 1\n4 4 0\n2 0 0\n8 8 7\n3 1 7\n3 10 7\n1 7 3\n7 9 1\n1 6 9\n0 9 5\n4 0 0\n2 10 0\n4 8 5\n10 0 1\n8 1 1\n",
"64\n0 0 0\n0 0 1\n0 0 2\n0 0 3\n0 1 0\n0 1 1\n0 1 2\n0 1 3\n0 2 0\n0 2 1\n0 2 2\n0 2 3\n0 3 0\n0 3 1\n0 3 2\n0 ... | 2CODEFORCES |
1253_F. Cheap Robot_337 | You're given a simple, undirected, connected, weighted graph with n nodes and m edges.
Nodes are numbered from 1 to n. There are exactly k centrals (recharge points), which are nodes 1, 2, …, k.
We consider a robot moving into this graph, with a battery of capacity c, not fixed by the constructor yet. At any time, th... | #include <bits/stdc++.h>
using namespace std;
struct Edge {
int x, y;
long long val;
} e[3 * 100055];
bool cmp(Edge x1, Edge x2) { return x1.val < x2.val; }
int head[100055], to[6 * 100055], nex[6 * 100055];
long long w[6 * 100055];
int edge;
inline void addEdge(int x, int y, long long z) {
to[++edge] = y, w[edge... | 2C++ | {
"input": [
"10 9 3 1\n10 9 11\n9 2 37\n2 4 4\n4 1 8\n1 5 2\n5 7 3\n7 3 2\n3 8 4\n8 6 13\n2 3\n",
"9 11 3 2\n1 3 99\n1 4 5\n4 5 3\n5 6 3\n6 4 11\n6 7 21\n7 2 6\n7 8 4\n8 9 3\n9 2 57\n9 3 2\n3 1\n2 3\n",
"30 35 4 30\n14 2 7\n22 23 2\n5 26 3\n28 4 3\n7 5 29\n19 15 2\n11 20 12\n1 22 9\n30 21 24\n24 11 9\n29... | 2CODEFORCES |
1253_F. Cheap Robot_338 | You're given a simple, undirected, connected, weighted graph with n nodes and m edges.
Nodes are numbered from 1 to n. There are exactly k centrals (recharge points), which are nodes 1, 2, …, k.
We consider a robot moving into this graph, with a battery of capacity c, not fixed by the constructor yet. At any time, th... | import java.io.*;
import java.util.*;
public class FTask {
private static final String QUICK_ANSWER = "NO";
private final MyReader in;
private final StringBuilder out;
private final int n;
private final int m;
private final int k;
private final int q;
private final Graph g;
private ... | 4JAVA | {
"input": [
"10 9 3 1\n10 9 11\n9 2 37\n2 4 4\n4 1 8\n1 5 2\n5 7 3\n7 3 2\n3 8 4\n8 6 13\n2 3\n",
"9 11 3 2\n1 3 99\n1 4 5\n4 5 3\n5 6 3\n6 4 11\n6 7 21\n7 2 6\n7 8 4\n8 9 3\n9 2 57\n9 3 2\n3 1\n2 3\n",
"30 35 4 30\n14 2 7\n22 23 2\n5 26 3\n28 4 3\n7 5 29\n19 15 2\n11 20 12\n1 22 9\n30 21 24\n24 11 9\n29... | 2CODEFORCES |
1277_E. Two Fairs_339 | There are n cities in Berland and some pairs of them are connected by two-way roads. It is guaranteed that you can pass from any city to any other, moving along the roads. Cities are numerated from 1 to n.
Two fairs are currently taking place in Berland — they are held in two different cities a and b (1 ≤ a, b ≤ n; a ... | 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('\r\n')
def find(... | 1Python2 | {
"input": [
"3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 3\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n",
"3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 4\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n",
"3\n7 7 3 5\n1 2\n2 3\n3 4\n2 5\n5 6\n6 7\n7 5\n4 5 2 4\n1 2\n2 3\n3 4\n4 1... | 2CODEFORCES |
1277_E. Two Fairs_340 | There are n cities in Berland and some pairs of them are connected by two-way roads. It is guaranteed that you can pass from any city to any other, moving along the roads. Cities are numerated from 1 to n.
Two fairs are currently taking place in Berland — they are held in two different cities a and b (1 ≤ a, b ≤ n; a ... | #include <bits/stdc++.h>
using namespace std;
bool vis[200010];
void dfs(vector<long long int> arr[], long long int i, long long int temp) {
vis[i] = true;
for (long long int u : arr[i]) {
if (!vis[u] and u != temp) dfs(arr, u, temp);
}
}
int main() {
long long int t;
cin >> t;
while (t--) {
long lo... | 2C++ | {
"input": [
"3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 3\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n",
"3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 4\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n",
"3\n7 7 3 5\n1 2\n2 3\n3 4\n2 5\n5 6\n6 7\n7 5\n4 5 2 4\n1 2\n2 3\n3 4\n4 1... | 2CODEFORCES |
1277_E. Two Fairs_341 | There are n cities in Berland and some pairs of them are connected by two-way roads. It is guaranteed that you can pass from any city to any other, moving along the roads. Cities are numerated from 1 to n.
Two fairs are currently taking place in Berland — they are held in two different cities a and b (1 ≤ a, b ≤ n; a ... | import sys
import threading
from collections import deque
def func():
lines = sys.stdin.readlines()
nxt = 0
t = int(lines[nxt])
nxt += 1
ans = []
for _ in range(t):
n,m,a,b = map(int, lines[nxt].split())
nxt += 1
g = [[] for _ in range(n)]
for _ in range(m):
... | 3Python3 | {
"input": [
"3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 3\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n",
"3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 4\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n",
"3\n7 7 3 5\n1 2\n2 3\n3 4\n2 5\n5 6\n6 7\n7 5\n4 5 2 4\n1 2\n2 3\n3 4\n4 1... | 2CODEFORCES |
1277_E. Two Fairs_342 | There are n cities in Berland and some pairs of them are connected by two-way roads. It is guaranteed that you can pass from any city to any other, moving along the roads. Cities are numerated from 1 to n.
Two fairs are currently taking place in Berland — they are held in two different cities a and b (1 ≤ a, b ≤ n; a ... | // Working program using Reader Class
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.*;
public class Main1
{
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
... | 4JAVA | {
"input": [
"3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 3\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n",
"3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 4\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n",
"3\n7 7 3 5\n1 2\n2 3\n3 4\n2 5\n5 6\n6 7\n7 5\n4 5 2 4\n1 2\n2 3\n3 4\n4 1... | 2CODEFORCES |
1320_F. Blocks and Sensors_343 | Polycarp plays a well-known computer game (we won't mention its name). Every object in this game consists of three-dimensional blocks — axis-aligned cubes of size 1 × 1 × 1. These blocks are unaffected by gravity, so they can float in the air without support. The blocks are placed in cells of size 1 × 1 × 1; each cell ... | #include <bits/stdc++.h>
using namespace std;
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
for (T& x : v) is >> x;
return is;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
if (!v.empty()) {
os << v.front();
for (int x = 1; x < v.size(); ++x) os << ' ' <... | 2C++ | {
"input": [
"1 1 1\n\n0\n\n0\n\n1337\n\n0\n\n0\n\n0\n",
"1 1 1\n\n1337\n\n1337\n\n1337\n\n1337\n\n1337\n\n1337\n",
"1 1 1\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n",
"4 3 2\n\n1 4\n3 2\n6 5\n\n1 4\n3 2\n6 7\n\n1 4\n1 4\n0 0\n0 7\n\n6 5\n6 5\n0 0\n0 7\n\n1 3 6\n1 3 6\n0 0 0\n0 0 7\n\n4 3 5\n4 2 5\n0 0 0\n0 0 7\... | 2CODEFORCES |
133_D. Piet_344 | Piet is one of the most known visual esoteric programming languages. The programs in Piet are constructed from colorful blocks of pixels and interpreted using pretty complicated rules. In this problem we will use a subset of Piet language with simplified rules.
The program will be a rectangular image consisting of col... | class Piet:
inc = [{'x':0,'y':-1},{'x':1,'y':0},{'x':0,'y':1},{'x':-1,'y':0}]
def __init__(self):
self.BP = {'x':0,'y':0}
self.DP = 1
self.CP = 0
self.getdata()
self.go()
def getdata(self):
in_line = raw_input().split()
self.m = int(in_line[0])
... | 1Python2 | {
"input": [
"5 9\n10345\n23456\n34567\n45678\n56789\n",
"2 10\n12\n43\n",
"3 12\n1423\n6624\n6625\n",
"49 749442\n8888888\n8888888\n8888888\n5777777\n5777777\n5777777\n5777777\n5777777\n5777777\n5777777\n5777777\n5777777\n5111111\n5111111\n5666666\n5666666\n5666666\n5666666\n5666666\n5666666\n5666666... | 2CODEFORCES |
133_D. Piet_345 | Piet is one of the most known visual esoteric programming languages. The programs in Piet are constructed from colorful blocks of pixels and interpreted using pretty complicated rules. In this problem we will use a subset of Piet language with simplified rules.
The program will be a rectangular image consisting of col... | #include <bits/stdc++.h>
using namespace std;
static const int INF = 500000000;
template <class T>
void debug(T a, T b) {
for (; a != b; ++a) cerr << *a << ' ';
cerr << endl;
}
int w, h, n;
char buf[55][55];
pair<int, int> moveTo[55][55][4][2];
int state[55][55][4][2];
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}... | 2C++ | {
"input": [
"5 9\n10345\n23456\n34567\n45678\n56789\n",
"2 10\n12\n43\n",
"3 12\n1423\n6624\n6625\n",
"49 749442\n8888888\n8888888\n8888888\n5777777\n5777777\n5777777\n5777777\n5777777\n5777777\n5777777\n5777777\n5777777\n5111111\n5111111\n5666666\n5666666\n5666666\n5666666\n5666666\n5666666\n5666666... | 2CODEFORCES |
133_D. Piet_346 | Piet is one of the most known visual esoteric programming languages. The programs in Piet are constructed from colorful blocks of pixels and interpreted using pretty complicated rules. In this problem we will use a subset of Piet language with simplified rules.
The program will be a rectangular image consisting of col... | import java.util.*;
public class ProblemC {
Scanner in = new Scanner(System.in);
void run() {
int[] dx = new int[]{1, 0, -1, 0};
int[] dy = new int[]{0, 1, 0, -1};
int h = in.nextInt();
int n = in.nextInt();
String[] map = new String[h + 2];
... | 4JAVA | {
"input": [
"5 9\n10345\n23456\n34567\n45678\n56789\n",
"2 10\n12\n43\n",
"3 12\n1423\n6624\n6625\n",
"49 749442\n8888888\n8888888\n8888888\n5777777\n5777777\n5777777\n5777777\n5777777\n5777777\n5777777\n5777777\n5777777\n5111111\n5111111\n5666666\n5666666\n5666666\n5666666\n5666666\n5666666\n5666666... | 2CODEFORCES |
1361_E. James and the Chase_347 | James Bond has a new plan for catching his enemy. There are some cities and directed roads between them, such that it is possible to travel between any two cities using these roads. When the enemy appears in some city, Bond knows her next destination but has no idea which path she will choose to move there.
The city ... | #include <bits/stdc++.h>
using namespace std;
mt19937 gene(233);
inline char GET_CHAR() {
const int maxn = 131072;
static char buf[maxn], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, maxn, stdin), p1 == p2)
? EOF
: *p1++;
}
inline int getInt() {
int res(0);... | 2C++ | {
"input": [
"4\n3 3\n1 2\n2 3\n3 1\n3 6\n1 2\n2 1\n2 3\n3 2\n1 3\n3 1\n7 10\n1 2\n2 3\n3 1\n1 4\n4 5\n5 1\n4 6\n6 7\n7 4\n6 1\n6 8\n1 2\n2 3\n3 4\n4 5\n5 6\n6 1\n6 2\n5 1\n",
"4\n3 3\n1 2\n2 3\n3 1\n3 6\n1 2\n2 1\n2 3\n3 2\n1 3\n3 1\n7 10\n1 2\n2 3\n3 1\n1 4\n4 5\n5 1\n4 6\n6 7\n7 4\n6 1\n6 8\n1 2\n2 3\n3 4\... | 2CODEFORCES |
1361_E. James and the Chase_348 | James Bond has a new plan for catching his enemy. There are some cities and directed roads between them, such that it is possible to travel between any two cities using these roads. When the enemy appears in some city, Bond knows her next destination but has no idea which path she will choose to move there.
The city ... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.PriorityQueue;
import java.util.AbstractQueue;
import java.util.Random;
import java.util.ArrayList;
import java.util.AbstractCollection;
import java.io.OutputStreamWriter;
import java.io.OutputStream;
import java.util.... | 4JAVA | {
"input": [
"4\n3 3\n1 2\n2 3\n3 1\n3 6\n1 2\n2 1\n2 3\n3 2\n1 3\n3 1\n7 10\n1 2\n2 3\n3 1\n1 4\n4 5\n5 1\n4 6\n6 7\n7 4\n6 1\n6 8\n1 2\n2 3\n3 4\n4 5\n5 6\n6 1\n6 2\n5 1\n",
"4\n3 3\n1 2\n2 3\n3 1\n3 6\n1 2\n2 1\n2 3\n3 2\n1 3\n3 1\n7 10\n1 2\n2 3\n3 1\n1 4\n4 5\n5 1\n4 6\n6 7\n7 4\n6 1\n6 8\n1 2\n2 3\n3 4\... | 2CODEFORCES |
1382_A. Common Subsequence_349 | You are given two arrays of integers a_1,…,a_n and b_1,…,b_m.
Your task is to find a non-empty array c_1,…,c_k that is a subsequence of a_1,…,a_n, and also a subsequence of b_1,…,b_m. If there are multiple answers, find one of the smallest possible length. If there are still multiple of the smallest possible length, f... |
for u in range(int(raw_input())):
n,m = map(int ,raw_input().split())
ais = set(map(int, raw_input().split()))
bis = map(int, raw_input().split())
flag = False
for b in bis:
if b in ais:
flag = True
break
print 'YES' if flag else 'NO'
if flag:
print '1 {}'.format(str(b))
| 1Python2 | {
"input": [
"5\n4 5\n10 8 6 4\n1 2 3 4 5\n1 1\n3\n3\n1 1\n3\n2\n5 3\n1000 2 2 2 3\n3 1 5\n5 5\n1 2 3 4 5\n1 2 3 4 5\n",
"1\n2 2\n1 1\n1 2\n",
"1\n1 3\n3\n1 2 3\n",
"1\n1 1\n1000\n1000\n",
"1\n2 2\n2 2\n2 2\n",
"5\n4 5\n10 8 6 4\n1 2 3 4 5\n1 1\n3\n3\n1 1\n3\n2\n5 3\n1000 2 2 2 3\n3 1 5\n5 5\n... | 2CODEFORCES |
1382_A. Common Subsequence_350 | You are given two arrays of integers a_1,…,a_n and b_1,…,b_m.
Your task is to find a non-empty array c_1,…,c_k that is a subsequence of a_1,…,a_n, and also a subsequence of b_1,…,b_m. If there are multiple answers, find one of the smallest possible length. If there are still multiple of the smallest possible length, f... | #include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
int arr[n];
int arr1[m];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
for (int i = 0; i < m; i++) {
cin >> arr1[i];
}
int num = -1;
for (int i = ... | 2C++ | {
"input": [
"5\n4 5\n10 8 6 4\n1 2 3 4 5\n1 1\n3\n3\n1 1\n3\n2\n5 3\n1000 2 2 2 3\n3 1 5\n5 5\n1 2 3 4 5\n1 2 3 4 5\n",
"1\n2 2\n1 1\n1 2\n",
"1\n1 3\n3\n1 2 3\n",
"1\n1 1\n1000\n1000\n",
"1\n2 2\n2 2\n2 2\n",
"5\n4 5\n10 8 6 4\n1 2 3 4 5\n1 1\n3\n3\n1 1\n3\n2\n5 3\n1000 2 2 2 3\n3 1 5\n5 5\n... | 2CODEFORCES |
1382_A. Common Subsequence_351 | You are given two arrays of integers a_1,…,a_n and b_1,…,b_m.
Your task is to find a non-empty array c_1,…,c_k that is a subsequence of a_1,…,a_n, and also a subsequence of b_1,…,b_m. If there are multiple answers, find one of the smallest possible length. If there are still multiple of the smallest possible length, f... | #!/usr/bin/env python3
import io
import os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def get_str():
return input().decode().strip()
def rint():
return map(int, input().split())
def oint():
return int(input())
t = oint()
for _ in range(t):
n, m = rint()
a = set(rint())
b =... | 3Python3 | {
"input": [
"5\n4 5\n10 8 6 4\n1 2 3 4 5\n1 1\n3\n3\n1 1\n3\n2\n5 3\n1000 2 2 2 3\n3 1 5\n5 5\n1 2 3 4 5\n1 2 3 4 5\n",
"1\n2 2\n1 1\n1 2\n",
"1\n1 3\n3\n1 2 3\n",
"1\n1 1\n1000\n1000\n",
"1\n2 2\n2 2\n2 2\n",
"5\n4 5\n10 8 6 4\n1 2 3 4 5\n1 1\n3\n3\n1 1\n3\n2\n5 3\n1000 2 2 2 3\n3 1 5\n5 5\n... | 2CODEFORCES |
1382_A. Common Subsequence_352 | You are given two arrays of integers a_1,…,a_n and b_1,…,b_m.
Your task is to find a non-empty array c_1,…,c_k that is a subsequence of a_1,…,a_n, and also a subsequence of b_1,…,b_m. If there are multiple answers, find one of the smallest possible length. If there are still multiple of the smallest possible length, f... | import java.io.*;
import java.util.*;
public class A {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
int m = sc.nextInt();
HashSet<Integer> h =... | 4JAVA | {
"input": [
"5\n4 5\n10 8 6 4\n1 2 3 4 5\n1 1\n3\n3\n1 1\n3\n2\n5 3\n1000 2 2 2 3\n3 1 5\n5 5\n1 2 3 4 5\n1 2 3 4 5\n",
"1\n2 2\n1 1\n1 2\n",
"1\n1 3\n3\n1 2 3\n",
"1\n1 1\n1000\n1000\n",
"1\n2 2\n2 2\n2 2\n",
"5\n4 5\n10 8 6 4\n1 2 3 4 5\n1 1\n3\n3\n1 1\n3\n2\n5 3\n1000 2 2 2 3\n3 1 5\n5 5\n... | 2CODEFORCES |
1424_N. BubbleSquare Tokens_353 | BubbleSquare social network is celebrating 13^{th} anniversary and it is rewarding its members with special edition BubbleSquare tokens. Every member receives one personal token. Also, two additional tokens are awarded to each member for every friend they have on the network. Yet, there is a twist – everyone should end... | #include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize("Ofast")
using namespace std;
namespace Base {
inline char gc(void) {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? EOF
: *p1++;
}
template... | 2C++ | {
"input": [
"2 1\n1 2\n",
"3 3\n1 2\n1 3\n2 3\n",
"2 0\n1 2\n",
"2 1\n1 3\n",
"3 3\n1 2\n1 5\n2 3\n",
"2 0\n1 0\n",
"4 0\n1 0\n",
"4 0\n1 -1\n",
"0 0\n1 2\n",
"2 0\n1 1\n",
"6 0\n1 0\n",
"4 0\n0 -1\n",
"0 0\n1 0\n",
"8 0\n0 -1\n",
"0 -1\n1 0\n",
"8 0\n0... | 2CODEFORCES |
1446_D2. Frequency Problem (Hard Version)_354 | This is the hard version of the problem. The difference between the versions is in the constraints on the array elements. You can make hacks only if all versions of the problem are solved.
You are given an array [a_1, a_2, ..., a_n].
Your goal is to find the length of the longest subarray of this array such that the... | #include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 69;
const int MX = 5e5 + 5;
const int LG = (int)log2(MX);
const long long mod = 1e9 + 7;
const int BLOCK = 450;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;
vector<int> v, cnt;
vector<int> q, inv;
int val = 0;
void ... | 2C++ | {
"input": [
"7\n1 1 2 2 3 3 3\n",
"10\n1 1 1 5 4 1 3 1 2 2\n",
"1\n1\n",
"100\n92 53 86 41 77 68 80 54 17 96 89 53 64 55 2 80 28 58 77 43 70 91 71 71 78 3 25 2 15 47 60 70 95 19 47 58 57 47 91 2 23 80 86 98 98 98 57 98 98 25 98 98 57 98 98 98 98 98 25 98 98 98 98 98 57 98 98 25 98 98 57 98 98 57 98 9... | 2CODEFORCES |
1446_D2. Frequency Problem (Hard Version)_355 | This is the hard version of the problem. The difference between the versions is in the constraints on the array elements. You can make hacks only if all versions of the problem are solved.
You are given an array [a_1, a_2, ..., a_n].
Your goal is to find the length of the longest subarray of this array such that the... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;
/*
15
1 1 2 2 3 3 3 3 3 3 3 3 3 3 3
*/
public class D2 {
//TODO: FIX THIS!
static int MAX_VAL=200_001;
... | 4JAVA | {
"input": [
"7\n1 1 2 2 3 3 3\n",
"10\n1 1 1 5 4 1 3 1 2 2\n",
"1\n1\n",
"100\n92 53 86 41 77 68 80 54 17 96 89 53 64 55 2 80 28 58 77 43 70 91 71 71 78 3 25 2 15 47 60 70 95 19 47 58 57 47 91 2 23 80 86 98 98 98 57 98 98 25 98 98 57 98 98 98 98 98 25 98 98 98 98 98 57 98 98 25 98 98 57 98 98 57 98 9... | 2CODEFORCES |
1470_E. Strange Permutation_356 | Alice had a permutation p_1, p_2, …, p_n. Unfortunately, the permutation looked very boring, so she decided to change it and choose some non-overlapping subranges of this permutation and reverse them. The cost of reversing a single subrange [l, r] (elements from position l to position r, inclusive) is equal to r - l, a... | #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void*wmem;
char memarr[96000000];
template<class S, class T> inline S min_L(S a,T b){
return a<=b?a:b;
}
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, ... | 2C++ | {
"input": [
"2\n3 1 9\n1 2 3\n1 1\n2 1\n3 1\n1 2\n2 2\n3 2\n1 3\n2 3\n3 3\n6 4 4\n6 5 4 3 1 2\n1 1\n3 14\n1 59\n2 6\n",
"1\n12 4 2\n1 2 3 4 5 6 7 8 9 10 11 12\n2 20\n2 21\n",
"1\n10 2 20\n8 5 2 4 10 3 9 7 1 6\n5 10\n3 17\n6 31\n3 46\n10 42\n7 19\n9 36\n7 3\n3 13\n8 32\n10 25\n9 34\n10 34\n6 33\n3 9\n2 17... | 2CODEFORCES |
1497_D. Genius_357 | Please note the non-standard memory limit.
There are n problems numbered with integers from 1 to n. i-th problem has the complexity c_i = 2^i, tag tag_i and score s_i.
After solving the problem i it's allowed to solve problem j if and only if IQ < |c_i - c_j| and tag_i ≠ tag_j. After solving it your IQ changes and be... | T = int(raw_input())
for case_ in xrange(T):
n = int(raw_input())
ts = map(int, raw_input().split())
ss = map(int, raw_input().split())
dp = [0 for i in xrange(n)]
for i in xrange(n):
for j in xrange(i - 1, -1, -1):
if ts[i] == ts[j]:
continue
delta... | 1Python2 | {
"input": [
"5\n4\n1 2 3 4\n5 10 15 20\n4\n1 2 1 2\n5 10 15 20\n4\n2 2 4 1\n2 8 19 1\n2\n1 1\n6 9\n1\n1\n666\n",
"5\n4\n1 2 3 4\n5 10 15 20\n4\n1 2 1 2\n5 10 15 20\n4\n2 2 4 1\n2 8 19 2\n2\n1 1\n6 9\n1\n1\n666\n",
"5\n4\n1 2 3 4\n5 10 15 20\n4\n1 2 2 2\n5 10 15 20\n4\n2 2 4 1\n2 8 19 2\n2\n1 1\n6 9\n1\n1... | 2CODEFORCES |
1497_D. Genius_358 | Please note the non-standard memory limit.
There are n problems numbered with integers from 1 to n. i-th problem has the complexity c_i = 2^i, tag tag_i and score s_i.
After solving the problem i it's allowed to solve problem j if and only if IQ < |c_i - c_j| and tag_i ≠ tag_j. After solving it your IQ changes and be... |
#include <stdio.h>
#include <map>
#include <vector>
int absi(int i) {
if (i > 0) return i;
else return -i;
}
int main()
{
int T;
scanf("%d", &T);
while (T--) {
int n;
long long ans = 0;
scanf("%d", &n);
std::vector<int> tag(n + 1);
std::vector<int> s(n + 1);
std::vector<long long> d(n + 1, 0);
fo... | 2C++ | {
"input": [
"5\n4\n1 2 3 4\n5 10 15 20\n4\n1 2 1 2\n5 10 15 20\n4\n2 2 4 1\n2 8 19 1\n2\n1 1\n6 9\n1\n1\n666\n",
"5\n4\n1 2 3 4\n5 10 15 20\n4\n1 2 1 2\n5 10 15 20\n4\n2 2 4 1\n2 8 19 2\n2\n1 1\n6 9\n1\n1\n666\n",
"5\n4\n1 2 3 4\n5 10 15 20\n4\n1 2 2 2\n5 10 15 20\n4\n2 2 4 1\n2 8 19 2\n2\n1 1\n6 9\n1\n1... | 2CODEFORCES |
1497_D. Genius_359 | Please note the non-standard memory limit.
There are n problems numbered with integers from 1 to n. i-th problem has the complexity c_i = 2^i, tag tag_i and score s_i.
After solving the problem i it's allowed to solve problem j if and only if IQ < |c_i - c_j| and tag_i ≠ tag_j. After solving it your IQ changes and be... | def nr():return int(input())
def nrs():return [int(i) for i in input().split()]
def f(n,t,s):
d=[0]*n
for i in range(1,n):
for j in range(i-1,-1,-1):
if t[i]==t[j]:continue
sc=abs(s[i]-s[j])
d[i],d[j]=max(d[i],d[j]+sc),max(d[j],d[i]+sc)
return max(d)
for _ in range(nr()):
n=nr()
t=nrs()
s=nrs()
print(... | 3Python3 | {
"input": [
"5\n4\n1 2 3 4\n5 10 15 20\n4\n1 2 1 2\n5 10 15 20\n4\n2 2 4 1\n2 8 19 1\n2\n1 1\n6 9\n1\n1\n666\n",
"5\n4\n1 2 3 4\n5 10 15 20\n4\n1 2 1 2\n5 10 15 20\n4\n2 2 4 1\n2 8 19 2\n2\n1 1\n6 9\n1\n1\n666\n",
"5\n4\n1 2 3 4\n5 10 15 20\n4\n1 2 2 2\n5 10 15 20\n4\n2 2 4 1\n2 8 19 2\n2\n1 1\n6 9\n1\n1... | 2CODEFORCES |
1497_D. Genius_360 | Please note the non-standard memory limit.
There are n problems numbered with integers from 1 to n. i-th problem has the complexity c_i = 2^i, tag tag_i and score s_i.
After solving the problem i it's allowed to solve problem j if and only if IQ < |c_i - c_j| and tag_i ≠ tag_j. After solving it your IQ changes and be... | import java.io.*;
import java.util.*;
public class CF1497D extends PrintWriter {
CF1497D() { super(System.out); }
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF1497D o = new CF1497D(); o.main(); o.flush();
}
void main() {
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.... | 4JAVA | {
"input": [
"5\n4\n1 2 3 4\n5 10 15 20\n4\n1 2 1 2\n5 10 15 20\n4\n2 2 4 1\n2 8 19 1\n2\n1 1\n6 9\n1\n1\n666\n",
"5\n4\n1 2 3 4\n5 10 15 20\n4\n1 2 1 2\n5 10 15 20\n4\n2 2 4 1\n2 8 19 2\n2\n1 1\n6 9\n1\n1\n666\n",
"5\n4\n1 2 3 4\n5 10 15 20\n4\n1 2 2 2\n5 10 15 20\n4\n2 2 4 1\n2 8 19 2\n2\n1 1\n6 9\n1\n1... | 2CODEFORCES |
151_C. Win or Freeze_361 | You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer q. During a move a player should write any integer number that is a non-trivial divisor of the last written number. Then he should run this number of circl... | from itertools import *
from collections import *
from operator import *
from bisect import *
from fractions import *
Ii = lambda: map(int, raw_input().split())
Is = lambda: raw_input().split()
def e_sieve(n):
'''generates primes <=n'''
sieve = [True]*(n+1)
sieve[0] = sieve[1] = False
falses = [Fa... | 1Python2 | {
"input": [
"1\n",
"6\n",
"30\n",
"8587340257\n",
"9\n",
"81\n",
"27\n",
"1408514752349\n",
"25\n",
"49380563\n",
"266418\n",
"319757451841\n",
"6599669076000\n",
"8\n",
"1000000000000\n",
"30971726\n",
"274875809788\n",
"64\n",
"34280152201... | 2CODEFORCES |
151_C. Win or Freeze_362 | You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer q. During a move a player should write any integer number that is a non-trivial divisor of the last written number. Then he should run this number of circl... | #include <bits/stdc++.h>
using namespace std;
inline int read() {
register int x = 0, f = 1, ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
bool prim(long long x) {
if (x == 1ll ... | 2C++ | {
"input": [
"1\n",
"6\n",
"30\n",
"8587340257\n",
"9\n",
"81\n",
"27\n",
"1408514752349\n",
"25\n",
"49380563\n",
"266418\n",
"319757451841\n",
"6599669076000\n",
"8\n",
"1000000000000\n",
"30971726\n",
"274875809788\n",
"64\n",
"34280152201... | 2CODEFORCES |
151_C. Win or Freeze_363 | You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer q. During a move a player should write any integer number that is a non-trivial divisor of the last written number. Then he should run this number of circl... | import sys
line = sys.stdin.readline()
N = int(line)
tmp = N
factor = []
i = 2
while i**2 <= tmp:
if tmp % i == 0:
tmp //= i
factor.append(i)
else: i += 1
if tmp != 1: factor.append(i)
if len(factor) == 2: print(2)
else:
print(1)
if len(factor) <= 1: print(0)
else: print(factor[0] * ... | 3Python3 | {
"input": [
"1\n",
"6\n",
"30\n",
"8587340257\n",
"9\n",
"81\n",
"27\n",
"1408514752349\n",
"25\n",
"49380563\n",
"266418\n",
"319757451841\n",
"6599669076000\n",
"8\n",
"1000000000000\n",
"30971726\n",
"274875809788\n",
"64\n",
"34280152201... | 2CODEFORCES |
151_C. Win or Freeze_364 | You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer q. During a move a player should write any integer number that is a non-trivial divisor of the last written number. Then he should run this number of circl... | import java.io.*;
import java.util.*;
public class c{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
long s = sc.nextLong();
long[][] factors = getFactors(s);
long tot = 0;
for(int i = 0; i < factors.length; i++){
tot += factors[i][1];
}
boolean res = isWinner(tot);
... | 4JAVA | {
"input": [
"1\n",
"6\n",
"30\n",
"8587340257\n",
"9\n",
"81\n",
"27\n",
"1408514752349\n",
"25\n",
"49380563\n",
"266418\n",
"319757451841\n",
"6599669076000\n",
"8\n",
"1000000000000\n",
"30971726\n",
"274875809788\n",
"64\n",
"34280152201... | 2CODEFORCES |
1547_C. Pair Programming_365 | Monocarp and Polycarp are learning new programming techniques. Now they decided to try pair programming.
It's known that they have worked together on the same file for n + m minutes. Every minute exactly one of them made one change to the file. Before they started, there were already k lines written in the file.
Ever... | from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
def main():
pass
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = ... | 1Python2 | {
"input": [
"5\n\n3 2 2\n2 0\n0 5\n\n4 3 2\n2 0 5\n0 6\n\n0 2 2\n1 0\n2 3\n\n5 4 4\n6 0 8 0\n0 7 0 9\n\n5 4 1\n8 7 8 0\n0\n",
"5\n\n3 2 2\n2 0\n0 5\n\n4 3 2\n2 0 5\n0 6\n\n0 2 2\n1 0\n2 3\n\n5 4 4\n6 0 8 0\n0 7 0 9\n\n5 4 1\n8 7 8 0\n0\n",
"5\n\n3 2 2\n2 0\n0 5\n\n4 3 2\n2 1 5\n0 6\n\n0 2 2\n1 0\n2 3\n\n... | 2CODEFORCES |
1547_C. Pair Programming_366 | Monocarp and Polycarp are learning new programming techniques. Now they decided to try pair programming.
It's known that they have worked together on the same file for n + m minutes. Every minute exactly one of them made one change to the file. Before they started, there were already k lines written in the file.
Ever... | #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N = 1e5 + 10;
int t, n, m, k, tot;
int a[N], b[N], ans[N];
template <typename T>
inline void read(T &x){
x = 0;
char c = getchar();
T op = 1;
for(; c < '0' || c > '9'; c = getchar())
if(c == '-') op = -1;
for(; c <= '9' && c ... | 2C++ | {
"input": [
"5\n\n3 2 2\n2 0\n0 5\n\n4 3 2\n2 0 5\n0 6\n\n0 2 2\n1 0\n2 3\n\n5 4 4\n6 0 8 0\n0 7 0 9\n\n5 4 1\n8 7 8 0\n0\n",
"5\n\n3 2 2\n2 0\n0 5\n\n4 3 2\n2 0 5\n0 6\n\n0 2 2\n1 0\n2 3\n\n5 4 4\n6 0 8 0\n0 7 0 9\n\n5 4 1\n8 7 8 0\n0\n",
"5\n\n3 2 2\n2 0\n0 5\n\n4 3 2\n2 1 5\n0 6\n\n0 2 2\n1 0\n2 3\n\n... | 2CODEFORCES |
1547_C. Pair Programming_367 | Monocarp and Polycarp are learning new programming techniques. Now they decided to try pair programming.
It's known that they have worked together on the same file for n + m minutes. Every minute exactly one of them made one change to the file. Before they started, there were already k lines written in the file.
Ever... | # -*- coding: utf-8 -*-
"""
Created on Sat Jul 10 23:15:34 2021
@author: Kevin Chang
Project: Codeforces Problem 1547C
"""
t = int(input())
for i in range(t):
shit = input()
k, n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = [... | 3Python3 | {
"input": [
"5\n\n3 2 2\n2 0\n0 5\n\n4 3 2\n2 0 5\n0 6\n\n0 2 2\n1 0\n2 3\n\n5 4 4\n6 0 8 0\n0 7 0 9\n\n5 4 1\n8 7 8 0\n0\n",
"5\n\n3 2 2\n2 0\n0 5\n\n4 3 2\n2 0 5\n0 6\n\n0 2 2\n1 0\n2 3\n\n5 4 4\n6 0 8 0\n0 7 0 9\n\n5 4 1\n8 7 8 0\n0\n",
"5\n\n3 2 2\n2 0\n0 5\n\n4 3 2\n2 1 5\n0 6\n\n0 2 2\n1 0\n2 3\n\n... | 2CODEFORCES |
1547_C. Pair Programming_368 | Monocarp and Polycarp are learning new programming techniques. Now they decided to try pair programming.
It's known that they have worked together on the same file for n + m minutes. Every minute exactly one of them made one change to the file. Before they started, there were already k lines written in the file.
Ever... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
public class java1 {
public static void main(String[] args) {... | 4JAVA | {
"input": [
"5\n\n3 2 2\n2 0\n0 5\n\n4 3 2\n2 0 5\n0 6\n\n0 2 2\n1 0\n2 3\n\n5 4 4\n6 0 8 0\n0 7 0 9\n\n5 4 1\n8 7 8 0\n0\n",
"5\n\n3 2 2\n2 0\n0 5\n\n4 3 2\n2 0 5\n0 6\n\n0 2 2\n1 0\n2 3\n\n5 4 4\n6 0 8 0\n0 7 0 9\n\n5 4 1\n8 7 8 0\n0\n",
"5\n\n3 2 2\n2 0\n0 5\n\n4 3 2\n2 1 5\n0 6\n\n0 2 2\n1 0\n2 3\n\n... | 2CODEFORCES |
174_E. Ancient Berland Hieroglyphs_369 | Polycarpus enjoys studying Berland hieroglyphs. Once Polycarp got hold of two ancient Berland pictures, on each of which was drawn a circle of hieroglyphs. We know that no hieroglyph occurs twice in either the first or the second circle (but in can occur once in each of them).
Polycarpus wants to save these pictures o... | #include <bits/stdc++.h>
using namespace std;
int lenA, lenB;
int A[1000004];
int B[1000004];
int idxB[1000004];
int main() {
scanf("%d %d", &lenA, &lenB);
for (int i = 0, _n = (lenA); i < _n; ++i) scanf("%d", A + i);
memset(idxB, -1, sizeof(idxB));
for (int j = 0, _n = (lenB); j < _n; ++j) {
scanf("%d", B ... | 2C++ | {
"input": [
"5 4\n1 2 3 4 5\n1 3 5 6\n",
"3 3\n1 2 3\n3 2 1\n",
"4 6\n1 3 5 2\n1 2 3 4 5 6\n",
"1 1\n1\n2\n",
"6 3\n1 2 3 4 5 6\n3 5 1\n",
"5 5\n5 6 3 2 1\n4 3 1 5 6\n",
"1 1\n1\n1\n",
"10 10\n1 2 3 4 5 6 7 8 9 10\n6 7 8 9 10 1 2 3 4 5\n",
"1 2\n1\n1 2\n",
"10 10\n9 12 15 2 4 ... | 2CODEFORCES |
195_A. Let's Watch Football_370 | Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will "hang up" as the size of data to watch per second will be more than the si... | import math
a, b, c = map(int, str(raw_input()).split())
print int(math.ceil((a*c)/float(b)))-c; | 1Python2 | {
"input": [
"10 3 2\n",
"13 12 1\n",
"4 1 1\n",
"993 992 991\n",
"100 1 10\n",
"960 935 994\n",
"99 8 99\n",
"60 16 1\n",
"759 10 258\n",
"24 19 9\n",
"196 169 144\n",
"1000 999 1\n",
"945 812 917\n",
"1000 100 10\n",
"500 300 300\n",
"888 777 1000\n",
... | 2CODEFORCES |
195_A. Let's Watch Football_371 | Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will "hang up" as the size of data to watch per second will be more than the si... | #include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
inline int gcd(int a, int b) {
if (a < b) {
a ^= b;
b ^= a;
a ^= b;
};
return (a > b) ? gcd(a - b, b) : a;
}
inline int abs(int x) { return x > 0 ? x : -x; }
void solve() {
int a, b, c, t, all;
bool fin = fals... | 2C++ | {
"input": [
"10 3 2\n",
"13 12 1\n",
"4 1 1\n",
"993 992 991\n",
"100 1 10\n",
"960 935 994\n",
"99 8 99\n",
"60 16 1\n",
"759 10 258\n",
"24 19 9\n",
"196 169 144\n",
"1000 999 1\n",
"945 812 917\n",
"1000 100 10\n",
"500 300 300\n",
"888 777 1000\n",
... | 2CODEFORCES |
195_A. Let's Watch Football_372 | Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will "hang up" as the size of data to watch per second will be more than the si... | from math import ceil
a,b,c = map(int,input().split())
t = (a*c - c*b)/b
print(ceil(t)) | 3Python3 | {
"input": [
"10 3 2\n",
"13 12 1\n",
"4 1 1\n",
"993 992 991\n",
"100 1 10\n",
"960 935 994\n",
"99 8 99\n",
"60 16 1\n",
"759 10 258\n",
"24 19 9\n",
"196 169 144\n",
"1000 999 1\n",
"945 812 917\n",
"1000 100 10\n",
"500 300 300\n",
"888 777 1000\n",
... | 2CODEFORCES |
195_A. Let's Watch Football_373 | Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will "hang up" as the size of data to watch per second will be more than the si... | import java.util.Scanner;
public class P7 {
public static void main(String[] arg) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int tot = a*c;
int cont = 0;
while(tot > 0){
tot = tot -b;... | 4JAVA | {
"input": [
"10 3 2\n",
"13 12 1\n",
"4 1 1\n",
"993 992 991\n",
"100 1 10\n",
"960 935 994\n",
"99 8 99\n",
"60 16 1\n",
"759 10 258\n",
"24 19 9\n",
"196 169 144\n",
"1000 999 1\n",
"945 812 917\n",
"1000 100 10\n",
"500 300 300\n",
"888 777 1000\n",
... | 2CODEFORCES |
219_A. k-String_374 | A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string s, ... | k = input()
s = [i for i in raw_input()]
d = {}
for i in set(s):
d[i] = s.count(i)
if d[i]%k != 0:
print -1
exit()
ss = ''
for i in d.keys():
ss += i*(d[i]/k)
print ss*k | 1Python2 | {
"input": [
"2\naazz\n",
"3\nabcabcabz\n",
"2\naaab\n",
"2\nbabac\n",
"2\naaaaaabbbb\n",
"1\naabaab\n",
"2\naabbbbccccccdddddddd\n",
"2\nabba\n",
"2\naaaazzzz\n",
"250\ncececececececececececececececececececececececececececececececececececececececececececececececececececececece... | 2CODEFORCES |
219_A. k-String_375 | A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string s, ... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
int ara[26];
for (int i = 0; i < 26; i++) {
ara[i] = 0;
}
for (int i = 0, len = s.length(); i < len; i++) {
ara[s[i] - 'a']++;
}
for (int i = 0; i < 26; i++) {
if (ara[i] % n != 0) {
pri... | 2C++ | {
"input": [
"2\naazz\n",
"3\nabcabcabz\n",
"2\naaab\n",
"2\nbabac\n",
"2\naaaaaabbbb\n",
"1\naabaab\n",
"2\naabbbbccccccdddddddd\n",
"2\nabba\n",
"2\naaaazzzz\n",
"250\ncececececececececececececececececececececececececececececececececececececececececececececececececececececece... | 2CODEFORCES |
219_A. k-String_376 | A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string s, ... | from collections import Counter
import string
import math
import sys
def array_int():
return [int(i) for i in sys.stdin.readline().split()]
def vary(number_of_variables):
if number_of_variables==1:
return int(sys.stdin.readline())
if number_of_variables>=2:
return map(int,sys.stdin.readline(... | 3Python3 | {
"input": [
"2\naazz\n",
"3\nabcabcabz\n",
"2\naaab\n",
"2\nbabac\n",
"2\naaaaaabbbb\n",
"1\naabaab\n",
"2\naabbbbccccccdddddddd\n",
"2\nabba\n",
"2\naaaazzzz\n",
"250\ncececececececececececececececececececececececececececececececececececececececececececececececececececececece... | 2CODEFORCES |
219_A. k-String_377 | A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string s, ... | import java.io.PrintWriter;
import java.util.Scanner;
/**
* <a href="http://codeforces.ru/problemset/problem/219/A"/>
*
* @author pvasilyev
* @since 07 Jan 2014
*/
public class Problem084 {
public static void main(String[] args) {
final Scanner reader = new Scanner(System.in);
final PrintWrit... | 4JAVA | {
"input": [
"2\naazz\n",
"3\nabcabcabz\n",
"2\naaab\n",
"2\nbabac\n",
"2\naaaaaabbbb\n",
"1\naabaab\n",
"2\naabbbbccccccdddddddd\n",
"2\nabba\n",
"2\naaaazzzz\n",
"250\ncececececececececececececececececececececececececececececececececececececececececececececececececececececece... | 2CODEFORCES |
242_C. King's Path_378 | The black king is standing on a chess field consisting of 109 rows and 109 columns. We will consider the rows of the field numbered with integers from 1 to 109 from top to bottom. The columns are similarly numbered with integers from 1 to 109 from left to right. We will denote a cell of the field that is located in the... | from collections import deque
R=lambda:map(int,raw_input().split())
x1,y1,x2,y2=R()
n=input()
inf=10**9
t={}
for _ in xrange(n):
r,a,b=R()
while a<=b:
t[(r,a)]=inf
a+=1
if (x1,y1) in t and (x2,y2) in t:
t[(x1,y1)]=0
q=deque(((x1,y1,0),))
while q and t[(x2,y2)]>=inf:
x,y,z=q.popleft()
for u in ... | 1Python2 | {
"input": [
"3 4 3 10\n3\n3 1 4\n4 5 9\n3 10 10\n",
"1 1 2 10\n2\n1 1 3\n2 6 10\n",
"5 7 6 11\n3\n5 3 8\n6 7 11\n5 2 5\n",
"1 1 1 2\n5\n1000000000 1 10000\n19920401 1188 5566\n1000000000 1 10000\n1 1 10000\n5 100 200\n",
"6 15 7 15\n9\n6 15 15\n7 14 14\n6 15 15\n9 14 14\n7 14 16\n6 15 15\n6 15 15... | 2CODEFORCES |
242_C. King's Path_379 | The black king is standing on a chess field consisting of 109 rows and 109 columns. We will consider the rows of the field numbered with integers from 1 to 109 from top to bottom. The columns are similarly numbered with integers from 1 to 109 from left to right. We will denote a cell of the field that is located in the... | #include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:36777216")
template <class T>
inline T &RD(T &);
template <class T>
inline void OT(const T &);
inline long long RD() {
long long x;
return RD(x);
}
inline char &RC(char &c) {
scanf(" %c", &c);
return c;
}
inline char RC() {
char c;
... | 2C++ | {
"input": [
"3 4 3 10\n3\n3 1 4\n4 5 9\n3 10 10\n",
"1 1 2 10\n2\n1 1 3\n2 6 10\n",
"5 7 6 11\n3\n5 3 8\n6 7 11\n5 2 5\n",
"1 1 1 2\n5\n1000000000 1 10000\n19920401 1188 5566\n1000000000 1 10000\n1 1 10000\n5 100 200\n",
"6 15 7 15\n9\n6 15 15\n7 14 14\n6 15 15\n9 14 14\n7 14 16\n6 15 15\n6 15 15... | 2CODEFORCES |
242_C. King's Path_380 | The black king is standing on a chess field consisting of 109 rows and 109 columns. We will consider the rows of the field numbered with integers from 1 to 109 from top to bottom. The columns are similarly numbered with integers from 1 to 109 from left to right. We will denote a cell of the field that is located in the... | from collections import deque
x0,y0,x1,y1=list(map(int, input().split()))
n=int(input())
allowed={}
for i in range(n):
r,a,b=list(map(int,input().split()))
for j in range(a,b+1):
allowed[(r,j)]=True
visited={}
q=deque()
q.append((x0,y0))
visited[(x0,y0)]=0
dire=[(-1,0),(1,0),(0,-1),(0,1),(-1,-1),(-1,1)... | 3Python3 | {
"input": [
"3 4 3 10\n3\n3 1 4\n4 5 9\n3 10 10\n",
"1 1 2 10\n2\n1 1 3\n2 6 10\n",
"5 7 6 11\n3\n5 3 8\n6 7 11\n5 2 5\n",
"1 1 1 2\n5\n1000000000 1 10000\n19920401 1188 5566\n1000000000 1 10000\n1 1 10000\n5 100 200\n",
"6 15 7 15\n9\n6 15 15\n7 14 14\n6 15 15\n9 14 14\n7 14 16\n6 15 15\n6 15 15... | 2CODEFORCES |
242_C. King's Path_381 | The black king is standing on a chess field consisting of 109 rows and 109 columns. We will consider the rows of the field numbered with integers from 1 to 109 from top to bottom. The columns are similarly numbered with integers from 1 to 109 from left to right. We will denote a cell of the field that is located in the... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.uti... | 4JAVA | {
"input": [
"3 4 3 10\n3\n3 1 4\n4 5 9\n3 10 10\n",
"1 1 2 10\n2\n1 1 3\n2 6 10\n",
"5 7 6 11\n3\n5 3 8\n6 7 11\n5 2 5\n",
"1 1 1 2\n5\n1000000000 1 10000\n19920401 1188 5566\n1000000000 1 10000\n1 1 10000\n5 100 200\n",
"6 15 7 15\n9\n6 15 15\n7 14 14\n6 15 15\n9 14 14\n7 14 16\n6 15 15\n6 15 15... | 2CODEFORCES |
268_A. Games_382 | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ... | import sys
input = sys.stdin.readline
def solve(teams):
res = 0
for first_t_i in range(len(teams)):
for second_t_i in range(len(teams)):
if first_t_i != second_t_i:
if teams[first_t_i][0] == teams[second_t_i][1]:
res += 1
return res
def inp():
return(int(input()))
def insr(n):
... | 1Python2 | {
"input": [
"2\n1 2\n1 2\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"3\n1 2\n2 4\n3 4\n",
"24\n9 83\n90 31\n83 3\n83 3\n21 31\n83 3\n32 31\n12 21\n31 21\n90 32\n32 21\n12 9\n12 31\n9 83\n83 12\n32 3\n32 83\n90 31\n9 32\n31 21\n83 90\n32 21\n21 3\n32 9\n",
"25\n91 57\n2 73\n54 57\n2 57\n23 57\n2 6\n5... | 2CODEFORCES |
268_A. Games_383 | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ... | #include <bits/stdc++.h>
using namespace std;
int main() {
int home[30];
int away[30];
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> home[i];
cin >> away[i];
}
int cnt = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j) continue;
if (home[i] == aw... | 2C++ | {
"input": [
"2\n1 2\n1 2\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"3\n1 2\n2 4\n3 4\n",
"24\n9 83\n90 31\n83 3\n83 3\n21 31\n83 3\n32 31\n12 21\n31 21\n90 32\n32 21\n12 9\n12 31\n9 83\n83 12\n32 3\n32 83\n90 31\n9 32\n31 21\n83 90\n32 21\n21 3\n32 9\n",
"25\n91 57\n2 73\n54 57\n2 57\n23 57\n2 6\n5... | 2CODEFORCES |
268_A. Games_384 | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ... | n=int(input())
mat=[]
for i in range(n):
mat.append(list(map(int, input().rstrip().split())))
b=0
for i in range (n):
for j in range (n):
if mat[i][0]==mat[j][1]:
b=b+1
print(b) | 3Python3 | {
"input": [
"2\n1 2\n1 2\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"3\n1 2\n2 4\n3 4\n",
"24\n9 83\n90 31\n83 3\n83 3\n21 31\n83 3\n32 31\n12 21\n31 21\n90 32\n32 21\n12 9\n12 31\n9 83\n83 12\n32 3\n32 83\n90 31\n9 32\n31 21\n83 90\n32 21\n21 3\n32 9\n",
"25\n91 57\n2 73\n54 57\n2 57\n23 57\n2 6\n5... | 2CODEFORCES |
268_A. Games_385 | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ... | import java.util.HashMap;
import java.util.Scanner;
public class A {
public static void main(String[] args) {
HashMap<Integer, Integer> setH = new HashMap<Integer, Integer>();
HashMap<Integer, Integer> setA = new HashMap<Integer, Integer>();
Scanner s = new Scanner(System.in);
int n... | 4JAVA | {
"input": [
"2\n1 2\n1 2\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"3\n1 2\n2 4\n3 4\n",
"24\n9 83\n90 31\n83 3\n83 3\n21 31\n83 3\n32 31\n12 21\n31 21\n90 32\n32 21\n12 9\n12 31\n9 83\n83 12\n32 3\n32 83\n90 31\n9 32\n31 21\n83 90\n32 21\n21 3\n32 9\n",
"25\n91 57\n2 73\n54 57\n2 57\n23 57\n2 6\n5... | 2CODEFORCES |
290_D. Orange_386 | <image>
Input
The first line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be a letter of English alphabet, lowercase or uppercase.
The second line of the input is an integer between 0 and 26, inclusive.
Output
Output the required string.
Examples
Input
AprilFool
14... | s = raw_input().lower()
n = int(raw_input())
print ''.join([(c.upper()if ord(c)<n+97 else c) for c in s]) | 1Python2 | {
"input": [
"AprilFool\n14\n",
"qH\n2\n",
"nifzlTLaeWxTD\n0\n",
"WlwbRjvrOZakKXqecEdlrCnmvXQtLKBsy\n5\n",
"LiqWMLEULRhW\n1\n",
"kGqopTbelcDUcoZgnnRYXgPCRQwSLoqeIByFWDI\n26\n",
"DuFhhnq\n4\n",
"aaaaAaaaaaaAAaaAaaAaAaaaAaaaaaAAaaAAAAAaaAaAAAAaAA\n4\n",
"VtQISIHREYaEGPustEkzJRN\n20\n... | 2CODEFORCES |
290_D. Orange_387 | <image>
Input
The first line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be a letter of English alphabet, lowercase or uppercase.
The second line of the input is an integer between 0 and 26, inclusive.
Output
Output the required string.
Examples
Input
AprilFool
14... | #include <bits/stdc++.h>
using namespace std;
template <typename T>
int size(T& a) {
return (int)a.size();
}
template <typename T>
T sqr(T a) {
return a * a;
}
bool isLowercase(char ch) { return ch >= 'a' && ch <= 'z'; }
bool isUppercase(char ch) { return !isLowercase(ch); }
char toLowercase(char ch) {
if (isUppe... | 2C++ | {
"input": [
"AprilFool\n14\n",
"qH\n2\n",
"nifzlTLaeWxTD\n0\n",
"WlwbRjvrOZakKXqecEdlrCnmvXQtLKBsy\n5\n",
"LiqWMLEULRhW\n1\n",
"kGqopTbelcDUcoZgnnRYXgPCRQwSLoqeIByFWDI\n26\n",
"DuFhhnq\n4\n",
"aaaaAaaaaaaAAaaAaaAaAaaaAaaaaaAAaaAAAAAaaAaAAAAaAA\n4\n",
"VtQISIHREYaEGPustEkzJRN\n20\n... | 2CODEFORCES |
290_D. Orange_388 | <image>
Input
The first line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be a letter of English alphabet, lowercase or uppercase.
The second line of the input is an integer between 0 and 26, inclusive.
Output
Output the required string.
Examples
Input
AprilFool
14... | text = input().lower()
caps = int(input())+97
for letter in text:
print(letter.upper(), end='')if letter < chr(caps) else print(letter, end='')
print() | 3Python3 | {
"input": [
"AprilFool\n14\n",
"qH\n2\n",
"nifzlTLaeWxTD\n0\n",
"WlwbRjvrOZakKXqecEdlrCnmvXQtLKBsy\n5\n",
"LiqWMLEULRhW\n1\n",
"kGqopTbelcDUcoZgnnRYXgPCRQwSLoqeIByFWDI\n26\n",
"DuFhhnq\n4\n",
"aaaaAaaaaaaAAaaAaaAaAaaaAaaaaaAAaaAAAAAaaAaAAAAaAA\n4\n",
"VtQISIHREYaEGPustEkzJRN\n20\n... | 2CODEFORCES |
290_D. Orange_389 | <image>
Input
The first line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be a letter of English alphabet, lowercase or uppercase.
The second line of the input is an integer between 0 and 26, inclusive.
Output
Output the required string.
Examples
Input
AprilFool
14... | import java.io.*;
public class Main {
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try{
String s = br.readLine();
int n = Integer.parseInt(br.readLine());
s = s.toLowerCase();
String... | 4JAVA | {
"input": [
"AprilFool\n14\n",
"qH\n2\n",
"nifzlTLaeWxTD\n0\n",
"WlwbRjvrOZakKXqecEdlrCnmvXQtLKBsy\n5\n",
"LiqWMLEULRhW\n1\n",
"kGqopTbelcDUcoZgnnRYXgPCRQwSLoqeIByFWDI\n26\n",
"DuFhhnq\n4\n",
"aaaaAaaaaaaAAaaAaaAaAaaaAaaaaaAAaaAAAAAaaAaAAAAaAA\n4\n",
"VtQISIHREYaEGPustEkzJRN\n20\n... | 2CODEFORCES |
316_B2. EKG_390 | In the rush of modern life, people often forget how beautiful the world is. The time to enjoy those around them is so little that some even stand in queues to several rooms at the same time in the clinic, running from one queue to another.
(Cultural note: standing in huge and disorganized queues for hours is a native ... | r=lambda:map(int,raw_input().split())
n,x=r()
a=[0]+r()
v=[0]*(n+1)
for i in range(n+1):
if a[i]:
v[a[i]] = i
r={0}
X=1
for i in range(1,n+1):
if a[i] < 1:
k = 1
z = i
f=0
while z:
if z == x:
X=k;f=1
break
z = v[z]
... | 1Python2 | {
"input": [
"6 2\n2 3 0 5 6 0\n",
"6 2\n0 0 1 0 4 5\n",
"6 1\n2 0 4 0 6 0\n",
"4 1\n0 0 0 0\n",
"20 20\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"10 4\n0 1 4 2 7 0 10 0 5 8\n",
"10 7\n10 8 6 5 0 0 0 4 3 9\n",
"10 1\n8 7 0 2 0 10 0 0 3 5\n",
"10 7\n7 9 2 10 0 0 0 3 5 1\n",
"... | 2CODEFORCES |
316_B2. EKG_391 | In the rush of modern life, people often forget how beautiful the world is. The time to enjoy those around them is so little that some even stand in queues to several rooms at the same time in the clinic, running from one queue to another.
(Cultural note: standing in huge and disorganized queues for hours is a native ... | #include <bits/stdc++.h>
using namespace std;
int s[5555], b[5555];
bool mark[5555], moze[5555];
int main() {
int n, x, i, j, t, q, br, of, bb;
scanf("%d%d", &n, &x);
for (i = 0; i <= n; i++) mark[i] = false;
for (i = 1; i <= n; i++) {
scanf("%d", &s[i]);
mark[s[i]] = true;
}
br = 0;
of = 0;
q =... | 2C++ | {
"input": [
"6 2\n2 3 0 5 6 0\n",
"6 2\n0 0 1 0 4 5\n",
"6 1\n2 0 4 0 6 0\n",
"4 1\n0 0 0 0\n",
"20 20\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"10 4\n0 1 4 2 7 0 10 0 5 8\n",
"10 7\n10 8 6 5 0 0 0 4 3 9\n",
"10 1\n8 7 0 2 0 10 0 0 3 5\n",
"10 7\n7 9 2 10 0 0 0 3 5 1\n",
"... | 2CODEFORCES |
316_B2. EKG_392 | In the rush of modern life, people often forget how beautiful the world is. The time to enjoy those around them is so little that some even stand in queues to several rooms at the same time in the clinic, running from one queue to another.
(Cultural note: standing in huge and disorganized queues for hours is a native ... | def f(x, p):
q = []
while x:
q.append(x)
x = p[x]
return q
from collections import defaultdict
n, k = map(int, input().split())
t = list(map(int, input().split()))
p = [0] * (n + 1)
for i, j in enumerate(t, 1):
p[j] = i
p = [f(i, p) for i, j in enumerate(t, 1) if j == 0]
s = defaultdict(... | 3Python3 | {
"input": [
"6 2\n2 3 0 5 6 0\n",
"6 2\n0 0 1 0 4 5\n",
"6 1\n2 0 4 0 6 0\n",
"4 1\n0 0 0 0\n",
"20 20\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"10 4\n0 1 4 2 7 0 10 0 5 8\n",
"10 7\n10 8 6 5 0 0 0 4 3 9\n",
"10 1\n8 7 0 2 0 10 0 0 3 5\n",
"10 7\n7 9 2 10 0 0 0 3 5 1\n",
"... | 2CODEFORCES |
316_B2. EKG_393 | In the rush of modern life, people often forget how beautiful the world is. The time to enjoy those around them is so little that some even stand in queues to several rooms at the same time in the clinic, running from one queue to another.
(Cultural note: standing in huge and disorganized queues for hours is a native ... | import java.util.*;
public class B {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int count = in.nextInt();
int me = in.nextInt()-1;
int[] map = new int[count];
int[] reverseMap = new int[count];
Arrays.fill(reverseMap,-1);
for(int i=0;i<count;++i) {
... | 4JAVA | {
"input": [
"6 2\n2 3 0 5 6 0\n",
"6 2\n0 0 1 0 4 5\n",
"6 1\n2 0 4 0 6 0\n",
"4 1\n0 0 0 0\n",
"20 20\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"10 4\n0 1 4 2 7 0 10 0 5 8\n",
"10 7\n10 8 6 5 0 0 0 4 3 9\n",
"10 1\n8 7 0 2 0 10 0 0 3 5\n",
"10 7\n7 9 2 10 0 0 0 3 5 1\n",
"... | 2CODEFORCES |
339_A. Helpful Maths_394 | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe... | import sys
def readline():
return sys.stdin.readline().rstrip()
def solve():
s = map(int, readline().split('+'))
s.sort()
print '+'.join(map(str, s))
if __name__ == '__main__':
solve()
| 1Python2 | {
"input": [
"2\n",
"3+2+1\n",
"1+1+3+1+3\n",
"2+2+1+1+3\n",
"3+1\n",
"1+3\n",
"2+2+1+1+1+3+1+1+3+3+2+3+1+3+1+1+3+1+1+2+2+2+2+1+2+1+2+1+1+1+3+1+3+2+3+2+3+3+1+1+1+2+3+2+1+3+1+3+2+2\n",
"2+2\n",
"1+1\n",
"2+3+3+1+2+2+2+1+1+2+1+3+2+2+3+3+2+2+3+3+3+1+1+1+3+3+3+2+1+3+2+3+2+1+1+3+3+3... | 2CODEFORCES |
339_A. Helpful Maths_395 | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe... | #include <bits/stdc++.h>
using namespace std;
int main() {
string s, x, z;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '+') {
continue;
}
for (int j = 0; j < s.size(); j++) {
if (s[j] == '+') {
continue;
}
if (s[i] < s[j]) {
swap(s[j], s[i]);
... | 2C++ | {
"input": [
"2\n",
"3+2+1\n",
"1+1+3+1+3\n",
"2+2+1+1+3\n",
"3+1\n",
"1+3\n",
"2+2+1+1+1+3+1+1+3+3+2+3+1+3+1+1+3+1+1+2+2+2+2+1+2+1+2+1+1+1+3+1+3+2+3+2+3+3+1+1+1+2+3+2+1+3+1+3+2+2\n",
"2+2\n",
"1+1\n",
"2+3+3+1+2+2+2+1+1+2+1+3+2+2+3+3+2+2+3+3+3+1+1+1+3+3+3+2+1+3+2+3+2+1+1+3+3+3... | 2CODEFORCES |
339_A. Helpful Maths_396 | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe... | x=input()
x=x.replace("+","")
x=sorted(x)
for i in range(1,2*len(x)-1,2):
x.insert(i,"+")
x=''.join(x)
print(x)
| 3Python3 | {
"input": [
"2\n",
"3+2+1\n",
"1+1+3+1+3\n",
"2+2+1+1+3\n",
"3+1\n",
"1+3\n",
"2+2+1+1+1+3+1+1+3+3+2+3+1+3+1+1+3+1+1+2+2+2+2+1+2+1+2+1+1+1+3+1+3+2+3+2+3+3+1+1+1+2+3+2+1+3+1+3+2+2\n",
"2+2\n",
"1+1\n",
"2+3+3+1+2+2+2+1+1+2+1+3+2+2+3+3+2+2+3+3+3+1+1+1+3+3+3+2+1+3+2+3+2+1+1+3+3+3... | 2CODEFORCES |
339_A. Helpful Maths_397 | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe... | import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
List<Integer> chao = new ArrayList<>();
Scanner sc = new Scanner(System.in);
int i,b,f,x=0;
String a... | 4JAVA | {
"input": [
"2\n",
"3+2+1\n",
"1+1+3+1+3\n",
"2+2+1+1+3\n",
"3+1\n",
"1+3\n",
"2+2+1+1+1+3+1+1+3+3+2+3+1+3+1+1+3+1+1+2+2+2+2+1+2+1+2+1+1+1+3+1+3+2+3+2+3+3+1+1+1+2+3+2+1+3+1+3+2+2\n",
"2+2\n",
"1+1\n",
"2+3+3+1+2+2+2+1+1+2+1+3+2+2+3+3+2+2+3+3+3+1+1+1+3+3+3+2+1+3+2+3+2+1+1+3+3+3... | 2CODEFORCES |
361_C. Levko and Array Recovery_398 | Levko loves array a1, a2, ... , an, consisting of integers, very much. That is why Levko is playing with array a, performing all sorts of operations with it. Each operation Levko performs is of one of two types:
1. Increase all elements from li to ri by di. In other words, perform assignments aj = aj + di for all j ... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 5000 + 10;
int a[maxn];
int b[maxn];
int c[maxn];
int cnt[maxn];
int n, m;
bool mark[maxn];
int q[maxn][5];
bool Bomb;
int main() {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> q[i][1];
if (q[i][1] == 1) {
cin >> q[i][2] >> q[i][3]... | 2C++ | {
"input": [
"4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 8\n",
"4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 13\n",
"4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 8\n",
"1 4\n1 1 1 2\n2 1 1 6\n1 1 1 1\n2 1 1 7\n",
"2 2\n2 1 2 8\n2 1 2 7\n",
"97 29\n2 78 82 356152\n2 14 29 430177\n1 59 8... | 2CODEFORCES |
361_C. Levko and Array Recovery_399 | Levko loves array a1, a2, ... , an, consisting of integers, very much. That is why Levko is playing with array a, performing all sorts of operations with it. Each operation Levko performs is of one of two types:
1. Increase all elements from li to ri by di. In other words, perform assignments aj = aj + di for all j ... | 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
self.write = self.buffer.write if self.writa... | 3Python3 | {
"input": [
"4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 8\n",
"4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 13\n",
"4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 8\n",
"1 4\n1 1 1 2\n2 1 1 6\n1 1 1 1\n2 1 1 7\n",
"2 2\n2 1 2 8\n2 1 2 7\n",
"97 29\n2 78 82 356152\n2 14 29 430177\n1 59 8... | 2CODEFORCES |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.