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 |
|---|---|---|---|---|---|
p02473 Difference of Big Integers_3300 | Difference of Big Integers
Given two integers $A$ and $B$, compute the difference, $A - B$.
Input
Two integers $A$ and $B$ separated by a space character are given in a line.
Output
Print the difference in a line.
Constraints
* $-1 \times 10^{100000} \leq A, B \leq 10^{100000}$
Sample Input 1
5 8
Sample O... | #include "bits/stdc++.h"
using namespace std;
class BigInteger {
public:
using ll = int64_t;
vector<int> val; // 10^9ごとに保管
int neg = 0; // 1のとき負
const ll u = 1e9;
BigInteger(vector<int>& a) :val(a) {}
BigInteger(int a) {
val.clear();
val.push_back(a);
}
BigInteger(const string& s) {
ll tmp = 0;
int l =... | 2C++ | {
"input": [
"5 8",
"5 4",
"5 5",
"5 1",
"4 1",
"2 0",
"8 0",
"15 0",
"15 1",
"8 1",
"0 1",
"0 2",
"0 3",
"-1 3",
"-1 4",
"-1 7",
"-1 8",
"0 16",
"0 31",
"0 45",
"-1 45",
"0 69",
"0 55",
"0 10",
"2 16",
"-2 4",
... | 6AIZU |
p02473 Difference of Big Integers_3301 | Difference of Big Integers
Given two integers $A$ and $B$, compute the difference, $A - B$.
Input
Two integers $A$ and $B$ separated by a space character are given in a line.
Output
Print the difference in a line.
Constraints
* $-1 \times 10^{100000} \leq A, B \leq 10^{100000}$
Sample Input 1
5 8
Sample O... | A, B = map(int, input().split())
print(A - B)
| 3Python3 | {
"input": [
"5 8",
"5 4",
"5 5",
"5 1",
"4 1",
"2 0",
"8 0",
"15 0",
"15 1",
"8 1",
"0 1",
"0 2",
"0 3",
"-1 3",
"-1 4",
"-1 7",
"-1 8",
"0 16",
"0 31",
"0 45",
"-1 45",
"0 69",
"0 55",
"0 10",
"2 16",
"-2 4",
... | 6AIZU |
p02473 Difference of Big Integers_3302 | Difference of Big Integers
Given two integers $A$ and $B$, compute the difference, $A - B$.
Input
Two integers $A$ and $B$ separated by a space character are given in a line.
Output
Print the difference in a line.
Constraints
* $-1 \times 10^{100000} \leq A, B \leq 10^{100000}$
Sample Input 1
5 8
Sample O... | import java.util.Scanner;
import java.math.BigInteger;
public class Main{
public static void main(String[] args){
Scanner cin=new Scanner(System.in);
System.out.println(cin.nextBigInteger().subtract(cin.nextBigInteger()));
}
}
| 4JAVA | {
"input": [
"5 8",
"5 4",
"5 5",
"5 1",
"4 1",
"2 0",
"8 0",
"15 0",
"15 1",
"8 1",
"0 1",
"0 2",
"0 3",
"-1 3",
"-1 4",
"-1 7",
"-1 8",
"0 16",
"0 31",
"0 45",
"-1 45",
"0 69",
"0 55",
"0 10",
"2 16",
"-2 4",
... | 6AIZU |
carvans_3303 | Most problems on CodeChef highlight chef's love for food and cooking but little is known about his love for racing sports. He is an avid Formula 1 fan. He went to watch this year's Indian Grand Prix at New Delhi. He noticed that one segment of the circuit was a long straight road. It was impossible for a car to overtak... | # cook your code here
for testcases in xrange(int(raw_input() ) ) :
n = int(raw_input())
Arr = map(int, raw_input().split() )
m = Arr[0]
c = 1
for i in xrange(1, len(Arr)):
if (Arr[i] <= m ):
c += 1
m = Arr[i]
print c | 1Python2 | {
"input": [
"3\n1\n10\n3\n8 3 6\n5\n4 5 1 2 3",
"3\n1\n10\n3\n8 3 6\n5\n4 5 1 2 4",
"3\n1\n10\n3\n0 3 6\n5\n4 5 1 2 3",
"3\n1\n10\n3\n8 3 1\n5\n4 5 1 2 4",
"3\n1\n0\n3\n8 3 6\n5\n6 5 1 2 5",
"3\n1\n10\n3\n8 3 1\n5\n6 5 1 2 4",
"3\n1\n10\n3\n8 3 1\n5\n0 8 1 2 7",
"3\n1\n10\n3\n0 3 6\n5... | 1CODECHEF |
cranbrom_3304 | Seeing the current political scenario in the city of Delhi,and the clean sweep of the Aam Aadmi Party, you are wondering that its maybe time to change careers and start selling broomsticks.
Now you sell broomsticks of various lengths. You initially do not have any brooms.You decide to roam about in the city finding bro... | t=int(input())
ans=0
l=[-1]*(100001)
while(t>0):
s=raw_input().split(" ")
x=int(s[1])
if(s[0]=="found"):
l[x]=ans
elif(l[x]>=0):
ans=max(ans,l[x]+x)
l[x]-=1
t-=1
print ans | 1Python2 | {
"input": [
"4\nfound 3\nfound 4\ndemand 3\ndemand 4"
],
"output": [
"4"
]
} | 1CODECHEF |
grid_3305 | Sherlock is stuck. There is a N X N grid in which some cells are empty (denoted by ‘.’), while some cells have rocks in them (denoted by ‘#’). Sherlock is on the South of the grid. He has to watch what is happening on the East of the grid. He can place a mirror at 45 degrees on an empty cell in the grid, so that he'll ... | def proc(a):
n=len(a)
j=n-1
l=0
ans=0
hsh=[True]*n
for j in range(n-1,-1,-1):
i=n-1
flag=True
while i>=0:
if a[i][j]=='#':
hsh[i]=False
flag=False
elif hsh[i] and flag: ans+=1
i-=1
print ans
t=int(inp... | 1Python2 | {
"input": [
"2\n3\n#..\n#..\n#..\n3\n#.#\n#.#\n#.#",
"2\n3\n#..\n..#\n#..\n3\n#.#\n#.#\n#.#",
"2\n3\n#..\n\"..\n#..\n3\n#.#\n#.#\n#.#",
"2\n3\n$..\n..#\n#..\n3\n\"-#\n#.#\n\"#.",
"2\n3\n$..\n.#.\n#..\n3\n\"-#\n#.#\n\".#",
"2\n3\n#..\n..#\n..#\n3\n#.#\n#.#\n#.#",
"2\n3\n#..\n#..\n..#\n3\n#... | 1CODECHEF |
mchairs_3306 | A new school in Byteland is now in the process of renewing some classrooms with new, stronger and better chairs, so that the students can stay still and pay attention to class :)
However, due to budget and logistic reasons, it's only possible to carry a chair at a time to the classroom, which means that for a long time... | t=input()
while t>0:
n=input()
print pow(2,n,1000000007)-1
t-=1 | 1Python2 | {
"input": [
"2\n1\n2",
"2\n1\n4",
"2\n1\n8",
"2\n1\n0",
"2\n0\n0",
"2\n1\n6",
"2\n1\n1",
"2\n2\n0",
"2\n1\n12",
"2\n2\n1",
"2\n2\n2",
"2\n1\n5",
"2\n0\n2",
"2\n2\n4",
"2\n1\n3",
"2\n1\n7",
"2\n2\n5",
"2\n0\n5",
"2\n0\n7",
"2\n2\n8",
... | 1CODECHEF |
rdioactv_3307 | EDIT : Please note that the user enters the whole string "Energy Level: 217" instead of just 217. You'd have to input accordingly. The output should only be the ids of radioactive elements, one id per line. Stick to the input/output format.
Note: For Turbo C++, select "Text" as your language
Problem description:
Af... | for u in range(input()):
string = raw_input().split()
if int(string[-1]) > 200:
print u + 1 | 1Python2 | {
"input": [
"4\nEnergy Level: 217\nEnergy Level: 246\nEnergy Level: 4\nEnergy Level: 349",
"4\nEnergy Level: 217\nEnergy Level: 246\nEnergy Level: 4\nEnergy Level: 497",
"4\nEnergy :leveL 111\nEnerhy Lfvel: 419\nEnerfy :lfveL 1\nEnergy :leveL 816",
"4\nxgdErp Lf:dlv 110\neynhDr :emveL 113\nDnfyfs Mmv... | 1CODECHEF |
tproduct_3308 | Given a complete binary tree with the height of H, we index the nodes respectively top-down and left-right from 1. The i-th node stores a positive integer Vi. Define Pi as follows: Pii if the i-th node is a leaf, otherwise Pii*PL, Vi*PR), where L and R are the indices of the left and right children of i, respectively. ... | # tree product - trproduct.py
try:
import psyco
psyco.full()
except ImportError:
pass
mod = 1000000007
h = int(raw_input())
while h>0:
v = map(int, raw_input().split())
if h>1:
level = 1<<(h-2)
while level>=1:
for i in xrange(level-1, 2*level-1):
... | 1Python2 | {
"input": [
"2\n1 2 3\n3\n3 1 5 2 6 4 7\n0",
"2\n1 2 3\n3\n3 1 1 2 6 4 7\n0",
"2\n1 2 3\n3\n3 1 1 2 6 1 8\n0",
"2\n1 2 1\n3\n3 1 1 2 3 1 8\n0",
"2\n1 2 3\n3\n3 1 5 2 12 4 7\n0",
"2\n1 2 3\n3\n3 2 1 2 6 1 7\n0",
"2\n1 2 1\n3\n4 1 1 2 3 1 8\n0",
"2\n1 2 3\n3\n1 2 1 2 6 1 7\n0",
"2\n... | 1CODECHEF |
1016_A. Death Note_3309 | You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during n consecutive days. During the i-th day you have to write exactly a_i names.". You got scared (of course yo... | n,m=map(int,raw_input().split())
p=0
a=map(int,raw_input().split())
for i in a:
print (p+i)/m,
p=(p+i)%m | 1Python2 | {
"input": [
"1 100\n99\n",
"4 20\n10 9 19 2\n",
"3 5\n3 7 9\n",
"1 1\n2\n",
"10 4\n9 5 6 4 3 9 5 1 10 7\n",
"9 9\n1 7 1 8 4 7 9 8 8\n",
"1 1\n1\n",
"16 2\n999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 ... | 2CODEFORCES |
1016_A. Death Note_3310 | You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during n consecutive days. During the i-th day you have to write exactly a_i names.". You got scared (of course yo... | #include <bits/stdc++.h>
using namespace std;
long long a[200005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie();
cout.tie(0);
int n;
long long m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
long long x;
cin >> x;
a[i] = a[i - 1] + x;
}
long long tmp = 0;
for (int i = 1; i <... | 2C++ | {
"input": [
"1 100\n99\n",
"4 20\n10 9 19 2\n",
"3 5\n3 7 9\n",
"1 1\n2\n",
"10 4\n9 5 6 4 3 9 5 1 10 7\n",
"9 9\n1 7 1 8 4 7 9 8 8\n",
"1 1\n1\n",
"16 2\n999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 ... | 2CODEFORCES |
1016_A. Death Note_3311 | You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during n consecutive days. During the i-th day you have to write exactly a_i names.". You got scared (of course yo... | (n,m) = tuple(map(int, input().split(" ")))
x = list(map(int, input().split(" ")))
nib = 0
ans = []
cou = 0;
for i in x:
nib+=i
if (nib<m):
ans.append(nib//m)
else:
ans.append(nib//m)
nib-=(nib//m)*m
print (*ans) | 3Python3 | {
"input": [
"1 100\n99\n",
"4 20\n10 9 19 2\n",
"3 5\n3 7 9\n",
"1 1\n2\n",
"10 4\n9 5 6 4 3 9 5 1 10 7\n",
"9 9\n1 7 1 8 4 7 9 8 8\n",
"1 1\n1\n",
"16 2\n999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 ... | 2CODEFORCES |
1016_A. Death Note_3312 | You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during n consecutive days. During the i-th day you have to write exactly a_i names.". You got scared (of course yo... | //package baobab;
import java.io.*;
import java.util.*;
public class A {
public static void main(String[] args) {
Solver solver = new Solver();
}
static class Solver {
IO io;
public Solver() {
this.io = new IO();
try {
solve();
... | 4JAVA | {
"input": [
"1 100\n99\n",
"4 20\n10 9 19 2\n",
"3 5\n3 7 9\n",
"1 1\n2\n",
"10 4\n9 5 6 4 3 9 5 1 10 7\n",
"9 9\n1 7 1 8 4 7 9 8 8\n",
"1 1\n1\n",
"16 2\n999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 ... | 2CODEFORCES |
103_A. Testing Pants for Sadness_3313 | The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of n questions; the questions are to be answered strictly in the order in which they are given, from question 1 to ... | n = input()
a = map(int, raw_input().split())
res = 0
for i in range(n):
res += i * (a[i] - 1) + a[i]
print res
| 1Python2 | {
"input": [
"2\n2 2\n",
"2\n1 1\n",
"1\n10\n",
"100\n1 3 2 1 1 2 1 3 2 2 3 1 1 1 2 2 1 3 3 1 1 2 2 3 2 1 3 1 3 2 1 1 3 3 2 1 2 2 2 3 2 2 3 2 2 3 2 1 3 1 1 2 1 3 2 2 1 1 1 1 1 1 3 1 2 3 1 1 1 1 1 2 3 3 1 1 1 1 2 3 3 1 3 2 2 3 2 1 3 2 2 3 1 1 3 2 3 2 3 1\n",
"1\n84355694\n",
"3\n2 4 1\n",
"... | 2CODEFORCES |
103_A. Testing Pants for Sadness_3314 | The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of n questions; the questions are to be answered strictly in the order in which they are given, from question 1 to ... | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, t, res = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> t;
res += (t * i) - (i - 1);
}
cout << res << endl;
}
| 2C++ | {
"input": [
"2\n2 2\n",
"2\n1 1\n",
"1\n10\n",
"100\n1 3 2 1 1 2 1 3 2 2 3 1 1 1 2 2 1 3 3 1 1 2 2 3 2 1 3 1 3 2 1 1 3 3 2 1 2 2 2 3 2 2 3 2 2 3 2 1 3 1 1 2 1 3 2 2 1 1 1 1 1 1 3 1 2 3 1 1 1 1 1 2 3 3 1 1 1 1 2 3 3 1 3 2 2 3 2 1 3 2 2 3 1 1 3 2 3 2 3 1\n",
"1\n84355694\n",
"3\n2 4 1\n",
"... | 2CODEFORCES |
103_A. Testing Pants for Sadness_3315 | The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of n questions; the questions are to be answered strictly in the order in which they are given, from question 1 to ... | import sys,math
s = int(input())
arr = list(map(int,input().split(' ')))
m = 0
for i in range(0,s):
m+=(arr[i]-1)*(i+1)+1
print(m)
'''
2 2 2
1+1 2
1+1+1 3
(1+1+1,1) 4
3 3
1+1+1 3
1+1+1+1+1 5
1+1+1,1+1+1,1 7
3
2 4 1
1+1
1+1+1+1+1+1+1
1
1+1+1+1
'''
| 3Python3 | {
"input": [
"2\n2 2\n",
"2\n1 1\n",
"1\n10\n",
"100\n1 3 2 1 1 2 1 3 2 2 3 1 1 1 2 2 1 3 3 1 1 2 2 3 2 1 3 1 3 2 1 1 3 3 2 1 2 2 2 3 2 2 3 2 2 3 2 1 3 1 1 2 1 3 2 2 1 1 1 1 1 1 3 1 2 3 1 1 1 1 1 2 3 3 1 1 1 1 2 3 3 1 3 2 2 3 2 1 3 2 2 3 1 1 3 2 3 2 3 1\n",
"1\n84355694\n",
"3\n2 4 1\n",
"... | 2CODEFORCES |
103_A. Testing Pants for Sadness_3316 | The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of n questions; the questions are to be answered strictly in the order in which they are given, from question 1 to ... |
import java.awt.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
i... | 4JAVA | {
"input": [
"2\n2 2\n",
"2\n1 1\n",
"1\n10\n",
"100\n1 3 2 1 1 2 1 3 2 2 3 1 1 1 2 2 1 3 3 1 1 2 2 3 2 1 3 1 3 2 1 1 3 3 2 1 2 2 2 3 2 2 3 2 2 3 2 1 3 1 1 2 1 3 2 2 1 1 1 1 1 1 3 1 2 3 1 1 1 1 1 2 3 3 1 1 1 1 2 3 3 1 3 2 2 3 2 1 3 2 2 3 1 1 3 2 3 2 3 1\n",
"1\n84355694\n",
"3\n2 4 1\n",
"... | 2CODEFORCES |
1062_B. Math_3317 | JATC's math teacher always gives the class some interesting math problems so that they don't get bored. Today the problem is as follows. Given an integer n, you can perform the following operations zero or more times:
* mul x: multiplies n by x (where x is an arbitrary positive integer).
* sqrt: replaces n with √... | import math
n=input()
if n==1:
print 1, 0
else:
flag=1
k=n
t=0
while flag:
c=int(math.sqrt(k))
if c*c==k:
k=c
t+=1
else:
flag=0
res=[]
vals=[]
for j in range(2,k+1):
c=0
while k%j==0:
k=k/j
c+=1
if c>0:
res.append(j)
vals.append(c)
ma1=max(vals)
ma=ma1
et=0
f2=1
if ma and n... | 1Python2 | {
"input": [
"20\n",
"5184\n",
"2\n",
"328509\n",
"279936\n",
"341\n",
"605000\n",
"11\n",
"4\n",
"786432\n",
"982081\n",
"52488\n",
"6444\n",
"12\n",
"1105\n",
"49\n",
"252601\n",
"1000000\n",
"162000\n",
"29341\n",
"1729\n",
"30... | 2CODEFORCES |
1062_B. Math_3318 | JATC's math teacher always gives the class some interesting math problems so that they don't get bored. Today the problem is as follows. Given an integer n, you can perform the following operations zero or more times:
* mul x: multiplies n by x (where x is an arbitrary positive integer).
* sqrt: replaces n with √... | #include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
const int mod = 1e9 + 7;
int dcmp(long double x, long double y) {
return fabs(x - y) <= 1e-12 ? 0 : x < y ? -1 : 1;
}
void fast() {
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout... | 2C++ | {
"input": [
"20\n",
"5184\n",
"2\n",
"328509\n",
"279936\n",
"341\n",
"605000\n",
"11\n",
"4\n",
"786432\n",
"982081\n",
"52488\n",
"6444\n",
"12\n",
"1105\n",
"49\n",
"252601\n",
"1000000\n",
"162000\n",
"29341\n",
"1729\n",
"30... | 2CODEFORCES |
1062_B. Math_3319 | JATC's math teacher always gives the class some interesting math problems so that they don't get bored. Today the problem is as follows. Given an integer n, you can perform the following operations zero or more times:
* mul x: multiplies n by x (where x is an arbitrary positive integer).
* sqrt: replaces n with √... | import math
def sieve(n):
mark = [0]*(n+1)
prime = []
for i in range(3, n+1, 2):
if not mark[i]:
for j in range(3*i, n+1, i+i):
mark[j] = 1
prime.append(2)
for i in range(3, n+1, 2):
if not mark[i]:
prime.append(i)
return prime
def isp... | 3Python3 | {
"input": [
"20\n",
"5184\n",
"2\n",
"328509\n",
"279936\n",
"341\n",
"605000\n",
"11\n",
"4\n",
"786432\n",
"982081\n",
"52488\n",
"6444\n",
"12\n",
"1105\n",
"49\n",
"252601\n",
"1000000\n",
"162000\n",
"29341\n",
"1729\n",
"30... | 2CODEFORCES |
1062_B. Math_3320 | JATC's math teacher always gives the class some interesting math problems so that they don't get bored. Today the problem is as follows. Given an integer n, you can perform the following operations zero or more times:
* mul x: multiplies n by x (where x is an arbitrary positive integer).
* sqrt: replaces n with √... | import java.io.*;
import java.util.*;
import java.math.*;
public class code{
public static void main(String args[]){
Scanner sc =new Scanner(System.in);
//Writer wr=new Writer(System.out);
int lpf[]=new int[1000001];
int N =1000001;
lpf[0]=-1;
lpf[1]=1;
for(int i=2;i<N;i++){
lpf[i]=i;
}
for(... | 4JAVA | {
"input": [
"20\n",
"5184\n",
"2\n",
"328509\n",
"279936\n",
"341\n",
"605000\n",
"11\n",
"4\n",
"786432\n",
"982081\n",
"52488\n",
"6444\n",
"12\n",
"1105\n",
"49\n",
"252601\n",
"1000000\n",
"162000\n",
"29341\n",
"1729\n",
"30... | 2CODEFORCES |
1084_A. The Fair Nut and Elevator_3321 | The Fair Nut lives in n story house. a_i people live on the i-th floor of the house. Every person uses elevator twice a day: to get from the floor where he/she lives to the ground (first) floor and to get from the first floor to the floor where he/she lives, when he/she comes back home in the evening.
It was decided ... | n=input()
l=map(int,raw_input().split(" "))
mn=1000000000000000
for i in range(n):
x=i
ans=0
for i in range(n):
ans+=2*l[i]*(i+x+abs(i-x))
#print l[i]*(i+1+x+abs(i+1-x))
mn=min(ans,mn)
print mn
| 1Python2 | {
"input": [
"2\n1 1\n",
"3\n0 2 1\n",
"5\n6 1 1 8 3\n",
"5\n4 9 4 2 6\n",
"3\n1 2 2\n",
"100\n23 94 2 59 41 51 92 74 92 76 37 98 76 47 60 4 22 32 22 32 57 39 68 60 38 41 61 7 34 98 42 44 52 100 81 24 16 51 10 84 34 52 73 100 69 38 14 77 32 4 59 37 68 81 6 37 52 6 96 22 12 23 63 57 59 18 20 1 ... | 2CODEFORCES |
1084_A. The Fair Nut and Elevator_3322 | The Fair Nut lives in n story house. a_i people live on the i-th floor of the house. Every person uses elevator twice a day: to get from the floor where he/she lives to the ground (first) floor and to get from the first floor to the floor where he/she lives, when he/she comes back home in the evening.
It was decided ... | #include <bits/stdc++.h>
using namespace std;
int a[200];
int main() {
int n;
cin >> n;
int pos = 0, maxx = 0;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) {
if (maxx < a[i]) {
maxx = a[i];
pos = i;
}
}
if (maxx == 0) return puts("0"), 0;
int ans = 0;
for ... | 2C++ | {
"input": [
"2\n1 1\n",
"3\n0 2 1\n",
"5\n6 1 1 8 3\n",
"5\n4 9 4 2 6\n",
"3\n1 2 2\n",
"100\n23 94 2 59 41 51 92 74 92 76 37 98 76 47 60 4 22 32 22 32 57 39 68 60 38 41 61 7 34 98 42 44 52 100 81 24 16 51 10 84 34 52 73 100 69 38 14 77 32 4 59 37 68 81 6 37 52 6 96 22 12 23 63 57 59 18 20 1 ... | 2CODEFORCES |
1084_A. The Fair Nut and Elevator_3323 | The Fair Nut lives in n story house. a_i people live on the i-th floor of the house. Every person uses elevator twice a day: to get from the floor where he/she lives to the ground (first) floor and to get from the first floor to the floor where he/she lives, when he/she comes back home in the evening.
It was decided ... | n = int(input())
arr = list(map(int, input().split()))
cur = 0
ans = 100000000
for x in range(n):
cur = 0
for i in range(n):
summ = 0
summ += abs(x - i)
summ += i
summ += x
summ += x
summ += i
summ += abs(x - i)
summ *= arr[i]
cur += summ
... | 3Python3 | {
"input": [
"2\n1 1\n",
"3\n0 2 1\n",
"5\n6 1 1 8 3\n",
"5\n4 9 4 2 6\n",
"3\n1 2 2\n",
"100\n23 94 2 59 41 51 92 74 92 76 37 98 76 47 60 4 22 32 22 32 57 39 68 60 38 41 61 7 34 98 42 44 52 100 81 24 16 51 10 84 34 52 73 100 69 38 14 77 32 4 59 37 68 81 6 37 52 6 96 22 12 23 63 57 59 18 20 1 ... | 2CODEFORCES |
1084_A. The Fair Nut and Elevator_3324 | The Fair Nut lives in n story house. a_i people live on the i-th floor of the house. Every person uses elevator twice a day: to get from the floor where he/she lives to the ground (first) floor and to get from the first floor to the floor where he/she lives, when he/she comes back home in the evening.
It was decided ... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Map.Entry;
import java.util.StringTokenizer;
import java.util.TreeMap;
public class A {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(Syst... | 4JAVA | {
"input": [
"2\n1 1\n",
"3\n0 2 1\n",
"5\n6 1 1 8 3\n",
"5\n4 9 4 2 6\n",
"3\n1 2 2\n",
"100\n23 94 2 59 41 51 92 74 92 76 37 98 76 47 60 4 22 32 22 32 57 39 68 60 38 41 61 7 34 98 42 44 52 100 81 24 16 51 10 84 34 52 73 100 69 38 14 77 32 4 59 37 68 81 6 37 52 6 96 22 12 23 63 57 59 18 20 1 ... | 2CODEFORCES |
1103_C. Johnny Solving_3325 | Today is tuesday, that means there is a dispute in JOHNNY SOLVING team again: they try to understand who is Johnny and who is Solving. That's why guys asked Umnik to help them. Umnik gave guys a connected graph with n vertices without loops and multiedges, such that a degree of any vertex is at least 3, and also he gav... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 5 * 100005;
vector<int> a[maxn];
int n, m, k, lim;
int head[maxn], Next[maxn * 2], to[maxn * 2], tot = 0;
int d[maxn], fa[maxn], size[maxn];
bool vis[maxn];
void add(int x, int y) {
to[++tot] = y;
Next[tot] = head[x];
head[x] = tot;
}
void dfs_tree(in... | 2C++ | {
"input": [
"4 6 2\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n",
"10 18 2\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 3\n3 4\n2 4\n5 6\n6 7\n5 7\n8 9\n9 10\n8 10\n",
"15 34 1\n1 8\n2 8\n3 8\n4 8\n5 8\n6 8\n7 8\n9 8\n10 8\n11 8\n12 8\n13 8\n14 8\n15 8\n1 9\n3 9\n5 9\n7 9\n11 9\n13 9\n15 9\n1 5\n13 5\n3 11\n7 11\... | 2CODEFORCES |
1103_C. Johnny Solving_3326 | Today is tuesday, that means there is a dispute in JOHNNY SOLVING team again: they try to understand who is Johnny and who is Solving. That's why guys asked Umnik to help them. Umnik gave guys a connected graph with n vertices without loops and multiedges, such that a degree of any vertex is at least 3, and also he gav... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Iterator;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.Writer;
imp... | 4JAVA | {
"input": [
"4 6 2\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n",
"10 18 2\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 3\n3 4\n2 4\n5 6\n6 7\n5 7\n8 9\n9 10\n8 10\n",
"15 34 1\n1 8\n2 8\n3 8\n4 8\n5 8\n6 8\n7 8\n9 8\n10 8\n11 8\n12 8\n13 8\n14 8\n15 8\n1 9\n3 9\n5 9\n7 9\n11 9\n13 9\n15 9\n1 5\n13 5\n3 11\n7 11\... | 2CODEFORCES |
1131_C. Birthday_3327 | Cowboy Vlad has a birthday today! There are n children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing n... | n=input()
l=map(int,raw_input().split())
l.sort()
t=[0]*n
i=0
j=n-1
for k in range(n):
if k%2==0:
t[i]=l[k]
i+=1
else:
t[j]=l[k]
j-=1
if n%2==1:
t[n/2]=l[n-1]
for i in t:
print i,
| 1Python2 | {
"input": [
"3\n30 10 20\n",
"5\n2 1 1 3 2\n",
"5\n7318577 1728333 8514304 9971719 9004162\n",
"100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70... | 2CODEFORCES |
1131_C. Birthday_3328 | Cowboy Vlad has a birthday today! There are n children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing n... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n = 0;
cin >> n;
vector<int> arr(n, 0);
for (int i = 0; i < n; i++) cin >> arr[i];
sort(arr.begin(), arr.end(), greater<int>());
vector<int> ans(n, 0);
int k = 0;
int i = n / 2;
int j = i - 1;
while (j >= 0) {
if (n > i) ans[i++] = a... | 2C++ | {
"input": [
"3\n30 10 20\n",
"5\n2 1 1 3 2\n",
"5\n7318577 1728333 8514304 9971719 9004162\n",
"100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70... | 2CODEFORCES |
1131_C. Birthday_3329 | Cowboy Vlad has a birthday today! There are n children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing n... | n = int(input())
arr = [int(i) for i in input().split()]
arr1, arr2 = [], []
arr.sort(reverse = True)
for i in range(n):
if i%2==0:
arr1.append(arr[i])
else:
arr2.append(arr[i])
arr2.reverse()
for i in arr2:
arr1.append(i)
print(*arr1) | 3Python3 | {
"input": [
"3\n30 10 20\n",
"5\n2 1 1 3 2\n",
"5\n7318577 1728333 8514304 9971719 9004162\n",
"100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70... | 2CODEFORCES |
1131_C. Birthday_3330 | Cowboy Vlad has a birthday today! There are n children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing n... |
import java.util.Arrays;
import java.util.Scanner;
public class qweqweqweqwe {
public static void main(String args[])
{
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
int ar[]=new int[n];
int ans[]=new int[n];
for(int i=0;i<n;i++)
{
ar[i]=scan.nextInt();
}
Arrays.sort(ar);
//for(i... | 4JAVA | {
"input": [
"3\n30 10 20\n",
"5\n2 1 1 3 2\n",
"5\n7318577 1728333 8514304 9971719 9004162\n",
"100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70... | 2CODEFORCES |
1151_E. Number of Components_3331 | The Kingdom of Kremland is a tree (a connected undirected graph without cycles) consisting of n vertices. Each vertex i has its own value a_i. All vertices are connected in series by edges. Formally, for every 1 ≤ i < n there is an edge between the vertices of i and i+1.
Denote the function f(l, r), which takes two in... |
def main():
inp = readnumbers()
n = inp[0]
big = n + 1
A = inp[1:]
A.append(0)
ans = 0
for i in range(n):
me = A[i]
nesta = A[i+1]
if me<nesta:
ans += me*(nesta - me)
else:
ans += (me - nesta)*(n - me + 1)
print ans
#######... | 1Python2 | {
"input": [
"3\n2 1 3\n",
"10\n1 5 2 5 5 3 10 6 5 1\n",
"4\n2 1 1 3\n",
"9\n1 9 1 1 4 5 9 9 1\n",
"44\n42 44 4 24 29 17 32 30 30 9 28 9 22 16 20 41 17 19 41 23 28 19 38 44 1 34 41 34 19 36 32 37 22 31 4 3 27 23 21 21 26 39 20 8\n",
"40\n35 33 20 13 21 4 16 21 22 35 20 39 32 29 27 5 24 3 12 10... | 2CODEFORCES |
1151_E. Number of Components_3332 | The Kingdom of Kremland is a tree (a connected undirected graph without cycles) consisting of n vertices. Each vertex i has its own value a_i. All vertices are connected in series by edges. Formally, for every 1 ≤ i < n there is an edge between the vertices of i and i+1.
Denote the function f(l, r), which takes two in... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int str[maxn];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> str[i];
long long ans = 0;
for (int i = 0; i < n; i++) {
if (i == 0) {
ans += 1ll * str[i] * (n - str[i] + 1);
} else {
if (str[i] > str[... | 2C++ | {
"input": [
"3\n2 1 3\n",
"10\n1 5 2 5 5 3 10 6 5 1\n",
"4\n2 1 1 3\n",
"9\n1 9 1 1 4 5 9 9 1\n",
"44\n42 44 4 24 29 17 32 30 30 9 28 9 22 16 20 41 17 19 41 23 28 19 38 44 1 34 41 34 19 36 32 37 22 31 4 3 27 23 21 21 26 39 20 8\n",
"40\n35 33 20 13 21 4 16 21 22 35 20 39 32 29 27 5 24 3 12 10... | 2CODEFORCES |
1151_E. Number of Components_3333 | The Kingdom of Kremland is a tree (a connected undirected graph without cycles) consisting of n vertices. Each vertex i has its own value a_i. All vertices are connected in series by edges. Formally, for every 1 ≤ i < n there is an edge between the vertices of i and i+1.
Denote the function f(l, r), which takes two in... | n = int(input()) + 1
res = 0
a = tuple(map(int, input().split()))
for ai in a:
res += ai * (n - ai)
for ai, aj in map(sorted, zip(a, a[1:])):
res -= ai * (n - aj)
print(res)
# | 3Python3 | {
"input": [
"3\n2 1 3\n",
"10\n1 5 2 5 5 3 10 6 5 1\n",
"4\n2 1 1 3\n",
"9\n1 9 1 1 4 5 9 9 1\n",
"44\n42 44 4 24 29 17 32 30 30 9 28 9 22 16 20 41 17 19 41 23 28 19 38 44 1 34 41 34 19 36 32 37 22 31 4 3 27 23 21 21 26 39 20 8\n",
"40\n35 33 20 13 21 4 16 21 22 35 20 39 32 29 27 5 24 3 12 10... | 2CODEFORCES |
1151_E. Number of Components_3334 | The Kingdom of Kremland is a tree (a connected undirected graph without cycles) consisting of n vertices. Each vertex i has its own value a_i. All vertices are connected in series by edges. Formally, for every 1 ≤ i < n there is an edge between the vertices of i and i+1.
Denote the function f(l, r), which takes two in... | // Don't place your source in a package
import javax.swing.*;
import java.lang.reflect.Array;
import java.text.DecimalFormat;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
import java.util.stream.Stream;
// Please name your class Main
public class Main {
static FastScanner fs=new ... | 4JAVA | {
"input": [
"3\n2 1 3\n",
"10\n1 5 2 5 5 3 10 6 5 1\n",
"4\n2 1 1 3\n",
"9\n1 9 1 1 4 5 9 9 1\n",
"44\n42 44 4 24 29 17 32 30 30 9 28 9 22 16 20 41 17 19 41 23 28 19 38 44 1 34 41 34 19 36 32 37 22 31 4 3 27 23 21 21 26 39 20 8\n",
"40\n35 33 20 13 21 4 16 21 22 35 20 39 32 29 27 5 24 3 12 10... | 2CODEFORCES |
1173_D. Nauuo and Circle_3335 | Nauuo is a girl who loves drawing circles.
One day she has drawn a circle and wanted to draw a tree on it.
The tree is a connected undirected graph consisting of n nodes and n-1 edges. The nodes are numbered from 1 to n.
Nauuo wants to draw a tree on the circle, the nodes of the tree should be in n distinct points o... | import sys,math
from fractions import gcd
from bisect import bisect_left, bisect
from collections import defaultdict
from io import BytesIO
sys.stdin = BytesIO(sys.stdin.read())
input = lambda: sys.stdin.readline().rstrip('\r\n')
n = int(input())
#arr = [int(_) for _ in input().split()]
dsv = defaultdict(set)
dv = def... | 1Python2 | {
"input": [
"4\n1 2\n1 3\n1 4\n",
"4\n1 2\n1 3\n2 4\n",
"8\n4 5\n1 2\n6 3\n2 3\n2 8\n4 7\n2 4\n",
"7\n2 7\n2 6\n4 7\n7 3\n7 5\n1 7\n",
"3\n1 2\n3 2\n",
"2\n2 1\n",
"10\n5 4\n5 2\n3 7\n9 3\n3 2\n3 1\n3 8\n9 10\n1 6\n",
"6\n2 1\n3 2\n4 1\n5 4\n1 6\n",
"5\n3 5\n4 3\n2 4\n1 2\n",
... | 2CODEFORCES |
1173_D. Nauuo and Circle_3336 | Nauuo is a girl who loves drawing circles.
One day she has drawn a circle and wanted to draw a tree on it.
The tree is a connected undirected graph consisting of n nodes and n-1 edges. The nodes are numbered from 1 to n.
Nauuo wants to draw a tree on the circle, the nodes of the tree should be in n distinct points o... | #include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
vector<int> edge[200000];
long long fact[200001];
void init() {
fact[0] = fact[1] = 1;
for ... | 2C++ | {
"input": [
"4\n1 2\n1 3\n1 4\n",
"4\n1 2\n1 3\n2 4\n",
"8\n4 5\n1 2\n6 3\n2 3\n2 8\n4 7\n2 4\n",
"7\n2 7\n2 6\n4 7\n7 3\n7 5\n1 7\n",
"3\n1 2\n3 2\n",
"2\n2 1\n",
"10\n5 4\n5 2\n3 7\n9 3\n3 2\n3 1\n3 8\n9 10\n1 6\n",
"6\n2 1\n3 2\n4 1\n5 4\n1 6\n",
"5\n3 5\n4 3\n2 4\n1 2\n",
... | 2CODEFORCES |
1173_D. Nauuo and Circle_3337 | Nauuo is a girl who loves drawing circles.
One day she has drawn a circle and wanted to draw a tree on it.
The tree is a connected undirected graph consisting of n nodes and n-1 edges. The nodes are numbered from 1 to n.
Nauuo wants to draw a tree on the circle, the nodes of the tree should be in n distinct points o... | import sys
n = int(sys.stdin.readline().strip())
D = [0] * n
p = 998244353
for i in range (0, n - 1):
u, v = list(map(int, sys.stdin.readline().strip().split()))
D[u-1] = D[u-1] + 1
D[v-1] = D[v-1] + 1
ans = n
for i in range (0, n):
for j in range (0, D[i]):
ans = (ans * (j + 1)) % p
print(an... | 3Python3 | {
"input": [
"4\n1 2\n1 3\n1 4\n",
"4\n1 2\n1 3\n2 4\n",
"8\n4 5\n1 2\n6 3\n2 3\n2 8\n4 7\n2 4\n",
"7\n2 7\n2 6\n4 7\n7 3\n7 5\n1 7\n",
"3\n1 2\n3 2\n",
"2\n2 1\n",
"10\n5 4\n5 2\n3 7\n9 3\n3 2\n3 1\n3 8\n9 10\n1 6\n",
"6\n2 1\n3 2\n4 1\n5 4\n1 6\n",
"5\n3 5\n4 3\n2 4\n1 2\n",
... | 2CODEFORCES |
1173_D. Nauuo and Circle_3338 | Nauuo is a girl who loves drawing circles.
One day she has drawn a circle and wanted to draw a tree on it.
The tree is a connected undirected graph consisting of n nodes and n-1 edges. The nodes are numbered from 1 to n.
Nauuo wants to draw a tree on the circle, the nodes of the tree should be in n distinct points o... | import java.io.*;
import java.util.*;
public class D {
private static int mod = 998244353;
public static void main(String[] args) {
FastReader in = new FastReader(System.in);
// FastReader in2 = new FastReader(new FileInputStream("input.txt"));
PrintWriter out = new PrintWriter... | 4JAVA | {
"input": [
"4\n1 2\n1 3\n1 4\n",
"4\n1 2\n1 3\n2 4\n",
"8\n4 5\n1 2\n6 3\n2 3\n2 8\n4 7\n2 4\n",
"7\n2 7\n2 6\n4 7\n7 3\n7 5\n1 7\n",
"3\n1 2\n3 2\n",
"2\n2 1\n",
"10\n5 4\n5 2\n3 7\n9 3\n3 2\n3 1\n3 8\n9 10\n1 6\n",
"6\n2 1\n3 2\n4 1\n5 4\n1 6\n",
"5\n3 5\n4 3\n2 4\n1 2\n",
... | 2CODEFORCES |
1191_A. Tokitsukaze and Enhancement_3339 | Tokitsukaze is one of the characters in the game "Kantai Collection". In this game, every character has a common attribute — health points, shortened to HP.
In general, different values of HP are grouped into 4 categories:
* Category A if HP is in the form of (4 n + 1), that is, when divided by 4, the remainder is ... | n=input()
a=n%4
if a==0:
print 1,"A"
elif a==1:
print 0,"A"
elif a==2:
print 1,"B"
elif a==3:
print 2,"A"
| 1Python2 | {
"input": [
"33\n",
"98\n",
"85\n",
"99\n",
"50\n",
"100\n",
"59\n",
"60\n",
"95\n",
"93\n",
"91\n",
"30\n",
"88\n",
"83\n",
"32\n",
"52\n",
"43\n",
"67\n",
"42\n",
"36\n",
"76\n",
"77\n",
"35\n",
"6\n",
"28\n",
"... | 2CODEFORCES |
1191_A. Tokitsukaze and Enhancement_3340 | Tokitsukaze is one of the characters in the game "Kantai Collection". In this game, every character has a common attribute — health points, shortened to HP.
In general, different values of HP are grouped into 4 categories:
* Category A if HP is in the form of (4 n + 1), that is, when divided by 4, the remainder is ... | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
long long int x = 0;
if (n % 4 == 1)
x = 1;
else if (n % 4 == 3)
x = 2;
else if (n % 4 == 2)
x = 3;
else
x = 4;
if (x == 1)
cout << "0 A";
else if (x == 2)
cout << "2 A";
else if (x == 3)
... | 2C++ | {
"input": [
"33\n",
"98\n",
"85\n",
"99\n",
"50\n",
"100\n",
"59\n",
"60\n",
"95\n",
"93\n",
"91\n",
"30\n",
"88\n",
"83\n",
"32\n",
"52\n",
"43\n",
"67\n",
"42\n",
"36\n",
"76\n",
"77\n",
"35\n",
"6\n",
"28\n",
"... | 2CODEFORCES |
1191_A. Tokitsukaze and Enhancement_3341 | Tokitsukaze is one of the characters in the game "Kantai Collection". In this game, every character has a common attribute — health points, shortened to HP.
In general, different values of HP are grouped into 4 categories:
* Category A if HP is in the form of (4 n + 1), that is, when divided by 4, the remainder is ... | n=int(input())
d={}
d[0]='1 A'
d[1]='0 A'
d[2]='1 B'
d[3]='2 A'
x=n%4
print(d[x]) | 3Python3 | {
"input": [
"33\n",
"98\n",
"85\n",
"99\n",
"50\n",
"100\n",
"59\n",
"60\n",
"95\n",
"93\n",
"91\n",
"30\n",
"88\n",
"83\n",
"32\n",
"52\n",
"43\n",
"67\n",
"42\n",
"36\n",
"76\n",
"77\n",
"35\n",
"6\n",
"28\n",
"... | 2CODEFORCES |
1191_A. Tokitsukaze and Enhancement_3342 | Tokitsukaze is one of the characters in the game "Kantai Collection". In this game, every character has a common attribute — health points, shortened to HP.
In general, different values of HP are grouped into 4 categories:
* Category A if HP is in the form of (4 n + 1), that is, when divided by 4, the remainder is ... | /**
* Enhance.java
* https://codeforces.com/problemset/problem/1191/A
* @author
* @version 1.0
* @since 8/28/2019
*/
import java.util.Scanner;
public class Enhance
{
private int x;
public static void main(String[] args)
{
Enhance run = new Enhance();
run.methods();
}
public void methods()
{
read... | 4JAVA | {
"input": [
"33\n",
"98\n",
"85\n",
"99\n",
"50\n",
"100\n",
"59\n",
"60\n",
"95\n",
"93\n",
"91\n",
"30\n",
"88\n",
"83\n",
"32\n",
"52\n",
"43\n",
"67\n",
"42\n",
"36\n",
"76\n",
"77\n",
"35\n",
"6\n",
"28\n",
"... | 2CODEFORCES |
120_A. Elevator_3343 | A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails n... | enter = {'front':0, 'back':1}
hand = ['L','R']
try:
op = open('output.txt', 'w');
with open('input.txt') as ip:
op.write(hand[enter[ip.readline().strip()]^(int(ip.readline())-1)])
op.close()
except IOError as e:
print 'L'
| 1Python2 | {
"input": [
"front\n1\n",
"back\n2\n",
"front\n2\n",
"back\n1\n",
"kcab\n2\n",
"front\n0\n",
"back\n4\n",
"fronu\n1\n",
"jcab\n2\n",
"ftonr\n1\n",
"back\n8\n",
"fronu\n0\n",
"bacj\n2\n",
"ftonr\n2\n",
"babk\n8\n",
"fqonu\n0\n",
"bacj\n4\n",
"fto... | 2CODEFORCES |
120_A. Elevator_3344 | A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails n... | #include <bits/stdc++.h>
using namespace std;
int main() {
ifstream ifile("input.txt");
if (ifile) freopen("input.txt", "rt", stdin);
if (ifile) freopen("output.txt", "wt", stdout);
string s;
cin >> s;
int r;
cin >> r;
if (s == "front") {
if (r == 1)
cout << "L";
else
cout << "R";
... | 2C++ | {
"input": [
"front\n1\n",
"back\n2\n",
"front\n2\n",
"back\n1\n",
"kcab\n2\n",
"front\n0\n",
"back\n4\n",
"fronu\n1\n",
"jcab\n2\n",
"ftonr\n1\n",
"back\n8\n",
"fronu\n0\n",
"bacj\n2\n",
"ftonr\n2\n",
"babk\n8\n",
"fqonu\n0\n",
"bacj\n4\n",
"fto... | 2CODEFORCES |
120_A. Elevator_3345 | A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails n... |
import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
public class Main{
public static void main(String[]args){
InputStream in = System.in;
PrintWriter out = new PrintWriter(System.out);
try{
... | 4JAVA | {
"input": [
"front\n1\n",
"back\n2\n",
"front\n2\n",
"back\n1\n",
"kcab\n2\n",
"front\n0\n",
"back\n4\n",
"fronu\n1\n",
"jcab\n2\n",
"ftonr\n1\n",
"back\n8\n",
"fronu\n0\n",
"bacj\n2\n",
"ftonr\n2\n",
"babk\n8\n",
"fqonu\n0\n",
"bacj\n4\n",
"fto... | 2CODEFORCES |
122_D. Lucky Transformation_3346 | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has a number consisting of n digits without leading zeroes. He represented it as an array of d... | n, m = map(int, raw_input().split())
s = list(raw_input())
i = 1
count = 0
while i != n and count != m:
if s[i-1] == '4' and s[i] == '7':
if i >= 2 and s[i-2] == '4' and i%2 == 0 and m - count != 1:
count += (m - count) - (m - count)%2
else:
if i%2 == 1:
s[i] = '4'
else:
s[i-1] = '7'
count += 1... | 1Python2 | {
"input": [
"4 2\n4478\n",
"7 4\n4727447\n",
"7 74\n4777774\n",
"3 99\n447\n",
"47 7\n77774477747474477477477774747747447447774777474\n",
"74 1000000000\n77474447774774747474777447474777777477474444477747444777447444474744744444\n",
"10 200\n6860544593\n",
"100 1000000000\n58493474544... | 2CODEFORCES |
122_D. Lucky Transformation_3347 | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has a number consisting of n digits without leading zeroes. He represented it as an array of d... | #include <bits/stdc++.h>
char A[100001];
int op;
int cnt;
int n;
int at;
inline void solve() {
while (cnt < op) {
if (at == n - 1) {
break;
} else {
if (A[at] == '4' && A[at + 1] == '7') {
if (at % 2 == 0) {
if (at == n - 2) {
A[at + 1] = '4';
cnt++;
... | 2C++ | {
"input": [
"4 2\n4478\n",
"7 4\n4727447\n",
"7 74\n4777774\n",
"3 99\n447\n",
"47 7\n77774477747474477477477774747747447447774777474\n",
"74 1000000000\n77474447774774747474777447474777777477474444477747444777447444474744744444\n",
"10 200\n6860544593\n",
"100 1000000000\n58493474544... | 2CODEFORCES |
122_D. Lucky Transformation_3348 | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has a number consisting of n digits without leading zeroes. He represented it as an array of d... | n, k = map(int, input().split())
s = list(input())
cnt = 0
for i in range(n - 1):
if cnt == k:
break
if s[i] == '4' and s[i + 1] == '7':
if i & 1:
if s[i - 1] == '4':
if (cnt - k) & 1:
s[i] = '7'
print(''.join(s))
ex... | 3Python3 | {
"input": [
"4 2\n4478\n",
"7 4\n4727447\n",
"7 74\n4777774\n",
"3 99\n447\n",
"47 7\n77774477747474477477477774747747447447774777474\n",
"74 1000000000\n77474447774774747474777447474777777477474444477747444777447444474744744444\n",
"10 200\n6860544593\n",
"100 1000000000\n58493474544... | 2CODEFORCES |
122_D. Lucky Transformation_3349 | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has a number consisting of n digits without leading zeroes. He represented it as an array of d... | /*
Author: @__goku__
ssrivastava990@gmail.com
`\-. `
\ `. `
\ \ |
__.._ | \. S O N - G O K U
..---~~ ~ . | Y
~-. `| |
`. `~~--.
\ ... | 4JAVA | {
"input": [
"4 2\n4478\n",
"7 4\n4727447\n",
"7 74\n4777774\n",
"3 99\n447\n",
"47 7\n77774477747474477477477774747747447447774777474\n",
"74 1000000000\n77474447774774747474777447474777777477474444477747444777447444474744744444\n",
"10 200\n6860544593\n",
"100 1000000000\n58493474544... | 2CODEFORCES |
1251_C. Minimize The Integer_3350 | You are given a huge integer a consisting of n digits (n is between 1 and 3 ⋅ 10^5, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by 2).
For example, if a = 032... | T = int(raw_input())
for _ in range(T):
s = map(int,list(raw_input()))
evens = []
odds = []
for i in s:
if i%2:
evens.append(i)
else:
odds.append(i)
ans = []
ind = 0
ind2 = 0
N = len(evens)
M = len(odds)
while ind < N or ind2 < M:
i... | 1Python2 | {
"input": [
"3\n0709\n1337\n246432\n",
"1\n1003\n",
"1\n890\n",
"3\n477\n1337\n246432\n",
"1\n454\n",
"3\n477\n1216\n246432\n",
"1\n638\n",
"3\n716\n1216\n246432\n",
"1\n540\n",
"3\n716\n1336\n246432\n",
"1\n119\n",
"3\n469\n1336\n246432\n",
"1\n176\n",
"3\n469... | 2CODEFORCES |
1251_C. Minimize The Integer_3351 | You are given a huge integer a consisting of n digits (n is between 1 and 3 ⋅ 10^5, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by 2).
For example, if a = 032... | #include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const long long N = 1e5;
const long long mod = 1e9 + 7;
const long double eps = 1E-7;
long long n, mx, mn = 1e9, cnt, m, ans;
void solve() {
string s;
cin >> s;
string s1, s2;
for (int i = 0; i < s.size(); i++) {
if (s[i] % 2 == 0)
... | 2C++ | {
"input": [
"3\n0709\n1337\n246432\n",
"1\n1003\n",
"1\n890\n",
"3\n477\n1337\n246432\n",
"1\n454\n",
"3\n477\n1216\n246432\n",
"1\n638\n",
"3\n716\n1216\n246432\n",
"1\n540\n",
"3\n716\n1336\n246432\n",
"1\n119\n",
"3\n469\n1336\n246432\n",
"1\n176\n",
"3\n469... | 2CODEFORCES |
1251_C. Minimize The Integer_3352 | You are given a huge integer a consisting of n digits (n is between 1 and 3 ⋅ 10^5, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by 2).
For example, if a = 032... | # -*- coding: utf-8 -*-
"""
Created on Fri Nov 1 14:39:37 2019
@author: uditg
"""
ans={}
test=int(input())
for each in range(test):
num=input()
n=len(num)
num={i:int(num[i]) for i in range(n)}
output={}
even={}
odd={}
even_count=0
odd_count=0
for i in range(n):
if num[i]%2=... | 3Python3 | {
"input": [
"3\n0709\n1337\n246432\n",
"1\n1003\n",
"1\n890\n",
"3\n477\n1337\n246432\n",
"1\n454\n",
"3\n477\n1216\n246432\n",
"1\n638\n",
"3\n716\n1216\n246432\n",
"1\n540\n",
"3\n716\n1336\n246432\n",
"1\n119\n",
"3\n469\n1336\n246432\n",
"1\n176\n",
"3\n469... | 2CODEFORCES |
1251_C. Minimize The Integer_3353 | You are given a huge integer a consisting of n digits (n is between 1 and 3 ⋅ 10^5, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by 2).
For example, if a = 032... | 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.AbstractCollection;
import java.io.Writer;
import java.io.Out... | 4JAVA | {
"input": [
"3\n0709\n1337\n246432\n",
"1\n1003\n",
"1\n890\n",
"3\n477\n1337\n246432\n",
"1\n454\n",
"3\n477\n1216\n246432\n",
"1\n638\n",
"3\n716\n1216\n246432\n",
"1\n540\n",
"3\n716\n1336\n246432\n",
"1\n119\n",
"3\n469\n1336\n246432\n",
"1\n176\n",
"3\n469... | 2CODEFORCES |
1271_A. Suits_3354 | A new delivery of clothing has arrived today to the clothing store. This delivery consists of a ties, b scarves, c vests and d jackets.
The store does not sell single clothing items — instead, it sells suits of two types:
* a suit of the first type consists of one tie and one jacket;
* a suit of the second type ... | a, b, c, d, e, f = input(), input(), input(), input(), input(), input()
nft = min(a, d)
nst = min(b, c, d)
if e >= f:
print nft * e + min(nst, d - nft) * f
else:
print nst * f + min(nft, d - nst) * e | 1Python2 | {
"input": [
"4\n5\n6\n3\n1\n2\n",
"17\n14\n5\n21\n15\n17\n",
"12\n11\n13\n20\n4\n6\n",
"88\n476\n735\n980\n731\n404\n",
"844\n909\n790\n209\n809\n949\n",
"406\n847\n512\n65\n86\n990\n",
"91\n75\n768\n322\n530\n291\n",
"58967\n2953\n35483\n681\n780\n304\n",
"58253\n17658\n9101\n949... | 2CODEFORCES |
1271_A. Suits_3355 | A new delivery of clothing has arrived today to the clothing store. This delivery consists of a ties, b scarves, c vests and d jackets.
The store does not sell single clothing items — instead, it sells suits of two types:
* a suit of the first type consists of one tie and one jacket;
* a suit of the second type ... | #include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
int a, b, c, d, e, f;
int main() {
scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f);
int tmp1 = min(a, d);
int tmp2 = min(b, min(c, d));
int ans = 0;
if (e > f) {
ans += tmp1 * e;
tmp2 = min(tmp2, d - tmp1);
ans += tmp2 * f;
} el... | 2C++ | {
"input": [
"4\n5\n6\n3\n1\n2\n",
"17\n14\n5\n21\n15\n17\n",
"12\n11\n13\n20\n4\n6\n",
"88\n476\n735\n980\n731\n404\n",
"844\n909\n790\n209\n809\n949\n",
"406\n847\n512\n65\n86\n990\n",
"91\n75\n768\n322\n530\n291\n",
"58967\n2953\n35483\n681\n780\n304\n",
"58253\n17658\n9101\n949... | 2CODEFORCES |
1271_A. Suits_3356 | A new delivery of clothing has arrived today to the clothing store. This delivery consists of a ties, b scarves, c vests and d jackets.
The store does not sell single clothing items — instead, it sells suits of two types:
* a suit of the first type consists of one tie and one jacket;
* a suit of the second type ... | a = int(input())
b = int(input())
c = int(input())
d = int(input())
c1 = int(input())
c2 = int(input())
p = 0
if c2 > c1:
m = min(b,c,d)
b -= m
c -= m
d -= m
p += m * c2
if d > 0:
p += (min(a,d) * c1)
else:
m = min(a,d)
a -= m
d -= m
p += m * c1
if d > 0:
p += (min(b,c,... | 3Python3 | {
"input": [
"4\n5\n6\n3\n1\n2\n",
"17\n14\n5\n21\n15\n17\n",
"12\n11\n13\n20\n4\n6\n",
"88\n476\n735\n980\n731\n404\n",
"844\n909\n790\n209\n809\n949\n",
"406\n847\n512\n65\n86\n990\n",
"91\n75\n768\n322\n530\n291\n",
"58967\n2953\n35483\n681\n780\n304\n",
"58253\n17658\n9101\n949... | 2CODEFORCES |
1271_A. Suits_3357 | A new delivery of clothing has arrived today to the clothing store. This delivery consists of a ties, b scarves, c vests and d jackets.
The store does not sell single clothing items — instead, it sells suits of two types:
* a suit of the first type consists of one tie and one jacket;
* a suit of the second type ... | //package com.company;
import java.io.*;
import java.util.*;
import java.lang.*;
public class Main{
public static class FastReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
... | 4JAVA | {
"input": [
"4\n5\n6\n3\n1\n2\n",
"17\n14\n5\n21\n15\n17\n",
"12\n11\n13\n20\n4\n6\n",
"88\n476\n735\n980\n731\n404\n",
"844\n909\n790\n209\n809\n949\n",
"406\n847\n512\n65\n86\n990\n",
"91\n75\n768\n322\n530\n291\n",
"58967\n2953\n35483\n681\n780\n304\n",
"58253\n17658\n9101\n949... | 2CODEFORCES |
1294_B. Collecting Packages_3358 | There is a robot in a warehouse and n packages he wants to collect. The warehouse can be represented as a coordinate grid. Initially, the robot stays at the point (0, 0). The i-th package is at the point (x_i, y_i). It is guaranteed that there are no two packages at the same point. It is also guaranteed that the point ... | import sys
range = xrange
input = raw_input
inp = [int(x) for x in sys.stdin.read().split()]; ii = 0
t = inp[ii]; ii += 1
for _ in range(t):
n = inp[ii]; ii += 1
X = inp[ii + 0: ii + 2 * n: 2]
Y = inp[ii + 1: ii + 2 * n: 2]
ii += 2 * n
order = sorted(range(n), key = lambda i: (X[i], Y[i]))
fo... | 1Python2 | {
"input": [
"3\n5\n1 3\n1 2\n3 3\n5 5\n4 3\n2\n1 0\n0 1\n1\n4 3\n",
"2\n1\n1 1\n1\n1 1\n",
"2\n1\n1 2\n1\n1 1\n",
"2\n1\n1 2\n1\n2 1\n",
"2\n1\n1 2\n1\n1 2\n",
"2\n1\n1 3\n1\n2 1\n",
"2\n1\n1 0\n1\n1 2\n",
"2\n1\n1 3\n1\n1 1\n",
"2\n1\n1 0\n1\n1 1\n",
"2\n1\n0 3\n1\n1 1\n",
... | 2CODEFORCES |
1294_B. Collecting Packages_3359 | There is a robot in a warehouse and n packages he wants to collect. The warehouse can be represented as a coordinate grid. Initially, the robot stays at the point (0, 0). The i-th package is at the point (x_i, y_i). It is guaranteed that there are no two packages at the same point. It is also guaranteed that the point ... | #include <bits/stdc++.h>
using namespace std;
int x, y, z, t, m, n, i, j, k, mn, mx, q, ind, inx;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> t;
while (t--) {
cin >> n;
pair<int, int> a[n + 5];
for (i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
sort(a, a +... | 2C++ | {
"input": [
"3\n5\n1 3\n1 2\n3 3\n5 5\n4 3\n2\n1 0\n0 1\n1\n4 3\n",
"2\n1\n1 1\n1\n1 1\n",
"2\n1\n1 2\n1\n1 1\n",
"2\n1\n1 2\n1\n2 1\n",
"2\n1\n1 2\n1\n1 2\n",
"2\n1\n1 3\n1\n2 1\n",
"2\n1\n1 0\n1\n1 2\n",
"2\n1\n1 3\n1\n1 1\n",
"2\n1\n1 0\n1\n1 1\n",
"2\n1\n0 3\n1\n1 1\n",
... | 2CODEFORCES |
1294_B. Collecting Packages_3360 | There is a robot in a warehouse and n packages he wants to collect. The warehouse can be represented as a coordinate grid. Initially, the robot stays at the point (0, 0). The i-th package is at the point (x_i, y_i). It is guaranteed that there are no two packages at the same point. It is also guaranteed that the point ... | t=int(input())
for q in range(t):
n=int(input())
a=[list(map(int,input().split())) for i in range(n)]
a.sort()
ans=""
x,y=0,0
f=0
for i in range(n):
if a[i][0]>=x and a[i][1]>=y:
ans+='R'*(a[i][0]-x)
x=a[i][0]
ans+='U'*(a[i][1]-y)
y=a[i][1]
else:
f=1
print('NO')
break
if f==0:
print('... | 3Python3 | {
"input": [
"3\n5\n1 3\n1 2\n3 3\n5 5\n4 3\n2\n1 0\n0 1\n1\n4 3\n",
"2\n1\n1 1\n1\n1 1\n",
"2\n1\n1 2\n1\n1 1\n",
"2\n1\n1 2\n1\n2 1\n",
"2\n1\n1 2\n1\n1 2\n",
"2\n1\n1 3\n1\n2 1\n",
"2\n1\n1 0\n1\n1 2\n",
"2\n1\n1 3\n1\n1 1\n",
"2\n1\n1 0\n1\n1 1\n",
"2\n1\n0 3\n1\n1 1\n",
... | 2CODEFORCES |
1294_B. Collecting Packages_3361 | There is a robot in a warehouse and n packages he wants to collect. The warehouse can be represented as a coordinate grid. Initially, the robot stays at the point (0, 0). The i-th package is at the point (x_i, y_i). It is guaranteed that there are no two packages at the same point. It is also guaranteed that the point ... | import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;
public class packages {
public static void main(String[] args) throws IOException {
Scanner scan = new Scanner(System.in);
int cases = scan.nextInt();
for(int i = 0; i < cases; i++) {
int n = scan.nex... | 4JAVA | {
"input": [
"3\n5\n1 3\n1 2\n3 3\n5 5\n4 3\n2\n1 0\n0 1\n1\n4 3\n",
"2\n1\n1 1\n1\n1 1\n",
"2\n1\n1 2\n1\n1 1\n",
"2\n1\n1 2\n1\n2 1\n",
"2\n1\n1 2\n1\n1 2\n",
"2\n1\n1 3\n1\n2 1\n",
"2\n1\n1 0\n1\n1 2\n",
"2\n1\n1 3\n1\n1 1\n",
"2\n1\n1 0\n1\n1 1\n",
"2\n1\n0 3\n1\n1 1\n",
... | 2CODEFORCES |
1315_B. Homecoming_3362 | After a long party Petya decided to return home, but he turned out to be at the opposite end of the town from his home. There are n crossroads in the line in the town, and there is either the bus or the tram station at each crossroad.
The crossroads are represented as a string s of length n, where s_i = A, if there is... | from collections import defaultdict as dd, Counter, OrderedDict as od, deque
from itertools import combinations as comb, permutations as perm
from functools import reduce
from math import log, ceil, floor
from fractions import gcd
import os, sys
#sys.stdin = open("pb.txt", "r")
raw_input = sys.stdin.readline
int_inp... | 1Python2 | {
"input": [
"5\n2 2 1\nBB\n1 1 1\nAB\n3 2 8\nAABBBBAABB\n5 3 4\nBBBBB\n2 1 1\nABABAB\n",
"5\n2 1 1\nBB\n1 1 1\nAB\n3 2 8\nAABBBBAABB\n5 3 4\nBBBBB\n2 1 1\nABABAB\n",
"5\n2 1 1\nBB\n1 1 1\nAB\n3 0 8\nAABBBBAABB\n5 3 4\nBBBBB\n2 1 1\nABABAB\n",
"5\n3 1 0\nBB\n1 1 2\nBA\n3 0 8\nAABBBBAABB\n5 3 4\nBBBBB\... | 2CODEFORCES |
1315_B. Homecoming_3363 | After a long party Petya decided to return home, but he turned out to be at the opposite end of the town from his home. There are n crossroads in the line in the town, and there is either the bus or the tram station at each crossroad.
The crossroads are represented as a string s of length n, where s_i = A, if there is... | #include <bits/stdc++.h>
using namespace std;
const int INF = int(1e9);
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--) {
int a, b, p;
cin >> a >> b >> p;
string s;
cin >> s;
int n = s.size();
int ans = s.size();
long long cost = 0;
for... | 2C++ | {
"input": [
"5\n2 2 1\nBB\n1 1 1\nAB\n3 2 8\nAABBBBAABB\n5 3 4\nBBBBB\n2 1 1\nABABAB\n",
"5\n2 1 1\nBB\n1 1 1\nAB\n3 2 8\nAABBBBAABB\n5 3 4\nBBBBB\n2 1 1\nABABAB\n",
"5\n2 1 1\nBB\n1 1 1\nAB\n3 0 8\nAABBBBAABB\n5 3 4\nBBBBB\n2 1 1\nABABAB\n",
"5\n3 1 0\nBB\n1 1 2\nBA\n3 0 8\nAABBBBAABB\n5 3 4\nBBBBB\... | 2CODEFORCES |
1315_B. Homecoming_3364 | After a long party Petya decided to return home, but he turned out to be at the opposite end of the town from his home. There are n crossroads in the line in the town, and there is either the bus or the tram station at each crossroad.
The crossroads are represented as a string s of length n, where s_i = A, if there is... | t = int(input())
for _ in range(t):
a, b, p = map(int, input().split())
s = input()
d = {'A': a, 'B': b}
i = len(s)-1
prev = len(s)-1
while i >= 0:
i -= 1
curr = s[i]
while s[i] == curr and i >= 0:
i -= 1
i += 1
p -= d[curr]
if p < 0:
... | 3Python3 | {
"input": [
"5\n2 2 1\nBB\n1 1 1\nAB\n3 2 8\nAABBBBAABB\n5 3 4\nBBBBB\n2 1 1\nABABAB\n",
"5\n2 1 1\nBB\n1 1 1\nAB\n3 2 8\nAABBBBAABB\n5 3 4\nBBBBB\n2 1 1\nABABAB\n",
"5\n2 1 1\nBB\n1 1 1\nAB\n3 0 8\nAABBBBAABB\n5 3 4\nBBBBB\n2 1 1\nABABAB\n",
"5\n3 1 0\nBB\n1 1 2\nBA\n3 0 8\nAABBBBAABB\n5 3 4\nBBBBB\... | 2CODEFORCES |
1315_B. Homecoming_3365 | After a long party Petya decided to return home, but he turned out to be at the opposite end of the town from his home. There are n crossroads in the line in the town, and there is either the bus or the tram station at each crossroad.
The crossroads are represented as a string s of length n, where s_i = A, if there is... | import java.util.*;
public class Solution{
public static void main(String args[]){
Scanner in=new Scanner (System.in);
int t=in.nextInt();
T:while(--t>=0){
int a=in.nextInt();
int b=in.nextInt();
int p=in.nextInt();
String s=in.nex... | 4JAVA | {
"input": [
"5\n2 2 1\nBB\n1 1 1\nAB\n3 2 8\nAABBBBAABB\n5 3 4\nBBBBB\n2 1 1\nABABAB\n",
"5\n2 1 1\nBB\n1 1 1\nAB\n3 2 8\nAABBBBAABB\n5 3 4\nBBBBB\n2 1 1\nABABAB\n",
"5\n2 1 1\nBB\n1 1 1\nAB\n3 0 8\nAABBBBAABB\n5 3 4\nBBBBB\n2 1 1\nABABAB\n",
"5\n3 1 0\nBB\n1 1 2\nBA\n3 0 8\nAABBBBAABB\n5 3 4\nBBBBB\... | 2CODEFORCES |
1336_E1. Chiori and Doll Picking (easy version)_3366 | This is the easy version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved.
Chiori loves dolls and now she is going to decorate her bedroom!
<image>
As a doll collector, Chiori has got n dolls. The i-th doll has a non-negati... | #include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC option("arch=native", "tune=native", "no-zero-upper")
#pragma GCC target("avx2")
using namespace std;
template <typename T>
void maxtt(T &t1, T t2) {
t1 = max(t1, t2);
}
template <typename T>
void mintt(... | 2C++ | {
"input": [
"6 7\n11 45 14 9 19 81\n",
"4 4\n3 5 8 14\n",
"30 30\n65536 536870912 2097152 512 32768 16384 8388608 16777216 524288 4194304 1 1048576 2048 262144 64 4096 8192 256 131072 2 268435456 33554432 32 16 134217728 8 67108864 128 4 1024\n",
"6 35\n23601314651 29074846252 10638992479 32779777411... | 2CODEFORCES |
1336_E1. Chiori and Doll Picking (easy version)_3367 | This is the easy version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved.
Chiori loves dolls and now she is going to decorate her bedroom!
<image>
As a doll collector, Chiori has got n dolls. The i-th doll has a non-negati... | import sys
MOD = 998244353
BOUND = 21
n, m = map(int, input().split())
l = list(map(int,input().split()))
basis = []
for p in range(m-1,-1,-1):
p2 = pow(2,p)
nex = -1
for i in range(n):
if l[i] >= p2:
nex = l[i]
break
if nex != -1:
basis.append(nex)
for... | 3Python3 | {
"input": [
"6 7\n11 45 14 9 19 81\n",
"4 4\n3 5 8 14\n",
"30 30\n65536 536870912 2097152 512 32768 16384 8388608 16777216 524288 4194304 1 1048576 2048 262144 64 4096 8192 256 131072 2 268435456 33554432 32 16 134217728 8 67108864 128 4 1024\n",
"6 35\n23601314651 29074846252 10638992479 32779777411... | 2CODEFORCES |
1336_E1. Chiori and Doll Picking (easy version)_3368 | This is the easy version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved.
Chiori loves dolls and now she is going to decorate her bedroom!
<image>
As a doll collector, Chiori has got n dolls. The i-th doll has a non-negati... | import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.Locale;
import java.util.StringTokenizer;
public class Solution implements Runn... | 4JAVA | {
"input": [
"6 7\n11 45 14 9 19 81\n",
"4 4\n3 5 8 14\n",
"30 30\n65536 536870912 2097152 512 32768 16384 8388608 16777216 524288 4194304 1 1048576 2048 262144 64 4096 8192 256 131072 2 268435456 33554432 32 16 134217728 8 67108864 128 4 1024\n",
"6 35\n23601314651 29074846252 10638992479 32779777411... | 2CODEFORCES |
1359_B. New Theatre Square_3369 | You might have remembered Theatre square from the [problem 1A](https://codeforces.com/problemset/problem/1/A). Now it's finally getting repaved.
The square still has a rectangular shape of n × m meters. However, the picture is about to get more complicated now. Let a_{i,j} be the j-th square in the i-th row of the pav... | FAST_IO = 0
if FAST_IO:
import io, sys, atexit
rr = iter(sys.stdin.read().splitlines()).next
sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
@atexit.register
def write():
sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().s... | 1Python2 | {
"input": [
"4\n1 1 10 1\n.\n1 2 10 1\n..\n2 1 10 1\n.\n.\n3 3 3 7\n..*\n*..\n.*.\n",
"1\n3 3 2 4\n**.\n***\n***\n",
"1\n9 9 9 9\n.........\n.........\n.........\n.........\n.........\n.........\n.........\n.........\n.........\n",
"1\n3 3 2 7\n**.\n***\n***\n",
"4\n1 1 10 1\n.\n1 2 10 1\n..\n2 1... | 2CODEFORCES |
1359_B. New Theatre Square_3370 | You might have remembered Theatre square from the [problem 1A](https://codeforces.com/problemset/problem/1/A). Now it's finally getting repaved.
The square still has a rectangular shape of n × m meters. However, the picture is about to get more complicated now. Let a_{i,j} be the j-th square in the i-th row of the pav... | #include <bits/stdc++.h>
using namespace std;
long long i = 0, j = 0, k = 0;
char arr[101][1001];
void solve() {
memset(arr, 0, sizeof(arr));
int n, m, o, t;
cin >> n >> m >> o >> t;
for (int i = 0; i <= n - 1; ++i)
for (int j = 0; j <= m - 1; ++j) cin >> arr[i][j];
vector<string> v;
for (i = 0; i < n; ... | 2C++ | {
"input": [
"4\n1 1 10 1\n.\n1 2 10 1\n..\n2 1 10 1\n.\n.\n3 3 3 7\n..*\n*..\n.*.\n",
"1\n3 3 2 4\n**.\n***\n***\n",
"1\n9 9 9 9\n.........\n.........\n.........\n.........\n.........\n.........\n.........\n.........\n.........\n",
"1\n3 3 2 7\n**.\n***\n***\n",
"4\n1 1 10 1\n.\n1 2 10 1\n..\n2 1... | 2CODEFORCES |
1359_B. New Theatre Square_3371 | You might have remembered Theatre square from the [problem 1A](https://codeforces.com/problemset/problem/1/A). Now it's finally getting repaved.
The square still has a rectangular shape of n × m meters. However, the picture is about to get more complicated now. Let a_{i,j} be the j-th square in the i-th row of the pav... | cases=input()
for i in range(0,int(cases)):
inss=input()
list=inss.split(' ')
n=int(list[0])
m=int(list[1])
x=int(list[2])
y=int(list[3])
price=0
if 2*x > y:
lame=True
else:
lame=False
for count in range(0,n):
data=input()
###print(data)
... | 3Python3 | {
"input": [
"4\n1 1 10 1\n.\n1 2 10 1\n..\n2 1 10 1\n.\n.\n3 3 3 7\n..*\n*..\n.*.\n",
"1\n3 3 2 4\n**.\n***\n***\n",
"1\n9 9 9 9\n.........\n.........\n.........\n.........\n.........\n.........\n.........\n.........\n.........\n",
"1\n3 3 2 7\n**.\n***\n***\n",
"4\n1 1 10 1\n.\n1 2 10 1\n..\n2 1... | 2CODEFORCES |
1359_B. New Theatre Square_3372 | You might have remembered Theatre square from the [problem 1A](https://codeforces.com/problemset/problem/1/A). Now it's finally getting repaved.
The square still has a rectangular shape of n × m meters. However, the picture is about to get more complicated now. Let a_{i,j} be the j-th square in the i-th row of the pav... | import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt(),m=sc.nextInt(),x=sc.nextInt(),y=sc.nextInt();
int cnt2=0,cnt1=0;
String[] s=new String[n... | 4JAVA | {
"input": [
"4\n1 1 10 1\n.\n1 2 10 1\n..\n2 1 10 1\n.\n.\n3 3 3 7\n..*\n*..\n.*.\n",
"1\n3 3 2 4\n**.\n***\n***\n",
"1\n9 9 9 9\n.........\n.........\n.........\n.........\n.........\n.........\n.........\n.........\n.........\n",
"1\n3 3 2 7\n**.\n***\n***\n",
"4\n1 1 10 1\n.\n1 2 10 1\n..\n2 1... | 2CODEFORCES |
1379_D. New Passenger Trams_3373 | There are many freight trains departing from Kirnes planet every day. One day on that planet consists of h hours, and each hour consists of m minutes, where m is an even number. Currently, there are n freight trains, and they depart every day at the same time: i-th train departs at h_i hours and m_i minutes.
The gover... | #include <bits/stdc++.h>
using namespace std;
struct node {
int x, t, id;
} a[200002];
int n, h, m, k, i, j;
int read() {
char c = getchar();
int w = 0;
while (c < '0' || c > '9') c = getchar();
while (c <= '9' && c >= '0') {
w = w * 10 + c - '0';
c = getchar();
}
return w;
}
int cmp1(const node &... | 2C++ | {
"input": [
"2 24 60 16\n16 0\n17 15\n",
"2 24 60 15\n16 0\n17 15\n",
"9 3 24 9\n1 15\n0 6\n0 22\n2 22\n2 7\n1 7\n1 23\n2 14\n0 14\n",
"10 11 12 6\n9 5\n8 5\n9 11\n7 5\n10 5\n1 5\n2 11\n3 5\n2 5\n3 11\n",
"10 24 60 8\n10 59\n21 56\n0 42\n21 27\n5 24\n5 53\n16 5\n5 22\n10 11\n10 46\n",
"9 24 6... | 2CODEFORCES |
1379_D. New Passenger Trams_3374 | There are many freight trains departing from Kirnes planet every day. One day on that planet consists of h hours, and each hour consists of m minutes, where m is an even number. Currently, there are n freight trains, and they depart every day at the same time: i-th train departs at h_i hours and m_i minutes.
The gover... | from collections import defaultdict
import sys
input=sys.stdin.readline
n,h,m,k=map(int,input().split())
l=[]
a=[]
start=0
for i in range(n):
H,M=map(int,input().split())
M=M%(m//2)
a.append(M)
l.append((M+1,1,i))
l.append(((M+k)%(m//2),-1,i))
if (M+1)>(M+k)%(m//2):
start+=1
l.append((0,... | 3Python3 | {
"input": [
"2 24 60 16\n16 0\n17 15\n",
"2 24 60 15\n16 0\n17 15\n",
"9 3 24 9\n1 15\n0 6\n0 22\n2 22\n2 7\n1 7\n1 23\n2 14\n0 14\n",
"10 11 12 6\n9 5\n8 5\n9 11\n7 5\n10 5\n1 5\n2 11\n3 5\n2 5\n3 11\n",
"10 24 60 8\n10 59\n21 56\n0 42\n21 27\n5 24\n5 53\n16 5\n5 22\n10 11\n10 46\n",
"9 24 6... | 2CODEFORCES |
1379_D. New Passenger Trams_3375 | There are many freight trains departing from Kirnes planet every day. One day on that planet consists of h hours, and each hour consists of m minutes, where m is an even number. Currently, there are n freight trains, and they depart every day at the same time: i-th train departs at h_i hours and m_i minutes.
The gover... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Main
{
public static void main(String[] args) {
new Thread(null, new Runnable() {
public void run() {
solve();
}
... | 4JAVA | {
"input": [
"2 24 60 16\n16 0\n17 15\n",
"2 24 60 15\n16 0\n17 15\n",
"9 3 24 9\n1 15\n0 6\n0 22\n2 22\n2 7\n1 7\n1 23\n2 14\n0 14\n",
"10 11 12 6\n9 5\n8 5\n9 11\n7 5\n10 5\n1 5\n2 11\n3 5\n2 5\n3 11\n",
"10 24 60 8\n10 59\n21 56\n0 42\n21 27\n5 24\n5 53\n16 5\n5 22\n10 11\n10 46\n",
"9 24 6... | 2CODEFORCES |
139_B. Wallpaper_3376 | Having bought his own apartment, Boris decided to paper the walls in every room. Boris's flat has n rooms, each of which has the form of a rectangular parallelepiped. For every room we known its length, width and height of the walls in meters (different rooms can have different dimensions, including height).
Boris cho... | n = int(raw_input())
room = []
for i in range(n):
room.append(map(int, raw_input().split()))
w = int(raw_input())
wall = []
for i in range(w):
wall.append(map(int, raw_input().split()))
#print room
#print wall
results = 0
for i in range(n):
temp = []
for j in range(w):
if wall[j][0] >= room[i][2]:
p = (room[i]... | 1Python2 | {
"input": [
"1\n5 5 3\n3\n10 1 100\n15 2 320\n3 19 500\n",
"1\n9 10 7\n1\n7 1 3\n",
"20\n110 466 472\n112 153 152\n424 492 490\n348 366 113\n208 337 415\n491 448 139\n287 457 403\n444 382 160\n325 486 284\n447 454 136\n216 412 418\n217 208 228\n109 436 291\n293 382 421\n483 339 174\n213 327 183\n278 268 ... | 2CODEFORCES |
139_B. Wallpaper_3377 | Having bought his own apartment, Boris decided to paper the walls in every room. Boris's flat has n rooms, each of which has the form of a rectangular parallelepiped. For every room we known its length, width and height of the walls in meters (different rooms can have different dimensions, including height).
Boris cho... | #include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
const long double pi = acos(-1.0);
int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }
int xabs(int a) { return a > 0 ? a : -a; }
int getCost(int l, int w, int h, int rl, int rw, int cost) {
int cnt = 1;
int p = 2 * (l + w);
in... | 2C++ | {
"input": [
"1\n5 5 3\n3\n10 1 100\n15 2 320\n3 19 500\n",
"1\n9 10 7\n1\n7 1 3\n",
"20\n110 466 472\n112 153 152\n424 492 490\n348 366 113\n208 337 415\n491 448 139\n287 457 403\n444 382 160\n325 486 284\n447 454 136\n216 412 418\n217 208 228\n109 436 291\n293 382 421\n483 339 174\n213 327 183\n278 268 ... | 2CODEFORCES |
139_B. Wallpaper_3378 | Having bought his own apartment, Boris decided to paper the walls in every room. Boris's flat has n rooms, each of which has the form of a rectangular parallelepiped. For every room we known its length, width and height of the walls in meters (different rooms can have different dimensions, including height).
Boris cho... | #------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
... | 3Python3 | {
"input": [
"1\n5 5 3\n3\n10 1 100\n15 2 320\n3 19 500\n",
"1\n9 10 7\n1\n7 1 3\n",
"20\n110 466 472\n112 153 152\n424 492 490\n348 366 113\n208 337 415\n491 448 139\n287 457 403\n444 382 160\n325 486 284\n447 454 136\n216 412 418\n217 208 228\n109 436 291\n293 382 421\n483 339 174\n213 327 183\n278 268 ... | 2CODEFORCES |
139_B. Wallpaper_3379 | Having bought his own apartment, Boris decided to paper the walls in every room. Boris's flat has n rooms, each of which has the form of a rectangular parallelepiped. For every room we known its length, width and height of the walls in meters (different rooms can have different dimensions, including height).
Boris cho... | import java.io.*;
import java.util.*;
import java.math.*;
public class b {
String _token() throws IOException {
while (in.ready() && !st.hasMoreTokens()) {
st = new StringTokenizer(in.readLine());
}
if (st.hasMoreTokens())
return st.nextToken();
return "";
... | 4JAVA | {
"input": [
"1\n5 5 3\n3\n10 1 100\n15 2 320\n3 19 500\n",
"1\n9 10 7\n1\n7 1 3\n",
"20\n110 466 472\n112 153 152\n424 492 490\n348 366 113\n208 337 415\n491 448 139\n287 457 403\n444 382 160\n325 486 284\n447 454 136\n216 412 418\n217 208 228\n109 436 291\n293 382 421\n483 339 174\n213 327 183\n278 268 ... | 2CODEFORCES |
1423_F. Coins_3380 | A famous gang of pirates, Sea Dogs, has come back to their hideout from one of their extravagant plunders. They want to split their treasure fairly amongst themselves, that is why You, their trusted financial advisor, devised a game to help them:
All of them take a sit at their round table, some of them with the golde... | #include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
long long n, k;
cin >> n >> k;
long long tot = 0;
long long sumPos = 0;
for (int _ = 0; _ < (k); ++_) {
long long pos, num;
cin >> pos >> num;
pos--;
sumPos += pos * num;... | 2C++ | {
"input": [
"4 2\n1 2\n2 2\n",
"3 2\n1 1\n2 2\n",
"6 2\n2 3\n4 1\n",
"25 2\n1 23\n3 1\n",
"178279081 0\n",
"999999999 1\n100 1000000000\n",
"1 1\n1 1\n",
"1001 1\n60 10001\n",
"10 4\n4 1\n6 5\n7 1\n8 3\n",
"999999999 1\n999999999 999999999\n",
"1000 1\n1 1000\n",
"1000... | 2CODEFORCES |
1423_F. Coins_3381 | A famous gang of pirates, Sea Dogs, has come back to their hideout from one of their extravagant plunders. They want to split their treasure fairly amongst themselves, that is why You, their trusted financial advisor, devised a game to help them:
All of them take a sit at their round table, some of them with the golde... | import os
import sys
from io import BytesIO, IOBase
# region fastio
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... | 3Python3 | {
"input": [
"4 2\n1 2\n2 2\n",
"3 2\n1 1\n2 2\n",
"6 2\n2 3\n4 1\n",
"25 2\n1 23\n3 1\n",
"178279081 0\n",
"999999999 1\n100 1000000000\n",
"1 1\n1 1\n",
"1001 1\n60 10001\n",
"10 4\n4 1\n6 5\n7 1\n8 3\n",
"999999999 1\n999999999 999999999\n",
"1000 1\n1 1000\n",
"1000... | 2CODEFORCES |
1423_F. Coins_3382 | A famous gang of pirates, Sea Dogs, has come back to their hideout from one of their extravagant plunders. They want to split their treasure fairly amongst themselves, that is why You, their trusted financial advisor, devised a game to help them:
All of them take a sit at their round table, some of them with the golde... | //JDope
import java.util.*;
import java.io.*;
import java.math.*;
public class F{
public static void main(String[] omkar) throws Exception
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(in.readLine());
StringBuilder sb = new StringBuilder();... | 4JAVA | {
"input": [
"4 2\n1 2\n2 2\n",
"3 2\n1 1\n2 2\n",
"6 2\n2 3\n4 1\n",
"25 2\n1 23\n3 1\n",
"178279081 0\n",
"999999999 1\n100 1000000000\n",
"1 1\n1 1\n",
"1001 1\n60 10001\n",
"10 4\n4 1\n6 5\n7 1\n8 3\n",
"999999999 1\n999999999 999999999\n",
"1000 1\n1 1000\n",
"1000... | 2CODEFORCES |
1442_E. Black, White and Grey Tree_3383 | You are given a tree with each vertex coloured white, black or grey. You can remove elements from the tree by selecting a subset of vertices in a single connected component and removing them and their adjacent edges from the graph. The only restriction is that you are not allowed to select a subset containing a white a... | #include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
bool mini(T1 &a, T2 b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T1, typename T2>
bool maxi(T1 &a, T2 b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const int N = 2e5 + 5;... | 2C++ | {
"input": [
"4\n2\n1 1\n1 2\n4\n1 2 1 2\n1 2\n2 3\n3 4\n5\n1 1 0 1 2\n1 2\n2 3\n3 4\n3 5\n8\n1 2 1 2 2 2 1 2\n1 3\n2 3\n3 4\n4 5\n5 6\n5 7\n5 8\n",
"1\n2\n0 0\n1 2\n",
"1\n3\n0 1 1\n1 3\n3 2\n",
"1\n8\n0 2 0 2 0 1 2 2\n8 4\n7 4\n2 7\n5 1\n7 1\n8 6\n8 3\n",
"1\n1\n2\n",
"1\n2\n0 1\n1 2\n",
... | 2CODEFORCES |
1442_E. Black, White and Grey Tree_3384 | You are given a tree with each vertex coloured white, black or grey. You can remove elements from the tree by selecting a subset of vertices in a single connected component and removing them and their adjacent edges from the graph. The only restriction is that you are not allowed to select a subset containing a white a... | //package round681;
import java.io.*;
import java.util.*;
public class E2 {
InputStream is;
FastWriter out;
String INPUT = "";
void solve()
{
for(int T = ni();T > 0;T--)go();
}
void go()
{
int n = ni();
int[] a = na(n);
int[] from = new int[n - 1];
int[] to = new int[n - 1];
for (int i = 0; i < n... | 4JAVA | {
"input": [
"4\n2\n1 1\n1 2\n4\n1 2 1 2\n1 2\n2 3\n3 4\n5\n1 1 0 1 2\n1 2\n2 3\n3 4\n3 5\n8\n1 2 1 2 2 2 1 2\n1 3\n2 3\n3 4\n4 5\n5 6\n5 7\n5 8\n",
"1\n2\n0 0\n1 2\n",
"1\n3\n0 1 1\n1 3\n3 2\n",
"1\n8\n0 2 0 2 0 1 2 2\n8 4\n7 4\n2 7\n5 1\n7 1\n8 6\n8 3\n",
"1\n1\n2\n",
"1\n2\n0 1\n1 2\n",
... | 2CODEFORCES |
1468_G. Hobbits_3385 | The hobbits Frodo and Sam are carrying the One Ring to Mordor. In order not to be spotted by orcs, they decided to go through the mountains.
The mountain relief can be represented as a polyline with n points (x_i, y_i), numbered from 1 to n (x_i < x_{i + 1} for 1 ≤ i ≤ n - 1). Hobbits start their journey at the point ... | from __future__ import division, print_function
from itertools import permutations
import threading,bisect,math,heapq,sys
from collections import deque
# threading.stack_size(2**27)
# sys.setrecursionlimit(10**4)
from sys import stdin, stdout
i_m=9223372036854775807
def cin():
return map(int,sin().split())
def... | 1Python2 | {
"input": [
"6 10\n10 40\n20 10\n25 30\n30 15\n50 15\n65 30\n",
"2 10000\n0 10000\n400000 0\n",
"9 5\n0 0\n5 10\n15 10\n20 0\n25 11\n30 0\n35 10\n50 10\n60 5\n",
"4 6\n0 0\n2 4\n7 5\n10 0\n",
"5 2\n1 3\n4 4\n5 7\n7 5\n10 4\n",
"5 2\n1 3\n4 4\n5 1\n7 5\n10 4\n",
"4 6\n0 0\n4 4\n7 5\n10 0\n... | 2CODEFORCES |
1468_G. Hobbits_3386 | The hobbits Frodo and Sam are carrying the One Ring to Mordor. In order not to be spotted by orcs, they decided to go through the mountains.
The mountain relief can be represented as a polyline with n points (x_i, y_i), numbered from 1 to n (x_i < x_{i + 1} for 1 ≤ i ≤ n - 1). Hobbits start their journey at the point ... | #include<bits/stdc++.h>
using namespace std;
#define debug printf("%d %s\n",__LINE__,__FUNCTION__);fflush(stdout)
using ll=long long;using i64=long long;using db=double;
using u32=unsigned int;using u64=unsigned long long;using db=double;
using pii=pair<db,db>;using vi=vector<int>;
using qi=queue<int>;using pqi=priorit... | 2C++ | {
"input": [
"6 10\n10 40\n20 10\n25 30\n30 15\n50 15\n65 30\n",
"2 10000\n0 10000\n400000 0\n",
"9 5\n0 0\n5 10\n15 10\n20 0\n25 11\n30 0\n35 10\n50 10\n60 5\n",
"4 6\n0 0\n2 4\n7 5\n10 0\n",
"5 2\n1 3\n4 4\n5 7\n7 5\n10 4\n",
"5 2\n1 3\n4 4\n5 1\n7 5\n10 4\n",
"4 6\n0 0\n4 4\n7 5\n10 0\n... | 2CODEFORCES |
1468_G. Hobbits_3387 | The hobbits Frodo and Sam are carrying the One Ring to Mordor. In order not to be spotted by orcs, they decided to go through the mountains.
The mountain relief can be represented as a polyline with n points (x_i, y_i), numbered from 1 to n (x_i < x_{i + 1} for 1 ≤ i ≤ n - 1). Hobbits start their journey at the point ... | import sys
input = sys.stdin.readline
n, H = map(int, input().split());points = [tuple(map(int, input().split())) for _ in range(n)];eye = (points[-1][0], points[-1][1] + H);peak = points[-1];out = 0
def dot(a,b): return a[0] * b[0] + a[1] * b[1]
def sub(a,b): return (a[0] - b[0], a[1] - b[1])
def norm(a): ret... | 3Python3 | {
"input": [
"6 10\n10 40\n20 10\n25 30\n30 15\n50 15\n65 30\n",
"2 10000\n0 10000\n400000 0\n",
"9 5\n0 0\n5 10\n15 10\n20 0\n25 11\n30 0\n35 10\n50 10\n60 5\n",
"4 6\n0 0\n2 4\n7 5\n10 0\n",
"5 2\n1 3\n4 4\n5 7\n7 5\n10 4\n",
"5 2\n1 3\n4 4\n5 1\n7 5\n10 4\n",
"4 6\n0 0\n4 4\n7 5\n10 0\n... | 2CODEFORCES |
1468_G. Hobbits_3388 | The hobbits Frodo and Sam are carrying the One Ring to Mordor. In order not to be spotted by orcs, they decided to go through the mountains.
The mountain relief can be represented as a polyline with n points (x_i, y_i), numbered from 1 to n (x_i < x_{i + 1} for 1 ≤ i ≤ n - 1). Hobbits start their journey at the point ... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Sparsh Sanchorawala
*/
pub... | 4JAVA | {
"input": [
"6 10\n10 40\n20 10\n25 30\n30 15\n50 15\n65 30\n",
"2 10000\n0 10000\n400000 0\n",
"9 5\n0 0\n5 10\n15 10\n20 0\n25 11\n30 0\n35 10\n50 10\n60 5\n",
"4 6\n0 0\n2 4\n7 5\n10 0\n",
"5 2\n1 3\n4 4\n5 7\n7 5\n10 4\n",
"5 2\n1 3\n4 4\n5 1\n7 5\n10 4\n",
"4 6\n0 0\n4 4\n7 5\n10 0\n... | 2CODEFORCES |
1493_A. Anti-knapsack_3389 | You are given two integers n and k. You are asked to choose maximum number of distinct integers from 1 to n so that there is no subset of chosen numbers with sum equal to k.
A subset of a set is a set that can be obtained from initial one by removing some (possibly all or none) elements of it.
Input
The first line c... |
for _ in range(input()):
n,k=map(int,raw_input().split())
l=[]
if k%2==0:
mid=k/2
else:
mid=(k+1)/2
while mid<=n:
if mid!=k:
l.append(mid)
mid+=1
if len(l)==0:
print 0
else:
print len(l)
for i in l:
print i,
... | 1Python2 | {
"input": [
"3\n3 2\n5 3\n1 1\n",
"70\n1 1\n2 1\n2 2\n3 1\n3 2\n3 3\n4 1\n4 2\n4 3\n4 4\n5 1\n5 2\n5 3\n5 4\n5 5\n6 1\n6 2\n6 3\n6 4\n6 5\n6 6\n7 1\n7 2\n7 3\n7 4\n7 5\n7 6\n7 7\n8 1\n8 2\n8 3\n8 4\n8 5\n8 6\n8 7\n8 8\n9 1\n9 2\n9 3\n9 4\n9 5\n9 6\n9 7\n9 8\n9 9\n10 1\n10 2\n10 3\n10 4\n10 5\n10 6\n10 7\n10 ... | 2CODEFORCES |
1493_A. Anti-knapsack_3390 | You are given two integers n and k. You are asked to choose maximum number of distinct integers from 1 to n so that there is no subset of chosen numbers with sum equal to k.
A subset of a set is a set that can be obtained from initial one by removing some (possibly all or none) elements of it.
Input
The first line c... | ///Fix the cause, not the symptom.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db double
#define sf scanf
#define pf printf
#define pb push_back
#define pi acos(-1)
#define MOD 100... | 2C++ | {
"input": [
"3\n3 2\n5 3\n1 1\n",
"70\n1 1\n2 1\n2 2\n3 1\n3 2\n3 3\n4 1\n4 2\n4 3\n4 4\n5 1\n5 2\n5 3\n5 4\n5 5\n6 1\n6 2\n6 3\n6 4\n6 5\n6 6\n7 1\n7 2\n7 3\n7 4\n7 5\n7 6\n7 7\n8 1\n8 2\n8 3\n8 4\n8 5\n8 6\n8 7\n8 8\n9 1\n9 2\n9 3\n9 4\n9 5\n9 6\n9 7\n9 8\n9 9\n10 1\n10 2\n10 3\n10 4\n10 5\n10 6\n10 7\n10 ... | 2CODEFORCES |
1493_A. Anti-knapsack_3391 | You are given two integers n and k. You are asked to choose maximum number of distinct integers from 1 to n so that there is no subset of chosen numbers with sum equal to k.
A subset of a set is a set that can be obtained from initial one by removing some (possibly all or none) elements of it.
Input
The first line c... | t=int(input())
for i in range(t):
n,k = map(int,input().split())
ans=[]
if n==1 and k==1:
print(0)
continue
else:
if k%2==0:
for j in range(k//2,k):
ans.append(j)
for j in range(k+1,n+1):
ans.append(j)
else:
for j in range(k//2+1,k):
ans.append(j)
for j in range(k+1,n+1):
ans.a... | 3Python3 | {
"input": [
"3\n3 2\n5 3\n1 1\n",
"70\n1 1\n2 1\n2 2\n3 1\n3 2\n3 3\n4 1\n4 2\n4 3\n4 4\n5 1\n5 2\n5 3\n5 4\n5 5\n6 1\n6 2\n6 3\n6 4\n6 5\n6 6\n7 1\n7 2\n7 3\n7 4\n7 5\n7 6\n7 7\n8 1\n8 2\n8 3\n8 4\n8 5\n8 6\n8 7\n8 8\n9 1\n9 2\n9 3\n9 4\n9 5\n9 6\n9 7\n9 8\n9 9\n10 1\n10 2\n10 3\n10 4\n10 5\n10 6\n10 7\n10 ... | 2CODEFORCES |
1493_A. Anti-knapsack_3392 | You are given two integers n and k. You are asked to choose maximum number of distinct integers from 1 to n so that there is no subset of chosen numbers with sum equal to k.
A subset of a set is a set that can be obtained from initial one by removing some (possibly all or none) elements of it.
Input
The first line c... | import java.util.Scanner;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
long t=sc.nextLong();
while(t--!=0) {
long n=sc.nextLong();
long k=sc.nextLong();
long x=k... | 4JAVA | {
"input": [
"3\n3 2\n5 3\n1 1\n",
"70\n1 1\n2 1\n2 2\n3 1\n3 2\n3 3\n4 1\n4 2\n4 3\n4 4\n5 1\n5 2\n5 3\n5 4\n5 5\n6 1\n6 2\n6 3\n6 4\n6 5\n6 6\n7 1\n7 2\n7 3\n7 4\n7 5\n7 6\n7 7\n8 1\n8 2\n8 3\n8 4\n8 5\n8 6\n8 7\n8 8\n9 1\n9 2\n9 3\n9 4\n9 5\n9 6\n9 7\n9 8\n9 9\n10 1\n10 2\n10 3\n10 4\n10 5\n10 6\n10 7\n10 ... | 2CODEFORCES |
1515_G. Phoenix and Odometers_3393 | In Fire City, there are n intersections and m one-way roads. The i-th road goes from intersection a_i to b_i and has length l_i miles.
There are q cars that may only drive along those roads. The i-th car starts at intersection v_i and has an odometer that begins at s_i, increments for each mile driven, and resets to ... | using namespace std;
#define visual
#ifdef visual
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <assert.h>
#include <functional>
#include <math.h>
#include <string>
#include <ctime>
#endif
#ifndef visual
#include <bits/stdc++.h>
#... | 2C++ | {
"input": [
"4 5\n1 2 1\n2 3 1\n3 1 2\n1 4 1\n4 3 2\n2\n1 2 4\n4 3 5\n",
"4 4\n1 2 1\n2 3 1\n3 1 2\n1 4 3\n3\n1 1 3\n1 2 4\n4 0 1\n",
"2 1\n2 1 1\n1\n2 1 2\n",
"4 5\n1 2 1\n2 3 1\n3 1 2\n1 4 1\n4 3 2\n2\n1 2 4\n3 3 5\n",
"3 1\n2 1 1\n1\n2 1 2\n",
"3 1\n2 1 1\n1\n2 0 2\n",
"4 4\n1 2 1\n2 3... | 2CODEFORCES |
1515_G. Phoenix and Odometers_3394 | In Fire City, there are n intersections and m one-way roads. The i-th road goes from intersection a_i to b_i and has length l_i miles.
There are q cars that may only drive along those roads. The i-th car starts at intersection v_i and has an odometer that begins at s_i, increments for each mile driven, and resets to ... | import sys
from sys import stdin
import math
from collections import deque
import sys
class scc_graph:
def __init__(self, N):
self.N = N
self.edges = []
def csr(self):
self.start = [0]*(self.N+1)
self.elist = [0]*len(self.edges)
for e in self.edges:
sel... | 3Python3 | {
"input": [
"4 5\n1 2 1\n2 3 1\n3 1 2\n1 4 1\n4 3 2\n2\n1 2 4\n4 3 5\n",
"4 4\n1 2 1\n2 3 1\n3 1 2\n1 4 3\n3\n1 1 3\n1 2 4\n4 0 1\n",
"2 1\n2 1 1\n1\n2 1 2\n",
"4 5\n1 2 1\n2 3 1\n3 1 2\n1 4 1\n4 3 2\n2\n1 2 4\n3 3 5\n",
"3 1\n2 1 1\n1\n2 1 2\n",
"3 1\n2 1 1\n1\n2 0 2\n",
"4 4\n1 2 1\n2 3... | 2CODEFORCES |
1515_G. Phoenix and Odometers_3395 | In Fire City, there are n intersections and m one-way roads. The i-th road goes from intersection a_i to b_i and has length l_i miles.
There are q cars that may only drive along those roads. The i-th car starts at intersection v_i and has an odometer that begins at s_i, increments for each mile driven, and resets to ... |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.StringTokenizer;
public final class G {
private static long gcd(long a, long b) {
return b ==... | 4JAVA | {
"input": [
"4 5\n1 2 1\n2 3 1\n3 1 2\n1 4 1\n4 3 2\n2\n1 2 4\n4 3 5\n",
"4 4\n1 2 1\n2 3 1\n3 1 2\n1 4 3\n3\n1 1 3\n1 2 4\n4 0 1\n",
"2 1\n2 1 1\n1\n2 1 2\n",
"4 5\n1 2 1\n2 3 1\n3 1 2\n1 4 1\n4 3 2\n2\n1 2 4\n3 3 5\n",
"3 1\n2 1 1\n1\n2 1 2\n",
"3 1\n2 1 1\n1\n2 0 2\n",
"4 4\n1 2 1\n2 3... | 2CODEFORCES |
1542_E2. Abnormal Permutation Pairs (hard version)_3396 | This is the hard version of the problem. The only difference between the easy version and the hard version is the constraints on n. You can only make hacks if both versions are solved.
A permutation of 1, 2, …, n is a sequence of n integers, where each integer from 1 to n appears exactly once. For example, [2,3,1,4] i... | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
#define alpha ios::sync_with_stdio(0); cin.tie(0);
const int B = 130000;
int w[2][2*B+5], ... | 2C++ | {
"input": [
"4 403458273\n",
"7 941492387\n",
"105 281546644\n",
"4 1\n",
"8 824608515\n",
"195 741424885\n",
"5 585325539\n",
"125 872744873\n",
"284 341291190\n",
"275 723775499\n",
"18 341796022\n",
"233 330436384\n",
"2 1\n",
"6 58376259\n",
"9 2691939\... | 2CODEFORCES |
1542_E2. Abnormal Permutation Pairs (hard version)_3397 | This is the hard version of the problem. The only difference between the easy version and the hard version is the constraints on n. You can only make hacks if both versions are solved.
A permutation of 1, 2, …, n is a sequence of n integers, where each integer from 1 to n appears exactly once. For example, [2,3,1,4] i... | //package round729;
import java.io.*;
import java.util.*;
public class E1 {
InputStream is;
FastWriter out;
String INPUT = "";
void solve()
{
int n = ni(), mod = ni();
long ans = 0;
long[] dp = new long[n*(n-1)/2+1];
dp[0] = 1 % mod;
long S = 0;
for(int i = 1;i <= n-1;){
long[] pre = new long[i*... | 4JAVA | {
"input": [
"4 403458273\n",
"7 941492387\n",
"105 281546644\n",
"4 1\n",
"8 824608515\n",
"195 741424885\n",
"5 585325539\n",
"125 872744873\n",
"284 341291190\n",
"275 723775499\n",
"18 341796022\n",
"233 330436384\n",
"2 1\n",
"6 58376259\n",
"9 2691939\... | 2CODEFORCES |
171_A. Mysterious numbers - 1_3398 |
Input
The input contains two integers a1, a2 (0 ≤ ai ≤ 109), separated by a single space.
Output
Output a single integer.
Examples
Input
3 14
Output
44
Input
27 12
Output
48
Input
100 200
Output
102 | import sys
import copy
from collections import Counter
sys.setrecursionlimit(11111)
import re
import itertools
a,b = sys.stdin.readline().strip().split()
print int(a) + int(b[::-1]) | 1Python2 | {
"input": [
"27 12\n",
"3 14\n",
"100 200\n",
"59961393 89018456\n",
"937477084 827336327\n",
"0 0\n",
"957747793 424238335\n",
"859484421 914544919\n",
"365180540 540383426\n",
"35005211 521595368\n",
"369133069 125898167\n",
"911759956 749241873\n",
"336465782 86... | 2CODEFORCES |
171_A. Mysterious numbers - 1_3399 |
Input
The input contains two integers a1, a2 (0 ≤ ai ≤ 109), separated by a single space.
Output
Output a single integer.
Examples
Input
3 14
Output
44
Input
27 12
Output
48
Input
100 200
Output
102 | #include <bits/stdc++.h>
int a, b, c = 0;
int main() {
scanf("%d%d", &a, &b);
while (b) {
c = c * 10 + b % 10;
b /= 10;
}
printf("%d\n", a + c);
}
| 2C++ | {
"input": [
"27 12\n",
"3 14\n",
"100 200\n",
"59961393 89018456\n",
"937477084 827336327\n",
"0 0\n",
"957747793 424238335\n",
"859484421 914544919\n",
"365180540 540383426\n",
"35005211 521595368\n",
"369133069 125898167\n",
"911759956 749241873\n",
"336465782 86... | 2CODEFORCES |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.