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
348_E. Pilgrims_2200
A long time ago there was a land called Dudeland. Dudeland consisted of n towns connected with n - 1 bidirectonal roads. The towns are indexed from 1 to n and one can reach any city from any other city if he moves along the roads of the country. There are m monasteries in Dudeland located in m different towns. In each ...
#include <bits/stdc++.h> using namespace std; int read() { char ch = getchar(); int x = 0; while (ch < '0' || ch > '9') ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x; } const int maxn = 2e5 + 5, inf = 1e9; struct Data { int next, to, w; }; struct LinkTable { ...
2C++
{ "input": [ "8 5\n7 2 5 4 8\n1 2 1\n2 3 2\n1 4 1\n4 5 2\n1 6 1\n6 7 8\n6 8 10\n", "7 3\n1 4 7\n1 2 2\n2 3 3\n3 4 8\n2 5 1\n1 6 4\n6 7 5\n", "10 2\n1 5\n5 3 2\n8 4 8\n7 6 9\n7 10 1\n10 1 4\n9 5 1\n5 8 2\n7 2 9\n6 5 6\n", "10 5\n4 8 7 5 1\n5 1 1\n2 7 1\n4 3 1\n10 9 1\n10 1 1\n1 8 1\n10 7 1\n10 3 1\n7 6...
2CODEFORCES
348_E. Pilgrims_2201
A long time ago there was a land called Dudeland. Dudeland consisted of n towns connected with n - 1 bidirectonal roads. The towns are indexed from 1 to n and one can reach any city from any other city if he moves along the roads of the country. There are m monasteries in Dudeland located in m different towns. In each ...
//https://github.com/EgorKulikov/yaal/tree/master/lib/main/net/egork import java.util.*; import java.io.*; public class E{ static PrintWriter out; static InputReader in; public static void main(String args[]){ out = new PrintWriter(System.out); in = new InputReader(); new E(...
4JAVA
{ "input": [ "8 5\n7 2 5 4 8\n1 2 1\n2 3 2\n1 4 1\n4 5 2\n1 6 1\n6 7 8\n6 8 10\n", "7 3\n1 4 7\n1 2 2\n2 3 3\n3 4 8\n2 5 1\n1 6 4\n6 7 5\n", "10 2\n1 5\n5 3 2\n8 4 8\n7 6 9\n7 10 1\n10 1 4\n9 5 1\n5 8 2\n7 2 9\n6 5 6\n", "10 5\n4 8 7 5 1\n5 1 1\n2 7 1\n4 3 1\n10 9 1\n10 1 1\n1 8 1\n10 7 1\n10 3 1\n7 6...
2CODEFORCES
372_A. Counting Kangaroos is Fun_2202
There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held. Each kangaroo can hold at most one kangaroo, and the kangaroo who is ...
n = int(raw_input()) t = sorted(map(int, [raw_input() for i in xrange(n)])) t.reverse() k = n // 2 a, b = [2 * i for i in t[- k: ]], t[: k] i = j = 0 while i < k: if a[i] <= b[j]: j += 1 i += 1 print n - j
1Python2
{ "input": [ "8\n2\n5\n7\n6\n9\n8\n4\n2\n", "8\n9\n1\n6\n2\n6\n5\n8\n3\n", "1\n1\n", "12\n55\n75\n1\n98\n63\n64\n9\n39\n82\n18\n47\n9\n", "7\n1\n2\n4\n8\n16\n32\n64\n", "4\n1\n1\n1\n2\n", "5\n1\n2\n4\n8\n16\n", "100\n678\n771\n96\n282\n135\n749\n168\n668\n17\n658\n979\n446\n998\n331\n6...
2CODEFORCES
372_A. Counting Kangaroos is Fun_2203
There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held. Each kangaroo can hold at most one kangaroo, and the kangaroo who is ...
#include <bits/stdc++.h> using namespace std; vector<int> v; int main() { int n, c = 0; cin >> n; int x; for (int i = 0; i < n; i++) { cin >> x; v.push_back(x); } sort(v.begin(), v.end()); int r = n - 1; for (int i = n / 2 - 1; i >= 0; i--) { if (2 * v[i] <= v[r]) { c++; r--; ...
2C++
{ "input": [ "8\n2\n5\n7\n6\n9\n8\n4\n2\n", "8\n9\n1\n6\n2\n6\n5\n8\n3\n", "1\n1\n", "12\n55\n75\n1\n98\n63\n64\n9\n39\n82\n18\n47\n9\n", "7\n1\n2\n4\n8\n16\n32\n64\n", "4\n1\n1\n1\n2\n", "5\n1\n2\n4\n8\n16\n", "100\n678\n771\n96\n282\n135\n749\n168\n668\n17\n658\n979\n446\n998\n331\n6...
2CODEFORCES
372_A. Counting Kangaroos is Fun_2204
There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held. Each kangaroo can hold at most one kangaroo, and the kangaroo who is ...
# Made By Mostafa_Khaled bot = True import math,sys n=int(input());k=n a=sorted([int(x) for x in sys.stdin.read().strip().split('\n')]) p1=math.floor((n-1)/2);p2=n-1 while p1>=0: if 2*a[p1]<=a[p2]: k-=1;a[p2]=0;p2-=1 p1-=1 k=max(math.ceil(n/2),k) sys.stdout.write(str(k)) # Made By Mostafa_Kh...
3Python3
{ "input": [ "8\n2\n5\n7\n6\n9\n8\n4\n2\n", "8\n9\n1\n6\n2\n6\n5\n8\n3\n", "1\n1\n", "12\n55\n75\n1\n98\n63\n64\n9\n39\n82\n18\n47\n9\n", "7\n1\n2\n4\n8\n16\n32\n64\n", "4\n1\n1\n1\n2\n", "5\n1\n2\n4\n8\n16\n", "100\n678\n771\n96\n282\n135\n749\n168\n668\n17\n658\n979\n446\n998\n331\n6...
2CODEFORCES
372_A. Counting Kangaroos is Fun_2205
There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held. Each kangaroo can hold at most one kangaroo, and the kangaroo who is ...
import java.io.*; import java.util.*; import java.awt.*; import java.math.*; public class Main { static BufferedReader br = new BufferedReader( new InputStreamReader(System.in) ); static StringTokenizer st = new StringTokenizer(""); static String next() throws Exception { while ( !st.hasMoreTokens() ) { String...
4JAVA
{ "input": [ "8\n2\n5\n7\n6\n9\n8\n4\n2\n", "8\n9\n1\n6\n2\n6\n5\n8\n3\n", "1\n1\n", "12\n55\n75\n1\n98\n63\n64\n9\n39\n82\n18\n47\n9\n", "7\n1\n2\n4\n8\n16\n32\n64\n", "4\n1\n1\n1\n2\n", "5\n1\n2\n4\n8\n16\n", "100\n678\n771\n96\n282\n135\n749\n168\n668\n17\n658\n979\n446\n998\n331\n6...
2CODEFORCES
393_C. Blocked Points_2206
Imagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points A and B on the plane are 4-connected if and only if: * the Euclidean distance between A and B is one unit and neither A nor B is blocked; * or there is some inte...
import math n=int(input()) if n==0: print 1 else: k=4*(int(n*math.sqrt(2)+1e-9)) print k
1Python2
{ "input": [ "2\n", "3\n", "1\n", "11\n", "0\n", "17\n", "18855321\n", "34609610\n", "25\n", "9\n", "40000000\n", "17464436\n", "38450759\n", "395938\n", "39099999\n", "8\n", "4\n", "30426905\n", "7\n", "17082858\n", "46341\n", "4...
2CODEFORCES
393_C. Blocked Points_2207
Imagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points A and B on the plane are 4-connected if and only if: * the Euclidean distance between A and B is one unit and neither A nor B is blocked; * or there is some inte...
#include <bits/stdc++.h> using namespace std; int main() { long long n, ans = 0; cin >> n; double R = n; long long tmp = n, k; for (long long i = 1; i <= n; i++) { double r = i; k = (long long)sqrt(R * R - r * r); ans += (tmp == k ? 1 : tmp - k); tmp = k; } if (n == 0) cout << 1 << end...
2C++
{ "input": [ "2\n", "3\n", "1\n", "11\n", "0\n", "17\n", "18855321\n", "34609610\n", "25\n", "9\n", "40000000\n", "17464436\n", "38450759\n", "395938\n", "39099999\n", "8\n", "4\n", "30426905\n", "7\n", "17082858\n", "46341\n", "4...
2CODEFORCES
393_C. Blocked Points_2208
Imagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points A and B on the plane are 4-connected if and only if: * the Euclidean distance between A and B is one unit and neither A nor B is blocked; * or there is some inte...
from math import sqrt n = int(input()) if n == 0: print(1) else: print(4 * int(n * sqrt(2)))
3Python3
{ "input": [ "2\n", "3\n", "1\n", "11\n", "0\n", "17\n", "18855321\n", "34609610\n", "25\n", "9\n", "40000000\n", "17464436\n", "38450759\n", "395938\n", "39099999\n", "8\n", "4\n", "30426905\n", "7\n", "17082858\n", "46341\n", "4...
2CODEFORCES
393_C. Blocked Points_2209
Imagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points A and B on the plane are 4-connected if and only if: * the Euclidean distance between A and B is one unit and neither A nor B is blocked; * or there is some inte...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class A { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter ou...
4JAVA
{ "input": [ "2\n", "3\n", "1\n", "11\n", "0\n", "17\n", "18855321\n", "34609610\n", "25\n", "9\n", "40000000\n", "17464436\n", "38450759\n", "395938\n", "39099999\n", "8\n", "4\n", "30426905\n", "7\n", "17082858\n", "46341\n", "4...
2CODEFORCES
416_D. Population Size_2210
Polycarpus develops an interesting theory about the interrelation of arithmetic progressions with just everything in the world. His current idea is that the population of the capital of Berland changes over time like an arithmetic progression. Well, or like multiple arithmetic progressions. Polycarpus believes that if...
class better_array: def __init__(self): self.arr = [] self.diff = None self.first = None self.knowna = None self.knownb = None def can_add(self, n): if n == -1: if self.diff == None: return True return self.first + self.diff...
1Python2
{ "input": [ "9\n-1 6 -1 2 -1 4 7 -1 2\n", "5\n-1 -1 -1 -1 -1\n", "7\n-1 -1 4 5 1 2 3\n", "9\n8 6 4 2 1 4 7 10 2\n", "3\n-1 1 -1\n", "4\n45 -1 41 -1\n", "1\n-1\n", "5\n40 -1 44 46 48\n", "6\n43 40 37 34 -1 -1\n", "7\n-1 2 4 -1 4 1 5\n", "19\n23 26 -1 -1 35 38 41 -1 -1 -1 53...
2CODEFORCES
416_D. Population Size_2211
Polycarpus develops an interesting theory about the interrelation of arithmetic progressions with just everything in the world. His current idea is that the population of the capital of Berland changes over time like an arithmetic progression. Well, or like multiple arithmetic progressions. Polycarpus believes that if...
#include <bits/stdc++.h> using namespace std; int n, m, ans; long long a[200005], d; int main() { cin >> n; int i, j; for (i = 1; i <= n; i++) cin >> a[i]; int k = 1; while (k <= n) { ans++; for (i = k; a[i] == -1; i++) ; for (j = i + 1; a[j] == -1; j++) ; if (j > n) break; d =...
2C++
{ "input": [ "9\n-1 6 -1 2 -1 4 7 -1 2\n", "5\n-1 -1 -1 -1 -1\n", "7\n-1 -1 4 5 1 2 3\n", "9\n8 6 4 2 1 4 7 10 2\n", "3\n-1 1 -1\n", "4\n45 -1 41 -1\n", "1\n-1\n", "5\n40 -1 44 46 48\n", "6\n43 40 37 34 -1 -1\n", "7\n-1 2 4 -1 4 1 5\n", "19\n23 26 -1 -1 35 38 41 -1 -1 -1 53...
2CODEFORCES
416_D. Population Size_2212
Polycarpus develops an interesting theory about the interrelation of arithmetic progressions with just everything in the world. His current idea is that the population of the capital of Berland changes over time like an arithmetic progression. Well, or like multiple arithmetic progressions. Polycarpus believes that if...
n = int(input()) a = list(map(int, input().split())) i = 0 ans = 0 while i < n: ans += 1 i1 = i while i1 < n and a[i1] == -1: i1 += 1 if i1 == n: break i2 = i1 + 1 while i2 < n and a[i2] == -1: i2 += 1 if i2 == n: break dist = i2 - i1 step = (a[i2] - a...
3Python3
{ "input": [ "9\n-1 6 -1 2 -1 4 7 -1 2\n", "5\n-1 -1 -1 -1 -1\n", "7\n-1 -1 4 5 1 2 3\n", "9\n8 6 4 2 1 4 7 10 2\n", "3\n-1 1 -1\n", "4\n45 -1 41 -1\n", "1\n-1\n", "5\n40 -1 44 46 48\n", "6\n43 40 37 34 -1 -1\n", "7\n-1 2 4 -1 4 1 5\n", "19\n23 26 -1 -1 35 38 41 -1 -1 -1 53...
2CODEFORCES
416_D. Population Size_2213
Polycarpus develops an interesting theory about the interrelation of arithmetic progressions with just everything in the world. His current idea is that the population of the capital of Berland changes over time like an arithmetic progression. Well, or like multiple arithmetic progressions. Polycarpus believes that if...
import java.util.*; import java.awt.Point; import java.io.*; import java.math.BigInteger; public class DNotGood { FastScanner in; PrintWriter out; public void solve() throws IOException { int n = in.nextInt(); int mas[] = in.nextIntArray(n); int cou...
4JAVA
{ "input": [ "9\n-1 6 -1 2 -1 4 7 -1 2\n", "5\n-1 -1 -1 -1 -1\n", "7\n-1 -1 4 5 1 2 3\n", "9\n8 6 4 2 1 4 7 10 2\n", "3\n-1 1 -1\n", "4\n45 -1 41 -1\n", "1\n-1\n", "5\n40 -1 44 46 48\n", "6\n43 40 37 34 -1 -1\n", "7\n-1 2 4 -1 4 1 5\n", "19\n23 26 -1 -1 35 38 41 -1 -1 -1 53...
2CODEFORCES
443_B. Kolya and Tandem Repeat_2214
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string. Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be? See notes for definition of a tandem repeat. I...
# -*- coding: utf-8 -*- """ Created on Sun Jul 6 21:30:46 2014 @author: d555_ """ db = False s = raw_input() N = int(raw_input()) cN = (len(s) + N)//2 s = s + "*"*N if db: print s, cN maxLen = N for n in range(cN, 0, -1): if db: print "\tn> ", n for i in range(len(s)): if db: print "i>", i if db: print "*&&...
1Python2
{ "input": [ "aaabbbb\n2\n", "aaba\n2\n", "abracadabra\n10\n", "jtifziirovbklaioslunwvtdavraandnzcwqbealbvqonoxufqrsewwrzvkrecrfqhdduwmcdcdhdtvpyshfhgdwdkmglskidhzayvouwhumzhcphocqyfcdddhzayvouwhumzhcphocqyfcddayfakoxofjgusuonehbxbokjsdlktqrcdurogxltsysyjbiagrvhky\n32\n", "kbxuunznjtxutlauuuipifgg...
2CODEFORCES
443_B. Kolya and Tandem Repeat_2215
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string. Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be? See notes for definition of a tandem repeat. I...
#include <bits/stdc++.h> using namespace std; inline int input() { int ret = 0; bool isN = 0; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') isN = 1; c = getchar(); } while (c >= '0' && c <= '9') { ret = ret * 10 + c - '0'; c = getchar(); } return isN ? -ret : ret; } inli...
2C++
{ "input": [ "aaabbbb\n2\n", "aaba\n2\n", "abracadabra\n10\n", "jtifziirovbklaioslunwvtdavraandnzcwqbealbvqonoxufqrsewwrzvkrecrfqhdduwmcdcdhdtvpyshfhgdwdkmglskidhzayvouwhumzhcphocqyfcdddhzayvouwhumzhcphocqyfcddayfakoxofjgusuonehbxbokjsdlktqrcdurogxltsysyjbiagrvhky\n32\n", "kbxuunznjtxutlauuuipifgg...
2CODEFORCES
443_B. Kolya and Tandem Repeat_2216
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string. Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be? See notes for definition of a tandem repeat. I...
s=input() k=int(input()) n=len(s) if k>=n: print(int(2*((n+k)//2))) raise SystemExit ll=0 for i in range(k+1): for l in range((n+i)//2,i-1,-1): if s[n-(l-i):n]==s[n+i-2*l:n-l]: if l>ll: ll=l break j=ll while 2*j<=n: j=j+1 for i in range(n-2*j): if s[i:i+j]==s[...
3Python3
{ "input": [ "aaabbbb\n2\n", "aaba\n2\n", "abracadabra\n10\n", "jtifziirovbklaioslunwvtdavraandnzcwqbealbvqonoxufqrsewwrzvkrecrfqhdduwmcdcdhdtvpyshfhgdwdkmglskidhzayvouwhumzhcphocqyfcdddhzayvouwhumzhcphocqyfcddayfakoxofjgusuonehbxbokjsdlktqrcdurogxltsysyjbiagrvhky\n32\n", "kbxuunznjtxutlauuuipifgg...
2CODEFORCES
443_B. Kolya and Tandem Repeat_2217
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string. Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be? See notes for definition of a tandem repeat. I...
import java.util.Scanner; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author Ahmad */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application lo...
4JAVA
{ "input": [ "aaabbbb\n2\n", "aaba\n2\n", "abracadabra\n10\n", "jtifziirovbklaioslunwvtdavraandnzcwqbealbvqonoxufqrsewwrzvkrecrfqhdduwmcdcdhdtvpyshfhgdwdkmglskidhzayvouwhumzhcphocqyfcdddhzayvouwhumzhcphocqyfcddayfakoxofjgusuonehbxbokjsdlktqrcdurogxltsysyjbiagrvhky\n32\n", "kbxuunznjtxutlauuuipifgg...
2CODEFORCES
465_C. No to Palindromes!_2218
Paul hates palindromes. He assumes that string s is tolerable if each its character is one of the first p letters of the English alphabet and s doesn't contain any palindrome contiguous substring of length 2 or more. Paul has found a tolerable string s of length n. Help him find the lexicographically next tolerable st...
import sys #sys.stdin = open('in', 'r') n, p = map(int, raw_input().split()) s = list(raw_input()) if p == 1: print 'NO' exit() def ok(a, pos, c): return sum([a[i] == c for i in xrange(max(0, pos - 2), pos)]) == 0 end = ord('a') + p - 1 for i in xrange(n - 1, -1, -1): cnt = 0 for j in xrange(ord(s[i]) + ...
1Python2
{ "input": [ "3 4\ncba\n", "3 3\ncba\n", "4 4\nabcd\n", "302 4\nabdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdc...
2CODEFORCES
465_C. No to Palindromes!_2219
Paul hates palindromes. He assumes that string s is tolerable if each its character is one of the first p letters of the English alphabet and s doesn't contain any palindrome contiguous substring of length 2 or more. Paul has found a tolerable string s of length n. Help him find the lexicographically next tolerable st...
#include <bits/stdc++.h> using namespace std; int p, n; bool build(string& in, int i) { bool gg = 0; for (char v = in[i] + 1; v <= p; ++v) { if ((i - 1 < 0 || in[i - 1] != v) && (i - 2 < 0 || in[i - 2] != v)) { gg = true; in[i] = v; break; } } if (gg) { bool can = true; for (in...
2C++
{ "input": [ "3 4\ncba\n", "3 3\ncba\n", "4 4\nabcd\n", "302 4\nabdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdc...
2CODEFORCES
465_C. No to Palindromes!_2220
Paul hates palindromes. He assumes that string s is tolerable if each its character is one of the first p letters of the English alphabet and s doesn't contain any palindrome contiguous substring of length 2 or more. Paul has found a tolerable string s of length n. Help him find the lexicographically next tolerable st...
import sys def main(): # fin = open("input.txt", "r") fin = sys.stdin fout = sys.stdout L = list("abcdefghijklmnopqrstuvwxyz") n, p = map(int, fin.readline().split()) A = list(fin.readline()) for i in range(n - 1, 1, -1): pr = ord(A[i - 1]) - ord("a") pp = ord(A[i - 2]) -...
3Python3
{ "input": [ "3 4\ncba\n", "3 3\ncba\n", "4 4\nabcd\n", "302 4\nabdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdc...
2CODEFORCES
465_C. No to Palindromes!_2221
Paul hates palindromes. He assumes that string s is tolerable if each its character is one of the first p letters of the English alphabet and s doesn't contain any palindrome contiguous substring of length 2 or more. Paul has found a tolerable string s of length n. Help him find the lexicographically next tolerable st...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class C265 { public static void main(String args[])throws IOException { BufferedReader obj = new BufferedReader(new InputStreamReader(System.in)); String line = obj.readLine(); String st...
4JAVA
{ "input": [ "3 4\ncba\n", "3 3\ncba\n", "4 4\nabcd\n", "302 4\nabdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdc...
2CODEFORCES
489_B. BerSU Ball_2222
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair m...
n=int(raw_input()) boys=list(map(int, raw_input().split())) boyskillz={} for i in boys: if i in boyskillz.keys(): boyskillz[i]+=1 else: boyskillz[i]=1 m=int(raw_input()) girls=list(map(int, raw_input().split())) girls.sort() pairs=0 for i in girls: if i-1 in boyskillz.keys(): pairs+=1 boyskillz[i-1]-=1 if ...
1Python2
{ "input": [ "4\n1 2 3 4\n4\n10 11 12 13\n", "4\n1 4 6 2\n5\n5 1 5 7 9\n", "5\n1 1 1 1 1\n3\n1 2 3\n", "1\n4\n3\n4 4 4\n", "3\n7 7 7\n4\n2 7 2 4\n", "3\n5 4 5\n2\n2 1\n", "100\n9 90 66 62 60 9 10 97 47 73 26 81 97 60 80 84 19 4 25 77 19 17 91 12 1 27 15 54 18 45 71 79 96 90 51 62 9 13 92 3...
2CODEFORCES
489_B. BerSU Ball_2223
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair m...
#include <bits/stdc++.h> using namespace std; int b[102]; int g[102]; int main() { int n, m; cin >> n; for (int i = 0; i < n; i++) { cin >> b[i]; } cin >> m; for (int i = 0; i < m; i++) { cin >> g[i]; } sort(b, b + n); sort(g, g + m); int itb, itg; itb = itg = 0; int cnt = 0; while (it...
2C++
{ "input": [ "4\n1 2 3 4\n4\n10 11 12 13\n", "4\n1 4 6 2\n5\n5 1 5 7 9\n", "5\n1 1 1 1 1\n3\n1 2 3\n", "1\n4\n3\n4 4 4\n", "3\n7 7 7\n4\n2 7 2 4\n", "3\n5 4 5\n2\n2 1\n", "100\n9 90 66 62 60 9 10 97 47 73 26 81 97 60 80 84 19 4 25 77 19 17 91 12 1 27 15 54 18 45 71 79 96 90 51 62 9 13 92 3...
2CODEFORCES
489_B. BerSU Ball_2224
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair m...
n = int(input()) b = list(map(int, input().split())) m = int(input()) g = list(map(int, input().split())) b.sort() g.sort() res = 0 i = 0 j = 0 while i < n and j < m: if abs(b[i]-g[j]) <= 1: res += 1 i += 1 j += 1 elif b[i] > g[j]: j += 1 else: i += 1 print(res)...
3Python3
{ "input": [ "4\n1 2 3 4\n4\n10 11 12 13\n", "4\n1 4 6 2\n5\n5 1 5 7 9\n", "5\n1 1 1 1 1\n3\n1 2 3\n", "1\n4\n3\n4 4 4\n", "3\n7 7 7\n4\n2 7 2 4\n", "3\n5 4 5\n2\n2 1\n", "100\n9 90 66 62 60 9 10 97 47 73 26 81 97 60 80 84 19 4 25 77 19 17 91 12 1 27 15 54 18 45 71 79 96 90 51 62 9 13 92 3...
2CODEFORCES
489_B. BerSU Ball_2225
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair m...
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.PriorityQueue; import java.util.StringTokenizer; public class CF_489_B_BERSU_BALL { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(Sy...
4JAVA
{ "input": [ "4\n1 2 3 4\n4\n10 11 12 13\n", "4\n1 4 6 2\n5\n5 1 5 7 9\n", "5\n1 1 1 1 1\n3\n1 2 3\n", "1\n4\n3\n4 4 4\n", "3\n7 7 7\n4\n2 7 2 4\n", "3\n5 4 5\n2\n2 1\n", "100\n9 90 66 62 60 9 10 97 47 73 26 81 97 60 80 84 19 4 25 77 19 17 91 12 1 27 15 54 18 45 71 79 96 90 51 62 9 13 92 3...
2CODEFORCES
513_A. Game_2226
Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly n1 balls and second player's box contains exactly n2 balls. In one move first player can take from 1 to k1 balls from his box and throw them away. Similarly, the second player can take from 1 to k2 balls f...
a,b,c,d=map(int,raw_input().split()) if a>b: print "First" elif a<b: print "Second" elif a==b: print "Second"
1Python2
{ "input": [ "2 1 1 1\n", "2 2 1 2\n", "50 50 50 50\n", "49 49 4 1\n", "48 50 12 11\n", "5 7 1 10\n", "1 50 50 50\n", "5 7 1 4\n", "32 4 17 3\n", "1 50 1 50\n", "50 1 1 1\n", "32 31 10 9\n", "5 7 4 1\n", "49 49 3 3\n", "50 49 1 2\n", "50 48 3 1\n", "...
2CODEFORCES
513_A. Game_2227
Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly n1 balls and second player's box contains exactly n2 balls. In one move first player can take from 1 to k1 balls from his box and throw them away. Similarly, the second player can take from 1 to k2 balls f...
#include <bits/stdc++.h> using namespace std; int main() { int n1, n2, k1, k2; cin >> n1 >> n2 >> k1 >> k2; if (n1 <= n2) cout << "Second"; else cout << "First"; return 0; }
2C++
{ "input": [ "2 1 1 1\n", "2 2 1 2\n", "50 50 50 50\n", "49 49 4 1\n", "48 50 12 11\n", "5 7 1 10\n", "1 50 50 50\n", "5 7 1 4\n", "32 4 17 3\n", "1 50 1 50\n", "50 1 1 1\n", "32 31 10 9\n", "5 7 4 1\n", "49 49 3 3\n", "50 49 1 2\n", "50 48 3 1\n", "...
2CODEFORCES
513_A. Game_2228
Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly n1 balls and second player's box contains exactly n2 balls. In one move first player can take from 1 to k1 balls from his box and throw them away. Similarly, the second player can take from 1 to k2 balls f...
n1 , n2 , k1 , k2 = map(int , (input().split(" "))) if n1 <= n2: print('Second') else: print('First')
3Python3
{ "input": [ "2 1 1 1\n", "2 2 1 2\n", "50 50 50 50\n", "49 49 4 1\n", "48 50 12 11\n", "5 7 1 10\n", "1 50 50 50\n", "5 7 1 4\n", "32 4 17 3\n", "1 50 1 50\n", "50 1 1 1\n", "32 31 10 9\n", "5 7 4 1\n", "49 49 3 3\n", "50 49 1 2\n", "50 48 3 1\n", "...
2CODEFORCES
513_A. Game_2229
Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly n1 balls and second player's box contains exactly n2 balls. In one move first player can take from 1 to k1 balls from his box and throw them away. Similarly, the second player can take from 1 to k2 balls f...
import java.util.*; import java.lang.reflect.Array; import java.math.*; import java.io.*; import java.awt.*; import java.awt.geom.Line2D; import javax.naming.BinaryRefAddr; public class Main{ static FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in))); static PrintWriter out = ...
4JAVA
{ "input": [ "2 1 1 1\n", "2 2 1 2\n", "50 50 50 50\n", "49 49 4 1\n", "48 50 12 11\n", "5 7 1 10\n", "1 50 50 50\n", "5 7 1 4\n", "32 4 17 3\n", "1 50 1 50\n", "50 1 1 1\n", "32 31 10 9\n", "5 7 4 1\n", "49 49 3 3\n", "50 49 1 2\n", "50 48 3 1\n", "...
2CODEFORCES
538_B. Quasi Binary_2230
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. Input The first line contains a single...
import sys from collections import defaultdict, Counter from math import sin, cos, asin, acos, tan, atan, pi sys.setrecursionlimit(10 ** 6) def pyes_no(condition, yes = "YES", no = "NO", none = "-1") : if condition == None: print (none) elif condition : print (yes) else : print (no) def plist(a, s ...
1Python2
{ "input": [ "32\n", "9\n", "111111\n", "100009\n", "10011\n", "1000000\n", "8\n", "10201\n", "102030\n", "908172\n", "123456\n", "415\n", "900000\n", "21\n", "909090\n", "314159\n", "999999\n", "909823\n", "987654\n", "1453\n", "1435...
2CODEFORCES
538_B. Quasi Binary_2231
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. Input The first line contains a single...
#include <bits/stdc++.h> using namespace std; const int maxN = 100 * 1000 + 100; int a, b, c, t[maxN]; string s; int main() { cin >> s; for (int i = 0; i < s.size(); i++) t[i] = s[i] - '0'; for (int i = 0; i < s.size(); i++) a = max(a, (s[i] - '0')); cout << a << endl; for (int i = 0; i < s.size(); i++) w...
2C++
{ "input": [ "32\n", "9\n", "111111\n", "100009\n", "10011\n", "1000000\n", "8\n", "10201\n", "102030\n", "908172\n", "123456\n", "415\n", "900000\n", "21\n", "909090\n", "314159\n", "999999\n", "909823\n", "987654\n", "1453\n", "1435...
2CODEFORCES
538_B. Quasi Binary_2232
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. Input The first line contains a single...
import math a = input() d = int(max(a)) print(d) dec = math.ceil(math.log10(int(a))) c = [0]*d if int(a) != 10**dec: for i in a: for j in range(int(i)): c[j] = c[j]+10**(dec-1) dec = dec - 1 d='' for i in c: d += str(i)+' ' if int(a) == 10**dec: print(a) else: print(d.strip()...
3Python3
{ "input": [ "32\n", "9\n", "111111\n", "100009\n", "10011\n", "1000000\n", "8\n", "10201\n", "102030\n", "908172\n", "123456\n", "415\n", "900000\n", "21\n", "909090\n", "314159\n", "999999\n", "909823\n", "987654\n", "1453\n", "1435...
2CODEFORCES
538_B. Quasi Binary_2233
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. Input The first line contains a single...
import java.util.*; public class GFG { public static void main (String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); ArrayList<Integer> arr=new ArrayList<Integer>(); while (n>0) { int n1=n,a=0,b=1; while(n1>0) { if(n1%10!=0)a+=b; b...
4JAVA
{ "input": [ "32\n", "9\n", "111111\n", "100009\n", "10011\n", "1000000\n", "8\n", "10201\n", "102030\n", "908172\n", "123456\n", "415\n", "900000\n", "21\n", "909090\n", "314159\n", "999999\n", "909823\n", "987654\n", "1453\n", "1435...
2CODEFORCES
566_C. Logistical Questions_2234
Some country consists of n cities, connected by a railroad network. The transport communication of the country is so advanced that the network consists of a minimum required number of (n - 1) bidirectional roads (in the other words, the graph of roads is a tree). The i-th road that directly connects cities ai and bi, h...
#include <bits/stdc++.h> using namespace std; const long long linf = 1e18 + 5; int mod = (int)1e9 + 7; const int logN = 18; const int inf = 1e9 + 9; const int N = 3e5 + 5; int n, m, x, y, z, t, c[N], p, sum[N], h[N]; double G[N]; vector<pair<int, int> > v[N]; vector<pair<double, int> > ans; int prep(int node, int root)...
2C++
{ "input": [ "5\n3 1 2 6 5\n1 2 3\n2 3 1\n4 3 9\n5 3 1\n", "2\n5 5\n1 2 2\n", "3\n1 1 5\n1 3 42\n1 2 42\n", "2\n42 23\n1 2 10\n", "10\n45792697 27183921 4791060 77070594 27286110 66957065 19283638 2944837 26775511 65379701\n5 8 25\n8 10 94\n1 4 14\n9 7 96\n4 2 16\n2 6 58\n2 3 99\n6 8 21\n8 9 87\n"...
2CODEFORCES
566_C. Logistical Questions_2235
Some country consists of n cities, connected by a railroad network. The transport communication of the country is so advanced that the network consists of a minimum required number of (n - 1) bidirectional roads (in the other words, the graph of roads is a tree). The i-th road that directly connects cities ai and bi, h...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.Writer; import java.io.OutputStreamWri...
4JAVA
{ "input": [ "5\n3 1 2 6 5\n1 2 3\n2 3 1\n4 3 9\n5 3 1\n", "2\n5 5\n1 2 2\n", "3\n1 1 5\n1 3 42\n1 2 42\n", "2\n42 23\n1 2 10\n", "10\n45792697 27183921 4791060 77070594 27286110 66957065 19283638 2944837 26775511 65379701\n5 8 25\n8 10 94\n1 4 14\n9 7 96\n4 2 16\n2 6 58\n2 3 99\n6 8 21\n8 9 87\n"...
2CODEFORCES
587_D. Duff in Mafia_2236
Duff is one if the heads of Mafia in her country, Andarz Gu. Andarz Gu has n cities (numbered from 1 to n) connected by m bidirectional roads (numbered by 1 to m). Each road has a destructing time, and a color. i-th road connects cities vi and ui and its color is ci and its destructing time is ti. Mafia wants to dest...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; const int mod = 1e9 + 7; struct edge { int u, v, t, c, id; } e[N]; int n, m; vector<edge> s[N]; bool cmp(edge a, edge b) { return a.c < b.c; } struct TwoSat { static const int N = ::N << 1; int dfn[N], low[N], id[N], st[N], _st, _, cc; vector<...
2C++
{ "input": [ "5 7\n2 1 3 7\n3 1 1 6\n5 4 1 8\n4 5 1 1\n3 2 2 3\n4 5 2 5\n2 3 2 4\n", "3 5\n3 2 1 3\n1 3 1 1\n3 2 1 4\n1 3 2 2\n1 3 2 10\n", "3 5\n2 1 608591421 720962564\n3 2 608591421 641991574\n3 2 718110706 353409763\n2 3 482786015 858341723\n3 2 825397574 357507279\n", "2 1\n2 1 317425595 63615632...
2CODEFORCES
587_D. Duff in Mafia_2237
Duff is one if the heads of Mafia in her country, Andarz Gu. Andarz Gu has n cities (numbered from 1 to n) connected by m bidirectional roads (numbered by 1 to m). Each road has a destructing time, and a color. i-th road connects cities vi and ui and its color is ci and its destructing time is ti. Mafia wants to dest...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.HashMap; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.io.InputStream; /** * Built using CHelper plug-in * Actual sol...
4JAVA
{ "input": [ "5 7\n2 1 3 7\n3 1 1 6\n5 4 1 8\n4 5 1 1\n3 2 2 3\n4 5 2 5\n2 3 2 4\n", "3 5\n3 2 1 3\n1 3 1 1\n3 2 1 4\n1 3 2 2\n1 3 2 10\n", "3 5\n2 1 608591421 720962564\n3 2 608591421 641991574\n3 2 718110706 353409763\n2 3 482786015 858341723\n3 2 825397574 357507279\n", "2 1\n2 1 317425595 63615632...
2CODEFORCES
609_F. Frogs and mosquitoes_2238
There are n frogs sitting on the coordinate axis Ox. For each frog two values xi, ti are known — the position and the initial length of the tongue of the i-th frog (it is guaranteed that all positions xi are different). m mosquitoes one by one are landing to the coordinate axis. For each mosquito two values are known p...
#include <bits/stdc++.h> using namespace std; const int inf = 987654321; const long long int INF = 123456789987654321; int N, M, Xn; struct Frog { int x, t, id; }; vector<Frog> frog; struct Mosq { int p, b; }; vector<Mosq> mosq; struct BIT { vector<pair<long long int, long long int> > tree; void init() { tr...
2C++
{ "input": [ "4 6\n10 2\n15 0\n6 1\n0 1\n110 10\n1 1\n6 0\n15 10\n14 100\n12 2\n", "1 2\n10 2\n20 2\n12 1\n", "2 2\n0 0\n30 9\n6 2\n19 2\n", "1 1\n1000000000 1000000000\n1000000000 1000000000\n", "20 20\n19 1\n67 10\n42 0\n185 1\n68 2\n88 0\n74 3\n138 2\n30 5\n112 8\n1 1\n137 0\n125 0\n106 5\n145 ...
2CODEFORCES
609_F. Frogs and mosquitoes_2239
There are n frogs sitting on the coordinate axis Ox. For each frog two values xi, ti are known — the position and the initial length of the tongue of the i-th frog (it is guaranteed that all positions xi are different). m mosquitoes one by one are landing to the coordinate axis. For each mosquito two values are known p...
import java.io.*; import java.util.*; public class mymy { static long Pinf=(long)Double.POSITIVE_INFINITY; static node4pos[] pos; static class Postree { int size;nodeTreePos[] arr; Postree(int n) { size=2*((int)Math.pow(2,(int)Math.ceil(Math.log(n)/Math.log(2))))-1; arr=new nodeTreePos[size]; } ...
4JAVA
{ "input": [ "4 6\n10 2\n15 0\n6 1\n0 1\n110 10\n1 1\n6 0\n15 10\n14 100\n12 2\n", "1 2\n10 2\n20 2\n12 1\n", "2 2\n0 0\n30 9\n6 2\n19 2\n", "1 1\n1000000000 1000000000\n1000000000 1000000000\n", "20 20\n19 1\n67 10\n42 0\n185 1\n68 2\n88 0\n74 3\n138 2\n30 5\n112 8\n1 1\n137 0\n125 0\n106 5\n145 ...
2CODEFORCES
630_E. A rectangle_2240
Developing tools for creation of locations maps for turn-based fights in a new game, Petya faced the following problem. A field map consists of hexagonal cells. Since locations sizes are going to be big, a game designer wants to have a tool for quick filling of a field part with identical enemy units. This action will...
x,y,xx,yy=map(int,raw_input().split()) dy=abs(yy-y) dx=abs(x-xx) print (dx/2+1)*(dy/2+1)+(dx/2)*dy/2
1Python2
{ "input": [ "1 1 5 5\n", "-157778763 218978790 976692563 591093088\n", "-1 -4 1 4\n", "-999999999 -1000000000 -1 0\n", "1000000000 1000000000 1000000000 1000000000\n", "-2 -3 -2 1\n", "-1000000000 -999999999 1000000000 999999999\n", "0 -1 0 1\n", "-999999999 -999999999 999999999 9...
2CODEFORCES
630_E. A rectangle_2241
Developing tools for creation of locations maps for turn-based fights in a new game, Petya faced the following problem. A field map consists of hexagonal cells. Since locations sizes are going to be big, a game designer wants to have a tool for quick filling of a field part with identical enemy units. This action will...
#include <bits/stdc++.h> using namespace std; inline int IN() { int x = 0, ch = getchar(), f = 1; while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar(); if (ch == '-') { f = -1; ch = getchar(); } while (isdigit(ch)) { x = (x << 1) + (x << 3) + ch - '0'; ch = getchar(); } return...
2C++
{ "input": [ "1 1 5 5\n", "-157778763 218978790 976692563 591093088\n", "-1 -4 1 4\n", "-999999999 -1000000000 -1 0\n", "1000000000 1000000000 1000000000 1000000000\n", "-2 -3 -2 1\n", "-1000000000 -999999999 1000000000 999999999\n", "0 -1 0 1\n", "-999999999 -999999999 999999999 9...
2CODEFORCES
630_E. A rectangle_2242
Developing tools for creation of locations maps for turn-based fights in a new game, Petya faced the following problem. A field map consists of hexagonal cells. Since locations sizes are going to be big, a game designer wants to have a tool for quick filling of a field part with identical enemy units. This action will...
x1,y1,x2,y2 = input().split( ) x1=int(x1) y1=int(y1) x2=int(x2) y2=int(y2) x =int(x2 - x1) y =int(y2 - y1) if x % 2 == 0: if y % 2 == 1: n= int(int( x + 1 ) * int(y + 1) / 2) else: t0=int(x*y)+int(x)+int(y) t1=int(t0)//2 n=int(t1)+1 else: n = int((x + 1) / 2 * ( y + 1 )) print(n)
3Python3
{ "input": [ "1 1 5 5\n", "-157778763 218978790 976692563 591093088\n", "-1 -4 1 4\n", "-999999999 -1000000000 -1 0\n", "1000000000 1000000000 1000000000 1000000000\n", "-2 -3 -2 1\n", "-1000000000 -999999999 1000000000 999999999\n", "0 -1 0 1\n", "-999999999 -999999999 999999999 9...
2CODEFORCES
630_E. A rectangle_2243
Developing tools for creation of locations maps for turn-based fights in a new game, Petya faced the following problem. A field map consists of hexagonal cells. Since locations sizes are going to be big, a game designer wants to have a tool for quick filling of a field part with identical enemy units. This action will...
import java.util.Scanner; public class codeforces { public static void main(String[] args) { TaskE Solver = new TaskE(); Solver.Solve(); } public static class TaskE { public void Solve() { Scanner in = new Scanner(System.in); ...
4JAVA
{ "input": [ "1 1 5 5\n", "-157778763 218978790 976692563 591093088\n", "-1 -4 1 4\n", "-999999999 -1000000000 -1 0\n", "1000000000 1000000000 1000000000 1000000000\n", "-2 -3 -2 1\n", "-1000000000 -999999999 1000000000 999999999\n", "0 -1 0 1\n", "-999999999 -999999999 999999999 9...
2CODEFORCES
658_B. Bear and Displayed Friends_2244
Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti. Spring is starting and the Winter sleep is ...
import sys def siftup(ind): global tree while (ind != 1) and (frendly[tree[ind]] < frendly[tree[ind // 2]]): tree[ind], tree[ind // 2] = tree[ind // 2], tree[ind] ind //= 2 def siftdown(ind): global tree while (ind * 2 + 1 <= len(tree) - 1) and (frendly[tree[ind]] > frendly[tree[...
1Python2
{ "input": [ "6 3 9\n50 20 51 17 99 24\n1 3\n1 4\n1 5\n1 2\n2 4\n2 2\n1 1\n2 4\n2 3\n", "4 2 8\n300 950 500 200\n1 3\n2 4\n2 3\n1 1\n1 2\n2 1\n2 2\n2 3\n", "1 1 1\n1000000000\n2 1\n", "20 2 15\n12698951 55128070 116962690 156763505 188535242 194018601 269939893 428710623 442819431 483000923 516768937 ...
2CODEFORCES
658_B. Bear and Displayed Friends_2245
Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti. Spring is starting and the Winter sleep is ...
#include <bits/stdc++.h> using namespace std; string ITS(long long x) { string s = ""; while (x > 0) { s += (char)(x % 10 + '0'); x /= 10; } string t = ""; for (int i = s.size() - 1; i > -1; i--) t += s[i]; return t; } long long inf = 1e9; long long mod = 1e9 + 7; const long long M = 2e5; pair<long ...
2C++
{ "input": [ "6 3 9\n50 20 51 17 99 24\n1 3\n1 4\n1 5\n1 2\n2 4\n2 2\n1 1\n2 4\n2 3\n", "4 2 8\n300 950 500 200\n1 3\n2 4\n2 3\n1 1\n1 2\n2 1\n2 2\n2 3\n", "1 1 1\n1000000000\n2 1\n", "20 2 15\n12698951 55128070 116962690 156763505 188535242 194018601 269939893 428710623 442819431 483000923 516768937 ...
2CODEFORCES
658_B. Bear and Displayed Friends_2246
Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti. Spring is starting and the Winter sleep is ...
str1 = input().split() n = int(str1[0]) k = int(str1[1]) q = int(str1[2]) friends = list(map(lambda x: int(x), input().split())) online = set() for i in range(q): str1 = input().split() if str1[0] == '2': if int(str1[1]) in online: print("YES") else: print("NO") els...
3Python3
{ "input": [ "6 3 9\n50 20 51 17 99 24\n1 3\n1 4\n1 5\n1 2\n2 4\n2 2\n1 1\n2 4\n2 3\n", "4 2 8\n300 950 500 200\n1 3\n2 4\n2 3\n1 1\n1 2\n2 1\n2 2\n2 3\n", "1 1 1\n1000000000\n2 1\n", "20 2 15\n12698951 55128070 116962690 156763505 188535242 194018601 269939893 428710623 442819431 483000923 516768937 ...
2CODEFORCES
658_B. Bear and Displayed Friends_2247
Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti. Spring is starting and the Winter sleep is ...
import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.util.Iterator; import java.util.TreeSet; /** * * @author Rishabh */ public class Main {static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buff...
4JAVA
{ "input": [ "6 3 9\n50 20 51 17 99 24\n1 3\n1 4\n1 5\n1 2\n2 4\n2 2\n1 1\n2 4\n2 3\n", "4 2 8\n300 950 500 200\n1 3\n2 4\n2 3\n1 1\n1 2\n2 1\n2 2\n2 3\n", "1 1 1\n1000000000\n2 1\n", "20 2 15\n12698951 55128070 116962690 156763505 188535242 194018601 269939893 428710623 442819431 483000923 516768937 ...
2CODEFORCES
680_D. Bear and Tower of Cubes_2248
Limak is a little polar bear. He plays by building towers from blocks. Every block is a cube with positive integer length of side. Limak has infinitely many blocks of each side length. A block with side a has volume a3. A tower consisting of blocks with sides a1, a2, ..., ak has the total volume a13 + a23 + ... + ak3....
import sys def solve(N): X = [N] cache = {0:(0,0), 1:(1,1), 2:(2,2), 3:(3,3), 4:(4,4), 5:(5,5), 6:(6,6), 7:(7,7)} while X: i = X.pop() maxX = int(i**(1./3))**3 a0 = maxX-1 not in cache a1 = i-maxX not in cache if a0 or a1: X.append(i) if a0: X.append(maxX-1) if a1: ...
1Python2
{ "input": [ "6\n", "48\n", "1000000000000000\n", "994\n", "200385\n", "3842529393411\n", "8\n", "409477218238717\n", "2\n", "419477218238718\n", "909383000\n", "7\n", "999088000000000\n", "265\n", "415000000238718\n", "780869426483087\n", "9\n", ...
2CODEFORCES
680_D. Bear and Tower of Cubes_2249
Limak is a little polar bear. He plays by building towers from blocks. Every block is a cube with positive integer length of side. Limak has infinitely many blocks of each side length. A block with side a has volume a3. A tower consisting of blocks with sides a1, a2, ..., ak has the total volume a13 + a23 + ... + ak3....
#include <bits/stdc++.h> using namespace std; pair<long long, long long> res; long long my_pow(long long x) { return x * x * x; } void dfs(long long m, long long s, long long v) { int x = 0; if (m <= 0) { res = max(res, make_pair(s, v)); return; } while (my_pow(x + 1) <= m) { x++; } dfs(m - my_p...
2C++
{ "input": [ "6\n", "48\n", "1000000000000000\n", "994\n", "200385\n", "3842529393411\n", "8\n", "409477218238717\n", "2\n", "419477218238718\n", "909383000\n", "7\n", "999088000000000\n", "265\n", "415000000238718\n", "780869426483087\n", "9\n", ...
2CODEFORCES
680_D. Bear and Tower of Cubes_2250
Limak is a little polar bear. He plays by building towers from blocks. Every block is a cube with positive integer length of side. Limak has infinitely many blocks of each side length. A block with side a has volume a3. A tower consisting of blocks with sides a1, a2, ..., ak has the total volume a13 + a23 + ... + ak3....
#!/usr/bin/env python3 import sys # 1 8 27 64 125 216 343 512 729 1000 # 1-7: blocks of size 1 # 8-15: 1 block of size 2, blocks of size 1 # 16-23: 2 blocks of size 2, blocks of size 1 # 24-26: 3 blocks of size 2, blocks of size 1 # 27-34: 1 block of size 3, blocks of size 1 # Maximum will always be when you have th...
3Python3
{ "input": [ "6\n", "48\n", "1000000000000000\n", "994\n", "200385\n", "3842529393411\n", "8\n", "409477218238717\n", "2\n", "419477218238718\n", "909383000\n", "7\n", "999088000000000\n", "265\n", "415000000238718\n", "780869426483087\n", "9\n", ...
2CODEFORCES
680_D. Bear and Tower of Cubes_2251
Limak is a little polar bear. He plays by building towers from blocks. Every block is a cube with positive integer length of side. Limak has infinitely many blocks of each side length. A block with side a has volume a3. A tower consisting of blocks with sides a1, a2, ..., ak has the total volume a13 + a23 + ... + ak3....
/** * * @author sarthak */ import java.util.*; import java.math.*; import java.io.*; public class rnd356_D { static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(InputStream is) { br = new BufferedReader(new InputStreamReader(is)); ...
4JAVA
{ "input": [ "6\n", "48\n", "1000000000000000\n", "994\n", "200385\n", "3842529393411\n", "8\n", "409477218238717\n", "2\n", "419477218238718\n", "909383000\n", "7\n", "999088000000000\n", "265\n", "415000000238718\n", "780869426483087\n", "9\n", ...
2CODEFORCES
703_C. Chris and Road_2252
And while Mishka is enjoying her trip... Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend. Once walking with his friend, John gave Chris the following proble...
line = raw_input().split() n = int(line[0]) w,v,u = map(float, line[1:]) x,y = map(int, raw_input().split()) x_up = x_down = x - v*y/u for i in xrange(n-1): x,y = map(int, raw_input().split()) new_x = x - v*y/u if new_x > x_down: x_down = new_x elif new_x < x_up: x_up = new_x if x_up < 0 and x_down > 0: pr...
1Python2
{ "input": [ "5 5 1 2\n1 2\n3 1\n4 3\n3 4\n1 4\n", "3 3 5 2\n3 1\n4 0\n5 1\n", "10 1000 59 381\n131 195\n303 53\n528 0\n546 0\n726 41\n792 76\n917 187\n755 945\n220 895\n124 796\n", "10 1000 787 576\n-126 73\n-20 24\n216 7\n314 34\n312 967\n288 976\n99 999\n-138 920\n-220 853\n-308 734\n", "10 100...
2CODEFORCES
703_C. Chris and Road_2253
And while Mishka is enjoying her trip... Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend. Once walking with his friend, John gave Chris the following proble...
#include <bits/stdc++.h> using namespace std; int N; long double W, B, P; pair<long double, long double> bus[10001]; bool win = true; long double ans; int main() { ios_base::sync_with_stdio(false); if (fopen("cf703c.in", "r")) { freopen("cf703c.in", "r", stdin); freopen("cf703c.out", "w", stdout); } cin...
2C++
{ "input": [ "5 5 1 2\n1 2\n3 1\n4 3\n3 4\n1 4\n", "3 3 5 2\n3 1\n4 0\n5 1\n", "10 1000 59 381\n131 195\n303 53\n528 0\n546 0\n726 41\n792 76\n917 187\n755 945\n220 895\n124 796\n", "10 1000 787 576\n-126 73\n-20 24\n216 7\n314 34\n312 967\n288 976\n99 999\n-138 920\n-220 853\n-308 734\n", "10 100...
2CODEFORCES
703_C. Chris and Road_2254
And while Mishka is enjoying her trip... Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend. Once walking with his friend, John gave Chris the following proble...
n, w, v, u = map(int, input().split()) maxwait = 0 curr = True for i in range(n): x, y = map(int, input().split()) maxwait = max(maxwait, x / v - y / u) if x / v < y / u: curr = False if curr: maxwait = 0 print(w / u + maxwait)
3Python3
{ "input": [ "5 5 1 2\n1 2\n3 1\n4 3\n3 4\n1 4\n", "3 3 5 2\n3 1\n4 0\n5 1\n", "10 1000 59 381\n131 195\n303 53\n528 0\n546 0\n726 41\n792 76\n917 187\n755 945\n220 895\n124 796\n", "10 1000 787 576\n-126 73\n-20 24\n216 7\n314 34\n312 967\n288 976\n99 999\n-138 920\n-220 853\n-308 734\n", "10 100...
2CODEFORCES
703_C. Chris and Road_2255
And while Mishka is enjoying her trip... Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend. Once walking with his friend, John gave Chris the following proble...
import java.util.Scanner; public class R703C { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n=in.nextInt(), w=in.nextInt(); long v=in.nextInt(), u=in.nextInt(); Pair[] c=new Pair[n]; for(int i=0; i<n; i++) c[i]=new Pair(in.ne...
4JAVA
{ "input": [ "5 5 1 2\n1 2\n3 1\n4 3\n3 4\n1 4\n", "3 3 5 2\n3 1\n4 0\n5 1\n", "10 1000 59 381\n131 195\n303 53\n528 0\n546 0\n726 41\n792 76\n917 187\n755 945\n220 895\n124 796\n", "10 1000 787 576\n-126 73\n-20 24\n216 7\n314 34\n312 967\n288 976\n99 999\n-138 920\n-220 853\n-308 734\n", "10 100...
2CODEFORCES
725_C. Hidden Word_2256
Let’s define a grid to be a set of tiles with 2 rows and 13 columns. Each tile has an English letter written in it. The letters don't have to be unique: there might be two or more tiles with the same letter written on them. Here is an example of a grid: ABCDEFGHIJKLM NOPQRSTUVWXYZ We say that two t...
s = raw_input() st = 0 en = 0 ans = [['.' for _ in xrange(13)] for _ in xrange(2)] for i in xrange(ord('A'),ord('Z')+1): c = chr(i) st = s.find(c) en = s.find(c,st+1) if en != -1: break if st+1 == en: print "Impossible" else: l = (en-st) l += (l%2) ss = 13-(l/2) p = [ss,0...
1Python2
{ "input": [ "BUVTYZFQSNRIWOXXGJLKACPEMDH\n", "ABCDEFGHIJKLMNOPQRSGTUVWXYZ\n", "MKBGVNDJRAWUEHFSYLIZCOPTXKQ\n", "ABACDEFGHIJKLMNOPQRSTUVWXYZ\n", "BACDEFGHIJKLMNOPQRSTUVWXYZA\n", "BADSLHIYGMZJQKTCOPRVUXFWENN\n", "HVDEBKMJTLKQORNWCZSGXYIPUAF\n", "UNGHFQRCIPBZTEOAYJXLDMSKNWV\n", "TEGX...
2CODEFORCES
725_C. Hidden Word_2257
Let’s define a grid to be a set of tiles with 2 rows and 13 columns. Each tile has an English letter written in it. The letters don't have to be unique: there might be two or more tiles with the same letter written on them. Here is an example of a grid: ABCDEFGHIJKLM NOPQRSTUVWXYZ We say that two t...
#include <bits/stdc++.h> using namespace std; string s, cur; int cnt[26]; char grid[2][13]; void construct(int x) { int row = 0, col = x; for (int i = 0; i <= (26) - 1; i++) { grid[row][col] = cur[i]; if (!row && col == 12) row = 1; else if (row == 1 && !col) row = 0; else if (row) ...
2C++
{ "input": [ "BUVTYZFQSNRIWOXXGJLKACPEMDH\n", "ABCDEFGHIJKLMNOPQRSGTUVWXYZ\n", "MKBGVNDJRAWUEHFSYLIZCOPTXKQ\n", "ABACDEFGHIJKLMNOPQRSTUVWXYZ\n", "BACDEFGHIJKLMNOPQRSTUVWXYZA\n", "BADSLHIYGMZJQKTCOPRVUXFWENN\n", "HVDEBKMJTLKQORNWCZSGXYIPUAF\n", "UNGHFQRCIPBZTEOAYJXLDMSKNWV\n", "TEGX...
2CODEFORCES
725_C. Hidden Word_2258
Let’s define a grid to be a set of tiles with 2 rows and 13 columns. Each tile has an English letter written in it. The letters don't have to be unique: there might be two or more tiles with the same letter written on them. Here is an example of a grid: ABCDEFGHIJKLM NOPQRSTUVWXYZ We say that two t...
import sys debug = False def print_debug(*args, **kwargs): if debug: print(*args, **kwargs, file=sys.stderr) s = input() double = '' for c in range(ord('A'), ord('Z')+1): if s.count(chr(c)) == 2: double = chr(c) i1, i2 = [ i for i, c in enumerate(s) if c == double ] print_debug(double, i1...
3Python3
{ "input": [ "BUVTYZFQSNRIWOXXGJLKACPEMDH\n", "ABCDEFGHIJKLMNOPQRSGTUVWXYZ\n", "MKBGVNDJRAWUEHFSYLIZCOPTXKQ\n", "ABACDEFGHIJKLMNOPQRSTUVWXYZ\n", "BACDEFGHIJKLMNOPQRSTUVWXYZA\n", "BADSLHIYGMZJQKTCOPRVUXFWENN\n", "HVDEBKMJTLKQORNWCZSGXYIPUAF\n", "UNGHFQRCIPBZTEOAYJXLDMSKNWV\n", "TEGX...
2CODEFORCES
725_C. Hidden Word_2259
Let’s define a grid to be a set of tiles with 2 rows and 13 columns. Each tile has an English letter written in it. The letters don't have to be unique: there might be two or more tiles with the same letter written on them. Here is an example of a grid: ABCDEFGHIJKLM NOPQRSTUVWXYZ We say that two t...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.HashSet; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelpe...
4JAVA
{ "input": [ "BUVTYZFQSNRIWOXXGJLKACPEMDH\n", "ABCDEFGHIJKLMNOPQRSGTUVWXYZ\n", "MKBGVNDJRAWUEHFSYLIZCOPTXKQ\n", "ABACDEFGHIJKLMNOPQRSTUVWXYZ\n", "BACDEFGHIJKLMNOPQRSTUVWXYZA\n", "BADSLHIYGMZJQKTCOPRVUXFWENN\n", "HVDEBKMJTLKQORNWCZSGXYIPUAF\n", "UNGHFQRCIPBZTEOAYJXLDMSKNWV\n", "TEGX...
2CODEFORCES
747_C. Servers_2260
There are n servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to n. It is known that during the day q tasks will come, the i-th of them is characterized with three integers: ti — the moment in seconds in which the task will come, ki — the number of servers needed to ...
from itertools import imap def ri(): return imap(int, raw_input().split()) n, q = ri() s = [0 for i in xrange(n+1)] op = [-1] ss = s[:] for i in xrange(1,q + 1): t, k, d = ri() opp = 0 for j in xrange(1, n+1): if k == 0: break if ss[j] < t: ss[j] = t+d-1 ...
1Python2
{ "input": [ "8 6\n1 3 20\n4 2 1\n6 5 5\n10 1 1\n15 3 6\n21 8 8\n", "4 3\n1 3 2\n2 2 1\n3 4 3\n", "3 2\n3 2 3\n5 1 2\n", "100 1\n1000000 100 1000\n", "5 3\n1 4 10\n2 2 5\n3 1 6\n", "10 4\n1 5 20\n2 5 200\n100 6 20\n101 1 100\n", "5 3\n1 3 4\n4 3 4\n6 4 1\n", "4 1\n6 1 1\n", "8 6\n1...
2CODEFORCES
747_C. Servers_2261
There are n servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to n. It is known that during the day q tasks will come, the i-th of them is characterized with three integers: ti — the moment in seconds in which the task will come, ki — the number of servers needed to ...
#include <bits/stdc++.h> using namespace std; int en[100 + 100]; int e[100 + 100]; int main() { int n, q; while (~scanf("%d%d", &n, &q)) { memset(en, -1, sizeof(en)); memset(e, -1, sizeof(e)); for (int i = 1; i <= q; i++) { int T, K, D; scanf("%d%d%d", &T, &K, &D); int ans = 0; i...
2C++
{ "input": [ "8 6\n1 3 20\n4 2 1\n6 5 5\n10 1 1\n15 3 6\n21 8 8\n", "4 3\n1 3 2\n2 2 1\n3 4 3\n", "3 2\n3 2 3\n5 1 2\n", "100 1\n1000000 100 1000\n", "5 3\n1 4 10\n2 2 5\n3 1 6\n", "10 4\n1 5 20\n2 5 200\n100 6 20\n101 1 100\n", "5 3\n1 3 4\n4 3 4\n6 4 1\n", "4 1\n6 1 1\n", "8 6\n1...
2CODEFORCES
747_C. Servers_2262
There are n servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to n. It is known that during the day q tasks will come, the i-th of them is characterized with three integers: ti — the moment in seconds in which the task will come, ki — the number of servers needed to ...
n, q = map(int, input().split()) servers = [i for i in range(1, n+1)] res, used = [], {} for i in range(q): t, s, d = map(int, input().split()) finish = t + d for i in list(used.keys()): if t >= i: servers += used[i] servers.sort() del used[i] if s > len(serv...
3Python3
{ "input": [ "8 6\n1 3 20\n4 2 1\n6 5 5\n10 1 1\n15 3 6\n21 8 8\n", "4 3\n1 3 2\n2 2 1\n3 4 3\n", "3 2\n3 2 3\n5 1 2\n", "100 1\n1000000 100 1000\n", "5 3\n1 4 10\n2 2 5\n3 1 6\n", "10 4\n1 5 20\n2 5 200\n100 6 20\n101 1 100\n", "5 3\n1 3 4\n4 3 4\n6 4 1\n", "4 1\n6 1 1\n", "8 6\n1...
2CODEFORCES
747_C. Servers_2263
There are n servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to n. It is known that during the day q tasks will come, the i-th of them is characterized with three integers: ti — the moment in seconds in which the task will come, ki — the number of servers needed to ...
import java.util.*; import java.lang.*; import java.io.*; public class CO_747C { static int imax=Integer.MAX_VALUE,imin=Integer.MIN_VALUE; static long lmax=Long.MAX_VALUE,lmin=Long.MIN_VALUE; static long mod=(long)1e9+7; public static void main (String[] args) throws java.lang.Exception { InputReader in =new I...
4JAVA
{ "input": [ "8 6\n1 3 20\n4 2 1\n6 5 5\n10 1 1\n15 3 6\n21 8 8\n", "4 3\n1 3 2\n2 2 1\n3 4 3\n", "3 2\n3 2 3\n5 1 2\n", "100 1\n1000000 100 1000\n", "5 3\n1 4 10\n2 2 5\n3 1 6\n", "10 4\n1 5 20\n2 5 200\n100 6 20\n101 1 100\n", "5 3\n1 3 4\n4 3 4\n6 4 1\n", "4 1\n6 1 1\n", "8 6\n1...
2CODEFORCES
76_F. Tourist_2264
Tourist walks along the X axis. He can choose either of two directions and any speed not exceeding V. He can also stand without moving anywhere. He knows from newspapers that at time t1 in the point with coordinate x1 an interesting event will occur, at time t2 in the point with coordinate x2 — another one, and so on u...
from bisect import bisect_right as br I = 1000000000 n = input() a = [map(int,raw_input().split()) for x in xrange(n)] v = input() a.append((0,0)) a = sorted((x-v*t,-x-v*t) for x,t in a) b = [I]*(n+1) for x,y in a: if x or y: b[br(b,y)]=y else: print br(b,y), print b.index(I)
1Python2
{ "input": [ "3\n-1 1\n42 7\n40 8\n2\n", "12\n-6712 6\n2375 73\n4643 197\n-5660 215\n-378 223\n2228 307\n3305 340\n3449 468\n-4389 707\n-7161 729\n-1838 921\n-1655 985\n730\n", "5\n1 5\n6 7\n17127 17\n17072 42\n17042 77\n3\n", "7\n-976754 20479\n79929143 911181\n9598220 82517\n-51609349 810257\n674165...
2CODEFORCES
76_F. Tourist_2265
Tourist walks along the X axis. He can choose either of two directions and any speed not exceeding V. He can also stand without moving anywhere. He knows from newspapers that at time t1 in the point with coordinate x1 an interesting event will occur, at time t2 in the point with coordinate x2 — another one, and so on u...
#include <bits/stdc++.h> long long Left[101000], Right[101000]; int x[101000], t[101000], n, V, s[101000], p[101000], f[101000], L, R, MAX, Ans, Ans2; bool cmp(int a, int b) { return Left[a] == Left[b] ? t[a] < t[b] : Left[a] < Left[b]; } int main() { int i; scanf("%d", &n); for (i = 1; i <= n; p[i] = i++) ...
2C++
{ "input": [ "3\n-1 1\n42 7\n40 8\n2\n", "12\n-6712 6\n2375 73\n4643 197\n-5660 215\n-378 223\n2228 307\n3305 340\n3449 468\n-4389 707\n-7161 729\n-1838 921\n-1655 985\n730\n", "5\n1 5\n6 7\n17127 17\n17072 42\n17042 77\n3\n", "7\n-976754 20479\n79929143 911181\n9598220 82517\n-51609349 810257\n674165...
2CODEFORCES
76_F. Tourist_2266
Tourist walks along the X axis. He can choose either of two directions and any speed not exceeding V. He can also stand without moving anywhere. He knows from newspapers that at time t1 in the point with coordinate x1 an interesting event will occur, at time t2 in the point with coordinate x2 — another one, and so on u...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; import java.io.BufferedReader; impo...
4JAVA
{ "input": [ "3\n-1 1\n42 7\n40 8\n2\n", "12\n-6712 6\n2375 73\n4643 197\n-5660 215\n-378 223\n2228 307\n3305 340\n3449 468\n-4389 707\n-7161 729\n-1838 921\n-1655 985\n730\n", "5\n1 5\n6 7\n17127 17\n17072 42\n17042 77\n3\n", "7\n-976754 20479\n79929143 911181\n9598220 82517\n-51609349 810257\n674165...
2CODEFORCES
794_C. Naming Company_2267
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company. To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor ea...
first = raw_input() second = raw_input() first = sorted([i for i in first]) second = sorted([i for i in second],reverse = True) n = len(first) ans = ['']*n l = 0 r = n-1 f = first[:n/2] s = second[:n/2] if n % 2 != 0: f += first[n/2] fl = 0 fr = len(f)-1 sl = 0 sr = len(s)-1 index = 0 while True: if i...
1Python2
{ "input": [ "xxxxxx\nxxxxxx\n", "tinkoff\nzscoder\n", "ioi\nimo\n", "bcdef\nabbbc\n", "z\ny\n", "reddit\nabcdef\n", "abc\naaa\n", "y\nz\n", "cbxz\naaaa\n", "fedcb\nabbbc\n", "reddit\nbbcdef\n", "cba\naaa\n", "bbxz\naaaa\n", "xxxxxw\nxxxxxx\n", "tinkogf\nzsc...
2CODEFORCES
794_C. Naming Company_2268
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company. To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor ea...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); string first, second; cin >> first >> second; multiset<char> X, Y; for (char ch : first) { X.insert(ch); } for (char ch : second) { Y.insert(ch); } int n = ((int)(first).si...
2C++
{ "input": [ "xxxxxx\nxxxxxx\n", "tinkoff\nzscoder\n", "ioi\nimo\n", "bcdef\nabbbc\n", "z\ny\n", "reddit\nabcdef\n", "abc\naaa\n", "y\nz\n", "cbxz\naaaa\n", "fedcb\nabbbc\n", "reddit\nbbcdef\n", "cba\naaa\n", "bbxz\naaaa\n", "xxxxxw\nxxxxxx\n", "tinkogf\nzsc...
2CODEFORCES
794_C. Naming Company_2269
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company. To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor ea...
from sys import * f = lambda: sorted(stdin.readline()[:-1]) a, b = f(), f() n = len(a) u = v = '' i, j = 0, -1 x, y = n - 1 >> 1, n - 2 >> 1 while x != -1: if a[i] < b[j]: u += a[i] i += 1 else: v += a[i + x] x -= 1 if y == -1: break elif a[i] < b[j]: u += b[j] j -= 1...
3Python3
{ "input": [ "xxxxxx\nxxxxxx\n", "tinkoff\nzscoder\n", "ioi\nimo\n", "bcdef\nabbbc\n", "z\ny\n", "reddit\nabcdef\n", "abc\naaa\n", "y\nz\n", "cbxz\naaaa\n", "fedcb\nabbbc\n", "reddit\nbbcdef\n", "cba\naaa\n", "bbxz\naaaa\n", "xxxxxw\nxxxxxx\n", "tinkogf\nzsc...
2CODEFORCES
794_C. Naming Company_2270
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company. To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor ea...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class R414C_ { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(...
4JAVA
{ "input": [ "xxxxxx\nxxxxxx\n", "tinkoff\nzscoder\n", "ioi\nimo\n", "bcdef\nabbbc\n", "z\ny\n", "reddit\nabcdef\n", "abc\naaa\n", "y\nz\n", "cbxz\naaaa\n", "fedcb\nabbbc\n", "reddit\nbbcdef\n", "cba\naaa\n", "bbxz\naaaa\n", "xxxxxw\nxxxxxx\n", "tinkogf\nzsc...
2CODEFORCES
815_B. Karen and Test_2271
Karen has just arrived at school, and she has a math test today! <image> The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points. Th...
from sys import stdin from itertools import repeat def main(): n = int(stdin.readline()) a = map(int, stdin.readline().split()) mod = 1000000007 sgn = 1 while n % 4 != 1: n -= 1 b = [0] * n for i in xrange(n): b[i] = a[i] + sgn * a[i+1] sgn = -sgn ...
1Python2
{ "input": [ "4\n3 7 5 2\n", "5\n3 6 9 12 15\n", "6\n58376259 643910770 5887448 757703054 544067926 902981667\n", "5\n585325539 365329221 412106895 291882089 564718673\n", "7\n941492387 72235422 449924898 783332532 378192988 592684636 147499872\n", "1\n1\n", "16\n985629174 189232688 486953...
2CODEFORCES
815_B. Karen and Test_2272
Karen has just arrived at school, and she has a math test today! <image> The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points. Th...
#include <bits/stdc++.h> using namespace std; template <typename T> struct outputer; struct outputable {}; template <typename T> inline auto sqr(T x) -> decltype(x * x) { return x * x; } template <typename T1, typename T2> inline bool umx(T1& a, T2 b) { if (a < b) { a = b; return 1; } return 0; } templa...
2C++
{ "input": [ "4\n3 7 5 2\n", "5\n3 6 9 12 15\n", "6\n58376259 643910770 5887448 757703054 544067926 902981667\n", "5\n585325539 365329221 412106895 291882089 564718673\n", "7\n941492387 72235422 449924898 783332532 378192988 592684636 147499872\n", "1\n1\n", "16\n985629174 189232688 486953...
2CODEFORCES
815_B. Karen and Test_2273
Karen has just arrived at school, and she has a math test today! <image> The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points. Th...
from sys import exit, stdin, stdout n = int(stdin.readline()) a = [int(i) for i in stdin.readline().split()] if n == 1: print(a[0]) exit(0) mod = 1000000007 f = [0] * (n + 1) f[0] = 1 for i in range(1, n + 1): f[i] = (f[i-1] * i) % mod def f_pow(a, k): if k == 0: return 1 if k % 2 == 1: ...
3Python3
{ "input": [ "4\n3 7 5 2\n", "5\n3 6 9 12 15\n", "6\n58376259 643910770 5887448 757703054 544067926 902981667\n", "5\n585325539 365329221 412106895 291882089 564718673\n", "7\n941492387 72235422 449924898 783332532 378192988 592684636 147499872\n", "1\n1\n", "16\n985629174 189232688 486953...
2CODEFORCES
815_B. Karen and Test_2274
Karen has just arrived at school, and she has a math test today! <image> The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points. Th...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Pradyumn Agrawal coderbond0...
4JAVA
{ "input": [ "4\n3 7 5 2\n", "5\n3 6 9 12 15\n", "6\n58376259 643910770 5887448 757703054 544067926 902981667\n", "5\n585325539 365329221 412106895 291882089 564718673\n", "7\n941492387 72235422 449924898 783332532 378192988 592684636 147499872\n", "1\n1\n", "16\n985629174 189232688 486953...
2CODEFORCES
840_B. Leha and another game about graph_2275
Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or - 1. To pass the level, he needs to find a «good» subset of edges of the graph or say...
from collections import deque def subtree_specs(graph, d, node, visited, edges_dict, res_edges): num_ones = 0 for nb in graph[node]: if not visited[nb]: visited[nb] = True res = subtree_specs(graph, d, nb, visited, edges_dict, res_edges) if res % 2 == 1: ...
1Python2
{ "input": [ "3 3\n0 -1 1\n1 2\n2 3\n1 3\n", "4 5\n0 0 0 -1\n1 2\n2 3\n3 4\n1 4\n2 4\n", "1 0\n1\n", "2 1\n1 1\n1 2\n", "3 2\n1 0 1\n1 2\n2 3\n", "10 10\n-1 -1 -1 -1 -1 -1 -1 -1 -1 -1\n6 7\n8 3\n6 4\n4 2\n9 2\n5 10\n9 8\n10 7\n5 1\n6 2\n", "10 10\n-1 -1 -1 -1 0 -1 -1 -1 -1 -1\n6 7\n8 3\n6 ...
2CODEFORCES
840_B. Leha and another game about graph_2276
Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or - 1. To pass the level, he needs to find a «good» subset of edges of the graph or say...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 100; vector<int> adj[N]; int n, m, d[N]; vector<pair<int, int> > edge; bool in[N]; int wildcard, sz[N]; bool vis[N]; void dfs(int u) { vis[u] = true; if (d[u] == -1) wildcard = u; sz[u] = (d[u] == 1); for (int id : adj[u]) { auto e = edge[id]...
2C++
{ "input": [ "3 3\n0 -1 1\n1 2\n2 3\n1 3\n", "4 5\n0 0 0 -1\n1 2\n2 3\n3 4\n1 4\n2 4\n", "1 0\n1\n", "2 1\n1 1\n1 2\n", "3 2\n1 0 1\n1 2\n2 3\n", "10 10\n-1 -1 -1 -1 -1 -1 -1 -1 -1 -1\n6 7\n8 3\n6 4\n4 2\n9 2\n5 10\n9 8\n10 7\n5 1\n6 2\n", "10 10\n-1 -1 -1 -1 0 -1 -1 -1 -1 -1\n6 7\n8 3\n6 ...
2CODEFORCES
840_B. Leha and another game about graph_2277
Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or - 1. To pass the level, he needs to find a «good» subset of edges of the graph or say...
import os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline import sys import heapq INF=10**9 def Dijkstra(graph, start,m): dist=[INF]*len(graph) parent=[INF]*len(graph) queue=[(0, start)] while queue: path_len, v=heapq.heappop(queue) if dist[v]==INF: dist[v]=path_len for w in gra...
3Python3
{ "input": [ "3 3\n0 -1 1\n1 2\n2 3\n1 3\n", "4 5\n0 0 0 -1\n1 2\n2 3\n3 4\n1 4\n2 4\n", "1 0\n1\n", "2 1\n1 1\n1 2\n", "3 2\n1 0 1\n1 2\n2 3\n", "10 10\n-1 -1 -1 -1 -1 -1 -1 -1 -1 -1\n6 7\n8 3\n6 4\n4 2\n9 2\n5 10\n9 8\n10 7\n5 1\n6 2\n", "10 10\n-1 -1 -1 -1 0 -1 -1 -1 -1 -1\n6 7\n8 3\n6 ...
2CODEFORCES
840_B. Leha and another game about graph_2278
Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or - 1. To pass the level, he needs to find a «good» subset of edges of the graph or say...
import java.io.*; import java.util.*; import java.math.*; import java.lang.*; import static java.lang.Math.*; public class Main implements Runnable { static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFi...
4JAVA
{ "input": [ "3 3\n0 -1 1\n1 2\n2 3\n1 3\n", "4 5\n0 0 0 -1\n1 2\n2 3\n3 4\n1 4\n2 4\n", "1 0\n1\n", "2 1\n1 1\n1 2\n", "3 2\n1 0 1\n1 2\n2 3\n", "10 10\n-1 -1 -1 -1 -1 -1 -1 -1 -1 -1\n6 7\n8 3\n6 4\n4 2\n9 2\n5 10\n9 8\n10 7\n5 1\n6 2\n", "10 10\n-1 -1 -1 -1 0 -1 -1 -1 -1 -1\n6 7\n8 3\n6 ...
2CODEFORCES
860_C. Tests Renumeration_2279
The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website. Unfortunately, the archive with Olympiad's data is a mess. For example, the files with tests are named arbitrary without any logic. Vladimir wants to re...
from sys import stdin from random import randint def main(): n = int(stdin.readline()) e = set() r = set() for line in stdin: s, l = line.split() if l == '1': e.add(s) else: r.add(s) en = len(e) es = set(map(str, xrange(1, en + 1))) rs = set(ma...
1Python2
{ "input": [ "5\n01 0\n2 1\n2extra 0\n3 1\n99 0\n", "2\n1 0\n2 1\n", "5\n1 0\n11 1\n111 0\n1111 1\n11111 0\n", "3\n1 1\nzwfnx2 1\n7g8t6z 1\n", "3\nqmf7iz 1\ndjwdce 1\n1 1\n", "6\n4 1\n410jiy 1\n1 0\n6 0\nxc98l2 1\n5 0\n", "3\n2 1\n3 0\nhs9j9t 1\n", "6\n5 1\n6 0\nxhfzge 0\n3 1\n1 0\n1n9...
2CODEFORCES
860_C. Tests Renumeration_2280
The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website. Unfortunately, the archive with Olympiad's data is a mess. For example, the files with tests are named arbitrary without any logic. Vladimir wants to re...
#include <bits/stdc++.h> using namespace std; template <class htpe, class cmp> using heap = priority_queue<htpe, vector<htpe>, cmp>; template <class htpe> using min_heap = heap<htpe, greater<htpe> >; template <class htpe> using max_heap = heap<htpe, less<htpe> >; const int INF = 1791791791; const long long INFLL = 1791...
2C++
{ "input": [ "5\n01 0\n2 1\n2extra 0\n3 1\n99 0\n", "2\n1 0\n2 1\n", "5\n1 0\n11 1\n111 0\n1111 1\n11111 0\n", "3\n1 1\nzwfnx2 1\n7g8t6z 1\n", "3\nqmf7iz 1\ndjwdce 1\n1 1\n", "6\n4 1\n410jiy 1\n1 0\n6 0\nxc98l2 1\n5 0\n", "3\n2 1\n3 0\nhs9j9t 1\n", "6\n5 1\n6 0\nxhfzge 0\n3 1\n1 0\n1n9...
2CODEFORCES
860_C. Tests Renumeration_2281
The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website. Unfortunately, the archive with Olympiad's data is a mess. For example, the files with tests are named arbitrary without any logic. Vladimir wants to re...
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF()...
3Python3
{ "input": [ "5\n01 0\n2 1\n2extra 0\n3 1\n99 0\n", "2\n1 0\n2 1\n", "5\n1 0\n11 1\n111 0\n1111 1\n11111 0\n", "3\n1 1\nzwfnx2 1\n7g8t6z 1\n", "3\nqmf7iz 1\ndjwdce 1\n1 1\n", "6\n4 1\n410jiy 1\n1 0\n6 0\nxc98l2 1\n5 0\n", "3\n2 1\n3 0\nhs9j9t 1\n", "6\n5 1\n6 0\nxhfzge 0\n3 1\n1 0\n1n9...
2CODEFORCES
860_C. Tests Renumeration_2282
The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website. Unfortunately, the archive with Olympiad's data is a mess. For example, the files with tests are named arbitrary without any logic. Vladimir wants to re...
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.StringTokenizer; import java.util.TreeSet; public class Di...
4JAVA
{ "input": [ "5\n01 0\n2 1\n2extra 0\n3 1\n99 0\n", "2\n1 0\n2 1\n", "5\n1 0\n11 1\n111 0\n1111 1\n11111 0\n", "3\n1 1\nzwfnx2 1\n7g8t6z 1\n", "3\nqmf7iz 1\ndjwdce 1\n1 1\n", "6\n4 1\n410jiy 1\n1 0\n6 0\nxc98l2 1\n5 0\n", "3\n2 1\n3 0\nhs9j9t 1\n", "6\n5 1\n6 0\nxhfzge 0\n3 1\n1 0\n1n9...
2CODEFORCES
887_B. Cubes for Masha_2283
Absent-minded Masha got set of n cubes for her birthday. At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural x such she can make using her new cubes all integers from 1 to x. To make a number Masha can rotate her cubes and put them in a row. Aft...
n = input() if n==1: s = map(int,raw_input().split()) elif n==2: s1 = raw_input().split() s2 = raw_input().split() s = [] for i in s1: s.append(int(i)) for i in s2: s.append(int(i)) for i in s1: for j in s2: s.append(int(i+j)) s.append(int(j+i)...
1Python2
{ "input": [ "3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9\n", "3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7\n", "2\n2 6 8 1 3 1\n2 1 3 8 6 7\n", "2\n1 8 9 1 1 0\n2 3 4 5 6 7\n", "2\n0 2 9 8 1 7\n6 7 4 3 2 5\n", "3\n9 4 6 2 7 0\n3 7 1 9 6 4\n6 1 0 8 7 2\n", "3\n2 7 4 0 7 1\n5 5 4 9 1 4\n2 1 7 5 1 ...
2CODEFORCES
887_B. Cubes for Masha_2284
Absent-minded Masha got set of n cubes for her birthday. At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural x such she can make using her new cubes all integers from 1 to x. To make a number Masha can rotate her cubes and put them in a row. Aft...
#include <bits/stdc++.h> using namespace std; int arr[3][15]; int ar[100005]; void solve() {} int main() { ios::sync_with_stdio(false); cin.tie(0); int t; int n; cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < 6; j++) cin >> arr[i][j]; } if (n == 1) { for (int i = 0; i < 6; i++) ar[a...
2C++
{ "input": [ "3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9\n", "3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7\n", "2\n2 6 8 1 3 1\n2 1 3 8 6 7\n", "2\n1 8 9 1 1 0\n2 3 4 5 6 7\n", "2\n0 2 9 8 1 7\n6 7 4 3 2 5\n", "3\n9 4 6 2 7 0\n3 7 1 9 6 4\n6 1 0 8 7 2\n", "3\n2 7 4 0 7 1\n5 5 4 9 1 4\n2 1 7 5 1 ...
2CODEFORCES
887_B. Cubes for Masha_2285
Absent-minded Masha got set of n cubes for her birthday. At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural x such she can make using her new cubes all integers from 1 to x. To make a number Masha can rotate her cubes and put them in a row. Aft...
n = int(input()) lst = [] for i in range(n): a = list(map(int,input().split())) lst.append(a) cnt = 0 ans = 0 if n == 1: i = 1 while 1: if i == 10: break if i in lst[0]: i += 1 else: print(i - 1) break elif n == 2: i = 1 f = 0 whil...
3Python3
{ "input": [ "3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9\n", "3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7\n", "2\n2 6 8 1 3 1\n2 1 3 8 6 7\n", "2\n1 8 9 1 1 0\n2 3 4 5 6 7\n", "2\n0 2 9 8 1 7\n6 7 4 3 2 5\n", "3\n9 4 6 2 7 0\n3 7 1 9 6 4\n6 1 0 8 7 2\n", "3\n2 7 4 0 7 1\n5 5 4 9 1 4\n2 1 7 5 1 ...
2CODEFORCES
887_B. Cubes for Masha_2286
Absent-minded Masha got set of n cubes for her birthday. At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural x such she can make using her new cubes all integers from 1 to x. To make a number Masha can rotate her cubes and put them in a row. Aft...
import java.util.*; public class Code { public static void main(String args[]) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int a[][] = new int[n][6]; boolean vis[] = new boolean[100]; for(int i=0; i<n; i++) { for(int j=0; j<6; j++) a[i][j] = in.nextInt(...
4JAVA
{ "input": [ "3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9\n", "3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7\n", "2\n2 6 8 1 3 1\n2 1 3 8 6 7\n", "2\n1 8 9 1 1 0\n2 3 4 5 6 7\n", "2\n0 2 9 8 1 7\n6 7 4 3 2 5\n", "3\n9 4 6 2 7 0\n3 7 1 9 6 4\n6 1 0 8 7 2\n", "3\n2 7 4 0 7 1\n5 5 4 9 1 4\n2 1 7 5 1 ...
2CODEFORCES
90_B. African Crossword_2287
An African crossword is a rectangular table n × m in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded. To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a lette...
#!/usr/bin/env python2 # -*- coding: utf-8 -*- import sys from operator import getitem input = sys.stdin output = sys.stdout def solve(size,lines): A = lines n,m = size # set of symbols symbols = {} for r in range(n): for c in range(m): a = A[r][c] if a not...
1Python2
{ "input": [ "3 3\ncba\nbcd\ncbc\n", "5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf\n", "1 2\nfg\n", "3 2\nxe\ner\nwb\n", "7 6\neklgxi\nxmpzgf\nxvwcmr\nrqssed\nouiqpt\ndueiok\nbbuorv\n", "9 3\njel\njws\ntab\nvyo\nkgm\npls\nabq\nbjx\nljt\n", "100 2\nhd\ngx\nmz\nbq\nof\nst\nzc\ndg\nth\nba\new\nbw\n...
2CODEFORCES
90_B. African Crossword_2288
An African crossword is a rectangular table n × m in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded. To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a lette...
#include <bits/stdc++.h> using namespace std; int main() { char a[150][150]; int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i]; } int s[150][150]; memset(s, 0, sizeof(s)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { char c = a[i][j]; for (int b = 0; b...
2C++
{ "input": [ "3 3\ncba\nbcd\ncbc\n", "5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf\n", "1 2\nfg\n", "3 2\nxe\ner\nwb\n", "7 6\neklgxi\nxmpzgf\nxvwcmr\nrqssed\nouiqpt\ndueiok\nbbuorv\n", "9 3\njel\njws\ntab\nvyo\nkgm\npls\nabq\nbjx\nljt\n", "100 2\nhd\ngx\nmz\nbq\nof\nst\nzc\ndg\nth\nba\new\nbw\n...
2CODEFORCES
90_B. African Crossword_2289
An African crossword is a rectangular table n × m in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded. To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a lette...
n, m = [int(x) for x in input().split()] lr = [] lc = [] lst = [] for i in range(n): l = list(input()) lr.append(l) for i in range(m): l = [] for j in range(n): s = lr[j][i] l.append(s) lc.append(l) for i in range(n): for j in range(m): s = lr[i][j] if lr[i].count...
3Python3
{ "input": [ "3 3\ncba\nbcd\ncbc\n", "5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf\n", "1 2\nfg\n", "3 2\nxe\ner\nwb\n", "7 6\neklgxi\nxmpzgf\nxvwcmr\nrqssed\nouiqpt\ndueiok\nbbuorv\n", "9 3\njel\njws\ntab\nvyo\nkgm\npls\nabq\nbjx\nljt\n", "100 2\nhd\ngx\nmz\nbq\nof\nst\nzc\ndg\nth\nba\new\nbw\n...
2CODEFORCES
90_B. African Crossword_2290
An African crossword is a rectangular table n × m in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded. To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a lette...
import java.util.Scanner; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author Xeyyam */ public class Main { static boolean[][] flag = new boolean[100][100]; static String s[] = new String[101]; static int n , m; pu...
4JAVA
{ "input": [ "3 3\ncba\nbcd\ncbc\n", "5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf\n", "1 2\nfg\n", "3 2\nxe\ner\nwb\n", "7 6\neklgxi\nxmpzgf\nxvwcmr\nrqssed\nouiqpt\ndueiok\nbbuorv\n", "9 3\njel\njws\ntab\nvyo\nkgm\npls\nabq\nbjx\nljt\n", "100 2\nhd\ngx\nmz\nbq\nof\nst\nzc\ndg\nth\nba\new\nbw\n...
2CODEFORCES
931_E. Game with String_2291
Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this string s, and then shifts it k letters to the left, i. e. creates a new string ...
from __future__ import print_function, division from sys import stdin, stdout from collections import * chrs = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:;?!"#&\'()*+,-./ ' rstr = lambda: stdin.readline().strip() s, ans = rstr(), 0 le = len(s) mem = [[[0 for _ in range(le)] for _ in range(26)] for...
1Python2
{ "input": [ "tictictactac\n", "bbaabaabbb\n", "technocup\n", "fabbbhgedd\n", "abbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaab\n", "hcdhgcchbdhbeagdcfedgcbaffebgcbcccadeefacbhefgeadfgchabgeebegahfgegahbddedfhffeadcedadgfbeebhgfahhfb\n", "khjcoiji...
2CODEFORCES
931_E. Game with String_2292
Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this string s, and then shifts it k letters to the left, i. e. creates a new string ...
#include <bits/stdc++.h> using namespace std; string find(int j) { string s = ""; while (j > 0) { char ch = j % 10 + '0'; s += ch; j = j / 10; } reverse(s.begin(), s.end()); return s; } int main() { string s; cin >> s; int n = s.size(); string t = ""; for (int i = 0; i < n - 1; i++) t +=...
2C++
{ "input": [ "tictictactac\n", "bbaabaabbb\n", "technocup\n", "fabbbhgedd\n", "abbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaab\n", "hcdhgcchbdhbeagdcfedgcbaffebgcbcccadeefacbhefgeadfgchabgeebegahfgegahbddedfhffeadcedadgfbeebhgfahhfb\n", "khjcoiji...
2CODEFORCES
931_E. Game with String_2293
Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this string s, and then shifts it k letters to the left, i. e. creates a new string ...
s = input() n = len(s) d = {} for i in range(n): if s[i] not in d: d[s[i]] = [] d[s[i]].append(s[i + 1:] + s[:i]) res = 0 for k, l in d.items(): ans = 0 for j in range(n - 1): seen, s1 = set(), set() for i in range(len(l)): if l[i][j] in s1: s1.remove(l[i][j]) eli...
3Python3
{ "input": [ "tictictactac\n", "bbaabaabbb\n", "technocup\n", "fabbbhgedd\n", "abbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaab\n", "hcdhgcchbdhbeagdcfedgcbaffebgcbcccadeefacbhefgeadfgchabgeebegahfgegahbddedfhffeadcedadgfbeebhgfahhfb\n", "khjcoiji...
2CODEFORCES
931_E. Game with String_2294
Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this string s, and then shifts it k letters to the left, i. e. creates a new string ...
import java.io.*; import java.util.*; import java.math.*; import java.lang.*; import static java.lang.Math.*; public class Main implements Runnable { static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int nu...
4JAVA
{ "input": [ "tictictactac\n", "bbaabaabbb\n", "technocup\n", "fabbbhgedd\n", "abbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaab\n", "hcdhgcchbdhbeagdcfedgcbaffebgcbcccadeefacbhefgeadfgchabgeebegahfgegahbddedfhffeadcedadgfbeebhgfahhfb\n", "khjcoiji...
2CODEFORCES
958_F3. Lightsabers (hard)_2295
There used to be unrest in the Galactic Senate. Several thousand solar systems had declared their intentions to leave the Republic. But fear not! Master Heidi was able to successfully select the Jedi Knights that have restored peace in the galaxy. However, she knows that evil never sleeps and a time may come when she w...
#include <bits/stdc++.h> using namespace std; namespace FFT { template <typename U> struct RootsOfUnity { using Complex = complex<U>; static std::vector<Complex> roots[32]; static bool initialized[32]; static void initialize_to(long long w) { assert(w > 0 && w == (w & -w)); long long lg = 31 - __builtin...
2C++
{ "input": [ "4 3 2\n1 2 3 2\n", "10 2 5\n1 1 1 2 2 2 2 2 2 2\n", "10 2 5\n1 1 1 1 1 1 2 2 2 2\n", "3 3 2\n1 3 1\n", "8 8 7\n7 2 8 6 8 5 3 8\n", "7 7 5\n2 6 3 6 3 5 1\n", "5 5 1\n5 2 5 1 2\n", "6 6 6\n5 6 5 3 4 2\n", "5 5 2\n2 3 2 2 4\n", "3 3 3\n1 1 1\n", "111 78 54\n24 13...
2CODEFORCES
958_F3. Lightsabers (hard)_2296
There used to be unrest in the Galactic Senate. Several thousand solar systems had declared their intentions to leave the Republic. But fear not! Master Heidi was able to successfully select the Jedi Knights that have restored peace in the galaxy. However, she knows that evil never sleeps and a time may come when she w...
import java.io.*; import java.util.*; public class E implements Runnable{ public static void main (String[] args) {new Thread(null, new E(), "_cf", 1 << 28).start();} int MOD = 1009; int N, K; public void run() { DeoxysS fs = new DeoxysS(); // try { fs = new DeoxysS("testdata.out"); } catch (Exception e) {} ...
4JAVA
{ "input": [ "4 3 2\n1 2 3 2\n", "10 2 5\n1 1 1 2 2 2 2 2 2 2\n", "10 2 5\n1 1 1 1 1 1 2 2 2 2\n", "3 3 2\n1 3 1\n", "8 8 7\n7 2 8 6 8 5 3 8\n", "7 7 5\n2 6 3 6 3 5 1\n", "5 5 1\n5 2 5 1 2\n", "6 6 6\n5 6 5 3 4 2\n", "5 5 2\n2 3 2 2 4\n", "3 3 3\n1 1 1\n", "111 78 54\n24 13...
2CODEFORCES
985_E. Pencils and Boxes_2297
Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where everything is of the same color and only saturation differs. This pack can be represented as a sequence a1, a2, ..., an of n integer numbers — saturation of the color of each pencil. Now Mishka wants to ...
from bisect import bisect from sys import exit [n, k, d] = map(int,raw_input().strip().split()) ais = list(map(int,raw_input().strip().split())) if k == 1: print ('YES') exit() ais.sort() # can do ais[i:] cando = [False for _ in range(n)] j = n - 1 count = 0 for i in reversed(range(n)): if i + k < n and cando[i...
1Python2
{ "input": [ "6 3 10\n7 2 7 7 4 2\n", "3 2 5\n10 16 22\n", "6 2 3\n4 5 3 13 4 10\n", "4 2 12\n10 16 22 28\n", "10 3 1\n5 5 5 6 6 7 8 8 8 9\n", "8 7 13\n52 85 14 52 92 33 80 85\n", "10 5 293149357\n79072863 760382815 358896034 663269192 233367425 32795628 837363300 46932461 179556769 763342...
2CODEFORCES
985_E. Pencils and Boxes_2298
Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where everything is of the same color and only saturation differs. This pack can be represented as a sequence a1, a2, ..., an of n integer numbers — saturation of the color of each pencil. Now Mishka wants to ...
#include <bits/stdc++.h> using namespace std; const int maxn = 5e6 + 5; int n, m; long long d; long long a[maxn], sum[maxn]; int main() { scanf("%d%d%lld", &n, &m, &d); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); sort(&a[1], &a[n + 1]); int good = 1; sum[0] = 1; for (int i = 1, j = 1; i <= n; i++) { ...
2C++
{ "input": [ "6 3 10\n7 2 7 7 4 2\n", "3 2 5\n10 16 22\n", "6 2 3\n4 5 3 13 4 10\n", "4 2 12\n10 16 22 28\n", "10 3 1\n5 5 5 6 6 7 8 8 8 9\n", "8 7 13\n52 85 14 52 92 33 80 85\n", "10 5 293149357\n79072863 760382815 358896034 663269192 233367425 32795628 837363300 46932461 179556769 763342...
2CODEFORCES
985_E. Pencils and Boxes_2299
Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where everything is of the same color and only saturation differs. This pack can be represented as a sequence a1, a2, ..., an of n integer numbers — saturation of the color of each pencil. Now Mishka wants to ...
n, k, d = list(map(int, input().split())) a = sorted(list(map(int, input().split()))) b = [0] * n i = j = 0 for i in range(n): while a[i] - a[j] > d: j += 1 b[i] = j c = [0] * n for i in range(k - 1, n): c[i] = c[i - 1] + int(i - b[i] + 1 >= k and (b[i] == 0 or c[i - k] > c[b[i] - 2] or (b[i] == 1 a...
3Python3
{ "input": [ "6 3 10\n7 2 7 7 4 2\n", "3 2 5\n10 16 22\n", "6 2 3\n4 5 3 13 4 10\n", "4 2 12\n10 16 22 28\n", "10 3 1\n5 5 5 6 6 7 8 8 8 9\n", "8 7 13\n52 85 14 52 92 33 80 85\n", "10 5 293149357\n79072863 760382815 358896034 663269192 233367425 32795628 837363300 46932461 179556769 763342...
2CODEFORCES