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
1152_A. Neko Finds Grapes_1800
On a random day, Neko found n treasure chests and m keys. The i-th chest has an integer a_i written on it and the j-th key has an integer b_j on it. Neko knows those chests contain the powerful mysterious green Grapes, thus Neko wants to open as many treasure chests as possible. The j-th key can be used to unlock the ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n, m, i, j, a, b, o = 0, e = 0, o1 = 0, e1 = 0, c, d; cin >> n >> m; for (i = 0; i < n; i++) { cin >> a; if (a % 2 == 1) o++; else e++; } for (j = 0; j < m; j++) { ...
2C++
{ "input": [ "5 1\n2 4 6 8 10\n5\n", "1 4\n10\n20 30 40 50\n", "5 4\n9 14 6 2 11\n8 4 7 20\n", "4 1\n3 5 7 8\n2\n", "5 1\n2 2 2 3 3\n3\n", "4 1\n1 1 2 2\n2\n", "10 10\n522312461 931001459 598654597 488228616 544064902 21923894 329635457 980089248 988262691 654502493\n967529230 543358150 83...
2CODEFORCES
1152_A. Neko Finds Grapes_1801
On a random day, Neko found n treasure chests and m keys. The i-th chest has an integer a_i written on it and the j-th key has an integer b_j on it. Neko knows those chests contain the powerful mysterious green Grapes, thus Neko wants to open as many treasure chests as possible. The j-th key can be used to unlock the ...
n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) aeven = 0 aodd = 0 beven = 0 bodd = 0 for i in range(n): if a[i] % 2 == 0: aeven += 1 else: aodd += 1 for i in range(m): if b[i] % 2 == 0: beven += 1 else: bodd += 1 ...
3Python3
{ "input": [ "5 1\n2 4 6 8 10\n5\n", "1 4\n10\n20 30 40 50\n", "5 4\n9 14 6 2 11\n8 4 7 20\n", "4 1\n3 5 7 8\n2\n", "5 1\n2 2 2 3 3\n3\n", "4 1\n1 1 2 2\n2\n", "10 10\n522312461 931001459 598654597 488228616 544064902 21923894 329635457 980089248 988262691 654502493\n967529230 543358150 83...
2CODEFORCES
1152_A. Neko Finds Grapes_1802
On a random day, Neko found n treasure chests and m keys. The i-th chest has an integer a_i written on it and the j-th key has an integer b_j on it. Neko knows those chests contain the powerful mysterious green Grapes, thus Neko wants to open as many treasure chests as possible. The j-th key can be used to unlock the ...
import java.util.Scanner; public class Main { private static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { int N = scanner.nextInt(); int M = scanner.nextInt(); int p = 0, q = 0; for (int i = 0; i < N; i++) if ((scanner.nextInt() & 1) != 0...
4JAVA
{ "input": [ "5 1\n2 4 6 8 10\n5\n", "1 4\n10\n20 30 40 50\n", "5 4\n9 14 6 2 11\n8 4 7 20\n", "4 1\n3 5 7 8\n2\n", "5 1\n2 2 2 3 3\n3\n", "4 1\n1 1 2 2\n2\n", "10 10\n522312461 931001459 598654597 488228616 544064902 21923894 329635457 980089248 988262691 654502493\n967529230 543358150 83...
2CODEFORCES
1173_E2. Nauuo and Pictures (hard version)_1803
The only difference between easy and hard versions is constraints. Nauuo is a girl who loves random picture websites. One day she made a random picture website by herself which includes n pictures. When Nauuo visits the website, she sees exactly one picture. The website does not display each picture with equal proba...
#include <bits/stdc++.h> using namespace std; const int md = 998244353; const int N = 200010; const int M = 3010; int pow_mod(int a, int b) { int ret = 1; while (b) { if (b & 1) { ret = 1LL * ret * a % md; } b >>= 1; a = 1LL * a * a % md; } return ret; } int inv[M << 1]; int f[M][M], g[M][...
2C++
{ "input": [ "3 3\n0 1 1\n4 3 5\n", "1 2\n1\n1\n", "2 1\n0 1\n2 1\n", "20 30\n1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 2 1 3 1 4 1 5 1 1 2 3 1 1 3 3 2 2 1 2\n", "20 30\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n765 451 7275 385 1686 78 554 114 1980 394 776 232 627 760 782 7 486 32 1100 1516\n", ...
2CODEFORCES
1173_E2. Nauuo and Pictures (hard version)_1804
The only difference between easy and hard versions is constraints. Nauuo is a girl who loves random picture websites. One day she made a random picture website by herself which includes n pictures. When Nauuo visits the website, she sees exactly one picture. The website does not display each picture with equal proba...
import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the templa...
4JAVA
{ "input": [ "3 3\n0 1 1\n4 3 5\n", "1 2\n1\n1\n", "2 1\n0 1\n2 1\n", "20 30\n1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 2 1 3 1 4 1 5 1 1 2 3 1 1 3 3 2 2 1 2\n", "20 30\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n765 451 7275 385 1686 78 554 114 1980 394 776 232 627 760 782 7 486 32 1100 1516\n", ...
2CODEFORCES
1191_C. Tokitsukaze and Discard Items_1805
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≤ m ≤ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed o...
n, m, k = map(int, raw_input().split()) l = map(int, raw_input().split()) l.sort() ans = 0 cnt = 0 i = 0 while i < m: bound = ((l[i] - cnt - 1)/k + 1)*k + cnt while i < m and l[i] <= bound: i += 1 cnt += 1 ans += 1 print ans
1Python2
{ "input": [ "13 4 5\n7 8 9 10\n", "10 4 5\n3 5 7 10\n", "10 5 5\n2 3 4 5 6\n", "1 1 1\n1\n", "1000000000000000000 10 68\n9818112234872670 233245257111863071 266483628625876079 375103213040049805 431982380866113633 489732004669478331 501030096787260719 541800997319766183 551892546260532408 6961786...
2CODEFORCES
1191_C. Tokitsukaze and Discard Items_1806
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≤ m ≤ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed o...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, m, k; cin >> n >> m >> k; long long arr[m]; for (long long i = 0; i < m; i++) cin >> arr[i]; long long ans = 0; long long sub = 0; long long g = 1, temp; long long now = (arr[0...
2C++
{ "input": [ "13 4 5\n7 8 9 10\n", "10 4 5\n3 5 7 10\n", "10 5 5\n2 3 4 5 6\n", "1 1 1\n1\n", "1000000000000000000 10 68\n9818112234872670 233245257111863071 266483628625876079 375103213040049805 431982380866113633 489732004669478331 501030096787260719 541800997319766183 551892546260532408 6961786...
2CODEFORCES
1191_C. Tokitsukaze and Discard Items_1807
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≤ m ≤ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed o...
from collections import deque n,m,k=list(map(int,input().split())) arr=list(map(int,input().split())) d=deque() for i in arr: d.append(i) chances=curr=tot=0 # print("WORKING") while tot<m: # print("S") if (d[0]-curr)%k==0: p=(d[0]-curr)//k else:p=((d[0]-curr)//k)+1 temp=curr while tot<m...
3Python3
{ "input": [ "13 4 5\n7 8 9 10\n", "10 4 5\n3 5 7 10\n", "10 5 5\n2 3 4 5 6\n", "1 1 1\n1\n", "1000000000000000000 10 68\n9818112234872670 233245257111863071 266483628625876079 375103213040049805 431982380866113633 489732004669478331 501030096787260719 541800997319766183 551892546260532408 6961786...
2CODEFORCES
1191_C. Tokitsukaze and Discard Items_1808
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≤ m ≤ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed o...
import java.io.*; import java.util.*; import java.util.regex.*; public class vk18 { public static void main(String[]stp) throws Exception { Scanner scan=new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)...
4JAVA
{ "input": [ "13 4 5\n7 8 9 10\n", "10 4 5\n3 5 7 10\n", "10 5 5\n2 3 4 5 6\n", "1 1 1\n1\n", "1000000000000000000 10 68\n9818112234872670 233245257111863071 266483628625876079 375103213040049805 431982380866113633 489732004669478331 501030096787260719 541800997319766183 551892546260532408 6961786...
2CODEFORCES
120_C. Winnie-the-Pooh and honey_1809
As we all know, Winnie-the-Pooh just adores honey. Ones he and the Piglet found out that the Rabbit has recently gotten hold of an impressive amount of this sweet and healthy snack. As you may guess, Winnie and the Piglet asked to come at the Rabbit's place. Thus, there are n jars of honey lined up in front of Winnie-t...
#include <bits/stdc++.h> using namespace std; using namespace std; void check() { int a, b, s = 0, k; cin >> a >> b; vector<int> v; for (typeof(a) i = 0; i < (a); ++i) { cin >> k; v.push_back(k); } for (typeof(a) i = 0; i < (a); ++i) { int c = v[i]; for (typeof(3) j = 0; j < (3); ++j) ...
2C++
{ "input": [ "3 3\n15 8 10\n", "100 1\n85 75 55 65 39 26 47 16 9 11 3 4 70 23 56 64 36 34 16 13 18 28 32 80 8 79 76 4 21 75 93 51 85 86 100 88 91 71 97 28 66 22 47 87 91 95 3 56 81 53 88 90 21 30 74 45 58 73 36 40 70 51 28 75 20 54 69 52 14 48 52 53 91 81 32 68 16 48 60 66 91 32 55 42 93 51 3 46 23 64 39 1 30...
2CODEFORCES
120_C. Winnie-the-Pooh and honey_1810
As we all know, Winnie-the-Pooh just adores honey. Ones he and the Piglet found out that the Rabbit has recently gotten hold of an impressive amount of this sweet and healthy snack. As you may guess, Winnie and the Piglet asked to come at the Rabbit's place. Thus, there are n jars of honey lined up in front of Winnie-t...
import java.io.*; import java.util.*; import java.text.*; import java.util.regex.*; /** * Problem-(#) - Main.java * * @author Isuru Madushanka Weerarathna * @team CSECodersV2 * @written 2011/10/22 * @competetion IEEEXtreme 5.0 */ public class Main { public static void main(String[] args) { try { ...
4JAVA
{ "input": [ "3 3\n15 8 10\n", "100 1\n85 75 55 65 39 26 47 16 9 11 3 4 70 23 56 64 36 34 16 13 18 28 32 80 8 79 76 4 21 75 93 51 85 86 100 88 91 71 97 28 66 22 47 87 91 95 3 56 81 53 88 90 21 30 74 45 58 73 36 40 70 51 28 75 20 54 69 52 14 48 52 53 91 81 32 68 16 48 60 66 91 32 55 42 93 51 3 46 23 64 39 1 30...
2CODEFORCES
1230_A. Dawid and Bags of Candies_1811
Dawid has four bags of candies. The i-th of them contains a_i candies. Also, Dawid has two friends. He wants to give each bag to one of his two friends. Is it possible to distribute the bags in such a way that each friend receives the same amount of candies in total? Note, that you can't keep bags for yourself or thro...
a,b,c,d=[int(z) for z in raw_input().split(' ')] summ= a+b+c+d if a+b==c+d: print 'YES' elif a+c==b+d: print 'YES' elif a+d==b+c: print 'YES' elif a== summ-a: print 'YES' elif b== summ-b: print 'YES' elif c== summ-c: print 'YES' elif d== summ-d: print 'YES' else: print 'NO'
1Python2
{ "input": [ "1 7 11 5\n", "7 3 2 5\n", "44 58 90 53\n", "20 14 37 71\n", "4 2 4 2\n", "1 2 5 5\n", "1 2 8 9\n", "99 100 3 98\n", "92 69 83 97\n", "3 1 1 1\n", "18 88 18 18\n", "1 1 1 1\n", "69 7 44 30\n", "90 30 30 30\n", "1 2 3 5\n", "1 1 3 1\n", "...
2CODEFORCES
1230_A. Dawid and Bags of Candies_1812
Dawid has four bags of candies. The i-th of them contains a_i candies. Also, Dawid has two friends. He wants to give each bag to one of his two friends. Is it possible to distribute the bags in such a way that each friend receives the same amount of candies in total? Note, that you can't keep bags for yourself or thro...
#include <bits/stdc++.h> using namespace std; int main() { int a[4], i; for (i = 0; i < 4; i++) cin >> a[i]; sort(a, a + 4); if (a[0] + a[3] == a[1] + a[2]) { cout << "YES" << endl; } else if (a[0] + a[1] + a[2] == a[3]) cout << "YES" << endl; else { cout << "NO" << endl; } return 0; }
2C++
{ "input": [ "1 7 11 5\n", "7 3 2 5\n", "44 58 90 53\n", "20 14 37 71\n", "4 2 4 2\n", "1 2 5 5\n", "1 2 8 9\n", "99 100 3 98\n", "92 69 83 97\n", "3 1 1 1\n", "18 88 18 18\n", "1 1 1 1\n", "69 7 44 30\n", "90 30 30 30\n", "1 2 3 5\n", "1 1 3 1\n", "...
2CODEFORCES
1230_A. Dawid and Bags of Candies_1813
Dawid has four bags of candies. The i-th of them contains a_i candies. Also, Dawid has two friends. He wants to give each bag to one of his two friends. Is it possible to distribute the bags in such a way that each friend receives the same amount of candies in total? Note, that you can't keep bags for yourself or thro...
list1 = list(map(int, input().split())) list1.sort() if list1[0] + list1[3] == list1[1] + list1[2]: print("YES") elif list1[0] + list1[2] +list1[1] == list1[3]: print("YES") else: print("NO")
3Python3
{ "input": [ "1 7 11 5\n", "7 3 2 5\n", "44 58 90 53\n", "20 14 37 71\n", "4 2 4 2\n", "1 2 5 5\n", "1 2 8 9\n", "99 100 3 98\n", "92 69 83 97\n", "3 1 1 1\n", "18 88 18 18\n", "1 1 1 1\n", "69 7 44 30\n", "90 30 30 30\n", "1 2 3 5\n", "1 1 3 1\n", "...
2CODEFORCES
1230_A. Dawid and Bags of Candies_1814
Dawid has four bags of candies. The i-th of them contains a_i candies. Also, Dawid has two friends. He wants to give each bag to one of his two friends. Is it possible to distribute the bags in such a way that each friend receives the same amount of candies in total? Note, that you can't keep bags for yourself or thro...
import java.util.Scanner; /** * * @author MiloMurphy */ public class DashaA { public static void main(String[] args) { Scanner s = new Scanner(System.in); int a = s.nextInt(); int b = s.nextInt(); int c = s.nextInt(); int d = s.nextInt(); if((a ...
4JAVA
{ "input": [ "1 7 11 5\n", "7 3 2 5\n", "44 58 90 53\n", "20 14 37 71\n", "4 2 4 2\n", "1 2 5 5\n", "1 2 8 9\n", "99 100 3 98\n", "92 69 83 97\n", "3 1 1 1\n", "18 88 18 18\n", "1 1 1 1\n", "69 7 44 30\n", "90 30 30 30\n", "1 2 3 5\n", "1 1 3 1\n", "...
2CODEFORCES
1251_E1. Voting (Easy Version)_1815
The only difference between easy and hard versions is constraints. Now elections are held in Berland and you want to win them. More precisely, you want everyone to vote for you. There are n voters, and two ways to convince each of them to vote for you. The first way to convince the i-th voter is to pay him p_i coins....
import heapq t = int(input()) for _ in range(t): n = int(input()) arr = [] for i in range(n): m,p = map(int,raw_input().split(" ")) arr.append((-m,p,i)) arr.sort() cnt = 1 s = 0 ans = 0 visited= [0]*n pq = [] heapq.heappush(pq,(arr[0][1],-arr[0][0],arr[0][2])) for i in range(1,n): if arr[i-1][0] == a...
1Python2
{ "input": [ "3\n3\n1 5\n2 10\n2 8\n7\n0 1\n3 1\n1 1\n6 1\n1 1\n4 1\n4 1\n6\n2 6\n2 3\n2 8\n2 7\n4 4\n5 5\n", "3\n3\n1 5\n2 10\n2 4\n7\n0 1\n3 1\n1 1\n6 1\n1 1\n4 1\n4 1\n6\n2 6\n2 3\n2 8\n2 7\n4 4\n5 5\n", "3\n3\n1 5\n2 10\n2 8\n7\n0 1\n1 1\n1 1\n6 1\n1 1\n4 1\n4 1\n6\n2 6\n2 3\n2 8\n2 7\n4 4\n5 5\n", ...
2CODEFORCES
1251_E1. Voting (Easy Version)_1816
The only difference between easy and hard versions is constraints. Now elections are held in Berland and you want to win them. More precisely, you want everyone to vote for you. There are n voters, and two ways to convince each of them to vote for you. The first way to convince the i-th voter is to pay him p_i coins....
#include <bits/stdc++.h> using namespace std; const int N = 5050; int a[N], b[N], pref[N]; vector<int> all[N]; int main() { int t; scanf("%i", &t); while (t--) { int n; scanf("%i", &n); for (int i = 0; i < n; i++) all[i].clear(); for (int i = 1; i <= n; i++) scanf("%i%i", &a[i], &b[i]), all[...
2C++
{ "input": [ "3\n3\n1 5\n2 10\n2 8\n7\n0 1\n3 1\n1 1\n6 1\n1 1\n4 1\n4 1\n6\n2 6\n2 3\n2 8\n2 7\n4 4\n5 5\n", "3\n3\n1 5\n2 10\n2 4\n7\n0 1\n3 1\n1 1\n6 1\n1 1\n4 1\n4 1\n6\n2 6\n2 3\n2 8\n2 7\n4 4\n5 5\n", "3\n3\n1 5\n2 10\n2 8\n7\n0 1\n1 1\n1 1\n6 1\n1 1\n4 1\n4 1\n6\n2 6\n2 3\n2 8\n2 7\n4 4\n5 5\n", ...
2CODEFORCES
1251_E1. Voting (Easy Version)_1817
The only difference between easy and hard versions is constraints. Now elections are held in Berland and you want to win them. More precisely, you want everyone to vote for you. There are n voters, and two ways to convince each of them to vote for you. The first way to convince the i-th voter is to pay him p_i coins....
import sys from heapq import * #sys.stdin = open('in', 'r') t = int(input()) for ti in range(t): n = int(input()) a = [] for i in range(n): mi, pi = map(int, input().split()) a.append((mi, -pi)) a.sort() c = 0 h = [] res = 0 for i in reversed(range(n)): heappush(h...
3Python3
{ "input": [ "3\n3\n1 5\n2 10\n2 8\n7\n0 1\n3 1\n1 1\n6 1\n1 1\n4 1\n4 1\n6\n2 6\n2 3\n2 8\n2 7\n4 4\n5 5\n", "3\n3\n1 5\n2 10\n2 4\n7\n0 1\n3 1\n1 1\n6 1\n1 1\n4 1\n4 1\n6\n2 6\n2 3\n2 8\n2 7\n4 4\n5 5\n", "3\n3\n1 5\n2 10\n2 8\n7\n0 1\n1 1\n1 1\n6 1\n1 1\n4 1\n4 1\n6\n2 6\n2 3\n2 8\n2 7\n4 4\n5 5\n", ...
2CODEFORCES
1251_E1. Voting (Easy Version)_1818
The only difference between easy and hard versions is constraints. Now elections are held in Berland and you want to win them. More precisely, you want everyone to vote for you. There are n voters, and two ways to convince each of them to vote for you. The first way to convince the i-th voter is to pay him p_i coins....
import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; public class voting { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); StringBuilder sb = new StringBuilder(); for(int r=0;r<t;r++) { int n = sc.nextInt(); State[] s= new St...
4JAVA
{ "input": [ "3\n3\n1 5\n2 10\n2 8\n7\n0 1\n3 1\n1 1\n6 1\n1 1\n4 1\n4 1\n6\n2 6\n2 3\n2 8\n2 7\n4 4\n5 5\n", "3\n3\n1 5\n2 10\n2 4\n7\n0 1\n3 1\n1 1\n6 1\n1 1\n4 1\n4 1\n6\n2 6\n2 3\n2 8\n2 7\n4 4\n5 5\n", "3\n3\n1 5\n2 10\n2 8\n7\n0 1\n1 1\n1 1\n6 1\n1 1\n4 1\n4 1\n6\n2 6\n2 3\n2 8\n2 7\n4 4\n5 5\n", ...
2CODEFORCES
1271_C. Shawarma Tent_1819
The map of the capital of Berland can be viewed on the infinite coordinate plane. Each point with integer coordinates contains a building, and there are streets connecting every building to four neighbouring buildings. All streets are parallel to the coordinate axes. The main school of the capital is located in (s_x, ...
from __future__ import division, print_function import os import sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip def main(): n, sx, sy = map(int, input().split()) first, second, third, fo...
1Python2
{ "input": [ "7 10 12\n5 6\n20 23\n15 4\n16 5\n4 54\n12 1\n4 15\n", "4 3 2\n1 3\n4 2\n5 1\n4 1\n", "3 100 100\n0 0\n0 0\n100 200\n", "1 1000000000 7\n1000000000 9\n", "3 2 2\n2 4\n2 1\n3 6\n", "2 1000000000 100000\n1000000000 1000000\n1000000000 10000\n", "1 100 100\n50 70\n", "1 100 1...
2CODEFORCES
1271_C. Shawarma Tent_1820
The map of the capital of Berland can be viewed on the infinite coordinate plane. Each point with integer coordinates contains a building, and there are streets connecting every building to four neighbouring buildings. All streets are parallel to the coordinate axes. The main school of the capital is located in (s_x, ...
#include <bits/stdc++.h> using namespace std; long long int xpow(long long int a, long long int b) { if (b == 0) return 1; if (b % 2 == 0) { long long int k = xpow(a, b / 2); return k * k; } if (b % 2 != 0) return a * xpow(a, b - 1); } int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout...
2C++
{ "input": [ "7 10 12\n5 6\n20 23\n15 4\n16 5\n4 54\n12 1\n4 15\n", "4 3 2\n1 3\n4 2\n5 1\n4 1\n", "3 100 100\n0 0\n0 0\n100 200\n", "1 1000000000 7\n1000000000 9\n", "3 2 2\n2 4\n2 1\n3 6\n", "2 1000000000 100000\n1000000000 1000000\n1000000000 10000\n", "1 100 100\n50 70\n", "1 100 1...
2CODEFORCES
1271_C. Shawarma Tent_1821
The map of the capital of Berland can be viewed on the infinite coordinate plane. Each point with integer coordinates contains a building, and there are streets connecting every building to four neighbouring buildings. All streets are parallel to the coordinate axes. The main school of the capital is located in (s_x, ...
n,x,y=map(int,input().split()) lu=0 ld=0 ru=0 rd=0 u=0 d=0 l=0 r=0 for i in range(n): a,b=map(int,input().split()) if(a<x and b<y): ld+=1 elif(a<x and b>y): lu+=1 elif(a==x and b!=y): if(b>y): u+=1 else: d+=1 elif(a>x and b<y): rd+=1 ...
3Python3
{ "input": [ "7 10 12\n5 6\n20 23\n15 4\n16 5\n4 54\n12 1\n4 15\n", "4 3 2\n1 3\n4 2\n5 1\n4 1\n", "3 100 100\n0 0\n0 0\n100 200\n", "1 1000000000 7\n1000000000 9\n", "3 2 2\n2 4\n2 1\n3 6\n", "2 1000000000 100000\n1000000000 1000000\n1000000000 10000\n", "1 100 100\n50 70\n", "1 100 1...
2CODEFORCES
1271_C. Shawarma Tent_1822
The map of the capital of Berland can be viewed on the infinite coordinate plane. Each point with integer coordinates contains a building, and there are streets connecting every building to four neighbouring buildings. All streets are parallel to the coordinate axes. The main school of the capital is located in (s_x, ...
import java.io.*; import java.util.*; public class Main { static point a[]; static int check(int wx, int wy, int sx, int sy) { //waurma int cnt = 0; for (int i = 0; i < a.length; i++) { int x = a[i].x; int y = a[i].y; if (wx >= Math.min(sx, x) && wy >= Math...
4JAVA
{ "input": [ "7 10 12\n5 6\n20 23\n15 4\n16 5\n4 54\n12 1\n4 15\n", "4 3 2\n1 3\n4 2\n5 1\n4 1\n", "3 100 100\n0 0\n0 0\n100 200\n", "1 1000000000 7\n1000000000 9\n", "3 2 2\n2 4\n2 1\n3 6\n", "2 1000000000 100000\n1000000000 1000000\n1000000000 10000\n", "1 100 100\n50 70\n", "1 100 1...
2CODEFORCES
1294_D. MEX maximizing_1823
Recall that MEX of an array is a minimum non-negative integer that does not belong to the array. Examples: * for the array [0, 0, 1, 0, 2] MEX equals to 3 because numbers 0, 1 and 2 are presented in the array and 3 is the minimum non-negative integer not presented in the array; * for the array [1, 2, 3, 4] MEX eq...
from collections import Counter, defaultdict from sys import stdin, stdout raw_input = stdin.readline #d=Counter() q,x=map(int,raw_input().split()) d=[0]*x ans=0 c=x var=0 for q in xrange(q): y=input() d[y%x]+=1 while d[ans]>var: ans+=1 if ans==x: var+=1 ans=0 ...
1Python2
{ "input": [ "4 3\n1\n2\n1\n2\n", "7 3\n0\n1\n2\n2\n0\n0\n10\n", "4 3\n1\n2\n1\n3\n", "3 3\n0\n1\n2\n2\n0\n0\n10\n", "4 2\n1\n2\n1\n0\n", "4 2\n1\n3\n1\n0\n", "4 2\n1\n3\n2\n0\n", "4 2\n0\n3\n2\n0\n", "3 2\n0\n6\n2\n0\n", "2 3\n0\n0\n3\n-1\n", "3 3\n0\n0\n1\n-2\n", "3 3...
2CODEFORCES
1294_D. MEX maximizing_1824
Recall that MEX of an array is a minimum non-negative integer that does not belong to the array. Examples: * for the array [0, 0, 1, 0, 2] MEX equals to 3 because numbers 0, 1 and 2 are presented in the array and 3 is the minimum non-negative integer not presented in the array; * for the array [1, 2, 3, 4] MEX eq...
#include <bits/stdc++.h> using namespace std; const long long int N = 1e5 + 5; void solve() { long long int n, q, x, y, z, w, mini, maxi = INT_MAX, prev; cin >> q >> x; unordered_map<long long int, int> m1, m2; y = 0; while (q--) { cin >> n; n %= x; m1[x * m2[n] + n]++; m2[n]++; while (m1[...
2C++
{ "input": [ "4 3\n1\n2\n1\n2\n", "7 3\n0\n1\n2\n2\n0\n0\n10\n", "4 3\n1\n2\n1\n3\n", "3 3\n0\n1\n2\n2\n0\n0\n10\n", "4 2\n1\n2\n1\n0\n", "4 2\n1\n3\n1\n0\n", "4 2\n1\n3\n2\n0\n", "4 2\n0\n3\n2\n0\n", "3 2\n0\n6\n2\n0\n", "2 3\n0\n0\n3\n-1\n", "3 3\n0\n0\n1\n-2\n", "3 3...
2CODEFORCES
1294_D. MEX maximizing_1825
Recall that MEX of an array is a minimum non-negative integer that does not belong to the array. Examples: * for the array [0, 0, 1, 0, 2] MEX equals to 3 because numbers 0, 1 and 2 are presented in the array and 3 is the minimum non-negative integer not presented in the array; * for the array [1, 2, 3, 4] MEX eq...
import os from io import BytesIO, IOBase import sys from collections import defaultdict, deque, Counter from bisect import * from math import sqrt, pi, ceil, log, inf,gcd from itertools import permutations from copy import deepcopy from heapq import * from sys import setrecursionlimit def main(): q, x = map(int, in...
3Python3
{ "input": [ "4 3\n1\n2\n1\n2\n", "7 3\n0\n1\n2\n2\n0\n0\n10\n", "4 3\n1\n2\n1\n3\n", "3 3\n0\n1\n2\n2\n0\n0\n10\n", "4 2\n1\n2\n1\n0\n", "4 2\n1\n3\n1\n0\n", "4 2\n1\n3\n2\n0\n", "4 2\n0\n3\n2\n0\n", "3 2\n0\n6\n2\n0\n", "2 3\n0\n0\n3\n-1\n", "3 3\n0\n0\n1\n-2\n", "3 3...
2CODEFORCES
1294_D. MEX maximizing_1826
Recall that MEX of an array is a minimum non-negative integer that does not belong to the array. Examples: * for the array [0, 0, 1, 0, 2] MEX equals to 3 because numbers 0, 1 and 2 are presented in the array and 3 is the minimum non-negative integer not presented in the array; * for the array [1, 2, 3, 4] MEX eq...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class hello2 {static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new Buffered...
4JAVA
{ "input": [ "4 3\n1\n2\n1\n2\n", "7 3\n0\n1\n2\n2\n0\n0\n10\n", "4 3\n1\n2\n1\n3\n", "3 3\n0\n1\n2\n2\n0\n0\n10\n", "4 2\n1\n2\n1\n0\n", "4 2\n1\n3\n1\n0\n", "4 2\n1\n3\n2\n0\n", "4 2\n0\n3\n2\n0\n", "3 2\n0\n6\n2\n0\n", "2 3\n0\n0\n3\n-1\n", "3 3\n0\n0\n1\n-2\n", "3 3...
2CODEFORCES
1315_D. Recommendations_1827
VK news recommendation system daily selects interesting publications of one of n disjoint categories for each user. Each publication belongs to exactly one category. For each category i batch algorithm selects a_i publications. The latest A/B test suggests that users are reading recommended publications more actively ...
#include <bits/stdc++.h> using namespace std; const int MAX = (2e5) + 10; pair<int, int> ara[MAX]; int id[MAX]; vector<int> didi[MAX]; void solve() { int n; cin >> n; for (int i = 0; i <= n - 1; i++) { cin >> ara[i].first; } for (int i = 0; i <= n - 1; i++) { cin >> ara[i].second; } sort(ara, ara ...
2C++
{ "input": [ "5\n3 7 9 7 8\n5 2 5 7 5\n", "5\n1 2 3 4 5\n1 1 1 1 1\n", "5\n1000000000 1000000000 1000000000 1000000000 1000000000\n100000 100000 100000 100000 100000\n", "10\n14 31 50 67 42 44 86 82 35 63\n76 17 26 44 60 54 50 73 71 70\n", "10\n4 4 1 2 2 2 5 4 1 5\n28 81 36 44 2 40 39 43 36 33\n",...
2CODEFORCES
1315_D. Recommendations_1828
VK news recommendation system daily selects interesting publications of one of n disjoint categories for each user. Each publication belongs to exactly one category. For each category i batch algorithm selects a_i publications. The latest A/B test suggests that users are reading recommended publications more actively ...
# Код программы написал на языке Python 3 import sys from heapq import heappush, heappop def main(): n = int(sys.stdin.readline()) h = sorted(list(zip([int(i) for i in sys.stdin.readline().split()], [int(i) for i in sys.stdin.readline().split()]))) z, w, o, res = [], 0, 0, 0 while o < n: ...
3Python3
{ "input": [ "5\n3 7 9 7 8\n5 2 5 7 5\n", "5\n1 2 3 4 5\n1 1 1 1 1\n", "5\n1000000000 1000000000 1000000000 1000000000 1000000000\n100000 100000 100000 100000 100000\n", "10\n14 31 50 67 42 44 86 82 35 63\n76 17 26 44 60 54 50 73 71 70\n", "10\n4 4 1 2 2 2 5 4 1 5\n28 81 36 44 2 40 39 43 36 33\n",...
2CODEFORCES
1315_D. Recommendations_1829
VK news recommendation system daily selects interesting publications of one of n disjoint categories for each user. Each publication belongs to exactly one category. For each category i batch algorithm selects a_i publications. The latest A/B test suggests that users are reading recommended publications more actively ...
import java.io.*; import java.util.*; import java.text.*; public final class isc { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String nex...
4JAVA
{ "input": [ "5\n3 7 9 7 8\n5 2 5 7 5\n", "5\n1 2 3 4 5\n1 1 1 1 1\n", "5\n1000000000 1000000000 1000000000 1000000000 1000000000\n100000 100000 100000 100000 100000\n", "10\n14 31 50 67 42 44 86 82 35 63\n76 17 26 44 60 54 50 73 71 70\n", "10\n4 4 1 2 2 2 5 4 1 5\n28 81 36 44 2 40 39 43 36 33\n",...
2CODEFORCES
1336_F. Journey_1830
In the wilds far beyond lies the Land of Sacredness, which can be viewed as a tree — connected undirected graph consisting of n nodes and n-1 edges. The nodes are numbered from 1 to n. There are m travelers attracted by its prosperity and beauty. Thereupon, they set off their journey on this land. The i-th traveler w...
#include <bits/stdc++.h> using namespace std; const int maxn = 150001; struct BIT { int bit[maxn]; BIT() { memset(bit, 0, sizeof(bit)); } void add(int x, int v) { for (x++; x < maxn; x += x & -x) bit[x] += v; } void add(int a, int b, int v) { add(a, 1), add(b + 1, -1); } int qry(int x) { int ret = 0...
2C++
{ "input": [ "13 8 3\n7 6\n9 11\n5 6\n11 3\n9 7\n2 12\n4 3\n1 2\n5 8\n6 13\n5 10\n3 1\n10 4\n10 11\n8 11\n4 9\n2 5\n3 5\n7 3\n8 10\n", "8 4 1\n1 7\n1 2\n2 5\n4 6\n6 3\n6 2\n6 8\n7 8\n3 8\n2 6\n4 1\n", "10 4 2\n3 10\n9 3\n4 9\n4 6\n8 2\n1 7\n2 1\n4 5\n6 7\n7 1\n8 7\n9 2\n10 3\n", "30 30 10\n6 1\n8 27\n...
2CODEFORCES
1359_D. Yet Another Yet Another Task_1831
Alice and Bob are playing yet another card game. This time the rules are the following. There are n cards lying in a row in front of them. The i-th card has value a_i. First, Alice chooses a non-empty consecutive segment of cards [l; r] (l ≤ r). After that Bob removes a single card j from that segment (l ≤ j ≤ r). Th...
from collections import Counter, defaultdict, deque import bisect from sys import stdin, stdout from itertools import repeat import math # sys.stdin = open('input') def inp(force_list=False): re = map(int, raw_input().split()) if len(re) == 1 and not force_list: return re[0] return re def inst():...
1Python2
{ "input": [ "3\n-10 6 -15\n", "8\n5 2 5 3 -30 -30 6 9\n", "5\n5 -2 10 -1 4\n", "10\n-3 4 -4 1 1 -4 -5 3 -4 -2\n", "10\n8 9 -10 -10 -4 -3 5 9 -9 9\n", "6\n5 -4 2 -1 2 -2\n", "11\n3 0 1 -2 5 -5 -1 0 3 2 2\n", "10\n4 -2 -2 -2 2 0 1 0 -4 -1\n", "4\n2 2 -3 4\n", "11\n-11 -7 -2 -24 ...
2CODEFORCES
1359_D. Yet Another Yet Another Task_1832
Alice and Bob are playing yet another card game. This time the rules are the following. There are n cards lying in a row in front of them. The i-th card has value a_i. First, Alice chooses a non-empty consecutive segment of cards [l; r] (l ≤ r). After that Bob removes a single card j from that segment (l ≤ j ≤ r). Th...
#include <bits/stdc++.h> using namespace std; long long M = 1e9 + 7; double pi = acos(-1.0); long long powerm(long long x, long long y) { long long res = 1; while (y) { if (y & 1) res = (res * x) % M; y = y >> 1; x = (x * x) % M; } return res % M; } long long power(long long x, long long y) { long...
2C++
{ "input": [ "3\n-10 6 -15\n", "8\n5 2 5 3 -30 -30 6 9\n", "5\n5 -2 10 -1 4\n", "10\n-3 4 -4 1 1 -4 -5 3 -4 -2\n", "10\n8 9 -10 -10 -4 -3 5 9 -9 9\n", "6\n5 -4 2 -1 2 -2\n", "11\n3 0 1 -2 5 -5 -1 0 3 2 2\n", "10\n4 -2 -2 -2 2 0 1 0 -4 -1\n", "4\n2 2 -3 4\n", "11\n-11 -7 -2 -24 ...
2CODEFORCES
1359_D. Yet Another Yet Another Task_1833
Alice and Bob are playing yet another card game. This time the rules are the following. There are n cards lying in a row in front of them. The i-th card has value a_i. First, Alice chooses a non-empty consecutive segment of cards [l; r] (l ≤ r). After that Bob removes a single card j from that segment (l ≤ j ≤ r). Th...
import math import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) ans = 0 for i in range(31): s = 0 for j in a: if j <= i: s = max(0, s + j) else: s = 0 ans = max(ans, s - i) print(ans)
3Python3
{ "input": [ "3\n-10 6 -15\n", "8\n5 2 5 3 -30 -30 6 9\n", "5\n5 -2 10 -1 4\n", "10\n-3 4 -4 1 1 -4 -5 3 -4 -2\n", "10\n8 9 -10 -10 -4 -3 5 9 -9 9\n", "6\n5 -4 2 -1 2 -2\n", "11\n3 0 1 -2 5 -5 -1 0 3 2 2\n", "10\n4 -2 -2 -2 2 0 1 0 -4 -1\n", "4\n2 2 -3 4\n", "11\n-11 -7 -2 -24 ...
2CODEFORCES
1359_D. Yet Another Yet Another Task_1834
Alice and Bob are playing yet another card game. This time the rules are the following. There are n cards lying in a row in front of them. The i-th card has value a_i. First, Alice chooses a non-empty consecutive segment of cards [l; r] (l ≤ r). After that Bob removes a single card j from that segment (l ≤ j ≤ r). Th...
import java.util.*; import java.lang.*; import java.io.*; import java.io.*; public class Main { static int INF = 1000000000; public static void main(String[] args) throws IOException { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); long []orig = new long[n]; for(i...
4JAVA
{ "input": [ "3\n-10 6 -15\n", "8\n5 2 5 3 -30 -30 6 9\n", "5\n5 -2 10 -1 4\n", "10\n-3 4 -4 1 1 -4 -5 3 -4 -2\n", "10\n8 9 -10 -10 -4 -3 5 9 -9 9\n", "6\n5 -4 2 -1 2 -2\n", "11\n3 0 1 -2 5 -5 -1 0 3 2 2\n", "10\n4 -2 -2 -2 2 0 1 0 -4 -1\n", "4\n2 2 -3 4\n", "11\n-11 -7 -2 -24 ...
2CODEFORCES
1379_F1. Chess Strikes Back (easy version)_1835
Note that the difference between easy and hard versions is that in hard version unavailable cells can become available again and in easy version can't. You can make hacks only if all versions are solved. Ildar and Ivan are tired of chess, but they really like the chessboard, so they invented a new game. The field is a...
#include <bits/stdc++.h> using namespace std; using ll = long long; unsigned euclidean_gcd(unsigned a, unsigned b) { if (a < b) return euclidean_gcd(b, a); unsigned r; while ((r = a % b)) { a = b; b = r; } return b; } ll ll_gcd(ll a, ll b) { if (a < b) return ll_gcd(b, a); ll r; while ((r = a % ...
2C++
{ "input": [ "1 3 3\n1 1\n1 5\n2 4\n", "3 2 7\n4 2\n6 4\n1 3\n2 2\n2 4\n4 4\n3 1\n", "3 3 20\n4 4\n2 4\n2 2\n2 2\n2 2\n5 5\n2 2\n2 2\n2 2\n5 5\n5 5\n3 5\n4 2\n2 2\n5 5\n5 5\n3 5\n5 5\n2 2\n3 3\n", "1 10 10\n1 19\n2 12\n2 8\n2 16\n2 2\n2 4\n1 9\n2 18\n2 14\n2 10\n", "10 10 10\n2 6\n17 7\n5 19\n14 1...
2CODEFORCES
1379_F1. Chess Strikes Back (easy version)_1836
Note that the difference between easy and hard versions is that in hard version unavailable cells can become available again and in easy version can't. You can make hacks only if all versions are solved. Ildar and Ivan are tired of chess, but they really like the chessboard, so they invented a new game. The field is a...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Set; import java.util.HashMap; import java.io.IOException; import java.util.Random; import java.io.InputStreamReader; import java.util.TreeSet; import java.util.Stri...
4JAVA
{ "input": [ "1 3 3\n1 1\n1 5\n2 4\n", "3 2 7\n4 2\n6 4\n1 3\n2 2\n2 4\n4 4\n3 1\n", "3 3 20\n4 4\n2 4\n2 2\n2 2\n2 2\n5 5\n2 2\n2 2\n2 2\n5 5\n5 5\n3 5\n4 2\n2 2\n5 5\n5 5\n3 5\n5 5\n2 2\n3 3\n", "1 10 10\n1 19\n2 12\n2 8\n2 16\n2 2\n2 4\n1 9\n2 18\n2 14\n2 10\n", "10 10 10\n2 6\n17 7\n5 19\n14 1...
2CODEFORCES
139_D. Digits Permutations_1837
Andrey's favourite number is n. Andrey's friends gave him two identical numbers n as a New Year present. He hung them on a wall and watched them adoringly. Then Andrey got bored from looking at the same number and he started to swap digits first in one, then in the other number, then again in the first number and so o...
import sys def d( digits ): pair9s = {} for i in range(10): pair9s[i] = 9 - i baseCounts = [0]*10 for digit in digits: baseCounts[int(digit)] += 1 iTen = -1 mxZeros = 0 for i in range(1,6): countsa = baseCounts[:] countsb = baseCounts[:] zeros=0 i10 = 10 - i mn9s = [0]*10 mni...
1Python2
{ "input": [ "500\n", "198\n", "545\n", "2603340571199714716025114079373828413509944752618962350632892540710372640383149198328312562980217104434880337288055817064\n", "670042\n", "1099\n", "8679647744\n", "5057017252180797906185\n", "404\n", "4877\n", "7665711\n", "3467...
2CODEFORCES
139_D. Digits Permutations_1838
Andrey's favourite number is n. Andrey's friends gave him two identical numbers n as a New Year present. He hung them on a wall and watched them adoringly. Then Andrey got bored from looking at the same number and he started to swap digits first in one, then in the other number, then again in the first number and so o...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; char s[N]; int cnt1[10], cnt2[10]; int mi[5]; int ma, mx = -1; int c[10][2] = {{5, 5}, {1, 9}, {2, 8}, {3, 7}, {4, 6}}; int cc[10][2] = {{0, 9}, {5, 4}, {1, 8}, {2, 7}, {3, 6}}; string a1, a2; int main() { scanf("%s", s); int n = strlen(s); for...
2C++
{ "input": [ "500\n", "198\n", "545\n", "2603340571199714716025114079373828413509944752618962350632892540710372640383149198328312562980217104434880337288055817064\n", "670042\n", "1099\n", "8679647744\n", "5057017252180797906185\n", "404\n", "4877\n", "7665711\n", "3467...
2CODEFORCES
139_D. Digits Permutations_1839
Andrey's favourite number is n. Andrey's friends gave him two identical numbers n as a New Year present. He hung them on a wall and watched them adoringly. Then Andrey got bored from looking at the same number and he started to swap digits first in one, then in the other number, then again in the first number and so o...
import itertools def countZeroes(s): ret = 0 for i in s: if i != '0': break ret += 1 return ret def stupid(n): ansMax = 0 bn1 = n bn2 = n for n1 in itertools.permutations(n): for n2 in itertools.permutations(n): val = str(int(''.join(n1)) + i...
3Python3
{ "input": [ "500\n", "198\n", "545\n", "2603340571199714716025114079373828413509944752618962350632892540710372640383149198328312562980217104434880337288055817064\n", "670042\n", "1099\n", "8679647744\n", "5057017252180797906185\n", "404\n", "4877\n", "7665711\n", "3467...
2CODEFORCES
139_D. Digits Permutations_1840
Andrey's favourite number is n. Andrey's friends gave him two identical numbers n as a New Year present. He hung them on a wall and watched them adoringly. Then Andrey got bored from looking at the same number and he started to swap digits first in one, then in the other number, then again in the first number and so o...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; public class Solution { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); ...
4JAVA
{ "input": [ "500\n", "198\n", "545\n", "2603340571199714716025114079373828413509944752618962350632892540710372640383149198328312562980217104434880337288055817064\n", "670042\n", "1099\n", "8679647744\n", "5057017252180797906185\n", "404\n", "4877\n", "7665711\n", "3467...
2CODEFORCES
1423_H. Virus_1841
In Bubbleland a group of special programming forces gets a top secret job to calculate the number of potentially infected people by a new unknown virus. The state has a population of n people and every day there is new information about new contacts between people. The job of special programming forces is to calculate ...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 10; int components, n, m, k; ifstream in; ofstream out; map<pair<int, int>, int> start; int ans[N], p[N], s[N]; vector<pair<int, int> > need[N + 1]; struct Query { int u, v; bool must_rollback; }; vector<Query> tree[N + 1 << 2]; struct Save { int u...
2C++
{ "input": [ "10 25 2\n1 9 3\n2 5\n1 1 3\n1 3 1\n2 2\n1 8 3\n1 5 6\n3\n1 9 2\n1 8 3\n2 9\n1 3 1\n2 5\n1 6 4\n3\n3\n2 4\n3\n1 10 9\n1 1 7\n3\n2 2\n3\n1 5 6\n1 1 4\n", "5 12 1\n1 1 2\n1 1 3\n1 3 4\n2 4\n2 5\n3\n2 1\n1 1 2\n1 3 2\n2 1\n3\n2 1\n", "5 12 2\n1 1 2\n1 1 3\n1 3 4\n2 4\n2 5\n3\n2 1\n1 1 2\n1 3 2\n...
2CODEFORCES
1423_H. Virus_1842
In Bubbleland a group of special programming forces gets a top secret job to calculate the number of potentially infected people by a new unknown virus. The state has a population of n people and every day there is new information about new contacts between people. The job of special programming forces is to calculate ...
//package bubblecup13.f; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class H { InputStream is; PrintWriter out; String INPUT = ""; void solve() { int n = ni(),...
4JAVA
{ "input": [ "10 25 2\n1 9 3\n2 5\n1 1 3\n1 3 1\n2 2\n1 8 3\n1 5 6\n3\n1 9 2\n1 8 3\n2 9\n1 3 1\n2 5\n1 6 4\n3\n3\n2 4\n3\n1 10 9\n1 1 7\n3\n2 2\n3\n1 5 6\n1 1 4\n", "5 12 1\n1 1 2\n1 1 3\n1 3 4\n2 4\n2 5\n3\n2 1\n1 1 2\n1 3 2\n2 1\n3\n2 1\n", "5 12 2\n1 1 2\n1 1 3\n1 3 4\n2 4\n2 5\n3\n2 1\n1 1 2\n1 3 2\n...
2CODEFORCES
1443_A. Kids Seating_1843
Today the kindergarten has a new group of n kids who need to be seated at the dinner table. The chairs at the table are numbered from 1 to 4n. Two kids can't sit on the same chair. It is known that two kids who sit on chairs with numbers a and b (a ≠ b) will indulge if: 1. gcd(a, b) = 1 or, 2. a divides b or b d...
#!/usr/bin/env python from __future__ import division, print_function import os import sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip def main(): t = int(input()) for _ in range(t):...
1Python2
{ "input": [ "3\n2\n3\n4\n", "3\n2\n3\n4\n", "100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n...
2CODEFORCES
1443_A. Kids Seating_1844
Today the kindergarten has a new group of n kids who need to be seated at the dinner table. The chairs at the table are numbered from 1 to 4n. Two kids can't sit on the same chair. It is known that two kids who sit on chairs with numbers a and b (a ≠ b) will indulge if: 1. gcd(a, b) = 1 or, 2. a divides b or b d...
#include <bits/stdc++.h> using namespace std; vector<int> pr[405]; void prime(int n) { for (int i = 2; i < n * n; i++) { if (n % i == 0) { pr[n].push_back(i); while (n % i == 0) n /= i; } } } int main() { ios_base::sync_with_stdio(false); int t; cin >> t; while (t--) { int n; cin...
2C++
{ "input": [ "3\n2\n3\n4\n", "3\n2\n3\n4\n", "100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n...
2CODEFORCES
1443_A. Kids Seating_1845
Today the kindergarten has a new group of n kids who need to be seated at the dinner table. The chairs at the table are numbered from 1 to 4n. Two kids can't sit on the same chair. It is known that two kids who sit on chairs with numbers a and b (a ≠ b) will indulge if: 1. gcd(a, b) = 1 or, 2. a divides b or b d...
# cook your dish here for _ in range(int(input())): n=int(input()) s=4*n-2 for i in range(n): print(s,end=" ") s-=2 print()
3Python3
{ "input": [ "3\n2\n3\n4\n", "3\n2\n3\n4\n", "100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n...
2CODEFORCES
1443_A. Kids Seating_1846
Today the kindergarten has a new group of n kids who need to be seated at the dinner table. The chairs at the table are numbered from 1 to 4n. Two kids can't sit on the same chair. It is known that two kids who sit on chairs with numbers a and b (a ≠ b) will indulge if: 1. gcd(a, b) = 1 or, 2. a divides b or b d...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class codefo { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(ne...
4JAVA
{ "input": [ "3\n2\n3\n4\n", "3\n2\n3\n4\n", "100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n...
2CODEFORCES
1468_J. Road Reform_1847
There are n cities and m bidirectional roads in Berland. The i-th road connects the cities x_i and y_i, and has the speed limit s_i. The road network allows everyone to get from any city to any other city. The Berland Transport Ministry is planning a road reform. First of all, maintaining all m roads is too costly, ...
from sys import stdin class disjointset: def __init__(self, n): self.rank, self.parent= [0] * (n + 1), [i for i in range(n + 1)] def find(self, x): xcopy = x while x != self.parent[x]: x = self.parent[x] while xcopy != x: self.parent[xcopy], xcopy = x,...
1Python2
{ "input": [ "4\n4 5 7\n4 1 3\n1 2 5\n2 3 8\n2 4 1\n3 4 4\n4 6 5\n1 2 1\n1 3 1\n1 4 2\n2 4 1\n4 3 1\n3 2 1\n3 2 10\n1 2 8\n1 3 10\n5 5 15\n1 2 17\n3 1 15\n2 3 10\n1 4 14\n2 5 8\n", "4\n4 5 7\n4 2 3\n1 2 5\n2 3 8\n2 4 1\n3 4 4\n4 6 5\n1 2 1\n1 3 1\n1 4 2\n2 4 1\n4 3 1\n3 2 1\n3 2 10\n1 2 8\n1 3 10\n5 5 15\n1 2...
2CODEFORCES
1468_J. Road Reform_1848
There are n cities and m bidirectional roads in Berland. The i-th road connects the cities x_i and y_i, and has the speed limit s_i. The road network allows everyone to get from any city to any other city. The Berland Transport Ministry is planning a road reform. First of all, maintaining all m roads is too costly, ...
#include <bits/stdc++.h> #define startt ios_base::sync_with_stdio(false);cin.tie(0); typedef long long ll; using namespace std; #define vint vector<int> #define all(v) v.begin(), v.end() #define MOD 1000000007 #define MOD2 998244353 #define MX 1000000000 #define MXL 1000000000000000000 #define PI 3.14159265 #define pb...
2C++
{ "input": [ "4\n4 5 7\n4 1 3\n1 2 5\n2 3 8\n2 4 1\n3 4 4\n4 6 5\n1 2 1\n1 3 1\n1 4 2\n2 4 1\n4 3 1\n3 2 1\n3 2 10\n1 2 8\n1 3 10\n5 5 15\n1 2 17\n3 1 15\n2 3 10\n1 4 14\n2 5 8\n", "4\n4 5 7\n4 2 3\n1 2 5\n2 3 8\n2 4 1\n3 4 4\n4 6 5\n1 2 1\n1 3 1\n1 4 2\n2 4 1\n4 3 1\n3 2 1\n3 2 10\n1 2 8\n1 3 10\n5 5 15\n1 2...
2CODEFORCES
1468_J. Road Reform_1849
There are n cities and m bidirectional roads in Berland. The i-th road connects the cities x_i and y_i, and has the speed limit s_i. The road network allows everyone to get from any city to any other city. The Berland Transport Ministry is planning a road reform. First of all, maintaining all m roads is too costly, ...
from collections import defaultdict from math import ceil, sqrt, floor from heapq import heappush,heappop import sys inf = float("inf") class DisjointSet: def __init__(self, n): self.n = n self.par = [-1] * n self.nc = n def findParent(self, i): if self.par[i] == -1: return i #no parent yet else: v...
3Python3
{ "input": [ "4\n4 5 7\n4 1 3\n1 2 5\n2 3 8\n2 4 1\n3 4 4\n4 6 5\n1 2 1\n1 3 1\n1 4 2\n2 4 1\n4 3 1\n3 2 1\n3 2 10\n1 2 8\n1 3 10\n5 5 15\n1 2 17\n3 1 15\n2 3 10\n1 4 14\n2 5 8\n", "4\n4 5 7\n4 2 3\n1 2 5\n2 3 8\n2 4 1\n3 4 4\n4 6 5\n1 2 1\n1 3 1\n1 4 2\n2 4 1\n4 3 1\n3 2 1\n3 2 10\n1 2 8\n1 3 10\n5 5 15\n1 2...
2CODEFORCES
1468_J. Road Reform_1850
There are n cities and m bidirectional roads in Berland. The i-th road connects the cities x_i and y_i, and has the speed limit s_i. The road network allows everyone to get from any city to any other city. The Berland Transport Ministry is planning a road reform. First of all, maintaining all m roads is too costly, ...
import java.io.*; import java.util.*; public class Codeforces { public static void main(String args[])throws Exception { BufferedReader bu=new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb=new StringBuilder(); int t=Integer.parseInt(bu.readLine()); while(t--...
4JAVA
{ "input": [ "4\n4 5 7\n4 1 3\n1 2 5\n2 3 8\n2 4 1\n3 4 4\n4 6 5\n1 2 1\n1 3 1\n1 4 2\n2 4 1\n4 3 1\n3 2 1\n3 2 10\n1 2 8\n1 3 10\n5 5 15\n1 2 17\n3 1 15\n2 3 10\n1 4 14\n2 5 8\n", "4\n4 5 7\n4 2 3\n1 2 5\n2 3 8\n2 4 1\n3 4 4\n4 6 5\n1 2 1\n1 3 1\n1 4 2\n2 4 1\n4 3 1\n3 2 1\n3 2 10\n1 2 8\n1 3 10\n5 5 15\n1 2...
2CODEFORCES
1493_C. K-beautiful Strings_1851
You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the lexicographically smallest beautiful string of length n, which is...
import threading import sys threading.stack_size(16*2048*2048) sys.setrecursionlimit(100010) def getnext(index,fre,k,s,flag): if sum(fre)>len(s)-index: return "ERROR" # print(index,fre,pre,flag) if index==len(s): return "" cur = ord(s[index])-97 if not flag: nexts = "" s...
1Python2
{ "input": [ "4\n4 2\nabcd\n3 1\nabc\n4 3\naaaa\n9 3\nabaabaaaa\n", "12\n12 3\nzazasqzqsasq\n1 1\nz\n1 1\na\n15 4\nabccbaabccbazaa\n16 8\ncadjfdsljfdkljds\n6 2\nbaazaa\n6 3\nbosszb\n6 1\nqwerty\n7 7\ndaaaaaa\n14 2\nacabcbdeffewzd\n18 6\nzzzzzzzzzzzzyyyyyz\n9 4\naabaabbbc\n", "12\n12 3\nzazasqzqsasq\n1 1\n...
2CODEFORCES
1493_C. K-beautiful Strings_1852
You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the lexicographically smallest beautiful string of length n, which is...
#include <bits/stdc++.h> using namespace std ; const int MAX = 1e5 + 10 ; int need[27] ; int n , k ; string s ; bool check(int idx) { memset(need , 0 , sizeof(need)) ; for(int i = 0 ; i < idx ; ++i) need[s[i]-'a'] = (need[s[i]-'a'] - 1 + k) % k ; int sum = 0 ; for(int i = 0 ; i < 26 ; ++i) sum += need[i] ;...
2C++
{ "input": [ "4\n4 2\nabcd\n3 1\nabc\n4 3\naaaa\n9 3\nabaabaaaa\n", "12\n12 3\nzazasqzqsasq\n1 1\nz\n1 1\na\n15 4\nabccbaabccbazaa\n16 8\ncadjfdsljfdkljds\n6 2\nbaazaa\n6 3\nbosszb\n6 1\nqwerty\n7 7\ndaaaaaa\n14 2\nacabcbdeffewzd\n18 6\nzzzzzzzzzzzzyyyyyz\n9 4\naabaabbbc\n", "12\n12 3\nzazasqzqsasq\n1 1\n...
2CODEFORCES
1493_C. K-beautiful Strings_1853
You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the lexicographically smallest beautiful string of length n, which is...
#!/usr/bin/python import sys from sys import stdin def solve(N, K, S): if N % K != 0: print(-1) return cnt_dict = {} for s in S: cnt_dict[s] = 0 for s in S: cnt_dict[s] += 1 bea = True for k in cnt_dict: if cnt_dict[k] % K != 0: bea = Fal...
3Python3
{ "input": [ "4\n4 2\nabcd\n3 1\nabc\n4 3\naaaa\n9 3\nabaabaaaa\n", "12\n12 3\nzazasqzqsasq\n1 1\nz\n1 1\na\n15 4\nabccbaabccbazaa\n16 8\ncadjfdsljfdkljds\n6 2\nbaazaa\n6 3\nbosszb\n6 1\nqwerty\n7 7\ndaaaaaa\n14 2\nacabcbdeffewzd\n18 6\nzzzzzzzzzzzzyyyyyz\n9 4\naabaabbbc\n", "12\n12 3\nzazasqzqsasq\n1 1\n...
2CODEFORCES
1493_C. K-beautiful Strings_1854
You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the lexicographically smallest beautiful string of length n, which is...
import java.io.*; import java.util.*; public class Main { static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); ; static String currentInputLine = ""; static int currentInputIndex = 0; // public FastScanner(String fileName) throws FileNotFoundException { // rea...
4JAVA
{ "input": [ "4\n4 2\nabcd\n3 1\nabc\n4 3\naaaa\n9 3\nabaabaaaa\n", "12\n12 3\nzazasqzqsasq\n1 1\nz\n1 1\na\n15 4\nabccbaabccbazaa\n16 8\ncadjfdsljfdkljds\n6 2\nbaazaa\n6 3\nbosszb\n6 1\nqwerty\n7 7\ndaaaaaa\n14 2\nacabcbdeffewzd\n18 6\nzzzzzzzzzzzzyyyyyz\n9 4\naabaabbbc\n", "12\n12 3\nzazasqzqsasq\n1 1\n...
2CODEFORCES
1515_I. Phoenix and Diamonds_1855
Phoenix wonders what it is like to rob diamonds from a jewelry store! There are n types of diamonds. The i-th type has weight w_i and value v_i. The store initially has a_i diamonds of the i-th type. Each day, for q days, one of the following will happen: 1. A new shipment of k_i diamonds of type d_i arrive. 2...
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #define maxn 200005 #define maxm 19 #define ll long long #define inf (ll)1e18+5 using namespace std; int n,q,i,j,k,id[maxn],L; struct arr{ll w,v,c; int i;} a[maxn]; int cmp(arr a,arr b){return a.v>b.v||a.v==b.v&&a.w<b.w;} ll res,sum; int now; st...
2C++
{ "input": [ "3 5\n2 3 4\n1 5 1\n0 2 4\n3 6\n1 3 3\n3 10\n2 2 3\n3 30\n", "2 8\n2 15 400\n1 13 100\n3 26\n3 27\n3 28\n3 29\n3 30\n3 31\n3 32\n3 33\n", "3 8\n2 15 400\n1 1 200\n1 13 100\n3 26\n3 27\n3 28\n3 29\n3 30\n3 31\n3 32\n3 33\n", "3 8\n2 15 400\n1 1 200\n1 13 110\n3 26\n3 27\n3 28\n3 29\n3 30\n...
2CODEFORCES
1543_B. Customising the Track_1856
Highway 201 is the most busy street in Rockport. Traffic cars cause a lot of hindrances to races, especially when there are a lot of them. The track which passes through this highway can be divided into n sub-tracks. You are given an array a where a_i represents the number of traffic cars in the i-th sub-track. You def...
from __future__ import division,print_function from heapq import* import sys le = sys.__stdin__.read().split("\n")[::-1] af=[] for zorg in range(int(le.pop())): n=int(le.pop()) s= sum(list(map(int,le.pop().split()))) r=s%n af.append(r*(n-r)) print("\n".join(map(str,af)))
1Python2
{ "input": [ "3\n3\n1 2 3\n4\n0 1 1 0\n10\n8 3 6 11 5 2 1 7 10 4\n", "3\n3\n1 2 3\n4\n0 1 1 0\n10\n8 3 6 11 4 2 1 7 10 4\n", "3\n3\n1 2 3\n4\n1 1 1 0\n10\n8 3 6 11 4 2 1 7 10 4\n", "3\n3\n1 1 3\n4\n1 1 1 0\n10\n8 3 6 11 4 2 1 7 10 4\n", "3\n3\n1 1 3\n4\n1 1 1 0\n10\n8 3 6 11 4 2 1 3 10 4\n", "...
2CODEFORCES
1543_B. Customising the Track_1857
Highway 201 is the most busy street in Rockport. Traffic cars cause a lot of hindrances to races, especially when there are a lot of them. The track which passes through this highway can be divided into n sub-tracks. You are given an array a where a_i represents the number of traffic cars in the i-th sub-track. You def...
#include<iostream> #include<bits/stdc++.h> #include <cmath> #define ll long long int #define mp make_pair #define pb push_back #define MOD 1000000007 #define fi first #define se second #define inf INT_MAX #define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL); #define all(v) v.begin(),v.end() #define sumof(v)...
2C++
{ "input": [ "3\n3\n1 2 3\n4\n0 1 1 0\n10\n8 3 6 11 5 2 1 7 10 4\n", "3\n3\n1 2 3\n4\n0 1 1 0\n10\n8 3 6 11 4 2 1 7 10 4\n", "3\n3\n1 2 3\n4\n1 1 1 0\n10\n8 3 6 11 4 2 1 7 10 4\n", "3\n3\n1 1 3\n4\n1 1 1 0\n10\n8 3 6 11 4 2 1 7 10 4\n", "3\n3\n1 1 3\n4\n1 1 1 0\n10\n8 3 6 11 4 2 1 3 10 4\n", "...
2CODEFORCES
1543_B. Customising the Track_1858
Highway 201 is the most busy street in Rockport. Traffic cars cause a lot of hindrances to races, especially when there are a lot of them. The track which passes through this highway can be divided into n sub-tracks. You are given an array a where a_i represents the number of traffic cars in the i-th sub-track. You def...
t = int(input()) for T in range(t): n = int(input()) A = [int(i) for i in input().split()] s = sum(A) mean = s//n rem = s%n for i in range(n): if i<rem: A[i] = mean+1 else: A[i] = mean A.sort() cursum = 0 curnums = 0 ans = 0 for i in ra...
3Python3
{ "input": [ "3\n3\n1 2 3\n4\n0 1 1 0\n10\n8 3 6 11 5 2 1 7 10 4\n", "3\n3\n1 2 3\n4\n0 1 1 0\n10\n8 3 6 11 4 2 1 7 10 4\n", "3\n3\n1 2 3\n4\n1 1 1 0\n10\n8 3 6 11 4 2 1 7 10 4\n", "3\n3\n1 1 3\n4\n1 1 1 0\n10\n8 3 6 11 4 2 1 7 10 4\n", "3\n3\n1 1 3\n4\n1 1 1 0\n10\n8 3 6 11 4 2 1 3 10 4\n", "...
2CODEFORCES
1543_B. Customising the Track_1859
Highway 201 is the most busy street in Rockport. Traffic cars cause a lot of hindrances to races, especially when there are a lot of them. The track which passes through this highway can be divided into n sub-tracks. You are given an array a where a_i represents the number of traffic cars in the i-th sub-track. You def...
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; import java.math.*; /* Name of the class has to be "Main" only if the class is public. */ public final class Solution { public static void main(String[] args) throws java.lang.Exception { // your code goe...
4JAVA
{ "input": [ "3\n3\n1 2 3\n4\n0 1 1 0\n10\n8 3 6 11 5 2 1 7 10 4\n", "3\n3\n1 2 3\n4\n0 1 1 0\n10\n8 3 6 11 4 2 1 7 10 4\n", "3\n3\n1 2 3\n4\n1 1 1 0\n10\n8 3 6 11 4 2 1 7 10 4\n", "3\n3\n1 1 3\n4\n1 1 1 0\n10\n8 3 6 11 4 2 1 7 10 4\n", "3\n3\n1 1 3\n4\n1 1 1 0\n10\n8 3 6 11 4 2 1 3 10 4\n", "...
2CODEFORCES
171_C. A Piece of Cake_1860
How to make a cake you'll never eat. Ingredients. * 2 carrots * 0 calories * 100 g chocolate spread * 1 pack of flour * 1 egg Method. 1. Put calories into the mixing bowl. 2. Take carrots from refrigerator. 3. Chop carrots. 4. Take chocolate spread from refrigerator. 5. Put chocolate spread ...
a=map(int,raw_input().split()) ans=0 t=0 for i in a: ans+=t*i t+=1 print ans
1Python2
{ "input": [ "4 1 2 3 4\n", "20 228 779 225 819 142 849 24 494 45 172 95 207 908 510 424 78 100 166 869 456\n", "4 220 380 729 969\n", "23 486 261 249 312 592 411 874 397 18 70 417 512 338 679 517 997 938 328 418 793 522 745 59\n", "17 644 532 255 57 108 413 51 284 364 300 597 646 712 470 42 730 2...
2CODEFORCES
171_C. A Piece of Cake_1861
How to make a cake you'll never eat. Ingredients. * 2 carrots * 0 calories * 100 g chocolate spread * 1 pack of flour * 1 egg Method. 1. Put calories into the mixing bowl. 2. Take carrots from refrigerator. 3. Chop carrots. 4. Take chocolate spread from refrigerator. 5. Put chocolate spread ...
#include <bits/stdc++.h> using namespace std; inline int getint() { int f = 1, x = 0; char c = getchar(); while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } return x * f; } inline long long getll() { long long f = 1, x...
2C++
{ "input": [ "4 1 2 3 4\n", "20 228 779 225 819 142 849 24 494 45 172 95 207 908 510 424 78 100 166 869 456\n", "4 220 380 729 969\n", "23 486 261 249 312 592 411 874 397 18 70 417 512 338 679 517 997 938 328 418 793 522 745 59\n", "17 644 532 255 57 108 413 51 284 364 300 597 646 712 470 42 730 2...
2CODEFORCES
171_C. A Piece of Cake_1862
How to make a cake you'll never eat. Ingredients. * 2 carrots * 0 calories * 100 g chocolate spread * 1 pack of flour * 1 egg Method. 1. Put calories into the mixing bowl. 2. Take carrots from refrigerator. 3. Chop carrots. 4. Take chocolate spread from refrigerator. 5. Put chocolate spread ...
a = input().split() s = 0 for i in range(int(a[0])): s += (i + 1) * int(a[i + 1]) print(s)
3Python3
{ "input": [ "4 1 2 3 4\n", "20 228 779 225 819 142 849 24 494 45 172 95 207 908 510 424 78 100 166 869 456\n", "4 220 380 729 969\n", "23 486 261 249 312 592 411 874 397 18 70 417 512 338 679 517 997 938 328 418 793 522 745 59\n", "17 644 532 255 57 108 413 51 284 364 300 597 646 712 470 42 730 2...
2CODEFORCES
171_C. A Piece of Cake_1863
How to make a cake you'll never eat. Ingredients. * 2 carrots * 0 calories * 100 g chocolate spread * 1 pack of flour * 1 egg Method. 1. Put calories into the mixing bowl. 2. Take carrots from refrigerator. 3. Chop carrots. 4. Take chocolate spread from refrigerator. 5. Put chocolate spread ...
import java.io.*; import java.math.*; import static java.lang.Math.*; import java.security.SecureRandom; import static java.util.Arrays.*; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; import sun.misc.Regexp; import java.awt.geom.*; import sun.net.www.content.text.plain; public c...
4JAVA
{ "input": [ "4 1 2 3 4\n", "20 228 779 225 819 142 849 24 494 45 172 95 207 908 510 424 78 100 166 869 456\n", "4 220 380 729 969\n", "23 486 261 249 312 592 411 874 397 18 70 417 512 338 679 517 997 938 328 418 793 522 745 59\n", "17 644 532 255 57 108 413 51 284 364 300 597 646 712 470 42 730 2...
2CODEFORCES
191_A. Dynasty Puzzles_1864
The ancient Berlanders believed that the longer the name, the more important its bearer is. Thus, Berland kings were famous for their long names. But long names are somewhat inconvenient, so the Berlanders started to abbreviate the names of their kings. They called every king by the first letters of its name. Thus, the...
import os, sys, atexit if sys.version_info[0] < 3: range = xrange from cStringIO import StringIO as BytesIO sys.stdout = BytesIO() else: from io import BytesIO sys.stdout = BytesIO() _write = sys.stdout.write sys.stdout.write = lambda s: _write(s.encode()) atexit.register(lambda: os.write...
1Python2
{ "input": [ "4\nvvp\nvvp\ndam\nvvp\n", "3\nab\nc\ndef\n", "3\nabc\nca\ncba\n", "10\nabdcced\nbdacdac\necb\ndc\neaeeebdd\nadcdbadcac\neb\naadecccde\nedbaeacad\naccd\n", "100\nd\na\ne\neb\nc\nd\nd\ne\nc\ne\nac\nd\nc\naa\na\ne\nda\ne\ne\nc\ne\na\nc\nc\nbc\nbd\nd\nda\ncc\nbe\nb\na\nee\nd\nbe\nbe\ne\n...
2CODEFORCES
191_A. Dynasty Puzzles_1865
The ancient Berlanders believed that the longer the name, the more important its bearer is. Thus, Berland kings were famous for their long names. But long names are somewhat inconvenient, so the Berlanders started to abbreviate the names of their kings. They called every king by the first letters of its name. Thus, the...
#include <bits/stdc++.h> using namespace std; long long dp[26][26]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, m, l = 0, p = 0, i, flag = 0, k, t, d = 0, q = 0, r = 0; cin >> n; string s; for (long long i = 0; i < n; i++) { cin >> s; long long start, last; ...
2C++
{ "input": [ "4\nvvp\nvvp\ndam\nvvp\n", "3\nab\nc\ndef\n", "3\nabc\nca\ncba\n", "10\nabdcced\nbdacdac\necb\ndc\neaeeebdd\nadcdbadcac\neb\naadecccde\nedbaeacad\naccd\n", "100\nd\na\ne\neb\nc\nd\nd\ne\nc\ne\nac\nd\nc\naa\na\ne\nda\ne\ne\nc\ne\na\nc\nc\nbc\nbd\nd\nda\ncc\nbe\nb\na\nee\nd\nbe\nbe\ne\n...
2CODEFORCES
191_A. Dynasty Puzzles_1866
The ancient Berlanders believed that the longer the name, the more important its bearer is. Thus, Berland kings were famous for their long names. But long names are somewhat inconvenient, so the Berlanders started to abbreviate the names of their kings. They called every king by the first letters of its name. Thus, the...
from sys import stdin, stdout fst = 97 sze = 26 values = [[0 for i in range(sze)] for j in range(sze)] n = int(stdin.readline()) challengers = [] for i in range(n): s = stdin.readline().strip() challengers.append((ord(s[0]) - fst, ord(s[-1]) - fst)) for i in range(sze): if values[i][challeng...
3Python3
{ "input": [ "4\nvvp\nvvp\ndam\nvvp\n", "3\nab\nc\ndef\n", "3\nabc\nca\ncba\n", "10\nabdcced\nbdacdac\necb\ndc\neaeeebdd\nadcdbadcac\neb\naadecccde\nedbaeacad\naccd\n", "100\nd\na\ne\neb\nc\nd\nd\ne\nc\ne\nac\nd\nc\naa\na\ne\nda\ne\ne\nc\ne\na\nc\nc\nbc\nbd\nd\nda\ncc\nbe\nb\na\nee\nd\nbe\nbe\ne\n...
2CODEFORCES
191_A. Dynasty Puzzles_1867
The ancient Berlanders believed that the longer the name, the more important its bearer is. Thus, Berland kings were famous for their long names. But long names are somewhat inconvenient, so the Berlanders started to abbreviate the names of their kings. They called every king by the first letters of its name. Thus, the...
import java.io.*; import java.util.*; public class dynasty { public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int[][] dp = new int[26][26]; //starting, ending int ans = 0; for (int ...
4JAVA
{ "input": [ "4\nvvp\nvvp\ndam\nvvp\n", "3\nab\nc\ndef\n", "3\nabc\nca\ncba\n", "10\nabdcced\nbdacdac\necb\ndc\neaeeebdd\nadcdbadcac\neb\naadecccde\nedbaeacad\naccd\n", "100\nd\na\ne\neb\nc\nd\nd\ne\nc\ne\nac\nd\nc\naa\na\ne\nda\ne\ne\nc\ne\na\nc\nc\nbc\nbd\nd\nda\ncc\nbe\nb\na\nee\nd\nbe\nbe\ne\n...
2CODEFORCES
215_A. Bicycle Chain_1868
Vasya's bicycle chain drive consists of two parts: n stars are attached to the pedal axle, m stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation. We know that the i-th star on the pedal axle has ai (0 < a1 < a2 < ... < an) teeth, and the j-th star on t...
n=input() a=[int(x) for x in raw_input().split()] m=input() b=[int(x) for x in raw_input().split()] x=[] for i in range(n): for j in range(m): q=float(b[j])/a[i] if q==int(q): x.append(int(q)) x.sort() m=x[-1] c=x.count(m) print c
1Python2
{ "input": [ "4\n1 2 3 4\n5\n10 11 12 13 14\n", "2\n4 5\n3\n12 13 15\n", "1\n1\n2\n1 2\n", "50\n17 20 22 28 36 38 46 47 48 50 52 57 58 62 63 69 70 74 75 78 79 81 82 86 87 90 93 95 103 202 292 442 1756 1769 2208 2311 2799 2957 3483 4280 4324 4932 5109 5204 6225 6354 6561 7136 8754 9670\n40\n68 214 957 ...
2CODEFORCES
215_A. Bicycle Chain_1869
Vasya's bicycle chain drive consists of two parts: n stars are attached to the pedal axle, m stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation. We know that the i-th star on the pedal axle has ai (0 < a1 < a2 < ... < an) teeth, and the j-th star on t...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i, j, max, count = 0, flag = 0; cin >> n; int a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } cin >> m; int b[m]; for (j = 0; j < m; j++) { cin >> b[j]; for (i = 0; i < n; i++) { if (b[j] % a[i] == 0) { if (fla...
2C++
{ "input": [ "4\n1 2 3 4\n5\n10 11 12 13 14\n", "2\n4 5\n3\n12 13 15\n", "1\n1\n2\n1 2\n", "50\n17 20 22 28 36 38 46 47 48 50 52 57 58 62 63 69 70 74 75 78 79 81 82 86 87 90 93 95 103 202 292 442 1756 1769 2208 2311 2799 2957 3483 4280 4324 4932 5109 5204 6225 6354 6561 7136 8754 9670\n40\n68 214 957 ...
2CODEFORCES
215_A. Bicycle Chain_1870
Vasya's bicycle chain drive consists of two parts: n stars are attached to the pedal axle, m stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation. We know that the i-th star on the pedal axle has ai (0 < a1 < a2 < ... < an) teeth, and the j-th star on t...
n = int(input()) a = list(map(int,input().split())) m = int(input()) b = list(map(int,input().split())) count = [] for i in range(n): for j in range(m): if((b[j]/a[i])==int(b[j]/a[i])): count.append(int(b[j]/a[i])) o = max(count) print(count.count(o))
3Python3
{ "input": [ "4\n1 2 3 4\n5\n10 11 12 13 14\n", "2\n4 5\n3\n12 13 15\n", "1\n1\n2\n1 2\n", "50\n17 20 22 28 36 38 46 47 48 50 52 57 58 62 63 69 70 74 75 78 79 81 82 86 87 90 93 95 103 202 292 442 1756 1769 2208 2311 2799 2957 3483 4280 4324 4932 5109 5204 6225 6354 6561 7136 8754 9670\n40\n68 214 957 ...
2CODEFORCES
215_A. Bicycle Chain_1871
Vasya's bicycle chain drive consists of two parts: n stars are attached to the pedal axle, m stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation. We know that the i-th star on the pedal axle has ai (0 < a1 < a2 < ... < an) teeth, and the j-th star on t...
import java.util.Scanner; public class C_132A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int a[] = new int [n]; for (int i = 0; i < a.length; i++) { a[i] = sc.nextInt(); } int m = sc.nextInt(); int b[] = new int [m]; for (int i = 0; i < b....
4JAVA
{ "input": [ "4\n1 2 3 4\n5\n10 11 12 13 14\n", "2\n4 5\n3\n12 13 15\n", "1\n1\n2\n1 2\n", "50\n17 20 22 28 36 38 46 47 48 50 52 57 58 62 63 69 70 74 75 78 79 81 82 86 87 90 93 95 103 202 292 442 1756 1769 2208 2311 2799 2957 3483 4280 4324 4932 5109 5204 6225 6354 6561 7136 8754 9670\n40\n68 214 957 ...
2CODEFORCES
239_A. Two Bags of Potatoes_1872
Valera had two bags of potatoes, the first of these bags contains x (x ≥ 1) potatoes, and the second — y (y ≥ 1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains x potatoes) Valera lost. Valera remembers that the total amount of potatoes (x + y) in the two bags, firstly, was not gerater ...
#coding=utf-8 y,k,n=map(int,raw_input().split()) l = [xy-y for xy in range(0, n+1, k) if xy > y] if len(l) == 0: print -1 else: for i in l: print i,
1Python2
{ "input": [ "10 6 40\n", "10 1 10\n", "78 7 15\n", "10 4 9174\n", "1 999999999 1000000000\n", "17 28 532\n", "1 100000007 1000000000\n", "30351 86 424\n", "100000000 1000000000 1000000000\n", "1000000000 1 1\n", "15946 76 360\n", "46592 52 232\n", "48 6 50\n", ...
2CODEFORCES
239_A. Two Bags of Potatoes_1873
Valera had two bags of potatoes, the first of these bags contains x (x ≥ 1) potatoes, and the second — y (y ≥ 1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains x potatoes) Valera lost. Valera remembers that the total amount of potatoes (x + y) in the two bags, firstly, was not gerater ...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { while (a != b) { if (a > b) a = a - b; else b = b - a; } return a; } int main() { int y, k, n; cin >> y >> k >> n; int f = 0; int d = y / k; int e = n / k; for (int i = d + 1; i <= e; i++) { cout << k * i - y...
2C++
{ "input": [ "10 6 40\n", "10 1 10\n", "78 7 15\n", "10 4 9174\n", "1 999999999 1000000000\n", "17 28 532\n", "1 100000007 1000000000\n", "30351 86 424\n", "100000000 1000000000 1000000000\n", "1000000000 1 1\n", "15946 76 360\n", "46592 52 232\n", "48 6 50\n", ...
2CODEFORCES
239_A. Two Bags of Potatoes_1874
Valera had two bags of potatoes, the first of these bags contains x (x ≥ 1) potatoes, and the second — y (y ≥ 1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains x potatoes) Valera lost. Valera remembers that the total amount of potatoes (x + y) in the two bags, firstly, was not gerater ...
""" author - Sayan Bose Brooklyn 99 is love! """ y, k, n = map(int, input().split()) if n-y == 0: print(-1) else: y1 = y res = [] f, f1 = 0, 0 while y <= n: if not y%k: f = 1 if y-y1: f1 = 1 print(y-y1, end = ' ') if not f: temp = y//k + 1 y = k * temp else: y += k if not f1:...
3Python3
{ "input": [ "10 6 40\n", "10 1 10\n", "78 7 15\n", "10 4 9174\n", "1 999999999 1000000000\n", "17 28 532\n", "1 100000007 1000000000\n", "30351 86 424\n", "100000000 1000000000 1000000000\n", "1000000000 1 1\n", "15946 76 360\n", "46592 52 232\n", "48 6 50\n", ...
2CODEFORCES
239_A. Two Bags of Potatoes_1875
Valera had two bags of potatoes, the first of these bags contains x (x ≥ 1) potatoes, and the second — y (y ≥ 1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains x potatoes) Valera lost. Valera remembers that the total amount of potatoes (x + y) in the two bags, firstly, was not gerater ...
// 20/8/20 12:14 PM Aug 2020 import java.util.*; public class _239A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long y=sc.nextLong(); long k=sc.nextLong(); long n=sc.nextLong(); StringBuilder st= new StringBuilder(); long i=k-y%...
4JAVA
{ "input": [ "10 6 40\n", "10 1 10\n", "78 7 15\n", "10 4 9174\n", "1 999999999 1000000000\n", "17 28 532\n", "1 100000007 1000000000\n", "30351 86 424\n", "100000000 1000000000 1000000000\n", "1000000000 1 1\n", "15946 76 360\n", "46592 52 232\n", "48 6 50\n", ...
2CODEFORCES
263_D. Cycle in Graph_1876
You've got a undirected graph G, consisting of n nodes. We will consider the nodes of the graph indexed by integers from 1 to n. We know that each node of graph G is connected by edges with at least k other nodes of this graph. Your task is to find in the given graph a simple cycle of length of at least k + 1. A simpl...
#!/usr/bin/python n, m, k = map(int, raw_input().split()) graph = [[] for i in range(n+1)] for i in range(m) : x, y = map(int, raw_input().split()) graph[x].append(y) graph[y].append(x) startPoint = max(zip(range(1, n+1), [len(graph[i]) for i in range(1, n+1)]), key = lambda pair: pair...
1Python2
{ "input": [ "4 6 3\n4 3\n1 2\n1 3\n1 4\n2 3\n2 4\n", "3 3 2\n1 2\n2 3\n3 1\n", "30 70 4\n22 1\n1 25\n27 5\n25 10\n10 2\n29 4\n29 26\n28 18\n15 18\n25 11\n11 10\n11 28\n4 11\n4 26\n26 7\n26 18\n18 21\n14 17\n17 30\n30 9\n30 6\n30 27\n27 22\n22 15\n22 8\n8 4\n8 17\n17 16\n16 19\n16 12\n12 23\n23 20\n20 1\n...
2CODEFORCES
263_D. Cycle in Graph_1877
You've got a undirected graph G, consisting of n nodes. We will consider the nodes of the graph indexed by integers from 1 to n. We know that each node of graph G is connected by edges with at least k other nodes of this graph. Your task is to find in the given graph a simple cycle of length of at least k + 1. A simpl...
#include <bits/stdc++.h> using namespace std; const int N = 100100; int n, m, k, p[N], niv[N], sol, tata; vector<int> v[N]; void dfs(int nod) { if (sol) return; for (vector<int>::iterator it = v[nod].begin(); it != v[nod].end(); ++it) if (p[nod] != *it) { if (!p[*it]) { p[*it] = nod; niv[*...
2C++
{ "input": [ "4 6 3\n4 3\n1 2\n1 3\n1 4\n2 3\n2 4\n", "3 3 2\n1 2\n2 3\n3 1\n", "30 70 4\n22 1\n1 25\n27 5\n25 10\n10 2\n29 4\n29 26\n28 18\n15 18\n25 11\n11 10\n11 28\n4 11\n4 26\n26 7\n26 18\n18 21\n14 17\n17 30\n30 9\n30 6\n30 27\n27 22\n22 15\n22 8\n8 4\n8 17\n17 16\n16 19\n16 12\n12 23\n23 20\n20 1\n...
2CODEFORCES
263_D. Cycle in Graph_1878
You've got a undirected graph G, consisting of n nodes. We will consider the nodes of the graph indexed by integers from 1 to n. We know that each node of graph G is connected by edges with at least k other nodes of this graph. Your task is to find in the given graph a simple cycle of length of at least k + 1. A simpl...
n, m, k = map(int, input().split()) d = {} for _ in range(m): u, v = map(int, input().split()) if u not in d: d[u] = [v] else: d[u].append(v) if v not in d: d[v] = [u] else: d[v].append(u) # print(d) stack = [] not_visited = set(range(1, n+1)) while not_visited: ...
3Python3
{ "input": [ "4 6 3\n4 3\n1 2\n1 3\n1 4\n2 3\n2 4\n", "3 3 2\n1 2\n2 3\n3 1\n", "30 70 4\n22 1\n1 25\n27 5\n25 10\n10 2\n29 4\n29 26\n28 18\n15 18\n25 11\n11 10\n11 28\n4 11\n4 26\n26 7\n26 18\n18 21\n14 17\n17 30\n30 9\n30 6\n30 27\n27 22\n22 15\n22 8\n8 4\n8 17\n17 16\n16 19\n16 12\n12 23\n23 20\n20 1\n...
2CODEFORCES
263_D. Cycle in Graph_1879
You've got a undirected graph G, consisting of n nodes. We will consider the nodes of the graph indexed by integers from 1 to n. We know that each node of graph G is connected by edges with at least k other nodes of this graph. Your task is to find in the given graph a simple cycle of length of at least k + 1. A simpl...
//package round161; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class D { InputStream is; PrintWriter out; String INPUT = ""; void solve() { int n = ni(), m = n...
4JAVA
{ "input": [ "4 6 3\n4 3\n1 2\n1 3\n1 4\n2 3\n2 4\n", "3 3 2\n1 2\n2 3\n3 1\n", "30 70 4\n22 1\n1 25\n27 5\n25 10\n10 2\n29 4\n29 26\n28 18\n15 18\n25 11\n11 10\n11 28\n4 11\n4 26\n26 7\n26 18\n18 21\n14 17\n17 30\n30 9\n30 6\n30 27\n27 22\n22 15\n22 8\n8 4\n8 17\n17 16\n16 19\n16 12\n12 23\n23 20\n20 1\n...
2CODEFORCES
287_D. Shifting_1880
John Doe has found the beautiful permutation formula. Let's take permutation p = p1, p2, ..., pn. Let's define transformation f of this permutation: <image> where k (k > 1) is an integer, the transformation parameter, r is such maximum integer that rk ≤ n. If rk = n, then elements prk + 1, prk + 2 and so on are omi...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int N = 4e6 + 5; int a[N]; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) a[i] = i + 1; int L = 0, R = n - 1; for (int i = 2; i <= n; ++i) { for (int k = (n - 1) / i; k > 0; --k) swap(a[L + (k - 1) * i], a[L +...
2C++
{ "input": [ "4\n", "2\n", "3\n", "2000\n", "2000\n", "1000\n", "5000\n", "100\n", "16\n", "17\n", "11\n", "10000\n", "12\n", "100\n", "5000\n", "10001\n", "10\n", "10001\n", "13\n", "15\n", "14\n", "1000\n", "10000\n", "1...
2CODEFORCES
287_D. Shifting_1881
John Doe has found the beautiful permutation formula. Let's take permutation p = p1, p2, ..., pn. Let's define transformation f of this permutation: <image> where k (k > 1) is an integer, the transformation parameter, r is such maximum integer that rk ≤ n. If rk = n, then elements prk + 1, prk + 2 and so on are omi...
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; /* public class _287D { } */ public class _287D { public void solve() throws FileNotFoundException { InputStream in...
4JAVA
{ "input": [ "4\n", "2\n", "3\n", "2000\n", "2000\n", "1000\n", "5000\n", "100\n", "16\n", "17\n", "11\n", "10000\n", "12\n", "100\n", "5000\n", "10001\n", "10\n", "10001\n", "13\n", "15\n", "14\n", "1000\n", "10000\n", "1...
2CODEFORCES
312_D. Cats Transport_1882
Zxr960115 is owner of a large farm. He feeds m cute cats and employs p feeders. There's a straight road across the farm and n hills along the road, numbered from 1 to n from left to right. The distance between hill i and (i - 1) is di meters. The feeders live in hill 1. One day, the cats went out to play. Cat i went o...
#include <bits/stdc++.h> using namespace std; struct line { long long k, b; long double value(long double x) { return k * x + b; } }; long double intersect(line a, line b) { return 1.0L * (b.b - a.b) / (a.k - b.k); } struct convex_hull_trick { vector<line> lines; vector<long double> pts = {-1e9}; convex_hul...
2C++
{ "input": [ "4 6 2\n1 3 5\n1 0\n2 1\n4 9\n1 10\n2 10\n3 12\n", "4 6 2\n1 3 5\n1 0\n2 1\n4 4\n1 10\n2 10\n3 12\n", "4 6 2\n1 3 1\n1 0\n2 1\n4 4\n1 10\n2 10\n3 12\n", "4 6 2\n1 3 2\n1 0\n2 1\n4 4\n1 10\n2 10\n3 12\n", "4 6 2\n1 3 5\n1 0\n4 1\n4 4\n1 10\n2 10\n3 12\n", "4 6 2\n1 3 1\n1 0\n2 1\n4...
2CODEFORCES
312_D. Cats Transport_1883
Zxr960115 is owner of a large farm. He feeds m cute cats and employs p feeders. There's a straight road across the farm and n hills along the road, numbered from 1 to n from left to right. The distance between hill i and (i - 1) is di meters. The feeders live in hill 1. One day, the cats went out to play. Cat i went o...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class D { BufferedReader reader; StringTokenizer tokenizer; PrintWriter out; public void solve() throws IOException { int N = nextInt(); int M = n...
4JAVA
{ "input": [ "4 6 2\n1 3 5\n1 0\n2 1\n4 9\n1 10\n2 10\n3 12\n", "4 6 2\n1 3 5\n1 0\n2 1\n4 4\n1 10\n2 10\n3 12\n", "4 6 2\n1 3 1\n1 0\n2 1\n4 4\n1 10\n2 10\n3 12\n", "4 6 2\n1 3 2\n1 0\n2 1\n4 4\n1 10\n2 10\n3 12\n", "4 6 2\n1 3 5\n1 0\n4 1\n4 4\n1 10\n2 10\n3 12\n", "4 6 2\n1 3 1\n1 0\n2 1\n4...
2CODEFORCES
335_B. Palindrome_1884
Given a string s, determine if it contains any palindrome of length exactly 100 as a subsequence. If it has any, print any one of them. If it doesn't have any, print a palindrome that is a subsequence of s and is as long as possible. Input The only line of the input contains one string s of length n (1 ≤ n ≤ 5·104) c...
def p2(a): n = len(a) last = [[0] * 26 for _ in range(n)] last[0][ord(a[0])-97] = 0 for i in range(1, n): for j in range(26): last[i][j] = last[i-1][j] last[i][ord(a[i])-97] = i dp = [''] * n for i in range(n-1, -1, -1): for j in range(n-1, i, -1): k = last[j][ord(a[i])-97] if ...
1Python2
{ "input": [ "rquwmzexectvnbanemsmdufrg\n", "bbbabcbbb\n", "gamjuklsvzwddaocadujdmvlenyyvlflipneqofeyipmtunbdmbdyhkovnpdetueeiunsipowrhxrhtastjniqdhmehcumdcrghewljvpikcraoouhfwtnoaukbnykjapkvyakdnckkypargamvnsqtchesbmuffqqycnjvolmtpjfykvkeexkpdxjexrvdzpcbthhkxuucermkaebrvcxoovidpqnpkgbhiatyjvumihptrigqxse...
2CODEFORCES
335_B. Palindrome_1885
Given a string s, determine if it contains any palindrome of length exactly 100 as a subsequence. If it has any, print any one of them. If it doesn't have any, print a palindrome that is a subsequence of s and is as long as possible. Input The only line of the input contains one string s of length n (1 ≤ n ≤ 5·104) c...
#include <bits/stdc++.h> using namespace std; char s[50005]; int n, dp[3005][3005], dpc[3005][3005]; int gogo() { static int c[26]; memset((c), (0), sizeof((c))); for (int(i) = (int)(1); (i) <= (int)(n); ++(i)) ++c[s[i] - 'a']; int z = -1; for (int(i) = 0; (i) < (int)(26); ++(i)) if (c[i] > 100) z = i; ...
2C++
{ "input": [ "rquwmzexectvnbanemsmdufrg\n", "bbbabcbbb\n", "gamjuklsvzwddaocadujdmvlenyyvlflipneqofeyipmtunbdmbdyhkovnpdetueeiunsipowrhxrhtastjniqdhmehcumdcrghewljvpikcraoouhfwtnoaukbnykjapkvyakdnckkypargamvnsqtchesbmuffqqycnjvolmtpjfykvkeexkpdxjexrvdzpcbthhkxuucermkaebrvcxoovidpqnpkgbhiatyjvumihptrigqxse...
2CODEFORCES
335_B. Palindrome_1886
Given a string s, determine if it contains any palindrome of length exactly 100 as a subsequence. If it has any, print any one of them. If it doesn't have any, print a palindrome that is a subsequence of s and is as long as possible. Input The only line of the input contains one string s of length n (1 ≤ n ≤ 5·104) c...
def p2(a): n = len(a) last = [[0] * 26 for _ in range(n)] last[0][ord(a[0])-97] = 0 for i in range(1, n): for j in range(26): last[i][j] = last[i-1][j] last[i][ord(a[i])-97] = i dp = [''] * n for i in range(n-1, -1, -1): for j in range(n-1, i, -1): k = last[j][ord(a[i])-97] ...
3Python3
{ "input": [ "rquwmzexectvnbanemsmdufrg\n", "bbbabcbbb\n", "gamjuklsvzwddaocadujdmvlenyyvlflipneqofeyipmtunbdmbdyhkovnpdetueeiunsipowrhxrhtastjniqdhmehcumdcrghewljvpikcraoouhfwtnoaukbnykjapkvyakdnckkypargamvnsqtchesbmuffqqycnjvolmtpjfykvkeexkpdxjexrvdzpcbthhkxuucermkaebrvcxoovidpqnpkgbhiatyjvumihptrigqxse...
2CODEFORCES
335_B. Palindrome_1887
Given a string s, determine if it contains any palindrome of length exactly 100 as a subsequence. If it has any, print any one of them. If it doesn't have any, print a palindrome that is a subsequence of s and is as long as possible. Input The only line of the input contains one string s of length n (1 ≤ n ≤ 5·104) c...
// No sorcery shall prevail. import java.util.*; import java.io.*; public class Main { static long mod = 1000000007; static long mod2 = 998244353; static Scanner inp= new Scanner(System.in); static PrintWriter out= new PrintWriter(System.out); public static void main(String args[]) { Main g=new Main(); ...
4JAVA
{ "input": [ "rquwmzexectvnbanemsmdufrg\n", "bbbabcbbb\n", "gamjuklsvzwddaocadujdmvlenyyvlflipneqofeyipmtunbdmbdyhkovnpdetueeiunsipowrhxrhtastjniqdhmehcumdcrghewljvpikcraoouhfwtnoaukbnykjapkvyakdnckkypargamvnsqtchesbmuffqqycnjvolmtpjfykvkeexkpdxjexrvdzpcbthhkxuucermkaebrvcxoovidpqnpkgbhiatyjvumihptrigqxse...
2CODEFORCES
358_B. Dima and Text Messages_1888
Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other. Dima and Inna are using a secret code in their text messages. ...
n = input() init = [] for i in xrange(n): init.append(raw_input()) astring = raw_input() found_heart = False found_angle = False lindex = 0 windex = 0 for i in xrange(len(astring)): if found_heart: if len(init) == lindex: break if astring[i] == init[lindex][windex]: windex += 1 ...
1Python2
{ "input": [ "7\ni\nam\nnot\nmain\nin\nthe\nfamily\n&lt;3i&lt;&gt;3am&lt;3the&lt;3&lt;main&lt;3in&lt;3the&lt;3&gt;&lt;3family&lt;3\n", "3\ni\nlove\nyou\n&lt;3i&lt;3love&lt;23you&lt;3\n", "3\ni\nlove\nyou\n<3i<3love<23you<3ww\n", "1\na\n<3a<3b\n", "4\na\nb\nc\nd\n<3a<3b<3c<3d\n", "3\ni\nlove\ny...
2CODEFORCES
358_B. Dima and Text Messages_1889
Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other. Dima and Inna are using a secret code in their text messages. ...
#include <bits/stdc++.h> using namespace std; template <class T> inline T _abs(T n) { return n < 0 ? -n : n; } template <class T> inline T _gcd(T a, T b) { return b == 0 ? a : _gcd(b, a % b); } template <class T> inline T _lcm(T a, T b) { return a / _gcd(a, b) * b; } int main() { int n; string in, temp; str...
2C++
{ "input": [ "7\ni\nam\nnot\nmain\nin\nthe\nfamily\n&lt;3i&lt;&gt;3am&lt;3the&lt;3&lt;main&lt;3in&lt;3the&lt;3&gt;&lt;3family&lt;3\n", "3\ni\nlove\nyou\n&lt;3i&lt;3love&lt;23you&lt;3\n", "3\ni\nlove\nyou\n<3i<3love<23you<3ww\n", "1\na\n<3a<3b\n", "4\na\nb\nc\nd\n<3a<3b<3c<3d\n", "3\ni\nlove\ny...
2CODEFORCES
358_B. Dima and Text Messages_1890
Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other. Dima and Inna are using a secret code in their text messages. ...
def werify_message(words, message): true_message = ''.join(['<3', '<3'.join(words), '<3']) # index in true_message i = 0 for litera in message: if len(true_message) != i: if litera == true_message[i]: i += 1 else: # Дошли до конца исходного сообще...
3Python3
{ "input": [ "7\ni\nam\nnot\nmain\nin\nthe\nfamily\n&lt;3i&lt;&gt;3am&lt;3the&lt;3&lt;main&lt;3in&lt;3the&lt;3&gt;&lt;3family&lt;3\n", "3\ni\nlove\nyou\n&lt;3i&lt;3love&lt;23you&lt;3\n", "3\ni\nlove\nyou\n<3i<3love<23you<3ww\n", "1\na\n<3a<3b\n", "4\na\nb\nc\nd\n<3a<3b<3c<3d\n", "3\ni\nlove\ny...
2CODEFORCES
358_B. Dima and Text Messages_1891
Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other. Dima and Inna are using a secret code in their text messages. ...
import static java.lang.Math.*; import static java.lang.System.currentTimeMillis; import static java.lang.System.exit; import static java.lang.System.arraycopy; import static java.util.Arrays.sort; import static java.util.Arrays.binarySearch; import static java.util.Arrays.fill; import java.util.*; import java.io.*; p...
4JAVA
{ "input": [ "7\ni\nam\nnot\nmain\nin\nthe\nfamily\n&lt;3i&lt;&gt;3am&lt;3the&lt;3&lt;main&lt;3in&lt;3the&lt;3&gt;&lt;3family&lt;3\n", "3\ni\nlove\nyou\n&lt;3i&lt;3love&lt;23you&lt;3\n", "3\ni\nlove\nyou\n<3i<3love<23you<3ww\n", "1\na\n<3a<3b\n", "4\na\nb\nc\nd\n<3a<3b<3c<3d\n", "3\ni\nlove\ny...
2CODEFORCES
381_A. Sereja and Dima_1892
Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The ...
n = int(raw_input()) a = map(int, raw_input().split()) s = d = 0 while len(a): s += a.pop(0) if a[0] > a[-1] else a.pop() if len(a): d += a.pop(0) if a[0] > a[-1] else a.pop() print s, d
1Python2
{ "input": [ "7\n1 2 3 4 5 6 7\n", "4\n4 1 2 10\n", "1\n1\n", "30\n334 443 223 424 168 549 189 303 429 559 516 220 459 134 344 346 316 446 209 148 487 526 69 286 102 366 518 280 392 325\n", "95\n122 29 188 265 292 287 183 225 222 187 155 256 64 148 173 278 218 136 290 17 31 130 2 87 57 283 255 280...
2CODEFORCES
381_A. Sereja and Dima_1893
Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The ...
#include <bits/stdc++.h> using namespace std; int main() { int n, s = 0, d = 0, beg = 0, end = 0; cin >> n; int a[n]; end = n - 1; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { if (i % 2 == 0) { if (a[beg] < a[end]) { s += a[end]; end--; } else { ...
2C++
{ "input": [ "7\n1 2 3 4 5 6 7\n", "4\n4 1 2 10\n", "1\n1\n", "30\n334 443 223 424 168 549 189 303 429 559 516 220 459 134 344 346 316 446 209 148 487 526 69 286 102 366 518 280 392 325\n", "95\n122 29 188 265 292 287 183 225 222 187 155 256 64 148 173 278 218 136 290 17 31 130 2 87 57 283 255 280...
2CODEFORCES
381_A. Sereja and Dima_1894
Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The ...
n = int(input("")) cards=list(map(int,input().split())) sereja = 0 dima = 0 temp = 0 turn = 1 while cards != []: nMax=max(cards[0],cards[-1]) if turn==1: temp = sereja + nMax sereja+=nMax turn=2 else: temp = dima + nMax dima+=nMax turn=1 cards.remo...
3Python3
{ "input": [ "7\n1 2 3 4 5 6 7\n", "4\n4 1 2 10\n", "1\n1\n", "30\n334 443 223 424 168 549 189 303 429 559 516 220 459 134 344 346 316 446 209 148 487 526 69 286 102 366 518 280 392 325\n", "95\n122 29 188 265 292 287 183 225 222 187 155 256 64 148 173 278 218 136 290 17 31 130 2 87 57 283 255 280...
2CODEFORCES
381_A. Sereja and Dima_1895
Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The ...
import java.io.IOException; import java.util.Scanner; public class SerejaAndDima { public static void main(String[] args) throws IOException { Scanner s = new Scanner(System.in); short n = s.nextShort(); short card[] = new short[n]; short i, j; for (i=0; i<n; i++) { card[i] = s.nextShort(); } i...
4JAVA
{ "input": [ "7\n1 2 3 4 5 6 7\n", "4\n4 1 2 10\n", "1\n1\n", "30\n334 443 223 424 168 549 189 303 429 559 516 220 459 134 344 346 316 446 209 148 487 526 69 286 102 366 518 280 392 325\n", "95\n122 29 188 265 292 287 183 225 222 187 155 256 64 148 173 278 218 136 290 17 31 130 2 87 57 283 255 280...
2CODEFORCES
401_E. Olympic Games_1896
This problem was deleted from the contest, because it was used previously at another competition. Input Output Examples Input 1 1 1 2 100 Output 6
#include <bits/stdc++.h> using namespace std; long long num[100005], d[100005][6]; long long n, m, l, r, p; long long cal(long long ql, long long qh, long long mm) { qh /= mm; ql = (ql + mm - 1) / mm; return ((qh - ql + 1) * (n + 1) - mm * ((qh * (qh + 1) - ql * (ql - 1)) / 2)) % p; } int main(...
2C++
{ "input": [ "1 1\n1 2 100\n", "410 628\n1 169 10000000\n", "9427 7520\n2755 6002 90550139\n", "100000 99999\n150000 150000 1000000000\n", "9823 7106\n2179 15938 859849100\n", "1 1\n1 1 100\n", "100000 100000\n1 150000 1000000000\n", "100000 100000\n150000 150000 1000000000\n", "27...
2CODEFORCES
401_E. Olympic Games_1897
This problem was deleted from the contest, because it was used previously at another competition. Input Output Examples Input 1 1 1 2 100 Output 6
//package round235; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class E2 { InputStream is; PrintWriter out; String INPUT = ""; void solve() { int n = ni(), m = ...
4JAVA
{ "input": [ "1 1\n1 2 100\n", "410 628\n1 169 10000000\n", "9427 7520\n2755 6002 90550139\n", "100000 99999\n150000 150000 1000000000\n", "9823 7106\n2179 15938 859849100\n", "1 1\n1 1 100\n", "100000 100000\n1 150000 1000000000\n", "100000 100000\n150000 150000 1000000000\n", "27...
2CODEFORCES
42_A. Guilty — to the kitchen!_1898
It's a very unfortunate day for Volodya today. He got bad mark in algebra and was therefore forced to do some work in the kitchen, namely to cook borscht (traditional Russian soup). This should also improve his algebra skills. According to the borscht recipe it consists of n ingredients that have to be mixed in propor...
n,V = map(int, str(raw_input()).split()) a = map(int, str(raw_input()).split()) b = map(int, str(raw_input()).split()) for i in xrange(n): b[i] /= float(a[i]) xm = min(b) s = sum(a) print round(min(xm*s, V), 6)
1Python2
{ "input": [ "1 100\n1\n40\n", "2 100\n1 1\n60 60\n", "2 100\n1 1\n25 30\n", "5 5005\n5 53 65 52 99\n21 49 9 3 66\n", "14 3615\n81 79 13 94 54 69 92 5 47 98 40 64 44 88\n52 73 7 12 29 40 46 47 60 66 63 68 71 4\n", "7 529\n77 18 67 64 43 51 30\n35 87 17 52 1 97 84\n", "16 1718\n42 68 96 52 ...
2CODEFORCES
42_A. Guilty — to the kitchen!_1899
It's a very unfortunate day for Volodya today. He got bad mark in algebra and was therefore forced to do some work in the kitchen, namely to cook borscht (traditional Russian soup). This should also improve his algebra skills. According to the borscht recipe it consists of n ingredients that have to be mixed in propor...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > v; int comparar(double i, double j) { if (j - i > 1e-07) return -1; if (i - j > 1e-07) return 1; return 0; } int main() { int n, V; scanf("%d %d", &n, &V); v.clear(); v.resize(n); for (int i = 0; i < n; i++) scanf("%d", &v[i].first); ...
2C++
{ "input": [ "1 100\n1\n40\n", "2 100\n1 1\n60 60\n", "2 100\n1 1\n25 30\n", "5 5005\n5 53 65 52 99\n21 49 9 3 66\n", "14 3615\n81 79 13 94 54 69 92 5 47 98 40 64 44 88\n52 73 7 12 29 40 46 47 60 66 63 68 71 4\n", "7 529\n77 18 67 64 43 51 30\n35 87 17 52 1 97 84\n", "16 1718\n42 68 96 52 ...
2CODEFORCES