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 |
|---|---|---|---|---|---|
1081_D. Maximum Distance_600 | Chouti was tired of the tedious homework, so he opened up an old programming problem he created years ago.
You are given a connected undirected graph with n vertices and m weighted edges. There are k special vertices: x_1, x_2, …, x_k.
Let's define the cost of the path as the maximum weight of the edges in it. And th... | '''input
4 5 3
1 2 3
1 2 5
4 2 1
2 3 2
1 4 4
1 3 3
'''
def mp():
return map(int,str(raw_input()).split())
arr=[i for i in range(100100)]
size=[0 for i in range(100100)]
def root(i):
while arr[i]!=i:
arr[i]=arr[arr[i]]
i=arr[i]
return i
def uni(a,b):
ra=root(a)
rb=root(b)
if ra==rb:
return 0
if size[ra]>=s... | 1Python2 | {
"input": [
"4 5 3\n1 2 3\n1 2 5\n4 2 1\n2 3 2\n1 4 4\n1 3 3\n",
"2 3 2\n2 1\n1 2 3\n1 2 2\n2 2 1\n",
"4 4 3\n1 2 3\n1 2 1\n2 3 2\n1 3 3\n1 4 4\n",
"4 3 2\n1 4\n1 2 1\n2 3 5\n3 4 1\n",
"3 2 2\n1 2\n1 2 1\n2 3 47\n",
"3 2 2\n1 2\n1 2 1\n2 3 1000\n",
"3 2 2\n1 2\n1 2 10\n2 3 100\n",
"3 ... | 2CODEFORCES |
1081_D. Maximum Distance_601 | Chouti was tired of the tedious homework, so he opened up an old programming problem he created years ago.
You are given a connected undirected graph with n vertices and m weighted edges. There are k special vertices: x_1, x_2, …, x_k.
Let's define the cost of the path as the maximum weight of the edges in it. And th... | #include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
vector<int> p;
vector<vector<pair<int, int> > > gr;
vector<int> x;
int dsu_get(int v) { return (v == p[v]) ? v : (p[v] = dsu_get(p[v])); }
void dsu_unite(int a, int b) {
a = dsu_get(a);
b = dsu_get(b);
if (rand() & 1) swap(a, b);
if ... | 2C++ | {
"input": [
"4 5 3\n1 2 3\n1 2 5\n4 2 1\n2 3 2\n1 4 4\n1 3 3\n",
"2 3 2\n2 1\n1 2 3\n1 2 2\n2 2 1\n",
"4 4 3\n1 2 3\n1 2 1\n2 3 2\n1 3 3\n1 4 4\n",
"4 3 2\n1 4\n1 2 1\n2 3 5\n3 4 1\n",
"3 2 2\n1 2\n1 2 1\n2 3 47\n",
"3 2 2\n1 2\n1 2 1\n2 3 1000\n",
"3 2 2\n1 2\n1 2 10\n2 3 100\n",
"3 ... | 2CODEFORCES |
1081_D. Maximum Distance_602 | Chouti was tired of the tedious homework, so he opened up an old programming problem he created years ago.
You are given a connected undirected graph with n vertices and m weighted edges. There are k special vertices: x_1, x_2, …, x_k.
Let's define the cost of the path as the maximum weight of the edges in it. And th... | """
@author: phamv
"""
####Function Definition
def find(x):
while f[x] != x :
f[x] = f[f[x]]
x = f[x]
return x
def merge(u, v) :
u, v = map(find, (u, v))
f[u] = v;
if u == v:
return False
ret = s[u] > 0 and s[v] > 0
s[v] += s[u]
return ret
###############
n, m... | 3Python3 | {
"input": [
"4 5 3\n1 2 3\n1 2 5\n4 2 1\n2 3 2\n1 4 4\n1 3 3\n",
"2 3 2\n2 1\n1 2 3\n1 2 2\n2 2 1\n",
"4 4 3\n1 2 3\n1 2 1\n2 3 2\n1 3 3\n1 4 4\n",
"4 3 2\n1 4\n1 2 1\n2 3 5\n3 4 1\n",
"3 2 2\n1 2\n1 2 1\n2 3 47\n",
"3 2 2\n1 2\n1 2 1\n2 3 1000\n",
"3 2 2\n1 2\n1 2 10\n2 3 100\n",
"3 ... | 2CODEFORCES |
1081_D. Maximum Distance_603 | Chouti was tired of the tedious homework, so he opened up an old programming problem he created years ago.
You are given a connected undirected graph with n vertices and m weighted edges. There are k special vertices: x_1, x_2, …, x_k.
Let's define the cost of the path as the maximum weight of the edges in it. And th... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.util.Collec... | 4JAVA | {
"input": [
"4 5 3\n1 2 3\n1 2 5\n4 2 1\n2 3 2\n1 4 4\n1 3 3\n",
"2 3 2\n2 1\n1 2 3\n1 2 2\n2 2 1\n",
"4 4 3\n1 2 3\n1 2 1\n2 3 2\n1 3 3\n1 4 4\n",
"4 3 2\n1 4\n1 2 1\n2 3 5\n3 4 1\n",
"3 2 2\n1 2\n1 2 1\n2 3 47\n",
"3 2 2\n1 2\n1 2 1\n2 3 1000\n",
"3 2 2\n1 2\n1 2 10\n2 3 100\n",
"3 ... | 2CODEFORCES |
1100_D. Dasha and Chess_604 | This is an interactive task.
Dasha and NN like playing chess. While playing a match they decided that normal chess isn't interesting enough for them, so they invented a game described below.
There are 666 black rooks and 1 white king on the chess board of size 999 × 999. The white king wins if he gets checked by rook... | #include <bits/stdc++.h>
using namespace std;
typedef struct point {
int i, j;
} point;
point rooks[666];
point king;
int mat[1000][1000];
void move(int i, int j) {
if (mat[king.i + i][king.j + j] == 1) i = 0;
king.i += i;
king.j += j;
cout << king.i << " " << king.j << endl;
cout.flush();
}
int main() {
... | 2C++ | {
"input": [
"999 999\n1 1\n1 2\n2 1\n2 2\n1 3\n2 3\n<...>\n26 13\n26 14\n26 15\n26 16\n\n1 700 800\n\n2 1 2\n\n<...>\n\n-1 -1 -1\n",
"999 999\n1 1\n1 2\n2 1\n2 2\n1 3\n2 0\n<...>\n26 13\n26 14\n26 15\n26 16\n\n1 700 800\n\n2 1 2\n\n<...>\n\n-1 -1 -1\n",
"999 999\n1 1\n1 2\n2 1\n2 ... | 2CODEFORCES |
1100_D. Dasha and Chess_605 | This is an interactive task.
Dasha and NN like playing chess. While playing a match they decided that normal chess isn't interesting enough for them, so they invented a game described below.
There are 666 black rooks and 1 white king on the chess board of size 999 × 999. The white king wins if he gets checked by rook... | import java.util.*;
public class Main {
public static Scanner sc = new Scanner(System.in);
public static Pair king;
public static Pair []rook = new Pair[666];
public static boolean finished;
public static boolean checkWhereCorner = false;
public static long movX;
public static long movY;
... | 4JAVA | {
"input": [
"999 999\n1 1\n1 2\n2 1\n2 2\n1 3\n2 3\n<...>\n26 13\n26 14\n26 15\n26 16\n\n1 700 800\n\n2 1 2\n\n<...>\n\n-1 -1 -1\n",
"999 999\n1 1\n1 2\n2 1\n2 2\n1 3\n2 0\n<...>\n26 13\n26 14\n26 15\n26 16\n\n1 700 800\n\n2 1 2\n\n<...>\n\n-1 -1 -1\n",
"999 999\n1 1\n1 2\n2 1\n2 ... | 2CODEFORCES |
1129_A2. Toy Train_606 | Alice received a set of Toy Train™ from Bob. It consists of one train and a connected railway network of n stations, enumerated from 1 through n. The train occupies one station at a time and travels around the network of stations in a circular manner. More precisely, the immediate station that the train will visit afte... | from sys import stdin, stdout
from collections import Counter, defaultdict
from itertools import permutations, combinations
raw_input = stdin.readline
pr = stdout.write
def in_num():
return int(raw_input())
def in_arr():
return map(int,raw_input().split())
def pr_num(n):
stdout.write(str(n)+'\n')
de... | 1Python2 | {
"input": [
"2 3\n1 2\n1 2\n1 2\n",
"5 7\n2 4\n5 1\n2 3\n3 4\n4 1\n5 3\n3 5\n",
"5 1\n3 2\n",
"3 3\n1 2\n1 2\n1 2\n",
"5 3\n2 4\n5 4\n3 2\n",
"20 5\n3 12\n5 20\n16 4\n13 3\n9 14\n",
"3 2\n3 1\n1 3\n",
"3 1\n3 1\n",
"3 2\n1 3\n2 1\n",
"50 20\n4 18\n39 33\n49 32\n7 32\n38 1\n46 ... | 2CODEFORCES |
1129_A2. Toy Train_607 | Alice received a set of Toy Train™ from Bob. It consists of one train and a connected railway network of n stations, enumerated from 1 through n. The train occupies one station at a time and travels around the network of stations in a circular manner. More precisely, the immediate station that the train will visit afte... | #include <bits/stdc++.h>
using namespace std;
vector<int> v[5005];
int n, m;
int x;
int dp[5005];
int dist(int a, int b) {
if (b >= a)
return b - a;
else
return b - a + n;
}
bool cmp(int xx, int yy) { return dist(x, xx) < dist(x, yy); }
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a... | 2C++ | {
"input": [
"2 3\n1 2\n1 2\n1 2\n",
"5 7\n2 4\n5 1\n2 3\n3 4\n4 1\n5 3\n3 5\n",
"5 1\n3 2\n",
"3 3\n1 2\n1 2\n1 2\n",
"5 3\n2 4\n5 4\n3 2\n",
"20 5\n3 12\n5 20\n16 4\n13 3\n9 14\n",
"3 2\n3 1\n1 3\n",
"3 1\n3 1\n",
"3 2\n1 3\n2 1\n",
"50 20\n4 18\n39 33\n49 32\n7 32\n38 1\n46 ... | 2CODEFORCES |
1129_A2. Toy Train_608 | Alice received a set of Toy Train™ from Bob. It consists of one train and a connected railway network of n stations, enumerated from 1 through n. The train occupies one station at a time and travels around the network of stations in a circular manner. More precisely, the immediate station that the train will visit afte... | #Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init... | 3Python3 | {
"input": [
"2 3\n1 2\n1 2\n1 2\n",
"5 7\n2 4\n5 1\n2 3\n3 4\n4 1\n5 3\n3 5\n",
"5 1\n3 2\n",
"3 3\n1 2\n1 2\n1 2\n",
"5 3\n2 4\n5 4\n3 2\n",
"20 5\n3 12\n5 20\n16 4\n13 3\n9 14\n",
"3 2\n3 1\n1 3\n",
"3 1\n3 1\n",
"3 2\n1 3\n2 1\n",
"50 20\n4 18\n39 33\n49 32\n7 32\n38 1\n46 ... | 2CODEFORCES |
1129_A2. Toy Train_609 | Alice received a set of Toy Train™ from Bob. It consists of one train and a connected railway network of n stations, enumerated from 1 through n. The train occupies one station at a time and travels around the network of stations in a circular manner. More precisely, the immediate station that the train will visit afte... | import java.util.*;
import java.io.*;
public class a
{
public static void main(String[] Args) throws Exception
{
FS sc = new FS(System.in);
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int n = sc.nextInt();
int m = sc.nextInt();
... | 4JAVA | {
"input": [
"2 3\n1 2\n1 2\n1 2\n",
"5 7\n2 4\n5 1\n2 3\n3 4\n4 1\n5 3\n3 5\n",
"5 1\n3 2\n",
"3 3\n1 2\n1 2\n1 2\n",
"5 3\n2 4\n5 4\n3 2\n",
"20 5\n3 12\n5 20\n16 4\n13 3\n9 14\n",
"3 2\n3 1\n1 3\n",
"3 1\n3 1\n",
"3 2\n1 3\n2 1\n",
"50 20\n4 18\n39 33\n49 32\n7 32\n38 1\n46 ... | 2CODEFORCES |
1149_B. Three Religions_610 | During the archaeological research in the Middle East you found the traces of three ancient religions: First religion, Second religion and Third religion. You compiled the information on the evolution of each of these beliefs, and you now wonder if the followers of each religion could coexist in peace.
The Word of Uni... | #include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
vector<string> vec_splitter(string s) {
s += ',';
vector<string> res;
while (!s.empty()) {
res.push_back(s.substr(0, s.find(',')));
s = s.substr(s.find(',') + 1);
}
return res;
}
void deb... | 2C++ | {
"input": [
"6 8\nabdabc\n+ 1 a\n+ 1 d\n+ 2 b\n+ 2 c\n+ 3 a\n+ 3 b\n+ 1 c\n- 2\n",
"6 8\nabbaab\n+ 1 a\n+ 2 a\n+ 3 a\n+ 1 b\n+ 2 b\n+ 3 b\n- 1\n+ 2 z\n",
"1 1\nt\n+ 2 p\n",
"2 12\naa\n+ 1 a\n+ 2 a\n+ 3 a\n- 1\n+ 1 a\n- 2\n+ 2 a\n- 3\n+ 3 a\n+ 2 a\n- 1\n- 3\n",
"2 10\nuh\n+ 1 h\n+ 2 u\n+ 3 h\n- 1\... | 2CODEFORCES |
1149_B. Three Religions_611 | During the archaeological research in the Middle East you found the traces of three ancient religions: First religion, Second religion and Third religion. You compiled the information on the evolution of each of these beliefs, and you now wonder if the followers of each religion could coexist in peace.
The Word of Uni... | n, q = map(int, input().split())
s = '!' + input()
nxt = [[n + 1] * (n + 2) for _ in range(26)]
for i in range(n - 1, -1, -1):
c = ord(s[i + 1]) - 97
for j in range(26):
nxt[j][i] = nxt[j][i + 1]
nxt[c][i] = i + 1
w = [[-1], [-1], [-1]]
idx = lambda i, j, k: i * 65536 + j * 256 + k
dp = [0] * (256... | 3Python3 | {
"input": [
"6 8\nabdabc\n+ 1 a\n+ 1 d\n+ 2 b\n+ 2 c\n+ 3 a\n+ 3 b\n+ 1 c\n- 2\n",
"6 8\nabbaab\n+ 1 a\n+ 2 a\n+ 3 a\n+ 1 b\n+ 2 b\n+ 3 b\n- 1\n+ 2 z\n",
"1 1\nt\n+ 2 p\n",
"2 12\naa\n+ 1 a\n+ 2 a\n+ 3 a\n- 1\n+ 1 a\n- 2\n+ 2 a\n- 3\n+ 3 a\n+ 2 a\n- 1\n- 3\n",
"2 10\nuh\n+ 1 h\n+ 2 u\n+ 3 h\n- 1\... | 2CODEFORCES |
1149_B. Three Religions_612 | During the archaeological research in the Middle East you found the traces of three ancient religions: First religion, Second religion and Third religion. You compiled the information on the evolution of each of these beliefs, and you now wonder if the followers of each religion could coexist in peace.
The Word of Uni... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;
/**
* @author khokharnikunj8
*/
public class Main {
public static void main(... | 4JAVA | {
"input": [
"6 8\nabdabc\n+ 1 a\n+ 1 d\n+ 2 b\n+ 2 c\n+ 3 a\n+ 3 b\n+ 1 c\n- 2\n",
"6 8\nabbaab\n+ 1 a\n+ 2 a\n+ 3 a\n+ 1 b\n+ 2 b\n+ 3 b\n- 1\n+ 2 z\n",
"1 1\nt\n+ 2 p\n",
"2 12\naa\n+ 1 a\n+ 2 a\n+ 3 a\n- 1\n+ 1 a\n- 2\n+ 2 a\n- 3\n+ 3 a\n+ 2 a\n- 1\n- 3\n",
"2 10\nuh\n+ 1 h\n+ 2 u\n+ 3 h\n- 1\... | 2CODEFORCES |
1189_A. Keanu Reeves_613 | After playing Neo in the legendary "Matrix" trilogy, Keanu Reeves started doubting himself: maybe we really live in virtual reality? To find if this is true, he needs to solve the following problem.
Let's call a string consisting of only zeroes and ones good if it contains different numbers of zeroes and ones. For exa... | n=input()
s=raw_input()
if s.count('0')*2==n:
print 2
print s[0],s[1:]
else:
print 1
print s | 1Python2 | {
"input": [
"1\n1\n",
"6\n100011\n",
"2\n10\n",
"72\n111101100111001110000000100010100000011011100110001010111010101011111100\n",
"3\n101\n",
"18\n101111001111000110\n",
"7\n1111000\n",
"3\n010\n",
"12\n101010100101\n",
"1\n0\n",
"4\n1010\n",
"6\n101100\n",
"100\n0... | 2CODEFORCES |
1189_A. Keanu Reeves_614 | After playing Neo in the legendary "Matrix" trilogy, Keanu Reeves started doubting himself: maybe we really live in virtual reality? To find if this is true, he needs to solve the following problem.
Let's call a string consisting of only zeroes and ones good if it contains different numbers of zeroes and ones. For exa... | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int n;
cin >> n >> s;
int cnt0 = 0, cnt1 = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '0') {
cnt0++;
} else
cnt1++;
}
if (cnt0 != cnt1) {
cout << "1" << endl;
cout << s << endl;
} else {
cout << "2" <<... | 2C++ | {
"input": [
"1\n1\n",
"6\n100011\n",
"2\n10\n",
"72\n111101100111001110000000100010100000011011100110001010111010101011111100\n",
"3\n101\n",
"18\n101111001111000110\n",
"7\n1111000\n",
"3\n010\n",
"12\n101010100101\n",
"1\n0\n",
"4\n1010\n",
"6\n101100\n",
"100\n0... | 2CODEFORCES |
1189_A. Keanu Reeves_615 | After playing Neo in the legendary "Matrix" trilogy, Keanu Reeves started doubting himself: maybe we really live in virtual reality? To find if this is true, he needs to solve the following problem.
Let's call a string consisting of only zeroes and ones good if it contains different numbers of zeroes and ones. For exa... | n = int(input())
s = str(input())
c = 0
for i in range(len(s)):
if s[i]=='0':
c+=1
else:
c-=1
if c!=0:
print("1"+ "\n" + s)
else:
print("2" + "\n" + s[0:-1],s[-1]) | 3Python3 | {
"input": [
"1\n1\n",
"6\n100011\n",
"2\n10\n",
"72\n111101100111001110000000100010100000011011100110001010111010101011111100\n",
"3\n101\n",
"18\n101111001111000110\n",
"7\n1111000\n",
"3\n010\n",
"12\n101010100101\n",
"1\n0\n",
"4\n1010\n",
"6\n101100\n",
"100\n0... | 2CODEFORCES |
1189_A. Keanu Reeves_616 | After playing Neo in the legendary "Matrix" trilogy, Keanu Reeves started doubting himself: maybe we really live in virtual reality? To find if this is true, he needs to solve the following problem.
Let's call a string consisting of only zeroes and ones good if it contains different numbers of zeroes and ones. For exa... | /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author BATCH1
*/
import java.util.*;
public class ques1 {
public static void main(String[] args){
Scanner sc = ... | 4JAVA | {
"input": [
"1\n1\n",
"6\n100011\n",
"2\n10\n",
"72\n111101100111001110000000100010100000011011100110001010111010101011111100\n",
"3\n101\n",
"18\n101111001111000110\n",
"7\n1111000\n",
"3\n010\n",
"12\n101010100101\n",
"1\n0\n",
"4\n1010\n",
"6\n101100\n",
"100\n0... | 2CODEFORCES |
1208_A. XORinacci_617 | Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows:
* f(0) = a;
* f(1) = b;
* f(n) = f(n-1) ⊕ f(n-2) when n > 1, where ⊕ de... | for t in range(input()):
a,b,n = [int(abn) for abn in raw_input().split(" ")]
n3 = n%3
if n3 == 0:
print a
elif n3 == 1:
print b
else:
print a^b
| 1Python2 | {
"input": [
"3\n3 4 2\n4 5 0\n325 265 1231232\n",
"10\n669924290 408119795 804030560\n663737793 250734602 29671646\n431160679 146708815 289491233\n189259304 606497663 379372476\n707829111 49504411 81710658\n54555019 65618101 626948607\n578351356 288589794 974275296\n400531973 205638174 323247740\n219131617 1... | 2CODEFORCES |
1208_A. XORinacci_618 | Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows:
* f(0) = a;
* f(1) = b;
* f(n) = f(n-1) ⊕ f(n-2) when n > 1, where ⊕ de... | #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t a, b, n, q;
cin >> q;
while (q--) {
cin >> a >> b >> n;
n %= 3;
int pd[3];
pd[0] = a;
pd[1] = b;
pd[2] = pd[0] ^ pd[1];
cout << pd[n] << endl;
}
return 0;
}
| 2C++ | {
"input": [
"3\n3 4 2\n4 5 0\n325 265 1231232\n",
"10\n669924290 408119795 804030560\n663737793 250734602 29671646\n431160679 146708815 289491233\n189259304 606497663 379372476\n707829111 49504411 81710658\n54555019 65618101 626948607\n578351356 288589794 974275296\n400531973 205638174 323247740\n219131617 1... | 2CODEFORCES |
1208_A. XORinacci_619 | Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows:
* f(0) = a;
* f(1) = b;
* f(n) = f(n-1) ⊕ f(n-2) when n > 1, where ⊕ de... | import sys
from collections import defaultdict as dd
from collections import deque
from functools import *
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from math import *
from itertools import permutations ,product
def eprint(*args):
print(*args, file=sys.stderr... | 3Python3 | {
"input": [
"3\n3 4 2\n4 5 0\n325 265 1231232\n",
"10\n669924290 408119795 804030560\n663737793 250734602 29671646\n431160679 146708815 289491233\n189259304 606497663 379372476\n707829111 49504411 81710658\n54555019 65618101 626948607\n578351356 288589794 974275296\n400531973 205638174 323247740\n219131617 1... | 2CODEFORCES |
1208_A. XORinacci_620 | Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows:
* f(0) = a;
* f(1) = b;
* f(n) = f(n-1) ⊕ f(n-2) when n > 1, where ⊕ de... | import java.io.*;
import static java.lang.Integer.parseInt;
import java.util.*;
import javax.swing.*;
public class Start
{
public static void main(String arge[]) throws IOException
{
BufferedReader in =new BufferedReader(new InputStreamReader(System.in));
StringBuilder out =new StringBuilder();
String... | 4JAVA | {
"input": [
"3\n3 4 2\n4 5 0\n325 265 1231232\n",
"10\n669924290 408119795 804030560\n663737793 250734602 29671646\n431160679 146708815 289491233\n189259304 606497663 379372476\n707829111 49504411 81710658\n54555019 65618101 626948607\n578351356 288589794 974275296\n400531973 205638174 323247740\n219131617 1... | 2CODEFORCES |
1227_A. Math Problem_621 | Your math teacher gave you the following problem:
There are n segments on the x-axis, [l_1; r_1], [l_2; r_2], …, [l_n; r_n]. The segment [l; r] includes the bounds, i.e. it is a set of such x that l ≤ x ≤ r. The length of the segment [l; r] is equal to r - l.
Two segments [a; b] and [c; d] have a common point (inters... | t=input()
for i in range(t):
n=input()
l=[0]*n
r=[0]*n
for j in range(n):
l[j],r[j]=map(int,raw_input().split())
r=sorted(r)
l=sorted(l)
print max(0,l[n-1]-r[0]) | 1Python2 | {
"input": [
"4\n3\n4 5\n5 9\n7 7\n5\n11 19\n4 17\n16 16\n3 12\n14 17\n1\n1 10\n1\n1 1\n",
"1\n2\n999999997 999999998\n999999999 1000000000\n",
"4\n1\n1 1000000000\n5\n1 1\n12 18\n1000000000 1000000000\n1 1\n8888888 88888888\n5\n2 5\n3 6\n4 7\n5 8\n6 9\n3\n1 1000000000\n1 1\n1000000000 1000000000\n",
... | 2CODEFORCES |
1227_A. Math Problem_622 | Your math teacher gave you the following problem:
There are n segments on the x-axis, [l_1; r_1], [l_2; r_2], …, [l_n; r_n]. The segment [l; r] includes the bounds, i.e. it is a set of such x that l ≤ x ≤ r. The length of the segment [l; r] is equal to r - l.
Two segments [a; b] and [c; d] have a common point (inters... | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n, i;
cin >> n;
int l[n], r[n];
for (i = 0; i < n; i++) {
cin >> l[i] >> r[i];
}
if (n == 1)
cout << 0 << endl;
else {
... | 2C++ | {
"input": [
"4\n3\n4 5\n5 9\n7 7\n5\n11 19\n4 17\n16 16\n3 12\n14 17\n1\n1 10\n1\n1 1\n",
"1\n2\n999999997 999999998\n999999999 1000000000\n",
"4\n1\n1 1000000000\n5\n1 1\n12 18\n1000000000 1000000000\n1 1\n8888888 88888888\n5\n2 5\n3 6\n4 7\n5 8\n6 9\n3\n1 1000000000\n1 1\n1000000000 1000000000\n",
... | 2CODEFORCES |
1227_A. Math Problem_623 | Your math teacher gave you the following problem:
There are n segments on the x-axis, [l_1; r_1], [l_2; r_2], …, [l_n; r_n]. The segment [l; r] includes the bounds, i.e. it is a set of such x that l ≤ x ≤ r. The length of the segment [l; r] is equal to r - l.
Two segments [a; b] and [c; d] have a common point (inters... | t = int(input())
for i in range(t):
n = int(input())
x = []
y = []
for i in range(n):
a, b = map(int, input().split())
x.append(a)
y.append(b)
if n == 1:
print(0)
elif min(y) > max(x):
print(0)
else:
print(abs(max(x)-min(y)))
| 3Python3 | {
"input": [
"4\n3\n4 5\n5 9\n7 7\n5\n11 19\n4 17\n16 16\n3 12\n14 17\n1\n1 10\n1\n1 1\n",
"1\n2\n999999997 999999998\n999999999 1000000000\n",
"4\n1\n1 1000000000\n5\n1 1\n12 18\n1000000000 1000000000\n1 1\n8888888 88888888\n5\n2 5\n3 6\n4 7\n5 8\n6 9\n3\n1 1000000000\n1 1\n1000000000 1000000000\n",
... | 2CODEFORCES |
1227_A. Math Problem_624 | Your math teacher gave you the following problem:
There are n segments on the x-axis, [l_1; r_1], [l_2; r_2], …, [l_n; r_n]. The segment [l; r] includes the bounds, i.e. it is a set of such x that l ≤ x ≤ r. The length of the segment [l; r] is equal to r - l.
Two segments [a; b] and [c; d] have a common point (inters... | import java.util.*;
import java.lang.*;
import java.math.*;
import java.text.*;
import java.io.*;
public final class Solution {
static PrintWriter out = new PrintWriter(System.out);
static void flush() {
out.flush();
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
publ... | 4JAVA | {
"input": [
"4\n3\n4 5\n5 9\n7 7\n5\n11 19\n4 17\n16 16\n3 12\n14 17\n1\n1 10\n1\n1 1\n",
"1\n2\n999999997 999999998\n999999999 1000000000\n",
"4\n1\n1 1000000000\n5\n1 1\n12 18\n1000000000 1000000000\n1 1\n8888888 88888888\n5\n2 5\n3 6\n4 7\n5 8\n6 9\n3\n1 1000000000\n1 1\n1000000000 1000000000\n",
... | 2CODEFORCES |
124_D. Squares_625 | You are given an infinite checkered field. You should get from a square (x1; y1) to a square (x2; y2). Using the shortest path is not necessary. You can move on the field squares in four directions. That is, when you are positioned in any square, you can move to any other side-neighboring one.
A square (x; y) is cons... | a, b, x1, y1, x2, y2 = map(int, raw_input().split())
def f(c, d):
if c >= 0:
return ((c/d))
return (c/d)
aa = f(x1+y1, 2*a)
aaa = f(x2+y2, 2*a)
ans1 = abs(aaa-aa)
bb = f(x1-y1, 2*b)
bbb = f(x2-y2, 2*b)
ans2 = abs(bbb - bb)
print (max(ans1, ans2))
| 1Python2 | {
"input": [
"2 2 1 0 0 1\n",
"2 2 10 11 0 1\n",
"2 4 3 -1 3 7\n",
"605 297 -251700323 -366763764 -445828791 325081312\n",
"14 9 44 45 -50 -9\n",
"18 17 -26078453 -12853708 26705417 -4593122\n",
"472555248 417950652 -897989583 -805741694 915661619 800897620\n",
"1005 557 -451917708 -32... | 2CODEFORCES |
124_D. Squares_626 | You are given an infinite checkered field. You should get from a square (x1; y1) to a square (x2; y2). Using the shortest path is not necessary. You can move on the field squares in four directions. That is, when you are positioned in any square, you can move to any other side-neighboring one.
A square (x; y) is cons... | #include <bits/stdc++.h>
using namespace std;
int f(string s) {
int k = 0;
for (int i = 0; i < s.size(); i++) k = 10 * k + int(s[i]) - 48;
return k;
}
int main() {
int n, k, l, m, i, j;
int x3, y3, x4, y4, a, b, x1, x2, y1, y2;
cin >> a >> b >> x1 >> y1 >> x2 >> y2;
if (x1 + y1 >= 0)
x3 = (x1 + y1) / ... | 2C++ | {
"input": [
"2 2 1 0 0 1\n",
"2 2 10 11 0 1\n",
"2 4 3 -1 3 7\n",
"605 297 -251700323 -366763764 -445828791 325081312\n",
"14 9 44 45 -50 -9\n",
"18 17 -26078453 -12853708 26705417 -4593122\n",
"472555248 417950652 -897989583 -805741694 915661619 800897620\n",
"1005 557 -451917708 -32... | 2CODEFORCES |
124_D. Squares_627 | You are given an infinite checkered field. You should get from a square (x1; y1) to a square (x2; y2). Using the shortest path is not necessary. You can move on the field squares in four directions. That is, when you are positioned in any square, you can move to any other side-neighboring one.
A square (x; y) is cons... | #!/usr/bin/python3
def cds(a, b, x, y):
return (x + y) // (2 * a), (x - y) // (2 * b)
def norm(x, y):
return max(x, y)
a, b, x1, y1, x2, y2 = map(int, input().split())
xp1, yp1 = cds(a, b, x1, y1)
xp2, yp2 = cds(a, b, x2, y2)
print(norm(abs(xp1 - xp2), abs(yp1 - yp2)))
| 3Python3 | {
"input": [
"2 2 1 0 0 1\n",
"2 2 10 11 0 1\n",
"2 4 3 -1 3 7\n",
"605 297 -251700323 -366763764 -445828791 325081312\n",
"14 9 44 45 -50 -9\n",
"18 17 -26078453 -12853708 26705417 -4593122\n",
"472555248 417950652 -897989583 -805741694 915661619 800897620\n",
"1005 557 -451917708 -32... | 2CODEFORCES |
124_D. Squares_628 | You are given an infinite checkered field. You should get from a square (x1; y1) to a square (x2; y2). Using the shortest path is not necessary. You can move on the field squares in four directions. That is, when you are positioned in any square, you can move to any other side-neighboring one.
A square (x; y) is cons... | import java.util.*;
import java.io.*;
public class D {
public static void main(String[] args) throws IOException {
Scanner s = new Scanner(System.in);
long a = s.nextLong(),b = s.nextLong(),x1 = s.nextLong(),y1 = s.nextLong(),x2 = s.nextLong(),y2 = s.nextLong();
long aInt1 = rd(x1+y1,2*a);
... | 4JAVA | {
"input": [
"2 2 1 0 0 1\n",
"2 2 10 11 0 1\n",
"2 4 3 -1 3 7\n",
"605 297 -251700323 -366763764 -445828791 325081312\n",
"14 9 44 45 -50 -9\n",
"18 17 -26078453 -12853708 26705417 -4593122\n",
"472555248 417950652 -897989583 -805741694 915661619 800897620\n",
"1005 557 -451917708 -32... | 2CODEFORCES |
1269_B. Modulo Equality_629 | You are given a positive integer m and two integer sequence: a=[a_1, a_2, …, a_n] and b=[b_1, b_2, …, b_n]. Both of these sequence have a length n.
Permutation is a sequence of n different positive integers from 1 to n. For example, these sequences are permutations: [1], [1,2], [2,1], [6,7,3,4,1,2,5]. These are not: [... | n, m = map(int,raw_input().split())
a = map(int,raw_input().split())
b = map(int,raw_input().split())
b.sort()
aux = []
for i in range(n):
aux.append((b[0]-a[i]) % m)
aux = list(set(aux))
for i in aux:
q = []
for j in range(n):
q.append((a[j]+i) % m)
q.sort()
if q == b:
print i
break
... | 1Python2 | {
"input": [
"3 2\n0 0 0\n1 1 1\n",
"4 3\n0 0 2 1\n2 0 1 1\n",
"5 10\n0 0 0 1 2\n2 1 0 0 0\n",
"20 10000000\n8861863 2169292 3484361 511558 5975675 1413584 774309 5847326 6668965 2531461 3337531 9484932 2648359 3710600 2232337 5474539 2785576 4119997 5005708 1717831\n247095 4003803 2013625 1177623 739... | 2CODEFORCES |
1269_B. Modulo Equality_630 | You are given a positive integer m and two integer sequence: a=[a_1, a_2, …, a_n] and b=[b_1, b_2, …, b_n]. Both of these sequence have a length n.
Permutation is a sequence of n different positive integers from 1 to n. For example, these sequences are permutations: [1], [1,2], [2,1], [6,7,3,4,1,2,5]. These are not: [... | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ll n, m;
cin >> n >> m;
vector<ll> ar(n);
vector<ll> br(n);
map<ll, ll> a, b;
for (auto &x : ar) {
cin >> x;
a[x]++;
}
for (auto &x : br) {
cin >> x;
b... | 2C++ | {
"input": [
"3 2\n0 0 0\n1 1 1\n",
"4 3\n0 0 2 1\n2 0 1 1\n",
"5 10\n0 0 0 1 2\n2 1 0 0 0\n",
"20 10000000\n8861863 2169292 3484361 511558 5975675 1413584 774309 5847326 6668965 2531461 3337531 9484932 2648359 3710600 2232337 5474539 2785576 4119997 5005708 1717831\n247095 4003803 2013625 1177623 739... | 2CODEFORCES |
1269_B. Modulo Equality_631 | You are given a positive integer m and two integer sequence: a=[a_1, a_2, …, a_n] and b=[b_1, b_2, …, b_n]. Both of these sequence have a length n.
Permutation is a sequence of n different positive integers from 1 to n. For example, these sequences are permutations: [1], [1,2], [2,1], [6,7,3,4,1,2,5]. These are not: [... | import sys
input=sys.stdin.readline
from collections import deque
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.sort()
b.sort()
a=deque(a)
b=deque(b)
ans=0
for _ in range(n):
if a==b:
break
f=1
for j in range(n-1):
if b[j+1]-a[j+1]!=b[j]-a[j]:
f=0
break
i... | 3Python3 | {
"input": [
"3 2\n0 0 0\n1 1 1\n",
"4 3\n0 0 2 1\n2 0 1 1\n",
"5 10\n0 0 0 1 2\n2 1 0 0 0\n",
"20 10000000\n8861863 2169292 3484361 511558 5975675 1413584 774309 5847326 6668965 2531461 3337531 9484932 2648359 3710600 2232337 5474539 2785576 4119997 5005708 1717831\n247095 4003803 2013625 1177623 739... | 2CODEFORCES |
1269_B. Modulo Equality_632 | You are given a positive integer m and two integer sequence: a=[a_1, a_2, …, a_n] and b=[b_1, b_2, …, b_n]. Both of these sequence have a length n.
Permutation is a sequence of n different positive integers from 1 to n. For example, these sequences are permutations: [1], [1,2], [2,1], [6,7,3,4,1,2,5]. These are not: [... | import java.util.*;
import java.io.*;
public class B1269{
public static void main(String args[]) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int arr[] = PA(br.readLine().split(" "));
int n = arr[0] ;
int m = arr[1];
int a[] = PA... | 4JAVA | {
"input": [
"3 2\n0 0 0\n1 1 1\n",
"4 3\n0 0 2 1\n2 0 1 1\n",
"5 10\n0 0 0 1 2\n2 1 0 0 0\n",
"20 10000000\n8861863 2169292 3484361 511558 5975675 1413584 774309 5847326 6668965 2531461 3337531 9484932 2648359 3710600 2232337 5474539 2785576 4119997 5005708 1717831\n247095 4003803 2013625 1177623 739... | 2CODEFORCES |
1291_B. Array Sharpening_633 | You're given an array a_1, …, a_n of n non-negative integers.
Let's call it sharpened if and only if there exists an integer 1 ≤ k ≤ n such that a_1 < a_2 < … < a_k and a_k > a_{k+1} > … > a_n. In particular, any strictly increasing or strictly decreasing array is sharpened. For example:
* The arrays [4], [0, 1], [... | n = int(raw_input())
for i in range(n):
t = int(raw_input())
s = raw_input()
s = s.split()
s = map(int, s)
idx, ma = -1, -1
dp1, dp2 = [], [0 for j in range(t)]
for j in range(t):
if j == 0:
dp1.append(True)
else:
dp1.append( (s[j] >= j and dp1[j - 1])... | 1Python2 | {
"input": [
"10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1\n",
"10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 2 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1\n",
"10\n1\n451008\n3\n12 10 8\n6\n000 11 15 9 2 8\n4\n0 1 1 0\n2\n... | 2CODEFORCES |
1291_B. Array Sharpening_634 | You're given an array a_1, …, a_n of n non-negative integers.
Let's call it sharpened if and only if there exists an integer 1 ≤ k ≤ n such that a_1 < a_2 < … < a_k and a_k > a_{k+1} > … > a_n. In particular, any strictly increasing or strictly decreasing array is sharpened. For example:
* The arrays [4], [0, 1], [... | #include <bits/stdc++.h>
using namespace std;
inline int read() {
char c = getchar();
int x = 0, f = 1;
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
const int inf = 2147483647 - 1;
... | 2C++ | {
"input": [
"10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1\n",
"10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 2 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1\n",
"10\n1\n451008\n3\n12 10 8\n6\n000 11 15 9 2 8\n4\n0 1 1 0\n2\n... | 2CODEFORCES |
1291_B. Array Sharpening_635 | You're given an array a_1, …, a_n of n non-negative integers.
Let's call it sharpened if and only if there exists an integer 1 ≤ k ≤ n such that a_1 < a_2 < … < a_k and a_k > a_{k+1} > … > a_n. In particular, any strictly increasing or strictly decreasing array is sharpened. For example:
* The arrays [4], [0, 1], [... | t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
rok = True
rrok = True
if n == 2 and a[0] == 0 and a[1] == 0:
print("No")
else:
if n%2 == 0:
ar = [0]*n
for i in range(n//2):
... | 3Python3 | {
"input": [
"10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1\n",
"10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 2 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1\n",
"10\n1\n451008\n3\n12 10 8\n6\n000 11 15 9 2 8\n4\n0 1 1 0\n2\n... | 2CODEFORCES |
1291_B. Array Sharpening_636 | You're given an array a_1, …, a_n of n non-negative integers.
Let's call it sharpened if and only if there exists an integer 1 ≤ k ≤ n such that a_1 < a_2 < … < a_k and a_k > a_{k+1} > … > a_n. In particular, any strictly increasing or strictly decreasing array is sharpened. For example:
* The arrays [4], [0, 1], [... | import java.util.*;
import java.io.*;
public class P1291B {
private static void solve() {
int tests = nextInt();
while (tests-- != 0) {
int n = nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
int first = 0;
for (int i = 0; i <... | 4JAVA | {
"input": [
"10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1\n",
"10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 2 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1\n",
"10\n1\n451008\n3\n12 10 8\n6\n000 11 15 9 2 8\n4\n0 1 1 0\n2\n... | 2CODEFORCES |
1311_C. Perform the Combo_637 | You want to perform the combo on your opponent in one popular fighting game. The combo is the string s consisting of n lowercase Latin letters. To perform the combo, you have to press all buttons in the order they appear in s. I.e. if s="abca" then you have to press 'a', then 'b', 'c' and 'a' again.
You know that you ... | import sys
__author__ = 'ratmir'
from collections import deque
alphabet = "abcdefghijklmnopqrstuvwxyz"
def solve(n, a, graph):
return 1
def execute():
[t] = [int(x) for x in sys.stdin.readline().split()]
results = []
for ti in range(0, t):
[n, m] = [int(x1) for x1 in sys.stdin.readline().sp... | 1Python2 | {
"input": [
"3\n4 2\nabca\n1 3\n10 5\ncodeforces\n2 8 3 2 9\n26 10\nqwertyuioplkjhgfdsazxcvbnm\n20 10 1 2 3 5 10 5 9 4\n",
"2\n2 2\nyz\n1 1\n2 2\nyz\n1 1\n",
"1\n11 2\nthisisatest\n3 5\n",
"2\n2 2\nyz\n1 1\n2 2\nzy\n1 1\n",
"1\n11 2\nthisisatest\n3 7\n",
"3\n4 2\nabca\n1 3\n10 5\ncodeforces\n... | 2CODEFORCES |
1311_C. Perform the Combo_638 | You want to perform the combo on your opponent in one popular fighting game. The combo is the string s consisting of n lowercase Latin letters. To perform the combo, you have to press all buttons in the order they appear in s. I.e. if s="abca" then you have to press 'a', then 'b', 'c' and 'a' again.
You know that you ... | #include <bits/stdc++.h>
using namespace std;
int T;
int n, m;
char s[200043];
int p[200043];
long long cnt[200043];
long long ans[43];
int main(int argc, char const *argv[]) {
scanf("%d", &T);
while (T--) {
scanf("%d%d", &n, &m);
scanf("%s", s);
for (int i = 0; i < m; ++i) {
scanf("%d", &p[i]);
... | 2C++ | {
"input": [
"3\n4 2\nabca\n1 3\n10 5\ncodeforces\n2 8 3 2 9\n26 10\nqwertyuioplkjhgfdsazxcvbnm\n20 10 1 2 3 5 10 5 9 4\n",
"2\n2 2\nyz\n1 1\n2 2\nyz\n1 1\n",
"1\n11 2\nthisisatest\n3 5\n",
"2\n2 2\nyz\n1 1\n2 2\nzy\n1 1\n",
"1\n11 2\nthisisatest\n3 7\n",
"3\n4 2\nabca\n1 3\n10 5\ncodeforces\n... | 2CODEFORCES |
1311_C. Perform the Combo_639 | You want to perform the combo on your opponent in one popular fighting game. The combo is the string s consisting of n lowercase Latin letters. To perform the combo, you have to press all buttons in the order they appear in s. I.e. if s="abca" then you have to press 'a', then 'b', 'c' and 'a' again.
You know that you ... | from sys import stdin
from bisect import bisect_left
from collections import Counter
for k in range(int(stdin.readline())):
n,m=[int(x) for x in stdin.readline().split()]
s=input()
d=Counter(s)
l=list(map(int,stdin.readline().split()))
l.sort()
ans=[0 for j in range(0,26)]
for j in range(0,l... | 3Python3 | {
"input": [
"3\n4 2\nabca\n1 3\n10 5\ncodeforces\n2 8 3 2 9\n26 10\nqwertyuioplkjhgfdsazxcvbnm\n20 10 1 2 3 5 10 5 9 4\n",
"2\n2 2\nyz\n1 1\n2 2\nyz\n1 1\n",
"1\n11 2\nthisisatest\n3 5\n",
"2\n2 2\nyz\n1 1\n2 2\nzy\n1 1\n",
"1\n11 2\nthisisatest\n3 7\n",
"3\n4 2\nabca\n1 3\n10 5\ncodeforces\n... | 2CODEFORCES |
1311_C. Perform the Combo_640 | You want to perform the combo on your opponent in one popular fighting game. The combo is the string s consisting of n lowercase Latin letters. To perform the combo, you have to press all buttons in the order they appear in s. I.e. if s="abca" then you have to press 'a', then 'b', 'c' and 'a' again.
You know that you ... | import java.util.*;
import java.io.*;
import static java.lang.Math.abs;
import static java.lang.Math.max;
import static java.lang.Math.min;
public class Sol implements Runnable {
long mod = (long) 1e9 + 7;
void solve(InputReader in, PrintWriter w) {
int t = in.nextInt();
while(t-- > 0) {
int n = i... | 4JAVA | {
"input": [
"3\n4 2\nabca\n1 3\n10 5\ncodeforces\n2 8 3 2 9\n26 10\nqwertyuioplkjhgfdsazxcvbnm\n20 10 1 2 3 5 10 5 9 4\n",
"2\n2 2\nyz\n1 1\n2 2\nyz\n1 1\n",
"1\n11 2\nthisisatest\n3 5\n",
"2\n2 2\nyz\n1 1\n2 2\nzy\n1 1\n",
"1\n11 2\nthisisatest\n3 7\n",
"3\n4 2\nabca\n1 3\n10 5\ncodeforces\n... | 2CODEFORCES |
1334_A. Level Statistics_641 | Polycarp has recently created a new level in this cool new game Berlio Maker 85 and uploaded it online. Now players from all over the world can try his level.
All levels in this game have two stats to them: the number of plays and the number of clears. So when a player attempts the level, the number of plays increases... | """Template for Python Competitive Programmers prepared by Mayank Chaudhary """
# to use the print and division function of Python3
from __future__ import division, print_function
"""value of mod"""
MOD = 998244353
mod = 10**9 + 7
"""use resource"""
# import resource
# resource.setrlimit(resource.RLIMIT_STACK, [0x10... | 1Python2 | {
"input": [
"6\n3\n0 0\n1 1\n1 2\n2\n1 0\n1000 3\n4\n10 1\n15 2\n10 2\n15 2\n1\n765 432\n2\n4 4\n4 3\n5\n0 0\n1 0\n1 0\n1 0\n1 0\n",
"1\n2\n110 2\n115 112\n",
"10\n5\n88 60\n10 3\n48 21\n90 70\n40 88\n5\n20 81\n39 98\n34 87\n100 82\n21 21\n2\n46 91\n89 71\n2\n81 98\n25 36\n3\n84 97\n40 32\n17 29\n2\n56 1... | 2CODEFORCES |
1334_A. Level Statistics_642 | Polycarp has recently created a new level in this cool new game Berlio Maker 85 and uploaded it online. Now players from all over the world can try his level.
All levels in this game have two stats to them: the number of plays and the number of clears. So when a player attempts the level, the number of plays increases... | #include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n = 0;
cin >> n;
long long mp = 0, mc = 0, is = 1;
do {
long long p, c;
cin >> p >> c;
if ((p < mp || c < mc || c > p || p - mp < c - mc) && is) {
cout << "NO" << end... | 2C++ | {
"input": [
"6\n3\n0 0\n1 1\n1 2\n2\n1 0\n1000 3\n4\n10 1\n15 2\n10 2\n15 2\n1\n765 432\n2\n4 4\n4 3\n5\n0 0\n1 0\n1 0\n1 0\n1 0\n",
"1\n2\n110 2\n115 112\n",
"10\n5\n88 60\n10 3\n48 21\n90 70\n40 88\n5\n20 81\n39 98\n34 87\n100 82\n21 21\n2\n46 91\n89 71\n2\n81 98\n25 36\n3\n84 97\n40 32\n17 29\n2\n56 1... | 2CODEFORCES |
1334_A. Level Statistics_643 | Polycarp has recently created a new level in this cool new game Berlio Maker 85 and uploaded it online. Now players from all over the world can try his level.
All levels in this game have two stats to them: the number of plays and the number of clears. So when a player attempts the level, the number of plays increases... | T=int(input())
list=[]
c=-1
d=-1
for i in range(T):
n=int(input())
k="Yes"
for j in range(n):
a,b=map(int,input().split())
if a>=b and c<=a and d<=b and (b-d)<=(a-c):
g=0
else:
k="No"
c=a
d=b
c=-1
d=-1
list.append(k)
for i in range(len(list)):
print(list[i]) | 3Python3 | {
"input": [
"6\n3\n0 0\n1 1\n1 2\n2\n1 0\n1000 3\n4\n10 1\n15 2\n10 2\n15 2\n1\n765 432\n2\n4 4\n4 3\n5\n0 0\n1 0\n1 0\n1 0\n1 0\n",
"1\n2\n110 2\n115 112\n",
"10\n5\n88 60\n10 3\n48 21\n90 70\n40 88\n5\n20 81\n39 98\n34 87\n100 82\n21 21\n2\n46 91\n89 71\n2\n81 98\n25 36\n3\n84 97\n40 32\n17 29\n2\n56 1... | 2CODEFORCES |
1334_A. Level Statistics_644 | Polycarp has recently created a new level in this cool new game Berlio Maker 85 and uploaded it online. Now players from all over the world can try his level.
All levels in this game have two stats to them: the number of plays and the number of clears. So when a player attempts the level, the number of plays increases... | import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class thing {
static boolean isPossible = true;
static int reps;
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWri... | 4JAVA | {
"input": [
"6\n3\n0 0\n1 1\n1 2\n2\n1 0\n1000 3\n4\n10 1\n15 2\n10 2\n15 2\n1\n765 432\n2\n4 4\n4 3\n5\n0 0\n1 0\n1 0\n1 0\n1 0\n",
"1\n2\n110 2\n115 112\n",
"10\n5\n88 60\n10 3\n48 21\n90 70\n40 88\n5\n20 81\n39 98\n34 87\n100 82\n21 21\n2\n46 91\n89 71\n2\n81 98\n25 36\n3\n84 97\n40 32\n17 29\n2\n56 1... | 2CODEFORCES |
1354_C2. Not So Simple Polygon Embedding_645 | The statement of this problem is the same as the statement of problem C1. The only difference is that, in problem C1, n is always even, and in C2, n is always odd.
You are given a regular polygon with 2 ⋅ n vertices (it's convex and has equal sides and equal angles) and all its sides have length 1. Let's name it as 2n... | import atexit
import io
import sys
import math
from collections import defaultdict
_INPUT_LINES = sys.stdin.read().splitlines()
raw_input = iter(_INPUT_LINES).next
_OUTPUT_BUFFER = io.BytesIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
t=int(raw_inpu... | 1Python2 | {
"input": [
"3\n3\n5\n199\n",
"99\n3\n5\n7\n9\n11\n13\n15\n17\n19\n21\n23\n25\n27\n29\n31\n33\n35\n37\n39\n41\n43\n45\n47\n49\n51\n53\n55\n57\n59\n61\n63\n65\n67\n69\n71\n73\n75\n77\n79\n81\n83\n85\n87\n89\n91\n93\n95\n97\n99\n101\n103\n105\n107\n109\n111\n113\n115\n117\n119\n121\n123\n125\n127\n129\n131\n13... | 2CODEFORCES |
1354_C2. Not So Simple Polygon Embedding_646 | The statement of this problem is the same as the statement of problem C1. The only difference is that, in problem C1, n is always even, and in C2, n is always odd.
You are given a regular polygon with 2 ⋅ n vertices (it's convex and has equal sides and equal angles) and all its sides have length 1. Let's name it as 2n... | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();
constexpr double PI = 3.14159265358979323846264338327... | 2C++ | {
"input": [
"3\n3\n5\n199\n",
"99\n3\n5\n7\n9\n11\n13\n15\n17\n19\n21\n23\n25\n27\n29\n31\n33\n35\n37\n39\n41\n43\n45\n47\n49\n51\n53\n55\n57\n59\n61\n63\n65\n67\n69\n71\n73\n75\n77\n79\n81\n83\n85\n87\n89\n91\n93\n95\n97\n99\n101\n103\n105\n107\n109\n111\n113\n115\n117\n119\n121\n123\n125\n127\n129\n131\n13... | 2CODEFORCES |
1354_C2. Not So Simple Polygon Embedding_647 | The statement of this problem is the same as the statement of problem C1. The only difference is that, in problem C1, n is always even, and in C2, n is always odd.
You are given a regular polygon with 2 ⋅ n vertices (it's convex and has equal sides and equal angles) and all its sides have length 1. Let's name it as 2n... | # Why do we fall ? So we can learn to pick ourselves up.
from math import pi,cos
t = int(input())
for _ in range(0,t):
n = int(input())
theta = pi/4
delta = pi/n
maxi,mini,x = 0,0,0
for i in range(0,2*n):
x += cos(theta)
theta -= delta
maxi = max(maxi,x)
mini = min(m... | 3Python3 | {
"input": [
"3\n3\n5\n199\n",
"99\n3\n5\n7\n9\n11\n13\n15\n17\n19\n21\n23\n25\n27\n29\n31\n33\n35\n37\n39\n41\n43\n45\n47\n49\n51\n53\n55\n57\n59\n61\n63\n65\n67\n69\n71\n73\n75\n77\n79\n81\n83\n85\n87\n89\n91\n93\n95\n97\n99\n101\n103\n105\n107\n109\n111\n113\n115\n117\n119\n121\n123\n125\n127\n129\n131\n13... | 2CODEFORCES |
1354_C2. Not So Simple Polygon Embedding_648 | The statement of this problem is the same as the statement of problem C1. The only difference is that, in problem C1, n is always even, and in C2, n is always odd.
You are given a regular polygon with 2 ⋅ n vertices (it's convex and has equal sides and equal angles) and all its sides have length 1. Let's name it as 2n... | import java.io.BufferedOutputStream;
import java.io.Closeable;
import java.io.DataInputStream;
import java.io.Flushable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.InputMismatchException;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
... | 4JAVA | {
"input": [
"3\n3\n5\n199\n",
"99\n3\n5\n7\n9\n11\n13\n15\n17\n19\n21\n23\n25\n27\n29\n31\n33\n35\n37\n39\n41\n43\n45\n47\n49\n51\n53\n55\n57\n59\n61\n63\n65\n67\n69\n71\n73\n75\n77\n79\n81\n83\n85\n87\n89\n91\n93\n95\n97\n99\n101\n103\n105\n107\n109\n111\n113\n115\n117\n119\n121\n123\n125\n127\n129\n131\n13... | 2CODEFORCES |
1374_B. Multiply by 2, divide by 6_649 | You are given an integer n. In one move, you can either multiply n by two or divide n by 6 (if it is divisible by 6 without the remainder).
Your task is to find the minimum number of moves needed to obtain 1 from n or determine if it's impossible to do that.
You have to answer t independent test cases.
Input
The fi... |
# Author : raj1307 - Raj Singh
# Date : 28.06.2020
from __future__ import division, print_function
import os,sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
def ii(): return int(input())... | 1Python2 | {
"input": [
"7\n1\n2\n3\n12\n12345\n15116544\n387420489\n",
"1\n999838675\n",
"1\n782058266\n",
"7\n1\n2\n4\n12\n12345\n15116544\n387420489\n",
"7\n1\n2\n4\n24\n12345\n2324038\n387420489\n",
"7\n1\n2\n4\n24\n12345\n2324038\n655615894\n",
"7\n1\n2\n3\n12\n22908\n15116544\n387420489\n",
... | 2CODEFORCES |
1374_B. Multiply by 2, divide by 6_650 | You are given an integer n. In one move, you can either multiply n by two or divide n by 6 (if it is divisible by 6 without the remainder).
Your task is to find the minimum number of moves needed to obtain 1 from n or determine if it's impossible to do that.
You have to answer t independent test cases.
Input
The fi... | #include <bits/stdc++.h>
using namespace std;
long long TestCases, N, a, b;
int main() {
cin >> TestCases;
while (TestCases--) {
cin >> N;
a = 0;
b = 0;
while (N % 3 == 0) {
N /= 3;
b++;
a++;
}
while (N % 2 == 0) {
N /= 2;
a--;
}
if (N != 1 || a < 0) {
... | 2C++ | {
"input": [
"7\n1\n2\n3\n12\n12345\n15116544\n387420489\n",
"1\n999838675\n",
"1\n782058266\n",
"7\n1\n2\n4\n12\n12345\n15116544\n387420489\n",
"7\n1\n2\n4\n24\n12345\n2324038\n387420489\n",
"7\n1\n2\n4\n24\n12345\n2324038\n655615894\n",
"7\n1\n2\n3\n12\n22908\n15116544\n387420489\n",
... | 2CODEFORCES |
1374_B. Multiply by 2, divide by 6_651 | You are given an integer n. In one move, you can either multiply n by two or divide n by 6 (if it is divisible by 6 without the remainder).
Your task is to find the minimum number of moves needed to obtain 1 from n or determine if it's impossible to do that.
You have to answer t independent test cases.
Input
The fi... | t=int(input())
for i in range(t):
n=int(input())
if n==1:
print(0)
else:
if n%3!=0:
print(-1)
else:
threes=0
twos=0
while n%3==0:
threes+=1
n=n//3
while n%2==0:
twos+=1
... | 3Python3 | {
"input": [
"7\n1\n2\n3\n12\n12345\n15116544\n387420489\n",
"1\n999838675\n",
"1\n782058266\n",
"7\n1\n2\n4\n12\n12345\n15116544\n387420489\n",
"7\n1\n2\n4\n24\n12345\n2324038\n387420489\n",
"7\n1\n2\n4\n24\n12345\n2324038\n655615894\n",
"7\n1\n2\n3\n12\n22908\n15116544\n387420489\n",
... | 2CODEFORCES |
1374_B. Multiply by 2, divide by 6_652 | You are given an integer n. In one move, you can either multiply n by two or divide n by 6 (if it is divisible by 6 without the remainder).
Your task is to find the minimum number of moves needed to obtain 1 from n or determine if it's impossible to do that.
You have to answer t independent test cases.
Input
The fi... | import java.util.Scanner;
public class Solution653B {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int t;
t=sc.nextInt();
long out[]=new long[t];
for(int i=0;i<t;i++)
{
long n;
n=sc.nextLong();
if(n==1)
out[i]=0;
else
{
long nm=0;
while(n%6==0)
... | 4JAVA | {
"input": [
"7\n1\n2\n3\n12\n12345\n15116544\n387420489\n",
"1\n999838675\n",
"1\n782058266\n",
"7\n1\n2\n4\n12\n12345\n15116544\n387420489\n",
"7\n1\n2\n4\n24\n12345\n2324038\n387420489\n",
"7\n1\n2\n4\n24\n12345\n2324038\n655615894\n",
"7\n1\n2\n3\n12\n22908\n15116544\n387420489\n",
... | 2CODEFORCES |
1397_C. Multiples of Length_653 | You are given an array a of n integers.
You want to make all elements of a equal to zero by doing the following operation exactly three times:
* Select a segment, for each number in this segment we can add a multiple of len to it, where len is the length of this segment (added integers can be different).
It can... | import sys
if sys.subversion[0] == "PyPy":
import io, atexit
sys.stdout = io.BytesIO()
atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))
sys.stdin = io.BytesIO(sys.stdin.read())
input = lambda: sys.stdin.readline().rstrip()
RS = raw_input
RI = lambda x=int: map(x,RS().split(... | 1Python2 | {
"input": [
"4\n1 3 2 4\n",
"2\n-492673762 -496405053\n",
"13\n-958184557 -577042357 -616514099 -553646903 -719490759 -761325526 -210773060 -44979753 864458686 -387054074 546903944 638449520 299190036\n",
"5\n450402558 -840167367 -231820501 586187125 -627664644\n",
"32\n474784688 671671886 -59275... | 2CODEFORCES |
1397_C. Multiples of Length_654 | You are given an array a of n integers.
You want to make all elements of a equal to zero by doing the following operation exactly three times:
* Select a segment, for each number in this segment we can add a multiple of len to it, where len is the length of this segment (added integers can be different).
It can... | #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
using namespace std;
const int BUBEN = 550;
const int MOD = 1e9 + 7;
const int BASE = 29;
const int MOD1 = 998244353;
const int BASE1 = 31;
char _getchar_nolock() { return getchar_unlocked(); }
char _p... | 2C++ | {
"input": [
"4\n1 3 2 4\n",
"2\n-492673762 -496405053\n",
"13\n-958184557 -577042357 -616514099 -553646903 -719490759 -761325526 -210773060 -44979753 864458686 -387054074 546903944 638449520 299190036\n",
"5\n450402558 -840167367 -231820501 586187125 -627664644\n",
"32\n474784688 671671886 -59275... | 2CODEFORCES |
1397_C. Multiples of Length_655 | You are given an array a of n integers.
You want to make all elements of a equal to zero by doing the following operation exactly three times:
* Select a segment, for each number in this segment we can add a multiple of len to it, where len is the length of this segment (added integers can be different).
It can... | from sys import stdin
def inp():
return stdin.buffer.readline().rstrip().decode('utf8')
def itg():
return int(stdin.buffer.readline())
def mpint():
return map(int, stdin.buffer.readline().split())
# ############################## import
# ############################## main
# for __ in range(itg()):... | 3Python3 | {
"input": [
"4\n1 3 2 4\n",
"2\n-492673762 -496405053\n",
"13\n-958184557 -577042357 -616514099 -553646903 -719490759 -761325526 -210773060 -44979753 864458686 -387054074 546903944 638449520 299190036\n",
"5\n450402558 -840167367 -231820501 586187125 -627664644\n",
"32\n474784688 671671886 -59275... | 2CODEFORCES |
1397_C. Multiples of Length_656 | You are given an array a of n integers.
You want to make all elements of a equal to zero by doing the following operation exactly three times:
* Select a segment, for each number in this segment we can add a multiple of len to it, where len is the length of this segment (added integers can be different).
It can... |
import java.util.Scanner;
public class Three {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
long n = s.nextLong();
long[] a = new long[(int) n];
long[] b = new long[(int) n];
for (long i = 0; i < n; i++) {
a[(int) i] = s.nextLong(... | 4JAVA | {
"input": [
"4\n1 3 2 4\n",
"2\n-492673762 -496405053\n",
"13\n-958184557 -577042357 -616514099 -553646903 -719490759 -761325526 -210773060 -44979753 864458686 -387054074 546903944 638449520 299190036\n",
"5\n450402558 -840167367 -231820501 586187125 -627664644\n",
"32\n474784688 671671886 -59275... | 2CODEFORCES |
1420_D. Rescue Nibel!_657 | Ori and Sein have overcome many difficult challenges. They finally lit the Shrouded Lantern and found Gumon Seal, the key to the Forlorn Ruins. When they tried to open the door to the ruins... nothing happened.
Ori was very surprised, but Sein gave the explanation quickly: clever Gumon decided to make an additional de... | #!/usr/bin/env python
from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
def make_nCr_mod(max_n=3 * 10**5, mod=998244353):
ma... | 1Python2 | {
"input": [
"3 3\n1 3\n2 3\n3 3\n",
"3 1\n1 1\n2 2\n3 3\n",
"7 3\n1 7\n3 8\n4 5\n6 7\n1 3\n5 10\n8 9\n",
"3 2\n1 1\n2 2\n3 3\n",
"5 2\n1 3\n2 4\n3 5\n4 6\n5 7\n",
"10 7\n1 10\n2 10\n3 10\n4 10\n5 10\n1 2\n1 3\n1 4\n1 5\n1 6\n",
"2 2\n1 1\n1 1\n",
"20 12\n18525 35038\n15816 31586\n1864... | 2CODEFORCES |
1420_D. Rescue Nibel!_658 | Ori and Sein have overcome many difficult challenges. They finally lit the Shrouded Lantern and found Gumon Seal, the key to the Forlorn Ruins. When they tried to open the door to the ruins... nothing happened.
Ori was very surprised, but Sein gave the explanation quickly: clever Gumon decided to make an additional de... | #include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const long long lmt = 3e5 + 5;
long long n, k, fac[lmt], inv[lmt];
pair<long long, long long> a[lmt];
map<long long, long long> m;
set<long long> s;
long long bigmod(long long n, long long p) {
if (p == 0) return 1;
long long x = bigmod(... | 2C++ | {
"input": [
"3 3\n1 3\n2 3\n3 3\n",
"3 1\n1 1\n2 2\n3 3\n",
"7 3\n1 7\n3 8\n4 5\n6 7\n1 3\n5 10\n8 9\n",
"3 2\n1 1\n2 2\n3 3\n",
"5 2\n1 3\n2 4\n3 5\n4 6\n5 7\n",
"10 7\n1 10\n2 10\n3 10\n4 10\n5 10\n1 2\n1 3\n1 4\n1 5\n1 6\n",
"2 2\n1 1\n1 1\n",
"20 12\n18525 35038\n15816 31586\n1864... | 2CODEFORCES |
1420_D. Rescue Nibel!_659 | Ori and Sein have overcome many difficult challenges. They finally lit the Shrouded Lantern and found Gumon Seal, the key to the Forlorn Ruins. When they tried to open the door to the ruins... nothing happened.
Ori was very surprised, but Sein gave the explanation quickly: clever Gumon decided to make an additional de... | import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c for j in range(b)] for i in range(a)]
def list3d(a, b, c, d): return [[[d for k in range(c)] for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e for l in range(d)] for k in range(c)] for j in range(b)]... | 3Python3 | {
"input": [
"3 3\n1 3\n2 3\n3 3\n",
"3 1\n1 1\n2 2\n3 3\n",
"7 3\n1 7\n3 8\n4 5\n6 7\n1 3\n5 10\n8 9\n",
"3 2\n1 1\n2 2\n3 3\n",
"5 2\n1 3\n2 4\n3 5\n4 6\n5 7\n",
"10 7\n1 10\n2 10\n3 10\n4 10\n5 10\n1 2\n1 3\n1 4\n1 5\n1 6\n",
"2 2\n1 1\n1 1\n",
"20 12\n18525 35038\n15816 31586\n1864... | 2CODEFORCES |
1420_D. Rescue Nibel!_660 | Ori and Sein have overcome many difficult challenges. They finally lit the Shrouded Lantern and found Gumon Seal, the key to the Forlorn Ruins. When they tried to open the door to the ruins... nothing happened.
Ori was very surprised, but Sein gave the explanation quickly: clever Gumon decided to make an additional de... | import java.io.*;
import java.util.*;
public class T4 {
public static void main(String[] args) {
FastScanner s = new FastScanner();
T4 main = new T4();
int n = 1;
while (n-- > 0) {
main.MainPrint(s);
}
}
long mod = 998244353L;
private void MainPr... | 4JAVA | {
"input": [
"3 3\n1 3\n2 3\n3 3\n",
"3 1\n1 1\n2 2\n3 3\n",
"7 3\n1 7\n3 8\n4 5\n6 7\n1 3\n5 10\n8 9\n",
"3 2\n1 1\n2 2\n3 3\n",
"5 2\n1 3\n2 4\n3 5\n4 6\n5 7\n",
"10 7\n1 10\n2 10\n3 10\n4 10\n5 10\n1 2\n1 3\n1 4\n1 5\n1 6\n",
"2 2\n1 1\n1 1\n",
"20 12\n18525 35038\n15816 31586\n1864... | 2CODEFORCES |
1439_C. Greedy Shopping_661 | You are given an array a_1, a_2, …, a_n of integers. This array is non-increasing.
Let's consider a line with n shops. The shops are numbered with integers from 1 to n from left to right. The cost of a meal in the i-th shop is equal to a_i.
You should process q queries of two types:
* 1 x y: for each shop 1 ≤ i ≤ ... | #include <bits/stdc++.h>
using namespace std;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vc<vc<T>>;
template <class T>
void mkuni(vector<T> &v) {
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
}
long long rand_int(long long l, long long r) {
static mt19937_64 ... | 2C++ | {
"input": [
"10 6\n10 10 10 6 6 5 5 5 3 1\n2 3 50\n2 4 10\n1 3 10\n2 2 36\n1 4 7\n2 2 17\n",
"1 1\n5\n2 1 6\n",
"1 1\n5\n2 1 7\n",
"10 6\n10 10 10 6 6 5 5 5 3 1\n2 3 50\n2 4 10\n1 3 10\n2 2 36\n1 4 7\n2 2 25\n",
"10 6\n19 10 10 6 6 5 5 5 3 1\n2 3 50\n2 4 10\n1 3 10\n2 2 36\n1 4 7\n2 2 17\n",
... | 2CODEFORCES |
1439_C. Greedy Shopping_662 | You are given an array a_1, a_2, …, a_n of integers. This array is non-increasing.
Let's consider a line with n shops. The shops are numbered with integers from 1 to n from left to right. The cost of a meal in the i-th shop is equal to a_i.
You should process q queries of two types:
* 1 x y: for each shop 1 ≤ i ≤ ... |
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.Random;
public final class E {
private static class SegTree {
int leftMost, rightMost;
SegTree left, right;
long sum;
int operation = Integer.MAX_... | 4JAVA | {
"input": [
"10 6\n10 10 10 6 6 5 5 5 3 1\n2 3 50\n2 4 10\n1 3 10\n2 2 36\n1 4 7\n2 2 17\n",
"1 1\n5\n2 1 6\n",
"1 1\n5\n2 1 7\n",
"10 6\n10 10 10 6 6 5 5 5 3 1\n2 3 50\n2 4 10\n1 3 10\n2 2 36\n1 4 7\n2 2 25\n",
"10 6\n19 10 10 6 6 5 5 5 3 1\n2 3 50\n2 4 10\n1 3 10\n2 2 36\n1 4 7\n2 2 17\n",
... | 2CODEFORCES |
1466_C. Canine poetry_663 | After his wife's tragic death, Eurydice, Orpheus descended to the realm of death to see her. Reaching its gates was uneasy, but passing through them proved to be even more challenging. Mostly because of Cerberus, the three-headed hound of Hades.
Orpheus, a famous poet, and musician plans to calm Cerberus with his poe... | #!/usr/bin/env python
from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
def main():
t = int(input())
for _ in range(t):... | 1Python2 | {
"input": [
"7\nbabba\nabaac\ncodeforces\nzeroorez\nabcdcba\nbbbbbbb\na\n",
"7\nabbab\nabaac\ncodeforces\nzeroorez\nabcdcba\nbbbbbbb\na\n",
"7\nabbab\nabaac\ncodeforces\nzeroorez\nabadcbc\nbbbbbbb\na\n",
"7\nabbab\nabaac\ncodeforces\nzeroorez\nabadcbc\nbbbbabb\na\n",
"7\nbbbaa\nabaac\ncodeforces\... | 2CODEFORCES |
1466_C. Canine poetry_664 | After his wife's tragic death, Eurydice, Orpheus descended to the realm of death to see her. Reaching its gates was uneasy, but passing through them proved to be even more challenging. Mostly because of Cerberus, the three-headed hound of Hades.
Orpheus, a famous poet, and musician plans to calm Cerberus with his poe... | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, st, n) for (int i = st; i < n; i++)
const int INF = 1e9+100;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while (t--){
string s;
cin>>s;
int n = s.size();
int ans = 0;
for (int i = 0; i < n-1;... | 2C++ | {
"input": [
"7\nbabba\nabaac\ncodeforces\nzeroorez\nabcdcba\nbbbbbbb\na\n",
"7\nabbab\nabaac\ncodeforces\nzeroorez\nabcdcba\nbbbbbbb\na\n",
"7\nabbab\nabaac\ncodeforces\nzeroorez\nabadcbc\nbbbbbbb\na\n",
"7\nabbab\nabaac\ncodeforces\nzeroorez\nabadcbc\nbbbbabb\na\n",
"7\nbbbaa\nabaac\ncodeforces\... | 2CODEFORCES |
1466_C. Canine poetry_665 | After his wife's tragic death, Eurydice, Orpheus descended to the realm of death to see her. Reaching its gates was uneasy, but passing through them proved to be even more challenging. Mostly because of Cerberus, the three-headed hound of Hades.
Orpheus, a famous poet, and musician plans to calm Cerberus with his poe... | import math
t=int(input())
for i in range(t):
s=input()
s=list(s)
l=len(s)
if l==1:
print(0)
elif l==2:
if s[0]==s[1]:
print(1)
else:
print(0)
else:
j=0
c=0
while(j<l):
if j==l-1:
break
... | 3Python3 | {
"input": [
"7\nbabba\nabaac\ncodeforces\nzeroorez\nabcdcba\nbbbbbbb\na\n",
"7\nabbab\nabaac\ncodeforces\nzeroorez\nabcdcba\nbbbbbbb\na\n",
"7\nabbab\nabaac\ncodeforces\nzeroorez\nabadcbc\nbbbbbbb\na\n",
"7\nabbab\nabaac\ncodeforces\nzeroorez\nabadcbc\nbbbbabb\na\n",
"7\nbbbaa\nabaac\ncodeforces\... | 2CODEFORCES |
1466_C. Canine poetry_666 | After his wife's tragic death, Eurydice, Orpheus descended to the realm of death to see her. Reaching its gates was uneasy, but passing through them proved to be even more challenging. Mostly because of Cerberus, the three-headed hound of Hades.
Orpheus, a famous poet, and musician plans to calm Cerberus with his poe... | import java.io.*;
import java.util.*;
public class C {
public static void main(String[] args) throws IOException {
InputReader in = new InputReader();
PrintWriter pw = new PrintWriter(System.out);
int t = in.nextInt();
while (t-- > 0) {
char[] str = in.nextLine().toCha... | 4JAVA | {
"input": [
"7\nbabba\nabaac\ncodeforces\nzeroorez\nabcdcba\nbbbbbbb\na\n",
"7\nabbab\nabaac\ncodeforces\nzeroorez\nabcdcba\nbbbbbbb\na\n",
"7\nabbab\nabaac\ncodeforces\nzeroorez\nabadcbc\nbbbbbbb\na\n",
"7\nabbab\nabaac\ncodeforces\nzeroorez\nabadcbc\nbbbbabb\na\n",
"7\nbbbaa\nabaac\ncodeforces\... | 2CODEFORCES |
1490_D. Permutation Transformation_667 | A permutation — is a sequence of length n integers from 1 to n, in which all the numbers occur exactly once. For example, [1], [3, 5, 2, 1, 4], [1, 3, 2] — permutations, and [2, 3, 2], [4, 3, 1], [0] — no.
Polycarp was recently gifted a permutation a[1 ... n] of length n. Polycarp likes trees more than permutations, s... | import inspect
import dis
import sys
def expecting():
"""Return how many values the caller is expecting"""
f = inspect.currentframe().f_back.f_back
return ord(f.f_code.co_code[f.f_lasti + 1])
inp = sys.stdin.read().split()
inp.reverse()
class cint:
def __iter__(self):
for i in range(expecting... | 1Python2 | {
"input": [
"3\n5\n3 5 2 1 4\n1\n1\n4\n4 3 1 2\n",
"3\n5\n3 5 1 2 4\n1\n1\n4\n4 3 1 2\n",
"3\n5\n4 5 2 1 3\n1\n1\n4\n4 3 1 2\n",
"3\n5\n3 4 2 1 5\n1\n1\n4\n4 3 1 2\n",
"3\n5\n2 5 3 1 4\n1\n1\n4\n4 3 1 2\n",
"3\n5\n4 5 1 2 3\n1\n1\n4\n4 3 1 2\n"
],
"output": [
"\n1 0 2 3 1 \n0 \n0 1 3 ... | 2CODEFORCES |
1490_D. Permutation Transformation_668 | A permutation — is a sequence of length n integers from 1 to n, in which all the numbers occur exactly once. For example, [1], [3, 5, 2, 1, 4], [1, 3, 2] — permutations, and [2, 3, 2], [4, 3, 1], [0] — no.
Polycarp was recently gifted a permutation a[1 ... n] of length n. Polycarp likes trees more than permutations, s... | //firstly save by ctrl+s before running the code
//press f5 to debug and input in terminal
//typcast by e.g (long long)variable and for constant e.g 5ll
//-----------------------------------------------------------------------------------------------------------------------------
//count set bits using __builtin_popcou... | 2C++ | {
"input": [
"3\n5\n3 5 2 1 4\n1\n1\n4\n4 3 1 2\n",
"3\n5\n3 5 1 2 4\n1\n1\n4\n4 3 1 2\n",
"3\n5\n4 5 2 1 3\n1\n1\n4\n4 3 1 2\n",
"3\n5\n3 4 2 1 5\n1\n1\n4\n4 3 1 2\n",
"3\n5\n2 5 3 1 4\n1\n1\n4\n4 3 1 2\n",
"3\n5\n4 5 1 2 3\n1\n1\n4\n4 3 1 2\n"
],
"output": [
"\n1 0 2 3 1 \n0 \n0 1 3 ... | 2CODEFORCES |
1490_D. Permutation Transformation_669 | A permutation — is a sequence of length n integers from 1 to n, in which all the numbers occur exactly once. For example, [1], [3, 5, 2, 1, 4], [1, 3, 2] — permutations, and [2, 3, 2], [4, 3, 1], [0] — no.
Polycarp was recently gifted a permutation a[1 ... n] of length n. Polycarp likes trees more than permutations, s... | import sys
input=sys.stdin.readline
I = lambda : list(map(int,input().split()))
t,=I()
for _ in range(t):
n,=I()
l=I()
an=[0]*n
for i in range(n):
x=y=0
j=i+1
x=l[i]
while j<n:
if l[j]>x:
an[i]+=1
x=l[j]
if l[j]==n:
break
j+=1
j=i-1
x=l[i]
while j>-1:
if l[j]>x:
an[i]+=1
... | 3Python3 | {
"input": [
"3\n5\n3 5 2 1 4\n1\n1\n4\n4 3 1 2\n",
"3\n5\n3 5 1 2 4\n1\n1\n4\n4 3 1 2\n",
"3\n5\n4 5 2 1 3\n1\n1\n4\n4 3 1 2\n",
"3\n5\n3 4 2 1 5\n1\n1\n4\n4 3 1 2\n",
"3\n5\n2 5 3 1 4\n1\n1\n4\n4 3 1 2\n",
"3\n5\n4 5 1 2 3\n1\n1\n4\n4 3 1 2\n"
],
"output": [
"\n1 0 2 3 1 \n0 \n0 1 3 ... | 2CODEFORCES |
1490_D. Permutation Transformation_670 | A permutation — is a sequence of length n integers from 1 to n, in which all the numbers occur exactly once. For example, [1], [3, 5, 2, 1, 4], [1, 3, 2] — permutations, and [2, 3, 2], [4, 3, 1], [0] — no.
Polycarp was recently gifted a permutation a[1 ... n] of length n. Polycarp likes trees more than permutations, s... | import java.awt.*;
import java.io.*;
import java.util.*;
import java.util.List;
public class Hell {
public static void main(String[] args) throws Exception {
FastReader sc = new FastReader();
int t=sc.nextInt();
while (t-->0){
int n=sc.nextInt();
int a[]=new int[n];
... | 4JAVA | {
"input": [
"3\n5\n3 5 2 1 4\n1\n1\n4\n4 3 1 2\n",
"3\n5\n3 5 1 2 4\n1\n1\n4\n4 3 1 2\n",
"3\n5\n4 5 2 1 3\n1\n1\n4\n4 3 1 2\n",
"3\n5\n3 4 2 1 5\n1\n1\n4\n4 3 1 2\n",
"3\n5\n2 5 3 1 4\n1\n1\n4\n4 3 1 2\n",
"3\n5\n4 5 1 2 3\n1\n1\n4\n4 3 1 2\n"
],
"output": [
"\n1 0 2 3 1 \n0 \n0 1 3 ... | 2CODEFORCES |
1512_G. Short Task_671 | Let us denote by d(n) the sum of all divisors of the number n, i.e. d(n) = ∑_{k | n} k.
For example, d(1) = 1, d(4) = 1+2+4=7, d(6) = 1+2+3+6=12.
For a given number c, find the minimum n such that d(n) = c.
Input
The first line contains one integer t (1 ≤ t ≤ 10^4). Then t test cases follow.
Each test case is char... | //#pragma GCC optimize ("O3", "unroll-loops")
//#pragma GCC target ("avx2")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int, int>
#define PLL pair<LL, LL>
#define all_of(v) (v... | 2C++ | {
"input": [
"12\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n39\n691\n",
"12\n1\n2\n3\n6\n5\n6\n7\n8\n9\n10\n39\n691\n",
"12\n1\n2\n3\n6\n5\n6\n7\n8\n9\n6\n39\n691\n",
"12\n1\n2\n3\n6\n5\n6\n6\n8\n9\n6\n39\n691\n",
"12\n1\n2\n3\n4\n5\n6\n6\n8\n9\n6\n39\n691\n",
"12\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n33\n691\... | 2CODEFORCES |
1512_G. Short Task_672 | Let us denote by d(n) the sum of all divisors of the number n, i.e. d(n) = ∑_{k | n} k.
For example, d(1) = 1, d(4) = 1+2+4=7, d(6) = 1+2+3+6=12.
For a given number c, find the minimum n such that d(n) = c.
Input
The first line contains one integer t (1 ≤ t ≤ 10^4). Then t test cases follow.
Each test case is char... | import java.io.*;
import java.util.*;
public class Main {
public static void main(String args[])
{
FastReader input=new FastReader();
PrintWriter out=new PrintWriter(System.out);
int T=input.nextInt();
long arr[]=new long[10000001];
for(int i=1;i<10000000;i++)
{
... | 4JAVA | {
"input": [
"12\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n39\n691\n",
"12\n1\n2\n3\n6\n5\n6\n7\n8\n9\n10\n39\n691\n",
"12\n1\n2\n3\n6\n5\n6\n7\n8\n9\n6\n39\n691\n",
"12\n1\n2\n3\n6\n5\n6\n6\n8\n9\n6\n39\n691\n",
"12\n1\n2\n3\n4\n5\n6\n6\n8\n9\n6\n39\n691\n",
"12\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n33\n691\... | 2CODEFORCES |
167_C. Wizards and Numbers_673 | In some country live wizards. They love playing with numbers.
The blackboard has two numbers written on it — a and b. The order of the numbers is not important. Let's consider a ≤ b for the sake of definiteness. The players can cast one of the two spells in turns:
* Replace b with b - ak. Number k can be chosen by... | import sys
from math import *
def win(a,b):
if (a==0):
return False
if (b==0):
return False
if (not win(b%a,a)):
return True
ans=b//a
ans%=a+1
ans%=2
if (ans%2==1):
return False
else:
return True
try:
fi = open("input.txt", "r")
fo = open... | 1Python2 | {
"input": [
"4\n10 21\n31 10\n0 1\n10 30\n",
"7\n576460752303423487 2\n82 9\n101 104\n10 21\n31 10\n0 1\n10 30\n",
"1\n128817972817282999 327672410994637530\n",
"66\n7 0\n5 7\n1 3\n3 2\n3 5\n0 6\n1 2\n0 7\n4 5\n4 7\n5 1\n2 0\n4 0\n0 5\n3 6\n7 3\n6 0\n5 2\n6 6\n1 7\n5 6\n2 2\n3 4\n2 1\n5 3\n4 6\n6 2\n... | 2CODEFORCES |
167_C. Wizards and Numbers_674 | In some country live wizards. They love playing with numbers.
The blackboard has two numbers written on it — a and b. The order of the numbers is not important. Let's consider a ≤ b for the sake of definiteness. The players can cast one of the two spells in turns:
* Replace b with b - ak. Number k can be chosen by... | #include <bits/stdc++.h>
using namespace std;
bool check(long long a, long long b) {
if (!a || !b) return false;
if (a > b) swap(a, b);
if (!check(a, b % a)) return true;
return !(((b / a) % (a + 1)) & 1);
}
int main() {
int T;
cin >> T;
for (; T; --T) {
long long a, b;
cin >> a >> b;
printf("... | 2C++ | {
"input": [
"4\n10 21\n31 10\n0 1\n10 30\n",
"7\n576460752303423487 2\n82 9\n101 104\n10 21\n31 10\n0 1\n10 30\n",
"1\n128817972817282999 327672410994637530\n",
"66\n7 0\n5 7\n1 3\n3 2\n3 5\n0 6\n1 2\n0 7\n4 5\n4 7\n5 1\n2 0\n4 0\n0 5\n3 6\n7 3\n6 0\n5 2\n6 6\n1 7\n5 6\n2 2\n3 4\n2 1\n5 3\n4 6\n6 2\n... | 2CODEFORCES |
167_C. Wizards and Numbers_675 | In some country live wizards. They love playing with numbers.
The blackboard has two numbers written on it — a and b. The order of the numbers is not important. Let's consider a ≤ b for the sake of definiteness. The players can cast one of the two spells in turns:
* Replace b with b - ak. Number k can be chosen by... | def solve(a, b):
if a == 0:
return False
if solve(b % a, a):
b //= a
return not (b % (a + 1) & 1)
return True
n = int(input())
for _ in range(n):
a, b = [int(x) for x in input().split()]
if a > b:
a, b = b, a
if solve(a, b):
print("First")
else:
... | 3Python3 | {
"input": [
"4\n10 21\n31 10\n0 1\n10 30\n",
"7\n576460752303423487 2\n82 9\n101 104\n10 21\n31 10\n0 1\n10 30\n",
"1\n128817972817282999 327672410994637530\n",
"66\n7 0\n5 7\n1 3\n3 2\n3 5\n0 6\n1 2\n0 7\n4 5\n4 7\n5 1\n2 0\n4 0\n0 5\n3 6\n7 3\n6 0\n5 2\n6 6\n1 7\n5 6\n2 2\n3 4\n2 1\n5 3\n4 6\n6 2\n... | 2CODEFORCES |
167_C. Wizards and Numbers_676 | In some country live wizards. They love playing with numbers.
The blackboard has two numbers written on it — a and b. The order of the numbers is not important. Let's consider a ≤ b for the sake of definiteness. The players can cast one of the two spells in turns:
* Replace b with b - ak. Number k can be chosen by... | import java.io.*;
import java.util.*;
public class C {
private static void solve() throws IOException {
int tc = nextInt();
while (tc-- > 0) {
long a = nextLong(), b = nextLong();
out.println(win(a, b) ? "First" : "Second");
}
}
static boolean win(long a, long b) {
if (a > b) {
long t = a;
a =... | 4JAVA | {
"input": [
"4\n10 21\n31 10\n0 1\n10 30\n",
"7\n576460752303423487 2\n82 9\n101 104\n10 21\n31 10\n0 1\n10 30\n",
"1\n128817972817282999 327672410994637530\n",
"66\n7 0\n5 7\n1 3\n3 2\n3 5\n0 6\n1 2\n0 7\n4 5\n4 7\n5 1\n2 0\n4 0\n0 5\n3 6\n7 3\n6 0\n5 2\n6 6\n1 7\n5 6\n2 2\n3 4\n2 1\n5 3\n4 6\n6 2\n... | 2CODEFORCES |
209_B. Pixels_677 | Flatland is inhabited by pixels of three colors: red, green and blue. We know that if two pixels of different colors meet in a violent fight, only one of them survives the fight (that is, the total number of pixels decreases by one). Besides, if pixels of colors x and y (x ≠ y) meet in a violent fight, then the pixel t... | num=sorted([int(i) for i in raw_input().split()])
ans=0
if((num[1]-num[0])%2==0):
ans=num[1]
elif((num[2]-num[1])%2==0):
ans=num[2]
else : ans=num[2]
print(ans) | 1Python2 | {
"input": [
"1 1 1\n",
"3 1 0\n",
"9 530792195 6\n",
"0 0 10\n",
"1944219055 454183506 1369298327\n",
"914835 2742837 9234739\n",
"10 10 0\n",
"2 2 0\n",
"0 0 1\n",
"3 10 1007169359\n",
"0 1 0\n",
"1016450951 2 9\n",
"0 2 10\n",
"2147483648 0 2147483647\n",
... | 2CODEFORCES |
209_B. Pixels_678 | Flatland is inhabited by pixels of three colors: red, green and blue. We know that if two pixels of different colors meet in a violent fight, only one of them survives the fight (that is, the total number of pixels decreases by one). Besides, if pixels of colors x and y (x ≠ y) meet in a violent fight, then the pixel t... | #include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T& num) {
num = 0;
bool f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = 0;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
num = num * 10 + ch - '0';
ch = getchar();
}
num =... | 2C++ | {
"input": [
"1 1 1\n",
"3 1 0\n",
"9 530792195 6\n",
"0 0 10\n",
"1944219055 454183506 1369298327\n",
"914835 2742837 9234739\n",
"10 10 0\n",
"2 2 0\n",
"0 0 1\n",
"3 10 1007169359\n",
"0 1 0\n",
"1016450951 2 9\n",
"0 2 10\n",
"2147483648 0 2147483647\n",
... | 2CODEFORCES |
209_B. Pixels_679 | Flatland is inhabited by pixels of three colors: red, green and blue. We know that if two pixels of different colors meet in a violent fight, only one of them survives the fight (that is, the total number of pixels decreases by one). Besides, if pixels of colors x and y (x ≠ y) meet in a violent fight, then the pixel t... | a = list(map(int,input().split()))
def calc(a):
return int((((a[1]-a[0])+(a[1]+a[0]))/2))
a.sort()
if a[1] % 2 == 0 and a[0] % 2 == 0:
print(calc(a))
elif a[1] % 2 == 0 or a[0] % 2 == 0:
print(a[2])
else:
print(calc(a)) | 3Python3 | {
"input": [
"1 1 1\n",
"3 1 0\n",
"9 530792195 6\n",
"0 0 10\n",
"1944219055 454183506 1369298327\n",
"914835 2742837 9234739\n",
"10 10 0\n",
"2 2 0\n",
"0 0 1\n",
"3 10 1007169359\n",
"0 1 0\n",
"1016450951 2 9\n",
"0 2 10\n",
"2147483648 0 2147483647\n",
... | 2CODEFORCES |
209_B. Pixels_680 | Flatland is inhabited by pixels of three colors: red, green and blue. We know that if two pixels of different colors meet in a violent fight, only one of them survives the fight (that is, the total number of pixels decreases by one). Besides, if pixels of colors x and y (x ≠ y) meet in a violent fight, then the pixel t... |
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
new Main().go();
}
Scanner scan;
PrintWriter print;
void go() {
try {
//scan = ne... | 4JAVA | {
"input": [
"1 1 1\n",
"3 1 0\n",
"9 530792195 6\n",
"0 0 10\n",
"1944219055 454183506 1369298327\n",
"914835 2742837 9234739\n",
"10 10 0\n",
"2 2 0\n",
"0 0 1\n",
"3 10 1007169359\n",
"0 1 0\n",
"1016450951 2 9\n",
"0 2 10\n",
"2147483648 0 2147483647\n",
... | 2CODEFORCES |
235_A. LCM Challenge_681 | Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than n. Can you help me to find th... | def find(a,b):
if(b==0):
return a
else:
return find(b,a%b)
n=input()
if(n>=3):
if(n%2==0):
if(n%3!=0):
print max(((n*(n-2))/2)*(n-1),(n-1)*(n-2)*(n-3),n*(n-1)*(n-3))
else:
print max(((n*(n-2))/2)*(n-1),(n-1)*(n-2)*(n-3))
else:
print n*(n-1)... | 1Python2 | {
"input": [
"7\n",
"9\n",
"447244\n",
"958507\n",
"816923\n",
"836603\n",
"862795\n",
"756604\n",
"1000000\n",
"4\n",
"668827\n",
"245\n",
"520731\n",
"642635\n",
"8\n",
"244\n",
"148\n",
"213\n",
"984699\n",
"20\n",
"810411\n",
... | 2CODEFORCES |
235_A. LCM Challenge_682 | Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than n. Can you help me to find th... | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
long long int n;
cin >> n;
if (n == 1)
cout << "1";
else if (n == 2)
cout << "2";
else if (n & 1)
cout << n * (n - 1) * (n - 2);
else {
if (n % 3 == 0)
cout << (n - 1) * ... | 2C++ | {
"input": [
"7\n",
"9\n",
"447244\n",
"958507\n",
"816923\n",
"836603\n",
"862795\n",
"756604\n",
"1000000\n",
"4\n",
"668827\n",
"245\n",
"520731\n",
"642635\n",
"8\n",
"244\n",
"148\n",
"213\n",
"984699\n",
"20\n",
"810411\n",
... | 2CODEFORCES |
235_A. LCM Challenge_683 | Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than n. Can you help me to find th... | import sys, math
input = sys.stdin.readline
def getInts():
return [int(s) for s in input().split()]
def getInt():
return int(input())
def getStrs():
return [s for s in input().split()]
def getStr():
return input()
def listStr():
return list(input())
import collections as col
import math
def s... | 3Python3 | {
"input": [
"7\n",
"9\n",
"447244\n",
"958507\n",
"816923\n",
"836603\n",
"862795\n",
"756604\n",
"1000000\n",
"4\n",
"668827\n",
"245\n",
"520731\n",
"642635\n",
"8\n",
"244\n",
"148\n",
"213\n",
"984699\n",
"20\n",
"810411\n",
... | 2CODEFORCES |
235_A. LCM Challenge_684 | Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than n. Can you help me to find th... | import java.util.*;
public class CodeForces236C{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
long n = input.nextLong();
if(n == 1){
System.out.println(1);
}
else if(n == 2){
System.out.println(2);
}
else if(n == 3){
System.out.println(6);
}
else{
if(n... | 4JAVA | {
"input": [
"7\n",
"9\n",
"447244\n",
"958507\n",
"816923\n",
"836603\n",
"862795\n",
"756604\n",
"1000000\n",
"4\n",
"668827\n",
"245\n",
"520731\n",
"642635\n",
"8\n",
"244\n",
"148\n",
"213\n",
"984699\n",
"20\n",
"810411\n",
... | 2CODEFORCES |
25_D. Roads not only in Berland_685 | Berland Government decided to improve relations with neighboring countries. First of all, it was decided to build new roads so that from each city of Berland and neighboring countries it became possible to reach all the others. There are n cities in Berland and neighboring countries in total and exactly n - 1 two-way r... | inp=input()
#1:37 start code
adj={}
rem=[]
remv=set()
vis=set()
part=[]
for i in xrange(inp-1):
u,v=map(int,raw_input().split())
if u not in adj:adj[u]=[]
if v not in adj:adj[v]=[]
adj[u].append(v)
adj[v].append(u)
def dfs(node,before):
vis.add(node)
if node not in adj:return
for i in ad... | 1Python2 | {
"input": [
"7\n1 2\n2 3\n3 1\n4 5\n5 6\n6 7\n",
"2\n1 2\n",
"4\n1 4\n3 1\n3 4\n",
"5\n4 1\n4 3\n5 3\n2 4\n",
"21\n7 15\n13 1\n14 3\n4 10\n2 3\n16 18\n17 20\n16 20\n8 4\n3 12\n2 17\n13 11\n16 1\n13 2\n13 5\n8 9\n6 14\n3 17\n16 9\n13 8\n",
"3\n3 1\n3 2\n",
"6\n5 2\n5 3\n1 4\n3 1\n5 6\n",
... | 2CODEFORCES |
25_D. Roads not only in Berland_686 | Berland Government decided to improve relations with neighboring countries. First of all, it was decided to build new roads so that from each city of Berland and neighboring countries it became possible to reach all the others. There are n cities in Berland and neighboring countries in total and exactly n - 1 two-way r... | #include <bits/stdc++.h>
#pragma comment(linker, "/STACK:25600000")
using namespace std;
const int undef = -1;
int n = 0;
int visited[1000];
vector<list<int> > graph;
vector<int> delegates;
set<pair<int, int> > road_list;
void init() {
delegates.reserve(1000 + 10);
graph.reserve(1000 + 10);
for (int i = 0; i < 10... | 2C++ | {
"input": [
"7\n1 2\n2 3\n3 1\n4 5\n5 6\n6 7\n",
"2\n1 2\n",
"4\n1 4\n3 1\n3 4\n",
"5\n4 1\n4 3\n5 3\n2 4\n",
"21\n7 15\n13 1\n14 3\n4 10\n2 3\n16 18\n17 20\n16 20\n8 4\n3 12\n2 17\n13 11\n16 1\n13 2\n13 5\n8 9\n6 14\n3 17\n16 9\n13 8\n",
"3\n3 1\n3 2\n",
"6\n5 2\n5 3\n1 4\n3 1\n5 6\n",
... | 2CODEFORCES |
25_D. Roads not only in Berland_687 | Berland Government decided to improve relations with neighboring countries. First of all, it was decided to build new roads so that from each city of Berland and neighboring countries it became possible to reach all the others. There are n cities in Berland and neighboring countries in total and exactly n - 1 two-way r... | '''
Auther: ghoshashis545 Ashis Ghosh
College: jalpaiguri Govt Enggineering College
'''
from os import path
import sys
from heapq import heappush,heappop
from functools import cmp_to_key as ctk
from collections import deque,defaultdict as dd
from bisect import bisect,bisect_left,bisect_right,insort,insort_lef... | 3Python3 | {
"input": [
"7\n1 2\n2 3\n3 1\n4 5\n5 6\n6 7\n",
"2\n1 2\n",
"4\n1 4\n3 1\n3 4\n",
"5\n4 1\n4 3\n5 3\n2 4\n",
"21\n7 15\n13 1\n14 3\n4 10\n2 3\n16 18\n17 20\n16 20\n8 4\n3 12\n2 17\n13 11\n16 1\n13 2\n13 5\n8 9\n6 14\n3 17\n16 9\n13 8\n",
"3\n3 1\n3 2\n",
"6\n5 2\n5 3\n1 4\n3 1\n5 6\n",
... | 2CODEFORCES |
25_D. Roads not only in Berland_688 | Berland Government decided to improve relations with neighboring countries. First of all, it was decided to build new roads so that from each city of Berland and neighboring countries it became possible to reach all the others. There are n cities in Berland and neighboring countries in total and exactly n - 1 two-way r... | import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.List;
import static java.lang.Math.abs;
import static java.lang.Math.max;
import static... | 4JAVA | {
"input": [
"7\n1 2\n2 3\n3 1\n4 5\n5 6\n6 7\n",
"2\n1 2\n",
"4\n1 4\n3 1\n3 4\n",
"5\n4 1\n4 3\n5 3\n2 4\n",
"21\n7 15\n13 1\n14 3\n4 10\n2 3\n16 18\n17 20\n16 20\n8 4\n3 12\n2 17\n13 11\n16 1\n13 2\n13 5\n8 9\n6 14\n3 17\n16 9\n13 8\n",
"3\n3 1\n3 2\n",
"6\n5 2\n5 3\n1 4\n3 1\n5 6\n",
... | 2CODEFORCES |
283_D. Cows and Cool Sequences_689 | Bessie and the cows have recently been playing with "cool" sequences and are trying to construct some. Unfortunately they are bad at arithmetic, so they need your help!
A pair (x, y) of positive integers is "cool" if x can be expressed as the sum of y consecutive integers (not necessarily positive). A sequence (a1, a2... | #include <bits/stdc++.h>
using namespace std;
const int N = 5005;
const int INF = 0x3f3f3f3f;
int n;
long long a[N], g[2][N];
int dp[2][N];
inline long long read() {
long long f = 1, x = 0;
char ch = getchar();
while (ch > '9' || ch < '0') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' &&... | 2C++ | {
"input": [
"3\n6 4 1\n",
"4\n20 6 3 4\n",
"5\n1 8 1 7 9\n",
"4\n6 7 4 5\n",
"5\n36 37 6 18 36\n",
"3\n5 1 3\n",
"200\n2 1 1 1 2 1 2 1 1 1 2 1 2 2 2 1 1 2 1 2 1 1 1 2 2 1 2 1 1 2 1 1 1 2 1 1 2 2 2 2 2 2 2 2 2 2 1 2 2 1 2 1 2 2 1 1 2 2 2 2 2 2 2 1 1 1 2 1 2 2 1 1 2 1 2 2 2 1 2 1 1 1 2 1 1 ... | 2CODEFORCES |
283_D. Cows and Cool Sequences_690 | Bessie and the cows have recently been playing with "cool" sequences and are trying to construct some. Unfortunately they are bad at arithmetic, so they need your help!
A pair (x, y) of positive integers is "cool" if x can be expressed as the sum of y consecutive integers (not necessarily positive). A sequence (a1, a2... | // Codeforces Round #174
// Problem D -- Cows and Cool Sequences
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {
InputReader reader;
PrintWriter writer;
Main() {
reader = new InputReader();
writer = new PrintWriter(System.out);
}
public static void ma... | 4JAVA | {
"input": [
"3\n6 4 1\n",
"4\n20 6 3 4\n",
"5\n1 8 1 7 9\n",
"4\n6 7 4 5\n",
"5\n36 37 6 18 36\n",
"3\n5 1 3\n",
"200\n2 1 1 1 2 1 2 1 1 1 2 1 2 2 2 1 1 2 1 2 1 1 1 2 2 1 2 1 1 2 1 1 1 2 1 1 2 2 2 2 2 2 2 2 2 2 1 2 2 1 2 1 2 2 1 1 2 2 2 2 2 2 2 1 1 1 2 1 2 2 1 1 2 1 2 2 2 1 2 1 1 1 2 1 1 ... | 2CODEFORCES |
306_C. White, Black and White Again_691 | Polycarpus is sure that his life fits the description: "first there is a white stripe, then a black one, then a white one again". So, Polycarpus is sure that this rule is going to fulfill during the next n days. Polycarpus knows that he is in for w good events and b not-so-good events. At least one event is going to ta... | from math import factorial as F
n, w, b = map(lambda x : int(x), raw_input().split())
print F(w+b-3)/F(n-3)/F(w+b-n)*(w-1)*F(w)*F(b)%(10**9+9)
| 1Python2 | {
"input": [
"3 2 1\n",
"3 2 2\n",
"4 2 2\n",
"3 3 1\n",
"300 2 300\n",
"4000 4000 1\n",
"4000 4000 100\n",
"4 2 3\n",
"3 300 300\n",
"4000 100 4000\n",
"3 300 1\n",
"300 300 1\n",
"4000 1000 3000\n",
"3 2 4000\n",
"4 3 2\n",
"3 2 300\n",
"4000 3998 ... | 2CODEFORCES |
306_C. White, Black and White Again_692 | Polycarpus is sure that his life fits the description: "first there is a white stripe, then a black one, then a white one again". So, Polycarpus is sure that this rule is going to fulfill during the next n days. Polycarpus knows that he is in for w good events and b not-so-good events. At least one event is going to ta... | #include <bits/stdc++.h>
long long ans;
long long jc[4010];
long long c[4010][4010];
int w, n, b;
int main() {
int i, j;
for (i = 0; i <= 4000; ++i) {
c[i][0] = 1;
for (j = 1; j <= i; ++j) {
c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
if (c[i][j] >= 1000000009) c[i][j] -= 1000000009;
}
}
jc... | 2C++ | {
"input": [
"3 2 1\n",
"3 2 2\n",
"4 2 2\n",
"3 3 1\n",
"300 2 300\n",
"4000 4000 1\n",
"4000 4000 100\n",
"4 2 3\n",
"3 300 300\n",
"4000 100 4000\n",
"3 300 1\n",
"300 300 1\n",
"4000 1000 3000\n",
"3 2 4000\n",
"4 3 2\n",
"3 2 300\n",
"4000 3998 ... | 2CODEFORCES |
306_C. White, Black and White Again_693 | Polycarpus is sure that his life fits the description: "first there is a white stripe, then a black one, then a white one again". So, Polycarpus is sure that this rule is going to fulfill during the next n days. Polycarpus knows that he is in for w good events and b not-so-good events. At least one event is going to ta... | import sys
MOD = int(1e9) + 9
def inv(n):
return pow(n, MOD - 2, MOD)
def combo(n):
rv = [0 for __ in range(n + 1)]
rv[0] = 1
for k in range(n):
rv[k + 1] = rv[k] * (n - k) % MOD * inv(k + 1) % MOD
return rv
with sys.stdin as fin, sys.stdout as fout:
n, w, b = map(int, next(fin).spl... | 3Python3 | {
"input": [
"3 2 1\n",
"3 2 2\n",
"4 2 2\n",
"3 3 1\n",
"300 2 300\n",
"4000 4000 1\n",
"4000 4000 100\n",
"4 2 3\n",
"3 300 300\n",
"4000 100 4000\n",
"3 300 1\n",
"300 300 1\n",
"4000 1000 3000\n",
"3 2 4000\n",
"4 3 2\n",
"3 2 300\n",
"4000 3998 ... | 2CODEFORCES |
306_C. White, Black and White Again_694 | Polycarpus is sure that his life fits the description: "first there is a white stripe, then a black one, then a white one again". So, Polycarpus is sure that this rule is going to fulfill during the next n days. Polycarpus knows that he is in for w good events and b not-so-good events. At least one event is going to ta... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper ... | 4JAVA | {
"input": [
"3 2 1\n",
"3 2 2\n",
"4 2 2\n",
"3 3 1\n",
"300 2 300\n",
"4000 4000 1\n",
"4000 4000 100\n",
"4 2 3\n",
"3 300 300\n",
"4000 100 4000\n",
"3 300 1\n",
"300 300 1\n",
"4000 1000 3000\n",
"3 2 4000\n",
"4 3 2\n",
"3 2 300\n",
"4000 3998 ... | 2CODEFORCES |
331_D2. Escaping on Beaveractor_695 | Don't put up with what you're sick of! The Smart Beaver decided to escape from the campus of Beaver Science Academy (BSA). BSA is a b × b square on a plane. Each point x, y (0 ≤ x, y ≤ b) belongs to BSA. To make the path quick and funny, the Beaver constructed a Beaveractor, an effective and comfortable types of transp... | #include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const double eps = 1e-9;
const double INF = inf;
const double EPS = eps;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int N[2][1100 * 1100 * 4];
long long T[110000];
int V[110000];
int main() {
int x, y, n, q, a, b, c, d, bb, it;
int i, j, ... | 2C++ | {
"input": [
"3 3\n0 0 0 1\n0 2 2 2\n3 3 2 3\n12\n0 0 L 0\n0 0 L 1\n0 0 L 2\n0 0 L 3\n0 0 L 4\n0 0 L 5\n0 0 L 6\n2 0 U 2\n2 0 U 3\n3 0 U 5\n1 3 D 2\n1 3 R 2\n",
"3 8\n2 4 4 4\n7 2 5 2\n6 5 6 3\n20\n3 2 U 1000000\n3 2 U 1\n3 2 U 2\n3 2 U 3\n3 2 U 4\n3 2 U 5\n3 2 U 6\n3 2 U 7\n3 2 U 8\n3 2 U 9\n3 2 U 10\n3 2 U ... | 2CODEFORCES |
331_D2. Escaping on Beaveractor_696 | Don't put up with what you're sick of! The Smart Beaver decided to escape from the campus of Beaver Science Academy (BSA). BSA is a b × b square on a plane. Each point x, y (0 ≤ x, y ≤ b) belongs to BSA. To make the path quick and funny, the Beaver constructed a Beaveractor, an effective and comfortable types of transp... | import java.io.*;
import java.util.*;
public class D1 {
BufferedReader br;
PrintWriter out;
StringTokenizer st;
boolean eof;
int b;
int decode(int x, int y) {
return x * b + y;
}
static final String DIRS = "ULDR";
static final int[] DX = { 0, -1, 0, 1 };
static final int[] DY = { 1, 0, -1, 0 };
stati... | 4JAVA | {
"input": [
"3 3\n0 0 0 1\n0 2 2 2\n3 3 2 3\n12\n0 0 L 0\n0 0 L 1\n0 0 L 2\n0 0 L 3\n0 0 L 4\n0 0 L 5\n0 0 L 6\n2 0 U 2\n2 0 U 3\n3 0 U 5\n1 3 D 2\n1 3 R 2\n",
"3 8\n2 4 4 4\n7 2 5 2\n6 5 6 3\n20\n3 2 U 1000000\n3 2 U 1\n3 2 U 2\n3 2 U 3\n3 2 U 4\n3 2 U 5\n3 2 U 6\n3 2 U 7\n3 2 U 8\n3 2 U 9\n3 2 U 10\n3 2 U ... | 2CODEFORCES |
354_B. Game with Strings_697 | Given an n × n table T consisting of lowercase English letters. We'll consider some string s good if the table contains a correct path corresponding to the given string. In other words, good strings are all strings we can obtain by moving from the left upper cell of the table only to the right and down. Here's the form... | #include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
const int N = 1e5 + 10;... | 2C++ | {
"input": [
"2\nxa\nay\n",
"2\nab\ncd\n",
"3\naab\nbcb\nbac\n",
"5\ncbbbb\nbcbbb\naacbb\naaacb\naaaac\n",
"20\nbifcabiabgfibfccdbgd\ncffaheagahcbacafbgeb\njagcacbadagcedbigaja\naaadicdbjdiibhihbgeb\nhiijbehdeaafdabiigha\nfiifibibgddjfbdafbif\nhdbgbcfjdgibadabfgaf\ngggdaijhfgbaidfajdaj\nfajhebaaai... | 2CODEFORCES |
354_B. Game with Strings_698 | Given an n × n table T consisting of lowercase English letters. We'll consider some string s good if the table contains a correct path corresponding to the given string. In other words, good strings are all strings we can obtain by moving from the left upper cell of the table only to the right and down. Here's the form... | import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.io.PrintWriter;
import java.io.InputStream;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in... | 4JAVA | {
"input": [
"2\nxa\nay\n",
"2\nab\ncd\n",
"3\naab\nbcb\nbac\n",
"5\ncbbbb\nbcbbb\naacbb\naaacb\naaaac\n",
"20\nbifcabiabgfibfccdbgd\ncffaheagahcbacafbgeb\njagcacbadagcedbigaja\naaadicdbjdiibhihbgeb\nhiijbehdeaafdabiigha\nfiifibibgddjfbdafbif\nhdbgbcfjdgibadabfgaf\ngggdaijhfgbaidfajdaj\nfajhebaaai... | 2CODEFORCES |
378_C. Maze_699 | Pavel loves grid mazes. A grid maze is an n × m rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.
Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any oth... | #!/usr/bin/env python
def read():
r, c, k = map(int, raw_input().split())
ret = []
for i in range(r):
ret.append(list(raw_input()))
return ret, k
def work((b, k)):
Q = []
cntEmpty = sum([b[i].count('.') for i in range(len(b))])
toVisit = cntEmpty - k
for i in range(len(... | 1Python2 | {
"input": [
"3 4 2\n#..#\n..#.\n#...\n",
"5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#\n",
"19 20 196\n###.....##.#..#..##.\n####............##..\n###....#..#.#....#.#\n##....###......#...#\n.####...#.....#.##..\n.###......#...#.#.#.\n...##.#...#..#..#...\n.....#.....#..#....#\n.#.....##..#........\n.##....#........ | 2CODEFORCES |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.