id stringlengths 11 112 | content stringlengths 42 13k | test listlengths 0 565 | labels dict | canonical_solution dict |
|---|---|---|---|---|
AIZU/p00831 | # Confusing Login Names
Meikyokan University is very famous for its research and education in the area of computer science. This university has a computer center that has advanced and secure computing facilities including supercomputers and many personal computers connected to the Internet.
One of the policies of the... | [
{
"input": {
"stdin": "8\n2\nomura\ntoshio\nraku\ntanaka\nimura\nyoshoi\nhayashi\nmiura\n3\n1\ntasaka\nnakata\ntanaka\n1\n1\nfoo\n5\n2\npsqt\nabcdef\nabzdefa\npqrst\nabdxcef\n0"
},
"output": {
"stdout": "imura,miura\nimura,omura\nmiura,omura\ntoshio,yoshoi\n4\ntanaka,tasaka\n1\n0\nabcdef,abd... | {
"tags": [],
"title": "Confusing Login Names"
} | {
"cpp": "#include<iostream>\n#include<vector>\n#include<iomanip>\n#include<string>\n#include<algorithm>\nusing namespace std;\n#define int long long\n#define loop(i,a,b) for(int i=a;i<b;i++)\n#define rep(i,a) loop(i,0,a)\n#define shosu(x) fixed<<setprecision(x)\n#define all(in) in.begin(),in.end()\ntypedef vector<in... |
AIZU/p00962 | # Pizza Delivery
Problem F Pizza Delivery
Alyssa is a college student, living in New Tsukuba City. All the streets in the city are one-way. A new social experiment starting tomorrow is on alternative traffic regulation reversing the one-way directions of street sections. Reversals will be on one single street section... | [
{
"input": {
"stdin": "4 5\n1 3 5\n3 4 6\n4 2 7\n2 1 18\n2 3 12"
},
"output": {
"stdout": "SAD\nSAD\nSAD\nSOSO\nHAPPY"
}
},
{
"input": {
"stdin": "7 1\n1 3 1\n3 7 3\n4 3 14\n0 1 10\n2 6 13"
},
"output": {
"stdout": "SOSO\n"
}
},
{
"input": {
... | {
"tags": [],
"title": "Pizza Delivery"
} | {
"cpp": "#include <bits/stdc++.h>\n#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME\n#define pr(...) cout<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl\n#define pr1(a) (#a)<<\"=\"<<(a)<<\" \"\n#define pr2(a,b) pr1(a)<<pr1(b)\n#define pr3(a,b,c) pr1(a)<<pr2(b,c)\n#define pr4(a,b... |
AIZU/p01095 | # Bamboo Blossoms
Bamboo Blossoms
The bamboos live for decades, and at the end of their lives, they flower to make their seeds. Dr. ACM, a biologist, was fascinated by the bamboos in blossom in his travel to Tsukuba. He liked the flower so much that he was tempted to make a garden where the bamboos bloom annually. Dr... | [
{
"input": {
"stdin": "3 1\n3 4\n10 20\n100 50\n2 500000\n0 0"
},
"output": {
"stdout": "4\n11\n47\n150\n7368791"
}
},
{
"input": {
"stdin": "3 2\n2 6\n10 15\n110 52\n2 371896\n0 0"
},
"output": {
"stdout": "5\n17\n31\n162\n5361757\n"
}
},
{
"input... | {
"tags": [],
"title": "Bamboo Blossoms"
} | {
"cpp": "#include<bits/stdc++.h>\nusing namespace std;\nint sow[7368791+10]={0};\nint main(){\n\tint m,n;\n\twhile(cin >> m >> n,m){\n\t\tfor(int i=0;i<=7368791+10;i++)\n\t\t\tsow[i]=0;\n\t\tn--;\n\t\twhile(1){\n\t\t\tfor(int i=1;m*i<=7368791+10;i++)\n\t\t\t\tsow[m*i]=1;\n\t\t\twhile(1){\n\t\t\t\tm++;\n\t\t\t\tif(so... |
AIZU/p01231 | # Aaron and Bruce
Aaron is a vicious criminal. He has repeatedly committed crimes (2 shoplifting, 16 peeping, 256 underwear thieves, 65,536 escapes), but has continued to escape from the police with his extraordinary physical abilities. Bruce is a police officer. Although he does not have outstanding athletic ability,... | [
{
"input": {
"stdin": "6\n8\n0 1 0 0 0 0 0 0\n1 0 1 0 0 0 0 0\n0 1 0 1 1 0 0 0\n0 0 1 0 0 0 0 0\n0 0 1 0 0 1 1 0\n0 0 0 0 1 0 0 0\n0 0 0 0 1 0 0 1\n0 0 0 0 0 0 1 0\n3 0\n4\n0 1 1 0\n1 0 0 1\n1 0 0 1\n0 1 1 0\n1 0\n5\n0 1 0 1 0\n1 0 0 1 0\n0 0 0 0 1\n1 1 0 0 0\n0 0 1 0 0\n2 0\n5\n0 1 0 0 1\n1 0 1 1 1\n0 1 ... | {
"tags": [],
"title": "Aaron and Bruce"
} | {
"cpp": "#include <iostream>\n#include <cstring>\nusing namespace std;\n#define INF (1<<25)\nint dp[60][50][50][2] = {};\nint g[50][50] = {};\nint n,m;\n\nint dfs(int mid,int a,int b,int t){\n\tif(t == 0 && a == b) return -INF;\n\tif(dp[mid][a][b][t] != -1) return dp[mid][a][b][t];\n\tif(mid == 0){\n\t\t//cout << a ... |
AIZU/p01365 | # Camera Control
"ACM48" is one of the most popular dance vocal units in Japan. In this winter, ACM48 is planning a world concert tour. You joined the tour as a camera engineer.
Your role is to develop software which controls the camera on a stage. For simplicity you can regard the stage as 2-dimensional space. You c... | [
{
"input": {
"stdin": "2\n0 0\n2\n-5 5 0\n5 5 10\n1\n0 6\n2\n5 5 0\n-5 5 10\n1\n6 10\n1\n7 -65\n2\n-65 10 0\n65 1 3\n2\n0 1\n23 24\n2\n0 0\n2\n100 10 0\n-10 10 10\n5\n0 1\n2 3\n4 5\n6 7\n8 9\n2\n10 0 0\n0 10 10\n5\n1 2\n3 4\n5 6\n7 8\n9 10\n0"
},
"output": {
"stdout": "9.00000000\n2.00000000... | {
"tags": [],
"title": "Camera Control"
} | {
"cpp": "#include <stdio.h>\n#include <string.h>\n#include <algorithm>\n#include <iostream>\n#include <math.h>\n#include <assert.h>\n#include <vector>\n#include <complex>\n#include <set>\n#include <map>\n\nusing namespace std;\ntypedef long long ll;\ntypedef unsigned int uint;\ntypedef unsigned long long ull;\nstati... |
AIZU/p01547 | # Final Defense Line
In a country that has been frequently invaded by unidentified creatures, it has decided to protect important facilities with new defense weapons.
This weapon can damage unidentified creatures by filling a polygonal area with a special gas. If the concentration of gas changes during the invasion of... | [
{
"input": {
"stdin": "2\n4\n0 4\n1 1\n3 1\n4 4\n3\n6 0\n10 0\n8 7\n1\n2 3 9 1"
},
"output": {
"stdout": "2"
}
},
{
"input": {
"stdin": "2\n4\n0 0\n10 0\n10 10\n0 10\n4\n10 0\n20 0\n20 10\n10 10\n1\n5 5 15 5"
},
"output": {
"stdout": "0"
}
},
{
"in... | {
"tags": [],
"title": "Final Defense Line"
} | {
"cpp": "#include <cstdio>\n#include <cmath>\n#include <cstring>\n#include <cstdlib>\n#include <climits>\n#include <ctime>\n#include <queue>\n#include <stack>\n#include <algorithm>\n#include <list>\n#include <vector>\n#include <set>\n#include <map>\n#include <iostream>\n#include <deque>\n#include <complex>\n#include... |
AIZU/p01703 | # Speedrun
Problem Statement
Infinite Chronicle -Princess Castle- is a simple role-playing game. There are $n + 1$ checkpoints, numbered $0$ through $n$, and for each $i = 1, 2, \ldots, n$, there is a unique one-way road running from checkpoint $i - 1$ to $i$. The game starts at checkpoint $0$ and ends at checkpoint ... | [
{
"input": {
"stdin": "2\n0.50 0.40\n2\n0.70 0.60\n4\n0.99 1.00 1.00 0.01\n0"
},
"output": {
"stdout": "5.5000000000\n4.0476190476\n104.0101010101"
}
},
{
"input": {
"stdin": "2\n0.50 0.9941160617471074\n2\n0.7441539466854266 0.60\n0\n0.99 1.00 1.00 0.8947303802667858\n0"
... | {
"tags": [],
"title": "Speedrun"
} | {
"cpp": "#include <bits/stdc++.h>\n\n#define REP(i,n) for(int i=0;i<(int)(n);i++)\n\nusing namespace std;\n\ntypedef long double ld; \nconst ld INF = 1e+12;\n\nint main() {\n while(1){\n int n;\n cin>>n;\n if(!n)break;\n vector<ld> p(n),p2(1,1);\n REP(i,n) cin>>p[i];\n int l = 0;\n vector<int> ... |
AIZU/p01847 | # Curtain
curtain
Summer is coming soon. You decide to redecorate your room for the summer. It is expected that the sun will be very strong this summer, and it will be a difficult season for you who are not good at dazzling. So you thought about installing a curtain on the window of the room to adjust the brightness ... | [
{
"input": {
"stdin": "4\n0 0\n10 0\n10 10\n0 10\n0 0\n5 0\n5 10\n0 10\n6\n0 0\n10 0\n10 5\n5 5\n5 10\n0 10\n2 0\n8 0\n8 10\n2 10\n12\n1 1\n1 3\n-1 3\n-1 1\n-3 1\n-3 -1\n-1 -1\n-1 -3\n1 -3\n1 -1\n3 -1\n3 1\n2 2\n-2 2\n-2 -2\n2 -2\n4\n20000 20000\n-20000 20000\n-20000 -20000\n20000 -20000\n1000 1000\n-1000... | {
"tags": [],
"title": "Curtain"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\nconst int MAX_N = 1<<16;\n\nclass RSQ2{\npublic:\n ll n,dat[2*MAX_N-1],td[2*MAX_N-1];\n RSQ2(){n=MAX_N,memset(dat,0,sizeof(dat)),memset(td,0,sizeof(td));};\n \n ll add(int a,int b,ll x,int k=0,int l=0,int r=-1){\n if(r==-1) r=n;\n... |
AIZU/p01983 | # Proof of Knowledge
Proof of knowledge
The entrance door of the apartment you live in has a password-type lock. This password consists of exactly four digits, ranging from 0 to 9, and you always use the password P given to you by the apartment manager to unlock this door.
One day, you wondered if all the residents ... | [
{
"input": {
"stdin": "[+c[+a[^bd]]]\n0404\n[*b[*[*cd]a]]\n7777\n[^[^ab][^cd]]\n1295\na\n9876\n[^dd]\n9090\n."
},
"output": {
"stdout": "0 10\n7 1\n15 544\n9 1000\n0 10000"
}
},
{
"input": {
"stdin": "[+c[*a[^bd]]]\n0404\n[*b[*[*cd]a]]\n2456\n[^[^ab][^cd]]\n2501\na\n6204\n[... | {
"tags": [],
"title": "Proof of Knowledge"
} | {
"cpp": "#include<bits/stdc++.h>\nusing namespace std;\n\n\nint gethash(const string& s, const vector<int>& v) {\n stack<int> st;\n for (char c : s) {\n if ('a' <= c && c <= 'd')\n st.push(v[c - 'a']);\n else if (c == '+') {\n int a = st.top();\n st.pop();\n ... |
AIZU/p02129 | # Ghost Legs
Problem
There are $ N $ Amidakuji with 3 vertical lines.
No matter which line you start from, the Amidakuji that ends at the starting line is considered a good Amidakuji.
You can select one or more Amidakuji and connect them vertically in any order.
Output "yes" if you can make a good Amidakuji, otherwis... | [
{
"input": {
"stdin": "3\n2 0 0\n1 1\n5 1 0 0 1 0"
},
"output": {
"stdout": "yes"
}
},
{
"input": {
"stdin": "2\n1 1\n1 0"
},
"output": {
"stdout": "no"
}
},
{
"input": {
"stdin": "2\n1 1\n3 0"
},
"output": {
"stdout": "no\n"
... | {
"tags": [],
"title": "Ghost Legs"
} | {
"cpp": "#include<bits/stdc++.h>\n#define rep(i,a,b) for(int i=a;i<b;i++)\n#define rrep(i,a,b) for(int i=a;i>=b;i--)\n#define fore(i,a) for(auto &i:a)\n#define all(x) (x).begin(),(x).end()\n#pragma GCC optimize (\"-O3\")\nusing namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(... |
AIZU/p02270 | # Allocation
You are given $n$ packages of $w_i$ kg from a belt conveyor in order ($i = 0, 1, ... n-1$). You should load all packages onto $k$ trucks which have the common maximum load $P$. Each truck can load consecutive packages (more than or equals to zero) from the belt conveyor unless the total weights of the pac... | [
{
"input": {
"stdin": "5 3\n8\n1\n7\n3\n9"
},
"output": {
"stdout": "10"
}
},
{
"input": {
"stdin": "4 2\n1\n2\n2\n6"
},
"output": {
"stdout": "6"
}
},
{
"input": {
"stdin": "4 4\n-1\n4\n9\n5\n4"
},
"output": {
"stdout": "9\n"
... | {
"tags": [],
"title": "Allocation"
} | {
"cpp": "#include<stdio.h>\n\nint a[100001],n,k;\nint solve(int x){\n\tint i=0,j=0,cur=0;\n\twhile(i<n && j<k){\n\t\tif(a[i]+cur<=x){\n\t\t\tcur+=a[i];\n\t\t\ti++;\n\t\t}\n\t\telse{\n\t\t\tcur=0;\n\t\t\tj++;\n\t\t}\n\t}\n\treturn (j<k);\n}\n\nint find(){\n\tint r=1000000000,l=0;\n\tint m;\n\twhile(l<r){\n\t\tm=(r+l)... |
AIZU/p02417 | # Counting Characters
Write a program which counts and reports the number of each alphabetical letter. Ignore the case of characters.
Constraints
* The number of characters in the sentence < 1200
Input
A sentence in English is given in several lines.
Output
Prints the number of alphabetical letters in the follow... | [
{
"input": {
"stdin": "This is a pen."
},
"output": {
"stdout": "a : 1\nb : 0\nc : 0\nd : 0\ne : 1\nf : 0\ng : 0\nh : 1\ni : 2\nj : 0\nk : 0\nl : 0\nm : 0\nn : 1\no : 0\np : 1\nq : 0\nr : 0\ns : 2\nt : 1\nu : 0\nv : 0\nw : 0\nx : 0\ny : 0\nz : 0"
}
},
{
"input": {
"stdin": ... | {
"tags": [],
"title": "Counting Characters"
} | {
"cpp": "#include<bits/stdc++.h>\n#define rep(i,n)for(int i=0;i<n;i++)\nusing namespace std;\n\nint cnt[26];\nint main() {\n\tstring s, t;\n\twhile (cin >> t)s += t;\n\tfor (char c : s) {\n\t\tif (!isalpha(c))continue;\n\t\tif (islower(c))c = toupper(c);\n\t\tcnt[c - 'A']++;\n\t}\n\trep(i, 26) {\n\t\tcout << (char)(... |
CodeChef/amsgame1 | Chef is playing a game on a sequence of N positive integers, say A1, A2, ... AN. The game is played as follows.
If all the numbers are equal, the game ends.
Otherwise
Select two numbers which are unequal
Subtract the smaller number from the larger number
Replace the larger number with the result from above (see the e... | [
{
"input": {
"stdin": "3\n2\n10 12\n2\n5 9\n3\n6 10 15"
},
"output": {
"stdout": "2\n1\n1\n"
}
},
{
"input": {
"stdin": "3\n2\n3 12\n2\n10 9\n3\n6 9 15"
},
"output": {
"stdout": "3\n1\n3\n"
}
},
{
"input": {
"stdin": "3\n2\n18 21\n2\n9 9\n3\n... | {
"tags": [],
"title": "amsgame1"
} | {
"cpp": null,
"java": null,
"python": "#making them equal <VigzMv/>\nfrom fractions import gcd\nfor t in range(int(raw_input())):\n n=int(raw_input())\n a=0\n N=map(int,raw_input().split())\n for i in N:\n a=gcd(a,i)\n print a"
} |
CodeChef/chn15a | Gru has not been in the limelight for a long time and is, therefore, planning something particularly nefarious. Frustrated by his minions' incapability which has kept him away from the limelight, he has built a transmogrifier — a machine which mutates minions.
Each minion has an intrinsic characteristic value (simila... | [
{
"input": {
"stdin": "1\n5 10\n2 4 1 35 1"
},
"output": {
"stdout": "1\n"
}
},
{
"input": {
"stdin": "1\n0 4\n1 29 1 1 1"
},
"output": {
"stdout": "0\n"
}
},
{
"input": {
"stdin": "1\n2 2\n0 15 1 0 1"
},
"output": {
"stdout": "... | {
"tags": [],
"title": "chn15a"
} | {
"cpp": null,
"java": null,
"python": "for _ in range(input()):\n\tn,k=map(int,raw_input().split())\n\ta=map(int,raw_input().split())\n\tc=0\n\t#print a\n\tfor i in range(n):\n\t\ta[i]+=k\n\t\tif not a[i]%7:\n\t\t\tc+=1\n\tprint c"
} |
CodeChef/entexam | The faculty of application management and consulting services (FAMCS) of the Berland State University (BSU) has always been popular among Berland's enrollees. This year, N students attended the entrance exams, but no more than K will enter the university. In order to decide who are these students, there are series of e... | [
{
"input": {
"stdin": "1\n4 2 3 10\n7 7 7\n4 6 10\n7 10 9\n9 9"
},
"output": {
"stdout": "4\n"
}
},
{
"input": {
"stdin": "1\n4 3 3 17\n4 7 7\n3 6 10\n7 10 7\n18 9"
},
"output": {
"stdout": "0\n"
}
},
{
"input": {
"stdin": "1\n4 3 3 10\n4 7 7... | {
"tags": [],
"title": "entexam"
} | {
"cpp": null,
"java": null,
"python": "# your code goes here\nt = int(raw_input())\nfor i in range(0,t):\n\tn,k,e,m = map(int,raw_input().split())\n\ta_sum = list()\n\tfor j in range(0,n-1):\n\t\ts_num = 0\n\t\tn_num = list(map(int,raw_input().split()))\n\t\tfor l in range(0,e):\n\t\t\t#print l\n\t\t\ts_num = s_... |
CodeChef/kjcc02 | Sum and Color
Chef is a mathematics student. His professor has given him a difficult task. Professor initially provides Chef with a list of numbers. For every number in the list, Chef has to calculate the sum 'S' of digits such that 0<=S<=9. Even if the sum of digits is coming as a 'n' digit number, Chef has to bring i... | [
{
"input": {
"stdin": "5\n5\n128 25 87 50 1558\n4\n11 22 33 44\n3\n36 14 1000\n5\n11112 95 96 256 2669\n3\n10 991 83"
},
"output": {
"stdout": "yellow\ngreen\nbrown\ncyan\npink"
}
}
] | {
"tags": [],
"title": "kjcc02"
} | {
"cpp": null,
"java": null,
"python": "def con(a):\n summ=0\n while True:\n summ+=a%10\n a/=10\n if(a==0):\n break\n if((summ/10)>=1):\n return con(summ)\n else:\n return summ\nfor _ in xrange(input()):\n s_li=[]\n input()\n li=map(int,raw_input(... |
CodeChef/orders | In Byteland it is always the military officer's main worry to order his soldiers on parade correctly. Luckily, ordering soldiers is not really such a problem. If a platoon consists of n men, all of them have different rank (from 1 - lowest to n - highest) and on parade they should be lined up from left to right in incr... | [
{
"input": {
"stdin": "2\n3\n0 1 0\n5\n0 1 2 0 1"
},
"output": {
"stdout": "2 1 3\n3 2 1 5 4\n"
}
},
{
"input": {
"stdin": "2\n0\n-1 -1 -1\n5\n0 0 1 1 0"
},
"output": {
"stdout": "\n1 4 2 3 5\n"
}
},
{
"input": {
"stdin": "2\n1\n0 1 0\n4\n0 1... | {
"tags": [],
"title": "orders"
} | {
"cpp": null,
"java": null,
"python": "# cook your code here\ntest = input()\nfor t in xrange(test):\n s = range(1, input()+1)\n w = map(int, raw_input().split())\n for i in xrange(len(w)-1, -1, -1):\n if w[i] > 0:\n s.insert(i, s.pop(i - w[i]))\n print ' '.join(map(str, s))"
} |
CodeChef/spoons | Lo and Behold! For you may be surprised by what our chief chef Noodle has in mind for this season! Today, Noodle announced one of his most extra-ordinary ideas ever - Project Spoon.
Noodle plans to deploy large spoons in the atmosphere so that people all around the world can download food directly from his kitchen th... | [
{
"input": {
"stdin": "2\n2\n3"
},
"output": {
"stdout": "2\n3\n"
}
},
{
"input": {
"stdin": "2\n68\n107"
},
"output": {
"stdout": "8\n9\n"
}
},
{
"input": {
"stdin": "2\n3\n40"
},
"output": {
"stdout": "3\n8\n"
}
},
{
... | {
"tags": [],
"title": "spoons"
} | {
"cpp": null,
"java": null,
"python": "def ncr(a,b):\n A=1\n B=1\n for i in range (a-b+1,a+1):\n A*=i;\n for j in range (1,b+1):\n B*=j;\n return A/B\nt=input()\ncomb=[]\nfor i in range (0,70):\n comb.append(ncr(i,int(i/2)))\nwhile(t):\n n=int(input())\n for i in range (2,70... |
Codeforces/1006/B | # Polycarp's Practice
Polycarp is practicing his problem solving skill. He has a list of n problems with difficulties a_1, a_2, ..., a_n, respectively. His plan is to practice for exactly k days. Each day he has to solve at least one problem from his list. Polycarp solves the problems in the order they are given in hi... | [
{
"input": {
"stdin": "8 3\n5 4 2 6 5 1 9 2\n"
},
"output": {
"stdout": "20\n1 3 4\n"
}
},
{
"input": {
"stdin": "4 2\n1 2000 2000 2\n"
},
"output": {
"stdout": "4000\n2 2\n"
}
},
{
"input": {
"stdin": "5 1\n1 1 1 1 1\n"
},
"output": ... | {
"tags": [
"greedy",
"implementation",
"sortings"
],
"title": "Polycarp's Practice"
} | {
"cpp": "#include <bits/stdc++.h>\nunsigned ks[2009];\nunsigned as[2009];\nint indircmp(const void* a, const void* b) {\n return as[*(unsigned*)b] - as[*(unsigned*)a];\n}\nint cmp(const void* a, const void* b) { return *(unsigned*)a - *(unsigned*)b; }\nint main() {\n unsigned i, n, k, max;\n scanf(\"%u%u\", &n, &... |
Codeforces/102/A | # Clothes
A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap.
Overall the shop sells n clothing items, and exactly m pairs of clothing items match. Each... | [
{
"input": {
"stdin": "4 4\n1 1 1 1\n1 2\n2 3\n3 4\n4 1\n"
},
"output": {
"stdout": "-1"
}
},
{
"input": {
"stdin": "3 3\n1 2 3\n1 2\n2 3\n3 1\n"
},
"output": {
"stdout": "6"
}
},
{
"input": {
"stdin": "3 2\n2 3 4\n2 3\n2 1\n"
},
"out... | {
"tags": [
"brute force"
],
"title": "Clothes"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n map<pair<int, int>, int> mp;\n map<int, int> mpn;\n long long sum = -1, res = 20000000000, n, m, value;\n cin >> n >> m;\n pair<int, int> p[m];\n for (int i = 1; i <= n; i++) {\n cin >> value;\n mpn[i] = value;\n }\n for (int i = 0... |
Codeforces/1051/A | # Vasya And Password
Vasya came up with a password to register for EatForces — a string s. The password in EatForces should be a string, consisting of lowercase and uppercase Latin letters and digits.
But since EatForces takes care of the security of its users, user passwords must contain at least one digit, at least... | [
{
"input": {
"stdin": "2\nabcDCE\nhtQw27\n"
},
"output": {
"stdout": "1bcDCE\nhtQw27\n"
}
},
{
"input": {
"stdin": "1\nA00\n"
},
"output": {
"stdout": "Aa0\n"
}
},
{
"input": {
"stdin": "1\na00\n"
},
"output": {
"stdout": "aA0\n... | {
"tags": [
"greedy",
"implementation",
"strings"
],
"title": "Vasya And Password"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n ios::sync_with_stdio(false);\n cin.tie(0);\n int t;\n cin >> t;\n while (t--) {\n string second;\n cin >> second;\n int flag1 = 0, flag2 = 0, flag3 = 0;\n for (int i = 0; i < second.size(); i++) {\n if (second[i] >= '0' && ... |
Codeforces/1073/B | # Vasya and Books
Vasya has got n books, numbered from 1 to n, arranged in a stack. The topmost book has number a_1, the next one — a_2, and so on. The book at the bottom of the stack has number a_n. All numbers are distinct.
Vasya wants to move all the books to his backpack in n steps. During i-th step he wants to m... | [
{
"input": {
"stdin": "3\n1 2 3\n2 1 3\n"
},
"output": {
"stdout": "2 0 1 "
}
},
{
"input": {
"stdin": "6\n6 5 4 3 2 1\n6 5 3 4 2 1\n"
},
"output": {
"stdout": "1 1 2 0 1 1 "
}
},
{
"input": {
"stdin": "5\n3 1 4 2 5\n4 5 1 3 2\n"
},
"... | {
"tags": [
"implementation",
"math"
],
"title": "Vasya and Books"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nint z[200001], q[200001];\nint main() {\n int n;\n cin >> n;\n for (int i = 1; i <= n; i++) {\n cin >> q[i];\n }\n int l = 1, r = n, xx, num;\n for (int i = 1; i <= n; i++) {\n cin >> xx;\n num = 0;\n while (!z[xx]) {\n z[q[l]] = 1;\n ... |
Codeforces/1095/B | # Array Stabilization
You are given an array a consisting of n integer numbers.
Let instability of the array be the following value: max_{i = 1}^{n} a_i - min_{i = 1}^{n} a_i.
You have to remove exactly one element from this array to minimize instability of the resulting (n-1)-elements array. Your task is to calcula... | [
{
"input": {
"stdin": "4\n1 3 3 7\n"
},
"output": {
"stdout": "2\n"
}
},
{
"input": {
"stdin": "2\n1 100000\n"
},
"output": {
"stdout": "0\n"
}
},
{
"input": {
"stdin": "30\n28 69 21 75 45 3 30 78 95 30 49 53 29 50 44 90 15 47 84 88 15 80 29 ... | {
"tags": [
"implementation"
],
"title": "Array Stabilization"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n int n, ma, mi;\n cin >> n;\n int arr[n];\n for (int i = 0; i < n; i++) {\n cin >> arr[i];\n }\n sort(arr, arr + n);\n ma = arr[n - 2] - arr[0];\n mi = arr[n - 1] - arr[1];\n if (ma > mi) {\n cout << mi;\n } else\n cout << ma;\... |
Codeforces/1114/C | # Trailing Loves (or L'oeufs?)
The number "zero" is called "love" (or "l'oeuf" to be precise, literally means "egg" in French), for example when denoting the zero score in a game of tennis.
Aki is fond of numbers, especially those with trailing zeros. For example, the number 9200 has two trailing zeros. Aki thinks t... | [
{
"input": {
"stdin": "6 9\n"
},
"output": {
"stdout": "1\n"
}
},
{
"input": {
"stdin": "5 2\n"
},
"output": {
"stdout": "3\n"
}
},
{
"input": {
"stdin": "5 10\n"
},
"output": {
"stdout": "1\n"
}
},
{
"input": {
... | {
"tags": [
"brute force",
"implementation",
"math",
"number theory"
],
"title": "Trailing Loves (or L'oeufs?)"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nconst long long N = 50155;\nlong long n, b, ans = 1e18, c;\nvector<long long> x, y;\nlong long D(long long a) {\n long long felan = 0, aa = a;\n while (1) {\n felan += (n / a);\n if (a > n / aa) break;\n a *= aa;\n }\n return felan;\n}\nint main()... |
Codeforces/1142/D | # Foreigner
Traveling around the world you noticed that many shop owners raise prices to inadequate values if the see you are a foreigner.
You define inadequate numbers as follows:
* all integers from 1 to 9 are inadequate;
* for an integer x ≥ 10 to be inadequate, it is required that the integer ⌊ x / 10 ⌋ is... | [
{
"input": {
"stdin": "110\n"
},
"output": {
"stdout": "3"
}
},
{
"input": {
"stdin": "4021\n"
},
"output": {
"stdout": "6"
}
},
{
"input": {
"stdin": "714230834541030105084207842301073032230401301054101030108580022410987192154341082164501051... | {
"tags": [
"dp"
],
"title": "Foreigner"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nint N, nxt[20][20];\nlong long cnt[20], old[20];\nchar sir[100009];\nint main() {\n for (int i = 0; i < 11; i++)\n for (int j = 0; j < 11; j++) nxt[i][j] = -1;\n int s = 9;\n for (int i = 1; i <= 11; i++)\n for (int d = 0; d < i % 11; d++) s++, nxt[i ... |
Codeforces/1162/F | # Palindrome XOR
You are given a string s consisting of characters "1", "0", and "?". The first character of s is guaranteed to be "1". Let m be the number of characters in s.
Count the number of ways we can choose a pair of integers a, b that satisfies the following:
* 1 ≤ a < b < 2^m
* When written without l... | [
{
"input": {
"stdin": "1\n"
},
"output": {
"stdout": "0\n"
}
},
{
"input": {
"stdin": "1?????????????????????????????????????\n"
},
"output": {
"stdout": "519569202\n"
}
},
{
"input": {
"stdin": "1?0???10\n"
},
"output": {
"stdo... | {
"tags": [
"dfs and similar",
"graphs"
],
"title": "Palindrome XOR"
} | {
"cpp": "#include <bits/stdc++.h>\nconst int MOD = 998244353;\nint n;\nchar s[1005];\nint a[1005], b[1005];\nint currLen;\nbool seta(int, int);\nbool setb(int pos, int value) {\n if (pos >= currLen) return true;\n int pos2 = currLen - 1 - pos;\n if (b[pos] == (value ^ 1)) return false;\n if (b[pos2] == (value ^ ... |
Codeforces/1183/E | # Subsequences (easy version)
The only difference between the easy and the hard versions is constraints.
A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, t... | [
{
"input": {
"stdin": "4 5\nasdf\n"
},
"output": {
"stdout": "4\n"
}
},
{
"input": {
"stdin": "5 6\naaaaa\n"
},
"output": {
"stdout": "15\n"
}
},
{
"input": {
"stdin": "5 7\naaaaa\n"
},
"output": {
"stdout": "-1\n"
}
},
... | {
"tags": [
"dp",
"graphs",
"implementation",
"shortest paths"
],
"title": "Subsequences (easy version)"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nusing ull = unsigned long long;\nvoid solve() {\n int n, k;\n string s;\n cin >> n >> k >> s;\n ll ans = 0;\n queue<string> q;\n q.push(s);\n set<string> used;\n int cnt = 0;\n while (!q.empty() && cnt < k) {\n string t = q.f... |
Codeforces/1200/F | # Graph Traveler
Gildong is experimenting with an interesting machine Graph Traveler. In Graph Traveler, there is a directed graph consisting of n vertices numbered from 1 to n. The i-th vertex has m_i outgoing edges that are labeled as e_i[0], e_i[1], …, e_i[m_i-1], each representing the destination vertex of the edg... | [
{
"input": {
"stdin": "4\n0 0 0 0\n2\n2 3\n1\n2\n3\n2 4 1\n4\n3 1 2 1\n6\n1 0\n2 0\n3 -1\n4 -2\n1 1\n1 5\n"
},
"output": {
"stdout": "1\n1\n2\n1\n3\n2\n"
}
},
{
"input": {
"stdin": "4\n4 -5 -3 -1\n2\n2 3\n1\n2\n3\n2 4 1\n4\n3 1 2 1\n6\n1 0\n2 0\n3 -1\n4 -2\n1 1\n1 5\n"
... | {
"tags": [
"brute force",
"data structures",
"dfs and similar",
"dp",
"graphs",
"implementation",
"math",
"number theory"
],
"title": "Graph Traveler"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nconst int maxm = 2520;\nconst int maxn = 1007;\nint n;\nint ans[maxn][maxm], k[maxn], m[maxn];\nint vis[maxn][maxm];\nvector<int> e[maxn];\npair<int, int> st[maxn * maxm];\nvoid solve(int u, int w) {\n queue<pair<int, int> > q;\n while (!q.empty()) {\n q.... |
Codeforces/1218/H | # Function Composition
We are definitely not going to bother you with another generic story when Alice finds about an array or when Alice and Bob play some stupid game. This time you'll get a simple, plain text.
First, let us define several things. We define function F on the array A such that F(i, 1) = A[i] and F(i,... | [
{
"input": {
"stdin": "10\n2 3 1 5 6 4 2 10 7 7\n5\n10 1\n5 7\n10 6\n1 1\n10 8\n"
},
"output": {
"stdout": "3\n0\n1\n1\n0\n"
}
},
{
"input": {
"stdin": "10\n2 2 1 5 4 4 2 10 6 7\n4\n0 2\n5 9\n10 6\n1 1\n19 8\n"
},
"output": {
"stdout": "1\n0\n0\n1\n"
}
}... | {
"tags": [
"dfs and similar"
],
"title": "Function Composition"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nconst int Nmax = 2e5 + 5;\nint A[Nmax], start[Nmax];\nlong long cnt[Nmax];\nbool cycle[Nmax];\nint go[Nmax], where[Nmax], visited[Nmax];\nvector<int> active[Nmax], when[Nmax];\nint zz[Nmax], ans[Nmax];\nint nrcomp, n, q, Nr;\nvector<int> cyc[Nmax];\nvector<int... |
Codeforces/1242/E | # Planar Perimeter
Ujan has finally cleaned up his house and now wants to decorate the interior. He decided to place a beautiful carpet that would really tie the guest room together.
He is interested in carpets that are made up of polygonal patches such that each side of a patch is either a side of another (different... | [
{
"input": {
"stdin": "2\n3 3\n"
},
"output": {
"stdout": "4\n3 4 1 \n1 2 3 \n"
}
},
{
"input": {
"stdin": "3\n5 3 5\n"
},
"output": {
"stdout": "6\n5 4 3 6 1 \n1 6 2 \n1 2 3 4 5 \n"
}
},
{
"input": {
"stdin": "10\n5 8 3 7 6 9 8 3 4 5\n"
... | {
"tags": [
"constructive algorithms",
"graphs"
],
"title": "Planar Perimeter"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nconst int MAXF = 1.1e5;\nint F;\nint st[MAXF];\nint en[MAXF];\nlist<int> A[MAXF];\nconst int MAXV = 3.1e5;\nint V;\nint par[MAXV];\nint realPar[MAXV];\nint getPar(int a) { return par[a] == -1 ? a : (par[a] = getPar(par[a])); }\nbool merge(int a, int b) {\n a ... |
Codeforces/1261/D2 | # Wrong Answer on test 233 (Hard Version)
Your program fails again. This time it gets "Wrong answer on test 233"
.
This is the harder version of the problem. In this version, 1 ≤ n ≤ 2⋅10^5. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems.
The probl... | [
{
"input": {
"stdin": "5 5\n1 1 4 2 2\n"
},
"output": {
"stdout": "1000"
}
},
{
"input": {
"stdin": "6 2\n1 1 2 2 1 1\n"
},
"output": {
"stdout": "16"
}
},
{
"input": {
"stdin": "3 3\n1 3 1\n"
},
"output": {
"stdout": "9"
}
... | {
"tags": [
"combinatorics",
"math"
],
"title": "Wrong Answer on test 233 (Hard Version)"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nconst long long N = 2e5 + 7, M = 998244353;\nlong long fact[N], obr[N], pref0[N], poww[N];\nlong long a[N];\nlong long bin_pow(long long a, long long n) {\n if (n == 0) return 1;\n if (n == 1) return a % M;\n if (n % 2 == 0) {\n long long mem = bin_pow(a... |
Codeforces/1284/A | # New Year and Naming
Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.
There are two sequences of n strings s_1, s_2, s_3, …, s_{n} and m strings t_... | [
{
"input": {
"stdin": "10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020\n"
},
"output": {
"stdout": "sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\nje... | {
"tags": [
"implementation",
"strings"
],
"title": "New Year and Naming"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n int n, m;\n cin >> n >> m;\n vector<string> v1, v2;\n string s;\n for (int i = 0; i < n; i++) {\n cin >> s;\n v1.push_back(s);\n }\n for (int i = 0; i < m; i++) {\n cin >> s;\n v2.push_back(s);\n }\n int q, y;\n cin >> q;\n... |
Codeforces/1303/C | # Perfect Keyboard
Polycarp wants to assemble his own keyboard. Layouts with multiple rows are too complicated for him — his keyboard will consist of only one row, where all 26 lowercase Latin letters will be arranged in some order.
Polycarp uses the same password s on all websites where he is registered (it is bad, ... | [
{
"input": {
"stdin": "5\nababa\ncodedoca\nabcda\nzxzytyz\nabcdefghijklmnopqrstuvwxyza\n"
},
"output": {
"stdout": "YES\nabcdefghijklmnopqrstuvwxyz\nYES\nacodebfghijklmnpqrstuvwxyz\nNO\nYES\ntyzxabcdefghijklmnopqrsuvw\nNO\n"
}
},
{
"input": {
"stdin": "5\nababa\necodnadc\na... | {
"tags": [
"dfs and similar",
"greedy",
"implementation"
],
"title": "Perfect Keyboard"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n int t;\n cin >> t;\n while (t--) {\n string s;\n cin >> s;\n int n = (int)s.size();\n if (n == 1) {\n string ans = \"\";\n for (char c = 'a'; c <= 'z'; ++c) {\n ... |
Codeforces/1327/D | # Infinite Path
You are given a colored permutation p_1, p_2, ..., p_n. The i-th element of the permutation has color c_i.
Let's define an infinite path as infinite sequence i, p[i], p[p[i]], p[p[p[i]]] ... where all elements have same color (c[i] = c[p[i]] = c[p[p[i]]] = ...).
We can also define a multiplication of... | [
{
"input": {
"stdin": "3\n4\n1 3 4 2\n1 2 2 3\n5\n2 3 4 5 1\n1 2 3 4 5\n8\n7 4 5 6 1 8 3 2\n5 3 6 4 7 5 8 4\n"
},
"output": {
"stdout": "1\n5\n2\n"
}
},
{
"input": {
"stdin": "3\n4\n1 3 4 2\n1 2 2 3\n5\n2 3 4 5 1\n1 2 5 4 5\n8\n7 4 5 6 1 8 3 2\n5 3 2 5 7 5 8 4\n"
},
... | {
"tags": [
"brute force",
"dfs and similar",
"graphs",
"math",
"number theory"
],
"title": "Infinite Path"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nconst int N = 1e6 + 5;\nconst long long mod = 998244353;\nlong long ksm(long long a, long long b) {\n long long ans = 1LL;\n while (b) {\n if (b & 1) ans = ans * a % mod;\n a = a * a % mod;\n b >>= 1;\n }\n return ans;\n}\nint a[N], c[N], tmp[N], ... |
Codeforces/1346/F | # Dune II: Battle For Arrakis
You're at the last mission in one very old and very popular strategy game Dune II: Battle For Arrakis. The map of the mission can be represented as a rectangular matrix of size n × m. Initially, there are a_{i, j} units of your army in the cell (i, j).
You want to prepare for the final b... | [
{
"input": {
"stdin": "3 3 1\n1 2 3\n2 1 2\n1 1 2\n2 3 100\n"
},
"output": {
"stdout": "\n21 22 \n"
}
},
{
"input": {
"stdin": "4 4 3\n2 5 6 3\n4 8 10 5\n2 6 7 1\n8 4 2 1\n1 1 8\n2 3 4\n4 4 5\n"
},
"output": {
"stdout": "\n123 135 129 145 \n"
}
}
] | {
"tags": [
"*special",
"data structures",
"greedy",
"math"
],
"title": "Dune II: Battle For Arrakis"
} | {
"cpp": null,
"java": null,
"python": null
} |
Codeforces/1368/D | # AND, OR and square sum
Gottfried learned about binary number representation. He then came up with this task and presented it to you.
You are given a collection of n non-negative integers a_1, …, a_n. You are allowed to perform the following operation: choose two distinct indices 1 ≤ i, j ≤ n. If before the operatio... | [
{
"input": {
"stdin": "1\n123\n"
},
"output": {
"stdout": "15129\n"
}
},
{
"input": {
"stdin": "3\n1 3 5\n"
},
"output": {
"stdout": "51\n"
}
},
{
"input": {
"stdin": "2\n349525 699050\n"
},
"output": {
"stdout": "1099509530625\... | {
"tags": [
"bitmasks",
"greedy",
"math"
],
"title": "AND, OR and square sum"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nint a[20];\nint main() {\n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n int n;\n cin >> n;\n for (int i = 0; i < n; i++) {\n int x;\n cin >> x;\n for (int j = 0; j < 20; j++) {\n if (x % 2) a[j]++;\n x /= 2;\n }\n }\n l... |
Codeforces/1389/F | # Bicolored Segments
You are given n segments [l_1, r_1], [l_2, r_2], ..., [l_n, r_n]. Each segment has one of two colors: the i-th segment's color is t_i.
Let's call a pair of segments i and j bad if the following two conditions are met:
* t_i ≠ t_j;
* the segments [l_i, r_i] and [l_j, r_j] intersect, embed or... | [
{
"input": {
"stdin": "7\n19 20 1\n13 15 2\n6 11 2\n4 10 1\n14 17 1\n13 13 2\n5 9 1\n"
},
"output": {
"stdout": "5\n"
}
},
{
"input": {
"stdin": "5\n5 8 1\n1 3 2\n3 4 2\n6 6 1\n2 10 2\n"
},
"output": {
"stdout": "4\n"
}
},
{
"input": {
"stdin... | {
"tags": [
"data structures",
"dp",
"graph matchings",
"sortings"
],
"title": "Bicolored Segments"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nclass segtree {\n struct node {\n long long v = 0;\n long long lazy = 0;\n void apply(int l, int r, long long x) { v += x; }\n void add_lazy(long long x) { lazy += x; }\n node operator+(const node &other) const {\n node ret;\n ret.v =... |
Codeforces/140/C | # New Year Snowmen
As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they've already made n snowballs with radii equal to r1, r2, ..., rn. To make a snowma... | [
{
"input": {
"stdin": "7\n1 2 3 4 5 6 7\n"
},
"output": {
"stdout": "2\n7 6 5\n4 3 2\n"
}
},
{
"input": {
"stdin": "3\n2 2 3\n"
},
"output": {
"stdout": "0\n"
}
},
{
"input": {
"stdin": "6\n1 2 2 3 4 5\n"
},
"output": {
"stdout"... | {
"tags": [
"binary search",
"data structures",
"greedy"
],
"title": "New Year Snowmen"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\npair<long long int, long long int> r1, r2, r3;\nset<pair<long long int, long long int> > number;\nset<pair<long long int, long long int> >::iterator it1, it2, it3;\nunordered_map<long long int, long long int> cont;\nunordered_map<long long int, long long int>:... |
Codeforces/1430/G | # Yet Another DAG Problem
You are given a directed acyclic graph (a directed graph that does not contain cycles) of n vertices and m arcs. The i-th arc leads from the vertex x_i to the vertex y_i and has the weight w_i.
Your task is to select an integer a_v for each vertex v, and then write a number b_i on each arcs ... | [
{
"input": {
"stdin": "5 4\n1 2 1\n2 3 1\n1 3 6\n4 5 8\n"
},
"output": {
"stdout": "2 1 0 1 0 \n"
}
},
{
"input": {
"stdin": "3 2\n2 1 4\n1 3 2\n"
},
"output": {
"stdout": "1 2 0 \n"
}
},
{
"input": {
"stdin": "5 5\n1 2 1\n2 3 1\n3 4 1\n1 5 1... | {
"tags": [
"bitmasks",
"dfs and similar",
"dp",
"flows",
"graphs",
"math"
],
"title": "Yet Another DAG Problem"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nconst long long inf = 1ll << 60;\nconst long long bias = 1e12;\nint n, m, s, t;\nconst int maxn = 2e2 + 5;\nlong long d[maxn * maxn];\nint vis[maxn * maxn];\nint id[maxn][maxn];\nint tot;\nstruct edge {\n int to, nex;\n long long w;\n} e[maxn * maxn * 10];\n... |
Codeforces/1454/C | # Sequence Transformation
You are given a sequence a, initially consisting of n integers.
You want to transform this sequence so that all elements in it are equal (i. e. it contains several occurrences of the same element).
To achieve this, you choose some integer x that occurs at least once in a, and then perform t... | [
{
"input": {
"stdin": "5\n3\n1 1 1\n5\n1 2 3 4 5\n5\n1 2 3 2 1\n7\n1 2 3 1 2 3 1\n11\n2 2 1 2 3 2 1 2 3 1 2\n"
},
"output": {
"stdout": "\n0\n1\n1\n2\n3\n"
}
},
{
"input": {
"stdin": "1\n17\n1 1 2 1 2 1 2 1 3 1 3 1 3 1 3 1 1\n"
},
"output": {
"stdout": "4\n"
... | {
"tags": [
"greedy",
"implementation"
],
"title": "Sequence Transformation"
} | {
"cpp": "#include<iostream>\n#include <map> \n#include<bits/stdc++.h>\n#include <limits>\n#include <cstdint>\n#include<stdio.h>\n#include<math.h>\n#include<string.h>\n#include<stdlib.h>\n#include<stdbool.h>\n#include<ctype.h>\nusing namespace std;\n\n#define pb push_back\n\n#define mp make_pair\n\n#define S second\n... |
Codeforces/1478/A | # Nezzar and Colorful Balls
Nezzar has n balls, numbered with integers 1, 2, …, n. Numbers a_1, a_2, …, a_n are written on them, respectively. Numbers on those balls form a non-decreasing sequence, which means that a_i ≤ a_{i+1} for all 1 ≤ i < n.
Nezzar wants to color the balls using the minimum number of colors, su... | [
{
"input": {
"stdin": "5\n6\n1 1 1 2 3 4\n5\n1 1 2 2 3\n4\n2 2 2 2\n3\n1 2 3\n1\n1\n"
},
"output": {
"stdout": "\n3\n2\n4\n1\n1\n"
}
},
{
"input": {
"stdin": "5\n6\n1 2 1 2 3 3\n5\n1 2 2 2 5\n4\n1 2 2 2\n3\n2 2 3\n1\n1\n"
},
"output": {
"stdout": "2\n3\n3\n2\n... | {
"tags": [
"brute force",
"greedy"
],
"title": "Nezzar and Colorful Balls"
} | {
"cpp": "#include<bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\ntypedef unsigned long long ull;\ntypedef long double lldd;\n\nint a[105];\n\nint main()\n{\n//\tfreopen(\"in.txt\",\"r\",stdin);\n\tstd::ios::sync_with_stdio(false);\n std::cin.tie(0);\n\tstd::cout.tie(0);\n\tint T,n;\n\tcin>>T;\n\twhi... |
Codeforces/1505/D | # Xenolith? Hippodrome?
Input
The input contains two integers N, M (1 ≤ N ≤ 1024, 2 ≤ M ≤ 16), separated by a single space.
Output
Output "YES" or "NO".
Examples
Input
2 3
Output
YES
Input
3 2
Output
NO
Input
33 16
Output
YES
Input
26 5
Output
NO | [
{
"input": {
"stdin": "2 3\n"
},
"output": {
"stdout": "\nYES\n"
}
},
{
"input": {
"stdin": "33 16\n"
},
"output": {
"stdout": "\nYES\n"
}
},
{
"input": {
"stdin": "26 5\n"
},
"output": {
"stdout": "\nNO\n"
}
},
{
"i... | {
"tags": [
"*special",
"number theory"
],
"title": "Xenolith? Hippodrome?"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\n\nvector<int> a;\nshort n;\nshort m;\n\nint main (){\n cin >> n >> m;\n while (n){\n a.push_back(n%m);\n n /= m;\n }\n sort(a.begin(), a.end());\n for (int i = 0; i < a.size()-1; i++){\n if (a[i] == a[i+1]){\n cou... |
Codeforces/1528/D | # It's a bird! No, it's a plane! No, it's AaParsa!
There are n cities in Shaazzzland, numbered from 0 to n-1. Ghaazzzland, the immortal enemy of Shaazzzland, is ruled by AaParsa.
As the head of the Ghaazzzland's intelligence agency, AaParsa is carrying out the most important spying mission in Ghaazzzland's history on... | [
{
"input": {
"stdin": "6 6\n0 0 1\n1 1 1\n2 2 1\n3 3 1\n4 4 1\n5 5 1\n"
},
"output": {
"stdout": "\n0 2 3 3 4 4 \n4 0 2 3 3 4 \n4 4 0 2 3 3 \n3 4 4 0 2 3 \n3 3 4 4 0 2 \n2 3 3 4 4 0 \n"
}
},
{
"input": {
"stdin": "4 5\n0 1 1\n1 3 2\n2 2 10\n3 0 1\n0 0 2\n"
},
"outpu... | {
"tags": [
"constructive algorithms",
"graphs",
"shortest paths"
],
"title": "It's a bird! No, it's a plane! No, it's AaParsa!"
} | {
"cpp": "#include <cmath>\n#include <vector>\n#include <iostream>\n#include <iomanip>\n#include <fstream>\n#include <algorithm>\n#include <set>\n#include <queue>\n#include <string>\n#include <map>\n#include <stack>\n#include <climits>\n#include <array>\n#include <unordered_set>\n#include <unordered_map>\n#include <m... |
Codeforces/15/C | # Industrial Nim
There are n stone quarries in Petrograd.
Each quarry owns mi dumpers (1 ≤ i ≤ n). It is known that the first dumper of the i-th quarry has xi stones in it, the second dumper has xi + 1 stones in it, the third has xi + 2, and the mi-th dumper (the last for the i-th quarry) has xi + mi - 1 stones in it... | [
{
"input": {
"stdin": "2\n2 1\n3 2\n"
},
"output": {
"stdout": "tolik\n"
}
},
{
"input": {
"stdin": "4\n1 1\n1 1\n1 1\n1 1\n"
},
"output": {
"stdout": "bolik\n"
}
},
{
"input": {
"stdin": "30\n53 12\n13 98\n21 60\n76 58\n39 5\n62 58\n73 80\n1... | {
"tags": [
"games"
],
"title": "Industrial Nim"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nint n;\nlong long ans;\nlong long Xor(long long x) {\n long long ans, i = x;\n while (i % 4 != 0) i--;\n ans = i;\n for (i++; i <= x; i++) ans ^= i;\n return ans;\n}\nint main() {\n long long x, m;\n scanf(\"%d\", &n);\n while (n--) {\n scanf(\"%I64... |
Codeforces/178/F3 | # Representative Sampling
The Smart Beaver from ABBYY has a long history of cooperating with the "Institute of Cytology and Genetics". Recently, the Institute staff challenged the Beaver with a new problem. The problem is as follows.
There is a collection of n proteins (not necessarily distinct). Each protein is a st... | [
{
"input": {
"stdin": "4 3\naaa\nabba\nabbc\nabbd\n"
},
"output": {
"stdout": "9\n"
}
},
{
"input": {
"stdin": "4 3\neee\nrrr\nttt\nqqq\n"
},
"output": {
"stdout": "0\n"
}
},
{
"input": {
"stdin": "3 2\naba\nbzd\nabq\n"
},
"output": {... | {
"tags": [
"dp",
"sortings",
"strings"
],
"title": "Representative Sampling"
} | {
"cpp": "#include <bits/stdc++.h>\nvoid Get(int &T) {\n char C;\n bool F = 0;\n for (; C = getchar(), C < '0' || C > '9';)\n if (C == '-') F = 1;\n for (T = C - '0'; C = getchar(), C >= '0' && C <= '9'; T = T * 10 + C - '0')\n ;\n F && (T = -T);\n}\nint N, K;\nchar S[2005][505];\nint Order[2005];\nbool Cm... |
Codeforces/202/A | # LLPS
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string s consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.
We'll call a non-empty string s[p1p2... pk] = sp1sp2... sp... | [
{
"input": {
"stdin": "mississipp\n"
},
"output": {
"stdout": "ssss\n"
}
},
{
"input": {
"stdin": "bowwowwow\n"
},
"output": {
"stdout": "wwwww\n"
}
},
{
"input": {
"stdin": "codeforces\n"
},
"output": {
"stdout": "s\n"
}
... | {
"tags": [
"binary search",
"bitmasks",
"brute force",
"greedy",
"implementation",
"strings"
],
"title": "LLPS"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n char s[18];\n scanf(\"%s\", s);\n int len = strlen(s);\n sort(s, s + len);\n int i = len - 1;\n cout << s[i];\n while (--i >= 0 && s[i] == s[len - 1]) cout << s[len - 1];\n cout << endl;\n}\n",
"java": "import java.util.*;\npublic clas... |
Codeforces/226/E | # Noble Knight's Path
In Berland each feudal owns exactly one castle and each castle belongs to exactly one feudal.
Each feudal, except one (the King) is subordinate to another feudal. A feudal can have any number of vassals (subordinates).
Some castles are connected by roads, it is allowed to move along the roads i... | [
{
"input": {
"stdin": "6\n2 5 2 2 0 5\n3\n2 1 6 2 0\n1 2\n2 4 5 1 0\n"
},
"output": {
"stdout": "5\n-1\n"
}
},
{
"input": {
"stdin": "3\n0 1 2\n5\n2 1 3 1 0\n1 2\n2 1 3 1 0\n2 1 3 1 1\n2 1 3 1 2\n"
},
"output": {
"stdout": "2\n-1\n-1\n2\n"
}
},
{
"... | {
"tags": [
"data structures",
"trees"
],
"title": "Noble Knight's Path"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nconst int MAXX = 100000;\nconst int MAXN = 1e5 + 7;\nconst int LOGN = 18;\nstruct Node {\n int cnt;\n Node *bam, *dan;\n Node(int c = 0, Node *b = NULL, Node *d = NULL) : cnt(c), bam(b), dan(d) {}\n void build(int l, int r) {\n if (l == r) return;\n ... |
Codeforces/250/C | # Movie Critics
A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre — an integer from 1 to k.
On the i-th day the festival will show a movie of genre ai. We know that a movie of each of k genres occurs in th... | [
{
"input": {
"stdin": "7 3\n3 1 3 2 3 1 2\n"
},
"output": {
"stdout": "1\n"
}
},
{
"input": {
"stdin": "10 3\n1 1 2 3 2 3 3 1 1 3\n"
},
"output": {
"stdout": "3\n"
}
},
{
"input": {
"stdin": "2 2\n1 2\n"
},
"output": {
"stdout":... | {
"tags": [
"greedy"
],
"title": "Movie Critics"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nconst int maxn = 1e5 + 5;\nint n, k, x[maxn], add[maxn];\nint main() {\n scanf(\"%d %d\", &n, &k);\n for (int i = 0; i < n; i++) scanf(\"%d\", &x[i]);\n int pos = 0;\n while (pos < n) {\n int left = pos - 1;\n while (pos + 1 < n && x[pos] == x[pos + ... |
Codeforces/275/D | # Zero Tree
A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices.
A subtree of a tree T is a tree with both vertices and edges as subsets of vertices and edges of T.
You'... | [
{
"input": {
"stdin": "3\n1 2\n1 3\n1 -1 1\n"
},
"output": {
"stdout": "3"
}
},
{
"input": {
"stdin": "5\n2 3\n4 5\n2 5\n1 3\n0 2 1 4 3\n"
},
"output": {
"stdout": "8"
}
},
{
"input": {
"stdin": "5\n3 1\n2 4\n3 4\n2 5\n0 -3 -1 2 4\n"
},
... | {
"tags": [
"dfs and similar",
"dp",
"greedy",
"trees"
],
"title": "Zero Tree"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nlong long n;\nvector<int> g[100005];\nlong long w[100005];\npair<long long, long long> sol[100005];\nlong long p[100005];\nvoid scan(void) {\n cin >> n;\n for (long long i = (0); i < (n - 1); i++) {\n long long a, b;\n cin >> a >> b;\n g[a].push_bac... |
Codeforces/299/A | # Ksusha and Array
Ksusha is a beginner coder. Today she starts studying arrays. She has array a1, a2, ..., an, consisting of n positive integers.
Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number!
Input
The first line co... | [
{
"input": {
"stdin": "3\n2 3 5\n"
},
"output": {
"stdout": "-1\n"
}
},
{
"input": {
"stdin": "5\n2 1 3 1 6\n"
},
"output": {
"stdout": "1\n"
}
},
{
"input": {
"stdin": "3\n2 2 4\n"
},
"output": {
"stdout": "2\n"
}
},
{
... | {
"tags": [
"brute force",
"number theory",
"sortings"
],
"title": "Ksusha and Array"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nint gcf(int a, int b) {\n if (b == 0) return a;\n return gcf(b, a % b);\n}\nint main() {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n int n;\n cin >> n;\n vector<int> v(n);\n for (int i = 0; i < n; i++) cin >> v[i];\n sort(v.begin()... |
Codeforces/321/D | # Ciel and Flipboard
Fox Ciel has a board with n rows and n columns, there is one integer in each cell.
It's known that n is an odd number, so let's introduce <image>. Fox Ciel can do the following operation many times: she choose a sub-board with size x rows and x columns, then all numbers in it will be multiplied b... | [
{
"input": {
"stdin": "3\n-1 -1 1\n-1 1 -1\n1 -1 -1\n"
},
"output": {
"stdout": "9\n"
}
},
{
"input": {
"stdin": "5\n-2 0 0 0 -2\n0 -2 0 -2 0\n0 0 -2 0 0\n0 -2 0 -2 0\n-2 0 0 0 -2\n"
},
"output": {
"stdout": "18\n"
}
},
{
"input": {
"stdin": ... | {
"tags": [
"dp",
"greedy",
"math"
],
"title": "Ciel and Flipboard"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nint n, nn;\nint t[50][50];\nint s[50][50];\nint main() {\n cin >> n;\n nn = (n + 1) / 2;\n for (int i = 1; i <= n; i++)\n for (int j = 1; j <= n; j++) cin >> t[i][j];\n int sol = -1e9;\n for (int c = 0; c < (1 << nn); c++) {\n int sol2 = 0;\n for... |
Codeforces/346/B | # Lucky Common Subsequence
In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence BDF is a subsequence of ABCDEF. A substring of a string is a continuous subsequence of the string. F... | [
{
"input": {
"stdin": "AA\nA\nA\n"
},
"output": {
"stdout": "0"
}
},
{
"input": {
"stdin": "AJKEQSLOBSROFGZ\nOVGURWZLWVLUXTH\nOZ\n"
},
"output": {
"stdout": "OGZ"
}
},
{
"input": {
"stdin": "ABABBB\nABABBB\nABB\n"
},
"output": {
... | {
"tags": [
"dp",
"strings"
],
"title": "Lucky Common Subsequence"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nconst int maxn = 310;\nconst int oo = 1e9;\nstring s1, s2;\nstring virus;\nint aut[maxn][31];\nint memo[maxn][maxn][maxn];\nint id(const char &ch) { return ch - 'A'; }\nint solve(int i, int j, int k) {\n if (k == (int)virus.size()) {\n return -oo;\n }\n ... |
Codeforces/36/A | # Extra-terrestrial Intelligence
Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for n days in a row. Each of those n days Vasya wrote a 1 in his notebook if he had received a signal that day and a 0 i... | [
{
"input": {
"stdin": "8\n00111000\n"
},
"output": {
"stdout": "YES\n"
}
},
{
"input": {
"stdin": "7\n1001011\n"
},
"output": {
"stdout": "NO\n"
}
},
{
"input": {
"stdin": "7\n1010100\n"
},
"output": {
"stdout": "YES\n"
}
... | {
"tags": [
"implementation"
],
"title": "Extra-terrestrial Intelligence"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nint n, m;\nset<int> ms;\nint main() {\n ifstream myReadFile;\n myReadFile.open(\"input.txt\");\n ofstream myfile;\n myfile.open(\"output.txt\");\n int n;\n myReadFile >> n;\n cin >> n;\n char str[200];\n myReadFile >> str;\n cin >> str;\n int i = 0;... |
Codeforces/391/D2 | # Supercollider
This problem consists of two subproblems: for solving subproblem D1 you will receive 3 points, and for solving subproblem D2 you will receive 16 points.
Manao is the chief architect involved in planning a new supercollider. He has to identify a plot of land where the largest possible supercollider can... | [
{
"input": {
"stdin": "1 2\n4 0 9\n1 1 8\n1 2 7\n"
},
"output": {
"stdout": "2\n"
}
},
{
"input": {
"stdin": "1 1\n0 0 99999998\n-49999999 50000000 99999999\n"
},
"output": {
"stdout": "49999998\n"
}
},
{
"input": {
"stdin": "1 1\n0 0 9999999... | {
"tags": [
"data structures"
],
"title": "Supercollider"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nstruct Line {\n long x, y, l;\n};\nlong n, m;\nvector<Line> ver, por, ver_, por_;\nvector<long> bit;\nvoid enter() {\n cin >> n >> m;\n ver.assign(n, Line());\n por.assign(m, Line());\n for (int i = 0; i < n; ++i) {\n cin >> ver[i].x >> ver[i].y >> ver... |
Codeforces/414/A | # Mashmokh and Numbers
It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh.
In this game Mashmokh writes sequence of n distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first and the second integer from from the board, o... | [
{
"input": {
"stdin": "7 2\n"
},
"output": {
"stdout": "-1\n"
}
},
{
"input": {
"stdin": "5 2\n"
},
"output": {
"stdout": "1 2 3 4 5"
}
},
{
"input": {
"stdin": "5 3"
},
"output": {
"stdout": "2 4 5 6 7"
}
},
{
"inpu... | {
"tags": [
"constructive algorithms",
"number theory"
],
"title": "Mashmokh and Numbers"
} | {
"cpp": "#include <bits/stdc++.h>\nint main() {\n int N, K;\n scanf(\"%d %d\", &N, &K);\n if (N == 1) {\n if (K == 0)\n puts(\"1\");\n else\n puts(\"-1\");\n return 0;\n }\n if (N / 2 > K)\n puts(\"-1\");\n else {\n int x = 1e9;\n K -= (N - 2) / 2;\n printf(\"%d %d\", K, K * 2);\... |
Codeforces/440/C | # One-Based Arithmetic
Prof. Vasechkin wants to represent positive integer n as a sum of addends, where each addends is an integer number containing only 1s. For example, he can represent 121 as 121=111+11+–1. Help him to find the least number of digits 1 in such sum.
Input
The first line of the input contains integ... | [
{
"input": {
"stdin": "121\n"
},
"output": {
"stdout": "6\n"
}
},
{
"input": {
"stdin": "5\n"
},
"output": {
"stdout": "5\n"
}
},
{
"input": {
"stdin": "768617061415848\n"
},
"output": {
"stdout": "390\n"
}
},
{
"inp... | {
"tags": [
"brute force",
"dfs and similar",
"divide and conquer"
],
"title": "One-Based Arithmetic"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nconst long long oo = 1000 * 1000 * 1000;\nlong long n, a[18];\nlong long ans = oo;\nlong long f(long long n, long long ind);\nint main() {\n ios ::sync_with_stdio(false);\n cin.tie(0);\n cin >> n;\n a[0] = 1;\n for (int i = 1; i < 18; i++) a[i] = a[i - 1]... |
Codeforces/462/E | # Appleman and a Sheet of Paper
Appleman has a very big sheet of paper. This sheet has a form of rectangle with dimensions 1 × n. Your task is help Appleman with folding of such a sheet. Actually, you need to perform q queries. Each query will have one of the following types:
1. Fold the sheet of paper at position ... | [
{
"input": {
"stdin": "7 4\n1 3\n1 2\n2 0 1\n2 1 2\n"
},
"output": {
"stdout": "4\n3\n"
}
},
{
"input": {
"stdin": "10 9\n2 2 9\n1 1\n2 0 1\n1 8\n2 0 8\n1 2\n2 1 3\n1 4\n2 2 4\n"
},
"output": {
"stdout": "7\n2\n10\n4\n5\n"
}
},
{
"input": {
"... | {
"tags": [
"data structures",
"implementation"
],
"title": "Appleman and a Sheet of Paper"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nconst long long mod = 1e9 + 7;\nconst int maxn = 1e5 + 50;\nconst int inf = 1e8;\nint n, q;\nint a[maxn];\nbool pre;\nvoid update(int x, int y) {\n while (x <= n) a[x] += y, x += x & -x;\n}\nint sum(int x) {\n int ans = 0;\n while (x) {\n ans += a[x];\n ... |
Codeforces/486/D | # Valid Sets
As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.
We call a set S of tree nodes valid if following conditions are satisfied:
1. S is non-empty.
2. S is ... | [
{
"input": {
"stdin": "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4\n"
},
"output": {
"stdout": "41"
}
},
{
"input": {
"stdin": "0 3\n1 2 3\n1 2\n2 3\n"
},
"output": {
"stdout": "3"
}
},
{
"input": {
"stdin": "1 4\n2 1 3 2\n1 2\n1... | {
"tags": [
"dfs and similar",
"dp",
"math",
"trees"
],
"title": "Valid Sets"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nvector<vector<int> > tree(2005);\nint arr[2005], d;\nint solve(int node, int parent, int maxi) {\n int res = 1;\n for (int i = 0; i < tree[node].size(); i++) {\n int temp = tree[node][i];\n if (temp == parent || arr[temp] > arr[maxi] || arr[maxi] - arr... |
Codeforces/50/C | # Happy Farm 5
The Happy Farm 5 creators decided to invent the mechanism of cow grazing. The cows in the game are very slow and they move very slowly, it can even be considered that they stand still. However, carnivores should always be chased off them.
For that a young player Vasya decided to make the shepherd run ... | [
{
"input": {
"stdin": "4\n1 1\n5 1\n5 3\n1 3\n"
},
"output": {
"stdout": "16\n"
}
},
{
"input": {
"stdin": "4\n0 2\n2 0\n3 5\n5 3\n"
},
"output": {
"stdout": "14\n"
}
},
{
"input": {
"stdin": "10\n1 0\n1 -3\n1 5\n1 -2\n1 5\n1 -2\n1 -2\n1 -2\n... | {
"tags": [
"geometry"
],
"title": "Happy Farm 5"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nvoid prepare() {}\nstruct Point {\n int x, y;\n Point() {}\n Point(int X, int Y) {\n x = X;\n y = Y;\n }\n bool operator<(Point b) { return x < b.x || (x == b.x && y < b.y); }\n Point operator-(Point b) { return Point(x - b.x, y - b.y); }\n Point ... |
Codeforces/534/E | # Berland Local Positioning System
In Berland a bus travels along the main street of the capital. The street begins from the main square and looks like a very long segment. There are n bus stops located along the street, the i-th of them is located at the distance ai from the central square, all distances are distinct... | [
{
"input": {
"stdin": "3\n10 200 300\n4\n1 2 2 3\n"
},
"output": {
"stdout": "-1\n"
}
},
{
"input": {
"stdin": "3\n1 2 3\n4\n1 2 2 3\n"
},
"output": {
"stdout": " 3\n"
}
},
{
"input": {
... | {
"tags": [
"constructive algorithms",
"greedy",
"hashing",
"implementation"
],
"title": "Berland Local Positioning System"
} | {
"cpp": "#include <bits/stdc++.h>\nconst int INF = 1e9;\nconst long long lINF = 1e18;\nconst double EPS = 1e-12;\nusing namespace std;\nconst int N = 200200;\nint n, a[N], m, b[2 * N];\nint cnt[N];\nvector<long long> ans;\nvoid check(int cur, bool left) {\n vector<int> p;\n long long len = 0;\n for (int i = 0; i ... |
Codeforces/559/E | # Gerald and Path
The main walking trail in Geraldion is absolutely straight, and it passes strictly from the north to the south, it is so long that no one has ever reached its ends in either of the two directions. The Geraldionians love to walk on this path at any time, so the mayor of the city asked the Herald to il... | [
{
"input": {
"stdin": "3\n1 1\n2 2\n3 3\n"
},
"output": {
"stdout": "5\n"
}
},
{
"input": {
"stdin": "4\n1 2\n3 3\n4 3\n6 2\n"
},
"output": {
"stdout": "9\n"
}
},
{
"input": {
"stdin": "5\n3 3\n4 3\n6 4\n2 3\n1 5\n"
},
"output": {
... | {
"tags": [
"dp",
"sortings"
],
"title": "Gerald and Path"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nconst int oo = 0x3f3f3f3f;\ntemplate <typename T>\nbool chkmax(T &a, const T &b) {\n return a < b ? a = b, 1 : 0;\n}\ntemplate <typename T>\nbool chkmin(T &a, const T &b) {\n return a > b ? a = b, 1 : 0;\n}\nconst int maxn = 100;\nint n;\npair<int, int> a[ma... |
Codeforces/585/C | # Alice, Bob, Oranges and Apples
Alice and Bob decided to eat some fruit. In the kitchen they found a large bag of oranges and apples. Alice immediately took an orange for herself, Bob took an apple. To make the process of sharing the remaining fruit more fun, the friends decided to play a game. They put multiple card... | [
{
"input": {
"stdin": "2 2\n"
},
"output": {
"stdout": "Impossible\n\n"
}
},
{
"input": {
"stdin": "1 4\n"
},
"output": {
"stdout": "3B\n"
}
},
{
"input": {
"stdin": "3 2\n"
},
"output": {
"stdout": "1A1B\n"
}
},
{
"... | {
"tags": [
"number theory"
],
"title": "Alice, Bob, Oranges and Apples"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nvoid solve(int test_number);\nint main() {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n cout.setf(ios::fixed);\n cout.precision(9);\n cerr.setf(ios::fixed);\n cerr.precision(3);\n int n = 1;\n for (int i = 0; i < n; i... |
Codeforces/607/C | # Marbles
In the spirit of the holidays, Saitama has given Genos two grid paths of length n (a weird gift even by Saitama's standards). A grid path is an ordered sequence of neighbouring squares in an infinite grid. Two squares are neighbouring if they share a side.
One example of a grid path is (0, 0) → (0, 1) → (0,... | [
{
"input": {
"stdin": "7\nNNESWW\nSWSWSW\n"
},
"output": {
"stdout": "YES\n"
}
},
{
"input": {
"stdin": "3\nNN\nSS\n"
},
"output": {
"stdout": "NO\n"
}
},
{
"input": {
"stdin": "2\nW\nS\n"
},
"output": {
"stdout": "YES\n"
}
... | {
"tags": [
"hashing",
"strings"
],
"title": "Marbles"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nconst int Imx = 2147483647;\nconst int mod = 1000000007;\nconst long long Lbg = 2e18;\nchar s[1000111], t[1000111];\nint n, id[256], a[1000111], b[1000111];\nint main() {\n id['N'] = 0;\n id['S'] = 1;\n id['E'] = 2;\n id['W'] = 3;\n scanf(\"%d\", &n);\n ... |
Codeforces/629/B | # Far Relative’s Problem
Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible.
Far cars... | [
{
"input": {
"stdin": "4\nM 151 307\nF 343 352\nF 117 145\nM 24 128\n"
},
"output": {
"stdout": "2\n"
}
},
{
"input": {
"stdin": "6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200\n"
},
"output": {
"stdout": "4\n"
}
},
{
"input": ... | {
"tags": [
"brute force"
],
"title": "Far Relative’s Problem"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\ntemplate <typename T>\ninline T POW(T B, T P) {\n if (P == 0) return 1;\n if (P & 1)\n return B * POW(B, P - 1);\n else\n return SQR(POW(B, P / 2));\n}\ntemplate <class T>\ninline T BigMod(T p, T e, T m) {\n T ret = 1;\n while (e) {\n if (e & 1) ... |
Codeforces/653/C | # Bear and Up-Down
The life goes up and down, just like nice sequences. Sequence t1, t2, ..., tn is called nice if the following two conditions are satisfied:
* ti < ti + 1 for each odd i < n;
* ti > ti + 1 for each even i < n.
For example, sequences (2, 8), (1, 5, 1) and (2, 5, 1, 100, 99, 120) are nice, w... | [
{
"input": {
"stdin": "5\n2 8 4 7 7\n"
},
"output": {
"stdout": "2"
}
},
{
"input": {
"stdin": "4\n200 150 100 50\n"
},
"output": {
"stdout": "1"
}
},
{
"input": {
"stdin": "10\n3 2 1 4 1 4 1 4 1 4\n"
},
"output": {
"stdout": "8... | {
"tags": [
"brute force",
"implementation"
],
"title": "Bear and Up-Down"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nint a[200000];\nvector<int> pos;\nmap<pair<int, int>, int> u;\nbool check(int l, int r) {\n for (int i = l; i < r; i++) {\n if (i % 2 == 0 and a[i] >= a[i + 1])\n return false;\n else if (i % 2 == 1 and a[i] <= a[i + 1])\n return false;\n }\n... |
Codeforces/679/A | # Bear and Prime 100
This is an interactive problem. In the output section below you will see the information about flushing the output.
Bear Limak thinks of some hidden number — an integer from interval [2, 100]. Your task is to say if the hidden number is prime or composite.
Integer x > 1 is called prime if it has... | [
{
"input": {
"stdin": "yes\nno\nyes\n"
},
"output": {
"stdout": "2\n3\n5\n7\n11\n13\n17\n19\n23\n29\n31\n37\n41\n43\n47\n4\n9\n25\n49\ncomposite\n"
}
},
{
"input": {
"stdin": "no\nyes\nno\nno\nno\n"
},
"output": {
"stdout": "2\n3\n5\n7\n11\n13\n17\n19\n23\n29\... | {
"tags": [
"constructive algorithms",
"interactive",
"math"
],
"title": "Bear and Prime 100"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nint n, m, x, y, z, k, w;\nint A[105];\nchar s[10];\nint main() {\n for (int i = (2); i <= (100); i++) {\n x = 0;\n for (int j = (2); j <= (i - 1); j++)\n if (i % j == 0) x = 1;\n if (x == 0) A[w++] = i;\n }\n for (int i = (0); i < (20); i++) {... |
Codeforces/701/B | # Cells Not Under Attack
Vasya has the square chessboard of size n × n and m rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another.
The cell of the field is under rook's attack, if there is at least one rook located in the same row or in the same column with th... | [
{
"input": {
"stdin": "5 2\n1 5\n5 1\n"
},
"output": {
"stdout": "16 9\n"
}
},
{
"input": {
"stdin": "100000 1\n300 400\n"
},
"output": {
"stdout": "9999800001\n"
}
},
{
"input": {
"stdin": "3 3\n1 1\n3 1\n2 2\n"
},
"output": {
... | {
"tags": [
"data structures",
"math"
],
"title": "Cells Not Under Attack"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nlong long mark[100005][2];\nint main(void) {\n ios_base::sync_with_stdio(0);\n long long a, n, b, m, c, d, e, t, f;\n cin >> n >> m;\n long long count = n * n;\n long long cx = 0, cy = 0;\n vector<long long> v;\n while (m--) {\n long long x, y;\n ... |
Codeforces/723/C | # Polycarp at the Radio
Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be represented as a sequence a1, a2, ..., an, where ai is a band, which performs the i-th song. Polycarp likes bands with the numbers from 1 to m, but he doesn't really like others.
We define as bj ... | [
{
"input": {
"stdin": "4 2\n1 2 3 2\n"
},
"output": {
"stdout": "2 1\n1 2 1 2 "
}
},
{
"input": {
"stdin": "7 3\n1 3 2 2 2 2 1\n"
},
"output": {
"stdout": "2 1\n1 3 3 2 2 2 1 "
}
},
{
"input": {
"stdin": "4 4\n1000000000 100 7 1000000000\n"
... | {
"tags": [
"greedy"
],
"title": "Polycarp at the Radio"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nint m, n;\nint a[2005];\nint cnt[2005];\nint ans;\nint main() {\n int i, j, k, t;\n scanf(\"%d%d\", &n, &m);\n for (i = 0; i < n; i++) scanf(\"%d\", &a[i]);\n memset(cnt, 0, sizeof cnt);\n for (i = 0; i < n; i++)\n if (a[i] > 0 && a[i] <= m) cnt[a[i]]+... |
Codeforces/745/B | # Hongcow Solves A Puzzle
Hongcow likes solving puzzles.
One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an n by m grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the gri... | [
{
"input": {
"stdin": "2 2\n.X\nXX\n"
},
"output": {
"stdout": "NO\n"
}
},
{
"input": {
"stdin": "5 5\n.....\n..X..\n.....\n.....\n.....\n"
},
"output": {
"stdout": "YES\n"
}
},
{
"input": {
"stdin": "2 3\nXXX\nXXX\n"
},
"output": {
... | {
"tags": [
"implementation"
],
"title": "Hongcow Solves A Puzzle"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nchar a[600][600];\nstruct p {\n int x, y;\n} b[600 * 600];\nbool cmp(p a, p b) {\n if (a.x == b.x)\n return a.y < b.y;\n else\n return a.x < b.x;\n}\nint main() {\n int n, m;\n scanf(\"%d%d\", &n, &m);\n for (int i = 0; i < n; i++) {\n scanf(\"%... |
Codeforces/768/D | # Jon and Orbs
Jon Snow is on the lookout for some orbs required to defeat the white walkers. There are k different types of orbs and he needs at least one of each. One orb spawns daily at the base of a Weirwood tree north of the wall. The probability of this orb being of any kind is equal. As the north of wall is ful... | [
{
"input": {
"stdin": "1 1\n1\n"
},
"output": {
"stdout": "1\n"
}
},
{
"input": {
"stdin": "2 2\n1\n2\n"
},
"output": {
"stdout": "2\n2\n"
}
},
{
"input": {
"stdin": "1 1\n1000\n"
},
"output": {
"stdout": "1\n"
}
},
{
... | {
"tags": [
"dp",
"math",
"probabilities"
],
"title": "Jon and Orbs"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nint k, q;\ndouble dp[10005][1005];\nint main() {\n scanf(\"%d%d\", &k, &q);\n dp[1][1] = 1;\n for (int i = 2; i < 10005; i++) {\n for (int j = 1; j <= k; j++) {\n dp[i][j] = dp[i - 1][j] * (j * 1.0 / k * 1.0) +\n dp[i - 1][j - 1] * (... |
Codeforces/792/C | # Divide by Three
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible.
The number is called beautiful if it consists of at least one digit, doesn... | [
{
"input": {
"stdin": "10\n"
},
"output": {
"stdout": "0\n"
}
},
{
"input": {
"stdin": "11\n"
},
"output": {
"stdout": "-1\n"
}
},
{
"input": {
"stdin": "1033\n"
},
"output": {
"stdout": "33\n"
}
},
{
"input": {
... | {
"tags": [
"dp",
"greedy",
"math",
"number theory"
],
"title": "Divide by Three"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nconst int INF = 0x3f3f3f3f;\nstring s;\nint n, cnt = 0;\nint dp[100005][2][3];\nint path[100005][2][3];\nint ans[100005];\nint trans(int index) { return s[index] - '0'; }\nint dfs(int now, bool lz, int mod) {\n if (dp[now][lz][mod] != -1) return dp[now][lz][m... |
Codeforces/812/E | # Sagheer and Apple Tree
Sagheer is playing a game with his best friend Soliman. He brought a tree with n nodes numbered from 1 to n and rooted at node 1. The i-th node has ai apples. This tree has a special property: the lengths of all paths from the root to any leaf have the same parity (i.e. all paths have even len... | [
{
"input": {
"stdin": "8\n7 2 2 5 4 3 1 1\n1 1 1 4 4 5 6\n"
},
"output": {
"stdout": "4\n"
}
},
{
"input": {
"stdin": "3\n1 2 3\n1 1\n"
},
"output": {
"stdout": "0\n"
}
},
{
"input": {
"stdin": "3\n2 2 3\n1 1\n"
},
"output": {
"... | {
"tags": [
"games",
"trees"
],
"title": "Sagheer and Apple Tree"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nlong long int n, total_blue = 0, total_red = 0;\nlong long int apple[100010];\nvector<long long int> adj[100010];\nbool is_red[100010], is_blue[100010];\nmap<long long int, long long int> red, blue;\nvector<int> blue_node;\nvoid dfs(long long int node) {\n if... |
Codeforces/838/E | # Convex Countour
You are given an strictly convex polygon with n vertices. It is guaranteed that no three points are collinear. You would like to take a maximum non intersecting path on the polygon vertices that visits each point at most once.
More specifically your path can be represented as some sequence of distin... | [
{
"input": {
"stdin": "4\n0 0\n0 1\n1 1\n1 0\n"
},
"output": {
"stdout": "3.414213562373094923\n"
}
},
{
"input": {
"stdin": "7\n-1000000000 -999999999\n-1000000000 999999999\n-999999999 1000000000\n86871471 971256336\n1000000000 -999999999\n999999999 -1000000000\n-99999999... | {
"tags": [
"dp"
],
"title": "Convex Countour"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nint n;\ndouble dp[2505][2505][2], ans;\npair<double, double> a[2505];\ndouble operator*(const pair<double, double> &a, const pair<double, double> &b) {\n return sqrt((a.first - b.first) * (a.first - b.first) +\n (a.second - b.second) * (a.second ... |
Codeforces/859/B | # Lazy Security Guard
Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly N city blocks, but they let him choose which blocks. That is, your friend must walk the perimeter of a region whose area is exactly N blocks. Yo... | [
{
"input": {
"stdin": "22\n"
},
"output": {
"stdout": "20\n"
}
},
{
"input": {
"stdin": "11\n"
},
"output": {
"stdout": "14\n"
}
},
{
"input": {
"stdin": "4\n"
},
"output": {
"stdout": "8\n"
}
},
{
"input": {
"... | {
"tags": [
"brute force",
"geometry",
"math"
],
"title": "Lazy Security Guard"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\ndouble n, ans;\nint main() {\n cin >> n;\n ans = 2 * ceil(2 * sqrt(n));\n long long ans1 = ans;\n cout << ans1 << endl;\n return 0;\n}\n",
"java": "import java.util.*;\npublic class abcd\n{\n public static void main(String args[])\n {\n Sca... |
Codeforces/884/A | # Book Reading
Recently Luba bought a very interesting book. She knows that it will take t seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of n next days. The number of seconds that Luba has to spend working during i-th day is ai. If some free time remain... | [
{
"input": {
"stdin": "2 2\n86400 86398\n"
},
"output": {
"stdout": "2\n"
}
},
{
"input": {
"stdin": "2 86400\n0 86400\n"
},
"output": {
"stdout": "1\n"
}
},
{
"input": {
"stdin": "6 1200\n86400 86400 86000 86000 86000 86400\n"
},
"ou... | {
"tags": [
"implementation"
],
"title": "Book Reading"
} | {
"cpp": "#include <bits/stdc++.h>\nint main() {\n int n, t, i, flag = 0, a, sum = 0, temp = 0;\n scanf(\"%d %d\", &n, &t);\n for (i = 1; i <= n; i++) {\n scanf(\"%d\", &a);\n sum++;\n if (a < 86400 && flag == 0) {\n temp = temp + 86400 - a;\n if (temp >= t) {\n printf(\"%d\", sum);\n ... |
Codeforces/908/C | # New Year and Curling
Carol is currently curling.
She has n disks each with radius r on the 2D plane.
Initially she has all these disks above the line y = 10100.
She then will slide the disks towards the line y = 0 one by one in order from 1 to n.
When she slides the i-th disk, she will place its center at the ... | [
{
"input": {
"stdin": "6 2\n5 5 6 8 3 12\n"
},
"output": {
"stdout": "2 6.0 9.872983346207416 13.33708496134517 12.518734657272006 13.33708496134517\n"
}
},
{
"input": {
"stdin": "1 1\n5\n"
},
"output": {
"stdout": "1\n"
}
},
{
"input": {
"st... | {
"tags": [
"brute force",
"geometry",
"implementation",
"math"
],
"title": "New Year and Curling"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nconst int INF = 2147483647;\nconst int mod = 1000000007;\nconst double eps2 = 1e-8;\nconst int maxn = 1e5 + 10;\nint ax[1111];\ndouble ay[1111];\nint main() {\n ios::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n int n, r;\n cin >> n >> r;\n for ... |
Codeforces/92/B | # Binary Number
Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations.
Fangy takes some positive integer x and wants to get a number one from it. While x is not equal to 1, Fangy repeats the following action: if x is odd, then he adds 1 to it, otherwis... | [
{
"input": {
"stdin": "1\n"
},
"output": {
"stdout": "0\n"
}
},
{
"input": {
"stdin": "101110\n"
},
"output": {
"stdout": "8\n"
}
},
{
"input": {
"stdin": "1001001\n"
},
"output": {
"stdout": "12\n"
}
},
{
"input": {... | {
"tags": [
"greedy"
],
"title": "Binary Number"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n string s1, s2;\n int a, b, c = 0;\n cin >> s1;\n while (s1 != \"1\") {\n if (s1[s1.size() - 1] == '0') {\n s1.resize(s1.size() - 1);\n c++;\n } else {\n while (s1[s1.size() - 1] == '1' && s1 != \"1\") {\n s1.resiz... |
Codeforces/958/A3 | # Death Stars (hard)
The stardate is 2015, and Death Stars are bigger than ever! This time, two rebel spies have yet again given Heidi two maps with the possible locations of the Death Stars.
Heidi has now received two maps with possible locations of N Death Stars. She knows that each of the maps is possibly corrupte... | [] | {
"tags": [],
"title": "Death Stars (hard)"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nconst int INF = 0x3fffffff;\nconst int SINF = 0x7fffffff;\nconst long long LINF = 0x3fffffffffffffff;\nconst long long SLINF = 0x7fffffffffffffff;\nconst int MAXN = 100007;\nint MAXS = 997;\nconst int MAXSS = 1100007;\nconst long double PI = acos(-1.0);\nconst... |
Codeforces/983/B | # XOR-pyramid
For an array b of length m we define the function f as
f(b) = \begin{cases} b[1] & if m = 1 \\\ f(b[1] ⊕ b[2],b[2] ⊕ b[3],...,b[m-1] ⊕ b[m]) & otherwise, \end{cases}
where ⊕ is [bitwise exclusive OR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
For example, f(1,2,4,8)=f(1⊕2,2⊕4,4⊕8)=... | [
{
"input": {
"stdin": "6\n1 2 4 8 16 32\n4\n1 6\n2 5\n3 4\n1 2\n"
},
"output": {
"stdout": "60\n30\n12\n3\n"
}
},
{
"input": {
"stdin": "3\n8 4 1\n2\n2 3\n1 2\n"
},
"output": {
"stdout": "5\n12\n"
}
},
{
"input": {
"stdin": "6\n1 2 4 12 16 32... | {
"tags": [
"dp"
],
"title": "XOR-pyramid"
} | {
"cpp": "#include <bits/stdc++.h>\nint main() {\n int n;\n scanf(\"%d\", &n);\n int a[n][n];\n int m[n][n];\n for (int i = 0; i < n; ++i) scanf(\"%d\", &a[0][i]), m[0][i] = a[0][i];\n for (int i = 1; i < n; ++i)\n for (int j = 0; j < n - i; ++j)\n a[i][j] = a[i - 1][j] ^ a[i - 1][j + 1],\n m[i][j]... |
HackerEarth/a-new-order | Consider a new order of english alphabets (a to z), that we are not aware of.
What we have though, dictionary of words, ordered according to the new order.
Our task is to give each alphabet a rank, ordered list of words.
The rank of an alphabet is the minimum integer R that can be given to it, such that:
if alphabet ... | [
{
"input": {
"stdin": "6\naaabc\naaade\nbacd\ncde\ncda\ncca\n\nSAMPLE"
},
"output": {
"stdout": "e\na\nb\nd\nc"
}
},
{
"input": {
"stdin": "2\nba\nab"
},
"output": {
"stdout": "b\na"
}
},
{
"input": {
"stdin": "3\nabc\naca\nca"
},
"ou... | {
"tags": [],
"title": "a-new-order"
} | {
"cpp": null,
"java": null,
"python": "Adj = {}\nroot = {}\ndef add(a, b):\n\tif a in Adj:\n\t\tAdj[a][\"child\"].add(b)\n\telse:\n\t\tAdj[a] = {\"rank\":0, \"child\":set([b])}\n\tif b in Adj:\n\t\tif b in root:\n\t\t\tdel root[b]\n\t\t#if a not in Adj[b][parent]:\n\t\t\t#Adj[b][rank] += 1\n\t\t\t#Adj[b][parent]... |
HackerEarth/bitwise-1 | You are a member of a bomb-disposal squad. Each bomb is identified by a unique serial id X, which is a positive integer. To disarm the bomb, a positive integral key Y needs to be entered such that X + Y = X ⊕ Y (here "⊕" denotes the bit-wise XOR operator and "+" denotes the arithmetic sum operator).
However, there ar... | [
{
"input": {
"stdin": "2\n16 3\n8 1\n\nSAMPLE"
},
"output": {
"stdout": "Case #1: 3\nCase #2: 1"
}
},
{
"input": {
"stdin": "2\n5 2\n2 11\n\nELMPAS"
},
"output": {
"stdout": "Case #1: 8\nCase #2: 21\n"
}
},
{
"input": {
"stdin": "2\n7 2\n2 4\... | {
"tags": [],
"title": "bitwise-1"
} | {
"cpp": null,
"java": null,
"python": "for i in range(input()):\n a, k = map(int, raw_input().split())\n cnt = 0\n start= 1\n while True:\n if (a & start) << 1 > 0:\n start += 1\n continue\n else:\n cnt += 1\n start += 1\n if cnt ==... |
HackerEarth/crazy-numbers-1 | Golu is crazy about numbers. He loves those numbers such that the difference between the adjacent digits of that number is exactly one. He calls these numbers crazy numbers and wants to find out how many such numbers exist for N number of digits. This task is very difficult for him so he wants your help.
Now your task... | [
{
"input": {
"stdin": "2\n1\n2\n\nSAMPLE"
},
"output": {
"stdout": "10\n17"
}
}
] | {
"tags": [],
"title": "crazy-numbers-1"
} | {
"cpp": null,
"java": null,
"python": "def crazy(n):\n\tif n==0:\n\t\treturn 0\n\ttable = [[0]*n for _ in range(10)]\n\tfor j in range(n):\n\t\tfor i in range(10):\n\t\t\tif j==0:\n\t\t\t\ttable[i][j] = 1\n\t\t\telse:\n\t\t\t\tif 0<i and i<9:\n\t\t\t\t\tif i==1 and j==1:\n\t\t\t\t\t\ttable[i][j] = table[i+1][j-1... |
HackerEarth/flip-the-world | Flip the world is a game. In this game a matrix of size N*M is given, which consists of numbers. Each number can be 1 or 0 only.
The rows are numbered from 1 to N, and the columns are numbered from 1 to M.
Following steps can be called as a single move.
Select two integers x,y (1 ≤ x ≤ N\; and\; 1 ≤ y ≤ M) i.e. one s... | [
{
"input": {
"stdin": "1\n5 5\n00011\n00011\n00011\n11111\n11111\n\nSAMPLE"
},
"output": {
"stdout": "1\n"
}
},
{
"input": {
"stdin": "30\n1 1\n1\n1 1\n0\n4 4\n0000\n1110\n0101\n1011\n4 4\n1100\n0010\n1010\n1101\n4 4\n1111\n1110\n0000\n0100\n4 4\n1000\n1110\n0011\n1110\n4 4... | {
"tags": [],
"title": "flip-the-world"
} | {
"cpp": null,
"java": null,
"python": "T = input()\nboard = []\n\ndef flipSquare(n, m):\n\tif board[n][m]: return 0\n\telse:\n\t\tfor i in xrange(n + 1):\n\t\t\tfor j in xrange(m + 1):\n\t\t\t\tboard[i][j] = not board[i][j]\n\t\treturn 1\n\ndef flipRow(n):\n\tmoves = 0\n\tfor m in reversed(xrange(len(board[n])))... |
HackerEarth/jholibaba-and-his-wish | JholiBaba is a student of vnit and he has a craze for rotation. A Roller contest is organized in vnit which JholiBaba wants to win. In the contest, there is one roller which is represented similar to a strip of 1xN blocks. Each block has a number written on it. The roller keeps rotating and you will figure out that aft... | [
{
"input": {
"stdin": "3\n20 30 10\n\nSAMPLE"
},
"output": {
"stdout": "140"
}
},
{
"input": {
"stdin": "5\n-12452 90611 67470 -528 -9054"
},
"output": {
"stdout": "643802"
}
},
{
"input": {
"stdin": "3\n9 52 0\n\nSAMOLE"
},
"output":... | {
"tags": [],
"title": "jholibaba-and-his-wish"
} | {
"cpp": null,
"java": null,
"python": "n = int(raw_input())\na = map(int, raw_input().split())\ns = sum(a)\np = sum((i+1) * a[i] for i in xrange(n))\nans = p\nfor i in xrange(n-1):\n\tp += a[i] * n - s\n\tans = max(ans, p)\nprint ans"
} |
HackerEarth/mike-and-his-guitar-collection-3 | Mike has a huge guitar collection which the whole band is jealous of. Brad, the lead guitarist of the band, gave Mike a challenge so that he can't use all his guitars. The band is on a world tour and Brad told Mike to assign numbers to all his guitars. After that, he told Mike that he can use the guitars in such a mann... | [
{
"input": {
"stdin": "3\n1\n1\n2\n1 2\n3\n1 2 3\n\nSAMPLE"
},
"output": {
"stdout": "2\n4\n7\n"
}
},
{
"input": {
"stdin": "3\n1\n0\n2\n0 0\n6\n1 1 1\n\nSLMQAE"
},
"output": {
"stdout": "1\n1\n4\n"
}
},
{
"input": {
"stdin": "3\n1\n1\n2\n4 0... | {
"tags": [],
"title": "mike-and-his-guitar-collection-3"
} | {
"cpp": null,
"java": null,
"python": "from itertools import combinations\nfor _ in range(input()):\n\tarr=[]\n\n\tn=input()\n\ta=map(int,raw_input().split())\n\tfor i in range(n+1):\n\t\tcomb = combinations(a,i)\n\t\tarr.append(comb)\n\tcount=0\n\tsumset=set()\n\t# Print the obtained combinations\n\tfor it in a... |
HackerEarth/p1-6 | Raj's lucky number is 101. His girl friend Rani wants to give him a string S as a birthday present to him. She went to a shop and there are variety of strings which contains only 1 and 0 ( Binary string ) in that shop. Now in order to impress Raj , she wants to buy a string with highest number of subsequence’s of 101'... | [
{
"input": {
"stdin": "10101\n\nSAMPLE"
},
"output": {
"stdout": "4\n"
}
},
{
"input": {
"stdin": "10101\n\nKFSOCM"
},
"output": {
"stdout": "4\n"
}
},
{
"input": {
"stdin": "10101\n\nFJQNRC"
},
"output": {
"stdout": "4\n"
}... | {
"tags": [],
"title": "p1-6"
} | {
"cpp": null,
"java": null,
"python": "def num_subsequences(seq, sub):\n m, n = len(seq), len(sub)\n table = [0] * n\n for i in xrange(m):\n previous = 1\n for j in xrange(n):\n current = table[j]\n if seq[i] == sub[j]:\n table[j] += previous\n ... |
HackerEarth/remove-friends-5 | After getting her PhD, Christie has become a celebrity at her university, and her facebook profile is full of friend requests. Being the nice girl she is, Christie has accepted all the requests.
Now Kuldeep is jealous of all the attention she is getting from other guys, so he asks her to delete some of the guys from h... | [
{
"input": {
"stdin": "3\n3 1\n3 100 1\n5 2\n19 12 3 4 17\n5 3\n23 45 11 77 18\n\nSAMPLE"
},
"output": {
"stdout": "100 1\n19 12 17\n77 18\n"
}
},
{
"input": {
"stdin": "3\n3 0\n3 000 1\n5 1\n19 2 3 -1 17\n5 3\n23 45 11 77 18\n\nSAMPLE"
},
"output": {
"stdout"... | {
"tags": [],
"title": "remove-friends-5"
} | {
"cpp": null,
"java": null,
"python": "for _ in xrange(input()):\n n,k = map(int,raw_input().split())\n arr = map(int,raw_input().split())\n stk = []\n for ele in arr:\n while k and len(stk) and stk[-1] < ele:\n stk.pop()\n k -= 1\n stk.append(ele)\n print ' '.j... |
HackerEarth/sonas-number-sequence | Sona is busy in organizing Port '16. Sona has to formulate two number sequence as two list. As she loves numbers she wrote the two number sequence in two different papers. Both the list have N numbers. She also named the number sequence as A and B where A = {a0,a1,...aN-1} and B = {b0,b1,..,bN-1} where as
b0 = a0... | [
{
"input": {
"stdin": "5\n10 11 12 13 14\n\nSAMPLE"
},
"output": {
"stdout": "10 12 14 16 18\n"
}
},
{
"input": {
"stdin": "5\n40 0 4 7 17\n\nSAMNLE"
},
"output": {
"stdout": "40 -40 12 16 57\n"
}
},
{
"input": {
"stdin": "5\n0 -3 2 0 0\n\nAM... | {
"tags": [],
"title": "sonas-number-sequence"
} | {
"cpp": null,
"java": null,
"python": "'''\n# Read input from stdin and provide input before running code\n\nname = raw_input('What is your name?\\n')\nprint 'Hi, %s.' % name\n'''\n#print 'Hello World!'\nn=input()\nl=[int(i) for i in raw_input().split()]\ns=0\nfor i in range(n):\n\tx=(i+1)*l[i]-s\n\ts+=x\n\tprin... |
HackerEarth/tom-and-coins | Problem Statement:
Tom is collecting money for his birthday party, he is having 'a' coins today and his father gives him 'k' coins each day.
Since his birthday is on 'nth' day, he wants to know the amount of money he will have on his birthday.
Tom is weak at maths, help him calculate the number of coins he will hav... | [
{
"input": {
"stdin": "3\n2 2 3\n1 2 3\n1 0 3\n\nSAMPLE"
},
"output": {
"stdout": "6\n5\n1\n"
}
},
{
"input": {
"stdin": "100\n84 87 78\n16 94 36\n87 93 50\n22 63 28\n91 60 64\n27 41 27\n73 37 12\n69 68 30\n83 31 63\n24 68 36\n30 3 23\n59 70 68\n94 57 12\n43 30 74\n22 20 85... | {
"tags": [],
"title": "tom-and-coins"
} | {
"cpp": null,
"java": null,
"python": "noOfTestCases = int(raw_input())\n\ndef totMoney(a, k, n):\n\ta,k,n = int(a), int(k), int(n)\n\treturn a + k * (n-1)\n\t\n\nfor j in range(1, noOfTestCases + 1):\n\ta, k, n = raw_input().split(\" \")\n\tprint totMoney(a, k, n)"
} |
p02565 AtCoder Library Practice Contest - Two SAT | Consider placing N flags on a line. Flags are numbered through 1 to N.
Flag i can be placed on the coordinate X_i or Y_i. For any two different flags, the distance between them should be at least D.
Decide whether it is possible to place all N flags. If it is possible, print such a configulation.
Constraints
* 1 \l... | [
{
"input": {
"stdin": "3 3\n1 4\n2 5\n0 6"
},
"output": {
"stdout": "No"
}
},
{
"input": {
"stdin": "3 2\n1 4\n2 5\n0 6"
},
"output": {
"stdout": "Yes\n4\n2\n0"
}
},
{
"input": {
"stdin": "3 3\n2 2\n2 4\n-1 9"
},
"output": {
"st... | {
"tags": [],
"title": "p02565 AtCoder Library Practice Contest - Two SAT"
} | {
"cpp": "#include <cassert>\n#include <cmath>\n#include <algorithm>\n#include <iostream>\n#include <iomanip>\n#include <limits.h>\n#include <map>\n#include <queue>\n#include <set>\n#include <string.h>\n#include <vector>\n\nusing namespace std;\ntypedef long long ll;\n\ntypedef vector <vector<int>> Graph;\n\n// 強連結成分... |
p02696 AtCoder Beginner Contest 165 - Floor Function | Given are integers A, B, and N.
Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N.
Here floor(t) denotes the greatest integer not greater than the real number t.
Constraints
* 1 ≤ A ≤ 10^{6}
* 1 ≤ B ≤ 10^{12}
* 1 ≤ N ≤ 10^{12}
* All values in input are i... | [
{
"input": {
"stdin": "5 7 4"
},
"output": {
"stdout": "2"
}
},
{
"input": {
"stdin": "11 10 9"
},
"output": {
"stdout": "9"
}
},
{
"input": {
"stdin": "0 36 3"
},
"output": {
"stdout": "0\n"
}
},
{
"input": {
... | {
"tags": [],
"title": "p02696 AtCoder Beginner Contest 165 - Floor Function"
} | {
"cpp": "#include <bits/stdc++.h>\nusing namespace std;\nint main(){\n \n long long A,B,N,D;\n cin >> A >> B >> N;\n D=min((B-1),N);\n cout << A*D/B << endl;\n \n}",
"java": "import java.util.Scanner;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner sc = new Scanner(Syste... |
p02825 AtCoder Grand Contest 041 - Domino Quality | Let us consider a grid of squares with N rows and N columns. You want to put some domino pieces on this grid. Each domino piece covers two squares that have a common side. Each square can be covered by at most one piece.
For each row of the grid, let's define its quality as the number of domino pieces that cover at le... | [
{
"input": {
"stdin": "2"
},
"output": {
"stdout": "-1"
}
},
{
"input": {
"stdin": "6"
},
"output": {
"stdout": "aabb..\nb..zz.\nba....\n.a..aa\n..a..b\n..a..b"
}
},
{
"input": {
"stdin": "111"
},
"output": {
"stdout": "aacd....... | {
"tags": [],
"title": "p02825 AtCoder Grand Contest 041 - Domino Quality"
} | {
"cpp": "#include <cstdio>\n#include <cstring>\n\nchar ans3[4][4]={\"aab\",\"b.b\",\"baa\"};\nchar ans4[5][5]={\"aacd\",\"bbcd\",\"dcaa\",\"dcbb\"};\nchar ans5[6][6]={\"aabc.\",\"..bcd\",\"ccd.d\",\"d.daa\",\"dccbb\"};\nchar ans6[7][7]={\"a..bcc\",\"a..bdd\",\".bccb.\",\".baab.\",\"ddb..a\",\"ccb..a\"};\nchar ans7[8... |
p02962 AtCoder Beginner Contest 135 - Strings of Eternity | Given are two strings s and t consisting of lowercase English letters. Determine if the number of non-negative integers i satisfying the following condition is finite, and find the maximum value of such i if the number is finite.
* There exists a non-negative integer j such that the concatenation of i copies of t is a... | [
{
"input": {
"stdin": "aa\naaaaaaa"
},
"output": {
"stdout": "-1"
}
},
{
"input": {
"stdin": "aba\nbaaab"
},
"output": {
"stdout": "0"
}
},
{
"input": {
"stdin": "abcabab\nab"
},
"output": {
"stdout": "3"
}
},
{
"inp... | {
"tags": [],
"title": "p02962 AtCoder Beginner Contest 135 - Strings of Eternity"
} | {
"cpp": "#include<bits/stdc++.h>\nusing namespace std;\nint n,N,m,ans,ANS,DFN;\nchar s1[5000050],s2[5000050];\nint f[5000050],b[5000050],l[5000050],dfn[5000050],len[5000050];\n\nint main()\n{\n\tint i,j,t;\n scanf(\"%s\",s1+1),n=strlen(s1+1);\n scanf(\"%s\",s2+1),m=strlen(s2+1);\n N=n;\n while(N<=2*m)\n {\n\t... |
p03097 AtCoder Grand Contest 031 - Differ by 1 Bit | You are given integers N,\ A and B. Determine if there exists a permutation (P_0,\ P_1,\ ...\ P_{2^N-1}) of (0,\ 1,\ ...\ 2^N-1) that satisfies all of the following conditions, and create one such permutation if it exists.
* P_0=A
* P_{2^N-1}=B
* For all 0 \leq i < 2^N-1, the binary representations of P_i and P_{i+1} ... | [
{
"input": {
"stdin": "3 2 1"
},
"output": {
"stdout": "NO"
}
},
{
"input": {
"stdin": "2 1 3"
},
"output": {
"stdout": "YES\n1 0 2 3"
}
},
{
"input": {
"stdin": "1 1 1"
},
"output": {
"stdout": "NO\n"
}
},
{
"input"... | {
"tags": [],
"title": "p03097 AtCoder Grand Contest 031 - Differ by 1 Bit"
} | {
"cpp": "#include<stdio.h>\n#include<stdlib.h>\n#include<string.h>\n#include<math.h>\n#include<algorithm>\n#include<queue>\n#include<set>\n#include<map>\n#include<iostream>\nusing namespace std;\n#define ll long long\n#define REP(a,b,c) for(int a=b;a<=c;a++)\n#define re register\n#define file(a) freopen(a\".in\",\"r... |
p03243 AtCoder Beginner Contest 111 - AtCoder Beginner Contest 111 | Kurohashi has never participated in AtCoder Beginner Contest (ABC).
The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same.
What is the earliest ABC where Kurohashi can make his debut?
Constraints
* 100 \leq N... | [
{
"input": {
"stdin": "750"
},
"output": {
"stdout": "777"
}
},
{
"input": {
"stdin": "112"
},
"output": {
"stdout": "222"
}
},
{
"input": {
"stdin": "111"
},
"output": {
"stdout": "111"
}
},
{
"input": {
"stdi... | {
"tags": [],
"title": "p03243 AtCoder Beginner Contest 111 - AtCoder Beginner Contest 111"
} | {
"cpp": "#include<iostream>\nusing namespace std;\nint main(){\n\tint n;\n\tcin>>n;\n\tif((n/100)*111>=n)cout<<(n/100)*111;\n\telse cout<<(n/100+1)*111;\n\treturn 0;\n}",
"java": "import java.util.*;\npublic class Main {\n\n\t\tstatic void solve() {\n\t\t\tScanner sc = new Scanner(System.in);\n\t\t\tint n = sc.nex... |
p03396 AtCoder Grand Contest 022 - Shopping | Yui loves shopping. She lives in Yamaboshi City and there is a train service in the city. The city can be modelled as a very long number line. Yui's house is at coordinate 0.
There are N shopping centres in the city, located at coordinates x_{1}, x_{2}, ..., x_{N} respectively. There are N + 2 train stations, one loca... | [
{
"input": {
"stdin": "5 100\n10 19 28 47 68\n200 200 200 200 200"
},
"output": {
"stdout": "1200"
}
},
{
"input": {
"stdin": "2 10\n5 8\n10 5"
},
"output": {
"stdout": "60"
}
},
{
"input": {
"stdin": "8 1000000000\n2018 123456 1719128 192918... | {
"tags": [],
"title": "p03396 AtCoder Grand Contest 022 - Shopping"
} | {
"cpp": "#include<bits/stdc++.h>\n#define ll long long\n#define ld long double\n#define db double\n#define pint pair<int,int>\n#define mk(x,y) make_pair(x,y)\n#define fir first\n#define sec second\n#define Rep(x,y,z) for(int x=y;x<=z;++x)\n#define Red(x,y,z) for(int x=y;x>=z;--x)\nusing namespace std;\nconst int MAX... |
p03561 AtCoder Regular Contest 084 - Finite Encyclopedia of Integer Sequences | In Finite Encyclopedia of Integer Sequences (FEIS), all integer sequences of lengths between 1 and N (inclusive) consisting of integers between 1 and K (inclusive) are listed.
Let the total number of sequences listed in FEIS be X. Among those sequences, find the (X/2)-th (rounded up to the nearest integer) lexicograph... | [
{
"input": {
"stdin": "2 4"
},
"output": {
"stdout": "1 2 2 2"
}
},
{
"input": {
"stdin": "5 14"
},
"output": {
"stdout": "3 3 3 3 3 3 3 3 3 3 3 3 2 2"
}
},
{
"input": {
"stdin": "3 2"
},
"output": {
"stdout": "2 1"
}
},
... | {
"tags": [],
"title": "p03561 AtCoder Regular Contest 084 - Finite Encyclopedia of Integer Sequences"
} | {
"cpp": "#include<bits/stdc++.h>\n#define ll long long\n#define N 300005\nusing namespace std;\nint f[N],k,n,top;\nll g[N];\nint main(){\n\tscanf(\"%d %d\",&k,&n);\n\tif (k%2==0){\n\t\tprintf(\"%d \",k/2);\n\t\tfor (int i=2;i<=n;i++)\n\t\t\tprintf(\"%d \",k);\n\t}\n\telse{\n\t\tf[1]=k&1; g[1]=k;\n\t\tfor (int i=2;i<... |
p03714 AtCoder Beginner Contest 062 - 3N Numbers | Let N be a positive integer.
There is a numerical sequence of length 3N, a = (a_1, a_2, ..., a_{3N}). Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements from a without changing the order of the remaining elements. Here, the score of a' is defined as follows: (the sum of the elements ... | [
{
"input": {
"stdin": "2\n3 1 4 1 5 9"
},
"output": {
"stdout": "1"
}
},
{
"input": {
"stdin": "1\n1 2 3"
},
"output": {
"stdout": "-1"
}
},
{
"input": {
"stdin": "3\n8 2 2 7 4 6 5 3 8"
},
"output": {
"stdout": "5"
}
},
... | {
"tags": [],
"title": "p03714 AtCoder Beginner Contest 062 - 3N Numbers"
} | {
"cpp": "#include<iostream>\n#include<algorithm>\n#include<vector>\n#include<queue>\nusing lint=int64_t;\nusing namespace std;\n\nint main()\n{\n\tint N;\n\tlint a[300010]={};\n\tpriority_queue<int,vector<int>,greater<int>> ql;\n\tpriority_queue<int> qr;\n\tlint qsum;\n\tlint lsum[100010]={};\n\tlint rsum[100010]={}... |
p03875 CODE FESTIVAL 2016 Grand Final - AB=C Problem | Snuke received two matrices A and B as birthday presents. Each of the matrices is an N by N matrix that consists of only 0 and 1.
Then he computed the product of the two matrices, C = AB. Since he performed all computations in modulo two, C was also an N by N matrix that consists of only 0 and 1. For each 1 ≤ i, j ≤ N... | [
{
"input": {
"stdin": "2\n0 1\n1 0"
},
"output": {
"stdout": "6"
}
},
{
"input": {
"stdin": "10\n1 0 0 1 1 1 0 0 1 0\n0 0 0 1 1 0 0 0 1 0\n0 0 1 1 1 1 1 1 1 1\n0 1 0 1 0 0 0 1 1 0\n0 0 1 0 1 1 1 1 1 1\n1 0 0 0 0 1 0 0 0 0\n1 1 1 0 1 0 0 0 0 1\n0 0 0 1 0 0 1 0 1 0\n0 0 0 1 1... | {
"tags": [],
"title": "p03875 CODE FESTIVAL 2016 Grand Final - AB=C Problem"
} | {
"cpp": "#include <bits/stdc++.h>\n\nusing namespace std;\n\nconst int md = 1000000007;\n\ninline void add(int &a, int b) {\n a += b;\n if (a >= md) {\n a -= md;\n }\n}\n\ninline int mul(int a, int b) {\n return (long long) a * b % md;\n}\n\nconst int N = 310;\n\nint a[N][N];\nint f[N][N];\nint p2[N * N];\nin... |
p04037 AtCoder Grand Contest 002 - Candy Piles | There are N piles of candies on the table. The piles are numbered 1 through N. At first, pile i contains a_i candies.
Snuke and Ciel are playing a game. They take alternating turns. Snuke goes first. In each turn, the current player must perform one of the following two operations:
1. Choose a pile with the largest n... | [
{
"input": {
"stdin": "3\n1 2 1"
},
"output": {
"stdout": "First"
}
},
{
"input": {
"stdin": "2\n1 3"
},
"output": {
"stdout": "First"
}
},
{
"input": {
"stdin": "3\n1 2 3"
},
"output": {
"stdout": "Second"
}
},
{
"i... | {
"tags": [],
"title": "p04037 AtCoder Grand Contest 002 - Candy Piles"
} | {
"cpp": "#include<cstdio>\n#include<algorithm>\nconst int N=1e5+3; \nint n,a[N];\nint main(){\n\tscanf(\"%d\",&n);\n\tfor(int i=1;i<=n;i++)scanf(\"%d\",a+i);\n\tstd::sort(a+1,a+1+n);\n\tfor(int i=0;i<n;i++)if(a[n-i]==i){\n\t int f;\n\t for(f=i+1;a[n-f]>=i;f++);\n\t return 0*puts((f-i+1&1)&&(a[n-i+1]-i+1&1)?\"Seco... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.