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 |
|---|---|---|---|---|---|
45_H. Road Problem_1300 | The Berland capital (as you very well know) contains n junctions, some pairs of which are connected by two-way roads. Unfortunately, the number of traffic jams in the capital has increased dramatically, that's why it was decided to build several new roads. Every road should connect two junctions.
The city administrat... | import sys
import threading
def main():
p = input().split()
n = int(p[0]) #number of locations
m = int(p[1]) #number of passages
if n==1: #if there's only one location, there's nothing to do
print(0)
return
if n==2: #if there's only two nodes, the only edge between them, is a... | 3Python3 | {
"input": [
"4 4\n1 2\n2 3\n2 4\n3 4\n",
"4 3\n1 2\n2 3\n3 4\n",
"10 9\n7 9\n8 9\n8 2\n10 6\n8 3\n9 4\n2 6\n8 5\n9 1\n",
"2 1\n1 2\n",
"20 20\n1 9\n11 9\n3 5\n15 13\n1 20\n11 18\n10 6\n10 8\n10 19\n12 16\n10 3\n9 18\n8 4\n15 1\n13 16\n11 2\n7 20\n10 15\n3 17\n17 14\n",
"20 20\n2 17\n5 17\n14 ... | 2CODEFORCES |
45_H. Road Problem_1301 | The Berland capital (as you very well know) contains n junctions, some pairs of which are connected by two-way roads. Unfortunately, the number of traffic jams in the capital has increased dramatically, that's why it was decided to build several new roads. Every road should connect two junctions.
The city administrat... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Stack;
import java.util.ArrayList;
import java.util.List;
imp... | 4JAVA | {
"input": [
"4 4\n1 2\n2 3\n2 4\n3 4\n",
"4 3\n1 2\n2 3\n3 4\n",
"10 9\n7 9\n8 9\n8 2\n10 6\n8 3\n9 4\n2 6\n8 5\n9 1\n",
"2 1\n1 2\n",
"20 20\n1 9\n11 9\n3 5\n15 13\n1 20\n11 18\n10 6\n10 8\n10 19\n12 16\n10 3\n9 18\n8 4\n15 1\n13 16\n11 2\n7 20\n10 15\n3 17\n17 14\n",
"20 20\n2 17\n5 17\n14 ... | 2CODEFORCES |
483_B. Friends and Presents_1302 | You have two friends. You want to present each of them several positive integers. You want to present cnt1 numbers to the first friend and cnt2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends.
In addition, the fir... | def solve(c1, c2, x, y):
l, h = 0, 10**18
while l < h:
m = l+(h-l)/2
if m-m/x >= c1 and m-m/y >= c2 and m-m/x/y >= c1+c2:
h = m
else:
l = m+1
return h
c1, c2, x, y = map(int, raw_input().split())
print solve(c1, c2, x, y)
| 1Python2 | {
"input": [
"3 1 2 3\n",
"1 3 2 3\n",
"1 999999999 29983 29989\n",
"9999999 10000 29983 29989\n",
"808351 17767 433 509\n",
"197 2 6361 18223\n",
"5099 2895 16273 29473\n",
"500000000 500000000 2 3\n",
"1000 9999999 29983 29989\n",
"1277613 596606 10427 29387\n",
"26941620... | 2CODEFORCES |
483_B. Friends and Presents_1303 | You have two friends. You want to present each of them several positive integers. You want to present cnt1 numbers to the first friend and cnt2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends.
In addition, the fir... | #include <bits/stdc++.h>
using namespace std;
int main() {
long cn1, cn2, x, y;
cin >> cn1 >> cn2 >> x >> y;
int lo = 1, hi = 0x7FFFFFFF, mid;
while (lo < hi) {
mid = lo + (hi - lo) / 2;
int rex = mid - (mid / x);
int rey = mid - (mid / y);
int total = mid - (mid / (x * y));
if (cn1 <= rex &... | 2C++ | {
"input": [
"3 1 2 3\n",
"1 3 2 3\n",
"1 999999999 29983 29989\n",
"9999999 10000 29983 29989\n",
"808351 17767 433 509\n",
"197 2 6361 18223\n",
"5099 2895 16273 29473\n",
"500000000 500000000 2 3\n",
"1000 9999999 29983 29989\n",
"1277613 596606 10427 29387\n",
"26941620... | 2CODEFORCES |
483_B. Friends and Presents_1304 | You have two friends. You want to present each of them several positive integers. You want to present cnt1 numbers to the first friend and cnt2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends.
In addition, the fir... | c1,c2,x,y=map(int,input().split())
def fn(val):
f=[val//x,val//y]
both=val//(x*y)
f=[i-both for i in f]
oth=val-f[0]-f[1]-both
cnt=[c1-f[1],c2-f[0]]
if cnt[0]<0:cnt[0]=0
if cnt[1] < 0: cnt[1] = 0
return (sum(cnt)<=oth)
l=0;r=int(1e18)
while r-l>1:
m=(r+l)//2
if fn(m):
r=m... | 3Python3 | {
"input": [
"3 1 2 3\n",
"1 3 2 3\n",
"1 999999999 29983 29989\n",
"9999999 10000 29983 29989\n",
"808351 17767 433 509\n",
"197 2 6361 18223\n",
"5099 2895 16273 29473\n",
"500000000 500000000 2 3\n",
"1000 9999999 29983 29989\n",
"1277613 596606 10427 29387\n",
"26941620... | 2CODEFORCES |
483_B. Friends and Presents_1305 | You have two friends. You want to present each of them several positive integers. You want to present cnt1 numbers to the first friend and cnt2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends.
In addition, the fir... | import java.io.*;
import java.util.*;
import org.omg.CORBA.PUBLIC_MEMBER;
public class Main
{
public static int cnt1,cnt2,x,y;
static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
public static void main(String[] args)throws IOException
{
while (in.nextToken()... | 4JAVA | {
"input": [
"3 1 2 3\n",
"1 3 2 3\n",
"1 999999999 29983 29989\n",
"9999999 10000 29983 29989\n",
"808351 17767 433 509\n",
"197 2 6361 18223\n",
"5099 2895 16273 29473\n",
"500000000 500000000 2 3\n",
"1000 9999999 29983 29989\n",
"1277613 596606 10427 29387\n",
"26941620... | 2CODEFORCES |
507_B. Amr and Pins_1306 | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius r and center in point (x, y). He wants the circle center to be in new position (x', y').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle ... | r, x, y, xi, yi = map(int, raw_input().split())
dist = ((xi - x)**2 + (yi - y)**2)**.5
print int(dist)//(r*2) + (1 if not dist.is_integer() or dist % (r*2) != 0 else 0)
| 1Python2 | {
"input": [
"1 1 1 4 4\n",
"2 0 0 0 4\n",
"4 5 6 5 6\n",
"1 100000 100000 100000 -100000\n",
"46456 -2621 -23623 -98302 -99305\n",
"9 20 0 40 0\n",
"100000 -100000 -100000 100000 100000\n",
"5 6 3 7 2\n",
"97741 23818 78751 97583 26933\n",
"99125 26876 -21414 14176 17443\n",
... | 2CODEFORCES |
507_B. Amr and Pins_1307 | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius r and center in point (x, y). He wants the circle center to be in new position (x', y').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle ... | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int r, x, y, x1, y1;
cin >> r >> x >> y >> x1 >> y1;
int ans;
ans = ceil(sqrt(pow(x - x1, 2) + pow(y - y1, 2)) / (2 * r));
cout << ans;
return 0;
}
| 2C++ | {
"input": [
"1 1 1 4 4\n",
"2 0 0 0 4\n",
"4 5 6 5 6\n",
"1 100000 100000 100000 -100000\n",
"46456 -2621 -23623 -98302 -99305\n",
"9 20 0 40 0\n",
"100000 -100000 -100000 100000 100000\n",
"5 6 3 7 2\n",
"97741 23818 78751 97583 26933\n",
"99125 26876 -21414 14176 17443\n",
... | 2CODEFORCES |
507_B. Amr and Pins_1308 | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius r and center in point (x, y). He wants the circle center to be in new position (x', y').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle ... | import math #.sqrt
def ceil (a, b):
return -(-a // b)
def answer(r, x, y, xp, yp):
d = math.sqrt((xp-x)**2 + (yp-y)**2)
num_rs = ceil(d, 2*r)
return int(num_rs)
def main():
r, x, y, xp, yp = [int(i) for i in input().split()]
print(answer(r, x, y, xp, yp))
return
main() | 3Python3 | {
"input": [
"1 1 1 4 4\n",
"2 0 0 0 4\n",
"4 5 6 5 6\n",
"1 100000 100000 100000 -100000\n",
"46456 -2621 -23623 -98302 -99305\n",
"9 20 0 40 0\n",
"100000 -100000 -100000 100000 100000\n",
"5 6 3 7 2\n",
"97741 23818 78751 97583 26933\n",
"99125 26876 -21414 14176 17443\n",
... | 2CODEFORCES |
507_B. Amr and Pins_1309 | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius r and center in point (x, y). He wants the circle center to be in new position (x', y').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle ... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class B {
public static void main(String[] args)throws Exception {
long r=in();
long x=in();
long y=in();
long x1=in();
long y1=in();
double d=Math.sqrt((x-x1)*(x-x1)+(... | 4JAVA | {
"input": [
"1 1 1 4 4\n",
"2 0 0 0 4\n",
"4 5 6 5 6\n",
"1 100000 100000 100000 -100000\n",
"46456 -2621 -23623 -98302 -99305\n",
"9 20 0 40 0\n",
"100000 -100000 -100000 100000 100000\n",
"5 6 3 7 2\n",
"97741 23818 78751 97583 26933\n",
"99125 26876 -21414 14176 17443\n",
... | 2CODEFORCES |
556_C. Case of Matryoshkas_1310 | Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be ... | I = lambda:map(int,raw_input().split())
n,k = I()
x = k
s = 0
for i in range(k):
lst = list(I())
s = s + len(lst) - 2
x = x + len(lst) - 2
if lst[1] == 1:
for j in range(2,len(lst)):
if lst[j] == j:
x = x - 1
s = s - 1
print x+s-1
... | 1Python2 | {
"input": [
"3 2\n2 1 2\n1 3\n",
"7 3\n3 1 3 7\n2 2 5\n2 4 6\n",
"100 3\n45 1 2 3 4 5 6 7 8 9 19 21 24 27 28 30 34 35 37 39 40 41 42 43 46 47 48 51 52 55 58 59 61 63 64 66 69 71 76 80 85 86 88 89 94 99\n26 10 11 15 18 23 29 31 33 36 38 44 49 54 56 60 62 65 75 78 82 83 84 95 96 97 98\n29 12 13 14 16 17 20... | 2CODEFORCES |
556_C. Case of Matryoshkas_1311 | Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be ... | #include <bits/stdc++.h>
using namespace std;
vector<vector<int> > v;
int main() {
int i, j, k, n, c = 0;
cin >> n >> k;
for (i = 0; i < k; i++) {
int temp;
cin >> temp;
vector<int> v1;
for (j = 0; j < temp; j++) {
int t;
cin >> t;
v1.push_back(t);
}
if (v1.size() > 1) {
... | 2C++ | {
"input": [
"3 2\n2 1 2\n1 3\n",
"7 3\n3 1 3 7\n2 2 5\n2 4 6\n",
"100 3\n45 1 2 3 4 5 6 7 8 9 19 21 24 27 28 30 34 35 37 39 40 41 42 43 46 47 48 51 52 55 58 59 61 63 64 66 69 71 76 80 85 86 88 89 94 99\n26 10 11 15 18 23 29 31 33 36 38 44 49 54 56 60 62 65 75 78 82 83 84 95 96 97 98\n29 12 13 14 16 17 20... | 2CODEFORCES |
556_C. Case of Matryoshkas_1312 | Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be ... | n, m = [int(x) for x in input().split()]
a = []
for i in range(m):
a.append([int(x) for x in input().split()][1:])
b = []
curt = 0
for i in a:
j = 0
b.append([])
while (j < len(i)) and (i[j] == (j + 1)):
j += 1
if j != 0:
b[-1] = [j]
b[-1] += [1] * (len(i) - j)
curt += len(b[... | 3Python3 | {
"input": [
"3 2\n2 1 2\n1 3\n",
"7 3\n3 1 3 7\n2 2 5\n2 4 6\n",
"100 3\n45 1 2 3 4 5 6 7 8 9 19 21 24 27 28 30 34 35 37 39 40 41 42 43 46 47 48 51 52 55 58 59 61 63 64 66 69 71 76 80 85 86 88 89 94 99\n26 10 11 15 18 23 29 31 33 36 38 44 49 54 56 60 62 65 75 78 82 83 84 95 96 97 98\n29 12 13 14 16 17 20... | 2CODEFORCES |
556_C. Case of Matryoshkas_1313 | Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be ... | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.StringTokenizer;
public class Main {
static class Reader
{
BufferedRe... | 4JAVA | {
"input": [
"3 2\n2 1 2\n1 3\n",
"7 3\n3 1 3 7\n2 2 5\n2 4 6\n",
"100 3\n45 1 2 3 4 5 6 7 8 9 19 21 24 27 28 30 34 35 37 39 40 41 42 43 46 47 48 51 52 55 58 59 61 63 64 66 69 71 76 80 85 86 88 89 94 99\n26 10 11 15 18 23 29 31 33 36 38 44 49 54 56 60 62 65 75 78 82 83 84 95 96 97 98\n29 12 13 14 16 17 20... | 2CODEFORCES |
582_A. GCD Table_1314 | The GCD table G of size n × n for an array of positive integers a of length n is defined by formula
<image>
Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as <image>. For example, for array a = {4, 3, 6,... | import sys
n = input()
l = raw_input().split()
a = [int(i) for i in l]
a.sort(reverse=True)
d = {}
for i in a:
if d.has_key(i):
d[i]+=1
else:
d[i]=1
now = [0]
def getNext(now):
while d[a[now[0]]]==0:
now[0]+=1
d[a[now[0]]]-=1
return a[now[0]]
def gcd(a,b):
if a%b==0: return b
return gcd(b,a%b)
ans = ... | 1Python2 | {
"input": [
"4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2\n",
"1\n42\n",
"2\n1 1 1 1\n",
"3\n121339 121339 121339 55451923 531222142 121339 121339 435485671 121339\n",
"3\n1 7 923264237 374288891 7 524125987 1 1 1\n",
"5\n2029 6087 2029 2029 6087 2029 527243766 4058 2029 2029 2029 2029 2029 2029 2029 2... | 2CODEFORCES |
582_A. GCD Table_1315 | The GCD table G of size n × n for an array of positive integers a of length n is defined by formula
<image>
Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as <image>. For example, for array a = {4, 3, 6,... | #include <bits/stdc++.h>
using namespace std;
vector<int> a;
map<int, int> m;
int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
int val;
scanf("%d", &val);
m[-val]++;
}
for (auto i... | 2C++ | {
"input": [
"4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2\n",
"1\n42\n",
"2\n1 1 1 1\n",
"3\n121339 121339 121339 55451923 531222142 121339 121339 435485671 121339\n",
"3\n1 7 923264237 374288891 7 524125987 1 1 1\n",
"5\n2029 6087 2029 2029 6087 2029 527243766 4058 2029 2029 2029 2029 2029 2029 2029 2... | 2CODEFORCES |
582_A. GCD Table_1316 | The GCD table G of size n × n for an array of positive integers a of length n is defined by formula
<image>
Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as <image>. For example, for array a = {4, 3, 6,... | import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.wri... | 3Python3 | {
"input": [
"4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2\n",
"1\n42\n",
"2\n1 1 1 1\n",
"3\n121339 121339 121339 55451923 531222142 121339 121339 435485671 121339\n",
"3\n1 7 923264237 374288891 7 524125987 1 1 1\n",
"5\n2029 6087 2029 2029 6087 2029 527243766 4058 2029 2029 2029 2029 2029 2029 2029 2... | 2CODEFORCES |
582_A. GCD Table_1317 | The GCD table G of size n × n for an array of positive integers a of length n is defined by formula
<image>
Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as <image>. For example, for array a = {4, 3, 6,... | //package round323;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.List;
public class A {
InputStream is;
PrintWriter out;
String I... | 4JAVA | {
"input": [
"4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2\n",
"1\n42\n",
"2\n1 1 1 1\n",
"3\n121339 121339 121339 55451923 531222142 121339 121339 435485671 121339\n",
"3\n1 7 923264237 374288891 7 524125987 1 1 1\n",
"5\n2029 6087 2029 2029 6087 2029 527243766 4058 2029 2029 2029 2029 2029 2029 2029 2... | 2CODEFORCES |
604_A. Uncowed Forces_1318 | Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd a... | n = 5;
ans = 0;
x = [500,1000,1500,2000,2500]
t = map(int,raw_input().split())
w = map(int,raw_input().split())
hs,hf = map(int,raw_input().split())
for i in range(n):
ans += (max((0.3*x[i]),(1.0-(1.0*t[i]/250.0))*x[i]-50.0*w[i]))
print (int)(ans) + 100*hs - 50*hf | 1Python2 | {
"input": [
"20 40 60 80 100\n0 1 2 3 4\n1 0\n",
"119 119 119 119 119\n0 0 0 0 0\n10 0\n",
"36 102 73 101 19\n5 9 2 2 6\n4 13\n",
"119 0 0 0 0\n2 0 0 0 0\n5 5\n",
"0 0 119 0 0\n0 0 2 0 0\n5 5\n",
"0 0 0 0 0\n10 10 10 10 10\n0 20\n",
"0 46 86 72 40\n1 5 5 5 9\n6 5\n",
"45 45 75 36 76\n... | 2CODEFORCES |
604_A. Uncowed Forces_1319 | Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd a... | #include <bits/stdc++.h>
using namespace std;
int main() {
int m[5], w[5], h[2], score[5] = {500, 1000, 1500, 2000, 2500};
for (int i = 0; i < 5; i++) cin >> m[i];
for (int i = 0; i < 5; i++) cin >> w[i];
cin >> h[0] >> h[1];
int ans = 0;
for (int i = 0; i < 5; i++) {
int mx = (3 * score[i]) / 10;
i... | 2C++ | {
"input": [
"20 40 60 80 100\n0 1 2 3 4\n1 0\n",
"119 119 119 119 119\n0 0 0 0 0\n10 0\n",
"36 102 73 101 19\n5 9 2 2 6\n4 13\n",
"119 0 0 0 0\n2 0 0 0 0\n5 5\n",
"0 0 119 0 0\n0 0 2 0 0\n5 5\n",
"0 0 0 0 0\n10 10 10 10 10\n0 20\n",
"0 46 86 72 40\n1 5 5 5 9\n6 5\n",
"45 45 75 36 76\n... | 2CODEFORCES |
604_A. Uncowed Forces_1320 | Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd a... | t=list(map(int,input().split()))
w=list(map(int,input().split()))
q,z=map(int,input().split())
c=0
v=0
for i in range(500,3000,500):
x=(1-(t[v]/250))*i-50*w[v]
a=max(0.3*i,x)
c=c+a
v=v+1
f=q*100-z*50
dp=c+f
print(int(dp))
| 3Python3 | {
"input": [
"20 40 60 80 100\n0 1 2 3 4\n1 0\n",
"119 119 119 119 119\n0 0 0 0 0\n10 0\n",
"36 102 73 101 19\n5 9 2 2 6\n4 13\n",
"119 0 0 0 0\n2 0 0 0 0\n5 5\n",
"0 0 119 0 0\n0 0 2 0 0\n5 5\n",
"0 0 0 0 0\n10 10 10 10 10\n0 20\n",
"0 46 86 72 40\n1 5 5 5 9\n6 5\n",
"45 45 75 36 76\n... | 2CODEFORCES |
604_A. Uncowed Forces_1321 | Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd a... | import java.util.Scanner;
public class ez {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int[] time = new int[5];
int[] wrong = new int[5];
for(int i = 0; i < 5; i++){
time[i]=in.nextInt();
}
for(int i = 0; i < 5; i++){
wrong[i]=in.nextInt();
}
double score =0;
... | 4JAVA | {
"input": [
"20 40 60 80 100\n0 1 2 3 4\n1 0\n",
"119 119 119 119 119\n0 0 0 0 0\n10 0\n",
"36 102 73 101 19\n5 9 2 2 6\n4 13\n",
"119 0 0 0 0\n2 0 0 0 0\n5 5\n",
"0 0 119 0 0\n0 0 2 0 0\n5 5\n",
"0 0 0 0 0\n10 10 10 10 10\n0 20\n",
"0 46 86 72 40\n1 5 5 5 9\n6 5\n",
"45 45 75 36 76\n... | 2CODEFORCES |
626_D. Jerry's Protest_1322 | Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds. In each round, Andrew and Jerry draw randomly without replacement from a jar containing n balls, each labeled with a distinct positive integer. Without looking, they hand their balls to Harry, who awards the point to t... | n , m = input() , map(int,raw_input().split())
a = {}
for i in xrange(n-1):
for j in xrange(i+1,n):
x = abs(m[i]-m[j])
if x in a:
a[x]+=1
else:
a[x]=1
d = [i for i in a]
b = [0]*10005
for i in xrange(len(d)):
for j in xrange(i,len(d)):
if d[i]==d[j]:
b[d[i]+d[j]] += a[d[i]]*a[d[j]]
else:
b[d[i... | 1Python2 | {
"input": [
"3\n1 2 10\n",
"2\n1 2\n",
"11\n54 91 4 6 88 23 38 71 77 26 84\n",
"20\n11 37 81 56 61 2 26 27 59 69 24 7 71 76 45 54 89 17 95 20\n",
"13\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096\n",
"11\n1 2 4 8 16 32 64 128 256 512 1024\n",
"4\n2 4 1 3\n",
"15\n1 2 3 4 5 10 20 40 80 ... | 2CODEFORCES |
626_D. Jerry's Protest_1323 | Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds. In each round, Andrew and Jerry draw randomly without replacement from a jar containing n balls, each labeled with a distinct positive integer. Without looking, they hand their balls to Harry, who awards the point to t... | #include <bits/stdc++.h>
using namespace std;
long long t[2222];
long long p1[5555];
long long p2[20000];
int main() {
long long n;
cin >> n;
for (long long i = 0; i < n; ++i) {
cin >> t[i];
}
sort(t, t + n);
for (long long i = 0; i < n; ++i) {
for (long long j = i + 1; j < n; ++j) {
p1[t[j] -... | 2C++ | {
"input": [
"3\n1 2 10\n",
"2\n1 2\n",
"11\n54 91 4 6 88 23 38 71 77 26 84\n",
"20\n11 37 81 56 61 2 26 27 59 69 24 7 71 76 45 54 89 17 95 20\n",
"13\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096\n",
"11\n1 2 4 8 16 32 64 128 256 512 1024\n",
"4\n2 4 1 3\n",
"15\n1 2 3 4 5 10 20 40 80 ... | 2CODEFORCES |
626_D. Jerry's Protest_1324 | Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds. In each round, Andrew and Jerry draw randomly without replacement from a jar containing n balls, each labeled with a distinct positive integer. Without looking, they hand their balls to Harry, who awards the point to t... | def main():
n = int(input())
a = list(map(int, input().split()))
max_element = max(a) + 1
#print(max_element)
diff_freq = [0 for i in range(max_element)]
for i in range(n):
for j in range(i):
diff_freq[abs(a[i] - a[j])] += 1
largest = [0 for i in range(max_element)]
... | 3Python3 | {
"input": [
"3\n1 2 10\n",
"2\n1 2\n",
"11\n54 91 4 6 88 23 38 71 77 26 84\n",
"20\n11 37 81 56 61 2 26 27 59 69 24 7 71 76 45 54 89 17 95 20\n",
"13\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096\n",
"11\n1 2 4 8 16 32 64 128 256 512 1024\n",
"4\n2 4 1 3\n",
"15\n1 2 3 4 5 10 20 40 80 ... | 2CODEFORCES |
626_D. Jerry's Protest_1325 | Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds. In each round, Andrew and Jerry draw randomly without replacement from a jar containing n balls, each labeled with a distinct positive integer. Without looking, they hand their balls to Harry, who awards the point to t... | import java.util.*;
public class JerrysProtest
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] array = new int[n];
for(int x = 0; x < n; x++)
{
array[x] = in.nextInt();
}
Arrays.sort(array);
long[] freq = new long[5000];
for(... | 4JAVA | {
"input": [
"3\n1 2 10\n",
"2\n1 2\n",
"11\n54 91 4 6 88 23 38 71 77 26 84\n",
"20\n11 37 81 56 61 2 26 27 59 69 24 7 71 76 45 54 89 17 95 20\n",
"13\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096\n",
"11\n1 2 4 8 16 32 64 128 256 512 1024\n",
"4\n2 4 1 3\n",
"15\n1 2 3 4 5 10 20 40 80 ... | 2CODEFORCES |
650_B. Image Preview_1326 | Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reach photo n. Similarly, by swiping right from the last photo you reach photo 1. It takes a sec... | def main():
n, a, b, t = map(int, raw_input().split())
b += 1
l = [b if char == "w" else 1 for char in raw_input()]
t -= sum(l) - a * (n + 2)
hi, n2 = n, n * 2
n3 = n2 + 1
lo = res = 0
l *= 2
while lo <= n and hi < n2:
t -= l[hi]
hi += 1
b = hi - n
whi... | 1Python2 | {
"input": [
"5 2 4 13\nhhwhh\n",
"3 1 100 10\nwhw\n",
"5 2 4 1000\nhhwhh\n",
"4 2 3 10\nwwhw\n",
"5 2 4 12\nhhhwh\n",
"2 5 5 1000000000\nwh\n",
"16 1 1000 2100\nhhhwwwhhhwhhhwww\n",
"1 2 3 3\nw\n",
"10 2 3 32\nhhwwhwhwwh\n",
"5 2 4 13\nhhhwh\n",
"7 1 1000 13\nhhhhwhh\n",
... | 2CODEFORCES |
650_B. Image Preview_1327 | Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reach photo n. Similarly, by swiping right from the last photo you reach photo 1. It takes a sec... | #include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, k, b, t;
cin >> n >> k >> b >> t;
string s;
cin >> s;
long long sum = 0;
long long a[2 * n + (long long)10];
for (long long i = 0; i < n; i++) {
a[i] = a[i + n] = ((s[i] == 'w') ? (b + 1) : 1);
sum += a[i];
}
sum -= a[0]... | 2C++ | {
"input": [
"5 2 4 13\nhhwhh\n",
"3 1 100 10\nwhw\n",
"5 2 4 1000\nhhwhh\n",
"4 2 3 10\nwwhw\n",
"5 2 4 12\nhhhwh\n",
"2 5 5 1000000000\nwh\n",
"16 1 1000 2100\nhhhwwwhhhwhhhwww\n",
"1 2 3 3\nw\n",
"10 2 3 32\nhhwwhwhwwh\n",
"5 2 4 13\nhhhwh\n",
"7 1 1000 13\nhhhhwhh\n",
... | 2CODEFORCES |
650_B. Image Preview_1328 | Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reach photo n. Similarly, by swiping right from the last photo you reach photo 1. It takes a sec... | def main():
n, a, b, t = map(int, input().split())
b += 1
l = [b if char == "w" else 1 for char in input()]
t -= sum(l) - a * (n + 2)
hi, n2 = n, n * 2
n21 = n2 + 1
lo = res = 0
l *= 2
while lo <= n and hi < n2:
t -= l[hi]
hi += 1
b = hi - n
while lo <... | 3Python3 | {
"input": [
"5 2 4 13\nhhwhh\n",
"3 1 100 10\nwhw\n",
"5 2 4 1000\nhhwhh\n",
"4 2 3 10\nwwhw\n",
"5 2 4 12\nhhhwh\n",
"2 5 5 1000000000\nwh\n",
"16 1 1000 2100\nhhhwwwhhhwhhhwww\n",
"1 2 3 3\nw\n",
"10 2 3 32\nhhwwhwhwwh\n",
"5 2 4 13\nhhhwh\n",
"7 1 1000 13\nhhhhwhh\n",
... | 2CODEFORCES |
650_B. Image Preview_1329 | Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reach photo n. Similarly, by swiping right from the last photo you reach photo 1. It takes a sec... | import javafx.util.Pair;
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
Reader in = new Reader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
int n = in.nextI... | 4JAVA | {
"input": [
"5 2 4 13\nhhwhh\n",
"3 1 100 10\nwhw\n",
"5 2 4 1000\nhhwhh\n",
"4 2 3 10\nwwhw\n",
"5 2 4 12\nhhhwh\n",
"2 5 5 1000000000\nwh\n",
"16 1 1000 2100\nhhhwwwhhhwhhhwww\n",
"1 2 3 3\nw\n",
"10 2 3 32\nhhwwhwhwwh\n",
"5 2 4 13\nhhhwh\n",
"7 1 1000 13\nhhhhwhh\n",
... | 2CODEFORCES |
675_E. Trains and Statistic_1330 | Vasya commutes by train every day. There are n train stations in the city, and at the i-th station it's possible to buy only tickets to stations from i + 1 to ai inclusive. No tickets are sold at the last station.
Let ρi, j be the minimum number of tickets one needs to buy in order to get from stations i to station j.... | MAX = 100000
def push(loc, value):
key = value + loc
cur = base_loc + loc
tree[cur] = key * MAX + loc
while cur > 1:
cur /= 2
if tree[cur] / MAX > key:
tree[cur] = key * MAX + loc
else:
break
def minimum(loc):
cur = 1
cur_low = 0
cur_high = tree_width
sofar = 5000000000 * MAX
while cur < tree_siz... | 1Python2 | {
"input": [
"4\n4 4 4\n",
"5\n2 3 5 5\n",
"7\n7 3 4 6 6 7\n",
"4\n3 3 4\n",
"6\n3 3 6 6 6\n",
"5\n4 4 4 5\n",
"9\n2 9 7 6 9 7 8 9\n",
"3\n3 3\n",
"8\n3 7 7 8 8 7 8\n",
"10\n2 10 8 7 8 8 10 9 10\n",
"2\n2\n",
"9\n3 9 7 6 9 7 8 9\n",
"4\n3 4 4\n",
"8\n3 5 7 8 8 7... | 2CODEFORCES |
675_E. Trains and Statistic_1331 | Vasya commutes by train every day. There are n train stations in the city, and at the i-th station it's possible to buy only tickets to stations from i + 1 to ai inclusive. No tickets are sold at the last station.
Let ρi, j be the minimum number of tickets one needs to buy in order to get from stations i to station j.... | #include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e5 + 100;
vector<int> tr(4 * maxn), a(maxn);
void upd(int idx) {
int l = idx * 2, r = idx * 2 + 1;
if (tr[l] == -1 || tr[r] == -1) {
tr[idx] = max(tr[l], tr[r]);
} else {
(a[tr[l]] >= a[tr[r]] ? tr[idx] = tr[l] : tr[idx] = tr[r]);
}
}
... | 2C++ | {
"input": [
"4\n4 4 4\n",
"5\n2 3 5 5\n",
"7\n7 3 4 6 6 7\n",
"4\n3 3 4\n",
"6\n3 3 6 6 6\n",
"5\n4 4 4 5\n",
"9\n2 9 7 6 9 7 8 9\n",
"3\n3 3\n",
"8\n3 7 7 8 8 7 8\n",
"10\n2 10 8 7 8 8 10 9 10\n",
"2\n2\n",
"9\n3 9 7 6 9 7 8 9\n",
"4\n3 4 4\n",
"8\n3 5 7 8 8 7... | 2CODEFORCES |
675_E. Trains and Statistic_1332 | Vasya commutes by train every day. There are n train stations in the city, and at the i-th station it's possible to buy only tickets to stations from i + 1 to ai inclusive. No tickets are sold at the last station.
Let ρi, j be the minimum number of tickets one needs to buy in order to get from stations i to station j.... | n=int(input())
a=list(map(int, input().split()))
a=[ai-1 for ai in a]
a[n:n] = [n - 1]
dp=[0]*n
ans=0
i=n-2
nmax=2**17
tree=[[0,0]]*2*nmax;
#Build Segment tree
j=0
while j<n:
tree[nmax + j] = [a[j], j]
j=j+1
j=nmax-1
while j>0:
tree[j]=max(tree[j*2],tree[j*2+1])
j=j-1
#get max of a interval [lef... | 3Python3 | {
"input": [
"4\n4 4 4\n",
"5\n2 3 5 5\n",
"7\n7 3 4 6 6 7\n",
"4\n3 3 4\n",
"6\n3 3 6 6 6\n",
"5\n4 4 4 5\n",
"9\n2 9 7 6 9 7 8 9\n",
"3\n3 3\n",
"8\n3 7 7 8 8 7 8\n",
"10\n2 10 8 7 8 8 10 9 10\n",
"2\n2\n",
"9\n3 9 7 6 9 7 8 9\n",
"4\n3 4 4\n",
"8\n3 5 7 8 8 7... | 2CODEFORCES |
675_E. Trains and Statistic_1333 | Vasya commutes by train every day. There are n train stations in the city, and at the i-th station it's possible to buy only tickets to stations from i + 1 to ai inclusive. No tickets are sold at the last station.
Let ρi, j be the minimum number of tickets one needs to buy in order to get from stations i to station j.... | /*-
* Codeforces problem :
* http://codeforces.com/problemset/problem/675/E
*
* Print the sum of ρi,j among all pairs of 1 ≤ i < j ≤ n.
*/
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.Inp... | 4JAVA | {
"input": [
"4\n4 4 4\n",
"5\n2 3 5 5\n",
"7\n7 3 4 6 6 7\n",
"4\n3 3 4\n",
"6\n3 3 6 6 6\n",
"5\n4 4 4 5\n",
"9\n2 9 7 6 9 7 8 9\n",
"3\n3 3\n",
"8\n3 7 7 8 8 7 8\n",
"10\n2 10 8 7 8 8 10 9 10\n",
"2\n2\n",
"9\n3 9 7 6 9 7 8 9\n",
"4\n3 4 4\n",
"8\n3 5 7 8 8 7... | 2CODEFORCES |
699_F. Limak and Shooting Points_1334 | Bearland is a dangerous place. Limak can’t travel on foot. Instead, he has k magic teleportation stones. Each stone can be used at most once. The i-th stone allows to teleport to a point (axi, ayi). Limak can use stones in any order.
There are n monsters in Bearland. The i-th of them stands at (mxi, myi).
The given k... | #include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
if (a < b) a = b;
}
int power(int a, int b, int m, int ans = 1) {
for (; b; b >>= 1, a = 1LL * a * a % m)
if (b & 1)... | 2C++ | {
"input": [
"3 8\n10 20\n0 0\n20 40\n300 600\n30 60\n170 340\n50 100\n28 56\n90 180\n-4 -8\n-1 -2\n",
"2 4\n-2 -1\n4 5\n4 2\n2 1\n4 -1\n1 -1\n",
"1 10\n778084 -205153\n778001 -205093\n778155 -205118\n778168 -204997\n778066 -205141\n778146 -205036\n778041 -205063\n778012 -204996\n778132 -205128\n778049 -2... | 2CODEFORCES |
699_F. Limak and Shooting Points_1335 | Bearland is a dangerous place. Limak can’t travel on foot. Instead, he has k magic teleportation stones. Each stone can be used at most once. The i-th stone allows to teleport to a point (axi, ayi). Limak can use stones in any order.
There are n monsters in Bearland. The i-th of them stands at (mxi, myi).
The given k... | // package codeforces.cf3xx.cf363.div1;
import java.io.PrintWriter;
import java.util.*;
import java.util.concurrent.ArrayBlockingQueue;
/**
* Created by hama_du on 2016/07/19.
*/
public class D {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
PrintWriter out = new ... | 4JAVA | {
"input": [
"3 8\n10 20\n0 0\n20 40\n300 600\n30 60\n170 340\n50 100\n28 56\n90 180\n-4 -8\n-1 -2\n",
"2 4\n-2 -1\n4 5\n4 2\n2 1\n4 -1\n1 -1\n",
"1 10\n778084 -205153\n778001 -205093\n778155 -205118\n778168 -204997\n778066 -205141\n778146 -205036\n778041 -205063\n778012 -204996\n778132 -205128\n778049 -2... | 2CODEFORCES |
720_C. Homework_1336 | Today Peter has got an additional homework for tomorrow. The teacher has given three integers to him: n, m and k, and asked him to mark one or more squares on a square grid of size n × m.
The marked squares must form a connected figure, and there must be exactly k triples of marked squares that form an L-shaped tromi... | #include <bits/stdc++.h>
using namespace std;
const int N = 41414;
bool a[N][320], as[N][320];
int n, m, k, ty, tl, t, z, mx;
bool pd(int k) {
if (k < 0 || k == 1 || k == 2 || k == 5 || k == 4 ||
k == 8 && n != 3 && m != 3)
return 1;
return 0;
}
void dfs(int x, int y, int ct) {
if (tl) return;
if ((x ... | 2C++ | {
"input": [
"3\n3 3 4\n3 3 5\n3 3 3\n",
"1\n317 314 18260\n",
"1\n315 315 355287\n",
"1\n316 314 143218\n",
"1\n516 6 6571\n",
"1\n317 315 396613\n",
"1\n18 5 158\n",
"1\n315 316 124373\n",
"1\n315 317 46432\n",
"1\n314 317 33011\n",
"1\n316 316 153829\n",
"1\n314 315 ... | 2CODEFORCES |
741_E. Arpa’s abnormal DNA and Mehrdad’s deep interest_1337 | All of us know that girls in Arpa’s land are... ok, you’ve got the idea :D
Anyone knows that Arpa isn't a normal man, he is ... well, sorry, I can't explain it more. Mehrdad is interested about the reason, so he asked Sipa, one of the best biology scientists in Arpa's land, for help. Sipa has a DNA editor.
<image>
S... | #include <bits/stdc++.h>
static const int MAXN = 200007;
static const int MAXQ = 100003;
static const int LOGN = 18;
static const int ALPHA_SZ = 29;
static const char ALPHA_OFFSET = '_';
static const int SOLANUM_TUBEROSUM = 128;
namespace sfx {
char *s;
int n;
int sa[MAXN], rk[MAXN], lcp[MAXN], nw[MAXN];
int st[MAXN][L... | 2C++ | {
"input": [
"abbbbbbaaa baababaaab 10\n1 2 1 0 0\n2 7 8 4 7\n2 3 9 2 8\n3 4 6 1 1\n0 8 5 2 4\n2 8 10 4 7\n7 10 1 0 0\n1 4 6 0 2\n0 9 8 0 6\n4 8 5 0 1\n",
"abc d 4\n0 3 2 0 0\n0 3 1 0 0\n1 2 1 0 0\n0 1 3 2 2\n",
"xkbvkadjec gqjlhxpnsx 10\n2 7 1 0 0\n2 5 8 0 0\n4 7 8 0 4\n0 4 7 3 6\n5 5 9 3 7\n7 9 5 0 3\n6... | 2CODEFORCES |
741_E. Arpa’s abnormal DNA and Mehrdad’s deep interest_1338 | All of us know that girls in Arpa’s land are... ok, you’ve got the idea :D
Anyone knows that Arpa isn't a normal man, he is ... well, sorry, I can't explain it more. Mehrdad is interested about the reason, so he asked Sipa, one of the best biology scientists in Arpa's land, for help. Sipa has a DNA editor.
<image>
S... | //package round383;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;
public class E3 {
InputStream is;
PrintWriter out;
String INPUT = "";
void so... | 4JAVA | {
"input": [
"abbbbbbaaa baababaaab 10\n1 2 1 0 0\n2 7 8 4 7\n2 3 9 2 8\n3 4 6 1 1\n0 8 5 2 4\n2 8 10 4 7\n7 10 1 0 0\n1 4 6 0 2\n0 9 8 0 6\n4 8 5 0 1\n",
"abc d 4\n0 3 2 0 0\n0 3 1 0 0\n1 2 1 0 0\n0 1 3 2 2\n",
"xkbvkadjec gqjlhxpnsx 10\n2 7 1 0 0\n2 5 8 0 0\n4 7 8 0 4\n0 4 7 3 6\n5 5 9 3 7\n7 9 5 0 3\n6... | 2CODEFORCES |
765_D. Artsem and Saunders_1339 | Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.
Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is defined in integer points 1, ..., x, and all its values are integers from 1 to y.
Now then, you are given a function f: [... | n = int(raw_input())
data = map(int, raw_input().split())
inPlace = 0
values = set()
for i in range(len(data)):
values.add(data[i])
if data[i] == i + 1:
inPlace += 1
if inPlace != len(values):
print -1
else:
h = [0] * len(values)
ind = 0
hi = {}
for v in values:
h[ind] = v
hi[v] = ind
ind += 1
g = [... | 1Python2 | {
"input": [
"3\n1 2 3\n",
"3\n2 2 2\n",
"2\n2 1\n",
"3\n2 2 3\n",
"5\n1 4 5 4 5\n",
"4\n2 2 4 4\n",
"3\n1 1 2\n",
"4\n1 2 1 2\n",
"4\n4 2 2 4\n",
"6\n1 2 3 4 5 5\n",
"1\n1\n",
"10\n4 4 4 4 4 4 4 4 4 4\n",
"7\n7 3 3 5 5 7 7\n",
"5\n1 2 3 4 3\n",
"4\n1 2 1 1\... | 2CODEFORCES |
765_D. Artsem and Saunders_1340 | Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.
Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is defined in integer points 1, ..., x, and all its values are integers from 1 to y.
Now then, you are given a function f: [... | #include <bits/stdc++.h>
#pragma warning(disable : 4996)
const int kMaxn = 100010;
int n, m, a[kMaxn], g[kMaxn], h[kMaxn];
int main() {
static int i, j, k, x, now, ans;
scanf("%d", &n);
for (i = 1; i <= n; ++i) scanf("%d", a + i);
m = 0;
memset(g, 0, sizeof(g));
memset(h, 0, sizeof(h));
for (i = 1; i <= n... | 2C++ | {
"input": [
"3\n1 2 3\n",
"3\n2 2 2\n",
"2\n2 1\n",
"3\n2 2 3\n",
"5\n1 4 5 4 5\n",
"4\n2 2 4 4\n",
"3\n1 1 2\n",
"4\n1 2 1 2\n",
"4\n4 2 2 4\n",
"6\n1 2 3 4 5 5\n",
"1\n1\n",
"10\n4 4 4 4 4 4 4 4 4 4\n",
"7\n7 3 3 5 5 7 7\n",
"5\n1 2 3 4 3\n",
"4\n1 2 1 1\... | 2CODEFORCES |
765_D. Artsem and Saunders_1341 | Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.
Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is defined in integer points 1, ..., x, and all its values are integers from 1 to y.
Now then, you are given a function f: [... | n = int(input())
f = list(map(int, input().split()))
h = []
ind_h = [-1] * (n + 1)
g = [0] * n
occs = {}
for i in range(len(f)):
if f[i] not in occs:
occs[f[i]] = {i + 1}
h.append(f[i])
ind_h[f[i]] = len(h) - 1
g[i] = len(h)
else:
g[i] = ind_h[f[i]] + 1
occs[f[i]]... | 3Python3 | {
"input": [
"3\n1 2 3\n",
"3\n2 2 2\n",
"2\n2 1\n",
"3\n2 2 3\n",
"5\n1 4 5 4 5\n",
"4\n2 2 4 4\n",
"3\n1 1 2\n",
"4\n1 2 1 2\n",
"4\n4 2 2 4\n",
"6\n1 2 3 4 5 5\n",
"1\n1\n",
"10\n4 4 4 4 4 4 4 4 4 4\n",
"7\n7 3 3 5 5 7 7\n",
"5\n1 2 3 4 3\n",
"4\n1 2 1 1\... | 2CODEFORCES |
765_D. Artsem and Saunders_1342 | Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.
Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is defined in integer points 1, ..., x, and all its values are integers from 1 to y.
Now then, you are given a function f: [... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.Writer;
... | 4JAVA | {
"input": [
"3\n1 2 3\n",
"3\n2 2 2\n",
"2\n2 1\n",
"3\n2 2 3\n",
"5\n1 4 5 4 5\n",
"4\n2 2 4 4\n",
"3\n1 1 2\n",
"4\n1 2 1 2\n",
"4\n4 2 2 4\n",
"6\n1 2 3 4 5 5\n",
"1\n1\n",
"10\n4 4 4 4 4 4 4 4 4 4\n",
"7\n7 3 3 5 5 7 7\n",
"5\n1 2 3 4 3\n",
"4\n1 2 1 1\... | 2CODEFORCES |
789_A. Anastasia and pebbles_1343 | Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at most k pebbles in each pocket at the same time.... | import math
def Pebbles():
n,k = map(int,raw_input().split())
pebbles = list(map(int,raw_input().split()))
days = 0
pebbles.sort()
s = 0
for i in pebbles:
s += math.ceil(float(i)/k)
print int(math.ceil(float(s)/2))
Pebbles() | 1Python2 | {
"input": [
"5 4\n3 1 8 9 7\n",
"3 2\n2 3 4\n",
"10 1\n1 1 1 1 1 1 1 1 1 1\n",
"3 57\n78 165 54\n",
"1 1\n10000\n",
"2 2\n2 2\n",
"9 13\n132 87 200 62 168 51 185 192 118\n",
"5 72\n74 10 146 189 184\n",
"1 22\n1\n",
"10 1\n1 0 1 1 1 1 1 1 1 1\n",
"3 87\n78 165 54\n",
"... | 2CODEFORCES |
789_A. Anastasia and pebbles_1344 | Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at most k pebbles in each pocket at the same time.... | #include <bits/stdc++.h>
int main() {
int n, k, t;
register int icount;
while (scanf("%d%d", &n, &k) != EOF) {
icount = 0;
while ((n--) > 0) {
scanf("%d", &t);
icount += (t + k - 1) / k;
}
printf("%d\n", (icount + 1) / 2);
}
return 0;
}
| 2C++ | {
"input": [
"5 4\n3 1 8 9 7\n",
"3 2\n2 3 4\n",
"10 1\n1 1 1 1 1 1 1 1 1 1\n",
"3 57\n78 165 54\n",
"1 1\n10000\n",
"2 2\n2 2\n",
"9 13\n132 87 200 62 168 51 185 192 118\n",
"5 72\n74 10 146 189 184\n",
"1 22\n1\n",
"10 1\n1 0 1 1 1 1 1 1 1 1\n",
"3 87\n78 165 54\n",
"... | 2CODEFORCES |
789_A. Anastasia and pebbles_1345 | Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at most k pebbles in each pocket at the same time.... | import math
n,k = map(int,input().split())
stones = list(map(int, input().split()))
days = 0
for i in range(n):
days += math.ceil(stones[i]/k)
print(math.ceil(days/2)) | 3Python3 | {
"input": [
"5 4\n3 1 8 9 7\n",
"3 2\n2 3 4\n",
"10 1\n1 1 1 1 1 1 1 1 1 1\n",
"3 57\n78 165 54\n",
"1 1\n10000\n",
"2 2\n2 2\n",
"9 13\n132 87 200 62 168 51 185 192 118\n",
"5 72\n74 10 146 189 184\n",
"1 22\n1\n",
"10 1\n1 0 1 1 1 1 1 1 1 1\n",
"3 87\n78 165 54\n",
"... | 2CODEFORCES |
789_A. Anastasia and pebbles_1346 | Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at most k pebbles in each pocket at the same time.... | /**
* DA-IICT
* Author : Savaliya Sagar
*/
import java.io.*;
import java.math.*;
import java.util.*;
public class A789 {
InputStream is;
PrintWriter out;
int n,w[],k;
void solve() {
n = ni();
k = ni();
w = na(n);
int p = 0;
for(int i=0;i<n;i++){
p += Math.ceil((double)w[i]/k);
}
out.println((lo... | 4JAVA | {
"input": [
"5 4\n3 1 8 9 7\n",
"3 2\n2 3 4\n",
"10 1\n1 1 1 1 1 1 1 1 1 1\n",
"3 57\n78 165 54\n",
"1 1\n10000\n",
"2 2\n2 2\n",
"9 13\n132 87 200 62 168 51 185 192 118\n",
"5 72\n74 10 146 189 184\n",
"1 22\n1\n",
"10 1\n1 0 1 1 1 1 1 1 1 1\n",
"3 87\n78 165 54\n",
"... | 2CODEFORCES |
80_C. Heroes_1347 | The year of 2012 is coming...
According to an ancient choradrican legend in this very year, in 2012, Diablo and his brothers Mephisto and Baal will escape from hell, and innumerable hordes of demons will enslave the human world. But seven brave heroes have already gathered on the top of a mountain Arreat to protect us... | import itertools
def countLike(like, perm, fromIdx, toIdx):
res = 0
for i in range(fromIdx,toIdx):
for j in range(fromIdx,toIdx):
if i != j:
if like[ perm[i] ][ perm[j] ]:
res = res + 1
return res
n = input()
inf = int(2e9)
#heroesNumber = {}
heroesNu... | 1Python2 | {
"input": [
"3\nTroll likes Dracul\nDracul likes Anka\nSnowy likes Hexadecimal\n210 200 180\n",
"2\nAnka likes Chapay\nChapay likes Anka\n10000 50 50\n",
"0\n2000000000 2000000000 1\n",
"22\nCleo likes Snowy\nCleo likes Troll\nChapay likes Dracul\nSnowy likes Troll\nDracul likes Chapay\nDracul likes ... | 2CODEFORCES |
80_C. Heroes_1348 | The year of 2012 is coming...
According to an ancient choradrican legend in this very year, in 2012, Diablo and his brothers Mephisto and Baal will escape from hell, and innumerable hordes of demons will enslave the human world. But seven brave heroes have already gathered on the top of a mountain Arreat to protect us... | #include <bits/stdc++.h>
using namespace std;
char nm[8][15] = {"", "Anka", "Chapay", "Snowy", "Hexadecimal",
"Dracul", "Troll", "Cleo"};
int m[10][10] = {{0}};
int n, a, b, c, i, k1, k2, k3;
int m1, m2, m3, md, d, p1, p2, p3, pp1, pp2;
int aa[20000][4] = {{0}}, mm;
void gen(int k1, int k2, int... | 2C++ | {
"input": [
"3\nTroll likes Dracul\nDracul likes Anka\nSnowy likes Hexadecimal\n210 200 180\n",
"2\nAnka likes Chapay\nChapay likes Anka\n10000 50 50\n",
"0\n2000000000 2000000000 1\n",
"22\nCleo likes Snowy\nCleo likes Troll\nChapay likes Dracul\nSnowy likes Troll\nDracul likes Chapay\nDracul likes ... | 2CODEFORCES |
80_C. Heroes_1349 | The year of 2012 is coming...
According to an ancient choradrican legend in this very year, in 2012, Diablo and his brothers Mephisto and Baal will escape from hell, and innumerable hordes of demons will enslave the human world. But seven brave heroes have already gathered on the top of a mountain Arreat to protect us... | # -*- coding: utf-8 -*-
"""
Created on Fri Nov 1 14:28:37 2019
@author: PC-4
"""
from itertools import combinations, product
Teams = [[1, 1, 5],
[1, 2, 4],
[1, 3, 3],
[2, 2, 3]]
Names = {}
Names["Anka"] = 0
Names["Chapay"] = 1
Names["Cleo"] = 2
Names["Dracul"] = 3
Names["Hexadecimal"] = 4... | 3Python3 | {
"input": [
"3\nTroll likes Dracul\nDracul likes Anka\nSnowy likes Hexadecimal\n210 200 180\n",
"2\nAnka likes Chapay\nChapay likes Anka\n10000 50 50\n",
"0\n2000000000 2000000000 1\n",
"22\nCleo likes Snowy\nCleo likes Troll\nChapay likes Dracul\nSnowy likes Troll\nDracul likes Chapay\nDracul likes ... | 2CODEFORCES |
80_C. Heroes_1350 | The year of 2012 is coming...
According to an ancient choradrican legend in this very year, in 2012, Diablo and his brothers Mephisto and Baal will escape from hell, and innumerable hordes of demons will enslave the human world. But seven brave heroes have already gathered on the top of a mountain Arreat to protect us... | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author jtimv
*/
import java.util.*;
public class Task {
public static void main(String[] args) {
new Task().main();
}
Scanner in = new Scanner(System.in);
String[] heores = {"Anka",... | 4JAVA | {
"input": [
"3\nTroll likes Dracul\nDracul likes Anka\nSnowy likes Hexadecimal\n210 200 180\n",
"2\nAnka likes Chapay\nChapay likes Anka\n10000 50 50\n",
"0\n2000000000 2000000000 1\n",
"22\nCleo likes Snowy\nCleo likes Troll\nChapay likes Dracul\nSnowy likes Troll\nDracul likes Chapay\nDracul likes ... | 2CODEFORCES |
835_A. Key races_1351 | Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 millis... | x=raw_input()
a=x.split()
s=int(a[0])
v1=int(a[1])
v2=int(a[2])
t1=int(a[3])
t2=int(a[4])
#calculating time of first participant
n1=2*t1 + v1*s
#calculating time of second participant
n2=2*t2 + v2*s
if n1<n2:
print "First"
elif n2<n1:
print "Second"
else:
print "Friendship"
| 1Python2 | {
"input": [
"4 5 3 1 5\n",
"5 1 2 1 2\n",
"3 3 1 1 1\n",
"2 313 856 964 421\n",
"61 464 623 89 548\n",
"37 261 207 1 1000\n",
"4 202 512 995 375\n",
"3 3 1 6 9\n",
"213 480 811 134 745\n",
"1 10 2 6 10\n",
"6 5 7 10 4\n",
"2 7 6 2 3\n",
"29 344 406 900 1\n",
"1... | 2CODEFORCES |
835_A. Key races_1352 | Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 millis... | #include <bits/stdc++.h>
using namespace std;
int main() {
int s, v1, v2, t1, t2;
cin >> s >> v1 >> v2 >> t1 >> t2;
int st = s * v1 + t1 * 2, nd = s * v2 + t2 * 2;
if (st < nd) {
cout << "First";
} else if (st > nd) {
cout << "Second";
} else {
cout << "Friendship";
}
return 0;
}
| 2C++ | {
"input": [
"4 5 3 1 5\n",
"5 1 2 1 2\n",
"3 3 1 1 1\n",
"2 313 856 964 421\n",
"61 464 623 89 548\n",
"37 261 207 1 1000\n",
"4 202 512 995 375\n",
"3 3 1 6 9\n",
"213 480 811 134 745\n",
"1 10 2 6 10\n",
"6 5 7 10 4\n",
"2 7 6 2 3\n",
"29 344 406 900 1\n",
"1... | 2CODEFORCES |
835_A. Key races_1353 | Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 millis... | s, v1, v2, t1, t2 = list(map(int, input().split()))
a = 2*t1 + s*v1
b = 2*t2 + s*v2
if a > b:
print("Second")
elif a < b:
print("First")
else:
print("Friendship")
| 3Python3 | {
"input": [
"4 5 3 1 5\n",
"5 1 2 1 2\n",
"3 3 1 1 1\n",
"2 313 856 964 421\n",
"61 464 623 89 548\n",
"37 261 207 1 1000\n",
"4 202 512 995 375\n",
"3 3 1 6 9\n",
"213 480 811 134 745\n",
"1 10 2 6 10\n",
"6 5 7 10 4\n",
"2 7 6 2 3\n",
"29 344 406 900 1\n",
"1... | 2CODEFORCES |
835_A. Key races_1354 | Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 millis... | import java.util.*;
public class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
//System.out.println("s");
int s=sc.nextInt();
int v1=sc.nextInt();
int v2=sc.nextInt();
int t1=sc.nextInt();
int t2=sc.nextInt();
int val1=(s*v1)+2*t1;
int val2=(s*v2)+2... | 4JAVA | {
"input": [
"4 5 3 1 5\n",
"5 1 2 1 2\n",
"3 3 1 1 1\n",
"2 313 856 964 421\n",
"61 464 623 89 548\n",
"37 261 207 1 1000\n",
"4 202 512 995 375\n",
"3 3 1 6 9\n",
"213 480 811 134 745\n",
"1 10 2 6 10\n",
"6 5 7 10 4\n",
"2 7 6 2 3\n",
"29 344 406 900 1\n",
"1... | 2CODEFORCES |
855_D. Rowena Ravenclaw's Diadem_1355 | Harry, upon inquiring Helena Ravenclaw's ghost, came to know that she told Tom Riddle or You-know-who about Rowena Ravenclaw's diadem and that he stole it from her.
Harry thought that Riddle would have assumed that he was the only one to discover the Room of Requirement and thus, would have hidden it there. So Harry ... | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int LG = 17;
int anc[N][LG];
int sum[N][LG];
int depth[N];
vector<pair<int, int>> chld[N];
int parent[N], type[N];
int n;
void build(int now, int par, int val) {
anc[now][0] = par;
sum[now][0] = val;
depth[now] = depth[par] + 1;
for (int... | 2C++ | {
"input": [
"3\n-1 -1\n1 0\n2 0\n2\n1 1 3\n2 1 3\n",
"3\n-1 -1\n1 0\n1 1\n2\n2 2 3\n2 3 2\n",
"20\n-1 -1\n1 0\n2 0\n2 1\n2 1\n4 0\n1 0\n4 0\n3 0\n9 0\n6 1\n3 1\n11 1\n2 0\n2 1\n8 1\n14 1\n5 1\n15 0\n18 1\n20\n1 11 11\n2 6 8\n1 13 13\n2 3 4\n2 3 7\n2 14 5\n2 5 4\n1 7 7\n2 10 15\n2 3 5\n1 16 16\n1 20 20\n2... | 2CODEFORCES |
855_D. Rowena Ravenclaw's Diadem_1356 | Harry, upon inquiring Helena Ravenclaw's ghost, came to know that she told Tom Riddle or You-know-who about Rowena Ravenclaw's diadem and that he stole it from her.
Harry thought that Riddle would have assumed that he was the only one to discover the Room of Requirement and thus, would have hidden it there. So Harry ... | import java.lang.*;
import java.lang.reflect.Array;
import java.math.*;
import java.util.*;
import java.io.*;
public class Main {
class Node {
int x;
int t;
public Node(int x,int t){
this.x=x;
this.t=t;
}
}
void solve() {
int n=ni();
MAXL=log2(n);
g=new Array... | 4JAVA | {
"input": [
"3\n-1 -1\n1 0\n2 0\n2\n1 1 3\n2 1 3\n",
"3\n-1 -1\n1 0\n1 1\n2\n2 2 3\n2 3 2\n",
"20\n-1 -1\n1 0\n2 0\n2 1\n2 1\n4 0\n1 0\n4 0\n3 0\n9 0\n6 1\n3 1\n11 1\n2 0\n2 1\n8 1\n14 1\n5 1\n15 0\n18 1\n20\n1 11 11\n2 6 8\n1 13 13\n2 3 4\n2 3 7\n2 14 5\n2 5 4\n1 7 7\n2 10 15\n2 3 5\n1 16 16\n1 20 20\n2... | 2CODEFORCES |
87_B. Vasya and Types_1357 | Programmer Vasya is studying a new programming language &K*. The &K* language resembles the languages of the C family in its syntax. However, it is more powerful, which is why the rules of the actual C-like languages are unapplicable to it. To fully understand the statement, please read the language's description below... | E='errtype'
d={'void':'void',E:E}
def T(s):return filter(lambda x:x!='&' and x!='*',s)
def V(s):
a,b=s.count('&'),s.count('*')
if a>b:return E
return E if T(s)==E else s[a:len(s)-a]
for _ in range(input()):
v=raw_input().split()
if 'typeof'==v[0]:
s=T(v[1])
if s in d:
print V(v[1].replace(s,d[s]... | 1Python2 | {
"input": [
"17\ntypedef void* b\ntypedef b* c\ntypeof b\ntypeof c\ntypedef &b b\ntypeof b\ntypeof c\ntypedef &&b* c\ntypeof c\ntypedef &b* c\ntypeof c\ntypedef &void b\ntypeof b\ntypedef b******* c\ntypeof c\ntypedef &&b* c\ntypeof c\n",
"5\ntypedef void* ptv\ntypeof ptv\ntypedef... | 2CODEFORCES |
87_B. Vasya and Types_1358 | Programmer Vasya is studying a new programming language &K*. The &K* language resembles the languages of the C family in its syntax. However, it is more powerful, which is why the rules of the actual C-like languages are unapplicable to it. To fully understand the statement, please read the language's description below... | #include <bits/stdc++.h>
using namespace std;
int n, v[100];
string s[100], c;
int def() {
string s1, s2, s3;
cin >> s1 >> s2;
int p = s1.rfind("&") + 1, q = s1.find("*"), v1;
if (q < 0) {
v1 = 0 - p;
q = 1000;
} else
v1 = (s1.size() - q) - p;
s3 = s1.substr(p, q - p);
if (s3 == "void") {
... | 2C++ | {
"input": [
"17\ntypedef void* b\ntypedef b* c\ntypeof b\ntypeof c\ntypedef &b b\ntypeof b\ntypeof c\ntypedef &&b* c\ntypeof c\ntypedef &b* c\ntypeof c\ntypedef &void b\ntypeof b\ntypedef b******* c\ntypeof c\ntypedef &&b* c\ntypeof c\n",
"5\ntypedef void* ptv\ntypeof ptv\ntypedef... | 2CODEFORCES |
87_B. Vasya and Types_1359 | Programmer Vasya is studying a new programming language &K*. The &K* language resembles the languages of the C family in its syntax. However, it is more powerful, which is why the rules of the actual C-like languages are unapplicable to it. To fully understand the statement, please read the language's description below... | types = {'void':'void', 'errtype':'errtype'}
def getRealType(type_expr):
expr_type = type_expr.strip('&*')
full_type_name = type_expr.replace(expr_type, types.get(expr_type, "errtype"))
base_type = full_type_name.strip('&*')
if base_type == "void":
addr_count = full_type_name.count('*')
deref_c... | 3Python3 | {
"input": [
"17\ntypedef void* b\ntypedef b* c\ntypeof b\ntypeof c\ntypedef &b b\ntypeof b\ntypeof c\ntypedef &&b* c\ntypeof c\ntypedef &b* c\ntypeof c\ntypedef &void b\ntypeof b\ntypedef b******* c\ntypeof c\ntypedef &&b* c\ntypeof c\n",
"5\ntypedef void* ptv\ntypeof ptv\ntypedef... | 2CODEFORCES |
87_B. Vasya and Types_1360 | Programmer Vasya is studying a new programming language &K*. The &K* language resembles the languages of the C family in its syntax. However, it is more powerful, which is why the rules of the actual C-like languages are unapplicable to it. To fully understand the statement, please read the language's description below... | import java.io.*;
import java.awt.geom.Point2D;
import java.text.*;
import java.math.*;
import java.util.*;
public class Main implements Runnable {
final String filename = "";
public void solve() throws Exception {
int n = iread();
HashMap<String, Integer> types = new HashMap<String, Integer>();
types.put("... | 4JAVA | {
"input": [
"17\ntypedef void* b\ntypedef b* c\ntypeof b\ntypeof c\ntypedef &b b\ntypeof b\ntypeof c\ntypedef &&b* c\ntypeof c\ntypedef &b* c\ntypeof c\ntypedef &void b\ntypeof b\ntypedef b******* c\ntypeof c\ntypedef &&b* c\ntypeof c\n",
"5\ntypedef void* ptv\ntypeof ptv\ntypedef... | 2CODEFORCES |
903_D. Almost Difference_1361 | Let's denote a function
<image>
You are given an array a consisting of n integers. You have to calculate the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
Input
The first line contains one integer n (1 ≤ n ≤ 200000) — the number of elements in a.
The second line contains n integers a1, a2, ..., ... | from fractions import gcd
from math import factorial, ceil, sqrt, atan2
from itertools import *
import string
import copy
import random
from decimal import *
import bisect
def id_generator(size=20, chars=string.digits):
return ''.join(random.choice(chars) for _ in range(size))
def mp():
return map(int,str(raw... | 1Python2 | {
"input": [
"4\n6 6 5 5\n",
"5\n1 2 3 1 3\n",
"4\n6 6 4 4\n",
"100\n591 417 888 251 792 847 685 3 182 461 102 348 555 956 771 901 712 878 580 631 342 333 285 899 525 725 537 718 929 653 84 788 104 355 624 803 253 853 201 995 536 184 65 205 540 652 549 777 248 405 677 950 431 580 600 846 328 429 134 9... | 2CODEFORCES |
903_D. Almost Difference_1362 | Let's denote a function
<image>
You are given an array a consisting of n integers. You have to calculate the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
Input
The first line contains one integer n (1 ≤ n ≤ 200000) — the number of elements in a.
The second line contains n integers a1, a2, ..., ... | #include <bits/stdc++.h>
using namespace std;
const long long maxn = 6e5 + 100;
const long long mx = 1e9 + 10;
long long n, a[maxn];
long double sum, ans, cc[maxn], tree[maxn];
vector<long double> v;
long long getid(long long x) {
return lower_bound(v.begin(), v.end(), x) - v.begin() + 1;
};
long long lowbit(long lon... | 2C++ | {
"input": [
"4\n6 6 5 5\n",
"5\n1 2 3 1 3\n",
"4\n6 6 4 4\n",
"100\n591 417 888 251 792 847 685 3 182 461 102 348 555 956 771 901 712 878 580 631 342 333 285 899 525 725 537 718 929 653 84 788 104 355 624 803 253 853 201 995 536 184 65 205 540 652 549 777 248 405 677 950 431 580 600 846 328 429 134 9... | 2CODEFORCES |
903_D. Almost Difference_1363 | Let's denote a function
<image>
You are given an array a consisting of n integers. You have to calculate the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
Input
The first line contains one integer n (1 ≤ n ≤ 200000) — the number of elements in a.
The second line contains n integers a1, a2, ..., ... | from sys import stdin, stdout
n = int(stdin.readline())
a = [int(i) for i in stdin.readline().split()]
d = dict()
ans, sm = 0, 0
for i in range(n):
if a[i] not in d.keys():
d[a[i]] = 0
d[a[i]] += 1
ans += i * a[i] - sm
if (a[i] + 1) in d.keys():
ans += 1 * d[a[i] + 1]
if (a[i] - 1) i... | 3Python3 | {
"input": [
"4\n6 6 5 5\n",
"5\n1 2 3 1 3\n",
"4\n6 6 4 4\n",
"100\n591 417 888 251 792 847 685 3 182 461 102 348 555 956 771 901 712 878 580 631 342 333 285 899 525 725 537 718 929 653 84 788 104 355 624 803 253 853 201 995 536 184 65 205 540 652 549 777 248 405 677 950 431 580 600 846 328 429 134 9... | 2CODEFORCES |
903_D. Almost Difference_1364 | Let's denote a function
<image>
You are given an array a consisting of n integers. You have to calculate the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
Input
The first line contains one integer n (1 ≤ n ≤ 200000) — the number of elements in a.
The second line contains n integers a1, a2, ..., ... | import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class D {
FastScanner in;
PrintWriter out;
boolean systemIO = true;
public void solve() {
int n = in.nextInt();
HashMap<Long, Integer> map = new HashMap();
BigInteger sum = BigInteger.ZERO;
BigInteger ans = BigInteger.valueOf(0)... | 4JAVA | {
"input": [
"4\n6 6 5 5\n",
"5\n1 2 3 1 3\n",
"4\n6 6 4 4\n",
"100\n591 417 888 251 792 847 685 3 182 461 102 348 555 956 771 901 712 878 580 631 342 333 285 899 525 725 537 718 929 653 84 788 104 355 624 803 253 853 201 995 536 184 65 205 540 652 549 777 248 405 677 950 431 580 600 846 328 429 134 9... | 2CODEFORCES |
925_E. May Holidays_1365 | It's May in Flatland, and there are m days in this month. Despite the fact that May Holidays are canceled long time ago, employees of some software company still have a habit of taking short or long vacations in May.
Of course, not all managers of the company like this. There are n employees in the company that form a... | #include <bits/stdc++.h>
using namespace std;
int a14;
inline int rd(int l, int r) { return rand() % (r - l + 1) + l; }
const int mxn = 1e5 + 3, sq = 333;
int to[mxn], nxt[mxn], fir[mxn],
gn = 1, n, fa[mxn], dep[mxn], siz[mxn], dfn[mxn], dn, top[mxn], zs[mxn],
dfa[mxn], va[mxn], m, xw[mxn], ans, ux[mxn], un, st... | 2C++ | {
"input": [
"5 6\n1 2 3 4\n4 0 0 1 0\n1 5 2 3 -5 -1\n",
"7 8\n4 5 1 1 5 5\n0 0 0 1 2 0 0\n2 6 3 7 -2 4 -3 1\n",
"10 10\n5 9 1 3 5 8 3 4 7\n2 0 4 7 1 0 0 0 7 0\n5 7 -7 3 10 4 7 2 9 -9\n",
"2 2\n1\n0 0\n1 2\n",
"2 2\n1\n0 0\n2 -2\n",
"10 10\n1 1 3 6 1 2 3 3 6\n3 0 2 0 0 0 0 0 0 0\n7 9 4 -9 6 -6... | 2CODEFORCES |
954_F. Runner's Problem_1366 | You are running through a rectangular field. This field can be represented as a matrix with 3 rows and m columns. (i, j) denotes a cell belonging to i-th row and j-th column.
You start in (2, 1) and have to end your path in (2, m). From the cell (i, j) you may advance to:
* (i - 1, j + 1) — only if i > 1,
* (i, ... | from __future__ import print_function, division
from collections import OrderedDict
mod = 1000000007
def mat(s, m):
t = [[0,0,0],[0,0,0],[0,0,0]]
for i in xrange(3):
for j in xrange(3):
t[i][j] = (s[i][0] * m[0][j] + s[i][1] * m[1][j] + s[i][2] * m[2][j]) % mod
for i in xrange(3):
s[i] = t[i][:]
def matmul(... | 1Python2 | {
"input": [
"2 5\n1 3 4\n2 2 3\n",
"50 100\n1 71 96\n2 34 52\n2 16 95\n1 54 55\n1 65 85\n1 76 92\n2 19 91\n1 26 43\n2 83 95\n2 70 88\n2 67 88\n1 9 75\n2 4 50\n2 9 11\n1 77 92\n1 28 58\n1 23 72\n1 24 75\n2 12 50\n1 54 55\n2 45 93\n1 88 93\n2 98 99\n1 40 58\n2 40 42\n1 16 61\n2 94 94\n1 82 86\n2 81 85\n2 46 46... | 2CODEFORCES |
954_F. Runner's Problem_1367 | You are running through a rectangular field. This field can be represented as a matrix with 3 rows and m columns. (i, j) denotes a cell belonging to i-th row and j-th column.
You start in (2, 1) and have to end your path in (2, m). From the cell (i, j) you may advance to:
* (i - 1, j + 1) — only if i > 1,
* (i, ... | #include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
long long add(long long a, long long b) {
long long res = a + b;
return res >= mod ? res - mod : res;
}
long long mul(long long a, long long b) { return a * b % mod; }
vector<vector<long long>> matmul(const vector<vector<long long>>& a,
... | 2C++ | {
"input": [
"2 5\n1 3 4\n2 2 3\n",
"50 100\n1 71 96\n2 34 52\n2 16 95\n1 54 55\n1 65 85\n1 76 92\n2 19 91\n1 26 43\n2 83 95\n2 70 88\n2 67 88\n1 9 75\n2 4 50\n2 9 11\n1 77 92\n1 28 58\n1 23 72\n1 24 75\n2 12 50\n1 54 55\n2 45 93\n1 88 93\n2 98 99\n1 40 58\n2 40 42\n1 16 61\n2 94 94\n1 82 86\n2 81 85\n2 46 46... | 2CODEFORCES |
954_F. Runner's Problem_1368 | You are running through a rectangular field. This field can be represented as a matrix with 3 rows and m columns. (i, j) denotes a cell belonging to i-th row and j-th column.
You start in (2, 1) and have to end your path in (2, m). From the cell (i, j) you may advance to:
* (i - 1, j + 1) — only if i > 1,
* (i, ... | from operator import itemgetter
import sys
input = sys.stdin.buffer.readline
def _mul(A, B, MOD):
C = [[0] * len(B[0]) for i in range(len(A))]
for i in range(len(A)):
for k in range(len(B)):
for j in range(len(B[0])):
C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD
return... | 3Python3 | {
"input": [
"2 5\n1 3 4\n2 2 3\n",
"50 100\n1 71 96\n2 34 52\n2 16 95\n1 54 55\n1 65 85\n1 76 92\n2 19 91\n1 26 43\n2 83 95\n2 70 88\n2 67 88\n1 9 75\n2 4 50\n2 9 11\n1 77 92\n1 28 58\n1 23 72\n1 24 75\n2 12 50\n1 54 55\n2 45 93\n1 88 93\n2 98 99\n1 40 58\n2 40 42\n1 16 61\n2 94 94\n1 82 86\n2 81 85\n2 46 46... | 2CODEFORCES |
954_F. Runner's Problem_1369 | You are running through a rectangular field. This field can be represented as a matrix with 3 rows and m columns. (i, j) denotes a cell belonging to i-th row and j-th column.
You start in (2, 1) and have to end your path in (2, m). From the cell (i, j) you may advance to:
* (i - 1, j + 1) — only if i > 1,
* (i, ... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;
/**
* Built using CHelper... | 4JAVA | {
"input": [
"2 5\n1 3 4\n2 2 3\n",
"50 100\n1 71 96\n2 34 52\n2 16 95\n1 54 55\n1 65 85\n1 76 92\n2 19 91\n1 26 43\n2 83 95\n2 70 88\n2 67 88\n1 9 75\n2 4 50\n2 9 11\n1 77 92\n1 28 58\n1 23 72\n1 24 75\n2 12 50\n1 54 55\n2 45 93\n1 88 93\n2 98 99\n1 40 58\n2 40 42\n1 16 61\n2 94 94\n1 82 86\n2 81 85\n2 46 46... | 2CODEFORCES |
980_E. The Number Games_1370 | The nation of Panel holds an annual show called The Number Games, where each district in the nation will be represented by one contestant.
The nation has n districts numbered from 1 to n, each district has exactly one path connecting it to every other district. The number of fans of a contestant from district i is equ... | import sys
# import time
def calc_result(n, k, edges):
# t1 = time.clock()
storage = [-1] * (4 * n)
storage_index = 0
lookup = [-1] * (n + 1)
for u, v in edges:
storage[storage_index] = lookup[u]
storage[storage_index + 1] = v
lookup[u] = storage_index
storage_inde... | 1Python2 | {
"input": [
"6 3\n2 1\n2 6\n4 2\n5 6\n2 3\n",
"8 4\n2 6\n2 7\n7 8\n1 2\n3 1\n2 4\n7 5\n",
"64 63\n11 51\n64 11\n64 39\n11 6\n24 64\n51 63\n43 51\n64 29\n6 22\n47 6\n1 47\n41 22\n41 38\n4 47\n35 47\n41 23\n45 1\n52 35\n26 45\n15 35\n21 35\n23 32\n12 21\n21 62\n25 21\n28 25\n15 54\n57 12\n20 28\n48 57\n8 5... | 2CODEFORCES |
980_E. The Number Games_1371 | The nation of Panel holds an annual show called The Number Games, where each district in the nation will be represented by one contestant.
The nation has n districts numbered from 1 to n, each district has exactly one path connecting it to every other district. The number of fans of a contestant from district i is equ... | #include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
long long tree[N];
bool a[N];
int sz[N];
int mapping[N];
int par[N];
long long n;
void print() {
for (int i = 1; i <= n; i++) {
if (a[i] == false) printf("%d ", i);
}
}
long long query(int idx) {
long long sum = 0;
while (idx > 0) {
... | 2C++ | {
"input": [
"6 3\n2 1\n2 6\n4 2\n5 6\n2 3\n",
"8 4\n2 6\n2 7\n7 8\n1 2\n3 1\n2 4\n7 5\n",
"64 63\n11 51\n64 11\n64 39\n11 6\n24 64\n51 63\n43 51\n64 29\n6 22\n47 6\n1 47\n41 22\n41 38\n4 47\n35 47\n41 23\n45 1\n52 35\n26 45\n15 35\n21 35\n23 32\n12 21\n21 62\n25 21\n28 25\n15 54\n57 12\n20 28\n48 57\n8 5... | 2CODEFORCES |
980_E. The Number Games_1372 | The nation of Panel holds an annual show called The Number Games, where each district in the nation will be represented by one contestant.
The nation has n districts numbered from 1 to n, each district has exactly one path connecting it to every other district. The number of fans of a contestant from district i is equ... | import java.io.*;
import java.util.*;
public class E implements Runnable{
public static void main (String[] args) {new Thread(null, new E(), "_cf", 1 << 26).start();}
int n, k, log;
int[][] adj;
int[][] lift;
public void run() {
FastScanner fs = new FastScanner();
PrintWriter out = new PrintWriter(System.o... | 4JAVA | {
"input": [
"6 3\n2 1\n2 6\n4 2\n5 6\n2 3\n",
"8 4\n2 6\n2 7\n7 8\n1 2\n3 1\n2 4\n7 5\n",
"64 63\n11 51\n64 11\n64 39\n11 6\n24 64\n51 63\n43 51\n64 29\n6 22\n47 6\n1 47\n41 22\n41 38\n4 47\n35 47\n41 23\n45 1\n52 35\n26 45\n15 35\n21 35\n23 32\n12 21\n21 62\n25 21\n28 25\n15 54\n57 12\n20 28\n48 57\n8 5... | 2CODEFORCES |
9_E. Interesting Graph and Apples_1373 | Hexadecimal likes drawing. She has drawn many graphs already, both directed and not. Recently she has started to work on a still-life «interesting graph and apples». An undirected graph is called interesting, if each of its vertices belongs to one cycle only — a funny ring — and does not belong to any other cycles. A f... | n, m = map(int, raw_input().split())
djs = [i for i in xrange(n)]
ct = [0] * n
def find(n):
if n == djs[n]:
return n
else:
djs[n] = find(djs[n])
return djs[n]
cycle = 0
max_degree = 0
for i in xrange(m):
a, b = map(int, raw_input().split())
a, b = a-1, b-1
if find(a) == fi... | 1Python2 | {
"input": [
"3 2\n1 2\n2 3\n",
"42 28\n7 19\n15 24\n3 42\n18 5\n32 27\n26 20\n40 30\n35 2\n14 8\n22 10\n36 4\n16 14\n21 29\n37 40\n2 12\n30 21\n19 17\n39 34\n31 28\n20 3\n4 33\n11 42\n26 21\n9 10\n4 32\n6 1\n1 14\n14 12\n",
"2 2\n1 2\n2 1\n",
"3 2\n3 2\n2 1\n",
"3 3\n1 3\n2 1\n3 2\n",
"2 3\n1... | 2CODEFORCES |
9_E. Interesting Graph and Apples_1374 | Hexadecimal likes drawing. She has drawn many graphs already, both directed and not. Recently she has started to work on a still-life «interesting graph and apples». An undirected graph is called interesting, if each of its vertices belongs to one cycle only — a funny ring — and does not belong to any other cycles. A f... | #include <bits/stdc++.h>
using namespace std;
void fun() {}
long long int __gcd(long long int a, long long int b) {
if (b == 0) return a;
return __gcd(b, a % b);
}
long long int poww(long long int a, long long int b, long long int md) {
if (b < 0) return 0;
if (a == 0) return 0;
long long int res = 1;
while... | 2C++ | {
"input": [
"3 2\n1 2\n2 3\n",
"42 28\n7 19\n15 24\n3 42\n18 5\n32 27\n26 20\n40 30\n35 2\n14 8\n22 10\n36 4\n16 14\n21 29\n37 40\n2 12\n30 21\n19 17\n39 34\n31 28\n20 3\n4 33\n11 42\n26 21\n9 10\n4 32\n6 1\n1 14\n14 12\n",
"2 2\n1 2\n2 1\n",
"3 2\n3 2\n2 1\n",
"3 3\n1 3\n2 1\n3 2\n",
"2 3\n1... | 2CODEFORCES |
9_E. Interesting Graph and Apples_1375 | Hexadecimal likes drawing. She has drawn many graphs already, both directed and not. Recently she has started to work on a still-life «interesting graph and apples». An undirected graph is called interesting, if each of its vertices belongs to one cycle only — a funny ring — and does not belong to any other cycles. A f... | def dfs(v, comp):
used[v] = comp
for u in graph[v]:
if not used[u]:
dfs(u, comp)
n, m = map(int, input().split())
graph = [[] for i in range(n)]
for i in range(m):
v, u = map(int, input().split())
graph[v - 1].append(u - 1)
graph[u - 1].append(v - 1)
used = [0] * n
ncomp = 0
fo... | 3Python3 | {
"input": [
"3 2\n1 2\n2 3\n",
"42 28\n7 19\n15 24\n3 42\n18 5\n32 27\n26 20\n40 30\n35 2\n14 8\n22 10\n36 4\n16 14\n21 29\n37 40\n2 12\n30 21\n19 17\n39 34\n31 28\n20 3\n4 33\n11 42\n26 21\n9 10\n4 32\n6 1\n1 14\n14 12\n",
"2 2\n1 2\n2 1\n",
"3 2\n3 2\n2 1\n",
"3 3\n1 3\n2 1\n3 2\n",
"2 3\n1... | 2CODEFORCES |
9_E. Interesting Graph and Apples_1376 | Hexadecimal likes drawing. She has drawn many graphs already, both directed and not. Recently she has started to work on a still-life «interesting graph and apples». An undirected graph is called interesting, if each of its vertices belongs to one cycle only — a funny ring — and does not belong to any other cycles. A f... | //package codeforces;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class E {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer = new PrintWriter(System.out);
... | 4JAVA | {
"input": [
"3 2\n1 2\n2 3\n",
"42 28\n7 19\n15 24\n3 42\n18 5\n32 27\n26 20\n40 30\n35 2\n14 8\n22 10\n36 4\n16 14\n21 29\n37 40\n2 12\n30 21\n19 17\n39 34\n31 28\n20 3\n4 33\n11 42\n26 21\n9 10\n4 32\n6 1\n1 14\n14 12\n",
"2 2\n1 2\n2 1\n",
"3 2\n3 2\n2 1\n",
"3 3\n1 3\n2 1\n3 2\n",
"2 3\n1... | 2CODEFORCES |
bhavanas-and-bhuvanas-bet_1377 | Bhavana and Bhuvana place bet every time they see something interesting that can occur with a probability 0.5.
Both of them place a bet for a higher amount which they don’t posses at that time. But when one wins she demands other for the bet amount. For example if Bhuvana wins she asks bhavana for the bet amount.
But... | from sys import stdin
t=stdin.readline()
a=stdin.readlines()
for i in a:
n = int(i)
cur = 1
ans = 0
while cur<=n:
cur = cur*2
ans+=1
ans-=1
if n==0:
ans = 0
if ans==0:
ans = -2147483648
print ans | 1Python2 | {
"input": [
"2\n3\n10"
],
"output": [
"1\n3"
]
} | 3HACKEREARTH |
cost-of-data-11_1378 | Strings can be efficiently stored as a data structure, to have efficient searching methods.
A new startup is going to use this method, but they don't have much space. So they want to check beforehand how much memory will be required for their data.
Following method describes the way in which this startup's engineers s... | '''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
class Node():
def __init__(self,alphabet):
self.value = alphabet
self.children = []
class Trie():
def __init__(self):
self.root = Node("root")
def insertWord(self,word):
le... | 1Python2 | {
"input": [
"5\net\neq\nbd\nbe\nbdp\n\nSAMPLE",
"5\neu\neq\nbd\nbe\nbdp\n\nSAMPLE",
"5\neu\neq\nbd\nbe\ndbp\n\nSAMQLE",
"5\neu\neq\nbd\nbd\ndbp\n\nSAMQLE",
"5\net\nqe\nbd\ndc\ndbp\n\nSAMQLE",
"5\nte\nqe\nbd\ndb\np`d\n\nDAQMKS",
"5\neu\neq\nbd\nbe\nbdp\n\nELPMAS",
"5\neu\neq\nbd\nbe\nb... | 3HACKEREARTH |
find-the-nth-prime_1379 | Given the value of n, print the n'th prime number.
Input : A single integer n.
Output : A single number which is the n'th prime number.
Constraints :
1 ≤ n ≤ 1000
SAMPLE INPUT
2
SAMPLE OUTPUT
3
Explanation
The first few prime numbers are:
2,3,5,7. So, the answer is 3. | no = input()
c = 0
for pk in range(2,7920):
am = 0
for qd in range(2,(pk/2)+1):
if (pk % qd == 0):
am = 1
break
if (am == 0):
c = c + 1
if(c == no):
print pk
break | 1Python2 | {
"input": [
"2\n\nSAMPLE",
"2\n\nSBMPLE",
"2\n\nSBPMLE",
"2\n\nELMPBS",
"2\n\nELMPAS",
"2\n\nSAPMLE",
"2\n\nSAQMLE",
"2\n\nELMQAS",
"2\n\nELMQBS",
"2\n\nELLQBS",
"2\n\nEMLQBS",
"2\n\nEMLQBT",
"2\n\nTBQLME",
"2\n\nTCQLME",
"2\n\nSCQLME",
"2\n\nTCQKME",
... | 3HACKEREARTH |
insect-colony-2_1380 | Yesterday Oz heard a story about insect colony. The specialty of insects is that they splits sometimes i.e an insect of size A can split into two insects of positive integral sizes B and C such that A = B + C. Also sometimes they attack each other i.e. two insects of sizes P and Q will become R = P XOR Q .
You are give... | t = int(raw_input())
for i in range(t):
arr = list(map(int,raw_input().split()))
arr = arr[1:]
ans = sum(arr)
if ans%2 == 1:
print 'No'
else:
print 'Yes' | 1Python2 | {
"input": [
"2\n2 9 17\n1 1\n\nSAMPLE",
"10\n75 995991040 148627929 566366239 458028006 823890903 945174886 530827147 546010999 720763988 183796976 748924885 868038355 870234651 273702889 972313979 607688156 495203509 981301128 72001489 10285302 970980434 30653173 738175457 455018413 940530064 537884091 4185... | 3HACKEREARTH |
max-min_1381 | you are given an array of size N. You need to select K elements from the array such that the difference between the max number among selected and the min number among selected array elements should be minimum. Print the minimum difference.
INPUT:
First line N number i.e., length of array
Second line K number
Next N l... | a=[]
t,k=input(),input()
for _ in xrange(t):
a.append(input())
a.sort()
t=[a[x+k-1]-a[x] for x in xrange(0,len(a)-k) ]
print min(t) | 1Python2 | {
"input": [
"5\n3\n1\n2\n3\n4\n5\n\nSAMPLE",
"5\n3\n1\n1\n3\n4\n5\n\nSAMPLE",
"5\n3\n1\n3\n3\n4\n5\n\nSAMPLE",
"5\n4\n1\n1\n3\n5\n5\n\nSAMPLE",
"5\n1\n0\n3\n3\n4\n5\n\nQAMRLD",
"5\n3\n0\n6\n3\n4\n9\n\nLMRDAQ",
"5\n3\n1\n1\n3\n5\n5\n\nSAMPLE",
"5\n3\n1\n2\n3\n4\n7\n\nSAMPLE",
"5\n3... | 3HACKEREARTH |
once-upon-a-time-in-time-land_1382 | In a mystical TimeLand, a person's health and wealth is measured in terms of time(seconds) left.
Suppose a person there has 24x60x60 = 86400 seconds left, then he would live for another 1 day.
A person dies when his time left becomes 0. Some time-amount can be borrowed from other person, or time-banks.
Some time-amoun... | def solve():
n,k=[int(x) for x in raw_input().split()]
nums =[0]
nums.extend( [int(x) for x in raw_input().split()])
for i in xrange(1,1+k+1):
nums[i] = max(nums[i-1],nums[i])
for i in xrange(1+k+1,n+1):
nums[i] = max(nums[i-1],nums[i-k-1]+nums[i])
print nums[n]
def main():
for _ in xrange(input()... | 1Python2 | {
"input": [
"2\n10 1\n1 2 -3 -5 4 6 -3 2 -1 2\n10 2\n1 2 -3 -5 4 6 -3 2 -1 2\n\nSAMPLE",
"30\n16 3\n-334 -500 -169 -724 -478 -358 -962 -464 -705 -145 -281 -827 -961 -491 -995 -942 \n22 2\n391 604 902 153 292 382 421 716 718 895 447 726 771 538 869 912 667 299 35 894 703 811 \n17 5\n-673 141 -253 -547 662 -37... | 3HACKEREARTH |
rams-love-for-sita-2_1383 | Sita loves chocolate and Ram being his boyfriend wants to give Sita as many chocolates as he can. So, he goes to a chocolate store with Rs. N in his pocket. The price of each chocolate is Rs. C. The store offers a discount that for every M wrappers he gives to the store, he gets one chocolate for free. How many chocola... | for _ in xrange(input()):
n,c,m=map(int,raw_input().split())
nc=n/c
nw=nc
if nw>=m:
while True:
c=nw/m
nc+=c
nw=nw%m+c
if nw<m:
break
print nc | 1Python2 | {
"input": [
"3\n10 2 5\n12 4 4\n6 2 2\n\nSAMPLE",
"3\n10 2 5\n12 4 8\n6 2 2\n\nSAMPLE",
"3\n7 2 5\n12 4 8\n6 2 2\n\nSAMPLF",
"3\n7 2 5\n12 4 8\n6 2 4\n\nSAMPLF",
"3\n12 2 5\n12 4 8\n6 2 4\n\nSAMPLF",
"3\n12 2 5\n2 4 16\n6 2 4\n\nSAMPLF",
"3\n12 2 5\n4 4 16\n6 2 4\n\nSAMPLF",
"3\n12 2 ... | 3HACKEREARTH |
simple-prime-factorization_1384 | Surya loves to play with primes. One day, he asked his friend don to print any number in the form of multiple of prime factors. Help don in solving the problem.
Input
The first line will contain an integer t (1 ≤ t ≤ 10^6) denoting number of test case.
For each test case, you will be given an integer n (2 ≤ n ≤ 10^6... | def CheckIfProbablyPrime(x):
return (2 << x - 2) % x
def primes(n):
primfac = []
d = 2
while d*d <= n:
while (n % d) == 0:
primfac.append(d)
n //= d
d += 1
if n > 1:
primfac.append(n)
return primfac
for i in range(input()):
a=input()
s=""
s1=""
... | 1Python2 | {
"input": [
"3\n32\n100\n9085\n\nSAMPLE",
"1000\n999001\n999002\n999003\n999004\n999005\n999006\n999007\n999008\n999009\n999010\n999011\n999012\n999013\n999014\n999015\n999016\n999017\n999018\n999019\n999020\n999021\n999022\n999023\n999024\n999025\n999026\n999027\n999028\n999029\n999030\n999031\n999032\n9990... | 3HACKEREARTH |
the-strongest-string-1-1_1385 | Maga and Alex are good at string manipulation problems. Just now they have faced a problem related to string. But it is not a standard string problem. They have no idea to solve it. They need your help.
A string is called unique if all characters of string are distinct.
String s_1 is called subsequence of string s_2 ... | input()
ans=''
inp=raw_input()
init=0
for j in xrange(ord('z'),ord('a')-1,-1):
a=chr(j)
for k in xrange(init,len(inp)):
if inp[k]==a:
ans+=a
init=k+1
break
print ans | 1Python2 | {
"input": [
"5\nabvzx\n\nSAMPLE",
"5\nabvzx\n\nSAMOLE",
"5\nxbvza\n\nSAMOLE",
"5\nxbvya\n\nSAMOLE",
"5\nabvxz\n\nSAMOLE",
"5\nayvbx\n\nSAMOLE",
"5\nzavbw\n\nSAMOLE",
"5\nazwaw\n\nSOMALF",
"5\nbywaw\n\nSOMALF",
"5\nwawyb\n\nSOMALG",
"5\nxywab\n\nDTALON",
"5\nxw`xb\n\nSO... | 3HACKEREARTH |
p02548 AtCoder Beginner Contest 179 - A x B + C_1386 | Given is a positive integer N. How many tuples (A,B,C) of positive integers satisfy A \times B + C = N?
Constraints
* 2 \leq N \leq 10^6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
3
Output
3
Input
100
... | import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')
# (int(x) ... | 1Python2 | {
"input": [
"3",
"100",
"1000000",
"4",
"101",
"5",
"001",
"8",
"6",
"2",
"110",
"10",
"13",
"111",
"12",
"17",
"9",
"7",
"14",
"16",
"11",
"22",
"26",
"18",
"19",
"24",
"43",
"23",
"44",
"72",
... | 5ATCODER |
p02548 AtCoder Beginner Contest 179 - A x B + C_1387 | Given is a positive integer N. How many tuples (A,B,C) of positive integers satisfy A \times B + C = N?
Constraints
* 2 \leq N \leq 10^6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
3
Output
3
Input
100
... | #include<iostream>
using namespace std;
int main(){
int n;
int count=0;
cin>>n;
for(int a=1;a<=n-1;a++){
for(int b=1;b<=(n-1)/a;b++){
count++;
}
}
cout<<count;
}
| 2C++ | {
"input": [
"3",
"100",
"1000000",
"4",
"101",
"5",
"001",
"8",
"6",
"2",
"110",
"10",
"13",
"111",
"12",
"17",
"9",
"7",
"14",
"16",
"11",
"22",
"26",
"18",
"19",
"24",
"43",
"23",
"44",
"72",
... | 5ATCODER |
p02548 AtCoder Beginner Contest 179 - A x B + C_1388 | Given is a positive integer N. How many tuples (A,B,C) of positive integers satisfy A \times B + C = N?
Constraints
* 2 \leq N \leq 10^6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
3
Output
3
Input
100
... | N = int(input())
ans = 0
for i in range(1, N):
ans += (N - 1) // i
print(ans) | 3Python3 | {
"input": [
"3",
"100",
"1000000",
"4",
"101",
"5",
"001",
"8",
"6",
"2",
"110",
"10",
"13",
"111",
"12",
"17",
"9",
"7",
"14",
"16",
"11",
"22",
"26",
"18",
"19",
"24",
"43",
"23",
"44",
"72",
... | 5ATCODER |
p02548 AtCoder Beginner Contest 179 - A x B + C_1389 | Given is a positive integer N. How many tuples (A,B,C) of positive integers satisfy A \times B + C = N?
Constraints
* 2 \leq N \leq 10^6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
3
Output
3
Input
100
... | import java.util.*;
import static java.lang.System.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long n = sc.nextLong();
int ans = 0;
for(int i=1; i<=n; i++){
ans += (n-1)/i;
}
out.println(ans);
... | 4JAVA | {
"input": [
"3",
"100",
"1000000",
"4",
"101",
"5",
"001",
"8",
"6",
"2",
"110",
"10",
"13",
"111",
"12",
"17",
"9",
"7",
"14",
"16",
"11",
"22",
"26",
"18",
"19",
"24",
"43",
"23",
"44",
"72",
... | 5ATCODER |
p02679 AtCoder Beginner Contest 168 - ∙ (Bullet)_1390 | We have caught N sardines. The deliciousness and fragrantness of the i-th sardine is A_i and B_i, respectively.
We will choose one or more of these sardines and put them into a cooler. However, two sardines on bad terms cannot be chosen at the same time.
The i-th and j-th sardines (i \neq j) are on bad terms if and o... | from collections import defaultdict
MOD = (10 ** 9) + 7
assert MOD == 1000000007
def gcd(a, b):
if a % b == 0:
return b
return gcd(b, a % b)
n = int(raw_input())
ns = []
d = defaultdict(int)
zero = 0
for i in xrange(n):
a, b = map(int, raw_input().split())
ns.append((a, b))
if a and b:
... | 1Python2 | {
"input": [
"3\n1 2\n-1 1\n2 -1",
"10\n3 2\n3 2\n-1 1\n2 -1\n-3 -9\n-8 12\n7 7\n8 1\n8 2\n8 4",
"3\n1 4\n-1 1\n2 -1",
"10\n3 2\n3 2\n-1 1\n2 -1\n-3 -6\n-8 12\n7 7\n8 1\n8 2\n8 4",
"3\n2 4\n-1 1\n2 -1",
"10\n3 2\n3 2\n-1 1\n2 -1\n-3 -6\n-8 12\n7 1\n8 1\n8 2\n8 4",
"3\n2 4\n-2 1\n2 -1",
... | 5ATCODER |
p02679 AtCoder Beginner Contest 168 - ∙ (Bullet)_1391 | We have caught N sardines. The deliciousness and fragrantness of the i-th sardine is A_i and B_i, respectively.
We will choose one or more of these sardines and put them into a cooler. However, two sardines on bad terms cannot be chosen at the same time.
The i-th and j-th sardines (i \neq j) are on bad terms if and o... | #include <cstdio>
#include <algorithm>
#include <map>
using namespace std;
#define MOD 1000000007
typedef long long ll;
map<pair<ll, ll>, pair<ll, ll> > M;
ll pow2[222222] = { 1 };
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int main(void)
{
ll n, i, x, y, tmp = -1, cnt = 1;
scanf("%lld", &n);
while (... | 2C++ | {
"input": [
"3\n1 2\n-1 1\n2 -1",
"10\n3 2\n3 2\n-1 1\n2 -1\n-3 -9\n-8 12\n7 7\n8 1\n8 2\n8 4",
"3\n1 4\n-1 1\n2 -1",
"10\n3 2\n3 2\n-1 1\n2 -1\n-3 -6\n-8 12\n7 7\n8 1\n8 2\n8 4",
"3\n2 4\n-1 1\n2 -1",
"10\n3 2\n3 2\n-1 1\n2 -1\n-3 -6\n-8 12\n7 1\n8 1\n8 2\n8 4",
"3\n2 4\n-2 1\n2 -1",
... | 5ATCODER |
p02679 AtCoder Beginner Contest 168 - ∙ (Bullet)_1392 | We have caught N sardines. The deliciousness and fragrantness of the i-th sardine is A_i and B_i, respectively.
We will choose one or more of these sardines and put them into a cooler. However, two sardines on bad terms cannot be chosen at the same time.
The i-th and j-th sardines (i \neq j) are on bad terms if and o... | from collections import defaultdict
def gcd(a, b):
return gcd(b, a%b) if b else a
mod = 10 ** 9 + 7
N = int(input())
X = defaultdict(lambda: [0, 0])
# X = dict()
x = 0
y = 0
z = 0
for i in range(N):
a, b = map(int, input().split())
g = abs(gcd(a, b))
if a * b > 0:
X[(abs(a) // g, abs(b) // g)]... | 3Python3 | {
"input": [
"3\n1 2\n-1 1\n2 -1",
"10\n3 2\n3 2\n-1 1\n2 -1\n-3 -9\n-8 12\n7 7\n8 1\n8 2\n8 4",
"3\n1 4\n-1 1\n2 -1",
"10\n3 2\n3 2\n-1 1\n2 -1\n-3 -6\n-8 12\n7 7\n8 1\n8 2\n8 4",
"3\n2 4\n-1 1\n2 -1",
"10\n3 2\n3 2\n-1 1\n2 -1\n-3 -6\n-8 12\n7 1\n8 1\n8 2\n8 4",
"3\n2 4\n-2 1\n2 -1",
... | 5ATCODER |
p02679 AtCoder Beginner Contest 168 - ∙ (Bullet)_1393 | We have caught N sardines. The deliciousness and fragrantness of the i-th sardine is A_i and B_i, respectively.
We will choose one or more of these sardines and put them into a cooler. However, two sardines on bad terms cannot be chosen at the same time.
The i-th and j-th sardines (i \neq j) are on bad terms if and o... | import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
public class Main {
static Input in = new Input(System.in);
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) {
int N = in.nextInt();
Map<Long, Map<Lon... | 4JAVA | {
"input": [
"3\n1 2\n-1 1\n2 -1",
"10\n3 2\n3 2\n-1 1\n2 -1\n-3 -9\n-8 12\n7 7\n8 1\n8 2\n8 4",
"3\n1 4\n-1 1\n2 -1",
"10\n3 2\n3 2\n-1 1\n2 -1\n-3 -6\n-8 12\n7 7\n8 1\n8 2\n8 4",
"3\n2 4\n-1 1\n2 -1",
"10\n3 2\n3 2\n-1 1\n2 -1\n-3 -6\n-8 12\n7 1\n8 1\n8 2\n8 4",
"3\n2 4\n-2 1\n2 -1",
... | 5ATCODER |
p02807 Dwango Programming Contest 6th - Fusing Slimes_1394 | There are N slimes standing on a number line. The i-th slime from the left is at position x_i.
It is guaruanteed that 1 \leq x_1 < x_2 < \ldots < x_N \leq 10^{9}.
Niwango will perform N-1 operations. The i-th operation consists of the following procedures:
* Choose an integer k between 1 and N-i (inclusive) with equ... | # -*- coding: utf-8 -*-
import sys
mod=10**9+7
N=input()
X=map(int, sys.stdin.readline().split())
L=map(lambda x: pow(x,mod-2,mod), range(1,N))
L_RUISEKI=[]
for i,x in enumerate(L):
if i==0: L_RUISEKI.append(x)
else: L_RUISEKI.append(L_RUISEKI[-1]+x)
ans=0
for i in range(N-1):
value=X[i+1]-X[i]
ans+... | 1Python2 | {
"input": [
"12\n161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 982631932",
"3\n1 2 3",
"12\n161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 1765707086",
"3\n1 2 5",
"12\n1... | 5ATCODER |
p02807 Dwango Programming Contest 6th - Fusing Slimes_1395 | There are N slimes standing on a number line. The i-th slime from the left is at position x_i.
It is guaruanteed that 1 \leq x_1 < x_2 < \ldots < x_N \leq 10^{9}.
Niwango will perform N-1 operations. The i-th operation consists of the following procedures:
* Choose an integer k between 1 and N-i (inclusive) with equ... | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL mod = 1000000007;
LL mi (LL x, LL m) {
// compute pow(x, m-2)
LL acc = 1;
LL p = m-2;
while (p) {
if (p%2 == 1) {
acc *= x;
acc %= m;
}
x *= x % m;
x %= m;
p >>= 1;
}
return acc;
}
int main()
{
LL n;
cin >> n;
vect... | 2C++ | {
"input": [
"12\n161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 982631932",
"3\n1 2 3",
"12\n161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 1765707086",
"3\n1 2 5",
"12\n1... | 5ATCODER |
p02807 Dwango Programming Contest 6th - Fusing Slimes_1396 | There are N slimes standing on a number line. The i-th slime from the left is at position x_i.
It is guaruanteed that 1 \leq x_1 < x_2 < \ldots < x_N \leq 10^{9}.
Niwango will perform N-1 operations. The i-th operation consists of the following procedures:
* Choose an integer k between 1 and N-i (inclusive) with equ... | n = int(input())
lst1 = list(map(int,input().split()))
mod = 10**9+7
def pow(n, p):
res = 1
while p > 0:
if p % 2 == 0:
n = n ** 2 % mod
p //= 2
else:
res = res * n % mod
p -= 1
return res % mod
fac = [1]
for i in range(n-1):
fac.append(fa... | 3Python3 | {
"input": [
"12\n161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 982631932",
"3\n1 2 3",
"12\n161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 1765707086",
"3\n1 2 5",
"12\n1... | 5ATCODER |
p02807 Dwango Programming Contest 6th - Fusing Slimes_1397 | There are N slimes standing on a number line. The i-th slime from the left is at position x_i.
It is guaruanteed that 1 \leq x_1 < x_2 < \ldots < x_N \leq 10^{9}.
Niwango will perform N-1 operations. The i-th operation consists of the following procedures:
* Choose an integer k between 1 and N-i (inclusive) with equ... | import java.util.*;
import java.io.*;
class Main{
static long MOD=1_000_000_007l;
static long[] comb;
static long[] fact;
static long[] inv;
public static void main(String[] args){
FastScanner fsc=new FastScanner();
int n=fsc.nextInt();
long[] x=new long[n+1];
long[]... | 4JAVA | {
"input": [
"12\n161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 982631932",
"3\n1 2 3",
"12\n161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 1765707086",
"3\n1 2 5",
"12\n1... | 5ATCODER |
p02943 AtCoder Grand Contest 037 - Reversing and Concatenating_1398 | Takahashi has a string S of length N consisting of lowercase English letters. On this string, he will perform the following operation K times:
* Let T be the string obtained by reversing S, and U be the string obtained by concatenating S and T in this order.
* Let S' be some contiguous substring of U with length N, an... | #include<cstdio>
#include<cstring>
#define N 10005
int i,j,k,l,n;char c[N],x[N],y[N];
inline void solve()
{
for(i=j=1;i<=n;i=j)
{
while(c[i]==c[j])j++;
if(k>12||j-i<<k>=n)
{
memset(x,c[i],n);
if(strcmp(x,y)<0)memcpy(y,x,n);
}
else if((j-i<<k)+(n<<1)-j+1>=n)
{
memset(x,c[i],j-i<<k),memcpy(x+(j-i<<... | 2C++ | {
"input": [
"5 1\nbacba",
"10 2\nbbaabbbaab",
"5 2\nbacba",
"10 2\nbbbabbbaaa",
"10 3\nbbaabbbaab",
"5 2\nbacaa",
"10 2\nbaabbbaabb",
"10 2\nbaabbaaabb",
"10 2\nbbaaabbbab",
"5 1\nbabba",
"10 2\nbabbbbaabb",
"10 1\nbaabbaaabb",
"5 1\nbabbb",
"10 2\nbbaabbbbab",... | 5ATCODER |
p02943 AtCoder Grand Contest 037 - Reversing and Concatenating_1399 | Takahashi has a string S of length N consisting of lowercase English letters. On this string, he will perform the following operation K times:
* Let T be the string obtained by reversing S, and U be the string obtained by concatenating S and T in this order.
* Let S' be some contiguous substring of U with length N, an... | def solve(n, k, s):
u = s + s[::-1]
t = min(u[i:i + n] for i in range(n + 1))
i, h = 0, t[0]
for i, c in enumerate(t):
if c != h:
break
j = i
for _ in range(k - 1):
j <<= 1
if j >= n:
return h * n
return h * j + t[i:i + n - j]
n, k = map(int,... | 3Python3 | {
"input": [
"5 1\nbacba",
"10 2\nbbaabbbaab",
"5 2\nbacba",
"10 2\nbbbabbbaaa",
"10 3\nbbaabbbaab",
"5 2\nbacaa",
"10 2\nbaabbbaabb",
"10 2\nbaabbaaabb",
"10 2\nbbaaabbbab",
"5 1\nbabba",
"10 2\nbabbbbaabb",
"10 1\nbaabbaaabb",
"5 1\nbabbb",
"10 2\nbbaabbbbab",... | 5ATCODER |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.